BLE配置文件帮助

⚠️
大家好. .谢谢你来到论坛。令人兴奋的消息!我们现在正在转移到新的论坛平台,它将提供更好的功能,包含在主对话网站中。所有岗位和账户都已迁移。我们现在只接受新论坛的流量-请在上面发布任何新帖子//www.wsdof.com/support.我们将在未来几天修复bug /优化搜索和标记。
5个职位/ 0个新
最后发表
匿名(未验证)
BLE配置文件帮助

你好,

我试图创建一个BLE配置文件发送传感器数据通过BLE链接。你能给我指个方向,让我找到这个例子吗?是否有一个文档,我可以阅读实现自定义配置文件?

问候

设备:
JK_Dialog
离线
最后看到:两个月三个星期前
工作人员
加入:2016-08-22 23:07
你好,穆

你好,穆

最终,我们将有一个应用程序注释来描述这个过程——但同时,您可以使用位于演示中的ble_peripheral来开始您的工作或pxp reporter。至于客户服务,在SDK 1.0.8中,你可以引用位于ble_services文件夹中的我们的串口服务(sps.c)。SPS是一个自定义服务,它使用sdk api的构造来创建自定义服务。按照SDK的流程,在应用层,使用以下两行来初始化服务:

ble_service_t * svc;

SVC = my_service_init(回调cb);
ble_service_add (svc);

----------------------------------------------------

然后,您可以从init函数——从sps_init函数——中遵循其他服务的流程:

ble_service_t * sps_init (sps_callbacks_t * cb)

Uint16_t num_attr, sps_tx_desc_h, sps_rx_desc_h, sps_flow_ctrl_desc_h;
sp_service_t * sps;
att_uuid_t uuid;

sps = OS_MALLOC (sizeof (* sps));
memset (sps 0 sizeof (sps));

Num_attr = ble_gatts_get_num_attr(0, 3, 5);

ble_uuid_from_string (UUID_SPS uuid);
ble_gatts_add_service (uuid, GATT_SERVICE_PRIMARY num_attr);

/* SPS服务器TX */
ble_uuid_from_string (UUID_SPS_SERVER_TX uuid);
ble_gatts_add_characteristic (uuid, GATT_PROP_NOTIFY ATT_PERM_NONE,
sps_server_tx_size, 0, NULL, &sps->sps_tx_val_h);

ble_uuid_create16 (UUID_GATT_CLIENT_CHAR_CONFIGURATION uuid);
ble_gatts_add_descriptor(&uuid, ATT_PERM_RW, 2, 0, &sps->sps_tx_ccc_h);

ble_uuid_create16 (UUID_GATT_CHAR_USER_DESCRIPTION uuid);
ble_gatts_add_descriptor(&uuid, ATT_PERM_READ, sizeof(sps_tx_desc), 0, &sps_tx_desc_h);

/* SPS Server RX */
ble_uuid_from_string (UUID_SPS_SERVER_RX uuid);
ble_gatts_add_characteristic (uuid, GATT_PROP_WRITE_NO_RESP ATT_PERM_WRITE,
sps_server_rx_size, 0, NULL, & sps_rx_val_h);

ble_uuid_create16 (UUID_GATT_CHAR_USER_DESCRIPTION uuid);
ble_gatts_add_descriptor(&uuid, ATT_PERM_READ, sizeof(sps_rx_desc), 0, &sps_rx_desc_h);

/* SPS Flow Control */
ble_uuid_from_string (UUID_SPS_FLOW_CTRL uuid);
ble_gatts_add_characteristic(&uuid, GATT_PROP_WRITE_NO_RESP | GATT_PROP_NOTIFY, ATT_PERM_WRITE,
1, 0, NULL, & sps_flow_ctrl_val_h);

ble_uuid_create16 (UUID_GATT_CLIENT_CHAR_CONFIGURATION uuid);
ble_gatts_add_descriptor(&uuid, ATT_PERM_RW, 2,0, &sps->sps_flow_ctrl_ccc_h);

ble_uuid_create16 (UUID_GATT_CHAR_USER_DESCRIPTION uuid);
ble_gatts_add_descriptor(&uuid, ATT_PERM_READ, sizeof(sps_flow_control_desc), 0, &sps_flow_ctrl_desc_h);

/*注册SPS服务*/
ble_gatts_register_service (sps - > svc。start_h sps - > sps_tx_val_h sps - > sps_tx_ccc_h,
&sps_tx_desc_h sps - > sps_rx_val_h &sps_rx_desc_h,
sps - > sps_flow_ctrl_val_h sps - > sps_flow_ctrl_ccc_h,
&sps_flow_ctrl_desc_h, 0);

/*设置特征描述值*/
ble_gatts_set_value (sps_tx_desc_h sizeof (sps_tx_desc) sps_tx_desc);
ble_gatts_set_value (sps_rx_desc_h sizeof (sps_rx_desc) sps_rx_desc);
ble_gatts_set_value (sps_flow_ctrl_desc_h sizeof (sps_flow_control_desc),
sps_flow_control_desc);

sps - > svc。end_h = sps - > svc。start_h + num_attr;
sps - > svc。write_req = handle_write_req;
sps - > svc。read_req = handle_read_req;
sps - > svc。event_sent = handle_event_sent;
sps - > cb = cb;

返回sps - > svc;

穆(未验证)
谢谢你的大力支持

感谢您的回复,非常感谢。回到ble_peripheral,我如何修改my_service有一个可读的数据值,我可以定期更新。

JK_Dialog
离线
最后看到:两个月三个星期前
工作人员
加入:2016-08-22 23:07
同样,请参考sps.c

同样,请参考sps.c(或任何其他ble配置文件)以获得示例。my_service_init现在什么也不做,但是可以进行修改。您可以将该特征更改为GATT_PROP_READ,然后注册一个读回调。注册读回调在sps.c的第287行中有说明,设置值也有说明。

/*设置特征描述值*/
ble_gatts_set_value (sps_tx_desc_h sizeof (sps_tx_desc) sps_tx_desc);
ble_gatts_set_value (sps_rx_desc_h sizeof (sps_rx_desc) sps_rx_desc);
ble_gatts_set_value (sps_flow_ctrl_desc_h sizeof (sps_flow_control_desc),
sps_flow_control_desc);

sps - > svc。end_h = sps - > svc。start_h + num_attr;
sps - > svc。write_req = handle_write_req;
sps - > svc。read_req = handle_read_req;
sps - > svc。event_sent = handle_event_sent;
sps - > cb = cb;

返回sps - > svc;

穆(未验证)
谢谢真的帮了

谢谢真的帮了