找回密码
 立即注册

使用微信账号登录

只需一步,快速开始

查看: 3051|回复: 3

[ADK相关资料] 这个赋值如何解释?

[复制链接]
连续签到天数:1天
签到总天数:1023天
签到总奖励:12600金币
发表于 2017-3-8 15:52:34 | 显示全部楼层 |阅读模式

马上注册,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册  

×
在BLE client中有一个赋值,有些看不明白。
  1. SERVICE_FUNC_POINTERS_T BatteryServiceFuncStore = {
  2.     .serviceUuid            = &BatteryServiceUuid,
  3.     .isMandatory            = NULL,
  4.     .serviceInit            = &BatteryServiceDataInit,
  5.     .checkHandle            = &BatteryServiceCheckHandle,
  6.     .getHandles             = &BatteryServiceGetHandles,
  7.     .charDiscovered         = &BatteryServiceCharDiscovered,
  8.     .descDiscovered         = &BatteryServiceCharDescDisc,
  9.     .discoveryComplete      = &BatteryServiceDiscoveryComplete,
  10.     .serviceIndNotifHandler = &BatteryServiceHandlerNotifInd,
  11.     .configureServiceNotif  = &BatteryServiceConfigNotif,
  12.     .writeRequest           = NULL,
  13.     .writeConfirm           = &BatteryServiceWriteConfirm,
  14.     .readRequest            = &BatteryServiceReadRequest,
  15.     .readConfirm            = &BatteryServiceReadConfirm,
  16.     .configureService       = &BatteryServiceConfigure,
  17.     .isServiceFound         = &BatteryServiceFound,
  18.     .resetServiceData       = &BatteryServiceResetData
  19. };
复制代码
该数据类型定义如下,是一个结构体,成员都是函数指针:
  1. /* Service callbacks */
  2. typedef struct _SERVICE_FUNC_POINTERS_T
  3. {
  4.     /* Returns the service UUID and its type (16-bit or 128-bit) */
  5.     void (*serviceUuid)(GATT_UUID_T *type, uint16 *uuid);

  6.     /* Returns TRUE if the service is mandatory */
  7.     bool (*isMandatory)(void);

  8.     /* Initialise service data */
  9.     void (*serviceInit)(uint16 dev_num,
  10.                         GATT_DISC_PRIM_SERV_BY_UUID_IND_T *p_event_data);

  11.     /* Returns TRUE if the handle is supported by the service */
  12.     bool (*checkHandle)(uint16 dev_num, uint16 handle);
  13.    
  14.     /* Get the start and end handle for the service or characteristic */
  15.     bool (*getHandles)(uint16 dev_num,
  16.                        uint16 *StartHandle,
  17.                        uint16 *EndHandle,
  18.                        gatt_profile_hierarchy_t type);

  19.     /* Called for each discovered characteristic */
  20.     bool (*charDiscovered)(uint16 dev_num,
  21.                            GATT_CHAR_DECL_INFO_IND_T *p_event_data);

  22.     /* Called for each discovered characteristic descriptor. This function must
  23.      * only be called after first calling charDiscovered.
  24.      */
  25.     void (*descDiscovered)(uint16 dev_num,
  26.                            GATT_CHAR_DESC_INFO_IND_T *p_event_data);

  27.     /* Called when the Discovery Procedure is complete for the current server.
  28.      * Returns TRUE if the callback starts a read or write, otherwise FALSE
  29.          */
  30.     bool (*discoveryComplete)(uint16 dev_num,
  31.                               uint16 connect_handle);

  32.     /* Configure notifications for a given characteristic by writing to the
  33.      * Client Characteristic Configuration Descriptor. Returns TRUE, if
  34.      * successful, otherwise FALSE
  35.      */
  36.     bool (*configureServiceNotif)(uint16 dev_num,
  37.                                   uint16 type,
  38.                                   uint8 sub_type,
  39.                                   bool enable);

  40.     /* Callback for handling indications and notifications */
  41.     bool (*serviceIndNotifHandler)(uint16 dev_num,
  42.                                    uint16 handle,
  43.                                    uint16 size,
  44.                                    uint8 *value);

  45.     /* Callback to modify the value of a characteristic on the peer device */
  46.     bool (*writeRequest)(uint16 dev_num,
  47.                          uint16 type,
  48.                          uint8 *data,
  49.                          uint16 size);

  50.     /* Function called after a characteristic value has been successfully
  51.      * written
  52.     */
  53.     void (*writeConfirm)(uint16 dev_num,
  54.                          uint16 connect_handle);

  55.     /* Callback to read the value of a characteristic on the peer device */
  56.     bool (*readRequest)(uint16 dev_num, uint16 type);

  57.     /* Function called when a characteristic value has been successfully read */
  58.     void (*readConfirm)(uint16 dev_num,
  59.                         uint16 size,
  60.                         uint8 *value);

  61.     /* Configure the service to request notifications or indications */
  62.     bool (*configureService)(uint16 dev_num);

  63.     /* Check if the service is present on the specified device */
  64.     bool (*isServiceFound)(uint16 dev_num);
  65.    
  66.     /* Reset the service data */
  67.     void (*resetServiceData)(uint16 dev_num);
  68. } SERVICE_FUNC_POINTERS_T;
复制代码
结构体赋初值不应该是如下这样吗?
  1. SERVICE_FUNC_POINTERS_T BatteryServiceFuncStore = {
  2.          &BatteryServiceUuid,
  3.          NULL,
  4.          &BatteryServiceDataInit,
  5.          &BatteryServiceCheckHandle,
  6.          &BatteryServiceGetHandles,
  7.          &BatteryServiceCharDiscovered,
  8.          &BatteryServiceCharDescDisc,
  9.          &BatteryServiceDiscoveryComplete,
  10.          &BatteryServiceHandlerNotifInd,
  11.          &BatteryServiceConfigNotif,
  12.          NULL,
  13.          &BatteryServiceWriteConfirm,
  14.          &BatteryServiceReadRequest,
  15.          &BatteryServiceReadConfirm,
  16.          &BatteryServiceConfigure,
  17.          &BatteryServiceFound,
  18.          &BatteryServiceResetData
  19. };
复制代码
例程中,成员前加一个.然后再=,这种赋值法在C里边没有见过啊,而且放到标准的C编译器里也编译不过。是SDK支持的特殊语法吗?

楼主热帖
积分商城 - 让您的金币更有价值!||官方Q群 - 让您的沟通更加及时!
连续签到天数:1天
签到总天数:1023天
签到总奖励:12600金币
 楼主| 发表于 2017-3-8 15:57:42 | 显示全部楼层
我最后的那种方法在SDK中也可以编译过,但是必须注意顺序不能乱。
第一个初始化的方法,成员顺序乱了也可以。但是这样赋值还是第一次见。
积分商城 - 让您的金币更有价值!||官方Q群 - 让您的沟通更加及时!
回复 支持 反对

使用道具 举报

连续签到天数:10天
签到总天数:42天
签到总奖励:1458金币
发表于 2017-3-13 17:33:56 | 显示全部楼层
GCC 專屬語法
請參照 6.27 Designated Initializers 章節
https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html

這種語法能避免賦值時意外將順序弄錯, 該語法只能用來初始結構變數用
积分商城 - 让您的金币更有价值!||官方Q群 - 让您的沟通更加及时!
回复 支持 反对

使用道具 举报

连续签到天数:1天
签到总天数:1023天
签到总奖励:12600金币
 楼主| 发表于 2017-3-13 18:05:29 | 显示全部楼层
shenada 发表于 2017-3-13 17:33
GCC 專屬語法
請參照 6.27 Designated Initializers 章節
https://gcc.gnu.org/onlinedocs/gcc/Designate ...

给力!多谢。
在VC里编译不通过,果然在单片机编译器里就可以通过了。
积分商城 - 让您的金币更有价值!||官方Q群 - 让您的沟通更加及时!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册  

本版积分规则

小黑屋|手机版|我爱蓝牙网 - 52Bluetooth

GMT+8, 2024-3-29 19:05 , Processed in 0.193521 second(s), 18 queries , Gzip On, MemCached On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表