complete BLEClientDis
This commit is contained in:
1 parent
fcddca77c5
commit
bd96f7df90
4 files changed
+45
-5
No files matched your search
@@ -13,8 +13,9 @@
|
||||
*********************************************************************/
|
||||
#include <bluefruit.h>
|
||||
|
||||
// BLE Service
|
||||
BLEAncs bleancs;
|
||||
// BLE Client Service
|
||||
BLEClientDis bleClientDis;
|
||||
BLEAncs bleancs;
|
||||
|
||||
char buffer[128];
|
||||
|
||||
@@ -41,7 +42,10 @@ void setup()
|
||||
Bluefruit.setConnectCallback(connect_callback);
|
||||
Bluefruit.setDisconnectCallback(disconnect_callback);
|
||||
|
||||
// Configure and Start Service
|
||||
// Configure DIS client
|
||||
bleClientDis.begin();
|
||||
|
||||
// Configure ANCS client
|
||||
bleancs.begin();
|
||||
bleancs.setNotificationCallback(ancs_notification_callback);
|
||||
|
||||
@@ -121,6 +125,20 @@ void ancs_notification_callback(AncsNotification_t* notif)
|
||||
void connect_callback(void)
|
||||
{
|
||||
Serial.println("Connected");
|
||||
|
||||
Serial.print("Dicovering DIS ... ");
|
||||
if ( bleClientDis.discover( Bluefruit.connHandle()) )
|
||||
{
|
||||
Serial.println("Found it");
|
||||
Serial.print("DIS Model: ");
|
||||
|
||||
// read and print out Model Number
|
||||
char buffer[32+1] = { 0 };
|
||||
if ( bleClientDis.getModel(buffer, sizeof(buffer)) )
|
||||
{
|
||||
Serial.println(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
Serial.print("Discovering ANCS ... ");
|
||||
if ( bleancs.discover( Bluefruit.connHandle() ) )
|
||||
|
||||
@@ -76,6 +76,8 @@ bool BLEDiscovery::_discoverService(uint16_t conn_handle, BLEClientService& svc,
|
||||
_evt_buf = &disc_svc;
|
||||
_evt_bufsize = sizeof(disc_svc);
|
||||
|
||||
LOG_LV2(Discover, "[SVC] Handle start = %d", start_handle);
|
||||
|
||||
VERIFY_STATUS( sd_ble_gattc_primary_services_discover(conn_handle, start_handle, &svc.uuid._uuid), false );
|
||||
|
||||
// wait for discovery event: timeout or has no data
|
||||
@@ -100,6 +102,7 @@ uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLEClientChar
|
||||
{
|
||||
uint8_t found = 0;
|
||||
|
||||
|
||||
while( found < count )
|
||||
{
|
||||
ble_gattc_evt_char_disc_rsp_t disc_chr;
|
||||
@@ -107,8 +110,7 @@ uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLEClientChar
|
||||
_evt_buf = &disc_chr;
|
||||
_evt_bufsize = sizeof(disc_chr);
|
||||
|
||||
// LOG_LV2(Discover, "[CHR] Handle start = %d, end = %d", _hdl_range.start_handle, _hdl_range.end_handle);
|
||||
|
||||
LOG_LV2(Discover, "[CHR] Handle start = %d, end = %d", _hdl_range.start_handle, _hdl_range.end_handle);
|
||||
VERIFY_STATUS( sd_ble_gattc_characteristics_discover(conn_handle, &_hdl_range), found );
|
||||
|
||||
// wait for discovery event: timeout or has no data
|
||||
|
||||
@@ -60,7 +60,25 @@ bool BLEClientDis::discover(uint16_t conn_handle)
|
||||
|
||||
uint16_t BLEClientDis::getChars(uint16_t uuid, char* buffer, uint16_t bufsize)
|
||||
{
|
||||
uint16_t count = 0;
|
||||
ble_gattc_handle_range_t bck_range = Bluefruit.Discovery.getHandleRange();
|
||||
|
||||
// Set discovery handle to DIS service
|
||||
Bluefruit.Discovery.setHandleRange(_hdl_range);
|
||||
|
||||
BLEClientCharacteristic chr(uuid);
|
||||
chr.begin(this);
|
||||
|
||||
if ( Bluefruit.Discovery.discoverCharacteristic(_conn_hdl, chr) )
|
||||
{
|
||||
count = chr.read(buffer, bufsize);
|
||||
PRINT_INT(count);
|
||||
}
|
||||
|
||||
// Set back
|
||||
Bluefruit.Discovery.setHandleRange(bck_range);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
uint16_t BLEClientDis::getModel(char* buffer, uint16_t bufsize)
|
||||
|
||||
@@ -58,6 +58,8 @@ class BLEClientDis : public BLEClientService
|
||||
private:
|
||||
uint16_t getChars(uint16_t uuid, char* buffer, uint16_t bufsize);
|
||||
|
||||
// BLE DIS has several characteristics but is often used one or two times
|
||||
// It is better to implement get() with on-the-fly BLEClientCharacteristic
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user