-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogramprotocol.h
56 lines (41 loc) · 949 Bytes
/
programprotocol.h
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
#ifndef PROGRAMPROTOCOL_H
#define PROGRAMPROTOCOL_H
#include <QByteArray>
#include <QString>
#include "qglobal.h"
namespace Protocol {
const char ValidationString[3+1] = {"MSG"};
typedef struct{
char validationString[sizeof(ValidationString)];
quint16 size;
}header_t;
typedef struct{
quint16 btn;
quint8 press;
}data_t;
int headerSize()
{
return sizeof(ValidationString) + sizeof(quint16);
}
int dataSize()
{
return sizeof(quint16) + sizeof(quint8);
}
header_t deserializeHeader(char* serialized)
{
QString str = serialized;
header_t header;
strcpy(header.validationString,str.mid(0,3).toLocal8Bit().data());
header.size = str.mid(3,3).toInt();
return header;
}
data_t deserializeData(char* serializedData)
{
QString str = serializedData;
data_t data;
data.btn = str.mid(0,2).toInt();
data.press = str.at(2) == 'S' ? 1 : 0;
return data;
}
}
#endif // PROGRAMPROTOCOL_H