UNPKG

@danidoble/webserial-vending-commands

Version:
2 lines (1 loc) 11.6 kB
"use strict";var h=Object.defineProperty;var f=(p,r,t)=>r in p?h(p,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):p[r]=t;var c=(p,r,t)=>f(p,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("./parser-Dsi8ZXwF.cjs"),e=class e{build(r){const t=this.jofemarCheckSum(r);return e.asHex?g.Uint8ArrayToHex({data:new Uint8Array(t),asString:!1}):g.parseToBuffer(t)}calcCheckSums(r){const t=[];return t.push(r&255|240),t.push(r&255|15),t}jofemarCheckSum(r){let t=0;for(let n=0;n<r.length;n++)t+=r[n];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"),n=r.getDate().toString().padStart(2,"0"),i=(r.getMonth()+1).toString().padStart(2,"0"),s=r.getFullYear().toString().substring(2,4),m=`${t}:${a} ${n}-${i}-${s}`,l=[];for(let u=0;u<14;u++)l.push(m.charCodeAt(u));return l}static connection({channel:r=1}={}){return e.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:n,tray:i}=e.instance.getTrayAndChannelBySelection(t);return e.instance.build([2,48,48,128+r,a?77:86,i,n])}static endCartDispense({machineChannel:r=1}={}){return e.instance.build([2,48,48,128+r,77,128,128])}static collect({machineChannel:r=1}={}){return e.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),e.instance.build([2,48,48,128+r,82,a,255])}static status({machineChannel:r=1}={}){return e.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 e.instance.build([2,48,48,128+r,76,a,255])}static program({machineChannel:r=1,param1:t=255,param2:a=255}={}){return e.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 e.program({machineChannel:r,param1:73,param2:a[t]})}static programBeeper({machineChannel:r=1,enable:t=!0}){return e.program({machineChannel:r,param1:90,param2:t?49:48})}static programDisableWorkingTemperature({machineChannel:r=1}){return e.program({machineChannel:r,param1:84,param2:128})}static programDisableThermometer({machineChannel:r=1}){return e.programDisableWorkingTemperature({machineChannel:r})}static programWorkingTemperature({machineChannel:r=1,degrees:t=.5,machineType:a="esplus"}={}){typeof t=="string"&&(t=parseFloat(t));const n=a==="iceplus"?6.5:32,i=a==="iceplus"?-25:.5;if(isNaN(t)||t<i||t>n||t%.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),e.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 e.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 e.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 e.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 e.program({param1:118,param2:a[t],machineChannel:r})}static programTemperatureExpiration({machineChannel:r=1,enable:t=!1}){return e.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 e.program({param1:100,param2:128+t,machineChannel:r})}static programTemperatureBeforeExpiration({machineChannel:r=1,degrees:t=.5}){if(typeof t=="string"&&(t=parseFloat(t)),isNaN(t)||t<.5||t>30||t%.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 e.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 e.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 e.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%.5!==0)throw new Error("Invalid voltage, valid range is 5 to 9.5");const n=109+t,s=128+(a-5)*2;return e.instance.build([2,48,48,128+r,71,n,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 n=109+t,i=a?49:48;return e.instance.build([2,48,48,128+r,79,n,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%.1!==0)throw new Error("Invalid seconds, valid range is 0.0 to 10.0 with a step of 0.1");const n=109+t;a=10*parseFloat(a.toFixed(1));const i=128+a;return e.instance.build([2,48,48,128+r,69,n,i])}static checkData({machineChannel:r=1,type:t=255,aux:a=255}){return e.instance.build([2,48,48,128+r,67,t,a])}static getDisplayLanguage({machineChannel:r=1}){return e.checkData({machineChannel:r,type:73})}static getBeeper({machineChannel:r=1}){return e.checkData({machineChannel:r,type:90})}static getWorkingTemperature({machineChannel:r=1}){return e.checkData({machineChannel:r,type:84})}static getIsolationTray({machineChannel:r=1}){return e.checkData({machineChannel:r,type:66})}static getProgramVersion({machineChannel:r=1}){return e.checkData({machineChannel:r,type:80})}static getFaults({machineChannel:r=1}){return e.checkData({machineChannel:r,type:83})}static getMachineId({machineChannel:r=1}){return e.checkData({machineChannel:r,type:78})}static getCurrentTemperature({machineChannel:r=1}){return e.checkData({machineChannel:r,type:116})}static getTimeToStandbyAfterCollect({machineChannel:r=1}){return e.checkData({machineChannel:r,type:70})}static getTimeToStandbyWithoutCollect({machineChannel:r=1}){return e.checkData({machineChannel:r,type:72})}static getElevatorSpeed({machineChannel:r=1}){return e.checkData({machineChannel:r,type:118})}static getTemperatureExpiration({machineChannel:r=1}){return e.checkData({machineChannel:r,type:99})}static getTemperatureBeforeExpiration({machineChannel:r=1}){return e.checkData({machineChannel:r,type:101})}static getTimeBeforeExpirationByTemperature({machineChannel:r=1}){return e.checkData({machineChannel:r,type:102})}static getTemperatureScale({machineChannel:r=1}){return e.checkData({machineChannel:r,type:103})}static getClockRegisters({machineChannel:r=1}){return e.checkData({machineChannel:r,type:114})}static getMachineActivity({machineChannel:r=1}){return e.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 e.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 e.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 e.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 e.checkData({machineChannel:r,type:69,aux:109+t})}static displayConfig({machineChannel:r=1,type:t=128,param2:a=[]}={}){return e.instance.build([2,48,48,128+r,68,t,...a])}static setDisplayStandbyMessage({machineChannel:r=1,message:t=""}={}){t=t.substring(0,32);const a=e.instance.makeDisplayMessage(t);return e.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 n=e.instance.makeDisplayMessage(t),i=128+a;return e.displayConfig({machineChannel:r,type:i,param2:n})}static setDisplayMessageUnlimited({machineChannel:r=1,message:t=""}){t=t.substring(0,32);const a=e.instance.makeDisplayMessage(t);return e.displayConfig({machineChannel:r,type:255,param2:a})}static programClock({machineChannel:r=1,date:t=new Date}={}){if(!(t instanceof Date))throw new Error("Invalid date, must be an instance of Date");return e.instance.build([2,48,48,128+r,114,...e.instance.makeTimeFormat(t)])}static eventsConfig({machineChannel:r=1,event:t=null,enable:a=!0}={}){if(t===null)throw new Error("Invalid event");const n=a?49:48;return e.instance.build([2,48,48,128+r,65,t,n])}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 e.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 e.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 e.instance.build(r)}};c(e,"asHex",!1),c(e,"instance");let o=e;o.instance=new o;exports.Jofemar=o;