UNPKG

@danidoble/webserial

Version:
1,349 lines (1,348 loc) 33.6 kB
const g = (i) => { if (i instanceof Uint8Array) return i; if (Array.isArray(i)) return new Uint8Array(i); if (typeof i == "string") return new TextEncoder().encode(i); if (i instanceof ArrayBuffer) return new Uint8Array(i); throw new Error("Unsupported data type"); }, P = ({ data: i, asString: e = !0 }) => e ? Array.from(i).map((n) => n.toString(16).padStart(2, "0")).join(" ") : Array.from(i).map((n) => n.toString(16).padStart(2, "0")); var F = Object.defineProperty, H = (i, e, n) => e in i ? F(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n, S = (i, e, n) => H(i, typeof e != "symbol" ? e + "" : e, n); const C = class m { build(e) { return g(e + m.append); } static connection() { return m.instance.build("CONNECT"); } static connect() { return m.connection(); } static credits() { return m.instance.build("CREDITS"); } static hi() { return m.instance.build("HI"); } static ara() { return m.instance.build("ARA"); } static custom(e) { return m.instance.build(e); } }; S(C, "append", ` `), S(C, "instance"); let k = C; k.instance = new k(); var J = Object.defineProperty, L = (i, e, n) => e in i ? J(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n, N = (i, e, n) => L(i, typeof e != "symbol" ? e + "" : e, n); const b = class c { build(e) { return c.asHex ? P({ data: e, asString: !1 }) : g(e); } serialBoardroidSumHex(e) { let n = 0; for (let t = 0; t < e.length; t++) t === 0 || t === 11 || (n += e[t]); return n; } boardroidCheckSum(e) { return e[11] = this.serialBoardroidSumHex(e), e; } static connection({ channel: e = 1 } = {}) { const n = c.instance.boardroidCheckSum( new Uint8Array([ 241, 5 + e, 0, 0, 0, 0, 0, 0, 0, 0, 242, 248 ]) ); return c.instance.build(n); } static coinPurseConfiguration({ enable: e = !1, high: n = 255, low: t = 255 } = {}) { const a = c.instance.boardroidCheckSum( new Uint8Array([ 241, 193, e ? 1 : 0, n, t, 0, 0, 0, 0, 0, 242, 0 ]) ); return c.instance.build(a); } static coinPurseDispense({ $50c: e = 0, $1: n = 0, $2: t = 0, $5: a = 0, $10: s = 0 } = {}) { if ([e, n, t, a, s].some( (u) => isNaN(u) || typeof u == "string" )) throw new Error("One of the values is not a number"); if (e < 1 && n < 1 && t < 1 && a < 1 && s < 1) throw new Error("No coins to dispense"); const o = c.instance.boardroidCheckSum( new Uint8Array([ 241, 198, e, n, t, a, s, 0, 0, 0, 242, 0 ]) ); return c.instance.build(o); } static coinPurseReadTubes() { const e = c.instance.boardroidCheckSum( new Uint8Array([ 241, 194, 0, 0, 0, 0, 0, 0, 0, 0, 242, 0 ]) ); return c.instance.build(e); } static banknotePurseICTConfigure({ enable: e = !1, scrow: n = !1 } = {}) { const t = e ? 255 : 0, a = n ? 255 : 0, s = c.instance.boardroidCheckSum( new Uint8Array([ 241, 192, t, t, a, a, 0, 0, 0, 0, 242, 0 ]) ); return c.instance.build(s); } static banknotePurseOtherConfigure({ enable: e = !1, scrow: n = !1 } = {}) { const t = e ? 1 : 0, a = n ? 1 : 0, s = c.instance.boardroidCheckSum( new Uint8Array([ 241, 192, t, a, 0, 0, 0, 0, 0, 0, 242, 0 ]) ); return c.instance.build(s); } static banknotePurseICTDispense({ quantity: e = 1, denomination: n = 20 }) { if (e < 1) throw new Error("No banknotes to dispense"); if ([20, 50, 100, 200, 500].indexOf(n) === -1) throw new Error("Invalid denomination"); const t = [20, 50, 100, 200, 500].indexOf(n), a = c.instance.boardroidCheckSum( new Uint8Array([ 241, 197, t, e, 0, 0, 0, 0, 0, 0, 242, 0 ]) ); return c.instance.build(a); } static banknotePurseOtherDispense({ $20: e = 0, $50: n = 0, $100: t = 0, $200: a = 0, $500: s = 0, $1000: o = 0 } = {}) { if ([e, n, t, a, s, o].some( (d) => isNaN(d) || typeof d == "string" )) throw new Error("One of the values is not a number"); if (e < 1 && n < 1 && t < 1 && a < 1 && s < 1 && o < 1) throw new Error("No banknotes to dispense"); const u = c.instance.boardroidCheckSum( new Uint8Array([ 241, 197, e, n, t, a, s, o, 0, 0, 242, 0 ]) ); return c.instance.build(u); } static banknotePurseAcceptInScrow() { const e = c.instance.boardroidCheckSum( new Uint8Array([ 241, 196, 1, 0, 0, 0, 0, 0, 0, 0, 242, 0 ]) ); return c.instance.build(e); } static banknotePurseRejectInScrow() { const e = c.instance.boardroidCheckSum( new Uint8Array([ 241, 196, 0, 0, 0, 0, 0, 0, 0, 0, 242, 0 ]) ); return c.instance.build(e); } static banknotePurseSaveMemory({ channel: e = null, $20: n = null, $50: t = null, $100: a = null, $200: s = null, $500: o = null, $1000: u = null } = { channel: null, $20: null, $50: null, $100: null, $200: null, $500: null, $1000: null }) { if (e === null || n === null || t === null || a === null || s === null || o === null || u === null) throw new Error( "One of the values is not defined: " + JSON.stringify({ channel: e, $20: n, $50: t, $100: a, $200: s, $500: o, $1000: u }) ); const d = c.instance.boardroidCheckSum( new Uint8Array([ 241, 200, e, 0, n, t, a, s, o, u, 242, 0 ]) ); return c.instance.build(d); } static banknotePurseReadRecycler() { const e = c.instance.boardroidCheckSum( new Uint8Array([ 241, 195, 0, 0, 0, 0, 0, 0, 0, 0, 242, 181 ]) ); return c.instance.build(e); } static cardReaderDisable() { const e = c.instance.boardroidCheckSum( new Uint8Array([ 241, 205, 0, 0, 0, 0, 0, 0, 0, 0, 242, 0 ]) ); return c.instance.build(e); } static cardReaderDispense({ selection: e = 1, second_selection: n = null, sensor: t = !0, seconds: a = null, price: s = 0 } = { selection: 1, second_selection: null, sensor: !0, seconds: null, price: 0 }) { const o = s / 256, u = s % 256, d = e + 9; let p = 0; n && (p = n + 9); let E = 0; t || (a || (a = 1.5), E = Math.round(a * 6.2)); const M = c.instance.boardroidCheckSum( new Uint8Array([ 241, 205, 1, d, p, E, o, u, 0, 0, 242, 0 ]) ); return c.instance.build(M); } static coolingRelayConfigure({ enable: e = !0 } = {}) { const n = c.instance.boardroidCheckSum( new Uint8Array([ 241, 204, e ? 1 : 0, 0, 0, 0, 0, 0, 0, 0, 242, 0 ]) ); return c.instance.build(n); } static readTemperature() { const e = c.instance.boardroidCheckSum( new Uint8Array([ 241, 203, 0, 0, 0, 0, 0, 0, 0, 0, 242, 0 ]) ); return c.instance.build(e); } static dispense({ selection: e = 1, second_selection: n = null, sensor: t = !0, seconds: a = null } = { selection: 1, second_selection: null, sensor: !0, seconds: null }) { e += 9; const s = e; let o = 0; n && (n += 9, o = n); let u = 0; t || (a || (a = 1.5), u = Math.round(a * 6.2)); const d = c.instance.boardroidCheckSum( new Uint8Array([ 241, 199, s, o, u, 0, 0, 0, 0, 0, 242, 0 ]) ); return c.instance.build(d); } static customCode(e) { typeof e[0] == "string" && (e = e.map((t) => parseInt(t, 16))); const n = c.instance.boardroidCheckSum( new Uint8Array(e) ); return c.instance.build(n); } }; N(b, "asHex", !1), N(b, "instance"); let I = b; I.instance = new I(); var B = Object.defineProperty, G = (i, e, n) => e in i ? B(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n, A = (i, e, n) => G(i, typeof e != "symbol" ? e + "" : e, n); const w = class r { build(e) { const n = this.jofemarCheckSum(e); return r.asHex ? P({ data: new Uint8Array(n), asString: !1 }) : g(n); } calcCheckSums(e) { const n = []; return n.push(e & 255 | 240), n.push(e & 255 | 15), n; } jofemarCheckSum(e) { let n = 0; for (let a = 0; a < e.length; a++) n += e[a]; const t = this.calcCheckSums(n); return e.push(t[0]), e.push(t[1]), e.push(3), new Uint8Array(e); } getTrayAndChannelBySelection(e) { if (e = parseInt(e) + 109, e = e.toString(), e.length !== 3) throw new Error("Invalid selection"); const n = (parseInt(e.substring(0, 2)) + 128).toString(16).padStart(2, "0"), t = (parseInt(e.substring(2, 3)) + 128).toString(16).padStart(2, "0"); return { channel: parseInt(t, 16), tray: parseInt(n, 16) }; } makeDisplayMessage(e = "") { e = e.padEnd(32, " "); const n = []; for (let t = 0; t < 32; t++) n.push(e.charCodeAt(t)); return n; } makeTimeFormat(e) { if (!(e instanceof Date)) throw new Error("Invalid date, must be an instance of Date"); const n = e.getHours().toString().padStart(2, "0"), t = e.getMinutes().toString().padStart(2, "0"), a = e.getDate().toString().padStart(2, "0"), s = (e.getMonth() + 1).toString().padStart(2, "0"), o = e.getFullYear().toString().substring(2, 4), u = `${n}:${t} ${a}-${s}-${o}`, d = []; for (let p = 0; p < 14; p++) d.push(u.charCodeAt(p)); return d; } static connection({ channel: e = 1 } = {}) { return r.instance.build([ 2, 48, 48, 128 + e, 83, 255, 255 ]); } static dispense({ machineChannel: e = 1, selection: n = 1, cart: t = !1 } = { machineChannel: 1, selection: 1, cart: !1 }) { if (n = parseInt(n), isNaN(n) || n < 1 || n > 130) throw new Error("Invalid selection"); const { channel: a, tray: s } = r.instance.getTrayAndChannelBySelection(n); return r.instance.build([ 2, 48, 48, 128 + e, t ? 77 : 86, s, a ]); } static endCartDispense({ machineChannel: e = 1 } = {}) { return r.instance.build([ 2, 48, 48, 128 + e, 77, 128, 128 ]); } static collect({ machineChannel: e = 1 } = {}) { return r.instance.build([ 2, 48, 48, 128 + e, 78, 255, 255 ]); } static reset({ machineChannel: e = 1, type: n = "soldOut" } = {}) { let t = 128; return n === "waiting" ? t = 129 : n === "machine" && (t = 255), r.instance.build([ 2, 48, 48, 128 + e, 82, t, 255 ]); } static status({ machineChannel: e = 1 } = {}) { return r.instance.build([ 2, 48, 48, 128 + e, 83, 255, 255 ]); } static lights({ machineChannel: e = 1, type: n = "on" } = {}) { const t = n === "on" ? 129 : 128; return r.instance.build([ 2, 48, 48, 128 + e, 76, t, 255 ]); } static program({ machineChannel: e = 1, param1: n = 255, param2: t = 255 } = {}) { return r.instance.build([ 2, 48, 48, 128 + e, 80, n, t ]); } static programDisplayLanguage({ machineChannel: e = 1, language: n = "spanish" } = {}) { const t = { spanish: 48, english: 49, french: 50 }; if (!t[n]) throw new Error("Invalid language"); return r.program({ machineChannel: e, param1: 73, param2: t[n] }); } static programBeeper({ machineChannel: e = 1, enable: n = !0 }) { return r.program({ machineChannel: e, param1: 90, param2: n ? 49 : 48 }); } static programDisableWorkingTemperature({ machineChannel: e = 1 }) { return r.program({ machineChannel: e, param1: 84, param2: 128 }); } static programDisableThermometer({ machineChannel: e = 1 }) { return r.programDisableWorkingTemperature({ machineChannel: e }); } static programWorkingTemperature({ machineChannel: e = 1, degrees: n = 0.5, machineType: t = "esplus" } = {}) { typeof n == "string" && (n = parseFloat(n)); const a = t === "iceplus" ? 6.5 : 32, s = t === "iceplus" ? -25 : 0.5; if (isNaN(n) || n < s || n > a || n % 0.5 !== 0) throw new Error( "Invalid degrees, must be a multiple of 0.5 and between 0.5 and 32" ); let o = n * 2 + 128; return t === "iceplus" && (o += 51), o = Math.ceil(o), r.program({ param1: 84, param2: o, machineChannel: e }); } static programIsolationTray({ machineChannel: e = 1, tray: n = 0 }) { if (typeof n == "string" && (n = parseInt(n)), isNaN(n) || n < 0 || n > 12) throw new Error("Invalid tray, valid range is 0 to 12"); const t = n === 0 ? 128 : n + 139; return r.program({ param1: 66, param2: t, machineChannel: e }); } static programTimeToStandbyAfterCollect({ machineChannel: e = 1, seconds: n = 15 } = {}) { if (typeof n == "string" && (n = parseInt(n)), isNaN(n) || n < 15 || n > 120) throw new Error("Invalid seconds, valid range is 15 to 120"); const t = 128 + n; return r.program({ param1: 70, param2: t, machineChannel: e }); } static programTimeToStandbyWithoutCollect({ machineChannel: e = 1, minutes: n = 1 } = {}) { if (typeof n == "string" && (n = parseInt(n)), isNaN(n) || n < 1 || n > 10) throw new Error("Invalid minutes, valid range is 1 to 10"); const t = 128 + n; return r.program({ param1: 72, param2: t, machineChannel: e }); } static programElevatorSpeed({ machineChannel: e = 1, speed: n = "high" } = {}) { const t = { high: 49, low: 48 }; if (!t[n]) throw new Error("Invalid speed, valid speeds are 'high' and 'low'"); return r.program({ param1: 118, param2: t[n], machineChannel: e }); } static programTemperatureExpiration({ machineChannel: e = 1, enable: n = !1 }) { return r.program({ machineChannel: e, param1: 99, param2: n ? 49 : 48 }); } static programMachineAddress({ machineChannel: e = 1, address: n = 1 }) { if (typeof n == "string" && (n = parseInt(n)), isNaN(n) || n < 1 || n > 31) throw new Error("Invalid address, valid range is 1 to 31"); return r.program({ param1: 100, param2: 128 + n, machineChannel: e }); } static programTemperatureBeforeExpiration({ machineChannel: e = 1, degrees: n = 0.5 }) { if (typeof n == "string" && (n = parseFloat(n)), isNaN(n) || n < 0.5 || n > 30 || n % 0.5 !== 0) throw new Error( "Invalid degrees, must be a multiple of 0.5 and valid range is 0.5 to 30" ); const t = 128 + n * 2; return r.program({ param1: 101, param2: t, machineChannel: e }); } static programTimeBeforeExpirationByTemperature({ machineChannel: e = 1, minutes: n = 1 }) { if (typeof n == "string" && (n = parseInt(n)), isNaN(n) || n < 1 || n > 120) throw new Error("Invalid minutes, valid range is 1 to 120"); const t = 128 + n; return r.program({ param1: 102, param2: t, machineChannel: e }); } static programTemperatureScale({ machineChannel: e = 1, scale: n = "celsius" } = {}) { const t = { celsius: 67, fahrenheit: 70 }; if (!t[n]) throw new Error( "Invalid scale, valid scales are 'celsius' and 'fahrenheit'" ); return r.program({ param1: 103, param2: t[n], machineChannel: e }); } static programVoltageEngine({ machineChannel: e = 1, selection: n = 1, voltage: t = 5 } = {}) { if (typeof t == "string" && (t = parseFloat(t)), typeof n == "string" && (n = parseInt(n)), isNaN(n) || n < 1 || n > 130) throw new Error("Invalid selection, valid range is 1 to 130"); if (isNaN(t) || t < 5 || t > 9.5 || t % 0.5 !== 0) throw new Error("Invalid voltage, valid range is 5 to 9.5"); const a = 109 + n, s = 128 + (t - 5) * 2; return r.instance.build([ 2, 48, 48, 128 + e, 71, a, s ]); } static programPushOverProducts({ machineChannel: e = 1, selection: n = 1, enable: t = !0 } = {}) { if (typeof n == "string" && (n = parseInt(n)), isNaN(n) || n < 1 || n > 130) throw new Error("Invalid selection, valid range is 1 to 130"); const a = 109 + n, s = t ? 49 : 48; return r.instance.build([ 2, 48, 48, 128 + e, 79, a, s ]); } static programChannelRunningAfterDispense({ machineChannel: e = 1, selection: n = 1, seconds: t = 0 } = {}) { if (typeof n == "string" && (n = parseInt(n)), typeof t == "string" && (t = parseFloat(t)), isNaN(n) || n < 1 || n > 130) throw new Error("Invalid selection, valid range is 1 to 130"); if (isNaN(t) || t < 0 || t > 10 || t % 0.1 !== 0) throw new Error( "Invalid seconds, valid range is 0.0 to 10.0 with a step of 0.1" ); const a = 109 + n; t = 10 * parseFloat(t.toFixed(1)); const s = 128 + t; return r.instance.build([ 2, 48, 48, 128 + e, 69, a, s ]); } static checkData({ machineChannel: e = 1, type: n = 255, aux: t = 255 }) { return r.instance.build([ 2, 48, 48, 128 + e, 67, n, t ]); } static getDisplayLanguage({ machineChannel: e = 1 }) { return r.checkData({ machineChannel: e, type: 73 }); } static getBeeper({ machineChannel: e = 1 }) { return r.checkData({ machineChannel: e, type: 90 }); } static getWorkingTemperature({ machineChannel: e = 1 }) { return r.checkData({ machineChannel: e, type: 84 }); } static getIsolationTray({ machineChannel: e = 1 }) { return r.checkData({ machineChannel: e, type: 66 }); } static getProgramVersion({ machineChannel: e = 1 }) { return r.checkData({ machineChannel: e, type: 80 }); } static getFaults({ machineChannel: e = 1 }) { return r.checkData({ machineChannel: e, type: 83 }); } static getMachineId({ machineChannel: e = 1 }) { return r.checkData({ machineChannel: e, type: 78 }); } static getCurrentTemperature({ machineChannel: e = 1 }) { return r.checkData({ machineChannel: e, type: 116 }); } static getTimeToStandbyAfterCollect({ machineChannel: e = 1 }) { return r.checkData({ machineChannel: e, type: 70 }); } static getTimeToStandbyWithoutCollect({ machineChannel: e = 1 }) { return r.checkData({ machineChannel: e, type: 72 }); } static getElevatorSpeed({ machineChannel: e = 1 }) { return r.checkData({ machineChannel: e, type: 118 }); } static getTemperatureExpiration({ machineChannel: e = 1 }) { return r.checkData({ machineChannel: e, type: 99 }); } static getTemperatureBeforeExpiration({ machineChannel: e = 1 }) { return r.checkData({ machineChannel: e, type: 101 }); } static getTimeBeforeExpirationByTemperature({ machineChannel: e = 1 }) { return r.checkData({ machineChannel: e, type: 102 }); } static getTemperatureScale({ machineChannel: e = 1 }) { return r.checkData({ machineChannel: e, type: 103 }); } static getClockRegisters({ machineChannel: e = 1 }) { return r.checkData({ machineChannel: e, type: 114 }); } static getMachineActivity({ machineChannel: e = 1 }) { return r.checkData({ machineChannel: e, type: 65 }); } static getVoltageEngine({ machineChannel: e = 1, selection: n = 1 }) { if (typeof n == "string" && (n = parseInt(n)), isNaN(n) || n < 1 || n > 130) throw new Error("Invalid selection, valid range is 1 to 130"); return r.checkData({ machineChannel: e, type: 71, aux: 109 + n }); } static getChannelPresence({ machineChannel: e = 1, selection: n = 1 } = {}) { if (typeof n == "string" && (n = parseInt(n)), isNaN(n) || n < 1 || n > 130) throw new Error("Invalid selection, valid range is 1 to 130"); return r.checkData({ machineChannel: e, type: 67, aux: 109 + n }); } static getPushOverProducts({ machineChannel: e = 1, selection: n = 1 } = {}) { if (typeof n == "string" && (n = parseInt(n)), isNaN(n) || n < 1 || n > 130) throw new Error("Invalid selection, valid range is 1 to 130"); return r.checkData({ machineChannel: e, type: 79, aux: 109 + n }); } static getChannelRunningAfterDispense({ machineChannel: e = 1, selection: n = 1 } = {}) { if (typeof n == "string" && (n = parseInt(n)), isNaN(n) || n < 1 || n > 130) throw new Error("Invalid selection, valid range is 1 to 130"); return r.checkData({ machineChannel: e, type: 69, aux: 109 + n }); } static displayConfig({ machineChannel: e = 1, type: n = 128, param2: t = [] } = {}) { return r.instance.build([ 2, 48, 48, 128 + e, 68, n, ...t ]); } static setDisplayStandbyMessage({ machineChannel: e = 1, message: n = "" } = {}) { n = n.substring(0, 32); const t = r.instance.makeDisplayMessage(n); return r.displayConfig({ machineChannel: e, type: 128, param2: t }); } static setDisplayMessageTemporarily({ machineChannel: e = 1, message: n = "", seconds: t = 1 }) { if (n = n.substring(0, 32), typeof t == "string" && (t = parseInt(t)), isNaN(t) || t < 1 || t > 125) throw new Error("Invalid seconds, valid range is 1 to 125"); const a = r.instance.makeDisplayMessage(n), s = 128 + t; return r.displayConfig({ machineChannel: e, type: s, param2: a }); } static setDisplayMessageUnlimited({ machineChannel: e = 1, message: n = "" }) { n = n.substring(0, 32); const t = r.instance.makeDisplayMessage(n); return r.displayConfig({ machineChannel: e, type: 255, param2: t }); } static programClock({ machineChannel: e = 1, date: n = /* @__PURE__ */ new Date() } = {}) { if (!(n instanceof Date)) throw new Error("Invalid date, must be an instance of Date"); return r.instance.build([ 2, 48, 48, 128 + e, 114, ...r.instance.makeTimeFormat(n) ]); } static eventsConfig({ machineChannel: e = 1, event: n = null, enable: t = !0 } = {}) { if (n === null) throw new Error("Invalid event"); const a = t ? 49 : 48; return r.instance.build([ 2, 48, 48, 128 + e, 65, n, a ]); } static eventEnable({ machineChannel: e = 1, event: n = null } = {}) { if (n === null) throw new Error("Invalid event"); const t = parseInt(n, 16); if (isNaN(t) || t < 38 || t > 100) throw new Error("Invalid event"); return r.eventsConfig({ machineChannel: e, event: n, enable: !0 }); } static eventDisable({ machineChannel: e = 1, event: n = null } = {}) { if (n === null) throw new Error("Invalid event"); const t = parseInt(n, 16); if (isNaN(t) || t < 38 || t > 100) throw new Error("Invalid event"); return r.eventsConfig({ machineChannel: e, event: n, enable: !1 }); } static sendCustomCode({ code: e = [] } = {}) { if (e.length < 5) throw new Error("Invalid code, minimum length is 5"); return r.instance.build(e); } }; A(w, "asHex", !1), A(w, "instance"); let D = w; D.instance = new D(); var j = Object.defineProperty, W = (i, e, n) => e in i ? j(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n, T = (i, e, n) => W(i, typeof e != "symbol" ? e + "" : e, n); const y = class h { serialLockerCmdMaker(e) { let n; try { n = new Uint8Array(e.length + 8), n.set(e, 2), n[0] = 2, n[1] = e.length + 4, n[n.length - 2] = 3; let t = 0; for (let o = 1; o < e.length; o++) t += e[o], t *= parseInt(Math.pow(2, o - 1).toString()); n[e.length + 2] = t % 256, n[e.length + 3] = 666 * 3 % 256, n[e.length + 4] = 666 * 8 % 256; let a = 0; for (let o = 3; o < e.length + 5; o++) a += n[o]; n[e.length + 5] = a % 256; let s = 0; for (let o = 0; o < n.length - 1; o++) s ^= n[o]; n[n.length - 1] = s; } catch (t) { throw n = new Uint8Array(0), t instanceof Error ? new Error(`Error generating command: ${t.message}`) : new Error("Error generating command: Unknown error"); } return n; } serialLockerHexCmd(e) { const n = this.serialLockerCmdMaker(e), t = []; for (let a = 0; a < n.length; a++) { const s = n[a].toString(16).padStart(2, "0"); t.push(s); } return t; } validateCell(e = 1) { let n; if (typeof e == "string" ? n = parseInt(e) : n = e, isNaN(n) || n < 1 || n > 90) throw new Error("Invalid cell number"); return n; } serialLockerGetStatusCellCmd({ cell: e = 1, channel: n = 1 } = {}) { return e = this.validateCell(e), this.build(new Uint8Array([16, n, e])); } serialLockerGetLightScanCmd({ since: e = 0, until: n = 10, channel: t = 1 } = {}) { return this.build(new Uint8Array([32, t, e, n])); } parseCellToColumnRow(e) { const n = Math.floor((e - 1) / 10) + 1; let t = e % 8; return t === 0 && (t = 8), [n, t]; } serialLockerGetConfigureCellCmd({ enable: e = !0, column: n = 0, row: t = 10, channel: a = 1 } = {}) { if (n < 0 || n > 8) throw new Error("Invalid column number"); if (t < 0 || t > 10) throw new Error("Invalid row number"); let s = 1; return e || (s = 0), this.build(new Uint8Array([48, a, n, t, s])); } serialLockerGetOpenCmd({ cell: e = 1, channel: n = 1 } = {}) { e = this.validateCell(e); const t = 666, a = t % 256, s = Math.floor(t / 3) % 256; return this.build(new Uint8Array([64, n, e, a, s])); } build(e) { return h.asHex ? this.serialLockerHexCmd(e) : g(this.serialLockerCmdMaker(e)); } static connection({ channel: e = 1 } = {}) { return h.instance.build(new Uint8Array([0, e])); } static openCell({ cell: e = 1, channel: n = 1 } = {}) { return e = h.instance.validateCell(e), h.instance.serialLockerGetOpenCmd({ cell: e, channel: n }); } static statusCell({ cell: e = 1, channel: n = 1 } = {}) { return e = h.instance.validateCell(e), h.instance.serialLockerGetStatusCellCmd({ cell: e, channel: n }); } static lightScan({ since: e = 0, until: n = 10, channel: t = 1 } = {}) { if (e < 0 || e > 10) throw new Error("Invalid since number"); if (n < 0 || n > 10) throw new Error("Invalid until number"); return h.instance.serialLockerGetLightScanCmd({ since: e, until: n, channel: t }); } static enableCell({ cell: e = 1, channel: n = 1 } = {}) { e = h.instance.validateCell(e); const [t, a] = h.instance.parseCellToColumnRow(e); return h.instance.serialLockerGetConfigureCellCmd({ enable: !0, column: t, row: a, channel: n }); } static disableCell({ cell: e = 1, channel: n = 1 } = {}) { e = h.instance.validateCell(e); const [t, a] = h.instance.parseCellToColumnRow(e); return h.instance.serialLockerGetConfigureCellCmd({ enable: !1, column: t, row: a, channel: n }); } }; T(y, "asHex", !1), T(y, "instance"); let $ = y; $.instance = new $(); var V = Object.defineProperty, Q = (i, e, n) => e in i ? V(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n, O = (i, e, n) => Q(i, typeof e != "symbol" ? e + "" : e, n); const v = class l { build(e) { return g(e + l.append); } static connection() { const e = JSON.stringify({ action: "CONNECT" }); return l.instance.build(e); } static connect() { return l.connection(); } static custom(e) { if (typeof e != "string") throw new Error("Invalid string"); return l.instance.build(e); } static readQR({ type: e = "production" } = { type: "production" }) { const n = JSON.stringify({ action: "READQR", server: e === "production" ? "PROD" : "QA" }); return l.instance.build(n); } static forceHide() { const e = JSON.stringify({ action: "FORCEHIDE" }); return l.instance.build(e); } static forceShow() { const e = JSON.stringify({ action: "FORCESHOW" }); return l.instance.build(e); } static makeSale({ amount: e = 0, reference: n = null } = {}) { if (e <= 0) throw new Error("Invalid amount"); if (typeof e != "number" && (e = parseFloat(e)), isNaN(e)) throw new Error("Invalid amount"); if (n && !/^[A-Z-a-z0-9_\s]+$/g.test(n)) throw new Error( "Reference must be alphanumeric and the only symbol allowed is midlescore or underscore (- _) or null" ); const t = e.toFixed(2), a = JSON.stringify({ action: "PAYMENT", amount: t, reference: n }); return l.instance.build(a); } static getVoucher({ folio: e = null } = {}) { if (!e) throw new Error("Folio must be a number"); const n = JSON.stringify({ action: "GETVOUCHER", folio: e }); return l.instance.build(n); } static info() { const e = JSON.stringify({ action: "DEVICEINFO" }); return l.instance.build(e); } static keepAlive() { const e = JSON.stringify({ action: "KEEPALIVE" }); return l.instance.build(e); } static restartApp() { const e = JSON.stringify({ action: "RESETAPP" }); return l.instance.build(e); } static getConfig() { const e = JSON.stringify({ action: "GETCONFIG" }); return l.instance.build(e); } static hideButtons() { const e = JSON.stringify({ action: "HIDEBUTTONS" }); return l.instance.build(e); } static showButtons() { const e = JSON.stringify({ action: "SHOWBUTTONS" }); return l.instance.build(e); } static demo() { const e = JSON.stringify({ action: "DEMO" }); return l.instance.build(e); } static refund({ amount: e = 0, folio: n = null, auth: t = null } = {}) { if (e <= 0) throw new Error("Invalid amount"); if (typeof e != "number" && (e = parseFloat(e)), isNaN(e)) throw new Error("Invalid amount"); if (!n) throw new Error("Folio must be a number"); if (!t) throw new Error("Auth must be a number"); const a = e.toFixed(2), s = JSON.stringify({ action: "REFUND", amount: a, folio: n, auth: t }); return l.instance.build(s); } static exit() { const e = JSON.stringify({ action: "EXIT" }); return l.instance.build(e); } static init() { const e = JSON.stringify({ action: "INIT" }); return l.instance.build(e); } static stop() { const e = JSON.stringify({ action: "STOP" }); return l.instance.build(e); } static verifyNetwork() { const e = JSON.stringify({ action: "CHECKINTERNET" }); return l.instance.build(e); } }; O(v, "append", `\r `), O(v, "instance"); let U = v; U.instance = new U(); var K = Object.defineProperty, Y = (i, e, n) => e in i ? K(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n, q = (i, e, n) => Y(i, e + "", n); const R = class f { build(e) { return e[3] = this.withChecksum(e), g(e); } withChecksum(e) { let n = 0; return e.forEach((t, a) => { a !== 3 && (n += t); }), n; } static connection(e = 1) { return f.instance.build([160, e, 0, 161]); } static deactivate(e = 1) { return f.connection(e); } static activate(e = 1) { return f.instance.build([160, e, 1, 162]); } static custom(e) { return f.instance.build(e); } }; q(R, "instance"); let x = R; x.instance = new x(); export { x as e, I as l, D as o, U as s, $ as u };