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;
44  size_t _write(uint8_t c);
45  size_t bufferSize;
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
(c)2015 Forward Computing and Control Pty.
static const size_t BLE_SEND_BLOCK_SIZE
virtual void flush()
uint8_t sendBlock[BLE_SEND_BLOCK_SIZE]
virtual size_t write(uint8_t)
virtual int peek()
pfodBLEBufferedSerial(size_t _bufferSize)
size_t _write(uint8_t c)
pfodBLEBufferedSerial * connect(Stream *_stream)
virtual size_t write(const uint8_t *buf, size_t size)
virtual int read()
void setDebugStream(Print *out)
virtual int available()
void setBLEBlockSendDelay(uint16_t count)