add hdl_range para to discoverDescriptor()
fix ancs descritpor discover issue
This commit is contained in:
1 parent
f7f4daa395
commit
121f73475a
5 files changed
+33
-24
No files matched your search
@@ -118,7 +118,7 @@ BLEClientService& BLEClientCharacteristic::parentService (void)
|
||||
return *_service;
|
||||
}
|
||||
|
||||
bool BLEClientCharacteristic::discoverDescriptor(uint16_t conn_handle)
|
||||
bool BLEClientCharacteristic::discoverDescriptor(uint16_t conn_handle, ble_gattc_handle_range_t hdl_range)
|
||||
{
|
||||
enum { MAX_DESCIRPTORS = 8 };
|
||||
|
||||
@@ -127,7 +127,7 @@ bool BLEClientCharacteristic::discoverDescriptor(uint16_t conn_handle)
|
||||
ble_gattc_desc_t descs[MAX_DESCIRPTORS];
|
||||
}disc_rsp;
|
||||
|
||||
uint16_t count = Bluefruit.Discovery._discoverDescriptor(conn_handle, (ble_gattc_evt_desc_disc_rsp_t*) &disc_rsp, sizeof(disc_rsp));
|
||||
uint16_t count = Bluefruit.Discovery._discoverDescriptor(conn_handle, (ble_gattc_evt_desc_disc_rsp_t*) &disc_rsp, sizeof(disc_rsp), hdl_range);
|
||||
|
||||
// only care CCCD for now
|
||||
for(uint16_t i=0; i<count; i++)
|
||||
|
||||
@@ -57,7 +57,7 @@ class BLEClientCharacteristic
|
||||
virtual ~BLEClientCharacteristic();
|
||||
|
||||
void assign(ble_gattc_char_t* gattc_chr);
|
||||
bool discoverDescriptor(uint16_t conn_handle);
|
||||
bool discoverDescriptor(uint16_t conn_handle, ble_gattc_handle_range_t hdl_range);
|
||||
|
||||
void begin(BLEClientService* parent_svc = NULL);
|
||||
|
||||
|
||||
@@ -137,12 +137,13 @@ uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLEClientChar
|
||||
// characteristic assign overload
|
||||
chr[i]->assign(&disc_chr->chars[d]);
|
||||
|
||||
// Discovery All descriptors as well
|
||||
_hdl_range.start_handle = disc_chr->chars[d].handle_value + 1;
|
||||
if (_hdl_range.start_handle < _hdl_range.end_handle )
|
||||
ble_gattc_handle_range_t range = { disc_chr->chars[d].handle_value + 1, _hdl_range.end_handle };
|
||||
|
||||
// Discovery All descriptors if possible
|
||||
if ( range.start_handle <= range.start_handle )
|
||||
{
|
||||
// skip discovery descriptor if it is last characteristic without descriptor
|
||||
chr[i]->discoverDescriptor(conn_handle);
|
||||
// skip discovery descriptor
|
||||
chr[i]->discoverDescriptor(conn_handle, range);
|
||||
}
|
||||
|
||||
found++;
|
||||
@@ -153,6 +154,10 @@ uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLEClientChar
|
||||
}
|
||||
|
||||
// increase handle range for next discovery
|
||||
// should be last descriptor +1, but that will cause missing on the next Characteristic !!!!!
|
||||
// Reason is descriptor also include BLE_UUID_CHARACTERISTIC 0x2803 (Char declaration) in the result
|
||||
//
|
||||
// To be safe we use last chars + 1
|
||||
_hdl_range.start_handle = disc_chr->chars[ disc_chr->count-1 ].handle_value + 1;
|
||||
}
|
||||
|
||||
@@ -161,13 +166,13 @@ uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLEClientChar
|
||||
return found;
|
||||
}
|
||||
|
||||
uint16_t BLEDiscovery::_discoverDescriptor(uint16_t conn_handle, ble_gattc_evt_desc_disc_rsp_t* disc_desc, uint16_t bufsize)
|
||||
uint16_t BLEDiscovery::_discoverDescriptor(uint16_t conn_handle, ble_gattc_evt_desc_disc_rsp_t* disc_desc, uint16_t bufsize, ble_gattc_handle_range_t hdl_range)
|
||||
{
|
||||
LOG_LV2(Discover, "[DESC] Handle start = %d, end = %d", _hdl_range.start_handle, _hdl_range.end_handle);
|
||||
LOG_LV2(Discover, "[DESC] Handle start = %d, end = %d", hdl_range.start_handle, hdl_range.end_handle);
|
||||
|
||||
_adamsg.prepare(disc_desc, bufsize);
|
||||
|
||||
VERIFY_STATUS( sd_ble_gattc_descriptors_discover(conn_handle, &_hdl_range), 0 );
|
||||
VERIFY_STATUS( sd_ble_gattc_descriptors_discover(conn_handle, &hdl_range), 0 );
|
||||
|
||||
// wait for discovery event
|
||||
int32_t bytecount = _adamsg.waitUntilComplete(BLE_DISCOVERY_TIMEOUT);
|
||||
@@ -180,11 +185,6 @@ uint16_t BLEDiscovery::_discoverDescriptor(uint16_t conn_handle, ble_gattc_evt_d
|
||||
LOG_LV2(Discover, "[DESC] Descriptor %d: uuid = 0x%04X, handle = %d", i, disc_desc->descs[i].uuid.uuid, disc_desc->descs[i].handle);
|
||||
}
|
||||
|
||||
// increase handle range for next discovery
|
||||
// should be +1 more, but that will cause missing on the next Characteristic !!!!!
|
||||
// Reason is descriptor also include BLE_UUID_CHARACTERISTIC 0x2803 (Char declaration) in the result
|
||||
_hdl_range.start_handle = disc_desc->descs[ disc_desc->count-1 ].handle;
|
||||
|
||||
return disc_desc->count;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ class BLEDiscovery
|
||||
* code. User should not call these directly
|
||||
*------------------------------------------------------------------*/
|
||||
bool _discoverService(uint16_t conn_handle, BLEClientService& svc, uint16_t start_handle = 1);
|
||||
uint16_t _discoverDescriptor(uint16_t conn_handle, ble_gattc_evt_desc_disc_rsp_t* disc_desc, uint16_t bufsize);
|
||||
uint16_t _discoverDescriptor(uint16_t conn_handle, ble_gattc_evt_desc_disc_rsp_t* disc_desc, uint16_t bufsize, ble_gattc_handle_range_t hdl_range);
|
||||
|
||||
friend class AdafruitBluefruit;
|
||||
};
|
||||
|
||||
@@ -38,12 +38,14 @@
|
||||
|
||||
#define BLE_ANCS_TIMEOUT (5*BLE_GENERIC_TIMEOUT)
|
||||
|
||||
#define DEBUG_ANCS 0
|
||||
|
||||
void bleancs_notification_cb(BLEClientCharacteristic& chr, uint8_t* data, uint16_t len);
|
||||
void bleancs_data_cb(BLEClientCharacteristic& chr, uint8_t* data, uint16_t len);
|
||||
|
||||
/* ANCS Service : 7905F431-B5CE-4E99-A40F-4B1E122D00D0
|
||||
* Notification Source : 9FBF120D-6301-42D9-8C58-25E699A21DBD
|
||||
* Control Point : 69D1D8F3-45E1-49A8-9821-9BBDFDAAD9D9
|
||||
* Notification Source : 9FBF120D-6301-42D9-8C58-25E699A21DBD
|
||||
* Data Source : 22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB
|
||||
*/
|
||||
|
||||
@@ -128,8 +130,8 @@ void BLEAncs::setNotificationCallback(notification_callback_t fp)
|
||||
bool BLEAncs::enableNotification(void)
|
||||
{
|
||||
// enable both Notification & Data Source
|
||||
_data.enableNotify();
|
||||
_notification.enableNotify();
|
||||
VERIFY ( _data.enableNotify() );
|
||||
VERIFY ( _notification.enableNotify() );
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -179,7 +181,7 @@ uint16_t BLEAncs::getAttribute(uint32_t uid, uint8_t attr, void* buffer, uint16_
|
||||
.cmd = ANCS_CMD_GET_NOTIFICATION_ATTR,
|
||||
.uid = uid,
|
||||
.attr = attr,
|
||||
.len = bufsize
|
||||
.len = bufsize
|
||||
};
|
||||
uint8_t cmdlen = 6;
|
||||
|
||||
@@ -190,7 +192,10 @@ uint16_t BLEAncs::getAttribute(uint32_t uid, uint8_t attr, void* buffer, uint16_
|
||||
}
|
||||
|
||||
// Write command using write response
|
||||
// PRINT_BUFFER(&command, cmdlen);
|
||||
#if DEBUG_ANCS
|
||||
PRINT_BUFFER(&command, cmdlen);
|
||||
#endif
|
||||
|
||||
_adamsg.prepare(buffer, bufsize);
|
||||
VERIFY( cmdlen == _control.write_resp(&command, cmdlen), 0);
|
||||
VERIFY( _adamsg.waitUntilComplete(BLE_ANCS_TIMEOUT) >= 0, 0);
|
||||
@@ -233,7 +238,9 @@ uint16_t BLEAncs::getAppAttribute(const char* appid, uint8_t attr, void* buffer,
|
||||
strcpy( (char*) command+1, appid);
|
||||
command[cmdlen-1] = attr;
|
||||
|
||||
// PRINT_BUFFER(command, cmdlen);
|
||||
#if DEBUG_ANCS
|
||||
PRINT_BUFFER(command, cmdlen);
|
||||
#endif
|
||||
_adamsg.prepare(buffer, bufsize);
|
||||
|
||||
// Write command using write response
|
||||
@@ -297,7 +304,9 @@ void BLEAncs::_handleNotification(uint8_t* data, uint16_t len)
|
||||
|
||||
void BLEAncs::_handleData(uint8_t* data, uint16_t len)
|
||||
{
|
||||
//PRINT_BUFFER(data, len);
|
||||
#if DEBUG_ANCS
|
||||
PRINT_BUFFER(data, len);
|
||||
#endif
|
||||
|
||||
_adamsg.feed(data, len);
|
||||
_adamsg.complete(); // mark as complete each time we received data
|
||||
|
||||
Reference in new issue
Block a user