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
@@ -1,203 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
- var __importDefault = (this && this.__importDefault) || function (mod) {
31
- return (mod && mod.__esModule) ? mod : { "default": mod };
32
- };
33
- Object.defineProperty(exports, "__esModule", { value: true });
34
- const protocol_1 = __importStar(require("../../protocol"));
35
- const gd_eventlog_1 = require("gd-eventlog");
36
- const registry_1 = __importDefault(require("../../registry"));
37
- const adapter_1 = __importDefault(require("./adapter"));
38
- const PROTOCOL_NAME = 'Kettler Racer';
39
- var ScanState;
40
- (function (ScanState) {
41
- ScanState[ScanState["IDLE"] = 0] = "IDLE";
42
- ScanState[ScanState["SCANNING"] = 1] = "SCANNING";
43
- ScanState[ScanState["STOPPING"] = 2] = "STOPPING";
44
- ScanState[ScanState["STOPPED"] = 3] = "STOPPED";
45
- })(ScanState || (ScanState = {}));
46
- class KettlerRacerProtocol extends protocol_1.default {
47
- constructor() {
48
- super();
49
- this.state = ScanState.IDLE;
50
- this.logger = new gd_eventlog_1.EventLogger('KettlerRacer');
51
- this.activeScans = [];
52
- this.devices = [];
53
- }
54
- getSerialPort() {
55
- return protocol_1.default.getSerialPort();
56
- }
57
- getInterfaces() {
58
- return [protocol_1.INTERFACE.SERIAL];
59
- }
60
- getName() {
61
- return PROTOCOL_NAME;
62
- }
63
- isBike() {
64
- return true;
65
- }
66
- isHrm() {
67
- return true;
68
- }
69
- isPower() {
70
- return true;
71
- }
72
- add(settings) {
73
- this.logger.logEvent({ message: 'adding device', settings });
74
- if (this.devices.length > 0) {
75
- const found = this.devices.find(d => d.getPort() === settings.port);
76
- if (found)
77
- return found;
78
- }
79
- let device = new adapter_1.default(this, settings);
80
- this.devices.push(device);
81
- return device;
82
- }
83
- scan(props) {
84
- this.logger.logEvent({ message: 'start scan', id: props.id, port: props.port });
85
- this.state = ScanState.SCANNING;
86
- const isAlreadyKnownOrScanning = this.checkDevice(props.port);
87
- if (!isAlreadyKnownOrScanning) {
88
- const port = props.port;
89
- const name = PROTOCOL_NAME;
90
- const device = new adapter_1.default(this, { name, port });
91
- const iv = setInterval(() => { this.doScan(port); }, 1000);
92
- this.activeScans.push({ iv, device, port, state: ScanState.IDLE, props });
93
- }
94
- }
95
- checkDevice(port) {
96
- if (this.devices.length > 0 && this.devices.findIndex(d => d.getPort() === port) >= 0)
97
- return true;
98
- if (this.activeScans.length > 0 && this.activeScans.findIndex(d => d.port === port) >= 0)
99
- return true;
100
- return false;
101
- }
102
- doScan(port) {
103
- const job = this.activeScans.find(d => d.port === port);
104
- if (!job)
105
- return;
106
- if (this.state === ScanState.STOPPING || job.state === ScanState.STOPPING)
107
- return;
108
- const device = job.device;
109
- if (device && (device.isDetected() || device.isSelected()))
110
- return;
111
- this.state = ScanState.SCANNING;
112
- job.state = ScanState.SCANNING;
113
- return device.check()
114
- .then((found) => __awaiter(this, void 0, void 0, function* () {
115
- if (found) {
116
- if (this.state === ScanState.STOPPING || this.state === ScanState.STOPPED)
117
- return;
118
- const { onDeviceFound, onScanFinished, id } = job.props;
119
- device.setDetected();
120
- if (onDeviceFound)
121
- onDeviceFound(device, device.getProtocol());
122
- if (onScanFinished) {
123
- onScanFinished(id);
124
- }
125
- }
126
- job.state = ScanState.STOPPED;
127
- try {
128
- yield device.waitForClosed();
129
- }
130
- catch (err) {
131
- this.logger.logEvent({ message: 'scanCommand warning: Could not close port', error: err.message });
132
- }
133
- clearInterval(job.iv);
134
- job.iv = null;
135
- job.state = ScanState.STOPPED;
136
- const idxActiveScan = this.activeScans.findIndex(d => d.state !== ScanState.STOPPED);
137
- if (idxActiveScan === -1) {
138
- this.state = ScanState.STOPPED;
139
- }
140
- }))
141
- .catch(() => {
142
- job.state = ScanState.STOPPED;
143
- });
144
- }
145
- doStopScan(job) {
146
- return __awaiter(this, void 0, void 0, function* () {
147
- if (!job)
148
- return;
149
- if (job.state === ScanState.STOPPING || job.state === ScanState.STOPPED)
150
- return;
151
- job.state = ScanState.STOPPING;
152
- clearInterval(job.iv);
153
- job.iv = null;
154
- });
155
- }
156
- isJobStopped(job) {
157
- return job.state === ScanState.STOPPED && !job.iv;
158
- }
159
- waitForStop(timeout) {
160
- return new Promise((resolve) => {
161
- let timedOut = false;
162
- if (timeout)
163
- setTimeout(() => { timedOut = true; }, timeout);
164
- const iv = setInterval(() => {
165
- const idxActiveScan = this.activeScans.findIndex(d => this.isJobStopped(d) === false);
166
- if (idxActiveScan === -1) {
167
- clearInterval(iv);
168
- resolve(true);
169
- return;
170
- }
171
- if (timedOut) {
172
- clearInterval(iv);
173
- resolve(false);
174
- return;
175
- }
176
- }, 500);
177
- });
178
- }
179
- stopScan() {
180
- return __awaiter(this, void 0, void 0, function* () {
181
- if (this.state === ScanState.STOPPING || this.state === ScanState.STOPPED)
182
- return;
183
- this.state = ScanState.STOPPING;
184
- this.logger.logEvent({ message: 'stop scan', activeScans: this.activeScans.map(j => j.port) });
185
- this.activeScans.forEach(job => this.doStopScan(job));
186
- const stopped = yield this.waitForStop();
187
- if (!stopped) {
188
- this.logger.logEvent({ message: 'scanCommand warning: stop scan timeout' });
189
- }
190
- else {
191
- this.logger.logEvent({ message: 'stop scan completed' });
192
- }
193
- this.activeScans = [];
194
- this.state = ScanState.IDLE;
195
- return true;
196
- });
197
- }
198
- isScanning() {
199
- return this.state === ScanState.SCANNING;
200
- }
201
- }
202
- exports.default = KettlerRacerProtocol;
203
- registry_1.default.register(new KettlerRacerProtocol());
package/lib/protocol.d.ts DELETED
@@ -1,74 +0,0 @@
1
- import { User } from "./types/user";
2
- export declare const INTERFACE: {
3
- SERIAL: string;
4
- ANT: string;
5
- BLE: string;
6
- BLUETOOTH: string;
7
- TCPIP: string;
8
- SIMULATOR: string;
9
- };
10
- export declare type Device = {
11
- getID(): string;
12
- getName(): string;
13
- getPort(): string;
14
- getProtocol(): DeviceProtocol;
15
- getProtocolName(): string;
16
- };
17
- export interface DeviceSettings {
18
- name: string;
19
- port?: string;
20
- userSettings?: User;
21
- bikeSettings?: any;
22
- }
23
- export declare type DeviceFoundCallback = (device: Device, protocol: DeviceProtocol) => void;
24
- export declare type ScanFinishedCallback = (id: number) => void;
25
- export declare type ScanProps = {
26
- id: number;
27
- onDeviceFound?: DeviceFoundCallback;
28
- onScanFinished?: ScanFinishedCallback;
29
- };
30
- export interface DeviceProtocol {
31
- add(props: DeviceSettings): any;
32
- getName(): string;
33
- getInterfaces(): Array<string>;
34
- isBike(): boolean;
35
- isHrm(): boolean;
36
- isPower(): boolean;
37
- scan(props: ScanProps): void;
38
- stopScan(): void;
39
- isScanning(): boolean;
40
- getDevices(): Array<any>;
41
- setAnt(antClass: any): void;
42
- getAnt(): any;
43
- setSerialPort(serialClass: any): void;
44
- getSerialPort(): any;
45
- setNetImpl(netClass: any): void;
46
- getNetImpl(): any;
47
- }
48
- export default class DeviceProtocolBase {
49
- devices: Array<Device>;
50
- constructor();
51
- getName(): string;
52
- getInterfaces(): Array<string>;
53
- isBike(): boolean;
54
- isHrm(): boolean;
55
- isPower(): boolean;
56
- scan(props: ScanProps): void;
57
- stopScan(): void;
58
- isScanning(): boolean;
59
- add(props: DeviceSettings): void;
60
- getDevices(): Array<Device>;
61
- setAnt(antClass: any): void;
62
- getAnt(): any;
63
- setSerialPort(serialClass: any): void;
64
- getSerialPort(): void;
65
- setNetImpl(netClass: any): void;
66
- getNetImpl(): any;
67
- setBinding(_bindingClass: any): void;
68
- static setAnt(antClass: any): void;
69
- static getAnt(): any;
70
- static setSerialPort(serialClass: any): void;
71
- static getSerialPort(): any;
72
- static setNetImpl(netClass: any): void;
73
- static getNetImpl(): any;
74
- }
package/lib/protocol.js DELETED
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.INTERFACE = void 0;
4
- exports.INTERFACE = {
5
- SERIAL: 'serial',
6
- ANT: 'ant',
7
- BLE: 'ble',
8
- BLUETOOTH: 'bluetooth',
9
- TCPIP: 'tcpip',
10
- SIMULATOR: 'simulator'
11
- };
12
- let _ant, _serial, _net;
13
- class DeviceProtocolBase {
14
- constructor() {
15
- this.devices = [];
16
- }
17
- getName() { throw new Error('not implemented'); }
18
- getInterfaces() { throw new Error('not implemented'); }
19
- isBike() { throw new Error('not implemented'); }
20
- isHrm() { throw new Error('not implemented'); }
21
- isPower() { throw new Error('not implemented'); }
22
- scan(props) { throw new Error('not implemented'); }
23
- stopScan() { throw new Error('not implemented'); }
24
- isScanning() { throw new Error('not implemented'); }
25
- add(props) { throw new Error('Method not implemented.'); }
26
- getDevices() { return this.devices; }
27
- setAnt(antClass) { DeviceProtocolBase.setAnt(antClass); }
28
- getAnt() { return DeviceProtocolBase.getAnt(); }
29
- setSerialPort(serialClass) { DeviceProtocolBase.setSerialPort(serialClass); }
30
- getSerialPort() { DeviceProtocolBase.getSerialPort(); }
31
- setNetImpl(netClass) { DeviceProtocolBase.setNetImpl(netClass); }
32
- getNetImpl() { return DeviceProtocolBase.getNetImpl(); }
33
- setBinding(_bindingClass) { }
34
- static setAnt(antClass) { _ant = antClass; }
35
- static getAnt() { return _ant; }
36
- static setSerialPort(serialClass) { _serial = serialClass; }
37
- static getSerialPort() { return _serial; }
38
- static setNetImpl(netClass) { _net = netClass; }
39
- static getNetImpl() { return _net; }
40
- }
41
- exports.default = DeviceProtocolBase;
package/lib/registry.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import { DeviceProtocol } from './protocol';
2
- export default class DeviceRegistry {
3
- static _reset(): void;
4
- static _get(): any[];
5
- static register(protocol: DeviceProtocol): void;
6
- static findByName(name: string): DeviceProtocol;
7
- static findByInterface(interf: string): Array<DeviceProtocol>;
8
- }
package/lib/registry.js DELETED
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- let _protocols = [];
4
- class DeviceRegistry {
5
- static _reset() {
6
- _protocols = [];
7
- }
8
- static _get() {
9
- return _protocols;
10
- }
11
- static register(protocol) {
12
- if (!protocol)
13
- return;
14
- const idx = _protocols.findIndex(d => d.getName() === protocol.getName());
15
- if (idx !== -1) {
16
- _protocols[idx] = protocol;
17
- }
18
- else {
19
- _protocols.push(protocol);
20
- }
21
- }
22
- static findByName(name) {
23
- if (!name)
24
- return;
25
- return _protocols.find(d => d.getName() === name);
26
- }
27
- static findByInterface(interf) {
28
- if (!interf)
29
- return;
30
- return _protocols.filter(d => d.getInterfaces().findIndex(i => i === interf) !== -1);
31
- }
32
- }
33
- exports.default = DeviceRegistry;
@@ -1,20 +0,0 @@
1
- /// <reference types="node" />
2
- import { BindingPortInterface, OpenOptions, PortStatus, SetOptions, UpdateOptions } from "@serialport/bindings-interface";
3
- export declare class TCPPortBinding implements BindingPortInterface {
4
- openOptions: Required<OpenOptions>;
5
- isOpen: boolean;
6
- close(): Promise<void>;
7
- read(buffer: Buffer, offset: number, length: number): Promise<{
8
- buffer: Buffer;
9
- bytesRead: number;
10
- }>;
11
- write(buffer: Buffer): Promise<void>;
12
- update(options: UpdateOptions): Promise<void>;
13
- set(options: SetOptions): Promise<void>;
14
- get(): Promise<PortStatus>;
15
- getBaudRate(): Promise<{
16
- baudRate: number;
17
- }>;
18
- flush(): Promise<void>;
19
- drain(): Promise<void>;
20
- }
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TCPPortBinding = void 0;
4
- class TCPPortBinding {
5
- close() {
6
- throw new Error("Method not implemented.");
7
- }
8
- read(buffer, offset, length) {
9
- throw new Error("Method not implemented.");
10
- }
11
- write(buffer) {
12
- throw new Error("Method not implemented.");
13
- }
14
- update(options) {
15
- throw new Error("Method not implemented.");
16
- }
17
- set(options) {
18
- throw new Error("Method not implemented.");
19
- }
20
- get() {
21
- throw new Error("Method not implemented.");
22
- }
23
- getBaudRate() {
24
- throw new Error("Method not implemented.");
25
- }
26
- flush() {
27
- throw new Error("Method not implemented.");
28
- }
29
- drain() {
30
- throw new Error("Method not implemented.");
31
- }
32
- }
33
- exports.TCPPortBinding = TCPPortBinding;
@@ -1,2 +0,0 @@
1
- import SerialPortProvider, { useSerialPortProvider } from './serialport';
2
- export { SerialPortProvider, useSerialPortProvider };
@@ -1,29 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.useSerialPortProvider = exports.SerialPortProvider = void 0;
27
- const serialport_1 = __importStar(require("./serialport"));
28
- exports.SerialPortProvider = serialport_1.default;
29
- Object.defineProperty(exports, "useSerialPortProvider", { enumerable: true, get: function () { return serialport_1.useSerialPortProvider; } });
@@ -1,29 +0,0 @@
1
- import { BindingInterface } from '@serialport/bindings-interface';
2
- export type InterfaceBinding = {
3
- name: string;
4
- binding: BindingInterface;
5
- };
6
- export type InterfaceImplementation = {
7
- name: string;
8
- Serialport: any;
9
- implementation?: any;
10
- };
11
- export type SerialPortProps = {
12
- interface: string;
13
- port?: string;
14
- };
15
- export default class SerialPortProvider {
16
- static _instance: SerialPortProvider;
17
- interfaces: InterfaceBinding[];
18
- implemenations: InterfaceImplementation[];
19
- static getInstance(): SerialPortProvider;
20
- constructor();
21
- setBinding(ifaceName: string, binding: BindingInterface): void;
22
- getBinding(ifaceName: string): BindingInterface;
23
- getSerialPort(ifaceName: string, props: any): any;
24
- list(ifaceName: string): Promise<any>;
25
- setLegacyClass(ifaceName: string, Serialport: any): void;
26
- getLegacyInfo(ifaceName: string): InterfaceImplementation;
27
- getLegacyClass(ifaceName: string): any;
28
- }
29
- export declare const useSerialPortProvider: () => SerialPortProvider;
@@ -1,87 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.useSerialPortProvider = void 0;
13
- const { SerialPortStream } = require('@serialport/stream');
14
- const DEFAULT_BAUD_RATE = 9600;
15
- class SerialPortProvider {
16
- static getInstance() {
17
- if (!SerialPortProvider._instance)
18
- SerialPortProvider._instance = new SerialPortProvider();
19
- return SerialPortProvider._instance;
20
- }
21
- constructor() {
22
- this.interfaces = [];
23
- this.implemenations = [];
24
- }
25
- setBinding(ifaceName, binding) {
26
- const existing = this.interfaces.find(ib => ib.name === ifaceName);
27
- if (existing)
28
- existing.binding = binding;
29
- else
30
- this.interfaces.push({ name: ifaceName, binding });
31
- }
32
- getBinding(ifaceName) {
33
- const existing = this.interfaces.find(ib => ib.name === ifaceName);
34
- if (existing)
35
- return existing.binding;
36
- }
37
- getSerialPort(ifaceName, props) {
38
- const binding = this.getBinding(ifaceName);
39
- if (binding) {
40
- props.binding = binding;
41
- if (props.autoOpen === undefined)
42
- props.autoOpen = false;
43
- if (!props.baudRate)
44
- props.baudRate = DEFAULT_BAUD_RATE;
45
- return new SerialPortStream(props);
46
- }
47
- const legacy = this.getLegacyInfo(ifaceName);
48
- if (legacy && legacy.Serialport) {
49
- const portName = props.path;
50
- if (props.autoOpen === undefined)
51
- props.autoOpen = false;
52
- const settings = Object.assign({}, props);
53
- delete settings.path;
54
- return new legacy.Serialport(portName, settings);
55
- }
56
- }
57
- list(ifaceName) {
58
- return __awaiter(this, void 0, void 0, function* () {
59
- const Binding = this.getBinding(ifaceName);
60
- if (Binding)
61
- return yield Binding.list();
62
- const legacy = this.getLegacyInfo(ifaceName);
63
- if (legacy && legacy.Serialport && legacy.Serialport.list) {
64
- return yield legacy.Serialport.list();
65
- }
66
- return [];
67
- });
68
- }
69
- setLegacyClass(ifaceName, Serialport) {
70
- const existing = this.getLegacyInfo(ifaceName);
71
- if (existing)
72
- existing.Serialport = Serialport;
73
- else
74
- this.implemenations.push({ name: ifaceName, Serialport });
75
- }
76
- getLegacyInfo(ifaceName) {
77
- return this.implemenations.find(ib => ib.name === ifaceName);
78
- }
79
- getLegacyClass(ifaceName) {
80
- const existing = this.implemenations.find(ib => ib.name === ifaceName);
81
- if (existing)
82
- return existing.Serialport;
83
- }
84
- }
85
- exports.default = SerialPortProvider;
86
- const useSerialPortProvider = () => SerialPortProvider.getInstance();
87
- exports.useSerialPortProvider = useSerialPortProvider;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes