-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPTPP.h
45 lines (37 loc) · 1005 Bytes
/
SPTPP.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
Simple PointToPoint Protocol
master/slave protocol for easy byte communication
Frame:
0xf0 - Write Command
0xaa - Read Command
0x55 - Response
Write:
0xf0 0x{adr} 0x{size} {... bytes ...} 0x{ CS1 } 0x{ CS2 }
Response:
0x0f 0x{size} 0x{ CS1 } 0x{ CS2 }
Read:
0xaa 0x{adr} 0x{size} 0x{ CS1 } 0x{ CS2 }
Response:
0x55 0x{size} {... bytes ...} 0x{ CS1 } 0x{ CS2 }
size = 0 when any error
*/
#include <Arduino.h>
class SPTPP {
public:
SPTPP(uint8_t* obj, int size, unsigned long timeout);
void GetedByte(uint8_t b);
private:
uint8_t* obj;
int size, pos, actSize;
uint8_t* buffer;
uint8_t* writeBuffer;
unsigned long lastTime, timeout;
int CheckFletcher16( uint8_t *data, int count );
uint8_t* Fletcher16( uint8_t *data, int count );
void RunRead();
void RunWrite();
void CheckNextBuffPosition();
void SetNewBuffer(int p);
void SendReadError();
void SendWriteError();
};