@willieee802/zigbee-herdsman 0.14.112 → 0.15.1

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 (348) hide show
  1. package/.release-please-manifest.json +4 -0
  2. package/CHANGELOG.md +27 -0
  3. package/dist/adapter/adapter.d.ts +61 -61
  4. package/dist/adapter/adapter.d.ts.map +1 -1
  5. package/dist/adapter/adapter.js +146 -100
  6. package/dist/adapter/adapter.js.map +1 -1
  7. package/dist/adapter/deconz/adapter/deconzAdapter.d.ts +68 -68
  8. package/dist/adapter/deconz/adapter/deconzAdapter.d.ts.map +1 -1
  9. package/dist/adapter/deconz/adapter/deconzAdapter.js +1060 -1063
  10. package/dist/adapter/deconz/adapter/deconzAdapter.js.map +1 -1
  11. package/dist/adapter/deconz/adapter/index.d.ts +2 -2
  12. package/dist/adapter/deconz/adapter/index.js +10 -10
  13. package/dist/adapter/deconz/driver/constants.d.ts +104 -104
  14. package/dist/adapter/deconz/driver/constants.js +55 -55
  15. package/dist/adapter/deconz/driver/driver.d.ts +81 -81
  16. package/dist/adapter/deconz/driver/driver.js +732 -732
  17. package/dist/adapter/deconz/driver/frame.d.ts +6 -6
  18. package/dist/adapter/deconz/driver/frame.js +13 -13
  19. package/dist/adapter/deconz/driver/frameParser.d.ts +2 -2
  20. package/dist/adapter/deconz/driver/frameParser.js +443 -443
  21. package/dist/adapter/deconz/driver/parser.d.ts +12 -12
  22. package/dist/adapter/deconz/driver/parser.js +61 -61
  23. package/dist/adapter/deconz/driver/writer.d.ts +8 -8
  24. package/dist/adapter/deconz/driver/writer.js +44 -44
  25. package/dist/adapter/events.d.ts +47 -47
  26. package/dist/adapter/events.js +14 -14
  27. package/dist/adapter/ezsp/adapter/backup.d.ts +9 -9
  28. package/dist/adapter/ezsp/adapter/backup.js +53 -53
  29. package/dist/adapter/ezsp/adapter/ezspAdapter.d.ts +59 -59
  30. package/dist/adapter/ezsp/adapter/ezspAdapter.js +585 -585
  31. package/dist/adapter/ezsp/adapter/index.d.ts +2 -2
  32. package/dist/adapter/ezsp/adapter/index.js +10 -10
  33. package/dist/adapter/ezsp/driver/commands.d.ts +36 -34
  34. package/dist/adapter/ezsp/driver/commands.d.ts.map +1 -1
  35. package/dist/adapter/ezsp/driver/commands.js +2359 -2357
  36. package/dist/adapter/ezsp/driver/commands.js.map +1 -1
  37. package/dist/adapter/ezsp/driver/consts.d.ts +10 -10
  38. package/dist/adapter/ezsp/driver/consts.js +13 -13
  39. package/dist/adapter/ezsp/driver/driver.d.ts +103 -103
  40. package/dist/adapter/ezsp/driver/driver.js +639 -639
  41. package/dist/adapter/ezsp/driver/driver.js.map +1 -1
  42. package/dist/adapter/ezsp/driver/ezsp.d.ts +96 -96
  43. package/dist/adapter/ezsp/driver/ezsp.d.ts.map +1 -1
  44. package/dist/adapter/ezsp/driver/ezsp.js +586 -577
  45. package/dist/adapter/ezsp/driver/ezsp.js.map +1 -1
  46. package/dist/adapter/ezsp/driver/index.d.ts +3 -3
  47. package/dist/adapter/ezsp/driver/index.js +8 -8
  48. package/dist/adapter/ezsp/driver/multicast.d.ts +12 -12
  49. package/dist/adapter/ezsp/driver/multicast.js +74 -74
  50. package/dist/adapter/ezsp/driver/parser.d.ts +12 -12
  51. package/dist/adapter/ezsp/driver/parser.js +111 -111
  52. package/dist/adapter/ezsp/driver/types/basic.d.ts +62 -62
  53. package/dist/adapter/ezsp/driver/types/basic.js +208 -208
  54. package/dist/adapter/ezsp/driver/types/basic.js.map +1 -1
  55. package/dist/adapter/ezsp/driver/types/index.d.ts +9 -9
  56. package/dist/adapter/ezsp/driver/types/index.js +133 -133
  57. package/dist/adapter/ezsp/driver/types/named.d.ts +697 -697
  58. package/dist/adapter/ezsp/driver/types/named.js +1726 -1726
  59. package/dist/adapter/ezsp/driver/types/named.js.map +1 -1
  60. package/dist/adapter/ezsp/driver/types/struct.d.ts +251 -251
  61. package/dist/adapter/ezsp/driver/types/struct.js +708 -708
  62. package/dist/adapter/ezsp/driver/types/struct.js.map +1 -1
  63. package/dist/adapter/ezsp/driver/uart.d.ts +44 -44
  64. package/dist/adapter/ezsp/driver/uart.d.ts.map +1 -1
  65. package/dist/adapter/ezsp/driver/uart.js +368 -366
  66. package/dist/adapter/ezsp/driver/uart.js.map +1 -1
  67. package/dist/adapter/ezsp/driver/utils/crc16ccitt.d.ts +2 -2
  68. package/dist/adapter/ezsp/driver/utils/crc16ccitt.js +55 -55
  69. package/dist/adapter/ezsp/driver/utils/index.d.ts +18 -18
  70. package/dist/adapter/ezsp/driver/utils/index.js +67 -67
  71. package/dist/adapter/ezsp/driver/writer.d.ts +13 -13
  72. package/dist/adapter/ezsp/driver/writer.js +88 -88
  73. package/dist/adapter/index.d.ts +4 -4
  74. package/dist/adapter/index.js +35 -35
  75. package/dist/adapter/serialPort.d.ts +8 -8
  76. package/dist/adapter/serialPort.js +22 -22
  77. package/dist/adapter/serialPort.js.map +1 -1
  78. package/dist/adapter/serialPortUtils.d.ts +12 -12
  79. package/dist/adapter/serialPortUtils.js +18 -18
  80. package/dist/adapter/socketPortUtils.d.ts +10 -10
  81. package/dist/adapter/socketPortUtils.js +16 -16
  82. package/dist/adapter/tstype.d.ts +85 -85
  83. package/dist/adapter/tstype.js +2 -2
  84. package/dist/adapter/z-stack/adapter/adapter-backup.d.ts +62 -62
  85. package/dist/adapter/z-stack/adapter/adapter-backup.js +441 -441
  86. package/dist/adapter/z-stack/adapter/adapter-nv-memory.d.ts +150 -150
  87. package/dist/adapter/z-stack/adapter/adapter-nv-memory.js +258 -258
  88. package/dist/adapter/z-stack/adapter/endpoints.d.ts +11 -11
  89. package/dist/adapter/z-stack/adapter/endpoints.js +73 -73
  90. package/dist/adapter/z-stack/adapter/index.d.ts +2 -2
  91. package/dist/adapter/z-stack/adapter/index.js +8 -8
  92. package/dist/adapter/z-stack/adapter/manager.d.ts +86 -86
  93. package/dist/adapter/z-stack/adapter/manager.js +476 -476
  94. package/dist/adapter/z-stack/adapter/tstype.d.ts +6 -6
  95. package/dist/adapter/z-stack/adapter/tstype.js +10 -10
  96. package/dist/adapter/z-stack/adapter/zStackAdapter.d.ts +81 -81
  97. package/dist/adapter/z-stack/adapter/zStackAdapter.js +868 -868
  98. package/dist/adapter/z-stack/constants/af.d.ts +23 -23
  99. package/dist/adapter/z-stack/constants/af.js +27 -27
  100. package/dist/adapter/z-stack/constants/common.d.ts +278 -278
  101. package/dist/adapter/z-stack/constants/common.js +289 -289
  102. package/dist/adapter/z-stack/constants/dbg.d.ts +22 -22
  103. package/dist/adapter/z-stack/constants/dbg.js +24 -24
  104. package/dist/adapter/z-stack/constants/index.d.ts +10 -10
  105. package/dist/adapter/z-stack/constants/index.js +47 -47
  106. package/dist/adapter/z-stack/constants/mac.d.ts +127 -127
  107. package/dist/adapter/z-stack/constants/mac.js +129 -129
  108. package/dist/adapter/z-stack/constants/sapi.d.ts +24 -24
  109. package/dist/adapter/z-stack/constants/sapi.js +26 -26
  110. package/dist/adapter/z-stack/constants/sys.d.ts +71 -71
  111. package/dist/adapter/z-stack/constants/sys.js +73 -73
  112. package/dist/adapter/z-stack/constants/util.d.ts +81 -81
  113. package/dist/adapter/z-stack/constants/util.js +83 -83
  114. package/dist/adapter/z-stack/constants/utils.d.ts +4 -4
  115. package/dist/adapter/z-stack/constants/utils.js +14 -14
  116. package/dist/adapter/z-stack/constants/zdo.d.ts +102 -102
  117. package/dist/adapter/z-stack/constants/zdo.js +104 -104
  118. package/dist/adapter/z-stack/models/index.d.ts +1 -1
  119. package/dist/adapter/z-stack/models/index.js +17 -17
  120. package/dist/adapter/z-stack/models/startup-options.d.ts +12 -12
  121. package/dist/adapter/z-stack/models/startup-options.js +2 -2
  122. package/dist/adapter/z-stack/structs/entries/address-manager-entry.d.ts +23 -23
  123. package/dist/adapter/z-stack/structs/entries/address-manager-entry.js +45 -45
  124. package/dist/adapter/z-stack/structs/entries/address-manager-table.d.ts +10 -10
  125. package/dist/adapter/z-stack/structs/entries/address-manager-table.js +22 -22
  126. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-entry.d.ts +10 -10
  127. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-entry.js +21 -21
  128. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-table.d.ts +10 -10
  129. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-table.js +23 -23
  130. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-entry.d.ts +10 -10
  131. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-entry.js +24 -24
  132. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-table.d.ts +10 -10
  133. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-table.js +23 -23
  134. package/dist/adapter/z-stack/structs/entries/channel-list.d.ts +8 -8
  135. package/dist/adapter/z-stack/structs/entries/channel-list.js +15 -15
  136. package/dist/adapter/z-stack/structs/entries/has-configured.d.ts +8 -8
  137. package/dist/adapter/z-stack/structs/entries/has-configured.js +16 -16
  138. package/dist/adapter/z-stack/structs/entries/index.d.ts +16 -16
  139. package/dist/adapter/z-stack/structs/entries/index.js +32 -32
  140. package/dist/adapter/z-stack/structs/entries/nib.d.ts +10 -10
  141. package/dist/adapter/z-stack/structs/entries/nib.js +68 -68
  142. package/dist/adapter/z-stack/structs/entries/nwk-key-descriptor.d.ts +10 -10
  143. package/dist/adapter/z-stack/structs/entries/nwk-key-descriptor.js +18 -18
  144. package/dist/adapter/z-stack/structs/entries/nwk-key.d.ts +8 -8
  145. package/dist/adapter/z-stack/structs/entries/nwk-key.js +15 -15
  146. package/dist/adapter/z-stack/structs/entries/nwk-pan-id.d.ts +8 -8
  147. package/dist/adapter/z-stack/structs/entries/nwk-pan-id.js +15 -15
  148. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.d.ts +13 -13
  149. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.js +23 -23
  150. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.d.ts +10 -10
  151. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.js +22 -22
  152. package/dist/adapter/z-stack/structs/entries/security-manager-entry.d.ts +20 -20
  153. package/dist/adapter/z-stack/structs/entries/security-manager-entry.js +36 -36
  154. package/dist/adapter/z-stack/structs/entries/security-manager-table.d.ts +10 -10
  155. package/dist/adapter/z-stack/structs/entries/security-manager-table.js +24 -24
  156. package/dist/adapter/z-stack/structs/index.d.ts +4 -4
  157. package/dist/adapter/z-stack/structs/index.js +20 -20
  158. package/dist/adapter/z-stack/structs/serializable-memory-object.d.ts +13 -13
  159. package/dist/adapter/z-stack/structs/serializable-memory-object.js +2 -2
  160. package/dist/adapter/z-stack/structs/struct.d.ts +99 -99
  161. package/dist/adapter/z-stack/structs/struct.js +295 -295
  162. package/dist/adapter/z-stack/structs/table.d.ts +94 -94
  163. package/dist/adapter/z-stack/structs/table.js +161 -161
  164. package/dist/adapter/z-stack/unpi/constants.d.ts +28 -28
  165. package/dist/adapter/z-stack/unpi/constants.js +41 -41
  166. package/dist/adapter/z-stack/unpi/frame.d.ts +16 -16
  167. package/dist/adapter/z-stack/unpi/frame.js +48 -48
  168. package/dist/adapter/z-stack/unpi/index.d.ts +5 -5
  169. package/dist/adapter/z-stack/unpi/index.js +37 -37
  170. package/dist/adapter/z-stack/unpi/parser.d.ts +10 -10
  171. package/dist/adapter/z-stack/unpi/parser.js +74 -74
  172. package/dist/adapter/z-stack/unpi/writer.d.ts +10 -10
  173. package/dist/adapter/z-stack/unpi/writer.js +44 -44
  174. package/dist/adapter/z-stack/utils/channel-list.d.ts +20 -20
  175. package/dist/adapter/z-stack/utils/channel-list.js +40 -40
  176. package/dist/adapter/z-stack/utils/index.d.ts +2 -2
  177. package/dist/adapter/z-stack/utils/index.js +18 -18
  178. package/dist/adapter/z-stack/utils/network-options.d.ts +8 -8
  179. package/dist/adapter/z-stack/utils/network-options.js +22 -22
  180. package/dist/adapter/z-stack/znp/buffaloZnp.d.ts +11 -11
  181. package/dist/adapter/z-stack/znp/buffaloZnp.js +113 -113
  182. package/dist/adapter/z-stack/znp/definition.d.ts +5 -5
  183. package/dist/adapter/z-stack/znp/definition.js +3050 -3050
  184. package/dist/adapter/z-stack/znp/index.d.ts +3 -3
  185. package/dist/adapter/z-stack/znp/index.js +10 -10
  186. package/dist/adapter/z-stack/znp/parameterType.d.ts +22 -22
  187. package/dist/adapter/z-stack/znp/parameterType.js +25 -25
  188. package/dist/adapter/z-stack/znp/tstype.d.ts +21 -21
  189. package/dist/adapter/z-stack/znp/tstype.js +2 -2
  190. package/dist/adapter/z-stack/znp/znp.d.ts +43 -43
  191. package/dist/adapter/z-stack/znp/znp.js +325 -325
  192. package/dist/adapter/z-stack/znp/zpiObject.d.ts +19 -19
  193. package/dist/adapter/z-stack/znp/zpiObject.js +96 -96
  194. package/dist/adapter/zigate/adapter/index.d.ts +2 -2
  195. package/dist/adapter/zigate/adapter/index.js +10 -10
  196. package/dist/adapter/zigate/adapter/zigateAdapter.d.ts +69 -69
  197. package/dist/adapter/zigate/adapter/zigateAdapter.js +678 -678
  198. package/dist/adapter/zigate/debug.d.ts +7 -7
  199. package/dist/adapter/zigate/debug.js +22 -22
  200. package/dist/adapter/zigate/driver/buffaloZiGate.d.ts +18 -18
  201. package/dist/adapter/zigate/driver/buffaloZiGate.js +139 -139
  202. package/dist/adapter/zigate/driver/commandType.d.ts +41 -41
  203. package/dist/adapter/zigate/driver/commandType.js +385 -385
  204. package/dist/adapter/zigate/driver/constants.d.ts +276 -276
  205. package/dist/adapter/zigate/driver/constants.js +371 -371
  206. package/dist/adapter/zigate/driver/frame.d.ts +26 -26
  207. package/dist/adapter/zigate/driver/frame.js +172 -172
  208. package/dist/adapter/zigate/driver/frame.js.map +1 -1
  209. package/dist/adapter/zigate/driver/messageType.d.ts +11 -11
  210. package/dist/adapter/zigate/driver/messageType.js +278 -278
  211. package/dist/adapter/zigate/driver/parameterType.d.ts +20 -20
  212. package/dist/adapter/zigate/driver/parameterType.js +23 -23
  213. package/dist/adapter/zigate/driver/ziGateObject.d.ts +23 -23
  214. package/dist/adapter/zigate/driver/ziGateObject.js +106 -106
  215. package/dist/adapter/zigate/driver/zigate.d.ts +49 -49
  216. package/dist/adapter/zigate/driver/zigate.js +303 -303
  217. package/dist/buffalo/buffalo.d.ts +50 -48
  218. package/dist/buffalo/buffalo.d.ts.map +1 -1
  219. package/dist/buffalo/buffalo.js +322 -307
  220. package/dist/buffalo/buffalo.js.map +1 -1
  221. package/dist/buffalo/index.d.ts +3 -3
  222. package/dist/buffalo/index.js +33 -33
  223. package/dist/buffalo/tstype.d.ts +8 -8
  224. package/dist/buffalo/tstype.js +2 -2
  225. package/dist/controller/controller.d.ts +110 -110
  226. package/dist/controller/controller.js +607 -607
  227. package/dist/controller/database.d.ts +18 -18
  228. package/dist/controller/database.js +93 -93
  229. package/dist/controller/events.d.ts +55 -55
  230. package/dist/controller/events.d.ts.map +1 -1
  231. package/dist/controller/events.js +101 -99
  232. package/dist/controller/events.js.map +1 -1
  233. package/dist/controller/greenPower.d.ts +12 -12
  234. package/dist/controller/greenPower.js +220 -220
  235. package/dist/controller/helpers/index.d.ts +2 -2
  236. package/dist/controller/helpers/index.js +28 -28
  237. package/dist/controller/helpers/request.d.ts +23 -0
  238. package/dist/controller/helpers/request.d.ts.map +1 -0
  239. package/dist/controller/helpers/request.js +72 -0
  240. package/dist/controller/helpers/request.js.map +1 -0
  241. package/dist/controller/helpers/zclFrameConverter.d.ts +7 -7
  242. package/dist/controller/helpers/zclFrameConverter.js +31 -31
  243. package/dist/controller/helpers/zclTransactionSequenceNumber.d.ts +5 -5
  244. package/dist/controller/helpers/zclTransactionSequenceNumber.js +13 -13
  245. package/dist/controller/index.d.ts +5 -5
  246. package/dist/controller/index.js +8 -8
  247. package/dist/controller/logger-stub.d.ts +6 -6
  248. package/dist/controller/logger-stub.js +2 -2
  249. package/dist/controller/model/device.d.ts +132 -127
  250. package/dist/controller/model/device.d.ts.map +1 -1
  251. package/dist/controller/model/device.js +708 -681
  252. package/dist/controller/model/device.js.map +1 -1
  253. package/dist/controller/model/endpoint.d.ts +131 -128
  254. package/dist/controller/model/endpoint.d.ts.map +1 -1
  255. package/dist/controller/model/endpoint.js +817 -665
  256. package/dist/controller/model/endpoint.js.map +1 -1
  257. package/dist/controller/model/entity.d.ts +14 -14
  258. package/dist/controller/model/entity.js +26 -26
  259. package/dist/controller/model/group.d.ts +39 -39
  260. package/dist/controller/model/group.js +221 -221
  261. package/dist/controller/model/index.d.ts +5 -5
  262. package/dist/controller/model/index.js +14 -14
  263. package/dist/controller/touchlink.d.ts +19 -19
  264. package/dist/controller/touchlink.js +157 -157
  265. package/dist/controller/tstype.d.ts +21 -20
  266. package/dist/controller/tstype.d.ts.map +1 -1
  267. package/dist/controller/tstype.js +9 -9
  268. package/dist/controller/tstype.js.map +1 -1
  269. package/dist/index.d.ts +3 -3
  270. package/dist/index.js +33 -33
  271. package/dist/models/backup-storage-legacy.d.ts +26 -26
  272. package/dist/models/backup-storage-legacy.js +2 -2
  273. package/dist/models/backup-storage-unified.d.ts +49 -49
  274. package/dist/models/backup-storage-unified.js +2 -2
  275. package/dist/models/backup.d.ts +37 -37
  276. package/dist/models/backup.js +2 -2
  277. package/dist/models/index.d.ts +4 -4
  278. package/dist/models/index.js +20 -20
  279. package/dist/models/network-options.d.ts +12 -12
  280. package/dist/models/network-options.js +2 -2
  281. package/dist/utils/assertString.d.ts +2 -2
  282. package/dist/utils/assertString.js +8 -8
  283. package/dist/utils/backup.d.ts +20 -20
  284. package/dist/utils/backup.js +187 -187
  285. package/dist/utils/equalsPartial.d.ts +2 -2
  286. package/dist/utils/equalsPartial.js +11 -11
  287. package/dist/utils/index.d.ts +9 -9
  288. package/dist/utils/index.js +45 -45
  289. package/dist/utils/isNumberArray.d.ts +2 -2
  290. package/dist/utils/isNumberArray.js +6 -6
  291. package/dist/utils/queue.d.ts +11 -11
  292. package/dist/utils/queue.js +50 -50
  293. package/dist/utils/realpathSync.d.ts +2 -2
  294. package/dist/utils/realpathSync.js +12 -12
  295. package/dist/utils/wait.d.ts +2 -2
  296. package/dist/utils/wait.js +8 -8
  297. package/dist/utils/waitress.d.ts +21 -21
  298. package/dist/utils/waitress.js +61 -61
  299. package/dist/zcl/buffaloZcl.d.ts +41 -41
  300. package/dist/zcl/buffaloZcl.js +591 -591
  301. package/dist/zcl/definition/buffaloZclDataType.d.ts +17 -17
  302. package/dist/zcl/definition/buffaloZclDataType.js +20 -20
  303. package/dist/zcl/definition/cluster.d.ts +29 -29
  304. package/dist/zcl/definition/cluster.d.ts.map +1 -1
  305. package/dist/zcl/definition/cluster.js +5335 -5215
  306. package/dist/zcl/definition/cluster.js.map +1 -1
  307. package/dist/zcl/definition/dataType.d.ts +59 -59
  308. package/dist/zcl/definition/dataType.d.ts.map +1 -1
  309. package/dist/zcl/definition/dataType.js +64 -64
  310. package/dist/zcl/definition/dataType.js.map +1 -1
  311. package/dist/zcl/definition/direction.d.ts +5 -5
  312. package/dist/zcl/definition/direction.js +8 -8
  313. package/dist/zcl/definition/endpointDeviceType.d.ts +4 -4
  314. package/dist/zcl/definition/endpointDeviceType.js +15 -15
  315. package/dist/zcl/definition/foundation.d.ts +11 -11
  316. package/dist/zcl/definition/foundation.js +167 -167
  317. package/dist/zcl/definition/frameControl.d.ts +10 -10
  318. package/dist/zcl/definition/frameControl.js +2 -2
  319. package/dist/zcl/definition/frameType.d.ts +5 -5
  320. package/dist/zcl/definition/frameType.js +8 -8
  321. package/dist/zcl/definition/index.d.ts +13 -13
  322. package/dist/zcl/definition/index.js +51 -51
  323. package/dist/zcl/definition/manufacturerCode.d.ts +1074 -1074
  324. package/dist/zcl/definition/manufacturerCode.js +1079 -1079
  325. package/dist/zcl/definition/powerSource.d.ts +4 -4
  326. package/dist/zcl/definition/powerSource.js +12 -12
  327. package/dist/zcl/definition/status.d.ts +38 -38
  328. package/dist/zcl/definition/status.js +41 -41
  329. package/dist/zcl/definition/tstype.d.ts +16 -16
  330. package/dist/zcl/definition/tstype.js +2 -2
  331. package/dist/zcl/index.d.ts +15 -15
  332. package/dist/zcl/index.js +55 -55
  333. package/dist/zcl/tstype.d.ts +56 -56
  334. package/dist/zcl/tstype.js +10 -10
  335. package/dist/zcl/utils.d.ts +6 -6
  336. package/dist/zcl/utils.js +165 -165
  337. package/dist/zcl/zclFrame.d.ts +45 -45
  338. package/dist/zcl/zclFrame.js +347 -347
  339. package/dist/zcl/zclStatusError.d.ts +5 -5
  340. package/dist/zcl/zclStatusError.js +13 -13
  341. package/package.json +6 -5
  342. package/release-please-config.json +13 -0
  343. package/.github/ISSUE_TEMPLATE/config.yml +0 -5
  344. package/.github/dependabot.yml +0 -6
  345. package/.github/workflows/ci.yml +0 -31
  346. package/.github/workflows/release.yml +0 -56
  347. package/.github/workflows/stale.yml +0 -19
  348. package/.github/workflows/update_deps.yml +0 -24
@@ -1,367 +1,369 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.SerialDriver = void 0;
30
- /* istanbul ignore file */
31
- const events_1 = require("events");
32
- const net_1 = __importDefault(require("net"));
33
- const serialPort_1 = require("../../serialPort");
34
- const socketPortUtils_1 = __importDefault(require("../../socketPortUtils"));
35
- const utils_1 = require("./utils");
36
- const utils_2 = require("../../../utils");
37
- const consts = __importStar(require("./consts"));
38
- const writer_1 = require("./writer");
39
- const parser_1 = require("./parser");
40
- const debug_1 = __importDefault(require("debug"));
41
- const debug = (0, debug_1.default)('zigbee-herdsman:adapter:ezsp:uart');
42
- var NcpResetCode;
43
- (function (NcpResetCode) {
44
- NcpResetCode[NcpResetCode["RESET_UNKNOWN_REASON"] = 0] = "RESET_UNKNOWN_REASON";
45
- NcpResetCode[NcpResetCode["RESET_EXTERNAL"] = 1] = "RESET_EXTERNAL";
46
- NcpResetCode[NcpResetCode["RESET_POWER_ON"] = 2] = "RESET_POWER_ON";
47
- NcpResetCode[NcpResetCode["RESET_WATCHDOG"] = 3] = "RESET_WATCHDOG";
48
- NcpResetCode[NcpResetCode["RESET_ASSERT"] = 6] = "RESET_ASSERT";
49
- NcpResetCode[NcpResetCode["RESET_BOOTLOADER"] = 9] = "RESET_BOOTLOADER";
50
- NcpResetCode[NcpResetCode["RESET_SOFTWARE"] = 11] = "RESET_SOFTWARE";
51
- NcpResetCode[NcpResetCode["ERROR_EXCEEDED_MAXIMUM_ACK_TIMEOUT_COUNT"] = 81] = "ERROR_EXCEEDED_MAXIMUM_ACK_TIMEOUT_COUNT";
52
- NcpResetCode[NcpResetCode["ERROR_UNKNOWN_EM3XX_ERROR"] = 128] = "ERROR_UNKNOWN_EM3XX_ERROR";
53
- })(NcpResetCode || (NcpResetCode = {}));
54
- class SerialDriver extends events_1.EventEmitter {
55
- constructor() {
56
- super();
57
- this.sendSeq = 0; // next frame number to send
58
- this.recvSeq = 0; // next frame number to receive
59
- this.ackSeq = 0; // next number after the last accepted frame
60
- this.initialized = false;
61
- this.queue = new utils_2.Queue(8);
62
- this.waitress = new utils_2.Waitress(this.waitressValidator, this.waitressTimeoutFormatter);
63
- }
64
- async connect(path, options) {
65
- this.portType = socketPortUtils_1.default.isTcpPath(path) ? 'socket' : 'serial';
66
- if (this.portType === 'serial') {
67
- await this.openSerialPort(path, options);
68
- }
69
- else {
70
- await this.openSocketPort(path);
71
- }
72
- }
73
- async openSerialPort(path, opt) {
74
- const options = {
75
- path,
76
- baudRate: typeof opt.baudRate === 'number' ? opt.baudRate : 115200,
77
- rtscts: typeof opt.rtscts === 'boolean' ? opt.rtscts : false,
78
- autoOpen: false
79
- };
80
- debug(`Opening SerialPort with ${JSON.stringify(options)}`);
81
- this.serialPort = new serialPort_1.SerialPort(options);
82
- this.writer = new writer_1.Writer();
83
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
84
- // @ts-ignore
85
- this.writer.pipe(this.serialPort);
86
- this.parser = new parser_1.Parser();
87
- this.serialPort.pipe(this.parser);
88
- this.parser.on('parsed', this.onParsed.bind(this));
89
- return new Promise((resolve, reject) => {
90
- this.serialPort.open(async (error) => {
91
- if (error) {
92
- this.initialized = false;
93
- if (this.serialPort.isOpen) {
94
- this.serialPort.close();
95
- }
96
- reject(new Error(`Error while opening serialport '${error}'`));
97
- }
98
- else {
99
- debug('Serialport opened');
100
- this.serialPort.once('close', this.onPortClose.bind(this));
101
- this.serialPort.once('error', (error) => {
102
- debug(`Serialport error: ${error}`);
103
- });
104
- // reset
105
- await this.reset();
106
- this.initialized = true;
107
- this.emit('connected');
108
- resolve();
109
- }
110
- });
111
- });
112
- }
113
- async openSocketPort(path) {
114
- const info = socketPortUtils_1.default.parseTcpPath(path);
115
- debug(`Opening TCP socket with ${info.host}:${info.port}`);
116
- this.socketPort = new net_1.default.Socket();
117
- this.socketPort.setNoDelay(true);
118
- this.socketPort.setKeepAlive(true, 15000);
119
- this.writer = new writer_1.Writer();
120
- this.writer.pipe(this.socketPort);
121
- this.parser = new parser_1.Parser();
122
- this.socketPort.pipe(this.parser);
123
- this.parser.on('parsed', this.onParsed.bind(this));
124
- return new Promise((resolve, reject) => {
125
- this.socketPort.on('connect', function () {
126
- debug('Socket connected');
127
- });
128
- // eslint-disable-next-line
129
- const self = this;
130
- this.socketPort.on('ready', async () => {
131
- debug('Socket ready');
132
- // reset
133
- await this.reset();
134
- self.initialized = true;
135
- this.emit('connected');
136
- resolve();
137
- });
138
- this.socketPort.once('close', this.onPortClose.bind(this));
139
- this.socketPort.on('error', function () {
140
- debug('Socket error');
141
- self.initialized = false;
142
- reject(new Error(`Error while opening socket`));
143
- });
144
- this.socketPort.connect(info.port, info.host);
145
- });
146
- }
147
- onParsed(data) {
148
- // check CRC
149
- const crc = (0, utils_1.crc16ccitt)(data.subarray(0, -3), 65535);
150
- const crcArr = Buffer.from([(crc >> 8), (crc % 256)]);
151
- if (!data.subarray(-3, -1).equals(crcArr)) {
152
- // CRC error
153
- debug(`<-- CRC error: ${data.toString('hex')}|` +
154
- `${data.subarray(-3, -1).toString('hex')}|` +
155
- `${crcArr.toString('hex')}`);
156
- // send NAK
157
- this.writer.sendNAK(this.recvSeq);
158
- // skip handler
159
- return;
160
- }
161
- try {
162
- /* Frame receive handler */
163
- switch (true) {
164
- case ((data[0] & 0x80) === 0):
165
- debug(`<-- DATA (${(data[0] & 0x70) >> 4},` +
166
- `${data[0] & 0x07},${(data[0] & 0x08) >> 3}): ${data.toString('hex')}`);
167
- this.handleDATA(data);
168
- break;
169
- case ((data[0] & 0xE0) === 0x80):
170
- debug(`<-- ACK (${data[0] & 0x07}): ${data.toString('hex')}`);
171
- this.handleACK(data[0]);
172
- break;
173
- case ((data[0] & 0xE0) === 0xA0):
174
- debug(`<-- NAK (${data[0] & 0x07}): ${data.toString('hex')}`);
175
- this.handleNAK(data[0]);
176
- break;
177
- case (data[0] === 0xC0):
178
- debug(`<-- RST: ${data.toString('hex')}`);
179
- break;
180
- case (data[0] === 0xC1):
181
- debug(`<-- RSTACK: ${data.toString('hex')}`);
182
- this.rstack_frame_received(data);
183
- break;
184
- case (data[0] === 0xC2):
185
- debug(`<-- Error: ${data.toString('hex')}`);
186
- // send reset
187
- this.reset();
188
- break;
189
- default:
190
- debug("UNKNOWN FRAME RECEIVED: %r", data);
191
- }
192
- }
193
- catch (error) {
194
- debug(`Error while parsing to ZpiObject '${error.stack}'`);
195
- }
196
- }
197
- handleDATA(data) {
198
- /* Data frame receive handler */
199
- const frmNum = (data[0] & 0x70) >> 4;
200
- const reTx = (data[0] & 0x08) >> 3;
201
- this.recvSeq = (frmNum + 1) & 7; // next
202
- debug(`--> ACK (${this.recvSeq})`);
203
- this.writer.sendACK(this.recvSeq);
204
- const handled = this.handleACK(data[0]);
205
- if (reTx && !handled) {
206
- // if the package is resent and did not expect it,
207
- // then will skip it - already processed it earlier
208
- debug(`Skipping the packet as repeated (${this.recvSeq})`);
209
- return;
210
- }
211
- data = data.subarray(1, -3);
212
- const frame = this.randomize(data);
213
- this.emit('received', frame);
214
- }
215
- handleACK(control) {
216
- /* Handle an acknowledgement frame */
217
- // next number after the last accepted frame
218
- this.ackSeq = control & 0x07;
219
- const handled = this.waitress.resolve({ sequence: this.ackSeq });
220
- if (!handled && this.sendSeq !== this.ackSeq) {
221
- debug(`Unexpected packet sequence ${this.ackSeq} | ${this.sendSeq}`);
222
- }
223
- return handled;
224
- }
225
- handleNAK(control) {
226
- /* Handle negative acknowledgment frame */
227
- const nakNum = control & 0x07;
228
- const handled = this.waitress.reject({ sequence: nakNum }, 'Recv NAK frame');
229
- if (!handled) {
230
- // send NAK
231
- debug(`NAK Unexpected packet sequence ${nakNum}`);
232
- }
233
- else {
234
- debug(`NAK Expected packet sequence ${nakNum}`);
235
- }
236
- }
237
- rstack_frame_received(data) {
238
- /* Reset acknowledgement frame receive handler */
239
- let code;
240
- this.sendSeq = 0;
241
- this.recvSeq = 0;
242
- try {
243
- code = NcpResetCode[data[2]];
244
- }
245
- catch (e) {
246
- code = NcpResetCode.ERROR_UNKNOWN_EM3XX_ERROR;
247
- }
248
- debug("RSTACK Version: %d Reason: %s frame: %s", data[1], code.toString(), data.toString('hex'));
249
- if (NcpResetCode[code].toString() !== NcpResetCode.RESET_SOFTWARE.toString()) {
250
- return;
251
- }
252
- this.waitress.resolve({ sequence: -1 });
253
- }
254
- randomize(s) {
255
- /*XOR s with a pseudo-random sequence for transmission
256
- Used only in data frames
257
- */
258
- let rand = consts.RANDOMIZE_START;
259
- const out = Buffer.alloc(s.length);
260
- let outIdx = 0;
261
- for (const c of s) {
262
- out.writeUInt8(c ^ rand, outIdx++);
263
- if ((rand % 2)) {
264
- rand = ((rand >> 1) ^ consts.RANDOMIZE_SEQ);
265
- }
266
- else {
267
- rand = (rand >> 1);
268
- }
269
- }
270
- return out;
271
- }
272
- async reset() {
273
- debug('Uart reseting');
274
- this.parser.reset();
275
- return this.queue.execute(async () => {
276
- debug(`--> Write reset`);
277
- const waiter = this.waitFor(-1, 10000).start();
278
- this.writer.sendReset();
279
- debug(`-?- waiting reset`);
280
- return waiter.promise.catch(async (e) => {
281
- debug(`--> Error: ${e}`);
282
- this.emit('reset');
283
- throw new Error(`Reset error: ${e}`);
284
- }).then(() => {
285
- debug(`-+- waiting reset success`);
286
- });
287
- });
288
- }
289
- close() {
290
- return new Promise((resolve, reject) => {
291
- if (this.initialized) {
292
- if (this.portType === 'serial') {
293
- this.serialPort.flush(() => {
294
- this.serialPort.close((error) => {
295
- this.initialized = false;
296
- error == null ?
297
- resolve() :
298
- reject(new Error(`Error while closing serialport '${error}'`));
299
- this.emit('close');
300
- });
301
- });
302
- }
303
- else {
304
- this.socketPort.destroy();
305
- resolve();
306
- }
307
- }
308
- else {
309
- resolve();
310
- this.emit('close');
311
- }
312
- });
313
- }
314
- onPortClose() {
315
- debug('Port closed');
316
- this.initialized = false;
317
- this.emit('close');
318
- }
319
- isInitialized() {
320
- return this.initialized;
321
- }
322
- async sendDATA(data) {
323
- const seq = this.sendSeq;
324
- this.sendSeq = ((seq + 1) % 8); // next
325
- const nextSeq = this.sendSeq;
326
- const ackSeq = this.recvSeq;
327
- return this.queue.execute(async () => {
328
- debug(`--> DATA (${seq},${ackSeq},0): ${data.toString('hex')}`);
329
- const randData = this.randomize(data);
330
- const waiter = this.waitFor(nextSeq).start();
331
- this.writer.sendData(randData, seq, 0, ackSeq);
332
- debug(`-?- waiting (${nextSeq})`);
333
- return waiter.promise.catch(async (e) => {
334
- debug(`--> Error: ${e}`);
335
- debug(`-!- break waiting (${nextSeq})`);
336
- debug(`Can't send DATA frame (${seq},${ackSeq},0): ${data.toString('hex')}`);
337
- await (0, utils_2.Wait)(500);
338
- debug(`->> DATA (${seq},${ackSeq},1): ${data.toString('hex')}`);
339
- const waiter = this.waitFor(nextSeq).start();
340
- this.writer.sendData(randData, seq, 1, ackSeq);
341
- debug(`-?- rewaiting (${nextSeq})`);
342
- return waiter.promise.catch(async (e) => {
343
- debug(`--> Error: ${e}`);
344
- debug(`-!- break rewaiting (${nextSeq})`);
345
- debug(`Can't resend DATA frame (${seq},${ackSeq},1): ${data.toString('hex')}`);
346
- this.emit('reset');
347
- throw new Error(`sendDATA error: ${e}`);
348
- }).then(() => {
349
- debug(`-+- rewaiting (${nextSeq}) success`);
350
- });
351
- }).then(() => {
352
- debug(`-+- waiting (${nextSeq}) success`);
353
- });
354
- });
355
- }
356
- waitFor(sequence, timeout = 2000) {
357
- return this.waitress.waitFor({ sequence }, timeout);
358
- }
359
- waitressTimeoutFormatter(matcher, timeout) {
360
- return `${JSON.stringify(matcher)} after ${timeout}ms`;
361
- }
362
- waitressValidator(payload, matcher) {
363
- return (payload.sequence === matcher.sequence);
364
- }
365
- }
366
- exports.SerialDriver = SerialDriver;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.SerialDriver = void 0;
30
+ /* istanbul ignore file */
31
+ const events_1 = require("events");
32
+ const net_1 = __importDefault(require("net"));
33
+ const serialPort_1 = require("../../serialPort");
34
+ const socketPortUtils_1 = __importDefault(require("../../socketPortUtils"));
35
+ const utils_1 = require("./utils");
36
+ const utils_2 = require("../../../utils");
37
+ const consts = __importStar(require("./consts"));
38
+ const writer_1 = require("./writer");
39
+ const parser_1 = require("./parser");
40
+ const debug_1 = __importDefault(require("debug"));
41
+ const debug = (0, debug_1.default)('zigbee-herdsman:adapter:ezsp:uart');
42
+ var NcpResetCode;
43
+ (function (NcpResetCode) {
44
+ NcpResetCode[NcpResetCode["RESET_UNKNOWN_REASON"] = 0] = "RESET_UNKNOWN_REASON";
45
+ NcpResetCode[NcpResetCode["RESET_EXTERNAL"] = 1] = "RESET_EXTERNAL";
46
+ NcpResetCode[NcpResetCode["RESET_POWER_ON"] = 2] = "RESET_POWER_ON";
47
+ NcpResetCode[NcpResetCode["RESET_WATCHDOG"] = 3] = "RESET_WATCHDOG";
48
+ NcpResetCode[NcpResetCode["RESET_ASSERT"] = 6] = "RESET_ASSERT";
49
+ NcpResetCode[NcpResetCode["RESET_BOOTLOADER"] = 9] = "RESET_BOOTLOADER";
50
+ NcpResetCode[NcpResetCode["RESET_SOFTWARE"] = 11] = "RESET_SOFTWARE";
51
+ NcpResetCode[NcpResetCode["ERROR_EXCEEDED_MAXIMUM_ACK_TIMEOUT_COUNT"] = 81] = "ERROR_EXCEEDED_MAXIMUM_ACK_TIMEOUT_COUNT";
52
+ NcpResetCode[NcpResetCode["ERROR_UNKNOWN_EM3XX_ERROR"] = 128] = "ERROR_UNKNOWN_EM3XX_ERROR";
53
+ })(NcpResetCode || (NcpResetCode = {}));
54
+ class SerialDriver extends events_1.EventEmitter {
55
+ constructor() {
56
+ super();
57
+ this.sendSeq = 0; // next frame number to send
58
+ this.recvSeq = 0; // next frame number to receive
59
+ this.ackSeq = 0; // next number after the last accepted frame
60
+ this.initialized = false;
61
+ this.queue = new utils_2.Queue(1);
62
+ this.waitress = new utils_2.Waitress(this.waitressValidator, this.waitressTimeoutFormatter);
63
+ }
64
+ async connect(path, options) {
65
+ this.portType = socketPortUtils_1.default.isTcpPath(path) ? 'socket' : 'serial';
66
+ if (this.portType === 'serial') {
67
+ await this.openSerialPort(path, options);
68
+ }
69
+ else {
70
+ await this.openSocketPort(path);
71
+ }
72
+ }
73
+ async openSerialPort(path, opt) {
74
+ const options = {
75
+ path,
76
+ baudRate: typeof opt.baudRate === 'number' ? opt.baudRate : 115200,
77
+ rtscts: typeof opt.rtscts === 'boolean' ? opt.rtscts : false,
78
+ autoOpen: false
79
+ };
80
+ debug(`Opening SerialPort with ${JSON.stringify(options)}`);
81
+ this.serialPort = new serialPort_1.SerialPort(options);
82
+ this.writer = new writer_1.Writer();
83
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
84
+ // @ts-ignore
85
+ this.writer.pipe(this.serialPort);
86
+ this.parser = new parser_1.Parser();
87
+ this.serialPort.pipe(this.parser);
88
+ this.parser.on('parsed', this.onParsed.bind(this));
89
+ return new Promise((resolve, reject) => {
90
+ this.serialPort.open(async (error) => {
91
+ if (error) {
92
+ this.initialized = false;
93
+ if (this.serialPort.isOpen) {
94
+ this.serialPort.close();
95
+ }
96
+ reject(new Error(`Error while opening serialport '${error}'`));
97
+ }
98
+ else {
99
+ debug('Serialport opened');
100
+ this.serialPort.once('close', this.onPortClose.bind(this));
101
+ this.serialPort.once('error', (error) => {
102
+ debug(`Serialport error: ${error}`);
103
+ });
104
+ // reset
105
+ await this.reset();
106
+ this.initialized = true;
107
+ this.emit('connected');
108
+ resolve();
109
+ }
110
+ });
111
+ });
112
+ }
113
+ async openSocketPort(path) {
114
+ const info = socketPortUtils_1.default.parseTcpPath(path);
115
+ debug(`Opening TCP socket with ${info.host}:${info.port}`);
116
+ this.socketPort = new net_1.default.Socket();
117
+ this.socketPort.setNoDelay(true);
118
+ this.socketPort.setKeepAlive(true, 15000);
119
+ this.writer = new writer_1.Writer();
120
+ this.writer.pipe(this.socketPort);
121
+ this.parser = new parser_1.Parser();
122
+ this.socketPort.pipe(this.parser);
123
+ this.parser.on('parsed', this.onParsed.bind(this));
124
+ return new Promise((resolve, reject) => {
125
+ this.socketPort.on('connect', function () {
126
+ debug('Socket connected');
127
+ });
128
+ // eslint-disable-next-line
129
+ const self = this;
130
+ this.socketPort.on('ready', async () => {
131
+ debug('Socket ready');
132
+ // reset
133
+ await this.reset();
134
+ self.initialized = true;
135
+ this.emit('connected');
136
+ resolve();
137
+ });
138
+ this.socketPort.once('close', this.onPortClose.bind(this));
139
+ this.socketPort.on('error', function () {
140
+ debug('Socket error');
141
+ self.initialized = false;
142
+ reject(new Error(`Error while opening socket`));
143
+ });
144
+ this.socketPort.connect(info.port, info.host);
145
+ });
146
+ }
147
+ onParsed(data) {
148
+ // check CRC
149
+ const crc = (0, utils_1.crc16ccitt)(data.subarray(0, -3), 65535);
150
+ const crcArr = Buffer.from([(crc >> 8), (crc % 256)]);
151
+ if (!data.subarray(-3, -1).equals(crcArr)) {
152
+ // CRC error
153
+ debug(`<-- CRC error: ${data.toString('hex')}|` +
154
+ `${data.subarray(-3, -1).toString('hex')}|` +
155
+ `${crcArr.toString('hex')}`);
156
+ // send NAK
157
+ this.writer.sendNAK(this.recvSeq);
158
+ // skip handler
159
+ return;
160
+ }
161
+ try {
162
+ /* Frame receive handler */
163
+ switch (true) {
164
+ case ((data[0] & 0x80) === 0):
165
+ debug(`<-- DATA (${(data[0] & 0x70) >> 4},` +
166
+ `${data[0] & 0x07},${(data[0] & 0x08) >> 3}): ${data.toString('hex')}`);
167
+ this.handleDATA(data);
168
+ break;
169
+ case ((data[0] & 0xE0) === 0x80):
170
+ debug(`<-- ACK (${data[0] & 0x07}): ${data.toString('hex')}`);
171
+ this.handleACK(data[0]);
172
+ break;
173
+ case ((data[0] & 0xE0) === 0xA0):
174
+ debug(`<-- NAK (${data[0] & 0x07}): ${data.toString('hex')}`);
175
+ this.handleNAK(data[0]);
176
+ break;
177
+ case (data[0] === 0xC0):
178
+ debug(`<-- RST: ${data.toString('hex')}`);
179
+ break;
180
+ case (data[0] === 0xC1):
181
+ debug(`<-- RSTACK: ${data.toString('hex')}`);
182
+ this.rstack_frame_received(data);
183
+ break;
184
+ case (data[0] === 0xC2):
185
+ debug(`<-- Error: ${data.toString('hex')}`);
186
+ // send reset
187
+ this.reset();
188
+ break;
189
+ default:
190
+ debug("UNKNOWN FRAME RECEIVED: %r", data);
191
+ }
192
+ }
193
+ catch (error) {
194
+ debug(`Error while parsing to ZpiObject '${error.stack}'`);
195
+ }
196
+ }
197
+ handleDATA(data) {
198
+ /* Data frame receive handler */
199
+ const frmNum = (data[0] & 0x70) >> 4;
200
+ const reTx = (data[0] & 0x08) >> 3;
201
+ this.recvSeq = (frmNum + 1) & 7; // next
202
+ debug(`--> ACK (${this.recvSeq})`);
203
+ this.writer.sendACK(this.recvSeq);
204
+ const handled = this.handleACK(data[0]);
205
+ if (reTx && !handled) {
206
+ // if the package is resent and did not expect it,
207
+ // then will skip it - already processed it earlier
208
+ debug(`Skipping the packet as repeated (${this.recvSeq})`);
209
+ return;
210
+ }
211
+ data = data.subarray(1, -3);
212
+ const frame = this.randomize(data);
213
+ this.emit('received', frame);
214
+ }
215
+ handleACK(control) {
216
+ /* Handle an acknowledgement frame */
217
+ // next number after the last accepted frame
218
+ this.ackSeq = control & 0x07;
219
+ const handled = this.waitress.resolve({ sequence: this.ackSeq });
220
+ if (!handled && this.sendSeq !== this.ackSeq) {
221
+ debug(`Unexpected packet sequence ${this.ackSeq} | ${this.sendSeq}`);
222
+ }
223
+ return handled;
224
+ }
225
+ handleNAK(control) {
226
+ /* Handle negative acknowledgment frame */
227
+ const nakNum = control & 0x07;
228
+ const handled = this.waitress.reject({ sequence: nakNum }, 'Recv NAK frame');
229
+ if (!handled) {
230
+ // send NAK
231
+ debug(`NAK Unexpected packet sequence ${nakNum}`);
232
+ }
233
+ else {
234
+ debug(`NAK Expected packet sequence ${nakNum}`);
235
+ }
236
+ }
237
+ rstack_frame_received(data) {
238
+ /* Reset acknowledgement frame receive handler */
239
+ let code;
240
+ this.sendSeq = 0;
241
+ this.recvSeq = 0;
242
+ try {
243
+ code = NcpResetCode[data[2]];
244
+ }
245
+ catch (e) {
246
+ code = NcpResetCode.ERROR_UNKNOWN_EM3XX_ERROR;
247
+ }
248
+ debug("RSTACK Version: %d Reason: %s frame: %s", data[1], code.toString(), data.toString('hex'));
249
+ if (NcpResetCode[code].toString() !== NcpResetCode.RESET_SOFTWARE.toString()) {
250
+ return;
251
+ }
252
+ this.waitress.resolve({ sequence: -1 });
253
+ }
254
+ randomize(s) {
255
+ /*XOR s with a pseudo-random sequence for transmission
256
+ Used only in data frames
257
+ */
258
+ let rand = consts.RANDOMIZE_START;
259
+ const out = Buffer.alloc(s.length);
260
+ let outIdx = 0;
261
+ for (const c of s) {
262
+ out.writeUInt8(c ^ rand, outIdx++);
263
+ if ((rand % 2)) {
264
+ rand = ((rand >> 1) ^ consts.RANDOMIZE_SEQ);
265
+ }
266
+ else {
267
+ rand = (rand >> 1);
268
+ }
269
+ }
270
+ return out;
271
+ }
272
+ async reset() {
273
+ debug('Uart reseting');
274
+ this.parser.reset();
275
+ this.queue.clear();
276
+ return this.queue.execute(async () => {
277
+ debug(`--> Write reset`);
278
+ const waiter = this.waitFor(-1, 10000).start();
279
+ this.writer.sendReset();
280
+ debug(`-?- waiting reset`);
281
+ return waiter.promise.catch(async (e) => {
282
+ debug(`--> Error: ${e}`);
283
+ this.emit('reset');
284
+ throw new Error(`Reset error: ${e}`);
285
+ }).then(() => {
286
+ debug(`-+- waiting reset success`);
287
+ });
288
+ });
289
+ }
290
+ close() {
291
+ return new Promise((resolve, reject) => {
292
+ this.queue.clear();
293
+ if (this.initialized) {
294
+ if (this.portType === 'serial') {
295
+ this.serialPort.flush(() => {
296
+ this.serialPort.close((error) => {
297
+ this.initialized = false;
298
+ this.emit('close');
299
+ error == null ?
300
+ resolve() :
301
+ reject(new Error(`Error while closing serialport '${error}'`));
302
+ });
303
+ });
304
+ }
305
+ else {
306
+ this.socketPort.destroy();
307
+ resolve();
308
+ }
309
+ }
310
+ else {
311
+ this.emit('close');
312
+ resolve();
313
+ }
314
+ });
315
+ }
316
+ onPortClose() {
317
+ debug('Port closed');
318
+ this.initialized = false;
319
+ this.emit('close');
320
+ }
321
+ isInitialized() {
322
+ return this.initialized;
323
+ }
324
+ async sendDATA(data) {
325
+ const seq = this.sendSeq;
326
+ this.sendSeq = ((seq + 1) % 8); // next
327
+ const nextSeq = this.sendSeq;
328
+ const ackSeq = this.recvSeq;
329
+ return this.queue.execute(async () => {
330
+ debug(`--> DATA (${seq},${ackSeq},0): ${data.toString('hex')}`);
331
+ const randData = this.randomize(data);
332
+ const waiter = this.waitFor(nextSeq).start();
333
+ this.writer.sendData(randData, seq, 0, ackSeq);
334
+ debug(`-?- waiting (${nextSeq})`);
335
+ return waiter.promise.catch(async (e) => {
336
+ debug(`--> Error: ${e}`);
337
+ debug(`-!- break waiting (${nextSeq})`);
338
+ debug(`Can't send DATA frame (${seq},${ackSeq},0): ${data.toString('hex')}`);
339
+ await (0, utils_2.Wait)(500);
340
+ debug(`->> DATA (${seq},${ackSeq},1): ${data.toString('hex')}`);
341
+ const waiter = this.waitFor(nextSeq).start();
342
+ this.writer.sendData(randData, seq, 1, ackSeq);
343
+ debug(`-?- rewaiting (${nextSeq})`);
344
+ return waiter.promise.catch(async (e) => {
345
+ debug(`--> Error: ${e}`);
346
+ debug(`-!- break rewaiting (${nextSeq})`);
347
+ debug(`Can't resend DATA frame (${seq},${ackSeq},1): ${data.toString('hex')}`);
348
+ this.emit('reset');
349
+ throw new Error(`sendDATA error: ${e}`);
350
+ }).then(() => {
351
+ debug(`-+- rewaiting (${nextSeq}) success`);
352
+ });
353
+ }).then(() => {
354
+ debug(`-+- waiting (${nextSeq}) success`);
355
+ });
356
+ });
357
+ }
358
+ waitFor(sequence, timeout = 2000) {
359
+ return this.waitress.waitFor({ sequence }, timeout);
360
+ }
361
+ waitressTimeoutFormatter(matcher, timeout) {
362
+ return `${JSON.stringify(matcher)} after ${timeout}ms`;
363
+ }
364
+ waitressValidator(payload, matcher) {
365
+ return (payload.sequence === matcher.sequence);
366
+ }
367
+ }
368
+ exports.SerialDriver = SerialDriver;
367
369
  //# sourceMappingURL=uart.js.map