add _disconnect_cb() and _connect_cb() to BLEService
integrate BLEService.addToGatt() to begin()
This commit is contained in:
1 parent
ca2d6f3dce
commit
5259a71ebb
9 files changed
+44
-19
No files matched your search
@@ -141,12 +141,20 @@ void BLEGatt::_eventHandler(ble_evt_t* evt)
|
||||
*------------------------------------------------------------------*/
|
||||
bool BLEGatt::_addCharacteristic(BLECharacteristic* chr)
|
||||
{
|
||||
if ( _server.chr_count == BLE_GATT_MAX_SERVER_CHARS ) return false;
|
||||
if ( _server.chr_count == CFG_GATT_MAX_SERVER_CHARS ) return false;
|
||||
_server.chr_list[ _server.chr_count++ ] = chr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BLEGatt::_addService(BLEService* svc)
|
||||
{
|
||||
VERIFY( _server.svc_count < CFG_GATT_MAX_SERVER_SERVICE );
|
||||
_server.svc_list[ _server.svc_count++ ] = svc;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Client
|
||||
*------------------------------------------------------------------*/
|
||||
@@ -173,7 +181,7 @@ void BLEGatt::_removeCharacteristic(BLEClientCharacteristic* chr)
|
||||
|
||||
bool BLEGatt::_addCharacteristic(BLEClientCharacteristic* chr)
|
||||
{
|
||||
VERIFY( _client.chr_count < BLE_GATT_MAX_CLIENT_CHARS );
|
||||
VERIFY( _client.chr_count < CFG_GATT_MAX_CLIENT_CHARS );
|
||||
_client.chr_list[ _client.chr_count++ ] = chr;
|
||||
|
||||
return true;
|
||||
@@ -181,7 +189,7 @@ bool BLEGatt::_addCharacteristic(BLEClientCharacteristic* chr)
|
||||
|
||||
bool BLEGatt::_addService(BLEClientService* svc)
|
||||
{
|
||||
VERIFY( _client.svc_count < BLE_GATT_MAX_CLIENT_SERVICE );
|
||||
VERIFY( _client.svc_count < CFG_GATT_MAX_CLIENT_SERVICE );
|
||||
_client.svc_list[ _client.svc_count++ ] = svc;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -46,10 +46,11 @@
|
||||
|
||||
#include "BLEClientService.h"
|
||||
|
||||
#define BLE_GATT_MAX_SERVER_CHARS 40
|
||||
#define CFG_GATT_MAX_SERVER_SERVICE 20
|
||||
#define CFG_GATT_MAX_SERVER_CHARS 40
|
||||
|
||||
#define BLE_GATT_MAX_CLIENT_SERVICE 20
|
||||
#define BLE_GATT_MAX_CLIENT_CHARS 40
|
||||
#define CFG_GATT_MAX_CLIENT_SERVICE 20
|
||||
#define CFG_GATT_MAX_CLIENT_CHARS 40
|
||||
|
||||
|
||||
class BLEGatt
|
||||
@@ -66,27 +67,30 @@ class BLEGatt
|
||||
*------------------------------------------------------------------*/
|
||||
// Server
|
||||
bool _addCharacteristic(BLECharacteristic* chr);
|
||||
bool _addService(BLEService* svc);
|
||||
|
||||
// Client
|
||||
bool _addCharacteristic(BLEClientCharacteristic* chr);
|
||||
void _removeCharacteristic(BLEClientCharacteristic* chr);
|
||||
|
||||
bool _addService(BLEClientService* svc);
|
||||
|
||||
void _eventHandler(ble_evt_t* evt);
|
||||
|
||||
private:
|
||||
struct {
|
||||
uint8_t svc_count;
|
||||
BLEService* svc_list[CFG_GATT_MAX_SERVER_SERVICE];
|
||||
|
||||
uint8_t chr_count;
|
||||
BLECharacteristic* chr_list[BLE_GATT_MAX_SERVER_CHARS];
|
||||
BLECharacteristic* chr_list[CFG_GATT_MAX_SERVER_CHARS];
|
||||
} _server;
|
||||
|
||||
struct {
|
||||
uint8_t svc_count;
|
||||
BLEClientService* svc_list[BLE_GATT_MAX_CLIENT_SERVICE];
|
||||
BLEClientService* svc_list[CFG_GATT_MAX_CLIENT_SERVICE];
|
||||
|
||||
uint8_t chr_count;
|
||||
BLEClientCharacteristic* chr_list[BLE_GATT_MAX_CLIENT_CHARS];
|
||||
BLEClientCharacteristic* chr_list[CFG_GATT_MAX_CLIENT_CHARS];
|
||||
}_client;
|
||||
|
||||
AdaMsg _adamsg;
|
||||
|
||||
@@ -61,7 +61,7 @@ void BLEService::setUuid(BLEUuid bleuuid)
|
||||
uuid = bleuuid;
|
||||
}
|
||||
|
||||
err_t BLEService::addToGatt(void)
|
||||
err_t BLEService::begin(void)
|
||||
{
|
||||
// Add UUID128 if needed
|
||||
uuid.begin();
|
||||
@@ -70,12 +70,18 @@ err_t BLEService::addToGatt(void)
|
||||
VERIFY_STATUS( sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &uuid._uuid, &handle) );
|
||||
|
||||
lastService = this;
|
||||
(void) Bluefruit.Gatt._addService(this);
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
err_t BLEService::begin(void)
|
||||
void BLEService::_disconnect_cb(void)
|
||||
{
|
||||
return addToGatt();
|
||||
// Template for inherited class
|
||||
}
|
||||
|
||||
void BLEService::_connect_cb(void)
|
||||
{
|
||||
// Template for inherited class
|
||||
}
|
||||
|
||||
@@ -44,8 +44,10 @@ class BLEService
|
||||
protected:
|
||||
uint16_t _handle;
|
||||
|
||||
err_t addToGatt(void);
|
||||
void _init(void);
|
||||
|
||||
virtual void _disconnect_cb(void);
|
||||
virtual void _connect_cb(void);
|
||||
|
||||
public:
|
||||
static BLEService* lastService;
|
||||
|
||||
@@ -44,7 +44,8 @@ BLEBas::BLEBas(void) :
|
||||
|
||||
err_t BLEBas::begin(void)
|
||||
{
|
||||
VERIFY_STATUS( this->addToGatt() );
|
||||
// Invoke base class begin()
|
||||
VERIFY_STATUS( BLEService::begin() );
|
||||
|
||||
_battery.setProperties(CHR_PROPS_READ | CHR_PROPS_NOTIFY); // could support notify
|
||||
_battery.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
|
||||
|
||||
@@ -171,7 +171,8 @@ BLEDfu::BLEDfu(void) : BLEService(UUID128_SVC_DFU_OTA), _chr_control(UUID128_CHR
|
||||
|
||||
err_t BLEDfu::begin(void)
|
||||
{
|
||||
VERIFY_STATUS( this->addToGatt() );
|
||||
// Invoke base class begin()
|
||||
VERIFY_STATUS( BLEService::begin() );
|
||||
|
||||
// No need to keep packet & revision characteristics
|
||||
BLECharacteristic chr_packet(UUID128_CHR_DFU_PACKET);
|
||||
|
||||
@@ -70,7 +70,8 @@ void BLEDis::setManufacturer(const char* manufacturer)
|
||||
|
||||
err_t BLEDis::begin(void)
|
||||
{
|
||||
VERIFY_STATUS( this->addToGatt() );
|
||||
// Invoke base class begin()
|
||||
VERIFY_STATUS( BLEService::begin() );
|
||||
|
||||
_serial = getMcuUniqueID();
|
||||
_firmware_rev = getFirmwareVersion();
|
||||
|
||||
@@ -133,7 +133,8 @@ err_t BLEHidGeneric::begin(void)
|
||||
{
|
||||
VERIFY ( (_report_map != NULL) && _report_map_len, NRF_ERROR_INVALID_PARAM);
|
||||
|
||||
VERIFY_STATUS( this->addToGatt() );
|
||||
// Invoke base class begin()
|
||||
VERIFY_STATUS( BLEService::begin() );
|
||||
|
||||
// Protocol Mode
|
||||
if ( _boot_keyboard || _boot_mouse )
|
||||
|
||||
@@ -140,7 +140,8 @@ void BLEMidi::begin(int baudrate)
|
||||
|
||||
err_t BLEMidi::begin(void)
|
||||
{
|
||||
VERIFY_STATUS( this->addToGatt() );
|
||||
// Invoke base class begin()
|
||||
VERIFY_STATUS( BLEService::begin() );
|
||||
|
||||
// IO characteristic
|
||||
_io.setProperties(CHR_PROPS_READ | CHR_PROPS_WRITE | CHR_PROPS_WRITE_WO_RESP | CHR_PROPS_NOTIFY);
|
||||
|
||||
Reference in new issue
Block a user