incyclist-devices 2.0.38 → 2.1.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 (192) hide show
  1. package/lib/adapters.d.ts +1 -1
  2. package/lib/antv2/adapter-factory.d.ts +4 -13
  3. package/lib/antv2/adapter.d.ts +16 -33
  4. package/lib/antv2/adapter.js +68 -112
  5. package/lib/antv2/ant-interface.d.ts +3 -11
  6. package/lib/antv2/ant-interface.js +1 -1
  7. package/lib/antv2/base/adapter.d.ts +62 -0
  8. package/lib/antv2/base/adapter.js +360 -0
  9. package/lib/antv2/base/ant-interface.d.ts +35 -0
  10. package/lib/antv2/base/ant-interface.js +285 -0
  11. package/lib/antv2/base/binding.d.ts +13 -0
  12. package/lib/antv2/base/binding.js +27 -0
  13. package/lib/antv2/cad/adapter.d.ts +10 -0
  14. package/lib/antv2/cad/adapter.js +25 -0
  15. package/lib/antv2/cad/index.d.ts +2 -0
  16. package/lib/antv2/cad/index.js +7 -0
  17. package/lib/antv2/consts.d.ts +2 -0
  18. package/lib/antv2/consts.js +5 -0
  19. package/lib/antv2/factories/adapter-factory.d.ts +14 -0
  20. package/lib/antv2/factories/adapter-factory.js +65 -0
  21. package/lib/antv2/factories/sensor-factory.d.ts +5 -0
  22. package/lib/antv2/factories/sensor-factory.js +22 -0
  23. package/lib/antv2/fe/adapter.d.ts +25 -26
  24. package/lib/antv2/fe/adapter.js +212 -218
  25. package/lib/antv2/hr/adapter.d.ts +6 -14
  26. package/lib/antv2/hr/adapter.js +7 -55
  27. package/lib/antv2/hr copy/adapter.d.ts +11 -0
  28. package/lib/antv2/hr copy/adapter.js +30 -0
  29. package/lib/antv2/hr copy/index.d.ts +2 -0
  30. package/lib/antv2/hr copy/index.js +7 -0
  31. package/lib/antv2/index.d.ts +5 -4
  32. package/lib/antv2/index.js +4 -2
  33. package/lib/antv2/pwr/adapter.d.ts +9 -29
  34. package/lib/antv2/pwr/adapter.js +20 -130
  35. package/lib/antv2/types.d.ts +23 -3
  36. package/lib/base/adpater.d.ts +42 -45
  37. package/lib/base/adpater.js +144 -110
  38. package/lib/base/consts.d.ts +4 -0
  39. package/lib/base/consts.js +9 -0
  40. package/lib/ble/adapter-factory.d.ts +4 -4
  41. package/lib/ble/base/adapter.d.ts +6 -24
  42. package/lib/ble/base/adapter.js +4 -94
  43. package/lib/ble/ble-interface.d.ts +2 -3
  44. package/lib/ble/cp/adapter.d.ts +6 -11
  45. package/lib/ble/cp/adapter.js +9 -12
  46. package/lib/ble/elite/adapter.d.ts +8 -8
  47. package/lib/ble/elite/adapter.js +6 -2
  48. package/lib/ble/fm/adapter.d.ts +11 -11
  49. package/lib/ble/fm/adapter.js +26 -20
  50. package/lib/ble/hr/adapter.d.ts +3 -4
  51. package/lib/ble/hr/adapter.js +2 -2
  52. package/lib/ble/tacx/adapter.d.ts +2 -3
  53. package/lib/ble/tacx/adapter.js +8 -8
  54. package/lib/ble/types.d.ts +1 -2
  55. package/lib/ble/wahoo/adapter.d.ts +2 -2
  56. package/lib/ble/wahoo/adapter.js +6 -6
  57. package/lib/ble/wahoo/comms.js +16 -16
  58. package/lib/factories/adapters.d.ts +7 -0
  59. package/lib/factories/adapters.js +49 -0
  60. package/lib/factories/index.d.ts +3 -0
  61. package/lib/factories/index.js +10 -0
  62. package/lib/factories/interfaces.d.ts +7 -0
  63. package/lib/factories/interfaces.js +27 -0
  64. package/lib/index.d.ts +8 -9
  65. package/lib/index.js +5 -8
  66. package/lib/interfaces.d.ts +1 -1
  67. package/lib/modes/ant-fe-adv-st-mode.d.ts +12 -0
  68. package/lib/modes/ant-fe-adv-st-mode.js +83 -0
  69. package/lib/modes/antble-erg.d.ts +31 -0
  70. package/lib/modes/antble-erg.js +28 -0
  71. package/lib/modes/antble-smarttrainer.d.ts +23 -0
  72. package/lib/modes/antble-smarttrainer.js +65 -0
  73. package/lib/modes/base.d.ts +29 -0
  74. package/lib/modes/{cycling-mode.js → base.js} +23 -26
  75. package/lib/modes/daum-classic-standard.d.ts +17 -0
  76. package/lib/modes/daum-classic-standard.js +54 -0
  77. package/lib/modes/daum-erg.d.ts +49 -0
  78. package/lib/{serial/daum/ERGCyclingMode.js → modes/daum-erg.js} +45 -73
  79. package/lib/modes/daum-power.d.ts +5 -0
  80. package/lib/{serial/daum/DaumPowerMeterCyclingMode.js → modes/daum-power.js} +1 -10
  81. package/lib/modes/daum-premium-standard.d.ts +24 -0
  82. package/lib/{serial/daum/premium/modes/daum-classic.js → modes/daum-premium-standard.js} +26 -38
  83. package/lib/modes/daum-smarttrainer.d.ts +83 -0
  84. package/lib/{serial/daum/SmartTrainerCyclingMode.js → modes/daum-smarttrainer.js} +23 -26
  85. package/lib/modes/kettler-erg.d.ts +44 -0
  86. package/lib/{serial/kettler/ergo-racer/modes/erg.js → modes/kettler-erg.js} +12 -23
  87. package/lib/modes/power-base.d.ts +28 -3
  88. package/lib/modes/power-base.js +184 -7
  89. package/lib/modes/power-meter.d.ts +11 -16
  90. package/lib/modes/power-meter.js +15 -54
  91. package/lib/modes/simulator.d.ts +38 -10
  92. package/lib/modes/simulator.js +14 -46
  93. package/lib/modes/{cycling-mode.d.ts → types.d.ts} +22 -30
  94. package/lib/modes/types.js +56 -0
  95. package/lib/serial/SinglePathScanner.d.ts +17 -0
  96. package/lib/serial/SinglePathScanner.js +87 -0
  97. package/lib/serial/adapter-factory.d.ts +8 -6
  98. package/lib/serial/adapter.d.ts +6 -11
  99. package/lib/serial/adapter.js +5 -2
  100. package/lib/serial/base/adapter.d.ts +17 -0
  101. package/lib/serial/base/adapter.js +67 -0
  102. package/lib/serial/base/comms.d.ts +62 -0
  103. package/lib/serial/base/comms.js +280 -0
  104. package/lib/serial/base/serial-interface.d.ts +36 -0
  105. package/lib/serial/base/serial-interface.js +288 -0
  106. package/lib/serial/base/serial-scanner.d.ts +16 -0
  107. package/lib/serial/base/serial-scanner.js +87 -0
  108. package/lib/serial/base/serialport.d.ts +17 -0
  109. package/lib/serial/base/serialport.js +87 -0
  110. package/lib/serial/comms.d.ts +2 -2
  111. package/lib/serial/daum/DaumAdapter.d.ts +26 -35
  112. package/lib/serial/daum/DaumAdapter.js +214 -161
  113. package/lib/serial/daum/classic/PROTOCOL_NAME.d.ts +2 -0
  114. package/lib/serial/daum/classic/PROTOCOL_NAME.js +5 -0
  115. package/lib/serial/daum/classic/adapter.d.ts +13 -26
  116. package/lib/serial/daum/classic/adapter.js +72 -176
  117. package/lib/serial/daum/classic/comms.d.ts +21 -17
  118. package/lib/serial/daum/classic/comms.js +41 -14
  119. package/lib/serial/daum/classic/consts.d.ts +2 -0
  120. package/lib/serial/daum/classic/consts.js +5 -0
  121. package/lib/serial/daum/classic/mock.d.ts +4 -0
  122. package/lib/serial/daum/classic/mock.js +18 -7
  123. package/lib/serial/daum/classic/types.d.ts +8 -10
  124. package/lib/serial/daum/classic/utils.d.ts +1 -2
  125. package/lib/serial/daum/consts.d.ts +0 -0
  126. package/lib/serial/daum/consts.js +0 -0
  127. package/lib/serial/daum/premium/adapter.d.ts +17 -15
  128. package/lib/serial/daum/premium/adapter.js +86 -109
  129. package/lib/serial/daum/premium/comms.d.ts +7 -7
  130. package/lib/serial/daum/premium/comms.js +25 -16
  131. package/lib/serial/daum/premium/mock.d.ts +5 -1
  132. package/lib/serial/daum/premium/mock.js +17 -7
  133. package/lib/serial/daum/premium/types.d.ts +32 -17
  134. package/lib/serial/daum/premium/types.js +8 -8
  135. package/lib/serial/daum/premium/utils.d.ts +2 -3
  136. package/lib/serial/daum/premium/utils.js +3 -3
  137. package/lib/serial/daum/types.d.ts +14 -0
  138. package/lib/serial/daum/types.js +13 -0
  139. package/lib/serial/factories/adapter-factory.d.ts +14 -0
  140. package/lib/serial/factories/adapter-factory.js +30 -0
  141. package/lib/serial/index.d.ts +8 -5
  142. package/lib/serial/index.js +15 -15
  143. package/lib/serial/kettler/comms.d.ts +1 -1
  144. package/lib/serial/kettler/ergo-racer/adapter.d.ts +11 -16
  145. package/lib/serial/kettler/ergo-racer/adapter.js +10 -12
  146. package/lib/serial/kettler/types.d.ts +8 -0
  147. package/lib/serial/kettler/types.js +2 -0
  148. package/lib/serial/serial-interface.d.ts +2 -32
  149. package/lib/serial/serial-interface.js +4 -78
  150. package/lib/serial/serial-scanner.d.ts +16 -0
  151. package/lib/serial/serial-scanner.js +87 -0
  152. package/lib/serial/serialport.d.ts +1 -13
  153. package/lib/serial/types.d.ts +45 -0
  154. package/lib/serial/types.js +9 -0
  155. package/lib/simulator/Simulator.d.ts +13 -19
  156. package/lib/simulator/Simulator.js +10 -51
  157. package/lib/types/Command.d.ts +8 -0
  158. package/lib/types/Command.js +2 -0
  159. package/lib/types/adapter.d.ts +34 -24
  160. package/lib/types/command.d.ts +0 -8
  161. package/lib/types/command.js +0 -2
  162. package/lib/types/data.d.ts +12 -1
  163. package/lib/types/device.d.ts +8 -23
  164. package/lib/types/device.js +9 -8
  165. package/lib/types/index.d.ts +6 -0
  166. package/lib/types/index.js +22 -0
  167. package/lib/types/route.d.ts +0 -19
  168. package/lib/types/route.js +0 -2
  169. package/lib/types/types.d.ts +8 -0
  170. package/lib/types/types.js +2 -0
  171. package/lib/utils/utils.d.ts +2 -1
  172. package/lib/utils/utils.js +22 -4
  173. package/package.json +3 -3
  174. package/lib/antv2/modes/ant-fe-adv-st-mode.d.ts +0 -9
  175. package/lib/antv2/modes/ant-fe-adv-st-mode.js +0 -51
  176. package/lib/antv2/modes/ant-fe-erg-mode.d.ts +0 -6
  177. package/lib/antv2/modes/ant-fe-erg-mode.js +0 -14
  178. package/lib/antv2/modes/ant-fe-st-mode.d.ts +0 -5
  179. package/lib/antv2/modes/ant-fe-st-mode.js +0 -13
  180. package/lib/modes/ble-erg-mode.d.ts +0 -18
  181. package/lib/modes/ble-erg-mode.js +0 -148
  182. package/lib/modes/ble-st-mode.d.ts +0 -15
  183. package/lib/modes/ble-st-mode.js +0 -96
  184. package/lib/serial/daum/DaumPowerMeterCyclingMode.d.ts +0 -8
  185. package/lib/serial/daum/ERGCyclingMode.d.ts +0 -26
  186. package/lib/serial/daum/SmartTrainerCyclingMode.d.ts +0 -42
  187. package/lib/serial/daum/classic/modes/daum-classic.d.ts +0 -13
  188. package/lib/serial/daum/classic/modes/daum-classic.js +0 -97
  189. package/lib/serial/daum/constants.d.ts +0 -19
  190. package/lib/serial/daum/constants.js +0 -22
  191. package/lib/serial/daum/premium/modes/daum-classic.d.ts +0 -14
  192. package/lib/serial/kettler/ergo-racer/modes/erg.d.ts +0 -25
@@ -12,26 +12,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.AbstractDaumAdapter = void 0;
16
- const ERGCyclingMode_1 = __importDefault(require("./ERGCyclingMode"));
17
- const SmartTrainerCyclingMode_1 = __importDefault(require("./SmartTrainerCyclingMode"));
18
- const DaumPowerMeterCyclingMode_1 = __importDefault(require("./DaumPowerMeterCyclingMode"));
15
+ const daum_erg_1 = __importDefault(require("../../modes/daum-erg"));
19
16
  const utils_1 = require("../../utils/utils");
20
- const adapter_1 = require("../adapter");
21
- const capabilities_1 = require("../../types/capabilities");
22
- class AbstractDaumAdapter extends adapter_1.SerialIncyclistDevice {
23
- }
24
- exports.AbstractDaumAdapter = AbstractDaumAdapter;
25
- class DaumAdapter extends AbstractDaumAdapter {
17
+ const types_1 = require("../../types");
18
+ const adapter_1 = require("../base/adapter");
19
+ const daum_smarttrainer_1 = __importDefault(require("../../modes/daum-smarttrainer"));
20
+ const daum_power_1 = __importDefault(require("../../modes/daum-power"));
21
+ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
26
22
  constructor(settings, props) {
27
23
  super(settings, props);
28
24
  this.requests = [];
29
25
  this.adapterTime = 0;
30
26
  this.requestBusy = false;
31
27
  this.updateBusy = false;
32
- this.stopped = false;
33
- this.paused = false;
34
- this.cyclingData = {
28
+ this.iv = undefined;
29
+ this.deviceData = {
35
30
  isPedalling: false,
36
31
  time: 0,
37
32
  power: 0,
@@ -40,37 +35,25 @@ class DaumAdapter extends AbstractDaumAdapter {
40
35
  distanceInternal: 0,
41
36
  heartrate: 0
42
37
  };
43
- this.deviceData = {};
44
38
  this.capabilities = [
45
- capabilities_1.IncyclistCapability.Power, capabilities_1.IncyclistCapability.Speed, capabilities_1.IncyclistCapability.Cadence, capabilities_1.IncyclistCapability.Gear, capabilities_1.IncyclistCapability.HeartRate,
46
- capabilities_1.IncyclistCapability.Control
39
+ types_1.IncyclistCapability.Power, types_1.IncyclistCapability.Speed, types_1.IncyclistCapability.Cadence, types_1.IncyclistCapability.Gear, types_1.IncyclistCapability.HeartRate,
40
+ types_1.IncyclistCapability.Control
47
41
  ];
48
42
  }
49
- setCyclingMode(mode, settings) {
50
- let selectedMode = this.cyclingMode;
51
- if (typeof mode === 'string') {
52
- if (!this.cyclingMode || this.cyclingMode.getName() !== mode) {
53
- const supported = this.getSupportedCyclingModes();
54
- const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
55
- if (CyclingModeClass) {
56
- this.cyclingMode = new CyclingModeClass(this, settings);
57
- return;
58
- }
59
- selectedMode = this.getDefaultCyclingMode();
60
- }
61
- }
62
- else {
63
- selectedMode = mode;
64
- }
65
- this.cyclingMode = selectedMode;
66
- this.cyclingMode.setSettings(settings);
43
+ getPort() {
44
+ var _a;
45
+ return (_a = this.comms) === null || _a === void 0 ? void 0 : _a.getPort();
46
+ }
47
+ getSerialInterface() {
48
+ var _a;
49
+ return (_a = this.comms) === null || _a === void 0 ? void 0 : _a.serial;
67
50
  }
68
51
  sendInitCommands() {
69
52
  return __awaiter(this, void 0, void 0, function* () {
70
53
  if (this.started && !this.stopped) {
71
54
  try {
72
- if (this.getCyclingMode() instanceof ERGCyclingMode_1.default) {
73
- const power = this.deviceData.power;
55
+ if (this.getCyclingMode() instanceof daum_erg_1.default) {
56
+ const power = this.data.power;
74
57
  const request = power ? { targetPower: power } : this.getCyclingMode().getBikeInitRequest();
75
58
  yield this.sendUpdate(request);
76
59
  return true;
@@ -80,27 +63,14 @@ class DaumAdapter extends AbstractDaumAdapter {
80
63
  return false;
81
64
  }
82
65
  }
83
- else {
84
- return false;
85
- }
66
+ return false;
86
67
  });
87
68
  }
88
- getSupportedCyclingModes() {
89
- return [ERGCyclingMode_1.default, SmartTrainerCyclingMode_1.default, DaumPowerMeterCyclingMode_1.default];
90
- }
91
- getCyclingMode() {
92
- if (!this.cyclingMode)
93
- this.setCyclingMode(this.getDefaultCyclingMode());
94
- return this.cyclingMode;
95
- }
96
- getDefaultCyclingMode() {
97
- return new ERGCyclingMode_1.default(this);
98
- }
99
69
  getCurrentBikeData() {
100
70
  throw new Error('Method not implemented.');
101
71
  }
102
- getBike() {
103
- return this.bike;
72
+ getComms() {
73
+ return this.comms;
104
74
  }
105
75
  isEqual(settings) {
106
76
  const as = this.settings;
@@ -123,7 +93,7 @@ class DaumAdapter extends AbstractDaumAdapter {
123
93
  this.distanceInternal = undefined;
124
94
  this.paused = false;
125
95
  this.stopped = false;
126
- this.cyclingData = {
96
+ this.deviceData = {
127
97
  isPedalling: false,
128
98
  time: 0,
129
99
  power: 0,
@@ -132,8 +102,7 @@ class DaumAdapter extends AbstractDaumAdapter {
132
102
  distanceInternal: 0,
133
103
  heartrate: 0
134
104
  };
135
- this.deviceData = {};
136
- this.currentRequest = {};
105
+ this.data = {};
137
106
  this.requests = [];
138
107
  const name = this.getCyclingMode().getName();
139
108
  const settings = this.getCyclingMode().getSettings();
@@ -145,7 +114,7 @@ class DaumAdapter extends AbstractDaumAdapter {
145
114
  });
146
115
  return __awaiter(this, void 0, void 0, function* () {
147
116
  const paused = yield _super.pause.call(this);
148
- this.bike.pauseLogging();
117
+ this.comms.pauseLogging();
149
118
  return paused;
150
119
  });
151
120
  }
@@ -155,75 +124,170 @@ class DaumAdapter extends AbstractDaumAdapter {
155
124
  });
156
125
  return __awaiter(this, void 0, void 0, function* () {
157
126
  const resumed = yield _super.resume.call(this);
158
- this.bike.resumeLogging();
127
+ this.comms.resumeLogging();
159
128
  return resumed;
160
129
  });
161
130
  }
131
+ waitForPrevCheckFinished() {
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ if (this.checkPromise) {
134
+ this.logEvent({ message: "waiting for previous check device", port: this.getPort() });
135
+ try {
136
+ yield this.checkPromise;
137
+ }
138
+ catch (_a) { }
139
+ this.logEvent({ message: "previous check device completed", port: this.getPort() });
140
+ this.checkPromise = undefined;
141
+ }
142
+ });
143
+ }
144
+ check() {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ yield this.waitForPrevCheckFinished();
147
+ yield this.waitForPrevStartFinished();
148
+ if (this.isStopped())
149
+ return false;
150
+ this.checkPromise = this.performCheck();
151
+ try {
152
+ const res = yield this.checkPromise;
153
+ this.checkPromise = undefined;
154
+ return res;
155
+ }
156
+ catch (err) {
157
+ this.checkPromise = undefined;
158
+ throw err;
159
+ }
160
+ });
161
+ }
162
+ performCheck() {
163
+ return __awaiter(this, void 0, void 0, function* () {
164
+ throw new Error('Method not implemented.');
165
+ });
166
+ }
167
+ waitForPrevStartFinished() {
168
+ return __awaiter(this, void 0, void 0, function* () {
169
+ if (this.startPromise) {
170
+ this.logEvent({ message: "waiting for previous device launch", port: this.getPort() });
171
+ try {
172
+ yield this.startPromise;
173
+ }
174
+ catch (_a) { }
175
+ this.logEvent({ message: "previous device launch attempt completed", port: this.getPort() });
176
+ this.startPromise = undefined;
177
+ }
178
+ });
179
+ }
162
180
  start(props) {
163
- throw new Error('Method not implemented.');
181
+ return __awaiter(this, void 0, void 0, function* () {
182
+ yield this.waitForPrevCheckFinished();
183
+ yield this.waitForPrevStartFinished();
184
+ const isRelaunch = this.started;
185
+ const message = isRelaunch ? 'relaunch of device' : 'initial start of device';
186
+ this.logEvent({ message });
187
+ try {
188
+ if (isRelaunch && this.isPaused())
189
+ this.resume();
190
+ this.startPromise = this.performStart(props, isRelaunch).then((started) => __awaiter(this, void 0, void 0, function* () {
191
+ if (!started) {
192
+ this.logEvent({ message: 'start result: not started' });
193
+ this.started = false;
194
+ return false;
195
+ }
196
+ if (!isRelaunch) {
197
+ try {
198
+ const deviceInfo = yield this.getDeviceInfo();
199
+ this.logEvent({ message: 'device info', deviceInfo });
200
+ }
201
+ catch (_a) { }
202
+ }
203
+ this.logEvent({ message: 'start result: success' });
204
+ this.started = true;
205
+ return true;
206
+ }));
207
+ const started = yield this.startPromise;
208
+ this.startPromise = undefined;
209
+ return started;
210
+ }
211
+ catch (err) {
212
+ this.logEvent({ message: 'start result: error', error: err.message });
213
+ this.startPromise = undefined;
214
+ this.started = false;
215
+ throw new Error(`could not start device, reason:${err.message}`);
216
+ }
217
+ });
164
218
  }
165
- stopUpdatePull() {
166
- if (!this.iv)
167
- return;
168
- if (this.iv.sync)
169
- clearInterval(this.iv.sync);
170
- if (this.iv.update)
171
- clearInterval(this.iv.update);
172
- this.iv = undefined;
219
+ performStart(props, isRelaunch = false) {
220
+ throw new Error('Method not implemented.');
173
221
  }
174
222
  startUpdatePull() {
175
- this.logEvent({ message: 'start update pull', iv: this.iv, ignoreBike: this.ignoreBike, ignoreHrm: this.ignoreHrm, ignorePower: this.ignorePower });
176
223
  if (this.iv)
177
224
  return;
178
- if (this.ignoreBike && this.ignoreHrm && this.ignorePower)
179
- return;
225
+ this.logEvent({ message: 'start update pull', port: this.getPort() });
180
226
  const ivSync = setInterval(() => {
181
- this.bikeSync();
227
+ try {
228
+ this.bikeSync();
229
+ }
230
+ catch (_a) { }
182
231
  }, this.pullFrequency);
183
232
  const ivUpdate = setInterval(() => {
184
- this.emitData(this.deviceData);
185
- this.refreshRequests();
233
+ try {
234
+ this.emitData(this.data);
235
+ this.refreshRequests();
236
+ }
237
+ catch (_a) { }
186
238
  }, this.pullFrequency);
187
239
  this.iv = {
188
240
  sync: ivSync,
189
241
  update: ivUpdate
190
242
  };
191
243
  }
244
+ stopUpdatePull() {
245
+ if (!this.iv)
246
+ return;
247
+ this.logEvent({ message: 'stop update pull', port: this.getPort() });
248
+ clearInterval(this.iv.sync);
249
+ clearInterval(this.iv.update);
250
+ this.iv = undefined;
251
+ }
192
252
  connect() {
193
253
  return __awaiter(this, void 0, void 0, function* () {
194
- if (this.bike.isConnected())
254
+ if (!this.comms)
255
+ return false;
256
+ if (this.comms.isConnected())
195
257
  return true;
196
258
  try {
197
- const connected = yield this.bike.connect();
259
+ const connected = yield this.comms.connect();
198
260
  return connected;
199
261
  }
200
262
  catch (err) {
201
- yield this.bike.close();
263
+ yield this.comms.close();
202
264
  return false;
203
265
  }
204
266
  });
205
267
  }
206
268
  close() {
207
269
  return __awaiter(this, void 0, void 0, function* () {
208
- if (!this.bike.isConnected())
270
+ if (!this.comms)
271
+ return true;
272
+ if (!this.comms.isConnected())
209
273
  return true;
210
- return yield this.bike.close();
274
+ return yield this.comms.close();
211
275
  });
212
276
  }
213
- logEvent(event) {
214
- if (!this.logger)
215
- return;
216
- this.logger.logEvent(event);
217
- const w = global.window;
218
- if (w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) {
219
- console.log(`~~~ ${this.logger.getName()}`, event);
220
- }
277
+ verifyConnection() {
278
+ return __awaiter(this, void 0, void 0, function* () {
279
+ if (!this.comms.isConnected()) {
280
+ const connected = yield this.comms.connect();
281
+ if (!connected)
282
+ throw new Error('not connected');
283
+ }
284
+ });
221
285
  }
222
286
  reconnect() {
223
287
  return __awaiter(this, void 0, void 0, function* () {
224
288
  try {
225
- yield this.bike.close();
226
- const connected = yield this.bike.connect();
289
+ yield this.comms.close();
290
+ const connected = yield this.comms.connect();
227
291
  return connected;
228
292
  }
229
293
  catch (err) {
@@ -231,38 +295,34 @@ class DaumAdapter extends AbstractDaumAdapter {
231
295
  }
232
296
  });
233
297
  }
298
+ logEvent(event) {
299
+ if (!this.logger || this.paused)
300
+ return;
301
+ this.logger.logEvent(event);
302
+ const w = global.window;
303
+ if (w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) {
304
+ console.log(`~~~ ${this.logger.getName()}`, event);
305
+ }
306
+ }
234
307
  stop() {
235
- if (this.stopped)
236
- return Promise.resolve(true);
237
- this.logEvent({ message: 'stop request' });
238
- if (this.paused)
239
- this.resume();
240
- this.stopped = true;
241
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
308
+ return __awaiter(this, void 0, void 0, function* () {
309
+ if (this.stopped)
310
+ return true;
311
+ this.logEvent({ message: 'stop request' });
312
+ if (this.paused)
313
+ this.resume();
242
314
  try {
243
- if (this.iv) {
244
- if (this.iv.sync)
245
- clearInterval(this.iv.sync);
246
- if (this.iv.update)
247
- clearInterval(this.iv.update);
248
- this.iv = undefined;
249
- }
250
- if (this.bike.stopWorker && typeof this.bike.stopWorker === 'function')
251
- this.bike.stopWorker();
252
- yield this.bike.close();
315
+ this.stopUpdatePull();
316
+ yield this.comms.close();
253
317
  this.logEvent({ message: 'stop request completed' });
254
- resolve(true);
318
+ this.stopped = true;
255
319
  }
256
320
  catch (err) {
257
- this.logEvent({ message: 'stop error', error: err.message });
258
- reject(err);
321
+ this.logEvent({ message: 'stop request failed', reason: err.message });
322
+ throw (err);
259
323
  }
260
- }));
261
- }
262
- canSendUpdate() {
263
- if (this.paused || this.stopped)
264
- return false;
265
- return super.canSendUpdate();
324
+ return this.stopped;
325
+ });
266
326
  }
267
327
  sendUpdate(request) {
268
328
  return __awaiter(this, void 0, void 0, function* () {
@@ -274,39 +334,44 @@ class DaumAdapter extends AbstractDaumAdapter {
274
334
  }
275
335
  update() {
276
336
  return __awaiter(this, void 0, void 0, function* () {
277
- if (this.stopped)
337
+ if (!this.canEmitData() || this.updateBusy)
278
338
  return;
279
339
  this.updateBusy = true;
280
- this.getCurrentBikeData()
281
- .then(bikeData => {
340
+ try {
341
+ const bikeData = yield this.getCurrentBikeData();
282
342
  const incyclistData = this.updateData(bikeData);
283
343
  const data = this.transformData(incyclistData);
284
344
  this.updateBusy = false;
285
345
  this.emitData(data);
286
- })
287
- .catch(err => {
288
- this.logEvent({ message: 'bike update error', error: err.message, stack: err.stack });
289
- const incyclistData = this.updateData(this.cyclingData);
290
- this.transformData(incyclistData);
346
+ }
347
+ catch (err) {
348
+ try {
349
+ this.logEvent({ message: 'bike update error', error: err.message, stack: err.stack });
350
+ const incyclistData = this.updateData(this.deviceData);
351
+ this.transformData(incyclistData);
352
+ }
353
+ catch (_a) { }
291
354
  this.updateBusy = false;
292
- });
355
+ }
293
356
  });
294
357
  }
295
358
  sendRequests() {
296
359
  return __awaiter(this, void 0, void 0, function* () {
297
360
  if (this.stopped || this.paused)
298
361
  return;
362
+ if (this.requestBusy)
363
+ return;
299
364
  if (this.requests.length > 0) {
300
- const processing = [...this.requests];
301
- const cnt = processing.length;
302
- processing.forEach((request, idx) => __awaiter(this, void 0, void 0, function* () {
303
- if (cnt > 1 && idx < cnt - 1) {
304
- this.logEvent({ message: 'ignoring bike update request', request });
305
- this.requests.shift();
306
- return;
307
- }
308
- }));
309
- const request = processing[0];
365
+ const cnt = this.requests.length;
366
+ if (cnt > 1) {
367
+ this.requests.forEach((request, idx) => {
368
+ if (idx !== cnt - 1) {
369
+ this.logEvent({ message: 'ignoring bike update request', request });
370
+ }
371
+ });
372
+ this.requests = [this.requests[cnt - 1]];
373
+ }
374
+ let request = this.requests[0];
310
375
  try {
311
376
  yield this.sendRequest(request);
312
377
  this.requests.shift();
@@ -319,16 +384,7 @@ class DaumAdapter extends AbstractDaumAdapter {
319
384
  }
320
385
  bikeSync() {
321
386
  return __awaiter(this, void 0, void 0, function* () {
322
- if (this.paused || this.stopped) {
323
- return;
324
- }
325
- if (this.updateBusy || this.requestBusy) {
326
- return;
327
- }
328
- this.logEvent({ message: 'bikeSync', ignoreBike: this.ignoreBike });
329
- if (!this.ignoreBike) {
330
- yield this.sendRequests();
331
- }
387
+ yield this.sendRequests();
332
388
  yield this.update();
333
389
  });
334
390
  }
@@ -346,8 +402,8 @@ class DaumAdapter extends AbstractDaumAdapter {
346
402
  data.time = bikeData.time;
347
403
  if (bikeData.slope)
348
404
  data.slope = bikeData.slope;
349
- this.cyclingData = this.getCyclingMode().updateData(data);
350
- return this.cyclingData;
405
+ this.deviceData = this.getCyclingMode().updateData(data);
406
+ return this.deviceData;
351
407
  }
352
408
  transformData(cyclingData) {
353
409
  let distance = 0;
@@ -367,16 +423,7 @@ class DaumAdapter extends AbstractDaumAdapter {
367
423
  deviceTime: cyclingData.time,
368
424
  deviceDistanceCounter: cyclingData.distanceInternal
369
425
  };
370
- if (this.ignoreHrm)
371
- delete data.heartrate;
372
- if (this.ignorePower) {
373
- delete data.power;
374
- delete data.cadence;
375
- }
376
- if (this.ignoreBike) {
377
- data = { heartrate: data.heartrate };
378
- }
379
- this.deviceData = data;
426
+ this.data = data;
380
427
  return data;
381
428
  }
382
429
  sendRequest(request) {
@@ -384,17 +431,17 @@ class DaumAdapter extends AbstractDaumAdapter {
384
431
  this.requestBusy = true;
385
432
  try {
386
433
  this.logEvent({ message: 'sendRequest', request });
387
- const bike = this.getBike();
434
+ const bike = this.getComms();
388
435
  const isReset = (!request || request.reset || Object.keys(request).length === 0);
389
436
  if (isReset) {
390
437
  this.requestBusy = false;
391
438
  return {};
392
439
  }
393
440
  if (request.slope !== undefined) {
394
- yield bike.setSlope(request.slope);
441
+ yield bike.setTargetSlope(request.slope);
395
442
  }
396
443
  if (request.targetPower !== undefined) {
397
- yield bike.setPower(request.targetPower);
444
+ yield bike.setTargetPower(request.targetPower);
398
445
  }
399
446
  this.requestBusy = false;
400
447
  return request;
@@ -409,7 +456,7 @@ class DaumAdapter extends AbstractDaumAdapter {
409
456
  refreshRequests() {
410
457
  if (this.isPaused() || this.isStopped())
411
458
  return;
412
- if (!this.cyclingData.isPedalling || this.cyclingData.pedalRpm === 0)
459
+ if (!this.deviceData.isPedalling || this.deviceData.pedalRpm === 0)
413
460
  return;
414
461
  let bikeRequest = this.getCyclingMode().sendBikeUpdate({ refresh: true }) || {};
415
462
  const prev = this.requests[this.requests.length - 1] || {};
@@ -420,7 +467,7 @@ class DaumAdapter extends AbstractDaumAdapter {
420
467
  }
421
468
  processClientRequest(request) {
422
469
  if (request.slope !== undefined) {
423
- this.cyclingData.slope = request.slope;
470
+ this.deviceData.slope = request.slope;
424
471
  }
425
472
  return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
426
473
  let bikeRequest = this.getCyclingMode().sendBikeUpdate(request);
@@ -429,8 +476,14 @@ class DaumAdapter extends AbstractDaumAdapter {
429
476
  resolve(bikeRequest);
430
477
  }));
431
478
  }
432
- check() {
433
- throw new Error('Method not implemented.');
479
+ getDeviceInfo() {
480
+ return __awaiter(this, void 0, void 0, function* () {
481
+ throw new Error('Method not implemented.');
482
+ });
434
483
  }
435
484
  }
485
+ DaumAdapter.controllers = {
486
+ modes: [daum_erg_1.default, daum_smarttrainer_1.default, daum_power_1.default],
487
+ default: daum_erg_1.default
488
+ };
436
489
  exports.default = DaumAdapter;
@@ -0,0 +1,2 @@
1
+ export declare const PROTOCOL_NAME = "Daum Classic";
2
+ export declare const DEFAULT_GEAR = 10;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_GEAR = exports.PROTOCOL_NAME = void 0;
4
+ exports.PROTOCOL_NAME = "Daum Classic";
5
+ exports.DEFAULT_GEAR = 10;
@@ -1,33 +1,20 @@
1
- import CyclingMode, { IncyclistBikeData } from '../../../modes/cycling-mode';
2
1
  import DaumAdapter from '../DaumAdapter';
3
- import { DeviceProperties } from '../../../types/device';
4
- import { SerialDeviceSettings } from '../../adapter';
5
- import SerialInterface from '../../serial-interface';
6
- export interface DaumClassicDeviceProperties extends DeviceProperties {
7
- gear?: number;
8
- }
9
- export default class DaumClassicAdapter extends DaumAdapter<SerialDeviceSettings, DaumClassicDeviceProperties> {
2
+ import { DaumClassicProperties } from './types';
3
+ import { SerialDeviceSettings, SerialCommProps } from "../../types";
4
+ import { IncyclistBikeData, ControllerConfig } from "../../../types";
5
+ import Daum8008 from './comms';
6
+ export default class DaumClassicAdapter extends DaumAdapter<SerialDeviceSettings, DaumClassicProperties, Daum8008> {
10
7
  static NAME: string;
11
- name: string;
12
- id: string;
13
- started: boolean;
14
- startPromise: Promise<unknown>;
15
- checkPromise: Promise<boolean>;
16
- constructor(settings: SerialDeviceSettings, props?: DaumClassicDeviceProperties);
17
- setID(id: any): void;
18
- getID(): string;
8
+ protected static controllers: ControllerConfig;
9
+ protected name: string;
10
+ protected id: string;
11
+ constructor(settings: SerialDeviceSettings, props?: DaumClassicProperties);
12
+ getBikeProps(props: SerialDeviceSettings): SerialCommProps;
19
13
  getName(): string;
20
- setName(name: any): void;
21
- getPort(): any;
14
+ setName(name: string): void;
22
15
  getProtocolName(): string;
23
- getSupportedCyclingModes(): Array<any>;
24
- getDefaultCyclingMode(): CyclingMode;
25
- getSerialInterface(): SerialInterface;
26
- check(): Promise<boolean>;
27
16
  performCheck(): Promise<boolean>;
28
- startRide(props?: DaumClassicDeviceProperties): Promise<boolean>;
29
- start(props?: DaumClassicDeviceProperties): Promise<boolean>;
30
- launch(props: DaumClassicDeviceProperties, isRelaunch?: boolean): Promise<boolean>;
31
- performStart(props?: DaumClassicDeviceProperties, isRelaunch?: boolean): Promise<unknown>;
17
+ performStart(props?: DaumClassicProperties, isRelaunch?: boolean): Promise<boolean>;
32
18
  getCurrentBikeData(): Promise<IncyclistBikeData>;
19
+ getDeviceInfo(): Promise<any>;
33
20
  }