@ovok/native 0.4.6 → 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 +9 -49
  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 +9 -49
  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 +1 -1
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ import { MeasurementTypeKey } from "@ovok/core";
4
+ import { defineCustomDevice } from "../../custom/define-custom-device.js";
5
+
6
+ /**
7
+ * Declarations for the AOJ Medical thermometers.
8
+ *
9
+ * Their frame is `aa | 01 | cmd | len | payload | xor`, where the checksum covers everything
10
+ * from the device-type byte up to itself. It is not the Lepu framing, despite both being
11
+ * reachable from the same vendor app: no complement byte, no sequence number, a one-byte
12
+ * length and an exclusive-or rather than a CRC.
13
+ */
14
+
15
+ /** Every frame opens with these two: a fixed start byte and a fixed device type. */
16
+ const FRAME_HEADER = ["aa", "01"];
17
+ const COMMAND_BYTE = 2;
18
+
19
+ /** Header, a three-byte payload and the checksum. */
20
+ const FRAME_BYTES = 8;
21
+ const CHECKSUM_INDEX = 7;
22
+
23
+ /** The checksum starts after the start byte, which it does not cover. */
24
+ const CHECKSUM_FROM = 1;
25
+ const PAYLOAD = 4;
26
+
27
+ /** The device answers a realtime-temperature request with this. */
28
+ const TEMPERATURE_REPLY = "c1";
29
+
30
+ /** Hundredths of a degree, big-endian - the one field in this family that is not little. */
31
+ const TEMPERATURE_SCALE = 0.01;
32
+ const TEMPERATURE_DECIMALS = 2;
33
+ const SPOT_CHECK_TIMEOUT_MS = 60_000;
34
+ /**
35
+ * The AOJ-20A infrared thermometer.
36
+ *
37
+ * Declared without a write characteristic, because the device sends its reading rather than
38
+ * waiting to be asked: the vendor app has a request for it, calls it from nowhere, and still
39
+ * displays temperatures - so the reply arrives when someone takes a measurement. Not writing
40
+ * also means not polling, which for a spot-check device would otherwise re-report the same
41
+ * reading for as long as the link stayed up.
42
+ *
43
+ * Only the realtime reply is declared. The stored-history reply shares the header and would
44
+ * need its own case; nothing reads history yet, and a case that decoded it into the same
45
+ * measurement would post old readings as though they had just been taken.
46
+ */
47
+ export const aoj20aThermometer = params => defineCustomDevice({
48
+ id: params.id,
49
+ nameMatch: params.nameMatch,
50
+ stuckDataTimeoutMs: params.stuckDataTimeoutMs ?? SPOT_CHECK_TIMEOUT_MS,
51
+ services: [{
52
+ uuid: "ffe0",
53
+ monitor: [{
54
+ uuid: "ffe1",
55
+ frame: {
56
+ header: FRAME_HEADER,
57
+ minLengthBytes: FRAME_BYTES,
58
+ checksum: {
59
+ algorithm: "xor",
60
+ index: CHECKSUM_INDEX,
61
+ from: CHECKSUM_FROM
62
+ }
63
+ },
64
+ caseSelectorBytes: [COMMAND_BYTE],
65
+ cases: [{
66
+ selector: TEMPERATURE_REPLY,
67
+ kind: "result",
68
+ measurementTypeKey: MeasurementTypeKey.temperature,
69
+ fields: [{
70
+ name: "bodyTemp",
71
+ byteIndexes: [PAYLOAD, PAYLOAD + 1],
72
+ byteOrder: "big",
73
+ unit: "Cel",
74
+ scale: TEMPERATURE_SCALE,
75
+ decimals: TEMPERATURE_DECIMALS
76
+ }]
77
+ }]
78
+ }]
79
+ }]
80
+ });
81
+ //# sourceMappingURL=aoj.thermometers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["MeasurementTypeKey","defineCustomDevice","FRAME_HEADER","COMMAND_BYTE","FRAME_BYTES","CHECKSUM_INDEX","CHECKSUM_FROM","PAYLOAD","TEMPERATURE_REPLY","TEMPERATURE_SCALE","TEMPERATURE_DECIMALS","SPOT_CHECK_TIMEOUT_MS","aoj20aThermometer","params","id","nameMatch","stuckDataTimeoutMs","services","uuid","monitor","frame","header","minLengthBytes","checksum","algorithm","index","from","caseSelectorBytes","cases","selector","kind","measurementTypeKey","temperature","fields","name","byteIndexes","byteOrder","unit","scale","decimals"],"sourceRoot":"../../../../../../../src","sources":["modules/bt-management/services/devices/aoj/aoj.thermometers.ts"],"mappings":";;AAAA,SAASA,kBAAkB,QAAQ,YAAY;AAG/C,SAASC,kBAAkB,QAAQ,sCAAmC;;AAEtE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,MAAMC,YAAY,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC;AAEjC,MAAMC,YAAY,GAAG,CAAC;;AAEtB;AACA,MAAMC,WAAW,GAAG,CAAC;AACrB,MAAMC,cAAc,GAAG,CAAC;;AAExB;AACA,MAAMC,aAAa,GAAG,CAAC;AAEvB,MAAMC,OAAO,GAAG,CAAC;;AAEjB;AACA,MAAMC,iBAAiB,GAAG,IAAI;;AAE9B;AACA,MAAMC,iBAAiB,GAAG,IAAI;AAC9B,MAAMC,oBAAoB,GAAG,CAAC;AAE9B,MAAMC,qBAAqB,GAAG,MAAM;AAapC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,iBAAiB,GAC5BC,MAAuB,IAEvBZ,kBAAkB,CAAC;EACjBa,EAAE,EAAED,MAAM,CAACC,EAAE;EACbC,SAAS,EAAEF,MAAM,CAACE,SAAS;EAC3BC,kBAAkB,EAAEH,MAAM,CAACG,kBAAkB,IAAIL,qBAAqB;EACtEM,QAAQ,EAAE,CACR;IACEC,IAAI,EAAE,MAAM;IACZC,OAAO,EAAE,CACP;MACED,IAAI,EAAE,MAAM;MACZE,KAAK,EAAE;QACLC,MAAM,EAAEnB,YAAY;QACpBoB,cAAc,EAAElB,WAAW;QAC3BmB,QAAQ,EAAE;UACRC,SAAS,EAAE,KAAK;UAChBC,KAAK,EAAEpB,cAAc;UACrBqB,IAAI,EAAEpB;QACR;MACF,CAAC;MACDqB,iBAAiB,EAAE,CAACxB,YAAY,CAAC;MACjCyB,KAAK,EAAE,CACL;QACEC,QAAQ,EAAErB,iBAAiB;QAC3BsB,IAAI,EAAE,QAAQ;QACdC,kBAAkB,EAAE/B,kBAAkB,CAACgC,WAAW;QAClDC,MAAM,EAAE,CACN;UACEC,IAAI,EAAE,UAAU;UAChBC,WAAW,EAAE,CAAC5B,OAAO,EAAEA,OAAO,GAAG,CAAC,CAAC;UACnC6B,SAAS,EAAE,KAAK;UAChBC,IAAI,EAAE,KAAK;UACXC,KAAK,EAAE7B,iBAAiB;UACxB8B,QAAQ,EAAE7B;QACZ,CAAC;MAEL,CAAC;IAEL,CAAC;EAEL,CAAC;AAEL,CAAC,CAAC","ignoreList":[]}
@@ -1,84 +1,19 @@
1
1
  "use strict";
2
2
 
3
- import { FrameReadStatus } from "../../../types/frame-read-status.js";
4
- import { calculateCrc8 } from "../../../utils/calculate-crc-8.js";
5
- import { hexToByte } from "../../../utils/hex-to-byte.js";
6
- import { le16FromHex } from "../../../utils/le-16-from-hex.js";
7
- const FRAME_START_BYTE = "a5";
8
- const COMMAND_INDEX = 1;
9
- const COMMAND_COMPLEMENT_INDEX = 2;
10
- const PAYLOAD_LENGTH_INDEX = 5;
11
- const HEADER_BYTES = 7;
12
- const CHECKSUM_BYTES = 1;
13
- const BYTE_MASK = 0xff;
3
+ import { LepuFrameReader } from "../lepu/lepu.frame-reader.js";
14
4
 
15
- /** Start byte, command and its complement: the shortest run that can identify a start. */
16
- const START_PATTERN_BYTES = 3;
17
- const isFrameStart = (buffer, index) => {
18
- if ((buffer[index] || "").toLowerCase() !== FRAME_START_BYTE) {
19
- return false;
20
- }
21
- const command = hexToByte(buffer[index + COMMAND_INDEX] || "0");
22
- const complement = hexToByte(buffer[index + COMMAND_COMPLEMENT_INDEX] || "0");
23
- return command === (~complement & BYTE_MASK);
24
- };
25
- const findFrameStart = buffer => {
26
- const lastCandidate = buffer.length - START_PATTERN_BYTES;
27
- for (let index = 0; index <= lastCandidate; index++) {
28
- if (isFrameStart(buffer, index)) {
29
- return index;
30
- }
31
- }
32
- return -1;
33
- };
34
-
35
- /**
36
- * Bytes that cannot begin a frame start, and are therefore safe to drop when no start
37
- * was found. The trailing bytes are kept because a start pattern may still be arriving.
38
- */
39
- const droppableLeadingBytes = buffer => Math.max(0, buffer.length - (START_PATTERN_BYTES - 1));
5
+ /** The start byte the BP2 and most of its family use. */
6
+ const BP2_START_BYTES = ["a5"];
40
7
 
41
8
  /**
42
9
  * Reads Lepu protocol frames as used by the BP2.
43
10
  *
44
- * Layout: `a5 | cmd | ~cmd | type | seq | lenLow lenHigh | payload | crc8`, where the
45
- * checksum covers every byte before it. The complement of the command byte only narrows
46
- * the search for a start; the checksum is what actually decides a frame is trustworthy.
11
+ * The frame itself is shared across the family, so it lives in `LepuFrameReader`; the only
12
+ * thing that makes it a BP2 is which start byte it accepts.
47
13
  */
48
- export class BP2FrameReader {
49
- readFrame(buffer) {
50
- const start = findFrameStart(buffer);
51
- if (start === -1) {
52
- return {
53
- status: FrameReadStatus.INCOMPLETE,
54
- consumedBytes: droppableLeadingBytes(buffer)
55
- };
56
- }
57
- const payloadLength = le16FromHex(buffer, start + PAYLOAD_LENGTH_INDEX);
58
- const frameLength = HEADER_BYTES + payloadLength + CHECKSUM_BYTES;
59
- if (start + frameLength > buffer.length) {
60
- return {
61
- status: FrameReadStatus.INCOMPLETE,
62
- consumedBytes: start
63
- };
64
- }
65
- const frame = buffer.slice(start, start + frameLength);
66
- if (!this.hasValidChecksum(frame)) {
67
- return {
68
- status: FrameReadStatus.CORRUPT,
69
- consumedBytes: start + START_PATTERN_BYTES
70
- };
71
- }
72
- return {
73
- status: FrameReadStatus.COMPLETE,
74
- consumedBytes: start + frameLength,
75
- frame
76
- };
77
- }
78
- hasValidChecksum(frame) {
79
- const checksummedBytes = frame.length - CHECKSUM_BYTES;
80
- const declared = hexToByte(frame[checksummedBytes] || "0");
81
- return declared === calculateCrc8(frame, checksummedBytes);
14
+ export class BP2FrameReader extends LepuFrameReader {
15
+ constructor() {
16
+ super(BP2_START_BYTES);
82
17
  }
83
18
  }
84
19
  //# sourceMappingURL=bp2.frame-reader.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["FrameReadStatus","calculateCrc8","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","complement","findFrameStart","lastCandidate","length","droppableLeadingBytes","Math","max","BP2FrameReader","readFrame","start","status","INCOMPLETE","consumedBytes","payloadLength","frameLength","frame","slice","hasValidChecksum","CORRUPT","COMPLETE","checksummedBytes","declared"],"sourceRoot":"../../../../../../../src","sources":["modules/bt-management/services/devices/bp2/bp2.frame-reader.ts"],"mappings":";;AACA,SAASA,eAAe,QAAQ,qCAAkC;AAElE,SAASC,aAAa,QAAQ,mCAAgC;AAC9D,SAASC,SAAS,QAAQ,+BAA4B;AACtD,SAASC,WAAW,QAAQ,kCAA+B;AAE3D,MAAMC,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,GAAGd,SAAS,CAACW,MAAM,CAACC,KAAK,GAAGT,aA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AAC4B,UAAU;QAAEC,aAAa,EAAEH;MAAM,CAAC;IACrE;IAEA,MAAMM,KAAK,GAAGnB,MAAM,CAACoB,KAAK,CAACP,KAAK,EAAEA,KAAK,GAAGK,WAAW,CAAC;IAEtD,IAAI,CAAC,IAAI,CAACG,gBAAgB,CAACF,KAAK,CAAC,EAAE;MACjC,OAAO;QACLL,MAAM,EAAE3B,eAAe,CAACmC,OAAO;QAC/BN,aAAa,EAAEH,KAAK,GAAGf;MACzB,CAAC;IACH;IAEA,OAAO;MACLgB,MAAM,EAAE3B,eAAe,CAACoC,QAAQ;MAChCP,aAAa,EAAEH,KAAK,GAAGK,WAAW;MAClCC;IACF,CAAC;EACH;EAEQE,gBAAgBA,CAACF,KAAe,EAAW;IACjD,MAAMK,gBAAgB,GAAGL,KAAK,CAACZ,MAAM,GAAGX,cAAc;IACtD,MAAM6B,QAAQ,GAAGpC,SAAS,CAAC8B,KAAK,CAACK,gBAAgB,CAAC,IAAI,GAAG,CAAC;IAE1D,OAAOC,QAAQ,KAAKrC,aAAa,CAAC+B,KAAK,EAAEK,gBAAgB,CAAC;EAC5D;AACF","ignoreList":[]}
1
+ {"version":3,"names":["LepuFrameReader","BP2_START_BYTES","BP2FrameReader","constructor"],"sourceRoot":"../../../../../../../src","sources":["modules/bt-management/services/devices/bp2/bp2.frame-reader.ts"],"mappings":";;AAAA,SAASA,eAAe,QAAQ,8BAA2B;;AAE3D;AACA,MAAMC,eAAe,GAAG,CAAC,IAAI,CAAC;;AAE9B;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,cAAc,SAASF,eAAe,CAAC;EAC3CG,WAAWA,CAAA,EAAG;IACnB,KAAK,CAACF,eAAe,CAAC;EACxB;AACF","ignoreList":[]}
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+
3
+ import { slog } from "../../../helpers/utils/s-log.js";
4
+ import { sentryLogger } from "../../../helpers/utils/sentry-logger.js";
5
+ import { hexToBase64 } from "../../utils/hex-to-base-64.js";
6
+ const MAX_WRITE_ATTEMPTS = 3;
7
+
8
+ /** The MTU every BLE link starts at, before either side asks for more. */
9
+ const DEFAULT_ATT_MTU = 23;
10
+
11
+ /** An ATT write spends three bytes on its own header. */
12
+ const ATT_WRITE_HEADER_BYTES = 3;
13
+
14
+ /**
15
+ * The write channel to a connected device.
16
+ *
17
+ * These protocols allow one command outstanding at a time, and the reply to it is what
18
+ * decides the next one, so writes are serialised rather than merely guarded against
19
+ * re-entry. Refusing a command while another is in flight stalls a self-clocking exchange
20
+ * permanently: the refused command is the one that would have provoked the next reply, and
21
+ * nothing retries it.
22
+ */
23
+ export class BTCommandWriter {
24
+ pendingWrites = Promise.resolve();
25
+ mtu = DEFAULT_ATT_MTU;
26
+ constructor(device, onError) {
27
+ this.device = device;
28
+ this.onError = onError;
29
+ }
30
+
31
+ /**
32
+ * Records what the link actually negotiated.
33
+ *
34
+ * The floor stands until something says otherwise, because a link that has not
35
+ * negotiated is at the minimum, and over-estimating truncates while under-estimating
36
+ * only costs a second packet.
37
+ */
38
+ useNegotiatedMtu = mtu => {
39
+ if (typeof mtu === "number" && Number.isInteger(mtu) && mtu > this.mtu) {
40
+ this.mtu = mtu;
41
+ }
42
+ };
43
+
44
+ /** Drops anything still queued, for a link that is going away. */
45
+ reset = () => {
46
+ this.pendingWrites = Promise.resolve();
47
+ };
48
+
49
+ /**
50
+ * Queues commands behind whatever is already being written.
51
+ *
52
+ * The returned promise settles when the last of them has been written and never rejects.
53
+ * A write that fails is retried and reported where it happens; the catch here is a
54
+ * backstop, so that anything that gets past that still cannot poison the queue and
55
+ * silence every command after it.
56
+ */
57
+ send = commands => {
58
+ this.pendingWrites = this.pendingWrites.then(() => this.writeInOrder(commands)).catch(error => {
59
+ this.onError?.(error);
60
+ });
61
+ return this.pendingWrites;
62
+ };
63
+ writeInOrder = async commands => {
64
+ for (const command of commands) {
65
+ await this.writeCommand(command);
66
+ }
67
+ };
68
+
69
+ /**
70
+ * Writes one command, split to fit the link.
71
+ *
72
+ * A write longer than the negotiated MTU is truncated by the stack rather than refused,
73
+ * so an oversized command arrives as a shorter one whose header still looks valid. The
74
+ * Er2 negotiates the 23-byte minimum where the rest of the family grants 247, which is
75
+ * enough to cut a 28-byte file-read request in half.
76
+ *
77
+ * A chunk that cannot be written abandons the rest of the command. The device reassembles
78
+ * by arrival, so continuing past a gap would hand it a frame that is not the one asked
79
+ * for - worse than sending nothing, because it would be answered.
80
+ */
81
+ writeCommand = async command => {
82
+ for (const chunk of this.chunksOf(command.frame)) {
83
+ const written = await this.writeChunk(command, chunk);
84
+ if (!written) {
85
+ return;
86
+ }
87
+ }
88
+ };
89
+
90
+ /**
91
+ * Splits a frame into writes the link will carry whole.
92
+ *
93
+ * A frame that already fits yields one chunk, so the common command - a poll of a handful
94
+ * of bytes - is written exactly as it was before there was any splitting at all.
95
+ */
96
+ chunksOf = frame => {
97
+ const size = Math.max(1, this.mtu - ATT_WRITE_HEADER_BYTES);
98
+ const chunks = [];
99
+ for (let start = 0; start < frame.length; start += size) {
100
+ chunks.push(frame.slice(start, start + size));
101
+ }
102
+ return chunks;
103
+ };
104
+
105
+ /**
106
+ * Writes one chunk, retrying a failed write.
107
+ *
108
+ * The attempt count is local rather than an instance field, so a write that exhausted its
109
+ * retries cannot leave the next one with none left - which is what a shared counter did
110
+ * on any path that failed to reset it.
111
+ */
112
+ writeChunk = async (command, chunk) => {
113
+ for (let attempt = 1; attempt <= MAX_WRITE_ATTEMPTS; attempt++) {
114
+ try {
115
+ const isConnected = await this.device.isConnected();
116
+ if (!isConnected) {
117
+ return false;
118
+ }
119
+ await this.device.writeCharacteristicWithResponseForService(command.serviceUuid, command.characteristicUuid, hexToBase64(chunk.join("")));
120
+ return true;
121
+ } catch (error) {
122
+ sentryLogger("error", "DEVICE: Error sending command", {
123
+ error: error instanceof Error ? error.message : error,
124
+ deviceName: this.device.name
125
+ });
126
+ if (attempt === MAX_WRITE_ATTEMPTS) {
127
+ slog(error, "BT_CONNECTION_HANDLER: Error sending command", {
128
+ deviceName: this.device.name
129
+ });
130
+ }
131
+ }
132
+ }
133
+ return false;
134
+ };
135
+ }
136
+ //# sourceMappingURL=bt-command-writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["slog","sentryLogger","hexToBase64","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","join","Error","message","deviceName","name"],"sourceRoot":"../../../../../../src","sources":["modules/bt-management/services/devices/bt-command-writer.ts"],"mappings":";;AAEA,SAASA,IAAI,QAAQ,iCAA8B;AACnD,SAASC,YAAY,QAAQ,yCAAsC;AAEnE,SAASC,WAAW,QAAQ,+BAA4B;AAExD,MAAMC,kBAAkB,GAAG,CAAC;;AAE5B;AACA,MAAMC,eAAe,GAAG,EAAE;;AAE1B;AACA,MAAMC,sBAAsB,GAAG,CAAC;;AAEhC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,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,QAAQ,IAAIK,MAAM,CAACC,SAAS,CAACN,GAAG,CAAC,IAAIA,GAAG,GAAG,IAAI,CAACA,GAAG,EAAE;MACtE,IAAI,CAACA,GAAG,GAAGA,GAAG;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IJ,IAAI,EAAE;MACvDG,MAAM,CAACG,IAAI,CAACT,KAAK,CAACU,KAAK,CAACH,KAAK,EAAEA,KAAK,GAAGJ,IAAI,CAAC,CAAC;IAC/C;IAEA,OAAOG,MAAM;EACf,CAAC;;EAED;AACF;AACA;AACA;AACA;AACA;AACA;EACUJ,UAAU,GAAG,MAAAA,CACnBN,OAAsB,EACtBE,KAAwB,KACH;IACrB,KAAK,IAAIa,OAAO,GAAG,CAAC,EAAEA,OAAO,IAAIpC,kBAAkB,EAAEoC,OAAO,EAAE,EAAE;MAC9D,IAAI;QACF,MAAMC,WAAW,GAAG,MAAM,IAAI,CAAC5B,MAAM,CAAC4B,WAAW,CAAC,CAAC;QAEnD,IAAI,CAACA,WAAW,EAAE;UAChB,OAAO,KAAK;QACd;QAEA,MAAM,IAAI,CAAC5B,MAAM,CAAC6B,yCAAyC,CACzDjB,OAAO,CAACkB,WAAW,EACnBlB,OAAO,CAACmB,kBAAkB,EAC1BzC,WAAW,CAACwB,KAAK,CAACkB,IAAI,CAAC,EAAE,CAAC,CAC5B,CAAC;QAED,OAAO,IAAI;MACb,CAAC,CAAC,OAAOrB,KAAK,EAAE;QACdtB,YAAY,CAAC,OAAO,EAAE,+BAA+B,EAAE;UACrDsB,KAAK,EAAEA,KAAK,YAAYsB,KAAK,GAAGtB,KAAK,CAACuB,OAAO,GAAGvB,KAAK;UACrDwB,UAAU,EAAE,IAAI,CAACnC,MAAM,CAACoC;QAC1B,CAAC,CAAC;QAEF,IAAIT,OAAO,KAAKpC,kBAAkB,EAAE;UAClCH,IAAI,CAACuB,KAAK,EAAE,8CAA8C,EAAE;YAC1DwB,UAAU,EAAE,IAAI,CAACnC,MAAM,CAACoC;UAC1B,CAAC,CAAC;QACJ;MACF;IACF;IAEA,OAAO,KAAK;EACd,CAAC;AACH","ignoreList":[]}
@@ -1,19 +1,17 @@
1
1
  "use strict";
2
2
 
3
- import { slog } from "../../../helpers/index.js";
4
3
  import { sentryLogger } from "../../../helpers/utils/sentry-logger.js";
5
4
  import { DeviceStatus } from "../../types/device-status.js";
6
5
  import { base64ToHex } from "../../utils/base-64-to-hex.js";
7
- import { hexToBase64 } from "../../utils/hex-to-base-64.js";
6
+ import { BTCommandWriter } from "./bt-command-writer.js";
8
7
  export class BTConnectionHandler {
9
8
  characteristicSubscriptions = [];
10
- isSendingCommand = false;
11
- retryCount = 0;
12
9
  constructor(device, mainServices, callbacks, preferredMtu) {
13
10
  this.device = device;
14
11
  this.mainServices = mainServices;
15
12
  this.callbacks = callbacks;
16
13
  this.preferredMtu = preferredMtu;
14
+ this.writer = new BTCommandWriter(device, callbacks.onError);
17
15
  }
18
16
  connect = async () => {
19
17
  try {
@@ -35,23 +33,12 @@ export class BTConnectionHandler {
35
33
  destroy = () => {
36
34
  this.characteristicSubscriptions.forEach(sub => sub?.remove());
37
35
  this.characteristicSubscriptions = [];
38
- this.isSendingCommand = false;
39
- this.retryCount = 0;
36
+ this.writer.reset();
40
37
  this.onDisconnectSubscription?.remove();
41
38
  };
42
- sendCommandToDevice = async () => {
43
- if (this.isSendingCommand) {
44
- return;
45
- }
46
- this.isSendingCommand = true;
47
- for (const mainService of this.mainServices) {
48
- if (mainService.writeUuid) {
49
- await this.sendCommand(mainService);
50
- }
51
- }
52
- this.isSendingCommand = false;
53
- this.retryCount = 0;
54
- };
39
+
40
+ /** Sends commands to the device, in order, one at a time. */
41
+ sendCommands = commands => this.writer.send(commands);
55
42
 
56
43
  /**
57
44
  * Asks for a larger MTU so a frame arrives in fewer notifications.
@@ -64,7 +51,8 @@ export class BTConnectionHandler {
64
51
  return;
65
52
  }
66
53
  try {
67
- await this.device.requestMTU(this.preferredMtu);
54
+ const negotiated = await this.device.requestMTU(this.preferredMtu);
55
+ this.writer.useNegotiatedMtu(negotiated?.mtu ?? this.device.mtu);
68
56
  } catch (error) {
69
57
  sentryLogger("info", "DEVICE: MTU request was not granted", {
70
58
  deviceId: this.device.id,
@@ -148,7 +136,7 @@ export class BTConnectionHandler {
148
136
  this.characteristicSubscriptions.push(subscription);
149
137
  }
150
138
  }
151
- await this.sendCommandToDevice();
139
+ await this.sendCommands(this.callbacks.initialCommands?.() ?? []);
152
140
  } catch (error) {
153
141
  sentryLogger("error", "DEVICE: Error subscribing to all characteristics", {
154
142
  error: error instanceof Error ? error.message : error,
@@ -157,33 +145,5 @@ export class BTConnectionHandler {
157
145
  this.callbacks.onError?.(error);
158
146
  }
159
147
  };
160
- sendCommand = async mainService => {
161
- if (!mainService.writeUuid) {
162
- return;
163
- }
164
- while (this.retryCount < 3) {
165
- try {
166
- const isConnected = await this.device.isConnected();
167
- if (!isConnected) {
168
- return;
169
- }
170
- const command = hexToBase64(mainService.writeUuid.mainCommandUuid);
171
- await this.device.writeCharacteristicWithResponseForService(mainService.uuid, mainService.writeUuid.uuid, command);
172
- this.retryCount = 0;
173
- break;
174
- } catch (error) {
175
- this.retryCount++;
176
- sentryLogger("error", "DEVICE: Error sending command", {
177
- error: error instanceof Error ? error.message : error,
178
- deviceName: this.device.name
179
- });
180
- if (this.retryCount === 3) {
181
- slog(error, "BT_CONNECTION_HANDLER: Error sending command", {
182
- deviceName: this.device.name
183
- });
184
- }
185
- }
186
- }
187
- };
188
148
  }
189
149
  //# sourceMappingURL=bt-connection-handler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["slog","sentryLogger","DeviceStatus","base64ToHex","hexToBase64","BTConnectionHandler","characteristicSubscriptions","isSendingCommand","retryCount","constructor","device","mainServices","callbacks","preferredMtu","connect","connectWithRetries","requestPreferredMtu","onStatusChanged","CONNECTED","discoverAllServicesAndCharacteristics","onDisconnectSubscription","onDisconnected","onDeviceDisconnected","subscribeToAllCharacteristics","error","Error","message","deviceName","name","onError","DISCONNECTED","destroy","forEach","sub","remove","sendCommandToDevice","mainService","writeUuid","sendCommand","requestMTU","deviceId","id","requestedMtu","String","maxRetries","retryDelay","maxDelay","connected","isConnected","errorCode","willRetry","Promise","resolve","setTimeout","Math","min","pow","monitorUuid","monitorUuids","subscription","monitorCharacteristicForService","uuid","result","value","hexValue","onDataReceived","push","command","mainCommandUuid","writeCharacteristicWithResponseForService"],"sourceRoot":"../../../../../../src","sources":["modules/bt-management/services/devices/bt-connection-handler.ts"],"mappings":";;AAEA,SAASA,IAAI,QAAQ,2BAAkB;AACvC,SAASC,YAAY,QAAQ,yCAAsC;AACnE,SAASC,YAAY,QAAQ,8BAA2B;AAGxD,SAASC,WAAW,QAAQ,+BAA4B;AACxD,SAASC,WAAW,QAAQ,+BAA4B;AAQxD,OAAO,MAAMC,mBAAmB,CAAC;EAEvBC,2BAA2B,GAAmB,EAAE;EAChDC,gBAAgB,GAAY,KAAK;EACjCC,UAAU,GAAW,CAAC;EAE9BC,WAAWA,CACQC,MAAc,EACdC,YAA2C,EAC3CC,SAAqC,EACrCC,YAAqB,EACtC;IAAA,KAJiBH,MAAc,GAAdA,MAAc;IAAA,KACdC,YAA2C,GAA3CA,YAA2C;IAAA,KAC3CC,SAAqC,GAArCA,SAAqC;IAAA,KACrCC,YAAqB,GAArBA,YAAqB;EACrC;EAEIC,OAAO,GAAG,MAAAA,CAAA,KAAY;IAC3B,IAAI;MACF,MAAM,IAAI,CAACC,kBAAkB,CAAC,CAAC;MAC/B,MAAM,IAAI,CAACC,mBAAmB,CAAC,CAAC;MAEhC,IAAI,CAACJ,SAAS,CAACK,eAAe,GAAGf,YAAY,CAACgB,SAAS,CAAC;MAExD,MAAM,IAAI,CAACR,MAAM,CAACS,qCAAqC,CAAC,CAAC;MAEzD,IAAI,CAACC,wBAAwB,GAAG,IAAI,CAACV,MAAM,CAACW,cAAc,CACxD,IAAI,CAACC,oBACP,CAAC;MAED,IAAI,CAACC,6BAA6B,CAAC,CAAC;IACtC,CAAC,CAAC,OAAOC,KAAK,EAAE;MACdvB,YAAY,CAAC,OAAO,EAAE,wCAAwC,EAAE;QAC9DuB,KAAK,EAAEA,KAAK,YAAYC,KAAK,GAAGD,KAAK,CAACE,OAAO,GAAGF,KAAK;QACrDG,UAAU,EAA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AAe,CAAC;QAElE,MAAM,IAAI,CAAC1D,MAAM,CAAC2D,yCAAyC,CACzDjC,WAAW,CAACyB,IAAI,EAChBzB,WAAW,CAACC,SAAS,CAACwB,IAAI,EAC1BM,OACF,CAAC;QACD,IAAI,CAAC3D,UAAU,GAAG,CAAC;QACnB;MACF,CAAC,CAAC,OAAOgB,KAAK,EAAE;QACd,IAAI,CAAChB,UAAU,EAAE;QACjBP,YAAY,CAAC,OAAO,EAAE,+BAA+B,EAAE;UACrDuB,KAAK,EAAEA,KAAK,YAAYC,KAAK,GAAGD,KAAK,CAACE,OAAO,GAAGF,KAAK;UACrDG,UAAU,EAAE,IAAI,CAACjB,MAAM,CAACkB;QAC1B,CAAC,CAAC;QACF,IAAI,IAAI,CAACpB,UAAU,KAAK,CAAC,EAAE;UACzBR,IAAI,CAACwB,KAAK,EAAE,8CAA8C,EAAE;YAC1DG,UAAU,EAAE,IAAI,CAACjB,MAAM,CAACkB;UAC1B,CAAC,CAAC;QACJ;MACF;IACF;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"names":["sentryLogger","DeviceStatus","base64ToHex","BTCommandWriter","BTConnectionHandler","characteristicSubscriptions","constructor","device","mainServices","callbacks","preferredMtu","writer","onError","connect","connectWithRetries","requestPreferredMtu","onStatusChanged","CONNECTED","discoverAllServicesAndCharacteristics","onDisconnectSubscription","onDisconnected","onDeviceDisconnected","subscribeToAllCharacteristics","error","Error","message","deviceName","name","DISCONNECTED","destroy","forEach","sub","remove","reset","sendCommands","commands","send","negotiated","requestMTU","useNegotiatedMtu","mtu","deviceId","id","requestedMtu","String","maxRetries","retryDelay","maxDelay","connected","retryCount","isConnected","errorCode","willRetry","Promise","resolve","setTimeout","Math","min","pow","mainService","monitorUuid","monitorUuids","subscription","monitorCharacteristicForService","uuid","result","value","hexValue","onDataReceived","push","initialCommands"],"sourceRoot":"../../../../../../src","sources":["modules/bt-management/services/devices/bt-connection-handler.ts"],"mappings":";;AAEA,SAASA,YAAY,QAA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,CAAC;YAE1C,IAAI,CAACzD,SAAS,CAAC2D,cAAc,GAAGH,MAAM,CAACD,IAAI,EAAEG,QAAQ,CAAC;UACxD,CACF,CAAC;UAED,IAAI,CAAC9D,2BAA2B,CAACgE,IAAI,CAACP,YAAY,CAAC;QACrD;MACF;MAEA,MAAM,IAAI,CAAC5B,YAAY,CAAC,IAAI,CAACzB,SAAS,CAAC6D,eAAe,GAAG,CAAC,IAAI,EAAE,CAAC;IACnE,CAAC,CAAC,OAAO/C,KAAK,EAAE;MACdvB,YAAY,CACV,OAAO,EACP,kDAAkD,EAClD;QACEuB,KAAK,EAAEA,KAAK,YAAYC,KAAK,GAAGD,KAAK,CAACE,OAAO,GAAGF,KAAK;QACrDG,UAAU,EAAE,IAAI,CAACnB,MAAM,CAACoB;MAC1B,CACF,CAAC;MACD,IAAI,CAAClB,SAAS,CAACG,OAAO,GAAGW,KAAyB,CAAC;IACrD;EACF,CAAC;AAEH","ignoreList":[]}
@@ -57,14 +57,13 @@ export class BTDataProcessor {
57
57
  * A frame that fails its integrity check is reported and skipped rather than parsed.
58
58
  */
59
59
  readFramesFromBuffer = (reader, uuid, buffer) => {
60
- let hasReadFrame = false;
61
60
  while (buffer.length > 0) {
62
61
  const result = reader.readFrame(buffer);
63
62
  const hasProgressed = result.consumedBytes > 0;
64
63
  buffer.splice(0, result.consumedBytes);
65
64
  if (result.status === FrameReadStatus.COMPLETE) {
66
- hasReadFrame = true;
67
65
  this.handleFrame(uuid, result.frame);
66
+ this.answerFrame(result.frame);
68
67
  continue;
69
68
  }
70
69
  if (result.status === FrameReadStatus.CORRUPT) {
@@ -74,9 +73,6 @@ export class BTDataProcessor {
74
73
  break;
75
74
  }
76
75
  }
77
- if (hasReadFrame) {
78
- this.callbacks.onSendCommandToDevice?.();
79
- }
80
76
  };
81
77
 
82
78
  /**
@@ -88,7 +84,22 @@ export class BTDataProcessor {
88
84
  }
89
85
  this.handleFrame(uuid, buffer);
90
86
  this.buffers.set(this.currentUuid, []);
91
- this.callbacks.onSendCommandToDevice?.();
87
+ this.answerFrame(buffer);
88
+ };
89
+
90
+ /**
91
+ * Answers one complete frame with whatever the device's sequencer decides.
92
+ *
93
+ * Every frame is offered, including one that matched no parsing case. An identity reply
94
+ * and a file-transfer chunk carry no measurement, and a sequencer that never saw them
95
+ * could not take the step that follows - the exchange would stop dead on the first frame
96
+ * that was protocol rather than data.
97
+ */
98
+ answerFrame = frame => {
99
+ const commands = this.callbacks.nextCommand?.(frame);
100
+ if (commands && commands.length > 0) {
101
+ this.callbacks.sendCommands?.(commands);
102
+ }
92
103
  };
93
104
  handleFrame = (uuid, frame) => {
94
105
  const data = this.frameParser.parse(uuid, frame);
@@ -1 +1 @@
1
- {"version":3,"names":["sentryLogger","CaseType","FrameReadStatus","FrameParser","MeasurementStateMachine","BTDataProcessor","buffers","Map","constructor","device","mainServices","stuckDataTimeoutDuration","callbacks","frameReader","frameParser","measurementState","onStatusChanged","onStreamStart","onResult","currentUuid","destroy","clear","reset","clearTimeout","stuckDataTimeout","undefined","processData","uuid","hexValue","String","toLowerCase","buffer","get","push","set","startStuckTimeout","readFramesFromBuffer","readWholeBuffer","reader","hasReadFrame","length","result","readFrame","hasProgressed","consumedBytes","splice","status","COMPLETE","handleFrame","frame","CORRUPT","reportCorruptFrame","INCOMPLETE","onSendCommandToDevice","validatePackage","data","parse","join","dependentData","parsingCase","caseType","DEPENDENT","handleDependentResult","advance","onError","Error","cause","message","setTimeout","cancelConnection"],"sourceRoot":"../../../../../../src","sources":["modules/bt-management/services/devices/bt-data-processor.ts"],"mappings":";;AAGA,SAASA,YAAY,QAAQ,yCAAsC;AACnE,SAASC,QAAQ,QAAQ,0BAAuB;AAGhD,SAASC,eAAe,QAAQ,kCAA+B;AAK/D,SAASC,WAAW,QAAQ,mBAAgB;AAC5C,SAASC,uBAAuB,QAAQ,gCAA6B;AAoBrE,OAAO,MAAMC,eAAe,CAAwB;EAClD;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACU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,gBAAgB,GAAG4C,UAAU,CAAC,MAAM;MACvC,IAAI,CAACxD,SAAS,CAACoD,OAAO,GACpB,IAAIC,KAAK,CAAC,2CAA2C,EAAE;QACrDC,KAAK,EAAE;UACLC,OAAO,EAAE;QACX;MACF,CAAC,CACH,CAAC;MACD,IAAI,CAAC1D,MAAM,CAAC4D,gBAAgB,GAAG,CAAC;IAClC,CAAC,EAAE,IAAI,CAAC1D,wBAAwB,CAAC;EACnC,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"names":["sentryLogger","CaseType","FrameReadStatus","FrameParser","MeasurementStateMachine","BTDataProcessor","buffers","Map","constructor","device","mainServices","stuckDataTimeoutDuration","callbacks","frameReader","frameParser","measurementState","onStatusChanged","onStreamStart","onResult","currentUuid","destroy","clear","reset","clearTimeout","stuckDataTimeout","undefined","processData","uuid","hexValue","String","toLowerCase","buffer","get","push","set","startStuckTimeout","readFramesFromBuffer","readWholeBuffer","reader","length","result","readFrame","hasProgressed","consumedBytes","splice","status","COMPLETE","handleFrame","frame","answerFrame","CORRUPT","reportCorruptFrame","INCOMPLETE","validatePackage","commands","nextCommand","sendCommands","data","parse","join","dependentData","parsingCase","caseType","DEPENDENT","handleDependentResult","advance","onError","Error","cause","message","setTimeout","cancelConnection"],"sourceRoot":"../../../../../../src","sources":["modules/bt-management/services/devices/bt-data-processor.ts"],"mappings":";;AAGA,SAASA,YAAY,QAAQ,yCAAsC;AACnE,SAASC,QAAQ,QAAQ,0BAAuB;AAIhD,SAASC,eAAe,QAAQ,kCAA+B;AAK/D,SAASC,WAAW,QAAQ,mBAAgB;AAC5C,SAASC,uBAAuB,QAAQ,gCAA6B;AAgCrE,OAAO,MAAMC,eAAe,CAAwB;EAClD;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACUC,OAAO,GAAG,IAAIC,GAAG,CAAmB,CAAC;EAI7CC,WAAWA,CACQC,MAAc,EAC/BC,YAA2C,EAC1BC,wBAAgC,EAChCC,SAAoC,EACpCC,WAA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AE;MACzBD,YAAY,CAAC,IAAI,CAACC,gBAAgB,CAAC;IACrC;IAEA,IAAI,CAACA,gBAAgB,GAAG8C,UAAU,CAAC,MAAM;MACvC,IAAI,CAAC1D,SAAS,CAACsD,OAAO,GACpB,IAAIC,KAAK,CAAC,2CAA2C,EAAE;QACrDC,KAAK,EAAE;UACLC,OAAO,EAAE;QACX;MACF,CAAC,CACH,CAAC;MACD,IAAI,CAAC5D,MAAM,CAAC8D,gBAAgB,GAAG,CAAC;IAClC,CAAC,EAAE,IAAI,CAAC5D,wBAAwB,CAAC;EACnC,CAAC;AACH","ignoreList":[]}
@@ -2,8 +2,11 @@
2
2
 
3
3
  import { sentryLogger } from "../../../helpers/utils/sentry-logger.js";
4
4
  import { DeviceStatus } from "../../types/device-status.js";
5
+ import { summariseMeasurementForLog } from "../../utils/summarise-measurement-for-log.js";
6
+ import { supportedMeasurementTypeKeys } from "../../utils/supported-measurement-type-keys.js";
5
7
  import { BTConnectionHandler } from "./bt-connection-handler.js";
6
8
  import { BTDataProcessor } from "./bt-data-processor.js";
9
+ import { pollingSequencerFor } from "./polling-command-sequencer.js";
7
10
  export class BTManagedDevice {
8
11
  /**
9
12
  * The timeout in milliseconds for the stuck data.
@@ -18,6 +21,17 @@ export class BTManagedDevice {
18
21
  * @returns The handled data.
19
22
  */
20
23
 
24
+ /**
25
+ * Builds the policy that decides what to send this device, and when.
26
+ *
27
+ * A factory rather than an instance, because a sequencer carries the state of the
28
+ * exchange - whether the device has identified itself, how far a file read has got. One
29
+ * shared across connections would resume a conversation the device has forgotten.
30
+ *
31
+ * A device that leaves this undefined polls with the command its services declare, which
32
+ * is what every device did before a policy could be expressed at all.
33
+ */
34
+
21
35
  /**
22
36
  * Locates frame boundaries inside the notification buffer.
23
37
  *
@@ -91,10 +105,7 @@ export class BTManagedDevice {
91
105
  ...data
92
106
  }) => {
93
107
  sentryLogger("info", "BT_MANAGER: Calling onResult callback", {
94
- data: {
95
- ...data,
96
- diagramPoints: "diagramPoints" in data ? data.diagramPoints.length : undefined
97
- },
108
+ data: summariseMeasurementForLog(data),
98
109
  deviceData: this.deviceData,
99
110
  deviceName: this.deviceData.name
100
111
  });
@@ -118,7 +129,8 @@ export class BTManagedDevice {
118
129
  };
119
130
  connect = async () => {
120
131
  // To access the abstract property in the constructor, we need to set it here
121
- this.deviceData.measurementTypes = this.getSupportedMeasurementTypeKeys();
132
+ this.deviceData.measurementTypes = supportedMeasurementTypeKeys(this.mainServices);
133
+ const sequencer = this.createCommandSequencer?.() ?? pollingSequencerFor(this.mainServices);
122
134
  this.connectionHandler = new BTConnectionHandler(this.device, this.mainServices, {
123
135
  onStatusChanged: status => {
124
136
  this.onDeviceStatusChanged?.bind(this)(status);
@@ -130,7 +142,8 @@ export class BTManagedDevice {
130
142
  onError: error => this.onError?.bind(this)(error),
131
143
  onDataReceived: (uuid, hexValue) => {
132
144
  this.dataProcessor?.processData(uuid, hexValue);
133
- }
145
+ },
146
+ initialCommands: () => sequencer.initialCommands()
134
147
  }, this.preferredMtu);
135
148
  this.dataProcessor = new BTDataProcessor(this.device, this.mainServices, this.stuckDataTimeout, {
136
149
  onStatusChanged: this.onDeviceStatusChanged?.bind(this),
@@ -143,18 +156,12 @@ export class BTManagedDevice {
143
156
  this.onError?.bind(this)(error);
144
157
  }
145
158
  },
146
- onSendCommandToDevice: this.connectionHandler?.sendCommandToDevice?.bind(this),
159
+ nextCommand: frame => sequencer.nextCommand(frame),
160
+ sendCommands: commands => void this.connectionHandler?.sendCommands(commands),
147
161
  onError: this.onError?.bind(this),
148
162
  handleDependentResult: this.handleDependentResult?.bind(this)
149
163
  }, this.frameReader);
150
164
  await this.connectionHandler.connect();
151
165
  };
152
- getSupportedMeasurementTypeKeys = () => {
153
- const measurementTypes = this.mainServices.flatMap(service => {
154
- return service.monitorUuids.flatMap(uuid => uuid.parsingModel.cases.map(c => c.measurementTypeKey) || []);
155
- }).filter(type => type !== undefined);
156
- const uniqueMeasurementTypes = [...new Set(measurementTypes.flat())];
157
- return uniqueMeasurementTypes;
158
- };
159
166
  }
160
167
  //# sourceMappingURL=bt-managed-device.js.map