Skip to content

Commit 861af7b

Browse files
committed
clean up BLEUuid merge uuid16 & uuid128 with copy operator
- also change DIS model to "Bluefruit Feather 52"
1 parent a6f1318 commit 861af7b

File tree

9 files changed

+60
-60
lines changed

9 files changed

+60
-60
lines changed

cores/nRF5/rtos.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "queue.h"
5252
#include "semphr.h"
5353

54+
#define DELAY_FOREVER portMAX_DELAY
5455
enum
5556
{
5657
TASK_PRIO_LOWEST = 0, // Idle task, should not be used
@@ -60,6 +61,8 @@ enum
6061
TASK_PRIO_HIGHEST = 4,
6162
};
6263

64+
#define malloc_type(type) rtos_malloc( sizeof(type) )
65+
6366
#if 0
6467
#define rtos_malloc(_size) ({ cprintf("[malloc] %s:%d : %d bytes\r\n", __PRETTY_FUNCTION__, __LINE__, _size); pvPortMalloc(_size); })
6568
#define rtos_free(ptr) ({ cprintf("[free] %s:%d\r\n" ,__PRETTY_FUNCTION__, __LINE__/*malloc_usable_size(ptr)*/); vPortFree(ptr); })

libraries/Bluefruit52Lib/src/BLEAdvertising.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,27 @@ bool BLEAdvertising::addData(uint8_t type, const void* data, uint8_t len)
101101
return true;
102102
}
103103

104-
bool BLEAdvertising::addUuid(uint16_t uuid16)
104+
bool BLEAdvertising::addUuid(BLEUuid bleuuid)
105105
{
106-
return addData(BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE, &uuid16, 2);
107-
}
106+
switch ( bleuuid.size() )
107+
{
108+
case 2:
109+
return addData(BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE, &bleuuid._uuid.uuid, 2);
110+
break;
108111

109-
bool BLEAdvertising::addUuid(uint8_t const uuid128[])
110-
{
111-
return addData(BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_MORE_AVAILABLE, uuid128, 16);
112+
case 16:
113+
return addData(BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_MORE_AVAILABLE, bleuuid._uuid128, 16);
114+
break;
115+
116+
default: break;
117+
}
118+
119+
return false;
112120
}
113121

114122
bool BLEAdvertising::addService(BLEService& service)
115123
{
116-
// UUID128
117-
if ( service.uuid._uuid128 )
118-
{
119-
return addUuid(service.uuid._uuid128);
120-
}else
121-
{
122-
return addUuid(service.uuid._uuid.uuid);
123-
}
124+
return addUuid(service.uuid);
124125
}
125126

126127
// Add Name to Adv packet, use setName() to set

libraries/Bluefruit52Lib/src/BLEAdvertising.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ class BLEAdvertising
6868
bool addName(void);
6969
bool addApperance(uint16_t appearance);
7070

71-
bool addUuid(uint16_t uuid16);
72-
bool addUuid(uint8_t const uuid128[]);
71+
bool addUuid(BLEUuid bleuuid);
7372
bool addService(BLEService& service);
7473

7574
bool setBeacon(BLEBeacon& beacon);

libraries/Bluefruit52Lib/src/BLECharacteristic.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,15 @@ BLECharacteristic::BLECharacteristic(void)
7171
init();
7272
}
7373

74-
BLECharacteristic::BLECharacteristic(uint16_t uuid16)
75-
: uuid(uuid16)
74+
BLECharacteristic::BLECharacteristic(BLEUuid bleuuid)
75+
: uuid(bleuuid)
7676
{
7777
init();
78-
}
79-
80-
BLECharacteristic::BLECharacteristic(uint8_t const uuid128[])
81-
: uuid(uuid128)
82-
{
83-
init();
84-
}
85-
86-
void BLECharacteristic::setUuid(uint16_t uuid16)
87-
{
88-
uuid.set(uuid16);
8978
}
9079

91-
void BLECharacteristic::setUuid(uint8_t const uuid128[])
80+
void BLECharacteristic::setUuid(BLEUuid bleuuid)
9281
{
93-
uuid.set(uuid128);
82+
uuid = bleuuid;
9483
}
9584

9685
/**

libraries/Bluefruit52Lib/src/BLECharacteristic.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,14 @@ class BLECharacteristic
113113
typedef void (*chars_cb_t) (void);
114114

115115
BLECharacteristic(void);
116-
BLECharacteristic(uint16_t uuid16);
117-
BLECharacteristic(uint8_t const uuid128[]);
116+
BLECharacteristic(BLEUuid bleuuid);
118117

119118
BLEService& parentService()
120119
{
121120
return *_service;
122121
}
123122

124-
void setUuid(uint16_t uuid16);
125-
void setUuid(uint8_t const uuid128[]);
126-
123+
void setUuid(BLEUuid bleuuid);
127124
void setTempMemory(void);
128125

129126
// Configure

libraries/Bluefruit52Lib/src/BLEService.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,15 @@ BLEService::BLEService(void)
5050
_init();
5151
}
5252

53-
BLEService::BLEService(uint16_t uuid16)
54-
: uuid(uuid16)
53+
BLEService::BLEService(BLEUuid bleuuid)
54+
: uuid(bleuuid)
5555
{
5656
_init();
5757
}
5858

59-
BLEService::BLEService(uint8_t const uuid128[])
60-
: uuid(uuid128)
59+
void BLEService::setUuid(BLEUuid bleuuid)
6160
{
62-
_init();
63-
}
64-
65-
void BLEService::setUuid(uint16_t uuid16)
66-
{
67-
uuid.set(uuid16);
68-
}
69-
70-
void BLEService::setUuid(uint8_t const uuid128[])
71-
{
72-
uuid.set(uuid128);
61+
uuid = bleuuid;
7362
}
7463

7564
err_t BLEService::addToGatt(void)

libraries/Bluefruit52Lib/src/BLEService.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,14 @@ class BLEService
4848
void _init(void);
4949

5050
public:
51-
BLEUuid uuid;
52-
5351
static BLEService* lastService;
5452

53+
BLEUuid uuid;
54+
5555
BLEService(void);
56-
BLEService(uint16_t uuid16);
57-
BLEService(uint8_t const uuid128[]);
56+
BLEService(BLEUuid bleuuid);
5857

59-
void setUuid(uint16_t uuid16);
60-
void setUuid(uint8_t const uuid128[]);
58+
void setUuid(BLEUuid bleuuid);
6159

6260
virtual err_t begin(void);
6361
};

libraries/Bluefruit52Lib/src/BLEUuid.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ class BLEUuid
4545
uint8_t const* _uuid128;
4646

4747
// Constructors
48-
BLEUuid(void ) { _uuid.type = BLE_UUID_TYPE_UNKNOWN; _uuid.uuid = 0; }
48+
BLEUuid(void ) { _uuid.type = BLE_UUID_TYPE_UNKNOWN; _uuid.uuid = 0; _uuid128 = NULL; }
4949
BLEUuid(uint16_t uuid16 ) { set(uuid16); }
5050
BLEUuid(uint8_t const uuid128[16] ) { set(uuid128); }
5151

5252
void set(uint16_t uuid16)
5353
{
5454
_uuid.type = BLE_UUID_TYPE_BLE;
5555
_uuid.uuid = uuid16;
56+
_uuid128 = NULL;
5657
}
5758

5859
void set(uint8_t const uuid128[16])
@@ -61,7 +62,17 @@ class BLEUuid
6162
_uuid128 = uuid128;
6263
}
6364

64-
// Add UUID128 if any, in case of UUID16, no ations is required
65+
uint8_t size (void)
66+
{
67+
// uuid 16
68+
if (_uuid.type == BLE_UUID_TYPE_BLE ) return 2;
69+
if (_uuid128 != NULL ) return 16;
70+
71+
// unknown
72+
return 0;
73+
}
74+
75+
// Add UUID128 if any, in case of UUID16, no actions is required
6576
// Application should call it anyway to be safe and consistent
6677
void begin(void)
6778
{
@@ -94,6 +105,19 @@ class BLEUuid
94105
{
95106
return !(*this == uuid);
96107
}
108+
109+
// Overload copy operator to allow initialization from other type
110+
BLEUuid& operator=(const uint16_t uuid)
111+
{
112+
set(uuid);
113+
return *this;
114+
}
115+
116+
BLEUuid& operator=(uint8_t const uuid128[16])
117+
{
118+
set(uuid128);
119+
return *this;
120+
}
97121
};
98122

99123
// Service UUID

libraries/Bluefruit52Lib/src/services/BLEDis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
BLEDis::BLEDis(void)
4141
: BLEService(UUID16_SVC_DEVICE_INFORMATION)
4242
{
43-
_model = "Bluefruit Feather52";
43+
_model = "Bluefruit Feather 52";
4444
_serial = NULL;
4545
_firmware_rev = NULL;
4646
_hardware_rev = NULL;

0 commit comments

Comments
 (0)