fix memory issue with discovery characteristic
- when Number of found chars > Number of expected chars
This commit is contained in:
1 parent
e33fe9374c
commit
f7f4daa395
4 files changed
+17
-8
No files matched your search
@@ -36,8 +36,6 @@
|
||||
|
||||
#include "bluefruit.h"
|
||||
|
||||
#define MAX_DESCIRPTORS 8
|
||||
|
||||
void BLEClientCharacteristic::_init(void)
|
||||
{
|
||||
varclr(&_chr);
|
||||
@@ -122,6 +120,8 @@ BLEClientService& BLEClientCharacteristic::parentService (void)
|
||||
|
||||
bool BLEClientCharacteristic::discoverDescriptor(uint16_t conn_handle)
|
||||
{
|
||||
enum { MAX_DESCIRPTORS = 8 };
|
||||
|
||||
struct {
|
||||
uint16_t count;
|
||||
ble_gattc_desc_t descs[MAX_DESCIRPTORS];
|
||||
@@ -186,7 +186,7 @@ uint16_t BLEClientCharacteristic::write_resp(const void* data, uint16_t len)
|
||||
_adamsg.prepare( (void*) data, len);
|
||||
VERIFY_STATUS ( sd_ble_gattc_write(_service->connHandle(), ¶m) );
|
||||
|
||||
// len is alwasy 0 in BLE_GATTC_EVT_WRITE_RSP for BLE_GATT_OP_WRITE_REQ
|
||||
// len is always 0 in BLE_GATTC_EVT_WRITE_RSP for BLE_GATT_OP_WRITE_REQ
|
||||
count = (_adamsg.waitUntilComplete(BLE_GENERIC_TIMEOUT) < 0 ? 0 : len);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -91,6 +91,11 @@ uint16_t BLEClientService::connHandle(void)
|
||||
return _conn_hdl;
|
||||
}
|
||||
|
||||
void BLEClientService::setHandleRange(ble_gattc_handle_range_t handle_range)
|
||||
{
|
||||
_hdl_range = handle_range;
|
||||
}
|
||||
|
||||
void BLEClientService::setHandleRange(uint16_t start_hdl, uint16_t end_hdl)
|
||||
{
|
||||
_hdl_range.start_handle = start_hdl;
|
||||
|
||||
@@ -63,6 +63,7 @@ class BLEClientService
|
||||
|
||||
uint16_t connHandle(void);
|
||||
void setHandleRange(uint16_t start_hdl, uint16_t end_hdl);
|
||||
void setHandleRange(ble_gattc_handle_range_t handle_range);
|
||||
|
||||
friend class BLEGatt;
|
||||
};
|
||||
|
||||
@@ -88,9 +88,9 @@ bool BLEDiscovery::_discoverService(uint16_t conn_handle, BLEClientService& svc,
|
||||
if ( (disc_svc.count) && (svc.uuid == disc_svc.services[0].uuid) )
|
||||
{
|
||||
_hdl_range = disc_svc.services[0].handle_range;
|
||||
svc.setHandleRange(_hdl_range.start_handle, _hdl_range.end_handle);
|
||||
svc.setHandleRange(_hdl_range);
|
||||
|
||||
LOG_LV2(Discover, "[SVC] Found 0x%04X, Handle start = %d, end = %d", disc_svc.services[0].uuid.uuid, _hdl_range.start_handle, _hdl_range.end_handle);
|
||||
LOG_LV2(Discover, "[SVC] Found 0x%04X, Handle start = %d, end = %d\n-----------------", disc_svc.services[0].uuid.uuid, _hdl_range.start_handle, _hdl_range.end_handle);
|
||||
|
||||
// increase for next discovery
|
||||
_hdl_range.start_handle++;
|
||||
@@ -102,11 +102,14 @@ bool BLEDiscovery::_discoverService(uint16_t conn_handle, BLEClientService& svc,
|
||||
|
||||
uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLEClientCharacteristic* chr[], uint8_t count)
|
||||
{
|
||||
uint8_t found = 0;
|
||||
// We could found more characteristic than we looking for. Buffer must be large enough
|
||||
enum { MAX_DISC_CHARS = 4 };
|
||||
|
||||
uint16_t bufsize = sizeof(ble_gattc_evt_char_disc_rsp_t) + (count-1)*sizeof(ble_gattc_char_t);
|
||||
uint16_t bufsize = sizeof(ble_gattc_evt_char_disc_rsp_t) + (MAX_DISC_CHARS-1)*sizeof(ble_gattc_char_t);
|
||||
ble_gattc_evt_char_disc_rsp_t* disc_chr = (ble_gattc_evt_char_disc_rsp_t*) rtos_malloc( bufsize );
|
||||
|
||||
uint8_t found = 0;
|
||||
|
||||
while( found < count )
|
||||
{
|
||||
LOG_LV2(Discover, "[CHR] Handle start = %d, end = %d", _hdl_range.start_handle, _hdl_range.end_handle);
|
||||
@@ -129,7 +132,7 @@ uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLEClientChar
|
||||
{
|
||||
if ( chr[i]->uuid == disc_chr->chars[d].uuid )
|
||||
{
|
||||
LOG_LV2(Discover, "[CHR] Found 0x%04X, handle = %d", disc_chr->chars[d].uuid.uuid, disc_chr->chars[d].handle_value);
|
||||
LOG_LV2(Discover, "[CHR] Found 0x%04X, handle = %d\n-----------------", disc_chr->chars[d].uuid.uuid, disc_chr->chars[d].handle_value);
|
||||
|
||||
// characteristic assign overload
|
||||
chr[i]->assign(&disc_chr->chars[d]);
|
||||
|
||||
Reference in new issue
Block a user