@ovok/native 1.17.0-dev.2211 → 1.17.0-dev.2215

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 (145) hide show
  1. package/lib/commonjs/modules/next/bluetooth/adapters/ble-plx-central.js +45 -24
  2. package/lib/commonjs/modules/next/bluetooth/adapters/ble-plx-central.js.map +1 -1
  3. package/lib/commonjs/modules/next/bluetooth/adapters/web-bluetooth-central.js +9 -1
  4. package/lib/commonjs/modules/next/bluetooth/adapters/web-bluetooth-central.js.map +1 -1
  5. package/lib/commonjs/modules/next/bluetooth/core/device-link.js +2 -1
  6. package/lib/commonjs/modules/next/bluetooth/core/device-link.js.map +1 -1
  7. package/lib/commonjs/modules/next/bluetooth/families/built-in.js +3 -2
  8. package/lib/commonjs/modules/next/bluetooth/families/built-in.js.map +1 -1
  9. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/am5.js +32 -0
  10. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/am5.js.map +1 -0
  11. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/bind.js +67 -0
  12. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/bind.js.map +1 -0
  13. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/block-reader.js +48 -0
  14. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/block-reader.js.map +1 -0
  15. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/block.js +57 -0
  16. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/block.js.map +1 -0
  17. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/commands.js +105 -0
  18. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/commands.js.map +1 -0
  19. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/connection.js +27 -0
  20. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/connection.js.map +1 -0
  21. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/device-info.js +39 -0
  22. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/device-info.js.map +1 -0
  23. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/frame.js +71 -0
  24. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/frame.js.map +1 -0
  25. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/history.js +69 -0
  26. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/history.js.map +1 -0
  27. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/ihealth-band.js +17 -0
  28. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/ihealth-band.js.map +1 -0
  29. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/live.js +42 -0
  30. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/live.js.map +1 -0
  31. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/models.js +18 -0
  32. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/models.js.map +1 -0
  33. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/records.js +99 -0
  34. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/records.js.map +1 -0
  35. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/replies.js +94 -0
  36. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/replies.js.map +1 -0
  37. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/session.js +71 -0
  38. package/lib/commonjs/modules/next/bluetooth/families/ihealth-band/session.js.map +1 -0
  39. package/lib/module/modules/next/bluetooth/adapters/ble-plx-central.js +45 -24
  40. package/lib/module/modules/next/bluetooth/adapters/ble-plx-central.js.map +1 -1
  41. package/lib/module/modules/next/bluetooth/adapters/web-bluetooth-central.js +9 -1
  42. package/lib/module/modules/next/bluetooth/adapters/web-bluetooth-central.js.map +1 -1
  43. package/lib/module/modules/next/bluetooth/core/device-link.js +2 -1
  44. package/lib/module/modules/next/bluetooth/core/device-link.js.map +1 -1
  45. package/lib/module/modules/next/bluetooth/families/built-in.js +3 -2
  46. package/lib/module/modules/next/bluetooth/families/built-in.js.map +1 -1
  47. package/lib/module/modules/next/bluetooth/families/ihealth-band/am5.js +30 -0
  48. package/lib/module/modules/next/bluetooth/families/ihealth-band/am5.js.map +1 -0
  49. package/lib/module/modules/next/bluetooth/families/ihealth-band/bind.js +63 -0
  50. package/lib/module/modules/next/bluetooth/families/ihealth-band/bind.js.map +1 -0
  51. package/lib/module/modules/next/bluetooth/families/ihealth-band/block-reader.js +44 -0
  52. package/lib/module/modules/next/bluetooth/families/ihealth-band/block-reader.js.map +1 -0
  53. package/lib/module/modules/next/bluetooth/families/ihealth-band/block.js +52 -0
  54. package/lib/module/modules/next/bluetooth/families/ihealth-band/block.js.map +1 -0
  55. package/lib/module/modules/next/bluetooth/families/ihealth-band/commands.js +92 -0
  56. package/lib/module/modules/next/bluetooth/families/ihealth-band/commands.js.map +1 -0
  57. package/lib/module/modules/next/bluetooth/families/ihealth-band/connection.js +24 -0
  58. package/lib/module/modules/next/bluetooth/families/ihealth-band/connection.js.map +1 -0
  59. package/lib/module/modules/next/bluetooth/families/ihealth-band/device-info.js +33 -0
  60. package/lib/module/modules/next/bluetooth/families/ihealth-band/device-info.js.map +1 -0
  61. package/lib/module/modules/next/bluetooth/families/ihealth-band/frame.js +64 -0
  62. package/lib/module/modules/next/bluetooth/families/ihealth-band/frame.js.map +1 -0
  63. package/lib/module/modules/next/bluetooth/families/ihealth-band/history.js +67 -0
  64. package/lib/module/modules/next/bluetooth/families/ihealth-band/history.js.map +1 -0
  65. package/lib/module/modules/next/bluetooth/families/ihealth-band/ihealth-band.js +9 -0
  66. package/lib/module/modules/next/bluetooth/families/ihealth-band/ihealth-band.js.map +1 -0
  67. package/lib/module/modules/next/bluetooth/families/ihealth-band/live.js +39 -0
  68. package/lib/module/modules/next/bluetooth/families/ihealth-band/live.js.map +1 -0
  69. package/lib/module/modules/next/bluetooth/families/ihealth-band/models.js +16 -0
  70. package/lib/module/modules/next/bluetooth/families/ihealth-band/models.js.map +1 -0
  71. package/lib/module/modules/next/bluetooth/families/ihealth-band/records.js +94 -0
  72. package/lib/module/modules/next/bluetooth/families/ihealth-band/records.js.map +1 -0
  73. package/lib/module/modules/next/bluetooth/families/ihealth-band/replies.js +85 -0
  74. package/lib/module/modules/next/bluetooth/families/ihealth-band/replies.js.map +1 -0
  75. package/lib/module/modules/next/bluetooth/families/ihealth-band/session.js +68 -0
  76. package/lib/module/modules/next/bluetooth/families/ihealth-band/session.js.map +1 -0
  77. package/lib/typescript/commonjs/src/modules/next/bluetooth/adapters/ble-plx-central.d.ts.map +1 -1
  78. package/lib/typescript/commonjs/src/modules/next/bluetooth/adapters/web-bluetooth-central.d.ts +4 -0
  79. package/lib/typescript/commonjs/src/modules/next/bluetooth/adapters/web-bluetooth-central.d.ts.map +1 -1
  80. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/built-in.d.ts.map +1 -1
  81. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/am5.d.ts +6 -0
  82. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/am5.d.ts.map +1 -0
  83. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/bind.d.ts +6 -0
  84. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/bind.d.ts.map +1 -0
  85. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/block-reader.d.ts +6 -0
  86. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/block-reader.d.ts.map +1 -0
  87. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/block.d.ts +18 -0
  88. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/block.d.ts.map +1 -0
  89. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/commands.d.ts +43 -0
  90. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/commands.d.ts.map +1 -0
  91. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/connection.d.ts +15 -0
  92. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/connection.d.ts.map +1 -0
  93. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/device-info.d.ts +10 -0
  94. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/device-info.d.ts.map +1 -0
  95. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/frame.d.ts +31 -0
  96. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/frame.d.ts.map +1 -0
  97. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/history.d.ts +6 -0
  98. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/history.d.ts.map +1 -0
  99. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/ihealth-band.d.ts +6 -0
  100. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/ihealth-band.d.ts.map +1 -0
  101. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/live.d.ts +6 -0
  102. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/live.d.ts.map +1 -0
  103. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/models.d.ts +5 -0
  104. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/models.d.ts.map +1 -0
  105. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/records.d.ts +8 -0
  106. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/records.d.ts.map +1 -0
  107. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/replies.d.ts +29 -0
  108. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/replies.d.ts.map +1 -0
  109. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/session.d.ts +21 -0
  110. package/lib/typescript/commonjs/src/modules/next/bluetooth/families/ihealth-band/session.d.ts.map +1 -0
  111. package/lib/typescript/module/src/modules/next/bluetooth/adapters/ble-plx-central.d.ts.map +1 -1
  112. package/lib/typescript/module/src/modules/next/bluetooth/adapters/web-bluetooth-central.d.ts +4 -0
  113. package/lib/typescript/module/src/modules/next/bluetooth/adapters/web-bluetooth-central.d.ts.map +1 -1
  114. package/lib/typescript/module/src/modules/next/bluetooth/families/built-in.d.ts.map +1 -1
  115. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/am5.d.ts +6 -0
  116. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/am5.d.ts.map +1 -0
  117. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/bind.d.ts +6 -0
  118. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/bind.d.ts.map +1 -0
  119. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/block-reader.d.ts +6 -0
  120. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/block-reader.d.ts.map +1 -0
  121. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/block.d.ts +18 -0
  122. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/block.d.ts.map +1 -0
  123. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/commands.d.ts +43 -0
  124. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/commands.d.ts.map +1 -0
  125. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/connection.d.ts +15 -0
  126. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/connection.d.ts.map +1 -0
  127. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/device-info.d.ts +10 -0
  128. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/device-info.d.ts.map +1 -0
  129. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/frame.d.ts +31 -0
  130. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/frame.d.ts.map +1 -0
  131. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/history.d.ts +6 -0
  132. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/history.d.ts.map +1 -0
  133. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/ihealth-band.d.ts +6 -0
  134. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/ihealth-band.d.ts.map +1 -0
  135. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/live.d.ts +6 -0
  136. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/live.d.ts.map +1 -0
  137. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/models.d.ts +5 -0
  138. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/models.d.ts.map +1 -0
  139. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/records.d.ts +8 -0
  140. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/records.d.ts.map +1 -0
  141. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/replies.d.ts +29 -0
  142. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/replies.d.ts.map +1 -0
  143. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/session.d.ts +21 -0
  144. package/lib/typescript/module/src/modules/next/bluetooth/families/ihealth-band/session.d.ts.map +1 -0
  145. package/package.json +1 -1
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.stopSyncCommand = exports.startSyncCommand = exports.setTimeCommand = exports.liveDataCommand = exports.functionTableCommand = exports.blockRequestCommand = exports.blockAckCommand = exports.bindCommand = exports.basicInfoCommand = exports.authCommand = exports.HEALTH_KEY = exports.BLOCK_PHASE = exports.BIND_KEY = void 0;
7
+ var _bytes = require("../../codec/bytes.js");
8
+ var _frame = require("./frame.js");
9
+ const BIND_KEY = exports.BIND_KEY = {
10
+ bind: 0x01,
11
+ auth: 0x03,
12
+ rejected: 0x04
13
+ };
14
+ const READ_KEY = {
15
+ basicInfo: 0x01,
16
+ functionTable: 0x02,
17
+ liveData: 0xa0
18
+ };
19
+ const SET_TIME_KEY = 0x01;
20
+
21
+ /** Keys of the health class: the sync's own, then the block of each kind of stored day, then the end of a block. */
22
+ const HEALTH_KEY = exports.HEALTH_KEY = {
23
+ start: 0x01,
24
+ stop: 0x02,
25
+ sportToday: 0x03,
26
+ sportHistory: 0x05,
27
+ heartRateToday: 0x07,
28
+ heartRateHistory: 0x08,
29
+ blockEnd: 0xee
30
+ };
31
+
32
+ /** The byte after a health key: 1 asks for a block and starts its first header, 2 ends a block and starts its second header. */
33
+ const BLOCK_PHASE = exports.BLOCK_PHASE = {
34
+ first: 0x01,
35
+ second: 0x02
36
+ };
37
+ const BIND_MARKER = [0xf1, 0x01];
38
+
39
+ /** What the phone says about itself when it binds, as the band's own app does. */
40
+ const BIND_PARAMETERS = {
41
+ version: 1,
42
+ osType: 2,
43
+ osVersion: 2,
44
+ cleanData: 1
45
+ };
46
+
47
+ /** What the phone says about itself when it sends the pairing code, as the band's own app does. */
48
+ const AUTH_PARAMETERS = {
49
+ osType: 1,
50
+ osVersion: 2,
51
+ cleanData: 1
52
+ };
53
+
54
+ /** The pairing code has one byte per digit, zero padded to this many. */
55
+ const AUTH_CODE_BYTES = 8;
56
+ const SYNC_MODE = 0x01;
57
+ const RESERVED = 0x00;
58
+ const FROM_THE_FIRST_ITEM = 0;
59
+ const DAYS_PER_WEEK = 7;
60
+
61
+ /** Monday is 0 and Sunday 6, as the band's own app counts. */
62
+ const weekdayOf = date => (date.getDay() + DAYS_PER_WEEK - 1) % DAYS_PER_WEEK;
63
+
64
+ /** Starts a bind; the band answers, or asks for the pairing code. */
65
+ const bindCommand = () => (0, _frame.command)(_frame.COMMAND_CLASS.bind, BIND_KEY.bind, [...BIND_MARKER, BIND_PARAMETERS.version, BIND_PARAMETERS.osType, BIND_PARAMETERS.osVersion, BIND_PARAMETERS.cleanData]);
66
+
67
+ /** Sends the pairing code the band shows, one byte per digit. */
68
+ exports.bindCommand = bindCommand;
69
+ const authCommand = digits => (0, _frame.command)(_frame.COMMAND_CLASS.bind, BIND_KEY.auth, [AUTH_PARAMETERS.osType, AUTH_PARAMETERS.osVersion, AUTH_PARAMETERS.cleanData, digits.length, ...Array.from({
70
+ length: AUTH_CODE_BYTES
71
+ }, (_, index) => digits[index] ?? 0)]);
72
+
73
+ /** Sets the band's clock to the local time of `now`. */
74
+ exports.authCommand = authCommand;
75
+ const setTimeCommand = now => (0, _frame.command)(_frame.COMMAND_CLASS.setting, SET_TIME_KEY, [...(0, _bytes.u16leBytes)(now.getFullYear()), now.getMonth() + 1, now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds(), weekdayOf(now)]);
76
+
77
+ /** Asks for the basic info: firmware, battery and whether the band is bound. */
78
+ exports.setTimeCommand = setTimeCommand;
79
+ const basicInfoCommand = () => (0, _frame.command)(_frame.COMMAND_CLASS.read, READ_KEY.basicInfo);
80
+
81
+ /** Asks for the table of features the band has. */
82
+ exports.basicInfoCommand = basicInfoCommand;
83
+ const functionTableCommand = () => (0, _frame.command)(_frame.COMMAND_CLASS.read, READ_KEY.functionTable);
84
+
85
+ /** Asks for the running counters. */
86
+ exports.functionTableCommand = functionTableCommand;
87
+ const liveDataCommand = () => (0, _frame.command)(_frame.COMMAND_CLASS.read, READ_KEY.liveData);
88
+
89
+ /** Starts a health sync; the band answers with how many days of each kind it holds. */
90
+ exports.liveDataCommand = liveDataCommand;
91
+ const startSyncCommand = () => (0, _frame.command)(_frame.COMMAND_CLASS.health, HEALTH_KEY.start, [SYNC_MODE, RESERVED]);
92
+
93
+ /** Ends a health sync. */
94
+ exports.startSyncCommand = startSyncCommand;
95
+ const stopSyncCommand = () => (0, _frame.command)(_frame.COMMAND_CLASS.health, HEALTH_KEY.stop, [RESERVED]);
96
+
97
+ /** Asks for one block, from its first item. */
98
+ exports.stopSyncCommand = stopSyncCommand;
99
+ const blockRequestCommand = key => (0, _frame.command)(_frame.COMMAND_CLASS.health, key, [BLOCK_PHASE.first, ...(0, _bytes.u16leBytes)(FROM_THE_FIRST_ITEM)]);
100
+
101
+ /** Tells the band the block of `key` arrived. */
102
+ exports.blockRequestCommand = blockRequestCommand;
103
+ const blockAckCommand = key => (0, _frame.command)(_frame.COMMAND_CLASS.health, key, [BLOCK_PHASE.second]);
104
+ exports.blockAckCommand = blockAckCommand;
105
+ //# sourceMappingURL=commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_bytes","require","_frame","BIND_KEY","exports","bind","auth","rejected","READ_KEY","basicInfo","functionTable","liveData","SET_TIME_KEY","HEALTH_KEY","start","stop","sportToday","sportHistory","heartRateToday","heartRateHistory","blockEnd","BLOCK_PHASE","first","second","BIND_MARKER","BIND_PARAMETERS","version","osType","osVersion","cleanData","AUTH_PARAMETERS","AUTH_CODE_BYTES","SYNC_MODE","RESERVED","FROM_THE_FIRST_ITEM","DAYS_PER_WEEK","weekdayOf","date","getDay","bindCommand","command","COMMAND_CLASS","authCommand","digits","length","Array","from","_","index","setTimeCommand","now","setting","u16leBytes","getFullYear","getMonth","getDate","getHours","getMinutes","getSeconds","basicInfoCommand","read","functionTableCommand","liveDataCommand","startSyncCommand","health","stopSyncCommand","blockRequestCommand","key","blockAckCommand"],"sourceRoot":"../../../../../../../src","sources":["modules/next/bluetooth/families/ihealth-band/commands.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAEA,MAAME,QAAQ,GAAAC,OAAA,CAAAD,QAAA,GAAG;EAAEE,IAAI,EAAE,IAAI;EAAEC,IAAI,EAAE,IAAI;EAAEC,QAAQ,EAAE;AAAK,CAAU;AACpE,MAAMC,QAAQ,GAAG;EAAEC,SAAS,EAAE,IAAI;EAAEC,aAAa,EAAE,IAAI;EAAEC,QAAQ,EAAE;AAAK,CAAU;AAClF,MAAMC,YAAY,GAAG,IAAI;;AAEzB;AACA,MAAMC,UAAU,GAAAT,OA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GAAGA,CAAA,KAAa,IAAAtB,cAAO,EAACC,oBAAa,CAACmB,IAAI,EAAEpD,QAAQ,CAACG,QAAQ,CAAC;;AAEnF;AAAAP,OAAA,CAAA0D,eAAA,GAAAA,eAAA;AACA,MAAMC,gBAAgB,GAAGA,CAAA,KAAa,IAAAvB,cAAO,EAACC,oBAAa,CAACuB,MAAM,EAAEnD,UAAU,CAACC,KAAK,EAAE,CAACkB,SAAS,EAAEC,QAAQ,CAAC,CAAC;;AAE5G;AAAA7B,OAAA,CAAA2D,gBAAA,GAAAA,gBAAA;AACA,MAAME,eAAe,GAAGA,CAAA,KAAa,IAAAzB,cAAO,EAACC,oBAAa,CAACuB,MAAM,EAAEnD,UAAU,CAACE,IAAI,EAAE,CAACkB,QAAQ,CAAC,CAAC;;AAE/F;AAAA7B,OAAA,CAAA6D,eAAA,GAAAA,eAAA;AACA,MAAMC,mBAAmB,GAAIC,GAAW,IACtC,IAAA3B,cAAO,EAACC,oBAAa,CAACuB,MAAM,EAAEG,GAAG,EAAE,CAAC9C,WAAW,CAACC,KAAK,EAAE,GAAG,IAAA8B,iBAAU,EAAClB,mBAAmB,CAAC,CAAC,CAAC;;AAE7F;AAAA9B,OAAA,CAAA8D,mBAAA,GAAAA,mBAAA;AACA,MAAME,eAAe,GAAID,GAAW,IAAY,IAAA3B,cAAO,EAACC,oBAAa,CAACuB,MAAM,EAAEG,GAAG,EAAE,CAAC9C,WAAW,CAACE,MAAM,CAAC,CAAC;AAACnB,OAAA,CAAAgE,eAAA,GAAAA,eAAA","ignoreList":[]}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.openBand = void 0;
7
+ var _bind = require("./bind.js");
8
+ var _session = require("./session.js");
9
+ /** What a protocol keeps of an open link to a band. */
10
+
11
+ /** Opens the session and binds a band that is not yet bound. */
12
+ const openBand = async context => {
13
+ const session = await (0, _session.openSession)(context);
14
+ try {
15
+ await (0, _bind.bindIfUnbound)(session, context.secret);
16
+ } catch (error) {
17
+ session.stop();
18
+ throw error;
19
+ }
20
+ return {
21
+ ...session,
22
+ logger: context.logger,
23
+ now: context.now
24
+ };
25
+ };
26
+ exports.openBand = openBand;
27
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_bind","require","_session","openBand","context","session","openSession","bindIfUnbound","secret","error","stop","logger","now","exports"],"sourceRoot":"../../../../../../../src","sources":["modules/next/bluetooth/families/ihealth-band/connection.ts"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAEA;;AAUA;AACA,MAAME,QAAQ,GAAG,MAAOC,OAAwB,IAA8B;EAC5E,MAAMC,OAAO,GAAG,MAAM,IAAAC,oBAAW,EAACF,OAAO,CAAC;EAE1C,IAAI;IACF,MAAM,IAAAG,mBAAa,EAACF,OAAO,EAAED,OAAO,CAACI,MAAM,CAAC;EAC9C,CAAC,CAAC,OAAOC,KAAK,EAAE;IACdJ,OAAO,CAACK,IAAI,CAAC,CAAC;IACd,MAAMD,KAAK;EACb;EAEA,OAAO;IAAE,GAAGJ,OAAO;IAAEM,MAAM,EAAEP,OAAO,CAACO,MAAM;IAAEC,GAAG,EAAER,OAAO,CAACQ;EAAI,CAAC;AACjE,CAAC;AAACC,OAAA,CAAAV,QAAA,GAAAA,QAAA","ignoreList":[]}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.readBasicInfo = exports.identify = exports.battery = void 0;
7
+ var _commands = require("./commands.js");
8
+ var _frame = require("./frame.js");
9
+ var _replies = require("./replies.js");
10
+ /** Asks the band for its basic info. */
11
+ const readBasicInfo = async ({
12
+ request
13
+ }) => {
14
+ const asked = (0, _commands.basicInfoCommand)();
15
+ return (0, _replies.basicInfoOf)(await request(asked, (0, _frame.isEchoOf)(asked)));
16
+ };
17
+
18
+ /** The firmware number the band reports; it gives no serial, hardware, maker or model. */
19
+ exports.readBasicInfo = readBasicInfo;
20
+ const identify = async session => ({
21
+ serial: null,
22
+ firmware: String((await readBasicInfo(session)).firmware),
23
+ hardware: null,
24
+ manufacturer: null,
25
+ model: null
26
+ });
27
+ exports.identify = identify;
28
+ const battery = async session => {
29
+ const {
30
+ percent,
31
+ charging
32
+ } = await readBasicInfo(session);
33
+ return {
34
+ percent,
35
+ charging
36
+ };
37
+ };
38
+ exports.battery = battery;
39
+ //# sourceMappingURL=device-info.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_commands","require","_frame","_replies","readBasicInfo","request","asked","basicInfoCommand","basicInfoOf","isEchoOf","exports","identify","session","serial","firmware","String","hardware","manufacturer","model","battery","percent","charging"],"sourceRoot":"../../../../../../../src","sources":["modules/next/bluetooth/families/ihealth-band/device-info.ts"],"mappings":";;;;;;AAEA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAGA;AACA,MAAMG,aAAa,GAAG,MAAAA,CAAO;EAAEC;AAAiB,CAAC,KAAyB;EACxE,MAAMC,KAAK,GAAG,IAAAC,0BAAgB,EAAC,CAAC;EAEhC,OAAO,IAAAC,oBAAW,EAAC,MAAMH,OAAO,CAACC,KAAK,EAAE,IAAAG,eAAQ,EAACH,KAAK,CAAC,CAAC,CAAC;AAC3D,CAAC;;AAED;AAAAI,OAAA,CAAAN,aAAA,GAAAA,aAAA;AACA,MAAMO,QAAQ,GAAG,MAAOC,OAAgB,KAA2C;EACjFC,MAAM,EAAE,IAAI;EACZC,QAAQ,EAAEC,MAAM,CAAC,CAAC,MAAMX,aAAa,CAACQ,OAAO,CAAC,EAAEE,QAAQ,CAAC;EACzDE,QAAQ,EAAE,IAAI;EACdC,YAAY,EAAE,IAAI;EAClBC,KAAK,EAAE;AACT,CAAC,CAAC;AAACR,OAAA,CAAAC,QAAA,GAAAA,QAAA;AAEH,MAAMQ,OAAO,GAAG,MAAOP,OAAgB,IAAmC;EACxE,MAAM;IAAEQ,OAAO;IAAEC;EAAS,CAAC,GAAG,MAAMjB,aAAa,CAACQ,OAAO,CAAC;EAE1D,OAAO;IAAEQ,OAAO;IAAEC;EAAS,CAAC;AAC9B,CAAC;AAACX,OAAA,CAAAS,OAAA,GAAAA,OAAA","ignoreList":[]}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isEchoOf = exports.frameOf = exports.frameBytes = exports.command = exports.characteristicOf = exports.NOTIFY_CHARACTERISTICS = exports.COMMAND_CLASS = exports.BAND_SERVICE = void 0;
7
+ var _advertisement = require("../../core/advertisement.js");
8
+ var _errors = require("../../core/errors.js");
9
+ /** The service every frame travels on. */
10
+ const BAND_SERVICE = exports.BAND_SERVICE = (0, _advertisement.fullUuid)("0AF0");
11
+ const COMMAND_CHARACTERISTIC = (0, _advertisement.fullUuid)("0AF6");
12
+ const HEALTH_CHARACTERISTIC = (0, _advertisement.fullUuid)("0AF1");
13
+
14
+ /** The characteristics the band notifies on, in the order it wants them enabled. */
15
+ const NOTIFY_CHARACTERISTICS = exports.NOTIFY_CHARACTERISTICS = [(0, _advertisement.fullUuid)("0AF7"), (0, _advertisement.fullUuid)("0AF2")];
16
+ const MAX_FRAME_BYTES = 20;
17
+ const MAX_INCOMING_BYTES = 100;
18
+ const HEADER_BYTES = 2;
19
+
20
+ /** The first byte of a frame: what kind of exchange it belongs to. */
21
+ const COMMAND_CLASS = exports.COMMAND_CLASS = {
22
+ read: 0x02,
23
+ setting: 0x03,
24
+ bind: 0x04,
25
+ health: 0x08,
26
+ workout: 0x09
27
+ };
28
+ const OWN_CHARACTERISTIC_CLASSES = [COMMAND_CLASS.health, COMMAND_CLASS.workout];
29
+
30
+ /** One packet: its command class, its key, and the payload after them; payload offsets count from there. */
31
+
32
+ /** A frame to send, from the bytes after its key. */
33
+ const command = (commandClass, key, payload = []) => ({
34
+ commandClass,
35
+ key,
36
+ payload: Uint8Array.from(payload)
37
+ });
38
+
39
+ /** The bytes to write; fails for a frame the band would refuse as too long. */
40
+ exports.command = command;
41
+ const frameBytes = ({
42
+ commandClass,
43
+ key,
44
+ payload
45
+ }) => {
46
+ const bytes = Uint8Array.of(commandClass, key, ...payload);
47
+ if (bytes.length > MAX_FRAME_BYTES) {
48
+ throw new _errors.DeviceError("protocol", "A frame is longer than the band takes");
49
+ }
50
+ return bytes;
51
+ };
52
+
53
+ /** The frame a notification carries; `null` when it is too short or too long to be one. */
54
+ exports.frameBytes = frameBytes;
55
+ const frameOf = bytes => bytes.length < HEADER_BYTES || bytes.length > MAX_INCOMING_BYTES ? null : {
56
+ commandClass: bytes[0] ?? 0,
57
+ key: bytes[1] ?? 0,
58
+ payload: bytes.subarray(HEADER_BYTES)
59
+ };
60
+
61
+ /** Where a frame is written: health and workout data have a characteristic of their own. */
62
+ exports.frameOf = frameOf;
63
+ const characteristicOf = ({
64
+ commandClass
65
+ }) => OWN_CHARACTERISTIC_CLASSES.includes(commandClass) ? HEALTH_CHARACTERISTIC : COMMAND_CHARACTERISTIC;
66
+
67
+ /** Accepts the reply that echoes the class and key of `request`, which is how the band acknowledges it. */
68
+ exports.characteristicOf = characteristicOf;
69
+ const isEchoOf = request => reply => reply.commandClass === request.commandClass && reply.key === request.key;
70
+ exports.isEchoOf = isEchoOf;
71
+ //# sourceMappingURL=frame.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_advertisement","require","_errors","BAND_SERVICE","exports","fullUuid","COMMAND_CHARACTERISTIC","HEALTH_CHARACTERISTIC","NOTIFY_CHARACTERISTICS","MAX_FRAME_BYTES","MAX_INCOMING_BYTES","HEADER_BYTES","COMMAND_CLASS","read","setting","bind","health","workout","OWN_CHARACTERISTIC_CLASSES","command","commandClass","key","payload","Uint8Array","from","frameBytes","bytes","of","length","DeviceError","frameOf","subarray","characteristicOf","includes","isEchoOf","request","re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U,CAACI,EAAE,CAACP,YAAY,EAAEC,GAAG,EAAE,GAAGC,OAAO,CAAC;EAE1D,IAAII,KAAK,CAACE,MAAM,GAAGnB,eAAe,EAAE;IAClC,MAAM,IAAIoB,mBAAW,CAAC,UAAU,EAAE,uCAAuC,CAAC;EAC5E;EAEA,OAAOH,KAAK;AACd,CAAC;;AAED;AAAAtB,OAAA,CAAAqB,UAAA,GAAAA,UAAA;AACA,MAAMK,OAAO,GAAIJ,KAAiB,IAChCA,KAAK,CAACE,MAAM,GAAGjB,YAAY,IAAIe,KAAK,CAACE,MAAM,GAAGlB,kBAAkB,GAC5D,IAAI,GACJ;EAAEU,YAAY,EAAEM,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;EAAEL,GAAG,EAAEK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;EAAEJ,OAAO,EAAEI,KAAK,CAACK,QAAQ,CAACpB,YAAY;AAAE,CAAC;;AAEhG;AAAAP,OAAA,CAAA0B,OAAA,GAAAA,OAAA;AACA,MAAME,gBAAgB,GAAGA,CAAC;EAAEZ;AAAoB,CAAC,KAC/CF,0BAA0B,CAACe,QAAQ,CAACb,YAAY,CAAC,GAAGb,qBAAqB,GAAGD,sBAAsB;;AAEpG;AAAAF,OAAA,CAAA4B,gBAAA,GAAAA,gBAAA;AACA,MAAME,QAAQ,GACXC,OAAc,IACdC,KAAY,IACXA,KAAK,CAAChB,YAAY,KAAKe,OAAO,CAACf,YAAY,IAAIgB,KAAK,CAACf,GAAG,KAAKc,OAAO,CAACd,GAAG;AAACjB,OAAA,CAAA8B,QAAA,GAAAA,QAAA","ignoreList":[]}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.storedRecords = storedRecords;
7
+ var _blockReader = require("./block-reader.js");
8
+ var _commands = require("./commands.js");
9
+ var _frame = require("./frame.js");
10
+ var _records = require("./records.js");
11
+ var _replies = require("./replies.js");
12
+ /** One kind of stored day: the block for today, the block for each earlier day, and what a block of it holds. */
13
+
14
+ const SPORT = {
15
+ todayKey: _commands.HEALTH_KEY.sportToday,
16
+ historyKey: _commands.HEALTH_KEY.sportHistory,
17
+ storedDays: ({
18
+ sport
19
+ }) => sport,
20
+ recordsOf: _records.stepsRecords
21
+ };
22
+ const HEART_RATE = {
23
+ todayKey: _commands.HEALTH_KEY.heartRateToday,
24
+ historyKey: _commands.HEALTH_KEY.heartRateHistory,
25
+ storedDays: ({
26
+ heartRate
27
+ }) => heartRate,
28
+ recordsOf: _records.heartRateRecords
29
+ };
30
+
31
+ /** Today's block, then one history block for each earlier day the band holds. */
32
+ const blockKeysOf = (kind, days) => [kind.todayKey, ...Array(kind.storedDays(days)).fill(kind.historyKey)];
33
+
34
+ /** Sleep and blood pressure are left on the band; heart rate is read only when the band says it measures it. */
35
+ const kindsToRead = async ({
36
+ request
37
+ }) => {
38
+ const asked = (0, _commands.functionTableCommand)();
39
+ return (0, _replies.measuresHeartRate)(await request(asked, (0, _frame.isEchoOf)(asked))) ? [SPORT, HEART_RATE] : [SPORT];
40
+ };
41
+ const startSync = async ({
42
+ request
43
+ }) => {
44
+ const start = (0, _commands.startSyncCommand)();
45
+ return (0, _replies.storedDaysOf)(await request(start, (0, _frame.isEchoOf)(start)));
46
+ };
47
+ const stopSync = async ({
48
+ request,
49
+ logger
50
+ }) => {
51
+ const stop = (0, _commands.stopSyncCommand)();
52
+ await request(stop, (0, _frame.isEchoOf)(stop)).catch(() => logger.warn("ihealth-band.stop-sync.failed"));
53
+ };
54
+
55
+ /** The steps of each 15-minute slot and each heart-rate sample the band stores, as the band's blocks come. */
56
+ async function* storedRecords(connection) {
57
+ const kinds = await kindsToRead(connection);
58
+ const days = await startSync(connection);
59
+ for (const kind of kinds) {
60
+ for (const key of blockKeysOf(kind, days)) {
61
+ const block = await (0, _blockReader.readBlock)(connection, key);
62
+ if (block !== null) {
63
+ yield* kind.recordsOf(block, connection.now());
64
+ }
65
+ }
66
+ }
67
+ await stopSync(connection);
68
+ }
69
+ //# sourceMappingURL=history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_blockReader","require","_commands","_frame","_records","_replies","SPORT","todayKey","HEALTH_KEY","sportToday","historyKey","sportHistory","storedDays","sport","recordsOf","stepsRecords","HEART_RATE","heartRateToday","heartRateHistory","heartRate","heartRateRecords","blockKeysOf","kind","days","Array","fill","kindsToRead","request","asked","functionTableCommand","measuresHeartRate","isEchoOf","startSync","start","startSyncCommand","storedDaysOf","stopSync","logger","stop","stopSyncCommand","catch","warn","storedRecords","connection","kinds","key","block","readBlock","now"],"sourceRoot":"../../../../../../../src","sources":["modules/next/bluetooth/families/ihealth-band/history.ts"],"mappings":";;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAEA;;AAQA,MAAMK,KAAiB,GAAG;EACxBC,QAAQ,EAAEC,oBAAU,CAACC,UAAU;EAC/BC,UAAU,EAAEF,oBAAU,CAACG,YAAY;EACnCC,UAAU,EAAEA,CAAC;IAAEC;EAAM,CAAC,KAAKA,KAAK;EAChCC,SAAS,EAAEC;AACb,CAAC;AAED,MAAMC,UAAsB,GAAG;EAC7BT,QAAQ,EAAEC,oBAAU,CAACS,cAAc;EACnCP,UAAU,EAAEF,oBAAU,CAACU,gBAAgB;EACvCN,UAAU,EAAEA,CAAC;IAAEO;EAAU,CAAC,KAAKA,SAAS;EACxCL,SAAS,EAAEM;AACb,CAAC;;AAED;AACA,MAAMC,WAAW,GAAGA,CAACC,IAAgB,EAAEC,IAAgB,KAAe,CACpED,IAAI,CAACf,QAAQ,EACb,GAAGiB,KAAK,CAASF,IAAI,CAACV,UAAU,CAACW,IAAI,CAAC,CAAC,CAACE,IAAI,CAACH,IAAI,CAACZ,UAAU,CAAC,CAC9D;;AAED;A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K,IAAI,EAAE;QAClB,OAAOxB,IAAI,CAACR,SAAS,CAACgC,KAAK,EAAEH,UAAU,CAACK,GAAG,CAAC,CAAC,CAAC;MAChD;IACF;EACF;EAEA,MAAMZ,QAAQ,CAACO,UAAU,CAAC;AAC5B","ignoreList":[]}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "IHEALTH_BAND_MODELS", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _models.IHEALTH_BAND_MODELS;
10
+ }
11
+ });
12
+ exports.IHEALTH_BAND_PROTOCOLS = void 0;
13
+ var _am = require("./am5.js");
14
+ var _models = require("./models.js");
15
+ /** The protocols of the iHealth fitness bands: the AM5. */
16
+ const IHEALTH_BAND_PROTOCOLS = exports.IHEALTH_BAND_PROTOCOLS = [_am.AM5];
17
+ //# sourceMappingURL=ihealth-band.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_am","require","_models","IHEALTH_BAND_PROTOCOLS","exports","AM5"],"sourceRoot":"../../../../../../../src","sources":["modules/next/bluetooth/families/ihealth-band/ihealth-band.ts"],"mappings":";;;;;;;;;;;;AAEA,IAAAA,GAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAEA;AACA,MAAME,sBAAiD,GAAAC,OAAA,CAAAD,sBAAA,GAAG,CAACE,OAAG,CAAC","ignoreList":[]}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.pollHeartRate = void 0;
7
+ var _waiting = require("../sig/waiting.js");
8
+ var _commands = require("./commands.js");
9
+ var _frame = require("./frame.js");
10
+ var _replies = require("./replies.js");
11
+ /** The band gives its counters when asked and sends none by itself, so the phone asks this often. */
12
+ const LIVE_POLL_MS = 1_000;
13
+ const NO_HEART_RATE = 0;
14
+ const heartRateFrame = (heartRate, at) => ({
15
+ values: {
16
+ at,
17
+ values: {
18
+ heart_rate: {
19
+ value: heartRate,
20
+ unit: "/min"
21
+ }
22
+ },
23
+ deviceFlags: []
24
+ }
25
+ });
26
+
27
+ /** Asks for the heart rate once a second until `signal` aborts; a reading of 0 is left out. */
28
+ const pollHeartRate = async ({
29
+ request,
30
+ now
31
+ }, onFrame, signal) => {
32
+ const asked = (0, _commands.liveDataCommand)();
33
+ while (!signal.aborted) {
34
+ const heartRate = (0, _replies.liveHeartRateOf)(await request(asked, (0, _frame.isEchoOf)(asked)));
35
+ if (heartRate !== NO_HEART_RATE) {
36
+ onFrame(heartRateFrame(heartRate, now()));
37
+ }
38
+ await Promise.race([(0, _waiting.pause)(LIVE_POLL_MS), (0, _waiting.untilAborted)(signal)]);
39
+ }
40
+ };
41
+ exports.pollHeartRate = pollHeartRate;
42
+ //# sourceMappingURL=live.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_waiting","require","_commands","_frame","_replies","LIVE_POLL_MS","NO_HEART_RATE","heartRateFrame","heartRate","at","values","heart_rate","value","unit","deviceFlags","pollHeartRate","request","now","onFrame","signal","asked","liveDataCommand","aborted","liveHeartRateOf","isEchoOf","Promise","race","pause","untilAborted","exports"],"sourceRoot":"../../../../../../../src","sources":["modules/next/bluetooth/families/ihealth-band/live.ts"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAEA;AACA,MAAMI,YAAY,GAAG,KAAK;AAE1B,MAAMC,aAAa,GAAG,CAAC;AAEvB,MAAMC,cAAc,GAAGA,CAACC,SAAiB,EAAEC,EAAQ,MAAiB;EAClEC,MAAM,EAAE;IAAED,EAAE;IAAEC,MAAM,EAAE;MAAEC,UAAU,EAAE;QAAEC,KAAK,EAAEJ,SAAS;QAAEK,IAAI,EAAE;MAAO;IAAE,CAAC;IAAEC,WAAW,EAAE;EAAG;AAC5F,CAAC,CAAC;;AAEF;AACA,MAAMC,aAAa,GAAG,MAAAA,CAAO;EAAEC,OAAO;EAAEC;AAAoB,CAAC,EAAEC,OAAmC,EAAEC,MAAmB,KAAoB;EACzI,MAAMC,KAAK,GAAG,IAAAC,yBAAe,EAAC,CAAC;EAE/B,OAAO,CAACF,MAAM,CAACG,OAAO,EAAE;IACtB,MAAMd,SAAS,GAAG,IAAAe,wBAAe,EAAC,MAAMP,OAAO,CAACI,KAAK,EAAE,IAAAI,eAAQ,EAACJ,KAAK,CAAC,CAAC,CAAC;IAExE,IAAIZ,SAAS,KAAKF,aAAa,EAAE;MAC/BY,OAAO,CAACX,cAAc,CAACC,SAAS,EAAES,GAAG,CAAC,CAAC,CAAC,CAAC;IAC3C;IACA,MAAMQ,OAAO,CAACC,IAAI,CAAC,CAAC,IAAAC,cAAK,EAACtB,YAAY,CAAC,EAAE,IAAAuB,qBAAY,EAACT,MAAM,CAAC,CAAC,CAAC;EACjE;AACF,CAAC;AAACU,OAAA,CAAAd,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.IHEALTH_BAND_MODELS = void 0;
7
+ var _modelRow = require("../sig/model-row.js");
8
+ var _am = require("./am5.js");
9
+ var _frame = require("./frame.js");
10
+ /** The one band; it has no advertised name, so the service it advertises is what finds it. */
11
+ const IHEALTH_BAND_MODELS = exports.IHEALTH_BAND_MODELS = [(0, _modelRow.modelRows)(_am.AM5.id, ["activity", "blood_pressure", "heart_rate", "sleep"])("iHealth", "AM5", [], {
12
+ services: [_frame.BAND_SERVICE],
13
+ requires: [{
14
+ kind: "service",
15
+ uuid: _frame.BAND_SERVICE
16
+ }]
17
+ })];
18
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_modelRow","require","_am","_frame","IHEALTH_BAND_MODELS","exports","modelRows","AM5","id","services","BAND_SERVICE","requires","kind","uuid"],"sourceRoot":"../../../../../../../src","sources":["modules/next/bluetooth/families/ihealth-band/models.ts"],"mappings":";;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,GAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAEA;AACA,MAAMG,mBAA2C,GAAAC,OAAA,CAAAD,mBAAA,GAAG,CAClD,IAAAE,mBAAS,EAACC,OAAG,CAACC,EAAE,EAAE,CAAC,UAAU,EAAE,gBAAgB,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE;EAC7FC,QAAQ,EAAE,CAACC,mBAAY,CAAC;EACxBC,QAAQ,EAAE,CAAC;IAAEC,IAAI,EAAE,SAAS;IAAEC,IAAI,EAAEH;EAAa,CAAC;AACpD,CAAC,CAAC,CACH","ignoreList":[]}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.stepsRecords = exports.heartRateRecords = void 0;
7
+ var _bytes = require("../../codec/bytes.js");
8
+ const MS_PER_MINUTE = 60_000;
9
+
10
+ /** Every stored sport item covers this many minutes, from local midnight of its day. */
11
+ const SLOT_MINUTES = 15;
12
+ const SPORT_ITEM_BYTES = 5;
13
+ const STEPS_SHIFT = 2;
14
+ const STEPS_MASK = 0xfff;
15
+ const STEPS_UNIT = "{steps}";
16
+ const HEART_RATE_ITEM_BYTES = 2;
17
+ const NO_SAMPLE_OFFSET = 255;
18
+ const HEART_RATE_UNIT = "/min";
19
+ const midnightOf = ({
20
+ year,
21
+ month,
22
+ day
23
+ }) => new Date(year, month - 1, day);
24
+
25
+ /** The same sample read again, however the phone's zone has changed, gets the same id: it names the day by its parts. */
26
+ const idOf = (kind, {
27
+ year,
28
+ month,
29
+ day
30
+ }, minutes, value) => [kind, year, month, day, minutes, value].join("-");
31
+
32
+ /** The steps of the item at `at`: bits 2 to 13 of its 40-bit little-endian value. */
33
+ const stepsAt = (data, at) => (0, _bytes.u16le)(data, at) >> STEPS_SHIFT & STEPS_MASK;
34
+ const stepsRecord = (day, slot, steps, takenAt) => ({
35
+ id: idOf("steps", day, slot * SLOT_MINUTES, steps),
36
+ reading: {
37
+ type: "activity",
38
+ takenAt,
39
+ values: {
40
+ steps: {
41
+ value: steps,
42
+ unit: STEPS_UNIT
43
+ }
44
+ },
45
+ deviceFlags: []
46
+ }
47
+ });
48
+
49
+ /** The steps of each 15-minute slot of the day that has ended by `now` and holds steps; a slot still counting would come back under another id. */
50
+ const stepsRecords = ({
51
+ day,
52
+ data
53
+ }, now) => {
54
+ const midnight = midnightOf(day).getTime();
55
+ const slots = Array.from({
56
+ length: Math.floor(data.length / SPORT_ITEM_BYTES)
57
+ }, (_, slot) => slot);
58
+ return slots.flatMap(slot => {
59
+ const steps = stepsAt(data, slot * SPORT_ITEM_BYTES);
60
+ const takenAt = new Date(midnight + slot * SLOT_MINUTES * MS_PER_MINUTE);
61
+ const endedAt = takenAt.getTime() + SLOT_MINUTES * MS_PER_MINUTE;
62
+ return steps === 0 || endedAt > now.getTime() ? [] : [stepsRecord(day, slot, steps, takenAt)];
63
+ });
64
+ };
65
+ exports.stepsRecords = stepsRecords;
66
+ const heartRateRecord = (day, minutes, rate) => ({
67
+ id: idOf("heart-rate", day, minutes, rate),
68
+ reading: {
69
+ type: "heart_rate",
70
+ takenAt: new Date(day.year, day.month - 1, day.day, 0, minutes),
71
+ values: {
72
+ heart_rate: {
73
+ value: rate,
74
+ unit: HEART_RATE_UNIT
75
+ }
76
+ },
77
+ deviceFlags: []
78
+ }
79
+ });
80
+
81
+ /** The samples of a heart-rate day: each item gives the minutes since the one before, which add up from local midnight. */
82
+ const heartRateRecords = ({
83
+ day,
84
+ data
85
+ }) => {
86
+ const records = [];
87
+ let minutes = 0;
88
+ for (let at = 0; at + HEART_RATE_ITEM_BYTES <= data.length; at += HEART_RATE_ITEM_BYTES) {
89
+ const offset = data[at] ?? 0;
90
+ const rate = data[at + 1] ?? 0;
91
+ minutes += offset;
92
+ if (offset !== NO_SAMPLE_OFFSET && rate !== 0) {
93
+ records.push(heartRateRecord(day, minutes, rate));
94
+ }
95
+ }
96
+ return records;
97
+ };
98
+ exports.heartRateRecords = heartRateRecords;
99
+ //# sourceMappingURL=records.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_bytes","require","MS_PER_MINUTE","SLOT_MINUTES","SPORT_ITEM_BYTES","STEPS_SHIFT","STEPS_MASK","STEPS_UNIT","HEART_RATE_ITEM_BYTES","NO_SAMPLE_OFFSET","HEART_RATE_UNIT","midnightOf","year","month","day","Date","idOf","kind","minutes","value","join","stepsAt","data","at","u16le","stepsRecord","slot","steps","takenAt","id","reading","type","values","unit","deviceFlags","stepsRecords","now","midnight","getTime","slots","Array","from","length","Math","floor","_","flatMap","endedAt","exports","heartRateRecord","rate","heart_rate","heartRateRecords","records","offset","push"],"sourceRoot":"../../../../../../../src","sources":["modules/next/bluetooth/families/ihealth-band/records.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAKA,MAAMC,aAAa,GAAG,MAAM;;AAE5B;AACA,MAAMC,YAAY,GAAG,EAAE;AAEvB,MAAMC,gBAAgB,GAAG,CAAC;AAC1B,MAAMC,WAAW,GAAG,CAAC;AACrB,MAAMC,UAAU,GAAG,KAAK;AACxB,MAAMC,UAAU,GAAG,SAAS;AAE5B,MAAMC,qBAAqB,GAAG,CAAC;AAC/B,MAAMC,gBAAgB,GAAG,GAAG;AAC5B,MAAMC,eAAe,GAAG,MAAM;AAE9B,MAAMC,UAAU,GAAGA,CAAC;EAAEC,IAAI;EAAEC,KAAK;EAAEC;AAAe,CAAC,KAAW,IAAIC,IAAI,CAACH,IAAI,EAAEC,KAAK,GAAG,CAAC,EAAEC,GAAG,CAAC;;AAE5F;AACA,MAAME,IAAI,GAAGA,CAACC,IAAY,EAAE;EAAEL,IAAI;EAAE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AAGhC,IAAI,CAACC,EAAE,CAAC,IAAI,CAAC;IAC5B,MAAM2B,IAAI,GAAG5B,IAAI,CAACC,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC;IAE9BL,OAAO,IAAIoC,MAAM;IACjB,IAAIA,MAAM,KAAK7C,gBAAgB,IAAIyC,IAAI,KAAK,CAAC,EAAE;MAC7CG,OAAO,CAACE,IAAI,CAACN,eAAe,CAACnC,GAAG,EAAEI,OAAO,EAAEgC,IAAI,CAAC,CAAC;IACnD;EACF;EAEA,OAAOG,OAAO;AAChB,CAAC;AAACL,OAAA,CAAAI,gBAAA,GAAAA,gBAAA","ignoreList":[]}
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.storedDaysOf = exports.measuresHeartRate = exports.liveHeartRateOf = exports.bindAnswerOf = exports.basicInfoOf = exports.authResultOf = void 0;
7
+ var _errors = require("../../core/errors.js");
8
+ /** The most days of one kind the band reports; a larger count is read as this. */
9
+ const MAX_STORED_DAYS = 40;
10
+ const FULL_CHARGE_PERCENT = 100;
11
+ const BOUND = 1;
12
+ const HEART_RATE_FLAG = 0x20;
13
+ const BIND_AT = {
14
+ result: 0,
15
+ codeLength: 1
16
+ };
17
+ const BASIC_INFO_AT = {
18
+ firmware: 2,
19
+ chargeState: 4,
20
+ percent: 5,
21
+ bound: 6
22
+ };
23
+ const STORED_DAYS_AT = {
24
+ sport: 2,
25
+ heartRate: 4
26
+ };
27
+ const FUNCTION_FLAGS_AT = 0;
28
+ const LIVE_HEART_RATE_AT = 16;
29
+
30
+ /** The states the band reports for its charge; only some say whether it is charging. */
31
+ const CHARGE_STATE = {
32
+ normal: 0,
33
+ charging: 1,
34
+ low: 3
35
+ };
36
+ const CHARGING_BY_STATE = {
37
+ [CHARGE_STATE.normal]: false,
38
+ [CHARGE_STATE.charging]: true,
39
+ [CHARGE_STATE.low]: false
40
+ };
41
+
42
+ /** The basic info reply: the firmware number, the charge, and whether the band is bound to a phone. */
43
+
44
+ /** How many days of each kind the sync reads; the band holds more kinds, which this does not read. */
45
+
46
+ const payloadOf = ({
47
+ payload
48
+ }, atLeastBytes) => {
49
+ if (payload.length < atLeastBytes) {
50
+ throw new _errors.DeviceError("protocol", "The band sent a reply that is too short");
51
+ }
52
+ return payload;
53
+ };
54
+
55
+ /** The bind reply: its result code, and how many digits of pairing code the band wants, none when 0. */
56
+ const bindAnswerOf = reply => {
57
+ const payload = payloadOf(reply, BIND_AT.codeLength + 1);
58
+ return {
59
+ result: payload[BIND_AT.result] ?? 0,
60
+ codeLength: payload[BIND_AT.codeLength] ?? 0
61
+ };
62
+ };
63
+
64
+ /** The result code of the reply to the pairing code. */
65
+ exports.bindAnswerOf = bindAnswerOf;
66
+ const authResultOf = reply => payloadOf(reply, 1)[0] ?? 0;
67
+ exports.authResultOf = authResultOf;
68
+ const basicInfoOf = reply => {
69
+ const payload = payloadOf(reply, BASIC_INFO_AT.bound + 1);
70
+ return {
71
+ firmware: payload[BASIC_INFO_AT.firmware] ?? 0,
72
+ percent: Math.min(payload[BASIC_INFO_AT.percent] ?? 0, FULL_CHARGE_PERCENT),
73
+ charging: CHARGING_BY_STATE[payload[BASIC_INFO_AT.chargeState] ?? 0] ?? null,
74
+ bound: payload[BASIC_INFO_AT.bound] === BOUND
75
+ };
76
+ };
77
+
78
+ /** Whether the band says it measures heart rate; without it the band has no heart-rate blocks. */
79
+ exports.basicInfoOf = basicInfoOf;
80
+ const measuresHeartRate = reply => ((payloadOf(reply, 1)[FUNCTION_FLAGS_AT] ?? 0) & HEART_RATE_FLAG) !== 0;
81
+ exports.measuresHeartRate = measuresHeartRate;
82
+ const storedDaysOf = reply => {
83
+ const payload = payloadOf(reply, STORED_DAYS_AT.heartRate + 1);
84
+ return {
85
+ sport: Math.min(payload[STORED_DAYS_AT.sport] ?? 0, MAX_STORED_DAYS),
86
+ heartRate: Math.min(payload[STORED_DAYS_AT.heartRate] ?? 0, MAX_STORED_DAYS)
87
+ };
88
+ };
89
+
90
+ /** The heart rate of a live data reply, in beats per minute. */
91
+ exports.storedDaysOf = storedDaysOf;
92
+ const liveHeartRateOf = reply => payloadOf(reply, LIVE_HEART_RATE_AT + 1)[LIVE_HEART_RATE_AT] ?? 0;
93
+ exports.liveHeartRateOf = liveHeartRateOf;
94
+ //# sourceMappingURL=replies.js.map