Skip to content

Commit 009eff9

Browse files
proper check for available packets
1 parent c37292f commit 009eff9

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

utility/BLEStream.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
44
Based on BLESerial.cpp by Voita Molda
55
https://github.com/sandeepmistry/arduino-BLEPeripheral/blob/master/examples/serial/BLESerial.cpp
6+
7+
Last updated by Jeff Hoefs: February 28th, 2016
68
*/
79

810
#include "BLEStream.h"
@@ -21,7 +23,6 @@ BLEStream::BLEStream(unsigned char req, unsigned char rdy, unsigned char rst) :
2123
this->_txCount = 0;
2224
this->_rxHead = this->_rxTail = 0;
2325
this->_flushed = 0;
24-
this->_packetTxCount = 0;
2526
BLEStream::_instance = this;
2627

2728
addAttribute(this->_uartService);
@@ -111,21 +112,9 @@ void BLEStream::flush(void)
111112
{
112113
if (this->_txCount == 0) return;
113114
#ifndef _VARIANT_ARDUINO_101_X_
114-
long diff = millis() - this->_flushed;
115-
// flush() is called approximately every 1ms or less when sending multiple packets and
116-
// otherwise no more frequently than BLESTREAM_TXBUFFER_FLUSH_INTERVAL
117-
// TODO - determine if 2 is the best value or if something higher is necessary
118-
if (diff < 2) {
119-
// 2 is the max number of packets that can be sent in short succession
120-
// TODO - get the max packet value programatically
121-
if (++this->_packetTxCount >= 2) {
122-
// delay after 2 packets have been sent in short succession
123-
// 100ms is the minimum necessary delay value
124-
delay(100);
125-
this->_packetTxCount = 0;
126-
}
127-
} else {
128-
this->_packetTxCount = 0;
115+
// ensure there are available packets before sending
116+
while(!this->_txCharacteristic.canNotify()) {
117+
BLEPeripheral::poll();
129118
}
130119
#endif
131120
this->_txCharacteristic.setValue(this->_txBuffer, this->_txCount);

utility/BLEStream.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
44
Based on BLESerial.cpp by Voita Molda
55
https://github.com/sandeepmistry/arduino-BLEPeripheral/blob/master/examples/serial/BLESerial.h
6+
7+
Last updated by Jeff Hoefs: February 28th, 2016
68
*/
79

810
#ifndef _BLE_STREAM_H_
@@ -53,8 +55,6 @@ class BLEStream : public BLEPeripheral, public Stream
5355
size_t _txCount;
5456
unsigned char _txBuffer[_MAX_ATTR_DATA_LEN_];
5557

56-
uint8_t _packetTxCount;
57-
5858
BLEService _uartService = BLEService("6E400001-B5A3-F393-E0A9-E50E24DCCA9E");
5959
BLEDescriptor _uartNameDescriptor = BLEDescriptor("2901", "UART");
6060
BLECharacteristic _rxCharacteristic = BLECharacteristic("6E400002-B5A3-F393-E0A9-E50E24DCCA9E", BLEWriteWithoutResponse, _MAX_ATTR_DATA_LEN_);

0 commit comments

Comments
 (0)