@ovok/native 0.4.5 → 0.4.7

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 (380) hide show
  1. package/lib/commonjs/modules/bt-management/index.js +176 -0
  2. package/lib/commonjs/modules/bt-management/index.js.map +1 -1
  3. package/lib/commonjs/modules/bt-management/services/custom/compile-case-fields.js +49 -0
  4. package/lib/commonjs/modules/bt-management/services/custom/compile-case-fields.js.map +1 -0
  5. package/lib/commonjs/modules/bt-management/services/custom/compile-custom-case.js +47 -41
  6. package/lib/commonjs/modules/bt-management/services/custom/compile-custom-case.js.map +1 -1
  7. package/lib/commonjs/modules/bt-management/services/custom/compile-custom-frame.js +48 -2
  8. package/lib/commonjs/modules/bt-management/services/custom/compile-custom-frame.js.map +1 -1
  9. package/lib/commonjs/modules/bt-management/services/custom/compile-custom-lepu.js +98 -0
  10. package/lib/commonjs/modules/bt-management/services/custom/compile-custom-lepu.js.map +1 -0
  11. package/lib/commonjs/modules/bt-management/services/custom/define-custom-device.js +24 -1
  12. package/lib/commonjs/modules/bt-management/services/custom/define-custom-device.js.map +1 -1
  13. package/lib/commonjs/modules/bt-management/services/device-creator.js +15 -8
  14. package/lib/commonjs/modules/bt-management/services/device-creator.js.map +1 -1
  15. package/lib/commonjs/modules/bt-management/services/devices/aoj/aoj.thermometers.js +85 -0
  16. package/lib/commonjs/modules/bt-management/services/devices/aoj/aoj.thermometers.js.map +1 -0
  17. package/lib/commonjs/modules/bt-management/services/devices/bp2/bp2.frame-reader.js +8 -74
  18. package/lib/commonjs/modules/bt-management/services/devices/bp2/bp2.frame-reader.js.map +1 -1
  19. package/lib/commonjs/modules/bt-management/services/devices/bt-command-writer.js +141 -0
  20. package/lib/commonjs/modules/bt-management/services/devices/bt-command-writer.js.map +1 -0
  21. package/lib/commonjs/modules/bt-management/services/devices/bt-connection-handler.js +16 -50
  22. package/lib/commonjs/modules/bt-management/services/devices/bt-connection-handler.js.map +1 -1
  23. package/lib/commonjs/modules/bt-management/services/devices/bt-data-processor.js +17 -6
  24. package/lib/commonjs/modules/bt-management/services/devices/bt-data-processor.js.map +1 -1
  25. package/lib/commonjs/modules/bt-management/services/devices/bt-managed-device.js +21 -14
  26. package/lib/commonjs/modules/bt-management/services/devices/bt-managed-device.js.map +1 -1
  27. package/lib/commonjs/modules/bt-management/services/devices/custom/custom-lepu-sequencer.js +36 -0
  28. package/lib/commonjs/modules/bt-management/services/devices/custom/custom-lepu-sequencer.js.map +1 -0
  29. package/lib/commonjs/modules/bt-management/services/devices/custom/custom.device.js +81 -14
  30. package/lib/commonjs/modules/bt-management/services/devices/custom/custom.device.js.map +1 -1
  31. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.command-builder.js +48 -0
  32. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.command-builder.js.map +1 -0
  33. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.commands.js +37 -0
  34. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.commands.js.map +1 -0
  35. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.device-info.js +83 -0
  36. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.device-info.js.map +1 -0
  37. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.device-names.js +26 -0
  38. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.device-names.js.map +1 -0
  39. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.file-names.js +36 -0
  40. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.file-names.js.map +1 -0
  41. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.file-transfer.js +155 -0
  42. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.file-transfer.js.map +1 -0
  43. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.frame-reader.js +98 -0
  44. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.frame-reader.js.map +1 -0
  45. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.frame.js +29 -0
  46. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.frame.js.map +1 -0
  47. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.identity-gate.js +103 -0
  48. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.identity-gate.js.map +1 -0
  49. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.name-match.js +32 -0
  50. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.name-match.js.map +1 -0
  51. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.response-type.js +64 -0
  52. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.response-type.js.map +1 -0
  53. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.transports.js +143 -0
  54. package/lib/commonjs/modules/bt-management/services/devices/lepu/lepu.transports.js.map +1 -0
  55. package/lib/commonjs/modules/bt-management/services/devices/polling-command-sequencer.js +38 -0
  56. package/lib/commonjs/modules/bt-management/services/devices/polling-command-sequencer.js.map +1 -0
  57. package/lib/commonjs/modules/bt-management/services/devices/standard-gatt/standard-gatt.devices.js +156 -0
  58. package/lib/commonjs/modules/bt-management/services/devices/standard-gatt/standard-gatt.devices.js.map +1 -0
  59. package/lib/commonjs/modules/bt-management/services/devices/viatom/viatom.bp-monitors.js +124 -0
  60. package/lib/commonjs/modules/bt-management/services/devices/viatom/viatom.bp-monitors.js.map +1 -0
  61. package/lib/commonjs/modules/bt-management/services/devices/viatom/viatom.ecg-recorders.js +113 -0
  62. package/lib/commonjs/modules/bt-management/services/devices/viatom/viatom.ecg-recorders.js.map +1 -0
  63. package/lib/commonjs/modules/bt-management/services/devices/viatom/viatom.lepod.js +117 -0
  64. package/lib/commonjs/modules/bt-management/services/devices/viatom/viatom.lepod.js.map +1 -0
  65. package/lib/commonjs/modules/bt-management/services/devices/viatom/viatom.oximeters.js +82 -0
  66. package/lib/commonjs/modules/bt-management/services/devices/viatom/viatom.oximeters.js.map +1 -0
  67. package/lib/commonjs/modules/bt-management/types/command-sequencer.js +6 -0
  68. package/lib/commonjs/modules/bt-management/types/command-sequencer.js.map +1 -0
  69. package/lib/commonjs/modules/bt-management/types/custom-checksum-algorithm.js +2 -0
  70. package/lib/commonjs/modules/bt-management/types/custom-checksum-algorithm.js.map +1 -0
  71. package/lib/commonjs/modules/bt-management/types/custom-checksum-spec.js +6 -0
  72. package/lib/commonjs/modules/bt-management/types/custom-checksum-spec.js.map +1 -0
  73. package/lib/commonjs/modules/bt-management/types/custom-lepu-spec.js +2 -0
  74. package/lib/commonjs/modules/bt-management/types/custom-lepu-spec.js.map +1 -0
  75. package/lib/commonjs/modules/bt-management/types/custom-measurement-spec.js +6 -0
  76. package/lib/commonjs/modules/bt-management/types/custom-measurement-spec.js.map +1 -0
  77. package/lib/commonjs/modules/bt-management/types/device-command.js +2 -0
  78. package/lib/commonjs/modules/bt-management/types/device-command.js.map +1 -0
  79. package/lib/commonjs/modules/bt-management/types/measurement-group.js +6 -0
  80. package/lib/commonjs/modules/bt-management/types/measurement-group.js.map +1 -0
  81. package/lib/commonjs/modules/bt-management/utils/calculate-checksum.js +49 -0
  82. package/lib/commonjs/modules/bt-management/utils/calculate-checksum.js.map +1 -0
  83. package/lib/commonjs/modules/bt-management/utils/create-frame-validator.js +9 -0
  84. package/lib/commonjs/modules/bt-management/utils/create-frame-validator.js.map +1 -1
  85. package/lib/commonjs/modules/bt-management/utils/hex-to-bytes.js +19 -0
  86. package/lib/commonjs/modules/bt-management/utils/hex-to-bytes.js.map +1 -0
  87. package/lib/commonjs/modules/bt-management/utils/le-32-to-bytes.js +13 -0
  88. package/lib/commonjs/modules/bt-management/utils/le-32-to-bytes.js.map +1 -0
  89. package/lib/commonjs/modules/bt-management/utils/summarise-measurement-for-log.js +22 -0
  90. package/lib/commonjs/modules/bt-management/utils/summarise-measurement-for-log.js.map +1 -0
  91. package/lib/commonjs/modules/bt-management/utils/supported-measurement-type-keys.js +18 -0
  92. package/lib/commonjs/modules/bt-management/utils/supported-measurement-type-keys.js.map +1 -0
  93. package/lib/module/modules/bt-management/index.js +16 -0
  94. package/lib/module/modules/bt-management/index.js.map +1 -1
  95. package/lib/module/modules/bt-management/services/custom/compile-case-fields.js +44 -0
  96. package/lib/module/modules/bt-management/services/custom/compile-case-fields.js.map +1 -0
  97. package/lib/module/modules/bt-management/services/custom/compile-custom-case.js +47 -41
  98. package/lib/module/modules/bt-management/services/custom/compile-custom-case.js.map +1 -1
  99. package/lib/module/modules/bt-management/services/custom/compile-custom-frame.js +48 -2
  100. package/lib/module/modules/bt-management/services/custom/compile-custom-frame.js.map +1 -1
  101. package/lib/module/modules/bt-management/services/custom/compile-custom-lepu.js +93 -0
  102. package/lib/module/modules/bt-management/services/custom/compile-custom-lepu.js.map +1 -0
  103. package/lib/module/modules/bt-management/services/custom/define-custom-device.js +24 -1
  104. package/lib/module/modules/bt-management/services/custom/define-custom-device.js.map +1 -1
  105. package/lib/module/modules/bt-management/services/device-creator.js +16 -8
  106. package/lib/module/modules/bt-management/services/device-creator.js.map +1 -1
  107. package/lib/module/modules/bt-management/services/devices/aoj/aoj.thermometers.js +81 -0
  108. package/lib/module/modules/bt-management/services/devices/aoj/aoj.thermometers.js.map +1 -0
  109. package/lib/module/modules/bt-management/services/devices/bp2/bp2.frame-reader.js +8 -73
  110. package/lib/module/modules/bt-management/services/devices/bp2/bp2.frame-reader.js.map +1 -1
  111. package/lib/module/modules/bt-management/services/devices/bt-command-writer.js +136 -0
  112. package/lib/module/modules/bt-management/services/devices/bt-command-writer.js.map +1 -0
  113. package/lib/module/modules/bt-management/services/devices/bt-connection-handler.js +16 -50
  114. package/lib/module/modules/bt-management/services/devices/bt-connection-handler.js.map +1 -1
  115. package/lib/module/modules/bt-management/services/devices/bt-data-processor.js +17 -6
  116. package/lib/module/modules/bt-management/services/devices/bt-data-processor.js.map +1 -1
  117. package/lib/module/modules/bt-management/services/devices/bt-managed-device.js +21 -14
  118. package/lib/module/modules/bt-management/services/devices/bt-managed-device.js.map +1 -1
  119. package/lib/module/modules/bt-management/services/devices/custom/custom-lepu-sequencer.js +32 -0
  120. package/lib/module/modules/bt-management/services/devices/custom/custom-lepu-sequencer.js.map +1 -0
  121. package/lib/module/modules/bt-management/services/devices/custom/custom.device.js +81 -14
  122. package/lib/module/modules/bt-management/services/devices/custom/custom.device.js.map +1 -1
  123. package/lib/module/modules/bt-management/services/devices/lepu/lepu.command-builder.js +43 -0
  124. package/lib/module/modules/bt-management/services/devices/lepu/lepu.command-builder.js.map +1 -0
  125. package/lib/module/modules/bt-management/services/devices/lepu/lepu.commands.js +33 -0
  126. package/lib/module/modules/bt-management/services/devices/lepu/lepu.commands.js.map +1 -0
  127. package/lib/module/modules/bt-management/services/devices/lepu/lepu.device-info.js +79 -0
  128. package/lib/module/modules/bt-management/services/devices/lepu/lepu.device-info.js.map +1 -0
  129. package/lib/module/modules/bt-management/services/devices/lepu/lepu.device-names.js +22 -0
  130. package/lib/module/modules/bt-management/services/devices/lepu/lepu.device-names.js.map +1 -0
  131. package/lib/module/modules/bt-management/services/devices/lepu/lepu.file-names.js +32 -0
  132. package/lib/module/modules/bt-management/services/devices/lepu/lepu.file-names.js.map +1 -0
  133. package/lib/module/modules/bt-management/services/devices/lepu/lepu.file-transfer.js +150 -0
  134. package/lib/module/modules/bt-management/services/devices/lepu/lepu.file-transfer.js.map +1 -0
  135. package/lib/module/modules/bt-management/services/devices/lepu/lepu.frame-reader.js +93 -0
  136. package/lib/module/modules/bt-management/services/devices/lepu/lepu.frame-reader.js.map +1 -0
  137. package/lib/module/modules/bt-management/services/devices/lepu/lepu.frame.js +24 -0
  138. package/lib/module/modules/bt-management/services/devices/lepu/lepu.frame.js.map +1 -0
  139. package/lib/module/modules/bt-management/services/devices/lepu/lepu.identity-gate.js +98 -0
  140. package/lib/module/modules/bt-management/services/devices/lepu/lepu.identity-gate.js.map +1 -0
  141. package/lib/module/modules/bt-management/services/devices/lepu/lepu.name-match.js +27 -0
  142. package/lib/module/modules/bt-management/services/devices/lepu/lepu.name-match.js.map +1 -0
  143. package/lib/module/modules/bt-management/services/devices/lepu/lepu.response-type.js +59 -0
  144. package/lib/module/modules/bt-management/services/devices/lepu/lepu.response-type.js.map +1 -0
  145. package/lib/module/modules/bt-management/services/devices/lepu/lepu.transports.js +140 -0
  146. package/lib/module/modules/bt-management/services/devices/lepu/lepu.transports.js.map +1 -0
  147. package/lib/module/modules/bt-management/services/devices/polling-command-sequencer.js +34 -0
  148. package/lib/module/modules/bt-management/services/devices/polling-command-sequencer.js.map +1 -0
  149. package/lib/module/modules/bt-management/services/devices/standard-gatt/standard-gatt.devices.js +149 -0
  150. package/lib/module/modules/bt-management/services/devices/standard-gatt/standard-gatt.devices.js.map +1 -0
  151. package/lib/module/modules/bt-management/services/devices/viatom/viatom.bp-monitors.js +118 -0
  152. package/lib/module/modules/bt-management/services/devices/viatom/viatom.bp-monitors.js.map +1 -0
  153. package/lib/module/modules/bt-management/services/devices/viatom/viatom.ecg-recorders.js +108 -0
  154. package/lib/module/modules/bt-management/services/devices/viatom/viatom.ecg-recorders.js.map +1 -0
  155. package/lib/module/modules/bt-management/services/devices/viatom/viatom.lepod.js +114 -0
  156. package/lib/module/modules/bt-management/services/devices/viatom/viatom.lepod.js.map +1 -0
  157. package/lib/module/modules/bt-management/services/devices/viatom/viatom.oximeters.js +79 -0
  158. package/lib/module/modules/bt-management/services/devices/viatom/viatom.oximeters.js.map +1 -0
  159. package/lib/module/modules/bt-management/types/command-sequencer.js +4 -0
  160. package/lib/module/modules/bt-management/types/command-sequencer.js.map +1 -0
  161. package/lib/module/modules/bt-management/types/custom-checksum-algorithm.js +2 -0
  162. package/lib/module/modules/bt-management/types/custom-checksum-algorithm.js.map +1 -0
  163. package/lib/module/modules/bt-management/types/custom-checksum-spec.js +4 -0
  164. package/lib/module/modules/bt-management/types/custom-checksum-spec.js.map +1 -0
  165. package/lib/module/modules/bt-management/types/custom-device-definition.js.map +1 -1
  166. package/lib/module/modules/bt-management/types/custom-lepu-spec.js +2 -0
  167. package/lib/module/modules/bt-management/types/custom-lepu-spec.js.map +1 -0
  168. package/lib/module/modules/bt-management/types/custom-measurement-spec.js +4 -0
  169. package/lib/module/modules/bt-management/types/custom-measurement-spec.js.map +1 -0
  170. package/lib/module/modules/bt-management/types/device-command.js +2 -0
  171. package/lib/module/modules/bt-management/types/device-command.js.map +1 -0
  172. package/lib/module/modules/bt-management/types/measurement-group.js +4 -0
  173. package/lib/module/modules/bt-management/types/measurement-group.js.map +1 -0
  174. package/lib/module/modules/bt-management/utils/calculate-checksum.js +44 -0
  175. package/lib/module/modules/bt-management/utils/calculate-checksum.js.map +1 -0
  176. package/lib/module/modules/bt-management/utils/create-frame-validator.js +9 -0
  177. package/lib/module/modules/bt-management/utils/create-frame-validator.js.map +1 -1
  178. package/lib/module/modules/bt-management/utils/hex-to-bytes.js +14 -0
  179. package/lib/module/modules/bt-management/utils/hex-to-bytes.js.map +1 -0
  180. package/lib/module/modules/bt-management/utils/le-32-to-bytes.js +8 -0
  181. package/lib/module/modules/bt-management/utils/le-32-to-bytes.js.map +1 -0
  182. package/lib/module/modules/bt-management/utils/summarise-measurement-for-log.js +17 -0
  183. package/lib/module/modules/bt-management/utils/summarise-measurement-for-log.js.map +1 -0
  184. package/lib/module/modules/bt-management/utils/supported-measurement-type-keys.js +13 -0
  185. package/lib/module/modules/bt-management/utils/supported-measurement-type-keys.js.map +1 -0
  186. package/lib/typescript/commonjs/src/modules/bt-management/index.d.ts +16 -0
  187. package/lib/typescript/commonjs/src/modules/bt-management/index.d.ts.map +1 -1
  188. package/lib/typescript/commonjs/src/modules/bt-management/services/custom/compile-case-fields.d.ts +13 -0
  189. package/lib/typescript/commonjs/src/modules/bt-management/services/custom/compile-case-fields.d.ts.map +1 -0
  190. package/lib/typescript/commonjs/src/modules/bt-management/services/custom/compile-custom-case.d.ts.map +1 -1
  191. package/lib/typescript/commonjs/src/modules/bt-management/services/custom/compile-custom-frame.d.ts.map +1 -1
  192. package/lib/typescript/commonjs/src/modules/bt-management/services/custom/compile-custom-lepu.d.ts +11 -0
  193. package/lib/typescript/commonjs/src/modules/bt-management/services/custom/compile-custom-lepu.d.ts.map +1 -0
  194. package/lib/typescript/commonjs/src/modules/bt-management/services/custom/define-custom-device.d.ts.map +1 -1
  195. package/lib/typescript/commonjs/src/modules/bt-management/services/device-creator.d.ts.map +1 -1
  196. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/aoj/aoj.thermometers.d.ts +24 -0
  197. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/aoj/aoj.thermometers.d.ts.map +1 -0
  198. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bp2/bp2.frame-reader.d.ts +5 -8
  199. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bp2/bp2.frame-reader.d.ts.map +1 -1
  200. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bt-command-writer.d.ts +67 -0
  201. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bt-command-writer.d.ts.map +1 -0
  202. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bt-connection-handler.d.ts +6 -4
  203. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bt-connection-handler.d.ts.map +1 -1
  204. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bt-data-processor.d.ts +20 -1
  205. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bt-data-processor.d.ts.map +1 -1
  206. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bt-managed-device.d.ts +12 -1
  207. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/bt-managed-device.d.ts.map +1 -1
  208. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/custom/custom-lepu-sequencer.d.ts +21 -0
  209. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/custom/custom-lepu-sequencer.d.ts.map +1 -0
  210. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/custom/custom.device.d.ts +33 -0
  211. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/custom/custom.device.d.ts.map +1 -1
  212. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.command-builder.d.ts +24 -0
  213. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.command-builder.d.ts.map +1 -0
  214. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.commands.d.ts +32 -0
  215. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.commands.d.ts.map +1 -0
  216. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.device-info.d.ts +27 -0
  217. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.device-info.d.ts.map +1 -0
  218. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.device-names.d.ts +20 -0
  219. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.device-names.d.ts.map +1 -0
  220. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.file-names.d.ts +14 -0
  221. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.file-names.d.ts.map +1 -0
  222. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.file-transfer.d.ts +75 -0
  223. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.file-transfer.d.ts.map +1 -0
  224. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.frame-reader.d.ts +28 -0
  225. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.frame-reader.d.ts.map +1 -0
  226. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.frame.d.ts +12 -0
  227. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.frame.d.ts.map +1 -0
  228. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.identity-gate.d.ts +81 -0
  229. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.identity-gate.d.ts.map +1 -0
  230. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.name-match.d.ts +17 -0
  231. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.name-match.d.ts.map +1 -0
  232. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.response-type.d.ts +33 -0
  233. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.response-type.d.ts.map +1 -0
  234. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.transports.d.ts +85 -0
  235. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/lepu/lepu.transports.d.ts.map +1 -0
  236. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/polling-command-sequencer.d.ts +27 -0
  237. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/polling-command-sequencer.d.ts.map +1 -0
  238. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/standard-gatt/standard-gatt.devices.d.ts +44 -0
  239. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/standard-gatt/standard-gatt.devices.d.ts.map +1 -0
  240. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/viatom/viatom.bp-monitors.d.ts +44 -0
  241. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/viatom/viatom.bp-monitors.d.ts.map +1 -0
  242. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/viatom/viatom.ecg-recorders.d.ts +32 -0
  243. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/viatom/viatom.ecg-recorders.d.ts.map +1 -0
  244. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/viatom/viatom.lepod.d.ts +25 -0
  245. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/viatom/viatom.lepod.d.ts.map +1 -0
  246. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/viatom/viatom.oximeters.d.ts +39 -0
  247. package/lib/typescript/commonjs/src/modules/bt-management/services/devices/viatom/viatom.oximeters.d.ts.map +1 -0
  248. package/lib/typescript/commonjs/src/modules/bt-management/types/command-sequencer.d.ts +26 -0
  249. package/lib/typescript/commonjs/src/modules/bt-management/types/command-sequencer.d.ts.map +1 -0
  250. package/lib/typescript/commonjs/src/modules/bt-management/types/custom-case-spec.d.ts +13 -0
  251. package/lib/typescript/commonjs/src/modules/bt-management/types/custom-case-spec.d.ts.map +1 -1
  252. package/lib/typescript/commonjs/src/modules/bt-management/types/custom-checksum-algorithm.d.ts +10 -0
  253. package/lib/typescript/commonjs/src/modules/bt-management/types/custom-checksum-algorithm.d.ts.map +1 -0
  254. package/lib/typescript/commonjs/src/modules/bt-management/types/custom-checksum-spec.d.ts +23 -0
  255. package/lib/typescript/commonjs/src/modules/bt-management/types/custom-checksum-spec.d.ts.map +1 -0
  256. package/lib/typescript/commonjs/src/modules/bt-management/types/custom-device-definition.d.ts +5 -0
  257. package/lib/typescript/commonjs/src/modules/bt-management/types/custom-device-definition.d.ts.map +1 -1
  258. package/lib/typescript/commonjs/src/modules/bt-management/types/custom-device-spec.d.ts +12 -0
  259. package/lib/typescript/commonjs/src/modules/bt-management/types/custom-device-spec.d.ts.map +1 -1
  260. package/lib/typescript/commonjs/src/modules/bt-management/types/custom-frame-spec.d.ts +8 -0
  261. package/lib/typescript/commonjs/src/modules/bt-management/types/custom-frame-spec.d.ts.map +1 -1
  262. package/lib/typescript/commonjs/src/modules/bt-management/types/custom-lepu-spec.d.ts +44 -0
  263. package/lib/typescript/commonjs/src/modules/bt-management/types/custom-lepu-spec.d.ts.map +1 -0
  264. package/lib/typescript/commonjs/src/modules/bt-management/types/custom-measurement-spec.d.ts +9 -0
  265. package/lib/typescript/commonjs/src/modules/bt-management/types/custom-measurement-spec.d.ts.map +1 -0
  266. package/lib/typescript/commonjs/src/modules/bt-management/types/device-command.d.ts +18 -0
  267. package/lib/typescript/commonjs/src/modules/bt-management/types/device-command.d.ts.map +1 -0
  268. package/lib/typescript/commonjs/src/modules/bt-management/types/measurement-group.d.ts +14 -0
  269. package/lib/typescript/commonjs/src/modules/bt-management/types/measurement-group.d.ts.map +1 -0
  270. package/lib/typescript/commonjs/src/modules/bt-management/types/parsing-case.d.ts +9 -0
  271. package/lib/typescript/commonjs/src/modules/bt-management/types/parsing-case.d.ts.map +1 -1
  272. package/lib/typescript/commonjs/src/modules/bt-management/utils/calculate-checksum.d.ts +13 -0
  273. package/lib/typescript/commonjs/src/modules/bt-management/utils/calculate-checksum.d.ts.map +1 -0
  274. package/lib/typescript/commonjs/src/modules/bt-management/utils/create-frame-validator.d.ts.map +1 -1
  275. package/lib/typescript/commonjs/src/modules/bt-management/utils/hex-to-bytes.d.ts +10 -0
  276. package/lib/typescript/commonjs/src/modules/bt-management/utils/hex-to-bytes.d.ts.map +1 -0
  277. package/lib/typescript/commonjs/src/modules/bt-management/utils/le-32-to-bytes.d.ts +3 -0
  278. package/lib/typescript/commonjs/src/modules/bt-management/utils/le-32-to-bytes.d.ts.map +1 -0
  279. package/lib/typescript/commonjs/src/modules/bt-management/utils/summarise-measurement-for-log.d.ts +9 -0
  280. package/lib/typescript/commonjs/src/modules/bt-management/utils/summarise-measurement-for-log.d.ts.map +1 -0
  281. package/lib/typescript/commonjs/src/modules/bt-management/utils/supported-measurement-type-keys.d.ts +10 -0
  282. package/lib/typescript/commonjs/src/modules/bt-management/utils/supported-measurement-type-keys.d.ts.map +1 -0
  283. package/lib/typescript/module/src/modules/bt-management/index.d.ts +16 -0
  284. package/lib/typescript/module/src/modules/bt-management/index.d.ts.map +1 -1
  285. package/lib/typescript/module/src/modules/bt-management/services/custom/compile-case-fields.d.ts +13 -0
  286. package/lib/typescript/module/src/modules/bt-management/services/custom/compile-case-fields.d.ts.map +1 -0
  287. package/lib/typescript/module/src/modules/bt-management/services/custom/compile-custom-case.d.ts.map +1 -1
  288. package/lib/typescript/module/src/modules/bt-management/services/custom/compile-custom-frame.d.ts.map +1 -1
  289. package/lib/typescript/module/src/modules/bt-management/services/custom/compile-custom-lepu.d.ts +11 -0
  290. package/lib/typescript/module/src/modules/bt-management/services/custom/compile-custom-lepu.d.ts.map +1 -0
  291. package/lib/typescript/module/src/modules/bt-management/services/custom/define-custom-device.d.ts.map +1 -1
  292. package/lib/typescript/module/src/modules/bt-management/services/device-creator.d.ts.map +1 -1
  293. package/lib/typescript/module/src/modules/bt-management/services/devices/aoj/aoj.thermometers.d.ts +24 -0
  294. package/lib/typescript/module/src/modules/bt-management/services/devices/aoj/aoj.thermometers.d.ts.map +1 -0
  295. package/lib/typescript/module/src/modules/bt-management/services/devices/bp2/bp2.frame-reader.d.ts +5 -8
  296. package/lib/typescript/module/src/modules/bt-management/services/devices/bp2/bp2.frame-reader.d.ts.map +1 -1
  297. package/lib/typescript/module/src/modules/bt-management/services/devices/bt-command-writer.d.ts +67 -0
  298. package/lib/typescript/module/src/modules/bt-management/services/devices/bt-command-writer.d.ts.map +1 -0
  299. package/lib/typescript/module/src/modules/bt-management/services/devices/bt-connection-handler.d.ts +6 -4
  300. package/lib/typescript/module/src/modules/bt-management/services/devices/bt-connection-handler.d.ts.map +1 -1
  301. package/lib/typescript/module/src/modules/bt-management/services/devices/bt-data-processor.d.ts +20 -1
  302. package/lib/typescript/module/src/modules/bt-management/services/devices/bt-data-processor.d.ts.map +1 -1
  303. package/lib/typescript/module/src/modules/bt-management/services/devices/bt-managed-device.d.ts +12 -1
  304. package/lib/typescript/module/src/modules/bt-management/services/devices/bt-managed-device.d.ts.map +1 -1
  305. package/lib/typescript/module/src/modules/bt-management/services/devices/custom/custom-lepu-sequencer.d.ts +21 -0
  306. package/lib/typescript/module/src/modules/bt-management/services/devices/custom/custom-lepu-sequencer.d.ts.map +1 -0
  307. package/lib/typescript/module/src/modules/bt-management/services/devices/custom/custom.device.d.ts +33 -0
  308. package/lib/typescript/module/src/modules/bt-management/services/devices/custom/custom.device.d.ts.map +1 -1
  309. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.command-builder.d.ts +24 -0
  310. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.command-builder.d.ts.map +1 -0
  311. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.commands.d.ts +32 -0
  312. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.commands.d.ts.map +1 -0
  313. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.device-info.d.ts +27 -0
  314. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.device-info.d.ts.map +1 -0
  315. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.device-names.d.ts +20 -0
  316. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.device-names.d.ts.map +1 -0
  317. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.file-names.d.ts +14 -0
  318. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.file-names.d.ts.map +1 -0
  319. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.file-transfer.d.ts +75 -0
  320. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.file-transfer.d.ts.map +1 -0
  321. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.frame-reader.d.ts +28 -0
  322. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.frame-reader.d.ts.map +1 -0
  323. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.frame.d.ts +12 -0
  324. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.frame.d.ts.map +1 -0
  325. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.identity-gate.d.ts +81 -0
  326. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.identity-gate.d.ts.map +1 -0
  327. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.name-match.d.ts +17 -0
  328. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.name-match.d.ts.map +1 -0
  329. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.response-type.d.ts +33 -0
  330. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.response-type.d.ts.map +1 -0
  331. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.transports.d.ts +85 -0
  332. package/lib/typescript/module/src/modules/bt-management/services/devices/lepu/lepu.transports.d.ts.map +1 -0
  333. package/lib/typescript/module/src/modules/bt-management/services/devices/polling-command-sequencer.d.ts +27 -0
  334. package/lib/typescript/module/src/modules/bt-management/services/devices/polling-command-sequencer.d.ts.map +1 -0
  335. package/lib/typescript/module/src/modules/bt-management/services/devices/standard-gatt/standard-gatt.devices.d.ts +44 -0
  336. package/lib/typescript/module/src/modules/bt-management/services/devices/standard-gatt/standard-gatt.devices.d.ts.map +1 -0
  337. package/lib/typescript/module/src/modules/bt-management/services/devices/viatom/viatom.bp-monitors.d.ts +44 -0
  338. package/lib/typescript/module/src/modules/bt-management/services/devices/viatom/viatom.bp-monitors.d.ts.map +1 -0
  339. package/lib/typescript/module/src/modules/bt-management/services/devices/viatom/viatom.ecg-recorders.d.ts +32 -0
  340. package/lib/typescript/module/src/modules/bt-management/services/devices/viatom/viatom.ecg-recorders.d.ts.map +1 -0
  341. package/lib/typescript/module/src/modules/bt-management/services/devices/viatom/viatom.lepod.d.ts +25 -0
  342. package/lib/typescript/module/src/modules/bt-management/services/devices/viatom/viatom.lepod.d.ts.map +1 -0
  343. package/lib/typescript/module/src/modules/bt-management/services/devices/viatom/viatom.oximeters.d.ts +39 -0
  344. package/lib/typescript/module/src/modules/bt-management/services/devices/viatom/viatom.oximeters.d.ts.map +1 -0
  345. package/lib/typescript/module/src/modules/bt-management/types/command-sequencer.d.ts +26 -0
  346. package/lib/typescript/module/src/modules/bt-management/types/command-sequencer.d.ts.map +1 -0
  347. package/lib/typescript/module/src/modules/bt-management/types/custom-case-spec.d.ts +13 -0
  348. package/lib/typescript/module/src/modules/bt-management/types/custom-case-spec.d.ts.map +1 -1
  349. package/lib/typescript/module/src/modules/bt-management/types/custom-checksum-algorithm.d.ts +10 -0
  350. package/lib/typescript/module/src/modules/bt-management/types/custom-checksum-algorithm.d.ts.map +1 -0
  351. package/lib/typescript/module/src/modules/bt-management/types/custom-checksum-spec.d.ts +23 -0
  352. package/lib/typescript/module/src/modules/bt-management/types/custom-checksum-spec.d.ts.map +1 -0
  353. package/lib/typescript/module/src/modules/bt-management/types/custom-device-definition.d.ts +5 -0
  354. package/lib/typescript/module/src/modules/bt-management/types/custom-device-definition.d.ts.map +1 -1
  355. package/lib/typescript/module/src/modules/bt-management/types/custom-device-spec.d.ts +12 -0
  356. package/lib/typescript/module/src/modules/bt-management/types/custom-device-spec.d.ts.map +1 -1
  357. package/lib/typescript/module/src/modules/bt-management/types/custom-frame-spec.d.ts +8 -0
  358. package/lib/typescript/module/src/modules/bt-management/types/custom-frame-spec.d.ts.map +1 -1
  359. package/lib/typescript/module/src/modules/bt-management/types/custom-lepu-spec.d.ts +44 -0
  360. package/lib/typescript/module/src/modules/bt-management/types/custom-lepu-spec.d.ts.map +1 -0
  361. package/lib/typescript/module/src/modules/bt-management/types/custom-measurement-spec.d.ts +9 -0
  362. package/lib/typescript/module/src/modules/bt-management/types/custom-measurement-spec.d.ts.map +1 -0
  363. package/lib/typescript/module/src/modules/bt-management/types/device-command.d.ts +18 -0
  364. package/lib/typescript/module/src/modules/bt-management/types/device-command.d.ts.map +1 -0
  365. package/lib/typescript/module/src/modules/bt-management/types/measurement-group.d.ts +14 -0
  366. package/lib/typescript/module/src/modules/bt-management/types/measurement-group.d.ts.map +1 -0
  367. package/lib/typescript/module/src/modules/bt-management/types/parsing-case.d.ts +9 -0
  368. package/lib/typescript/module/src/modules/bt-management/types/parsing-case.d.ts.map +1 -1
  369. package/lib/typescript/module/src/modules/bt-management/utils/calculate-checksum.d.ts +13 -0
  370. package/lib/typescript/module/src/modules/bt-management/utils/calculate-checksum.d.ts.map +1 -0
  371. package/lib/typescript/module/src/modules/bt-management/utils/create-frame-validator.d.ts.map +1 -1
  372. package/lib/typescript/module/src/modules/bt-management/utils/hex-to-bytes.d.ts +10 -0
  373. package/lib/typescript/module/src/modules/bt-management/utils/hex-to-bytes.d.ts.map +1 -0
  374. package/lib/typescript/module/src/modules/bt-management/utils/le-32-to-bytes.d.ts +3 -0
  375. package/lib/typescript/module/src/modules/bt-management/utils/le-32-to-bytes.d.ts.map +1 -0
  376. package/lib/typescript/module/src/modules/bt-management/utils/summarise-measurement-for-log.d.ts +9 -0
  377. package/lib/typescript/module/src/modules/bt-management/utils/summarise-measurement-for-log.d.ts.map +1 -0
  378. package/lib/typescript/module/src/modules/bt-management/utils/supported-measurement-type-keys.d.ts +10 -0
  379. package/lib/typescript/module/src/modules/bt-management/utils/supported-measurement-type-keys.d.ts.map +1 -0
  380. package/package.json +12 -1
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.compileCustomLepu = void 0;
7
+ var _customDeviceError = require("./custom-device-error.js");
8
+ var _normalizeBleUuid = require("./normalize-ble-uuid.js");
9
+ const HEX_BYTE = /^[0-9a-f]{2}$/;
10
+ const MAX_OPCODE = 0xff;
11
+ const MAX_DEVICE_TYPE = 0xffff;
12
+ const assertStartBytes = (id, startBytes) => {
13
+ if (!Array.isArray(startBytes) || startBytes.length === 0) {
14
+ throw (0, _customDeviceError.customDeviceError)(id, "lepu.startBytes", "must list at least one frame start byte, such as [\"a5\"]");
15
+ }
16
+ return startBytes.map((byte, index) => {
17
+ const normalized = String(byte).toLowerCase();
18
+ if (!HEX_BYTE.test(normalized)) {
19
+ throw (0, _customDeviceError.customDeviceError)(id, `lepu.startBytes[${index}]`, `is "${String(byte)}"; it must be exactly two hex digits`);
20
+ }
21
+ return normalized;
22
+ });
23
+ };
24
+ const assertDeviceTypes = (id, deviceTypes) => {
25
+ if (!Array.isArray(deviceTypes)) {
26
+ throw (0, _customDeviceError.customDeviceError)(id, "lepu.expectedDeviceTypes", "must be an array of the model numbers this declaration was written for");
27
+ }
28
+ return deviceTypes.map((deviceType, index) => {
29
+ if (!Number.isInteger(deviceType) || deviceType < 0 || deviceType > MAX_DEVICE_TYPE) {
30
+ throw (0, _customDeviceError.customDeviceError)(id, `lepu.expectedDeviceTypes[${index}]`, `is ${String(deviceType)}; a model number is a whole number between 0 and ${MAX_DEVICE_TYPE}`);
31
+ }
32
+ return deviceType;
33
+ });
34
+ };
35
+
36
+ /**
37
+ * The opcode to poll with, once the device has been identified.
38
+ *
39
+ * Identification is the advertised name unless `expectedDeviceTypes` narrows it further.
40
+ * The name is what the vendor's own SDK binds every one of its products on - a 732-line
41
+ * cascade of name checks resolving to 176 models - so requiring more than that to poll at
42
+ * all would hold this SDK to a bar the hardware's own maker does not meet, and would leave
43
+ * every device undeclarable.
44
+ *
45
+ * Naming the models is still the stronger declaration, and is worth doing once the numbers
46
+ * are known: the family's low opcodes act, and a frame built for the wrong product is still
47
+ * well formed, so a name that matched the wrong hardware would not be caught by anything
48
+ * else in the protocol.
49
+ */
50
+ const assertPollCommand = (id, lepu) => {
51
+ const {
52
+ pollCommand
53
+ } = lepu;
54
+ if (pollCommand === undefined) {
55
+ return undefined;
56
+ }
57
+ if (!Number.isInteger(pollCommand) || pollCommand < 0 || pollCommand > MAX_OPCODE) {
58
+ throw (0, _customDeviceError.customDeviceError)(id, "lepu.pollCommand", `is ${String(pollCommand)}; an opcode is a whole number between 0 and ${MAX_OPCODE}`);
59
+ }
60
+ return pollCommand;
61
+ };
62
+
63
+ /**
64
+ * Validates the Lepu declaration and normalises its UUIDs.
65
+ *
66
+ * The write service has to be one the declaration already monitors: a command written to a
67
+ * service the device never opened is accepted by nothing and answered by nothing, which
68
+ * looks exactly like hardware that is simply not responding.
69
+ */
70
+ const compileCustomLepu = (id, spec, serviceUuids) => {
71
+ const lepu = spec.lepu;
72
+ if (!lepu) {
73
+ return undefined;
74
+ }
75
+ if (spec.services.some(service => service.write)) {
76
+ throw (0, _customDeviceError.customDeviceError)(id, "services[].write", "cannot be declared alongside lepu, which builds its own commands and addresses them through lepu.write");
77
+ }
78
+ const startBytes = assertStartBytes(id, lepu.startBytes);
79
+ const expectedDeviceTypes = assertDeviceTypes(id, lepu.expectedDeviceTypes);
80
+ const pollCommand = assertPollCommand(id, lepu);
81
+ const serviceUuid = (0, _normalizeBleUuid.normalizeBleUuid)(id, "lepu.write.serviceUuid", lepu.write?.serviceUuid);
82
+ if (!serviceUuids.includes(serviceUuid)) {
83
+ throw (0, _customDeviceError.customDeviceError)(id, "lepu.write.serviceUuid", `is "${serviceUuid}", which this device does not declare among its services`);
84
+ }
85
+ return {
86
+ startBytes,
87
+ expectedDeviceTypes,
88
+ ...(pollCommand === undefined ? {} : {
89
+ pollCommand
90
+ }),
91
+ write: {
92
+ serviceUuid,
93
+ characteristicUuid: (0, _normalizeBleUuid.normalizeBleUuid)(id, "lepu.write.characteristicUuid", lepu.write?.characteristicUuid)
94
+ }
95
+ };
96
+ };
97
+ exports.compileCustomLepu = compileCustomLepu;
98
+ //# sourceMappingURL=compile-custom-lepu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_customDeviceError","require","_normalizeBleUuid","HEX_BYTE","MAX_OPCODE","MAX_DEVICE_TYPE","assertStartBytes","id","startBytes","Array","isArray","length","customDeviceError","map","byte","index","normalized","String","toLowerCase","test","assertDeviceTypes","deviceTypes","deviceType","Number","isInteger","assertPollCommand","lepu","pollCommand","undefined","compileCustomLepu","spec","serviceUuids","services","some","service","write","expectedDeviceTypes","serviceUuid","normalizeBleUuid","includes","characteristicUuid","exports"],"sourceRoot":"../../../../../../src","sources":["modules/bt-management/services/custom/compile-custom-lepu.ts"],"mappings":";;;;;;AAGA,IAAAA,kBAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AAEA,MAAME,QAAQ,GAAG,eAAe;AAChC,MAAMC,UAAU,GAAG,IAAI;AACvB,MAAMC,eAAe,GAAG,MAAM;AAE9B,MAAMC,gBAAgB,GAAGA,CAACC,EAAU,EAAEC,UAAmB,KAAe;EACtE,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,UAAU,CAAC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DACpB,CAAC;EACH;EAEA,OAAO;IACL7B,UAAU;IACV4B,mBAAmB;IACnB,IAAIT,WAAW,KAAKC,SAAS,GAAG,CAAC,CAAC,GAAG;MAAED;IAAY,CAAC,CAAC;IACrDQ,KAAK,EAAE;MACLE,WAAW;MACXG,kBAAkB,EAAE,IAAAF,kCAAgB,EAClC/B,EAAE,EACF,+BAA+B,EAC/BmB,IAAI,CAACS,KAAK,EAAEK,kBACd;IACF;EACF,CAAC;AACH,CAAC;AAACC,OAAA,CAAAZ,iBAAA,GAAAA,iBAAA","ignoreList":[]}
@@ -6,11 +6,16 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.defineCustomDevice = void 0;
7
7
  var _customDeviceBrand = require("../../constants/custom-device-brand.js");
8
8
  var _integratedDevices = require("../../types/integrated-devices.js");
9
+ var _compileCustomLepu = require("./compile-custom-lepu.js");
9
10
  var _compileCustomMonitor = require("./compile-custom-monitor.js");
10
11
  var _customDeviceError = require("./custom-device-error.js");
11
12
  var _normalizeBleUuid = require("./normalize-ble-uuid.js");
12
13
  const MIN_STUCK_TIMEOUT_MS = 1_000;
13
14
 
15
+ /** The smallest MTU a BLE link has, and the largest an ATT packet may declare. */
16
+ const MIN_MTU = 23;
17
+ const MAX_MTU = 517;
18
+
14
19
  // The SDK's own F4 scale waits this long, because it sleeps while still connected.
15
20
  const MAX_STUCK_TIMEOUT_MS = 6_000_000;
16
21
  const HEX_BYTES = /^([0-9a-f]{2})+$/;
@@ -46,6 +51,16 @@ const assertStuckTimeout = (id, spec) => {
46
51
  }
47
52
  return timeout;
48
53
  };
54
+ const assertPreferredMtu = (id, spec) => {
55
+ const mtu = spec.preferredMtu;
56
+ if (mtu === undefined) {
57
+ return undefined;
58
+ }
59
+ if (!Number.isInteger(mtu) || mtu < MIN_MTU || mtu > MAX_MTU) {
60
+ throw (0, _customDeviceError.customDeviceError)(id, "preferredMtu", `is ${String(mtu)}; it must be a whole number between ${MIN_MTU} and ${MAX_MTU}`);
61
+ }
62
+ return mtu;
63
+ };
49
64
  const compileWrite = (id, path, write) => {
50
65
  if (!write) {
51
66
  return undefined;
@@ -72,6 +87,7 @@ const defineCustomDevice = spec => {
72
87
  const id = assertIdentity(spec);
73
88
  const nameMatch = compileNameMatch(id, spec);
74
89
  const stuckDataTimeout = assertStuckTimeout(id, spec);
90
+ const preferredMtu = assertPreferredMtu(id, spec);
75
91
  if (!Array.isArray(spec.services) || spec.services.length === 0) {
76
92
  throw (0, _customDeviceError.customDeviceError)(id, "services", "must declare at least one service");
77
93
  }
@@ -105,6 +121,7 @@ const defineCustomDevice = spec => {
105
121
  writeUuid: compileWrite(id, path, service.write)
106
122
  };
107
123
  });
124
+ const lepu = (0, _compileCustomLepu.compileCustomLepu)(id, spec, mainServices.map(service => service.uuid));
108
125
  return {
109
126
  [_customDeviceBrand.CUSTOM_DEVICE_BRAND]: true,
110
127
  id: id,
@@ -113,7 +130,13 @@ const defineCustomDevice = spec => {
113
130
  mainServices,
114
131
  stuckDataTimeout,
115
132
  fields,
116
- frames
133
+ frames,
134
+ ...(preferredMtu === undefined ? {} : {
135
+ preferredMtu
136
+ }),
137
+ ...(lepu === undefined ? {} : {
138
+ lepu
139
+ })
117
140
  };
118
141
  };
119
142
  exports.defineCustomDevice = defineCustomDevice;
@@ -1 +1 @@
1
- {"version":3,"names":["_customDeviceBrand","require","_integratedDevices","_compileCustomMonitor","_customDeviceError","_normalizeBleUuid","MIN_STUCK_TIMEOUT_MS","MAX_STUCK_TIMEOUT_MS","HEX_BYTES","assertIdentity","spec","id","trim","customDeviceError","String","builtIn","Object","values","IntegratedDevices","find","name","toLowerCase","compileNameMatch","nameMatch","RegExp","global","sticky","exact","replace","assertStuckTimeout","timeout","stuckDataTimeoutMs","Number","isInteger","compileWrite","path","write","undefined","commandHex","test","uuid","normalizeBleUuid","mainCommandUuid","defineCustomDevice","stuckDataTimeout","Array","isArray","services","length","fields","Map","frames","seenCharacteristics","Set","mainServices","map","service","serviceIndex","monitor","monitorUuids","monitorIndex","monitorPath","characteristic","frame","compileCustomMonitor","has","add","set","writeUuid","CUSTOM_DEVICE_BRAND","exports"],"sourceRoot":"../../../../../../src","sources":["modules/bt-management/services/custom/define-custom-device.ts"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAMA,IAAAC,kBAAA,GAAAD,OAAA;AAGA,IAAAE,qBAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AAEA,MAAMK,oBAAoB,GAAG,KAAK;;AAElC;AACA,MAAMC,oBAAoB,GAAG,SAAS;AACtC,MAAMC,SAAS,GAAG,kBAAkB;AAEpC,MAAMC,cAAc,GAAIC,IAAsB,IAAa;EACzD,MAAMC,EAAE,GAAG,OAAOD,IAAI,EAAEC,EAAE,KAAK,QAAQ,GAAGD,IAAI,CAACC,EAAE,CAACC,IAAI,CAAC,CAAC,GAAG,EAAE;EAE7D,IAAI,CAACD,EAAE,EAAE;IACP,MAAM,IAAAE,oCAAiB,EAACC,MAAM,CAACJ,IAAI,EAAEC,EAAE,CAAC,EAAE,IAAI,EAAE,mBAAmB,CAAC;EACtE;EAEA,MAAMI,OAAO,GAAGC,MAAM,CAACC,MAAM,CAACC,oCAAiB,CAAC,CAACC,IAAI,CAClDC,IAAI,IAAKA,IAAI,CAACC,WAAW,CAAC,CAAC,KAAKV,EAAE,CAACU,WAAW,CAAC,CAClD,CAAC;EAED,IAAIN,OAAO,EAAE;IACX,MAAM,IAAAF,oCAAiB,EACrBF,EAAE,EACF,IAAI,EACJ,sCAAsCI,OAAO,GAC/C,CAAC;EACH;EAEA,OAAOJ,EAAE;AACX,CAAC;AAED,MAAMW,gBAAgB,GAAGA,CAACX,EAAU,EAAED,IAAsB,KAAa;EACvE,MAAMa,SAAS,GAAGb,IAAI,CAACa,SAAS;EAEhC,IAAIA,SAAS,YAAYC,MAAM,EAAE;IAC/B,IAAID,SAAS,CAACE,MAAM,IAAIF,SAAS,C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"names":["_customDeviceBrand","require","_integratedDevices","_compileCustomLepu","_compileCustomMonitor","_customDeviceError","_normalizeBleUuid","MIN_STUCK_TIMEOUT_MS","MIN_MTU","MAX_MTU","MAX_STUCK_TIMEOUT_MS","HEX_BYTES","assertIdentity","spec","id","trim","customDeviceError","String","builtIn","Object","values","IntegratedDevices","find","name","toLowerCase","compileNameMatch","nameMatch","RegExp","global","sticky","exact","replace","assertStuckTimeout","timeout","stuckDataTimeoutMs","Number","isInteger","assertPreferredMtu","mtu","preferredMtu","undefined","compileWrite","path","write","commandHex","test","uuid","normalizeBleUuid","mainCommandUuid","defineCustomDevice","stuckDataTimeout","Array","isArray","services","length","fields","Map","frames","seenCharacteristics","Set","mainServices","map","service","serviceIndex","monitor","monitorUuids","monitorIndex","monitorPath","characteristic","frame","compileCustomMonitor","has","add","set","writeUuid","lepu","compileCustomLepu","CUSTOM_DEVICE_BRAND","exports"],"sourceRoot":"../../../../../../src","sources":["modules/bt-management/services/custom/define-custom-device.ts"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAMA,IAAAC,kBAAA,GAAAD,OAAA;AAGA,IAAAE,kBAAA,GAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAH,OAAA;AACA,IAAAI,kBAAA,GAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAL,OAAA;AAEA,MAAMM,oBAAoB,GAAG,KAAK;;AAElC;AACA,MAAMC,OAAO,GAAG,EAAE;AAClB,MAAMC,OAAO,GAAG,GAAG;;AAEnB;AACA,MAAMC,oBAAoB,GAAG,SAAS;AACtC,MAAMC,SAAS,GAAG,kBAAkB;AAEpC,MAAMC,cAAc,GAAIC,IAAsB,IAAa;EACzD,MAAMC,EAAE,GAAG,OAAOD,IAAI,EAAEC,EAAE,KAAK,QAAQ,GAAGD,IAAI,CAACC,EAAE,CAACC,IAAI,CAAC,CAAC,GAAG,EAAE;EAE7D,IAAI,CAACD,EAAE,EAAE;IACP,MAAM,IAAAE,oCAAi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AAC,GAAG;MAAED;IAAa,CAAC,CAAC;IACvD,IAAIoC,IAAI,KAAKnC,SAAS,GAAG,CAAC,CAAC,GAAG;MAAEmC;IAAK,CAAC;EACxC,CAAC;AACH,CAAC;AAACG,OAAA,CAAA7B,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -12,6 +12,19 @@ var _bp2Device = require("./devices/bp2/bp2.device.js");
12
12
  var _customDevice = require("./devices/custom/custom.device.js");
13
13
  var _f4Device = require("./devices/f4/f4.device.js");
14
14
  var _spo2Device = require("./devices/spo/spo2.device.js");
15
+ /**
16
+ * The built-in names the SDK can actually build.
17
+ *
18
+ * `integratedDevicesMap` matches more names than this, on purpose: matching is what names a
19
+ * device in a scan result and a device list, which is useful for hardware the SDK cannot
20
+ * yet decode. Connecting to one of those is what fails, and it fails saying so.
21
+ */
22
+ const DEVICE_CLASSES = {
23
+ [_integratedDevices.IntegratedDevices.BP2]: _bp2Device.BP2Device,
24
+ [_integratedDevices.IntegratedDevices.F4]: _f4Device.F4Device,
25
+ [_integratedDevices.IntegratedDevices.PC60WF]: _spo2Device.SPO2Device,
26
+ [_integratedDevices.IntegratedDevices.BC01]: _bc01Device.BC01Device
27
+ };
15
28
  const collectCustomDevices = acceptedDevices => {
16
29
  const customDevices = new Map();
17
30
  const matchers = new Set();
@@ -71,15 +84,9 @@ class DeviceCreator {
71
84
  // @ts-expect-error - the caller asked for this custom device by its own id
72
85
  return new _customDevice.CustomDevice(params.device, params, custom);
73
86
  }
74
- const deviceMap = {
75
- [_integratedDevices.IntegratedDevices.BP2]: _bp2Device.BP2Device,
76
- [_integratedDevices.IntegratedDevices.F4]: _f4Device.F4Device,
77
- [_integratedDevices.IntegratedDevices.PC60WF]: _spo2Device.SPO2Device,
78
- [_integratedDevices.IntegratedDevices.BC01]: _bc01Device.BC01Device
79
- };
80
- const deviceClass = deviceMap[params.deviceName];
87
+ const deviceClass = DEVICE_CLASSES[params.deviceName];
81
88
  if (!deviceClass) {
82
- throw new Error(`Device ${params.device.name} not found`);
89
+ throw new Error(`"${params.deviceName}" is a name the SDK matches during a scan but has no decoder for, so "${params.device.name}" cannot be connected. The names it can decode are ${Object.keys(DEVICE_CLASSES).join(", ")}; anything else needs a declaration registered with defineCustomDevice and passed in acceptedDevices.`);
83
90
  }
84
91
 
85
92
  // @ts-expect-error - This is a workaround to allow the deviceClass to be instantiated with the correct type
@@ -1 +1 @@
1
- {"version":3,"names":["_integratedDevicesMap","require","_integratedDevices","_isCustomDeviceDefinition","_bc01Device","_bp2Device","_customDevice","_f4Device","_spo2Device","collectCustomDevices","acceptedDevices","customDevices","Map","matchers","Set","forEach","entry","index","isCustomDeviceDefinition","Error","has","id","nameMatch","source","set","add","DeviceCreator","deviceNameCache","CACHE_MAX_SIZE","constructor","acceptedDeviceNames","getDeviceName","foundName","undefined","get","matched","matchDeviceName","cacheDeviceName","createDevice","params","String","deviceName","trim","device","name","custom","CustomDevice","deviceMap","IntegratedDevices","BP2","BP2Device","F4","F4Device","PC60WF","SPO2Device","BC01","BC01Device","deviceClass","destroy","clear","regex","deviceType","integratedDevicesMap","test","some","values","size","firstKey","keys","next","value","delete","exports"],"sourceRoot":"../../../../../src","sources":["modules/bt-management/services/device-creator.ts"],"mappings":";;;;;;AAAA,IAAAA,qBAAA,GAAAC,OAAA;AAMA,IAAAC,kBAAA,GAAAD,OAAA;AACA,IAAAE,yBAAA,GAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAEA,IAAAK,aAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AAEA,MAAMQ,oBAAoB,GACxBC,eAA0C,IACF;EACxC,MAAMC,aAAa,GAAG,IAAIC,GAAG,CAAiC,CAAC;EAC/D,MAAMC,QAAQ,GAAG,IAAIC,GAAG,CAAS,CAAC;EAElCJ,eAAe,CAACK,OAAO,CAAC,CAACC,KAAK,EAAEC,KAA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"version":3,"names":["_integratedDevicesMap","require","_integratedDevices","_isCustomDeviceDefinition","_bc01Device","_bp2Device","_customDevice","_f4Device","_spo2Device","DEVICE_CLASSES","IntegratedDevices","BP2","BP2Device","F4","F4Device","PC60WF","SPO2Device","BC01","BC01Device","collectCustomDevices","acceptedDevices","customDevices","Map","matchers","Set","forEach","entry","index","isCustomDeviceDefinition","Error","has","id","nameMatch","source","set","add","DeviceCreator","deviceNameCache","CACHE_MAX_SIZE","constructor","acceptedDeviceNames","getDeviceName","foundName","undefined","get","matched","matchDeviceName","cacheDeviceName","createDevice","params","String","deviceName","trim","device","name","custom","CustomDevice","deviceClass","Object","keys","join","destroy","clear","regex","deviceType","integratedDevicesMap","test","some","values","size","firstKey","next","value","delete","exports"],"sourceRoot":"../../../../../src","sources":["modules/bt-management/services/device-creator.ts"],"mappings":";;;;;;AAAA,IAAAA,qBAAA,GAAAC,OAAA;AAMA,IAAAC,kBAAA,GAAAD,OAAA;AACA,IAAAE,yBAAA,GAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAEA,IAAAK,aAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMQ,cAAc,GAAG;EACrB,CAACC,oCAAiB,CAACC,GAAG,GAAGC,oBAAS;EAClC,CAACF,oCAAiB,CAACG,EAAE,GAAGC,kBAAQ;EAChC,CAACJ,oCAAiB,CAACK,MAAM,GAAGC,sBAAU;EACtC,CAACN,oCAAiB,CAACO,IAAI,GAAGC;AAC5B,CAAC;AAID,MAAMC,oBAAoB,GACxBC,eAA0C,IACF;EACxC,MAAMC,aAAa,GAAG,IAAIC,GAAG,CAAiC,CAAC;EAC/D,MAAMC,QAAQ,GAAG,IAAIC,GAAG,CAAS,CAAC;EAElCJ,eAAe,CAACK,OAAO,CAAC,CAACC,KAAK,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C;EAC/C;EAEOY,OAAO,GAAGA,CAAA,KAAM;IACrB,IAAI,CAACxB,eAAe,CAACyB,KAAK,CAAC,CAAC;EAC9B,CAAC;;EAED;AACF;AACA;AACA;EACUhB,eAAe,GACrBK,UAAkB,IACa;IAC/B,KAAK,MAAM,CAACY,KAAK,EAAEC,UAAU,CAAC,IAAIC,0CAAoB,EAAE;MACtD,IACEF,KAAK,CAACG,IAAI,CAACf,UAAU,CAAC,IACtB,IAAI,CAACX,mBAAmB,CAAC2B,IAAI,CAAEb,IAAI,IAAKA,IAAI,KAAKU,UAAU,CAAC,EAC5D;QACA,OAAOA,UAAU;MACnB;IACF;IAEA,KAAK,MAAMT,MAAM,IAAI,IAAI,CAAClC,aAAa,CAAC+C,MAAM,CAAC,CAAC,EAAE;MAChD,IAAIb,MAAM,CAACvB,SAAS,CAACkC,IAAI,CAACf,UAAU,CAAC,EAAE;QACrC,OAAOI,MAAM,CAACxB,EAAE;MAClB;IACF;IAEA,OAAOY,SAAS;EAClB,CAAC;EAEOI,eAAeA,CACrBI,UAAkB,EAClBa,UAA4B,EACtB;IACN;IACA,IAAI,IAAI,CAAC3B,eAAe,CAACgC,IAAI,IAAI,IAAI,CAAC/B,cAAc,EAAE;MACpD,MAAMgC,QAAQ,GAAG,IAAI,CAACjC,eAAe,CAACsB,IAAI,CAAC,CAAC,CAACY,IAAI,CAAC,CAAC,CAACC,KAAK;MAEzD,IAAIF,QAAQ,KAAK3B,SAAS,EAAE;QAC1B,IAAI,CAACN,eAAe,CAACoC,MAAM,CAACH,QAAQ,CAAC;MACvC;IACF;IAEA,IAAI,CAACjC,eAAe,CAACH,GAAG,CAACiB,UAAU,EAAEa,UAAU,CAAC;EAClD;AACF;AAACU,OAAA,CAAAtC,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.aoj20aThermometer = void 0;
7
+ var _core = require("@ovok/core");
8
+ var _defineCustomDevice = require("../../custom/define-custom-device.js");
9
+ /**
10
+ * Declarations for the AOJ Medical thermometers.
11
+ *
12
+ * Their frame is `aa | 01 | cmd | len | payload | xor`, where the checksum covers everything
13
+ * from the device-type byte up to itself. It is not the Lepu framing, despite both being
14
+ * reachable from the same vendor app: no complement byte, no sequence number, a one-byte
15
+ * length and an exclusive-or rather than a CRC.
16
+ */
17
+
18
+ /** Every frame opens with these two: a fixed start byte and a fixed device type. */
19
+ const FRAME_HEADER = ["aa", "01"];
20
+ const COMMAND_BYTE = 2;
21
+
22
+ /** Header, a three-byte payload and the checksum. */
23
+ const FRAME_BYTES = 8;
24
+ const CHECKSUM_INDEX = 7;
25
+
26
+ /** The checksum starts after the start byte, which it does not cover. */
27
+ const CHECKSUM_FROM = 1;
28
+ const PAYLOAD = 4;
29
+
30
+ /** The device answers a realtime-temperature request with this. */
31
+ const TEMPERATURE_REPLY = "c1";
32
+
33
+ /** Hundredths of a degree, big-endian - the one field in this family that is not little. */
34
+ const TEMPERATURE_SCALE = 0.01;
35
+ const TEMPERATURE_DECIMALS = 2;
36
+ const SPOT_CHECK_TIMEOUT_MS = 60_000;
37
+ /**
38
+ * The AOJ-20A infrared thermometer.
39
+ *
40
+ * Declared without a write characteristic, because the device sends its reading rather than
41
+ * waiting to be asked: the vendor app has a request for it, calls it from nowhere, and still
42
+ * displays temperatures - so the reply arrives when someone takes a measurement. Not writing
43
+ * also means not polling, which for a spot-check device would otherwise re-report the same
44
+ * reading for as long as the link stayed up.
45
+ *
46
+ * Only the realtime reply is declared. The stored-history reply shares the header and would
47
+ * need its own case; nothing reads history yet, and a case that decoded it into the same
48
+ * measurement would post old readings as though they had just been taken.
49
+ */
50
+ const aoj20aThermometer = params => (0, _defineCustomDevice.defineCustomDevice)({
51
+ id: params.id,
52
+ nameMatch: params.nameMatch,
53
+ stuckDataTimeoutMs: params.stuckDataTimeoutMs ?? SPOT_CHECK_TIMEOUT_MS,
54
+ services: [{
55
+ uuid: "ffe0",
56
+ monitor: [{
57
+ uuid: "ffe1",
58
+ frame: {
59
+ header: FRAME_HEADER,
60
+ minLengthBytes: FRAME_BYTES,
61
+ checksum: {
62
+ algorithm: "xor",
63
+ index: CHECKSUM_INDEX,
64
+ from: CHECKSUM_FROM
65
+ }
66
+ },
67
+ caseSelectorBytes: [COMMAND_BYTE],
68
+ cases: [{
69
+ selector: TEMPERATURE_REPLY,
70
+ kind: "result",
71
+ measurementTypeKey: _core.MeasurementTypeKey.temperature,
72
+ fields: [{
73
+ name: "bodyTemp",
74
+ byteIndexes: [PAYLOAD, PAYLOAD + 1],
75
+ byteOrder: "big",
76
+ unit: "Cel",
77
+ scale: TEMPERATURE_SCALE,
78
+ decimals: TEMPERATURE_DECIMALS
79
+ }]
80
+ }]
81
+ }]
82
+ }]
83
+ });
84
+ exports.aoj20aThermometer = aoj20aThermometer;
85
+ //# sourceMappingURL=aoj.thermometers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_core","require","_defineCustomDevice","FRAME_HEADER","COMMAND_BYTE","FRAME_BYTES","CHECKSUM_INDEX","CHECKSUM_FROM","PAYLOAD","TEMPERATURE_REPLY","TEMPERATURE_SCALE","TEMPERATURE_DECIMALS","SPOT_CHECK_TIMEOUT_MS","aoj20aThermometer","params","defineCustomDevice","id","nameMatch","stuckDataTimeoutMs","services","uuid","monitor","frame","header","minLengthBytes","checksum","algorithm","index","from","caseSelectorBytes","cases","selector","kind","measurementTypeKey","MeasurementTypeKey","temperature","fields","name","byteIndexes","byteOrder","unit","scale","decimals","exports"],"sourceRoot":"../../../../../../../src","sources":["modules/bt-management/services/devices/aoj/aoj.thermometers.ts"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAGA,IAAAC,mBAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,MAAME,YAAY,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC;AAEjC,MAAMC,YAA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/B;QACZ,CAAC;MAEL,CAAC;IAEL,CAAC;EAEL,CAAC;AAEL,CAAC,CAAC;AAACgC,OAAA,CAAA9B,iBAAA,GAAAA,iBAAA","ignoreList":[]}
@@ -4,85 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.BP2FrameReader = void 0;
7
- var _frameReadStatus = require("../../../types/frame-read-status.js");
8
- var _calculateCrc = require("../../../utils/calculate-crc-8.js");
9
- var _hexToByte = require("../../../utils/hex-to-byte.js");
10
- var _le16FromHex = require("../../../utils/le-16-from-hex.js");
11
- const FRAME_START_BYTE = "a5";
12
- const COMMAND_INDEX = 1;
13
- const COMMAND_COMPLEMENT_INDEX = 2;
14
- const PAYLOAD_LENGTH_INDEX = 5;
15
- const HEADER_BYTES = 7;
16
- const CHECKSUM_BYTES = 1;
17
- const BYTE_MASK = 0xff;
18
-
19
- /** Start byte, command and its complement: the shortest run that can identify a start. */
20
- const START_PATTERN_BYTES = 3;
21
- const isFrameStart = (buffer, index) => {
22
- if ((buffer[index] || "").toLowerCase() !== FRAME_START_BYTE) {
23
- return false;
24
- }
25
- const command = (0, _hexToByte.hexToByte)(buffer[index + COMMAND_INDEX] || "0");
26
- const complement = (0, _hexToByte.hexToByte)(buffer[index + COMMAND_COMPLEMENT_INDEX] || "0");
27
- return command === (~complement & BYTE_MASK);
28
- };
29
- const findFrameStart = buffer => {
30
- const lastCandidate = buffer.length - START_PATTERN_BYTES;
31
- for (let index = 0; index <= lastCandidate; index++) {
32
- if (isFrameStart(buffer, index)) {
33
- return index;
34
- }
35
- }
36
- return -1;
37
- };
38
-
39
- /**
40
- * Bytes that cannot begin a frame start, and are therefore safe to drop when no start
41
- * was found. The trailing bytes are kept because a start pattern may still be arriving.
42
- */
43
- const droppableLeadingBytes = buffer => Math.max(0, buffer.length - (START_PATTERN_BYTES - 1));
7
+ var _lepuFrameReader = require("../lepu/lepu.frame-reader.js");
8
+ /** The start byte the BP2 and most of its family use. */
9
+ const BP2_START_BYTES = ["a5"];
44
10
 
45
11
  /**
46
12
  * Reads Lepu protocol frames as used by the BP2.
47
13
  *
48
- * Layout: `a5 | cmd | ~cmd | type | seq | lenLow lenHigh | payload | crc8`, where the
49
- * checksum covers every byte before it. The complement of the command byte only narrows
50
- * the search for a start; the checksum is what actually decides a frame is trustworthy.
14
+ * The frame itself is shared across the family, so it lives in `LepuFrameReader`; the only
15
+ * thing that makes it a BP2 is which start byte it accepts.
51
16
  */
52
- class BP2FrameReader {
53
- readFrame(buffer) {
54
- const start = findFrameStart(buffer);
55
- if (start === -1) {
56
- return {
57
- status: _frameReadStatus.FrameReadStatus.INCOMPLETE,
58
- consumedBytes: droppableLeadingBytes(buffer)
59
- };
60
- }
61
- const payloadLength = (0, _le16FromHex.le16FromHex)(buffer, start + PAYLOAD_LENGTH_INDEX);
62
- const frameLength = HEADER_BYTES + payloadLength + CHECKSUM_BYTES;
63
- if (start + frameLength > buffer.length) {
64
- return {
65
- status: _frameReadStatus.FrameReadStatus.INCOMPLETE,
66
- consumedBytes: start
67
- };
68
- }
69
- const frame = buffer.slice(start, start + frameLength);
70
- if (!this.hasValidChecksum(frame)) {
71
- return {
72
- status: _frameReadStatus.FrameReadStatus.CORRUPT,
73
- consumedBytes: start + START_PATTERN_BYTES
74
- };
75
- }
76
- return {
77
- status: _frameReadStatus.FrameReadStatus.COMPLETE,
78
- consumedBytes: start + frameLength,
79
- frame
80
- };
81
- }
82
- hasValidChecksum(frame) {
83
- const checksummedBytes = frame.length - CHECKSUM_BYTES;
84
- const declared = (0, _hexToByte.hexToByte)(frame[checksummedBytes] || "0");
85
- return declared === (0, _calculateCrc.calculateCrc8)(frame, checksummedBytes);
17
+ class BP2FrameReader extends _lepuFrameReader.LepuFrameReader {
18
+ constructor() {
19
+ super(BP2_START_BYTES);
86
20
  }
87
21
  }
88
22
  exports.BP2FrameReader = BP2FrameReader;
@@ -1 +1 @@
1
- {"version":3,"names":["_frameReadStatus","require","_calculateCrc","_hexToByte","_le16FromHex","FRAME_START_BYTE","COMMAND_INDEX","COMMAND_COMPLEMENT_INDEX","PAYLOAD_LENGTH_INDEX","HEADER_BYTES","CHECKSUM_BYTES","BYTE_MASK","START_PATTERN_BYTES","isFrameStart","buffer","index","toLowerCase","command","hexToByte","complement","findFrameStart","lastCandidate","length","droppableLeadingBytes","Math","max","BP2FrameReader","readFrame","start","status","FrameReadStatus","INCOMPLETE","consumedBytes","payloadLength","le16FromHex","frameLength","frame","slice","hasValidChecksum","CORRUPT","COMPLETE","checksummedBytes","declared","calculateCrc8","exports"],"sourceRoot":"../../../../../../../src","sources":["modules/bt-management/services/devices/bp2/bp2.frame-reader.ts"],"mappings":";;;;;;AACA,IAAAA,gBAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AAEA,MAAMI,gBAAgB,GAAG,IAAI;AAC7B,MAAMC,aAAa,GAAG,CAAC;AACvB,MAAMC,wBAAwB,GAAG,CAAC;AAClC,MAAMC,oBAAoB,GAAG,CAAC;AAC9B,MAAMC,YAAY,GAAG,CAAC;AACtB,MAAMC,cAAc,GAAG,CAAC;AACxB,MAAMC,SAAS,GAAG,IAAI;;AAEtB;AACA,MAAMC,mBAAmB,GAAG,CAAC;AAE7B,MAAMC,YAAY,GAAGA,CAACC,MAAyB,EAAEC,KAAa,KAAc;EAC1E,IAAI,CAACD,MAAM,CAACC,KAAK,CAAC,IAAI,EAAE,EAAEC,WAAW,CAAC,CAAC,KAAKX,gBAAgB,EAAE;IAC5D,OAAO,KAAK;EACd;EAEA,MAAMY,OAAO,GAAG,IAAAC,oBAAS,EAACJ,MAAM,CAACC,KAAK,GAAGT,aAAa,CAAC,IAAI,GAAG,CAAC;EAC/D,MAAMa,UAAU,GAAG,IAAAD,oBAAS,EAACJ,MAAM,CAACC,KAAK,GAAGR,wBAAwB,CAAC,IAAI,GAAG,CAAC;EAE7E,OAAO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,CAAC;IAEtD,IAAI,CAAC,IAAI,CAACG,gBAAgB,CAACF,KAAK,CAAC,EAAE;MACjC,OAAO;QACLP,MAAM,EAAEC,gCAAe,CAACS,OAAO;QAC/BP,aAAa,EAAEJ,KAAK,GAAGhB;MACzB,CAAC;IACH;IAEA,OAAO;MACLiB,MAAM,EAAEC,gCAAe,CAACU,QAAQ;MAChCR,aAAa,EAAEJ,KAAK,GAAGO,WAAW;MAClCC;IACF,CAAC;EACH;EAEQE,gBAAgBA,CAACF,KAAe,EAAW;IACjD,MAAMK,gBAAgB,GAAGL,KAAK,CAACd,MAAM,GAAGZ,cAAc;IACtD,MAAMgC,QAAQ,GAAG,IAAAxB,oBAAS,EAACkB,KAAK,CAACK,gBAAgB,CAAC,IAAI,GAAG,CAAC;IAE1D,OAAOC,QAAQ,KAAK,IAAAC,2BAAa,EAACP,KAAK,EAAEK,gBAAgB,CAAC;EAC5D;AACF;AAACG,OAAA,CAAAlB,cAAA,GAAAA,cAAA","ignoreList":[]}
1
+ {"version":3,"names":["_lepuFrameReader","require","BP2_START_BYTES","BP2FrameReader","LepuFrameReader","constructor","exports"],"sourceRoot":"../../../../../../../src","sources":["modules/bt-management/services/devices/bp2/bp2.frame-reader.ts"],"mappings":";;;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA;AAEA;AACA,MAAMC,eAAe,GAAG,CAAC,IAAI,CAAC;;AAE9B;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,cAAc,SAASC,gCAAe,CAAC;EAC3CC,WAAWA,CAAA,EAAG;IACnB,KAAK,CAACH,eAAe,CAAC;EACxB;AACF;AAACI,OAAA,CAAAH,cAAA,GAAAA,cAAA","ignoreList":[]}
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.BTCommandWriter = void 0;
7
+ var _sLog = require("../../../helpers/utils/s-log.js");
8
+ var _sentryLogger = require("../../../helpers/utils/sentry-logger.js");
9
+ var _hexToBase = require("../../utils/hex-to-base-64.js");
10
+ const MAX_WRITE_ATTEMPTS = 3;
11
+
12
+ /** The MTU every BLE link starts at, before either side asks for more. */
13
+ const DEFAULT_ATT_MTU = 23;
14
+
15
+ /** An ATT write spends three bytes on its own header. */
16
+ const ATT_WRITE_HEADER_BYTES = 3;
17
+
18
+ /**
19
+ * The write channel to a connected device.
20
+ *
21
+ * These protocols allow one command outstanding at a time, and the reply to it is what
22
+ * decides the next one, so writes are serialised rather than merely guarded against
23
+ * re-entry. Refusing a command while another is in flight stalls a self-clocking exchange
24
+ * permanently: the refused command is the one that would have provoked the next reply, and
25
+ * nothing retries it.
26
+ */
27
+ class BTCommandWriter {
28
+ pendingWrites = Promise.resolve();
29
+ mtu = DEFAULT_ATT_MTU;
30
+ constructor(device, onError) {
31
+ this.device = device;
32
+ this.onError = onError;
33
+ }
34
+
35
+ /**
36
+ * Records what the link actually negotiated.
37
+ *
38
+ * The floor stands until something says otherwise, because a link that has not
39
+ * negotiated is at the minimum, and over-estimating truncates while under-estimating
40
+ * only costs a second packet.
41
+ */
42
+ useNegotiatedMtu = mtu => {
43
+ if (typeof mtu === "number" && Number.isInteger(mtu) && mtu > this.mtu) {
44
+ this.mtu = mtu;
45
+ }
46
+ };
47
+
48
+ /** Drops anything still queued, for a link that is going away. */
49
+ reset = () => {
50
+ this.pendingWrites = Promise.resolve();
51
+ };
52
+
53
+ /**
54
+ * Queues commands behind whatever is already being written.
55
+ *
56
+ * The returned promise settles when the last of them has been written and never rejects.
57
+ * A write that fails is retried and reported where it happens; the catch here is a
58
+ * backstop, so that anything that gets past that still cannot poison the queue and
59
+ * silence every command after it.
60
+ */
61
+ send = commands => {
62
+ this.pendingWrites = this.pendingWrites.then(() => this.writeInOrder(commands)).catch(error => {
63
+ this.onError?.(error);
64
+ });
65
+ return this.pendingWrites;
66
+ };
67
+ writeInOrder = async commands => {
68
+ for (const command of commands) {
69
+ await this.writeCommand(command);
70
+ }
71
+ };
72
+
73
+ /**
74
+ * Writes one command, split to fit the link.
75
+ *
76
+ * A write longer than the negotiated MTU is truncated by the stack rather than refused,
77
+ * so an oversized command arrives as a shorter one whose header still looks valid. The
78
+ * Er2 negotiates the 23-byte minimum where the rest of the family grants 247, which is
79
+ * enough to cut a 28-byte file-read request in half.
80
+ *
81
+ * A chunk that cannot be written abandons the rest of the command. The device reassembles
82
+ * by arrival, so continuing past a gap would hand it a frame that is not the one asked
83
+ * for - worse than sending nothing, because it would be answered.
84
+ */
85
+ writeCommand = async command => {
86
+ for (const chunk of this.chunksOf(command.frame)) {
87
+ const written = await this.writeChunk(command, chunk);
88
+ if (!written) {
89
+ return;
90
+ }
91
+ }
92
+ };
93
+
94
+ /**
95
+ * Splits a frame into writes the link will carry whole.
96
+ *
97
+ * A frame that already fits yields one chunk, so the common command - a poll of a handful
98
+ * of bytes - is written exactly as it was before there was any splitting at all.
99
+ */
100
+ chunksOf = frame => {
101
+ const size = Math.max(1, this.mtu - ATT_WRITE_HEADER_BYTES);
102
+ const chunks = [];
103
+ for (let start = 0; start < frame.length; start += size) {
104
+ chunks.push(frame.slice(start, start + size));
105
+ }
106
+ return chunks;
107
+ };
108
+
109
+ /**
110
+ * Writes one chunk, retrying a failed write.
111
+ *
112
+ * The attempt count is local rather than an instance field, so a write that exhausted its
113
+ * retries cannot leave the next one with none left - which is what a shared counter did
114
+ * on any path that failed to reset it.
115
+ */
116
+ writeChunk = async (command, chunk) => {
117
+ for (let attempt = 1; attempt <= MAX_WRITE_ATTEMPTS; attempt++) {
118
+ try {
119
+ const isConnected = await this.device.isConnected();
120
+ if (!isConnected) {
121
+ return false;
122
+ }
123
+ await this.device.writeCharacteristicWithResponseForService(command.serviceUuid, command.characteristicUuid, (0, _hexToBase.hexToBase64)(chunk.join("")));
124
+ return true;
125
+ } catch (error) {
126
+ (0, _sentryLogger.sentryLogger)("error", "DEVICE: Error sending command", {
127
+ error: error instanceof Error ? error.message : error,
128
+ deviceName: this.device.name
129
+ });
130
+ if (attempt === MAX_WRITE_ATTEMPTS) {
131
+ (0, _sLog.slog)(error, "BT_CONNECTION_HANDLER: Error sending command", {
132
+ deviceName: this.device.name
133
+ });
134
+ }
135
+ }
136
+ }
137
+ return false;
138
+ };
139
+ }
140
+ exports.BTCommandWriter = BTCommandWriter;
141
+ //# sourceMappingURL=bt-command-writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_sLog","require","_sentryLogger","_hexToBase","MAX_WRITE_ATTEMPTS","DEFAULT_ATT_MTU","ATT_WRITE_HEADER_BYTES","BTCommandWriter","pendingWrites","Promise","resolve","mtu","constructor","device","onError","useNegotiatedMtu","Number","isInteger","reset","send","commands","then","writeInOrder","catch","error","command","writeCommand","chunk","chunksOf","frame","written","writeChunk","size","Math","max","chunks","start","length","push","slice","attempt","isConnected","writeCharacteristicWithResponseForService","serviceUuid","characteristicUuid","hexToBase64","join","sentryLogger","Error","message","deviceName","name","slog","exports"],"sourceRoot":"../../../../../../src","sources":["modules/bt-management/services/devices/bt-command-writer.ts"],"mappings":";;;;;;AAEA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAEA,IAAAE,UAAA,GAAAF,OAAA;AAEA,MAAMG,kBAAkB,GAAG,CAAC;;AAE5B;AACA,MAAMC,eAAe,GAAG,EAAE;;AAE1B;AACA,MAAMC,sBAAsB,GAAG,CAAC;;AAEhC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,eAAe,CAAC;EACnBC,aAAa,GAAkBC,OAAO,CAACC,OAAO,CAAC,CAAC;EAChDC,GAAG,GAAGN,eAAe;EAEtBO,WAAWA,CACCC,MAAc,EACdC,OAA2C,EAC5D;IAAA,KAFiBD,MAAc,GAAdA,MAAc;IAAA,KACdC,OAA2C,GAA3CA,OAA2C;EAC3D;;EAEH;AACF;AACA;AACA;AACA;AACA;AACA;EACSC,gBAAgB,GAAIJ,GAAY,IAAW;IAChD,IAAI,OAAOA,GAAG,KAAK,Q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