add ble_gattc_handle_range_t to clientService

This commit is contained in:
hathach committed 2017-04-13 15:42:58 +07:00
1 parent 08187e3c15
commit cece1ef746
5 files changed
+48

No files matched your search

@@ -42,6 +42,9 @@ BLEClientService* BLEClientService::lastService = NULL;
void BLEClientService::_init(void)
{
_conn_hdl = BLE_CONN_HANDLE_INVALID;
_hdl_range.start_handle = 1;
_hdl_range.end_handle = 0xffff;
}
BLEClientService::BLEClientService(void)
@@ -85,6 +88,12 @@ uint16_t BLEClientService::connHandle(void)
return _conn_hdl;
}
void BLEClientService::setHandleRange(uint16_t start_hdl, uint16_t end_hdl)
{
_hdl_range.start_handle = start_hdl;
_hdl_range.end_handle = end_hdl;
}
void BLEClientService::disconnect(void)
{
_conn_hdl = BLE_CONN_HANDLE_INVALID;
@@ -43,6 +43,7 @@ class BLEClientService
{
protected:
uint16_t _conn_hdl;
ble_gattc_handle_range_t _hdl_range;
void _init(void);
virtual void disconnect(void);
@@ -61,6 +62,7 @@ class BLEClientService
bool discovered(void);
uint16_t connHandle(void);
void setHandleRange(uint16_t start_hdl, uint16_t end_hdl);
friend class BLEGatt;
};
@@ -75,6 +75,8 @@ bool BLEDiscovery::_discoverService(uint16_t conn_handle, BLEClientService& svc,
if ( (disc_svc.count == 1) && (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);
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);
_hdl_range.start_handle++; // increase for characteristic discovery
+31
View File
@@ -38,11 +38,27 @@
BLEGatt::BLEGatt(void)
//: _adamsg()
{
varclr(&_server);
varclr(&_client);
}
uint16_t BLEGatt::readCharByUuid(uint16_t conn_hdl, BLEUuid bleuuid, void* buffer, uint16_t bufsize, uint16_t start_hdl, uint16_t end_hdl)
{
#if 0
ble_gattc_handle_range_t hdl_range = { .start_handle = start_hdl, .end_handle = end_hdl };
_adamsg.prepare(buffer, bufsize);
VERIFY_STATUS( sd_ble_gattc_char_value_by_uuid_read(conn_hdl, &bleuuid._uuid, &hdl_range), 0);
int32_t count = _adamsg.waitUntilComplete(BLE_GENERIC_TIMEOUT);
return (count < 0) ? 0 : count;
#endif
return 0;
}
void BLEGatt::_eventHandler(ble_evt_t* evt)
{
// Server Characteristics
@@ -77,6 +93,21 @@ void BLEGatt::_eventHandler(ble_evt_t* evt)
{
for(int i=0; i<_client.svc_count; i++) _client.svc_list[i]->disconnect();
}
#if 0
// GATTC Read Characteristic by UUID procedure
if ( evt->header.evt_id == BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP )
{
ble_gattc_evt_char_val_by_uuid_read_rsp_t* rd_rsp = &evt->evt.gattc_evt.params.char_val_by_uuid_read_rsp;
PRINT_INT(rd_rsp->count);
PRINT_INT(rd_rsp->value_len);
if (rd_rsp->count)
{
_adamsg.feed(rd_rsp->handle_value[0].p_value, rd_rsp->value_len)
}
}
#endif
}
bool BLEGatt::_addCharacteristic(BLECharacteristic* chr)
+4
View File
@@ -57,6 +57,8 @@ class BLEGatt
public:
BLEGatt(void);
uint16_t readCharByUuid(uint16_t conn_hdl, BLEUuid bleuuid, void* buffer, uint16_t bufsize, uint16_t start_hdl = 1, uint16_t end_hdl = 0xffff);
/*------------------------------------------------------------------*/
/* INTERNAL USAGE ONLY
* Although declare as public, it is meant to be invoked by internal
@@ -84,6 +86,8 @@ class BLEGatt
uint8_t chr_count;
BLEClientCharacteristic* chr_list[BLE_GATT_MAX_CLIENT_CHARS];
}_client;
// AdaMsg _adamsg;
};
#endif /* BLEGATT_H_ */