-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMessage.cpp
More file actions
62 lines (55 loc) · 895 Bytes
/
CMessage.cpp
File metadata and controls
62 lines (55 loc) · 895 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
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "CMessage.h"
const char* StrMessage[] ={
"None",
"Start",
"Angles",
"Height,roll",
"Roll",
"Stabilize at",
"Stiff stabilize",
"All",
"Empty",
"Reset",
"Stop",
"Quit",
"Learn",
"Traverse",
"Turn",
"Select camera",
"ABS Position",
"Number"
};
CMessage::CMessage()
{
type = MSG_NONE;
for (int i = 0;i<MESSAGE_LENGTH/3;i++)value[i]=0;
}
CMessage::~CMessage()
{
}
const char * CMessage::getStrType()
{
return StrMessage[type];
}
void CMessage::pack()
{
buf[0] = type;
for (int i = 0;i<MESSAGE_LENGTH/3;i++){
if (value[i] < 0) {
value[i] = - value[i];
buf[i*3+3] = 1;
}else{
buf[i*3+3] = 0;
}
buf[i*3+1] = value[i]%256;
buf[i*3+2] = value[i]/256;
}
}
void CMessage::unpack()
{
type = (TMessageType)buf[0];
for (int i = 0;i<MESSAGE_LENGTH/3;i++){
value[i] = buf[3*i+1] + buf[3*i+2]*256;
if (buf[3*i+3] > 0) value[i] = - value[i];
}
}