incyclist-devices 2.0.37 → 2.1.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 (103) hide show
  1. package/lib/antv2/adapter-factory.d.ts +4 -2
  2. package/lib/antv2/adapter.d.ts +3 -20
  3. package/lib/antv2/adapter.js +7 -93
  4. package/lib/antv2/fe/adapter.d.ts +9 -5
  5. package/lib/antv2/fe/adapter.js +25 -14
  6. package/lib/antv2/hr/adapter.d.ts +2 -1
  7. package/lib/antv2/pwr/adapter.d.ts +9 -5
  8. package/lib/antv2/pwr/adapter.js +19 -8
  9. package/lib/antv2/types.d.ts +2 -1
  10. package/lib/base/adpater.d.ts +31 -13
  11. package/lib/base/adpater.js +84 -28
  12. package/lib/ble/adapter-factory.d.ts +10 -9
  13. package/lib/ble/base/adapter.d.ts +9 -20
  14. package/lib/ble/base/adapter.js +15 -72
  15. package/lib/ble/ble-interface.d.ts +5 -4
  16. package/lib/ble/cp/adapter.d.ts +5 -8
  17. package/lib/ble/cp/adapter.js +26 -10
  18. package/lib/ble/elite/adapter.d.ts +6 -5
  19. package/lib/ble/elite/adapter.js +26 -2
  20. package/lib/ble/fm/adapter.d.ts +10 -9
  21. package/lib/ble/fm/adapter.js +38 -11
  22. package/lib/ble/hr/adapter.d.ts +5 -3
  23. package/lib/ble/peripheral-cache.d.ts +3 -2
  24. package/lib/ble/tacx/adapter.d.ts +2 -2
  25. package/lib/ble/wahoo/adapter.d.ts +2 -2
  26. package/lib/index.d.ts +5 -5
  27. package/lib/index.js +4 -2
  28. package/lib/interfaces.d.ts +1 -1
  29. package/lib/modes/ant-fe-adv-st-mode.d.ts +12 -0
  30. package/lib/modes/ant-fe-adv-st-mode.js +83 -0
  31. package/lib/modes/antble-erg.d.ts +31 -0
  32. package/lib/modes/antble-erg.js +28 -0
  33. package/lib/modes/antble-smarttrainer.d.ts +23 -0
  34. package/lib/modes/antble-smarttrainer.js +65 -0
  35. package/lib/modes/base.d.ts +29 -0
  36. package/lib/modes/{cycling-mode.js → base.js} +23 -26
  37. package/lib/modes/daum-classic-standard.d.ts +16 -0
  38. package/lib/modes/daum-classic-standard.js +54 -0
  39. package/lib/modes/daum-erg.d.ts +49 -0
  40. package/lib/{serial/daum/ERGCyclingMode.js → modes/daum-erg.js} +45 -73
  41. package/lib/modes/daum-power.d.ts +5 -0
  42. package/lib/{serial/daum/DaumPowerMeterCyclingMode.js → modes/daum-power.js} +1 -10
  43. package/lib/modes/daum-premium-standard.d.ts +23 -0
  44. package/lib/{serial/daum/premium/modes/daum-classic.js → modes/daum-premium-standard.js} +26 -38
  45. package/lib/modes/daum-smarttrainer.d.ts +82 -0
  46. package/lib/{serial/daum/SmartTrainerCyclingMode.js → modes/daum-smarttrainer.js} +23 -26
  47. package/lib/modes/kettler-erg.d.ts +44 -0
  48. package/lib/{serial/kettler/ergo-racer/modes/erg.js → modes/kettler-erg.js} +12 -23
  49. package/lib/modes/power-base.d.ts +28 -3
  50. package/lib/modes/power-base.js +182 -5
  51. package/lib/modes/power-meter.d.ts +10 -16
  52. package/lib/modes/power-meter.js +15 -54
  53. package/lib/modes/simulator.d.ts +37 -10
  54. package/lib/modes/simulator.js +14 -46
  55. package/lib/modes/{cycling-mode.d.ts → types.d.ts} +22 -19
  56. package/lib/modes/types.js +56 -0
  57. package/lib/serial/adapter-factory.d.ts +7 -5
  58. package/lib/serial/adapter.d.ts +2 -2
  59. package/lib/serial/adapter.js +5 -2
  60. package/lib/serial/daum/DaumAdapter.d.ts +27 -24
  61. package/lib/serial/daum/DaumAdapter.js +200 -128
  62. package/lib/serial/daum/classic/adapter.d.ts +20 -21
  63. package/lib/serial/daum/classic/adapter.js +83 -157
  64. package/lib/serial/daum/classic/comms.d.ts +19 -13
  65. package/lib/serial/daum/classic/comms.js +39 -12
  66. package/lib/serial/daum/classic/mock.d.ts +4 -0
  67. package/lib/serial/daum/classic/mock.js +14 -4
  68. package/lib/serial/daum/premium/adapter.d.ts +16 -11
  69. package/lib/serial/daum/premium/adapter.js +98 -95
  70. package/lib/serial/daum/premium/comms.d.ts +4 -1
  71. package/lib/serial/daum/premium/comms.js +25 -17
  72. package/lib/serial/daum/premium/mock.d.ts +4 -0
  73. package/lib/serial/daum/premium/mock.js +15 -5
  74. package/lib/serial/daum/types.d.ts +11 -0
  75. package/lib/serial/daum/types.js +5 -0
  76. package/lib/serial/kettler/ergo-racer/adapter.d.ts +10 -8
  77. package/lib/serial/kettler/ergo-racer/adapter.js +17 -7
  78. package/lib/serial/serial-interface.js +1 -2
  79. package/lib/simulator/Simulator.d.ts +14 -17
  80. package/lib/simulator/Simulator.js +18 -47
  81. package/lib/types/adapter.d.ts +29 -8
  82. package/lib/types/adapter.js +68 -0
  83. package/lib/utils/utils.d.ts +1 -1
  84. package/package.json +3 -3
  85. package/lib/antv2/modes/ant-fe-adv-st-mode.d.ts +0 -9
  86. package/lib/antv2/modes/ant-fe-adv-st-mode.js +0 -51
  87. package/lib/antv2/modes/ant-fe-erg-mode.d.ts +0 -6
  88. package/lib/antv2/modes/ant-fe-erg-mode.js +0 -14
  89. package/lib/antv2/modes/ant-fe-st-mode.d.ts +0 -5
  90. package/lib/antv2/modes/ant-fe-st-mode.js +0 -13
  91. package/lib/modes/ble-erg-mode.d.ts +0 -18
  92. package/lib/modes/ble-erg-mode.js +0 -148
  93. package/lib/modes/ble-st-mode.d.ts +0 -15
  94. package/lib/modes/ble-st-mode.js +0 -96
  95. package/lib/serial/daum/DaumPowerMeterCyclingMode.d.ts +0 -8
  96. package/lib/serial/daum/ERGCyclingMode.d.ts +0 -26
  97. package/lib/serial/daum/SmartTrainerCyclingMode.d.ts +0 -42
  98. package/lib/serial/daum/classic/modes/daum-classic.d.ts +0 -13
  99. package/lib/serial/daum/classic/modes/daum-classic.js +0 -97
  100. package/lib/serial/daum/premium/modes/daum-classic.d.ts +0 -14
  101. package/lib/serial/kettler/ergo-racer/modes/erg.d.ts +0 -25
  102. /package/lib/serial/daum/{constants.d.ts → consts.d.ts} +0 -0
  103. /package/lib/serial/daum/{constants.js → consts.js} +0 -0
@@ -1,12 +1,14 @@
1
+ import { ControllableDevice } from '../base/adpater';
2
+ import { DeviceProperties } from '../types/device';
1
3
  import { SerialIncyclistDevice, SerialDeviceSettings } from './adapter';
2
4
  export default class SerialAdapterFactory {
3
5
  static _instance: SerialAdapterFactory;
4
- adapters: {
6
+ adapters: Array<{
5
7
  protocol: string;
6
- AdapterClass: typeof SerialIncyclistDevice;
7
- }[];
8
+ AdapterClass: typeof SerialIncyclistDevice<ControllableDevice<DeviceProperties>, DeviceProperties>;
9
+ }>;
8
10
  static getInstance(): SerialAdapterFactory;
9
11
  constructor();
10
- registerAdapter(protocol: string, AdapterClass: typeof SerialIncyclistDevice): void;
11
- createInstance(props: SerialDeviceSettings, settings?: any): SerialIncyclistDevice;
12
+ registerAdapter(protocol: string, AdapterClass: typeof SerialIncyclistDevice<ControllableDevice<DeviceProperties>, DeviceProperties>): void;
13
+ createInstance(props: SerialDeviceSettings, settings?: any): SerialIncyclistDevice<ControllableDevice<DeviceProperties>, DeviceProperties>;
12
14
  }
@@ -1,5 +1,5 @@
1
1
  import { DeviceProperties, DeviceSettings } from "../types/device";
2
- import { ControllableDevice } from "../base/adpater";
2
+ import IncyclistDevice, { ControllableDevice } from "../base/adpater";
3
3
  import SerialInterface from "./serial-interface";
4
4
  export interface SerialDeviceSettings extends DeviceSettings {
5
5
  protocol: string;
@@ -7,7 +7,7 @@ export interface SerialDeviceSettings extends DeviceSettings {
7
7
  port?: string;
8
8
  interface: string | SerialInterface;
9
9
  }
10
- export declare class SerialIncyclistDevice extends ControllableDevice {
10
+ export declare class SerialIncyclistDevice<C extends ControllableDevice<P>, P extends DeviceProperties> extends IncyclistDevice<C, P> {
11
11
  pullFrequency: number;
12
12
  check(): Promise<boolean>;
13
13
  constructor(settings: SerialDeviceSettings, props?: DeviceProperties);
@@ -8,11 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.SerialIncyclistDevice = void 0;
13
- const adpater_1 = require("../base/adpater");
16
+ const adpater_1 = __importDefault(require("../base/adpater"));
14
17
  const DEFAULT_PULL_FREQUENCY = 1000;
15
- class SerialIncyclistDevice extends adpater_1.ControllableDevice {
18
+ class SerialIncyclistDevice extends adpater_1.default {
16
19
  check() {
17
20
  return __awaiter(this, void 0, void 0, function* () { throw new Error('not implemnted'); });
18
21
  }
@@ -1,54 +1,57 @@
1
- import { EventLogger } from 'gd-eventlog';
2
- import CyclingMode, { IncyclistBikeData } from '../../modes/cycling-mode';
3
- import { Bike } from '../../types/adapter';
1
+ import ICyclingMode, { CyclingMode, IncyclistBikeData } from '../../modes/types';
4
2
  import { DeviceProperties } from '../../types/device';
5
3
  import { SerialDeviceSettings, SerialIncyclistDevice } from '../adapter';
6
4
  import { DeviceData } from '../../types/data';
5
+ import SerialInterface from '../serial-interface';
6
+ import DaumSerialComms from './types';
7
+ import { ControllableDevice } from '../../base/adpater';
8
+ import { IncyclistDeviceAdapter } from '../../types/adapter';
7
9
  export interface IDaumAdapter {
8
10
  getCurrentBikeData(): Promise<IncyclistBikeData>;
9
11
  }
10
- export declare abstract class AbstractDaumAdapter extends SerialIncyclistDevice implements IDaumAdapter {
11
- abstract getCurrentBikeData(): Promise<any>;
12
+ export declare class DaumControl<P extends DeviceProperties> extends ControllableDevice<P> {
13
+ getSupportedCyclingModes(): Array<typeof CyclingMode>;
14
+ getDefaultCyclingMode(): ICyclingMode;
15
+ sendInitCommands(): Promise<boolean>;
12
16
  }
13
- export default class DaumAdapter<S extends SerialDeviceSettings, P extends DeviceProperties> extends AbstractDaumAdapter implements Bike {
14
- bike: any;
15
- ignoreHrm: boolean;
16
- ignoreBike: boolean;
17
- ignorePower: boolean;
17
+ export default class DaumAdapter<DC extends DaumControl<P>, S extends SerialDeviceSettings, P extends DeviceProperties, C extends DaumSerialComms> extends SerialIncyclistDevice<DC, P> implements IDaumAdapter {
18
+ bike: C;
18
19
  distanceInternal: number;
19
- paused: boolean;
20
- stopped: boolean;
21
20
  cyclingData: IncyclistBikeData;
22
21
  deviceData: DeviceData;
23
- currentRequest: any;
24
22
  requests: Array<any>;
25
23
  iv: any;
26
- logger: EventLogger;
27
24
  tsPrevData: number;
28
25
  adapterTime: number;
29
26
  requestBusy: boolean;
30
27
  updateBusy: boolean;
28
+ startPromise: Promise<boolean>;
29
+ checkPromise: Promise<boolean>;
31
30
  constructor(settings: S, props?: P);
32
- setCyclingMode(mode: CyclingMode | string, settings?: any): void;
31
+ getPort(): string;
32
+ getSerialInterface(): SerialInterface;
33
33
  sendInitCommands(): Promise<boolean>;
34
- getSupportedCyclingModes(): Array<any>;
35
- getCyclingMode(): CyclingMode;
36
- getDefaultCyclingMode(): CyclingMode;
37
34
  getCurrentBikeData(): Promise<IncyclistBikeData>;
38
- getBike(): any;
35
+ getBike(): C;
39
36
  isEqual(settings: SerialDeviceSettings): boolean;
40
- isSame(device: SerialIncyclistDevice): boolean;
37
+ isSame(device: IncyclistDeviceAdapter): boolean;
41
38
  isStopped(): boolean;
42
39
  initData(): void;
43
40
  pause(): Promise<boolean>;
44
41
  resume(): Promise<boolean>;
45
- start(props?: P): Promise<any>;
46
- stopUpdatePull(): void;
42
+ waitForPrevCheckFinished(): Promise<void>;
43
+ check(): Promise<boolean>;
44
+ performCheck(): Promise<boolean>;
45
+ waitForPrevStartFinished(): Promise<void>;
46
+ start(props?: P): Promise<boolean>;
47
+ performStart(props?: P, isRelaunch?: boolean): Promise<boolean>;
47
48
  startUpdatePull(): void;
49
+ stopUpdatePull(): void;
48
50
  connect(): Promise<boolean>;
49
51
  close(): Promise<boolean>;
50
- logEvent(event: any): void;
52
+ verifyConnection(): Promise<void>;
51
53
  reconnect(): Promise<boolean>;
54
+ logEvent(event: any): void;
52
55
  stop(): Promise<boolean>;
53
56
  canSendUpdate(): boolean;
54
57
  sendUpdate(request: any): Promise<unknown>;
@@ -60,5 +63,5 @@ export default class DaumAdapter<S extends SerialDeviceSettings, P extends Devic
60
63
  sendRequest(request: any): Promise<any>;
61
64
  refreshRequests(): void;
62
65
  processClientRequest(request: any): Promise<unknown>;
63
- check(): Promise<boolean>;
66
+ getDeviceInfo(): Promise<any>;
64
67
  }
@@ -12,25 +12,36 @@ 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
+ exports.DaumControl = void 0;
16
+ const daum_erg_1 = __importDefault(require("../../modes/daum-erg"));
17
+ const daum_smarttrainer_1 = __importDefault(require("../../modes/daum-smarttrainer"));
18
+ const daum_power_1 = __importDefault(require("../../modes/daum-power"));
19
19
  const utils_1 = require("../../utils/utils");
20
20
  const adapter_1 = require("../adapter");
21
21
  const capabilities_1 = require("../../types/capabilities");
22
- class AbstractDaumAdapter extends adapter_1.SerialIncyclistDevice {
22
+ const adpater_1 = require("../../base/adpater");
23
+ class DaumControl extends adpater_1.ControllableDevice {
24
+ getSupportedCyclingModes() {
25
+ return [daum_erg_1.default, daum_smarttrainer_1.default, daum_power_1.default];
26
+ }
27
+ getDefaultCyclingMode() {
28
+ return new daum_erg_1.default(this.adapter);
29
+ }
30
+ sendInitCommands() {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ return true;
33
+ });
34
+ }
23
35
  }
24
- exports.AbstractDaumAdapter = AbstractDaumAdapter;
25
- class DaumAdapter extends AbstractDaumAdapter {
36
+ exports.DaumControl = DaumControl;
37
+ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
26
38
  constructor(settings, props) {
27
39
  super(settings, props);
28
40
  this.requests = [];
29
41
  this.adapterTime = 0;
30
42
  this.requestBusy = false;
31
43
  this.updateBusy = false;
32
- this.stopped = false;
33
- this.paused = false;
44
+ this.iv = undefined;
34
45
  this.cyclingData = {
35
46
  isPedalling: false,
36
47
  time: 0,
@@ -45,31 +56,21 @@ class DaumAdapter extends AbstractDaumAdapter {
45
56
  capabilities_1.IncyclistCapability.Power, capabilities_1.IncyclistCapability.Speed, capabilities_1.IncyclistCapability.Cadence, capabilities_1.IncyclistCapability.Gear, capabilities_1.IncyclistCapability.HeartRate,
46
57
  capabilities_1.IncyclistCapability.Control
47
58
  ];
59
+ this.setControl(new DaumControl(this, props));
48
60
  }
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);
61
+ getPort() {
62
+ var _a;
63
+ return (_a = this.bike) === null || _a === void 0 ? void 0 : _a.getPort();
64
+ }
65
+ getSerialInterface() {
66
+ var _a;
67
+ return (_a = this.bike) === null || _a === void 0 ? void 0 : _a.serial;
67
68
  }
68
69
  sendInitCommands() {
69
70
  return __awaiter(this, void 0, void 0, function* () {
70
71
  if (this.started && !this.stopped) {
71
72
  try {
72
- if (this.getCyclingMode() instanceof ERGCyclingMode_1.default) {
73
+ if (this.getCyclingMode() instanceof daum_erg_1.default) {
73
74
  const power = this.deviceData.power;
74
75
  const request = power ? { targetPower: power } : this.getCyclingMode().getBikeInitRequest();
75
76
  yield this.sendUpdate(request);
@@ -80,22 +81,9 @@ class DaumAdapter extends AbstractDaumAdapter {
80
81
  return false;
81
82
  }
82
83
  }
83
- else {
84
- return false;
85
- }
84
+ return false;
86
85
  });
87
86
  }
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
87
  getCurrentBikeData() {
100
88
  throw new Error('Method not implemented.');
101
89
  }
@@ -133,7 +121,6 @@ class DaumAdapter extends AbstractDaumAdapter {
133
121
  heartrate: 0
134
122
  };
135
123
  this.deviceData = {};
136
- this.currentRequest = {};
137
124
  this.requests = [];
138
125
  const name = this.getCyclingMode().getName();
139
126
  const settings = this.getCyclingMode().getSettings();
@@ -159,38 +146,131 @@ class DaumAdapter extends AbstractDaumAdapter {
159
146
  return resumed;
160
147
  });
161
148
  }
149
+ waitForPrevCheckFinished() {
150
+ return __awaiter(this, void 0, void 0, function* () {
151
+ if (this.checkPromise) {
152
+ this.logEvent({ message: "waiting for previous check device", port: this.getPort() });
153
+ try {
154
+ yield this.checkPromise;
155
+ }
156
+ catch (_a) { }
157
+ this.logEvent({ message: "previous check device completed", port: this.getPort() });
158
+ this.checkPromise = undefined;
159
+ }
160
+ });
161
+ }
162
+ check() {
163
+ return __awaiter(this, void 0, void 0, function* () {
164
+ yield this.waitForPrevCheckFinished();
165
+ yield this.waitForPrevStartFinished();
166
+ if (this.isStopped())
167
+ return false;
168
+ this.checkPromise = this.performCheck();
169
+ try {
170
+ const res = yield this.checkPromise;
171
+ this.checkPromise = undefined;
172
+ return res;
173
+ }
174
+ catch (err) {
175
+ this.checkPromise = undefined;
176
+ throw err;
177
+ }
178
+ });
179
+ }
180
+ performCheck() {
181
+ return __awaiter(this, void 0, void 0, function* () {
182
+ throw new Error('Method not implemented.');
183
+ });
184
+ }
185
+ waitForPrevStartFinished() {
186
+ return __awaiter(this, void 0, void 0, function* () {
187
+ if (this.startPromise) {
188
+ this.logEvent({ message: "waiting for previous device launch", port: this.getPort() });
189
+ try {
190
+ yield this.startPromise;
191
+ }
192
+ catch (_a) { }
193
+ this.logEvent({ message: "previous device launch attempt completed", port: this.getPort() });
194
+ this.startPromise = undefined;
195
+ }
196
+ });
197
+ }
162
198
  start(props) {
163
- throw new Error('Method not implemented.');
199
+ return __awaiter(this, void 0, void 0, function* () {
200
+ yield this.waitForPrevCheckFinished();
201
+ yield this.waitForPrevStartFinished();
202
+ const isRelaunch = this.started;
203
+ const message = isRelaunch ? 'relaunch of device' : 'initial start of device';
204
+ this.logEvent({ message });
205
+ try {
206
+ if (isRelaunch && this.isPaused())
207
+ this.resume();
208
+ this.startPromise = this.performStart(props, isRelaunch).then((started) => __awaiter(this, void 0, void 0, function* () {
209
+ if (!started) {
210
+ this.logEvent({ message: 'start result: not started' });
211
+ this.started = false;
212
+ return false;
213
+ }
214
+ if (!isRelaunch) {
215
+ try {
216
+ const deviceInfo = yield this.getDeviceInfo();
217
+ this.logEvent({ message: 'device info', deviceInfo });
218
+ }
219
+ catch (_a) { }
220
+ }
221
+ this.logEvent({ message: 'start result: success' });
222
+ this.started = true;
223
+ return true;
224
+ }));
225
+ const started = yield this.startPromise;
226
+ this.startPromise = undefined;
227
+ return started;
228
+ }
229
+ catch (err) {
230
+ this.logEvent({ message: 'start result: error', error: err.message });
231
+ this.startPromise = undefined;
232
+ this.started = false;
233
+ throw new Error(`could not start device, reason:${err.message}`);
234
+ }
235
+ });
164
236
  }
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;
237
+ performStart(props, isRelaunch = false) {
238
+ throw new Error('Method not implemented.');
173
239
  }
174
240
  startUpdatePull() {
175
- this.logEvent({ message: 'start update pull', iv: this.iv, ignoreBike: this.ignoreBike, ignoreHrm: this.ignoreHrm, ignorePower: this.ignorePower });
176
241
  if (this.iv)
177
242
  return;
178
- if (this.ignoreBike && this.ignoreHrm && this.ignorePower)
179
- return;
243
+ this.logEvent({ message: 'start update pull', port: this.getPort() });
180
244
  const ivSync = setInterval(() => {
181
- this.bikeSync();
245
+ try {
246
+ this.bikeSync();
247
+ }
248
+ catch (_a) { }
182
249
  }, this.pullFrequency);
183
250
  const ivUpdate = setInterval(() => {
184
- this.emitData(this.deviceData);
185
- this.refreshRequests();
251
+ try {
252
+ this.emitData(this.deviceData);
253
+ this.refreshRequests();
254
+ }
255
+ catch (_a) { }
186
256
  }, this.pullFrequency);
187
257
  this.iv = {
188
258
  sync: ivSync,
189
259
  update: ivUpdate
190
260
  };
191
261
  }
262
+ stopUpdatePull() {
263
+ if (!this.iv)
264
+ return;
265
+ this.logEvent({ message: 'stop update pull', port: this.getPort() });
266
+ clearInterval(this.iv.sync);
267
+ clearInterval(this.iv.update);
268
+ this.iv = undefined;
269
+ }
192
270
  connect() {
193
271
  return __awaiter(this, void 0, void 0, function* () {
272
+ if (!this.bike)
273
+ return false;
194
274
  if (this.bike.isConnected())
195
275
  return true;
196
276
  try {
@@ -205,19 +285,21 @@ class DaumAdapter extends AbstractDaumAdapter {
205
285
  }
206
286
  close() {
207
287
  return __awaiter(this, void 0, void 0, function* () {
288
+ if (!this.bike)
289
+ return true;
208
290
  if (!this.bike.isConnected())
209
291
  return true;
210
292
  return yield this.bike.close();
211
293
  });
212
294
  }
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
- }
295
+ verifyConnection() {
296
+ return __awaiter(this, void 0, void 0, function* () {
297
+ if (!this.bike.isConnected()) {
298
+ const connected = yield this.bike.connect();
299
+ if (!connected)
300
+ throw new Error('not connected');
301
+ }
302
+ });
221
303
  }
222
304
  reconnect() {
223
305
  return __awaiter(this, void 0, void 0, function* () {
@@ -231,33 +313,34 @@ class DaumAdapter extends AbstractDaumAdapter {
231
313
  }
232
314
  });
233
315
  }
316
+ logEvent(event) {
317
+ if (!this.logger || this.paused)
318
+ return;
319
+ this.logger.logEvent(event);
320
+ const w = global.window;
321
+ if (w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) {
322
+ console.log(`~~~ ${this.logger.getName()}`, event);
323
+ }
324
+ }
234
325
  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* () {
326
+ return __awaiter(this, void 0, void 0, function* () {
327
+ if (this.stopped)
328
+ return true;
329
+ this.logEvent({ message: 'stop request' });
330
+ if (this.paused)
331
+ this.resume();
242
332
  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();
333
+ this.stopUpdatePull();
252
334
  yield this.bike.close();
253
335
  this.logEvent({ message: 'stop request completed' });
254
- resolve(true);
336
+ this.stopped = true;
255
337
  }
256
338
  catch (err) {
257
- this.logEvent({ message: 'stop error', error: err.message });
258
- reject(err);
339
+ this.logEvent({ message: 'stop request failed', reason: err.message });
340
+ throw (err);
259
341
  }
260
- }));
342
+ return this.stopped;
343
+ });
261
344
  }
262
345
  canSendUpdate() {
263
346
  if (this.paused || this.stopped)
@@ -274,39 +357,44 @@ class DaumAdapter extends AbstractDaumAdapter {
274
357
  }
275
358
  update() {
276
359
  return __awaiter(this, void 0, void 0, function* () {
277
- if (this.stopped)
360
+ if (!this.canSendUpdate() || this.updateBusy)
278
361
  return;
279
362
  this.updateBusy = true;
280
- this.getCurrentBikeData()
281
- .then(bikeData => {
363
+ try {
364
+ const bikeData = yield this.getCurrentBikeData();
282
365
  const incyclistData = this.updateData(bikeData);
283
366
  const data = this.transformData(incyclistData);
284
367
  this.updateBusy = false;
285
368
  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);
369
+ }
370
+ catch (err) {
371
+ try {
372
+ this.logEvent({ message: 'bike update error', error: err.message, stack: err.stack });
373
+ const incyclistData = this.updateData(this.cyclingData);
374
+ this.transformData(incyclistData);
375
+ }
376
+ catch (_a) { }
291
377
  this.updateBusy = false;
292
- });
378
+ }
293
379
  });
294
380
  }
295
381
  sendRequests() {
296
382
  return __awaiter(this, void 0, void 0, function* () {
297
383
  if (this.stopped || this.paused)
298
384
  return;
385
+ if (this.requestBusy)
386
+ return;
299
387
  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];
388
+ const cnt = this.requests.length;
389
+ if (cnt > 1) {
390
+ this.requests.forEach((request, idx) => {
391
+ if (idx !== cnt - 1) {
392
+ this.logEvent({ message: 'ignoring bike update request', request });
393
+ }
394
+ });
395
+ this.requests = [this.requests[cnt - 1]];
396
+ }
397
+ let request = this.requests[0];
310
398
  try {
311
399
  yield this.sendRequest(request);
312
400
  this.requests.shift();
@@ -319,16 +407,7 @@ class DaumAdapter extends AbstractDaumAdapter {
319
407
  }
320
408
  bikeSync() {
321
409
  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
- }
410
+ yield this.sendRequests();
332
411
  yield this.update();
333
412
  });
334
413
  }
@@ -367,15 +446,6 @@ class DaumAdapter extends AbstractDaumAdapter {
367
446
  deviceTime: cyclingData.time,
368
447
  deviceDistanceCounter: cyclingData.distanceInternal
369
448
  };
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
449
  this.deviceData = data;
380
450
  return data;
381
451
  }
@@ -391,10 +461,10 @@ class DaumAdapter extends AbstractDaumAdapter {
391
461
  return {};
392
462
  }
393
463
  if (request.slope !== undefined) {
394
- yield bike.setSlope(request.slope);
464
+ yield bike.setTargetSlope(request.slope);
395
465
  }
396
466
  if (request.targetPower !== undefined) {
397
- yield bike.setPower(request.targetPower);
467
+ yield bike.setTargetPower(request.targetPower);
398
468
  }
399
469
  this.requestBusy = false;
400
470
  return request;
@@ -429,8 +499,10 @@ class DaumAdapter extends AbstractDaumAdapter {
429
499
  resolve(bikeRequest);
430
500
  }));
431
501
  }
432
- check() {
433
- throw new Error('Method not implemented.');
502
+ getDeviceInfo() {
503
+ return __awaiter(this, void 0, void 0, function* () {
504
+ throw new Error('Method not implemented.');
505
+ });
434
506
  }
435
507
  }
436
508
  exports.default = DaumAdapter;
@@ -1,33 +1,32 @@
1
- import CyclingMode, { IncyclistBikeData } from '../../../modes/cycling-mode';
2
- import DaumAdapter from '../DaumAdapter';
1
+ import ICyclingMode, { CyclingMode, IncyclistBikeData } from '../../../modes/types';
2
+ import DaumAdapter, { DaumControl } from '../DaumAdapter';
3
3
  import { DeviceProperties } from '../../../types/device';
4
4
  import { SerialDeviceSettings } from '../../adapter';
5
- import SerialInterface from '../../serial-interface';
5
+ import { SerialCommProps } from '../../comm';
6
+ import Daum8008 from './comms';
6
7
  export interface DaumClassicDeviceProperties extends DeviceProperties {
7
8
  gear?: number;
8
9
  }
9
- export default class DaumClassicAdapter extends DaumAdapter<SerialDeviceSettings, DaumClassicDeviceProperties> {
10
+ export type DaumClassicStartInfo = {
11
+ bikeNo?: number;
12
+ serialNo?: string;
13
+ cockpit?: string;
14
+ };
15
+ export declare class DaumClassicControl extends DaumControl<DaumClassicDeviceProperties> {
16
+ getSupportedCyclingModes(): Array<typeof CyclingMode>;
17
+ getDefaultCyclingMode(): ICyclingMode;
18
+ }
19
+ export default class DaumClassicAdapter extends DaumAdapter<DaumClassicControl, SerialDeviceSettings, DaumClassicDeviceProperties, Daum8008> {
10
20
  static NAME: string;
11
- name: string;
12
- id: string;
13
- started: boolean;
14
- startPromise: Promise<unknown>;
15
- checkPromise: Promise<boolean>;
21
+ protected name: string;
22
+ protected id: string;
16
23
  constructor(settings: SerialDeviceSettings, props?: DaumClassicDeviceProperties);
17
- setID(id: any): void;
18
- getID(): string;
24
+ getBikeProps(props: SerialDeviceSettings): SerialCommProps;
19
25
  getName(): string;
20
- setName(name: any): void;
21
- getPort(): any;
26
+ setName(name: string): void;
22
27
  getProtocolName(): string;
23
- getSupportedCyclingModes(): Array<any>;
24
- getDefaultCyclingMode(): CyclingMode;
25
- getSerialInterface(): SerialInterface;
26
- check(): Promise<boolean>;
27
28
  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>;
29
+ performStart(props?: DaumClassicDeviceProperties, isRelaunch?: boolean): Promise<boolean>;
32
30
  getCurrentBikeData(): Promise<IncyclistBikeData>;
31
+ getDeviceInfo(): Promise<any>;
33
32
  }