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,216 @@
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.KettlerRacerMockBinding = exports.KettlerRacerSimulator = exports.KettlerRacerMockImpl = exports.KettlerRacerMock = void 0;
13
+ const binding_mock_1 = require("@serialport/binding-mock");
14
+ const __1 = require("../..");
15
+ const utils_1 = require("../../../utils/utils");
16
+ const user_1 = require("../../../types/user");
17
+ const CRLF = '\r\n';
18
+ function pad(num, size) {
19
+ let str = Math.round(num).toString();
20
+ while (str.length < size)
21
+ str = "0" + str;
22
+ return str;
23
+ }
24
+ exports.KettlerRacerMock = {
25
+ reset() {
26
+ KettlerRacerMockImpl.getInstance().reset();
27
+ },
28
+ createPort(path, options = {}) {
29
+ return KettlerRacerMockImpl.getInstance().createPort(path, options);
30
+ },
31
+ list() {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ return KettlerRacerMockImpl.getInstance().list();
34
+ });
35
+ },
36
+ open(options) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ return KettlerRacerMockImpl.getInstance().open(options);
39
+ });
40
+ }
41
+ };
42
+ class KettlerRacerMockImpl {
43
+ static getInstance() {
44
+ if (!KettlerRacerMockImpl._instance)
45
+ KettlerRacerMockImpl._instance = new KettlerRacerMockImpl();
46
+ return KettlerRacerMockImpl._instance;
47
+ }
48
+ static reset() {
49
+ KettlerRacerMockImpl._instance = undefined;
50
+ __1.SerialPortProvider._instance = undefined;
51
+ __1.SerialInterface._instances = [];
52
+ }
53
+ constructor() {
54
+ this.simulators = new Map();
55
+ this.ports = [];
56
+ }
57
+ setSimulator(path, simulator) {
58
+ this.simulators.set(path, simulator);
59
+ }
60
+ getSimulator(path) {
61
+ return this.simulators.get(path);
62
+ }
63
+ reset() {
64
+ binding_mock_1.MockBinding.reset();
65
+ }
66
+ createPort(path, options = {}) {
67
+ return binding_mock_1.MockBinding.createPort(path, options);
68
+ }
69
+ list() {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ return binding_mock_1.MockBinding.list();
72
+ });
73
+ }
74
+ open(options) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ const port = yield binding_mock_1.MockBinding.open(options);
77
+ return new KettlerRacerMockBinding(port);
78
+ });
79
+ }
80
+ }
81
+ exports.KettlerRacerMockImpl = KettlerRacerMockImpl;
82
+ class KettlerRacerSimulator {
83
+ constructor() {
84
+ this.identifier = 'SDFB3129';
85
+ this.version = '131';
86
+ this.bikeType = 'SDJB';
87
+ this.ifVersion = 'E5';
88
+ this.power = 0;
89
+ this.requestedPower = 0;
90
+ this.person = { weight: 75, length: 180, age: 30, sex: user_1.Gender.MALE };
91
+ this.cadence = 0;
92
+ this.distance = 0;
93
+ this.speed = 0;
94
+ this.heartrate = 0;
95
+ this.time = 4;
96
+ this.energy = 0;
97
+ }
98
+ }
99
+ exports.KettlerRacerSimulator = KettlerRacerSimulator;
100
+ class KettlerRacerMockBinding extends binding_mock_1.MockPortBinding {
101
+ constructor(parent) {
102
+ super(parent.port, parent.openOptions);
103
+ this.simulator = KettlerRacerMockImpl.getInstance().getSimulator(this.getPath());
104
+ if (!this.simulator) {
105
+ this.simulator = new KettlerRacerSimulator();
106
+ KettlerRacerMockImpl.getInstance().setSimulator(this.getPath(), this.simulator);
107
+ }
108
+ this.initHandlers();
109
+ }
110
+ getPath() {
111
+ return this.port.info.path;
112
+ }
113
+ initHandlers() {
114
+ this.handlers = new Map();
115
+ this.handlers.set('CP', this.onSetComputerMode.bind(this));
116
+ this.handlers.set('CM', this.onSetClientMode.bind(this));
117
+ this.handlers.set('RS', this.onReset.bind(this));
118
+ this.handlers.set('ID', this.onGetIdentifier.bind(this));
119
+ this.handlers.set('VE', this.onGetVersion.bind(this));
120
+ this.handlers.set('KI', this.onGetKettlerInfo.bind(this));
121
+ this.handlers.set('PW', this.onSetPower.bind(this));
122
+ this.handlers.set('ST', this.onGetStatus.bind(this));
123
+ }
124
+ write(buffer) {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ if (!Buffer.isBuffer(buffer)) {
127
+ throw new TypeError('"buffer" is not a Buffer');
128
+ }
129
+ if (!this.isOpen || !this.port) {
130
+ throw new Error('Port is not open');
131
+ }
132
+ if (this.writeOperation) {
133
+ throw new Error('Overlapping writes are not supported and should be queued by the serialport object');
134
+ }
135
+ this.writeOperation = (() => __awaiter(this, void 0, void 0, function* () {
136
+ yield (0, utils_1.resolveNextTick)();
137
+ if (!this.isOpen || !this.port) {
138
+ throw new Error('Write canceled');
139
+ }
140
+ setTimeout(() => { this.processData(buffer); }, 5);
141
+ this.writeOperation = null;
142
+ }))();
143
+ return this.writeOperation;
144
+ });
145
+ }
146
+ processData(buffer) {
147
+ return __awaiter(this, void 0, void 0, function* () {
148
+ const data = buffer.toString();
149
+ const lines = data.split(CRLF);
150
+ lines.forEach(line => {
151
+ let payload;
152
+ let cmd = line.substring(0, 2);
153
+ if (cmd === 'ES') {
154
+ cmd = line.substring(0, 3);
155
+ payload = line.substring(3);
156
+ }
157
+ else {
158
+ payload = line.substring(2);
159
+ }
160
+ if (!cmd || cmd.length === 0)
161
+ return;
162
+ const handler = this.handlers.get(cmd);
163
+ if (handler) {
164
+ handler(payload);
165
+ }
166
+ else {
167
+ this, this.emitData('ERROR' + CRLF);
168
+ }
169
+ });
170
+ });
171
+ }
172
+ onSetComputerMode(_payload) {
173
+ this.sendResponse('ACK');
174
+ }
175
+ onSetClientMode(_payload) {
176
+ this.sendResponse('ACK');
177
+ }
178
+ onReset(_payload) {
179
+ this.sendResponse('ACK');
180
+ }
181
+ onGetIdentifier(_payload) {
182
+ this.sendResponse(this.simulator.identifier);
183
+ }
184
+ onGetVersion(_payload) {
185
+ this.sendResponse(this.simulator.version);
186
+ }
187
+ onGetKettlerInfo(_payload) {
188
+ const { bikeType, ifVersion } = this.simulator;
189
+ this.sendResponse(`${bikeType}\t${ifVersion}`);
190
+ }
191
+ onSetPower(payload) {
192
+ this.simulator.requestedPower = Number(payload);
193
+ setTimeout(() => { this.simulator.power = this.simulator.requestedPower; }, 1000);
194
+ this.onGetStatus();
195
+ }
196
+ onGetStatus() {
197
+ const { heartrate, cadence, speed, distance, power, energy, time, requestedPower } = this.simulator;
198
+ const mins = time % 60;
199
+ const secs = time - mins * 60;
200
+ const data = [];
201
+ data.push(pad(heartrate, 3));
202
+ data.push(pad(cadence, 3));
203
+ data.push(pad(speed * 10, 3));
204
+ data.push(pad(distance, 3));
205
+ data.push(pad(power, 3));
206
+ data.push(pad(energy, 3));
207
+ data.push(pad(mins, 2) + ':' + pad(secs, 2));
208
+ data.push(pad(requestedPower, 3));
209
+ const response = data.join('\t');
210
+ this.sendResponse(response);
211
+ }
212
+ sendResponse(msg) {
213
+ this.emitData(msg + CRLF);
214
+ }
215
+ }
216
+ exports.KettlerRacerMockBinding = KettlerRacerMockBinding;
@@ -1,7 +1,7 @@
1
- import CyclingMode, { CyclingModeProperty, IncyclistBikeData, UpdateRequest } from '../../cycling-mode';
2
- import KettlerAdapter from "./adapter";
3
- import PowerBasedCyclingModeBase from '../../modes/power-base';
4
- export declare type ERGEvent = {
1
+ import CyclingMode, { CyclingModeProperty, IncyclistBikeData, UpdateRequest } from '../../../../modes/cycling-mode';
2
+ import KettlerAdapter from "../adapter";
3
+ import PowerBasedCyclingModeBase from '../../../../modes/power-base';
4
+ export type ERGEvent = {
5
5
  rpmUpdated?: boolean;
6
6
  gearUpdated?: boolean;
7
7
  starting?: boolean;
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const cycling_mode_1 = require("../../cycling-mode");
7
- const power_base_1 = __importDefault(require("../../modes/power-base"));
6
+ const cycling_mode_1 = require("../../../../modes/cycling-mode");
7
+ const power_base_1 = __importDefault(require("../../../../modes/power-base"));
8
8
  const MIN_SPEED = 10;
9
9
  const config = {
10
10
  name: "ERG",
@@ -0,0 +1,60 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import EventEmitter from "events";
4
+ import { BindingInterface } from "@serialport/bindings-interface";
5
+ import { SerialPortStream } from '@serialport/stream';
6
+ import { SerialDeviceSettings } from './adapter';
7
+ import { EventLogger } from "gd-eventlog";
8
+ import { IncyclistScanProps } from "../types/device";
9
+ import { IncyclistInterface, InterfaceProps } from "../types/interface";
10
+ export declare const SerialInterfaceType: {
11
+ SERIAL: string;
12
+ TCPIP: string;
13
+ };
14
+ export interface SerialInterfaceProps extends InterfaceProps {
15
+ ifaceName: string;
16
+ binding?: BindingInterface;
17
+ }
18
+ export type PortMapping = {
19
+ path: string;
20
+ port: SerialPortStream;
21
+ };
22
+ export interface SerialScannerProps extends IncyclistScanProps {
23
+ port?: string;
24
+ protocol: string;
25
+ }
26
+ export declare class SinglePathScanner {
27
+ path: string;
28
+ serial: SerialInterface;
29
+ result: SerialDeviceSettings;
30
+ isScanning: boolean;
31
+ props: SerialScannerProps;
32
+ logger: EventLogger;
33
+ constructor(path: string, serial: SerialInterface, props: SerialScannerProps);
34
+ onStopRequest(resolve: any): Promise<void>;
35
+ scan(): Promise<SerialDeviceSettings | undefined>;
36
+ }
37
+ export default class SerialInterface extends EventEmitter implements IncyclistInterface {
38
+ ifaceName: string;
39
+ binding: BindingInterface;
40
+ ports: PortMapping[];
41
+ isScanning: boolean;
42
+ isStopScanRequested: boolean;
43
+ scanEvents: EventEmitter;
44
+ logger: EventLogger;
45
+ toScan: NodeJS.Timeout;
46
+ connected: boolean;
47
+ static _instances: SerialInterface[];
48
+ static getInstance(props: SerialInterfaceProps): SerialInterface;
49
+ static _add(instance: SerialInterface): void;
50
+ constructor(props: SerialInterfaceProps);
51
+ setBinding(binding: BindingInterface): void;
52
+ getName(): string;
53
+ isConnected(): boolean;
54
+ connect(): Promise<boolean>;
55
+ disconnect(): Promise<boolean>;
56
+ openPort(path: string): Promise<SerialPortStream | null>;
57
+ closePort(path: string): Promise<Boolean>;
58
+ scan(props: SerialScannerProps): Promise<SerialDeviceSettings[]>;
59
+ stopScan(): Promise<boolean>;
60
+ }
@@ -0,0 +1,309 @@
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.SinglePathScanner = exports.SerialInterfaceType = void 0;
16
+ const events_1 = __importDefault(require("events"));
17
+ const serialport_1 = __importDefault(require("./serialport"));
18
+ const gd_eventlog_1 = require("gd-eventlog");
19
+ const utils_1 = require("../utils/utils");
20
+ const adapters_1 = __importDefault(require("../adapters"));
21
+ const DEFAULT_SCAN_TIMEOUT = 10000;
22
+ exports.SerialInterfaceType = {
23
+ SERIAL: 'serial',
24
+ TCPIP: 'tcpip'
25
+ };
26
+ class SinglePathScanner {
27
+ constructor(path, serial, props) {
28
+ this.path = path;
29
+ this.serial = serial;
30
+ this.result = undefined;
31
+ this.isScanning = false;
32
+ this.props = props;
33
+ this.logger = props.logger || new gd_eventlog_1.EventLogger('SerialScanner');
34
+ }
35
+ onStopRequest(resolve) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ this.logger.logEvent({ message: 'stopping scan', path: this.path });
38
+ yield this.serial.closePort(this.path);
39
+ this.isScanning = false;
40
+ resolve(this.result);
41
+ });
42
+ }
43
+ scan() {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ console.log('~~~ start SERIAL Scan', this.isScanning);
46
+ if (this.isScanning)
47
+ return;
48
+ this.isScanning = true;
49
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
50
+ this.logger.logEvent({ message: 'starting scan', path: this.path });
51
+ this.serial.scanEvents.on('timeout', () => this.onStopRequest(resolve));
52
+ this.serial.scanEvents.on('stop', () => this.onStopRequest(resolve));
53
+ let found = false;
54
+ while (!found && this.isScanning) {
55
+ try {
56
+ console.log('~~~ adapter check attempt');
57
+ const { protocol } = this.props;
58
+ let host, port;
59
+ if (this.serial.getName() === exports.SerialInterfaceType.TCPIP) {
60
+ [host, port] = this.path.split(':');
61
+ }
62
+ else {
63
+ port = this.path;
64
+ }
65
+ const adapterSettings = { interface: this.serial.getName(), host, port, protocol };
66
+ const adapter = adapters_1.default.create(adapterSettings);
67
+ found = yield adapter.check();
68
+ if (found) {
69
+ const name = adapter.getName();
70
+ resolve(Object.assign(Object.assign({}, adapterSettings), { name }));
71
+ }
72
+ yield (0, utils_1.sleep)(100);
73
+ }
74
+ catch (err) {
75
+ console.log('~~~ERROR', err);
76
+ this.logger.logEvent({ message: 'error', fn: 'scan()', error: err.message || err, stack: err.stack });
77
+ yield (0, utils_1.sleep)(100);
78
+ }
79
+ }
80
+ }));
81
+ });
82
+ }
83
+ }
84
+ exports.SinglePathScanner = SinglePathScanner;
85
+ class SerialInterface extends events_1.default {
86
+ static getInstance(props) {
87
+ const { ifaceName, binding, logger } = props;
88
+ let instance = SerialInterface._instances.find(i => i.ifaceName === ifaceName);
89
+ if (!instance) {
90
+ if (binding)
91
+ instance = new SerialInterface(props);
92
+ else {
93
+ instance = new SerialInterface({ ifaceName, binding: serialport_1.default.getInstance().getBinding(ifaceName), logger });
94
+ if (instance)
95
+ SerialInterface._instances.push(instance);
96
+ }
97
+ }
98
+ return instance;
99
+ }
100
+ static _add(instance) {
101
+ let existingIdx = SerialInterface._instances.findIndex(i => i.ifaceName === instance.ifaceName);
102
+ if (existingIdx !== -1)
103
+ SerialInterface._instances[existingIdx] = instance;
104
+ else
105
+ SerialInterface._instances.push(instance);
106
+ }
107
+ constructor(props) {
108
+ super();
109
+ const { ifaceName, binding } = props;
110
+ this.ifaceName = ifaceName;
111
+ this.binding = undefined;
112
+ this.ports = [];
113
+ this.isScanning = false;
114
+ this.isStopScanRequested = false;
115
+ this.scanEvents = new events_1.default();
116
+ this.logger = props.logger || new gd_eventlog_1.EventLogger(`Serial:${ifaceName}`);
117
+ this.connected = false;
118
+ this.logger.logEvent({ message: 'new serial interface', ifaceName });
119
+ if (binding) {
120
+ this.setBinding(binding);
121
+ }
122
+ SerialInterface._add(this);
123
+ }
124
+ setBinding(binding) {
125
+ this.binding = binding;
126
+ serialport_1.default.getInstance().setBinding(this.ifaceName, binding);
127
+ }
128
+ getName() {
129
+ return this.ifaceName;
130
+ }
131
+ isConnected() {
132
+ return this.connected;
133
+ }
134
+ connect() {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ const binding = serialport_1.default.getInstance().getBinding(this.ifaceName);
137
+ if (!binding || !this.binding) {
138
+ this.connected = false;
139
+ return false;
140
+ }
141
+ try {
142
+ const SerialPort = this.binding;
143
+ const res = yield SerialPort.list();
144
+ this.connected = true;
145
+ return true;
146
+ }
147
+ catch (err) {
148
+ this.connected = false;
149
+ return false;
150
+ }
151
+ });
152
+ }
153
+ disconnect() {
154
+ return __awaiter(this, void 0, void 0, function* () {
155
+ this.connected = false;
156
+ return true;
157
+ });
158
+ }
159
+ openPort(path) {
160
+ return __awaiter(this, void 0, void 0, function* () {
161
+ console.log('~~~ SerialPort.openPort', this.ifaceName, path);
162
+ this.logger.logEvent({ message: 'opening port', path });
163
+ const port = serialport_1.default.getInstance().getSerialPort(this.ifaceName, { path });
164
+ if (!port) {
165
+ return null;
166
+ }
167
+ const existing = this.ports.findIndex(p => p.path === path);
168
+ if (existing !== -1) {
169
+ const port = this.ports[existing].port;
170
+ if (port.isOpen)
171
+ return port;
172
+ else {
173
+ this.ports.splice(existing, 1);
174
+ }
175
+ }
176
+ return new Promise((resolve) => {
177
+ port.once('error', (err) => {
178
+ this.logger.logEvent({ message: 'error', path, error: err || err.message });
179
+ port.removeAllListeners();
180
+ resolve(null);
181
+ });
182
+ port.once('open', () => {
183
+ this.logger.logEvent({ message: 'port opened', path });
184
+ port.removeAllListeners();
185
+ this.ports.push({ path, port });
186
+ resolve(port);
187
+ });
188
+ port.open();
189
+ });
190
+ });
191
+ }
192
+ closePort(path) {
193
+ return __awaiter(this, void 0, void 0, function* () {
194
+ console.log('~~~ SerialPort.closePort', this.ifaceName, path);
195
+ const existing = this.ports.findIndex(p => p.path === path);
196
+ if (existing === -1)
197
+ return true;
198
+ const port = this.ports[existing].port;
199
+ if (!port.isOpen)
200
+ return true;
201
+ port.on('error', () => { });
202
+ port.flush();
203
+ yield port.drain();
204
+ return new Promise(resolve => {
205
+ port.close(err => {
206
+ if (!err) {
207
+ this.ports.splice(existing, 1);
208
+ port.removeAllListeners();
209
+ resolve(true);
210
+ }
211
+ resolve(false);
212
+ });
213
+ });
214
+ });
215
+ }
216
+ scan(props) {
217
+ return __awaiter(this, void 0, void 0, function* () {
218
+ console.log('~~serial scan', this.isScanning, this.isConnected());
219
+ if (this.isScanning)
220
+ return [];
221
+ if (!this.isConnected())
222
+ yield this.connect();
223
+ const binding = serialport_1.default.getInstance().getBinding(this.ifaceName);
224
+ if (!binding || !this.binding)
225
+ return [];
226
+ const { port, timeout = DEFAULT_SCAN_TIMEOUT } = props;
227
+ let paths;
228
+ const detected = [];
229
+ let timeOutExpired = false;
230
+ let toExpiresAt = Date.now() + timeout;
231
+ if (timeout) {
232
+ this.toScan = setTimeout(() => {
233
+ timeOutExpired = true;
234
+ this.scanEvents.emit('timeout');
235
+ }, timeout);
236
+ }
237
+ this.logger.logEvent({ message: 'checking for ports ' });
238
+ this.isScanning = true;
239
+ do {
240
+ try {
241
+ if (this.getName() === 'tcpip') {
242
+ const _binding = binding;
243
+ paths = (yield _binding.list(port)) || [];
244
+ }
245
+ else {
246
+ paths = (yield binding.list()) || [];
247
+ }
248
+ }
249
+ catch (err) {
250
+ console.log('~~~ERROR', err);
251
+ }
252
+ if (!paths || paths.length === 0) {
253
+ this.logger.logEvent({ message: 'scanning: no ports detected', interface: this.ifaceName, paths: paths.map(p => p.path), timeout });
254
+ yield (0, utils_1.sleep)(1000);
255
+ }
256
+ if (Date.now() > toExpiresAt)
257
+ timeOutExpired = true;
258
+ } while (this.isScanning && !timeOutExpired && paths.length === 0);
259
+ if (paths.length === 0) {
260
+ this.logger.logEvent({ message: 'nothing to scan ' });
261
+ if (this.toScan) {
262
+ clearTimeout(this.toScan);
263
+ this.toScan = null;
264
+ }
265
+ return [];
266
+ }
267
+ this.logger.logEvent({ message: 'scanning on ', paths: paths.map(p => p.path), timeout });
268
+ const scanners = paths.map(p => new SinglePathScanner(p.path, this, Object.assign(Object.assign({}, props), { logger: this.logger })));
269
+ try {
270
+ yield Promise.all(scanners.map(s => s.scan()
271
+ .then(device => {
272
+ if (device) {
273
+ detected.push(device);
274
+ this.emit('device', device);
275
+ }
276
+ })
277
+ .catch()));
278
+ }
279
+ catch (err) {
280
+ this.logger.logEvent({ message: 'error', fn: 'scan()', error: err.message || err, stack: err.stack });
281
+ }
282
+ if (this.toScan) {
283
+ clearTimeout(this.toScan);
284
+ this.toScan = null;
285
+ }
286
+ this.isScanning = false;
287
+ this.logger.logEvent({ message: 'scan finished on', interface: this.ifaceName, paths: paths.map(p => p.path), devices: detected.map(d => {
288
+ const res = Object.assign({}, d);
289
+ res.interface = this.ifaceName;
290
+ return res;
291
+ }) });
292
+ return detected;
293
+ });
294
+ }
295
+ stopScan() {
296
+ return __awaiter(this, void 0, void 0, function* () {
297
+ if (!this.isScanning)
298
+ return true;
299
+ if (this.toScan) {
300
+ clearTimeout(this.toScan);
301
+ this.toScan = null;
302
+ }
303
+ this.scanEvents.emit('stop');
304
+ return true;
305
+ });
306
+ }
307
+ }
308
+ exports.default = SerialInterface;
309
+ SerialInterface._instances = [];
@@ -1,18 +1,18 @@
1
- import DeviceProtocolBase, { DeviceSettings, DeviceProtocol } from '../protocol';
2
- import DeviceAdapter from '../device';
1
+ import DeviceAdapter, { ControllableDevice } from '../base/adpater';
3
2
  import { EventLogger } from 'gd-eventlog';
4
- import CyclingMode, { IncyclistBikeData } from '../cycling-mode';
5
- interface SimulatorSettings extends DeviceSettings {
3
+ import CyclingMode, { IncyclistBikeData } from '../modes/cycling-mode';
4
+ import { DeviceProperties, DeviceSettings } from '../types/device';
5
+ interface SimulatorProperties extends DeviceProperties {
6
6
  isBot?: boolean;
7
7
  settings?: any;
8
+ activity?: any;
8
9
  }
9
- export declare class Simulator extends DeviceAdapter {
10
+ export declare class Simulator extends ControllableDevice {
10
11
  static NAME: string;
11
12
  logger: EventLogger;
12
13
  speed: number;
13
14
  power: number;
14
15
  cadence: number;
15
- paused: boolean;
16
16
  time: number;
17
17
  iv: any;
18
18
  started: boolean;
@@ -30,21 +30,18 @@ export declare class Simulator extends DeviceAdapter {
30
30
  bikeSettings: {
31
31
  weight?: number;
32
32
  };
33
- constructor(protocol?: DeviceProtocol, props?: SimulatorSettings);
34
- isBike(): boolean;
35
- isHrm(): boolean;
36
- isPower(): boolean;
33
+ constructor(settings: DeviceSettings, props?: SimulatorProperties);
34
+ isEqual(settings: DeviceSettings): boolean;
37
35
  isSame(device: DeviceAdapter): boolean;
38
36
  getID(): string;
39
37
  getName(): string;
40
- getPort(): string;
41
- getWeight(): number;
38
+ getUniqueName(): string;
42
39
  setIgnoreHrm(ignore: any): void;
43
40
  getSupportedCyclingModes(): Array<any>;
44
41
  getDefaultCyclingMode(): CyclingMode;
45
42
  getCyclingMode(): CyclingMode;
46
43
  setCyclingMode(mode: CyclingMode | string, settings?: any): void;
47
- start(props?: any): Promise<unknown>;
44
+ start(props?: SimulatorProperties): Promise<boolean>;
48
45
  stop(): Promise<boolean>;
49
46
  pause(): Promise<boolean>;
50
47
  resume(): Promise<boolean>;
@@ -52,18 +49,8 @@ export declare class Simulator extends DeviceAdapter {
52
49
  faster(): void;
53
50
  slower(): void;
54
51
  update(): void;
52
+ canSendUpdate(): boolean;
55
53
  calculateDistance(speedKps: any, timeS: any): number;
56
- sendUpdate(request: any): import("../cycling-mode").UpdateRequest;
57
- }
58
- export default class SimulatorProtocol extends DeviceProtocolBase {
59
- static NAME: string;
60
- constructor();
61
- add(settings: SimulatorSettings): any;
62
- getName(): string;
63
- getInterfaces(): string[];
64
- isBike(): boolean;
65
- isHrm(): boolean;
66
- isPower(): boolean;
67
- getDevices(): import("../protocol").Device[];
54
+ sendUpdate(request: any): import("../modes/cycling-mode").UpdateRequest;
68
55
  }
69
56
  export {};