-
Notifications
You must be signed in to change notification settings - Fork 5
/
bau.js
114 lines (98 loc) · 4.51 KB
/
bau.js
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
const genmega = require('./build/Release/genmega.node')
const return_codes = require('./return_codes')
const return_messages = require('./return_messages')
exports.open = serialPortName => {
const { return_int, data } = genmega.BAUOpenV2(serialPortName);
const return_code = return_codes[return_int]
const return_message = return_messages[return_int]
console.log('BAU Firmware Version: ', data);
if (return_int < 0) console.error('BAU OPEN: ', return_int);
return { return_int, return_code, return_message };
}
exports.close = () => genmega.BAUCloseV2()
exports.reset = () => {
const { return_int } = genmega.BAUResetV2();
const return_code = return_codes[return_int]
const return_message = return_messages[return_int]
if (return_int < 0) console.error(`BAU RESET: ${return_code} (${return_int}): ${return_message}`)
return { return_int, return_code, return_message };
}
exports.getLastError = () => {
const { data } = genmega.BAUGetLastErrorV2();
return data
}
exports.status = () => {
const { return_int, data } = genmega.BAUStatusV2();
const return_code = return_codes[return_int]
const return_message = return_messages[return_int]
if (return_int < 0) console.error(`BAU STATUS: ${return_code} (${return_int}): ${return_message}`)
if (data === "") console.log(`BAU STATUS EMPTY!`)
/* NOTE: order matters; see src/devices/bill-validator.cpp:BAUStatus() */
const [
bLineStatus,
bIdling,
bAccepting,
bEscrow,
bStacking,
bReturning,
bJammed,
bStackerFull,
bCassetteAttached,
bPaused,
bCalibration,
bFailure,
bPushNoPush,
bFlashDownload,
] = data
const result = { bLineStatus, bIdling, bAccepting, bEscrow, bStacking, bReturning, bJammed, bStackerFull, bCassetteAttached, bPaused, bCalibration, bFailure, bPushNoPush, bFlashDownload }
return { return_int, return_code, return_message, result };
}
exports.setCapabilities = (escrow_enabled) => {
const { return_int } = genmega.BAUSetCapabilitiesV2(escrow_enabled)
const return_code = return_codes[return_int]
const return_message = return_messages[return_int]
if (return_int < 0) console.error(`BAU SET CAPABILITIES: ${return_code} (${return_int}): ${return_message}`)
return { return_int, return_code, return_message }
}
exports.setEnableDenom = (denominationData) => {
const { return_int } = genmega.BAUSetEnableDenomV2(denominationData);
const return_code = return_codes[return_int]
const return_message = return_messages[return_int]
if (return_int < 0) console.error(`BAU SET ENABLE DENOM: ${return_code} (${return_int}): ${return_message}`);
return { return_int, return_code, return_message }
}
exports.cancel = () => {
const { return_int, data } = genmega.BAUCancelV2();
const return_code = return_codes[return_int]
const return_message = return_messages[return_int]
if (return_int < 0) console.error(`BAU CANCEL BILL: ${return_code} (${return_int}): ${return_message}`);
return { return_int, return_code, return_message, data }
}
exports.acceptBill = mode => {
const { return_int, data } = genmega.BAUAcceptBillV2(mode);
const return_code = return_codes[return_int]
const return_message = return_messages[return_int]
if (return_int < 0) console.error(`BAU ACCEPT BILL: ${return_code} (${return_int}): ${return_message}`);
return { return_int, return_code, return_message, data }
}
exports.reject = () => {
const { return_int } = genmega.BAUReturnBillV2();
const return_code = return_codes[return_int]
const return_message = return_messages[return_int]
if (return_int < 0) console.error(`BAU RETURN BILL: ${return_code} (${return_int}): ${return_message}`);
return { return_int, return_code, return_message }
}
exports.stack = () => {
const { return_int } = genmega.BAUStackBillV2();
const return_code = return_codes[return_int]
const return_message = return_messages[return_int]
if (return_int < 0) console.error(`BAU STACK BILL: ${return_code} (${return_int}): ${return_message}`);
return { return_int, return_code, return_message }
}
exports.getSupportCurrency = () => {
const { return_int, data } = genmega.BAUGetSupportCurrencyV2();
const return_code = return_codes[return_int]
const return_message = return_messages[return_int]
if (return_int < 0) console.error(`BAU GET SUPPORT CURRENCY: ${return_code} (${return_int}): ${return_message}`);
return { return_int, return_code, return_message, data }
}