incyclist-devices 1.5.38 → 2.0.0-beta.1

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 (251) hide show
  1. package/README.MD +0 -0
  2. package/lib/adapters.d.ts +6 -0
  3. package/lib/adapters.js +30 -0
  4. package/lib/antv2/adapter-factory.d.ts +20 -10
  5. package/lib/antv2/adapter-factory.js +49 -33
  6. package/lib/antv2/adapter.d.ts +64 -0
  7. package/lib/antv2/adapter.js +299 -0
  8. package/lib/antv2/ant-interface.d.ts +11 -9
  9. package/lib/antv2/ant-interface.js +15 -11
  10. package/lib/antv2/fe/adapter.d.ts +25 -0
  11. package/lib/antv2/{fe.js → fe/adapter.js} +48 -72
  12. package/lib/antv2/fe/index.d.ts +2 -0
  13. package/lib/antv2/fe/index.js +7 -0
  14. package/lib/antv2/hr/adapter.d.ts +14 -0
  15. package/lib/antv2/hr/adapter.js +73 -0
  16. package/lib/antv2/hr/index.d.ts +2 -0
  17. package/lib/antv2/hr/index.js +7 -0
  18. package/lib/antv2/index.d.ts +7 -0
  19. package/lib/antv2/index.js +20 -0
  20. package/lib/antv2/modes/ant-fe-adv-st-mode.d.ts +9 -0
  21. package/lib/{ant/antfe → antv2/modes}/ant-fe-adv-st-mode.js +1 -1
  22. package/lib/antv2/modes/ant-fe-erg-mode.d.ts +6 -0
  23. package/lib/{ant/antfe → antv2/modes}/ant-fe-erg-mode.js +1 -1
  24. package/lib/antv2/modes/ant-fe-st-mode.d.ts +5 -0
  25. package/lib/{ant/antfe → antv2/modes}/ant-fe-st-mode.js +1 -1
  26. package/lib/antv2/pwr/adapter.d.ts +22 -0
  27. package/lib/antv2/{pwr.js → pwr/adapter.js} +38 -76
  28. package/lib/antv2/pwr/index.d.ts +2 -0
  29. package/lib/antv2/pwr/index.js +7 -0
  30. package/lib/antv2/types.d.ts +19 -0
  31. package/lib/antv2/types.js +2 -0
  32. package/lib/antv2/utils.d.ts +1 -0
  33. package/lib/antv2/utils.js +181 -0
  34. package/lib/base/adpater.d.ts +56 -0
  35. package/lib/base/adpater.js +144 -0
  36. package/lib/ble/adapter-factory.d.ts +31 -0
  37. package/lib/ble/adapter-factory.js +96 -0
  38. package/lib/ble/adapter.d.ts +41 -0
  39. package/lib/ble/adapter.js +188 -0
  40. package/lib/ble/{ble-device.d.ts → ble-comms.d.ts} +9 -4
  41. package/lib/ble/{ble-device.js → ble-comms.js} +23 -11
  42. package/lib/ble/ble-interface.d.ts +15 -24
  43. package/lib/ble/ble-interface.js +32 -137
  44. package/lib/ble/ble-peripheral.d.ts +3 -3
  45. package/lib/ble/ble-peripheral.js +14 -14
  46. package/lib/ble/ble.d.ts +9 -81
  47. package/lib/ble/ble.js +1 -39
  48. package/lib/ble/consts.d.ts +2 -0
  49. package/lib/ble/consts.js +3 -1
  50. package/lib/ble/cp/adapter.d.ts +23 -0
  51. package/lib/ble/cp/adapter.js +124 -0
  52. package/lib/ble/cp/comm.d.ts +28 -0
  53. package/lib/ble/cp/comm.js +140 -0
  54. package/lib/ble/cp/index.d.ts +4 -0
  55. package/lib/ble/cp/index.js +10 -0
  56. package/lib/ble/cp/types.d.ts +13 -0
  57. package/lib/ble/cp/types.js +2 -0
  58. package/lib/ble/elite/adapter.d.ts +20 -0
  59. package/lib/ble/elite/adapter.js +127 -0
  60. package/lib/ble/elite/comms.d.ts +28 -0
  61. package/lib/ble/elite/comms.js +139 -0
  62. package/lib/ble/elite/index.d.ts +3 -0
  63. package/lib/ble/elite/index.js +10 -0
  64. package/lib/ble/fm/adapter.d.ts +21 -0
  65. package/lib/ble/fm/adapter.js +190 -0
  66. package/lib/ble/fm/comms.d.ts +50 -0
  67. package/lib/ble/{fm.js → fm/comms.js} +3 -224
  68. package/lib/ble/fm/consts.d.ts +6 -0
  69. package/lib/ble/fm/consts.js +9 -0
  70. package/lib/ble/fm/index.d.ts +5 -0
  71. package/lib/ble/fm/index.js +13 -0
  72. package/lib/ble/fm/types.d.ts +25 -0
  73. package/lib/ble/fm/types.js +2 -0
  74. package/lib/ble/hr/adapter.d.ts +17 -0
  75. package/lib/ble/hr/adapter.js +62 -0
  76. package/lib/ble/hr/comm.d.ts +15 -0
  77. package/lib/ble/hr/comm.js +52 -0
  78. package/lib/ble/hr/index.d.ts +4 -0
  79. package/lib/ble/hr/index.js +10 -0
  80. package/lib/ble/hr/types.d.ts +5 -0
  81. package/lib/ble/hr/types.js +2 -0
  82. package/lib/ble/index.d.ts +8 -0
  83. package/lib/ble/index.js +26 -0
  84. package/lib/ble/tacx/adapter.d.ts +10 -0
  85. package/lib/ble/tacx/adapter.js +93 -0
  86. package/lib/ble/{tacx.d.ts → tacx/comms.d.ts} +6 -38
  87. package/lib/ble/{tacx.js → tacx/comms.js} +13 -112
  88. package/lib/ble/tacx/index.d.ts +4 -0
  89. package/lib/ble/tacx/index.js +10 -0
  90. package/lib/ble/tacx/types.d.ts +25 -0
  91. package/lib/ble/tacx/types.js +2 -0
  92. package/lib/ble/types.d.ts +101 -0
  93. package/lib/ble/types.js +19 -0
  94. package/lib/ble/utils.d.ts +7 -0
  95. package/lib/ble/utils.js +95 -0
  96. package/lib/ble/wahoo/adapter.d.ts +9 -0
  97. package/lib/ble/wahoo/adapter.js +93 -0
  98. package/lib/ble/{wahoo-kickr.d.ts → wahoo/comms.d.ts} +5 -39
  99. package/lib/ble/{wahoo-kickr.js → wahoo/comms.js} +14 -112
  100. package/lib/ble/wahoo/index.d.ts +4 -0
  101. package/lib/ble/wahoo/index.js +10 -0
  102. package/lib/ble/wahoo/types.d.ts +19 -0
  103. package/lib/ble/wahoo/types.js +2 -0
  104. package/lib/device.d.ts +0 -94
  105. package/lib/device.js +0 -76
  106. package/lib/index.d.ts +12 -0
  107. package/lib/index.js +38 -0
  108. package/lib/interfaces.d.ts +6 -0
  109. package/lib/interfaces.js +23 -0
  110. package/lib/{ble → modes}/ble-erg-mode.d.ts +4 -4
  111. package/lib/{ble → modes}/ble-erg-mode.js +2 -2
  112. package/lib/{ble → modes}/ble-st-mode.d.ts +3 -3
  113. package/lib/{ble → modes}/ble-st-mode.js +1 -1
  114. package/lib/{cycling-mode.d.ts → modes/cycling-mode.d.ts} +8 -8
  115. package/lib/modes/power-base.d.ts +3 -3
  116. package/lib/modes/power-base.js +4 -4
  117. package/lib/modes/power-meter.d.ts +3 -3
  118. package/lib/modes/simulator.d.ts +2 -2
  119. package/lib/modes/simulator.js +1 -1
  120. package/lib/serial/adapter-factory.d.ts +12 -0
  121. package/lib/serial/adapter-factory.js +30 -0
  122. package/lib/serial/adapter.d.ts +16 -0
  123. package/lib/serial/adapter.js +42 -0
  124. package/lib/serial/bindings/tcp.d.ts +44 -0
  125. package/lib/serial/bindings/tcp.js +270 -0
  126. package/lib/serial/comm.d.ts +7 -0
  127. package/lib/serial/comm.js +2 -0
  128. package/lib/{daum → serial/daum}/DaumAdapter.d.ts +13 -22
  129. package/lib/{daum → serial/daum}/DaumAdapter.js +44 -90
  130. package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.d.ts +2 -2
  131. package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.js +1 -1
  132. package/lib/{daum → serial/daum}/ERGCyclingMode.d.ts +3 -3
  133. package/lib/{daum → serial/daum}/ERGCyclingMode.js +3 -3
  134. package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.d.ts +3 -3
  135. package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.js +4 -3
  136. package/lib/serial/daum/classic/adapter.d.ts +29 -0
  137. package/lib/{daum/classic/DaumClassicAdapter.js → serial/daum/classic/adapter.js} +77 -50
  138. package/lib/{daum/classic/bike.d.ts → serial/daum/classic/comms.d.ts} +14 -16
  139. package/lib/{daum/classic/bike.js → serial/daum/classic/comms.js} +68 -152
  140. package/lib/serial/daum/classic/mock.d.ts +96 -0
  141. package/lib/serial/daum/classic/mock.js +365 -0
  142. package/lib/{daum/classic/DaumClassicCyclingMode.d.ts → serial/daum/classic/modes/daum-classic.d.ts} +3 -3
  143. package/lib/{daum/classic/DaumClassicCyclingMode.js → serial/daum/classic/modes/daum-classic.js} +2 -2
  144. package/lib/{daum → serial/daum}/classic/utils.d.ts +1 -1
  145. package/lib/serial/daum/premium/adapter.d.ts +24 -0
  146. package/lib/{daum/premium/DaumPremiumAdapter.js → serial/daum/premium/adapter.js} +99 -46
  147. package/lib/{daum/premium/bike.d.ts → serial/daum/premium/comms.d.ts} +26 -54
  148. package/lib/{daum/premium/bike.js → serial/daum/premium/comms.js} +208 -420
  149. package/lib/serial/daum/premium/mock.d.ts +75 -0
  150. package/lib/serial/daum/premium/mock.js +290 -0
  151. package/lib/{daum/premium/DaumClassicCyclingMode.d.ts → serial/daum/premium/modes/daum-classic.d.ts} +3 -3
  152. package/lib/{daum/premium/DaumClassicCyclingMode.js → serial/daum/premium/modes/daum-classic.js} +2 -2
  153. package/lib/serial/daum/premium/types.d.ts +12 -0
  154. package/lib/serial/daum/premium/types.js +2 -0
  155. package/lib/{daum → serial/daum}/premium/utils.d.ts +8 -11
  156. package/lib/{daum → serial/daum}/premium/utils.js +22 -63
  157. package/lib/serial/index.d.ts +9 -0
  158. package/lib/serial/index.js +49 -0
  159. package/lib/{kettler → serial/kettler}/comms.d.ts +8 -6
  160. package/lib/{kettler → serial/kettler}/comms.js +71 -32
  161. package/lib/{kettler → serial/kettler}/ergo-racer/adapter.d.ts +13 -24
  162. package/lib/{kettler → serial/kettler}/ergo-racer/adapter.js +87 -130
  163. package/lib/serial/kettler/ergo-racer/mock.d.ts +66 -0
  164. package/lib/serial/kettler/ergo-racer/mock.js +216 -0
  165. package/lib/{kettler/ergo-racer/ERGCyclingMode.d.ts → serial/kettler/ergo-racer/modes/erg.d.ts} +4 -4
  166. package/lib/{kettler/ergo-racer/ERGCyclingMode.js → serial/kettler/ergo-racer/modes/erg.js} +2 -2
  167. package/lib/serial/serial-interface.d.ts +58 -0
  168. package/lib/serial/serial-interface.js +283 -0
  169. package/lib/simulator/Simulator.d.ts +10 -25
  170. package/lib/simulator/Simulator.js +19 -83
  171. package/lib/types/adapter.d.ts +32 -0
  172. package/lib/types/adapter.js +2 -0
  173. package/lib/types/capabilities.d.ts +8 -0
  174. package/lib/types/capabilities.js +12 -0
  175. package/lib/types/data.d.ts +12 -0
  176. package/lib/types/data.js +2 -0
  177. package/lib/types/device.d.ts +29 -0
  178. package/lib/types/device.js +11 -0
  179. package/lib/types/interface.d.ts +14 -0
  180. package/lib/types/interface.js +2 -0
  181. package/lib/types/route.d.ts +2 -2
  182. package/lib/types/user.d.ts +1 -1
  183. package/lib/{utils.d.ts → utils/utils.d.ts} +1 -0
  184. package/lib/{utils.js → utils/utils.js} +5 -1
  185. package/package.json +15 -11
  186. package/lib/DeviceSupport.d.ts +0 -36
  187. package/lib/DeviceSupport.js +0 -82
  188. package/lib/ant/AntAdapter.d.ts +0 -50
  189. package/lib/ant/AntAdapter.js +0 -109
  190. package/lib/ant/AntScanner.d.ts +0 -60
  191. package/lib/ant/AntScanner.js +0 -651
  192. package/lib/ant/antfe/AntFEAdapter.d.ts +0 -83
  193. package/lib/ant/antfe/AntFEAdapter.js +0 -652
  194. package/lib/ant/antfe/ant-fe-adv-st-mode.d.ts +0 -9
  195. package/lib/ant/antfe/ant-fe-erg-mode.d.ts +0 -6
  196. package/lib/ant/antfe/ant-fe-st-mode.d.ts +0 -5
  197. package/lib/ant/anthrm/AntHrmAdapter.d.ts +0 -16
  198. package/lib/ant/anthrm/AntHrmAdapter.js +0 -130
  199. package/lib/ant/antpwr/pwr-adapter.d.ts +0 -49
  200. package/lib/ant/antpwr/pwr-adapter.js +0 -251
  201. package/lib/ant/utils.d.ts +0 -1
  202. package/lib/ant/utils.js +0 -23
  203. package/lib/antv2/AntAdapter.d.ts +0 -48
  204. package/lib/antv2/AntAdapter.js +0 -104
  205. package/lib/antv2/ant-device.d.ts +0 -59
  206. package/lib/antv2/ant-device.js +0 -161
  207. package/lib/antv2/fe.d.ts +0 -32
  208. package/lib/antv2/hr.d.ts +0 -18
  209. package/lib/antv2/hr.js +0 -102
  210. package/lib/antv2/incyclist-protocol.d.ts +0 -37
  211. package/lib/antv2/incyclist-protocol.js +0 -126
  212. package/lib/antv2/pwr.d.ts +0 -28
  213. package/lib/ble/elite.d.ts +0 -90
  214. package/lib/ble/elite.js +0 -322
  215. package/lib/ble/fm.d.ts +0 -125
  216. package/lib/ble/hrm.d.ts +0 -48
  217. package/lib/ble/hrm.js +0 -134
  218. package/lib/ble/incyclist-protocol.d.ts +0 -31
  219. package/lib/ble/incyclist-protocol.js +0 -153
  220. package/lib/ble/pwr.d.ts +0 -89
  221. package/lib/ble/pwr.js +0 -322
  222. package/lib/daum/classic/DaumClassicAdapter.d.ts +0 -28
  223. package/lib/daum/classic/DaumClassicProtocol.d.ts +0 -27
  224. package/lib/daum/classic/DaumClassicProtocol.js +0 -185
  225. package/lib/daum/premium/DaumPremiumAdapter.d.ts +0 -16
  226. package/lib/daum/premium/DaumPremiumProtocol.d.ts +0 -32
  227. package/lib/daum/premium/DaumPremiumProtocol.js +0 -207
  228. package/lib/daum/premium/tcpserial.d.ts +0 -33
  229. package/lib/daum/premium/tcpserial.js +0 -123
  230. package/lib/kettler/ergo-racer/protocol.d.ts +0 -41
  231. package/lib/kettler/ergo-racer/protocol.js +0 -203
  232. package/lib/protocol.d.ts +0 -74
  233. package/lib/protocol.js +0 -41
  234. package/lib/registry.d.ts +0 -8
  235. package/lib/registry.js +0 -33
  236. package/lib/serialport/bindings/tcp.d.ts +0 -20
  237. package/lib/serialport/bindings/tcp.js +0 -33
  238. package/lib/serialport/index.d.ts +0 -2
  239. package/lib/serialport/index.js +0 -29
  240. package/lib/serialport/serialport.d.ts +0 -29
  241. package/lib/serialport/serialport.js +0 -87
  242. /package/lib/antv2/{ant-binding.d.ts → binding.d.ts} +0 -0
  243. /package/lib/antv2/{ant-binding.js → binding.js} +0 -0
  244. /package/lib/{cycling-mode.js → modes/cycling-mode.js} +0 -0
  245. /package/lib/{daum → serial/daum}/classic/utils.js +0 -0
  246. /package/lib/{daum → serial/daum}/constants.d.ts +0 -0
  247. /package/lib/{daum → serial/daum}/constants.js +0 -0
  248. /package/lib/{serialport.d.ts → serial/serialport.d.ts} +0 -0
  249. /package/lib/{serialport.js → serial/serialport.js} +0 -0
  250. /package/lib/{calculations.d.ts → utils/calculations.d.ts} +0 -0
  251. /package/lib/{calculations.js → utils/calculations.js} +0 -0
package/README.MD ADDED
File without changes
@@ -0,0 +1,6 @@
1
+ import { IncyclistDeviceAdapter } from "./types/adapter";
2
+ import { DeviceProperties, DeviceSettings } from "./types/device";
3
+ export default class AdapterFactory {
4
+ static adapters: IncyclistDeviceAdapter[];
5
+ static create(settings: DeviceSettings, props?: DeviceProperties): any;
6
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const antv2_1 = require("./antv2");
4
+ const serial_1 = require("./serial");
5
+ const device_1 = require("./types/device");
6
+ class AdapterFactory {
7
+ static create(settings, props) {
8
+ const adapters = AdapterFactory.adapters;
9
+ const existing = adapters.find(a => a.isEqual(settings));
10
+ if (existing)
11
+ return existing;
12
+ const ifaceName = typeof settings.interface === 'string' ? settings.interface : settings.interface.getName();
13
+ let adapter;
14
+ switch (ifaceName) {
15
+ case device_1.INTERFACE.SERIAL:
16
+ case device_1.INTERFACE.TCPIP:
17
+ adapter = serial_1.SerialAdapterFactory.getInstance().createInstance(settings, props);
18
+ break;
19
+ case device_1.INTERFACE.ANT:
20
+ adapter = antv2_1.AntAdapterFactory.getInstance().createInstance(settings, props);
21
+ break;
22
+ }
23
+ if (adapter) {
24
+ adapters.push(adapter);
25
+ }
26
+ return adapter;
27
+ }
28
+ }
29
+ exports.default = AdapterFactory;
30
+ AdapterFactory.adapters = [];
@@ -1,11 +1,21 @@
1
- import AntProtocol, { AntDeviceSettings } from "./incyclist-protocol";
2
- import AntAdapter from "./ant-device";
3
- export default class AdapterFactory {
4
- static create(settings: {
5
- configuration?: AntDeviceSettings;
6
- detected?: {
7
- profile: string;
8
- deviceID: number;
9
- };
10
- }, protocol: AntProtocol): AntAdapter;
1
+ import AntAdapter from "./adapter";
2
+ import { AntDeviceProperties, AntDeviceSettings } from "./types";
3
+ export type AntAdapterInfo = {
4
+ antProfile: string;
5
+ incyclistProfile: string;
6
+ Adapter: typeof AntAdapter;
7
+ };
8
+ export type AdapterQuery = {
9
+ antProfile?: string;
10
+ incyclistProfile?: string;
11
+ };
12
+ export default class AntAdapterFactory {
13
+ static _instance: AntAdapterFactory;
14
+ adapters: AntAdapterInfo[];
15
+ static getInstance(): AntAdapterFactory;
16
+ constructor();
17
+ register(antProfile: string, incyclistProfile: string, Adapter: typeof AntAdapter): void;
18
+ getAdapter(query?: AdapterQuery): any;
19
+ createInstance(settings: AntDeviceSettings, props?: AntDeviceProperties): any;
20
+ createFromDetected(profile: string, deviceID: number, props?: AntDeviceProperties): any;
11
21
  }
@@ -1,40 +1,56 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const incyclist_protocol_1 = require("./incyclist-protocol");
7
- const fe_1 = __importDefault(require("./fe"));
8
- const hr_1 = __importDefault(require("./hr"));
9
- const pwr_1 = __importDefault(require("./pwr"));
10
- const sensor_factory_1 = __importDefault(require("./sensor-factory"));
11
- const profiles = [
12
- { profile: 'PWR', Class: pwr_1.default },
13
- { profile: 'HR', Class: hr_1.default },
14
- { profile: 'FE', Class: fe_1.default },
15
- ];
16
- class AdapterFactory {
17
- static create(settings, protocol) {
18
- let profile;
19
- let deviceID;
20
- if (settings && settings.configuration) {
21
- profile = (0, incyclist_protocol_1.mapIncyclistProfile)(settings.configuration.profile);
22
- deviceID = settings.configuration.deviceID;
23
- }
24
- else if (settings && settings.detected) {
25
- profile = settings.detected.profile;
26
- deviceID = settings.detected.deviceID;
3
+ class AntAdapterFactory {
4
+ static getInstance() {
5
+ if (!AntAdapterFactory._instance)
6
+ AntAdapterFactory._instance = new AntAdapterFactory();
7
+ return AntAdapterFactory._instance;
8
+ }
9
+ constructor() {
10
+ this.adapters = [];
11
+ }
12
+ register(antProfile, incyclistProfile, Adapter) {
13
+ const info = Object.assign({}, { antProfile, incyclistProfile, Adapter });
14
+ const existing = this.adapters.findIndex(a => a.antProfile === antProfile);
15
+ if (existing !== -1)
16
+ this.adapters[existing] = info;
17
+ else
18
+ this.adapters.push(info);
19
+ }
20
+ getAdapter(query) {
21
+ const { antProfile, incyclistProfile } = query;
22
+ if (!antProfile && !incyclistProfile)
23
+ throw new Error('Illegal arguments: either "antProfile" or "incyclistProfile" must be set');
24
+ let found;
25
+ if (antProfile)
26
+ found = this.adapters.find(a => a.antProfile === antProfile);
27
+ if (incyclistProfile)
28
+ found = this.adapters.find(a => a.incyclistProfile === incyclistProfile);
29
+ return found;
30
+ }
31
+ createInstance(settings, props) {
32
+ let info;
33
+ const { profile, protocol } = settings;
34
+ if (protocol) {
35
+ info = this.getAdapter({ incyclistProfile: profile });
27
36
  }
28
37
  else {
29
- return;
30
- }
31
- const sensor = sensor_factory_1.default.create(profile, Number(deviceID));
32
- if (sensor) {
33
- const info = profiles.find(i => i.profile === profile);
34
- if (!info)
35
- return;
36
- return new info.Class(sensor, protocol);
38
+ info = this.getAdapter({ antProfile: profile });
37
39
  }
40
+ if (info && info.Adapter)
41
+ return new info.Adapter(settings, props);
42
+ }
43
+ createFromDetected(profile, deviceID, props) {
44
+ const info = this.getAdapter({ antProfile: profile });
45
+ if (!info || !info.Adapter)
46
+ return;
47
+ const settings = Object.assign({}, {
48
+ profile: info.incyclistProfile,
49
+ deviceID: deviceID.toString(),
50
+ interface: 'ant',
51
+ protocol: 'Ant'
52
+ });
53
+ return new info.Adapter(settings, props);
38
54
  }
39
55
  }
40
- exports.default = AdapterFactory;
56
+ exports.default = AntAdapterFactory;
@@ -0,0 +1,64 @@
1
+ /// <reference types="node" />
2
+ import { IChannel, ISensor } from 'incyclist-ant-plus';
3
+ import AntInterface from './ant-interface';
4
+ import IncyclistDevice from '../base/adpater';
5
+ import { AntDeviceProperties, AntDeviceSettings } from './types';
6
+ import { DeviceProperties } from '../types/device';
7
+ import { Bike, IncyclistDeviceAdapter, OnDeviceDataCallback } from '../types/adapter';
8
+ import CyclingMode from '../modes/cycling-mode';
9
+ import { User } from '../types/user';
10
+ export declare const DEFAULT_UPDATE_FREQUENCY = 1000;
11
+ export default class AntAdapter extends IncyclistDevice {
12
+ sensor: ISensor;
13
+ lastUpdate?: number;
14
+ data: any;
15
+ deviceData: any;
16
+ updateFrequency: number;
17
+ channel: IChannel;
18
+ ant: AntInterface;
19
+ userSettings: {
20
+ weight?: number;
21
+ };
22
+ bikeSettings: {
23
+ weight?: number;
24
+ };
25
+ onDataFn: OnDeviceDataCallback;
26
+ startupRetryPause: number;
27
+ protected ivDataTimeout: NodeJS.Timer;
28
+ protected lastDataTS: number;
29
+ protected dataMsgCount: number;
30
+ protected ivWaitForData: NodeJS.Timer;
31
+ constructor(settings: AntDeviceSettings, props?: DeviceProperties);
32
+ createSensor(settings: AntDeviceSettings): ISensor;
33
+ isEqual(settings: AntDeviceSettings): boolean;
34
+ connect(): Promise<boolean>;
35
+ close(): Promise<boolean>;
36
+ resetData(): void;
37
+ isSame(device: IncyclistDeviceAdapter): boolean;
38
+ hasData(): boolean;
39
+ onDeviceData(deviceData: any): void;
40
+ waitForData(timeout: number): Promise<unknown>;
41
+ getID(): string;
42
+ getName(): string;
43
+ getInterface(): string;
44
+ getProfile(): string;
45
+ startDataTimeoutCheck(): void;
46
+ stopDataTimeoutCheck(): void;
47
+ check(): Promise<boolean>;
48
+ checkCapabilities(): Promise<void>;
49
+ initControl(): Promise<void>;
50
+ start(props?: AntDeviceProperties): Promise<boolean>;
51
+ stop(): Promise<boolean>;
52
+ }
53
+ export declare class ControllableAntAdapter extends AntAdapter implements Bike {
54
+ cyclingMode: CyclingMode;
55
+ user?: User;
56
+ constructor(settings: AntDeviceSettings, props?: AntDeviceProperties);
57
+ setUser(user: User): void;
58
+ setBikeProps(props: DeviceProperties): void;
59
+ getWeight(): number;
60
+ getSupportedCyclingModes(): any[];
61
+ getDefaultCyclingMode(): CyclingMode;
62
+ setCyclingMode(mode: CyclingMode | string, settings?: any): void;
63
+ getCyclingMode(): CyclingMode;
64
+ }
@@ -0,0 +1,299 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.ControllableAntAdapter = exports.DEFAULT_UPDATE_FREQUENCY = void 0;
39
+ const ant_interface_1 = __importDefault(require("./ant-interface"));
40
+ const adpater_1 = __importStar(require("../base/adpater"));
41
+ const utils_1 = require("../utils/utils");
42
+ const capabilities_1 = require("../types/capabilities");
43
+ const adpater_2 = require("../base/adpater");
44
+ const utils_2 = require("./utils");
45
+ exports.DEFAULT_UPDATE_FREQUENCY = 1000;
46
+ const NO_DATA_TIMEOUT = 5000;
47
+ const INTERFACE_NAME = 'ant';
48
+ class AntAdapter extends adpater_1.default {
49
+ constructor(settings, props) {
50
+ super(settings, props);
51
+ this.startupRetryPause = 1000;
52
+ if (this.settings.interface !== 'ant')
53
+ throw new Error('Incorrect interface');
54
+ this.sensor = this.createSensor(settings);
55
+ this.deviceData = {};
56
+ this.data = {};
57
+ this.dataMsgCount = 0;
58
+ this.updateFrequency = exports.DEFAULT_UPDATE_FREQUENCY;
59
+ this.channel = undefined;
60
+ this.ant = ant_interface_1.default.getInstance();
61
+ }
62
+ createSensor(settings) {
63
+ throw new Error('Method not implemented.');
64
+ }
65
+ isEqual(settings) {
66
+ const as = this.settings;
67
+ if (as.interface !== settings.interface)
68
+ return false;
69
+ if (as.deviceID != settings.deviceID || as.profile !== settings.profile)
70
+ return false;
71
+ return true;
72
+ }
73
+ connect() {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ const connected = yield ant_interface_1.default.getInstance().connect();
76
+ return connected;
77
+ });
78
+ }
79
+ close() {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ return true;
82
+ });
83
+ }
84
+ resetData() {
85
+ this.dataMsgCount = 0;
86
+ const { DeviceID } = this.deviceData;
87
+ this.deviceData = { DeviceID };
88
+ this.lastDataTS = undefined;
89
+ }
90
+ isSame(device) {
91
+ if (!(device instanceof AntAdapter))
92
+ return false;
93
+ const adapter = device;
94
+ return (adapter.getID() === this.getID() && adapter.getProfile() === this.getProfile());
95
+ }
96
+ hasData() {
97
+ return this.dataMsgCount > 0;
98
+ }
99
+ onDeviceData(deviceData) {
100
+ const { ManId } = this.deviceData;
101
+ this.deviceData = Object.assign({}, deviceData);
102
+ if (!ManId && deviceData.ManId) {
103
+ this.emit('device-info', { manufacturer: (0, utils_2.getBrand)(deviceData.ManId) });
104
+ }
105
+ }
106
+ waitForData(timeout) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ const startTs = Date.now();
109
+ const timeoutTs = startTs + timeout;
110
+ if (this.hasData())
111
+ return true;
112
+ return new Promise((resolve, reject) => {
113
+ if (this.ivWaitForData)
114
+ return reject(new Error('busy'));
115
+ this.ivWaitForData = setInterval(() => {
116
+ const nowTs = Date.now();
117
+ const hasData = this.hasData();
118
+ if (nowTs > timeoutTs && !hasData) {
119
+ clearInterval(this.ivWaitForData);
120
+ this.ivWaitForData = undefined;
121
+ reject(new Error('No Data Received'));
122
+ }
123
+ if (hasData) {
124
+ clearInterval(this.ivWaitForData);
125
+ this.ivWaitForData = undefined;
126
+ resolve(true);
127
+ }
128
+ }, 500);
129
+ });
130
+ });
131
+ }
132
+ getID() {
133
+ return this.sensor.getDeviceID().toString();
134
+ }
135
+ getName() {
136
+ const deviceID = this.sensor.getDeviceID();
137
+ const profile = this.sensor.getProfile();
138
+ return `Ant+${profile} ${deviceID}`;
139
+ }
140
+ getInterface() {
141
+ return INTERFACE_NAME;
142
+ }
143
+ getProfile() {
144
+ const settings = this.settings;
145
+ return settings.profile;
146
+ }
147
+ startDataTimeoutCheck() {
148
+ if (this.ivDataTimeout)
149
+ return;
150
+ this.ivDataTimeout = setInterval(() => {
151
+ if (!this.lastDataTS)
152
+ return;
153
+ if (this.lastDataTS + NO_DATA_TIMEOUT < Date.now()) {
154
+ this.emit('disconnected', Date.now() - this.lastDataTS);
155
+ }
156
+ }, 1000);
157
+ }
158
+ stopDataTimeoutCheck() {
159
+ if (!this.ivDataTimeout)
160
+ return;
161
+ clearInterval(this.ivDataTimeout);
162
+ this.ivDataTimeout = undefined;
163
+ this.lastDataTS = undefined;
164
+ this.dataMsgCount = 0;
165
+ }
166
+ check() {
167
+ return __awaiter(this, void 0, void 0, function* () {
168
+ try {
169
+ return yield this.start();
170
+ }
171
+ catch (error) {
172
+ return false;
173
+ }
174
+ });
175
+ }
176
+ checkCapabilities() {
177
+ return __awaiter(this, void 0, void 0, function* () {
178
+ return;
179
+ });
180
+ }
181
+ initControl() {
182
+ return __awaiter(this, void 0, void 0, function* () {
183
+ return;
184
+ });
185
+ }
186
+ start(props = {}) {
187
+ return __awaiter(this, void 0, void 0, function* () {
188
+ if (this.started)
189
+ return true;
190
+ const connected = yield this.connect();
191
+ if (!connected)
192
+ throw new Error(`could not start device, reason:could not connect`);
193
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
194
+ this.resetData();
195
+ this.stopped = false;
196
+ const { startupTimeout = 20000 } = props;
197
+ let to = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
198
+ try {
199
+ yield this.stop();
200
+ }
201
+ catch (_a) { }
202
+ this.started = false;
203
+ reject(new Error(`could not start device, reason:timeout`));
204
+ }), startupTimeout);
205
+ let started = false;
206
+ do {
207
+ started = yield this.ant.startSensor(this.sensor, (data) => {
208
+ this.onDeviceData(data);
209
+ });
210
+ if (!started)
211
+ yield (0, utils_1.sleep)(this.startupRetryPause);
212
+ } while (!started);
213
+ try {
214
+ yield this.waitForData(startupTimeout - 100);
215
+ yield this.checkCapabilities();
216
+ if (this.hasCapability(capabilities_1.IncyclistCapability.Control))
217
+ yield this.initControl();
218
+ this.started = true;
219
+ if (to)
220
+ clearTimeout(to);
221
+ resolve(true);
222
+ }
223
+ catch (err) {
224
+ }
225
+ }));
226
+ });
227
+ }
228
+ stop() {
229
+ return __awaiter(this, void 0, void 0, function* () {
230
+ this.stopDataTimeoutCheck();
231
+ let stopped = yield this.ant.stopSensor(this.sensor);
232
+ if (!stopped)
233
+ return false;
234
+ this.started = false;
235
+ this.stopped = true;
236
+ this.removeAllListeners();
237
+ return true;
238
+ });
239
+ }
240
+ }
241
+ exports.default = AntAdapter;
242
+ class ControllableAntAdapter extends AntAdapter {
243
+ constructor(settings, props) {
244
+ super(settings, props);
245
+ this.cyclingMode = this.getDefaultCyclingMode();
246
+ this.user = {};
247
+ }
248
+ setUser(user) {
249
+ this.user = user;
250
+ if (!user.weight)
251
+ this.user.weight = adpater_2.DEFAULT_USER_WEIGHT;
252
+ }
253
+ setBikeProps(props) {
254
+ const { user, userWeight, bikeWeight } = props || {};
255
+ if (user)
256
+ this.setUser(user);
257
+ if (userWeight)
258
+ this.user.weight = userWeight;
259
+ const keys = Object.keys(props);
260
+ keys.forEach(k => {
261
+ const p = props[k];
262
+ if (p === null)
263
+ delete this.props[k];
264
+ else if (p !== undefined)
265
+ this.props[k] = p;
266
+ });
267
+ }
268
+ getWeight() {
269
+ const { user = {}, props = adpater_2.DEFAULT_PROPS } = this;
270
+ const userWeight = user.weight || props.userWeight || adpater_2.DEFAULT_USER_WEIGHT;
271
+ const bikeWeight = props.bikeWeight || adpater_1.DEFAULT_BIKE_WEIGHT;
272
+ return userWeight + bikeWeight;
273
+ }
274
+ getSupportedCyclingModes() { throw new Error('not implemented'); }
275
+ getDefaultCyclingMode() { throw new Error('not implemented'); }
276
+ setCyclingMode(mode, settings) {
277
+ let selectedMode;
278
+ if (typeof mode === 'string') {
279
+ const supported = this.getSupportedCyclingModes();
280
+ const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
281
+ if (CyclingModeClass) {
282
+ this.cyclingMode = new CyclingModeClass(this, settings);
283
+ return;
284
+ }
285
+ selectedMode = this.getDefaultCyclingMode();
286
+ }
287
+ else {
288
+ selectedMode = mode;
289
+ }
290
+ this.cyclingMode = selectedMode;
291
+ this.cyclingMode.setSettings(settings);
292
+ }
293
+ getCyclingMode() {
294
+ if (!this.cyclingMode)
295
+ this.setCyclingMode(this.getDefaultCyclingMode());
296
+ return this.cyclingMode;
297
+ }
298
+ }
299
+ exports.ControllableAntAdapter = ControllableAntAdapter;
@@ -2,15 +2,16 @@
2
2
  import EventEmitter from "events";
3
3
  import { EventLogger } from "gd-eventlog";
4
4
  import { IAntDevice, IChannel, ISensor } from "incyclist-ant-plus";
5
- import AntDeviceBinding from "./ant-binding";
6
- import { AntScannerProps } from "./incyclist-protocol";
7
- export declare type AntInterfaceProps = {
8
- binding?: typeof AntDeviceBinding;
9
- logger?: EventLogger;
5
+ import { InterfaceProps } from "../types/interface";
6
+ import AntDeviceBinding from "./binding";
7
+ import { IncyclistInterface } from "../types/interface";
8
+ import { AntDeviceSettings, AntScanProps } from "./types";
9
+ export interface AntInterfaceProps extends InterfaceProps {
10
10
  startupTimeout?: number;
11
- };
12
- export default class AntInterface extends EventEmitter {
11
+ }
12
+ export default class AntInterface extends EventEmitter implements IncyclistInterface {
13
13
  static _instance: AntInterface;
14
+ static INTERFACE_NAME: string;
14
15
  static getInstance(props?: AntInterfaceProps): AntInterface;
15
16
  static hasInstance(): boolean;
16
17
  protected logger: EventLogger;
@@ -21,15 +22,16 @@ export default class AntInterface extends EventEmitter {
21
22
  protected props: AntInterfaceProps;
22
23
  protected activeScan: IChannel;
23
24
  constructor(props: AntInterfaceProps);
25
+ getName(): string;
24
26
  getBinding(): typeof AntDeviceBinding;
25
27
  setBinding(binding: typeof AntDeviceBinding): void;
26
28
  setLogger(logger: EventLogger): void;
27
29
  logEvent(event: any): void;
28
- connect(): Promise<unknown>;
30
+ connect(): Promise<boolean>;
29
31
  disconnect(): Promise<boolean>;
30
32
  onError(profile: any, error: any): void;
31
33
  onData(profile: any, id: any, data: any, tag: any): void;
32
- scan(props?: AntScannerProps): Promise<unknown>;
34
+ scan(props?: AntScanProps): Promise<AntDeviceSettings[]>;
33
35
  stopScan(): Promise<boolean>;
34
36
  startSensor(sensor: ISensor, onDeviceData: (data: any) => void): Promise<boolean>;
35
37
  stopSensor(sensor: ISensor): Promise<boolean>;
@@ -16,6 +16,14 @@ const events_1 = __importDefault(require("events"));
16
16
  const gd_eventlog_1 = require("gd-eventlog");
17
17
  const sensor_factory_1 = __importDefault(require("./sensor-factory"));
18
18
  class AntInterface extends events_1.default {
19
+ static getInstance(props = {}) {
20
+ if (AntInterface._instance === undefined)
21
+ AntInterface._instance = new AntInterface(props);
22
+ return AntInterface._instance;
23
+ }
24
+ static hasInstance() {
25
+ return AntInterface._instance !== undefined;
26
+ }
19
27
  constructor(props) {
20
28
  super();
21
29
  this.props = props;
@@ -32,13 +40,8 @@ class AntInterface extends events_1.default {
32
40
  this.Binding = binding;
33
41
  }
34
42
  }
35
- static getInstance(props = {}) {
36
- if (AntInterface._instance === undefined)
37
- AntInterface._instance = new AntInterface(props);
38
- return AntInterface._instance;
39
- }
40
- static hasInstance() {
41
- return AntInterface._instance !== undefined;
43
+ getName() {
44
+ return AntInterface.INTERFACE_NAME;
42
45
  }
43
46
  getBinding() {
44
47
  return this.Binding;
@@ -94,10 +97,10 @@ class AntInterface extends events_1.default {
94
97
  return __awaiter(this, void 0, void 0, function* () {
95
98
  if (!this.device)
96
99
  return true;
97
- this.logEvent({ message: 'disconnecting ...' });
100
+ this.logEvent({ message: 'ANT+ disconnecting ...' });
98
101
  const closed = yield this.device.close();
99
102
  this.isConnected = !closed;
100
- this.logEvent({ message: 'disconnected' });
103
+ this.logEvent({ message: 'ANT+ disconnected' });
101
104
  return closed;
102
105
  });
103
106
  }
@@ -119,8 +122,8 @@ class AntInterface extends events_1.default {
119
122
  const onDetected = (profile, deviceID) => {
120
123
  if (deviceID && detected.find(s => s.deviceID === deviceID && s.profile === profile) === undefined) {
121
124
  try {
122
- detected.push({ profile, deviceID });
123
- this.emit('detected', profile, deviceID);
125
+ detected.push({ interface: this.getName(), profile, deviceID });
126
+ this.emit('device', profile, deviceID);
124
127
  }
125
128
  catch (err) {
126
129
  this.logEvent({ message: 'error', fn: 'onDerected', error: err.message, stack: err.stack });
@@ -267,3 +270,4 @@ class AntInterface extends events_1.default {
267
270
  }
268
271
  exports.default = AntInterface;
269
272
  AntInterface._instance = undefined;
273
+ AntInterface.INTERFACE_NAME = 'ant';
@@ -0,0 +1,25 @@
1
+ import { ISensor } from "incyclist-ant-plus";
2
+ import { ControllableAntAdapter } from "../adapter";
3
+ import CyclingMode, { IncyclistBikeData } from '../../modes/cycling-mode';
4
+ import { AntDeviceProperties, AntDeviceSettings } from "../types";
5
+ export default class AntFEAdapter extends ControllableAntAdapter {
6
+ static INCYCLIST_PROFILE_NAME: string;
7
+ static ANT_PROFILE_NAME: string;
8
+ protected distanceInternal?: number;
9
+ protected startProps: AntDeviceProperties;
10
+ protected isReconnecting: boolean;
11
+ constructor(settings: AntDeviceSettings, props?: AntDeviceProperties);
12
+ createSensor(settings: AntDeviceSettings): ISensor;
13
+ getName(): string;
14
+ getDisplayName(): string;
15
+ getSupportedCyclingModes(): Array<any>;
16
+ getDefaultCyclingMode(): CyclingMode;
17
+ getLogData(data: any, excludeList: any): any;
18
+ sendUpdate(request: any): Promise<void>;
19
+ onDeviceData(deviceData: any): void;
20
+ mapData(deviceData: any): IncyclistBikeData;
21
+ transformData(bikeData: any): any;
22
+ start(props?: any): Promise<any>;
23
+ setFEDefaultTimeout(): void;
24
+ reconnect(): Promise<boolean>;
25
+ }