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
@@ -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,58 @@
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
+ static _instances: SerialInterface[];
47
+ static getInstance(props: SerialInterfaceProps): SerialInterface;
48
+ static _add(instance: SerialInterface): void;
49
+ constructor(props: SerialInterfaceProps);
50
+ setBinding(binding: BindingInterface): void;
51
+ getName(): string;
52
+ connect(): Promise<boolean>;
53
+ disconnect(): Promise<Boolean>;
54
+ openPort(path: string): Promise<SerialPortStream | null>;
55
+ closePort(path: string): Promise<Boolean>;
56
+ scan(props: SerialScannerProps): Promise<SerialDeviceSettings[]>;
57
+ stopScan(): Promise<boolean>;
58
+ }
@@ -0,0 +1,283 @@
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
+ if (this.isScanning)
46
+ return;
47
+ this.isScanning = true;
48
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
49
+ this.logger.logEvent({ message: 'starting scan', path: this.path });
50
+ this.serial.scanEvents.on('timeout', () => this.onStopRequest(resolve));
51
+ this.serial.scanEvents.on('stop', () => this.onStopRequest(resolve));
52
+ let found = false;
53
+ while (!found && this.isScanning) {
54
+ try {
55
+ const { protocol } = this.props;
56
+ let host, port;
57
+ if (this.serial.getName() === exports.SerialInterfaceType.TCPIP) {
58
+ [host, port] = this.path.split(':');
59
+ }
60
+ else {
61
+ port = this.path;
62
+ }
63
+ const adapterSettings = { interface: this.serial, host, port, protocol };
64
+ const adapter = adapters_1.default.create(adapterSettings);
65
+ found = yield adapter.check();
66
+ if (found) {
67
+ const name = adapter.getName();
68
+ resolve(Object.assign(Object.assign({}, adapterSettings), { name }));
69
+ yield this.serial.closePort(this.path).catch();
70
+ }
71
+ }
72
+ catch (err) {
73
+ this.logger.logEvent({ message: 'error', fn: 'scan()', error: err.message || err, stack: err.stack });
74
+ }
75
+ }
76
+ }));
77
+ });
78
+ }
79
+ }
80
+ exports.SinglePathScanner = SinglePathScanner;
81
+ class SerialInterface extends events_1.default {
82
+ static getInstance(props) {
83
+ const { ifaceName, binding, logger } = props;
84
+ let instance = SerialInterface._instances.find(i => i.ifaceName === ifaceName);
85
+ if (!instance) {
86
+ if (binding)
87
+ instance = new SerialInterface(props);
88
+ else {
89
+ instance = new SerialInterface({ ifaceName, binding: serialport_1.default.getInstance().getBinding(ifaceName), logger });
90
+ if (instance)
91
+ SerialInterface._instances.push(instance);
92
+ }
93
+ }
94
+ return instance;
95
+ }
96
+ static _add(instance) {
97
+ let existingIdx = SerialInterface._instances.findIndex(i => i.ifaceName === instance.ifaceName);
98
+ if (existingIdx !== -1)
99
+ SerialInterface._instances[existingIdx] = instance;
100
+ else
101
+ SerialInterface._instances.push(instance);
102
+ }
103
+ constructor(props) {
104
+ super();
105
+ const { ifaceName, binding } = props;
106
+ this.ifaceName = ifaceName;
107
+ this.binding = undefined;
108
+ this.ports = [];
109
+ this.isScanning = false;
110
+ this.isStopScanRequested = false;
111
+ this.scanEvents = new events_1.default();
112
+ this.logger = props.logger || new gd_eventlog_1.EventLogger(`Serial:${ifaceName}`);
113
+ this.logger.logEvent({ message: 'new serial interface', ifaceName });
114
+ if (binding) {
115
+ this.setBinding(binding);
116
+ }
117
+ SerialInterface._add(this);
118
+ }
119
+ setBinding(binding) {
120
+ this.binding = binding;
121
+ serialport_1.default.getInstance().setBinding(this.ifaceName, binding);
122
+ }
123
+ getName() {
124
+ return this.ifaceName;
125
+ }
126
+ connect() {
127
+ return __awaiter(this, void 0, void 0, function* () {
128
+ const binding = serialport_1.default.getInstance().getBinding(this.ifaceName);
129
+ if (!binding || !this.binding)
130
+ return false;
131
+ try {
132
+ const SerialPort = this.binding;
133
+ yield SerialPort.list();
134
+ return true;
135
+ }
136
+ catch (err) {
137
+ return false;
138
+ }
139
+ });
140
+ }
141
+ disconnect() {
142
+ return __awaiter(this, void 0, void 0, function* () {
143
+ return true;
144
+ });
145
+ }
146
+ openPort(path) {
147
+ return __awaiter(this, void 0, void 0, function* () {
148
+ this.logger.logEvent({ message: 'opening port', path });
149
+ const port = serialport_1.default.getInstance().getSerialPort(this.ifaceName, { path });
150
+ if (!port) {
151
+ return null;
152
+ }
153
+ const existing = this.ports.findIndex(p => p.path === path);
154
+ if (existing !== -1) {
155
+ const port = this.ports[existing].port;
156
+ if (port.isOpen)
157
+ return port;
158
+ else {
159
+ this.ports.splice(existing, 1);
160
+ }
161
+ }
162
+ return new Promise((resolve) => {
163
+ port.on('error', (err) => {
164
+ this.logger.logEvent({ message: 'error', path, error: err || err.message });
165
+ resolve(null);
166
+ port.removeAllListeners();
167
+ });
168
+ port.once('open', () => {
169
+ this.logger.logEvent({ message: 'port opened', path });
170
+ resolve(port);
171
+ port.removeAllListeners();
172
+ this.ports.push({ path, port });
173
+ });
174
+ port.open();
175
+ });
176
+ });
177
+ }
178
+ closePort(path) {
179
+ return __awaiter(this, void 0, void 0, function* () {
180
+ const existing = this.ports.findIndex(p => p.path === path);
181
+ if (existing === -1)
182
+ return true;
183
+ const port = this.ports[existing].port;
184
+ if (!port.isOpen)
185
+ return true;
186
+ port.on('error', () => { });
187
+ port.flush();
188
+ yield port.drain();
189
+ return new Promise(resolve => {
190
+ port.close(err => {
191
+ if (!err) {
192
+ this.ports.splice(existing, 1);
193
+ port.removeAllListeners();
194
+ resolve(true);
195
+ }
196
+ resolve(false);
197
+ });
198
+ });
199
+ });
200
+ }
201
+ scan(props) {
202
+ return __awaiter(this, void 0, void 0, function* () {
203
+ if (this.isScanning)
204
+ return [];
205
+ const binding = serialport_1.default.getInstance().getBinding(this.ifaceName);
206
+ if (!binding || !this.binding)
207
+ return [];
208
+ const { port, timeout = DEFAULT_SCAN_TIMEOUT } = props;
209
+ let paths;
210
+ const detected = [];
211
+ let timeOutExpired = false;
212
+ let toExpiresAt = Date.now() + timeout;
213
+ if (timeout) {
214
+ this.toScan = setTimeout(() => {
215
+ console.log('~~~ TIMEOUT');
216
+ timeOutExpired = true;
217
+ this.scanEvents.emit('timeout');
218
+ }, timeout);
219
+ }
220
+ this.isScanning = true;
221
+ do {
222
+ if (this.getName() === 'tcpip') {
223
+ const _binding = binding;
224
+ paths = (yield _binding.list(port)) || [];
225
+ }
226
+ else {
227
+ paths = (yield binding.list()) || [];
228
+ }
229
+ if (paths.length === 0) {
230
+ this.logger.logEvent({ message: 'scanning: no ports detected', interface: this.ifaceName, paths: paths.map(p => p.path), timeout });
231
+ (0, utils_1.sleep)(1000);
232
+ }
233
+ if (Date.now() > toExpiresAt)
234
+ timeOutExpired = true;
235
+ } while (this.isScanning && !timeOutExpired && paths.length === 0);
236
+ if (paths.length === 0) {
237
+ if (this.toScan) {
238
+ clearTimeout(this.toScan);
239
+ this.toScan = null;
240
+ }
241
+ return [];
242
+ }
243
+ this.logger.logEvent({ message: 'scanning on ', paths: paths.map(p => p.path), timeout });
244
+ const scanners = paths.map(p => new SinglePathScanner(p.path, this, Object.assign(Object.assign({}, props), { logger: this.logger })));
245
+ try {
246
+ yield Promise.all(scanners.map(s => s.scan()
247
+ .then(device => {
248
+ detected.push(device);
249
+ this.emit('device', device);
250
+ })
251
+ .catch()));
252
+ }
253
+ catch (err) {
254
+ this.logger.logEvent({ message: 'error', fn: 'scan()', error: err.message || err, stack: err.stack });
255
+ }
256
+ if (this.toScan) {
257
+ clearTimeout(this.toScan);
258
+ this.toScan = null;
259
+ }
260
+ this.isScanning = false;
261
+ this.logger.logEvent({ message: 'scan finished on', interface: this.ifaceName, paths: paths.map(p => p.path), devices: detected.map(d => {
262
+ const res = Object.assign({}, d);
263
+ res.interface = this.ifaceName;
264
+ return res;
265
+ }) });
266
+ return detected;
267
+ });
268
+ }
269
+ stopScan() {
270
+ return __awaiter(this, void 0, void 0, function* () {
271
+ if (!this.isScanning)
272
+ return true;
273
+ if (this.toScan) {
274
+ clearTimeout(this.toScan);
275
+ this.toScan = null;
276
+ }
277
+ this.scanEvents.emit('stop');
278
+ return true;
279
+ });
280
+ }
281
+ }
282
+ exports.default = SerialInterface;
283
+ 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,17 @@ 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;
42
38
  setIgnoreHrm(ignore: any): void;
43
39
  getSupportedCyclingModes(): Array<any>;
44
40
  getDefaultCyclingMode(): CyclingMode;
45
41
  getCyclingMode(): CyclingMode;
46
42
  setCyclingMode(mode: CyclingMode | string, settings?: any): void;
47
- start(props?: any): Promise<unknown>;
43
+ start(props?: SimulatorProperties): Promise<boolean>;
48
44
  stop(): Promise<boolean>;
49
45
  pause(): Promise<boolean>;
50
46
  resume(): Promise<boolean>;
@@ -53,17 +49,6 @@ export declare class Simulator extends DeviceAdapter {
53
49
  slower(): void;
54
50
  update(): void;
55
51
  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[];
52
+ sendUpdate(request: any): import("../modes/cycling-mode").UpdateRequest;
68
53
  }
69
54
  export {};