-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryProtocol.h
More file actions
executable file
·49 lines (39 loc) · 1017 Bytes
/
Copy pathBinaryProtocol.h
File metadata and controls
executable file
·49 lines (39 loc) · 1017 Bytes
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
46
47
48
/*
BinaryProtocol.h - Library for binary comunication
Created by Filip Richter
Released into the public domain.
*/
#ifndef BinaryProtocol_h
#define BinaryProtocol_h
#include "Arduino.h"
#define BUFFER_SIZE 256
#define ESCAPE_CHAR 27
#define START_CHAR 1
#define END_CHAR 4
#if BUFFER_SIZE > 256
#define POINTER_TYPE int
#else
#define POINTER_TYPE byte
#endif
class BinaryProtocol
{
public:
BinaryProtocol(Stream &s);
BinaryProtocol(Stream &s, void (*callback)(byte data[], POINTER_TYPE len));
void sendPacket(byte data[],POINTER_TYPE len);
void sendIRQ(byte irq);
void doWork();
void setCallback(void (*callback)(byte data[], POINTER_TYPE len));
void setIrqCallback(void (*callbackIrq)(byte code));
private:
void parse(byte b);
void addByte(byte b);
byte buffer[BUFFER_SIZE];
POINTER_TYPE pointer;
bool escaped;
bool decoding;
Stream& _s;
void (*_callback)(byte data[], POINTER_TYPE len);
void (*_callbackIrq)(byte code);
};
#endif