add Central's service list
change central service begin()'s return type to bool
This commit is contained in:
1 parent
0beff63269
commit
dade06c68a
6 files changed
+31
-10
No files matched your search
@@ -51,6 +51,9 @@ BLECentral::BLECentral(void)
|
||||
|
||||
_txpacket_sem = NULL;
|
||||
|
||||
_svc_count = 0;
|
||||
for(uint8_t i=0; i<BLE_CENTRAL_MAX_SERVICE; i++) _svc_list[i] = NULL;
|
||||
|
||||
_chars_count = 0;
|
||||
for(uint8_t i=0; i<BLE_CENTRAL_MAX_CHARS; i++) _chars_list[i] = NULL;
|
||||
|
||||
@@ -76,9 +79,17 @@ void BLECentral::begin(void)
|
||||
_evt_sem = xSemaphoreCreateBinary();
|
||||
}
|
||||
|
||||
bool BLECentral::_registerService(BLECentralService* svc)
|
||||
{
|
||||
VERIFY( _svc_count < BLE_CENTRAL_MAX_SERVICE );
|
||||
_svc_list[ _svc_count++ ] = svc;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BLECentral::_registerCharacteristic(BLECentralCharacteristic* chr)
|
||||
{
|
||||
if ( _chars_count == BLE_CENTRAL_MAX_CHARS ) return false;
|
||||
VERIFY( _chars_count < BLE_CENTRAL_MAX_CHARS );
|
||||
_chars_list[ _chars_count++ ] = chr;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -46,7 +46,8 @@
|
||||
#include "BLECentralCharacteristic.h"
|
||||
#include "BLECentralService.h"
|
||||
|
||||
#define BLE_CENTRAL_MAX_CHARS 20
|
||||
#define BLE_CENTRAL_MAX_SERVICE 10
|
||||
#define BLE_CENTRAL_MAX_CHARS 30
|
||||
|
||||
|
||||
class AdafruitBluefruit;
|
||||
@@ -107,9 +108,11 @@ class BLECentral
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* INTERNAL USAGE ONLY
|
||||
* Although declare as public, it is meant to be invoked by internal
|
||||
* code. User should not call these directly
|
||||
*------------------------------------------------------------------*/
|
||||
// Called by discoverCharacteristic(), user should not call this directly
|
||||
uint16_t _discoverDescriptor(ble_gattc_evt_desc_disc_rsp_t* disc_desc, uint16_t max_count);
|
||||
bool _registerService(BLECentralService* svc);
|
||||
bool _registerCharacteristic(BLECentralCharacteristic* chr);
|
||||
|
||||
private:
|
||||
@@ -122,6 +125,9 @@ class BLECentral
|
||||
// Transmission Buffer Count for HVX notification, max is seen at 7
|
||||
SemaphoreHandle_t _txpacket_sem;
|
||||
|
||||
BLECentralService* _svc_list[BLE_CENTRAL_MAX_SERVICE];
|
||||
uint8_t _svc_count;
|
||||
|
||||
BLECentralCharacteristic* _chars_list[BLE_CENTRAL_MAX_CHARS];
|
||||
uint8_t _chars_count;
|
||||
|
||||
|
||||
@@ -57,14 +57,15 @@ BLECentralService::BLECentralService(BLEUuid bleuuid)
|
||||
}
|
||||
|
||||
|
||||
err_t BLECentralService::begin(void)
|
||||
bool BLECentralService::begin(void)
|
||||
{
|
||||
// Add UUID128 if needed
|
||||
uuid.begin();
|
||||
|
||||
lastService = this;
|
||||
(void) Bluefruit.Central._registerService(this);
|
||||
|
||||
return ERROR_NONE;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BLECentralService::discover(void)
|
||||
@@ -81,5 +82,6 @@ bool BLECentralService::discovered(void)
|
||||
|
||||
void BLECentralService::disconnect(void)
|
||||
{
|
||||
// do nothing, inherited service may want to clean up its own
|
||||
_discovered = false;
|
||||
// inherited service may want to clean up its own characteristic
|
||||
}
|
||||
@@ -54,7 +54,7 @@ class BLECentralService
|
||||
BLECentralService(void);
|
||||
BLECentralService(BLEUuid bleuuid);
|
||||
|
||||
virtual err_t begin(void);
|
||||
virtual bool begin(void);
|
||||
|
||||
virtual bool discover (void);
|
||||
bool discovered(void);
|
||||
|
||||
@@ -45,7 +45,7 @@ BLECentralUart::BLECentralUart(uint16_t fifo_depth)
|
||||
_rx_cb = NULL;
|
||||
}
|
||||
|
||||
err_t BLECentralUart::begin(void)
|
||||
bool BLECentralUart::begin(void)
|
||||
{
|
||||
// Invoke basde class begin()
|
||||
BLECentralService::begin();
|
||||
@@ -56,7 +56,7 @@ err_t BLECentralUart::begin(void)
|
||||
// set up notify callback
|
||||
_txd.setNotifyCallback(bleuart_central_notify_cb);
|
||||
|
||||
return ERROR_NONE;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BLECentralUart::enableNotify(void)
|
||||
@@ -86,7 +86,9 @@ bool BLECentralUart::discover(void)
|
||||
|
||||
void BLECentralUart::disconnect(void)
|
||||
{
|
||||
BLECentralService::disconnect();
|
||||
|
||||
flush();
|
||||
}
|
||||
|
||||
void bleuart_central_notify_cb(BLECentralCharacteristic& chr, uint8_t* data, uint16_t len)
|
||||
|
||||
@@ -51,7 +51,7 @@ class BLECentralUart : public BLECentralService, public Stream
|
||||
|
||||
BLECentralUart(uint16_t fifo_depth = BLE_UART_DEFAULT_FIFO_DEPTH);
|
||||
|
||||
virtual err_t begin(void);
|
||||
virtual bool begin(void);
|
||||
virtual bool discover(void);
|
||||
virtual void disconnect(void);
|
||||
|
||||
|
||||
Reference in new issue
Block a user