UNPKG

@danidoble/webserial-vending-commands

Version:
607 lines (606 loc) 16 kB
var m = Object.defineProperty; var h = (p, r, t) => r in p ? m(p, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : p[r] = t; var u = (p, r, t) => h(p, typeof r != "symbol" ? r + "" : r, t); import { p as f, a as w } from "./parser-DRICA5j-.js"; const n = class n { build(r) { const t = this.jofemarCheckSum(r); return n.asHex ? w({ data: new Uint8Array(t), asString: !1 }) : f(t); } calcCheckSums(r) { const t = []; return t.push(r & 255 | 240), t.push(r & 255 | 15), t; } jofemarCheckSum(r) { let t = 0; for (let e = 0; e < r.length; e++) t += r[e]; const a = this.calcCheckSums(t); return r.push(a[0]), r.push(a[1]), r.push(3), new Uint8Array(r); } getTrayAndChannelBySelection(r) { if (r = parseInt(r) + 109, r = r.toString(), r.length !== 3) throw new Error("Invalid selection"); const t = (parseInt(r.substring(0, 2)) + 128).toString(16).padStart(2, "0"), a = (parseInt(r.substring(2, 3)) + 128).toString(16).padStart(2, "0"); return { channel: parseInt(a, 16), tray: parseInt(t, 16) }; } makeDisplayMessage(r = "") { r = r.padEnd(32, " "); const t = []; for (let a = 0; a < 32; a++) t.push(r.charCodeAt(a)); return t; } makeTimeFormat(r) { if (!(r instanceof Date)) throw new Error("Invalid date, must be an instance of Date"); const t = r.getHours().toString().padStart(2, "0"), a = r.getMinutes().toString().padStart(2, "0"), e = r.getDate().toString().padStart(2, "0"), i = (r.getMonth() + 1).toString().padStart(2, "0"), s = r.getFullYear().toString().substring(2, 4), g = `${t}:${a} ${e}-${i}-${s}`, l = []; for (let c = 0; c < 14; c++) l.push(g.charCodeAt(c)); return l; } static connection({ channel: r = 1 } = {}) { return n.instance.build([ 2, 48, 48, 128 + r, 83, 255, 255 ]); } static dispense({ machineChannel: r = 1, selection: t = 1, cart: a = !1 } = { machineChannel: 1, selection: 1, cart: !1 }) { if (t = parseInt(t), isNaN(t) || t < 1 || t > 130) throw new Error("Invalid selection"); const { channel: e, tray: i } = n.instance.getTrayAndChannelBySelection(t); return n.instance.build([ 2, 48, 48, 128 + r, a ? 77 : 86, i, e ]); } static endCartDispense({ machineChannel: r = 1 } = {}) { return n.instance.build([ 2, 48, 48, 128 + r, 77, 128, 128 ]); } static collect({ machineChannel: r = 1 } = {}) { return n.instance.build([ 2, 48, 48, 128 + r, 78, 255, 255 ]); } static reset({ machineChannel: r = 1, type: t = "soldOut" } = {}) { let a = 128; return t === "waiting" ? a = 129 : t === "machine" && (a = 255), n.instance.build([ 2, 48, 48, 128 + r, 82, a, 255 ]); } static status({ machineChannel: r = 1 } = {}) { return n.instance.build([ 2, 48, 48, 128 + r, 83, 255, 255 ]); } static lights({ machineChannel: r = 1, type: t = "on" } = {}) { const a = t === "on" ? 129 : 128; return n.instance.build([ 2, 48, 48, 128 + r, 76, a, 255 ]); } static program({ machineChannel: r = 1, param1: t = 255, param2: a = 255 } = {}) { return n.instance.build([ 2, 48, 48, 128 + r, 80, t, a ]); } static programDisplayLanguage({ machineChannel: r = 1, language: t = "spanish" } = {}) { const a = { spanish: 48, english: 49, french: 50 }; if (!a[t]) throw new Error("Invalid language"); return n.program({ machineChannel: r, param1: 73, param2: a[t] }); } static programBeeper({ machineChannel: r = 1, enable: t = !0 }) { return n.program({ machineChannel: r, param1: 90, param2: t ? 49 : 48 }); } static programDisableWorkingTemperature({ machineChannel: r = 1 }) { return n.program({ machineChannel: r, param1: 84, param2: 128 }); } static programDisableThermometer({ machineChannel: r = 1 }) { return n.programDisableWorkingTemperature({ machineChannel: r }); } static programWorkingTemperature({ machineChannel: r = 1, degrees: t = 0.5, machineType: a = "esplus" } = {}) { typeof t == "string" && (t = parseFloat(t)); const e = a === "iceplus" ? 6.5 : 32, i = a === "iceplus" ? -25 : 0.5; if (isNaN(t) || t < i || t > e || t % 0.5 !== 0) throw new Error( "Invalid degrees, must be a multiple of 0.5 and between 0.5 and 32" ); let s = t * 2 + 128; return a === "iceplus" && (s += 51), s = Math.ceil(s), n.program({ param1: 84, param2: s, machineChannel: r }); } static programIsolationTray({ machineChannel: r = 1, tray: t = 0 }) { if (typeof t == "string" && (t = parseInt(t)), isNaN(t) || t < 0 || t > 12) throw new Error("Invalid tray, valid range is 0 to 12"); const a = t === 0 ? 128 : t + 139; return n.program({ param1: 66, param2: a, machineChannel: r }); } static programTimeToStandbyAfterCollect({ machineChannel: r = 1, seconds: t = 15 } = {}) { if (typeof t == "string" && (t = parseInt(t)), isNaN(t) || t < 15 || t > 120) throw new Error("Invalid seconds, valid range is 15 to 120"); const a = 128 + t; return n.program({ param1: 70, param2: a, machineChannel: r }); } static programTimeToStandbyWithoutCollect({ machineChannel: r = 1, minutes: t = 1 } = {}) { if (typeof t == "string" && (t = parseInt(t)), isNaN(t) || t < 1 || t > 10) throw new Error("Invalid minutes, valid range is 1 to 10"); const a = 128 + t; return n.program({ param1: 72, param2: a, machineChannel: r }); } static programElevatorSpeed({ machineChannel: r = 1, speed: t = "high" } = {}) { const a = { high: 49, low: 48 }; if (!a[t]) throw new Error("Invalid speed, valid speeds are 'high' and 'low'"); return n.program({ param1: 118, param2: a[t], machineChannel: r }); } static programTemperatureExpiration({ machineChannel: r = 1, enable: t = !1 }) { return n.program({ machineChannel: r, param1: 99, param2: t ? 49 : 48 }); } static programMachineAddress({ machineChannel: r = 1, address: t = 1 }) { if (typeof t == "string" && (t = parseInt(t)), isNaN(t) || t < 1 || t > 31) throw new Error("Invalid address, valid range is 1 to 31"); return n.program({ param1: 100, param2: 128 + t, machineChannel: r }); } static programTemperatureBeforeExpiration({ machineChannel: r = 1, degrees: t = 0.5 }) { if (typeof t == "string" && (t = parseFloat(t)), isNaN(t) || t < 0.5 || t > 30 || t % 0.5 !== 0) throw new Error( "Invalid degrees, must be a multiple of 0.5 and valid range is 0.5 to 30" ); const a = 128 + t * 2; return n.program({ param1: 101, param2: a, machineChannel: r }); } static programTimeBeforeExpirationByTemperature({ machineChannel: r = 1, minutes: t = 1 }) { if (typeof t == "string" && (t = parseInt(t)), isNaN(t) || t < 1 || t > 120) throw new Error("Invalid minutes, valid range is 1 to 120"); const a = 128 + t; return n.program({ param1: 102, param2: a, machineChannel: r }); } static programTemperatureScale({ machineChannel: r = 1, scale: t = "celsius" } = {}) { const a = { celsius: 67, fahrenheit: 70 }; if (!a[t]) throw new Error( "Invalid scale, valid scales are 'celsius' and 'fahrenheit'" ); return n.program({ param1: 103, param2: a[t], machineChannel: r }); } static programVoltageEngine({ machineChannel: r = 1, selection: t = 1, voltage: a = 5 } = {}) { if (typeof a == "string" && (a = parseFloat(a)), typeof t == "string" && (t = parseInt(t)), isNaN(t) || t < 1 || t > 130) throw new Error("Invalid selection, valid range is 1 to 130"); if (isNaN(a) || a < 5 || a > 9.5 || a % 0.5 !== 0) throw new Error("Invalid voltage, valid range is 5 to 9.5"); const e = 109 + t, s = 128 + (a - 5) * 2; return n.instance.build([ 2, 48, 48, 128 + r, 71, e, s ]); } static programPushOverProducts({ machineChannel: r = 1, selection: t = 1, enable: a = !0 } = {}) { if (typeof t == "string" && (t = parseInt(t)), isNaN(t) || t < 1 || t > 130) throw new Error("Invalid selection, valid range is 1 to 130"); const e = 109 + t, i = a ? 49 : 48; return n.instance.build([ 2, 48, 48, 128 + r, 79, e, i ]); } static programChannelRunningAfterDispense({ machineChannel: r = 1, selection: t = 1, seconds: a = 0 } = {}) { if (typeof t == "string" && (t = parseInt(t)), typeof a == "string" && (a = parseFloat(a)), isNaN(t) || t < 1 || t > 130) throw new Error("Invalid selection, valid range is 1 to 130"); if (isNaN(a) || a < 0 || a > 10 || a % 0.1 !== 0) throw new Error( "Invalid seconds, valid range is 0.0 to 10.0 with a step of 0.1" ); const e = 109 + t; a = 10 * parseFloat(a.toFixed(1)); const i = 128 + a; return n.instance.build([ 2, 48, 48, 128 + r, 69, e, i ]); } static checkData({ machineChannel: r = 1, type: t = 255, aux: a = 255 }) { return n.instance.build([ 2, 48, 48, 128 + r, 67, t, a ]); } static getDisplayLanguage({ machineChannel: r = 1 }) { return n.checkData({ machineChannel: r, type: 73 }); } static getBeeper({ machineChannel: r = 1 }) { return n.checkData({ machineChannel: r, type: 90 }); } static getWorkingTemperature({ machineChannel: r = 1 }) { return n.checkData({ machineChannel: r, type: 84 }); } static getIsolationTray({ machineChannel: r = 1 }) { return n.checkData({ machineChannel: r, type: 66 }); } static getProgramVersion({ machineChannel: r = 1 }) { return n.checkData({ machineChannel: r, type: 80 }); } static getFaults({ machineChannel: r = 1 }) { return n.checkData({ machineChannel: r, type: 83 }); } static getMachineId({ machineChannel: r = 1 }) { return n.checkData({ machineChannel: r, type: 78 }); } static getCurrentTemperature({ machineChannel: r = 1 }) { return n.checkData({ machineChannel: r, type: 116 }); } static getTimeToStandbyAfterCollect({ machineChannel: r = 1 }) { return n.checkData({ machineChannel: r, type: 70 }); } static getTimeToStandbyWithoutCollect({ machineChannel: r = 1 }) { return n.checkData({ machineChannel: r, type: 72 }); } static getElevatorSpeed({ machineChannel: r = 1 }) { return n.checkData({ machineChannel: r, type: 118 }); } static getTemperatureExpiration({ machineChannel: r = 1 }) { return n.checkData({ machineChannel: r, type: 99 }); } static getTemperatureBeforeExpiration({ machineChannel: r = 1 }) { return n.checkData({ machineChannel: r, type: 101 }); } static getTimeBeforeExpirationByTemperature({ machineChannel: r = 1 }) { return n.checkData({ machineChannel: r, type: 102 }); } static getTemperatureScale({ machineChannel: r = 1 }) { return n.checkData({ machineChannel: r, type: 103 }); } static getClockRegisters({ machineChannel: r = 1 }) { return n.checkData({ machineChannel: r, type: 114 }); } static getMachineActivity({ machineChannel: r = 1 }) { return n.checkData({ machineChannel: r, type: 65 }); } static getVoltageEngine({ machineChannel: r = 1, selection: t = 1 }) { if (typeof t == "string" && (t = parseInt(t)), isNaN(t) || t < 1 || t > 130) throw new Error("Invalid selection, valid range is 1 to 130"); return n.checkData({ machineChannel: r, type: 71, aux: 109 + t }); } static getChannelPresence({ machineChannel: r = 1, selection: t = 1 } = {}) { if (typeof t == "string" && (t = parseInt(t)), isNaN(t) || t < 1 || t > 130) throw new Error("Invalid selection, valid range is 1 to 130"); return n.checkData({ machineChannel: r, type: 67, aux: 109 + t }); } static getPushOverProducts({ machineChannel: r = 1, selection: t = 1 } = {}) { if (typeof t == "string" && (t = parseInt(t)), isNaN(t) || t < 1 || t > 130) throw new Error("Invalid selection, valid range is 1 to 130"); return n.checkData({ machineChannel: r, type: 79, aux: 109 + t }); } static getChannelRunningAfterDispense({ machineChannel: r = 1, selection: t = 1 } = {}) { if (typeof t == "string" && (t = parseInt(t)), isNaN(t) || t < 1 || t > 130) throw new Error("Invalid selection, valid range is 1 to 130"); return n.checkData({ machineChannel: r, type: 69, aux: 109 + t }); } static displayConfig({ machineChannel: r = 1, type: t = 128, param2: a = [] } = {}) { return n.instance.build([ 2, 48, 48, 128 + r, 68, t, ...a ]); } static setDisplayStandbyMessage({ machineChannel: r = 1, message: t = "" } = {}) { t = t.substring(0, 32); const a = n.instance.makeDisplayMessage(t); return n.displayConfig({ machineChannel: r, type: 128, param2: a }); } static setDisplayMessageTemporarily({ machineChannel: r = 1, message: t = "", seconds: a = 1 }) { if (t = t.substring(0, 32), typeof a == "string" && (a = parseInt(a)), isNaN(a) || a < 1 || a > 125) throw new Error("Invalid seconds, valid range is 1 to 125"); const e = n.instance.makeDisplayMessage(t), i = 128 + a; return n.displayConfig({ machineChannel: r, type: i, param2: e }); } static setDisplayMessageUnlimited({ machineChannel: r = 1, message: t = "" }) { t = t.substring(0, 32); const a = n.instance.makeDisplayMessage(t); return n.displayConfig({ machineChannel: r, type: 255, param2: a }); } static programClock({ machineChannel: r = 1, date: t = /* @__PURE__ */ new Date() } = {}) { if (!(t instanceof Date)) throw new Error("Invalid date, must be an instance of Date"); return n.instance.build([ 2, 48, 48, 128 + r, 114, ...n.instance.makeTimeFormat(t) ]); } static eventsConfig({ machineChannel: r = 1, event: t = null, enable: a = !0 } = {}) { if (t === null) throw new Error("Invalid event"); const e = a ? 49 : 48; return n.instance.build([ 2, 48, 48, 128 + r, 65, t, e ]); } static eventEnable({ machineChannel: r = 1, event: t = null } = {}) { if (t === null) throw new Error("Invalid event"); const a = parseInt(t, 16); if (isNaN(a) || a < 38 || a > 100) throw new Error("Invalid event"); return n.eventsConfig({ machineChannel: r, event: t, enable: !0 }); } static eventDisable({ machineChannel: r = 1, event: t = null } = {}) { if (t === null) throw new Error("Invalid event"); const a = parseInt(t, 16); if (isNaN(a) || a < 38 || a > 100) throw new Error("Invalid event"); return n.eventsConfig({ machineChannel: r, event: t, enable: !1 }); } static sendCustomCode({ code: r = [] } = {}) { if (r.length < 5) throw new Error("Invalid code, minimum length is 5"); return n.instance.build(r); } }; u(n, "asHex", !1), u(n, "instance"); let o = n; o.instance = new o(); export { o as Jofemar };