@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.
Files changed (116) hide show
  1. package/dist/boardroid.cjs +1 -1
  2. package/dist/boardroid.js +4 -3
  3. package/dist/devices-BndwHuvP.cjs +1 -0
  4. package/dist/devices-CHc7K4eY.js +67 -0
  5. package/dist/hopper.cjs +1 -1
  6. package/dist/hopper.js +1 -1
  7. package/dist/jofemar.cjs +1 -1
  8. package/dist/jofemar.js +30 -29
  9. package/dist/jsd.cjs +1 -0
  10. package/dist/jsd.js +2443 -0
  11. package/dist/kernel-As0xv_MS.cjs +1 -0
  12. package/dist/{kernel-BZzs36vi.js → kernel-CFxkp4Nz.js} +147 -204
  13. package/dist/kernel.cjs +1 -1
  14. package/dist/kernel.js +4 -3
  15. package/dist/locker.cjs +1 -1
  16. package/dist/locker.js +12 -11
  17. package/dist/pinpad.cjs +11 -11
  18. package/dist/pinpad.js +684 -639
  19. package/dist/pinpax.cjs +2 -2
  20. package/dist/pinpax.js +4 -3
  21. package/dist/relay.cjs +1 -1
  22. package/dist/relay.js +8 -7
  23. package/dist/types/lib/commands/jsd/applications/licensing.d.ts +51 -0
  24. package/dist/types/lib/commands/jsd/applications/licensing.d.ts.map +1 -0
  25. package/dist/types/lib/commands/jsd/applications/manifest.d.ts +73 -0
  26. package/dist/types/lib/commands/jsd/applications/manifest.d.ts.map +1 -0
  27. package/dist/types/lib/commands/jsd/applications/vision.d.ts +444 -0
  28. package/dist/types/lib/commands/jsd/applications/vision.d.ts.map +1 -0
  29. package/dist/types/lib/commands/jsd/frames/licensing/licensingClient.d.ts +34 -0
  30. package/dist/types/lib/commands/jsd/frames/licensing/licensingClient.d.ts.map +1 -0
  31. package/dist/types/lib/commands/jsd/frames/licensing/opCodes.d.ts +28 -0
  32. package/dist/types/lib/commands/jsd/frames/licensing/opCodes.d.ts.map +1 -0
  33. package/dist/types/lib/commands/jsd/frames/manifest/manifestClient.d.ts +40 -0
  34. package/dist/types/lib/commands/jsd/frames/manifest/manifestClient.d.ts.map +1 -0
  35. package/dist/types/lib/commands/jsd/frames/manifest/opCodes.d.ts +28 -0
  36. package/dist/types/lib/commands/jsd/frames/manifest/opCodes.d.ts.map +1 -0
  37. package/dist/types/lib/commands/jsd/frames/vision/opCodes.d.ts +72 -0
  38. package/dist/types/lib/commands/jsd/frames/vision/opCodes.d.ts.map +1 -0
  39. package/dist/types/lib/commands/jsd/frames/vision/visionClient.d.ts +336 -0
  40. package/dist/types/lib/commands/jsd/frames/vision/visionClient.d.ts.map +1 -0
  41. package/dist/types/lib/commands/jsd/protocol/crc16.d.ts +37 -0
  42. package/dist/types/lib/commands/jsd/protocol/crc16.d.ts.map +1 -0
  43. package/dist/types/lib/commands/jsd/protocol/responseHandler.d.ts +38 -0
  44. package/dist/types/lib/commands/jsd/protocol/responseHandler.d.ts.map +1 -0
  45. package/dist/types/lib/commands/jsd/protocol/rs232Strategy.d.ts +23 -0
  46. package/dist/types/lib/commands/jsd/protocol/rs232Strategy.d.ts.map +1 -0
  47. package/dist/types/lib/commands/jsd/protocol/tcpIpStrategy.d.ts +49 -0
  48. package/dist/types/lib/commands/jsd/protocol/tcpIpStrategy.d.ts.map +1 -0
  49. package/dist/types/lib/commands/jsd/types/LicensingClient.d.ts +32 -0
  50. package/dist/types/lib/commands/jsd/types/LicensingClient.d.ts.map +1 -0
  51. package/dist/types/lib/commands/jsd/types/jsd.types.d.ts +140 -0
  52. package/dist/types/lib/commands/jsd/types/jsd.types.d.ts.map +1 -0
  53. package/dist/types/lib/commands/jsd/types/manifestClient.d.ts +40 -0
  54. package/dist/types/lib/commands/jsd/types/manifestClient.d.ts.map +1 -0
  55. package/dist/types/lib/commands/jsd/types/transport.types.d.ts +29 -0
  56. package/dist/types/lib/commands/jsd/types/transport.types.d.ts.map +1 -0
  57. package/dist/types/lib/commands/jsd/types/visionClient.types.d.ts +356 -0
  58. package/dist/types/lib/commands/jsd/types/visionClient.types.d.ts.map +1 -0
  59. package/dist/types/lib/commands/jsd/utils/aplications.d.ts +48 -0
  60. package/dist/types/lib/commands/jsd/utils/aplications.d.ts.map +1 -0
  61. package/dist/types/lib/commands/jsd/utils/helpers.d.ts +15 -0
  62. package/dist/types/lib/commands/jsd/utils/helpers.d.ts.map +1 -0
  63. package/dist/types/lib/kernel.d.ts.map +1 -0
  64. package/dist/types/{main.d.ts → lib/main.d.ts} +6 -0
  65. package/dist/types/lib/main.d.ts.map +1 -0
  66. package/dist/types/lib/parsers/delimiterTransformer.d.ts +29 -0
  67. package/dist/types/lib/parsers/delimiterTransformer.d.ts.map +1 -0
  68. package/dist/types/lib/serial/boardroid.d.ts.map +1 -0
  69. package/dist/types/lib/serial/hopper.d.ts.map +1 -0
  70. package/dist/types/lib/serial/jofemar.d.ts.map +1 -0
  71. package/dist/types/lib/serial/jsd.d.ts +40 -0
  72. package/dist/types/lib/serial/jsd.d.ts.map +1 -0
  73. package/dist/types/{serial → lib/serial}/kernel.d.ts +1 -0
  74. package/dist/types/{serial → lib/serial}/kernel.d.ts.map +1 -1
  75. package/dist/types/lib/serial/locker.d.ts.map +1 -0
  76. package/dist/types/lib/serial/pinpad.d.ts.map +1 -0
  77. package/dist/types/lib/serial/pinpax.d.ts.map +1 -0
  78. package/dist/types/lib/serial/relay.d.ts.map +1 -0
  79. package/dist/types/{utils → lib/utils}/devices.d.ts +2 -0
  80. package/dist/types/lib/utils/devices.d.ts.map +1 -0
  81. package/dist/types/lib/utils/dispatcher.d.ts.map +1 -0
  82. package/dist/types/lib/utils/emulator.d.ts.map +1 -0
  83. package/dist/types/lib/utils/utils.d.ts.map +1 -0
  84. package/dist/types/test/t.d.ts +2 -0
  85. package/dist/types/test/t.d.ts.map +1 -0
  86. package/dist/webserial-core-3UL91lxi.cjs +4 -0
  87. package/dist/{webserial-core-Zwd9L-Y9.js → webserial-core-DSv1dX3s.js} +160 -148
  88. package/dist/webserial.cjs +1 -1
  89. package/dist/webserial.js +29 -23
  90. package/package.json +15 -10
  91. package/dist/kernel-7ObJp74F.cjs +0 -1
  92. package/dist/types/kernel.d.ts.map +0 -1
  93. package/dist/types/main.d.ts.map +0 -1
  94. package/dist/types/serial/boardroid.d.ts.map +0 -1
  95. package/dist/types/serial/hopper.d.ts.map +0 -1
  96. package/dist/types/serial/jofemar.d.ts.map +0 -1
  97. package/dist/types/serial/locker.d.ts.map +0 -1
  98. package/dist/types/serial/pinpad.d.ts.map +0 -1
  99. package/dist/types/serial/pinpax.d.ts.map +0 -1
  100. package/dist/types/serial/relay.d.ts.map +0 -1
  101. package/dist/types/utils/devices.d.ts.map +0 -1
  102. package/dist/types/utils/dispatcher.d.ts.map +0 -1
  103. package/dist/types/utils/emulator.d.ts.map +0 -1
  104. package/dist/types/utils/utils.d.ts.map +0 -1
  105. package/dist/webserial-core-Co8HLQvu.cjs +0 -4
  106. /package/dist/types/{kernel.d.ts → lib/kernel.d.ts} +0 -0
  107. /package/dist/types/{serial → lib/serial}/boardroid.d.ts +0 -0
  108. /package/dist/types/{serial → lib/serial}/hopper.d.ts +0 -0
  109. /package/dist/types/{serial → lib/serial}/jofemar.d.ts +0 -0
  110. /package/dist/types/{serial → lib/serial}/locker.d.ts +0 -0
  111. /package/dist/types/{serial → lib/serial}/pinpad.d.ts +0 -0
  112. /package/dist/types/{serial → lib/serial}/pinpax.d.ts +0 -0
  113. /package/dist/types/{serial → lib/serial}/relay.d.ts +0 -0
  114. /package/dist/types/{utils → lib/utils}/dispatcher.d.ts +0 -0
  115. /package/dist/types/{utils → lib/utils}/emulator.d.ts +0 -0
  116. /package/dist/types/{utils → lib/utils}/utils.d.ts +0 -0
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./kernel-7ObJp74F.cjs"),l=require("./relay-E3NCcSjS.cjs");class p extends c.Kernel{__coin_purse={available:!0};__banknote_purse={available:!0,isRecycler:!0,recycler:{ict:!0,banknote:1}};__sale={price:0,change:0,change_verified:0,dispense_all:!0,last_change:0,clear(){this.price=0,this.change=0,this.change_verified=0,this.dispense_all=!0,this.last_change=0}};__money_session={inserted:0,retired:0,clear(){this.inserted=0,this.retired=0}};coins={tubes:{g50:0,c50:0,p1:0,p2:0,p5:0,p10:0},box:{g50:0,c50:0,p1:0,p2:0,p5:0,p10:0},totals:{g50:0,c50:0,p1:0,p2:0,p5:0,p10:0},total:0};banknotes={stacker:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},recycler:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},out:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},totals:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},total:0};card_reader={available:!1,max_pre_credit:0};#n=!1;#e=0;#t=0;constructor({filters:n=null,config_port:e,no_device:t=1,socket:s=!1}={}){if(super({filters:n,config_port:e,no_device:t,socket:s}),this.__internal__.device.type="boardroid",c.Devices.getCustom(this.typeDevice,t))throw new Error(`Device ${this.typeDevice} ${t} already exists`);this.__internal__.serial.config_port.baudRate=115200,this.__internal__.serial.response.length=14,this.__internal__.time.response_connection=600,this.__internal__.time.response_general=4e3,this.__internal__.time.response_engines=15e3,this.__internal__.dispense.limit_counter=15,this.__internal__.dispense.custom_limit_counter=null,this.__internal__.dispense.backup_dispense={channel:1,second_channel:null,sensor:!0,seconds:null},this.#u(),c.Devices.add(this)}#u(){const n=["banknote-purse:banknote-scrow-status","banknote-purse:config","banknote-purse:event-banknote","banknote-purse:read-memory","banknote-purse:recycler","banknote-purse:save-memory","card-reader:event","change:pending","change:dispense","coin-purse:coin-event","coin-purse:config","coin-purse:reject-lever","coin-purse:reset","coin-purse:tubes","percentage:test","run:default-load","session:money-dispensed","session:money-request","event:door","door:event","status:relay","status:temperature","money:inserted"];for(const e of n)this.serialRegisterAvailableListener(e)}get totalInTubes(){return this.coins.tubes.g50*.5+this.coins.tubes.c50*.5+this.coins.tubes.p1+this.coins.tubes.p2*2+this.coins.tubes.p5*5+this.coins.tubes.p10*10}get totalInRecycler(){return this.banknotes.recycler.p20*20+this.banknotes.recycler.p50*50+this.banknotes.recycler.p100*100+this.banknotes.recycler.p200*200+this.banknotes.recycler.p500*500+this.banknotes.recycler.p1000*1e3}get hasRecycler(){return this.__banknote_purse.available&&this.__banknote_purse.isRecycler}set hasRecycler(n){this.__banknote_purse.isRecycler=n}get hasICT(){return this.hasRecycler&&this.__banknote_purse.recycler.ict}set hasICT(n){this.__banknote_purse.recycler.ict=n}set banknoteICT(n){if(![20,50,100,200,500].includes(n))throw new Error(`Invalid banknote value: ${n}`);n=[20,50,100,200,500].indexOf(n),this.__banknote_purse.recycler.banknote=n}get banknoteICT(){return[20,50,100,200,500][this.__banknote_purse.recycler.banknote]}get hasCoinPurse(){return this.__coin_purse.available}set hasCoinPurse(n){if(typeof n!="boolean")throw new Error(`Invalid value: ${n}`);this.__coin_purse.available=n}set price(n){let e=parseFloat(n);(isNaN(e)||e<0)&&(e=0),this.__sale.price=e}get price(){return this.__sale.price}get change(){return this.__sale.price<=0||this.__money_session.inserted<=this.__sale.price?0:this.__money_session.inserted-this.__sale.price}#s(){return this.__banknote_purse.isRecycler&&this.__banknote_purse.recycler.ict}#p(){return this.hasCoinPurse||this.hasRecycler}softReload(){super.softReload(),this.__sale.clear(),this.__money_session.clear()}#d(n){return n.name="Connection with the serial device completed.",n.description="Your connection with the serial device was successfully completed.",n.no_code=1,this.dispatch("run:default-load",{}),n}#h(n){const e={g50:{value:.5,name:"50 pennies (the big one)"},c0:{value:.5,name:"50 pennies (the little one)"},p1:{value:1,name:"1 peso"},p2:{value:2,name:"2 pesos"},p5:{value:5,name:"5 pesos"},p10:{value:10,name:"10 pesos"},p20:{value:20,name:"20 pesos"}};return e[n]?e[n]:!1}#b(n){const e={g50:["40","50","60","70","90"],c50:["41","51","61","71","91"],p1:["42","52","62","72","92"],p2:["43","53","63","73","93"],p5:["44","54","64","74","94"],p10:["45","55","65","75","95"],p20:["47","57","67","77","97"]};let t=null;for(const i in e)if(e[i].includes(n)){t=i;break}return t?[{g50:"50 pennies (the big one)",c0:"50 pennies (the little one)",p1:"1 peso",p2:"2 pesos",p5:"5 pesos",p10:"10 pesos",p20:"20 pesos"}[t],t]:[`Undefined value: ¿${n}?`,null]}#_(n){return["g50","c50","p1","p2","p5","p10","p20"].includes(n)}#f(n){const e={p20:["80","90","a0","b0"],p50:["81","91","a1","b1"],p100:["82","92","a2","b2"],p200:["83","93","a3","b3"],p500:["84","94","a4","b4"],p1000:["85","95","a5","b5"]};let t=null;for(const i in e)if(e[i].includes(n)){t=i;break}return t?[{p20:"20 pesos",p50:"50 pesos",p100:"100 pesos",p200:"200 pesos",p500:"500 pesos",p1000:"1000 pesos"}[t],t]:[`Undefined value: ¿${n}?`,null]}#k(n){const e={p20:{value:20,name:"20 pesos"},p50:{value:50,name:"50 pesos"},p100:{value:100,name:"100 pesos"},p200:{value:200,name:"200 pesos"},p500:{value:500,name:"500 pesos"},p1000:{value:1e3,name:"1000 pesos"}};return e[n]?e[n]:!1}#y(n){return["p20","p50","p100","p200","p500","p1000"].includes(n)}#w(n){return["r20","r50","r100"].includes(n)}#v(){return["r20","r50","r100","r200","r500"][this.__banknote_purse.recycler.banknote]}#r(n,e,t){if(!n)return;let s=!0;if(this.#_(n)&&t==="coin"){if(typeof this.coins.tubes[n]>"u")return;e==="tube"?this.coins.tubes[n]+=1:e==="box"&&(this.coins.box[n]+=1);let i=0;["g50","c50"].includes(n)?i=.5:i+=parseInt(n.slice(1)),this.coins.totals[n]+=i,this.__money_session.inserted+=i,this.coins.total+=i;const r=this.#h(n);r&&this.dispatch("money:inserted",{type:"coin",money:r,where:e})}else if(this.#y(n)&&t==="banknote"){if(typeof this.banknotes.recycler[n]>"u")return;e==="recycler"?this.banknotes.recycler[n]+=1:e==="stacker"&&(this.banknotes.stacker[n]+=1);const i=parseInt(n.slice(1));this.banknotes.totals[n]+=i,this.__money_session.inserted+=i,this.banknotes.total+=i;const r=this.#k(n);r&&this.dispatch("money:inserted",{type:"banknote",money:r,where:e})}else if(this.#w(n)&&e==="out"&&t==="banknote"){if(typeof this.banknotes.out[n.replace("r","p")]>"u")return;this.banknotes.out[n.replace("r","p")]+=1;const i=parseInt(n.slice(1));this.__money_session.retired+=i,this.banknotes.recycler[n.replace("r","p")]-=1,this.banknotes.total-=i,s=!1,this.dispatch("session:money-dispensed",{type_money:n,retired:i,finish:!1,type:"banknotes"})}s&&this.dispatch("session:money-request",{})}#C(n,e){const t=parseInt(n[2],16);return e.name="Coin Inserted",e.no_code=2,e.additional={where:null,coin:null},t===1?(e.name="Lever pressed",e.description="Reject lever",e.no_code=100,this.dispatch("coin-purse:reject-lever",{})):t===2?(e.name="Reset coin purse",e.description="The configuration of coin purse was reset",e.no_code=101,this.dispatch("coin-purse:reset",{})):t>=64&&t<=79?(e.name="Coin inserted in profit box",e.additional.where="box"):t>=80&&t<=95?(e.name="Coin inserted in tube",e.additional.where="tube"):t>=96&&t<=111?(e.name="Unused coin",e.description="Something come from coin changer but in MDB Docs is unused",e.additional.where="unused"):t>=112&&t<=127?(e.name="Coin rejected",e.additional.where="rejected"):t>=144&&t<=159?(e.name="Coin dispensed",e.additional.where="out",e.description=`Undefined value: ¿${n[2]}?`):(e.name="Coin inserted",e.description="Undefined status. Without information of this",e.no_code=400),t===1||t===2||t>=160||t>=128&&t<=143||([e.description,e.additional.coin]=this.#b(n[2]),e.no_code=38+t,this.#r(e.additional.coin,e.additional.where,"coin"),["tube","out"].includes(e.additional.where)&&this.dispatch("coin-purse:tubes",this.coins.tubes),this.dispatch("coin-purse:coin-event",this.coins)),e}#I(n,e){const t=parseInt(n[2],16);return e.name="Banknote Inserted",e.no_code=2,e.additional={where:null,banknote:null},t===42?(e.name="Banknote dispensed",e.description="Banknote dispensed by request.",e.additional.banknote=this.#v(),e.additional.where="out",e.no_code=200):t>=128&&t<=143?(e.name="Banknote inserted",e.additional.where="stacker"):t>=144&&t<=159?(e.name="Banknote inserted in pre stacker",e.additional.where="tmp"):t>=160&&t<=175?(e.name="Banknote rejected",e.additional.where="nothing"):t>=176&&t<=191&&(e.name="Banknote inserted",e.additional.where="recycler"),t>=128&&t<=191&&([e.description,e.additional.banknote]=this.#f(n[2]),e.no_code=74+t),this.#r(e.additional.banknote,e.additional.where,"banknote"),this.dispatch("banknote-purse:event-banknote",this.banknotes),e}#T(n,e){const t=parseInt(n,16);return t===1?(e.name="Coin purse enabled",e.description="Configuration complete, enabled",e.no_code=3):t===0?(e.name="Coin purse disabled",e.description="Disabled by system request",e.no_code=4):(e.name="Status unknown",e.description="The response of coin purse doesn't identify successfully",e.no_code=400),this.dispatch("coin-purse:config",{enabled:t===1}),e}#R(n,e){const t=parseInt(n[2],16),s=parseInt(n[3],16);return t===0?(e.name="Bill purse disabled",e.description="Configuration complete, disabled"):t===1&&(e.name="Bill purse enabled",e.description="Configuration complete, enabled"),s===0?e.additional.scrow="Scrow disabled, banknote received automatic":s===1&&(e.additional.scrow="Scrow enabled, require manual action"),e.no_code=5,this.dispatch("banknote-purse:config",{enabled:t===1,scrow:s===1}),e}#P(n,e){e.no_code=6;const[t,s,i,r,a,o]=[parseInt(n[2],16),parseInt(n[3],16),parseInt(n[4],16),parseInt(n[5],16),parseInt(n[6],16),parseInt(n[7],16)];return e.additional={coins:{g50:t,c50:s,p1:i,p2:r,p5:a,p10:o}},this.coins.tubes.g50=t,this.coins.tubes.c50=s,this.coins.tubes.p1=i,this.coins.tubes.p2=r,this.coins.tubes.p5=a,this.coins.tubes.p10=o,this.coins.totals.g50=(this.coins.box.g50+t)*.5,this.coins.totals.c50=(this.coins.box.c50+s)*.5,this.coins.totals.p1=this.coins.box.p1+i,this.coins.totals.p2=(this.coins.box.p2+r)*2,this.coins.totals.p5=(this.coins.box.p5+a)*5,this.coins.totals.p10=(this.coins.box.p10+o)*10,this.coins.total=this.coins.totals.g50+this.coins.totals.c50+this.coins.totals.p1+this.coins.totals.p2+this.coins.totals.p5+this.coins.totals.p10,e.name="Read tubes",e.description="Quantity of coins approximated",this.dispatch("coin-purse:tubes",this.coins.tubes),e}#$(n,e){e.no_code=7;const[t,s,i,r,a,o]=[parseInt(n[2],16),parseInt(n[3],16),parseInt(n[4],16),parseInt(n[5],16),parseInt(n[6],16),parseInt(n[7],16)];return e.additional={banknotes:{b20:t,b50:s,b100:i,b200:r,b500:a,b1000:o}},this.banknotes.recycler.p20=t,this.banknotes.recycler.p50=s,this.banknotes.recycler.p100=i,this.banknotes.recycler.p200=r,this.banknotes.recycler.p500=a,this.banknotes.recycler.p1000=o,this.banknotes.totals.p20=(this.banknotes.stacker.p20+t)*20,this.banknotes.totals.p50=(this.banknotes.stacker.p50+s)*50,this.banknotes.totals.p100=(this.banknotes.stacker.p100+i)*100,this.banknotes.totals.p200=(this.banknotes.stacker.p200+r)*200,this.banknotes.totals.p500=(this.banknotes.stacker.p500+a)*500,this.banknotes.totals.p1000=(this.banknotes.stacker.p1000+o)*1e3,this.banknotes.total=this.banknotes.totals.p20+this.banknotes.totals.p50+this.banknotes.totals.p100+this.banknotes.totals.p200+this.banknotes.totals.p500+this.banknotes.totals.p1000,e.name="Read recycler",e.description="Quantity of banknotes approximated",this.dispatch("banknote-purse:recycler",this.banknotes.recycler),e}#B(n,e){const t=parseInt(n,16);return t===1?e.name="Banknote accepted":t===0?e.name="Banknote rejected":e.name="Unknown status banknote",e.no_code=8,this.dispatch("banknote-purse:banknote-scrow-status",{status:t===1}),e}#q(n,e){const[t,s,i,r,a,o]=[parseInt(n[2],16),parseInt(n[3],16),parseInt(n[4],16),parseInt(n[5],16),parseInt(n[6],16),parseInt(n[7],16)],u=t*20+s*50+i*100+r*200+a*500+o*1e3;return e.name="Banknotes dispensed",e.description=u>0?"Banknotes dispensed by request":"No banknotes dispensed, recycler empty",e.no_code=9,e.additional={banknotes:{b20:t,b50:s,b100:i,b200:r,b500:a,b1000:o},total_dispensed:u},this.dispatch("session:money-dispensed",{type_money:null,retired:null,finish:!1,type:"banknotes",data:e}),e}#D(n){n.name="Coins dispensed",n.no_code=10,n.description="Coins dispensed by request",isNaN(this.__sale.last_change)&&(this.__sale.last_change=0),this.__money_session.retired+=this.__sale.last_change;const e={type_money:null,retired:null,finish:!1,type:"coins"};return this.dispatchAsync("session:money-dispensed",e,500),n}#x(n,e){const t=parseInt(n,16);return t===1?(e.name="Product not delivered",e.description="The product requested wasn't delivered",e.no_code=11,this.__internal__.dispense.status=!1):t===0?(e.name="Product delivered",e.description="The product requested was delivered",e.no_code=12,this.__internal__.dispense.status=!0):(e.name="Unknown status product",e.description="The response of product doesn't identify successfully",e.no_code=400,this.__internal__.dispense.status=!1),this.dispatch("dispensed",{}),e}#E(n,e){let t="closed";return n==="db"?(e.name="Door closed",e.no_code=13):n==="dc"?(e.name="Door open",e.no_code=14,t="open"):(e.name="Unknown status door",e.description="The response of door doesn't identify successfully",e.no_code=400,t="unknown"),this.__internal__.device.door_open=t==="open",this.dispatch("event:door",{open:t==="open"}),this.dispatch("door:event",{open:t==="open"}),e}#M(n,e){const t=parseInt(n[2],16)*255,s=parseInt(n[3],16),i=(t+s)*.1;return e.no_code=15,e.name="Temperature status",e.description=`Temperature: ${i}`,e.additional={high:t,low:s,temperature:parseFloat(i.toString())},this.dispatch("status:temperature",e.additional),e}#S(n,e){const t=parseInt(n,16);let s="unknown";return t===1?(e.name="Relay on",e.description="Relay on",e.no_code=16,s="on"):t===0?(e.name="Relay off",e.description="Relay off",e.no_code=17,s="off"):(e.name="Status unknown",e.description="Status unknown",e.no_code=400),this.dispatch("status:relay",{enabled:s==="on"}),e}#Q(n,e){const t=parseInt(n[2],16);if(e.no_code=20+t,e.name="Status unknown",e.description="The status of card reader does not identified correctly",t===0)e.request+=":disable",e.name="Card reader disabled",e.description="Card reader device was disabled successfully";else if(t===1||t===2)e.request+=":dispense",e.name="Card reader enabled",e.description="Card reader device is now enabled";else if(t===3)e.request+=":pre-authorize",e.name="Pre-authorized credit",e.description="The pre credit was authorized successfully";else if(t===4)e.request+=":cancel",e.name="Cancellation in progress",e.description="Cancellation request done successfully";else if(t===5)e.request+=":sell",e.name="Sell approved",e.description="Sell approved, starting dispense product";else if(t===6)e.request+=":sell",e.name="Sell denied",e.description="This sell was denied, try again";else if(t===7)e.request+=":end",e.name="Session ended",e.description="The session ended";else if(t===8)e.request+=":cancel",e.name="Cancelled",e.description="Cancellation complete";else if(t===10){const s=parseInt(n[8],16);s===1?(e.no_code=30,e.name="product not dispensed",e.description="The product requested wasn't delivered"):s===0?(e.no_code=31,e.name="product dispensed",e.description="The product requested was delivered"):(e.name="finished-unknown",e.no_code=400)}else e.no_code=400;return this.dispatch("card-reader:event",e),e}serialMessage(n){n=this.fixHexArray(n);let e={code:n,name:null,description:null,request:null,no_code:0};const t=(5+this.deviceNumber).toString(16).padStart(2,"0").toLowerCase();switch(n[1]){case t:e.request="connect",e=this.#d(e);break;case"a0":e.request="--automatic",e=this.#C(n,e);break;case"b0":e.request="--automatic",e=this.#I(n,e);break;case"d0":e.request="coin-purse:config",e=this.#T(n[2],e);break;case"d1":e.request="banknote-purse:config",e.additional={scrow:null},e=this.#R(n,e);break;case"d2":e.request="coin-purse:read-tubes",e=this.#P(n,e);break;case"d3":e.request="banknote-purse:read-recycler",e=this.#$(n,e);break;case"d4":e.request="banknote-purse:banknote-scrow-status",e=this.#B(n[2],e);break;case"d5":e.request="banknote-purse:dispense",e=this.#q(n,e);break;case"d6":e.request="coin-purse:dispense",e=this.#D(e);break;case"d7":e.request="dispense",e=this.#x(n[5],e);break;case"d8":e.request="--automatic",e=this.#E(n[13],e);break;case"d9":e.request="status:temperature",e=this.#M(n,e);break;case"da":e.request="status:relay",e=this.#S(n[2],e);break;case"db":e.request="banknote-purse:save-memory",e.no_code=18,e.name="Bill purse memory saved?",e.description="The memory of bill purse was saved successfully?",this.dispatch("banknote-purse:save-memory",{message:e});break;case"dc":e.request="coin-purse:read-memory",e.no_code=19,e.name="Coin purse memory read?",e.description="The memory of coin purse was read successfully?",this.dispatch("banknote-purse:read-memory",{message:e});break;case"dd":e.request="card-reader",this.#Q(n,e);break;default:e.request="--unknown",e.name="Response unrecognized",e.description="The response of application was received, but dont identify with any of current parameters",e.no_code=400,this.dispatch("unknown",e);break}this.dispatch("serial:message",e)}serialSetConnectionConstant(n=1){return l.l.connection({channel:n})}async coinPurseConfigure({enable:n=!1,high:e=255,low:t=255}={}){if(!this.__coin_purse.available)throw new Error("Coin purse not available");return await this.appendToQueue(l.l.coinPurseConfiguration({enable:n,high:e,low:t}),"coin-purse:config")}async coinPurseEnable(){await this.coinPurseConfigure({enable:!0})}async coinPurseDisable(){await this.coinPurseConfigure({enable:!1})}async coinPurseDispense({$_50c:n=0,$_1:e=0,$_2:t=0,$_5:s=0,$_10:i=0}={}){if(!this.__coin_purse.available)throw new Error("Coin purse not available");return await this.appendToQueue(l.l.coinPurseDispense({$50c:n,$1:e,$2:t,$5:s,$10:i}),"coin-purse:dispense")}async coinPurseReadTubes(){return await this.appendToQueue(l.l.coinPurseReadTubes(),"coin-purse:read-tubes")}#N({enable:n=!1,scrow:e=!1}={}){return l.l.banknotePurseICTConfigure({enable:n,scrow:e})}#j({enable:n=!1,scrow:e=!1}={}){return l.l.banknotePurseOtherConfigure({enable:n,scrow:e})}async banknotePurseConfigure({enable:n=!1,scrow:e=!1}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");let t;return this.#s()?t=this.#N({enable:n,scrow:e}):t=this.#j({enable:n,scrow:e}),await this.appendToQueue(t,"banknote-purse:config")}#m(n=1){if(n<1)throw new Error("No banknotes to dispense");const e=[20,50,100,200,500][this.__banknote_purse.recycler.banknote];return l.l.banknotePurseICTDispense({quantity:n,denomination:e})}#O({$_20:n=0,$_50:e=0,$_100:t=0,$_200:s=0,$_500:i=0,$_1000:r=0}={}){return l.l.banknotePurseOtherDispense({$20:n,$50:e,$100:t,$200:s,$500:i,$1000:r})}async banknotePurseDispense({$_20:n=0,$_50:e=0,$_100:t=0,$_200:s=0,$_500:i=0,$_1000:r=0}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");if(!this.__banknote_purse.isRecycler)throw new Error("Banknote purse is not recycler");let a;if(this.#s()){const o=[n,e,t,s,i];a=this.#m(o[this.__banknote_purse.recycler.banknote])}else a=this.#O({$_20:n,$_50:e,$_100:t,$_200:s,$_500:i,$_1000:r});await this.appendToQueue(a,"banknote-purse:dispense")}async banknotePurseEnable({scrow:n=!1}){return await this.banknotePurseConfigure({enable:!0,scrow:n})}async banknotePurseDisable(){return await this.banknotePurseConfigure({enable:!1})}async banknotePurseAcceptInScrow(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");return await this.appendToQueue(l.l.banknotePurseAcceptInScrow(),"banknote-purse:banknote-scrow-status")}async banknotePurseRejectInScrow(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");return await this.appendToQueue(l.l.banknotePurseRejectInScrow(),"banknote-purse:banknote-scrow-status")}async banknotePurseSaveMemory({channel:n=null,$_20:e=null,$_50:t=null,$_100:s=null,$_200:i=null,$_500:r=null,$_1000:a=null}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");return await this.appendToQueue(l.l.banknotePurseSaveMemory({channel:n,$20:e,$50:t,$100:s,$200:i,$500:r,$1000:a}),"banknote-purse:save-memory")}async banknotePurseReadRecycler(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");if(!this.__banknote_purse.isRecycler)throw new Error("Banknote purse is not recycler");return await this.appendToQueue(l.l.banknotePurseReadRecycler(),"banknote-purse:read-recycler")}async cardReaderDisable(){if(!this.card_reader.available)throw new Error("Card reader not available");return await this.appendToQueue(l.l.cardReaderDisable(),"card-reader:disable")}async cardReaderDispense({channel:n=1,second_channel:e=null,sensor:t=!0,seconds:s=null,price:i=0}={}){if(!this.card_reader.available)throw new Error("Card reader not available");if((isNaN(this.card_reader.max_pre_credit)||this.card_reader.max_pre_credit===0)&&(this.card_reader.max_pre_credit=i),isNaN(i)||i<=0)throw new Error("Price must be greater than 0");if(i>this.card_reader.max_pre_credit)throw new Error("Price is greater than pre-credit configured");if(!t&&(s===null||s<=0||s>40))throw new Error("Invalid time to dispense without sensor, must be between 0.1 and 40.0 seconds");return this.appendToQueue(l.l.cardReaderDispense({selection:n,second_selection:e,sensor:t,seconds:s,price:i}),"card-reader:dispense")}async paymentPursesDisable({coin:n=!0,banknote:e=!0,cardReader:t=!1}={}){n&&this.__coin_purse.available&&await this.coinPurseDisable(),e&&this.__banknote_purse.available&&await this.banknotePurseDisable(),t&&this.card_reader.available&&await this.cardReaderDisable()}async paymentPursesEnable({coin:n=!0,banknote:e=!0,scrowBanknote:t=!1}={}){n&&this.__coin_purse.available&&await this.coinPurseEnable(),e&&this.__banknote_purse.available&&await this.banknotePurseEnable({scrow:t})}async coolingRelayConfigure({enable:n=!1}={}){return await this.appendToQueue(l.l.coolingRelayConfigure({enable:n}),"status:relay")}async coolingRelayEnable(){return await this.coolingRelayConfigure({enable:!0})}async coolingRelayDisable(){return await this.coolingRelayConfigure({enable:!1})}async readTemperature(){return await this.appendToQueue(l.l.readTemperature(),"status:temperature")}async dispense({selection:n=1,second_selection:e=null,sensor:t=!0,seconds:s=null,retry:i=!0}={selection:1,second_selection:null,sensor:!0,seconds:null,retry:!0}){if(n=parseInt(n,10),isNaN(n)||n<1||n>80)throw new Error("Invalid channel number");if(e!==null&&(e<1||e>80||e===n))throw new Error("Invalid second channel number");if(!t&&(s===null||s<=0||s>40))throw new Error("Invalid time to dispense without sensor, must be between 0.1 and 40.0 seconds");i&&(this.__internal__.dispense.backup_dispense={selection:n,second_selection:e,sensor:t,seconds:s});const r=l.l.dispense({selection:n,second_selection:e,sensor:t,seconds:s});t||(s||(s=1.5),this.__internal__.dispense.custom_limit_counter=s+.2);let a=await this.internalDispense(r);return!a.status&&i&&(a=await this.internalDispense(r)),this.__internal__.dispense.custom_limit_counter=null,a}#a(){this.#n=!1,this.#e=0,this.#t=0}#i({dispensed:n=null,limit:e=80}={}){this.#t=Math.round(this.#e*100/e),this.dispatch("percentage:test",{percentage:this.#t,dispensed:n})}async testEngines({singleEngine:n=!1}={}){if(this.isDispensing)throw new Error("Another dispensing process is running");if(this.#n)throw new Error("Another test is running");this.#a(),this.#n=!0;const e=[];this.#i();for(let t=1;t<=80;t++){const s=await this.dispense({selection:t,second_selection:n?null:t+1,sensor:!1,seconds:.4,retry:!1});e.push(s),this.#e=t,this.#i(),n||t++}this.#e=80,this.#i({dispensed:e}),this.#a()}async sendCustomCode({code:n=[]}={code:[]}){if(n.length===0)throw new Error("Invalid code");return await this.appendToQueue(l.l.customCode(n),"custom")}#A(n){const e=["20","50","100","200","500"],t=this.__banknote_purse.recycler.banknote,s="$_"+e[t],i=parseInt(e[t]),r=this.banknotes.recycler[`p${e[t]}`],a=Math.min(Math.floor(n/i),r),o={banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:n,will_dispense:a>0};return this.totalInRecycler===0||a<1||n===0||(o.banknotes[s]=a,o.pending=parseFloat((n-a*i).toFixed(2))),o}#U(n){const e={banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:n,will_dispense:!1};if(this.totalInRecycler===0||n===0)return e;const t=(s,i)=>{if(this.banknotes.recycler[i]>0){const r=Math.floor(e.pending/s),a=Math.min(r,this.banknotes.recycler[i]);e.banknotes[`$_${s}`]=a,e.pending=parseFloat((e.pending-a*s).toFixed(2))}};return t(1e3,"p1000"),t(500,"p500"),t(200,"p200"),t(100,"p100"),t(50,"p50"),t(20,"p20"),e.will_dispense=Object.values(e.banknotes).some(s=>s>0),e}#o(n){return this.hasRecycler?this.#s()?this.#A(n):this.#U(n):{banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:n,will_dispense:!1}}#l(n){const e={coins:{$_50c:0,$_1:0,$_2:0,$_5:0,$_10:0},pending:n,will_dispense:!1};if(!this.hasCoinPurse||n<=0||this.totalInTubes===0)return e;const t=(s,i,r=null)=>{if(this.coins.tubes[i]>0){r===null&&(r="$_"+s);const a=Math.floor(e.pending/s),o=Math.min(a,this.coins.tubes[i]);e.coins[r]=o,e.pending=parseFloat((e.pending-o*s).toFixed(2))}};return t(10,"p10"),t(5,"p5"),t(2,"p2"),t(1,"p1"),t(.5,"g50","$_50c"),e.will_dispense=Object.values(e.coins).some(s=>s>0),e}hasToReturnChange(n=0){let e=n;return e<=0?!0:(e=this.#o(e).pending,e=this.#l(e).pending,!(e>0))}async#c(n=null){if(!this.#p())throw new Error("Change not available");let e=this.change,t=this.change;if(n!==null&&(e=n,t=n),t<=0)return!1;const s=this.#o(t);t=s.pending;const i=this.#l(t);return t=i.pending,t>0&&this.dispatch("change:pending",{pending:t}),this.dispatch("change:dispense",{recycler:s.banknotes,coins:i.coins,pending:t,delivery:e-t}),t===e?!1:(s.will_dispense&&await this.banknotePurseDispense(s.banknotes),i.will_dispense&&await this.coinPurseDispense(i.coins),!0)}async returnChange(){return await this.#c()}async returnInsertedMoney(){return this.__money_session.inserted<=0?!1:await this.#c(this.__money_session.inserted)}async serialCorruptMessage(n,e){this.dispatch("corrupt:message",{data:n,message:e})}}exports.Boardroid=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./kernel-As0xv_MS.cjs"),u=require("./devices-BndwHuvP.cjs"),l=require("./relay-E3NCcSjS.cjs");class d extends p.Kernel{__coin_purse={available:!0};__banknote_purse={available:!0,isRecycler:!0,recycler:{ict:!0,banknote:1}};__sale={price:0,change:0,change_verified:0,dispense_all:!0,last_change:0,clear(){this.price=0,this.change=0,this.change_verified=0,this.dispense_all=!0,this.last_change=0}};__money_session={inserted:0,retired:0,clear(){this.inserted=0,this.retired=0}};coins={tubes:{g50:0,c50:0,p1:0,p2:0,p5:0,p10:0},box:{g50:0,c50:0,p1:0,p2:0,p5:0,p10:0},totals:{g50:0,c50:0,p1:0,p2:0,p5:0,p10:0},total:0};banknotes={stacker:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},recycler:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},out:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},totals:{p20:0,p50:0,p100:0,p200:0,p500:0,p1000:0},total:0};card_reader={available:!1,max_pre_credit:0};#n=!1;#e=0;#t=0;constructor({filters:n=null,config_port:e,no_device:t=1,socket:s=!1}={}){if(super({filters:n,config_port:e,no_device:t,socket:s}),this.__internal__.device.type="boardroid",u.Devices.getCustom(this.typeDevice,t))throw new Error(`Device ${this.typeDevice} ${t} already exists`);this.__internal__.serial.config_port.baudRate=115200,this.__internal__.serial.response.length=14,this.__internal__.time.response_connection=600,this.__internal__.time.response_general=4e3,this.__internal__.time.response_engines=15e3,this.__internal__.dispense.limit_counter=15,this.__internal__.dispense.custom_limit_counter=null,this.__internal__.dispense.backup_dispense={channel:1,second_channel:null,sensor:!0,seconds:null},this.#u(),u.Devices.add(this)}#u(){const n=["banknote-purse:banknote-scrow-status","banknote-purse:config","banknote-purse:event-banknote","banknote-purse:read-memory","banknote-purse:recycler","banknote-purse:save-memory","card-reader:event","change:pending","change:dispense","coin-purse:coin-event","coin-purse:config","coin-purse:reject-lever","coin-purse:reset","coin-purse:tubes","percentage:test","run:default-load","session:money-dispensed","session:money-request","event:door","door:event","status:relay","status:temperature","money:inserted"];for(const e of n)this.serialRegisterAvailableListener(e)}get totalInTubes(){return this.coins.tubes.g50*.5+this.coins.tubes.c50*.5+this.coins.tubes.p1+this.coins.tubes.p2*2+this.coins.tubes.p5*5+this.coins.tubes.p10*10}get totalInRecycler(){return this.banknotes.recycler.p20*20+this.banknotes.recycler.p50*50+this.banknotes.recycler.p100*100+this.banknotes.recycler.p200*200+this.banknotes.recycler.p500*500+this.banknotes.recycler.p1000*1e3}get hasRecycler(){return this.__banknote_purse.available&&this.__banknote_purse.isRecycler}set hasRecycler(n){this.__banknote_purse.isRecycler=n}get hasICT(){return this.hasRecycler&&this.__banknote_purse.recycler.ict}set hasICT(n){this.__banknote_purse.recycler.ict=n}set banknoteICT(n){if(![20,50,100,200,500].includes(n))throw new Error(`Invalid banknote value: ${n}`);n=[20,50,100,200,500].indexOf(n),this.__banknote_purse.recycler.banknote=n}get banknoteICT(){return[20,50,100,200,500][this.__banknote_purse.recycler.banknote]}get hasCoinPurse(){return this.__coin_purse.available}set hasCoinPurse(n){if(typeof n!="boolean")throw new Error(`Invalid value: ${n}`);this.__coin_purse.available=n}set price(n){let e=parseFloat(n);(isNaN(e)||e<0)&&(e=0),this.__sale.price=e}get price(){return this.__sale.price}get change(){return this.__sale.price<=0||this.__money_session.inserted<=this.__sale.price?0:this.__money_session.inserted-this.__sale.price}#s(){return this.__banknote_purse.isRecycler&&this.__banknote_purse.recycler.ict}#p(){return this.hasCoinPurse||this.hasRecycler}softReload(){super.softReload(),this.__sale.clear(),this.__money_session.clear()}#d(n){return n.name="Connection with the serial device completed.",n.description="Your connection with the serial device was successfully completed.",n.no_code=1,this.dispatch("run:default-load",{}),n}#h(n){const e={g50:{value:.5,name:"50 pennies (the big one)"},c0:{value:.5,name:"50 pennies (the little one)"},p1:{value:1,name:"1 peso"},p2:{value:2,name:"2 pesos"},p5:{value:5,name:"5 pesos"},p10:{value:10,name:"10 pesos"},p20:{value:20,name:"20 pesos"}};return e[n]?e[n]:!1}#b(n){const e={g50:["40","50","60","70","90"],c50:["41","51","61","71","91"],p1:["42","52","62","72","92"],p2:["43","53","63","73","93"],p5:["44","54","64","74","94"],p10:["45","55","65","75","95"],p20:["47","57","67","77","97"]};let t=null;for(const i in e)if(e[i].includes(n)){t=i;break}return t?[{g50:"50 pennies (the big one)",c0:"50 pennies (the little one)",p1:"1 peso",p2:"2 pesos",p5:"5 pesos",p10:"10 pesos",p20:"20 pesos"}[t],t]:[`Undefined value: ¿${n}?`,null]}#_(n){return["g50","c50","p1","p2","p5","p10","p20"].includes(n)}#f(n){const e={p20:["80","90","a0","b0"],p50:["81","91","a1","b1"],p100:["82","92","a2","b2"],p200:["83","93","a3","b3"],p500:["84","94","a4","b4"],p1000:["85","95","a5","b5"]};let t=null;for(const i in e)if(e[i].includes(n)){t=i;break}return t?[{p20:"20 pesos",p50:"50 pesos",p100:"100 pesos",p200:"200 pesos",p500:"500 pesos",p1000:"1000 pesos"}[t],t]:[`Undefined value: ¿${n}?`,null]}#k(n){const e={p20:{value:20,name:"20 pesos"},p50:{value:50,name:"50 pesos"},p100:{value:100,name:"100 pesos"},p200:{value:200,name:"200 pesos"},p500:{value:500,name:"500 pesos"},p1000:{value:1e3,name:"1000 pesos"}};return e[n]?e[n]:!1}#y(n){return["p20","p50","p100","p200","p500","p1000"].includes(n)}#w(n){return["r20","r50","r100"].includes(n)}#v(){return["r20","r50","r100","r200","r500"][this.__banknote_purse.recycler.banknote]}#r(n,e,t){if(!n)return;let s=!0;if(this.#_(n)&&t==="coin"){if(typeof this.coins.tubes[n]>"u")return;e==="tube"?this.coins.tubes[n]+=1:e==="box"&&(this.coins.box[n]+=1);let i=0;["g50","c50"].includes(n)?i=.5:i+=parseInt(n.slice(1)),this.coins.totals[n]+=i,this.__money_session.inserted+=i,this.coins.total+=i;const r=this.#h(n);r&&this.dispatch("money:inserted",{type:"coin",money:r,where:e})}else if(this.#y(n)&&t==="banknote"){if(typeof this.banknotes.recycler[n]>"u")return;e==="recycler"?this.banknotes.recycler[n]+=1:e==="stacker"&&(this.banknotes.stacker[n]+=1);const i=parseInt(n.slice(1));this.banknotes.totals[n]+=i,this.__money_session.inserted+=i,this.banknotes.total+=i;const r=this.#k(n);r&&this.dispatch("money:inserted",{type:"banknote",money:r,where:e})}else if(this.#w(n)&&e==="out"&&t==="banknote"){if(typeof this.banknotes.out[n.replace("r","p")]>"u")return;this.banknotes.out[n.replace("r","p")]+=1;const i=parseInt(n.slice(1));this.__money_session.retired+=i,this.banknotes.recycler[n.replace("r","p")]-=1,this.banknotes.total-=i,s=!1,this.dispatch("session:money-dispensed",{type_money:n,retired:i,finish:!1,type:"banknotes"})}s&&this.dispatch("session:money-request",{})}#C(n,e){const t=parseInt(n[2],16);return e.name="Coin Inserted",e.no_code=2,e.additional={where:null,coin:null},t===1?(e.name="Lever pressed",e.description="Reject lever",e.no_code=100,this.dispatch("coin-purse:reject-lever",{})):t===2?(e.name="Reset coin purse",e.description="The configuration of coin purse was reset",e.no_code=101,this.dispatch("coin-purse:reset",{})):t>=64&&t<=79?(e.name="Coin inserted in profit box",e.additional.where="box"):t>=80&&t<=95?(e.name="Coin inserted in tube",e.additional.where="tube"):t>=96&&t<=111?(e.name="Unused coin",e.description="Something come from coin changer but in MDB Docs is unused",e.additional.where="unused"):t>=112&&t<=127?(e.name="Coin rejected",e.additional.where="rejected"):t>=144&&t<=159?(e.name="Coin dispensed",e.additional.where="out",e.description=`Undefined value: ¿${n[2]}?`):(e.name="Coin inserted",e.description="Undefined status. Without information of this",e.no_code=400),t===1||t===2||t>=160||t>=128&&t<=143||([e.description,e.additional.coin]=this.#b(n[2]),e.no_code=38+t,this.#r(e.additional.coin,e.additional.where,"coin"),["tube","out"].includes(e.additional.where)&&this.dispatch("coin-purse:tubes",this.coins.tubes),this.dispatch("coin-purse:coin-event",this.coins)),e}#I(n,e){const t=parseInt(n[2],16);return e.name="Banknote Inserted",e.no_code=2,e.additional={where:null,banknote:null},t===42?(e.name="Banknote dispensed",e.description="Banknote dispensed by request.",e.additional.banknote=this.#v(),e.additional.where="out",e.no_code=200):t>=128&&t<=143?(e.name="Banknote inserted",e.additional.where="stacker"):t>=144&&t<=159?(e.name="Banknote inserted in pre stacker",e.additional.where="tmp"):t>=160&&t<=175?(e.name="Banknote rejected",e.additional.where="nothing"):t>=176&&t<=191&&(e.name="Banknote inserted",e.additional.where="recycler"),t>=128&&t<=191&&([e.description,e.additional.banknote]=this.#f(n[2]),e.no_code=74+t),this.#r(e.additional.banknote,e.additional.where,"banknote"),this.dispatch("banknote-purse:event-banknote",this.banknotes),e}#T(n,e){const t=parseInt(n,16);return t===1?(e.name="Coin purse enabled",e.description="Configuration complete, enabled",e.no_code=3):t===0?(e.name="Coin purse disabled",e.description="Disabled by system request",e.no_code=4):(e.name="Status unknown",e.description="The response of coin purse doesn't identify successfully",e.no_code=400),this.dispatch("coin-purse:config",{enabled:t===1}),e}#R(n,e){const t=parseInt(n[2],16),s=parseInt(n[3],16);return t===0?(e.name="Bill purse disabled",e.description="Configuration complete, disabled"):t===1&&(e.name="Bill purse enabled",e.description="Configuration complete, enabled"),s===0?e.additional.scrow="Scrow disabled, banknote received automatic":s===1&&(e.additional.scrow="Scrow enabled, require manual action"),e.no_code=5,this.dispatch("banknote-purse:config",{enabled:t===1,scrow:s===1}),e}#P(n,e){e.no_code=6;const[t,s,i,r,a,o]=[parseInt(n[2],16),parseInt(n[3],16),parseInt(n[4],16),parseInt(n[5],16),parseInt(n[6],16),parseInt(n[7],16)];return e.additional={coins:{g50:t,c50:s,p1:i,p2:r,p5:a,p10:o}},this.coins.tubes.g50=t,this.coins.tubes.c50=s,this.coins.tubes.p1=i,this.coins.tubes.p2=r,this.coins.tubes.p5=a,this.coins.tubes.p10=o,this.coins.totals.g50=(this.coins.box.g50+t)*.5,this.coins.totals.c50=(this.coins.box.c50+s)*.5,this.coins.totals.p1=this.coins.box.p1+i,this.coins.totals.p2=(this.coins.box.p2+r)*2,this.coins.totals.p5=(this.coins.box.p5+a)*5,this.coins.totals.p10=(this.coins.box.p10+o)*10,this.coins.total=this.coins.totals.g50+this.coins.totals.c50+this.coins.totals.p1+this.coins.totals.p2+this.coins.totals.p5+this.coins.totals.p10,e.name="Read tubes",e.description="Quantity of coins approximated",this.dispatch("coin-purse:tubes",this.coins.tubes),e}#$(n,e){e.no_code=7;const[t,s,i,r,a,o]=[parseInt(n[2],16),parseInt(n[3],16),parseInt(n[4],16),parseInt(n[5],16),parseInt(n[6],16),parseInt(n[7],16)];return e.additional={banknotes:{b20:t,b50:s,b100:i,b200:r,b500:a,b1000:o}},this.banknotes.recycler.p20=t,this.banknotes.recycler.p50=s,this.banknotes.recycler.p100=i,this.banknotes.recycler.p200=r,this.banknotes.recycler.p500=a,this.banknotes.recycler.p1000=o,this.banknotes.totals.p20=(this.banknotes.stacker.p20+t)*20,this.banknotes.totals.p50=(this.banknotes.stacker.p50+s)*50,this.banknotes.totals.p100=(this.banknotes.stacker.p100+i)*100,this.banknotes.totals.p200=(this.banknotes.stacker.p200+r)*200,this.banknotes.totals.p500=(this.banknotes.stacker.p500+a)*500,this.banknotes.totals.p1000=(this.banknotes.stacker.p1000+o)*1e3,this.banknotes.total=this.banknotes.totals.p20+this.banknotes.totals.p50+this.banknotes.totals.p100+this.banknotes.totals.p200+this.banknotes.totals.p500+this.banknotes.totals.p1000,e.name="Read recycler",e.description="Quantity of banknotes approximated",this.dispatch("banknote-purse:recycler",this.banknotes.recycler),e}#q(n,e){const t=parseInt(n,16);return t===1?e.name="Banknote accepted":t===0?e.name="Banknote rejected":e.name="Unknown status banknote",e.no_code=8,this.dispatch("banknote-purse:banknote-scrow-status",{status:t===1}),e}#B(n,e){const[t,s,i,r,a,o]=[parseInt(n[2],16),parseInt(n[3],16),parseInt(n[4],16),parseInt(n[5],16),parseInt(n[6],16),parseInt(n[7],16)],c=t*20+s*50+i*100+r*200+a*500+o*1e3;return e.name="Banknotes dispensed",e.description=c>0?"Banknotes dispensed by request":"No banknotes dispensed, recycler empty",e.no_code=9,e.additional={banknotes:{b20:t,b50:s,b100:i,b200:r,b500:a,b1000:o},total_dispensed:c},this.dispatch("session:money-dispensed",{type_money:null,retired:null,finish:!1,type:"banknotes",data:e}),e}#D(n){n.name="Coins dispensed",n.no_code=10,n.description="Coins dispensed by request",isNaN(this.__sale.last_change)&&(this.__sale.last_change=0),this.__money_session.retired+=this.__sale.last_change;const e={type_money:null,retired:null,finish:!1,type:"coins"};return this.dispatchAsync("session:money-dispensed",e,500),n}#x(n,e){const t=parseInt(n,16);return t===1?(e.name="Product not delivered",e.description="The product requested wasn't delivered",e.no_code=11,this.__internal__.dispense.status=!1):t===0?(e.name="Product delivered",e.description="The product requested was delivered",e.no_code=12,this.__internal__.dispense.status=!0):(e.name="Unknown status product",e.description="The response of product doesn't identify successfully",e.no_code=400,this.__internal__.dispense.status=!1),this.dispatch("dispensed",{}),e}#E(n,e){let t="closed";return n==="db"?(e.name="Door closed",e.no_code=13):n==="dc"?(e.name="Door open",e.no_code=14,t="open"):(e.name="Unknown status door",e.description="The response of door doesn't identify successfully",e.no_code=400,t="unknown"),this.__internal__.device.door_open=t==="open",this.dispatch("event:door",{open:t==="open"}),this.dispatch("door:event",{open:t==="open"}),e}#M(n,e){const t=parseInt(n[2],16)*255,s=parseInt(n[3],16),i=(t+s)*.1;return e.no_code=15,e.name="Temperature status",e.description=`Temperature: ${i}`,e.additional={high:t,low:s,temperature:parseFloat(i.toString())},this.dispatch("status:temperature",e.additional),e}#S(n,e){const t=parseInt(n,16);let s="unknown";return t===1?(e.name="Relay on",e.description="Relay on",e.no_code=16,s="on"):t===0?(e.name="Relay off",e.description="Relay off",e.no_code=17,s="off"):(e.name="Status unknown",e.description="Status unknown",e.no_code=400),this.dispatch("status:relay",{enabled:s==="on"}),e}#Q(n,e){const t=parseInt(n[2],16);if(e.no_code=20+t,e.name="Status unknown",e.description="The status of card reader does not identified correctly",t===0)e.request+=":disable",e.name="Card reader disabled",e.description="Card reader device was disabled successfully";else if(t===1||t===2)e.request+=":dispense",e.name="Card reader enabled",e.description="Card reader device is now enabled";else if(t===3)e.request+=":pre-authorize",e.name="Pre-authorized credit",e.description="The pre credit was authorized successfully";else if(t===4)e.request+=":cancel",e.name="Cancellation in progress",e.description="Cancellation request done successfully";else if(t===5)e.request+=":sell",e.name="Sell approved",e.description="Sell approved, starting dispense product";else if(t===6)e.request+=":sell",e.name="Sell denied",e.description="This sell was denied, try again";else if(t===7)e.request+=":end",e.name="Session ended",e.description="The session ended";else if(t===8)e.request+=":cancel",e.name="Cancelled",e.description="Cancellation complete";else if(t===10){const s=parseInt(n[8],16);s===1?(e.no_code=30,e.name="product not dispensed",e.description="The product requested wasn't delivered"):s===0?(e.no_code=31,e.name="product dispensed",e.description="The product requested was delivered"):(e.name="finished-unknown",e.no_code=400)}else e.no_code=400;return this.dispatch("card-reader:event",e),e}serialMessage(n){n=this.fixHexArray(n);let e={code:n,name:null,description:null,request:null,no_code:0};const t=(5+this.deviceNumber).toString(16).padStart(2,"0").toLowerCase();switch(n[1]){case t:e.request="connect",e=this.#d(e);break;case"a0":e.request="--automatic",e=this.#C(n,e);break;case"b0":e.request="--automatic",e=this.#I(n,e);break;case"d0":e.request="coin-purse:config",e=this.#T(n[2],e);break;case"d1":e.request="banknote-purse:config",e.additional={scrow:null},e=this.#R(n,e);break;case"d2":e.request="coin-purse:read-tubes",e=this.#P(n,e);break;case"d3":e.request="banknote-purse:read-recycler",e=this.#$(n,e);break;case"d4":e.request="banknote-purse:banknote-scrow-status",e=this.#q(n[2],e);break;case"d5":e.request="banknote-purse:dispense",e=this.#B(n,e);break;case"d6":e.request="coin-purse:dispense",e=this.#D(e);break;case"d7":e.request="dispense",e=this.#x(n[5],e);break;case"d8":e.request="--automatic",e=this.#E(n[13],e);break;case"d9":e.request="status:temperature",e=this.#M(n,e);break;case"da":e.request="status:relay",e=this.#S(n[2],e);break;case"db":e.request="banknote-purse:save-memory",e.no_code=18,e.name="Bill purse memory saved?",e.description="The memory of bill purse was saved successfully?",this.dispatch("banknote-purse:save-memory",{message:e});break;case"dc":e.request="coin-purse:read-memory",e.no_code=19,e.name="Coin purse memory read?",e.description="The memory of coin purse was read successfully?",this.dispatch("banknote-purse:read-memory",{message:e});break;case"dd":e.request="card-reader",this.#Q(n,e);break;default:e.request="--unknown",e.name="Response unrecognized",e.description="The response of application was received, but dont identify with any of current parameters",e.no_code=400,this.dispatch("unknown",e);break}this.dispatch("serial:message",e)}serialSetConnectionConstant(n=1){return l.l.connection({channel:n})}async coinPurseConfigure({enable:n=!1,high:e=255,low:t=255}={}){if(!this.__coin_purse.available)throw new Error("Coin purse not available");return await this.appendToQueue(l.l.coinPurseConfiguration({enable:n,high:e,low:t}),"coin-purse:config")}async coinPurseEnable(){await this.coinPurseConfigure({enable:!0})}async coinPurseDisable(){await this.coinPurseConfigure({enable:!1})}async coinPurseDispense({$_50c:n=0,$_1:e=0,$_2:t=0,$_5:s=0,$_10:i=0}={}){if(!this.__coin_purse.available)throw new Error("Coin purse not available");return await this.appendToQueue(l.l.coinPurseDispense({$50c:n,$1:e,$2:t,$5:s,$10:i}),"coin-purse:dispense")}async coinPurseReadTubes(){return await this.appendToQueue(l.l.coinPurseReadTubes(),"coin-purse:read-tubes")}#N({enable:n=!1,scrow:e=!1}={}){return l.l.banknotePurseICTConfigure({enable:n,scrow:e})}#j({enable:n=!1,scrow:e=!1}={}){return l.l.banknotePurseOtherConfigure({enable:n,scrow:e})}async banknotePurseConfigure({enable:n=!1,scrow:e=!1}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");let t;return this.#s()?t=this.#N({enable:n,scrow:e}):t=this.#j({enable:n,scrow:e}),await this.appendToQueue(t,"banknote-purse:config")}#m(n=1){if(n<1)throw new Error("No banknotes to dispense");const e=[20,50,100,200,500][this.__banknote_purse.recycler.banknote];return l.l.banknotePurseICTDispense({quantity:n,denomination:e})}#O({$_20:n=0,$_50:e=0,$_100:t=0,$_200:s=0,$_500:i=0,$_1000:r=0}={}){return l.l.banknotePurseOtherDispense({$20:n,$50:e,$100:t,$200:s,$500:i,$1000:r})}async banknotePurseDispense({$_20:n=0,$_50:e=0,$_100:t=0,$_200:s=0,$_500:i=0,$_1000:r=0}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");if(!this.__banknote_purse.isRecycler)throw new Error("Banknote purse is not recycler");let a;if(this.#s()){const o=[n,e,t,s,i];a=this.#m(o[this.__banknote_purse.recycler.banknote])}else a=this.#O({$_20:n,$_50:e,$_100:t,$_200:s,$_500:i,$_1000:r});await this.appendToQueue(a,"banknote-purse:dispense")}async banknotePurseEnable({scrow:n=!1}){return await this.banknotePurseConfigure({enable:!0,scrow:n})}async banknotePurseDisable(){return await this.banknotePurseConfigure({enable:!1})}async banknotePurseAcceptInScrow(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");return await this.appendToQueue(l.l.banknotePurseAcceptInScrow(),"banknote-purse:banknote-scrow-status")}async banknotePurseRejectInScrow(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");return await this.appendToQueue(l.l.banknotePurseRejectInScrow(),"banknote-purse:banknote-scrow-status")}async banknotePurseSaveMemory({channel:n=null,$_20:e=null,$_50:t=null,$_100:s=null,$_200:i=null,$_500:r=null,$_1000:a=null}={}){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");return await this.appendToQueue(l.l.banknotePurseSaveMemory({channel:n,$20:e,$50:t,$100:s,$200:i,$500:r,$1000:a}),"banknote-purse:save-memory")}async banknotePurseReadRecycler(){if(!this.__banknote_purse.available)throw new Error("Banknote purse not available");if(!this.__banknote_purse.isRecycler)throw new Error("Banknote purse is not recycler");return await this.appendToQueue(l.l.banknotePurseReadRecycler(),"banknote-purse:read-recycler")}async cardReaderDisable(){if(!this.card_reader.available)throw new Error("Card reader not available");return await this.appendToQueue(l.l.cardReaderDisable(),"card-reader:disable")}async cardReaderDispense({channel:n=1,second_channel:e=null,sensor:t=!0,seconds:s=null,price:i=0}={}){if(!this.card_reader.available)throw new Error("Card reader not available");if((isNaN(this.card_reader.max_pre_credit)||this.card_reader.max_pre_credit===0)&&(this.card_reader.max_pre_credit=i),isNaN(i)||i<=0)throw new Error("Price must be greater than 0");if(i>this.card_reader.max_pre_credit)throw new Error("Price is greater than pre-credit configured");if(!t&&(s===null||s<=0||s>40))throw new Error("Invalid time to dispense without sensor, must be between 0.1 and 40.0 seconds");return this.appendToQueue(l.l.cardReaderDispense({selection:n,second_selection:e,sensor:t,seconds:s,price:i}),"card-reader:dispense")}async paymentPursesDisable({coin:n=!0,banknote:e=!0,cardReader:t=!1}={}){n&&this.__coin_purse.available&&await this.coinPurseDisable(),e&&this.__banknote_purse.available&&await this.banknotePurseDisable(),t&&this.card_reader.available&&await this.cardReaderDisable()}async paymentPursesEnable({coin:n=!0,banknote:e=!0,scrowBanknote:t=!1}={}){n&&this.__coin_purse.available&&await this.coinPurseEnable(),e&&this.__banknote_purse.available&&await this.banknotePurseEnable({scrow:t})}async coolingRelayConfigure({enable:n=!1}={}){return await this.appendToQueue(l.l.coolingRelayConfigure({enable:n}),"status:relay")}async coolingRelayEnable(){return await this.coolingRelayConfigure({enable:!0})}async coolingRelayDisable(){return await this.coolingRelayConfigure({enable:!1})}async readTemperature(){return await this.appendToQueue(l.l.readTemperature(),"status:temperature")}async dispense({selection:n=1,second_selection:e=null,sensor:t=!0,seconds:s=null,retry:i=!0}={selection:1,second_selection:null,sensor:!0,seconds:null,retry:!0}){if(n=parseInt(n,10),isNaN(n)||n<1||n>80)throw new Error("Invalid channel number");if(e!==null&&(e<1||e>80||e===n))throw new Error("Invalid second channel number");if(!t&&(s===null||s<=0||s>40))throw new Error("Invalid time to dispense without sensor, must be between 0.1 and 40.0 seconds");i&&(this.__internal__.dispense.backup_dispense={selection:n,second_selection:e,sensor:t,seconds:s});const r=l.l.dispense({selection:n,second_selection:e,sensor:t,seconds:s});t||(s||(s=1.5),this.__internal__.dispense.custom_limit_counter=s+.2);let a=await this.internalDispense(r);return!a.status&&i&&(a=await this.internalDispense(r)),this.__internal__.dispense.custom_limit_counter=null,a}#a(){this.#n=!1,this.#e=0,this.#t=0}#i({dispensed:n=null,limit:e=80}={}){this.#t=Math.round(this.#e*100/e),this.dispatch("percentage:test",{percentage:this.#t,dispensed:n})}async testEngines({singleEngine:n=!1}={}){if(this.isDispensing)throw new Error("Another dispensing process is running");if(this.#n)throw new Error("Another test is running");this.#a(),this.#n=!0;const e=[];this.#i();for(let t=1;t<=80;t++){const s=await this.dispense({selection:t,second_selection:n?null:t+1,sensor:!1,seconds:.4,retry:!1});e.push(s),this.#e=t,this.#i(),n||t++}this.#e=80,this.#i({dispensed:e}),this.#a()}async sendCustomCode({code:n=[]}={code:[]}){if(n.length===0)throw new Error("Invalid code");return await this.appendToQueue(l.l.customCode(n),"custom")}#A(n){const e=["20","50","100","200","500"],t=this.__banknote_purse.recycler.banknote,s="$_"+e[t],i=parseInt(e[t]),r=this.banknotes.recycler[`p${e[t]}`],a=Math.min(Math.floor(n/i),r),o={banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:n,will_dispense:a>0};return this.totalInRecycler===0||a<1||n===0||(o.banknotes[s]=a,o.pending=parseFloat((n-a*i).toFixed(2))),o}#U(n){const e={banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:n,will_dispense:!1};if(this.totalInRecycler===0||n===0)return e;const t=(s,i)=>{if(this.banknotes.recycler[i]>0){const r=Math.floor(e.pending/s),a=Math.min(r,this.banknotes.recycler[i]);e.banknotes[`$_${s}`]=a,e.pending=parseFloat((e.pending-a*s).toFixed(2))}};return t(1e3,"p1000"),t(500,"p500"),t(200,"p200"),t(100,"p100"),t(50,"p50"),t(20,"p20"),e.will_dispense=Object.values(e.banknotes).some(s=>s>0),e}#o(n){return this.hasRecycler?this.#s()?this.#A(n):this.#U(n):{banknotes:{$_20:0,$_50:0,$_100:0,$_200:0,$_500:0,$_1000:0},pending:n,will_dispense:!1}}#l(n){const e={coins:{$_50c:0,$_1:0,$_2:0,$_5:0,$_10:0},pending:n,will_dispense:!1};if(!this.hasCoinPurse||n<=0||this.totalInTubes===0)return e;const t=(s,i,r=null)=>{if(this.coins.tubes[i]>0){r===null&&(r="$_"+s);const a=Math.floor(e.pending/s),o=Math.min(a,this.coins.tubes[i]);e.coins[r]=o,e.pending=parseFloat((e.pending-o*s).toFixed(2))}};return t(10,"p10"),t(5,"p5"),t(2,"p2"),t(1,"p1"),t(.5,"g50","$_50c"),e.will_dispense=Object.values(e.coins).some(s=>s>0),e}hasToReturnChange(n=0){let e=n;return e<=0?!0:(e=this.#o(e).pending,e=this.#l(e).pending,!(e>0))}async#c(n=null){if(!this.#p())throw new Error("Change not available");let e=this.change,t=this.change;if(n!==null&&(e=n,t=n),t<=0)return!1;const s=this.#o(t);t=s.pending;const i=this.#l(t);return t=i.pending,t>0&&this.dispatch("change:pending",{pending:t}),this.dispatch("change:dispense",{recycler:s.banknotes,coins:i.coins,pending:t,delivery:e-t}),t===e?!1:(s.will_dispense&&await this.banknotePurseDispense(s.banknotes),i.will_dispense&&await this.coinPurseDispense(i.coins),!0)}async returnChange(){return await this.#c()}async returnInsertedMoney(){return this.__money_session.inserted<=0?!1:await this.#c(this.__money_session.inserted)}async serialCorruptMessage(n,e){this.dispatch("corrupt:message",{data:n,message:e})}}exports.Boardroid=d;
package/dist/boardroid.js CHANGED
@@ -1,6 +1,7 @@
1
- import { K as u, D as p } from "./kernel-BZzs36vi.js";
1
+ import { K as u } from "./kernel-CFxkp4Nz.js";
2
+ import { D as p } from "./devices-CHc7K4eY.js";
2
3
  import { l } from "./relay-DP8PLsDP.js";
3
- class _ extends u {
4
+ class f extends u {
4
5
  __coin_purse = {
5
6
  available: !0
6
7
  };
@@ -761,5 +762,5 @@ class _ extends u {
761
762
  }
762
763
  }
763
764
  export {
764
- _ as Boardroid
765
+ f as Boardroid
765
766
  };
@@ -0,0 +1 @@
1
+ "use strict";const a=require("./webserial-core-3UL91lxi.cjs");class r extends a.s{constructor(){super(),r.registerType("boardroid"),r.registerType("hopper"),r.registerType("jofemar"),r.registerType("locker"),r.registerType("pinpad"),r.registerType("pinpax"),r.registerType("relay"),r.registerType("jsd")}static addCustom(t,e){r.registerType(t),r.add(e)}static getCustomByUuid(t,e){return r.get(t,e)}static getJofemarByUuid(t){return r.get("jofemar",t)}static getLockerByUuid(t){return r.get("locker",t)}static getRelayByUuid(t){return r.get("relay",t)}static getBoardroidByUuid(t){return r.get("boardroid",t)}static getPinPadByUuid(t){return r.get("pinpad",t)}static getPinPaxByUuid(t){return r.get("pinpax",t)}static getHopperByUuid(t){return r.get("hopper",t)}static getJsdByUuid(t){return r.get("jsd",t)}static getJofemar(t=1){return r.getByNumber("jofemar",t)}static getBoardroid(t=1){return r.getByNumber("boardroid",t)}static getLocker(t=1){return r.getByNumber("locker",t)}static getRelay(t=1){return r.getByNumber("relay",t)}static getPinPad(t=1){return r.getByNumber("pinpad",t)}static getPinPax(t=1){return r.getByNumber("pinpax",t)}static getHopper(t=1){return r.getByNumber("hopper",t)}static getJsd(t=1){return r.getByNumber("jsd",t)}}r.instance=new r;exports.Devices=r;
@@ -0,0 +1,67 @@
1
+ import { s as a } from "./webserial-core-DSv1dX3s.js";
2
+ class r extends a {
3
+ constructor() {
4
+ super(), r.registerType("boardroid"), r.registerType("hopper"), r.registerType("jofemar"), r.registerType("locker"), r.registerType("pinpad"), r.registerType("pinpax"), r.registerType("relay"), r.registerType("jsd");
5
+ }
6
+ static addCustom(t, e) {
7
+ r.registerType(t), r.add(e);
8
+ }
9
+ /**
10
+ * @deprecated use get instead
11
+ * */
12
+ static getCustomByUuid(t, e) {
13
+ return r.get(t, e);
14
+ }
15
+ static getJofemarByUuid(t) {
16
+ return r.get("jofemar", t);
17
+ }
18
+ static getLockerByUuid(t) {
19
+ return r.get("locker", t);
20
+ }
21
+ static getRelayByUuid(t) {
22
+ return r.get("relay", t);
23
+ }
24
+ static getBoardroidByUuid(t) {
25
+ return r.get("boardroid", t);
26
+ }
27
+ static getPinPadByUuid(t) {
28
+ return r.get("pinpad", t);
29
+ }
30
+ static getPinPaxByUuid(t) {
31
+ return r.get("pinpax", t);
32
+ }
33
+ static getHopperByUuid(t) {
34
+ return r.get("hopper", t);
35
+ }
36
+ static getJsdByUuid(t) {
37
+ return r.get("jsd", t);
38
+ }
39
+ static getJofemar(t = 1) {
40
+ return r.getByNumber("jofemar", t);
41
+ }
42
+ static getBoardroid(t = 1) {
43
+ return r.getByNumber("boardroid", t);
44
+ }
45
+ static getLocker(t = 1) {
46
+ return r.getByNumber("locker", t);
47
+ }
48
+ static getRelay(t = 1) {
49
+ return r.getByNumber("relay", t);
50
+ }
51
+ static getPinPad(t = 1) {
52
+ return r.getByNumber("pinpad", t);
53
+ }
54
+ static getPinPax(t = 1) {
55
+ return r.getByNumber("pinpax", t);
56
+ }
57
+ static getHopper(t = 1) {
58
+ return r.getByNumber("hopper", t);
59
+ }
60
+ static getJsd(t = 1) {
61
+ return r.getByNumber("jsd", t);
62
+ }
63
+ }
64
+ r.instance = new r();
65
+ export {
66
+ r as D
67
+ };
package/dist/hopper.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./webserial-core-Co8HLQvu.cjs");class d extends s.S{__hoppers__={levels:[{id:1,currency:10,key:"Hopper 1",name:"10 Pesos",amount:0,capacity:1e3},{id:2,currency:5,key:"Hopper 2",name:"5 Pesos",amount:0,capacity:1e3},{id:3,currency:2,key:"Hopper 3",name:"2 Pesos",amount:0,capacity:1e3},{id:4,currency:1,key:"Hopper 4",name:"1 Peso",amount:0,capacity:1e3}],balance:0,current:null};constructor({filters:e=null,config_port:t={baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:r=1,socket:n=!1}={filters:null,config_port:{baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:1,socket:!1}){if(super({filters:e,config_port:t,no_device:r,socket:n}),this.__internal__.device.type="hopper",s.s.getCustom(this.typeDevice,r))throw new Error(`Device ${this.typeDevice} ${r} already exists`);this.__internal__.time.response_connection=7e3,this.__internal__.time.response_general=7e3,this.__internal__.serial.delay_first_connection=500,this.__internal__.serial.response.replacer="",this.__internal__.serial.response.limiter=`\r
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./webserial-core-3UL91lxi.cjs");class d extends s.T{__hoppers__={levels:[{id:1,currency:10,key:"Hopper 1",name:"10 Pesos",amount:0,capacity:1e3},{id:2,currency:5,key:"Hopper 2",name:"5 Pesos",amount:0,capacity:1e3},{id:3,currency:2,key:"Hopper 3",name:"2 Pesos",amount:0,capacity:1e3},{id:4,currency:1,key:"Hopper 4",name:"1 Peso",amount:0,capacity:1e3}],balance:0,current:null};constructor({filters:e=null,config_port:t={baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:r=1,socket:n=!1}={filters:null,config_port:{baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:1,socket:!1}){if(super({filters:e,config_port:t,no_device:r,socket:n}),this.__internal__.device.type="hopper",s.s.getCustom(this.typeDevice,r))throw new Error(`Device ${this.typeDevice} ${r} already exists`);this.__internal__.time.response_connection=7e3,this.__internal__.time.response_general=7e3,this.__internal__.serial.delay_first_connection=500,this.__internal__.serial.response.replacer="",this.__internal__.serial.response.limiter=`\r
2
2
  `,s.s.add(this),this.#s()}#s(){const e=["levels","hopper:updated","dispense-change","balance:updated","validator:status","change:1x1"];for(const t of e)this.serialRegisterAvailableListener(t)}get balance(){return this.__hoppers__.balance}get currentHopper(){return this.__hoppers__.current}get levels(){return this.__hoppers__.levels}setMaxCapacity({hopper:e=1,capacity:t=1e3}={hopper:1,capacity:1e3}){return this.#r(e),this.__hoppers__.levels[e-1].capacity=t,this}setHopperName({hopper:e=1,name:t=""}={hopper:1,name:""}){if(this.#r(e),typeof t!="string"||t.length===0)throw new TypeError("Name must be a non-empty string");return this.__hoppers__.levels[e-1].name=t,this}setHopperKey({hopper:e=1,key:t=""}={hopper:1,key:""}){if(this.#r(e),typeof t!="string"||t.length===0)throw new TypeError("Key must be a non-empty string");return this.__hoppers__.levels[e-1].key=t,this}setHopperCurrency({hopper:e=1,currency:t=1}={hopper:1,currency:1}){if(this.#r(e),typeof t!="number"||t<=0)throw new RangeError("Currency must be a positive number");return this.__hoppers__.levels[e-1].currency=t,this}#n(e){e.error=!0,e.ascii.includes("ffffff")?(e.name="SINTAX",e.description="Error de Sintaxis",e.no_code=400):e.ascii.includes("ffaaaa")?(e.name="LOWLEVEL",e.description="Bajo nivel de monedas en Hopper (99)",e.no_code=401):e.ascii.includes("ffbbbb")?(e.name="TIMEOUT_DISPENSE",e.description="Error de dispensado, timeout",e.no_code=402):(e.name="UNKNOWN_ERROR",e.description="Unknown error occurred",e.no_code=999),this.dispatch("serial:message",e)}#i(e){if(this.lastAction==="status")e.name="STATUS",e.description="Hoppers status",e.no_code=1,this.__hoppers__.levels[0].amount=this.#t(e.code[9],e.code[10]),this.__hoppers__.levels[1].amount=this.#t(e.code[7],e.code[8]),this.__hoppers__.levels[2].amount=this.#t(e.code[5],e.code[6]),this.__hoppers__.levels[3].amount=this.#t(e.code[3],e.code[4]),e.data=this.__hoppers__.levels,this.dispatch("levels",e.data);else if(this.lastAction==="readHopper"){e.name="READ_HOPPER",e.description=`Hopper ${this.__hoppers__.current} level`,e.no_code=2;const t=(this.__hoppers__.current||1)-1;this.__hoppers__.levels[t].amount=this.#t(e.code[9],e.code[10]),e.data=this.__hoppers__.levels,e.hopperId=this.__hoppers__.current,this.dispatch("hopper:updated",this.__hoppers__.levels[t])}else if(this.lastAction==="writeHopper"){e.name="WRITE_HOPPER",e.description="Hopper "+this.__hoppers__.current+" write",e.no_code=3,this.__hoppers__.levels[(this.__hoppers__.current||1)-1].amount=this.#t(e.code[9],e.code[10]),e.data=this.__hoppers__.levels,e.hopperId=this.__hoppers__.current;const t=(this.__hoppers__.current||1)-1;this.dispatch("hopper:updated",this.__hoppers__.levels[t])}else if(this.lastAction==="dispenseHopper"){e.name="DISPENSEHOPPER",e.description="Hopper "+this.__hoppers__.current+" dispense",e.no_code=4,this.__hoppers__.levels[(this.__hoppers__.current||1)-1].amount=this.#t(e.code[9],e.code[10]),e.data=this.__hoppers__.levels,e.hopperId=this.__hoppers__.current;const t=(this.__hoppers__.current||0)-1;this.dispatch("hopper:updated",this.__hoppers__.levels[t])}else this.lastAction==="dispenseChange"?(e.name="DISPENSE_CHANGE",e.description="Change dispensed",e.no_code=5,e.data=this.#t(e.code[9],e.code[10]),this.dispatch("dispense-change",{amount:e.data})):this.lastAction==="readBalance"?(e.name="READ_BALANCE",e.description="Read Balance",e.no_code=6,this.__hoppers__.balance=this.#t(e.code[9],e.code[10]),e.data=this.__hoppers__.balance,this.dispatch("balance:updated",{balance:e.data})):this.lastAction==="clearBalance"?(e.name="CLEAR_BALANCE",e.description="Clared hoppers balance",e.no_code=7,this.__hoppers__.balance=this.#t(e.code[9],e.code[10]),e.data=this.__hoppers__.balance,this.dispatch("balance:updated",{balance:e.data})):this.lastAction==="configValidator"?(e.code[2]===1?(e.name="ENABLE_VALIDATOR",e.description="Validator enabled",e.no_code=8,this.dispatch("validator:status",{enabled:!0})):(e.name="DISABLE_VALIDATOR",e.description="Validator disabled",e.no_code=9,this.dispatch("validator:status",{enabled:!1})),e.no_code=400,e.data=e.code[2]===1?"enabled":"disabled"):this.lastAction?.includes("change1x1Hopper")&&(e.code[2]===1?(e.name="CHANGE_1X1_HOPPER_1",e.description="Change 1x1 Hopper 1",e.no_code=10):e.code[2]===2?(e.name="CHANGE_1X1_HOPPER_2",e.description="Change 1x1 Hopper 2",e.no_code=11):e.code[2]===3?(e.name="CHANGE_1X1_HOPPER_3",e.description="Change 1x1 Hopper 3",e.no_code=12):e.code[2]===4?(e.name="CHANGE_1X1_HOPPER_4",e.description="Change 1x1 Hopper 4",e.no_code=13):(e.name="CHANGE_1X1_HOPPER_UNKNOWN",e.description="Change 1x1 Hopper Unknown",e.no_code=14),this.dispatch("change:1x1",{hopperId:e.code[2]}));this.dispatch("serial:message",e)}serialMessage(e){const t=e,r=this.parseUint8ArrayToString(t),i={ascii:this.asciiToHex(r),code:t,name:"",description:"",request:this.lastAction,no_code:0,error:!1,data:null};if(t.length===3){this.#n(i);return}const p=Array.from(t);if(t.length!==13){const c=this.#p({array:p,chunkSize:13});for(const o of c){const a=this.parseUint8ArrayToString(new Uint8Array(o)),h=this.asciiToHex(a),_=this.stringToArrayHex(a);i.code=o,i.hex=_,i.ascii=h,o.length!==13?this.#n(i):this.#i(i)}return}this.#i(i)}#t(e,t){return(e<<8|t)<<16>>16}#r(e){if(typeof e!="number"||e<1||e>4)throw new RangeError("Hopper ID must be a number between 1 and 4");if(typeof e!="number"||!Number.isInteger(e))throw new TypeError("Hopper ID must be an integer")}#o(e){if(typeof e!="number"||e<-32768||e>32767)throw new RangeError("Quantity must be a number between -32768 and 32767");if(typeof e!="number"||!Number.isInteger(e))throw new TypeError("Quantity must be an integer")}#a(e){this.#o(e);const t=e&65535,r=t>>8&255,n=t&255;return[r,n]}#p({array:e,chunkSize:t=13}={array:[],chunkSize:13}){if(!Array.isArray(e))throw new TypeError("Expected an array");if(typeof t!="number"||t<=0)throw new RangeError("Chunk size must be a positive number");const r=[];for(let n=0;n<e.length;n+=t)r.push(e.slice(n,n+t));return r}#e(e){e.length<11&&(e=[...e,...Array(11-e.length).fill(0)]);const r=e.slice(1,11).reduce((n,i)=>{if(typeof i!="number")throw new TypeError("Array must contain only numbers");return n+i},0)&255;return e[11]=r,e[12]=15,e}serialSetConnectionConstant(){return[10,0,0,0,0,0,0,0,0,0,0,0,15]}async sendConnect(){const e=this.#e([10]);return await this.appendToQueue(e,"connect")}async requestStatus(){const e=this.#e([10,10,11,12]);return await this.appendToQueue(e,"status")}async readBalance(){const e=this.#e([10,192,1]);return await this.appendToQueue(e,"readBalance")}async clearBalance(){const e=this.#e([10,192,2]);return await this.appendToQueue(e,"clearBalance")}async forceInvalid(){const e="0A000F00".match(/.{1,2}/g);return await this.appendToQueue(e,"ForceInvalid")}async readHopper({hopper:e=1}={hopper:1}){this.#r(e),this.__hoppers__.current=e;const t=this.#e([10,e,e]);return await this.appendToQueue(t,"readHopper")}async writeHopper({hopper:e=1,quantity:t=0}={hopper:1,quantity:0}){this.#r(e),this.#o(t),this.__hoppers__.current=e;const[r,n]=this.#a(t),i=this.#e([10,240,e,0,0,0,0,0,0,r,n]);return await this.appendToQueue(i,"writeHopper")}async dispenseHopper({hopper:e=1}={hopper:1}){this.#r(e),this.__hoppers__.current=e;const t=this.#e([10,2,e]);return await this.appendToQueue(t,"dispenseHopper")}async dispenseChange({change:e=0}={change:0}){if(typeof e!="number"||e<0||e>32767)throw new RangeError("Change must be a number between 0 and 32767");if(typeof e!="number"||!Number.isInteger(e))throw new TypeError("Change must be an integer");const t=e&255,r=e>>8&255,n=this.#e([10,204,170,0,0,0,0,0,0,r,t]);return await this.appendToQueue(n,"dispenseChange")}async configValidator({enable:e=!1}={enable:!1}){if(typeof e!="boolean")throw new TypeError("Enable must be a boolean");const t=this.#e([10,176,e?1:0]);return await this.appendToQueue(t,"configValidator")}async disableValidator(){return await this.configValidator({enable:!1})}async enableValidator(){return await this.configValidator({enable:!0})}async change1x1({hopper:e=1}={hopper:1}){this.#r(e),this.__hoppers__.current=e;const t=this.#e([10,224,e]);return await this.appendToQueue(t,"change1x1Hopper-"+e)}async sendCustomCode({code:e=[]}={code:[]}){if(!Array.isArray(e)||!e.every(r=>typeof r=="number"&&r>=0&&r<=255))throw new TypeError("Code must be an array of numbers between 0 and 255");const t=this.#e(e);await this.appendToQueue(t,"custom")}}exports.Hopper=d;
package/dist/hopper.js CHANGED
@@ -1,4 +1,4 @@
1
- import { S as d, s as p } from "./webserial-core-Zwd9L-Y9.js";
1
+ import { T as d, s as p } from "./webserial-core-DSv1dX3s.js";
2
2
  class f extends d {
3
3
  __hoppers__ = {
4
4
  levels: [
package/dist/jofemar.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./kernel-7ObJp74F.cjs"),i=require("./relay-E3NCcSjS.cjs");class y extends h.Kernel{__device={type:"esplus",support_cart:!1,withdraw:{in_process:!1,seconds:60,interval:0},cart:{in_process:!1},channels:{verification:{clear(){this.running=!1,this.current=1,this.channels=[]},running:!1,start:1,end:80,current:1,channels:[]}}};constructor({filters:t=null,config_port:e,no_device:n=1,device_listen_on_channel:r=1,type:a="esplus",support_cart:o=!0,socket:c=!1}={}){if(super({filters:t,config_port:e,no_device:n,device_listen_on_channel:r,socket:c}),this.__internal__.device.type="jofemar",h.Devices.getCustom(this.typeDevice,n))throw new Error(`Device ${this.typeDevice} ${n} already exists`);this.__internal__.dispense.must_response=!0,this.__internal__.time.response_general=800,this.__internal__.time.response_engines=800,this.__internal__.dispense.limit_counter=40,this.__internal__.dispense.timeout=0,this.__internal__.dispense.timeout_time=4e3,this.__internal__.dispense.interval=0,this.__internal__.dispense.interval_time=1e3,this.__internal__.device.hex_number=(128+this.listenOnChannel).toString(16),this.__internal__.device.door_open=!1,this.__internal__.dispense.elevator={locking_time:60,locking_interval:0,need_reset:!1},this.deviceType=a,this.supportCart=o,this.#h(),h.Devices.add(this),this.#l()}set startChannelVerification(t){const e=parseInt(t);if(isNaN(e))throw new Error("Invalid start channel verification, must be a number");if(e<1||e>126)throw new Error("Invalid start channel verification, valid range is 1 to 126");this.__device.channels.verification.start=e}set endChannelVerification(t){const e=parseInt(t);if(isNaN(e))throw new Error("Invalid end channel verification, must be a number");if(e<1||e>126)throw new Error("Invalid end channel verification, valid range is 1 to 126");this.__device.channels.verification.end=e}set listenOnChannel(t){if(t=parseInt(t),isNaN(t)||t<1||t>31)throw new Error("Invalid port number, valid range is 1 to 31");this.__internal__.device.listen_on_port=t,this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(t),this.__internal__.device.hex_number=(128+t).toString(16)}set listenOnPort(t){this.listenOnChannel=t}set deviceType(t){if(typeof t!="string")throw new Error("Invalid device type, must be a string");this.__device.type=t}set supportCart(t){if(typeof t!="boolean")throw new Error("Invalid support cart, must be a boolean");this.__device.support_cart=t}#h(){const t=["dispensing:withdrawal","command-executed","keyboard:pressed","door:event","program:version","machine:faults","clock:registers","machine:activity","check:language","check:beeper","check:isolation-tray","check:engine-voltage","check:push-over","check:extractor-after-dispense","check:standby-after-collect","check:standby-without-collect","check:elevator-speed","check:expiration-by-temperature","check:temperature-before-expiration","check:expiration-after","check:temperature-scale","check:machine-id","temperature:working","temperature:current","jofemar:warning","jofemar:error","serial:message","reset:errors","channels","channels:progress","channel:status","machine:status"];for(const e of t)this.serialRegisterAvailableListener(e)}#l(){this.on("internal:dispense:running",this.#F.bind(this))}serialSetConnectionConstant(t=1){return i.o.connection({channel:t})}async#s(){if(!this.__internal__.dispense.elevator.locking_interval)return this.__internal__.dispense.elevator.need_reset&&(this.__internal__.dispense.elevator.need_reset=!1,await this.resetWaitingProductRemovedError(),await h.wait(500)),this.__internal__.dispense.status="elevator-locked",this.__internal__.dispense.elevator.locking_time=60,new Promise(t=>{this.__internal__.dispense.elevator.locking_interval=setInterval(()=>{this.dispatch("dispensing:withdrawal",{elevator:!0,seconds:this.__internal__.dispense.elevator.locking_time,description:"Please recall products from the elevator"}),this.__internal__.dispense.elevator.locking_time-=1,this.__internal__.dispense.elevator.locking_time<=0&&(clearInterval(this.__internal__.dispense.elevator.locking_interval),this.__internal__.dispense.elevator.locking_interval=0,t(!0))},1e3)})}#d(t){return t.name="ok",t.description="The last command was executed successfully",t.no_code=1,this.dispatch("command-executed",t),t}#p(t,e){e.additional={hex:t,dec:this.hexToDec(t),ascii:null};const n={30:"0",31:"1",32:"2",33:"3",34:"4",35:"5",36:"6",37:"7",38:"8",39:"9","2a":"*",23:"#",41:"A",42:"B",43:"C",44:"D"},r=t.toString().toLowerCase();return e.additional.ascii=n[r]??null,e.name="Key pressed",e.description=`The key ${e.additional.ascii} was pressed`,e.no_code=2,this.dispatch("keyboard:pressed",e.additional),e}#u(t,e){return e.additional={open:!1},e.no_code=3,t==="4f"?(e.name="door open",e.description="The door was opened",e.additional.open=!0,this.__internal__.device.door_open=!0,this.dispatch("door:event",e.additional)):t==="43"?(e.name="door close",e.description="The door was closed",e.additional.open=!1,this.__internal__.device.door_open=!1,this.dispatch("door:event",e.additional)):(e.name="door event",e.description="The door event received is unknown",this.dispatch("door:event",{open:e.additional.open,message:e})),e}#_(t,e){e.no_code=404;let n=t[5]??null;if(n&&this.listenOnChannel>1&&(n=this.hexToDec(n)-this.listenOnChannel+1,n=this.decToHex(n)),!n)return e;if(n==="fd"?(e.no_code=4,e.name="channel disconnected",e.description="The channel is disconnected",e.additional={active:!1}):n==="fc"?(e.no_code=5,e.name="channel connected",e.description="The channel is connected",e.additional={active:!0}):(e.no_code=6,e.name="channel sold out",e.description="The channel is empty",e.additional={active:!0}),this.__device.channels.verification.running){const r=this.__device.channels.verification.channels.length+this.__device.channels.verification.start;this.__device.channels.verification.channels.push({selection:r,active:e.additional.active}),e.additional.selection=r}return this.dispatch("channel:status",e.additional),e}#f(t,e){e.no_code=39,e.name="Program version";const n=t.slice(4,12),r=n.map(a=>String.fromCharCode(this.hexToDec(a))).join("");return e.additional={version:r,hex:n},e.description=`The program version is ${r}`,this.dispatch("program:version",e.additional),e}#y(t,e){e.no_code=39,e.name="Machine faults",e.description="No faults detected",e.additional={no_faults:0,faults:[]};const n=t.slice(4,-3);if(n.length>1&&n[0]!=="30"){e.description="Machine has faults";const r={31:"Busy",32:"Invalid tray",33:"Invalid channel",34:"Empty channel",35:"Jam in elevator engine",36:"Malfunction in the elevator belt or product detector",37:"Failure in one of the photo transistors in the cabinet",38:"No channels detected",39:"Product detector fault",41:"Machine display is disconnected",42:"Product alarm under elevator",43:"Error when elevator approaching to a position",44:"Fault in keyboard",45:"Eeprom writing error",46:"Fault communicating with temperature control",47:"The thermometer is disconnected",48:"Thermometer programming lost",49:"Thermometer faulty","4a":"Channels power consumption detector faulty","4b":"Elevator does not find channel or tray","4c":"Elevator does not find delivery product position","4d":"Interior of elevator blocked","4e":"Error in tester of product detector","4f":"Waiting for product to be removed",50:"Product expired by temperature reasons",51:"Automatic door faulty",59:"Product is expired","5a":"Product is expired",61:"Product is expired",62:"Product is expired",63:"Product is expired",64:"Product detector didn't change during its verification test"};for(const a of n)r[a]&&e.additional.faults&&typeof e.additional.no_faults<"u"&&(e.additional.faults.push(r[a]||"Unknown fault"),e.additional.no_faults++)}return this.dispatch("machine:faults",e.additional),e}#v(t,e){e.no_code=40,e.name="Clock registers",e.description="Clock registers";const n=t.slice(4,-3),r=n.map(_=>String.fromCharCode(this.hexToDec(_))).join(""),[a,o]=r.split(" "),[c,l]=a.split(":"),[s,d,p]=o.split("-"),u=new Date(2e3+parseInt(p),parseInt(d)-1,parseInt(s),parseInt(c),parseInt(l));return e.additional={day:s,month:d,year:p,hours:c,minutes:l,formatted:r,date:u,hex:n},this.dispatch("clock:registers",e.additional),e}#C(t,e){e.no_code=41,e.name="Machine activity",e.description="Events from read machine activity";const n=String.fromCharCode(this.hexToDec(t[4])).toUpperCase();if(n!=="0"){const r=t.slice(5,-3);if(n==="T"&&r.length===4){const a=String.fromCharCode(this.hexToDec(r[0])),o=String.fromCharCode(this.hexToDec(r[1])),c=String.fromCharCode(this.hexToDec(r[3]));e.additional={ascii:n,type:"DU.d",dozens:a,units:o,decimals:c,time:parseFloat(`${a}${o}.${c}`),meaning:"Extraction time (in seconds)"}}else if(["B","D","E","F","G"].includes(n)&&r.length===3){const a=String.fromCharCode(this.hexToDec(r[0])),o=String.fromCharCode(this.hexToDec(r[1])),c=String.fromCharCode(this.hexToDec(r[2])),l=parseInt(`${a}${o}${c}`),s={B:"Error on going to tray channel",D:"Error on product detector",E:"Extraction of channel ok",F:"Error on engine intensity detection",G:"Error on product exit door"};e.additional={type:"HDU",hundreds:a,dozens:o,decimals:c,channel:l,selection:l-109,ascii:n,meaning:s[n]||"Unknown"}}else if(r.length===13){const a=r.map(f=>String.fromCharCode(this.hexToDec(f))).join(""),o=parseInt(a.slice(0,2)),c=parseInt(a.slice(2,4)),l=parseInt(a.slice(4,6)),s=parseInt(a.slice(7,9)),d=parseInt(a.slice(9,11))-1,p=2e3+parseInt(a.slice(11,13)),u=new Date(p,d,s,o,c,l),_={A:"Attempt to close product exit door",C:"Closing of exterior door",H:"Error on opening of product exit door",I:"New attempt to arrive at product exit position after an error on first attempt",J:"Power on cooling unit",K:"Power off cooling unit",L:"Start of defrosting",M:"End of defrosting",O:"Opening of exterior door",R:"Memory reset",S:"Error on going to product exit position",Y:"Power on machine",Z:"Power off machine",c:"Closing of inner door",e:"New attempt to extract from channel due no product detection when elevator arrived to product exit position",o:"Opening of inner door"};e.additional={type:"hhmmssWddMMAA",date:u,hex:r,formatted:u.toLocaleString(),ascii:n,meaning:_[n]||"Unknown"}}}return this.dispatch("machine:activity",e.additional),e}#T(t,e){const n={30:"Spanish",31:"English",32:"French"};return e.no_code=42,e.name="Language",e.description=`The language is ${n[t]||"unknown"}`,e.additional={hex:t,language:n[t]||"unknown"},this.dispatch("check:language",e.additional),e}#k(t,e){return e.no_code=43,e.name="Beeper",e.description=`The beeper is ${t==="30"?"on":"off"}`,e.additional={hex:t,beeper:t==="30"},this.dispatch("check:beeper",e.additional),e}#m(t,e){e.no_code=44,e.name="Isolation tray",e.description="Isolation tray";const n=this.hexToDec(t)-139;return e.additional={hex:t,tray:n},this.dispatch("check:isolation-tray",e.additional),e}#w(t,e){e.no_code=45,e.name="Engine voltage",e.description="Engine voltage";const n=(this.hexToDec(t)-128)/2+5;return e.additional={hex:t,voltage:n},this.dispatch("check:engine-voltage",e.additional),e}#b(t,e){e.no_code=46,e.name="Push over",e.description="Push over";const n=t==="30";return e.additional={hex:t,push:n},this.dispatch("check:push-over",e.additional),e}#x(t,e){e.no_code=47,e.name="Extractor after dispense",e.description="Extractor after dispense";const n=(this.hexToDec(t)-128)/10;return e.additional={hex:t,seconds:n},this.dispatch("check:extractor-after-dispense",e.additional),e}#E(t,e){e.no_code=48,e.name="Standby after collect",e.description="Time to standby after collect product";const n=this.hexToDec(t)-128;return e.additional={hex:t,seconds:n},this.dispatch("check:standby-after-collect",e.additional),e}#D(t,e){e.no_code=49,e.name="Standby without collect",e.description="Time to standby when product delivery is not collected";const n=this.hexToDec(t)-128;return e.additional={hex:t,minutes:n},this.dispatch("check:standby-without-collect",e.additional),e}#O(t,e){e.no_code=50,e.name="Elevator speed",e.description="Elevator speed";const n=t==="30"?"low":"high";return e.additional={hex:t,speed:n},this.dispatch("check:elevator-speed",e.additional),e}#M(t,e){e.no_code=51,e.name="Temperature expiration",e.description="Temperature expiration";const n=t==="31";return e.additional={hex:t,enabled:n},this.dispatch("check:expiration-by-temperature",e.additional),e}#I(t,e){e.no_code=52,e.name="Temperature before expiration",e.description="Temperature before expiration";const n=(this.hexToDec(t)-128)/2;return e.additional={hex:t,temperature:n},this.dispatch("check:temperature-before-expiration",e.additional),e}#S(t,e){e.no_code=53,e.name="Time before expiration",e.description="Time before expiration";const n=this.hexToDec(t)-128;return e.additional={hex:t,minutes:n},this.dispatch("check:expiration-after",e.additional),e}#P(t,e){e.no_code=54,e.name="Temperature scale",e.description="Temperature scale";const n=t==="43"?"Celsius":"Fahrenheit";return e.additional={hex:t,scale:n},this.dispatch("check:temperature-scale",e.additional),e}#Q(t,e){return e.no_code=54,e.name="Machine ID",e.description="Machine ID",e.additional={hex:t[4],full_hex:t},this.dispatch("check:machine-id",e.additional),e}#g(t,e){return e.no_code=7,e.name="working temperature",e.description=`The working temperature is ${t}`,e.additional={hex:t,temperature:{traditional:(this.hexToDec(t)-this.hexToDec("80"))/2,ice_plus:(this.hexToDec(t)-this.hexToDec("80"))/2-25.5}},this.dispatch("temperature:working",e.additional),e}#A(t,e){return e.no_code=8,e.name="current temperature",e.additional={sign:null,tens:null,units:null,decimals:null,type_degrees:null,formatted:null,decimal_point:t[7]==="2e"?".":null,degrees:t[9]==="7f"?"°":null,error:null},t[4]==="2b"?e.additional.sign=t[4]="+":["2e","2d"].includes(t[4])?e.additional.sign=t[4]="-":t[4]==="20"&&(e.additional.error="Error in thermometer"),this.hexToDec(t[5])>=48&&this.hexToDec(t[5])<=57?e.additional.tens=this.hexToDec(t[5])-48:t[5]==="2a"&&(e.additional.error="Error in thermometer"),this.hexToDec(t[6])>=48&&this.hexToDec(t[6])<=57?e.additional.units=this.hexToDec(t[6])-48:t[6]==="2a"&&(e.additional.error="Error in thermometer"),this.hexToDec(t[8])>=48&&this.hexToDec(t[8])<=57?e.additional.decimals=this.hexToDec(t[8])-48:t[8]==="2a"&&(e.additional.error="Error in thermometer"),t[10]==="43"?e.additional.type_degrees="C":t[10]==="46"&&(e.additional.type_degrees="F"),e.additional.error==="Error in thermometer"?(e.additional.formatted="Error in thermometer",e.description="The current temperature cannot be read because there is an error in the thermometer"):(e.additional.formatted=(e.additional.sign??"")+(e.additional.tens??"")+(e.additional.units??"")+(e.additional.decimal_point??"")+(e.additional.decimals??"")+(e.additional.degrees??"")+(e.additional.type_degrees??""),e.description=`The current temperature is ${e.additional.formatted}`),this.dispatch("temperature:current",e.additional),e}#B(t,e,n=128){if(t[1]&&(e.additional.machine||(e.additional.machine={hex:null,dec:null}),e.additional.machine.hex=t[1],e.additional.machine.dec=this.hexToDec(t[1])-n),!(t[1]&&t[2]))e=this.#d(e);else switch(t[2]){case"54":e.request="--automatic",e=this.#p(t[3],e);break;case"50":e.request="--automatic",e=this.#u(t[3],e);break;case"43":switch(e.request="check-data",t[3]){case"41":e=this.#C(t,e);break;case"43":e.request="channel-status",e=this.#_(t,e);break;case"50":e=this.#f(t,e);break;case"53":e=this.#y(t,e);break;case"54":e.request="working-temperature",e=this.#g(t[4],e);break;case"72":e=this.#v(t,e);break;case"74":e.request="current-temperature",e=this.#A(t,e);break;case"49":e=this.#T(t[4],e);break;case"5a":e=this.#k(t[4],e);break;case"42":e=this.#m(t[4],e);break;case"47":e=this.#w(t[4],e);break;case"4e":e=this.#Q(t,e);break;case"4f":e=this.#b(t[4],e);break;case"45":e=this.#x(t[4],e);break;case"46":e=this.#E(t[4],e);break;case"48":e=this.#D(t[4],e);break;case"76":e=this.#O(t[4],e);break;case"63":e=this.#M(t[4],e);break;case"65":e=this.#I(t[4],e);break;case"66":e=this.#S(t[4],e);break;case"67":e=this.#P(t[4],e);break}break}return e}#n(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status=!0)}#e(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status=!1)}#a(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status="elevator-locked")}#t({type:t=null,severity:e="low"}={}){this.dispatch("jofemar:warning",{type:t,severity:e})}#i({type:t=null,severity:e="high"}={}){this.dispatch("jofemar:error",{type:t,severity:e})}#W(t,e){if(e.request="status",t[1]&&!t[2]){switch(t[1]){case"30":e.name="Machine ready",e.description="The machine is ready for instructions",e.no_code=9,this.#n();break;case"31":e.name="Machine busy",e.description="The machine is busy right now",e.no_code=10;break;case"32":e.name="Invalid tray",e.description="The tray requested is invalid",e.no_code=11,this.#e(),this.#t({type:"invalid-tray"});break;case"33":e.name="Invalid channel",e.description="The channel requested is invalid",e.no_code=12,this.#e(),this.#t({type:"invalid-channel"});break;case"34":e.name="Empty channel",e.description="The channel requested is empty",e.no_code=13,this.#e(),this.#t({type:"empty-channel"});break;case"35":e.name="Jam",e.description="Jam in elevator engine",e.no_code=14,this.#e(),this.#i({type:"jam"});break;case"36":e.name="Malfunction",e.description="Malfunction in the elevator belt or product detector",e.no_code=15,this.#e(),this.#i({type:"malfunction"});break;case"37":e.name="Photo transistors",e.description="Failure in one of the photo transistors in the cabinet",e.no_code=16,this.#e(),this.#i({type:"photo-transistors"});break;case"38":e.name="Without channels",e.description="No channels detected",e.no_code=17,this.#e(),this.#i({type:"without-channels"});break;case"39":e.name="Product detector fault",e.description="Product detector fault",e.no_code=18,this.#a(),this.#t({type:"fault-product-detector"});break;case"41":e.name="Fault in 485 BUS",e.description="Machine display is disconnected",e.no_code=19,this.#n(),this.#t({type:"display-disconnected"});break;case"42":e.name="Product under elevator",e.description="Product alarm under elevator",e.no_code=20,this.#e(),this.#t({type:"product-under-elevator"});break;case"43":e.name="Error when elevator approaching to a position",e.description="Error when elevator approaching to a position",e.no_code=21,this.#n(),this.#t({type:"error-approaching-position",severity:"high"});break;case"44":e.name="Fault in keyboard",e.description="Fault in keyboard",e.no_code=22,this.#e(),this.#i({type:"fault-keyboard"});break;case"45":e.name="Eeprom writing error",e.description="Eeprom writing error",e.no_code=23,this.#e(),this.#i({type:"eeprom-writing-error",severity:"critical"});break;case"46":e.name="Fault communicating with temperature control",e.description="Fault communicating with temperature control",e.no_code=24,this.#n(),this.#t({type:"fault-temperature-control"});break;case"47":e.name="Thermometer disconnected",e.description="The thermometer is disconnected",e.no_code=25,this.#n(),this.#t({type:"thermometer-disconnected"});break;case"48":e.name="Thermometer programming lost",e.description="Thermometer programming lost",e.no_code=26,this.#n(),this.#t({type:"thermometer-programming-lost"});break;case"49":e.name="Thermometer faulty",e.description="Thermometer faulty",e.no_code=27,this.#n(),this.#t({type:"thermometer-faulty"});break;case"4a":e.name="Channels power consumption detector faulty",e.description="Channels power consumption detector faulty",e.no_code=28,this.#e(),this.#i({type:"channels-power-consumption-detector-faulty",severity:"critical"});break;case"4b":e.name="Elevator does not find channel or tray",e.description="Elevator does not find channel or tray",e.no_code=29,this.#e(),this.#t({type:"elevator-not-find-channel-tray"});break;case"4c":e.name="Elevator does not find delivery product position",e.description="Elevator does not find delivery product position",e.no_code=30,this.#e(),this.#i({type:"elevator-not-find-delivery-position"});break;case"4d":e.name="Interior of elevator blocked",e.description="Interior of elevator blocked",e.no_code=31,this.#a(),this.__internal__.dispense.elevator.need_reset||(this.__internal__.dispense.elevator.need_reset=!0),this.#i({type:"interior-elevator-blocked",severity:"low"});break;case"4e":e.name="Error in tester of product detector",e.description="Error in tester of product detector",e.no_code=32,this.#e(),this.#i({type:"error-tester-product-detector"});break;case"4f":e.name="Waiting for product to be removed",e.description="Waiting for product to be removed",e.no_code=33,this.#a();break;case"50":e.name="Product expired by temperature reasons",e.description="Product expired by temperature reasons",e.no_code=34,this.#n(),this.#t({type:"product-expired-temperature"});break;case"51":e.name="Automatic door faulty",e.description="Automatic door faulty",e.no_code=35,this.#n(),this.#t({type:"automatic-door-faulty"});break;case"59":case"5a":case"61":case"62":case"63":switch(e.name="Product is expired",e.description="Product is expired",e.additional={nsf_alarm:1},t[1]){case"5a":e.additional.nsf_alarm=2;break;case"61":e.additional.nsf_alarm=3;break;case"62":e.additional.nsf_alarm=4;break;case"63":e.additional.nsf_alarm=5;break}e.no_code=36,this.#n(),this.#t({type:"product-expired"});break;case"64":e.name="Product detector didn't change during its verification test",e.description="Product detector didn't change during its verification test",e.no_code=37,this.#n(),this.#t({type:"automatic-door-faulty"});break}this.dispatch("machine:status",e)}else e.name="executed",e.description="The last command was executed successfully",e.no_code=8,!t[1]&&this.__internal__.dispense.dispensing&&this.#e();return e}serialMessage(t){t=this.fixHexArray(t);const e=128;let n={code:t,name:null,description:null,request:"unknown",no_code:0,additional:{machine:{hex:null,dec:null}}};switch(t[0]){case"02":n=this.#B(t,n,e);break;case"06":n=this.#W(t,n);break;case"15":n.name="Checksum error",n.description="The calculated checksum does not match the received checksum",n.no_code=38,this.#e();break;default:n.name="unknown",n.description="The message received is unknown",n.no_code=404;break}this.dispatch("serial:message",n)}productRemovedContinueDispensing(){this.__internal__.dispense.elevator.locking_interval&&(this.__internal__.dispense.elevator.locking_time=0)}async dispense({selection:t=1,cart:e=!1}={}){const n=i.o.dispense({selection:t,cart:e,machineChannel:this.listenOnChannel}),r=n[5],a=n[6];this.__internal__.dispense.backup_dispense={selection:t,cart:e,channel:a,tray:r};let o;do o=await this.internalDispense(n),this.#q(),o.error==="elevator-locked"?await this.#s():o.error==="no-response"&&await h.wait(1e3);while(["elevator-locked","no-response"].includes(o.error||""));return this.__internal__.dispense.backup_dispense={},o}#q(){this.__internal__.dispense.timeout&&clearTimeout(this.__internal__.dispense.timeout),this.__internal__.dispense.interval&&clearInterval(this.__internal__.dispense.interval),this.__internal__.dispense.timeout=0,this.__internal__.dispense.interval=0}#F(){this.__internal__.dispense.timeout&&clearTimeout(this.__internal__.dispense.timeout),this.__internal__.dispense.interval&&clearInterval(this.__internal__.dispense.interval),this.__internal__.dispense.timeout=setTimeout(()=>{this.__internal__.dispense.interval=setInterval(()=>{this.status().then(()=>{})},this.__internal__.dispense.interval_time)},this.__internal__.dispense.timeout_time)}internalClearSensing(){super.internalClearSensing(),this.__internal__.dispense.timeout&&clearTimeout(this.__internal__.dispense.timeout),this.__internal__.dispense.interval&&clearInterval(this.__internal__.dispense.interval),this.__internal__.serial.queue.length>0&&(this.__internal__.serial.queue=this.__internal__.serial.queue.filter(t=>t.action!=="status"))}async endDispense(){const t=i.o.endCartDispense({machineChannel:this.listenOnChannel});return await this.internalDispense(t)}async collect(){return await this.appendToQueue(i.o.collect({machineChannel:this.listenOnChannel}),"collect")}async#r(t){return await this.appendToQueue(i.o.reset({machineChannel:this.listenOnChannel,type:t}),"reset")}async resetSoldOutErrors(){return await this.#r("soldOut")}async resetWaitingProductRemovedError(){return await this.#r("waiting")}async resetMachineErrors(){return this.__internal__.serial.queue.length===0?(this.#o(),await this.#r("machine")):new Promise(t=>{const e=setInterval(async()=>{this.__internal__.serial.queue.length>0||(clearInterval(e),await this.#r("machine"),this.#o(),t(!0))},100)})}#o(){const t=this.__device.type==="iceplus"?h.getSeconds(40):h.getSeconds(25),e=new Date().getTime(),n=new Date(e),r=1e3*t+e,a=new Date(r);this.dispatch("reset:errors",{description:"Resetting machine errors",duration:t,started_at:n,finished_at:a})}async resetAllErrors(){return await this.resetWaitingProductRemovedError(),await h.wait(200),await this.resetSoldOutErrors(),await h.wait(400),await this.resetMachineErrors()}async status(){return await this.appendToQueue(i.o.status({machineChannel:this.listenOnChannel}),"status")}async#c(t){return await this.appendToQueue(i.o.lights({machineChannel:this.listenOnChannel,type:t}),"lights")}async lightsOn(){return await this.#c("on")}async lightsOff(){return await this.#c("off")}async program(t,e){return await this.appendToQueue(i.o.program({machineChannel:this.listenOnChannel,param1:t,param2:e}),"program")}async programDisplayLanguage({language:t="spanish"}={}){return await this.appendToQueue(i.o.programDisplayLanguage({machineChannel:this.listenOnChannel,language:t}),"program")}async programBeeper({enable:t=!0}={}){return await this.appendToQueue(i.o.programBeeper({machineChannel:this.listenOnChannel,enable:t}),"program")}async programDisableWorkingTemperature(){if(this.__device.type==="iceplus")throw new Error("IcePlus does not support disable working temperature");return await this.appendToQueue(i.o.programDisableWorkingTemperature({machineChannel:this.listenOnChannel}),"program")}async programDisableThermometer(){return await this.appendToQueue(i.o.programDisableThermometer({machineChannel:this.listenOnChannel}),"program")}async programWorkingTemperature({degrees:t=.5}={}){return await this.appendToQueue(i.o.programWorkingTemperature({machineChannel:this.listenOnChannel,degrees:t,machineType:this.__device.type}),"program")}async programIsolationTray({tray:t=0}={}){return await this.appendToQueue(i.o.programIsolationTray({machineChannel:this.listenOnChannel,tray:t}),"program")}async programTimeToStandbyAfterCollect({seconds:t=15}={}){return await this.appendToQueue(i.o.programTimeToStandbyAfterCollect({machineChannel:this.listenOnChannel,seconds:t}),"program")}async programTimeToStandbyWithoutCollect({minutes:t=1}={}){return await this.appendToQueue(i.o.programTimeToStandbyWithoutCollect({machineChannel:this.listenOnChannel,minutes:t}),"program")}async programElevatorSpeed({speed:t="high"}={}){return await this.appendToQueue(i.o.programElevatorSpeed({machineChannel:this.listenOnChannel,speed:t}),"program")}async programTemperatureExpiration({enable:t=!1}={}){return await this.appendToQueue(i.o.programTemperatureExpiration({machineChannel:this.listenOnChannel,enable:t}),"program")}async programEnableTemperatureExpiration(){return await this.programTemperatureExpiration({enable:!0})}async programDisableTemperatureExpiration(){return await this.programTemperatureExpiration({enable:!1})}async programMachineAddress({address:t=1}={}){return await this.appendToQueue(i.o.programMachineAddress({machineChannel:this.listenOnChannel,address:t}),"program")}async programTemperatureBeforeExpiration({degrees:t=.5}={}){return await this.appendToQueue(i.o.programTemperatureBeforeExpiration({machineChannel:this.listenOnChannel,degrees:t}),"program")}async programTimeBeforeExpirationByTemperature({minutes:t=1}={}){return await this.appendToQueue(i.o.programTimeBeforeExpirationByTemperature({machineChannel:this.listenOnChannel,minutes:t}),"program")}async programTemperatureScale({scale:t="celsius"}={}){return await this.appendToQueue(i.o.programTemperatureScale({machineChannel:this.listenOnChannel,scale:t}),"program")}async programVoltageEngine({selection:t=1,voltage:e=5}={}){return await this.appendToQueue(i.o.programVoltageEngine({machineChannel:this.listenOnChannel,selection:t,voltage:e}),"voltage-engine")}async programPushOverProducts({selection:t=1,enable:e=!0}={}){return await this.appendToQueue(i.o.programPushOverProducts({machineChannel:this.listenOnChannel,selection:t,enable:e}),"push-over-products")}async programChannelRunningAfterDispense({selection:t=1,seconds:e=0}={}){return await this.appendToQueue(i.o.programChannelRunningAfterDispense({machineChannel:this.listenOnChannel,selection:t,seconds:e}),"channel-running-after-dispense")}async checkData(t,e=255){return await this.appendToQueue(i.o.checkData({machineChannel:this.listenOnChannel,type:t,aux:e}),"check-data")}async getDisplayLanguage(){return await this.appendToQueue(i.o.getDisplayLanguage({machineChannel:this.listenOnChannel}),"check-data")}async getBeeper(){return await this.appendToQueue(i.o.getBeeper({machineChannel:this.listenOnChannel}),"check-data")}async getWorkingTemperature(){return await this.appendToQueue(i.o.getWorkingTemperature({machineChannel:this.listenOnChannel}),"check-data")}async getIsolationTray(){return await this.appendToQueue(i.o.getIsolationTray({machineChannel:this.listenOnChannel}),"check-data")}async getProgramVersion(){return await this.appendToQueue(i.o.getProgramVersion({machineChannel:this.listenOnChannel}),"check-data")}async getFaults(){return await this.appendToQueue(i.o.getFaults({machineChannel:this.listenOnChannel}),"check-data")}async getMachineId(){return await this.appendToQueue(i.o.getMachineId({machineChannel:this.listenOnChannel}),"check-data")}async getCurrentTemperature(){return await this.appendToQueue(i.o.getCurrentTemperature({machineChannel:this.listenOnChannel}),"check-data")}async getTimeToStandbyAfterCollect(){return await this.appendToQueue(i.o.getTimeToStandbyAfterCollect({machineChannel:this.listenOnChannel}),"check-data")}async getTimeToStandbyWithoutCollect(){return await this.appendToQueue(i.o.getTimeToStandbyWithoutCollect({machineChannel:this.listenOnChannel}),"check-data")}async getElevatorSpeed(){return await this.appendToQueue(i.o.getElevatorSpeed({machineChannel:this.listenOnChannel}),"check-data")}async getTemperatureExpiration(){return await this.appendToQueue(i.o.getTemperatureExpiration({machineChannel:this.listenOnChannel}),"check-data")}async getTemperatureBeforeExpiration(){return await this.appendToQueue(i.o.getTemperatureBeforeExpiration({machineChannel:this.listenOnChannel}),"check-data")}async getTimeBeforeExpirationByTemperature(){return await this.appendToQueue(i.o.getTimeBeforeExpirationByTemperature({machineChannel:this.listenOnChannel}),"check-data")}async getTemperatureScale(){return await this.appendToQueue(i.o.getTemperatureScale({machineChannel:this.listenOnChannel}),"check-data")}async getClockRegisters(){return await this.appendToQueue(i.o.getClockRegisters({machineChannel:this.listenOnChannel}),"check-data")}async getMachineActivity(){return await this.appendToQueue(i.o.getMachineActivity({machineChannel:this.listenOnChannel}),"check-data")}async getVoltageEngine({selection:t=1}={}){return await this.appendToQueue(i.o.getVoltageEngine({machineChannel:this.listenOnChannel,selection:t}),"check-data")}async getChannelPresence({selection:t=1}={}){return await this.appendToQueue(i.o.getChannelPresence({machineChannel:this.listenOnChannel,selection:t}),"check-data")}async getPushOverProducts({selection:t=1}={}){return await this.appendToQueue(i.o.getPushOverProducts({machineChannel:this.listenOnChannel,selection:t}),"check-data")}async getChannelRunningAfterDispense({selection:t=1}={}){return await this.appendToQueue(i.o.getChannelRunningAfterDispense({machineChannel:this.listenOnChannel,selection:t}),"check-data")}async setDisplayStandbyMessage({message:t=""}={}){return await this.appendToQueue(i.o.setDisplayStandbyMessage({machineChannel:this.listenOnChannel,message:t}),"display")}async setDisplayMessageTemporarily({message:t="",seconds:e=1}){return this.appendToQueue(i.o.setDisplayMessageTemporarily({machineChannel:this.listenOnChannel,message:t,seconds:e}),"display")}async setDisplayMessageUnlimited({message:t=""}){return await this.appendToQueue(i.o.setDisplayMessageUnlimited({machineChannel:this.listenOnChannel,message:t}),"display")}async programClock({date:t=new Date}={}){return await this.appendToQueue(i.o.programClock({machineChannel:this.listenOnChannel,date:t}),"clock")}async eventsConfig({event:t=null,enable:e=!0}={}){return await this.appendToQueue(i.o.eventsConfig({machineChannel:this.listenOnChannel,event:t,enable:e}),"events-config")}async eventEnable({event:t=null}={}){return await this.appendToQueue(i.o.eventEnable({machineChannel:this.listenOnChannel,event:t}),"events-config")}async eventDisable({event:t=null}={}){return await this.appendToQueue(i.o.eventEnable({machineChannel:this.listenOnChannel,event:t}),"events-config")}async sendCustomCode({code:t=[]}={code:[]}){return await this.appendToQueue(i.o.sendCustomCode({code:t}),"custom")}async assignChannels(){const t=this.__device.channels.verification.start,e=this.__device.channels.verification.end;if(t>e)throw new Error("Invalid range, start must be less than end");this.__device.channels.verification.clear(),this.__device.channels.verification.running=!0;for(let n=t;n<=e;n++)this.__device.channels.verification.current=n,await this.getChannelPresence({selection:n});return new Promise(n=>{const r=setInterval(()=>{this.__device.channels.verification.channels.length===e-t+1?(clearInterval(r),this.dispatch("channels",{channels:this.__device.channels.verification.channels}),this.__device.channels.verification.clear(),n(!0)):this.dispatch("channels:progress",{current:this.__device.channels.verification.channels.length+this.__device.channels.verification.start-1,start:this.__device.channels.verification.start,end:this.__device.channels.verification.end,total:e-t+1,verified:this.__device.channels.verification.channels.length,percentage:Math.min(100,Math.round(this.__device.channels.verification.channels.length/(e-t+1)*100))})},500)})}}exports.Jofemar=y;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./kernel-As0xv_MS.cjs"),f=require("./devices-BndwHuvP.cjs"),i=require("./relay-E3NCcSjS.cjs");class y extends l.Kernel{__device={type:"esplus",support_cart:!1,withdraw:{in_process:!1,seconds:60,interval:0},cart:{in_process:!1},channels:{verification:{clear(){this.running=!1,this.current=1,this.channels=[]},running:!1,start:1,end:80,current:1,channels:[]}}};constructor({filters:t=null,config_port:e,no_device:n=1,device_listen_on_channel:r=1,type:a="esplus",support_cart:o=!0,socket:c=!1}={}){if(super({filters:t,config_port:e,no_device:n,device_listen_on_channel:r,socket:c}),this.__internal__.device.type="jofemar",f.Devices.getCustom(this.typeDevice,n))throw new Error(`Device ${this.typeDevice} ${n} already exists`);this.__internal__.dispense.must_response=!0,this.__internal__.time.response_general=800,this.__internal__.time.response_engines=800,this.__internal__.dispense.limit_counter=40,this.__internal__.dispense.timeout=0,this.__internal__.dispense.timeout_time=4e3,this.__internal__.dispense.interval=0,this.__internal__.dispense.interval_time=1e3,this.__internal__.device.hex_number=(128+this.listenOnChannel).toString(16),this.__internal__.device.door_open=!1,this.__internal__.dispense.elevator={locking_time:60,locking_interval:0,need_reset:!1},this.deviceType=a,this.supportCart=o,this.#l(),f.Devices.add(this),this.#s()}set startChannelVerification(t){const e=parseInt(t);if(isNaN(e))throw new Error("Invalid start channel verification, must be a number");if(e<1||e>126)throw new Error("Invalid start channel verification, valid range is 1 to 126");this.__device.channels.verification.start=e}set endChannelVerification(t){const e=parseInt(t);if(isNaN(e))throw new Error("Invalid end channel verification, must be a number");if(e<1||e>126)throw new Error("Invalid end channel verification, valid range is 1 to 126");this.__device.channels.verification.end=e}set listenOnChannel(t){if(t=parseInt(t),isNaN(t)||t<1||t>31)throw new Error("Invalid port number, valid range is 1 to 31");this.__internal__.device.listen_on_port=t,this.__internal__.serial.bytes_connection=this.serialSetConnectionConstant(t),this.__internal__.device.hex_number=(128+t).toString(16)}set listenOnPort(t){this.listenOnChannel=t}set deviceType(t){if(typeof t!="string")throw new Error("Invalid device type, must be a string");this.__device.type=t}set supportCart(t){if(typeof t!="boolean")throw new Error("Invalid support cart, must be a boolean");this.__device.support_cart=t}#l(){const t=["dispensing:withdrawal","command-executed","keyboard:pressed","door:event","program:version","machine:faults","clock:registers","machine:activity","check:language","check:beeper","check:isolation-tray","check:engine-voltage","check:push-over","check:extractor-after-dispense","check:standby-after-collect","check:standby-without-collect","check:elevator-speed","check:expiration-by-temperature","check:temperature-before-expiration","check:expiration-after","check:temperature-scale","check:machine-id","temperature:working","temperature:current","jofemar:warning","jofemar:error","serial:message","reset:errors","channels","channels:progress","channel:status","machine:status"];for(const e of t)this.serialRegisterAvailableListener(e)}#s(){this.on("internal:dispense:running",this.#F.bind(this))}serialSetConnectionConstant(t=1){return i.o.connection({channel:t})}async#d(){if(!this.__internal__.dispense.elevator.locking_interval)return this.__internal__.dispense.elevator.need_reset&&(this.__internal__.dispense.elevator.need_reset=!1,await this.resetWaitingProductRemovedError(),await l.wait(500)),this.__internal__.dispense.status="elevator-locked",this.__internal__.dispense.elevator.locking_time=60,new Promise(t=>{this.__internal__.dispense.elevator.locking_interval=setInterval(()=>{this.dispatch("dispensing:withdrawal",{elevator:!0,seconds:this.__internal__.dispense.elevator.locking_time,description:"Please recall products from the elevator"}),this.__internal__.dispense.elevator.locking_time-=1,this.__internal__.dispense.elevator.locking_time<=0&&(clearInterval(this.__internal__.dispense.elevator.locking_interval),this.__internal__.dispense.elevator.locking_interval=0,t(!0))},1e3)})}#p(t){return t.name="ok",t.description="The last command was executed successfully",t.no_code=1,this.dispatch("command-executed",t),t}#u(t,e){e.additional={hex:t,dec:this.hexToDec(t),ascii:null};const n={30:"0",31:"1",32:"2",33:"3",34:"4",35:"5",36:"6",37:"7",38:"8",39:"9","2a":"*",23:"#",41:"A",42:"B",43:"C",44:"D"},r=t.toString().toLowerCase();return e.additional.ascii=n[r]??null,e.name="Key pressed",e.description=`The key ${e.additional.ascii} was pressed`,e.no_code=2,this.dispatch("keyboard:pressed",e.additional),e}#o(t,e){return e.additional={open:!1},e.no_code=3,t==="4f"?(e.name="door open",e.description="The door was opened",e.additional.open=!0,this.__internal__.device.door_open=!0,this.dispatch("door:event",e.additional)):t==="43"?(e.name="door close",e.description="The door was closed",e.additional.open=!1,this.__internal__.device.door_open=!1,this.dispatch("door:event",e.additional)):(e.name="door event",e.description="The door event received is unknown",this.dispatch("door:event",{open:e.additional.open,message:e})),e}#_(t,e){e.no_code=404;let n=t[5]??null;if(n&&this.listenOnChannel>1&&(n=this.hexToDec(n)-this.listenOnChannel+1,n=this.decToHex(n)),!n)return e;if(n==="fd"?(e.no_code=4,e.name="channel disconnected",e.description="The channel is disconnected",e.additional={active:!1}):n==="fc"?(e.no_code=5,e.name="channel connected",e.description="The channel is connected",e.additional={active:!0}):(e.no_code=6,e.name="channel sold out",e.description="The channel is empty",e.additional={active:!0}),this.__device.channels.verification.running){const r=this.__device.channels.verification.channels.length+this.__device.channels.verification.start;this.__device.channels.verification.channels.push({selection:r,active:e.additional.active}),e.additional.selection=r}return this.dispatch("channel:status",e.additional),e}#f(t,e){e.no_code=39,e.name="Program version";const n=t.slice(4,12),r=n.map(a=>String.fromCharCode(this.hexToDec(a))).join("");return e.additional={version:r,hex:n},e.description=`The program version is ${r}`,this.dispatch("program:version",e.additional),e}#v(t,e){e.no_code=39,e.name="Machine faults",e.description="No faults detected",e.additional={no_faults:0,faults:[]};const n=t.slice(4,-3);if(n.length>1&&n[0]!=="30"){e.description="Machine has faults";const r={31:"Busy",32:"Invalid tray",33:"Invalid channel",34:"Empty channel",35:"Jam in elevator engine",36:"Malfunction in the elevator belt or product detector",37:"Failure in one of the photo transistors in the cabinet",38:"No channels detected",39:"Product detector fault",41:"Machine display is disconnected",42:"Product alarm under elevator",43:"Error when elevator approaching to a position",44:"Fault in keyboard",45:"Eeprom writing error",46:"Fault communicating with temperature control",47:"The thermometer is disconnected",48:"Thermometer programming lost",49:"Thermometer faulty","4a":"Channels power consumption detector faulty","4b":"Elevator does not find channel or tray","4c":"Elevator does not find delivery product position","4d":"Interior of elevator blocked","4e":"Error in tester of product detector","4f":"Waiting for product to be removed",50:"Product expired by temperature reasons",51:"Automatic door faulty",59:"Product is expired","5a":"Product is expired",61:"Product is expired",62:"Product is expired",63:"Product is expired",64:"Product detector didn't change during its verification test"};for(const a of n)r[a]&&e.additional.faults&&typeof e.additional.no_faults<"u"&&(e.additional.faults.push(r[a]||"Unknown fault"),e.additional.no_faults++)}return this.dispatch("machine:faults",e.additional),e}#y(t,e){e.no_code=40,e.name="Clock registers",e.description="Clock registers";const n=t.slice(4,-3),r=n.map(_=>String.fromCharCode(this.hexToDec(_))).join(""),[a,o]=r.split(" "),[c,h]=a.split(":"),[s,d,p]=o.split("-"),u=new Date(2e3+parseInt(p),parseInt(d)-1,parseInt(s),parseInt(c),parseInt(h));return e.additional={day:s,month:d,year:p,hours:c,minutes:h,formatted:r,date:u,hex:n},this.dispatch("clock:registers",e.additional),e}#C(t,e){e.no_code=41,e.name="Machine activity",e.description="Events from read machine activity";const n=String.fromCharCode(this.hexToDec(t[4])).toUpperCase();if(n!=="0"){const r=t.slice(5,-3);if(n==="T"&&r.length===4){const a=String.fromCharCode(this.hexToDec(r[0])),o=String.fromCharCode(this.hexToDec(r[1])),c=String.fromCharCode(this.hexToDec(r[3]));e.additional={ascii:n,type:"DU.d",dozens:a,units:o,decimals:c,time:parseFloat(`${a}${o}.${c}`),meaning:"Extraction time (in seconds)"}}else if(["B","D","E","F","G"].includes(n)&&r.length===3){const a=String.fromCharCode(this.hexToDec(r[0])),o=String.fromCharCode(this.hexToDec(r[1])),c=String.fromCharCode(this.hexToDec(r[2])),h=parseInt(`${a}${o}${c}`),s={B:"Error on going to tray channel",D:"Error on product detector",E:"Extraction of channel ok",F:"Error on engine intensity detection",G:"Error on product exit door"};e.additional={type:"HDU",hundreds:a,dozens:o,decimals:c,channel:h,selection:h-109,ascii:n,meaning:s[n]||"Unknown"}}else if(r.length===13){const a=r.map(v=>String.fromCharCode(this.hexToDec(v))).join(""),o=parseInt(a.slice(0,2)),c=parseInt(a.slice(2,4)),h=parseInt(a.slice(4,6)),s=parseInt(a.slice(7,9)),d=parseInt(a.slice(9,11))-1,p=2e3+parseInt(a.slice(11,13)),u=new Date(p,d,s,o,c,h),_={A:"Attempt to close product exit door",C:"Closing of exterior door",H:"Error on opening of product exit door",I:"New attempt to arrive at product exit position after an error on first attempt",J:"Power on cooling unit",K:"Power off cooling unit",L:"Start of defrosting",M:"End of defrosting",O:"Opening of exterior door",R:"Memory reset",S:"Error on going to product exit position",Y:"Power on machine",Z:"Power off machine",c:"Closing of inner door",e:"New attempt to extract from channel due no product detection when elevator arrived to product exit position",o:"Opening of inner door"};e.additional={type:"hhmmssWddMMAA",date:u,hex:r,formatted:u.toLocaleString(),ascii:n,meaning:_[n]||"Unknown"}}}return this.dispatch("machine:activity",e.additional),e}#T(t,e){const n={30:"Spanish",31:"English",32:"French"};return e.no_code=42,e.name="Language",e.description=`The language is ${n[t]||"unknown"}`,e.additional={hex:t,language:n[t]||"unknown"},this.dispatch("check:language",e.additional),e}#k(t,e){return e.no_code=43,e.name="Beeper",e.description=`The beeper is ${t==="30"?"on":"off"}`,e.additional={hex:t,beeper:t==="30"},this.dispatch("check:beeper",e.additional),e}#m(t,e){e.no_code=44,e.name="Isolation tray",e.description="Isolation tray";const n=this.hexToDec(t)-139;return e.additional={hex:t,tray:n},this.dispatch("check:isolation-tray",e.additional),e}#w(t,e){e.no_code=45,e.name="Engine voltage",e.description="Engine voltage";const n=(this.hexToDec(t)-128)/2+5;return e.additional={hex:t,voltage:n},this.dispatch("check:engine-voltage",e.additional),e}#b(t,e){e.no_code=46,e.name="Push over",e.description="Push over";const n=t==="30";return e.additional={hex:t,push:n},this.dispatch("check:push-over",e.additional),e}#x(t,e){e.no_code=47,e.name="Extractor after dispense",e.description="Extractor after dispense";const n=(this.hexToDec(t)-128)/10;return e.additional={hex:t,seconds:n},this.dispatch("check:extractor-after-dispense",e.additional),e}#E(t,e){e.no_code=48,e.name="Standby after collect",e.description="Time to standby after collect product";const n=this.hexToDec(t)-128;return e.additional={hex:t,seconds:n},this.dispatch("check:standby-after-collect",e.additional),e}#D(t,e){e.no_code=49,e.name="Standby without collect",e.description="Time to standby when product delivery is not collected";const n=this.hexToDec(t)-128;return e.additional={hex:t,minutes:n},this.dispatch("check:standby-without-collect",e.additional),e}#O(t,e){e.no_code=50,e.name="Elevator speed",e.description="Elevator speed";const n=t==="30"?"low":"high";return e.additional={hex:t,speed:n},this.dispatch("check:elevator-speed",e.additional),e}#M(t,e){e.no_code=51,e.name="Temperature expiration",e.description="Temperature expiration";const n=t==="31";return e.additional={hex:t,enabled:n},this.dispatch("check:expiration-by-temperature",e.additional),e}#S(t,e){e.no_code=52,e.name="Temperature before expiration",e.description="Temperature before expiration";const n=(this.hexToDec(t)-128)/2;return e.additional={hex:t,temperature:n},this.dispatch("check:temperature-before-expiration",e.additional),e}#I(t,e){e.no_code=53,e.name="Time before expiration",e.description="Time before expiration";const n=this.hexToDec(t)-128;return e.additional={hex:t,minutes:n},this.dispatch("check:expiration-after",e.additional),e}#P(t,e){e.no_code=54,e.name="Temperature scale",e.description="Temperature scale";const n=t==="43"?"Celsius":"Fahrenheit";return e.additional={hex:t,scale:n},this.dispatch("check:temperature-scale",e.additional),e}#Q(t,e){return e.no_code=54,e.name="Machine ID",e.description="Machine ID",e.additional={hex:t[4],full_hex:t},this.dispatch("check:machine-id",e.additional),e}#g(t,e){return e.no_code=7,e.name="working temperature",e.description=`The working temperature is ${t}`,e.additional={hex:t,temperature:{traditional:(this.hexToDec(t)-this.hexToDec("80"))/2,ice_plus:(this.hexToDec(t)-this.hexToDec("80"))/2-25.5}},this.dispatch("temperature:working",e.additional),e}#A(t,e){return e.no_code=8,e.name="current temperature",e.additional={sign:null,tens:null,units:null,decimals:null,type_degrees:null,formatted:null,decimal_point:t[7]==="2e"?".":null,degrees:t[9]==="7f"?"°":null,error:null},t[4]==="2b"?e.additional.sign=t[4]="+":["2e","2d"].includes(t[4])?e.additional.sign=t[4]="-":t[4]==="20"&&(e.additional.error="Error in thermometer"),this.hexToDec(t[5])>=48&&this.hexToDec(t[5])<=57?e.additional.tens=this.hexToDec(t[5])-48:t[5]==="2a"&&(e.additional.error="Error in thermometer"),this.hexToDec(t[6])>=48&&this.hexToDec(t[6])<=57?e.additional.units=this.hexToDec(t[6])-48:t[6]==="2a"&&(e.additional.error="Error in thermometer"),this.hexToDec(t[8])>=48&&this.hexToDec(t[8])<=57?e.additional.decimals=this.hexToDec(t[8])-48:t[8]==="2a"&&(e.additional.error="Error in thermometer"),t[10]==="43"?e.additional.type_degrees="C":t[10]==="46"&&(e.additional.type_degrees="F"),e.additional.error==="Error in thermometer"?(e.additional.formatted="Error in thermometer",e.description="The current temperature cannot be read because there is an error in the thermometer"):(e.additional.formatted=(e.additional.sign??"")+(e.additional.tens??"")+(e.additional.units??"")+(e.additional.decimal_point??"")+(e.additional.decimals??"")+(e.additional.degrees??"")+(e.additional.type_degrees??""),e.description=`The current temperature is ${e.additional.formatted}`),this.dispatch("temperature:current",e.additional),e}#B(t,e,n=128){if(t[1]&&(e.additional.machine||(e.additional.machine={hex:null,dec:null}),e.additional.machine.hex=t[1],e.additional.machine.dec=this.hexToDec(t[1])-n),!(t[1]&&t[2]))e=this.#p(e);else switch(t[2]){case"54":e.request="--automatic",e=this.#u(t[3],e);break;case"50":e.request="--automatic",e=this.#o(t[3],e);break;case"43":switch(e.request="check-data",t[3]){case"41":e=this.#C(t,e);break;case"43":e.request="channel-status",e=this.#_(t,e);break;case"50":e=this.#f(t,e);break;case"53":e=this.#v(t,e);break;case"54":e.request="working-temperature",e=this.#g(t[4],e);break;case"72":e=this.#y(t,e);break;case"74":e.request="current-temperature",e=this.#A(t,e);break;case"49":e=this.#T(t[4],e);break;case"5a":e=this.#k(t[4],e);break;case"42":e=this.#m(t[4],e);break;case"47":e=this.#w(t[4],e);break;case"4e":e=this.#Q(t,e);break;case"4f":e=this.#b(t[4],e);break;case"45":e=this.#x(t[4],e);break;case"46":e=this.#E(t[4],e);break;case"48":e=this.#D(t[4],e);break;case"76":e=this.#O(t[4],e);break;case"63":e=this.#M(t[4],e);break;case"65":e=this.#S(t[4],e);break;case"66":e=this.#I(t[4],e);break;case"67":e=this.#P(t[4],e);break}break}return e}#n(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status=!0)}#e(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status=!1)}#a(){this.__internal__.dispense.dispensing&&(this.__internal__.dispense.status="elevator-locked")}#t({type:t=null,severity:e="low"}={}){this.dispatch("jofemar:warning",{type:t,severity:e})}#i({type:t=null,severity:e="high"}={}){this.dispatch("jofemar:error",{type:t,severity:e})}#W(t,e){if(e.request="status",t[1]&&!t[2]){switch(t[1]){case"30":e.name="Machine ready",e.description="The machine is ready for instructions",e.no_code=9,this.#n();break;case"31":e.name="Machine busy",e.description="The machine is busy right now",e.no_code=10;break;case"32":e.name="Invalid tray",e.description="The tray requested is invalid",e.no_code=11,this.#e(),this.#t({type:"invalid-tray"});break;case"33":e.name="Invalid channel",e.description="The channel requested is invalid",e.no_code=12,this.#e(),this.#t({type:"invalid-channel"});break;case"34":e.name="Empty channel",e.description="The channel requested is empty",e.no_code=13,this.#e(),this.#t({type:"empty-channel"});break;case"35":e.name="Jam",e.description="Jam in elevator engine",e.no_code=14,this.#e(),this.#i({type:"jam"});break;case"36":e.name="Malfunction",e.description="Malfunction in the elevator belt or product detector",e.no_code=15,this.#e(),this.#i({type:"malfunction"});break;case"37":e.name="Photo transistors",e.description="Failure in one of the photo transistors in the cabinet",e.no_code=16,this.#e(),this.#i({type:"photo-transistors"});break;case"38":e.name="Without channels",e.description="No channels detected",e.no_code=17,this.#e(),this.#i({type:"without-channels"});break;case"39":e.name="Product detector fault",e.description="Product detector fault",e.no_code=18,this.#a(),this.#t({type:"fault-product-detector"});break;case"41":e.name="Fault in 485 BUS",e.description="Machine display is disconnected",e.no_code=19,this.#n(),this.#t({type:"display-disconnected"});break;case"42":e.name="Product under elevator",e.description="Product alarm under elevator",e.no_code=20,this.#e(),this.#t({type:"product-under-elevator"});break;case"43":e.name="Error when elevator approaching to a position",e.description="Error when elevator approaching to a position",e.no_code=21,this.#n(),this.#t({type:"error-approaching-position",severity:"high"});break;case"44":e.name="Fault in keyboard",e.description="Fault in keyboard",e.no_code=22,this.#e(),this.#i({type:"fault-keyboard"});break;case"45":e.name="Eeprom writing error",e.description="Eeprom writing error",e.no_code=23,this.#e(),this.#i({type:"eeprom-writing-error",severity:"critical"});break;case"46":e.name="Fault communicating with temperature control",e.description="Fault communicating with temperature control",e.no_code=24,this.#n(),this.#t({type:"fault-temperature-control"});break;case"47":e.name="Thermometer disconnected",e.description="The thermometer is disconnected",e.no_code=25,this.#n(),this.#t({type:"thermometer-disconnected"});break;case"48":e.name="Thermometer programming lost",e.description="Thermometer programming lost",e.no_code=26,this.#n(),this.#t({type:"thermometer-programming-lost"});break;case"49":e.name="Thermometer faulty",e.description="Thermometer faulty",e.no_code=27,this.#n(),this.#t({type:"thermometer-faulty"});break;case"4a":e.name="Channels power consumption detector faulty",e.description="Channels power consumption detector faulty",e.no_code=28,this.#e(),this.#i({type:"channels-power-consumption-detector-faulty",severity:"critical"});break;case"4b":e.name="Elevator does not find channel or tray",e.description="Elevator does not find channel or tray",e.no_code=29,this.#e(),this.#t({type:"elevator-not-find-channel-tray"});break;case"4c":e.name="Elevator does not find delivery product position",e.description="Elevator does not find delivery product position",e.no_code=30,this.#e(),this.#i({type:"elevator-not-find-delivery-position"});break;case"4d":e.name="Interior of elevator blocked",e.description="Interior of elevator blocked",e.no_code=31,this.#a(),this.__internal__.dispense.elevator.need_reset||(this.__internal__.dispense.elevator.need_reset=!0),this.#i({type:"interior-elevator-blocked",severity:"low"});break;case"4e":e.name="Error in tester of product detector",e.description="Error in tester of product detector",e.no_code=32,this.#e(),this.#i({type:"error-tester-product-detector"});break;case"4f":e.name="Waiting for product to be removed",e.description="Waiting for product to be removed",e.no_code=33,this.#a();break;case"50":e.name="Product expired by temperature reasons",e.description="Product expired by temperature reasons",e.no_code=34,this.#n(),this.#t({type:"product-expired-temperature"});break;case"51":e.name="Automatic door faulty",e.description="Automatic door faulty",e.no_code=35,this.#n(),this.#t({type:"automatic-door-faulty"});break;case"59":case"5a":case"61":case"62":case"63":switch(e.name="Product is expired",e.description="Product is expired",e.additional={nsf_alarm:1},t[1]){case"5a":e.additional.nsf_alarm=2;break;case"61":e.additional.nsf_alarm=3;break;case"62":e.additional.nsf_alarm=4;break;case"63":e.additional.nsf_alarm=5;break}e.no_code=36,this.#n(),this.#t({type:"product-expired"});break;case"64":e.name="Product detector didn't change during its verification test",e.description="Product detector didn't change during its verification test",e.no_code=37,this.#n(),this.#t({type:"automatic-door-faulty"});break}this.dispatch("machine:status",e)}else e.name="executed",e.description="The last command was executed successfully",e.no_code=8,!t[1]&&this.__internal__.dispense.dispensing&&this.#e();return e}serialMessage(t){t=this.fixHexArray(t);const e=128;let n={code:t,name:null,description:null,request:"unknown",no_code:0,additional:{machine:{hex:null,dec:null}}};switch(t[0]){case"02":n=this.#B(t,n,e);break;case"06":n=this.#W(t,n);break;case"15":n.name="Checksum error",n.description="The calculated checksum does not match the received checksum",n.no_code=38,this.#e();break;default:t.toString().includes("01,20,1e,02,18,1e,03,36,04")?(n.request="--automatic",n=this.#o("4f",n)):(n.name="unknown",n.description="The message received is unknown",n.no_code=404);break}this.dispatch("serial:message",n)}productRemovedContinueDispensing(){this.__internal__.dispense.elevator.locking_interval&&(this.__internal__.dispense.elevator.locking_time=0)}async dispense({selection:t=1,cart:e=!1}={}){const n=i.o.dispense({selection:t,cart:e,machineChannel:this.listenOnChannel}),r=n[5],a=n[6];this.__internal__.dispense.backup_dispense={selection:t,cart:e,channel:a,tray:r};let o;do o=await this.internalDispense(n),this.#q(),o.error==="elevator-locked"?await this.#d():o.error==="no-response"&&await l.wait(1e3);while(["elevator-locked","no-response"].includes(o.error||""));return this.__internal__.dispense.backup_dispense={},o}#q(){this.__internal__.dispense.timeout&&clearTimeout(this.__internal__.dispense.timeout),this.__internal__.dispense.interval&&clearInterval(this.__internal__.dispense.interval),this.__internal__.dispense.timeout=0,this.__internal__.dispense.interval=0}#F(){this.__internal__.dispense.timeout&&clearTimeout(this.__internal__.dispense.timeout),this.__internal__.dispense.interval&&clearInterval(this.__internal__.dispense.interval),this.__internal__.dispense.timeout=setTimeout(()=>{this.__internal__.dispense.interval=setInterval(()=>{this.status().then(()=>{})},this.__internal__.dispense.interval_time)},this.__internal__.dispense.timeout_time)}internalClearSensing(){super.internalClearSensing(),this.__internal__.dispense.timeout&&clearTimeout(this.__internal__.dispense.timeout),this.__internal__.dispense.interval&&clearInterval(this.__internal__.dispense.interval),this.__internal__.serial.queue.length>0&&(this.__internal__.serial.queue=this.__internal__.serial.queue.filter(t=>t.action!=="status"))}async endDispense(){const t=i.o.endCartDispense({machineChannel:this.listenOnChannel});return await this.internalDispense(t)}async collect(){return await this.appendToQueue(i.o.collect({machineChannel:this.listenOnChannel}),"collect")}async#r(t){return await this.appendToQueue(i.o.reset({machineChannel:this.listenOnChannel,type:t}),"reset")}async resetSoldOutErrors(){return await this.#r("soldOut")}async resetWaitingProductRemovedError(){return await this.#r("waiting")}async resetMachineErrors(){return this.__internal__.serial.queue.length===0?(this.#c(),await this.#r("machine")):new Promise(t=>{const e=setInterval(async()=>{this.__internal__.serial.queue.length>0||(clearInterval(e),await this.#r("machine"),this.#c(),t(!0))},100)})}#c(){const t=this.__device.type==="iceplus"?l.getSeconds(40):l.getSeconds(25),e=new Date().getTime(),n=new Date(e),r=1e3*t+e,a=new Date(r);this.dispatch("reset:errors",{description:"Resetting machine errors",duration:t,started_at:n,finished_at:a})}async resetAllErrors(){return await this.resetWaitingProductRemovedError(),await l.wait(200),await this.resetSoldOutErrors(),await l.wait(400),await this.resetMachineErrors()}async status(){return await this.appendToQueue(i.o.status({machineChannel:this.listenOnChannel}),"status")}async#h(t){return await this.appendToQueue(i.o.lights({machineChannel:this.listenOnChannel,type:t}),"lights")}async lightsOn(){return await this.#h("on")}async lightsOff(){return await this.#h("off")}async program(t,e){return await this.appendToQueue(i.o.program({machineChannel:this.listenOnChannel,param1:t,param2:e}),"program")}async programDisplayLanguage({language:t="spanish"}={}){return await this.appendToQueue(i.o.programDisplayLanguage({machineChannel:this.listenOnChannel,language:t}),"program")}async programBeeper({enable:t=!0}={}){return await this.appendToQueue(i.o.programBeeper({machineChannel:this.listenOnChannel,enable:t}),"program")}async programDisableWorkingTemperature(){if(this.__device.type==="iceplus")throw new Error("IcePlus does not support disable working temperature");return await this.appendToQueue(i.o.programDisableWorkingTemperature({machineChannel:this.listenOnChannel}),"program")}async programDisableThermometer(){return await this.appendToQueue(i.o.programDisableThermometer({machineChannel:this.listenOnChannel}),"program")}async programWorkingTemperature({degrees:t=.5}={}){return await this.appendToQueue(i.o.programWorkingTemperature({machineChannel:this.listenOnChannel,degrees:t,machineType:this.__device.type}),"program")}async programIsolationTray({tray:t=0}={}){return await this.appendToQueue(i.o.programIsolationTray({machineChannel:this.listenOnChannel,tray:t}),"program")}async programTimeToStandbyAfterCollect({seconds:t=15}={}){return await this.appendToQueue(i.o.programTimeToStandbyAfterCollect({machineChannel:this.listenOnChannel,seconds:t}),"program")}async programTimeToStandbyWithoutCollect({minutes:t=1}={}){return await this.appendToQueue(i.o.programTimeToStandbyWithoutCollect({machineChannel:this.listenOnChannel,minutes:t}),"program")}async programElevatorSpeed({speed:t="high"}={}){return await this.appendToQueue(i.o.programElevatorSpeed({machineChannel:this.listenOnChannel,speed:t}),"program")}async programTemperatureExpiration({enable:t=!1}={}){return await this.appendToQueue(i.o.programTemperatureExpiration({machineChannel:this.listenOnChannel,enable:t}),"program")}async programEnableTemperatureExpiration(){return await this.programTemperatureExpiration({enable:!0})}async programDisableTemperatureExpiration(){return await this.programTemperatureExpiration({enable:!1})}async programMachineAddress({address:t=1}={}){return await this.appendToQueue(i.o.programMachineAddress({machineChannel:this.listenOnChannel,address:t}),"program")}async programTemperatureBeforeExpiration({degrees:t=.5}={}){return await this.appendToQueue(i.o.programTemperatureBeforeExpiration({machineChannel:this.listenOnChannel,degrees:t}),"program")}async programTimeBeforeExpirationByTemperature({minutes:t=1}={}){return await this.appendToQueue(i.o.programTimeBeforeExpirationByTemperature({machineChannel:this.listenOnChannel,minutes:t}),"program")}async programTemperatureScale({scale:t="celsius"}={}){return await this.appendToQueue(i.o.programTemperatureScale({machineChannel:this.listenOnChannel,scale:t}),"program")}async programVoltageEngine({selection:t=1,voltage:e=5}={}){return await this.appendToQueue(i.o.programVoltageEngine({machineChannel:this.listenOnChannel,selection:t,voltage:e}),"voltage-engine")}async programPushOverProducts({selection:t=1,enable:e=!0}={}){return await this.appendToQueue(i.o.programPushOverProducts({machineChannel:this.listenOnChannel,selection:t,enable:e}),"push-over-products")}async programChannelRunningAfterDispense({selection:t=1,seconds:e=0}={}){return await this.appendToQueue(i.o.programChannelRunningAfterDispense({machineChannel:this.listenOnChannel,selection:t,seconds:e}),"channel-running-after-dispense")}async checkData(t,e=255){return await this.appendToQueue(i.o.checkData({machineChannel:this.listenOnChannel,type:t,aux:e}),"check-data")}async getDisplayLanguage(){return await this.appendToQueue(i.o.getDisplayLanguage({machineChannel:this.listenOnChannel}),"check-data")}async getBeeper(){return await this.appendToQueue(i.o.getBeeper({machineChannel:this.listenOnChannel}),"check-data")}async getWorkingTemperature(){return await this.appendToQueue(i.o.getWorkingTemperature({machineChannel:this.listenOnChannel}),"check-data")}async getIsolationTray(){return await this.appendToQueue(i.o.getIsolationTray({machineChannel:this.listenOnChannel}),"check-data")}async getProgramVersion(){return await this.appendToQueue(i.o.getProgramVersion({machineChannel:this.listenOnChannel}),"check-data")}async getFaults(){return await this.appendToQueue(i.o.getFaults({machineChannel:this.listenOnChannel}),"check-data")}async getMachineId(){return await this.appendToQueue(i.o.getMachineId({machineChannel:this.listenOnChannel}),"check-data")}async getCurrentTemperature(){return await this.appendToQueue(i.o.getCurrentTemperature({machineChannel:this.listenOnChannel}),"check-data")}async getTimeToStandbyAfterCollect(){return await this.appendToQueue(i.o.getTimeToStandbyAfterCollect({machineChannel:this.listenOnChannel}),"check-data")}async getTimeToStandbyWithoutCollect(){return await this.appendToQueue(i.o.getTimeToStandbyWithoutCollect({machineChannel:this.listenOnChannel}),"check-data")}async getElevatorSpeed(){return await this.appendToQueue(i.o.getElevatorSpeed({machineChannel:this.listenOnChannel}),"check-data")}async getTemperatureExpiration(){return await this.appendToQueue(i.o.getTemperatureExpiration({machineChannel:this.listenOnChannel}),"check-data")}async getTemperatureBeforeExpiration(){return await this.appendToQueue(i.o.getTemperatureBeforeExpiration({machineChannel:this.listenOnChannel}),"check-data")}async getTimeBeforeExpirationByTemperature(){return await this.appendToQueue(i.o.getTimeBeforeExpirationByTemperature({machineChannel:this.listenOnChannel}),"check-data")}async getTemperatureScale(){return await this.appendToQueue(i.o.getTemperatureScale({machineChannel:this.listenOnChannel}),"check-data")}async getClockRegisters(){return await this.appendToQueue(i.o.getClockRegisters({machineChannel:this.listenOnChannel}),"check-data")}async getMachineActivity(){return await this.appendToQueue(i.o.getMachineActivity({machineChannel:this.listenOnChannel}),"check-data")}async getVoltageEngine({selection:t=1}={}){return await this.appendToQueue(i.o.getVoltageEngine({machineChannel:this.listenOnChannel,selection:t}),"check-data")}async getChannelPresence({selection:t=1}={}){return await this.appendToQueue(i.o.getChannelPresence({machineChannel:this.listenOnChannel,selection:t}),"check-data")}async getPushOverProducts({selection:t=1}={}){return await this.appendToQueue(i.o.getPushOverProducts({machineChannel:this.listenOnChannel,selection:t}),"check-data")}async getChannelRunningAfterDispense({selection:t=1}={}){return await this.appendToQueue(i.o.getChannelRunningAfterDispense({machineChannel:this.listenOnChannel,selection:t}),"check-data")}async setDisplayStandbyMessage({message:t=""}={}){return await this.appendToQueue(i.o.setDisplayStandbyMessage({machineChannel:this.listenOnChannel,message:t}),"display")}async setDisplayMessageTemporarily({message:t="",seconds:e=1}){return this.appendToQueue(i.o.setDisplayMessageTemporarily({machineChannel:this.listenOnChannel,message:t,seconds:e}),"display")}async setDisplayMessageUnlimited({message:t=""}){return await this.appendToQueue(i.o.setDisplayMessageUnlimited({machineChannel:this.listenOnChannel,message:t}),"display")}async programClock({date:t=new Date}={}){return await this.appendToQueue(i.o.programClock({machineChannel:this.listenOnChannel,date:t}),"clock")}async eventsConfig({event:t=null,enable:e=!0}={}){return await this.appendToQueue(i.o.eventsConfig({machineChannel:this.listenOnChannel,event:t,enable:e}),"events-config")}async eventEnable({event:t=null}={}){return await this.appendToQueue(i.o.eventEnable({machineChannel:this.listenOnChannel,event:t}),"events-config")}async eventDisable({event:t=null}={}){return await this.appendToQueue(i.o.eventEnable({machineChannel:this.listenOnChannel,event:t}),"events-config")}async sendCustomCode({code:t=[]}={code:[]}){return await this.appendToQueue(i.o.sendCustomCode({code:t}),"custom")}async assignChannels(){const t=this.__device.channels.verification.start,e=this.__device.channels.verification.end;if(t>e)throw new Error("Invalid range, start must be less than end");this.__device.channels.verification.clear(),this.__device.channels.verification.running=!0;for(let n=t;n<=e;n++)this.__device.channels.verification.current=n,await this.getChannelPresence({selection:n});return new Promise(n=>{const r=setInterval(()=>{this.__device.channels.verification.channels.length===e-t+1?(clearInterval(r),this.dispatch("channels",{channels:this.__device.channels.verification.channels}),this.__device.channels.verification.clear(),n(!0)):this.dispatch("channels:progress",{current:this.__device.channels.verification.channels.length+this.__device.channels.verification.start-1,start:this.__device.channels.verification.start,end:this.__device.channels.verification.end,total:e-t+1,verified:this.__device.channels.verification.channels.length,percentage:Math.min(100,Math.round(this.__device.channels.verification.channels.length/(e-t+1)*100))})},500)})}}exports.Jofemar=y;