move conn_hdl to the first parameter for connection specific API
This commit is contained in:
1 parent
7d5c88cd20
commit
3b9805f124
8 files changed
+114
-47
No files matched your search
@@ -640,7 +640,7 @@ bool BLECharacteristic::notifyEnabled(uint16_t conn_hdl)
|
||||
return (getCccd(conn_hdl) & BLE_GATT_HVX_NOTIFICATION);
|
||||
}
|
||||
|
||||
bool BLECharacteristic::notify(const void* data, uint16_t len, uint16_t conn_hdl)
|
||||
bool BLECharacteristic::notify(uint16_t conn_hdl, const void* data, uint16_t len)
|
||||
{
|
||||
VERIFY( _properties.notify );
|
||||
|
||||
@@ -690,31 +690,65 @@ bool BLECharacteristic::notify(const void* data, uint16_t len, uint16_t conn_hdl
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BLECharacteristic::notify(const char * str, uint16_t conn_hdl)
|
||||
bool BLECharacteristic::notify(uint16_t conn_hdl, const char * str)
|
||||
{
|
||||
return notify((const uint8_t*) str, strlen(str), conn_hdl);
|
||||
return notify(conn_hdl, (const uint8_t*) str, strlen(str));
|
||||
}
|
||||
|
||||
bool BLECharacteristic::notify8(uint8_t num, uint16_t conn_hdl)
|
||||
bool BLECharacteristic::notify8(uint16_t conn_hdl, uint8_t num)
|
||||
{
|
||||
return notify((uint8_t*) &num, sizeof(num), conn_hdl);
|
||||
return notify(conn_hdl, (uint8_t*) &num, sizeof(num));
|
||||
}
|
||||
|
||||
bool BLECharacteristic::notify16(uint16_t num, uint16_t conn_hdl)
|
||||
bool BLECharacteristic::notify16(uint16_t conn_hdl, uint16_t num)
|
||||
{
|
||||
return notify((uint8_t*) &num, sizeof(num), conn_hdl);
|
||||
return notify(conn_hdl, (uint8_t*) &num, sizeof(num));
|
||||
}
|
||||
|
||||
bool BLECharacteristic::notify32(uint32_t num, uint16_t conn_hdl)
|
||||
bool BLECharacteristic::notify32(uint16_t conn_hdl, uint32_t num)
|
||||
{
|
||||
return notify((uint8_t*) &num, sizeof(num), conn_hdl);
|
||||
return notify(conn_hdl, (uint8_t*) &num, sizeof(num));
|
||||
}
|
||||
|
||||
bool BLECharacteristic::notify32(int num, uint16_t conn_hdl)
|
||||
bool BLECharacteristic::notify32(uint16_t conn_hdl, int num)
|
||||
{
|
||||
return notify32((uint32_t) num, conn_hdl);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Notify with single connection
|
||||
//--------------------------------------------------------------------+
|
||||
bool BLECharacteristic::notify(const void* data, uint16_t len)
|
||||
{
|
||||
return notify(BLE_CONN_HANDLE_INVALID, data, len);
|
||||
}
|
||||
|
||||
bool BLECharacteristic::notify(const char* str)
|
||||
{
|
||||
return notify(BLE_CONN_HANDLE_INVALID, str);
|
||||
}
|
||||
|
||||
bool BLECharacteristic::notify8(uint8_t num)
|
||||
{
|
||||
return notify8(BLE_CONN_HANDLE_INVALID, num);
|
||||
}
|
||||
|
||||
bool BLECharacteristic::notify16(uint16_t num)
|
||||
{
|
||||
return notify16(BLE_CONN_HANDLE_INVALID, num);
|
||||
}
|
||||
|
||||
bool BLECharacteristic::notify32(uint32_t num)
|
||||
{
|
||||
return notify32(BLE_CONN_HANDLE_INVALID, num);
|
||||
}
|
||||
|
||||
bool BLECharacteristic::notify32(int num)
|
||||
{
|
||||
return notify32(BLE_CONN_HANDLE_INVALID, num);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* INDICATE
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
@@ -133,19 +133,28 @@ class BLECharacteristic
|
||||
uint16_t read16(void);
|
||||
uint32_t read32(void);
|
||||
|
||||
/*------------- Notify -------------*/
|
||||
uint16_t getCccd(uint16_t conn_hdl);
|
||||
|
||||
bool notifyEnabled(void);
|
||||
bool notifyEnabled(uint16_t conn_hdl);
|
||||
|
||||
bool notify (const void* data, uint16_t len, uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
|
||||
bool notify (const char* str, uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
|
||||
/*------------- Notify -------------*/
|
||||
bool notify (const void* data, uint16_t len);
|
||||
bool notify (const char* str);
|
||||
|
||||
bool notify8 (uint8_t num, uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
|
||||
bool notify16 (uint16_t num, uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
|
||||
bool notify32 (uint32_t num, uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
|
||||
bool notify32 (int num, uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
|
||||
bool notify8 (uint8_t num);
|
||||
bool notify16 (uint16_t num);
|
||||
bool notify32 (uint32_t num);
|
||||
bool notify32 (int num);
|
||||
|
||||
/*------------- Notify -------------*/
|
||||
bool notify (uint16_t conn_hdl, const void* data, uint16_t len);
|
||||
bool notify (uint16_t conn_hdl, const char* str);
|
||||
|
||||
bool notify8 (uint16_t conn_hdl, uint8_t num);
|
||||
bool notify16 (uint16_t conn_hdl, uint16_t num);
|
||||
bool notify32 (uint16_t conn_hdl, uint32_t num);
|
||||
bool notify32 (uint16_t conn_hdl, int num);
|
||||
|
||||
/*------------- Indicate -------------*/
|
||||
bool indicateEnabled(void);
|
||||
|
||||
@@ -65,7 +65,7 @@ bool BLEBas::notify(uint8_t level)
|
||||
return _battery.notify8(level);
|
||||
}
|
||||
|
||||
bool BLEBas::notify(uint8_t level, uint16_t conn_hdl)
|
||||
bool BLEBas::notify(uint16_t conn_hdl, uint8_t level)
|
||||
{
|
||||
return _battery.notify8(level, conn_hdl);
|
||||
return _battery.notify8(conn_hdl, level);
|
||||
}
|
||||
@@ -54,7 +54,7 @@ class BLEBas : public BLEService
|
||||
bool write (uint8_t level);
|
||||
|
||||
bool notify(uint8_t level);
|
||||
bool notify(uint8_t level, uint16_t conn_hdl);
|
||||
bool notify(uint16_t conn_hdl, uint8_t level);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -251,21 +251,36 @@ err_t BLEHidGeneric::begin(void)
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Input Report
|
||||
*------------------------------------------------------------------*/
|
||||
bool BLEHidGeneric::inputReport(uint8_t reportID, void const* data, int len, uint16_t conn_hdl)
|
||||
bool BLEHidGeneric::inputReport(uint16_t conn_hdl, uint8_t reportID, void const* data, int len)
|
||||
{
|
||||
// index is ID-1
|
||||
uint8_t const idx = ( reportID ? (reportID-1) : 0 );
|
||||
return _chr_inputs[idx].notify( (uint8_t const*) data, len, conn_hdl);
|
||||
return _chr_inputs[idx].notify(conn_hdl, (uint8_t const*) data, len);
|
||||
}
|
||||
|
||||
bool BLEHidGeneric::bootKeyboardReport(void const* data, int len, uint16_t conn_hdl)
|
||||
bool BLEHidGeneric::bootKeyboardReport(uint16_t conn_hdl, void const* data, int len)
|
||||
{
|
||||
return _chr_boot_keyboard_input->notify(data, len, conn_hdl);
|
||||
return _chr_boot_keyboard_input->notify(conn_hdl, data, len);
|
||||
}
|
||||
|
||||
bool BLEHidGeneric::bootMouseReport(void const* data, int len, uint16_t conn_hdl)
|
||||
bool BLEHidGeneric::bootMouseReport(uint16_t conn_hdl, void const* data, int len)
|
||||
{
|
||||
return _chr_boot_mouse_input->notify(data, len, conn_hdl);
|
||||
return _chr_boot_mouse_input->notify(conn_hdl, data, len);
|
||||
}
|
||||
|
||||
bool BLEHidGeneric::inputReport(uint8_t reportID, void const* data, int len)
|
||||
{
|
||||
return inputReport(BLE_CONN_HANDLE_INVALID, reportID, data, len);
|
||||
}
|
||||
|
||||
bool BLEHidGeneric::bootKeyboardReport(void const* data, int len)
|
||||
{
|
||||
return bootKeyboardReport(BLE_CONN_HANDLE_INVALID, data, len);
|
||||
}
|
||||
|
||||
bool BLEHidGeneric::bootMouseReport(void const* data, int len)
|
||||
{
|
||||
return bootMouseReport(BLE_CONN_HANDLE_INVALID, data, len);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
|
||||
@@ -115,10 +115,15 @@ class BLEHidGeneric : public BLEService
|
||||
|
||||
bool isBootMode(void) { return _protocol_mode == HID_PROTOCOL_MODE_BOOT; }
|
||||
|
||||
// Send Report
|
||||
bool inputReport(uint8_t reportID, void const* data, int len, uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
|
||||
bool bootKeyboardReport(void const* data, int len, uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
|
||||
bool bootMouseReport(void const* data, int len, uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
|
||||
// Send Report to default connection
|
||||
bool inputReport(uint8_t reportID, void const* data, int len);
|
||||
bool bootKeyboardReport(void const* data, int len);
|
||||
bool bootMouseReport(void const* data, int len);
|
||||
|
||||
// Send report to specific connection
|
||||
bool inputReport(uint16_t conn_hdl, uint8_t reportID, void const* data, int len);
|
||||
bool bootKeyboardReport(uint16_t conn_hdl, void const* data, int len);
|
||||
bool bootMouseReport(uint16_t conn_hdl, void const* data, int len);
|
||||
|
||||
protected:
|
||||
uint8_t _num_input;
|
||||
|
||||
@@ -187,27 +187,27 @@ int BLEUart::read (void)
|
||||
return read(&ch, 1) ? (int) ch : EOF;
|
||||
}
|
||||
|
||||
int BLEUart::read (uint8_t * buf, size_t size)
|
||||
int BLEUart::read(uint8_t * buf, size_t size)
|
||||
{
|
||||
return _rx_fifo->read(buf, size);
|
||||
}
|
||||
|
||||
size_t BLEUart::write (uint8_t b)
|
||||
size_t BLEUart::write(uint8_t b)
|
||||
{
|
||||
return this->write(&b, 1, Bluefruit.connHandle());
|
||||
return this->write(Bluefruit.connHandle(), &b, 1);
|
||||
}
|
||||
|
||||
size_t BLEUart::write (const uint8_t *content, size_t len)
|
||||
size_t BLEUart::write(uint16_t conn_hdl, uint8_t b)
|
||||
{
|
||||
return this->write(content, len, Bluefruit.connHandle());
|
||||
return this->write(conn_hdl, &b, 1);
|
||||
}
|
||||
|
||||
size_t BLEUart::write (uint8_t b, uint16_t conn_hdl)
|
||||
size_t BLEUart::write(const uint8_t *content, size_t len)
|
||||
{
|
||||
return this->write(&b, 1, conn_hdl);
|
||||
return this->write(Bluefruit.connHandle(), content, len);
|
||||
}
|
||||
|
||||
size_t BLEUart::write (const uint8_t *content, size_t len, uint16_t conn_hdl)
|
||||
size_t BLEUart::write(uint16_t conn_hdl, const uint8_t *content, size_t len)
|
||||
{
|
||||
BLEConnection* conn = Bluefruit.Connection(conn_hdl);
|
||||
VERIFY(conn, 0);
|
||||
@@ -218,7 +218,7 @@ size_t BLEUart::write (const uint8_t *content, size_t len, uint16_t conn_hdl)
|
||||
// notify right away if txd buffered is not enabled
|
||||
if ( !(_tx_buffered && _tx_fifo) )
|
||||
{
|
||||
return _txd.notify(content, len, conn_hdl) ? len : 0;
|
||||
return _txd.notify(conn_hdl, content, len) ? len : 0;
|
||||
}else
|
||||
{
|
||||
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)
|
||||
// still more data left, send them all
|
||||
if ( written < len )
|
||||
{
|
||||
VERIFY(_txd.notify(content+written, len-written, conn_hdl), written);
|
||||
VERIFY(_txd.notify(conn_hdl, content+written, len-written), written);
|
||||
}
|
||||
|
||||
return len;
|
||||
@@ -260,11 +260,13 @@ void BLEUart::flush (void)
|
||||
_rx_fifo->clear();
|
||||
}
|
||||
|
||||
bool BLEUart::flushTXD (void)
|
||||
{
|
||||
return flushTXD(Bluefruit.connHandle());
|
||||
}
|
||||
|
||||
bool BLEUart::flushTXD(uint16_t conn_hdl)
|
||||
{
|
||||
// use default conn handle if not passed
|
||||
if ( conn_hdl == BLE_CONN_HANDLE_INVALID ) conn_hdl = Bluefruit.connHandle();
|
||||
|
||||
BLEConnection* conn = Bluefruit.Connection(conn_hdl);
|
||||
VERIFY(conn);
|
||||
|
||||
@@ -277,7 +279,7 @@ bool BLEUart::flushTXD(uint16_t conn_hdl)
|
||||
|
||||
if ( len )
|
||||
{
|
||||
result = _txd.notify(ff_data, len, conn_hdl);
|
||||
result = _txd.notify(conn_hdl, ff_data, len);
|
||||
}
|
||||
|
||||
rtos_free(ff_data);
|
||||
|
||||
@@ -66,7 +66,9 @@ class BLEUart : public BLEService, public Stream
|
||||
void setNotifyCallback(notify_callback_t fp);
|
||||
|
||||
void bufferTXD(bool enable);
|
||||
bool flushTXD (uint16_t conn_hdl = BLE_CONN_HANDLE_INVALID);
|
||||
|
||||
bool flushTXD (void);
|
||||
bool flushTXD (uint16_t conn_hdl);
|
||||
|
||||
// Stream API
|
||||
virtual int read ( void );
|
||||
@@ -76,8 +78,8 @@ class BLEUart : public BLEService, public Stream
|
||||
virtual size_t write ( uint8_t b );
|
||||
virtual size_t write ( const uint8_t *content, size_t len);
|
||||
|
||||
virtual size_t write ( uint8_t b, uint16_t conn_hdl);
|
||||
virtual size_t write ( const uint8_t *content, size_t len, uint16_t conn_hdl);
|
||||
virtual size_t write (uint16_t conn_hdl, uint8_t b);
|
||||
virtual size_t write (uint16_t conn_hdl, const uint8_t *content, size_t len);
|
||||
|
||||
virtual int available ( void );
|
||||
virtual int peek ( void );
|
||||
|
||||
Reference in new issue
Block a user