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
@@ -0,0 +1,141 @@
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 adapter_1 = require("../adapter");
7
+ const utils_1 = require("../utils");
8
+ const gd_eventlog_1 = require("gd-eventlog");
9
+ const power_meter_1 = __importDefault(require("../../modes/power-meter"));
10
+ const sensor_factory_1 = __importDefault(require("../sensor-factory"));
11
+ const capabilities_1 = require("../../types/capabilities");
12
+ class AntPwrAdapter extends adapter_1.ControllableAntAdapter {
13
+ constructor(settings, props) {
14
+ if (settings.protocol && settings.profile !== AntPwrAdapter.INCYCLIST_PROFILE_NAME)
15
+ throw new Error('Incorrect Profile');
16
+ if (!settings.protocol && settings.profile !== AntPwrAdapter.ANT_PROFILE_NAME)
17
+ throw new Error('Incorrect Profile');
18
+ super(settings, props);
19
+ this.deviceData = {
20
+ DeviceID: this.sensor.getDeviceID()
21
+ };
22
+ this.logger = new gd_eventlog_1.EventLogger('Ant+PWR');
23
+ this.capabilities = [
24
+ capabilities_1.IncyclistCapability.Power, capabilities_1.IncyclistCapability.Cadence, capabilities_1.IncyclistCapability.Speed
25
+ ];
26
+ }
27
+ createSensor(settings) {
28
+ return sensor_factory_1.default.create(AntPwrAdapter.ANT_PROFILE_NAME, Number(settings.deviceID));
29
+ }
30
+ getName() {
31
+ if (this.settings.name)
32
+ return this.settings.name;
33
+ const deviceID = this.sensor.getDeviceID();
34
+ return `Ant+PWR ${deviceID}`;
35
+ }
36
+ getUniqueName() {
37
+ if (this.settings.name)
38
+ return this.settings.name;
39
+ const { DeviceID, ManId } = this.deviceData;
40
+ const brand = (0, utils_1.getBrand)(ManId);
41
+ if (brand)
42
+ return `${brand} PWR ${DeviceID}`;
43
+ else
44
+ return `${this.getName()}`;
45
+ }
46
+ getDisplayName() {
47
+ const { Power } = this.deviceData;
48
+ const pwrStr = Power ? ` (${Power})` : '';
49
+ return `${this.getUniqueName()}${pwrStr}`;
50
+ }
51
+ getDefaultCyclingMode() {
52
+ return new power_meter_1.default(this);
53
+ }
54
+ getSupportedCyclingModes() {
55
+ return [power_meter_1.default];
56
+ }
57
+ getLogData(data, excludeList) {
58
+ const logData = JSON.parse(JSON.stringify(data));
59
+ excludeList.forEach((key) => {
60
+ delete logData[key];
61
+ });
62
+ return logData;
63
+ }
64
+ onDeviceData(deviceData) {
65
+ this.dataMsgCount++;
66
+ this.lastDataTS = Date.now();
67
+ super.onDeviceData(deviceData);
68
+ if (!this.started)
69
+ return;
70
+ if (!this.ivDataTimeout)
71
+ this.startDataTimeoutCheck();
72
+ try {
73
+ if (!this.canSendUpdate())
74
+ return;
75
+ const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
76
+ this.logger.logEvent({ message: 'onDeviceData', data: logData });
77
+ let incyclistData = this.mapData(deviceData);
78
+ incyclistData = this.getCyclingMode().updateData(incyclistData);
79
+ const data = this.transformData(incyclistData);
80
+ this.emitData(data);
81
+ }
82
+ catch (err) {
83
+ }
84
+ }
85
+ canSendUpdate() {
86
+ if (!this.hasDataListeners() || this.paused)
87
+ return false;
88
+ return super.canSendUpdate();
89
+ }
90
+ sendUpdate(request) {
91
+ if (this.isPaused())
92
+ return;
93
+ this.getCyclingMode().sendBikeUpdate(request);
94
+ }
95
+ mapData(deviceData) {
96
+ const data = {
97
+ isPedalling: false,
98
+ power: 0,
99
+ pedalRpm: 0,
100
+ speed: 0,
101
+ heartrate: 0,
102
+ distanceInternal: 0,
103
+ slope: undefined,
104
+ time: undefined
105
+ };
106
+ data.slope = (deviceData.Slope !== undefined ? deviceData.Slope : data.slope);
107
+ data.power = (deviceData.Power !== undefined ? deviceData.Power : data.power);
108
+ data.pedalRpm = (deviceData.Cadence !== undefined ? deviceData.Cadence : data.pedalRpm);
109
+ data.time = (deviceData.TimeStamp !== undefined ? deviceData.TimeStamp : data.time);
110
+ data.isPedalling = data.pedalRpm > 0;
111
+ return data;
112
+ }
113
+ transformData(bikeData) {
114
+ if (bikeData === undefined)
115
+ return;
116
+ let distance = 0;
117
+ if (this.distanceInternal !== undefined && bikeData.distanceInternal !== undefined) {
118
+ distance = bikeData.distanceInternal - this.distanceInternal;
119
+ }
120
+ if (bikeData.distanceInternal !== undefined)
121
+ this.distanceInternal = bikeData.distanceInternal;
122
+ let data = {
123
+ speed: bikeData.speed,
124
+ slope: bikeData.slope,
125
+ power: bikeData.power,
126
+ cadence: bikeData.pedalRpm,
127
+ distance,
128
+ timestamp: Date.now()
129
+ };
130
+ return data;
131
+ }
132
+ hasData() {
133
+ const { Power, Cadence, TimeStamp } = this.deviceData;
134
+ return Power !== undefined && Power !== null ||
135
+ Cadence !== undefined || Cadence !== null ||
136
+ TimeStamp !== undefined || TimeStamp !== null;
137
+ }
138
+ }
139
+ exports.default = AntPwrAdapter;
140
+ AntPwrAdapter.INCYCLIST_PROFILE_NAME = 'Power Meter';
141
+ AntPwrAdapter.ANT_PROFILE_NAME = 'PWR';
@@ -0,0 +1,2 @@
1
+ import AntPwrAdapter from './adapter';
2
+ export default AntPwrAdapter;
@@ -0,0 +1,7 @@
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 adapter_1 = __importDefault(require("./adapter"));
7
+ exports.default = adapter_1.default;
@@ -1,5 +1,5 @@
1
- import { ISensor } from "incyclist-ant-plus";
1
+ import { ISensor, Profile } from "incyclist-ant-plus";
2
2
  export default class SensorFactory {
3
- static create(profile: string, deviceID?: number): ISensor;
3
+ static create(profile: Profile, deviceID?: number): ISensor;
4
4
  static createAll(): ISensor[];
5
5
  }
@@ -0,0 +1,22 @@
1
+ import { Profile } from 'incyclist-ant-plus';
2
+ import IncyclistDevice from '../base/adpater';
3
+ import { DeviceProperties, DeviceSettings, IncyclistScanProps } from '../types/device';
4
+ export interface AntDeviceSettings extends DeviceSettings {
5
+ deviceID?: string;
6
+ profile: Profile | LegacyProfile;
7
+ protocol?: string;
8
+ }
9
+ export type LegacyProfile = 'Heartrate Monitor' | 'Power Meter' | 'Smart Trainer' | 'Speed Sensor' | 'Cadence Sensor' | 'Speed + Cadence Sensor';
10
+ export declare const isLegacyProfile: (o: unknown) => boolean;
11
+ export type DeviceFoundCallback = (device: IncyclistDevice, protocol: string) => void;
12
+ export type ScanFinishedCallback = (id: number) => void;
13
+ export interface AntScanProps extends IncyclistScanProps {
14
+ profiles?: Profile[];
15
+ id?: number;
16
+ onDeviceFound?: DeviceFoundCallback;
17
+ onScanFinished?: ScanFinishedCallback;
18
+ }
19
+ export interface AntDeviceProperties extends DeviceProperties {
20
+ startupTimeout?: number;
21
+ automaticReconnect?: boolean;
22
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isLegacyProfile = void 0;
4
+ const isLegacyProfile = (o) => o === 'Heartrate Monitor' || o === 'Power Meter' || o === 'Smart Trainer' || o === 'Speed Sensor' || o === 'Cadence Sensor' || o === 'Speed + Cadence Sensor';
5
+ exports.isLegacyProfile = isLegacyProfile;
@@ -0,0 +1,4 @@
1
+ import { Profile } from "incyclist-ant-plus";
2
+ import { LegacyProfile } from "./types";
3
+ export declare const getBrand: (manId: number) => string;
4
+ export declare const mapLegacyProfile: (legacy: LegacyProfile) => Profile;
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapLegacyProfile = exports.getBrand = void 0;
4
+ const brands = [
5
+ 'Garmin,1',
6
+ 'garmin_fr405_antfs,2',
7
+ 'Zephyr,3',
8
+ 'Dayton,4',
9
+ 'idt,5',
10
+ 'SRM,6',
11
+ 'Quarq,7',
12
+ 'ibike,8',
13
+ 'Saris,9',
14
+ 'spark_hk,10',
15
+ 'Tanita,11',
16
+ 'echowell,12',
17
+ 'Dynastream_oem,13',
18
+ 'Nautilus,14',
19
+ 'Dynastream,15',
20
+ 'Timex,16',
21
+ 'Metrigear,17',
22
+ 'Xelic,18',
23
+ 'Beurer,19',
24
+ 'Cardiosport,20',
25
+ 'A&D,21',
26
+ 'Hmm,22',
27
+ 'Suunto,23',
28
+ 'Thita Elektronik,24',
29
+ 'Gpulse,25',
30
+ 'Clean Mobile,26',
31
+ 'Pedal Brain,27',
32
+ 'Peaksware,28',
33
+ 'Saxonar,29',
34
+ 'Lemond Fitness,30',
35
+ 'Dexcom,31',
36
+ 'Wahoo,32',
37
+ 'Octane,33',
38
+ 'Archinoetics,34',
39
+ 'The Hurt Box,35',
40
+ 'Citizen Systems,36',
41
+ 'Magellan,37',
42
+ 'Osynce,38',
43
+ 'Holux,39',
44
+ 'Concept2,40',
45
+ 'One Giant Leap,42',
46
+ 'Ace Sensor,43',
47
+ 'Brim Brothers,44',
48
+ 'Xplova,45',
49
+ 'Perception Digital,46',
50
+ 'Bf1systems,47',
51
+ 'Pioneer,48',
52
+ 'Spantec,49',
53
+ 'Metalogics,50',
54
+ '4iiiis,51',
55
+ 'Seiko,52',
56
+ 'Seiko,53',
57
+ 'Ifor Powell,54',
58
+ 'Maxwell Guider,55',
59
+ 'Star rac,56',
60
+ 'Breakaway,57',
61
+ 'Alatech,58',
62
+ 'Mio,59',
63
+ 'Rotor,60',
64
+ 'Geonaute,61',
65
+ 'Id Bike,62',
66
+ 'Specialized,63',
67
+ 'Wtek,64',
68
+ 'Physical Enterprises,65',
69
+ 'North Pole,66',
70
+ 'Bkool,67',
71
+ 'Cateye,68',
72
+ 'Stages,69',
73
+ 'Sigma,70',
74
+ 'Tomtom,71',
75
+ 'Peripedal,72',
76
+ 'Wattbike,73',
77
+ 'Moxy,76',
78
+ 'Ciclosport,77',
79
+ 'Powerbahn,78',
80
+ 'Acorn,79',
81
+ 'Lifebeam,80',
82
+ 'Bontrager,81',
83
+ 'Wellgo,82',
84
+ 'Scosche,83',
85
+ 'Magura,84',
86
+ 'Woodway,85',
87
+ 'Elite,86',
88
+ 'Nielsen Kellerman,87',
89
+ 'DK City,88',
90
+ 'Tacx,89',
91
+ 'Direction,90',
92
+ 'Magtonic,91',
93
+ '1partcarbon,92',
94
+ 'Inside Ride,93',
95
+ 'Sound Of Motion,94',
96
+ 'Stryd,95',
97
+ 'icg,96',
98
+ 'MiPulse,97',
99
+ 'Bsx Athletics,98',
100
+ 'Look,99',
101
+ 'Campagnolo,100',
102
+ 'Body Bike Smart,101',
103
+ 'Praxisworks,102',
104
+ 'Limits,103',
105
+ 'Topaction,104',
106
+ 'Cosinuss,105',
107
+ 'Fitcare,106',
108
+ 'Magene,107',
109
+ 'Giant,108',
110
+ 'Tigrasport,109',
111
+ 'Salutron,110',
112
+ 'Technogym,111',
113
+ 'Bryton,112',
114
+ 'Latitude,113',
115
+ 'Soaring,114',
116
+ 'Igpsport,115',
117
+ 'Thinkrider,116',
118
+ 'Gopher,117',
119
+ 'Waterrower,118',
120
+ 'Orangetheory,119',
121
+ 'Inpeak,120',
122
+ 'Kinetic,121',
123
+ 'Johnson,122',
124
+ 'Polar,123',
125
+ 'Seesense,124',
126
+ 'NCI,125',
127
+ 'Development,255',
128
+ 'Healthandlife,257',
129
+ 'Lezyne,258',
130
+ 'Scribe,259',
131
+ 'Zwift,260',
132
+ 'Watteam,261',
133
+ 'Recon,262',
134
+ 'Favero,263',
135
+ 'Dynovelo,264',
136
+ 'Strava,265',
137
+ 'Precor,266',
138
+ 'Bryton,267',
139
+ 'Sram,268',
140
+ 'Navman,269',
141
+ 'Cobi,270',
142
+ 'Spivi,271',
143
+ 'Mio Magellan,272',
144
+ 'Evesports,273',
145
+ 'Sensitivus Gauge,274',
146
+ 'Podoon,275',
147
+ 'Life Time Fitness,276',
148
+ 'Falco,277',
149
+ 'Minoura,278',
150
+ 'Cycliq,279',
151
+ 'Luxottica,280',
152
+ 'Trainer Road,281',
153
+ 'The Sufferfest,282',
154
+ 'Fullspeedahead,283',
155
+ 'Virtualtraining,284',
156
+ 'Feedbacksports,285',
157
+ 'Omata,286',
158
+ 'VDO,287',
159
+ 'Magneticdays,288',
160
+ 'Hammerhead,289',
161
+ 'Kinetic By Kurt,290',
162
+ 'Shapelog,291',
163
+ 'Dabuziduo,292',
164
+ 'Jetblack,293',
165
+ 'Coros,294',
166
+ 'Virtugo,295',
167
+ 'Velosense,296',
168
+ 'Cycligentinc,297',
169
+ 'Actigraphcorp,5759'
170
+ ];
171
+ const brandLookup = brands.map(str => {
172
+ const [name, id] = str.split(',');
173
+ return { name, id: Number(id) };
174
+ });
175
+ const getBrand = (manId) => {
176
+ const found = brandLookup.find(l => l.id === manId);
177
+ if (found)
178
+ return found.name;
179
+ return;
180
+ };
181
+ exports.getBrand = getBrand;
182
+ const mapLegacyProfile = (legacy) => {
183
+ switch (legacy) {
184
+ case 'Heartrate Monitor': return 'HR';
185
+ case 'Power Meter': return 'PWR';
186
+ case 'Smart Trainer': return 'FE';
187
+ case 'Cadence Sensor': return 'CAD';
188
+ case 'Speed Sensor': return 'SPD';
189
+ case 'Speed + Cadence Sensor': return 'SC';
190
+ }
191
+ };
192
+ exports.mapLegacyProfile = mapLegacyProfile;
@@ -0,0 +1,68 @@
1
+ /// <reference types="node" />
2
+ import CyclingMode from "../modes/cycling-mode";
3
+ import { DeviceProperties, DeviceSettings } from "../types/device";
4
+ import { Bike, IncyclistDeviceAdapter, OnDeviceDataCallback } from '../types/adapter';
5
+ import { User } from "../types/user";
6
+ import { IncyclistCapability } from "../types/capabilities";
7
+ import { EventLogger } from "gd-eventlog";
8
+ import { DeviceData } from "../types/data";
9
+ import EventEmitter from "events";
10
+ export declare const DEFAULT_BIKE_WEIGHT = 10;
11
+ export declare const DEFAULT_USER_WEIGHT = 75;
12
+ export declare const DEFAULT_PROPS: DeviceProperties;
13
+ export default class IncyclistDevice extends EventEmitter implements IncyclistDeviceAdapter {
14
+ onDataFn: OnDeviceDataCallback;
15
+ settings: DeviceSettings;
16
+ props: DeviceProperties;
17
+ lastUpdate?: number;
18
+ updateFrequency: number;
19
+ capabilities: IncyclistCapability[];
20
+ protected logger: EventLogger;
21
+ started: boolean;
22
+ stopped: boolean;
23
+ paused: boolean;
24
+ constructor(settings: DeviceSettings, props?: DeviceProperties);
25
+ connect(): Promise<boolean>;
26
+ close(): Promise<boolean>;
27
+ check(): Promise<boolean>;
28
+ isControllable(): boolean;
29
+ isEqual(settings: DeviceSettings): boolean;
30
+ getCapabilities(): IncyclistCapability[];
31
+ hasCapability(capability: IncyclistCapability): boolean;
32
+ addCapability(capability: IncyclistCapability): void;
33
+ update(): void;
34
+ start(props?: DeviceProperties): Promise<boolean>;
35
+ stop(): Promise<boolean>;
36
+ pause(): Promise<boolean>;
37
+ resume(): Promise<boolean>;
38
+ logEvent(event: any): void;
39
+ getMaxUpdateFrequency(): number;
40
+ setMaxUpdateFrequency(value: number): void;
41
+ sendUpdate(request: any): void;
42
+ getID(): string;
43
+ getDisplayName(): string;
44
+ getName(): string;
45
+ getUniqueName(): string;
46
+ getSettings(): DeviceSettings;
47
+ getInterface(): string;
48
+ onData(callback: OnDeviceDataCallback): void;
49
+ canSendUpdate(): boolean;
50
+ emitData(data: DeviceData): void;
51
+ isStopped(): boolean;
52
+ isStarted(): boolean;
53
+ isPaused(): boolean;
54
+ hasDataListeners(): boolean | OnDeviceDataCallback;
55
+ }
56
+ export declare class ControllableDevice extends IncyclistDevice implements Bike {
57
+ cyclingMode: CyclingMode;
58
+ user?: User;
59
+ constructor(settings: DeviceSettings, props?: DeviceProperties);
60
+ isControllable(): boolean;
61
+ setUser(user: User): void;
62
+ setBikeProps(props: DeviceProperties): void;
63
+ getWeight(): number;
64
+ getSupportedCyclingModes(): any[];
65
+ getDefaultCyclingMode(): CyclingMode;
66
+ setCyclingMode(mode: CyclingMode | string, settings?: any): void;
67
+ getCyclingMode(): CyclingMode;
68
+ }
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ControllableDevice = exports.DEFAULT_PROPS = exports.DEFAULT_USER_WEIGHT = exports.DEFAULT_BIKE_WEIGHT = void 0;
16
+ const events_1 = __importDefault(require("events"));
17
+ exports.DEFAULT_BIKE_WEIGHT = 10;
18
+ exports.DEFAULT_USER_WEIGHT = 75;
19
+ exports.DEFAULT_PROPS = {
20
+ userWeight: exports.DEFAULT_USER_WEIGHT,
21
+ bikeWeight: exports.DEFAULT_BIKE_WEIGHT
22
+ };
23
+ class IncyclistDevice extends events_1.default {
24
+ constructor(settings, props) {
25
+ super();
26
+ this.onDataFn = undefined;
27
+ this.settings = settings;
28
+ this.props = props || {};
29
+ this.capabilities = [];
30
+ this.started = false;
31
+ this.stopped = false;
32
+ this.paused = false;
33
+ }
34
+ connect() { throw new Error('not implemented'); }
35
+ close() { throw new Error('not implemented'); }
36
+ check() { throw new Error("Method not implemented."); }
37
+ isControllable() {
38
+ return false;
39
+ }
40
+ isEqual(settings) { throw new Error("Method not implemented."); }
41
+ getCapabilities() { return this.capabilities; }
42
+ hasCapability(capability) {
43
+ return this.capabilities.find(c => c === capability) !== undefined;
44
+ }
45
+ addCapability(capability) {
46
+ if (!this.capabilities.includes(capability))
47
+ this.capabilities.push(capability);
48
+ }
49
+ update() { throw new Error("Method not implemented."); }
50
+ start(props) { throw new Error("Method not implemented."); }
51
+ stop() { throw new Error("Method not implemented."); }
52
+ pause() {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ this.paused = true;
55
+ return true;
56
+ });
57
+ }
58
+ resume() {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ this.paused = false;
61
+ return true;
62
+ });
63
+ }
64
+ logEvent(event) {
65
+ if (!this.logger || this.paused)
66
+ return;
67
+ this.logger.logEvent(event);
68
+ }
69
+ getMaxUpdateFrequency() {
70
+ return this.updateFrequency;
71
+ }
72
+ setMaxUpdateFrequency(value) {
73
+ this.updateFrequency = value;
74
+ }
75
+ sendUpdate(request) { throw new Error("Method not implemented."); }
76
+ getID() { throw new Error('not implemented'); }
77
+ getDisplayName() {
78
+ return this.getName();
79
+ }
80
+ getName() {
81
+ return this.settings.name;
82
+ }
83
+ getUniqueName() {
84
+ throw new Error("Method not implemented.");
85
+ }
86
+ getSettings() {
87
+ return this.settings;
88
+ }
89
+ getInterface() {
90
+ return typeof this.settings.interface === 'string' ? this.settings.interface : this.settings.interface.getName();
91
+ }
92
+ onData(callback) {
93
+ this.onDataFn = callback;
94
+ }
95
+ canSendUpdate() {
96
+ const updateFrequency = this.getMaxUpdateFrequency();
97
+ if (updateFrequency === -1 || updateFrequency === undefined)
98
+ return true;
99
+ return (!this.lastUpdate || (Date.now() - this.lastUpdate) > updateFrequency);
100
+ }
101
+ emitData(data) {
102
+ if (!this.canSendUpdate())
103
+ return;
104
+ if (this.onDataFn)
105
+ this.onDataFn(data);
106
+ this.emit('data', this.getSettings(), data);
107
+ this.lastUpdate = Date.now();
108
+ }
109
+ isStopped() {
110
+ return this.stopped;
111
+ }
112
+ isStarted() {
113
+ return this.started;
114
+ }
115
+ isPaused() {
116
+ return this.paused;
117
+ }
118
+ hasDataListeners() {
119
+ return this.onDataFn || this.listenerCount('data') > 0;
120
+ }
121
+ }
122
+ exports.default = IncyclistDevice;
123
+ class ControllableDevice extends IncyclistDevice {
124
+ constructor(settings, props) {
125
+ super(settings, props);
126
+ this.cyclingMode = this.getDefaultCyclingMode();
127
+ this.user = {};
128
+ }
129
+ isControllable() {
130
+ return true;
131
+ }
132
+ setUser(user) {
133
+ this.user = user;
134
+ if (!user.weight)
135
+ this.user.weight = exports.DEFAULT_USER_WEIGHT;
136
+ }
137
+ setBikeProps(props) {
138
+ const { user, userWeight } = props || {};
139
+ if (user)
140
+ this.setUser(user);
141
+ if (userWeight)
142
+ this.user.weight = userWeight;
143
+ const keys = Object.keys(props);
144
+ keys.forEach(k => {
145
+ const p = props[k];
146
+ if (p === null)
147
+ delete this.props[k];
148
+ else if (p !== undefined)
149
+ this.props[k] = p;
150
+ });
151
+ }
152
+ getWeight() {
153
+ const { user = {}, props = exports.DEFAULT_PROPS } = this;
154
+ const userWeight = user.weight || props.userWeight || exports.DEFAULT_USER_WEIGHT;
155
+ const bikeWeight = props.bikeWeight || exports.DEFAULT_BIKE_WEIGHT;
156
+ return userWeight + bikeWeight;
157
+ }
158
+ getSupportedCyclingModes() { throw new Error('not implemented'); }
159
+ getDefaultCyclingMode() { throw new Error('not implemented'); }
160
+ setCyclingMode(mode, settings) {
161
+ let selectedMode;
162
+ if (typeof mode === 'string') {
163
+ const supported = this.getSupportedCyclingModes();
164
+ const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
165
+ if (CyclingModeClass) {
166
+ this.cyclingMode = new CyclingModeClass(this, settings);
167
+ return;
168
+ }
169
+ selectedMode = this.getDefaultCyclingMode();
170
+ }
171
+ else {
172
+ selectedMode = mode;
173
+ }
174
+ this.cyclingMode = selectedMode;
175
+ this.cyclingMode.setSettings(settings);
176
+ }
177
+ getCyclingMode() {
178
+ if (!this.cyclingMode)
179
+ this.setCyclingMode(this.getDefaultCyclingMode());
180
+ return this.cyclingMode;
181
+ }
182
+ }
183
+ exports.ControllableDevice = ControllableDevice;
@@ -0,0 +1,33 @@
1
+ import { DeviceProperties } from "../types/device";
2
+ import BleAdapter from "./base/adapter";
3
+ import { BleDeviceSettings, BleProtocol } from "./types";
4
+ import { BleComms } from "./base/comms";
5
+ export interface BleAdapterInfo {
6
+ protocol: BleProtocol;
7
+ Adapter: typeof BleAdapter;
8
+ Comm: typeof BleComms;
9
+ }
10
+ export default class BleAdapterFactory {
11
+ static _instance: BleAdapterFactory;
12
+ implementations: BleAdapterInfo[];
13
+ instances: BleAdapter[];
14
+ static getInstance(): BleAdapterFactory;
15
+ constructor();
16
+ getAdapterInfo(protocol: BleProtocol): BleAdapterInfo;
17
+ getAll(): BleAdapterInfo[];
18
+ createInstance(settings: BleDeviceSettings, props?: DeviceProperties): BleAdapter;
19
+ removeInstance(query: {
20
+ settings?: BleDeviceSettings;
21
+ adapter?: BleAdapter;
22
+ }): void;
23
+ find(settings?: BleDeviceSettings): BleAdapter;
24
+ register(protocol: BleProtocol, Adapter: typeof BleAdapter, Comm: typeof BleComms): void;
25
+ getAllInstances(): BleAdapter[];
26
+ getAllSupportedComms(): (typeof BleComms)[];
27
+ getAllSupportedAdapters(): (typeof BleAdapter)[];
28
+ getAllSupportedServices(): string[];
29
+ getDeviceClasses(peripheral: any, props?: {
30
+ protocol?: BleProtocol;
31
+ services?: string[];
32
+ }): (typeof BleComms)[];
33
+ }