Skip to content

Commit 226c99a

Browse files
committed
implement #41
read peer Gap Device Name
1 parent 6053993 commit 226c99a

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

libraries/Bluefruit52Lib/src/BLEGap.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ bool BLEGap::getTxPacket(uint16_t conn_handle)
5353
return xSemaphoreTake(_txpacket_sem[conn_handle], ms2tick(BLE_GENERIC_TIMEOUT));
5454
}
5555

56+
uint16_t BLEGap::getPeerDevName(char* buf, uint16_t bufsize)
57+
{
58+
return getPeerDevName(Bluefruit.connHandle(), buf, bufsize);
59+
}
60+
61+
uint16_t BLEGap::getPeerDevName(uint16_t conn_handle, char* buf, uint16_t bufsize)
62+
{
63+
return Bluefruit.Gatt.readCharByUuid(conn_handle, BLEUuid(BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME), buf, bufsize);
64+
}
65+
5666
void BLEGap::_eventHandler(ble_evt_t* evt)
5767
{
5868
// conn handle has fixed offset regardless of event type

libraries/Bluefruit52Lib/src/BLEGap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class BLEGap
5050
bool getTxPacket(void);
5151
bool getTxPacket(uint16_t conn_handle);
5252

53+
uint16_t getPeerDevName(char* buf, uint16_t bufsize);
54+
uint16_t getPeerDevName(uint16_t conn_handle, char* buf, uint16_t bufsize);
55+
5356
/*------------------------------------------------------------------*/
5457
/* INTERNAL USAGE ONLY
5558
* Although declare as public, it is meant to be invoked by internal

libraries/Bluefruit52Lib/src/BLEGatt.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,28 @@
3838

3939

4040
BLEGatt::BLEGatt(void)
41-
//: _adamsg()
41+
: _adamsg()
4242
{
4343
varclr(&_server);
4444
varclr(&_client);
4545
}
4646

4747
uint16_t BLEGatt::readCharByUuid(uint16_t conn_hdl, BLEUuid bleuuid, void* buffer, uint16_t bufsize, uint16_t start_hdl, uint16_t end_hdl)
4848
{
49-
#if 0
49+
int32_t count = 0;
5050
ble_gattc_handle_range_t hdl_range = { .start_handle = start_hdl, .end_handle = end_hdl };
5151

52+
_adamsg.begin(true);
5253
_adamsg.prepare(buffer, bufsize);
53-
VERIFY_STATUS( sd_ble_gattc_char_value_by_uuid_read(conn_hdl, &bleuuid._uuid, &hdl_range), 0);
5454

55-
int32_t count = _adamsg.waitUntilComplete(BLE_GENERIC_TIMEOUT);
56-
return (count < 0) ? 0 : count;
57-
#endif
55+
if( NRF_SUCCESS == sd_ble_gattc_char_value_by_uuid_read(conn_hdl, &bleuuid._uuid, &hdl_range) )
56+
{
57+
count = _adamsg.waitUntilComplete(BLE_GENERIC_TIMEOUT);
58+
}
5859

59-
return 0;
60+
_adamsg.stop();
61+
62+
return (count < 0) ? 0 : count;
6063
}
6164

6265
void BLEGatt::_eventHandler(ble_evt_t* evt)
@@ -94,7 +97,6 @@ void BLEGatt::_eventHandler(ble_evt_t* evt)
9497
for(int i=0; i<_client.svc_count; i++) _client.svc_list[i]->disconnect();
9598
}
9699

97-
#if 0
98100
// GATTC Read Characteristic by UUID procedure
99101
if ( evt->header.evt_id == BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP )
100102
{
@@ -104,10 +106,10 @@ void BLEGatt::_eventHandler(ble_evt_t* evt)
104106
PRINT_INT(rd_rsp->value_len);
105107
if (rd_rsp->count)
106108
{
107-
_adamsg.feed(rd_rsp->handle_value[0].p_value, rd_rsp->value_len)
109+
_adamsg.feed(rd_rsp->handle_value[0].p_value, rd_rsp->value_len);
110+
_adamsg.complete();
108111
}
109112
}
110-
#endif
111113
}
112114

113115
/*------------------------------------------------------------------*/

libraries/Bluefruit52Lib/src/BLEGatt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class BLEGatt
8989
BLEClientCharacteristic* chr_list[BLE_GATT_MAX_CLIENT_CHARS];
9090
}_client;
9191

92-
// AdaMsg _adamsg;
92+
AdaMsg _adamsg;
9393
};
9494

9595
#endif /* BLEGATT_H_ */

0 commit comments

Comments
 (0)