-
Notifications
You must be signed in to change notification settings - Fork 3
/
serpro.pde
72 lines (55 loc) · 1.27 KB
/
serpro.pde
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "SerPro.h"
#include "SerProPacket.h"
#include "SerProHDLC.h"
class SerialWrapper
{
public:
static inline void write(uint8_t v){
Serial.write(v);
};
static inline void flush(){
};
};
// 4 functions
// 32 bytes maximum receive buffer size
struct SerProConfig {
static unsigned int const maxFunctions = 4;
static unsigned int const maxPacketSize = 32;
static unsigned int const stationId = 3;
};
// SerialWrapper is class to handle tx
// Name of class is SerPro
// Protocol type is SerProPacket or SerProHDLC
DECLARE_SERPRO(SerProConfig,SerialWrapper,SerProHDLC,SerPro);
DECLARE_FUNCTION(0)(int a, int b, int c) {
SerPro::send(0, a+b+c);
}
END_FUNCTION
DECLARE_FUNCTION(1)(int a, int b) {
SerPro::send(1, a+b);
}
END_FUNCTION
DECLARE_FUNCTION(2)(void) {
SerPro::send(2);
}
END_FUNCTION
DECLARE_FUNCTION(3)(int a, char *b) {
SerPro::send(3, b, a+1);
SerPro::send<uint8_t>(4, a+1); // Enforce int argument to be a uint8_t
}
END_FUNCTION
// Implementation - 4 functions, name SerPro, protocol SerProHDLC.
// Make sure this agrees with DECLARE statement.
IMPLEMENT_SERPRO(4,SerPro,SerProHDLC);
const int ledPin = 13;
void setup()
{
Serial.begin(115200);
pinMode(ledPin,OUTPUT);
}
void loop()
{
if (Serial.available()>0) {
SerPro::processData(Serial.read());
}
}