我在GATT客户端(笔记本电脑)上使用bluez
,在GATT服务器(TI基于CC2541的PCB)上使用TI的SimpleBLEPeripheral代码。 PCB的UUID是:
0000fff0-0000-1000-8000-00805f9b34fb
使用bluez
,我有以下
static GAttrib *attrib = NULL;
...
static void cmd_primary(int argcp, char **argvp)
{
bt_uuid_t uuid;
if (conn_state != STATE_CONNECTED) {
resp_error(err_BAD_STATE);
return;
}
if (argcp == 1) {
gatt_discover_primary(attrib, NULL, primary_all_cb, NULL);
return;
}
if (bt_string_to_uuid(&uuid, argvp[1]) < 0) {
resp_error(err_BAD_PARAM);
return;
}
gatt_discover_primary(attrib, &uuid, primary_by_uuid_cb, NULL);
}
static void primary_by_uuid_cb(uint8_t status, GSList *ranges, void *user_data)
{
GSList *l;
if (status) {
resp_error(err_COMM_ERR); // Todo: status
return;
}
resp_begin(rsp_DISCOVERY);
for (l = ranges; l; l = l->next) {
struct att_range *range = l->data;
send_uint(tag_RANGE_START, range->start);
send_uint(tag_RANGE_END, range->end);
}
resp_end();
}
成功连接到PCB后,运行cmd_primary(2, (char* []){"svcs", "0000fff0-0000-1000-0000-000000000000"}
会导致回调primary_by_uuid_cb()
被调用,参数ranges
为NULL
。如果服务得到识别,ranges
不应该NULL
- 是否正确?
如果是这种情况,是否有人知道为什么找不到该服务(或ranges
为什么NULL
,如果它不应该?)
任何帮助将不胜感激。