pfodParser 3.61.0 The pfodParser library is handles commands sent from the Android pfodApp, pfodApp supports WiFi, BLE, Bluetooth and SMS connections

pfodBLEBufferedSerial.h
Go to the documentation of this file.
1 #ifndef pfodBLEBufferedSerial_h
2 #define pfodBLEBufferedSerial_h
9 #include "pfodStream.h"
10
11 // This class will block if buffer is full
12 // because there is a 0.2sec delay between sending each 20 byte block
13 // a full buffer can result in noticable delays in processing the loop() method
14
15 class pfodBLEBufferedSerial : public Stream {
16
17 public:
18 // pfodBLEBufferedSerial use malloc to allocate buffer, if malloc fails then default static 32byte buffer is used.
19 // malloc uses dynamic memory not already used by variables, i.e. bytes free for local variables
20 // but need to leave some bytes for local variables, say 300 or so, after malloc
21 // for example if compiler shows "leaving 1135 bytes for local variables" then use pfodBLEBufferedSerial(800) or less
22 // pfod messages are ALWAYS less then 1024 bytes so the buffer size NEVER needs to be larger then 1024
23 // the sample pfod messages at the top of the pfodDesigner generated code give you an idea of the length of the messages being sent.
24
25 pfodBLEBufferedSerial(); // default 1024 byte buffer and default send delay 200mS
26 pfodBLEBufferedSerial(size_t _bufferSize); // set buffer size (min size is 32) and use default send delay 200mS
27 pfodBLEBufferedSerial* connect(Stream* _stream);
28 virtual size_t write(uint8_t); // this blocks if buffer full
29 virtual size_t write(const uint8_t *buf, size_t size); // this blocks if buffer full
30 virtual int available();
31 virtual int read();
32 virtual int peek();
33 virtual void flush();
34 void setDebugStream(Print* out);
35 size_t bytesToBeSent(); // bytes in buffer to be sent
36 static const size_t BLE_SEND_BLOCK_SIZE = 20; // BLE msg size
37 void clearTxBuffer();
38 void setBLEBlockSendDelay(uint16_t count); // NOTE: count is number of 1.25mS to delay between send blocks of BLE data
39 // this number should be > maxConnection interval number so previous block is picked up prior to sending next one.
40 // must be call BEFORE connect() is called, otherwise ignored
41 protected:
42 Stream* stream;
43 void sendAfterDelay();
44 size_t _write(uint8_t c);
45 size_t bufferSize;
46 size_t sendBufferIdxHead;
47 size_t sendBufferIdxTail;
48 uint8_t sendBlock[BLE_SEND_BLOCK_SIZE];
49 uint8_t* sendBuffer; // allow for terminating null
50 Print* debugOut;
51 unsigned long sendDelay_uS;
52
53 private:
54 static const unsigned long DEFAULT_BLE_SEND_DELAY_TIME = 200; // 200mS delay between 20byte msgs
55 bool connectCalled;
56 static const size_t PFOD_DEFAULT_SEND_BUFFER_SIZE = 1024; // Max data size pfodApp msg
57 static const size_t defaultBufferSize = 32; // BLE msg size
58 uint8_t defaultBuffer[defaultBufferSize]; // if malloc fails
59 unsigned long sendTimerStart;
60 bool timerRunning = false;
61 void setBuffer(size_t _bufferSize);
62 };
63
64 #endif // pfodBLEBufferedSerial_h
pfodBLEBufferedSerial
(c)2015 Forward Computing and Control Pty.
Definition: pfodBLEBufferedSerial.h:15
pfodBLEBufferedSerial::BLE_SEND_BLOCK_SIZE
static const size_t BLE_SEND_BLOCK_SIZE
Definition: pfodBLEBufferedSerial.h:36
pfodBLEBufferedSerial::flush
virtual void flush()
pfodBLEBufferedSerial::sendBuffer
uint8_t * sendBuffer
Definition: pfodBLEBufferedSerial.h:49
pfodBLEBufferedSerial::sendBlock
uint8_t sendBlock[BLE_SEND_BLOCK_SIZE]
Definition: pfodBLEBufferedSerial.h:48
pfodBLEBufferedSerial::write
virtual size_t write(uint8_t)
pfodBLEBufferedSerial::sendBufferIdxTail
size_t sendBufferIdxTail
Definition: pfodBLEBufferedSerial.h:47
pfodBLEBufferedSerial::debugOut
Print * debugOut
Definition: pfodBLEBufferedSerial.h:50
pfodBLEBufferedSerial::sendDelay_uS
unsigned long sendDelay_uS
Definition: pfodBLEBufferedSerial.h:51
pfodBLEBufferedSerial::pfodBLEBufferedSerial
pfodBLEBufferedSerial()
pfodBLEBufferedSerial::peek
virtual int peek()
pfodBLEBufferedSerial::stream
Stream * stream
Definition: pfodBLEBufferedSerial.h:42
pfodBLEBufferedSerial::bytesToBeSent
size_t bytesToBeSent()
pfodBLEBufferedSerial::pfodBLEBufferedSerial
pfodBLEBufferedSerial(size_t _bufferSize)
pfodBLEBufferedSerial::sendBufferIdxHead
size_t sendBufferIdxHead
Definition: pfodBLEBufferedSerial.h:46
pfodBLEBufferedSerial::_write
size_t _write(uint8_t c)
pfodBLEBufferedSerial::connect
pfodBLEBufferedSerial * connect(Stream *_stream)
pfodBLEBufferedSerial::write
virtual size_t write(const uint8_t *buf, size_t size)
pfodBLEBufferedSerial::read
virtual int read()
pfodBLEBufferedSerial::setDebugStream
void setDebugStream(Print *out)
pfodBLEBufferedSerial::bufferSize
size_t bufferSize
Definition: pfodBLEBufferedSerial.h:45
pfodBLEBufferedSerial::clearTxBuffer
void clearTxBuffer()
pfodBLEBufferedSerial::available
virtual int available()
pfodBLEBufferedSerial::setBLEBlockSendDelay
void setBLEBlockSendDelay(uint16_t count)
pfodBLEBufferedSerial::sendAfterDelay
void sendAfterDelay()
pfodStream.h