嗨对话框
我在基于DA14681的自定义板上工作,我使用pxp报告器作为一个基础项目,并通过BLE发送数据,使自定义服务可通知。到目前为止,一切都很顺利。现在我想发送超过1字节,例如我想发送10或20字节的特征,但我不能这样做。
这里是服务代码,但它是为单字节的数据传输工作。如何我可以修改它发送20字节或有任何例子代码,可以帮助我在这方面。谢谢
typedef struct {
ble_service_t svc;
/ /处理
uint16_t templ_val_h;
uint16_t templ_ccc_h;
} mmtn_service_t;
Static void handle_read_req(ble_service_t *svc, const ble_evt_gatts_read_req_t *evt)
{
Mmtn_service_t *mmtn = (Mmtn_service_t *) svc;
If (evt->句柄== mmtn->templ_ccc_h)
{
UINT16_T CCC = 0x0000;
ble_storage_get_u16 (evt - > conn_idx mmtn - > templ_ccc_h, ccc);
//我们很少 - endian,好的,直接从uint16_t写
ble_gatts_read_cfm(evt->conn_idx, evt->句柄,ATT_ERROR_OK, sizeof(ccc), &ccc);
其他}
{
Int8_t temp_level = 0;
/*默认警告级别- 'No alert ' */
/ / pm_stay_alive ();
temp_level = get_thermistor_temperature (TEMP_IN_C 0);// 0 -> th4
/ / test_temp_counter + +;
bl_gatts_read_cfm (evt->conn_idx, evt->句柄,ATT_ERROR_OK, sizeof(temp_level), &temp_level);
/ / pm_resume_sleep ();
}
}
bl_service_t *mmtn_init(const bl_service_config_t *config, const mm_tempsense_info_t *info)
{
uint16_t num_descr;
uint16_t num_attr;
Uint16_t cpf_h = 0;
mmtn_service_t * mmtn;
att_uuid_t uuid;
Int8_t level = 0;
mmtn = OS_MALLOC (sizeof (* mmtn));
memset (mmtn 0 sizeof (* mmtn));
mmtn - > svc。connected_evt = handle_connected_evt;
mmtn - > svc。read_req = handle_read_req;
mmtn - > svc。write_req = handle_write_req;
//如果设置为“info”,则内容呈现格式描述符
Num_descr = (info ?2: 1);
Num_attr = ble_service_get_num_attr(config, 1, num_descr);
ble_uuid_from_string (UUID_MMTN uuid);
ble_gatts_add_service (uuid, GATT_SERVICE_PRIMARY num_attr);
ble_service_config_add_includes(配置);
ble_uuid_from_string (UUID_MMTN_TEMPRATURE_LEVEL uuid);
blatts_add_characteristic (&uuid, GATT_PROP_READ | GATT_PROP_NOTIFY,
ble_service_config_elevate_perm (ATT_PERM_READ配置),
1, 0, NULL, &mmtn->templ_val_h);
ble_uuid_create16 (UUID_GATT_CLIENT_CHAR_CONFIGURATION uuid);
bl_gatts_add_descriptor (&uuid, ATT_PERM_RW, 1,0, &mmtn->templ_ccc_h);
如果(信息){
ble_uuid_create16 (UUID_GATT_CHAR_PRESENTATION_FORMAT uuid);
ble_gatts_add_descriptor (uuid,
ble_service_config_elevate_perm (ATT_PERM_READ配置),
7 0 &cpf_h);
}
ble_gatts_register_service (&mmtn - > svc。start_h &mmtn - > templ_val_h &mmtn - > templ_ccc_h, &cpf_h, 0);
/*设置初始值的电池水平,以便我们总是有适当的特征值设置。*/
ble_gatts_set_value (mmtn - > templ_val_h sizeof (
bl_service_t *mmtn_init(const bl_service_config_t *config, const mm_tempsense_info_t *info)
{
uint16_t num_descr;
uint16_t num_attr;
Uint16_t cpf_h = 0;
mmtn_service_t * mmtn;
att_uuid_t uuid;
Int8_t level = 0;
mmtn = OS_MALLOC (sizeof (* mmtn));
memset (mmtn 0 sizeof (* mmtn));
mmtn - > svc。connected_evt = handle_connected_evt;
mmtn - > svc。read_req = handle_read_req;
mmtn - > svc。write_req = handle_write_req;
//如果设置为“info”,则内容呈现格式描述符
Num_descr = (info ?2: 1);
Num_attr = ble_service_get_num_attr(config, 1, num_descr);
ble_uuid_from_string (UUID_MMTN uuid);
ble_gatts_add_service (uuid, GATT_SERVICE_PRIMARY num_attr);
ble_service_config_add_includes(配置);
ble_uuid_from_string (UUID_MMTN_TEMPRATURE_LEVEL uuid);
blatts_add_characteristic (&uuid, GATT_PROP_READ | GATT_PROP_NOTIFY,
ble_service_config_elevate_perm (ATT_PERM_READ配置),
1, 0, NULL, &mmtn->templ_val_h);
ble_uuid_create16 (UUID_GATT_CLIENT_CHAR_CONFIGURATION uuid);
bl_gatts_add_descriptor (&uuid, ATT_PERM_RW, 1,0, &mmtn->templ_ccc_h);
如果(信息){
ble_uuid_create16 (UUID_GATT_CHAR_PRESENTATION_FORMAT uuid);
ble_gatts_add_descriptor (uuid,
ble_service_config_elevate_perm (ATT_PERM_READ配置),
7 0 &cpf_h);
}
ble_gatts_register_service (&mmtn - > svc。start_h &mmtn - > templ_val_h &mmtn - > templ_ccc_h, &cpf_h, 0);
/*设置初始值的电池水平,以便我们总是有适当的特征值设置。*/
bl_gatts_set_value (mmtn->templ_val_h, sizeof(temp_level), &temp_level);
如果(信息){
uint8_t cpf_val [7];
Uint8_t *p = cpf_val;
put_u8_inc(拟定,0 x04);//格式=无符号8位整数
0 x00 put_u8_inc(拟定);/ /指数= 0
put_u16_inc(拟定,0 x27ad);/ /单位=百分比
put_u8_inc(拟定信息- >名称空间);
put_u16_inc(&p,信息 - >描述符);
//内容表示格式描述符具有静态值
ble_gatts_set_value (cpf_h sizeof (cpf_val) cpf_val);
}
mmtn - > svc。end_h = mmtn - > svc。start_h + num_attr;
返回&mmtn - > svc;
}
)、数组);
如果(信息){
uint8_t cpf_val [7];
Uint8_t *p = cpf_val;
put_u8_inc(拟定,0 x04);//格式=无符号8位整数
0 x00 put_u8_inc(拟定);/ /指数= 0
put_u16_inc(拟定,0 x27ad);/ /单位=百分比
put_u8_inc(拟定信息- >名称空间);
put_u16_inc(&p,信息 - >描述符);
//内容表示格式描述符具有静态值
ble_gatts_set_value (cpf_h sizeof (cpf_val) cpf_val);
}
mmtn - > svc。end_h = mmtn - > svc。start_h + num_attr;
返回&mmtn - > svc;
}
Static void notify_level(ble_service_t *svc, uint16_t conn_idx, int8_t level)
{
Mmtn_service_t *mmtn = (Mmtn_service_t *) svc;
UINT16_T CCC = 0x0000;
ble_storage_get_u16 (conn_idx mmtn - > templ_ccc_h, ccc);
如果(!(ccc & GATT_CCC_NOTIFICATIONS)) {
返回;
}
ble_gatts_send_event(conn_idx, mmtn->templ_val_h, GATT_EVENT_NOTIFICATION, sizeof(level), &level);
}
嗨mahmed106,
谢谢你的建议。我浏览了您提供的代码片段,发现特征值的最大长度是1字节。ble_gatts_add_characteristic()的max_len参数被设置为1,这意味着最大长度是1个字节。你能换一下吗?
谢谢,PM_Dialog