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.
- package/README.MD +0 -0
- package/lib/adapters.d.ts +6 -0
- package/lib/adapters.js +30 -0
- package/lib/antv2/adapter-factory.d.ts +20 -10
- package/lib/antv2/adapter-factory.js +49 -33
- package/lib/antv2/adapter.d.ts +64 -0
- package/lib/antv2/adapter.js +299 -0
- package/lib/antv2/ant-interface.d.ts +11 -9
- package/lib/antv2/ant-interface.js +15 -11
- package/lib/antv2/fe/adapter.d.ts +25 -0
- package/lib/antv2/{fe.js → fe/adapter.js} +48 -72
- package/lib/antv2/fe/index.d.ts +2 -0
- package/lib/antv2/fe/index.js +7 -0
- package/lib/antv2/hr/adapter.d.ts +14 -0
- package/lib/antv2/hr/adapter.js +73 -0
- package/lib/antv2/hr/index.d.ts +2 -0
- package/lib/antv2/hr/index.js +7 -0
- package/lib/antv2/index.d.ts +7 -0
- package/lib/antv2/index.js +20 -0
- package/lib/antv2/modes/ant-fe-adv-st-mode.d.ts +9 -0
- package/lib/{ant/antfe → antv2/modes}/ant-fe-adv-st-mode.js +1 -1
- package/lib/antv2/modes/ant-fe-erg-mode.d.ts +6 -0
- package/lib/{ant/antfe → antv2/modes}/ant-fe-erg-mode.js +1 -1
- package/lib/antv2/modes/ant-fe-st-mode.d.ts +5 -0
- package/lib/{ant/antfe → antv2/modes}/ant-fe-st-mode.js +1 -1
- package/lib/antv2/pwr/adapter.d.ts +22 -0
- package/lib/antv2/{pwr.js → pwr/adapter.js} +38 -76
- package/lib/antv2/pwr/index.d.ts +2 -0
- package/lib/antv2/pwr/index.js +7 -0
- package/lib/antv2/types.d.ts +19 -0
- package/lib/antv2/types.js +2 -0
- package/lib/antv2/utils.d.ts +1 -0
- package/lib/antv2/utils.js +181 -0
- package/lib/base/adpater.d.ts +56 -0
- package/lib/base/adpater.js +144 -0
- package/lib/ble/adapter-factory.d.ts +31 -0
- package/lib/ble/adapter-factory.js +96 -0
- package/lib/ble/adapter.d.ts +41 -0
- package/lib/ble/adapter.js +188 -0
- package/lib/ble/{ble-device.d.ts → ble-comms.d.ts} +9 -4
- package/lib/ble/{ble-device.js → ble-comms.js} +23 -11
- package/lib/ble/ble-interface.d.ts +15 -24
- package/lib/ble/ble-interface.js +32 -137
- package/lib/ble/ble-peripheral.d.ts +3 -3
- package/lib/ble/ble-peripheral.js +14 -14
- package/lib/ble/ble.d.ts +9 -81
- package/lib/ble/ble.js +1 -39
- package/lib/ble/consts.d.ts +2 -0
- package/lib/ble/consts.js +3 -1
- package/lib/ble/cp/adapter.d.ts +23 -0
- package/lib/ble/cp/adapter.js +124 -0
- package/lib/ble/cp/comm.d.ts +28 -0
- package/lib/ble/cp/comm.js +140 -0
- package/lib/ble/cp/index.d.ts +4 -0
- package/lib/ble/cp/index.js +10 -0
- package/lib/ble/cp/types.d.ts +13 -0
- package/lib/ble/cp/types.js +2 -0
- package/lib/ble/elite/adapter.d.ts +20 -0
- package/lib/ble/elite/adapter.js +127 -0
- package/lib/ble/elite/comms.d.ts +28 -0
- package/lib/ble/elite/comms.js +139 -0
- package/lib/ble/elite/index.d.ts +3 -0
- package/lib/ble/elite/index.js +10 -0
- package/lib/ble/fm/adapter.d.ts +21 -0
- package/lib/ble/fm/adapter.js +190 -0
- package/lib/ble/fm/comms.d.ts +50 -0
- package/lib/ble/{fm.js → fm/comms.js} +3 -224
- package/lib/ble/fm/consts.d.ts +6 -0
- package/lib/ble/fm/consts.js +9 -0
- package/lib/ble/fm/index.d.ts +5 -0
- package/lib/ble/fm/index.js +13 -0
- package/lib/ble/fm/types.d.ts +25 -0
- package/lib/ble/fm/types.js +2 -0
- package/lib/ble/hr/adapter.d.ts +17 -0
- package/lib/ble/hr/adapter.js +62 -0
- package/lib/ble/hr/comm.d.ts +15 -0
- package/lib/ble/hr/comm.js +52 -0
- package/lib/ble/hr/index.d.ts +4 -0
- package/lib/ble/hr/index.js +10 -0
- package/lib/ble/hr/types.d.ts +5 -0
- package/lib/ble/hr/types.js +2 -0
- package/lib/ble/index.d.ts +8 -0
- package/lib/ble/index.js +26 -0
- package/lib/ble/tacx/adapter.d.ts +10 -0
- package/lib/ble/tacx/adapter.js +93 -0
- package/lib/ble/{tacx.d.ts → tacx/comms.d.ts} +6 -38
- package/lib/ble/{tacx.js → tacx/comms.js} +13 -112
- package/lib/ble/tacx/index.d.ts +4 -0
- package/lib/ble/tacx/index.js +10 -0
- package/lib/ble/tacx/types.d.ts +25 -0
- package/lib/ble/tacx/types.js +2 -0
- package/lib/ble/types.d.ts +101 -0
- package/lib/ble/types.js +19 -0
- package/lib/ble/utils.d.ts +7 -0
- package/lib/ble/utils.js +95 -0
- package/lib/ble/wahoo/adapter.d.ts +9 -0
- package/lib/ble/wahoo/adapter.js +93 -0
- package/lib/ble/{wahoo-kickr.d.ts → wahoo/comms.d.ts} +5 -39
- package/lib/ble/{wahoo-kickr.js → wahoo/comms.js} +14 -112
- package/lib/ble/wahoo/index.d.ts +4 -0
- package/lib/ble/wahoo/index.js +10 -0
- package/lib/ble/wahoo/types.d.ts +19 -0
- package/lib/ble/wahoo/types.js +2 -0
- package/lib/device.d.ts +0 -94
- package/lib/device.js +0 -76
- package/lib/index.d.ts +12 -0
- package/lib/index.js +38 -0
- package/lib/interfaces.d.ts +6 -0
- package/lib/interfaces.js +23 -0
- package/lib/{ble → modes}/ble-erg-mode.d.ts +4 -4
- package/lib/{ble → modes}/ble-erg-mode.js +2 -2
- package/lib/{ble → modes}/ble-st-mode.d.ts +3 -3
- package/lib/{ble → modes}/ble-st-mode.js +1 -1
- package/lib/{cycling-mode.d.ts → modes/cycling-mode.d.ts} +8 -8
- package/lib/modes/power-base.d.ts +3 -3
- package/lib/modes/power-base.js +4 -4
- package/lib/modes/power-meter.d.ts +3 -3
- package/lib/modes/simulator.d.ts +2 -2
- package/lib/modes/simulator.js +1 -1
- package/lib/serial/adapter-factory.d.ts +12 -0
- package/lib/serial/adapter-factory.js +30 -0
- package/lib/serial/adapter.d.ts +16 -0
- package/lib/serial/adapter.js +42 -0
- package/lib/serial/bindings/tcp.d.ts +44 -0
- package/lib/serial/bindings/tcp.js +270 -0
- package/lib/serial/comm.d.ts +7 -0
- package/lib/serial/comm.js +2 -0
- package/lib/{daum → serial/daum}/DaumAdapter.d.ts +13 -22
- package/lib/{daum → serial/daum}/DaumAdapter.js +44 -90
- package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.d.ts +2 -2
- package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.js +1 -1
- package/lib/{daum → serial/daum}/ERGCyclingMode.d.ts +3 -3
- package/lib/{daum → serial/daum}/ERGCyclingMode.js +3 -3
- package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.d.ts +3 -3
- package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.js +4 -3
- package/lib/serial/daum/classic/adapter.d.ts +29 -0
- package/lib/{daum/classic/DaumClassicAdapter.js → serial/daum/classic/adapter.js} +77 -50
- package/lib/{daum/classic/bike.d.ts → serial/daum/classic/comms.d.ts} +14 -16
- package/lib/{daum/classic/bike.js → serial/daum/classic/comms.js} +68 -152
- package/lib/serial/daum/classic/mock.d.ts +96 -0
- package/lib/serial/daum/classic/mock.js +365 -0
- package/lib/{daum/classic/DaumClassicCyclingMode.d.ts → serial/daum/classic/modes/daum-classic.d.ts} +3 -3
- package/lib/{daum/classic/DaumClassicCyclingMode.js → serial/daum/classic/modes/daum-classic.js} +2 -2
- package/lib/{daum → serial/daum}/classic/utils.d.ts +1 -1
- package/lib/serial/daum/premium/adapter.d.ts +24 -0
- package/lib/{daum/premium/DaumPremiumAdapter.js → serial/daum/premium/adapter.js} +99 -46
- package/lib/{daum/premium/bike.d.ts → serial/daum/premium/comms.d.ts} +26 -54
- package/lib/{daum/premium/bike.js → serial/daum/premium/comms.js} +208 -420
- package/lib/serial/daum/premium/mock.d.ts +75 -0
- package/lib/serial/daum/premium/mock.js +290 -0
- package/lib/{daum/premium/DaumClassicCyclingMode.d.ts → serial/daum/premium/modes/daum-classic.d.ts} +3 -3
- package/lib/{daum/premium/DaumClassicCyclingMode.js → serial/daum/premium/modes/daum-classic.js} +2 -2
- package/lib/serial/daum/premium/types.d.ts +12 -0
- package/lib/serial/daum/premium/types.js +2 -0
- package/lib/{daum → serial/daum}/premium/utils.d.ts +8 -11
- package/lib/{daum → serial/daum}/premium/utils.js +22 -63
- package/lib/serial/index.d.ts +9 -0
- package/lib/serial/index.js +49 -0
- package/lib/{kettler → serial/kettler}/comms.d.ts +8 -6
- package/lib/{kettler → serial/kettler}/comms.js +71 -32
- package/lib/{kettler → serial/kettler}/ergo-racer/adapter.d.ts +13 -24
- package/lib/{kettler → serial/kettler}/ergo-racer/adapter.js +87 -130
- package/lib/serial/kettler/ergo-racer/mock.d.ts +66 -0
- package/lib/serial/kettler/ergo-racer/mock.js +216 -0
- package/lib/{kettler/ergo-racer/ERGCyclingMode.d.ts → serial/kettler/ergo-racer/modes/erg.d.ts} +4 -4
- package/lib/{kettler/ergo-racer/ERGCyclingMode.js → serial/kettler/ergo-racer/modes/erg.js} +2 -2
- package/lib/serial/serial-interface.d.ts +58 -0
- package/lib/serial/serial-interface.js +283 -0
- package/lib/simulator/Simulator.d.ts +10 -25
- package/lib/simulator/Simulator.js +19 -83
- package/lib/types/adapter.d.ts +32 -0
- package/lib/types/adapter.js +2 -0
- package/lib/types/capabilities.d.ts +8 -0
- package/lib/types/capabilities.js +12 -0
- package/lib/types/data.d.ts +12 -0
- package/lib/types/data.js +2 -0
- package/lib/types/device.d.ts +29 -0
- package/lib/types/device.js +11 -0
- package/lib/types/interface.d.ts +14 -0
- package/lib/types/interface.js +2 -0
- package/lib/types/route.d.ts +2 -2
- package/lib/types/user.d.ts +1 -1
- package/lib/{utils.d.ts → utils/utils.d.ts} +1 -0
- package/lib/{utils.js → utils/utils.js} +5 -1
- package/package.json +15 -11
- package/lib/DeviceSupport.d.ts +0 -36
- package/lib/DeviceSupport.js +0 -82
- package/lib/ant/AntAdapter.d.ts +0 -50
- package/lib/ant/AntAdapter.js +0 -109
- package/lib/ant/AntScanner.d.ts +0 -60
- package/lib/ant/AntScanner.js +0 -651
- package/lib/ant/antfe/AntFEAdapter.d.ts +0 -83
- package/lib/ant/antfe/AntFEAdapter.js +0 -652
- package/lib/ant/antfe/ant-fe-adv-st-mode.d.ts +0 -9
- package/lib/ant/antfe/ant-fe-erg-mode.d.ts +0 -6
- package/lib/ant/antfe/ant-fe-st-mode.d.ts +0 -5
- package/lib/ant/anthrm/AntHrmAdapter.d.ts +0 -16
- package/lib/ant/anthrm/AntHrmAdapter.js +0 -130
- package/lib/ant/antpwr/pwr-adapter.d.ts +0 -49
- package/lib/ant/antpwr/pwr-adapter.js +0 -251
- package/lib/ant/utils.d.ts +0 -1
- package/lib/ant/utils.js +0 -23
- package/lib/antv2/AntAdapter.d.ts +0 -48
- package/lib/antv2/AntAdapter.js +0 -104
- package/lib/antv2/ant-device.d.ts +0 -59
- package/lib/antv2/ant-device.js +0 -161
- package/lib/antv2/fe.d.ts +0 -32
- package/lib/antv2/hr.d.ts +0 -18
- package/lib/antv2/hr.js +0 -102
- package/lib/antv2/incyclist-protocol.d.ts +0 -37
- package/lib/antv2/incyclist-protocol.js +0 -126
- package/lib/antv2/pwr.d.ts +0 -28
- package/lib/ble/elite.d.ts +0 -90
- package/lib/ble/elite.js +0 -322
- package/lib/ble/fm.d.ts +0 -125
- package/lib/ble/hrm.d.ts +0 -48
- package/lib/ble/hrm.js +0 -134
- package/lib/ble/incyclist-protocol.d.ts +0 -31
- package/lib/ble/incyclist-protocol.js +0 -153
- package/lib/ble/pwr.d.ts +0 -89
- package/lib/ble/pwr.js +0 -322
- package/lib/daum/classic/DaumClassicAdapter.d.ts +0 -28
- package/lib/daum/classic/DaumClassicProtocol.d.ts +0 -27
- package/lib/daum/classic/DaumClassicProtocol.js +0 -185
- package/lib/daum/premium/DaumPremiumAdapter.d.ts +0 -16
- package/lib/daum/premium/DaumPremiumProtocol.d.ts +0 -32
- package/lib/daum/premium/DaumPremiumProtocol.js +0 -207
- package/lib/daum/premium/tcpserial.d.ts +0 -33
- package/lib/daum/premium/tcpserial.js +0 -123
- package/lib/kettler/ergo-racer/protocol.d.ts +0 -41
- package/lib/kettler/ergo-racer/protocol.js +0 -203
- package/lib/protocol.d.ts +0 -74
- package/lib/protocol.js +0 -41
- package/lib/registry.d.ts +0 -8
- package/lib/registry.js +0 -33
- package/lib/serialport/bindings/tcp.d.ts +0 -20
- package/lib/serialport/bindings/tcp.js +0 -33
- package/lib/serialport/index.d.ts +0 -2
- package/lib/serialport/index.js +0 -29
- package/lib/serialport/serialport.d.ts +0 -29
- package/lib/serialport/serialport.js +0 -87
- /package/lib/antv2/{ant-binding.d.ts → binding.d.ts} +0 -0
- /package/lib/antv2/{ant-binding.js → binding.js} +0 -0
- /package/lib/{cycling-mode.js → modes/cycling-mode.js} +0 -0
- /package/lib/{daum → serial/daum}/classic/utils.js +0 -0
- /package/lib/{daum → serial/daum}/constants.d.ts +0 -0
- /package/lib/{daum → serial/daum}/constants.js +0 -0
- /package/lib/{serialport.d.ts → serial/serialport.d.ts} +0 -0
- /package/lib/{serialport.js → serial/serialport.js} +0 -0
- /package/lib/{calculations.d.ts → utils/calculations.d.ts} +0 -0
- /package/lib/{calculations.js → utils/calculations.js} +0 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
2
|
+
/// <reference types="node" />
|
|
3
3
|
import { EventLogger } from "gd-eventlog";
|
|
4
|
-
import { Command } from "
|
|
4
|
+
import { Command } from "../../types/command";
|
|
5
5
|
import EventEmitter from "events";
|
|
6
|
-
|
|
6
|
+
import { SerialInterface } from "..";
|
|
7
|
+
export type SerialCommsProps = {
|
|
7
8
|
logger?: EventLogger;
|
|
8
|
-
|
|
9
|
+
interface: string | SerialInterface;
|
|
9
10
|
port: string;
|
|
10
11
|
settings?: any;
|
|
11
12
|
};
|
|
@@ -33,7 +34,8 @@ export default class KettlerSerialComms<T extends Command> extends EventEmitter
|
|
|
33
34
|
private sendState;
|
|
34
35
|
private currentCmd;
|
|
35
36
|
private currentTimeout;
|
|
36
|
-
private
|
|
37
|
+
private serial;
|
|
38
|
+
private openPromise;
|
|
37
39
|
constructor(opts: SerialCommsProps);
|
|
38
40
|
getPort(): string;
|
|
39
41
|
setPort(port: any): void;
|
|
@@ -47,7 +49,7 @@ export default class KettlerSerialComms<T extends Command> extends EventEmitter
|
|
|
47
49
|
onPortOpen(): void;
|
|
48
50
|
onPortClose(): Promise<void>;
|
|
49
51
|
onPortError(err: any): void;
|
|
50
|
-
open():
|
|
52
|
+
open(): Promise<boolean>;
|
|
51
53
|
close(): void;
|
|
52
54
|
startWorker(): void;
|
|
53
55
|
stopWorker(): void;
|
|
@@ -14,8 +14,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.SendState = exports.SerialCommsState = void 0;
|
|
16
16
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
17
|
-
const utils_1 = require("
|
|
17
|
+
const utils_1 = require("../../utils/utils");
|
|
18
18
|
const events_1 = __importDefault(require("events"));
|
|
19
|
+
const __1 = require("..");
|
|
20
|
+
const parser_readline_1 = require("@serialport/parser-readline");
|
|
19
21
|
const DEFAULT_RCV_TIMEOUT = 1500;
|
|
20
22
|
const DEFAULT_OPEN_TIMEOUT = 3000;
|
|
21
23
|
const DEBUG_LOGGER = {
|
|
@@ -37,6 +39,23 @@ var SendState;
|
|
|
37
39
|
SendState[SendState["Sending"] = 1] = "Sending";
|
|
38
40
|
SendState[SendState["Receiving"] = 2] = "Receiving";
|
|
39
41
|
})(SendState = exports.SendState || (exports.SendState = {}));
|
|
42
|
+
const getBikeProps = (props) => {
|
|
43
|
+
const { port, interface: ifaceName } = props;
|
|
44
|
+
let serial;
|
|
45
|
+
if (ifaceName && typeof ifaceName === 'string') {
|
|
46
|
+
serial = __1.SerialInterface.getInstance({ ifaceName });
|
|
47
|
+
}
|
|
48
|
+
else if (!ifaceName) {
|
|
49
|
+
serial = __1.SerialInterface.getInstance({ ifaceName: 'serial' });
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
serial = props.interface;
|
|
53
|
+
}
|
|
54
|
+
if (!serial)
|
|
55
|
+
throw new Error(`unknonwn interface: ${ifaceName}`);
|
|
56
|
+
const path = `${port}`;
|
|
57
|
+
return { serial, path };
|
|
58
|
+
};
|
|
40
59
|
const CRLF = '\r\n';
|
|
41
60
|
class KettlerSerialComms extends events_1.default {
|
|
42
61
|
constructor(opts) {
|
|
@@ -44,8 +63,10 @@ class KettlerSerialComms extends events_1.default {
|
|
|
44
63
|
this.stateIn = (allowedStates) => {
|
|
45
64
|
return allowedStates.indexOf(this.state) >= 0;
|
|
46
65
|
};
|
|
47
|
-
|
|
48
|
-
this.
|
|
66
|
+
const { serial, path } = getBikeProps(opts);
|
|
67
|
+
this.logger = process.env.DEBUG ? DEBUG_LOGGER : (opts.logger || new gd_eventlog_1.EventLogger('Kettler'));
|
|
68
|
+
this.serial = serial;
|
|
69
|
+
this.port = path;
|
|
49
70
|
this.sp = undefined;
|
|
50
71
|
this.queue = new utils_1.Queue();
|
|
51
72
|
this.state = SerialCommsState.Idle;
|
|
@@ -53,7 +74,6 @@ class KettlerSerialComms extends events_1.default {
|
|
|
53
74
|
this.settings = opts.settings || {};
|
|
54
75
|
this.currentCmd = undefined;
|
|
55
76
|
this.currentTimeout = undefined;
|
|
56
|
-
this.protocol = opts.protocol;
|
|
57
77
|
}
|
|
58
78
|
getPort() {
|
|
59
79
|
return this.port;
|
|
@@ -101,7 +121,8 @@ class KettlerSerialComms extends events_1.default {
|
|
|
101
121
|
this.stopCurrentTimeoutCheck();
|
|
102
122
|
this.queue.clear();
|
|
103
123
|
this.emit('closed');
|
|
104
|
-
this.sp
|
|
124
|
+
if (this.sp)
|
|
125
|
+
this.sp.removeAllListeners();
|
|
105
126
|
this.sp = undefined;
|
|
106
127
|
});
|
|
107
128
|
}
|
|
@@ -115,42 +136,60 @@ class KettlerSerialComms extends events_1.default {
|
|
|
115
136
|
ignore = true;
|
|
116
137
|
if (!ignore) {
|
|
117
138
|
this.logger.logEvent({ message: "port error:", port: this.getPort(), error: err.message, stack: err.stack, state: this.state });
|
|
118
|
-
this.emit('error', err);
|
|
119
139
|
this.stopCurrentTimeoutCheck();
|
|
120
140
|
if (this.state === SerialCommsState.Connecting || this.state === SerialCommsState.Disconnecting) {
|
|
121
141
|
this.state = SerialCommsState.Error;
|
|
122
|
-
this.sp
|
|
142
|
+
if (this.sp)
|
|
143
|
+
this.sp.removeAllListeners();
|
|
123
144
|
this.sp = undefined;
|
|
124
145
|
}
|
|
125
146
|
}
|
|
126
147
|
}
|
|
127
148
|
open() {
|
|
128
|
-
this
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (this.sp === undefined) {
|
|
135
|
-
this.sp = new SerialPort(this.getPort(), this.settings);
|
|
136
|
-
this.sp.on('open', () => { this.onPortOpen(); });
|
|
137
|
-
this.sp.on('close', () => { this.onPortClose(); });
|
|
138
|
-
this.sp.on('error', (error) => { this.onPortError(error); });
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
this.logger.logEvent({ message: "open()", port: this.getPort() });
|
|
151
|
+
if (this.state === SerialCommsState.Connected)
|
|
152
|
+
return true;
|
|
153
|
+
if (this.stateIn([SerialCommsState.Connecting, SerialCommsState.Disconnecting])) {
|
|
154
|
+
return this.openPromise;
|
|
139
155
|
}
|
|
140
|
-
this.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
156
|
+
this.openPromise = new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
const done = (result) => {
|
|
158
|
+
if (this.openPromise) {
|
|
159
|
+
this.openPromise = undefined;
|
|
160
|
+
resolve(result);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
try {
|
|
164
|
+
const timeout = this.settings.openTimeout || DEFAULT_OPEN_TIMEOUT;
|
|
165
|
+
this.currentTimeout = setTimeout(() => {
|
|
166
|
+
this.logger.logEvent({ message: "open() timeout", port: this.getPort() });
|
|
167
|
+
this.onPortError(new Error("open() timeout"));
|
|
168
|
+
return done(false);
|
|
169
|
+
}, timeout);
|
|
170
|
+
const port = yield this.serial.openPort(this.port);
|
|
171
|
+
if (port) {
|
|
172
|
+
this.onPortOpen();
|
|
173
|
+
this.sp = port;
|
|
174
|
+
this.sp.on('close', () => { this.onPortClose(); });
|
|
175
|
+
this.sp.on('error', (error) => { this.onPortError(error); });
|
|
176
|
+
const parser = this.sp.pipe(new parser_readline_1.ReadlineParser({ delimiter: CRLF }));
|
|
177
|
+
parser.on('data', (data) => { this.onData(data); });
|
|
178
|
+
return done(true);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
this.onPortError(new Error('could not open port'));
|
|
182
|
+
return done(false);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
this.logger.logEvent({ message: "error", fn: 'open()', error: err.message });
|
|
187
|
+
this.state = SerialCommsState.Disconnected;
|
|
188
|
+
return done(false);
|
|
189
|
+
}
|
|
190
|
+
}));
|
|
191
|
+
return this.openPromise;
|
|
192
|
+
});
|
|
154
193
|
}
|
|
155
194
|
close() {
|
|
156
195
|
this.logger.logEvent({ message: 'close()', port: this.getPort() });
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import DeviceAdapterBase, { DeviceAdapter, DeviceData, Bike } from "../../device";
|
|
3
|
-
import { DeviceProtocol } from "../../protocol";
|
|
1
|
+
import { DeviceProperties } from "../../../types/device";
|
|
4
2
|
import { EventLogger } from "gd-eventlog";
|
|
5
3
|
import SerialComms from "../comms";
|
|
6
|
-
import { Command } from "
|
|
7
|
-
import CyclingMode, { IncyclistBikeData } from "
|
|
8
|
-
import {
|
|
4
|
+
import { Command } from "../../../types/command";
|
|
5
|
+
import CyclingMode, { IncyclistBikeData } from "../../../modes/cycling-mode";
|
|
6
|
+
import { SerialDeviceSettings, SerialIncyclistDevice } from "../../adapter";
|
|
7
|
+
import { DeviceData } from "../../../types/data";
|
|
9
8
|
export interface KettlerRacerCommand extends Command {
|
|
10
9
|
}
|
|
11
10
|
export interface KettlerExtendedBikeData {
|
|
@@ -21,18 +20,11 @@ export interface KettlerBikeData {
|
|
|
21
20
|
time: number;
|
|
22
21
|
power: number;
|
|
23
22
|
}
|
|
24
|
-
export
|
|
25
|
-
userSettings?: User;
|
|
26
|
-
bikeSettings?: any;
|
|
27
|
-
cyclingMode?: CyclingMode;
|
|
28
|
-
}
|
|
29
|
-
export default class KettlerRacerAdapter extends DeviceAdapterBase implements DeviceAdapter, Bike {
|
|
23
|
+
export default class KettlerRacerAdapter extends SerialIncyclistDevice {
|
|
30
24
|
private id;
|
|
31
25
|
private ignoreHrm;
|
|
32
26
|
private ignoreBike;
|
|
33
27
|
private ignorePower;
|
|
34
|
-
private logger;
|
|
35
|
-
private paused;
|
|
36
28
|
private iv;
|
|
37
29
|
private requests;
|
|
38
30
|
private data;
|
|
@@ -42,11 +34,12 @@ export default class KettlerRacerAdapter extends DeviceAdapterBase implements De
|
|
|
42
34
|
private requestBusy;
|
|
43
35
|
private comms;
|
|
44
36
|
private prevDistance;
|
|
45
|
-
constructor(
|
|
37
|
+
constructor(settings: SerialDeviceSettings, props?: DeviceProperties);
|
|
46
38
|
isBike(): boolean;
|
|
47
39
|
isPower(): boolean;
|
|
48
40
|
isHrm(): boolean;
|
|
49
|
-
|
|
41
|
+
getProtocolName(): string;
|
|
42
|
+
isSame(device: SerialIncyclistDevice): boolean;
|
|
50
43
|
setID(id: any): void;
|
|
51
44
|
getID(): string;
|
|
52
45
|
getName(): string;
|
|
@@ -57,13 +50,11 @@ export default class KettlerRacerAdapter extends DeviceAdapterBase implements De
|
|
|
57
50
|
_getComms(): SerialComms<KettlerRacerCommand>;
|
|
58
51
|
_setComms(comms: SerialComms<KettlerRacerCommand>): void;
|
|
59
52
|
getLogger(): EventLogger;
|
|
60
|
-
getUserSettings(): User;
|
|
61
|
-
getWeight(): number;
|
|
62
53
|
setComputerMode(): Promise<boolean>;
|
|
63
54
|
setClientMode(): Promise<boolean>;
|
|
64
55
|
reset(): Promise<boolean>;
|
|
65
56
|
getIdentifier(): Promise<string>;
|
|
66
|
-
|
|
57
|
+
getKettlerInterface(): Promise<string>;
|
|
67
58
|
getVersion(): Promise<string>;
|
|
68
59
|
getCalibration(): Promise<string>;
|
|
69
60
|
startTraining(): Promise<string>;
|
|
@@ -77,11 +68,9 @@ export default class KettlerRacerAdapter extends DeviceAdapterBase implements De
|
|
|
77
68
|
parseExtendedStatus(data: string): KettlerExtendedBikeData;
|
|
78
69
|
parseStatus(data: string): KettlerBikeData;
|
|
79
70
|
check(): Promise<boolean>;
|
|
80
|
-
start(props?: any): Promise<
|
|
71
|
+
start(props?: any): Promise<boolean>;
|
|
81
72
|
startUpdatePull(): void;
|
|
82
73
|
stop(): Promise<boolean>;
|
|
83
|
-
pause(): Promise<boolean>;
|
|
84
|
-
resume(): Promise<boolean>;
|
|
85
74
|
mapData(bikeData: KettlerBikeData): IncyclistBikeData;
|
|
86
75
|
transformData(internalData: IncyclistBikeData, bikeData: KettlerBikeData): DeviceData;
|
|
87
76
|
update(): Promise<void>;
|
|
@@ -92,10 +81,10 @@ export default class KettlerRacerAdapter extends DeviceAdapterBase implements De
|
|
|
92
81
|
sendData(): void;
|
|
93
82
|
refreshRequests(): void;
|
|
94
83
|
processClientRequest(request: any): Promise<unknown>;
|
|
84
|
+
connect(): Promise<boolean>;
|
|
85
|
+
close(): Promise<boolean>;
|
|
95
86
|
waitForOpened(retries?: boolean): Promise<boolean>;
|
|
96
87
|
waitForClosed(): Promise<boolean>;
|
|
97
88
|
getSupportedCyclingModes(): any[];
|
|
98
89
|
getDefaultCyclingMode(): CyclingMode;
|
|
99
|
-
setUserSettings(userSettings: any): void;
|
|
100
|
-
setBikeSettings(bikeSettings: any): void;
|
|
101
90
|
}
|