incyclist-devices 1.5.38 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. package/README.MD +238 -0
  2. package/lib/adapters.d.ts +7 -0
  3. package/lib/adapters.js +49 -0
  4. package/lib/antv2/adapter-factory.d.ts +21 -10
  5. package/lib/antv2/adapter-factory.js +51 -33
  6. package/lib/antv2/adapter.d.ts +65 -0
  7. package/lib/antv2/adapter.js +310 -0
  8. package/lib/antv2/ant-interface.d.ts +17 -11
  9. package/lib/antv2/ant-interface.js +41 -31
  10. package/lib/antv2/{ant-binding.d.ts → binding.d.ts} +1 -1
  11. package/lib/antv2/{ant-binding.js → binding.js} +1 -1
  12. package/lib/antv2/fe/adapter.d.ts +28 -0
  13. package/lib/antv2/{fe.js → fe/adapter.js} +106 -90
  14. package/lib/antv2/fe/index.d.ts +2 -0
  15. package/lib/antv2/fe/index.js +7 -0
  16. package/lib/antv2/hr/adapter.d.ts +15 -0
  17. package/lib/antv2/hr/adapter.js +76 -0
  18. package/lib/antv2/hr/index.d.ts +2 -0
  19. package/lib/antv2/hr/index.js +7 -0
  20. package/lib/antv2/index.d.ts +7 -0
  21. package/lib/antv2/index.js +20 -0
  22. package/lib/antv2/modes/ant-fe-adv-st-mode.d.ts +9 -0
  23. package/lib/{ant/antfe → antv2/modes}/ant-fe-adv-st-mode.js +1 -1
  24. package/lib/antv2/modes/ant-fe-erg-mode.d.ts +6 -0
  25. package/lib/{ant/antfe → antv2/modes}/ant-fe-erg-mode.js +1 -1
  26. package/lib/antv2/modes/ant-fe-st-mode.d.ts +5 -0
  27. package/lib/{ant/antfe → antv2/modes}/ant-fe-st-mode.js +1 -1
  28. package/lib/antv2/pwr/adapter.d.ts +24 -0
  29. package/lib/antv2/pwr/adapter.js +141 -0
  30. package/lib/antv2/pwr/index.d.ts +2 -0
  31. package/lib/antv2/pwr/index.js +7 -0
  32. package/lib/antv2/sensor-factory.d.ts +2 -2
  33. package/lib/antv2/types.d.ts +22 -0
  34. package/lib/antv2/types.js +5 -0
  35. package/lib/antv2/utils.d.ts +4 -0
  36. package/lib/antv2/utils.js +192 -0
  37. package/lib/base/adpater.d.ts +68 -0
  38. package/lib/base/adpater.js +183 -0
  39. package/lib/ble/adapter-factory.d.ts +33 -0
  40. package/lib/ble/adapter-factory.js +105 -0
  41. package/lib/ble/base/adapter.d.ts +53 -0
  42. package/lib/ble/base/adapter.js +290 -0
  43. package/lib/ble/base/comms-utils.d.ts +7 -0
  44. package/lib/ble/base/comms-utils.js +91 -0
  45. package/lib/ble/{ble-device.d.ts → base/comms.d.ts} +31 -16
  46. package/lib/ble/{ble-device.js → base/comms.js} +193 -55
  47. package/lib/ble/bindings/index.d.ts +2 -0
  48. package/lib/ble/bindings/index.js +8 -0
  49. package/lib/ble/bindings/linux.d.ts +15 -0
  50. package/lib/ble/bindings/linux.js +39 -0
  51. package/lib/ble/bindings/mock.d.ts +9 -0
  52. package/lib/ble/bindings/mock.js +108 -0
  53. package/lib/ble/bindings/types.d.ts +57 -0
  54. package/lib/ble/bindings/types.js +96 -0
  55. package/lib/ble/ble-interface.d.ts +38 -59
  56. package/lib/ble/ble-interface.js +254 -462
  57. package/lib/ble/ble-peripheral.d.ts +7 -5
  58. package/lib/ble/ble-peripheral.js +52 -21
  59. package/lib/ble/consts.d.ts +3 -0
  60. package/lib/ble/consts.js +4 -1
  61. package/lib/ble/cp/adapter.d.ts +22 -0
  62. package/lib/ble/cp/adapter.js +111 -0
  63. package/lib/ble/cp/comm.d.ts +31 -0
  64. package/lib/ble/cp/comm.js +125 -0
  65. package/lib/ble/cp/index.d.ts +4 -0
  66. package/lib/ble/cp/index.js +10 -0
  67. package/lib/ble/cp/types.d.ts +13 -0
  68. package/lib/ble/cp/types.js +2 -0
  69. package/lib/ble/elite/adapter.d.ts +19 -0
  70. package/lib/ble/elite/adapter.js +120 -0
  71. package/lib/ble/elite/comms.d.ts +32 -0
  72. package/lib/ble/elite/comms.js +126 -0
  73. package/lib/ble/elite/index.d.ts +3 -0
  74. package/lib/ble/elite/index.js +10 -0
  75. package/lib/ble/fm/adapter.d.ts +22 -0
  76. package/lib/ble/fm/adapter.js +249 -0
  77. package/lib/ble/fm/comms.d.ts +50 -0
  78. package/lib/ble/{fm.js → fm/comms.js} +34 -277
  79. package/lib/ble/fm/consts.d.ts +6 -0
  80. package/lib/ble/fm/consts.js +9 -0
  81. package/lib/ble/fm/index.d.ts +5 -0
  82. package/lib/ble/fm/index.js +13 -0
  83. package/lib/ble/fm/types.d.ts +30 -0
  84. package/lib/ble/fm/types.js +2 -0
  85. package/lib/ble/hr/adapter.d.ts +14 -0
  86. package/lib/ble/hr/adapter.js +45 -0
  87. package/lib/ble/hr/comm.d.ts +19 -0
  88. package/lib/ble/hr/comm.js +56 -0
  89. package/lib/ble/hr/index.d.ts +4 -0
  90. package/lib/ble/hr/index.js +10 -0
  91. package/lib/ble/hr/mock.d.ts +7 -0
  92. package/lib/ble/hr/mock.js +47 -0
  93. package/lib/ble/hr/types.d.ts +5 -0
  94. package/lib/ble/hr/types.js +2 -0
  95. package/lib/ble/index.d.ts +9 -0
  96. package/lib/ble/index.js +26 -0
  97. package/lib/ble/peripheral-cache.d.ts +43 -0
  98. package/lib/ble/peripheral-cache.js +107 -0
  99. package/lib/ble/tacx/adapter.d.ts +10 -0
  100. package/lib/ble/tacx/adapter.js +99 -0
  101. package/lib/ble/{tacx.d.ts → tacx/comms.d.ts} +11 -43
  102. package/lib/ble/{tacx.js → tacx/comms.js} +23 -155
  103. package/lib/ble/tacx/index.d.ts +4 -0
  104. package/lib/ble/tacx/index.js +10 -0
  105. package/lib/ble/tacx/types.d.ts +25 -0
  106. package/lib/ble/tacx/types.js +2 -0
  107. package/lib/ble/types.d.ts +128 -0
  108. package/lib/ble/types.js +2 -0
  109. package/lib/ble/utils.d.ts +17 -0
  110. package/lib/ble/utils.js +54 -0
  111. package/lib/ble/wahoo/adapter.d.ts +9 -0
  112. package/lib/ble/wahoo/adapter.js +95 -0
  113. package/lib/ble/{wahoo-kickr.d.ts → wahoo/comms.d.ts} +11 -44
  114. package/lib/ble/{wahoo-kickr.js → wahoo/comms.js} +29 -129
  115. package/lib/ble/wahoo/index.d.ts +4 -0
  116. package/lib/ble/wahoo/index.js +10 -0
  117. package/lib/ble/wahoo/types.d.ts +19 -0
  118. package/lib/ble/wahoo/types.js +2 -0
  119. package/lib/index.d.ts +15 -0
  120. package/lib/index.js +34 -0
  121. package/lib/interfaces.d.ts +7 -0
  122. package/lib/interfaces.js +27 -0
  123. package/lib/{ble → modes}/ble-erg-mode.d.ts +4 -4
  124. package/lib/{ble → modes}/ble-erg-mode.js +2 -2
  125. package/lib/{ble → modes}/ble-st-mode.d.ts +3 -3
  126. package/lib/{ble → modes}/ble-st-mode.js +1 -1
  127. package/lib/{cycling-mode.d.ts → modes/cycling-mode.d.ts} +8 -8
  128. package/lib/modes/power-base.d.ts +3 -3
  129. package/lib/modes/power-base.js +8 -4
  130. package/lib/modes/power-meter.d.ts +3 -3
  131. package/lib/modes/simulator.d.ts +2 -2
  132. package/lib/modes/simulator.js +1 -1
  133. package/lib/serial/adapter-factory.d.ts +12 -0
  134. package/lib/serial/adapter-factory.js +30 -0
  135. package/lib/serial/adapter.d.ts +21 -0
  136. package/lib/serial/adapter.js +61 -0
  137. package/lib/serial/bindings/tcp.d.ts +45 -0
  138. package/lib/serial/bindings/tcp.js +284 -0
  139. package/lib/serial/comm.d.ts +7 -0
  140. package/lib/serial/comm.js +2 -0
  141. package/lib/{daum → serial/daum}/DaumAdapter.d.ts +14 -23
  142. package/lib/{daum → serial/daum}/DaumAdapter.js +57 -97
  143. package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.d.ts +2 -2
  144. package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.js +1 -1
  145. package/lib/{daum → serial/daum}/ERGCyclingMode.d.ts +3 -3
  146. package/lib/{daum → serial/daum}/ERGCyclingMode.js +3 -3
  147. package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.d.ts +3 -3
  148. package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.js +4 -3
  149. package/lib/serial/daum/classic/adapter.d.ts +29 -0
  150. package/lib/{daum/classic/DaumClassicAdapter.js → serial/daum/classic/adapter.js} +77 -50
  151. package/lib/{daum/classic/bike.d.ts → serial/daum/classic/comms.d.ts} +14 -16
  152. package/lib/{daum/classic/bike.js → serial/daum/classic/comms.js} +68 -152
  153. package/lib/serial/daum/classic/mock.d.ts +96 -0
  154. package/lib/serial/daum/classic/mock.js +365 -0
  155. package/lib/{daum/classic/DaumClassicCyclingMode.d.ts → serial/daum/classic/modes/daum-classic.d.ts} +3 -3
  156. package/lib/{daum/classic/DaumClassicCyclingMode.js → serial/daum/classic/modes/daum-classic.js} +2 -2
  157. package/lib/{daum → serial/daum}/classic/utils.d.ts +1 -1
  158. package/lib/serial/daum/premium/adapter.d.ts +25 -0
  159. package/lib/{daum/premium/DaumPremiumAdapter.js → serial/daum/premium/adapter.js} +107 -47
  160. package/lib/{daum/premium/bike.d.ts → serial/daum/premium/comms.d.ts} +26 -54
  161. package/lib/{daum/premium/bike.js → serial/daum/premium/comms.js} +215 -420
  162. package/lib/serial/daum/premium/mock.d.ts +75 -0
  163. package/lib/serial/daum/premium/mock.js +289 -0
  164. package/lib/{daum/premium/DaumClassicCyclingMode.d.ts → serial/daum/premium/modes/daum-classic.d.ts} +3 -3
  165. package/lib/{daum/premium/DaumClassicCyclingMode.js → serial/daum/premium/modes/daum-classic.js} +2 -2
  166. package/lib/serial/daum/premium/types.d.ts +12 -0
  167. package/lib/serial/daum/premium/types.js +2 -0
  168. package/lib/{daum → serial/daum}/premium/utils.d.ts +8 -11
  169. package/lib/{daum → serial/daum}/premium/utils.js +22 -63
  170. package/lib/serial/index.d.ts +9 -0
  171. package/lib/serial/index.js +49 -0
  172. package/lib/{kettler → serial/kettler}/comms.d.ts +8 -6
  173. package/lib/{kettler → serial/kettler}/comms.js +71 -32
  174. package/lib/{kettler → serial/kettler}/ergo-racer/adapter.d.ts +14 -28
  175. package/lib/{kettler → serial/kettler}/ergo-racer/adapter.js +102 -169
  176. package/lib/serial/kettler/ergo-racer/mock.d.ts +66 -0
  177. package/lib/serial/kettler/ergo-racer/mock.js +216 -0
  178. package/lib/{kettler/ergo-racer/ERGCyclingMode.d.ts → serial/kettler/ergo-racer/modes/erg.d.ts} +4 -4
  179. package/lib/{kettler/ergo-racer/ERGCyclingMode.js → serial/kettler/ergo-racer/modes/erg.js} +2 -2
  180. package/lib/serial/serial-interface.d.ts +60 -0
  181. package/lib/serial/serial-interface.js +309 -0
  182. package/lib/simulator/Simulator.d.ts +12 -25
  183. package/lib/simulator/Simulator.js +26 -87
  184. package/lib/types/adapter.d.ts +39 -0
  185. package/lib/types/adapter.js +2 -0
  186. package/lib/types/capabilities.d.ts +8 -0
  187. package/lib/types/capabilities.js +12 -0
  188. package/lib/types/data.d.ts +12 -0
  189. package/lib/types/data.js +2 -0
  190. package/lib/types/device.d.ts +32 -0
  191. package/lib/types/device.js +11 -0
  192. package/lib/types/interface.d.ts +18 -0
  193. package/lib/types/interface.js +2 -0
  194. package/lib/types/route.d.ts +2 -2
  195. package/lib/types/user.d.ts +1 -1
  196. package/lib/{utils.d.ts → utils/utils.d.ts} +1 -0
  197. package/lib/{utils.js → utils/utils.js} +5 -1
  198. package/package.json +16 -14
  199. package/lib/DeviceSupport.d.ts +0 -36
  200. package/lib/DeviceSupport.js +0 -82
  201. package/lib/ant/AntAdapter.d.ts +0 -50
  202. package/lib/ant/AntAdapter.js +0 -109
  203. package/lib/ant/AntScanner.d.ts +0 -60
  204. package/lib/ant/AntScanner.js +0 -651
  205. package/lib/ant/antfe/AntFEAdapter.d.ts +0 -83
  206. package/lib/ant/antfe/AntFEAdapter.js +0 -652
  207. package/lib/ant/antfe/ant-fe-adv-st-mode.d.ts +0 -9
  208. package/lib/ant/antfe/ant-fe-erg-mode.d.ts +0 -6
  209. package/lib/ant/antfe/ant-fe-st-mode.d.ts +0 -5
  210. package/lib/ant/anthrm/AntHrmAdapter.d.ts +0 -16
  211. package/lib/ant/anthrm/AntHrmAdapter.js +0 -130
  212. package/lib/ant/antpwr/pwr-adapter.d.ts +0 -49
  213. package/lib/ant/antpwr/pwr-adapter.js +0 -251
  214. package/lib/ant/utils.d.ts +0 -1
  215. package/lib/ant/utils.js +0 -23
  216. package/lib/antv2/AntAdapter.d.ts +0 -48
  217. package/lib/antv2/AntAdapter.js +0 -104
  218. package/lib/antv2/ant-device.d.ts +0 -59
  219. package/lib/antv2/ant-device.js +0 -161
  220. package/lib/antv2/fe.d.ts +0 -32
  221. package/lib/antv2/hr.d.ts +0 -18
  222. package/lib/antv2/hr.js +0 -102
  223. package/lib/antv2/incyclist-protocol.d.ts +0 -37
  224. package/lib/antv2/incyclist-protocol.js +0 -126
  225. package/lib/antv2/pwr.d.ts +0 -28
  226. package/lib/antv2/pwr.js +0 -171
  227. package/lib/ble/ble.d.ts +0 -129
  228. package/lib/ble/ble.js +0 -86
  229. package/lib/ble/elite.d.ts +0 -90
  230. package/lib/ble/elite.js +0 -322
  231. package/lib/ble/fm.d.ts +0 -125
  232. package/lib/ble/hrm.d.ts +0 -48
  233. package/lib/ble/hrm.js +0 -134
  234. package/lib/ble/incyclist-protocol.d.ts +0 -31
  235. package/lib/ble/incyclist-protocol.js +0 -153
  236. package/lib/ble/pwr.d.ts +0 -89
  237. package/lib/ble/pwr.js +0 -322
  238. package/lib/daum/classic/DaumClassicAdapter.d.ts +0 -28
  239. package/lib/daum/classic/DaumClassicProtocol.d.ts +0 -27
  240. package/lib/daum/classic/DaumClassicProtocol.js +0 -185
  241. package/lib/daum/premium/DaumPremiumAdapter.d.ts +0 -16
  242. package/lib/daum/premium/DaumPremiumProtocol.d.ts +0 -32
  243. package/lib/daum/premium/DaumPremiumProtocol.js +0 -207
  244. package/lib/daum/premium/tcpserial.d.ts +0 -33
  245. package/lib/daum/premium/tcpserial.js +0 -123
  246. package/lib/device.d.ts +0 -94
  247. package/lib/device.js +0 -76
  248. package/lib/kettler/ergo-racer/protocol.d.ts +0 -41
  249. package/lib/kettler/ergo-racer/protocol.js +0 -203
  250. package/lib/protocol.d.ts +0 -74
  251. package/lib/protocol.js +0 -41
  252. package/lib/registry.d.ts +0 -8
  253. package/lib/registry.js +0 -33
  254. package/lib/serialport/bindings/tcp.d.ts +0 -20
  255. package/lib/serialport/bindings/tcp.js +0 -33
  256. package/lib/serialport/index.d.ts +0 -2
  257. package/lib/serialport/index.js +0 -29
  258. package/lib/serialport/serialport.d.ts +0 -29
  259. package/lib/serialport/serialport.js +0 -87
  260. /package/lib/{cycling-mode.js → modes/cycling-mode.js} +0 -0
  261. /package/lib/{daum → serial/daum}/classic/utils.js +0 -0
  262. /package/lib/{daum → serial/daum}/constants.d.ts +0 -0
  263. /package/lib/{daum → serial/daum}/constants.js +0 -0
  264. /package/lib/{serialport.d.ts → serial/serialport.d.ts} +0 -0
  265. /package/lib/{serialport.js → serial/serialport.js} +0 -0
  266. /package/lib/{calculations.d.ts → utils/calculations.d.ts} +0 -0
  267. /package/lib/{calculations.js → utils/calculations.js} +0 -0
@@ -8,26 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.FmAdapter = void 0;
16
- const ble_device_1 = require("./ble-device");
17
- const ble_interface_1 = __importDefault(require("./ble-interface"));
18
- const device_1 = __importDefault(require("../device"));
19
- const gd_eventlog_1 = require("gd-eventlog");
20
- const power_meter_1 = __importDefault(require("../modes/power-meter"));
21
- const ble_st_mode_1 = __importDefault(require("./ble-st-mode"));
22
- const ble_erg_mode_1 = __importDefault(require("./ble-erg-mode"));
23
- const consts_1 = require("./consts");
24
- const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
25
- const cwABike = {
26
- race: 0.35,
27
- triathlon: 0.29,
28
- mountain: 0.57
29
- };
30
- const cRR = 0.0036;
12
+ const consts_1 = require("../consts");
13
+ const comms_1 = require("../base/comms");
31
14
  const bit = (nr) => (1 << nr);
32
15
  const IndoorBikeDataFlag = {
33
16
  MoreData: bit(0),
@@ -82,7 +65,7 @@ const TargetSettingFeatureFlag = {
82
65
  SpinDownControlSupported: bit(15),
83
66
  TargetedCadenceConfigurationSupported: bit(16)
84
67
  };
85
- class BleFitnessMachineDevice extends ble_device_1.BleDevice {
68
+ class BleFitnessMachineDevice extends comms_1.BleComms {
86
69
  constructor(props) {
87
70
  super(props);
88
71
  this.features = undefined;
@@ -96,7 +79,7 @@ class BleFitnessMachineDevice extends ble_device_1.BleDevice {
96
79
  this.data = {};
97
80
  this.services = BleFitnessMachineDevice.services;
98
81
  }
99
- isMatching(characteristics) {
82
+ static isMatching(characteristics) {
100
83
  if (!characteristics)
101
84
  return false;
102
85
  const hasStatus = characteristics.find(c => c === consts_1.FTMS_STATUS) !== undefined;
@@ -107,7 +90,7 @@ class BleFitnessMachineDevice extends ble_device_1.BleDevice {
107
90
  subscribeWriteResponse(cuuid) {
108
91
  return __awaiter(this, void 0, void 0, function* () {
109
92
  this.logEvent({ message: 'subscribe to CP response', characteristics: cuuid });
110
- const connector = this.ble.getConnector(this.peripheral);
93
+ const connector = this.ble.peripheralCache.getConnector(this.peripheral);
111
94
  const isAlreadySubscribed = connector.isSubscribed(cuuid);
112
95
  if (!isAlreadySubscribed) {
113
96
  connector.removeAllListeners(cuuid);
@@ -127,36 +110,14 @@ class BleFitnessMachineDevice extends ble_device_1.BleDevice {
127
110
  });
128
111
  }
129
112
  subscribeAll(conn) {
130
- return new Promise(resolve => {
131
- const characteristics = [consts_1.INDOOR_BIKE_DATA, consts_1.FTMS_STATUS, consts_1.FTMS_CP];
132
- const timeout = Date.now() + 5500;
133
- const iv = setInterval(() => {
134
- const subscriptionStatus = characteristics.map(c => this.subscribedCharacteristics.find(s => s === c) !== undefined);
135
- const done = subscriptionStatus.filter(s => s === true).length === characteristics.length;
136
- if (done || Date.now() > timeout) {
137
- clearInterval(iv);
138
- resolve();
139
- }
140
- }, 100);
141
- try {
142
- const connector = conn || this.ble.getConnector(this.peripheral);
143
- for (let i = 0; i < characteristics.length; i++) {
144
- const c = characteristics[i];
145
- const isAlreadySubscribed = connector.isSubscribed(c);
146
- if (!isAlreadySubscribed) {
147
- connector.removeAllListeners(c);
148
- connector.on(c, (uuid, data) => {
149
- this.onData(uuid, data);
150
- });
151
- connector.subscribe(c);
152
- this.subscribedCharacteristics.push(c);
153
- }
154
- }
155
- }
156
- catch (err) {
157
- this.logEvent({ message: 'Error', fn: 'subscribeAll()', error: err.message, stack: err.stack });
158
- }
159
- });
113
+ const characteristics = [consts_1.INDOOR_BIKE_DATA, consts_1.FTMS_STATUS, consts_1.FTMS_CP];
114
+ if (!this.features || (this.features && this.features.cadence))
115
+ characteristics.push(consts_1.CSC_MEASUREMENT);
116
+ if (!this.features || (this.features && this.features.power))
117
+ characteristics.push(consts_1.CSP_MEASUREMENT);
118
+ if (!this.features || (this.features && this.features.heartrate))
119
+ characteristics.push(consts_1.HR_MEASUREMENT);
120
+ return this.subscribeMultiple(characteristics, conn);
160
121
  }
161
122
  init() {
162
123
  const _super = Object.create(null, {
@@ -167,39 +128,32 @@ class BleFitnessMachineDevice extends ble_device_1.BleDevice {
167
128
  yield _super.initDevice.call(this);
168
129
  yield this.getFitnessMachineFeatures();
169
130
  this.logEvent({ message: 'device info', deviceInfo: this.deviceInfo, features: this.features });
131
+ return true;
170
132
  }
171
133
  catch (err) {
172
134
  this.logEvent({ message: 'error', fn: 'BleFitnessMachineDevice.init()', error: err.message || err, stack: err.stack });
173
- return Promise.resolve(false);
135
+ return false;
174
136
  }
175
137
  });
176
138
  }
177
139
  onDisconnect() {
178
- super.onDisconnect();
179
- this.hasControl = false;
140
+ const _super = Object.create(null, {
141
+ onDisconnect: { get: () => super.onDisconnect }
142
+ });
143
+ return __awaiter(this, void 0, void 0, function* () {
144
+ _super.onDisconnect.call(this);
145
+ this.hasControl = false;
146
+ });
180
147
  }
181
148
  getProfile() {
182
149
  return 'Smart Trainer';
183
150
  }
151
+ getProtocol() {
152
+ return BleFitnessMachineDevice.protocol;
153
+ }
184
154
  getServiceUUids() {
185
155
  return BleFitnessMachineDevice.services;
186
156
  }
187
- isBike() {
188
- return this.features === undefined ||
189
- ((this.features.targetSettings & TargetSettingFeatureFlag.IndoorBikeSimulationParametersSupported) !== 0);
190
- }
191
- isPower() {
192
- if (this.hasService('1818'))
193
- return true;
194
- if (this.features === undefined)
195
- return false;
196
- const { fitnessMachine } = this.features;
197
- if (fitnessMachine & FitnessMachineFeatureFlag.PowerMeasurementSupported)
198
- return true;
199
- }
200
- isHrm() {
201
- return this.hasService('180d') || (this.features && (this.features.fitnessMachine & FitnessMachineFeatureFlag.HeartRateMeasurementSupported) !== 0);
202
- }
203
157
  parseHrm(_data) {
204
158
  const data = Buffer.from(_data);
205
159
  try {
@@ -344,8 +298,14 @@ class BleFitnessMachineDevice extends ble_device_1.BleDevice {
344
298
  if (buffer) {
345
299
  const fitnessMachine = buffer.readUInt32LE(0);
346
300
  const targetSettings = buffer.readUInt32LE(4);
347
- this.features = { fitnessMachine, targetSettings };
348
- this.logEvent({ message: 'supported Features: ', fatures: this.features });
301
+ const power = (fitnessMachine & FitnessMachineFeatureFlag.PowerMeasurementSupported) !== 0;
302
+ const heartrate = (fitnessMachine & FitnessMachineFeatureFlag.HeartRateMeasurementSupported) !== 0;
303
+ const cadence = (fitnessMachine & FitnessMachineFeatureFlag.CadenceSupported) !== 0;
304
+ const setSlope = (targetSettings & TargetSettingFeatureFlag.IndoorBikeSimulationParametersSupported) !== 0
305
+ || (targetSettings & TargetSettingFeatureFlag.InclinationTargetSettingSupported) !== 0;
306
+ const setPower = (targetSettings & TargetSettingFeatureFlag.PowerTargetSettingSupported) !== 0;
307
+ this.features = { fitnessMachine, targetSettings, power, heartrate, cadence, setPower, setSlope };
308
+ this.logEvent({ message: 'supported Features: ', fatures: this.features, power, heartrate, cadence });
349
309
  }
350
310
  }
351
311
  catch (err) {
@@ -537,210 +497,7 @@ class BleFitnessMachineDevice extends ble_device_1.BleDevice {
537
497
  }
538
498
  }
539
499
  exports.default = BleFitnessMachineDevice;
500
+ BleFitnessMachineDevice.protocol = 'fm';
540
501
  BleFitnessMachineDevice.services = [consts_1.FTMS];
541
502
  BleFitnessMachineDevice.characteristics = ['2acc', consts_1.INDOOR_BIKE_DATA, '2ad6', '2ad8', consts_1.FTMS_CP, consts_1.FTMS_STATUS];
542
503
  BleFitnessMachineDevice.detectionPriority = 100;
543
- ble_interface_1.default.register('BleFitnessMachineDevice', 'fm', BleFitnessMachineDevice, BleFitnessMachineDevice.services);
544
- class FmAdapter extends device_1.default {
545
- constructor(device, protocol) {
546
- super(protocol);
547
- this.ignore = false;
548
- this.paused = false;
549
- this.distanceInternal = 0;
550
- this.device = device;
551
- this.ble = protocol.ble;
552
- this.cyclingMode = this.getDefaultCyclingMode();
553
- this.logger = new gd_eventlog_1.EventLogger('BLE-FM');
554
- if (this.device)
555
- this.device.setLogger(this.logger);
556
- }
557
- isBike() { return this.device.isBike() || this.device.isPower(); }
558
- isHrm() { return this.device.isHrm(); }
559
- isPower() { return this.device.isPower(); }
560
- isSame(device) {
561
- if (!(device instanceof FmAdapter))
562
- return false;
563
- const adapter = device;
564
- return (adapter.getName() === this.getName() && adapter.getProfile() === this.getProfile());
565
- }
566
- getProfile() {
567
- const profile = this.device ? this.device.getProfile() : undefined;
568
- return profile || 'Smart Trainer';
569
- }
570
- getName() {
571
- return `${this.device.name}`;
572
- }
573
- getDisplayName() {
574
- return this.getName();
575
- }
576
- getSupportedCyclingModes() {
577
- return [ble_st_mode_1.default, ble_erg_mode_1.default, power_meter_1.default];
578
- }
579
- setCyclingMode(mode, settings) {
580
- let selectedMode;
581
- if (typeof mode === 'string') {
582
- const supported = this.getSupportedCyclingModes();
583
- const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
584
- if (CyclingModeClass) {
585
- this.cyclingMode = new CyclingModeClass(this, settings);
586
- return;
587
- }
588
- selectedMode = this.getDefaultCyclingMode();
589
- }
590
- else {
591
- selectedMode = mode;
592
- }
593
- this.cyclingMode = selectedMode;
594
- this.cyclingMode.setSettings(settings);
595
- }
596
- getCyclingMode() {
597
- if (!this.cyclingMode)
598
- this.cyclingMode = this.getDefaultCyclingMode();
599
- return this.cyclingMode;
600
- }
601
- getDefaultCyclingMode() {
602
- return new ble_st_mode_1.default(this);
603
- }
604
- getPort() {
605
- return 'ble';
606
- }
607
- setIgnoreBike(ignore) {
608
- this.ignore = ignore;
609
- }
610
- setIgnorePower(ignore) {
611
- this.ignore = ignore;
612
- }
613
- onDeviceData(deviceData) {
614
- if (this.prevDataTS && Date.now() - this.prevDataTS < 1000)
615
- return;
616
- this.prevDataTS = Date.now();
617
- this.logger.logEvent({ message: 'onDeviceData', data: deviceData });
618
- let incyclistData = this.mapData(deviceData);
619
- incyclistData = this.getCyclingMode().updateData(incyclistData);
620
- const data = this.transformData(incyclistData);
621
- if (this.onDataFn && !this.ignore && !this.paused)
622
- this.onDataFn(data);
623
- }
624
- mapData(deviceData) {
625
- const data = {
626
- isPedalling: false,
627
- power: 0,
628
- pedalRpm: undefined,
629
- speed: 0,
630
- heartrate: 0,
631
- distanceInternal: 0,
632
- slope: undefined,
633
- time: undefined
634
- };
635
- data.power = (deviceData.instantaneousPower !== undefined ? deviceData.instantaneousPower : data.power);
636
- data.pedalRpm = (deviceData.cadence !== undefined ? deviceData.cadence : data.pedalRpm);
637
- data.time = (deviceData.time !== undefined ? deviceData.time : data.time);
638
- data.isPedalling = data.pedalRpm > 0 || (data.pedalRpm === undefined && data.power > 0);
639
- return data;
640
- }
641
- transformData(bikeData) {
642
- if (this.ignore) {
643
- return {};
644
- }
645
- if (bikeData === undefined)
646
- return;
647
- let distance = 0;
648
- if (this.distanceInternal !== undefined && bikeData.distanceInternal !== undefined) {
649
- distance = Math.round(bikeData.distanceInternal - this.distanceInternal);
650
- }
651
- if (bikeData.distanceInternal !== undefined)
652
- this.distanceInternal = bikeData.distanceInternal;
653
- let data = {
654
- speed: bikeData.speed,
655
- slope: bikeData.slope,
656
- power: bikeData.power !== undefined ? Math.round(bikeData.power) : undefined,
657
- cadence: bikeData.pedalRpm !== undefined ? Math.round(bikeData.pedalRpm) : undefined,
658
- distance,
659
- timestamp: Date.now()
660
- };
661
- return data;
662
- }
663
- start(props) {
664
- return __awaiter(this, void 0, void 0, function* () {
665
- this.logger.logEvent({ message: 'ftms: start requested', profile: this.getProfile(), props });
666
- const { restart } = props || {};
667
- if (!restart && this.ble.isScanning())
668
- yield this.ble.stopScan();
669
- try {
670
- let bleDevice;
671
- if (!this.device || !restart) {
672
- bleDevice = (yield this.ble.connectDevice(this.device));
673
- this.device = bleDevice;
674
- }
675
- else
676
- bleDevice = this.device;
677
- if (bleDevice) {
678
- bleDevice.setLogger(this.logger);
679
- const mode = this.getCyclingMode();
680
- if (mode && mode.getSetting('bikeType')) {
681
- const bikeType = mode.getSetting('bikeType').toLowerCase();
682
- this.device.setCrr(cRR);
683
- switch (bikeType) {
684
- case 'race':
685
- this.device.setCw(cwABike.race);
686
- break;
687
- case 'triathlon':
688
- this.device.setCw(cwABike.triathlon);
689
- break;
690
- case 'mountain':
691
- this.device.setCw(cwABike.mountain);
692
- break;
693
- }
694
- }
695
- let hasControl = yield this.device.requestControl();
696
- if (!hasControl) {
697
- let retry = 1;
698
- while (!hasControl && retry < 3) {
699
- yield sleep(1000);
700
- hasControl = yield this.device.requestControl();
701
- retry++;
702
- }
703
- }
704
- if (!hasControl)
705
- throw new Error('could not establish control');
706
- const startRequest = this.getCyclingMode().getBikeInitRequest();
707
- yield this.sendUpdate(startRequest);
708
- bleDevice.on('data', (data) => {
709
- this.onDeviceData(data);
710
- });
711
- bleDevice.on('disconnected', this.emit);
712
- return true;
713
- }
714
- }
715
- catch (err) {
716
- this.logger.logEvent({ message: 'start result: error', error: err.message, profile: this.getProfile() });
717
- throw new Error(`could not start device, reason:${err.message}`);
718
- }
719
- });
720
- }
721
- stop() {
722
- return __awaiter(this, void 0, void 0, function* () {
723
- this.logger.logEvent({ message: 'stop requested', profile: this.getProfile() });
724
- this.distanceInternal = 0;
725
- this.device.reset();
726
- return this.device.disconnect();
727
- });
728
- }
729
- sendUpdate(request) {
730
- return __awaiter(this, void 0, void 0, function* () {
731
- if (this.paused || !this.device)
732
- return;
733
- const update = this.getCyclingMode().sendBikeUpdate(request);
734
- this.logger.logEvent({ message: 'send bike update requested', profile: this.getProfile(), update, request });
735
- if (update.slope !== undefined) {
736
- yield this.device.setSlope(update.slope);
737
- }
738
- if (update.targetPower !== undefined) {
739
- yield this.device.setTargetPower(update.targetPower);
740
- }
741
- });
742
- }
743
- pause() { this.paused = true; return Promise.resolve(true); }
744
- resume() { this.paused = false; return Promise.resolve(true); }
745
- }
746
- exports.FmAdapter = FmAdapter;
@@ -0,0 +1,6 @@
1
+ export declare const cwABike: {
2
+ race: number;
3
+ triathlon: number;
4
+ mountain: number;
5
+ };
6
+ export declare const cRR = 0.0036;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cRR = exports.cwABike = void 0;
4
+ exports.cwABike = {
5
+ race: 0.35,
6
+ triathlon: 0.29,
7
+ mountain: 0.57
8
+ };
9
+ exports.cRR = 0.0036;
@@ -0,0 +1,5 @@
1
+ import BleFmComms from './comms';
2
+ import BleFmAdapter from './adapter';
3
+ import { IndoorBikeData } from './types';
4
+ import { cRR, cwABike } from './consts';
5
+ export { BleFmAdapter, BleFmComms, IndoorBikeData, cRR, cwABike };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.cwABike = exports.cRR = exports.BleFmComms = exports.BleFmAdapter = void 0;
7
+ const comms_1 = __importDefault(require("./comms"));
8
+ exports.BleFmComms = comms_1.default;
9
+ const adapter_1 = __importDefault(require("./adapter"));
10
+ exports.BleFmAdapter = adapter_1.default;
11
+ const consts_1 = require("./consts");
12
+ Object.defineProperty(exports, "cRR", { enumerable: true, get: function () { return consts_1.cRR; } });
13
+ Object.defineProperty(exports, "cwABike", { enumerable: true, get: function () { return consts_1.cwABike; } });
@@ -0,0 +1,30 @@
1
+ export type IndoorBikeData = {
2
+ speed?: number;
3
+ averageSpeed?: number;
4
+ cadence?: number;
5
+ averageCadence?: number;
6
+ totalDistance?: number;
7
+ resistanceLevel?: number;
8
+ instantaneousPower?: number;
9
+ averagePower?: number;
10
+ totalEnergy?: number;
11
+ energyPerHour?: number;
12
+ energyPerMinute?: number;
13
+ heartrate?: number;
14
+ metabolicEquivalent?: number;
15
+ time?: number;
16
+ remainingTime?: number;
17
+ raw?: string;
18
+ targetPower?: number;
19
+ targetInclination?: number;
20
+ status?: string;
21
+ };
22
+ export type IndoorBikeFeatures = {
23
+ fitnessMachine: number;
24
+ targetSettings: number;
25
+ power?: boolean;
26
+ heartrate?: boolean;
27
+ cadence?: boolean;
28
+ setSlope?: boolean;
29
+ setPower?: boolean;
30
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ import BleAdapter from '../base/adapter';
2
+ import { DeviceProperties } from '../../types/device';
3
+ import { BleDeviceSettings } from '../types';
4
+ import { HrmData } from './types';
5
+ import { DeviceData } from '../../types/data';
6
+ export default class HrmAdapter extends BleAdapter {
7
+ ignore: boolean;
8
+ constructor(settings: BleDeviceSettings, props?: DeviceProperties);
9
+ isSame(device: BleAdapter): boolean;
10
+ getProfile(): string;
11
+ getName(): string;
12
+ getDisplayName(): string;
13
+ mapData(deviceData: HrmData): DeviceData;
14
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const gd_eventlog_1 = require("gd-eventlog");
7
+ const adapter_1 = __importDefault(require("../base/adapter"));
8
+ const comm_1 = __importDefault(require("./comm"));
9
+ const capabilities_1 = require("../../types/capabilities");
10
+ class HrmAdapter extends adapter_1.default {
11
+ constructor(settings, props) {
12
+ super(settings, props);
13
+ this.ignore = false;
14
+ this.logger = new gd_eventlog_1.EventLogger('Ble-HR');
15
+ const { id, address, name } = settings;
16
+ const logger = this.logger;
17
+ const ble = this.ble;
18
+ this.device = new comm_1.default({ id, address, name, ble, logger });
19
+ this.capabilities = [
20
+ capabilities_1.IncyclistCapability.HeartRate
21
+ ];
22
+ }
23
+ isSame(device) {
24
+ if (!(device instanceof HrmAdapter))
25
+ return false;
26
+ return this.isEqual(device.settings);
27
+ }
28
+ getProfile() {
29
+ return 'Heartrate Monitor';
30
+ }
31
+ getName() {
32
+ return `${this.device.name}`;
33
+ }
34
+ getDisplayName() {
35
+ const { name } = this.device;
36
+ const { heartrate: hrm } = this.deviceData;
37
+ const hrmStr = hrm ? ` (${hrm})` : '';
38
+ return `${name}${hrmStr}`;
39
+ }
40
+ mapData(deviceData) {
41
+ const { heartrate } = deviceData;
42
+ return { heartrate };
43
+ }
44
+ }
45
+ exports.default = HrmAdapter;
@@ -0,0 +1,19 @@
1
+ /// <reference types="node" />
2
+ import { LegacyProfile } from '../../antv2/types';
3
+ import { BleComms } from '../base/comms';
4
+ import { BleProtocol } from '../types';
5
+ import { HrmData } from './types';
6
+ export default class BleHrmDevice extends BleComms {
7
+ static protocol: BleProtocol;
8
+ static services: string[];
9
+ static characteristics: string[];
10
+ static detectionPriority: number;
11
+ heartrate: number;
12
+ rr: number;
13
+ constructor(props?: any);
14
+ getProfile(): LegacyProfile;
15
+ getProtocol(): BleProtocol;
16
+ getServiceUUids(): string[];
17
+ parseHrm(_data: Uint8Array): HrmData;
18
+ onData(characteristic: string, data: Buffer): boolean;
19
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const comms_1 = require("../base/comms");
4
+ class BleHrmDevice extends comms_1.BleComms {
5
+ constructor(props) {
6
+ super(props);
7
+ this.heartrate = undefined;
8
+ this.rr = undefined;
9
+ }
10
+ getProfile() {
11
+ return 'Heartrate Monitor';
12
+ }
13
+ getProtocol() {
14
+ return BleHrmDevice.protocol;
15
+ }
16
+ getServiceUUids() {
17
+ return BleHrmDevice.services;
18
+ }
19
+ parseHrm(_data) {
20
+ const data = Buffer.from(_data);
21
+ try {
22
+ const flags = data.readUInt8(0);
23
+ let offset = 2;
24
+ if (flags % 1 === 0) {
25
+ this.heartrate = data.readUInt8(1);
26
+ }
27
+ else {
28
+ this.heartrate = data.readUInt16LE(1);
29
+ offset = 3;
30
+ }
31
+ if (flags % 0xF) {
32
+ this.rr = (data.readUInt16LE(offset)) / 1024;
33
+ }
34
+ }
35
+ catch (err) {
36
+ }
37
+ const { heartrate, rr } = this;
38
+ return { heartrate, rr, raw: data.toString('hex') };
39
+ }
40
+ onData(characteristic, data) {
41
+ const hasData = super.onData(characteristic, data);
42
+ if (!hasData)
43
+ return;
44
+ if (characteristic.toLocaleLowerCase() === '2a37') {
45
+ const res = this.parseHrm(data);
46
+ this.emit('data', res);
47
+ return false;
48
+ }
49
+ return true;
50
+ }
51
+ }
52
+ exports.default = BleHrmDevice;
53
+ BleHrmDevice.protocol = 'hr';
54
+ BleHrmDevice.services = ['180d'];
55
+ BleHrmDevice.characteristics = ['2a37', '2a38', '2a39', '2a3c'];
56
+ BleHrmDevice.detectionPriority = 1;
@@ -0,0 +1,4 @@
1
+ import { HrmData } from './types';
2
+ import BleHrmAdapter from './adapter';
3
+ import BleHrmComms from './comm';
4
+ export { HrmData, BleHrmAdapter, BleHrmComms };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BleHrmComms = exports.BleHrmAdapter = void 0;
7
+ const adapter_1 = __importDefault(require("./adapter"));
8
+ exports.BleHrmAdapter = adapter_1.default;
9
+ const comm_1 = __importDefault(require("./comm"));
10
+ exports.BleHrmComms = comm_1.default;
@@ -0,0 +1,7 @@
1
+ import { BleMockPeripheral } from "../bindings/mock";
2
+ interface BleHrMockPeripheral extends BleMockPeripheral {
3
+ setNotifyFrequency: (ms: number) => void;
4
+ setHeartrate: (hr: number) => void;
5
+ }
6
+ export declare const HrMock: BleHrMockPeripheral;
7
+ export {};
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HrMock = void 0;
4
+ const types_1 = require("../bindings/types");
5
+ class HeartRateMeasuremenCharacteristic extends types_1.StaticNotifyCharacteristic {
6
+ constructor(uuid, description, heartrate = 0) {
7
+ super(uuid, description);
8
+ this.heartrate = heartrate;
9
+ this.value = Buffer.from(this.heartrate.toString());
10
+ }
11
+ notify() {
12
+ const buffer = Buffer.alloc(2);
13
+ buffer.writeUInt8(0, 0);
14
+ buffer.writeUInt8(this.heartrate, 1);
15
+ this.emit('data', buffer);
16
+ }
17
+ }
18
+ const HR = {
19
+ uuid: "180d",
20
+ characteristics: [
21
+ new HeartRateMeasuremenCharacteristic('2a37', 'Heart Rate Measurement', 60)
22
+ ]
23
+ };
24
+ const DIS = {
25
+ uuid: '180a',
26
+ characteristics: [
27
+ new types_1.StaticReadCharacteristic('2a23', 'System Id', '0'),
28
+ new types_1.StaticReadCharacteristic('2a24', 'Model Number', '1'),
29
+ new types_1.StaticReadCharacteristic('2a25', 'Serial Number', '4711'),
30
+ new types_1.StaticReadCharacteristic('2a26', 'Firmware Revision', '1'),
31
+ new types_1.StaticReadCharacteristic('2a27', 'Hardware Revision', '1'),
32
+ new types_1.StaticReadCharacteristic('2a28', 'Software Revision', '1'),
33
+ new types_1.StaticReadCharacteristic('2a29', 'Manufacturer Name', 'Incyclist')
34
+ ]
35
+ };
36
+ exports.HrMock = {
37
+ services: [HR, DIS],
38
+ id: "a87b6100820d48b1401bf83a8cf6f046",
39
+ name: "HRM-Mock",
40
+ address: "a87b6100820d48b1401bf83a8cf6f046",
41
+ setNotifyFrequency: (ms) => {
42
+ HR.characteristics[0].notifyFrequency = ms;
43
+ },
44
+ setHeartrate: (hr) => {
45
+ HR.characteristics[0].heartrate = hr;
46
+ }
47
+ };
@@ -0,0 +1,5 @@
1
+ export type HrmData = {
2
+ heartrate: number;
3
+ rr: number;
4
+ raw: string;
5
+ };