implemented read() support for BLECentralUart
This commit is contained in:
1 parent
be42b0a360
commit
c8e0d8f537
3 files changed
+62
-4
No files matched your search
@@ -40,7 +40,7 @@
|
|||||||
#include "BLEUuid.h"
|
#include "BLEUuid.h"
|
||||||
#include "BLECharacteristic.h"
|
#include "BLECharacteristic.h"
|
||||||
|
|
||||||
// forward declaration
|
// Forward declaration
|
||||||
class BLECentralService;
|
class BLECentralService;
|
||||||
|
|
||||||
class BLECentralCharacteristic
|
class BLECentralCharacteristic
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
#include "bluefruit.h"
|
#include "bluefruit.h"
|
||||||
|
|
||||||
BLECentralUart::BLECentralUart(uint16_t fifo_depth)
|
BLECentralUart::BLECentralUart(uint16_t fifo_depth)
|
||||||
: BLECentralService(BLEUART_UUID_SERVICE), _txd(), _rxd(), _rxd_fifo(fifo_depth, 1)
|
: BLECentralService(BLEUART_UUID_SERVICE), _txd(), _rxd(), _fifo(fifo_depth, 1)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,10 @@ err_t BLECentralUart::begin(void)
|
|||||||
|
|
||||||
void bleuart_central_notify_cb(BLECentralCharacteristic& chr, uint8_t* data, uint16_t len)
|
void bleuart_central_notify_cb(BLECentralCharacteristic& chr, uint8_t* data, uint16_t len)
|
||||||
{
|
{
|
||||||
|
BLECentralUart& uart_svc = (BLECentralUart&) chr.parentService();
|
||||||
|
uart_svc._fifo.write(data, len);
|
||||||
|
|
||||||
|
// invoke callback
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BLECentralUart::discover(uint16_t start_handle)
|
bool BLECentralUart::discover(uint16_t start_handle)
|
||||||
@@ -93,3 +96,43 @@ bool BLECentralUart::enableNotify(void)
|
|||||||
{
|
{
|
||||||
return _txd.enableNotify();
|
return _txd.enableNotify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------*/
|
||||||
|
/* STREAM API
|
||||||
|
*------------------------------------------------------------------*/
|
||||||
|
int BLECentralUart::read (void)
|
||||||
|
{
|
||||||
|
uint8_t ch;
|
||||||
|
return read(&ch, 1) ? (int) ch : EOF;
|
||||||
|
}
|
||||||
|
|
||||||
|
int BLECentralUart::read (uint8_t * buf, size_t size)
|
||||||
|
{
|
||||||
|
return _fifo.read(buf, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t BLECentralUart::write (uint8_t b)
|
||||||
|
{
|
||||||
|
return write(&b, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t BLECentralUart::write (const uint8_t *content, size_t len)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
int BLECentralUart::available (void)
|
||||||
|
{
|
||||||
|
return _fifo.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
int BLECentralUart::peek (void)
|
||||||
|
{
|
||||||
|
uint8_t ch;
|
||||||
|
return _fifo.peek(&ch) ? (int) ch : EOF;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLECentralUart::flush (void)
|
||||||
|
{
|
||||||
|
_fifo.clear();
|
||||||
|
}
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
|
|
||||||
#include "services/BLEUart.h"
|
#include "services/BLEUart.h"
|
||||||
|
|
||||||
class BLECentralUart : public BLECentralService
|
class BLECentralUart : public BLECentralService, public Stream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BLECentralUart(uint16_t fifo_depth = BLE_UART_DEFAULT_FIFO_DEPTH);
|
BLECentralUart(uint16_t fifo_depth = BLE_UART_DEFAULT_FIFO_DEPTH);
|
||||||
@@ -54,11 +54,26 @@ class BLECentralUart : public BLECentralService
|
|||||||
|
|
||||||
bool enableNotify(void);
|
bool enableNotify(void);
|
||||||
|
|
||||||
|
// Stream API
|
||||||
|
virtual int read ( void );
|
||||||
|
virtual int read ( uint8_t * buf, size_t size );
|
||||||
|
virtual size_t write ( uint8_t b );
|
||||||
|
virtual size_t write ( const uint8_t *content, size_t len );
|
||||||
|
virtual int available ( void );
|
||||||
|
virtual int peek ( void );
|
||||||
|
virtual void flush ( void );
|
||||||
|
|
||||||
|
// pull in write(str) and write(buf, size) from Print
|
||||||
|
using Print::write;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BLECentralCharacteristic _txd;
|
BLECentralCharacteristic _txd;
|
||||||
BLECentralCharacteristic _rxd;
|
BLECentralCharacteristic _rxd;
|
||||||
|
|
||||||
Adafruit_FIFO _rxd_fifo;
|
Adafruit_FIFO _fifo;
|
||||||
|
|
||||||
|
friend void bleuart_central_notify_cb(BLECentralCharacteristic& chr, uint8_t* data, uint16_t len);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* BLECENTRALUART_H_ */
|
#endif /* BLECENTRALUART_H_ */
|
||||||
Reference in new issue
Block a user