clean up BLEUuid merge uuid16 & uuid128 with copy operator
- also change DIS model to "Bluefruit Feather 52"
This commit is contained in:
1 parent
a6f1318f3e
commit
861af7b7e2
9 files changed
+61
-61
No files matched your search
@@ -51,6 +51,7 @@
|
||||
#include "queue.h"
|
||||
#include "semphr.h"
|
||||
|
||||
#define DELAY_FOREVER portMAX_DELAY
|
||||
enum
|
||||
{
|
||||
TASK_PRIO_LOWEST = 0, // Idle task, should not be used
|
||||
@@ -60,6 +61,8 @@ enum
|
||||
TASK_PRIO_HIGHEST = 4,
|
||||
};
|
||||
|
||||
#define malloc_type(type) rtos_malloc( sizeof(type) )
|
||||
|
||||
#if 0
|
||||
#define rtos_malloc(_size) ({ cprintf("[malloc] %s:%d : %d bytes\r\n", __PRETTY_FUNCTION__, __LINE__, _size); pvPortMalloc(_size); })
|
||||
#define rtos_free(ptr) ({ cprintf("[free] %s:%d\r\n" ,__PRETTY_FUNCTION__, __LINE__/*malloc_usable_size(ptr)*/); vPortFree(ptr); })
|
||||
|
||||
@@ -101,26 +101,27 @@ bool BLEAdvertising::addData(uint8_t type, const void* data, uint8_t len)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BLEAdvertising::addUuid(uint16_t uuid16)
|
||||
bool BLEAdvertising::addUuid(BLEUuid bleuuid)
|
||||
{
|
||||
return addData(BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE, &uuid16, 2);
|
||||
}
|
||||
switch ( bleuuid.size() )
|
||||
{
|
||||
case 2:
|
||||
return addData(BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE, &bleuuid._uuid.uuid, 2);
|
||||
break;
|
||||
|
||||
bool BLEAdvertising::addUuid(uint8_t const uuid128[])
|
||||
{
|
||||
return addData(BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_MORE_AVAILABLE, uuid128, 16);
|
||||
case 16:
|
||||
return addData(BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_MORE_AVAILABLE, bleuuid._uuid128, 16);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BLEAdvertising::addService(BLEService& service)
|
||||
{
|
||||
// UUID128
|
||||
if ( service.uuid._uuid128 )
|
||||
{
|
||||
return addUuid(service.uuid._uuid128);
|
||||
}else
|
||||
{
|
||||
return addUuid(service.uuid._uuid.uuid);
|
||||
}
|
||||
return addUuid(service.uuid);
|
||||
}
|
||||
|
||||
// Add Name to Adv packet, use setName() to set
|
||||
|
||||
@@ -68,8 +68,7 @@ public:
|
||||
bool addName(void);
|
||||
bool addApperance(uint16_t appearance);
|
||||
|
||||
bool addUuid(uint16_t uuid16);
|
||||
bool addUuid(uint8_t const uuid128[]);
|
||||
bool addUuid(BLEUuid bleuuid);
|
||||
bool addService(BLEService& service);
|
||||
|
||||
bool setBeacon(BLEBeacon& beacon);
|
||||
|
||||
@@ -71,26 +71,15 @@ BLECharacteristic::BLECharacteristic(void)
|
||||
init();
|
||||
}
|
||||
|
||||
BLECharacteristic::BLECharacteristic(uint16_t uuid16)
|
||||
: uuid(uuid16)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
BLECharacteristic::BLECharacteristic(uint8_t const uuid128[])
|
||||
: uuid(uuid128)
|
||||
BLECharacteristic::BLECharacteristic(BLEUuid bleuuid)
|
||||
: uuid(bleuuid)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
void BLECharacteristic::setUuid(uint16_t uuid16)
|
||||
void BLECharacteristic::setUuid(BLEUuid bleuuid)
|
||||
{
|
||||
uuid.set(uuid16);
|
||||
}
|
||||
|
||||
void BLECharacteristic::setUuid(uint8_t const uuid128[])
|
||||
{
|
||||
uuid.set(uuid128);
|
||||
uuid = bleuuid;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -113,17 +113,14 @@ class BLECharacteristic
|
||||
typedef void (*chars_cb_t) (void);
|
||||
|
||||
BLECharacteristic(void);
|
||||
BLECharacteristic(uint16_t uuid16);
|
||||
BLECharacteristic(uint8_t const uuid128[]);
|
||||
BLECharacteristic(BLEUuid bleuuid);
|
||||
|
||||
BLEService& parentService()
|
||||
{
|
||||
return *_service;
|
||||
}
|
||||
|
||||
void setUuid(uint16_t uuid16);
|
||||
void setUuid(uint8_t const uuid128[]);
|
||||
|
||||
void setUuid(BLEUuid bleuuid);
|
||||
void setTempMemory(void);
|
||||
|
||||
// Configure
|
||||
|
||||
@@ -50,26 +50,15 @@ BLEService::BLEService(void)
|
||||
_init();
|
||||
}
|
||||
|
||||
BLEService::BLEService(uint16_t uuid16)
|
||||
: uuid(uuid16)
|
||||
BLEService::BLEService(BLEUuid bleuuid)
|
||||
: uuid(bleuuid)
|
||||
{
|
||||
_init();
|
||||
}
|
||||
|
||||
BLEService::BLEService(uint8_t const uuid128[])
|
||||
: uuid(uuid128)
|
||||
void BLEService::setUuid(BLEUuid bleuuid)
|
||||
{
|
||||
_init();
|
||||
}
|
||||
|
||||
void BLEService::setUuid(uint16_t uuid16)
|
||||
{
|
||||
uuid.set(uuid16);
|
||||
}
|
||||
|
||||
void BLEService::setUuid(uint8_t const uuid128[])
|
||||
{
|
||||
uuid.set(uuid128);
|
||||
uuid = bleuuid;
|
||||
}
|
||||
|
||||
err_t BLEService::addToGatt(void)
|
||||
|
||||
@@ -48,16 +48,14 @@ class BLEService
|
||||
void _init(void);
|
||||
|
||||
public:
|
||||
BLEUuid uuid;
|
||||
|
||||
static BLEService* lastService;
|
||||
|
||||
BLEService(void);
|
||||
BLEService(uint16_t uuid16);
|
||||
BLEService(uint8_t const uuid128[]);
|
||||
BLEUuid uuid;
|
||||
|
||||
void setUuid(uint16_t uuid16);
|
||||
void setUuid(uint8_t const uuid128[]);
|
||||
BLEService(void);
|
||||
BLEService(BLEUuid bleuuid);
|
||||
|
||||
void setUuid(BLEUuid bleuuid);
|
||||
|
||||
virtual err_t begin(void);
|
||||
};
|
||||
|
||||
@@ -45,7 +45,7 @@ class BLEUuid
|
||||
uint8_t const* _uuid128;
|
||||
|
||||
// Constructors
|
||||
BLEUuid(void ) { _uuid.type = BLE_UUID_TYPE_UNKNOWN; _uuid.uuid = 0; }
|
||||
BLEUuid(void ) { _uuid.type = BLE_UUID_TYPE_UNKNOWN; _uuid.uuid = 0; _uuid128 = NULL; }
|
||||
BLEUuid(uint16_t uuid16 ) { set(uuid16); }
|
||||
BLEUuid(uint8_t const uuid128[16] ) { set(uuid128); }
|
||||
|
||||
@@ -53,6 +53,7 @@ class BLEUuid
|
||||
{
|
||||
_uuid.type = BLE_UUID_TYPE_BLE;
|
||||
_uuid.uuid = uuid16;
|
||||
_uuid128 = NULL;
|
||||
}
|
||||
|
||||
void set(uint8_t const uuid128[16])
|
||||
@@ -61,7 +62,17 @@ class BLEUuid
|
||||
_uuid128 = uuid128;
|
||||
}
|
||||
|
||||
// Add UUID128 if any, in case of UUID16, no ations is required
|
||||
uint8_t size (void)
|
||||
{
|
||||
// uuid 16
|
||||
if (_uuid.type == BLE_UUID_TYPE_BLE ) return 2;
|
||||
if (_uuid128 != NULL ) return 16;
|
||||
|
||||
// unknown
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Add UUID128 if any, in case of UUID16, no actions is required
|
||||
// Application should call it anyway to be safe and consistent
|
||||
void begin(void)
|
||||
{
|
||||
@@ -94,6 +105,19 @@ class BLEUuid
|
||||
{
|
||||
return !(*this == uuid);
|
||||
}
|
||||
|
||||
// Overload copy operator to allow initialization from other type
|
||||
BLEUuid& operator=(const uint16_t uuid)
|
||||
{
|
||||
set(uuid);
|
||||
return *this;
|
||||
}
|
||||
|
||||
BLEUuid& operator=(uint8_t const uuid128[16])
|
||||
{
|
||||
set(uuid128);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
// Service UUID
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
BLEDis::BLEDis(void)
|
||||
: BLEService(UUID16_SVC_DEVICE_INFORMATION)
|
||||
{
|
||||
_model = "Bluefruit Feather52";
|
||||
_model = "Bluefruit Feather 52";
|
||||
_serial = NULL;
|
||||
_firmware_rev = NULL;
|
||||
_hardware_rev = NULL;
|
||||
|
||||
Reference in new issue
Block a user