-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.h
76 lines (64 loc) · 1.45 KB
/
command.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef COMMAND_H
#define COMMAND_H
#include <QObject>
#include <QTimerEvent>
#include "bytearray.h"
// Команды
#define CMD_INIT 0x30
#define CMD_CARD 0x31
#define CMD_MAGTRACK 0x32
#define CMD_LED 0x33
/*
#define CMD_ 0x34
#define CMD_ 0x35
#define CMD_ 0x36
#define CMD_ 0x
*/
#define CMD_SHUTTER 0x40
#define CMD_TIMER 0x57
// Маркеры пакетов
#define CMD_BYTE_STX 0xF2
#define CMD_BYTE_ACK 0x06
#define CMD_BYTE_DLE 0x10
#define CMD_BYTE_EOT 0x04
#define CMD_BYTE_NAK 0x15
// Смещения
#define CMD_OFFSET_CODE 4
// Таймауты (мс)
#define CMD_TM_WRITE 10
#define CMD_TM_ERROR 1000
class Command : public QObject
{
Q_OBJECT
public:
enum AnswerType
{
AnswerNone = 0x2,
AnswerACK = 0x4,
AnswerFull = 0x8,
AnswerDLE = 0x10,
AnswerAll = 0xFF
};
Command(QObject *parent, const ByteArray &cmd, const ByteArray &data);
Command(const Command &cmd);
inline unsigned char code() const { return m_code; }
inline unsigned char param() const { return m_param; }
void send(int timeout = -1);
void setNext(Command *next);
void setTimeout(int timeout);
inline Command *next() const { return m_next; }
bool answerType(int answerType) const;
signals:
void send(ByteArray);
protected:
void timerEvent(QTimerEvent *event);
private:
unsigned char m_code;
unsigned char m_param;
ByteArray m_cmd;
Command *m_next;
int m_waitbytes;
int m_answerType;
int m_timeout;
};
#endif // COMMAND_H