@danidoble/webserial 4.4.4 → 4.5.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/boardroid.cjs +1 -1
- package/dist/boardroid.js +4 -3
- package/dist/devices-BndwHuvP.cjs +1 -0
- package/dist/devices-CHc7K4eY.js +67 -0
- package/dist/hopper.cjs +1 -1
- package/dist/hopper.js +1 -1
- package/dist/jofemar.cjs +1 -1
- package/dist/jofemar.js +30 -29
- package/dist/jsd.cjs +1 -0
- package/dist/jsd.js +2443 -0
- package/dist/kernel-As0xv_MS.cjs +1 -0
- package/dist/{kernel-BZzs36vi.js → kernel-CFxkp4Nz.js} +147 -204
- package/dist/kernel.cjs +1 -1
- package/dist/kernel.js +4 -3
- package/dist/locker.cjs +1 -1
- package/dist/locker.js +12 -11
- package/dist/pinpad.cjs +11 -11
- package/dist/pinpad.js +684 -639
- package/dist/pinpax.cjs +2 -2
- package/dist/pinpax.js +4 -3
- package/dist/relay.cjs +1 -1
- package/dist/relay.js +8 -7
- package/dist/types/lib/commands/jsd/applications/licensing.d.ts +51 -0
- package/dist/types/lib/commands/jsd/applications/licensing.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/applications/manifest.d.ts +73 -0
- package/dist/types/lib/commands/jsd/applications/manifest.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/applications/vision.d.ts +444 -0
- package/dist/types/lib/commands/jsd/applications/vision.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/frames/licensing/licensingClient.d.ts +34 -0
- package/dist/types/lib/commands/jsd/frames/licensing/licensingClient.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/frames/licensing/opCodes.d.ts +28 -0
- package/dist/types/lib/commands/jsd/frames/licensing/opCodes.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/frames/manifest/manifestClient.d.ts +40 -0
- package/dist/types/lib/commands/jsd/frames/manifest/manifestClient.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/frames/manifest/opCodes.d.ts +28 -0
- package/dist/types/lib/commands/jsd/frames/manifest/opCodes.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/frames/vision/opCodes.d.ts +72 -0
- package/dist/types/lib/commands/jsd/frames/vision/opCodes.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/frames/vision/visionClient.d.ts +336 -0
- package/dist/types/lib/commands/jsd/frames/vision/visionClient.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/protocol/crc16.d.ts +37 -0
- package/dist/types/lib/commands/jsd/protocol/crc16.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/protocol/responseHandler.d.ts +38 -0
- package/dist/types/lib/commands/jsd/protocol/responseHandler.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/protocol/rs232Strategy.d.ts +23 -0
- package/dist/types/lib/commands/jsd/protocol/rs232Strategy.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/protocol/tcpIpStrategy.d.ts +49 -0
- package/dist/types/lib/commands/jsd/protocol/tcpIpStrategy.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/types/LicensingClient.d.ts +32 -0
- package/dist/types/lib/commands/jsd/types/LicensingClient.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/types/jsd.types.d.ts +140 -0
- package/dist/types/lib/commands/jsd/types/jsd.types.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/types/manifestClient.d.ts +40 -0
- package/dist/types/lib/commands/jsd/types/manifestClient.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/types/transport.types.d.ts +29 -0
- package/dist/types/lib/commands/jsd/types/transport.types.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/types/visionClient.types.d.ts +356 -0
- package/dist/types/lib/commands/jsd/types/visionClient.types.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/utils/aplications.d.ts +48 -0
- package/dist/types/lib/commands/jsd/utils/aplications.d.ts.map +1 -0
- package/dist/types/lib/commands/jsd/utils/helpers.d.ts +15 -0
- package/dist/types/lib/commands/jsd/utils/helpers.d.ts.map +1 -0
- package/dist/types/lib/kernel.d.ts.map +1 -0
- package/dist/types/{main.d.ts → lib/main.d.ts} +6 -0
- package/dist/types/lib/main.d.ts.map +1 -0
- package/dist/types/lib/parsers/delimiterTransformer.d.ts +29 -0
- package/dist/types/lib/parsers/delimiterTransformer.d.ts.map +1 -0
- package/dist/types/lib/serial/boardroid.d.ts.map +1 -0
- package/dist/types/lib/serial/hopper.d.ts.map +1 -0
- package/dist/types/lib/serial/jofemar.d.ts.map +1 -0
- package/dist/types/lib/serial/jsd.d.ts +40 -0
- package/dist/types/lib/serial/jsd.d.ts.map +1 -0
- package/dist/types/{serial → lib/serial}/kernel.d.ts +1 -0
- package/dist/types/{serial → lib/serial}/kernel.d.ts.map +1 -1
- package/dist/types/lib/serial/locker.d.ts.map +1 -0
- package/dist/types/lib/serial/pinpad.d.ts.map +1 -0
- package/dist/types/lib/serial/pinpax.d.ts.map +1 -0
- package/dist/types/lib/serial/relay.d.ts.map +1 -0
- package/dist/types/{utils → lib/utils}/devices.d.ts +2 -0
- package/dist/types/lib/utils/devices.d.ts.map +1 -0
- package/dist/types/lib/utils/dispatcher.d.ts.map +1 -0
- package/dist/types/lib/utils/emulator.d.ts.map +1 -0
- package/dist/types/lib/utils/utils.d.ts.map +1 -0
- package/dist/types/test/t.d.ts +2 -0
- package/dist/types/test/t.d.ts.map +1 -0
- package/dist/webserial-core-3UL91lxi.cjs +4 -0
- package/dist/{webserial-core-Zwd9L-Y9.js → webserial-core-DSv1dX3s.js} +160 -148
- package/dist/webserial.cjs +1 -1
- package/dist/webserial.js +29 -23
- package/package.json +15 -10
- package/dist/kernel-7ObJp74F.cjs +0 -1
- package/dist/types/kernel.d.ts.map +0 -1
- package/dist/types/main.d.ts.map +0 -1
- package/dist/types/serial/boardroid.d.ts.map +0 -1
- package/dist/types/serial/hopper.d.ts.map +0 -1
- package/dist/types/serial/jofemar.d.ts.map +0 -1
- package/dist/types/serial/locker.d.ts.map +0 -1
- package/dist/types/serial/pinpad.d.ts.map +0 -1
- package/dist/types/serial/pinpax.d.ts.map +0 -1
- package/dist/types/serial/relay.d.ts.map +0 -1
- package/dist/types/utils/devices.d.ts.map +0 -1
- package/dist/types/utils/dispatcher.d.ts.map +0 -1
- package/dist/types/utils/emulator.d.ts.map +0 -1
- package/dist/types/utils/utils.d.ts.map +0 -1
- package/dist/webserial-core-Co8HLQvu.cjs +0 -4
- /package/dist/types/{kernel.d.ts → lib/kernel.d.ts} +0 -0
- /package/dist/types/{serial → lib/serial}/boardroid.d.ts +0 -0
- /package/dist/types/{serial → lib/serial}/hopper.d.ts +0 -0
- /package/dist/types/{serial → lib/serial}/jofemar.d.ts +0 -0
- /package/dist/types/{serial → lib/serial}/locker.d.ts +0 -0
- /package/dist/types/{serial → lib/serial}/pinpad.d.ts +0 -0
- /package/dist/types/{serial → lib/serial}/pinpax.d.ts +0 -0
- /package/dist/types/{serial → lib/serial}/relay.d.ts +0 -0
- /package/dist/types/{utils → lib/utils}/dispatcher.d.ts +0 -0
- /package/dist/types/{utils → lib/utils}/emulator.d.ts +0 -0
- /package/dist/types/{utils → lib/utils}/utils.d.ts +0 -0
package/dist/jsd.js
ADDED
|
@@ -0,0 +1,2443 @@
|
|
|
1
|
+
import { T as O } from "./webserial-core-DSv1dX3s.js";
|
|
2
|
+
import { D as k } from "./devices-CHc7K4eY.js";
|
|
3
|
+
class T {
|
|
4
|
+
/**
|
|
5
|
+
* Byte order configuration
|
|
6
|
+
* - true: Big Endian (high byte first) - Current JSD firmware
|
|
7
|
+
* - false: Little Endian (low byte first)
|
|
8
|
+
*/
|
|
9
|
+
static USE_BIG_ENDIAN = !0;
|
|
10
|
+
/**
|
|
11
|
+
* CRC algorithm type
|
|
12
|
+
* - false: Non-reflected/MSB-first with polynomial 0x8005 - Current JSD firmware
|
|
13
|
+
* - true: Reflected/LSB-first with polynomial 0xA001 (reflected 0x8005)
|
|
14
|
+
*/
|
|
15
|
+
static USE_REFLECTED = !1;
|
|
16
|
+
/**
|
|
17
|
+
* Calculate CRC-16 based on configuration flags.
|
|
18
|
+
* @param bytes - Array of bytes to calculate CRC for.
|
|
19
|
+
* @returns [firstByte, secondByte] - Order depends on USE_BIG_ENDIAN setting.
|
|
20
|
+
*/
|
|
21
|
+
static calculate(e) {
|
|
22
|
+
let t;
|
|
23
|
+
if (this.USE_REFLECTED) {
|
|
24
|
+
t = 0;
|
|
25
|
+
for (const s of e) {
|
|
26
|
+
t ^= s & 255;
|
|
27
|
+
for (let n = 0; n < 8; n++)
|
|
28
|
+
t & 1 ? t = t >> 1 ^ 40961 : t >>= 1;
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
t = 0;
|
|
32
|
+
for (const s of e) {
|
|
33
|
+
t ^= s << 8;
|
|
34
|
+
for (let n = 0; n < 8; n++)
|
|
35
|
+
t & 32768 ? t = (t << 1 ^ 32773) & 65535 : t = t << 1 & 65535;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return this.USE_BIG_ENDIAN ? [t >> 8 & 255, t & 255] : [t & 255, t >> 8 & 255];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get current configuration info (for debugging).
|
|
42
|
+
* @returns Object containing configuration flags.
|
|
43
|
+
*/
|
|
44
|
+
static getConfig() {
|
|
45
|
+
return {
|
|
46
|
+
bigEndian: this.USE_BIG_ENDIAN,
|
|
47
|
+
reflected: this.USE_REFLECTED
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
class b {
|
|
52
|
+
/**
|
|
53
|
+
* Application ID for Vision Machines (Snacks, PPEs, Supplies, Medicines, etc.)
|
|
54
|
+
* Each Jofemar application has its specific protocol and application number
|
|
55
|
+
* APP_ID = 402 → Vision
|
|
56
|
+
* APP_ID = 601 → Manifest & Log of events
|
|
57
|
+
* @see APP_NO
|
|
58
|
+
*/
|
|
59
|
+
_name = "tcpip";
|
|
60
|
+
get name() {
|
|
61
|
+
return this._name;
|
|
62
|
+
}
|
|
63
|
+
get packetId() {
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
_overridePacketId(e) {
|
|
67
|
+
console.warn(`TCP/IP transport does not use packet IDs. Ignoring override to ${e}.`);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Convert number to 2 bytes Little Endian.
|
|
71
|
+
* Example: 10000 → 0x2710 → [0x10, 0x27].
|
|
72
|
+
* @param val - Number to convert.
|
|
73
|
+
* @returns Tuple of two numbers [lowByte, highByte].
|
|
74
|
+
*/
|
|
75
|
+
toLittleEndian(e) {
|
|
76
|
+
return [e & 255, e >> 8 & 255];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Build a packet for TCP/IP transport.
|
|
80
|
+
* @param opcode - Operation code.
|
|
81
|
+
* @param args - Arguments string.
|
|
82
|
+
* @param APP_ID - Application ID.
|
|
83
|
+
* @returns Array of numbers representing the packet.
|
|
84
|
+
*/
|
|
85
|
+
buildPacket(e, t, s) {
|
|
86
|
+
const n = t ? t.split("").map((h) => h.charCodeAt(0)) : [], a = 6 + n.length, i = this.toLittleEndian(a), c = this.toLittleEndian(s), o = this.toLittleEndian(e);
|
|
87
|
+
return {
|
|
88
|
+
bytes: [
|
|
89
|
+
...i,
|
|
90
|
+
// NumBytes (total chain length)
|
|
91
|
+
...c,
|
|
92
|
+
// App ID (402 for Vision)
|
|
93
|
+
...o,
|
|
94
|
+
// Opcode (e.g., 100 for machine status)
|
|
95
|
+
...n
|
|
96
|
+
// Data associated (ASCII args)
|
|
97
|
+
],
|
|
98
|
+
packetId: 0
|
|
99
|
+
// TCP/IP doesn't use packet IDs, but we include it for consistency
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Transparency (Byte Stuffing): 0xC0 -> 0xDB, 0xDC | 0xDB -> 0xDB, 0xDD.
|
|
104
|
+
* @param bytes - Array of bytes to escape.
|
|
105
|
+
* @returns Array of escaped bytes.
|
|
106
|
+
*/
|
|
107
|
+
escapeBytes(e) {
|
|
108
|
+
const t = [];
|
|
109
|
+
for (const s of e)
|
|
110
|
+
s === 192 ? t.push(219, 220) : s === 219 ? t.push(219, 221) : t.push(s);
|
|
111
|
+
return t;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Build an Acknowledge (ACK) packet.
|
|
115
|
+
* @param packetId - Packet ID to acknowledge.
|
|
116
|
+
* @returns Array of numbers representing the ACK packet.
|
|
117
|
+
*/
|
|
118
|
+
buildAckPacket(e) {
|
|
119
|
+
const n = [192, 2, e], [a, i] = T.calculate(n), c = [2, e, a, i];
|
|
120
|
+
return [192, ...this.escapeBytes(c), 192];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
class N extends b {
|
|
124
|
+
packetIdCounter = 1;
|
|
125
|
+
_name = "rs232";
|
|
126
|
+
get packetId() {
|
|
127
|
+
return this.packetIdCounter;
|
|
128
|
+
}
|
|
129
|
+
_overridePacketId(e) {
|
|
130
|
+
this.packetIdCounter = e & 255;
|
|
131
|
+
}
|
|
132
|
+
getNextPacketId() {
|
|
133
|
+
const e = this.packetIdCounter;
|
|
134
|
+
return this.packetIdCounter = this.packetIdCounter + 1 & 255, this.packetIdCounter === 0 && (this.packetIdCounter = 1), e;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Build a packet for RS232 transport.
|
|
138
|
+
* @param opcode - Operation code.
|
|
139
|
+
* @param args - Arguments string.
|
|
140
|
+
* @param APP_ID - Application ID.
|
|
141
|
+
* @returns Array of numbers representing the packet.
|
|
142
|
+
*/
|
|
143
|
+
buildPacket(e, t, s) {
|
|
144
|
+
const i = this.getNextPacketId(), { bytes: c } = super.buildPacket(e, t, s), o = [192, 1, i, ...c], [h, p] = T.calculate(o), l = [1, i, ...c, h, p];
|
|
145
|
+
return { bytes: [192, ...this.escapeBytes(l), 192], packetId: i };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const r = {
|
|
149
|
+
requestMachineStatus: 100,
|
|
150
|
+
requestStatusChannel: 101,
|
|
151
|
+
requestStatusSelection: 102,
|
|
152
|
+
configureSelectionDispense: 103,
|
|
153
|
+
addChannelToSelection: 104,
|
|
154
|
+
requestMachineIdentification: 105,
|
|
155
|
+
programWorkingTemperature: 106,
|
|
156
|
+
programWaitingTimings: 107,
|
|
157
|
+
resetSoldOutChannels: 108,
|
|
158
|
+
programTimeWaitingAfterPickup: 109,
|
|
159
|
+
requestJSDVersion: 110,
|
|
160
|
+
requestFaultMachine: 111,
|
|
161
|
+
manageJSDDispensingQueue: 112,
|
|
162
|
+
defineSpecialCharacteristicsSelection: 113,
|
|
163
|
+
configurePerishableProducts: 114,
|
|
164
|
+
requestActiveFaults: 115,
|
|
165
|
+
configureExtendedDispenseStatusData: 116,
|
|
166
|
+
requestStatusTrayPositioningPhototransistors: 117,
|
|
167
|
+
dispenseFromChannel: 150,
|
|
168
|
+
dispenseFromSelection: 151,
|
|
169
|
+
controlLights: 152,
|
|
170
|
+
resetFaultsAndSelfTest: 153,
|
|
171
|
+
performCollectCycle: 154,
|
|
172
|
+
dispenseFromChannelExtended: 155,
|
|
173
|
+
restartingTheJSDKnowingThatItIsDangerous: 156,
|
|
174
|
+
responseFormatCmdWrong: 200,
|
|
175
|
+
responseMachineStatus: 201,
|
|
176
|
+
responseStatusChannel: 202,
|
|
177
|
+
responseStatusSelection: 203,
|
|
178
|
+
responseDispenseStatus: 204,
|
|
179
|
+
responseConfigurationSelectionDispense: 205,
|
|
180
|
+
responseConfigurationChannelsLinkedToSelection: 206,
|
|
181
|
+
responseMachineIdentification: 207,
|
|
182
|
+
responseCurrentTemperature: 208,
|
|
183
|
+
responseReportEventsAlarmsAndFaults: 209,
|
|
184
|
+
responseNewTimingWaitingForProductCollection: 210,
|
|
185
|
+
responsePerformingProductCollectionCycle: 211,
|
|
186
|
+
responseResetMachineSoldOutChannels: 212,
|
|
187
|
+
responseNewTimingWaitingAfterProductCollection: 213,
|
|
188
|
+
responseJSDVersion: 214,
|
|
189
|
+
responseActiveFaults: 215,
|
|
190
|
+
responseJSDDispensingQueue: 216,
|
|
191
|
+
responseSpecialCharacteristicsSelection: 217,
|
|
192
|
+
responsePerishableProducts: 218,
|
|
193
|
+
responseActiveFaultsList: 219,
|
|
194
|
+
responseJSDResetStatus: 220,
|
|
195
|
+
responseExtendedDispenseStatusData: 221,
|
|
196
|
+
responseTraysPositioningPhototransistorsStatus: 222,
|
|
197
|
+
jsdErrorLicenseTemporarilyBlocked: 300,
|
|
198
|
+
jsdErrorLicenseNotActive: 301,
|
|
199
|
+
jsdErrorCommandNotExecutable: 302
|
|
200
|
+
}, C = (d) => Object.keys(r).find((t) => r[t] === d) || "Unknown", f = {
|
|
201
|
+
VISION: 402,
|
|
202
|
+
LICENSING: 600,
|
|
203
|
+
MANIFESTS_AND_LOGS: 601,
|
|
204
|
+
SIMULATOR_VISION: 1e4
|
|
205
|
+
}, L = (d) => [f.VISION, f.SIMULATOR_VISION].includes(d), F = (d) => [f.LICENSING].includes(d), w = (d) => [f.MANIFESTS_AND_LOGS].includes(d);
|
|
206
|
+
class u {
|
|
207
|
+
transport;
|
|
208
|
+
static APP_ID = f.VISION;
|
|
209
|
+
// Manifest & Logs Application ID
|
|
210
|
+
constructor(e) {
|
|
211
|
+
this.transport = e;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Alias to Opcode 100: Connection command (no data).
|
|
215
|
+
* @param options Object containing the machine index and transport protocol.
|
|
216
|
+
* @param options.machine Machine index (0-3).
|
|
217
|
+
* @param options.transport Transport protocol instance to use.
|
|
218
|
+
* @returns The generated packet as a number array.
|
|
219
|
+
*/
|
|
220
|
+
static connection({
|
|
221
|
+
transport: e,
|
|
222
|
+
packetId: t
|
|
223
|
+
}) {
|
|
224
|
+
return e._overridePacketId(t || 255), new u(e).requestJSDVersion();
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Opcode 100: Request machine status.
|
|
228
|
+
* @param options Object containing the machine index.
|
|
229
|
+
* @param options.machine Machine index (0-3).
|
|
230
|
+
* @returns The generated packet as a number array.
|
|
231
|
+
*/
|
|
232
|
+
requestMachineStatus({ machine: e }) {
|
|
233
|
+
const t = `${e}`;
|
|
234
|
+
return this.transport.buildPacket(r.requestMachineStatus, t, u.APP_ID);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Opcode 101: Request status of a specific channel.
|
|
238
|
+
* @param options Object containing the options.
|
|
239
|
+
* @param options.machine Machine index (0-3).
|
|
240
|
+
* @param options.tray Tray number (11-18).
|
|
241
|
+
* @param options.channel Channel number (0-9).
|
|
242
|
+
* @returns The generated packet as a number array.
|
|
243
|
+
*/
|
|
244
|
+
requestStatusChannel({ machine: e, tray: t, channel: s }) {
|
|
245
|
+
const n = `${e},${t},${s}`;
|
|
246
|
+
return this.transport.buildPacket(r.requestStatusChannel, n, u.APP_ID);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Opcode 102: Request status of a specific selection.
|
|
250
|
+
* @param options Object containing the options.
|
|
251
|
+
* @param options.selection Selection number (1-240).
|
|
252
|
+
* @returns The generated packet as a number array.
|
|
253
|
+
*/
|
|
254
|
+
requestStatusSelection({ selection: e }) {
|
|
255
|
+
const t = `${e}`;
|
|
256
|
+
return this.transport.buildPacket(r.requestStatusSelection, t, u.APP_ID);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Configure dispense parameters for a selection.
|
|
260
|
+
* @param options Object containing the options.
|
|
261
|
+
* @param options.selection Selection number (1-240).
|
|
262
|
+
* @param options.speed Speed of the dispense engine (0-21).
|
|
263
|
+
* @param options.timePostRun Time post run (0-255).
|
|
264
|
+
* @returns The generated packet as a number array.
|
|
265
|
+
*/
|
|
266
|
+
configureSelectionDispense({
|
|
267
|
+
selection: e,
|
|
268
|
+
speed: t,
|
|
269
|
+
timePostRun: s
|
|
270
|
+
}) {
|
|
271
|
+
const n = `${e},${t},${s}`;
|
|
272
|
+
return this.transport.buildPacket(r.configureSelectionDispense, n, u.APP_ID);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Get current dispense configuration for a selection.
|
|
276
|
+
* @param options Object containing the options.
|
|
277
|
+
* @param options.machine Machine index (0-3).
|
|
278
|
+
* @returns The generated packet as a number array.
|
|
279
|
+
*/
|
|
280
|
+
getSelectionDispenseConfig({ machine: e }) {
|
|
281
|
+
const t = `${e}`;
|
|
282
|
+
return this.transport.buildPacket(r.configureSelectionDispense, t, u.APP_ID);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Request to add a channel to a selection.
|
|
286
|
+
* @param options Object containing the options.
|
|
287
|
+
* @param options.selection Selection number (1-240).
|
|
288
|
+
* @param options.machine Machine index (0-3).
|
|
289
|
+
* @param options.tray Tray number (11-18).
|
|
290
|
+
* @param options.channel Channel number (0-9).
|
|
291
|
+
* @returns The generated packet as a number array.
|
|
292
|
+
*/
|
|
293
|
+
addChannelToSelection({ selection: e, machine: t, tray: s, channel: n }) {
|
|
294
|
+
const a = `${e},${t},${s},${n}`;
|
|
295
|
+
return this.transport.buildPacket(r.addChannelToSelection, a, u.APP_ID);
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Get channels linked to a selection.
|
|
299
|
+
* @param options Object containing the options.
|
|
300
|
+
* @param options.selection Selection number (1-240).
|
|
301
|
+
* @returns The generated packet as a number array.
|
|
302
|
+
*/
|
|
303
|
+
getChannelsLinkedToSelection({ selection: e }) {
|
|
304
|
+
const t = `${e}`;
|
|
305
|
+
return this.transport.buildPacket(r.addChannelToSelection, t, u.APP_ID);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Request machine identification.
|
|
309
|
+
* @param options Object containing the options.
|
|
310
|
+
* @param options.machine Machine index (0-3).
|
|
311
|
+
* @returns The generated packet as a number array.
|
|
312
|
+
*/
|
|
313
|
+
requestMachineIdentification({ machine: e }) {
|
|
314
|
+
const t = `${e}`;
|
|
315
|
+
return this.transport.buildPacket(r.requestMachineIdentification, t, u.APP_ID);
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Format temperature to +05.0 or -03.5
|
|
319
|
+
* @param temperature The temperature value to format.
|
|
320
|
+
* @returns The formatted date string (5 characters).
|
|
321
|
+
*/
|
|
322
|
+
formatTemperature(e) {
|
|
323
|
+
const t = e >= 0 ? "+" : "-", s = Math.abs(e).toFixed(1).padStart(4, "0");
|
|
324
|
+
return `${t}${s}`;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Program working temperature.
|
|
328
|
+
* @param options Object containing the options.
|
|
329
|
+
* @param options.machine Machine index (0-3).
|
|
330
|
+
* @param options.temperature The target temperature.
|
|
331
|
+
* @param options.enable Boolean indicating if the temperature control should be enabled (true) or disabled (false).
|
|
332
|
+
* @returns The generated packet as a number array.
|
|
333
|
+
*/
|
|
334
|
+
programWorkingTemperature({
|
|
335
|
+
machine: e,
|
|
336
|
+
temperature: t,
|
|
337
|
+
enable: s
|
|
338
|
+
}) {
|
|
339
|
+
const n = this.formatTemperature(t), i = `${e},${n},${s ? 1 : 0}`;
|
|
340
|
+
return this.transport.buildPacket(r.programWorkingTemperature, i, u.APP_ID);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Get working temperature.
|
|
344
|
+
* @param options Object containing the options.
|
|
345
|
+
* @param options.machine Machine index (0-3).
|
|
346
|
+
* @returns The generated packet as a number array.
|
|
347
|
+
*/
|
|
348
|
+
getWorkingTemperature({ machine: e }) {
|
|
349
|
+
const t = `${e}`;
|
|
350
|
+
return this.transport.buildPacket(r.programWorkingTemperature, t, u.APP_ID);
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Program waiting timings.
|
|
354
|
+
* @param options Object containing the options.
|
|
355
|
+
* @param options.collectPosition Time for collect position (1-10).
|
|
356
|
+
* @param options.dispenseManoeuvres Time for dispense manoeuvres (0-65).
|
|
357
|
+
* @param options.afterPickup Time waiting after pickup (1-255).
|
|
358
|
+
* @returns The generated packet as a number array.
|
|
359
|
+
*/
|
|
360
|
+
programWaitingTimings({
|
|
361
|
+
collectPosition: e,
|
|
362
|
+
dispenseManoeuvres: t,
|
|
363
|
+
afterPickup: s
|
|
364
|
+
}) {
|
|
365
|
+
const n = `${e},${t},${s}`;
|
|
366
|
+
return this.transport.buildPacket(r.programWaitingTimings, n, u.APP_ID);
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Get waiting timings.
|
|
370
|
+
* @returns The generated packet as a number array.
|
|
371
|
+
*/
|
|
372
|
+
getWaitingTimings() {
|
|
373
|
+
return this.transport.buildPacket(r.programWaitingTimings, "", u.APP_ID);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Reset sold-out status for all channels in a machine.
|
|
377
|
+
* @param options Object containing the options.
|
|
378
|
+
* @param options.machine Machine index (0-3).
|
|
379
|
+
* @returns The generated packet as a number array.
|
|
380
|
+
*/
|
|
381
|
+
resetSoldOutChannels({ machine: e }) {
|
|
382
|
+
const t = `${e}`;
|
|
383
|
+
return this.transport.buildPacket(r.resetSoldOutChannels, t, u.APP_ID);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Program time waiting after pickup.
|
|
387
|
+
* @param options Object containing the options.
|
|
388
|
+
* @param options.time Time in seconds (15-120).
|
|
389
|
+
* @returns The generated packet as a number array.
|
|
390
|
+
*/
|
|
391
|
+
programTimeWaitingAfterPickup({ time: e }) {
|
|
392
|
+
const t = `${e}`;
|
|
393
|
+
return this.transport.buildPacket(r.programTimeWaitingAfterPickup, t, u.APP_ID);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Get time waiting after pickup.
|
|
397
|
+
* @returns The generated packet as a number array.
|
|
398
|
+
*/
|
|
399
|
+
getTimeWaitingAfterPickup() {
|
|
400
|
+
return this.transport.buildPacket(r.programTimeWaitingAfterPickup, "", u.APP_ID);
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Opcode 110: Request JSD firmware version.
|
|
404
|
+
* Data: None.
|
|
405
|
+
* @returns The generated packet as a number array.
|
|
406
|
+
*/
|
|
407
|
+
requestJSDVersion() {
|
|
408
|
+
return this.transport.buildPacket(r.requestJSDVersion, "", u.APP_ID);
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Opcode 111: Request or clear machine faults.
|
|
412
|
+
* @param options Object containing the options.
|
|
413
|
+
* @param options.machine Machine index (0-3).
|
|
414
|
+
* @param options.type Type of operation: 'report-active', 'report-inactive', or 'clear-inactive'.
|
|
415
|
+
* @returns The generated packet as a number array.
|
|
416
|
+
*/
|
|
417
|
+
requestFaultMachine({ machine: e, type: t }) {
|
|
418
|
+
const n = `${e},${{
|
|
419
|
+
"report-active": 0,
|
|
420
|
+
"report-inactive": 1,
|
|
421
|
+
"clear-inactive": 2
|
|
422
|
+
}[t]}`;
|
|
423
|
+
return this.transport.buildPacket(r.requestFaultMachine, n, u.APP_ID);
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Request report of active faults.
|
|
427
|
+
* @param machine Machine index (0-3).
|
|
428
|
+
* @returns The generated packet as a number array.
|
|
429
|
+
*/
|
|
430
|
+
requestReportActiveFaults(e) {
|
|
431
|
+
return this.requestFaultMachine({ machine: e, type: "report-active" });
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Request report of inactive faults.
|
|
435
|
+
* @param machine Machine index (0-3).
|
|
436
|
+
* @returns The generated packet as a number array.
|
|
437
|
+
*/
|
|
438
|
+
requestReportInactiveFaults(e) {
|
|
439
|
+
return this.requestFaultMachine({ machine: e, type: "report-inactive" });
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Request to clear inactive faults.
|
|
443
|
+
* @param machine Machine index (0-3).
|
|
444
|
+
* @returns The generated packet as a number array.
|
|
445
|
+
*/
|
|
446
|
+
requestClearInactiveFaults(e) {
|
|
447
|
+
return this.requestFaultMachine({ machine: e, type: "clear-inactive" });
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Manage JSD dispensations requested list (product petitions queue).
|
|
451
|
+
* @param options Object containing the options.
|
|
452
|
+
* @param options.type Type of operation (0 = Request status, 1 = Clear queue).
|
|
453
|
+
* @returns The generated packet as a number array.
|
|
454
|
+
*/
|
|
455
|
+
manageJSDDispensingQueue({ type: e }) {
|
|
456
|
+
const t = `${e}`;
|
|
457
|
+
return this.transport.buildPacket(r.manageJSDDispensingQueue, t, u.APP_ID);
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Request JSD dispensing queue status.
|
|
461
|
+
* @returns The generated packet as a number array.
|
|
462
|
+
*/
|
|
463
|
+
requestJSDDispensingQueueStatus() {
|
|
464
|
+
return this.manageJSDDispensingQueue({ type: 0 });
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Clear JSD dispensing queue.
|
|
468
|
+
* @returns The generated packet as a number array.
|
|
469
|
+
*/
|
|
470
|
+
clearJSDDispensingQueue() {
|
|
471
|
+
return this.manageJSDDispensingQueue({ type: 1 });
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Define special characteristics for a selection.
|
|
475
|
+
* @param options Object containing the options.
|
|
476
|
+
* @param options.selection Selection number (1-240).
|
|
477
|
+
* @param options.perishable Boolean indicating if the product is perishable.
|
|
478
|
+
* @param options.fragileOrHeavy Boolean [false=standard, true=fragile/heavy] (if fragileOrHeavy is true, multidispense is disabled).
|
|
479
|
+
* @param options.typeAdjustElevator Type of elevator adjustment ('lower' | 'upper').
|
|
480
|
+
* @param options.timeAdjustElevator Time for elevator adjustment (in ms).
|
|
481
|
+
* @returns The generated packet as a number array.
|
|
482
|
+
*/
|
|
483
|
+
defineSpecialCharacteristicsSelection({
|
|
484
|
+
selection: e,
|
|
485
|
+
perishable: t,
|
|
486
|
+
fragileOrHeavy: s,
|
|
487
|
+
typeAdjustElevator: n,
|
|
488
|
+
timeAdjustElevator: a
|
|
489
|
+
}) {
|
|
490
|
+
const p = `${e},${t ? 1 : 0},${s ? 1 : 0},${n === "lower" ? 0 : 1},${a}`;
|
|
491
|
+
return this.transport.buildPacket(r.defineSpecialCharacteristicsSelection, p, u.APP_ID);
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Get special characteristics for a selection.
|
|
495
|
+
* @param options Object containing the options.
|
|
496
|
+
* @param options.selection Selection number (1-240).
|
|
497
|
+
* @returns The generated packet as a number array.
|
|
498
|
+
*/
|
|
499
|
+
getSpecialCharacteristicsSelection({ selection: e }) {
|
|
500
|
+
const t = `${e}`;
|
|
501
|
+
return this.transport.buildPacket(r.defineSpecialCharacteristicsSelection, t, u.APP_ID);
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Configure perishable products settings for a machine.
|
|
505
|
+
* @param options Object containing the options.
|
|
506
|
+
* @param options.machine Machine index (0-3).
|
|
507
|
+
* @param options.enable Boolean indicating whether to enable perishable product settings.
|
|
508
|
+
* @param options.temperatureLimit Temperature limit.
|
|
509
|
+
* @param options.minutesToExpiry Minutes to expiry.
|
|
510
|
+
* @returns The generated packet as a number array.
|
|
511
|
+
*/
|
|
512
|
+
configurePerishableProducts({
|
|
513
|
+
machine: e,
|
|
514
|
+
enable: t,
|
|
515
|
+
temperatureLimit: s,
|
|
516
|
+
minutesToExpiry: n
|
|
517
|
+
}) {
|
|
518
|
+
const a = t ? 1 : 0, i = this.formatTemperature(s), c = `${e},${a},${i},${n}`;
|
|
519
|
+
return this.transport.buildPacket(r.configurePerishableProducts, c, u.APP_ID);
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Request active faults for a machine.
|
|
523
|
+
* @param options Object containing the options.
|
|
524
|
+
* @param options.machine Machine index (0-3).
|
|
525
|
+
* @returns The generated packet as a number array.
|
|
526
|
+
*/
|
|
527
|
+
requestActiveFaults({ machine: e }) {
|
|
528
|
+
const t = `${e}`;
|
|
529
|
+
return this.transport.buildPacket(r.requestActiveFaults, t, u.APP_ID);
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Configure extended dispense status data.
|
|
533
|
+
* @param options Object containing the options.
|
|
534
|
+
* @param options.enable Boolean indicating whether to enable extended dispense status data.
|
|
535
|
+
* @returns The generated packet as a number array.
|
|
536
|
+
*/
|
|
537
|
+
configureExtendedDispenseStatusData({
|
|
538
|
+
enable: e
|
|
539
|
+
}) {
|
|
540
|
+
const s = `${e ? 1 : 0}`;
|
|
541
|
+
return this.transport.buildPacket(r.configureExtendedDispenseStatusData, s, u.APP_ID);
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Get extended dispense status data configuration.
|
|
545
|
+
* @returns The generated packet as a number array.
|
|
546
|
+
*/
|
|
547
|
+
getExtendedDispenseStatusDataConfig() {
|
|
548
|
+
return this.transport.buildPacket(r.configureExtendedDispenseStatusData, "", u.APP_ID);
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Request the status of the tray positioning phototransistors.
|
|
552
|
+
* @param options Object containing the options.
|
|
553
|
+
* @param options.machine Machine index (0-3).
|
|
554
|
+
* @returns The generated packet as a number array.
|
|
555
|
+
*/
|
|
556
|
+
requestStatusTrayPositioningPhototransistors({ machine: e }) {
|
|
557
|
+
const t = `${e}`;
|
|
558
|
+
return this.transport.buildPacket(
|
|
559
|
+
r.requestStatusTrayPositioningPhototransistors,
|
|
560
|
+
t,
|
|
561
|
+
u.APP_ID
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Request dispense from channel.
|
|
566
|
+
* @param options Object containing the options.
|
|
567
|
+
* @param options.token Token for tracking the request.
|
|
568
|
+
* @param options.machine Machine index (0-3).
|
|
569
|
+
* @param options.tray Tray number (11-18).
|
|
570
|
+
* @param options.channel Channel number (0-9).
|
|
571
|
+
* @param options.speed Speed of the dispense engine (0-21).
|
|
572
|
+
* @param options.timePostRun Time post run (0-255).
|
|
573
|
+
* @returns The generated packet as a number array.
|
|
574
|
+
*/
|
|
575
|
+
dispenseFromChannel({
|
|
576
|
+
token: e,
|
|
577
|
+
machine: t,
|
|
578
|
+
tray: s,
|
|
579
|
+
channel: n,
|
|
580
|
+
speed: a,
|
|
581
|
+
timePostRun: i
|
|
582
|
+
}) {
|
|
583
|
+
const c = `${e},${t},${s},${n},${a},${i}`;
|
|
584
|
+
return this.transport.buildPacket(r.dispenseFromChannel, c, u.APP_ID);
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Get dispense status from channel thought token.
|
|
588
|
+
* @param options Object containing the options.
|
|
589
|
+
* @param options.token Token for tracking the request.
|
|
590
|
+
* @returns The generated packet as a number array.
|
|
591
|
+
*/
|
|
592
|
+
getDispenseStatusFromChannel({ token: e }) {
|
|
593
|
+
const t = `${e}`;
|
|
594
|
+
return this.transport.buildPacket(r.dispenseFromChannel, t, u.APP_ID);
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Request dispense from selection.
|
|
598
|
+
* @param options Object containing the options.
|
|
599
|
+
* @param options.token Token for tracking the request.
|
|
600
|
+
* @param options.selection Selection number (1-240).
|
|
601
|
+
* @returns The generated packet as a number array.
|
|
602
|
+
*/
|
|
603
|
+
dispenseFromSelection({ token: e, selection: t }) {
|
|
604
|
+
const s = `${e},${t}`;
|
|
605
|
+
return this.transport.buildPacket(r.dispenseFromSelection, s, u.APP_ID);
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Get dispense status from selection thought token.
|
|
609
|
+
* @param options Object containing the options.
|
|
610
|
+
* @param options.token Token for tracking the request.
|
|
611
|
+
* @returns The generated packet as a number array.
|
|
612
|
+
*/
|
|
613
|
+
getDispenseStatusFromSelection({ token: e }) {
|
|
614
|
+
const t = `${e}`;
|
|
615
|
+
return this.transport.buildPacket(r.dispenseFromSelection, t, u.APP_ID);
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
/**
|
|
619
|
+
* Change lighting status.
|
|
620
|
+
* @param options Object containing the options.
|
|
621
|
+
* @param options.machine Machine index (0-3).
|
|
622
|
+
* @param options.turnOn Boolean indicating whether to turn the lights on (true) or off (false).
|
|
623
|
+
* @returns The generated packet as a number array.
|
|
624
|
+
*/
|
|
625
|
+
controlLights({ machine: e, turnOn: t }) {
|
|
626
|
+
const n = `${e},${t ? 1 : 0}`;
|
|
627
|
+
return this.transport.buildPacket(r.controlLights, n, u.APP_ID);
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
/**
|
|
631
|
+
* Reset faults and perform self-test.
|
|
632
|
+
* @param options Object containing the options.
|
|
633
|
+
* @param options.machine Machine index (0-3).
|
|
634
|
+
* @returns The generated packet as a number array.
|
|
635
|
+
*/
|
|
636
|
+
resetFaultsAndSelfTest({ machine: e }) {
|
|
637
|
+
const t = `${e}`;
|
|
638
|
+
return this.transport.buildPacket(r.resetFaultsAndSelfTest, t, u.APP_ID);
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
/**
|
|
642
|
+
* Perform collect cycle.
|
|
643
|
+
* @param options Object containing the options.
|
|
644
|
+
* @param options.machine Machine index (0-3).
|
|
645
|
+
* @returns The generated packet as a number array.
|
|
646
|
+
*/
|
|
647
|
+
performCollectCycle({ machine: e }) {
|
|
648
|
+
const t = `${e}`;
|
|
649
|
+
return this.transport.buildPacket(r.performCollectCycle, t, u.APP_ID);
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
/**
|
|
653
|
+
* Request dispense from channel with extended options.
|
|
654
|
+
* @param options Object containing the extended dispense options.
|
|
655
|
+
* @param options.token Token for tracking the request.
|
|
656
|
+
* @param options.machine Machine index (0-3).
|
|
657
|
+
* @param options.tray Tray number (11-18).
|
|
658
|
+
* @param options.channel Channel number (0-9).
|
|
659
|
+
* @param options.speed Speed of the dispense engine (0-21).
|
|
660
|
+
* @param options.timePostRun Time post run (0-255).
|
|
661
|
+
* @param options.fragileOrHeavy Boolean indicating if the product is fragile or heavy.
|
|
662
|
+
* @param options.typeAdjustElevator Type of elevator adjustment ('lower' | 'upper').
|
|
663
|
+
* @param options.timeAdjustElevator Time for elevator adjustment (in ms).
|
|
664
|
+
* @returns The generated packet as a number array.
|
|
665
|
+
*/
|
|
666
|
+
dispenseFromChannelExtended({
|
|
667
|
+
token: e,
|
|
668
|
+
machine: t,
|
|
669
|
+
tray: s,
|
|
670
|
+
channel: n,
|
|
671
|
+
speed: a,
|
|
672
|
+
timePostRun: i,
|
|
673
|
+
fragileOrHeavy: c,
|
|
674
|
+
typeAdjustElevator: o,
|
|
675
|
+
timeAdjustElevator: h
|
|
676
|
+
}) {
|
|
677
|
+
const I = `${e},${t},${s},${n},${a},${i},${c ? 1 : 0},${o === "lower" ? 0 : 1},${h}`;
|
|
678
|
+
return this.transport.buildPacket(r.dispenseFromChannelExtended, I, u.APP_ID);
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
/**
|
|
682
|
+
* Get dispense status from channel with extended options using a token.
|
|
683
|
+
* @param options Object containing the options.
|
|
684
|
+
* @param options.token Token for tracking the request.
|
|
685
|
+
* @returns The generated packet as a number array.
|
|
686
|
+
*/
|
|
687
|
+
getDispenseStatusFromChannelExtended({ token: e }) {
|
|
688
|
+
const t = `${e}`;
|
|
689
|
+
return this.transport.buildPacket(r.dispenseFromChannelExtended, t, u.APP_ID);
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Request for a complete JSD reset.
|
|
693
|
+
* VERY IMPORTANT: the JSD will respond with Opcode 220. Once received by the JSD, it will perform a total
|
|
694
|
+
* reset without taking care of the machine's current situation (manoeuvres, dispenses, etc.).
|
|
695
|
+
* This must not be used for solving anything and must be used thinking about the possible consequences.
|
|
696
|
+
* @returns The generated packet as a number array.
|
|
697
|
+
*/
|
|
698
|
+
restartingTheJSDKnowingThatItIsDangerous() {
|
|
699
|
+
return this.transport.buildPacket(r.restartingTheJSDKnowingThatItIsDangerous, "", u.APP_ID);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
function q(d) {
|
|
703
|
+
if (d.length > 5)
|
|
704
|
+
throw new Error(`Token must be max 5 characters, got ${d.length}`);
|
|
705
|
+
return d;
|
|
706
|
+
}
|
|
707
|
+
function _() {
|
|
708
|
+
let d;
|
|
709
|
+
do {
|
|
710
|
+
const e = new Uint8Array(2);
|
|
711
|
+
d = parseInt(crypto.getRandomValues(e).toString().replaceAll(",", "")).toString(36);
|
|
712
|
+
} while (d.length > 5);
|
|
713
|
+
return q(d);
|
|
714
|
+
}
|
|
715
|
+
const E = {
|
|
716
|
+
status: "NO-CONNECTED",
|
|
717
|
+
machineInService: !1,
|
|
718
|
+
doorOpen: !1,
|
|
719
|
+
availabilityToDispense: "NOT-AVAILABLE-TO-DISPENSE",
|
|
720
|
+
hasLightsOn: !1,
|
|
721
|
+
temperature: ""
|
|
722
|
+
};
|
|
723
|
+
class M {
|
|
724
|
+
_commands;
|
|
725
|
+
jsd;
|
|
726
|
+
APP_ID = f.VISION;
|
|
727
|
+
_machineStatus = [
|
|
728
|
+
{ ...E },
|
|
729
|
+
{ ...E },
|
|
730
|
+
{ ...E },
|
|
731
|
+
{ ...E }
|
|
732
|
+
];
|
|
733
|
+
constructor(e, t) {
|
|
734
|
+
this._commands = new u(t), this.jsd = e;
|
|
735
|
+
}
|
|
736
|
+
_performingChannelAssignment = {
|
|
737
|
+
enabled: !1,
|
|
738
|
+
selections: [],
|
|
739
|
+
currentSelection: 1
|
|
740
|
+
};
|
|
741
|
+
_dispensingTokens = {};
|
|
742
|
+
async send(e, t) {
|
|
743
|
+
return this.jsd._lastApplicationCode = this.APP_ID, this.jsd._toQueue(e, {
|
|
744
|
+
alias: t.alias,
|
|
745
|
+
waitResponse: t.waitResponse || !1,
|
|
746
|
+
timeout: t.timeout || 500
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
get cmd() {
|
|
750
|
+
return this._commands;
|
|
751
|
+
}
|
|
752
|
+
_getMachineIndex(e) {
|
|
753
|
+
return e - 1;
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Check if a machine is available to dispense based on its status.
|
|
757
|
+
* @param options.machine Machine index to check availability for.
|
|
758
|
+
* @returns True if the machine is available to dispense, false otherwise.
|
|
759
|
+
*/
|
|
760
|
+
isAvailableToDispense({ machine: e = 1 } = {}) {
|
|
761
|
+
const t = this._getMachineIndex(e);
|
|
762
|
+
return ["ELEVATOR-COLLECTION-POSITION", "AVAILABLE-TO-DISPENSE"].includes(this._machineStatus[t]?.availabilityToDispense || "") && this._machineStatus[t]?.machineInService === !0 && this._machineStatus[t]?.doorOpen === !1 && this._machineStatus[t]?.status === "CONNECTED";
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Request machine status.
|
|
766
|
+
* @param options Object containing the machine index.
|
|
767
|
+
* @param options.machine Machine index (defaults to 1).
|
|
768
|
+
* @returns Promise resolving when the command is sent.
|
|
769
|
+
*/
|
|
770
|
+
async requestMachineStatus({ machine: e = 1 } = {}) {
|
|
771
|
+
const t = this._getMachineIndex(e), s = this.cmd.requestMachineStatus({ machine: t });
|
|
772
|
+
return await this.send(s, { alias: "requestMachineStatus" });
|
|
773
|
+
}
|
|
774
|
+
_getTrayChannelFromSelection(e) {
|
|
775
|
+
const t = Math.floor((e - 1) / 10) + 11, s = (e - 1) % 10;
|
|
776
|
+
return { tray: t, channel: s };
|
|
777
|
+
}
|
|
778
|
+
_getSelectionFromTrayChannel(e, t) {
|
|
779
|
+
return (e - 11) * 10 + t + 1;
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Request status of a specific channel.
|
|
783
|
+
* @param options Object containing machine and selection.
|
|
784
|
+
* @param options.machine Machine index.
|
|
785
|
+
* @param options.selection Selection number (1-81) to derive tray and channel.
|
|
786
|
+
* @returns Promise resolving when the command is sent.
|
|
787
|
+
*/
|
|
788
|
+
async requestStatusChannel({ machine: e, selection: t }) {
|
|
789
|
+
const s = this._getMachineIndex(e), { tray: n, channel: a } = this._getTrayChannelFromSelection(t), i = this.cmd.requestStatusChannel({ machine: s, tray: n, channel: a });
|
|
790
|
+
return await this.send(i, { alias: "requestStatusChannel" });
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* Get status of all channels in a machine.
|
|
794
|
+
* WARNING: This method triggers a sequence of requests for all 80 selections.
|
|
795
|
+
* @param options Object containing the machine index.
|
|
796
|
+
* @param options.machine Machine index.
|
|
797
|
+
* @returns Promise resolving to an array of SelectionStatus objects.
|
|
798
|
+
*/
|
|
799
|
+
async assignChannels({ machine: e }) {
|
|
800
|
+
if (this._performingChannelAssignment.enabled)
|
|
801
|
+
throw new Error("Channel assignment already in progress");
|
|
802
|
+
this._performingChannelAssignment.enabled = !0;
|
|
803
|
+
for (let t = 1; t <= 80; t++)
|
|
804
|
+
await this.requestStatusChannel({ machine: e, selection: t });
|
|
805
|
+
return new Promise((t) => {
|
|
806
|
+
const s = setInterval(() => {
|
|
807
|
+
if (this._performingChannelAssignment.enabled)
|
|
808
|
+
return;
|
|
809
|
+
clearInterval(s);
|
|
810
|
+
const n = this._performingChannelAssignment.selections;
|
|
811
|
+
this._performingChannelAssignment.selections = [], t(n);
|
|
812
|
+
}, 200);
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Request status of a specific selection.
|
|
817
|
+
* @param options Object containing the selection number.
|
|
818
|
+
* @param options.selection Selection number (1-240).
|
|
819
|
+
* @returns Promise resolving when the command is sent.
|
|
820
|
+
*/
|
|
821
|
+
async requestStatusSelection({ selection: e }) {
|
|
822
|
+
const t = this.cmd.requestStatusSelection({ selection: e });
|
|
823
|
+
return await this.send(t, { alias: "requestStatusSelection" });
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Configure dispense parameters for a selection.
|
|
827
|
+
* @param options Object containing selection, speed, and timePostRun.
|
|
828
|
+
* @param options.selection Selection number.
|
|
829
|
+
* @param options.speed Dispense speed.
|
|
830
|
+
* @param options.timePostRun Time post run.
|
|
831
|
+
* @returns Promise resolving when the command is sent.
|
|
832
|
+
*/
|
|
833
|
+
async configureSelectionDispense({ selection: e, speed: t, timePostRun: s }) {
|
|
834
|
+
const n = this.cmd.configureSelectionDispense({ selection: e, speed: t, timePostRun: s });
|
|
835
|
+
return await this.send(n, { alias: "configureSelectionDispense" });
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Get current dispense configuration for a selection.
|
|
839
|
+
* @param options Object containing the machine index.
|
|
840
|
+
* @param options.machine Machine index.
|
|
841
|
+
* @returns Promise resolving when the command is sent.
|
|
842
|
+
*/
|
|
843
|
+
async requestSelectionDispenseConfig({ machine: e }) {
|
|
844
|
+
const t = this._getMachineIndex(e), s = this.cmd.getSelectionDispenseConfig({ machine: t });
|
|
845
|
+
return await this.send(s, { alias: "getSelectionDispenseConfig" });
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* Add a channel to a selection.
|
|
849
|
+
* @param options Object containing details for adding a channel.
|
|
850
|
+
* @param options.selection Selection number.
|
|
851
|
+
* @param options.machine Machine index.
|
|
852
|
+
* @param options.tray Tray number.
|
|
853
|
+
* @param options.channel Channel number.
|
|
854
|
+
* @returns Promise resolving when the command is sent.
|
|
855
|
+
*/
|
|
856
|
+
async configureAddChannelToSelection({ selection: e, machine: t, tray: s, channel: n }) {
|
|
857
|
+
const a = this._getMachineIndex(t), i = this.cmd.addChannelToSelection({ selection: e, machine: a, tray: s, channel: n });
|
|
858
|
+
return await this.send(i, { alias: "addChannelToSelection" });
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Get channels linked to a selection.
|
|
862
|
+
* @param options Object containing the selection number.
|
|
863
|
+
* @param options.selection Selection number.
|
|
864
|
+
* @returns Promise resolving when the command is sent.
|
|
865
|
+
*/
|
|
866
|
+
async requestChannelsLinkedToSelection({ selection: e }) {
|
|
867
|
+
const t = this.cmd.getChannelsLinkedToSelection({ selection: e });
|
|
868
|
+
return await this.send(t, { alias: "getChannelsLinkedToSelection" });
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* Request machine identification.
|
|
872
|
+
* @param options Object containing the machine index.
|
|
873
|
+
* @param options.machine Machine index.
|
|
874
|
+
* @returns Promise resolving when the command is sent.
|
|
875
|
+
*/
|
|
876
|
+
async requestMachineIdentification({ machine: e }) {
|
|
877
|
+
const t = this._getMachineIndex(e), s = this.cmd.requestMachineIdentification({ machine: t });
|
|
878
|
+
return await this.send(s, { alias: "requestMachineIdentification" });
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Program working temperature.
|
|
882
|
+
* @param options Object containing temperature settings.
|
|
883
|
+
* @param options.machine Machine index.
|
|
884
|
+
* @param options.temperature Target temperature.
|
|
885
|
+
* @param options.enable Enable or disable temperature control.
|
|
886
|
+
* @returns Promise resolving when the command is sent.
|
|
887
|
+
*/
|
|
888
|
+
async configureWorkingTemperature({ machine: e, temperature: t, enable: s }) {
|
|
889
|
+
const n = this._getMachineIndex(e), a = this.cmd.programWorkingTemperature({ machine: n, temperature: t, enable: s });
|
|
890
|
+
return await this.send(a, { alias: "programWorkingTemperature" });
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Get working temperature.
|
|
894
|
+
* @param options Object containing the machine index.
|
|
895
|
+
* @param options.machine Machine index.
|
|
896
|
+
* @returns Promise resolving when the command is sent.
|
|
897
|
+
*/
|
|
898
|
+
async requestWorkingTemperature({ machine: e }) {
|
|
899
|
+
const t = this._getMachineIndex(e), s = this.cmd.getWorkingTemperature({ machine: t });
|
|
900
|
+
return await this.send(s, { alias: "getWorkingTemperature" });
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* Program waiting timings.
|
|
904
|
+
* @param options Object containing timing settings.
|
|
905
|
+
* @param options.collectPosition Time for collect position.
|
|
906
|
+
* @param options.dispenseManoeuvres Time for dispense manoeuvres.
|
|
907
|
+
* @param options.afterPickup Time waiting after pickup.
|
|
908
|
+
* @returns Promise resolving when the command is sent.
|
|
909
|
+
*/
|
|
910
|
+
async configureWaitingTimings({ collectPosition: e, dispenseManoeuvres: t, afterPickup: s }) {
|
|
911
|
+
const n = this.cmd.programWaitingTimings({ collectPosition: e, dispenseManoeuvres: t, afterPickup: s });
|
|
912
|
+
return await this.send(n, { alias: "programWaitingTimings" });
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* Get waiting timings.
|
|
916
|
+
* @returns Promise resolving when the command is sent.
|
|
917
|
+
*/
|
|
918
|
+
async requestWaitingTimings() {
|
|
919
|
+
const e = this.cmd.getWaitingTimings();
|
|
920
|
+
return await this.send(e, { alias: "getWaitingTimings" });
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Reset sold-out status for all channels in a machine.
|
|
924
|
+
* @param options Object containing the machine index.
|
|
925
|
+
* @param options.machine Machine index.
|
|
926
|
+
* @returns Promise resolving when the command is sent.
|
|
927
|
+
*/
|
|
928
|
+
async resetSoldOutChannels({ machine: e }) {
|
|
929
|
+
const t = this._getMachineIndex(e), s = this.cmd.resetSoldOutChannels({ machine: t });
|
|
930
|
+
return await this.send(s, { alias: "resetSoldOutChannels" });
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Reset faults and perform self-test for a machine.
|
|
934
|
+
* @param options Object containing the machine index.
|
|
935
|
+
* @param options.machine Machine index.
|
|
936
|
+
* @returns Promise resolving when the command is sent.
|
|
937
|
+
*/
|
|
938
|
+
async resetAllErrors({ machine: e }) {
|
|
939
|
+
return await Promise.all([
|
|
940
|
+
this.clearInactiveFaults({ machine: e }),
|
|
941
|
+
this.resetSoldOutChannels({ machine: e }),
|
|
942
|
+
this.resetFaultsAndSelfTest({ machine: e })
|
|
943
|
+
]);
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Program time waiting after pickup.
|
|
947
|
+
* @param options Object containing time setting.
|
|
948
|
+
* @param options.time Time in seconds.
|
|
949
|
+
* @returns Promise resolving when the command is sent.
|
|
950
|
+
*/
|
|
951
|
+
async configureTimeWaitingAfterPickup({ time: e }) {
|
|
952
|
+
const t = this.cmd.programTimeWaitingAfterPickup({ time: e });
|
|
953
|
+
return await this.send(t, { alias: "programTimeWaitingAfterPickup" });
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Get time waiting after pickup.
|
|
957
|
+
* @returns Promise resolving when the command is sent.
|
|
958
|
+
*/
|
|
959
|
+
async requestTimeWaitingAfterPickup() {
|
|
960
|
+
const e = this.cmd.getTimeWaitingAfterPickup();
|
|
961
|
+
return await this.send(e, { alias: "getTimeWaitingAfterPickup" });
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* Request JSD firmware version.
|
|
965
|
+
* @returns Promise resolving when the command is sent.
|
|
966
|
+
*/
|
|
967
|
+
async requestJSDVersion() {
|
|
968
|
+
const e = this.cmd.requestJSDVersion();
|
|
969
|
+
return await this.send(e, { alias: "requestJSDVersion" });
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* Request report of active faults.
|
|
973
|
+
* @param machine Machine index.
|
|
974
|
+
* @returns Promise resolving when the command is sent.
|
|
975
|
+
*/
|
|
976
|
+
async requestReportActiveFaults({ machine: e }) {
|
|
977
|
+
const t = this._getMachineIndex(e), s = this.cmd.requestReportActiveFaults(t);
|
|
978
|
+
return await this.send(s, { alias: "requestReportActiveFaults" });
|
|
979
|
+
}
|
|
980
|
+
/**
|
|
981
|
+
* Request report of inactive faults.
|
|
982
|
+
* @param machine Machine index.
|
|
983
|
+
* @returns Promise resolving when the command is sent.
|
|
984
|
+
*/
|
|
985
|
+
async requestReportInactiveFaults({ machine: e }) {
|
|
986
|
+
const t = this._getMachineIndex(e), s = this.cmd.requestReportInactiveFaults(t);
|
|
987
|
+
return await this.send(s, { alias: "requestReportInactiveFaults" });
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* Request to clear inactive faults.
|
|
991
|
+
* @param machine Machine index.
|
|
992
|
+
* @returns Promise resolving when the command is sent.
|
|
993
|
+
*/
|
|
994
|
+
async clearInactiveFaults({ machine: e }) {
|
|
995
|
+
const t = this._getMachineIndex(e), s = this.cmd.requestClearInactiveFaults(t);
|
|
996
|
+
return await this.send(s, { alias: "requestClearInactiveFaults" });
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
* Request JSD dispensing queue status.
|
|
1000
|
+
* @returns Promise resolving when the command is sent.
|
|
1001
|
+
*/
|
|
1002
|
+
async requestJSDDispensingQueueStatus() {
|
|
1003
|
+
const e = this.cmd.requestJSDDispensingQueueStatus();
|
|
1004
|
+
return await this.send(e, { alias: "requestJSDDispensingQueueStatus" });
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Clear JSD dispensing queue.
|
|
1008
|
+
* @returns Promise resolving when the command is sent.
|
|
1009
|
+
*/
|
|
1010
|
+
async clearJSDDispensingQueue() {
|
|
1011
|
+
const e = this.cmd.clearJSDDispensingQueue();
|
|
1012
|
+
return await this.send(e, { alias: "clearJSDDispensingQueue" });
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* Define special characteristics for a selection.
|
|
1016
|
+
* @param options Object containing special characteristics.
|
|
1017
|
+
* @param options.selection Selection number.
|
|
1018
|
+
* @param options.perishable Perishable flag.
|
|
1019
|
+
* @param options.fragileOrHeavy Fragile or heavy flag.
|
|
1020
|
+
* @param options.typeAdjustElevator Elevator adjustment type.
|
|
1021
|
+
* @param options.timeAdjustElevator Elevator adjustment time.
|
|
1022
|
+
* @returns Promise resolving when the command is sent.
|
|
1023
|
+
*/
|
|
1024
|
+
async configureSpecialCharacteristicsSelection({
|
|
1025
|
+
selection: e,
|
|
1026
|
+
perishable: t,
|
|
1027
|
+
fragileOrHeavy: s,
|
|
1028
|
+
typeAdjustElevator: n,
|
|
1029
|
+
timeAdjustElevator: a
|
|
1030
|
+
}) {
|
|
1031
|
+
const i = this.cmd.defineSpecialCharacteristicsSelection({
|
|
1032
|
+
selection: e,
|
|
1033
|
+
perishable: t,
|
|
1034
|
+
fragileOrHeavy: s,
|
|
1035
|
+
typeAdjustElevator: n,
|
|
1036
|
+
timeAdjustElevator: a
|
|
1037
|
+
});
|
|
1038
|
+
return await this.send(i, { alias: "defineSpecialCharacteristicsSelection" });
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* Get special characteristics for a selection.
|
|
1042
|
+
* @param options Object containing the selection number.
|
|
1043
|
+
* @param options.selection Selection number.
|
|
1044
|
+
* @returns Promise resolving when the command is sent.
|
|
1045
|
+
*/
|
|
1046
|
+
requestSpecialCharacteristicsSelection({ selection: e }) {
|
|
1047
|
+
const t = this.cmd.getSpecialCharacteristicsSelection({ selection: e });
|
|
1048
|
+
return this.send(t, { alias: "getSpecialCharacteristicsSelection" });
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* Configure perishable products settings.
|
|
1052
|
+
* @param options Object containing perishable product settings.
|
|
1053
|
+
* @param options.machine Machine index.
|
|
1054
|
+
* @param options.enable Enable or disable.
|
|
1055
|
+
* @param options.temperatureLimit Temperature limit.
|
|
1056
|
+
* @param options.minutesToExpiry Minutes to expiry.
|
|
1057
|
+
* @returns Promise resolving when the command is sent.
|
|
1058
|
+
*/
|
|
1059
|
+
configurePerishableProducts({ machine: e, enable: t, temperatureLimit: s, minutesToExpiry: n }) {
|
|
1060
|
+
const a = this._getMachineIndex(e), i = this.cmd.configurePerishableProducts({
|
|
1061
|
+
machine: a,
|
|
1062
|
+
enable: t,
|
|
1063
|
+
temperatureLimit: s,
|
|
1064
|
+
minutesToExpiry: n
|
|
1065
|
+
});
|
|
1066
|
+
return this.send(i, { alias: "configurePerishableProducts" });
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* Request active faults.
|
|
1070
|
+
* @param options Object containing the machine index.
|
|
1071
|
+
* @param options.machine Machine index.
|
|
1072
|
+
* @returns Promise resolving when the command is sent.
|
|
1073
|
+
*/
|
|
1074
|
+
async requestActiveFaults({ machine: e }) {
|
|
1075
|
+
const t = this._getMachineIndex(e), s = this.cmd.requestActiveFaults({ machine: t });
|
|
1076
|
+
return await this.send(s, { alias: "requestActiveFaults" });
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Configure extended dispense status data.
|
|
1080
|
+
* @param options Object containing enable flag.
|
|
1081
|
+
* @param options.enable Enable extended data.
|
|
1082
|
+
* @returns Promise resolving when the command is sent.
|
|
1083
|
+
*/
|
|
1084
|
+
async configureExtendedDispenseStatusData({ enable: e }) {
|
|
1085
|
+
const t = this.cmd.configureExtendedDispenseStatusData({ enable: e });
|
|
1086
|
+
return await this.send(t, { alias: "configureExtendedDispenseStatusData" });
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* Get extended dispense status data configuration.
|
|
1090
|
+
* @returns Promise resolving when the command is sent.
|
|
1091
|
+
*/
|
|
1092
|
+
async requestExtendedDispenseStatusDataConfig() {
|
|
1093
|
+
const e = this.cmd.getExtendedDispenseStatusDataConfig();
|
|
1094
|
+
return await this.send(e, { alias: "getExtendedDispenseStatusDataConfig" });
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Request status of tray positioning phototransistors.
|
|
1098
|
+
* @param options Object containing the machine index.
|
|
1099
|
+
* @param options.machine Machine index.
|
|
1100
|
+
* @returns Promise resolving when the command is sent.
|
|
1101
|
+
*/
|
|
1102
|
+
async requestStatusTrayPositioningPhototransistors({ machine: e }) {
|
|
1103
|
+
const t = this._getMachineIndex(e), s = this.cmd.requestStatusTrayPositioningPhototransistors({ machine: t });
|
|
1104
|
+
return await this.send(s, { alias: "requestStatusTrayPositioningPhototransistors" });
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* Dispense from a specific channel.
|
|
1108
|
+
* @param options Object containing dispense details.
|
|
1109
|
+
* @param options.machine Machine index.
|
|
1110
|
+
* @param options.tray Tray number.
|
|
1111
|
+
* @param options.channel Channel number.
|
|
1112
|
+
* @param options.speed Dispense speed.
|
|
1113
|
+
* @param options.timePostRun Time post run.
|
|
1114
|
+
* @param options.cart Cart flag (optional, defaults to false).
|
|
1115
|
+
* @returns Promise resolving when the command is sent.
|
|
1116
|
+
*/
|
|
1117
|
+
async dispenseFromChannel({ machine: e, tray: t, channel: s, speed: n, timePostRun: a, cart: i = !1 }) {
|
|
1118
|
+
if (!this.isAvailableToDispense({ machine: e }))
|
|
1119
|
+
throw new Error(`Machine ${e} is not available to dispense`);
|
|
1120
|
+
const c = this._getMachineIndex(e), o = _(), h = this.cmd.dispenseFromChannel({
|
|
1121
|
+
token: o,
|
|
1122
|
+
machine: c,
|
|
1123
|
+
tray: t,
|
|
1124
|
+
channel: s,
|
|
1125
|
+
speed: n,
|
|
1126
|
+
timePostRun: a
|
|
1127
|
+
});
|
|
1128
|
+
return await this.send(h, { alias: "dispenseFromChannel" }), this._dispensingTokens[o] = {
|
|
1129
|
+
cart: !!i,
|
|
1130
|
+
resolve: () => {
|
|
1131
|
+
delete this._dispensingTokens[o];
|
|
1132
|
+
},
|
|
1133
|
+
reject: () => {
|
|
1134
|
+
}
|
|
1135
|
+
}, new Promise((p, l) => {
|
|
1136
|
+
this._dispensingTokens[o].resolve = p, this._dispensingTokens[o].reject = l;
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Dispense from a selection using the channel assignment logic.
|
|
1141
|
+
* @param options Object containing dispense details.
|
|
1142
|
+
* @param options.machine Machine index.
|
|
1143
|
+
* @param options.selection Selection number (1-81).
|
|
1144
|
+
* @param options.speed Dispense speed.
|
|
1145
|
+
* @param options.timePostRun Time post run.
|
|
1146
|
+
* @param options.cart Cart flag (optional, defaults to false).
|
|
1147
|
+
* @returns Promise resolving when the command is sent.
|
|
1148
|
+
*/
|
|
1149
|
+
async dispense({ machine: e, selection: t, speed: s, timePostRun: n, cart: a = !1 }) {
|
|
1150
|
+
const { tray: i, channel: c } = this._getTrayChannelFromSelection(t);
|
|
1151
|
+
return this.dispenseFromChannel({ machine: e, tray: i, channel: c, speed: s || 5, timePostRun: n || 0, cart: !!a });
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Dispense multiple selections in a cart.
|
|
1155
|
+
* WARNING: This method sends dispense commands in batches of 10 and waits for machines to be available before sending the next batch.
|
|
1156
|
+
* @param data Array of objects containing machine and selection details for each dispense command.
|
|
1157
|
+
* @param data.machine Machine index for each dispense command.
|
|
1158
|
+
* @param data.selection Selection number (1-81) for each dispense command.
|
|
1159
|
+
* @returns Promise resolving to an array of objects containing selection and dispense result for each command.
|
|
1160
|
+
*/
|
|
1161
|
+
async dispenseCart(e = []) {
|
|
1162
|
+
const t = [];
|
|
1163
|
+
for (let n = 0; n < e.length; n += 10)
|
|
1164
|
+
t.push(e.slice(n, n + 10));
|
|
1165
|
+
let s = [];
|
|
1166
|
+
for (const n of t)
|
|
1167
|
+
try {
|
|
1168
|
+
const a = await Promise.all(n.map((o) => this.dispense({ machine: o.machine, selection: o.selection, cart: !0 }))), i = [...new Set(n.map((o) => o.machine))];
|
|
1169
|
+
await new Promise((o) => {
|
|
1170
|
+
const h = setInterval(() => {
|
|
1171
|
+
i.every((l) => this.getMachineStatus(l)?.availabilityToDispense === "AVAILABLE-TO-DISPENSE") && (clearInterval(h), o(!0));
|
|
1172
|
+
}, 300);
|
|
1173
|
+
});
|
|
1174
|
+
for (const o of i)
|
|
1175
|
+
this._machineStatus[this._getMachineIndex(o)]?.availabilityToDispense === "WAITING-COLLECTION" && this.emit("waiting-collection", { machine: o !== null ? o + 1 : null });
|
|
1176
|
+
const c = n.map((o, h) => ({
|
|
1177
|
+
machine: o.machine,
|
|
1178
|
+
selection: o.selection,
|
|
1179
|
+
dispensed: a[h]
|
|
1180
|
+
}));
|
|
1181
|
+
s = s.concat(c);
|
|
1182
|
+
} catch (a) {
|
|
1183
|
+
console.error("Error sending dispense command:", a);
|
|
1184
|
+
}
|
|
1185
|
+
return s;
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Get dispense status from channel using a token.
|
|
1189
|
+
* @param options Object containing the token.
|
|
1190
|
+
* @param options.token Dispense token.
|
|
1191
|
+
* @returns Promise resolving when the command is sent.
|
|
1192
|
+
*/
|
|
1193
|
+
async requestDispenseStatusFromChannel({ token: e }) {
|
|
1194
|
+
const t = this.cmd.getDispenseStatusFromChannel({ token: e });
|
|
1195
|
+
return await this.send(t, { alias: "getDispenseStatusFromChannel" });
|
|
1196
|
+
}
|
|
1197
|
+
/**
|
|
1198
|
+
* Dispense from a selection.
|
|
1199
|
+
* @param options Object containing selection dispense details.
|
|
1200
|
+
* @param options.selection Selection number.
|
|
1201
|
+
* @param options.cart Cart flag (optional, defaults to false).
|
|
1202
|
+
* @returns Promise resolving when the command is sent.
|
|
1203
|
+
*/
|
|
1204
|
+
async dispenseFromSelection({ selection: e, cart: t = !1 }) {
|
|
1205
|
+
const s = _(), n = this.cmd.dispenseFromSelection({ token: s, selection: e });
|
|
1206
|
+
return await this.send(n, { alias: "dispenseFromSelection" }), this._dispensingTokens[s] = {
|
|
1207
|
+
cart: !!t,
|
|
1208
|
+
resolve: () => {
|
|
1209
|
+
},
|
|
1210
|
+
reject: () => {
|
|
1211
|
+
}
|
|
1212
|
+
}, new Promise((a, i) => {
|
|
1213
|
+
this._dispensingTokens[s].resolve = a, this._dispensingTokens[s].reject = i;
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* Get dispense status from selection using a token.
|
|
1218
|
+
* @param options Object containing the token.
|
|
1219
|
+
* @param options.token Dispense token.
|
|
1220
|
+
* @returns Promise resolving when the command is sent.
|
|
1221
|
+
*/
|
|
1222
|
+
async requestDispenseStatusFromSelection({ token: e }) {
|
|
1223
|
+
const t = this.cmd.getDispenseStatusFromSelection({ token: e });
|
|
1224
|
+
return await this.send(t, { alias: "getDispenseStatusFromSelection" });
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* Control lights.
|
|
1228
|
+
* @param options Object containing machine and light status.
|
|
1229
|
+
* @param options.machine Machine index.
|
|
1230
|
+
* @param options.turnOn Turn lights on or off.
|
|
1231
|
+
* @returns Promise resolving when the command is sent.
|
|
1232
|
+
*/
|
|
1233
|
+
async _configureLights({ machine: e, turnOn: t, alias: s }) {
|
|
1234
|
+
const n = this._getMachineIndex(e), a = this.cmd.controlLights({ machine: n, turnOn: t });
|
|
1235
|
+
return await this.send(a, { alias: s });
|
|
1236
|
+
}
|
|
1237
|
+
/**
|
|
1238
|
+
* Turn lights on for a machine.
|
|
1239
|
+
* @param options Object containing the machine index.
|
|
1240
|
+
* @param options.machine Machine index.
|
|
1241
|
+
* @returns Promise resolving when the command is sent.
|
|
1242
|
+
*/
|
|
1243
|
+
async lightsOn({ machine: e }) {
|
|
1244
|
+
return this._configureLights({ machine: e, turnOn: !0, alias: "lightsOn" });
|
|
1245
|
+
}
|
|
1246
|
+
/**
|
|
1247
|
+
* Turn lights off for a machine.
|
|
1248
|
+
* @param options Object containing the machine index.
|
|
1249
|
+
* @param options.machine Machine index.
|
|
1250
|
+
* @returns Promise resolving when the command is sent.
|
|
1251
|
+
*/
|
|
1252
|
+
async lightsOff({ machine: e }) {
|
|
1253
|
+
return this._configureLights({ machine: e, turnOn: !1, alias: "lightsOff" });
|
|
1254
|
+
}
|
|
1255
|
+
/**
|
|
1256
|
+
* Reset faults and perform self-test.
|
|
1257
|
+
* @param options Object containing the machine index.
|
|
1258
|
+
* @param options.machine Machine index.
|
|
1259
|
+
* @returns Promise resolving when the command is sent.
|
|
1260
|
+
*/
|
|
1261
|
+
async resetFaultsAndSelfTest({ machine: e }) {
|
|
1262
|
+
const t = this._getMachineIndex(e), s = this.cmd.resetFaultsAndSelfTest({ machine: t });
|
|
1263
|
+
return await this.send(s, { alias: "resetFaultsAndSelfTest" });
|
|
1264
|
+
}
|
|
1265
|
+
/**
|
|
1266
|
+
* Perform collect cycle.
|
|
1267
|
+
* @param options Object containing the machine index.
|
|
1268
|
+
* @param options.machine Machine index.
|
|
1269
|
+
* @returns Promise resolving when the command is sent.
|
|
1270
|
+
*/
|
|
1271
|
+
async collect({ machine: e }) {
|
|
1272
|
+
const t = this._getMachineIndex(e), s = this.cmd.performCollectCycle({ machine: t });
|
|
1273
|
+
return await this.send(s, { alias: "performCollectCycle" });
|
|
1274
|
+
}
|
|
1275
|
+
/**
|
|
1276
|
+
* Dispense from a channel with extended options.
|
|
1277
|
+
* @param options Object containing extended dispense details.
|
|
1278
|
+
* @param options.machine Machine index.
|
|
1279
|
+
* @param options.tray Tray number.
|
|
1280
|
+
* @param options.channel Channel number.
|
|
1281
|
+
* @param options.speed Dispense speed.
|
|
1282
|
+
* @param options.timePostRun Time post run.
|
|
1283
|
+
* @param options.fragileOrHeavy Fragile or heavy flag.
|
|
1284
|
+
* @param options.typeAdjustElevator Elevator adjustment type.
|
|
1285
|
+
* @param options.timeAdjustElevator Elevator adjustment time.
|
|
1286
|
+
* @param options.cart Cart flag (optional, defaults to false).
|
|
1287
|
+
* @returns Promise resolving when the command is sent.
|
|
1288
|
+
*/
|
|
1289
|
+
async dispenseFromChannelExtended({
|
|
1290
|
+
machine: e,
|
|
1291
|
+
tray: t,
|
|
1292
|
+
channel: s,
|
|
1293
|
+
speed: n,
|
|
1294
|
+
timePostRun: a,
|
|
1295
|
+
fragileOrHeavy: i,
|
|
1296
|
+
typeAdjustElevator: c,
|
|
1297
|
+
timeAdjustElevator: o,
|
|
1298
|
+
cart: h = !1
|
|
1299
|
+
}) {
|
|
1300
|
+
if (!this.isAvailableToDispense({ machine: e }))
|
|
1301
|
+
throw new Error(`Machine ${e} is not available to dispense`);
|
|
1302
|
+
const p = this._getMachineIndex(e), l = _(), m = this.cmd.dispenseFromChannelExtended({
|
|
1303
|
+
token: l,
|
|
1304
|
+
machine: p,
|
|
1305
|
+
tray: t,
|
|
1306
|
+
channel: s,
|
|
1307
|
+
speed: n,
|
|
1308
|
+
timePostRun: a,
|
|
1309
|
+
fragileOrHeavy: i,
|
|
1310
|
+
typeAdjustElevator: c,
|
|
1311
|
+
timeAdjustElevator: o
|
|
1312
|
+
});
|
|
1313
|
+
return await this.send(m, { alias: "dispenseFromChannelExtended" }), this._dispensingTokens[l] = {
|
|
1314
|
+
cart: !!h,
|
|
1315
|
+
resolve: () => {
|
|
1316
|
+
},
|
|
1317
|
+
reject: () => {
|
|
1318
|
+
}
|
|
1319
|
+
}, new Promise((I, D) => {
|
|
1320
|
+
this._dispensingTokens[l].resolve = I, this._dispensingTokens[l].reject = D;
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* Get dispense status from channel with extended options using a token.
|
|
1325
|
+
* @param options Object containing the token.
|
|
1326
|
+
* @param options.token Dispense token.
|
|
1327
|
+
* @returns Promise resolving when the command is sent.
|
|
1328
|
+
*/
|
|
1329
|
+
async requestDispenseStatusFromChannelExtended({ token: e }) {
|
|
1330
|
+
const t = this.cmd.getDispenseStatusFromChannelExtended({ token: e });
|
|
1331
|
+
return await this.send(t, { alias: "getDispenseStatusFromChannelExtended" });
|
|
1332
|
+
}
|
|
1333
|
+
/**
|
|
1334
|
+
* Request for a complete JSD reset (DANGEROUS).
|
|
1335
|
+
* @returns Promise resolving when the command is sent.
|
|
1336
|
+
*/
|
|
1337
|
+
async restartJSD() {
|
|
1338
|
+
const e = this.cmd.restartingTheJSDKnowingThatItIsDangerous();
|
|
1339
|
+
return await this.send(e, { alias: "restartingTheJSDKnowingThatItIsDangerous" });
|
|
1340
|
+
}
|
|
1341
|
+
serialMessage(e) {
|
|
1342
|
+
switch (e.opcode) {
|
|
1343
|
+
case r.responseFormatCmdWrong:
|
|
1344
|
+
this._responseFormatCmdWrong(e);
|
|
1345
|
+
break;
|
|
1346
|
+
case r.responseMachineStatus:
|
|
1347
|
+
this._responseMachineStatus(e);
|
|
1348
|
+
break;
|
|
1349
|
+
case r.responseStatusChannel:
|
|
1350
|
+
this._responseStatusChannel(e);
|
|
1351
|
+
break;
|
|
1352
|
+
case r.responseStatusSelection:
|
|
1353
|
+
this._responseStatusSelection(e);
|
|
1354
|
+
break;
|
|
1355
|
+
case r.responseDispenseStatus:
|
|
1356
|
+
this._responseDispenseStatus(e);
|
|
1357
|
+
break;
|
|
1358
|
+
case r.responseConfigurationSelectionDispense:
|
|
1359
|
+
this._responseConfigurationSelectionDispense(e);
|
|
1360
|
+
break;
|
|
1361
|
+
case r.responseConfigurationChannelsLinkedToSelection:
|
|
1362
|
+
this._responseConfigurationChannelsLinkedToSelection(e);
|
|
1363
|
+
break;
|
|
1364
|
+
case r.responseMachineIdentification:
|
|
1365
|
+
this._responseMachineIdentification(e);
|
|
1366
|
+
break;
|
|
1367
|
+
case r.responseCurrentTemperature:
|
|
1368
|
+
this._responseCurrentTemperature(e);
|
|
1369
|
+
break;
|
|
1370
|
+
case r.responseReportEventsAlarmsAndFaults:
|
|
1371
|
+
this._responseReportEventsAlarmsAndFaults(e);
|
|
1372
|
+
break;
|
|
1373
|
+
case r.responseNewTimingWaitingForProductCollection:
|
|
1374
|
+
this._responseNewTimingWaitingForProductCollection(e);
|
|
1375
|
+
break;
|
|
1376
|
+
case r.responsePerformingProductCollectionCycle:
|
|
1377
|
+
this._responsePerformingProductCollectionCycle(e);
|
|
1378
|
+
break;
|
|
1379
|
+
case r.responseResetMachineSoldOutChannels:
|
|
1380
|
+
this._responseResetMachineSoldOutChannels(e);
|
|
1381
|
+
break;
|
|
1382
|
+
case r.responseNewTimingWaitingAfterProductCollection:
|
|
1383
|
+
this._responseNewTimingWaitingAfterProductCollection(e);
|
|
1384
|
+
break;
|
|
1385
|
+
case r.responseJSDVersion:
|
|
1386
|
+
this._responseJSDVersion(e);
|
|
1387
|
+
break;
|
|
1388
|
+
case r.responseActiveFaults:
|
|
1389
|
+
this._responseActiveFaults(e);
|
|
1390
|
+
break;
|
|
1391
|
+
case r.responseJSDDispensingQueue:
|
|
1392
|
+
this._responseJSDDispensingQueue(e);
|
|
1393
|
+
break;
|
|
1394
|
+
case r.responseSpecialCharacteristicsSelection:
|
|
1395
|
+
this._responseSpecialCharacteristicsSelection(e);
|
|
1396
|
+
break;
|
|
1397
|
+
case r.responsePerishableProducts:
|
|
1398
|
+
this._responsePerishableProducts(e);
|
|
1399
|
+
break;
|
|
1400
|
+
case r.responseActiveFaultsList:
|
|
1401
|
+
this._responseActiveFaultsList(e);
|
|
1402
|
+
break;
|
|
1403
|
+
case r.responseJSDResetStatus:
|
|
1404
|
+
this._responseJSDResetStatus(e);
|
|
1405
|
+
break;
|
|
1406
|
+
case r.responseExtendedDispenseStatusData:
|
|
1407
|
+
this._responseExtendedDispenseStatusData(e);
|
|
1408
|
+
break;
|
|
1409
|
+
case r.responseTraysPositioningPhototransistorsStatus:
|
|
1410
|
+
this._responseTraysPositioningPhototransistorsStatus(e);
|
|
1411
|
+
break;
|
|
1412
|
+
case r.jsdErrorLicenseTemporarilyBlocked:
|
|
1413
|
+
this._responseJsdErrorLicenseTemporarilyBlocked(e);
|
|
1414
|
+
break;
|
|
1415
|
+
case r.jsdErrorLicenseNotActive:
|
|
1416
|
+
this._responseJsdErrorLicenseNotActive(e);
|
|
1417
|
+
break;
|
|
1418
|
+
case r.jsdErrorCommandNotExecutable:
|
|
1419
|
+
this._responseJsdErrorCommandNotExecutable(e);
|
|
1420
|
+
break;
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
emit(e, ...t) {
|
|
1424
|
+
this.jsd.dispatch(`vision:${e}`, ...t);
|
|
1425
|
+
}
|
|
1426
|
+
_responseFormatCmdWrong(e) {
|
|
1427
|
+
const t = parseInt(e.params[0], 10), s = e.params.slice(1), n = C(t);
|
|
1428
|
+
this.emit("wrong-cmd", {
|
|
1429
|
+
opcodeName: n,
|
|
1430
|
+
opcode: t,
|
|
1431
|
+
params: s
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1434
|
+
setMachineStatus(e, t) {
|
|
1435
|
+
this._machineStatus[e] = t;
|
|
1436
|
+
}
|
|
1437
|
+
/**
|
|
1438
|
+
* Get the last known status of a machine.
|
|
1439
|
+
* @param machine Machine index.
|
|
1440
|
+
* @returns MachineStatus object or null.
|
|
1441
|
+
*/
|
|
1442
|
+
getMachineStatus(e) {
|
|
1443
|
+
const t = this._getMachineIndex(e);
|
|
1444
|
+
return this._machineStatus[t] || null;
|
|
1445
|
+
}
|
|
1446
|
+
_getMachineStatusName(e) {
|
|
1447
|
+
switch (e) {
|
|
1448
|
+
case 0:
|
|
1449
|
+
return "NO-CONNECTED";
|
|
1450
|
+
case 1:
|
|
1451
|
+
return "CONNECTED";
|
|
1452
|
+
case 2:
|
|
1453
|
+
return "LOST";
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
_responseMachineStatus(e) {
|
|
1457
|
+
const [t, s, n, a, i, c, o] = e.params, h = {
|
|
1458
|
+
0: "AVAILABLE-TO-DISPENSE",
|
|
1459
|
+
1: "NOT-AVAILABLE-TO-DISPENSE",
|
|
1460
|
+
2: "ALREADY-DISPENSING",
|
|
1461
|
+
3: "WAITING-COLLECTION",
|
|
1462
|
+
4: "ELEVATOR-COLLECTION-POSITION",
|
|
1463
|
+
5: "UNCOLLECTED"
|
|
1464
|
+
}, p = {
|
|
1465
|
+
status: this._getMachineStatusName(parseInt(s, 10)),
|
|
1466
|
+
machineInService: parseInt(n, 10) === 1,
|
|
1467
|
+
doorOpen: parseInt(a, 10) === 0,
|
|
1468
|
+
availabilityToDispense: h[i] || "NOT-AVAILABLE-TO-DISPENSE",
|
|
1469
|
+
hasLightsOn: isNaN(parseInt(c, 10)) ? !1 : parseInt(c, 10) === 1,
|
|
1470
|
+
temperature: o || ""
|
|
1471
|
+
};
|
|
1472
|
+
this.setMachineStatus(parseInt(t, 10), p), this.emit("machine-status", {
|
|
1473
|
+
machine: parseInt(t, 10) + 1,
|
|
1474
|
+
...p
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
_statusChannelName(e) {
|
|
1478
|
+
switch (e) {
|
|
1479
|
+
case 0:
|
|
1480
|
+
return "NO-CONNECTED";
|
|
1481
|
+
case 1:
|
|
1482
|
+
return "AVAILABLE";
|
|
1483
|
+
case 2:
|
|
1484
|
+
return "SOLD-OUT";
|
|
1485
|
+
case 3:
|
|
1486
|
+
return "FAULT";
|
|
1487
|
+
default:
|
|
1488
|
+
return "NO-CONNECTED";
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
_responseStatusChannel(e) {
|
|
1492
|
+
const [t, s, n, a] = e.params, i = this._statusChannelName(parseInt(a, 10)), c = this._getSelectionFromTrayChannel(Number(s), Number(n)), o = ["AVAILABLE", "SOLD-OUT"].includes(i);
|
|
1493
|
+
if (this._performingChannelAssignment.enabled) {
|
|
1494
|
+
this._performingChannelAssignment.selections.push({
|
|
1495
|
+
selection: c,
|
|
1496
|
+
active: o,
|
|
1497
|
+
machine: Number(t) + 1
|
|
1498
|
+
}), this._performingChannelAssignment.currentSelection = this._performingChannelAssignment.selections.length;
|
|
1499
|
+
const h = this._performingChannelAssignment.currentSelection / 80 * 100;
|
|
1500
|
+
this.emit("channels-progress", {
|
|
1501
|
+
progress: Math.min(100, Math.round(h * 100) / 100),
|
|
1502
|
+
current: this._performingChannelAssignment.currentSelection,
|
|
1503
|
+
verified: this._performingChannelAssignment.selections.length
|
|
1504
|
+
}), this._performingChannelAssignment.selections.length >= 80 && (this.emit("channels", this._performingChannelAssignment.selections), this._performingChannelAssignment.enabled = !1);
|
|
1505
|
+
} else
|
|
1506
|
+
this.emit("channel-status", {
|
|
1507
|
+
machine: Number(t) + 1,
|
|
1508
|
+
selection: c,
|
|
1509
|
+
active: o
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1512
|
+
_statusSelectionName(e) {
|
|
1513
|
+
switch (e) {
|
|
1514
|
+
case 0:
|
|
1515
|
+
return "NO-CONFIGURED";
|
|
1516
|
+
case 1:
|
|
1517
|
+
return "ASSOCIATED";
|
|
1518
|
+
case 2:
|
|
1519
|
+
return "NO-ASSOCIATED";
|
|
1520
|
+
case 3:
|
|
1521
|
+
return "NO-VISION-OWNED";
|
|
1522
|
+
case 4:
|
|
1523
|
+
return "EXPIRED";
|
|
1524
|
+
default:
|
|
1525
|
+
return "NO-CONFIGURED";
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
_responseStatusSelection(e) {
|
|
1529
|
+
const [t, s] = e.params, n = this._statusSelectionName(parseInt(s, 10));
|
|
1530
|
+
this.emit("status-selection", {
|
|
1531
|
+
selection: Number(t),
|
|
1532
|
+
status: n
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
_responseDispenseStatus(e) {
|
|
1536
|
+
const [t, s, n, a] = e.params, i = {
|
|
1537
|
+
0: "RECEIVED",
|
|
1538
|
+
1: "IN-PROGRESS",
|
|
1539
|
+
2: "WAITING-COLLECTION",
|
|
1540
|
+
3: "COLLECTED",
|
|
1541
|
+
4: "NO-PERFORMED",
|
|
1542
|
+
5: "TOKEN-NOT-FOUND",
|
|
1543
|
+
6: "QUEUE-FULL",
|
|
1544
|
+
7: "CHANNEL-NO-CONNECTED",
|
|
1545
|
+
8: "SELECTION-UNAVAILABLE",
|
|
1546
|
+
9: "FAILED-DISPENSE",
|
|
1547
|
+
10: "UNCOLLECTED",
|
|
1548
|
+
11: "DISPENSED-CAN-MULTIPLE",
|
|
1549
|
+
12: "DISPENSE-CANCELLED",
|
|
1550
|
+
13: "PRODUCT-EXPIRED"
|
|
1551
|
+
}, c = Object.values(i).filter(
|
|
1552
|
+
(D) => [
|
|
1553
|
+
"NO-PERFORMED",
|
|
1554
|
+
"TOKEN-NOT-FOUND",
|
|
1555
|
+
"QUEUE-FULL",
|
|
1556
|
+
"CHANNEL-NO-CONNECTED",
|
|
1557
|
+
"SELECTION-UNAVAILABLE",
|
|
1558
|
+
"FAILED-DISPENSE",
|
|
1559
|
+
"DISPENSE-CANCELLED",
|
|
1560
|
+
"PRODUCT-EXPIRED",
|
|
1561
|
+
"UNCOLLECTED"
|
|
1562
|
+
].includes(D)
|
|
1563
|
+
), o = {
|
|
1564
|
+
0: "NONE",
|
|
1565
|
+
1: "DOOR-OPEN",
|
|
1566
|
+
2: "MACHINE-NOT-AVAILABLE",
|
|
1567
|
+
3: "ERROR-PHOTOSENSORS",
|
|
1568
|
+
4: "ERROR-MOTOR-POWER-CONSUMPSION-DETECTOR",
|
|
1569
|
+
5: "ALREADY-SOLD-OUT",
|
|
1570
|
+
6: "ERROR-TEST-PRODUCT-DETECTOR",
|
|
1571
|
+
7: "SOLD-OUT",
|
|
1572
|
+
8: "ELEVATOR-CANT-REACH-TRAY",
|
|
1573
|
+
9: "UNCOLLECTED",
|
|
1574
|
+
10: "MACHINE-RESET-DURING-DISPENSE",
|
|
1575
|
+
11: "MACHINE-COMMUNICATION-ERROR",
|
|
1576
|
+
12: "MACHINE-COMMUNICATION-LOST",
|
|
1577
|
+
13: "NO-VISION",
|
|
1578
|
+
14: "PRODUCT-PERISHABLE-EXPIRED",
|
|
1579
|
+
20: "DECIDE"
|
|
1580
|
+
}, h = i[parseInt(s, 10)] || "UNKNOWN", [p, l, m] = n && n.trim() !== "" ? n.split(".").map((D) => parseInt(D, 10)) : [null, null, null], I = a ? o[parseInt(a, 10)] || "UNKNOWN" : null;
|
|
1581
|
+
this._dispensingTokens[t] && (this._dispensingTokens[t].cart === !1 && h === "WAITING-COLLECTION" ? (this._dispensingTokens[t].resolve(!0), delete this._dispensingTokens[t], this.emit("waiting-collection", { machine: p !== null ? p + 1 : null })) : this._dispensingTokens[t].cart === !0 && h === "DISPENSED-CAN-MULTIPLE" ? (this._dispensingTokens[t].resolve(!0), delete this._dispensingTokens[t]) : c.includes(h) && (this._dispensingTokens[t].resolve(!1), delete this._dispensingTokens[t])), h === "IN-PROGRESS" && this.emit("dispensing", {
|
|
1582
|
+
token: t,
|
|
1583
|
+
machine: p !== null ? p + 1 : null,
|
|
1584
|
+
tray: l !== null ? l : null,
|
|
1585
|
+
channel: m !== null ? m : null,
|
|
1586
|
+
selection: m !== null && l !== null ? this._getSelectionFromTrayChannel(l, m) : null
|
|
1587
|
+
}), this.emit("dispense-status", {
|
|
1588
|
+
token: t,
|
|
1589
|
+
status: h,
|
|
1590
|
+
machine: p !== null ? p + 1 : null,
|
|
1591
|
+
tray: l !== null ? l : null,
|
|
1592
|
+
channel: m !== null ? m : null,
|
|
1593
|
+
extendedStatus: I
|
|
1594
|
+
});
|
|
1595
|
+
}
|
|
1596
|
+
_responseConfigurationSelectionDispense(e) {
|
|
1597
|
+
const [t, s, n] = e.params;
|
|
1598
|
+
this.emit("selection-dispense-config", {
|
|
1599
|
+
selection: Number(t),
|
|
1600
|
+
speed: Number(s),
|
|
1601
|
+
timePostRun: Number(n)
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
_responseConfigurationChannelsLinkedToSelection(e) {
|
|
1605
|
+
const [t, ...s] = e.params, a = s[s.length - 1].includes(":") ? s.pop() : null, i = {
|
|
1606
|
+
0: "OK",
|
|
1607
|
+
1: "ALREADY-DEFINED",
|
|
1608
|
+
2: "OUT-OF-RANGE"
|
|
1609
|
+
}, c = s.map((o) => {
|
|
1610
|
+
const [h, p, l] = o.split(":");
|
|
1611
|
+
return {
|
|
1612
|
+
machine: parseInt(h, 10) + 1,
|
|
1613
|
+
tray: parseInt(p, 10),
|
|
1614
|
+
channel: parseInt(l, 10)
|
|
1615
|
+
};
|
|
1616
|
+
});
|
|
1617
|
+
this.emit("channels-linked-to-selection", {
|
|
1618
|
+
selection: Number(t),
|
|
1619
|
+
linkedChannels: c,
|
|
1620
|
+
status: a ? i[parseInt(a, 10)] || "UNKNOWN" : null
|
|
1621
|
+
});
|
|
1622
|
+
}
|
|
1623
|
+
_responseMachineIdentification(e) {
|
|
1624
|
+
const [t, s, n, a] = e.params;
|
|
1625
|
+
this.emit("machine-id", {
|
|
1626
|
+
machine: parseInt(t, 10) + 1,
|
|
1627
|
+
model: s,
|
|
1628
|
+
serialNumber: n,
|
|
1629
|
+
firmwareVersion: a
|
|
1630
|
+
});
|
|
1631
|
+
}
|
|
1632
|
+
_responseCurrentTemperature(e) {
|
|
1633
|
+
const [t, s, n, a, i] = e.params, c = parseInt(t, 10) + 1, o = parseInt(i, 10) === 1 ? "ON" : "OFF";
|
|
1634
|
+
this.emit("current-temperature", {
|
|
1635
|
+
machine: c,
|
|
1636
|
+
workingTemperature: s,
|
|
1637
|
+
currentTemperatureInsideMachine: n,
|
|
1638
|
+
currentTemperatureAir: a,
|
|
1639
|
+
coolUnitStatus: o
|
|
1640
|
+
});
|
|
1641
|
+
}
|
|
1642
|
+
_responseReportEventsAlarmsAndFaults(e) {
|
|
1643
|
+
const [t, s, n] = e.params, a = parseInt(t, 10) + 1, i = {
|
|
1644
|
+
1: "Product detector",
|
|
1645
|
+
2: "None of the motors are connected. Possible control board faulty",
|
|
1646
|
+
3: "Channels jamp detector error",
|
|
1647
|
+
4: "Temperature control error",
|
|
1648
|
+
5: "Elevator faulty",
|
|
1649
|
+
6: "Photosensor, which determine the position of the elevator in relation with the cabinet, faulty",
|
|
1650
|
+
7: "Elevator tester (flap), ES-Plus, faulty",
|
|
1651
|
+
8: "Product expired (perishable)"
|
|
1652
|
+
};
|
|
1653
|
+
this.emit("alarm-faults-events", {
|
|
1654
|
+
machine: a,
|
|
1655
|
+
event: i[parseInt(s, 10)] || "UNKNOWN",
|
|
1656
|
+
status: parseInt(n, 10) === 1 ? "ACTIVE" : "CLEARED"
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
_responseNewTimingWaitingForProductCollection(e) {
|
|
1660
|
+
const [t, s, n] = e.params;
|
|
1661
|
+
this.emit("time-waiting-for-product-collection", {
|
|
1662
|
+
minutesProductCollection: Number(t),
|
|
1663
|
+
secondsTimeBetweenDispenseManoeuvres: Number(s),
|
|
1664
|
+
secondsBetweenCollectAndStartNextDispense: Number(n)
|
|
1665
|
+
});
|
|
1666
|
+
}
|
|
1667
|
+
_responsePerformingProductCollectionCycle(e) {
|
|
1668
|
+
const [t, s] = e.params, n = {
|
|
1669
|
+
0: "Manoeuvre has started",
|
|
1670
|
+
1: "Wron machine number",
|
|
1671
|
+
2: "Machine no connected",
|
|
1672
|
+
3: "Wron machine model",
|
|
1673
|
+
4: "Machine cannot perform collection now",
|
|
1674
|
+
5: "Communication error with machine"
|
|
1675
|
+
};
|
|
1676
|
+
this.emit("collect", {
|
|
1677
|
+
machine: parseInt(t, 10) + 1,
|
|
1678
|
+
status: n[parseInt(s, 10)] || "UNKNOWN"
|
|
1679
|
+
});
|
|
1680
|
+
}
|
|
1681
|
+
_responseResetMachineSoldOutChannels(e) {
|
|
1682
|
+
const [t, s] = e.params, n = {
|
|
1683
|
+
0: "Reset performed",
|
|
1684
|
+
1: "Wrong machine number",
|
|
1685
|
+
2: "Machine not connected",
|
|
1686
|
+
3: "Communication error with machine"
|
|
1687
|
+
};
|
|
1688
|
+
this.emit("reset-sold-out-channels", {
|
|
1689
|
+
machine: parseInt(t, 10) + 1,
|
|
1690
|
+
status: n[parseInt(s, 10)] || "UNKNOWN"
|
|
1691
|
+
});
|
|
1692
|
+
}
|
|
1693
|
+
_responseNewTimingWaitingAfterProductCollection(e) {
|
|
1694
|
+
const [t] = e.params;
|
|
1695
|
+
this.emit("time-waiting-after-product-collection", {
|
|
1696
|
+
secondsBetweenCollectAndStartNextDispense: Number(t)
|
|
1697
|
+
});
|
|
1698
|
+
}
|
|
1699
|
+
_responseJSDVersion(e) {
|
|
1700
|
+
const [t, s, n, a] = e.params;
|
|
1701
|
+
this.emit("jsd-version", {
|
|
1702
|
+
name: t,
|
|
1703
|
+
compileNumber: s,
|
|
1704
|
+
compileDate: n,
|
|
1705
|
+
description: a
|
|
1706
|
+
});
|
|
1707
|
+
}
|
|
1708
|
+
_responseActiveFaults(e) {
|
|
1709
|
+
const [t, s, n, a, i, c, o] = e.params;
|
|
1710
|
+
this.emit("active-faults", {
|
|
1711
|
+
machine: parseInt(t, 10) + 1,
|
|
1712
|
+
status: parseInt(s, 10) === 1 ? "ACTIVE" : "CLEARED",
|
|
1713
|
+
fault: parseInt(n, 10),
|
|
1714
|
+
appearancesNumber: parseInt(a, 10),
|
|
1715
|
+
partialNumberActivated: parseInt(i, 10),
|
|
1716
|
+
minutesActive: parseInt(c, 10),
|
|
1717
|
+
date: o
|
|
1718
|
+
});
|
|
1719
|
+
}
|
|
1720
|
+
_responseJSDDispensingQueue(e) {
|
|
1721
|
+
const [t, s, n] = e.params;
|
|
1722
|
+
this.emit("jsd-dispensing-queue", {
|
|
1723
|
+
free: parseInt(t, 10),
|
|
1724
|
+
processed: parseInt(s, 10),
|
|
1725
|
+
notProcessed: parseInt(n, 10)
|
|
1726
|
+
});
|
|
1727
|
+
}
|
|
1728
|
+
_responseSpecialCharacteristicsSelection(e) {
|
|
1729
|
+
const [t, s, n, a, i] = e.params;
|
|
1730
|
+
this.emit("special-characteristics-selection", {
|
|
1731
|
+
selection: Number(t),
|
|
1732
|
+
perishable: parseInt(s, 10) === 1,
|
|
1733
|
+
fragileOrHeavy: parseInt(n, 10) === 1,
|
|
1734
|
+
typeAdjustElevator: a === "0" ? "lower" : "upper",
|
|
1735
|
+
timeAdjustElevator: Number(i)
|
|
1736
|
+
});
|
|
1737
|
+
}
|
|
1738
|
+
_responsePerishableProducts(e) {
|
|
1739
|
+
const [t, s, n, a, i] = e.params;
|
|
1740
|
+
this.emit("perishable-products-config", {
|
|
1741
|
+
machine: parseInt(t, 10) + 1,
|
|
1742
|
+
perishableActive: parseInt(s, 10) === 1,
|
|
1743
|
+
alarmPerisableTriggered: parseInt(n, 10) === 1,
|
|
1744
|
+
maxTemperature: a,
|
|
1745
|
+
minutesBeforeExpire: Number(i)
|
|
1746
|
+
});
|
|
1747
|
+
}
|
|
1748
|
+
_responseActiveFaultsList(e) {
|
|
1749
|
+
const [t, ...s] = e.params, n = {
|
|
1750
|
+
1: "Product detector",
|
|
1751
|
+
2: "None of the motors are connected. Possible control board faulty",
|
|
1752
|
+
3: "Channels jamp detector error",
|
|
1753
|
+
4: "Temperature control error",
|
|
1754
|
+
5: "Elevator faulty",
|
|
1755
|
+
6: "Photosensor, which determine the position of the elevator in relation with the cabinet, faulty",
|
|
1756
|
+
7: "Elevator tester (flap), ES-Plus, faulty",
|
|
1757
|
+
8: "Product expired (perishable)"
|
|
1758
|
+
}, a = s.map((i) => ({
|
|
1759
|
+
code: parseInt(i, 10),
|
|
1760
|
+
description: n[parseInt(i, 10)] || "UNKNOWN"
|
|
1761
|
+
}));
|
|
1762
|
+
this.emit("active-faults-list", {
|
|
1763
|
+
machine: parseInt(t, 10) + 1,
|
|
1764
|
+
faults: a,
|
|
1765
|
+
ok: s.length === 0
|
|
1766
|
+
});
|
|
1767
|
+
}
|
|
1768
|
+
_responseJSDResetStatus(e) {
|
|
1769
|
+
const [t] = e.params, s = {
|
|
1770
|
+
0: "RESETED",
|
|
1771
|
+
//'JSD has performed a reset, therefore it has started up',
|
|
1772
|
+
1: "RECEIVED"
|
|
1773
|
+
//'JSD is near to performe a reset. Request received'
|
|
1774
|
+
};
|
|
1775
|
+
this.emit("jsd-status-reset", {
|
|
1776
|
+
type: s[parseInt(t, 10)] || "UNKNOWN"
|
|
1777
|
+
});
|
|
1778
|
+
}
|
|
1779
|
+
_responseExtendedDispenseStatusData(e) {
|
|
1780
|
+
const [t] = e.params;
|
|
1781
|
+
this.emit("extended-dispense-status-data", {
|
|
1782
|
+
enabled: parseInt(t, 10) === 1
|
|
1783
|
+
});
|
|
1784
|
+
}
|
|
1785
|
+
_responseTraysPositioningPhototransistorsStatus(e) {
|
|
1786
|
+
const [t, s, n, a, i, c, o, h, p] = e.params, l = {
|
|
1787
|
+
0: "OK",
|
|
1788
|
+
C: "SHORT-CIRCUIT",
|
|
1789
|
+
N: "TRAY-NOT-DETECTED"
|
|
1790
|
+
}, m = {
|
|
1791
|
+
machine: parseInt(t, 10) + 1,
|
|
1792
|
+
trays: {
|
|
1793
|
+
11: l[s] || null,
|
|
1794
|
+
12: l[n] || null,
|
|
1795
|
+
13: l[a] || null,
|
|
1796
|
+
14: l[i] || null,
|
|
1797
|
+
15: l[c] || null,
|
|
1798
|
+
16: l[o] || null,
|
|
1799
|
+
17: l[h] || null,
|
|
1800
|
+
18: l[p] || null
|
|
1801
|
+
}
|
|
1802
|
+
};
|
|
1803
|
+
this.emit("trays-positioning-phototransistors-status", m);
|
|
1804
|
+
}
|
|
1805
|
+
_responseJsdErrorLicenseTemporarilyBlocked(e) {
|
|
1806
|
+
const [t, ...s] = e.params;
|
|
1807
|
+
this.emit("jsd-license-error", {
|
|
1808
|
+
type: "exprired-license",
|
|
1809
|
+
opcode: parseInt(t, 10),
|
|
1810
|
+
actionName: C(parseInt(t, 10)),
|
|
1811
|
+
params: s
|
|
1812
|
+
});
|
|
1813
|
+
}
|
|
1814
|
+
_responseJsdErrorLicenseNotActive(e) {
|
|
1815
|
+
const [t, ...s] = e.params;
|
|
1816
|
+
this.emit("jsd-license-error", {
|
|
1817
|
+
type: "app-number-not-licensed",
|
|
1818
|
+
opcode: parseInt(t, 10),
|
|
1819
|
+
actionName: C(parseInt(t, 10)),
|
|
1820
|
+
params: s
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1823
|
+
_responseJsdErrorCommandNotExecutable(e) {
|
|
1824
|
+
const [t, ...s] = e.params;
|
|
1825
|
+
this.emit("jsd-license-error", {
|
|
1826
|
+
type: "price-control-active-direct-dispense-not-allowed",
|
|
1827
|
+
opcode: parseInt(t),
|
|
1828
|
+
actionName: C(parseInt(t, 10)),
|
|
1829
|
+
params: s
|
|
1830
|
+
});
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
const g = {
|
|
1834
|
+
requestLogsEvents: 101,
|
|
1835
|
+
requestLogsByDate: 102,
|
|
1836
|
+
requestForSendingManifest: 110,
|
|
1837
|
+
sendManifestDataBlock: 111,
|
|
1838
|
+
responseCmdWrong: 200,
|
|
1839
|
+
responseLineLogEvent: 201,
|
|
1840
|
+
responseManifestDataBlock: 210,
|
|
1841
|
+
responseManifestCompleted: 211
|
|
1842
|
+
}, x = (d) => Object.keys(g).find((t) => g[t] === d) || "Unknown";
|
|
1843
|
+
class P {
|
|
1844
|
+
transport;
|
|
1845
|
+
static APP_ID = f.MANIFESTS_AND_LOGS;
|
|
1846
|
+
// Manifest & Logs Application ID
|
|
1847
|
+
constructor(e) {
|
|
1848
|
+
this.transport = e;
|
|
1849
|
+
}
|
|
1850
|
+
/**
|
|
1851
|
+
* Opcode 101: Request for logs events.
|
|
1852
|
+
* @param previous Boolean indicating whether to request previous logs (true) or current logs (false). Defaults to false.
|
|
1853
|
+
* @returns The generated packet as a number array.
|
|
1854
|
+
*/
|
|
1855
|
+
requestLogsEvents(e = !1) {
|
|
1856
|
+
const s = `${e ? "+" : "0"}`;
|
|
1857
|
+
return this.transport.buildPacket(g.requestLogsEvents, s, P.APP_ID);
|
|
1858
|
+
}
|
|
1859
|
+
/**
|
|
1860
|
+
* Opcode 102: Request logs by date range.
|
|
1861
|
+
* @param since Start date in MMDDhhmmss format.
|
|
1862
|
+
* @param until End date in MMDDhhmmss format.
|
|
1863
|
+
* @returns The generated packet as a number array.
|
|
1864
|
+
*/
|
|
1865
|
+
requestLogsByDate(e, t) {
|
|
1866
|
+
const s = `${e},${t}`;
|
|
1867
|
+
return this.transport.buildPacket(g.requestLogsByDate, s, P.APP_ID);
|
|
1868
|
+
}
|
|
1869
|
+
/**
|
|
1870
|
+
* Opcode 110: Request for sending manifest.
|
|
1871
|
+
* @param fileSizeBytes Size of the file in bytes.
|
|
1872
|
+
* @param crcFile CRC of the file.
|
|
1873
|
+
* @returns The generated packet as a number array.
|
|
1874
|
+
*/
|
|
1875
|
+
requestForSendingManifest(e, t) {
|
|
1876
|
+
const s = `${e},${t}`;
|
|
1877
|
+
return this.transport.buildPacket(g.requestForSendingManifest, s, P.APP_ID);
|
|
1878
|
+
}
|
|
1879
|
+
/**
|
|
1880
|
+
* Opcode 111: Send manifest data block.
|
|
1881
|
+
* @param prevBlockId Previous block ID.
|
|
1882
|
+
* @param dataBlock Data block buffer.
|
|
1883
|
+
* @returns The generated packet as a number array.
|
|
1884
|
+
*/
|
|
1885
|
+
sendManifestDataBlock(e, t) {
|
|
1886
|
+
const s = Array.from(t).map((a) => a.toString(2).padStart(8, "0")).join(" "), n = `${e},${s}`;
|
|
1887
|
+
return this.transport.buildPacket(g.sendManifestDataBlock, n, P.APP_ID);
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
class R {
|
|
1891
|
+
_commands;
|
|
1892
|
+
jsd;
|
|
1893
|
+
APP_ID = f.MANIFESTS_AND_LOGS;
|
|
1894
|
+
_logs = {
|
|
1895
|
+
status: "idle",
|
|
1896
|
+
data: []
|
|
1897
|
+
};
|
|
1898
|
+
constructor(e, t) {
|
|
1899
|
+
this._commands = new P(t), this.jsd = e;
|
|
1900
|
+
}
|
|
1901
|
+
async send(e, t) {
|
|
1902
|
+
return this.jsd._lastApplicationCode = this.APP_ID, this.jsd._toQueue(e, {
|
|
1903
|
+
alias: t.alias,
|
|
1904
|
+
waitResponse: t.waitResponse || !1,
|
|
1905
|
+
timeout: t.timeout || 500
|
|
1906
|
+
});
|
|
1907
|
+
}
|
|
1908
|
+
get cmd() {
|
|
1909
|
+
return this._commands;
|
|
1910
|
+
}
|
|
1911
|
+
/**
|
|
1912
|
+
* Request logs events.
|
|
1913
|
+
* @param options Object containing the previous flag.
|
|
1914
|
+
* @param options.previous Boolean indicating whether to request previous logs.
|
|
1915
|
+
* @returns Promise resolving when the command is sent.
|
|
1916
|
+
*/
|
|
1917
|
+
async requestLogsEvent({ previous: e }) {
|
|
1918
|
+
const t = this.cmd.requestLogsEvents(e);
|
|
1919
|
+
return await this.send(t, { alias: "requestLogsEvents" });
|
|
1920
|
+
}
|
|
1921
|
+
/**
|
|
1922
|
+
* Request logs and return them as an array of strings.
|
|
1923
|
+
* This method will handle the fetching of logs in batches if necessary.
|
|
1924
|
+
* @returns Promise resolving to an array of log strings.
|
|
1925
|
+
* @throws Error if logs are already being fetched.
|
|
1926
|
+
*/
|
|
1927
|
+
async requestLogs() {
|
|
1928
|
+
if (["fetching", "more"].includes(this._logs.status))
|
|
1929
|
+
throw new Error("Already fetching logs");
|
|
1930
|
+
return this._logs.status = "fetching", this.requestLogsEvent({ previous: !1 }), new Promise((e) => {
|
|
1931
|
+
const t = setInterval(() => {
|
|
1932
|
+
if (this._logs.status === "completed") {
|
|
1933
|
+
clearInterval(t);
|
|
1934
|
+
const s = this._logs.data;
|
|
1935
|
+
e(s);
|
|
1936
|
+
} else this._logs.status === "more" && (this._logs.status = "fetching", this.requestLogsEvent({ previous: !0 }));
|
|
1937
|
+
}, 100);
|
|
1938
|
+
});
|
|
1939
|
+
}
|
|
1940
|
+
/**
|
|
1941
|
+
* Request logs by date range.
|
|
1942
|
+
* @param options Object containing start and end dates.
|
|
1943
|
+
* @param options.since Start date.
|
|
1944
|
+
* @param options.until End date.
|
|
1945
|
+
* @returns Promise resolving when the command is sent.
|
|
1946
|
+
*/
|
|
1947
|
+
async requestLogsByDate({ since: e, until: t }) {
|
|
1948
|
+
const s = (c) => {
|
|
1949
|
+
const o = String(c.getMonth() + 1).padStart(2, "0"), h = String(c.getDate()).padStart(2, "0"), p = String(c.getHours()).padStart(2, "0"), l = String(c.getMinutes()).padStart(2, "0"), m = String(c.getSeconds()).padStart(2, "0");
|
|
1950
|
+
return `${o}/${h}/${p}/${l}/${m}`;
|
|
1951
|
+
}, n = s(e), a = s(t), i = this.cmd.requestLogsByDate(n, a);
|
|
1952
|
+
return await this.send(i, { alias: "requestLogsByDate" });
|
|
1953
|
+
}
|
|
1954
|
+
/**
|
|
1955
|
+
* Request to Start Sending Manifest.
|
|
1956
|
+
* @param options Object containing file size and CRC.
|
|
1957
|
+
* @param options.fileSizeBytes Size of the file in bytes.
|
|
1958
|
+
* @param options.crc CRC of the file.
|
|
1959
|
+
* @returns Promise resolving when the command is sent.
|
|
1960
|
+
*/
|
|
1961
|
+
async requestForSendingManifest({ fileSizeBytes: e, crc: t }) {
|
|
1962
|
+
const s = this.cmd.requestForSendingManifest(e, t);
|
|
1963
|
+
return await this.send(s, { alias: "requestForSendingManifest" });
|
|
1964
|
+
}
|
|
1965
|
+
/**
|
|
1966
|
+
* Send a block of manifest data.
|
|
1967
|
+
* @param options Object containing previous block ID and data block.
|
|
1968
|
+
* @param options.prevBlockId ID of the previous block.
|
|
1969
|
+
* @param options.dataBlock Buffer containing the data block.
|
|
1970
|
+
* @returns Promise resolving when the command is sent.
|
|
1971
|
+
*/
|
|
1972
|
+
async sendManifestDataBlock({ prevBlockId: e, dataBlock: t }) {
|
|
1973
|
+
const s = this.cmd.sendManifestDataBlock(e, t);
|
|
1974
|
+
return await this.send(s, { alias: "sendManifestDataBlock" });
|
|
1975
|
+
}
|
|
1976
|
+
serialMessage(e) {
|
|
1977
|
+
switch (e.opcode) {
|
|
1978
|
+
case g.responseCmdWrong:
|
|
1979
|
+
this._responseCmdWrong(e);
|
|
1980
|
+
break;
|
|
1981
|
+
case g.responseLineLogEvent:
|
|
1982
|
+
this._responseLineLogEvent(e);
|
|
1983
|
+
break;
|
|
1984
|
+
case g.responseManifestDataBlock:
|
|
1985
|
+
this._responseManifestDataBlock(e);
|
|
1986
|
+
break;
|
|
1987
|
+
case g.responseManifestCompleted:
|
|
1988
|
+
this._responseManifestCompleted(e);
|
|
1989
|
+
break;
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
emit(e, ...t) {
|
|
1993
|
+
this.jsd.dispatch(`manifest:${e}`, ...t);
|
|
1994
|
+
}
|
|
1995
|
+
_responseCmdWrong(e) {
|
|
1996
|
+
const t = parseInt(e.params[0], 10), s = e.params.slice(1), n = x(t);
|
|
1997
|
+
this.emit("wrong-cmd", {
|
|
1998
|
+
opcodeName: n,
|
|
1999
|
+
opcode: t,
|
|
2000
|
+
params: s
|
|
2001
|
+
});
|
|
2002
|
+
}
|
|
2003
|
+
_responseLineLogEvent(e) {
|
|
2004
|
+
const [...t] = e.params, s = t[0] === "END_LOG";
|
|
2005
|
+
if (s)
|
|
2006
|
+
this._logs.status = "completed";
|
|
2007
|
+
else {
|
|
2008
|
+
const a = t.join(",");
|
|
2009
|
+
this._logs.data.push(a), this._logs.status === "fetching" && (this._logs.status = "more");
|
|
2010
|
+
}
|
|
2011
|
+
const n = s ? "end" : "log";
|
|
2012
|
+
this.emit("log", {
|
|
2013
|
+
type: n,
|
|
2014
|
+
log: t
|
|
2015
|
+
});
|
|
2016
|
+
}
|
|
2017
|
+
_responseManifestDataBlock(e) {
|
|
2018
|
+
const [t, s, n] = e.params;
|
|
2019
|
+
this.emit("block", {
|
|
2020
|
+
blockId: parseInt(t, 10),
|
|
2021
|
+
indexFile: parseInt(s, 10),
|
|
2022
|
+
quantity: parseInt(n, 10)
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
_responseManifestCompleted(e) {
|
|
2026
|
+
const [t] = e.params, s = {
|
|
2027
|
+
0: "Success",
|
|
2028
|
+
1: "CRC Error",
|
|
2029
|
+
2: "Transference interrupted",
|
|
2030
|
+
3: "Reset JSD and try again"
|
|
2031
|
+
};
|
|
2032
|
+
this.emit("completed", {
|
|
2033
|
+
result: s[t] || "Unknown Result",
|
|
2034
|
+
resultKey: parseInt(t, 10)
|
|
2035
|
+
});
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
const S = {
|
|
2039
|
+
requestFeatureStatus: 100,
|
|
2040
|
+
requestTemporaryLicenseStatus: 101,
|
|
2041
|
+
requestSeedData: 102,
|
|
2042
|
+
requestLicenseActivation: 110,
|
|
2043
|
+
responseCmdWrong: 200,
|
|
2044
|
+
responseFeatureStatus: 201,
|
|
2045
|
+
responseSeedData: 202,
|
|
2046
|
+
responseTemporaryLicenseStatus: 203
|
|
2047
|
+
}, B = (d) => Object.keys(S).find((t) => S[t] === d) || "Unknown";
|
|
2048
|
+
class y {
|
|
2049
|
+
transport;
|
|
2050
|
+
static APP_ID = f.LICENSING;
|
|
2051
|
+
// Manifest & Logs Application ID
|
|
2052
|
+
constructor(e) {
|
|
2053
|
+
this.transport = e;
|
|
2054
|
+
}
|
|
2055
|
+
/**
|
|
2056
|
+
* Opcode 100: Request feature status.
|
|
2057
|
+
* @param feature Feature ID to check.
|
|
2058
|
+
* @returns The generated packet as a number array.
|
|
2059
|
+
*/
|
|
2060
|
+
requestFeatureStatus(e) {
|
|
2061
|
+
const t = `${e}`;
|
|
2062
|
+
return this.transport.buildPacket(S.requestFeatureStatus, t, y.APP_ID);
|
|
2063
|
+
}
|
|
2064
|
+
/**
|
|
2065
|
+
* Opcode 101: Request temporary license status.
|
|
2066
|
+
* @returns The generated packet as a number array.
|
|
2067
|
+
*/
|
|
2068
|
+
requestTemporaryLicenseStatus() {
|
|
2069
|
+
return this.transport.buildPacket(S.requestTemporaryLicenseStatus, "", y.APP_ID);
|
|
2070
|
+
}
|
|
2071
|
+
/**
|
|
2072
|
+
* Opcode 102: Request seed data for license generation.
|
|
2073
|
+
* @returns The generated packet as a number array.
|
|
2074
|
+
*/
|
|
2075
|
+
requestSeedData() {
|
|
2076
|
+
return this.transport.buildPacket(S.requestSeedData, "", y.APP_ID);
|
|
2077
|
+
}
|
|
2078
|
+
/**
|
|
2079
|
+
* Opcode 110: Request license activation.
|
|
2080
|
+
* @param licenseFile The license file content or identifier.
|
|
2081
|
+
* @returns The generated packet as a number array.
|
|
2082
|
+
*/
|
|
2083
|
+
requestLicenseActivation(e) {
|
|
2084
|
+
const t = `${e}`;
|
|
2085
|
+
return this.transport.buildPacket(S.requestLicenseActivation, t, y.APP_ID);
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
class $ {
|
|
2089
|
+
_commands;
|
|
2090
|
+
jsd;
|
|
2091
|
+
APP_ID = f.LICENSING;
|
|
2092
|
+
constructor(e, t) {
|
|
2093
|
+
this._commands = new y(t), this.jsd = e;
|
|
2094
|
+
}
|
|
2095
|
+
async send(e, t) {
|
|
2096
|
+
return this.jsd._lastApplicationCode = this.APP_ID, this.jsd._toQueue(e, {
|
|
2097
|
+
alias: t.alias,
|
|
2098
|
+
waitResponse: t.waitResponse || !1,
|
|
2099
|
+
timeout: t.timeout || 500
|
|
2100
|
+
});
|
|
2101
|
+
}
|
|
2102
|
+
get cmd() {
|
|
2103
|
+
return this._commands;
|
|
2104
|
+
}
|
|
2105
|
+
/**
|
|
2106
|
+
* Request feature status.
|
|
2107
|
+
* @param options Object containing the feature ID.
|
|
2108
|
+
* @param options.feature Feature ID to check.
|
|
2109
|
+
* @returns Promise resolving when the command is sent.
|
|
2110
|
+
*/
|
|
2111
|
+
async requestFeatureStatus({ feature: e }) {
|
|
2112
|
+
const t = this.cmd.requestFeatureStatus(e);
|
|
2113
|
+
return this.send(t, { alias: "requestFeatureStatus" });
|
|
2114
|
+
}
|
|
2115
|
+
/**
|
|
2116
|
+
* Request temporary license status.
|
|
2117
|
+
* @returns Promise resolving when the command is sent.
|
|
2118
|
+
*/
|
|
2119
|
+
async requestTemporaryLicenseStatus() {
|
|
2120
|
+
const e = this.cmd.requestTemporaryLicenseStatus();
|
|
2121
|
+
return this.send(e, { alias: "requestTemporaryLicenseStatus" });
|
|
2122
|
+
}
|
|
2123
|
+
/**
|
|
2124
|
+
* Request seed data.
|
|
2125
|
+
* @returns Promise resolving when the command is sent.
|
|
2126
|
+
*/
|
|
2127
|
+
async requestSeedData() {
|
|
2128
|
+
const e = this.cmd.requestSeedData();
|
|
2129
|
+
return this.send(e, { alias: "requestSeedData" });
|
|
2130
|
+
}
|
|
2131
|
+
/**
|
|
2132
|
+
* Request license activation.
|
|
2133
|
+
* @param options Object containing the license string.
|
|
2134
|
+
* @param options.license License string.
|
|
2135
|
+
* @returns Promise resolving when the command is sent.
|
|
2136
|
+
*/
|
|
2137
|
+
async requestLicenseActivation({ license: e }) {
|
|
2138
|
+
const t = this.cmd.requestLicenseActivation(e);
|
|
2139
|
+
return this.send(t, { alias: "requestLicenseActivation" });
|
|
2140
|
+
}
|
|
2141
|
+
serialMessage(e) {
|
|
2142
|
+
switch (e.opcode) {
|
|
2143
|
+
case S.responseCmdWrong:
|
|
2144
|
+
this._responseCmdWrong(e);
|
|
2145
|
+
break;
|
|
2146
|
+
case S.responseFeatureStatus:
|
|
2147
|
+
this._responseFeatureStatus(e);
|
|
2148
|
+
break;
|
|
2149
|
+
case S.responseSeedData:
|
|
2150
|
+
this._responseSeedData(e);
|
|
2151
|
+
break;
|
|
2152
|
+
case S.responseTemporaryLicenseStatus:
|
|
2153
|
+
this._responseTemporaryLicenseStatus(e);
|
|
2154
|
+
break;
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
emit(e, ...t) {
|
|
2158
|
+
this.jsd.dispatch(`licensing:${e}`, ...t);
|
|
2159
|
+
}
|
|
2160
|
+
_responseCmdWrong(e) {
|
|
2161
|
+
const t = parseInt(e.params[0], 10), s = e.params.slice(1), n = B(t);
|
|
2162
|
+
this.emit("wrong-cmd", {
|
|
2163
|
+
opcodeName: n,
|
|
2164
|
+
opcode: t,
|
|
2165
|
+
params: s
|
|
2166
|
+
});
|
|
2167
|
+
}
|
|
2168
|
+
_responseFeatureStatus(e) {
|
|
2169
|
+
const [t, s] = e.params;
|
|
2170
|
+
this.emit("feature-status", {
|
|
2171
|
+
feature: t,
|
|
2172
|
+
active: s === "1"
|
|
2173
|
+
});
|
|
2174
|
+
}
|
|
2175
|
+
_responseSeedData(e) {
|
|
2176
|
+
const [...t] = e.params, s = t.join(","), n = t.map((a) => parseInt(a, 10).toString(16).padStart(2, "0")).join(" ");
|
|
2177
|
+
this.emit("seed", {
|
|
2178
|
+
seed: s,
|
|
2179
|
+
hex: n
|
|
2180
|
+
});
|
|
2181
|
+
}
|
|
2182
|
+
_responseTemporaryLicenseStatus(e) {
|
|
2183
|
+
const [t, s, n] = e.params, a = {
|
|
2184
|
+
0: "Inactive, permanent license",
|
|
2185
|
+
1: "Active",
|
|
2186
|
+
2: "Expired",
|
|
2187
|
+
3: "Blocked up"
|
|
2188
|
+
};
|
|
2189
|
+
this.emit("temporary-license-status", {
|
|
2190
|
+
status: a[t] || "Unknown",
|
|
2191
|
+
remainingDays: parseInt(s, 10),
|
|
2192
|
+
daysSinceExpiration: parseInt(n, 10)
|
|
2193
|
+
});
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
class j {
|
|
2197
|
+
/**
|
|
2198
|
+
* Reverse Transparency (Byte Destuffing).
|
|
2199
|
+
* Converts 0xDB,0xDC -> 0xC0 and 0xDB,0xDD -> 0xDB.
|
|
2200
|
+
* @param escapedBytes - Array of bytes or Buffer with escaped characters.
|
|
2201
|
+
* @returns Array of numbers with unescaped bytes.
|
|
2202
|
+
*/
|
|
2203
|
+
static unescapeBytes(e) {
|
|
2204
|
+
const t = [];
|
|
2205
|
+
for (let s = 0; s < e.length; s++) {
|
|
2206
|
+
const n = e[s];
|
|
2207
|
+
if (n === 219) {
|
|
2208
|
+
const a = e[s + 1];
|
|
2209
|
+
a === 220 ? (t.push(192), s++) : a === 221 ? (t.push(219), s++) : t.push(n);
|
|
2210
|
+
} else
|
|
2211
|
+
t.push(n);
|
|
2212
|
+
}
|
|
2213
|
+
return t;
|
|
2214
|
+
}
|
|
2215
|
+
/**
|
|
2216
|
+
* Parses a raw received frame.
|
|
2217
|
+
* Automatically strips 0xC0 flags if present at the beginning/end.
|
|
2218
|
+
* @param rawFrame - Raw bytes received from JSD device.
|
|
2219
|
+
* @returns Parsed response object or error message string if invalid.
|
|
2220
|
+
*/
|
|
2221
|
+
static parseFrame(e) {
|
|
2222
|
+
let t = e;
|
|
2223
|
+
t.length > 0 && t[0] === 192 && (t = t.slice(1)), t.length > 0 && t[t.length - 1] === 192 && (t = t.slice(0, -1));
|
|
2224
|
+
const s = this.unescapeBytes(t);
|
|
2225
|
+
if (s.length < 1)
|
|
2226
|
+
return console.error("Frame too short"), "Frame too short";
|
|
2227
|
+
const n = s[0], a = s[1], i = s.slice(2, -2), c = s[s.length - 2], o = s[s.length - 1], h = [192, n, a, ...i], [p, l] = T.calculate(h);
|
|
2228
|
+
if (p !== c || l !== o)
|
|
2229
|
+
return console.error("CRC mismatch"), "CRC mismatch";
|
|
2230
|
+
if (n === 2) return { type: "ACK", id: a };
|
|
2231
|
+
if (n === 3) return { type: "NACK", id: a };
|
|
2232
|
+
if (n !== 1)
|
|
2233
|
+
return console.warn("Unknown code"), "Unknown code";
|
|
2234
|
+
if (i.length < 6)
|
|
2235
|
+
return console.error("JConnect header too short"), "JConnect header too short";
|
|
2236
|
+
const m = i[0] | i[1] << 8, I = i[2] | i[3] << 8, D = i[4] | i[5] << 8, v = i.slice(6), A = String.fromCharCode(...v);
|
|
2237
|
+
return {
|
|
2238
|
+
type: "DATA",
|
|
2239
|
+
opcode: D,
|
|
2240
|
+
appId: I,
|
|
2241
|
+
noBytes: m,
|
|
2242
|
+
params: A ? A.split(",") : [],
|
|
2243
|
+
id: a,
|
|
2244
|
+
rawAscii: A
|
|
2245
|
+
};
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
class W {
|
|
2249
|
+
delimiter;
|
|
2250
|
+
buffer;
|
|
2251
|
+
/**
|
|
2252
|
+
* Creates a new DelimiterTransformer instance
|
|
2253
|
+
* @param delimiter - The byte sequence used to split the incoming stream
|
|
2254
|
+
*/
|
|
2255
|
+
constructor(e) {
|
|
2256
|
+
this.delimiter = e, this.buffer = new Uint8Array(0);
|
|
2257
|
+
}
|
|
2258
|
+
/**
|
|
2259
|
+
* Processes each chunk received from the serial port.
|
|
2260
|
+
* Accumulates data in a buffer and enqueues complete messages when delimiters are found.
|
|
2261
|
+
* @param chunk - The incoming data chunk from the stream
|
|
2262
|
+
* @param controller - The transform stream controller to enqueue processed data
|
|
2263
|
+
*/
|
|
2264
|
+
transform(e, t) {
|
|
2265
|
+
const s = new Uint8Array(this.buffer.length + e.length);
|
|
2266
|
+
s.set(this.buffer), s.set(e, this.buffer.length), this.buffer = s;
|
|
2267
|
+
let n;
|
|
2268
|
+
for (; (n = this.findDelimiterIndex()) !== -1; ) {
|
|
2269
|
+
const a = this.buffer.slice(0, n);
|
|
2270
|
+
this.buffer = this.buffer.slice(n + this.delimiter.length), t.enqueue(a);
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
/**
|
|
2274
|
+
* Searches for the exact position of the delimiter in the current buffer.
|
|
2275
|
+
* Performs a byte-by-byte comparison to find the delimiter sequence.
|
|
2276
|
+
* @returns The index of the delimiter's start position, or -1 if not found
|
|
2277
|
+
*/
|
|
2278
|
+
findDelimiterIndex() {
|
|
2279
|
+
for (let e = 0; e <= this.buffer.length - this.delimiter.length; e++) {
|
|
2280
|
+
let t = !0;
|
|
2281
|
+
for (let s = 0; s < this.delimiter.length; s++)
|
|
2282
|
+
if (this.buffer[e + s] !== this.delimiter[s]) {
|
|
2283
|
+
t = !1;
|
|
2284
|
+
break;
|
|
2285
|
+
}
|
|
2286
|
+
if (t) return e;
|
|
2287
|
+
}
|
|
2288
|
+
return -1;
|
|
2289
|
+
}
|
|
2290
|
+
/**
|
|
2291
|
+
* Executes when the stream is closed.
|
|
2292
|
+
* Enqueues any remaining buffered data that hasn't been terminated by a delimiter.
|
|
2293
|
+
* @param controller - The transform stream controller to enqueue any remaining data
|
|
2294
|
+
*/
|
|
2295
|
+
flush(e) {
|
|
2296
|
+
this.buffer.length > 0 && (e.enqueue(this.buffer), this.buffer = new Uint8Array(0));
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
class K extends O {
|
|
2300
|
+
_transport;
|
|
2301
|
+
vision;
|
|
2302
|
+
manifest;
|
|
2303
|
+
licensing;
|
|
2304
|
+
_queue = [];
|
|
2305
|
+
_timeoutPacketId = 0;
|
|
2306
|
+
_runningQueue = !1;
|
|
2307
|
+
_lastApplicationCode = 0;
|
|
2308
|
+
constructor({
|
|
2309
|
+
filters: e = null,
|
|
2310
|
+
config_port: t,
|
|
2311
|
+
no_device: s = 1,
|
|
2312
|
+
socket: n = !1,
|
|
2313
|
+
transport: a = "rs232"
|
|
2314
|
+
} = {}) {
|
|
2315
|
+
const i = new Uint8Array([192]), c = new TransformStream(new W(i));
|
|
2316
|
+
if (super({ filters: e, config_port: t, no_device: s, socket: n, transformStream: c }), this.__internal__.device.type = "jsd", this.__internal__.time.response_general = 500, this.__internal__.time.response_engines = 500, k.getCustom(this.typeDevice, s))
|
|
2317
|
+
throw new Error(`Device ${this.typeDevice} ${s} already exists`);
|
|
2318
|
+
k.add(this), this.#e(), this.getResponseAsUint8Array(), this._transport = a === "rs232" ? new N() : new b(), this.vision = new M(this, this._transport), this.manifest = new R(this, this._transport), this.licensing = new $(this, this._transport);
|
|
2319
|
+
}
|
|
2320
|
+
#e() {
|
|
2321
|
+
const e = [
|
|
2322
|
+
"licensing:wrong-cmd",
|
|
2323
|
+
"licensing:feature-status",
|
|
2324
|
+
"licensing:seed",
|
|
2325
|
+
"licensing:temporary-license-status",
|
|
2326
|
+
"manifest:wrong-cmd",
|
|
2327
|
+
"manifest:log",
|
|
2328
|
+
"manifest:block",
|
|
2329
|
+
"manifest:completed",
|
|
2330
|
+
"vision:wrong-cmd",
|
|
2331
|
+
"vision:machine-status",
|
|
2332
|
+
"vision:channels-progress",
|
|
2333
|
+
"vision:channels",
|
|
2334
|
+
"vision:channel-status",
|
|
2335
|
+
"vision:status-selection",
|
|
2336
|
+
"vision:dispense-status",
|
|
2337
|
+
"vision:selection-dispense-config",
|
|
2338
|
+
"vision:channels-linked-to-selection",
|
|
2339
|
+
"vision:machine-id",
|
|
2340
|
+
"vision:current-temperature",
|
|
2341
|
+
"vision:alarm-faults-events",
|
|
2342
|
+
"vision:time-waiting-for-product-collection",
|
|
2343
|
+
"vision:collect",
|
|
2344
|
+
"vision:reset-sold-out-channels",
|
|
2345
|
+
"vision:time-waiting-after-product-collection",
|
|
2346
|
+
"vision:jsd-version",
|
|
2347
|
+
"vision:active-faults",
|
|
2348
|
+
"vision:jsd-dispensing-queue",
|
|
2349
|
+
"vision:special-characteristics-selection",
|
|
2350
|
+
"vision:perishable-products-config",
|
|
2351
|
+
"vision:active-faults-list",
|
|
2352
|
+
"vision:jsd-status-reset",
|
|
2353
|
+
"vision:extended-dispense-status-data",
|
|
2354
|
+
"vision:trays-positioning-phototransistors-status",
|
|
2355
|
+
"vision:jsd-license-error",
|
|
2356
|
+
"serial:jsd-error",
|
|
2357
|
+
"serial:jsd-ack",
|
|
2358
|
+
"serial:jsd-nack",
|
|
2359
|
+
"serial:jsd-data"
|
|
2360
|
+
];
|
|
2361
|
+
for (const t of e)
|
|
2362
|
+
this.serialRegisterAvailableListener(t);
|
|
2363
|
+
}
|
|
2364
|
+
serialSetConnectionConstant() {
|
|
2365
|
+
const e = this._transport ? this._transport : new N();
|
|
2366
|
+
let t = 255;
|
|
2367
|
+
this._transport && (t = e.packetId, this._transport._overridePacketId(t + 1));
|
|
2368
|
+
const { bytes: s } = u.connection({ transport: e, packetId: t });
|
|
2369
|
+
return s;
|
|
2370
|
+
}
|
|
2371
|
+
send(e, t) {
|
|
2372
|
+
return this.appendToQueue(e, t.alias || "unknown");
|
|
2373
|
+
}
|
|
2374
|
+
onEvent(e, t) {
|
|
2375
|
+
super.on(e, t);
|
|
2376
|
+
}
|
|
2377
|
+
offEvent(e, t) {
|
|
2378
|
+
super.off(e, t);
|
|
2379
|
+
}
|
|
2380
|
+
onceEvent(e, t) {
|
|
2381
|
+
const s = ((...n) => {
|
|
2382
|
+
t(...n), this.offEvent(e, s);
|
|
2383
|
+
});
|
|
2384
|
+
this.onEvent(e, s);
|
|
2385
|
+
}
|
|
2386
|
+
get transport() {
|
|
2387
|
+
return this._transport.name;
|
|
2388
|
+
}
|
|
2389
|
+
acknowledge(e) {
|
|
2390
|
+
return this._transport.buildAckPacket(e);
|
|
2391
|
+
}
|
|
2392
|
+
ack(e) {
|
|
2393
|
+
this.isConnected && this.send(new Uint8Array(this.acknowledge(e)), {
|
|
2394
|
+
alias: "ACK Response"
|
|
2395
|
+
});
|
|
2396
|
+
}
|
|
2397
|
+
_toQueue(e, t) {
|
|
2398
|
+
this._queue.push({
|
|
2399
|
+
packetId: e.packetId,
|
|
2400
|
+
data: e.bytes,
|
|
2401
|
+
alias: t?.alias || "unknown",
|
|
2402
|
+
timeout: t?.timeout || 500,
|
|
2403
|
+
resendCount: 0
|
|
2404
|
+
}), this._runQueue();
|
|
2405
|
+
}
|
|
2406
|
+
_runQueue() {
|
|
2407
|
+
if (this._queue.length === 0 || this._runningQueue)
|
|
2408
|
+
return;
|
|
2409
|
+
const e = this._queue[0];
|
|
2410
|
+
this.isConnected && (this.appendToQueue(new Uint8Array(e.data), e.alias || "unknown"), this._runningQueue = !0, this._timeoutPacketId = setTimeout(() => {
|
|
2411
|
+
const t = this._queue.findIndex((s) => s.packetId === e.packetId);
|
|
2412
|
+
t !== -1 && (e.resendCount < 3 ? (this._queue[t].resendCount += 1, this._runningQueue = !1, this._runQueue()) : (this.dispatch("serial:jsd-error", `No response for packet ID ${e.packetId} after 3 attempts.`), this._queue.splice(t, 1), this._runningQueue = !1, this._queue.length > 0 && this._runQueue()));
|
|
2413
|
+
}, e.timeout));
|
|
2414
|
+
}
|
|
2415
|
+
_dequeue(e) {
|
|
2416
|
+
const t = this._queue.findIndex((s) => s.packetId === e);
|
|
2417
|
+
t !== -1 && (this._queue.splice(t, 1), this._timeoutPacketId && (clearTimeout(this._timeoutPacketId), this._timeoutPacketId = 0), this._runningQueue = !1, this._queue.length > 0 && this._runQueue());
|
|
2418
|
+
}
|
|
2419
|
+
serialMessage(e) {
|
|
2420
|
+
const t = Array.from(structuredClone(e));
|
|
2421
|
+
if (t.length === 0) return;
|
|
2422
|
+
const s = j.parseFrame(t);
|
|
2423
|
+
if (typeof s == "string")
|
|
2424
|
+
this.dispatch("serial:jsd-error", s);
|
|
2425
|
+
else if (s.type === "ACK")
|
|
2426
|
+
this._queue.findIndex((a) => a.packetId === s.id) !== -1 && this._dequeue(s.id), this.dispatch("serial:jsd-ack", s);
|
|
2427
|
+
else if (s.type === "NACK")
|
|
2428
|
+
this.dispatch("serial:jsd-nack", s);
|
|
2429
|
+
else if (s.type === "DATA") {
|
|
2430
|
+
this.ack(s.id), typeof s.appId > "u" && (s.appId = this._lastApplicationCode);
|
|
2431
|
+
const n = s.appId;
|
|
2432
|
+
L(n) && this.vision.serialMessage(s), w(n) && this.manifest.serialMessage(s), F(n) && this.licensing.serialMessage(s), this.dispatch("serial:jsd-data", s);
|
|
2433
|
+
}
|
|
2434
|
+
this.dispatch("serial:message", {
|
|
2435
|
+
raw: e,
|
|
2436
|
+
parsed: s
|
|
2437
|
+
// alias: alias || 'unknown'
|
|
2438
|
+
});
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
export {
|
|
2442
|
+
K as JSD
|
|
2443
|
+
};
|