-
Notifications
You must be signed in to change notification settings - Fork 1
/
matrixjxj.cpp
106 lines (101 loc) · 2.29 KB
/
matrixjxj.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "serialmatrix.h"
#include "keyboardswitchmessage.h"
#include "keyboardptzmessage.h"
#include "log.h"
static int toPacket(char *buf, KeyboardSwitchMessage &msg)
{
buf[0] = 0xff;
buf[1] = 0x00;
buf[2] = 0x11;
buf[3] = 0x00;
buf[4] = (char)msg.camera();
buf[5] = (char)msg.monitor();
buf[6] = 0x55;
buf[7] = buf[1] + buf[2] + buf[3] + buf[4] + buf[5] + buf[6];
return 0;
}
static int toPacket(char *buf, KeyboardPtzMessage &msg)
{
buf[0] = 0xff;
buf[1] = 0x00;
buf[2] = 0x21;
buf[3] = 0x00;
buf[5] = 0x00;
buf[6] = 0x00;
// zoom param
if(msg.zoomInSpeed())
buf[3] = 0x40;
else if(msg.zoomOutSpeed())
buf[3] = 0x80;
// camera id
buf[4] = (char)msg.camera();
// v operation
if(msg.hSpeed() > 0)
buf[5] = msg.hSpeed();
else if(msg.hSpeed() < 0)
buf[5] = 0x80 - msg.hSpeed();
// h operation
if(msg.vSpeed() > 0)
buf[6] = msg.vSpeed();
else if(msg.vSpeed() < 0)
buf[6] = 0x80 - msg.vSpeed();
buf[7] = buf[1] + buf[2] + buf[3] + buf[4] + buf[5] + buf[6];
return 0;
}
class MatrixJXJ : public SerialMatrix {
public:
MatrixJXJ(Postable *receiver, ModuleInfo *info) : SerialMatrix(receiver, info) {}
virtual int onReadable(SerialPort& sp)
{
char queries = 0;
static char buf[8] = {0xff, 0x00, 0x11, 0x00, 0x01, 0x01, 0x55, 0x68};
char reg[] = {0xff, 0x00, 0x41, 0x11, 0x55, 0x00, 0x00, 0xa7};
static int rcv_cnt = 0;
Message *msg;
int len = sp.read(&queries, 1);
assert(len == 1);
if(rcv_cnt == 0)
{
if((queries & 0xff) != 0x50)
return 0;
assert(sp.write(reg, 8) == 8);
rcv_cnt++;
}
else if((0xff & queries) == 0x50)
{
if(mFifo.tryget(msg) == 0)
{
KeyboardSwitchMessage *smsg = dynamic_cast<KeyboardSwitchMessage*>(msg);
if(smsg)
{
toPacket(buf, *smsg);
}
else {
KeyboardPtzMessage *pmsg = dynamic_cast<KeyboardPtzMessage*>(msg);
if(pmsg)
{
toPacket(buf, *pmsg);
}
}
delete msg;
}
sp.write(buf, 8);
}
return 0;
}
virtual int onExcept(SerialPort& sp)
{
ErrLog("serial port has encounter a problem!");
}
};
/*
class MatrixJXJFactory : public MatrixFactory {
public:
virtual Matrix* create(Postable *receiver) {
if(mInfo)
return new MatrixJXJ(receiver, mInfo);
return NULL;
}
} _factory;
*/
DECL_MATRIX_FACTORY(MatrixJXJ)