Loading...
Searching...
No Matches
SLPacker.hpp
1#ifndef __SLPACKER_H
2#define __SLPACKER_H
3#include <stdint.h>
4#include <string.h>
5#include <stddef.h>
6#ifdef __AVR__
7 #define MAX_DATA_LENGHT 64
8#else
9 #define MAX_DATA_LENGHT 100
10#endif
11
12
13 class SLPacker
14{
15 private:
16 enum SLSteps
17 {
18 UNDEF,
19 GET_CMD,
20 GET_DATA,
21 ESC_DATA
22 };
23 size_t bufIndex = 0;
24 SLSteps slStep = UNDEF;
25 static const uint8_t FEND = 0xC0;
26 static const uint8_t FESC = 0xDB;
27 static const uint8_t TFEND = 0xDC;
28 static const uint8_t TFESC = 0xDD;
29 static const uint8_t CMD_DATA = 0x00;
30 void writeToRxBuf(uint8_t data);
31 void resetState(uint8_t data);
32 size_t dataHandler(uint8_t data);
33 void escDataHandler(uint8_t data);
34
35 public:
36#ifdef __AVR__
37 // Note: The multiplication factor here should have been * 2 for worst-case scenarios,
38 // but due to memory constraints on AVR Arduino, a compromise was made, and just an additional 20 bytes were added.
39 uint8_t buf[MAX_DATA_LENGHT + 20];
40#else
41 uint8_t buf[MAX_DATA_LENGHT * 2];
42#endif
43
44 size_t encode(uint8_t *writeBuffer, uint8_t const *readBuffer, size_t len);
45 static size_t encode(uint8_t *readBuffer, size_t len);
46 size_t decode(uint8_t data);
47};
48
49#endif /* __SLPACKER_H */
SLPacker
Definition SLPacker.hpp:14