-
Notifications
You must be signed in to change notification settings - Fork 3
/
SerPro-example.cpp
73 lines (59 loc) · 1.48 KB
/
SerPro-example.cpp
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
73
#include <iostream>
#include "SerProHDLC.h"
#include "SerProPacket.h"
#include "SerPro.h"
#include "crc16.h"
class SerialWrapper
{
public:
static void write(uint8_t v);
static void write(const unsigned char *buf, unsigned int size);
static void flush();
};
struct SerProConfig {
static unsigned int const maxFunctions = 4;
static unsigned int const maxPacketSize = 32;
static unsigned int const stationId = 3; /* Only for HDLC */
};
DECLARE_SERPRO( SerProConfig, SerialWrapper, SerProHDLC, SerPro);
DECLARE_FUNCTION(0)(int a, int b, int c) {
std::cerr<<"METHOD 0: A(int) "<<a<<",B(int) "<<b<<",C(int) "<<c<<std::endl;
SerPro::send(1,a,c,b);
}
END_FUNCTION
DECLARE_FUNCTION(1)( int a, int b, int c) {
std::cerr<<"METHOD 1: A(int) "<<a<<",B(int) "<<b<<",C(int) "<<c<<std::endl;
SerPro::send(2,c,b,a);
}
END_FUNCTION
DECLARE_FUNCTION(2)( int a, int b, int c ) {
std::cerr<<"METHOD 2: Empty function"<<std::endl;
SerPro::send(3);
}
END_FUNCTION
DECLARE_FUNCTION(3)(void) {
std::cerr<<"METHOD 3: END"<<std::endl;
}
END_FUNCTION
IMPLEMENT_SERPRO(4,SerPro,SerProHDLC);
static SerPro serpro;
void SerialWrapper::write(uint8_t v)
{
SerPro::processData(v);
}
void SerialWrapper::flush()
{
fflush(stdout);
}
void SerialWrapper::write(const unsigned char *buf, unsigned int size)
{
}
int main()
{
int myints[3];
myints[0] = 0x7E7D7D7E; // Special case. Will cause lots of escapes
myints[1] = -60;
myints[2] = 32178632;
char buffer[40];
serpro.callFunction(0, (unsigned char*)&myints,1 );
}