-
Notifications
You must be signed in to change notification settings - Fork 0
/
cardreader.h
91 lines (77 loc) · 1.98 KB
/
cardreader.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef CARDREADER_H
#define CARDREADER_H
#include <QObject>
#include "qextserialport.h"
#include "bytearray.h"
#include "command.h"
// Таймауты (мс)
#define CR_TM_READCHAR 250
#define CR_TM_OPEN 800
#define CR_TM_WAITCARD "00060000" // 8 символов
#define CR_TM_EJECTCARD "00060000" // 8 символов
#define CR_CARDNUM_LENGTH 16
class Cardreader : public QObject
{
Q_OBJECT
public:
Cardreader(const QString &tty, QObject *parent = 0);
~Cardreader();
void init();
inline QString cardnum() { return m_cardnum; }
signals:
void initFailed();
void initSucceeded();
void cardInserted();
void cardEject(bool);
void cardEjected();
public slots:
protected:
void timerEvent(QTimerEvent *event);
private:
struct
{
bool initialized;
} m_state;
enum ReadMode
{
ReadNone,
ReadResponse,
ReadLength,
ReadData,
ReadCrc
} m_reading;
enum Error
{
ErrorNak,
ErrorCrc
};
QextSerialPort *m_tty;
int m_waitbytes, m_rtimer;
ByteArray m_rcvbuf, m_rheader, m_rdata;
Command *m_lastCmd, *m_curCmd;
QString m_cardnum;
bool read(ByteArray &buffer);
void skip(int bytes = 1);
inline void flush() { m_tty->flush(); m_rcvbuf.clear(); }
void sendCmd(const ByteArray &cmd, const ByteArray &data, Command *prev = NULL);
void sendCmd(const ByteArray &data, Command *prev = NULL);
void queueCmd(Command *cmd, Command *prev);
void repeatCmd(int timeout = CMD_TM_ERROR);
void handleData();
void nextMode(enum ReadMode mode, int bytes = 0);
void handleMsg(const ByteArray &block);
void handleResponse(bool positive = true);
void handleError(enum Error error);
void handleCurCmd(int answerType);
void stopTimer(int *timer, bool condition = true);
void reset();
void handleCard(unsigned char param, int errcode);
void ready();
private slots:
void initContinue();
void read();
void writeCmd(ByteArray cmd);
void ejectCard(bool err = false);
void ejectCardError();
};
#endif // CARDREADER_H