Skip to content

Commit 3b9805f

Browse files
committed
move conn_hdl to the first parameter for connection specific API
1 parent 7d5c88c commit 3b9805f

File tree

8 files changed

+114
-47
lines changed

8 files changed

+114
-47
lines changed

libraries/Bluefruit52Lib/src/BLECharacteristic.cpp

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ bool BLECharacteristic::notifyEnabled(uint16_t conn_hdl)
640640
return (getCccd(conn_hdl) & BLE_GATT_HVX_NOTIFICATION);
641641
}
642642

643-
bool BLECharacteristic::notify(const void* data, uint16_t len, uint16_t conn_hdl)
643+
bool BLECharacteristic::notify(uint16_t conn_hdl, const void* data, uint16_t len)
644644
{
645645
VERIFY( _properties.notify );
646646

@@ -690,31 +690,65 @@ bool BLECharacteristic::notify(const void* data, uint16_t len, uint16_t conn_hdl
690690
return true;
691691
}
692692

693-
bool BLECharacteristic::notify(const char * str, uint16_t conn_hdl)
693+
bool BLECharacteristic::notify(uint16_t conn_hdl, const char * str)
694694
{
695-
return notify((const uint8_t*) str, strlen(str), conn_hdl);
695+
return notify(conn_hdl, (const uint8_t*) str, strlen(str));
696696
}
697697

698-
bool BLECharacteristic::notify8(uint8_t num, uint16_t conn_hdl)
698+
bool BLECharacteristic::notify8(uint16_t conn_hdl, uint8_t num)
699699
{
700-
return notify((uint8_t*) &num, sizeof(num), conn_hdl);
700+
return notify(conn_hdl, (uint8_t*) &num, sizeof(num));
701701
}
702702

703-
bool BLECharacteristic::notify16(uint16_t num, uint16_t conn_hdl)
703+
bool BLECharacteristic::notify16(uint16_t conn_hdl, uint16_t num)
704704
{
705-
return notify((uint8_t*) &num, sizeof(num), conn_hdl);
705+
return notify(conn_hdl, (uint8_t*) &num, sizeof(num));
706706
}
707707

708-
bool BLECharacteristic::notify32(uint32_t num, uint16_t conn_hdl)
708+
bool BLECharacteristic::notify32(uint16_t conn_hdl, uint32_t num)
709709
{
710-
return notify((uint8_t*) &num, sizeof(num), conn_hdl);
710+
return notify(conn_hdl, (uint8_t*) &num, sizeof(num));
711711
}
712712

713-
bool BLECharacteristic::notify32(int num, uint16_t conn_hdl)
713+
bool BLECharacteristic::notify32(uint16_t conn_hdl, int num)
714714
{
715715
return notify32((uint32_t) num, conn_hdl);
716716
}
717717

718+
//--------------------------------------------------------------------+
719+
// Notify with single connection
720+
//--------------------------------------------------------------------+
721+
bool BLECharacteristic::notify(const void* data, uint16_t len)
722+
{
723+
return notify(BLE_CONN_HANDLE_INVALID, data, len);
724+
}
725+
726+
bool BLECharacteristic::notify(const char* str)
727+
{
728+
return notify(BLE_CONN_HANDLE_INVALID, str);
729+
}
730+
731+
bool BLECharacteristic::notify8(uint8_t num)
732+
{
733+
return notify8(BLE_CONN_HANDLE_INVALID, num);
734+
}
735+
736+
bool BLECharacteristic::notify16(uint16_t num)
737+
{
738+
return notify16(BLE_CONN_HANDLE_INVALID, num);
739+
}
740+
741+
bool BLECharacteristic::notify32(uint32_t num)
742+
{
743+
return notify32(BLE_CONN_HANDLE_INVALID, num);
744+
}
745+
746+
bool BLECharacteristic::notify32(int num)
747+
{
748+
return notify32(BLE_CONN_HANDLE_INVALID, num);
749+
}
750+
751+
718752
/*------------------------------------------------------------------*/
719753
/* INDICATE
720754
*------------------------------------------------------------------*/

libraries/Bluefruit52Lib/src/BLECharacteristic.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,28 @@ class BLECharacteristic
133133
uint16_t read16(void);
134134
uint32_t read32(void);
135135

136-
/*------------- Notify -------------*/
137136
uint16_t getCccd(uint16_t conn_hdl);
138137

139138
bool notifyEnabled(void);
140139
bool notifyEnabled(uint16_t conn_hdl);
141140

142-
bool notify (const void* data, uint16_t len, uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
143-
bool notify (const char* str, uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
141+
/*------------- Notify -------------*/
142+
bool notify (const void* data, uint16_t len);
143+
bool notify (const char* str);
144+
145+
bool notify8 (uint8_t num);
146+
bool notify16 (uint16_t num);
147+
bool notify32 (uint32_t num);
148+
bool notify32 (int num);
149+
150+
/*------------- Notify -------------*/
151+
bool notify (uint16_t conn_hdl, const void* data, uint16_t len);
152+
bool notify (uint16_t conn_hdl, const char* str);
144153

145-
bool notify8 (uint8_t num, uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
146-
bool notify16 (uint16_t num, uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
147-
bool notify32 (uint32_t num, uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
148-
bool notify32 (int num, uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
154+
bool notify8 (uint16_t conn_hdl, uint8_t num);
155+
bool notify16 (uint16_t conn_hdl, uint16_t num);
156+
bool notify32 (uint16_t conn_hdl, uint32_t num);
157+
bool notify32 (uint16_t conn_hdl, int num);
149158

150159
/*------------- Indicate -------------*/
151160
bool indicateEnabled(void);

libraries/Bluefruit52Lib/src/services/BLEBas.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ bool BLEBas::notify(uint8_t level)
6565
return _battery.notify8(level);
6666
}
6767

68-
bool BLEBas::notify(uint8_t level, uint16_t conn_hdl)
68+
bool BLEBas::notify(uint16_t conn_hdl, uint8_t level)
6969
{
70-
return _battery.notify8(level, conn_hdl);
70+
return _battery.notify8(conn_hdl, level);
7171
}

libraries/Bluefruit52Lib/src/services/BLEBas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class BLEBas : public BLEService
5454
bool write (uint8_t level);
5555

5656
bool notify(uint8_t level);
57-
bool notify(uint8_t level, uint16_t conn_hdl);
57+
bool notify(uint16_t conn_hdl, uint8_t level);
5858
};
5959

6060

libraries/Bluefruit52Lib/src/services/BLEHidGeneric.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,21 +251,36 @@ err_t BLEHidGeneric::begin(void)
251251
/*------------------------------------------------------------------*/
252252
/* Input Report
253253
*------------------------------------------------------------------*/
254-
bool BLEHidGeneric::inputReport(uint8_t reportID, void const* data, int len, uint16_t conn_hdl)
254+
bool BLEHidGeneric::inputReport(uint16_t conn_hdl, uint8_t reportID, void const* data, int len)
255255
{
256256
// index is ID-1
257257
uint8_t const idx = ( reportID ? (reportID-1) : 0 );
258-
return _chr_inputs[idx].notify( (uint8_t const*) data, len, conn_hdl);
258+
return _chr_inputs[idx].notify(conn_hdl, (uint8_t const*) data, len);
259259
}
260260

261-
bool BLEHidGeneric::bootKeyboardReport(void const* data, int len, uint16_t conn_hdl)
261+
bool BLEHidGeneric::bootKeyboardReport(uint16_t conn_hdl, void const* data, int len)
262262
{
263-
return _chr_boot_keyboard_input->notify(data, len, conn_hdl);
263+
return _chr_boot_keyboard_input->notify(conn_hdl, data, len);
264264
}
265265

266-
bool BLEHidGeneric::bootMouseReport(void const* data, int len, uint16_t conn_hdl)
266+
bool BLEHidGeneric::bootMouseReport(uint16_t conn_hdl, void const* data, int len)
267267
{
268-
return _chr_boot_mouse_input->notify(data, len, conn_hdl);
268+
return _chr_boot_mouse_input->notify(conn_hdl, data, len);
269+
}
270+
271+
bool BLEHidGeneric::inputReport(uint8_t reportID, void const* data, int len)
272+
{
273+
return inputReport(BLE_CONN_HANDLE_INVALID, reportID, data, len);
274+
}
275+
276+
bool BLEHidGeneric::bootKeyboardReport(void const* data, int len)
277+
{
278+
return bootKeyboardReport(BLE_CONN_HANDLE_INVALID, data, len);
279+
}
280+
281+
bool BLEHidGeneric::bootMouseReport(void const* data, int len)
282+
{
283+
return bootMouseReport(BLE_CONN_HANDLE_INVALID, data, len);
269284
}
270285

271286
/*------------------------------------------------------------------*/

libraries/Bluefruit52Lib/src/services/BLEHidGeneric.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,15 @@ class BLEHidGeneric : public BLEService
115115

116116
bool isBootMode(void) { return _protocol_mode == HID_PROTOCOL_MODE_BOOT; }
117117

118-
// Send Report
119-
bool inputReport(uint8_t reportID, void const* data, int len, uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
120-
bool bootKeyboardReport(void const* data, int len, uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
121-
bool bootMouseReport(void const* data, int len, uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
118+
// Send Report to default connection
119+
bool inputReport(uint8_t reportID, void const* data, int len);
120+
bool bootKeyboardReport(void const* data, int len);
121+
bool bootMouseReport(void const* data, int len);
122+
123+
// Send report to specific connection
124+
bool inputReport(uint16_t conn_hdl, uint8_t reportID, void const* data, int len);
125+
bool bootKeyboardReport(uint16_t conn_hdl, void const* data, int len);
126+
bool bootMouseReport(uint16_t conn_hdl, void const* data, int len);
122127

123128
protected:
124129
uint8_t _num_input;

libraries/Bluefruit52Lib/src/services/BLEUart.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,27 +187,27 @@ int BLEUart::read (void)
187187
return read(&ch, 1) ? (int) ch : EOF;
188188
}
189189

190-
int BLEUart::read (uint8_t * buf, size_t size)
190+
int BLEUart::read(uint8_t * buf, size_t size)
191191
{
192192
return _rx_fifo->read(buf, size);
193193
}
194194

195-
size_t BLEUart::write (uint8_t b)
195+
size_t BLEUart::write(uint8_t b)
196196
{
197-
return this->write(&b, 1, Bluefruit.connHandle());
197+
return this->write(Bluefruit.connHandle(), &b, 1);
198198
}
199199

200-
size_t BLEUart::write (const uint8_t *content, size_t len)
200+
size_t BLEUart::write(uint16_t conn_hdl, uint8_t b)
201201
{
202-
return this->write(content, len, Bluefruit.connHandle());
202+
return this->write(conn_hdl, &b, 1);
203203
}
204204

205-
size_t BLEUart::write (uint8_t b, uint16_t conn_hdl)
205+
size_t BLEUart::write(const uint8_t *content, size_t len)
206206
{
207-
return this->write(&b, 1, conn_hdl);
207+
return this->write(Bluefruit.connHandle(), content, len);
208208
}
209209

210-
size_t BLEUart::write (const uint8_t *content, size_t len, uint16_t conn_hdl)
210+
size_t BLEUart::write(uint16_t conn_hdl, const uint8_t *content, size_t len)
211211
{
212212
BLEConnection* conn = Bluefruit.Connection(conn_hdl);
213213
VERIFY(conn, 0);
@@ -218,7 +218,7 @@ size_t BLEUart::write (const uint8_t *content, size_t len, uint16_t conn_hdl)
218218
// notify right away if txd buffered is not enabled
219219
if ( !(_tx_buffered && _tx_fifo) )
220220
{
221-
return _txd.notify(content, len, conn_hdl) ? len : 0;
221+
return _txd.notify(conn_hdl, content, len) ? len : 0;
222222
}else
223223
{
224224
uint16_t written = _tx_fifo->write(content, len);
@@ -236,7 +236,7 @@ size_t BLEUart::write (const uint8_t *content, size_t len, uint16_t conn_hdl)
236236
// still more data left, send them all
237237
if ( written < len )
238238
{
239-
VERIFY(_txd.notify(content+written, len-written, conn_hdl), written);
239+
VERIFY(_txd.notify(conn_hdl, content+written, len-written), written);
240240
}
241241

242242
return len;
@@ -260,11 +260,13 @@ void BLEUart::flush (void)
260260
_rx_fifo->clear();
261261
}
262262

263-
bool BLEUart::flushTXD(uint16_t conn_hdl)
263+
bool BLEUart::flushTXD (void)
264264
{
265-
// use default conn handle if not passed
266-
if ( conn_hdl == BLE_CONN_HANDLE_INVALID ) conn_hdl = Bluefruit.connHandle();
265+
return flushTXD(Bluefruit.connHandle());
266+
}
267267

268+
bool BLEUart::flushTXD(uint16_t conn_hdl)
269+
{
268270
BLEConnection* conn = Bluefruit.Connection(conn_hdl);
269271
VERIFY(conn);
270272

@@ -277,7 +279,7 @@ bool BLEUart::flushTXD(uint16_t conn_hdl)
277279

278280
if ( len )
279281
{
280-
result = _txd.notify(ff_data, len, conn_hdl);
282+
result = _txd.notify(conn_hdl, ff_data, len);
281283
}
282284

283285
rtos_free(ff_data);

libraries/Bluefruit52Lib/src/services/BLEUart.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ class BLEUart : public BLEService, public Stream
6666
void setNotifyCallback(notify_callback_t fp);
6767

6868
void bufferTXD(bool enable);
69-
bool flushTXD (uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
69+
70+
bool flushTXD (void);
71+
bool flushTXD (uint16_t conn_hdl);
7072

7173
// Stream API
7274
virtual int read ( void );
@@ -76,8 +78,8 @@ class BLEUart : public BLEService, public Stream
7678
virtual size_t write ( uint8_t b );
7779
virtual size_t write ( const uint8_t *content, size_t len);
7880

79-
virtual size_t write ( uint8_t b, uint16_t conn_hdl);
80-
virtual size_t write ( const uint8_t *content, size_t len, uint16_t conn_hdl);
81+
virtual size_t write (uint16_t conn_hdl, uint8_t b);
82+
virtual size_t write (uint16_t conn_hdl, const uint8_t *content, size_t len);
8183

8284
virtual int available ( void );
8385
virtual int peek ( void );

0 commit comments

Comments
 (0)