SDK5.0.3:如何创建一个使用16位UUID的服务,cust_prf_func_callbacks只有128位UUID
你好,
可以使用相同的数据结构定义16位UUID服务。使用"struct attm_desc_128"的原因是允许相同的数据结构同时覆盖16位和128位UUID元素。仔细查看CUSTOM1数据库的声明,您可以看到服务声明为16位UUID, LED状态特征声明为128位UUID。这个数据库混合包含16位和128位的UUID元素。您可以将此作为参考来创建自己的自定义配置文件。
///属性描述(用于创建数据库)struct attm_desc_128{///元素UUID.uint8_t * uuid;// <<<<< uuid数组/ / / UUID的大小uint8_t uuid_size;// <<<<<用于定义uuid长度,(ATT_UUID_128_LEN或ATT_UUID_16_LEN)/ / /属性许可uint16_t烫;///元素的最大长度att_size_t max_length;///元素的当前长度att_size_t长度;///元素值数组uint8_t *值;};
/*---------------- 声明 -----------------*////主服务声明ATT_DECL_PRIMARY_SERVICE = 0 x2800,///二级服务声明ATT_DECL_SECONDARY_SERVICE,/ / /包括声明ATT_DECL_INCLUDE,/ / /声明特征ATT_DECL_CHARACTERISTIC,
static uint16_t att_decl_svc = ATT_DECL_PRIMARY_SERVICE;static uint16_t att_decl_char = ATT_DECL_CHARACTERISTIC;
#define DEF_CUST1_SVC_UUID_128 {0x2F、0x2A、0x93、0xA6、0xBD、0xD8、0x41、0x52、0xAC、0x0B、0x10、0x99、0x2E、0xC6、0xFE、0xED}
#define DEF_CUST1_CTRL_POINT_UUID_128 {0x20、0xEE、0x8D、0x0C、0xE1、0xF0、0x4A、0x0C、0xB3、0x25、0xDC、0x53、0x6A、0x68、0x86、0x2D}#define DEF_CUST1_LED_STATE_UUID_128 {0x4F、0x43、0x31、0x3C、0x93、0x92、0x42、0xE6、0xA8、0x76、0xFA、0x3B、0xEF、0xB4、0x87、0x5A}#define DEF_CUST1_ADC_VAL_1_UUID_128 {0x17、0xB9、0x67、0x98、0x4C、0x66、0x4C、0x01、0x96、0x33、0x31、0xB1、0x91、0x59、0x00、0x15}#define DEF_CUST1_ADC_VAL_2_UUID_128 {0x23、0x68、0xEC、0x52、0x1E、0x62、0x44、0x74、0x9A、0x1B、0xD1、0x8B、0xAB、0x75、0xB6、0x6E}#define DEF_CUST1_BUTTON_STATE_UUID_128 {0x9E, 0xE7, 0xBA, 0x08, 0xB9, 0xA9, 0x48, 0xAB, 0xA1, 0xAC, 0x03, 0x1C, 0x2E, 0x0D, 0x29, 0x6C}#define def_cust1_indicateable_uuuid_128 {0x28,0xd5,0xe1,0xc1,0xe1,0xc5,0x47,0x29,0xb5,0x57,0x65,0xc3,0xba,0x47,0x15,0x9e}定义DEF_CUST1_LONG_VALUE_UUID_128 {0x8C, 0x09, 0xE0, 0xD1, 0x81, 0x54, 0x42, 0x40, 0x8E, 0x4F, 0xD2, 0xB3, 0x77, 0xE3, 0x2A, 0x77}
#定义x0002 ATT_UUID_16_LEN 0#define att_uuid_128_len 0x0010
//================================================================================================================
///完整CUSTOM1数据库描述-用于向数据库中添加属性struct attm_desc_128 custs1_att_db[CUST1_IDX_NB] ={// CUSTOM1服务声明[CUST1_IDX_SVC] = {(uint8_t*)&att_decl_svc, ATT_UUID_16_LEN, PERM(RD, ENABLE),sizeof (custs1_svc), sizeof (custs1_svc), (uint8_t *) &custs1_svc},
//控制点特征声明[CUST1_IDX_CONTROL_POINT_CHAR] = {(uint8_t*)&att_decl_char, ATT_UUID_16_LEN, PERM(RD, ENABLE),sizeof (custs1_ctrl_point_char), sizeof (custs1_ctrl_point_char), (uint8_t *) &custs1_ctrl_point_char},
//控制点特征值[cust1_idx_control_point_val] = {cust1_ctrl_point_uuid_128, att_uuid_128_len, perm (wr, enable),DEF_CUST1_CTRL_POINT_CHAR_LEN 0零},
//控制点特征用户描述[CUST1_IDX_CONTROL_POINT_USER_DESC] = {(uint8_t*)&att_decl_user_desc, ATT_UUID_16_LEN, PERM(RD, ENABLE),CUST1_CONTROL_POINT_USER_DESC - 1, CUST1_CONTROL_POINT_USER_DESC},
// LED状态特性声明[CUST1_IDX_LED_STATE_CHAR] = {(uint8_t*)&att_decl_char, ATT_UUID_16_LEN, PERM(RD, ENABLE),sizeof (custs1_led_state_char), sizeof (custs1_led_state_char), (uint8_t *) &custs1_led_state_char},
// LED状态特征值[cust1_idx_led_state_val] = {cust1_led_state_uuid_128, att_uuid_128_len, perm (wr, enable),DEF_CUST1_LED_STATE_CHAR_LEN 0零},
// LED状态特征用户描述[CUST1_IDX_LED_STATE_USER_DESC] = {(uint8_t*)&att_decl_user_desc, ATT_UUID_16_LEN, PERM(RD, ENABLE),CUST1_LED_STATE_USER_DESC - 1, CUST1_LED_STATE_USER_DESC},
// ADC值1特征声明[CUST1_IDX_ADC_VAL_1_CHAR] = {(uint8_t*)&att_decl_char, ATT_UUID_16_LEN, PERM(RD, ENABLE),sizeof (custs1_adc_val_1_char), sizeof (custs1_adc_val_1_char), (uint8_t *) &custs1_adc_val_1_char},
// ADC值1特征值[cust1_idx_adc_val_1_val] = {cust1_adc_val_1_uuid_128,att_uuid_128_len,perm(rd,启用)|perm(ntf,启用),DEF_CUST1_ADC_VAL_1_CHAR_LEN 0零},
// ADC值1客户端特征配置描述符[CUST1_IDX_ADC_VAL_1_NTF_CFG] = {(uint8_t*)&att_decl_cfg, ATT_UUID_16_LEN, PERM(RD, ENABLE) | PERM(WR, ENABLE),sizeof (uint16_t), 0,零},
// ADC值1特征用户描述[CUST1_IDX_ADC_VAL_1_USER_DESC] = {(uint8_t*)&att_decl_user_desc, ATT_UUID_16_LEN, PERM(RD, ENABLE),1, CUST1_ADC_VAL_1_USER_DESC},
// ADC值2特征声明[CUST1_IDX_ADC_VAL_2_CHAR] = {(uint8_t*)&att_decl_char, ATT_UUID_16_LEN, PERM(RD, ENABLE),sizeof (custs1_adc_val_2_char), sizeof (custs1_adc_val_2_char), (uint8_t *) &custs1_adc_val_2_char},
// ADC值2特征值[cust1_idx_adc_val_2_val] = {cust1_adc_val_2_uuid_128, att_uuid_128_len, perm (rd, enable),DEF_CUST1_ADC_VAL_2_CHAR_LEN 0零},
// ADC值2特征用户描述[CUST1_IDX_ADC_VAL_2_USER_DESC] = {(uint8_t*)&att_decl_user_desc, ATT_UUID_16_LEN, PERM(RD, ENABLE),1, CUST1_ADC_VAL_2_USER_DESC, CUST1_ADC_VAL_2_USER_DESC,
//按钮状态特征声明[CUST1_IDX_BUTTON_STATE_CHAR] = {(uint8_t*)&att_decl_char, ATT_UUID_16_LEN, PERM(RD, ENABLE),sizeof (custs1_button_state_char), sizeof (custs1_button_state_char), (uint8_t *) &custs1_button_state_char},
//按钮状态特征值[cust1_idx_button_state_val] = {cust1_button_state_uuid_128, att_uuid_128_len, perm (rd, enable) | perm (ntf, enable),DEF_CUST1_BUTTON_STATE_CHAR_LEN 0零},
//按钮状态客户端特征配置描述符[CUST1_IDX_BUTTON_STATE_NTF_CFG] = {(uint8_t*)&att_decl_cfg, ATT_UUID_16_LEN, PERM(RD, ENABLE) | PERM(WR, ENABLE),sizeof (uint16_t), 0,零},
//按钮状态特征用户描述[CUST1_IDX_BUTTON_STATE_USER_DESC] = {(uint8_t*)&att_decl_user_desc, ATT_UUID_16_LEN, PERM(RD, ENABLE),(CUST1_BUTTON_STATE_USER_DESC) - 1, CUST1_BUTTON_STATE_USER_DESC,
//可指示性特征声明[CUST1_IDX_INDICATEABLE_CHAR] = {(uint8_t*)&att_decl_char, ATT_UUID_16_LEN, PERM(RD, ENABLE),sizeof (custs1_indicateable_char), sizeof (custs1_indicateable_char), (uint8_t *) &custs1_indicateable_char},
//可指示的特征值[cust1_idx_indicateable_val] = {cust1_indicateable_uuid_128, att_uuid_128_len, perm (rd, enable) | perm (ind, enable),DEF_CUST1_INDICATEABLE_CHAR_LEN 0零},
//可指示的客户端特征配置描述符[CUST1_IDX_INDICATEABLE_IND_CFG] = {(uint8_t*)&att_decl_cfg, ATT_UUID_16_LEN, PERM(RD, ENABLE) | PERM(WR, ENABLE),sizeof (uint16_t), 0,零},
//可指示的特征用户描述[CUST1_IDX_INDICATEABLE_USER_DESC] = {(uint8_t*)&att_decl_user_desc, ATT_UUID_16_LEN, PERM(RD, ENABLE),CUST1_INDICATEABLE_USER_DESC - 1, CUST1_INDICATEABLE_USER_DESC},
//长值特征声明[CUST1_IDX_LONG_VALUE_CHAR] = {(uint8_t*)&att_decl_char, ATT_UUID_16_LEN, PERM(RD, ENABLE),sizeof (custs1_long_value_char), sizeof (custs1_long_value_char), (uint8_t *) &custs1_long_value_char},
//长值特征值[cust1_idx_long_value_val] = {cust1_long_value_uuid_128, att_uuid_128_len, perm (rd, enable) | perm (wr, enable) | perm (ntf, enable),def_cust1_long_value_char_len,0,null},
//长值客户端特征配置描述符[CUST1_IDX_LONG_VALUE_NTF_CFG] = {(uint8_t*)&att_decl_cfg, ATT_UUID_16_LEN, PERM(RD, ENABLE) | PERM(WR, ENABLE),sizeof (uint16_t), 0,零},
// Long Value特征用户描述[CUST1_IDX_LONG_VALUE_USER_DESC] = {(uint8_t*)&att_decl_user_desc, ATT_UUID_16_LEN, PERM(RD, ENABLE),1, CUST1_LONG_VALUE_CHAR_USER_DESC, 1, CUST1_LONG_VALUE_CHAR_USER_DESC};
问候,
嗨,对话框的工程师,
只是一个小问题,发送ADC1到应用程序(信标),哪个参数我可以修改。
我正在从ADC读取温度,希望通过这个ADC服务在app(信标)上显示它。
嗨anghockleong50,
请查看一下SDk5.0.4的ble_app_peripheral示例,以及ADC值1特性是如何定义的。您应该遵循类似的实现。通过通知发送测量的ADC值的函数是app_adcval1_timer_cb_handler()回调。
谢谢,PM_Dialog
你好,
可以使用相同的数据结构定义16位UUID服务。使用"struct attm_desc_128"的原因是允许相同的数据结构同时覆盖16位和128位UUID元素。仔细查看CUSTOM1数据库的声明,您可以看到服务声明为16位UUID, LED状态特征声明为128位UUID。这个数据库混合包含16位和128位的UUID元素。您可以将此作为参考来创建自己的自定义配置文件。
///属性描述(用于创建数据库)
struct attm_desc_128
{
///元素UUID.
uint8_t * uuid;// <<<<< uuid数组
/ / / UUID的大小
uint8_t uuid_size;// <<<<<用于定义uuid长度,(ATT_UUID_128_LEN或ATT_UUID_16_LEN)
/ / /属性许可
uint16_t烫;
///元素的最大长度
att_size_t max_length;
///元素的当前长度
att_size_t长度;
///元素值数组
uint8_t *值;
};
/*---------------- 声明 -----------------*/
///主服务声明
ATT_DECL_PRIMARY_SERVICE = 0 x2800,
///二级服务声明
ATT_DECL_SECONDARY_SERVICE,
/ / /包括声明
ATT_DECL_INCLUDE,
/ / /声明特征
ATT_DECL_CHARACTERISTIC,
static uint16_t att_decl_svc = ATT_DECL_PRIMARY_SERVICE;
static uint16_t att_decl_char = ATT_DECL_CHARACTERISTIC;
#define DEF_CUST1_SVC_UUID_128 {0x2F、0x2A、0x93、0xA6、0xBD、0xD8、0x41、0x52、0xAC、0x0B、0x10、0x99、0x2E、0xC6、0xFE、0xED}
#define DEF_CUST1_CTRL_POINT_UUID_128 {0x20、0xEE、0x8D、0x0C、0xE1、0xF0、0x4A、0x0C、0xB3、0x25、0xDC、0x53、0x6A、0x68、0x86、0x2D}
#define DEF_CUST1_LED_STATE_UUID_128 {0x4F、0x43、0x31、0x3C、0x93、0x92、0x42、0xE6、0xA8、0x76、0xFA、0x3B、0xEF、0xB4、0x87、0x5A}
#define DEF_CUST1_ADC_VAL_1_UUID_128 {0x17、0xB9、0x67、0x98、0x4C、0x66、0x4C、0x01、0x96、0x33、0x31、0xB1、0x91、0x59、0x00、0x15}
#define DEF_CUST1_ADC_VAL_2_UUID_128 {0x23、0x68、0xEC、0x52、0x1E、0x62、0x44、0x74、0x9A、0x1B、0xD1、0x8B、0xAB、0x75、0xB6、0x6E}
#define DEF_CUST1_BUTTON_STATE_UUID_128 {0x9E, 0xE7, 0xBA, 0x08, 0xB9, 0xA9, 0x48, 0xAB, 0xA1, 0xAC, 0x03, 0x1C, 0x2E, 0x0D, 0x29, 0x6C}
#define def_cust1_indicateable_uuuid_128 {0x28,0xd5,0xe1,0xc1,0xe1,0xc5,0x47,0x29,0xb5,0x57,0x65,0xc3,0xba,0x47,0x15,0x9e}
定义DEF_CUST1_LONG_VALUE_UUID_128 {0x8C, 0x09, 0xE0, 0xD1, 0x81, 0x54, 0x42, 0x40, 0x8E, 0x4F, 0xD2, 0xB3, 0x77, 0xE3, 0x2A, 0x77}
#定义x0002 ATT_UUID_16_LEN 0
#define att_uuid_128_len 0x0010
//================================================================================================================
///完整CUSTOM1数据库描述-用于向数据库中添加属性
struct attm_desc_128 custs1_att_db[CUST1_IDX_NB] =
{
// CUSTOM1服务声明
[CUST1_IDX_SVC] = {(uint8_t*)&att_decl_svc, ATT_UUID_16_LEN, PERM(RD, ENABLE),
sizeof (custs1_svc), sizeof (custs1_svc), (uint8_t *) &custs1_svc},
//控制点特征声明
[CUST1_IDX_CONTROL_POINT_CHAR] = {(uint8_t*)&att_decl_char, ATT_UUID_16_LEN, PERM(RD, ENABLE),
sizeof (custs1_ctrl_point_char), sizeof (custs1_ctrl_point_char), (uint8_t *) &custs1_ctrl_point_char},
//控制点特征值
[cust1_idx_control_point_val] = {cust1_ctrl_point_uuid_128, att_uuid_128_len, perm (wr, enable),
DEF_CUST1_CTRL_POINT_CHAR_LEN 0零},
//控制点特征用户描述
[CUST1_IDX_CONTROL_POINT_USER_DESC] = {(uint8_t*)&att_decl_user_desc, ATT_UUID_16_LEN, PERM(RD, ENABLE),
CUST1_CONTROL_POINT_USER_DESC - 1, CUST1_CONTROL_POINT_USER_DESC},
// LED状态特性声明
[CUST1_IDX_LED_STATE_CHAR] = {(uint8_t*)&att_decl_char, ATT_UUID_16_LEN, PERM(RD, ENABLE),
sizeof (custs1_led_state_char), sizeof (custs1_led_state_char), (uint8_t *) &custs1_led_state_char},
// LED状态特征值
[cust1_idx_led_state_val] = {cust1_led_state_uuid_128, att_uuid_128_len, perm (wr, enable),
DEF_CUST1_LED_STATE_CHAR_LEN 0零},
// LED状态特征用户描述
[CUST1_IDX_LED_STATE_USER_DESC] = {(uint8_t*)&att_decl_user_desc, ATT_UUID_16_LEN, PERM(RD, ENABLE),
CUST1_LED_STATE_USER_DESC - 1, CUST1_LED_STATE_USER_DESC},
// ADC值1特征声明
[CUST1_IDX_ADC_VAL_1_CHAR] = {(uint8_t*)&att_decl_char, ATT_UUID_16_LEN, PERM(RD, ENABLE),
sizeof (custs1_adc_val_1_char), sizeof (custs1_adc_val_1_char), (uint8_t *) &custs1_adc_val_1_char},
// ADC值1特征值
[cust1_idx_adc_val_1_val] = {cust1_adc_val_1_uuid_128,att_uuid_128_len,perm(rd,启用)|perm(ntf,启用),
DEF_CUST1_ADC_VAL_1_CHAR_LEN 0零},
// ADC值1客户端特征配置描述符
[CUST1_IDX_ADC_VAL_1_NTF_CFG] = {(uint8_t*)&att_decl_cfg, ATT_UUID_16_LEN, PERM(RD, ENABLE) | PERM(WR, ENABLE),
sizeof (uint16_t), 0,零},
// ADC值1特征用户描述
[CUST1_IDX_ADC_VAL_1_USER_DESC] = {(uint8_t*)&att_decl_user_desc, ATT_UUID_16_LEN, PERM(RD, ENABLE),
1, CUST1_ADC_VAL_1_USER_DESC},
// ADC值2特征声明
[CUST1_IDX_ADC_VAL_2_CHAR] = {(uint8_t*)&att_decl_char, ATT_UUID_16_LEN, PERM(RD, ENABLE),
sizeof (custs1_adc_val_2_char), sizeof (custs1_adc_val_2_char), (uint8_t *) &custs1_adc_val_2_char},
// ADC值2特征值
[cust1_idx_adc_val_2_val] = {cust1_adc_val_2_uuid_128, att_uuid_128_len, perm (rd, enable),
DEF_CUST1_ADC_VAL_2_CHAR_LEN 0零},
// ADC值2特征用户描述
[CUST1_IDX_ADC_VAL_2_USER_DESC] = {(uint8_t*)&att_decl_user_desc, ATT_UUID_16_LEN, PERM(RD, ENABLE),
1, CUST1_ADC_VAL_2_USER_DESC, CUST1_ADC_VAL_2_USER_DESC,
//按钮状态特征声明
[CUST1_IDX_BUTTON_STATE_CHAR] = {(uint8_t*)&att_decl_char, ATT_UUID_16_LEN, PERM(RD, ENABLE),
sizeof (custs1_button_state_char), sizeof (custs1_button_state_char), (uint8_t *) &custs1_button_state_char},
//按钮状态特征值
[cust1_idx_button_state_val] = {cust1_button_state_uuid_128, att_uuid_128_len, perm (rd, enable) | perm (ntf, enable),
DEF_CUST1_BUTTON_STATE_CHAR_LEN 0零},
//按钮状态客户端特征配置描述符
[CUST1_IDX_BUTTON_STATE_NTF_CFG] = {(uint8_t*)&att_decl_cfg, ATT_UUID_16_LEN, PERM(RD, ENABLE) | PERM(WR, ENABLE),
sizeof (uint16_t), 0,零},
//按钮状态特征用户描述
[CUST1_IDX_BUTTON_STATE_USER_DESC] = {(uint8_t*)&att_decl_user_desc, ATT_UUID_16_LEN, PERM(RD, ENABLE),
(CUST1_BUTTON_STATE_USER_DESC) - 1, CUST1_BUTTON_STATE_USER_DESC,
//可指示性特征声明
[CUST1_IDX_INDICATEABLE_CHAR] = {(uint8_t*)&att_decl_char, ATT_UUID_16_LEN, PERM(RD, ENABLE),
sizeof (custs1_indicateable_char), sizeof (custs1_indicateable_char), (uint8_t *) &custs1_indicateable_char},
//可指示的特征值
[cust1_idx_indicateable_val] = {cust1_indicateable_uuid_128, att_uuid_128_len, perm (rd, enable) | perm (ind, enable),
DEF_CUST1_INDICATEABLE_CHAR_LEN 0零},
//可指示的客户端特征配置描述符
[CUST1_IDX_INDICATEABLE_IND_CFG] = {(uint8_t*)&att_decl_cfg, ATT_UUID_16_LEN, PERM(RD, ENABLE) | PERM(WR, ENABLE),
sizeof (uint16_t), 0,零},
//可指示的特征用户描述
[CUST1_IDX_INDICATEABLE_USER_DESC] = {(uint8_t*)&att_decl_user_desc, ATT_UUID_16_LEN, PERM(RD, ENABLE),
CUST1_INDICATEABLE_USER_DESC - 1, CUST1_INDICATEABLE_USER_DESC},
//长值特征声明
[CUST1_IDX_LONG_VALUE_CHAR] = {(uint8_t*)&att_decl_char, ATT_UUID_16_LEN, PERM(RD, ENABLE),
sizeof (custs1_long_value_char), sizeof (custs1_long_value_char), (uint8_t *) &custs1_long_value_char},
//长值特征值
[cust1_idx_long_value_val] = {cust1_long_value_uuid_128, att_uuid_128_len, perm (rd, enable) | perm (wr, enable) | perm (ntf, enable),
def_cust1_long_value_char_len,0,null},
//长值客户端特征配置描述符
[CUST1_IDX_LONG_VALUE_NTF_CFG] = {(uint8_t*)&att_decl_cfg, ATT_UUID_16_LEN, PERM(RD, ENABLE) | PERM(WR, ENABLE),
sizeof (uint16_t), 0,零},
// Long Value特征用户描述
[CUST1_IDX_LONG_VALUE_USER_DESC] = {(uint8_t*)&att_decl_user_desc, ATT_UUID_16_LEN, PERM(RD, ENABLE),
1, CUST1_LONG_VALUE_CHAR_USER_DESC, 1, CUST1_LONG_VALUE_CHAR_USER_DESC
};
问候,
嗨,对话框的工程师,
只是一个小问题,发送ADC1到应用程序(信标),哪个参数我可以修改。
我正在从ADC读取温度,希望通过这个ADC服务在app(信标)上显示它。
// ADC值1特征用户描述
[CUST1_IDX_ADC_VAL_1_USER_DESC] = {(uint8_t*)&att_decl_user_desc, ATT_UUID_16_LEN, PERM(RD, ENABLE),
1, CUST1_ADC_VAL_1_USER_DESC},
嗨anghockleong50,
请查看一下SDk5.0.4的ble_app_peripheral示例,以及ADC值1特性是如何定义的。您应该遵循类似的实现。通过通知发送测量的ADC值的函数是app_adcval1_timer_cb_handler()回调。
谢谢,PM_Dialog