-
Notifications
You must be signed in to change notification settings - Fork 4
/
ICT_Protocol.h
75 lines (66 loc) · 1.91 KB
/
ICT_Protocol.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
#ifndef ICT_PROTOCOL_INCLUDED
#define ICT_PROTOCOL_INCLUDED
#include <iostream>
#include <map>
#include <stdint.h>
#include <sstream>
#include <time.h>
#include "SerialPort.h"
#include "config.h"
#include "Logger.h"
#include "ConfigReader.h"
class ICT_Protocol{
public:
enum CommunicationLineState{
COMMUNICATION_STATE_UNKNOWN=2,
COMMUNICATION_STATE_ALIVE=1,
COMMUNICATION_STATE_BROKEN=0
};
enum DeviceEnableState{
DEVICE_STATE_UNKNOWN=2,
DEVICE_STATE_ENABLED=1,
DEVICE_STATE_DISABLED=0
};
//Messages from the reader
enum MessageCodesDevice{
MSG_DEVICE_POWERUP=0x80,
MSG_DEVICE_COMM_FAILURE=0x26,
MSG_DEVICE_ESCROW=0x81,
MSG_DEVICE_BILL_ACCEPT_FINISH=0x10,
MSG_DEVICE_BILL_ACCEPT_FAILURE=0x11,
MSG_DEVICE_STATUS_RESP_ENABLED=0x3e,
MSG_DEVICE_STATUS_RESP_INHIBIT=0x5e
};
//messages from the driver
enum MessageCodesController{
MSG_CTRL_PWRUP_COMMFAIL_RESPONSE=0x02,
MSG_CTRL_BILL_REQUEST_ACCEPT=0x02,
MSG_CTRL_BILL_REQUEST_REJECT=0x0f,
MSG_CTRL_ENABLE_ACCEPTOR_REQ=0x3e,
MSG_CTRL_DISABLE_ACCEPTOR_REQ=0x5e,
MSG_CTRL_STATUS_REQ=0x0C,
MSG_CTRL_RESET_DEVICE=0x30
};
ICT_Protocol();
bool init(string serialPortName);
void run();
private:
void die();
bool portReadByte(unsigned char &data);
bool sendMessage(ICT_Protocol::MessageCodesController messageCode);
void parseInput(unsigned char data);
bool sendEnableAcceptor();
bool sendDisableAcceptor();
bool sendBillAccept();
bool sendBillReject();
bool sendResetDevice();
CommunicationLineState commLineState;
CommunicationLineState lastCommLineState;
DeviceEnableState deviceInhibitState;
DeviceEnableState lastDeviceInhibitState;
uint32_t commErrorCounter;
SerialPort port;
time_t sendTime;
time_t currentTime;
};
#endif