tcMenu
BaseBufferedRemoteTransport.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 https://www.thecoderscorner.com (Dave Cherry).
3  * This product is licensed under an Apache license, see the LICENSE file in the top-level directory.
4  */
5 
11 #ifndef TCMENU_BASEBUFFEREDREMOTETRANSPORT_H
12 #define TCMENU_BASEBUFFEREDREMOTETRANSPORT_H
13 
14 #include <RemoteConnector.h>
15 #define TICKS_TO_FLUSH_WRITE 140
16 
17 namespace tcremote {
18 
19  enum BufferingMode : uint8_t {
20  BUFFER_ONE_MESSAGE, BUFFER_MESSAGES_TILL_FULL
21  };
22 
28  public:
37  virtual int encryptData(const uint8_t *plainText, int bytesIn, const uint8_t *buffer, size_t buffLen) = 0;
46  virtual int decryptData(const uint8_t *encoded, int bytesIn, const uint8_t *buffer, size_t buffLen) = 0;
47  };
48 
49 
57  protected:
58  const uint16_t writeBufferSize;
59  const uint16_t readBufferSize;
60  uint8_t *readBuffer;
61  uint8_t *writeBuffer;
62  uint8_t *encryptionBuffer;
63  uint16_t writeBufferPos;
64  uint16_t readBufferPos;
65  uint16_t encryptionBufferPos;
66  uint16_t readBufferAvail;
67  EncryptionHandler* encryptionHandler;
68  BufferingMode mode;
69  uint8_t ticksSinceWrite;
70  public:
71  BaseBufferedRemoteTransport(BufferingMode bufferMode, uint8_t readBufferSize, uint8_t writeBufferSize,
72  EncryptionHandler* encHandler = nullptr);
73 
74  ~BaseBufferedRemoteTransport() override;
75 
76  void endMsg() override;
77 
78  int writeChar(char data) override;
79 
80  int writeStr(const char *data) override;
81 
82  uint8_t readByte() override;
83 
84  bool readAvailable() override;
85 
86  void close() override;
87 
88  void flushIfRequired();
89 
90  void flushInternal();
91 
92  virtual int fillReadBuffer(uint8_t *dataBuffer, int maxSize) = 0;
93  };
94 }
95 
96 #endif //TCMENU_BASEBUFFEREDREMOTETRANSPORT_H
Contains the base functionality for communication between the menu library and remote APIs.
Definition: RemoteConnector.h:141
Definition: BaseBufferedRemoteTransport.h:56
Definition: BaseBufferedRemoteTransport.h:27
virtual int encryptData(const uint8_t *plainText, int bytesIn, const uint8_t *buffer, size_t buffLen)=0
virtual int decryptData(const uint8_t *encoded, int bytesIn, const uint8_t *buffer, size_t buffLen)=0