-
Notifications
You must be signed in to change notification settings - Fork 2
/
sspcoms.h
131 lines (107 loc) · 3.74 KB
/
sspcoms.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef SSPCOMS_H
#define SSPCOMS_H
#include <functional>
#include <QList>
#include <QQueue>
#include <QThread>
#include <QMutex>
#include <QMutexLocker>
#include <QWaitCondition>
#include <QtSerialPort/QtSerialPort>
#include <openssl/aes.h>
#include <openssl/bn.h>
class SSPComsTask;
class SSPEvent;
class TimeoutException {};
class SSPComs : public QThread {
Q_OBJECT
Q_PROPERTY(bool terminate READ terminate WRITE setTerminate)
QSerialPort *m_port;
QSerialPortInfo m_portInfo;
public:
explicit SSPComs(const QSerialPortInfo &info);
~SSPComs();
enum Result {
ok = 0xf0,
commandNotKnown = 0xf2,
wrongNumberOfParameters = 0xf3,
parameterOutOfRange = 0xf4,
commandCannotBeProcessed = 0xf5,
softwareError = 0xf6,
fail = 0xf8,
keyNotSet = 0xfa
};
enum Result_Payout {
payoutOk = -1,
notEnoughValue = 0,
cannotPayAmount = 1,
deviceBusy = 3,
deviceDisabled = 4
};
enum Result_Route {
deviceError = -3,
invalidCurrency = -2,
notConnected = -1,
recycled = 0,
cashbox = 1
};
void startConnection();
bool terminate() const { return m_terminate; }
void setTerminate(bool terminate);
void reset(std::function<void()> callback);
void disable(std::function<void()> callback);
void enable(std::function<void()> callback);
void datasetVersion(std::function<void(const QString&)> callback);
void firmwareVersion(std::function<void(const QString&)> callback);
void emptyAll(std::function<void()> callback);
void displayOn(std::function<void()> callback);
void displayOff(std::function<void()> callback);
Result_Payout payout(uint32_t amount, bool test=false);
uint32_t getDenominationLevel(uint32_t denomination, const QString ¤cy);
Result_Route getDenominationRoute(uint32_t denomination, const QString ¤cy);
uint32_t getMinimalPayout(const QString ¤cy);
void setCoinInhibits(bool inhibited, uint32_t denomination, const QString ¤cy);
struct PayoutDenomination {
uint32_t number;
uint32_t denomination; // in cents
QString currency;
};
Result_Payout payoutByDenomination(const QList<PayoutDenomination> &requests);
void smartEmpty();
void poll(std::function<void(QList<QSharedPointer<SSPEvent>>)> callback);
uint32_t getSerialNumber();
QString getFirmwareVersion();
const QList<PayoutDenomination> getAllLevels();
bool setDenominationLevel(uint32_t numToAdd, uint32_t denomination, const QString ¤cy);
void haltPayout();
Result_Payout floatAmount(unsigned minPayout, uint32_t totalAmount, const QString ¤cy, bool test=false);
void emptyAll();
void setCoinMechGlobalInhibit(bool enable);
QList<PayoutDenomination> cashboxPayoutOperationData(); // after smartEmpty, emptyAll, floatAmount, "dispense"
protected:
void run();
signals:
void terminating();
private:
bool m_terminate;
QQueue<SSPComsTask*> m_taskQueue;
QMutex m_taskQueueMutex;
QWaitCondition m_taskQueueUpdatedCondition;
bool m_sequence;
bool open();
void enqueueTask(const QByteArray &data, const std::function<void(uint8_t, const QByteArray&)> &response);
QByteArray readResponse();
bool sendCommand(uint8_t slave_id, const QByteArray &cmd, bool retry=false);
uint16_t calculateCRC(const QByteArray &p, uint16_t seed, uint16_t cd);
bool sync();
// encryption
bool m_encryptionEnabled;
QByteArray m_key;
uint32_t m_encryptionCount;
QByteArray encrypt(const QByteArray &cmd, bool retry);
QByteArray decrypt(const QByteArray &cmd);
void negotiateEncryption(uint64_t fixedKey);
BN_CTX *m_bn_ctx;
Q_DISABLE_COPY(SSPComs)
};
#endif // SSPCOMS_H