-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmpost_process.go
More file actions
220 lines (191 loc) · 5.89 KB
/
mpost_process.go
File metadata and controls
220 lines (191 loc) · 5.89 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package mpost
import (
"github.com/hard-soft-ware/mpost/acceptor"
"github.com/hard-soft-ware/mpost/bill"
"github.com/hard-soft-ware/mpost/enum"
"github.com/hard-soft-ware/mpost/hook"
)
////////////////////////////////////
func (a *MpostObj) processData0(data0 byte) {
if (data0 & 0x01) != 0 {
if acceptor.Device.State != enum.StateCalibrating && acceptor.Device.State != enum.StateCalibrateStart {
acceptor.Device.State = enum.StateIdling
}
}
if (data0 & 0x02) != 0 {
if acceptor.Device.State != enum.StateCalibrating && acceptor.Device.State != enum.StateCalibrateStart {
acceptor.Device.State = enum.StateAccepting
}
}
if (data0 & 0x04) != 0 {
acceptor.Device.State = enum.StateEscrow
if acceptor.AutoStack {
hook.Escrow = false
}
} else {
hook.Escrow = true
}
if (data0 & 0x08) != 0 {
acceptor.Device.State = enum.StateStacking
}
if (data0 & 0x10) != 0 {
acceptor.Device.State = enum.StateStacked
} else {
hook.Stacked = true
}
if (data0 & 0x20) != 0 {
acceptor.Device.State = enum.StateReturning
}
if (data0 & 0x40) != 0 {
acceptor.Device.State = enum.StateReturned
bill.Reset() // Resetting the bill
} else {
hook.Returned = true
}
}
func (a *MpostObj) processData1(data1 byte) {
if (data1 & 0x01) != 0 {
acceptor.IsCheated = true
} else {
acceptor.IsCheated = false
hook.Cheated = true
}
if (data1 & 0x02) != 0 {
acceptor.Device.State = enum.StateRejected
} else {
hook.Rejected = true
}
if (data1 & 0x04) != 0 {
acceptor.Device.Jammed = true
hook.JamDetected = true
} else {
acceptor.Device.Jammed = false
hook.JamCleared = true
}
if (data1 & 0x08) != 0 {
acceptor.Cash.BoxFull = true
} else {
acceptor.Cash.BoxFull = false
hook.StackerFull = true
}
acceptor.Cash.BoxAttached = (data1 & 0x10) != 0
if !acceptor.Cash.BoxAttached {
// Assume a DocumentType exists that handles this
// _DocType = NoValue
}
if (data1 & 0x20) != 0 {
acceptor.Device.Paused = true
hook.PauseCleared = true
} else {
acceptor.Device.Paused = false
hook.PauseDetected = true
}
if (data1 & 0x40) != 0 {
acceptor.Device.State = enum.StateCalibrating
if hook.CalibrateProgress {
hook.Raise.Calibrate.Progress()
}
} else {
if acceptor.Device.State == enum.StateCalibrating {
hook.CalibrateFinish = true
acceptor.Device.State = enum.StateIdling
}
}
}
func (a *MpostObj) processData2(data2 byte) {
if !acceptor.ExpandedNoteReporting {
billTypeIndex := (data2 & 0x38) >> 3
if billTypeIndex > 0 {
if acceptor.Device.State == enum.StateEscrow || (acceptor.Device.State == enum.StateStacked && !acceptor.WasDocTypeSetOnEscrow) {
bill.Bill = bill.Types[billTypeIndex-1]
a.DocType = enum.DocumentBill
acceptor.WasDocTypeSetOnEscrow = acceptor.Device.State == enum.StateEscrow
}
} else {
if acceptor.Device.State == enum.StateStacked || acceptor.Device.State == enum.StateEscrow {
bill.Reset()
a.DocType = enum.DocumentNoValue
acceptor.WasDocTypeSetOnEscrow = false
}
}
} else {
if acceptor.Device.State == enum.StateStacked {
if a.DocType == enum.DocumentBill && bill.Bill.Value == 0.0 {
a.DocType = enum.DocumentNoValue
}
} else if acceptor.Device.State == enum.StateEscrow {
bill.Reset()
a.DocType = enum.DocumentNoValue
}
}
if (data2 & 0x01) != 0 {
acceptor.IsPoweredUp = true
a.DocType = enum.DocumentNoValue
} else {
hook.PowerUp = true
if !acceptor.IsVeryFirstPoll {
acceptor.IsPoweredUp = false
}
}
if (data2 & 0x02) != 0 {
acceptor.IsInvalidCommand = true
} else {
acceptor.IsInvalidCommand = false
hook.InvalidCommand = true
}
if (data2 & 0x04) != 0 {
acceptor.Device.State = enum.StateFailed
}
}
func (a *MpostObj) processData3(data3 byte) {
if (data3 & 0x01) != 0 {
acceptor.Device.State = enum.StateStalled
hook.StallCleared = true
} else {
hook.StallDetected = true
}
if (data3 & 0x02) != 0 {
acceptor.Device.State = enum.StateDownloadRestart
}
if (data3 & 0x08) != 0 {
acceptor.Cap.BarCodesExt = true
}
if (data3 & 0x10) != 0 {
acceptor.IsQueryDeviceCapabilitiesSupported = true
}
}
func (a *MpostObj) processData4(data4 byte) {
acceptor.Device.Model = int(data4 & 0x7F)
m := acceptor.Device.Model
d := m
acceptor.Cap.ApplicationPN = m == 'T' || m == 'U'
acceptor.Cap.AssetNumber = m == 'T' || m == 'U'
acceptor.Cap.Audit = m == 'T' || m == 'U'
acceptor.Cap.BarCodes = m == 'T' || m == 'U' || d == 15 || d == 23
acceptor.Cap.Bookmark = true
acceptor.Cap.BootPN = m == 'T' || m == 'U'
acceptor.Cap.Calibrate = true
acceptor.Cap.CashBoxTotal = m == 'A' || m == 'B' || m == 'C' || m == 'D' || m == 'G' || m == 'M' || m == 'P' || m == 'W' || m == 'X'
acceptor.Cap.CouponExt = m == 'P' || m == 'X'
acceptor.Cap.DevicePaused = m == 'P' || m == 'X' || d == 31
acceptor.Cap.DeviceSoftReset = m == 'A' || m == 'B' || m == 'C' || m == 'D' || m == 'G' || m == 'M' || m == 'P' || m == 'T' || m == 'U' || m == 'W' || m == 'X' || d == 31
acceptor.Cap.DeviceType = m == 'T' || m == 'U'
acceptor.Cap.DeviceResets = m == 'A' || m == 'B' || m == 'C' || m == 'D' || m == 'G' || m == 'M' || m == 'P' || m == 'T' || m == 'U' || m == 'W' || m == 'X'
acceptor.Cap.DeviceSerialNumber = m == 'T' || m == 'U'
acceptor.Cap.FlashDownload = true
acceptor.Cap.EscrowTimeout = m == 'T' || m == 'U'
acceptor.Cap.NoPush = m == 'P' || m == 'X' || d == 31 || d == 23
acceptor.Cap.VariantPN = m == 'T' || m == 'U'
acceptor.ExpandedNoteReporting = m == 'T' || m == 'U' // This setting might be toggled in debug or production builds
}
func (a *MpostObj) processData5(data5 byte) {
switch {
case acceptor.Device.Model < 23, // S1K
acceptor.Device.Model == 30 || acceptor.Device.Model == 31, // S3K
acceptor.Device.Model == 74, // CFMC
acceptor.Device.Model == 84 || acceptor.Device.Model == 85: // CFSC
acceptor.Device.Revision = int(data5 & 0x7F)
default: // S2K
acceptor.Device.Revision = int(data5&0x0F) + (int(data5&0x70)>>4)*10
}
}