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.
- package/lib/adapters.d.ts +1 -1
- package/lib/antv2/adapter-factory.d.ts +4 -13
- package/lib/antv2/adapter.d.ts +16 -33
- package/lib/antv2/adapter.js +68 -112
- package/lib/antv2/ant-interface.d.ts +3 -11
- package/lib/antv2/ant-interface.js +1 -1
- package/lib/antv2/base/adapter.d.ts +62 -0
- package/lib/antv2/base/adapter.js +360 -0
- package/lib/antv2/base/ant-interface.d.ts +35 -0
- package/lib/antv2/base/ant-interface.js +285 -0
- package/lib/antv2/base/binding.d.ts +13 -0
- package/lib/antv2/base/binding.js +27 -0
- package/lib/antv2/cad/adapter.d.ts +10 -0
- package/lib/antv2/cad/adapter.js +25 -0
- package/lib/antv2/cad/index.d.ts +2 -0
- package/lib/antv2/cad/index.js +7 -0
- package/lib/antv2/consts.d.ts +2 -0
- package/lib/antv2/consts.js +5 -0
- package/lib/antv2/factories/adapter-factory.d.ts +14 -0
- package/lib/antv2/factories/adapter-factory.js +65 -0
- package/lib/antv2/factories/sensor-factory.d.ts +5 -0
- package/lib/antv2/factories/sensor-factory.js +22 -0
- package/lib/antv2/fe/adapter.d.ts +25 -26
- package/lib/antv2/fe/adapter.js +212 -218
- package/lib/antv2/hr/adapter.d.ts +6 -14
- package/lib/antv2/hr/adapter.js +7 -55
- package/lib/antv2/hr copy/adapter.d.ts +11 -0
- package/lib/antv2/hr copy/adapter.js +30 -0
- package/lib/antv2/hr copy/index.d.ts +2 -0
- package/lib/antv2/hr copy/index.js +7 -0
- package/lib/antv2/index.d.ts +5 -4
- package/lib/antv2/index.js +4 -2
- package/lib/antv2/pwr/adapter.d.ts +9 -29
- package/lib/antv2/pwr/adapter.js +20 -130
- package/lib/antv2/types.d.ts +23 -3
- package/lib/base/adpater.d.ts +42 -45
- package/lib/base/adpater.js +144 -110
- package/lib/base/consts.d.ts +4 -0
- package/lib/base/consts.js +9 -0
- package/lib/ble/adapter-factory.d.ts +4 -4
- package/lib/ble/base/adapter.d.ts +6 -24
- package/lib/ble/base/adapter.js +4 -94
- package/lib/ble/ble-interface.d.ts +2 -3
- package/lib/ble/cp/adapter.d.ts +6 -11
- package/lib/ble/cp/adapter.js +9 -12
- package/lib/ble/elite/adapter.d.ts +8 -8
- package/lib/ble/elite/adapter.js +6 -2
- package/lib/ble/fm/adapter.d.ts +11 -11
- package/lib/ble/fm/adapter.js +26 -20
- package/lib/ble/hr/adapter.d.ts +3 -4
- package/lib/ble/hr/adapter.js +2 -2
- package/lib/ble/tacx/adapter.d.ts +2 -3
- package/lib/ble/tacx/adapter.js +8 -8
- package/lib/ble/types.d.ts +1 -2
- package/lib/ble/wahoo/adapter.d.ts +2 -2
- package/lib/ble/wahoo/adapter.js +6 -6
- package/lib/ble/wahoo/comms.js +16 -16
- package/lib/factories/adapters.d.ts +7 -0
- package/lib/factories/adapters.js +49 -0
- package/lib/factories/index.d.ts +3 -0
- package/lib/factories/index.js +10 -0
- package/lib/factories/interfaces.d.ts +7 -0
- package/lib/factories/interfaces.js +27 -0
- package/lib/index.d.ts +8 -9
- package/lib/index.js +5 -8
- package/lib/interfaces.d.ts +1 -1
- package/lib/modes/ant-fe-adv-st-mode.d.ts +12 -0
- package/lib/modes/ant-fe-adv-st-mode.js +83 -0
- package/lib/modes/antble-erg.d.ts +31 -0
- package/lib/modes/antble-erg.js +28 -0
- package/lib/modes/antble-smarttrainer.d.ts +23 -0
- package/lib/modes/antble-smarttrainer.js +65 -0
- package/lib/modes/base.d.ts +29 -0
- package/lib/modes/{cycling-mode.js → base.js} +23 -26
- package/lib/modes/daum-classic-standard.d.ts +17 -0
- package/lib/modes/daum-classic-standard.js +54 -0
- package/lib/modes/daum-erg.d.ts +49 -0
- package/lib/{serial/daum/ERGCyclingMode.js → modes/daum-erg.js} +45 -73
- package/lib/modes/daum-power.d.ts +5 -0
- package/lib/{serial/daum/DaumPowerMeterCyclingMode.js → modes/daum-power.js} +1 -10
- package/lib/modes/daum-premium-standard.d.ts +24 -0
- package/lib/{serial/daum/premium/modes/daum-classic.js → modes/daum-premium-standard.js} +26 -38
- package/lib/modes/daum-smarttrainer.d.ts +83 -0
- package/lib/{serial/daum/SmartTrainerCyclingMode.js → modes/daum-smarttrainer.js} +23 -26
- package/lib/modes/kettler-erg.d.ts +44 -0
- package/lib/{serial/kettler/ergo-racer/modes/erg.js → modes/kettler-erg.js} +12 -23
- package/lib/modes/power-base.d.ts +28 -3
- package/lib/modes/power-base.js +184 -7
- package/lib/modes/power-meter.d.ts +11 -16
- package/lib/modes/power-meter.js +15 -54
- package/lib/modes/simulator.d.ts +38 -10
- package/lib/modes/simulator.js +14 -46
- package/lib/modes/{cycling-mode.d.ts → types.d.ts} +22 -30
- package/lib/modes/types.js +56 -0
- package/lib/serial/SinglePathScanner.d.ts +17 -0
- package/lib/serial/SinglePathScanner.js +87 -0
- package/lib/serial/adapter-factory.d.ts +8 -6
- package/lib/serial/adapter.d.ts +6 -11
- package/lib/serial/adapter.js +5 -2
- package/lib/serial/base/adapter.d.ts +17 -0
- package/lib/serial/base/adapter.js +67 -0
- package/lib/serial/base/comms.d.ts +62 -0
- package/lib/serial/base/comms.js +280 -0
- package/lib/serial/base/serial-interface.d.ts +36 -0
- package/lib/serial/base/serial-interface.js +288 -0
- package/lib/serial/base/serial-scanner.d.ts +16 -0
- package/lib/serial/base/serial-scanner.js +87 -0
- package/lib/serial/base/serialport.d.ts +17 -0
- package/lib/serial/base/serialport.js +87 -0
- package/lib/serial/comms.d.ts +2 -2
- package/lib/serial/daum/DaumAdapter.d.ts +26 -35
- package/lib/serial/daum/DaumAdapter.js +214 -161
- package/lib/serial/daum/classic/PROTOCOL_NAME.d.ts +2 -0
- package/lib/serial/daum/classic/PROTOCOL_NAME.js +5 -0
- package/lib/serial/daum/classic/adapter.d.ts +13 -26
- package/lib/serial/daum/classic/adapter.js +72 -176
- package/lib/serial/daum/classic/comms.d.ts +21 -17
- package/lib/serial/daum/classic/comms.js +41 -14
- package/lib/serial/daum/classic/consts.d.ts +2 -0
- package/lib/serial/daum/classic/consts.js +5 -0
- package/lib/serial/daum/classic/mock.d.ts +4 -0
- package/lib/serial/daum/classic/mock.js +18 -7
- package/lib/serial/daum/classic/types.d.ts +8 -10
- package/lib/serial/daum/classic/utils.d.ts +1 -2
- package/lib/serial/daum/consts.d.ts +0 -0
- package/lib/serial/daum/consts.js +0 -0
- package/lib/serial/daum/premium/adapter.d.ts +17 -15
- package/lib/serial/daum/premium/adapter.js +86 -109
- package/lib/serial/daum/premium/comms.d.ts +7 -7
- package/lib/serial/daum/premium/comms.js +25 -16
- package/lib/serial/daum/premium/mock.d.ts +5 -1
- package/lib/serial/daum/premium/mock.js +17 -7
- package/lib/serial/daum/premium/types.d.ts +32 -17
- package/lib/serial/daum/premium/types.js +8 -8
- package/lib/serial/daum/premium/utils.d.ts +2 -3
- package/lib/serial/daum/premium/utils.js +3 -3
- package/lib/serial/daum/types.d.ts +14 -0
- package/lib/serial/daum/types.js +13 -0
- package/lib/serial/factories/adapter-factory.d.ts +14 -0
- package/lib/serial/factories/adapter-factory.js +30 -0
- package/lib/serial/index.d.ts +8 -5
- package/lib/serial/index.js +15 -15
- package/lib/serial/kettler/comms.d.ts +1 -1
- package/lib/serial/kettler/ergo-racer/adapter.d.ts +11 -16
- package/lib/serial/kettler/ergo-racer/adapter.js +10 -12
- package/lib/serial/kettler/types.d.ts +8 -0
- package/lib/serial/kettler/types.js +2 -0
- package/lib/serial/serial-interface.d.ts +2 -32
- package/lib/serial/serial-interface.js +4 -78
- package/lib/serial/serial-scanner.d.ts +16 -0
- package/lib/serial/serial-scanner.js +87 -0
- package/lib/serial/serialport.d.ts +1 -13
- package/lib/serial/types.d.ts +45 -0
- package/lib/serial/types.js +9 -0
- package/lib/simulator/Simulator.d.ts +13 -19
- package/lib/simulator/Simulator.js +10 -51
- package/lib/types/Command.d.ts +8 -0
- package/lib/types/Command.js +2 -0
- package/lib/types/adapter.d.ts +34 -24
- package/lib/types/command.d.ts +0 -8
- package/lib/types/command.js +0 -2
- package/lib/types/data.d.ts +12 -1
- package/lib/types/device.d.ts +8 -23
- package/lib/types/device.js +9 -8
- package/lib/types/index.d.ts +6 -0
- package/lib/types/index.js +22 -0
- package/lib/types/route.d.ts +0 -19
- package/lib/types/route.js +0 -2
- package/lib/types/types.d.ts +8 -0
- package/lib/types/types.js +2 -0
- package/lib/utils/utils.d.ts +2 -1
- package/lib/utils/utils.js +22 -4
- package/package.json +3 -3
- package/lib/antv2/modes/ant-fe-adv-st-mode.d.ts +0 -9
- package/lib/antv2/modes/ant-fe-adv-st-mode.js +0 -51
- package/lib/antv2/modes/ant-fe-erg-mode.d.ts +0 -6
- package/lib/antv2/modes/ant-fe-erg-mode.js +0 -14
- package/lib/antv2/modes/ant-fe-st-mode.d.ts +0 -5
- package/lib/antv2/modes/ant-fe-st-mode.js +0 -13
- package/lib/modes/ble-erg-mode.d.ts +0 -18
- package/lib/modes/ble-erg-mode.js +0 -148
- package/lib/modes/ble-st-mode.d.ts +0 -15
- package/lib/modes/ble-st-mode.js +0 -96
- package/lib/serial/daum/DaumPowerMeterCyclingMode.d.ts +0 -8
- package/lib/serial/daum/ERGCyclingMode.d.ts +0 -26
- package/lib/serial/daum/SmartTrainerCyclingMode.d.ts +0 -42
- package/lib/serial/daum/classic/modes/daum-classic.d.ts +0 -13
- package/lib/serial/daum/classic/modes/daum-classic.js +0 -97
- package/lib/serial/daum/constants.d.ts +0 -19
- package/lib/serial/daum/constants.js +0 -22
- package/lib/serial/daum/premium/modes/daum-classic.d.ts +0 -14
- package/lib/serial/kettler/ergo-racer/modes/erg.d.ts +0 -25
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { EventLogger } from "gd-eventlog";
|
|
2
|
+
import SerialInterface from "./base/serial-interface";
|
|
3
|
+
import { BindingInterface } from "@serialport/bindings-interface";
|
|
4
|
+
import { SerialPortStream } from "@serialport/stream";
|
|
5
|
+
import { DeviceSettings, IncyclistScanProps, InterfaceProps } from "../types";
|
|
6
|
+
export type SerialCommProps = {
|
|
7
|
+
serial: SerialInterface;
|
|
8
|
+
path: string;
|
|
9
|
+
logger?: EventLogger;
|
|
10
|
+
};
|
|
11
|
+
export type InterfaceBinding = {
|
|
12
|
+
name: string;
|
|
13
|
+
binding: BindingInterface;
|
|
14
|
+
};
|
|
15
|
+
export type InterfaceImplementation = {
|
|
16
|
+
name: string;
|
|
17
|
+
Serialport: any;
|
|
18
|
+
implementation?: any;
|
|
19
|
+
};
|
|
20
|
+
export type SerialPortProps = {
|
|
21
|
+
interface: string;
|
|
22
|
+
port?: string;
|
|
23
|
+
};
|
|
24
|
+
export declare enum SerialInterfaceType {
|
|
25
|
+
SERIAL = "serial",
|
|
26
|
+
TCPIP = "tcpip"
|
|
27
|
+
}
|
|
28
|
+
export interface SerialInterfaceProps extends InterfaceProps {
|
|
29
|
+
ifaceName: string;
|
|
30
|
+
binding?: BindingInterface;
|
|
31
|
+
}
|
|
32
|
+
export type PortMapping = {
|
|
33
|
+
path: string;
|
|
34
|
+
port: SerialPortStream;
|
|
35
|
+
};
|
|
36
|
+
export interface SerialScannerProps extends IncyclistScanProps {
|
|
37
|
+
port?: string;
|
|
38
|
+
protocol: string;
|
|
39
|
+
}
|
|
40
|
+
export interface SerialDeviceSettings extends DeviceSettings {
|
|
41
|
+
protocol: string;
|
|
42
|
+
host?: string;
|
|
43
|
+
port?: string;
|
|
44
|
+
interface: string | SerialInterface;
|
|
45
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SerialInterfaceType = void 0;
|
|
4
|
+
var SerialInterfaceType;
|
|
5
|
+
(function (SerialInterfaceType) {
|
|
6
|
+
SerialInterfaceType["SERIAL"] = "serial";
|
|
7
|
+
SerialInterfaceType["TCPIP"] = "tcpip";
|
|
8
|
+
})(SerialInterfaceType || (exports.SerialInterfaceType = SerialInterfaceType = {}));
|
|
9
|
+
;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { DeviceProperties, DeviceSettings } from '../types
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import SimulatorCyclingMode from '../modes/simulator';
|
|
3
|
+
import IncyclistDevice from '../base/adpater';
|
|
4
|
+
import { IAdapter, IncyclistBikeData, DeviceProperties, DeviceSettings } from '../types';
|
|
5
5
|
interface SimulatorProperties extends DeviceProperties {
|
|
6
6
|
isBot?: boolean;
|
|
7
7
|
settings?: any;
|
|
8
8
|
activity?: any;
|
|
9
9
|
}
|
|
10
|
-
export declare class Simulator extends
|
|
10
|
+
export declare class Simulator extends IncyclistDevice<SimulatorProperties> {
|
|
11
11
|
static NAME: string;
|
|
12
|
-
|
|
12
|
+
protected static controllers: {
|
|
13
|
+
modes: (typeof SimulatorCyclingMode)[];
|
|
14
|
+
default: typeof SimulatorCyclingMode;
|
|
15
|
+
};
|
|
13
16
|
speed: number;
|
|
14
17
|
power: number;
|
|
15
18
|
cadence: number;
|
|
16
19
|
time: number;
|
|
17
|
-
iv: any;
|
|
18
|
-
started: boolean;
|
|
19
20
|
slope: number;
|
|
20
21
|
limit: any;
|
|
21
22
|
startProps?: any;
|
|
22
|
-
cyclingMode: CyclingMode;
|
|
23
23
|
startTS: number;
|
|
24
24
|
data: IncyclistBikeData;
|
|
25
25
|
isBot: boolean;
|
|
26
|
-
|
|
26
|
+
iv: NodeJS.Timeout;
|
|
27
27
|
userSettings: {
|
|
28
28
|
weight?: number;
|
|
29
29
|
};
|
|
@@ -32,16 +32,10 @@ export declare class Simulator extends ControllableDevice {
|
|
|
32
32
|
};
|
|
33
33
|
constructor(settings: DeviceSettings, props?: SimulatorProperties);
|
|
34
34
|
isEqual(settings: DeviceSettings): boolean;
|
|
35
|
-
isSame(device:
|
|
35
|
+
isSame(device: IAdapter): boolean;
|
|
36
36
|
getID(): string;
|
|
37
37
|
getName(): string;
|
|
38
38
|
getUniqueName(): string;
|
|
39
|
-
setIgnoreHrm(ignore: any): void;
|
|
40
|
-
getSupportedCyclingModes(): Array<any>;
|
|
41
|
-
getDefaultCyclingMode(): CyclingMode;
|
|
42
|
-
getCyclingMode(): CyclingMode;
|
|
43
|
-
setCyclingMode(mode: CyclingMode | string, settings?: any): void;
|
|
44
|
-
sendInitCommands(): Promise<boolean>;
|
|
45
39
|
start(props?: SimulatorProperties): Promise<boolean>;
|
|
46
40
|
stop(): Promise<boolean>;
|
|
47
41
|
pause(): Promise<boolean>;
|
|
@@ -50,8 +44,8 @@ export declare class Simulator extends ControllableDevice {
|
|
|
50
44
|
faster(): void;
|
|
51
45
|
slower(): void;
|
|
52
46
|
update(): void;
|
|
53
|
-
|
|
47
|
+
canEmitData(): boolean;
|
|
54
48
|
calculateDistance(speedKps: any, timeS: any): number;
|
|
55
|
-
sendUpdate(request: any): import("
|
|
49
|
+
sendUpdate(request: any): import("..").UpdateRequest;
|
|
56
50
|
}
|
|
57
51
|
export {};
|
|
@@ -13,35 +13,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Simulator = void 0;
|
|
16
|
-
const adpater_1 = require("../base/adpater");
|
|
17
16
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
18
17
|
const simulator_1 = __importDefault(require("../modes/simulator"));
|
|
19
|
-
const
|
|
18
|
+
const adpater_1 = __importDefault(require("../base/adpater"));
|
|
19
|
+
const types_1 = require("../types");
|
|
20
20
|
const DEFAULT_PROPS = { isBot: false };
|
|
21
|
-
class Simulator extends adpater_1.
|
|
21
|
+
class Simulator extends adpater_1.default {
|
|
22
22
|
constructor(settings, props = DEFAULT_PROPS) {
|
|
23
23
|
super(settings, props);
|
|
24
24
|
this.logger = new gd_eventlog_1.EventLogger(Simulator.NAME);
|
|
25
25
|
this.speed = 0;
|
|
26
26
|
this.power = 0;
|
|
27
27
|
this.cadence = 90;
|
|
28
|
-
this.paused = undefined;
|
|
29
28
|
this.time = undefined;
|
|
30
|
-
this.iv = undefined;
|
|
31
|
-
this.started = false;
|
|
32
|
-
this.paused = false;
|
|
33
29
|
this.slope = 0;
|
|
34
30
|
this.limit = {};
|
|
35
31
|
this.startTS = undefined;
|
|
36
32
|
this.data = { isPedalling: false, power: 0, pedalRpm: 0, speed: 0, heartrate: 0, distanceInternal: 0 };
|
|
37
33
|
this.isBot = props.isBot || false;
|
|
38
|
-
this.ignoreHrm = false;
|
|
39
34
|
const name = this.getCyclingMode().getName();
|
|
40
35
|
const modeSettings = this.isBot ? props.settings : this.getCyclingMode().getSettings();
|
|
41
36
|
this.setCyclingMode(name, modeSettings);
|
|
42
37
|
this.capabilities = [
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
types_1.IncyclistCapability.Power, types_1.IncyclistCapability.Speed, types_1.IncyclistCapability.Cadence, types_1.IncyclistCapability.Gear,
|
|
39
|
+
types_1.IncyclistCapability.Control
|
|
45
40
|
];
|
|
46
41
|
}
|
|
47
42
|
isEqual(settings) {
|
|
@@ -55,44 +50,6 @@ class Simulator extends adpater_1.ControllableDevice {
|
|
|
55
50
|
getID() { return Simulator.NAME; }
|
|
56
51
|
getName() { return Simulator.NAME; }
|
|
57
52
|
getUniqueName() { return Simulator.NAME; }
|
|
58
|
-
setIgnoreHrm(ignore) {
|
|
59
|
-
this.ignoreHrm = ignore;
|
|
60
|
-
}
|
|
61
|
-
getSupportedCyclingModes() {
|
|
62
|
-
const supported = [];
|
|
63
|
-
supported.push(simulator_1.default);
|
|
64
|
-
return supported;
|
|
65
|
-
}
|
|
66
|
-
getDefaultCyclingMode() {
|
|
67
|
-
return new simulator_1.default(this);
|
|
68
|
-
}
|
|
69
|
-
getCyclingMode() {
|
|
70
|
-
if (!this.cyclingMode)
|
|
71
|
-
this.setCyclingMode(this.getDefaultCyclingMode());
|
|
72
|
-
return this.cyclingMode;
|
|
73
|
-
}
|
|
74
|
-
setCyclingMode(mode, settings) {
|
|
75
|
-
let selectedMode;
|
|
76
|
-
if (typeof mode === 'string') {
|
|
77
|
-
const supported = this.getSupportedCyclingModes();
|
|
78
|
-
const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
|
|
79
|
-
if (CyclingModeClass) {
|
|
80
|
-
this.cyclingMode = new CyclingModeClass(this, settings);
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
selectedMode = this.getDefaultCyclingMode();
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
selectedMode = mode;
|
|
87
|
-
}
|
|
88
|
-
this.cyclingMode = selectedMode;
|
|
89
|
-
this.cyclingMode.setSettings(settings);
|
|
90
|
-
}
|
|
91
|
-
sendInitCommands() {
|
|
92
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
return true;
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
53
|
start(props) {
|
|
97
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
98
55
|
this.startProps = props;
|
|
@@ -212,11 +169,9 @@ class Simulator extends adpater_1.ControllableDevice {
|
|
|
212
169
|
if (this.isBot) {
|
|
213
170
|
this.logger.logEvent(Object.assign({ message: 'Coach update', prevDist, prevTime }, data));
|
|
214
171
|
}
|
|
215
|
-
if (this.ignoreHrm)
|
|
216
|
-
delete data.heartrate;
|
|
217
172
|
this.emitData(data);
|
|
218
173
|
}
|
|
219
|
-
|
|
174
|
+
canEmitData() {
|
|
220
175
|
return true;
|
|
221
176
|
}
|
|
222
177
|
calculateDistance(speedKps, timeS) {
|
|
@@ -230,3 +185,7 @@ class Simulator extends adpater_1.ControllableDevice {
|
|
|
230
185
|
}
|
|
231
186
|
exports.Simulator = Simulator;
|
|
232
187
|
Simulator.NAME = 'Simulator';
|
|
188
|
+
Simulator.controllers = {
|
|
189
|
+
modes: [simulator_1.default],
|
|
190
|
+
default: simulator_1.default
|
|
191
|
+
};
|
package/lib/types/adapter.d.ts
CHANGED
|
@@ -1,41 +1,51 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import EventEmitter from "events";
|
|
3
|
-
import CyclingMode from "../modes/
|
|
3
|
+
import ICyclingMode, { CyclingMode } from "../modes/types";
|
|
4
4
|
import { IncyclistCapability } from "./capabilities";
|
|
5
|
-
import {
|
|
5
|
+
import { IncyclistAdapterData } from "./data";
|
|
6
6
|
import { DeviceProperties, DeviceSettings } from "./device";
|
|
7
7
|
import { User } from "./user";
|
|
8
|
-
|
|
9
|
-
export type
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
export type OnDeviceDataCallback = (data: IncyclistAdapterData) => void;
|
|
9
|
+
export type ControllerConfig = {
|
|
10
|
+
modes?: Array<typeof CyclingMode>;
|
|
11
|
+
default?: typeof CyclingMode;
|
|
12
|
+
};
|
|
13
|
+
export interface IBike {
|
|
14
|
+
setCyclingMode(mode: ICyclingMode | string, settings?: any, sendInitCommands?: boolean): void;
|
|
15
|
+
getSupportedCyclingModes(): Array<typeof CyclingMode>;
|
|
16
|
+
getCyclingMode(): ICyclingMode;
|
|
17
|
+
getDefaultCyclingMode(): ICyclingMode;
|
|
18
|
+
setBikeProps(props: DeviceProperties): void;
|
|
19
|
+
sendInitCommands(): Promise<boolean>;
|
|
20
|
+
sendUpdate(request: any): any;
|
|
21
|
+
setUser(user: User): void;
|
|
22
|
+
getWeight(): number;
|
|
23
|
+
getUser(): User;
|
|
24
|
+
}
|
|
25
|
+
export interface ISensor {
|
|
26
|
+
isControllable(): boolean;
|
|
16
27
|
getCapabilities(): IncyclistCapability[];
|
|
17
28
|
hasCapability(capability: IncyclistCapability): boolean;
|
|
18
29
|
addCapability(capability: IncyclistCapability): void;
|
|
19
|
-
|
|
30
|
+
getMaxUpdateFrequency(): any;
|
|
31
|
+
setMaxUpdateFrequency(value: number): any;
|
|
32
|
+
update(): any;
|
|
33
|
+
}
|
|
34
|
+
export interface IAdapter extends EventEmitter, IBike, ISensor {
|
|
20
35
|
getName(): string;
|
|
36
|
+
getID(): string;
|
|
21
37
|
getUniqueName(): string;
|
|
22
|
-
getSettings(): DeviceSettings;
|
|
23
38
|
getDisplayName(): string;
|
|
24
|
-
|
|
39
|
+
getSettings(): DeviceSettings;
|
|
40
|
+
isSame(adapter: IAdapter): boolean;
|
|
41
|
+
isEqual(settings: DeviceSettings): boolean;
|
|
42
|
+
getInterface(): string;
|
|
43
|
+
check(): Promise<boolean>;
|
|
25
44
|
start(props?: DeviceProperties): Promise<boolean>;
|
|
26
45
|
stop(): Promise<boolean>;
|
|
27
46
|
pause(): Promise<boolean>;
|
|
28
47
|
resume(): Promise<boolean>;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
setMaxUpdateFrequency(value: number): any;
|
|
48
|
+
connect(): Promise<boolean>;
|
|
49
|
+
close(): Promise<boolean>;
|
|
32
50
|
onData(callback: OnDeviceDataCallback): any;
|
|
33
51
|
}
|
|
34
|
-
export interface Bike {
|
|
35
|
-
setCyclingMode(mode: CyclingMode | string, settings?: any, sendInitCommands?: boolean): void;
|
|
36
|
-
getSupportedCyclingModes(): Array<any>;
|
|
37
|
-
getCyclingMode(): CyclingMode;
|
|
38
|
-
getDefaultCyclingMode(): CyclingMode;
|
|
39
|
-
setBikeProps(props: DeviceProperties): void;
|
|
40
|
-
setUser(user: User): void;
|
|
41
|
-
}
|
package/lib/types/command.d.ts
CHANGED
package/lib/types/command.js
CHANGED
package/lib/types/data.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type IncyclistAdapterData = {
|
|
2
2
|
speed?: number;
|
|
3
3
|
slope?: number;
|
|
4
4
|
power?: number;
|
|
@@ -10,3 +10,14 @@ export type DeviceData = {
|
|
|
10
10
|
deviceDistanceCounter?: number;
|
|
11
11
|
internalDistanceCounter?: number;
|
|
12
12
|
};
|
|
13
|
+
export type IncyclistBikeData = {
|
|
14
|
+
isPedalling?: boolean;
|
|
15
|
+
power: number;
|
|
16
|
+
pedalRpm: number;
|
|
17
|
+
speed: number;
|
|
18
|
+
heartrate?: number;
|
|
19
|
+
distanceInternal?: number;
|
|
20
|
+
time?: number;
|
|
21
|
+
gear?: number;
|
|
22
|
+
slope?: number;
|
|
23
|
+
};
|
package/lib/types/device.d.ts
CHANGED
|
@@ -1,30 +1,15 @@
|
|
|
1
1
|
import { EventLogger } from "gd-eventlog";
|
|
2
2
|
import { IncyclistInterface } from "./interface";
|
|
3
3
|
import { User } from "./user";
|
|
4
|
-
export declare
|
|
5
|
-
SERIAL
|
|
6
|
-
TCPIP
|
|
7
|
-
ANT
|
|
8
|
-
BLE
|
|
9
|
-
USB
|
|
10
|
-
SIMULATOR
|
|
11
|
-
}
|
|
4
|
+
export declare enum INTERFACE {
|
|
5
|
+
SERIAL = "serial",
|
|
6
|
+
TCPIP = "tcpip",
|
|
7
|
+
ANT = "ant",
|
|
8
|
+
BLE = "ble",
|
|
9
|
+
USB = "usb",
|
|
10
|
+
SIMULATOR = "simulator"
|
|
11
|
+
}
|
|
12
12
|
export type DeviceType = 'race' | 'mountain' | 'triathlon';
|
|
13
|
-
export type Device = {
|
|
14
|
-
getID(): string;
|
|
15
|
-
getName(): string;
|
|
16
|
-
getInterface(): string;
|
|
17
|
-
};
|
|
18
|
-
export type DaumBikeData = {
|
|
19
|
-
cadence: number;
|
|
20
|
-
speed: number;
|
|
21
|
-
power: number;
|
|
22
|
-
heartrate: number;
|
|
23
|
-
distanceInternal: number;
|
|
24
|
-
gear: number;
|
|
25
|
-
time: number;
|
|
26
|
-
slope?: number;
|
|
27
|
-
};
|
|
28
13
|
export type DeviceProperties = {
|
|
29
14
|
user?: User;
|
|
30
15
|
userWeight?: number;
|
package/lib/types/device.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.INTERFACE = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
var INTERFACE;
|
|
5
|
+
(function (INTERFACE) {
|
|
6
|
+
INTERFACE["SERIAL"] = "serial";
|
|
7
|
+
INTERFACE["TCPIP"] = "tcpip";
|
|
8
|
+
INTERFACE["ANT"] = "ant";
|
|
9
|
+
INTERFACE["BLE"] = "ble";
|
|
10
|
+
INTERFACE["USB"] = "usb";
|
|
11
|
+
INTERFACE["SIMULATOR"] = "simulator";
|
|
12
|
+
})(INTERFACE || (exports.INTERFACE = INTERFACE = {}));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./adapter"), exports);
|
|
18
|
+
__exportStar(require("./capabilities"), exports);
|
|
19
|
+
__exportStar(require("./data"), exports);
|
|
20
|
+
__exportStar(require("./device"), exports);
|
|
21
|
+
__exportStar(require("./interface"), exports);
|
|
22
|
+
__exportStar(require("./user"), exports);
|
package/lib/types/route.d.ts
CHANGED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export type Point = {
|
|
2
|
-
lat?: number;
|
|
3
|
-
lng?: number;
|
|
4
|
-
elevation?: number;
|
|
5
|
-
distance: number;
|
|
6
|
-
slope?: number;
|
|
7
|
-
};
|
|
8
|
-
export type Route = {
|
|
9
|
-
programId: number;
|
|
10
|
-
points: Point[];
|
|
11
|
-
type: string;
|
|
12
|
-
name?: string;
|
|
13
|
-
description?: string;
|
|
14
|
-
lapMode: boolean;
|
|
15
|
-
totalDistance: number;
|
|
16
|
-
minElevation?: number;
|
|
17
|
-
maxElevation?: number;
|
|
18
|
-
sampleRate?: number;
|
|
19
|
-
};
|
package/lib/types/route.js
CHANGED
package/lib/utils/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const sleep: (ms: any) => Promise<unknown>;
|
|
2
2
|
export declare const resolveNextTick: () => Promise<void>;
|
|
3
|
-
export declare function runWithRetries(fn: any, maxRetries: any, timeBetween: any): Promise<
|
|
3
|
+
export declare function runWithRetries(fn: any, maxRetries: any, timeBetween: any): Promise<any>;
|
|
4
4
|
export declare function floatVal(d?: number | string): number;
|
|
5
5
|
export declare function intVal(d?: number | string): number;
|
|
6
6
|
export declare function hexstr(arr: any, start?: any, len?: any): string;
|
|
@@ -13,4 +13,5 @@ export declare class Queue<T> {
|
|
|
13
13
|
dequeue(): T;
|
|
14
14
|
enqueue(value: T): void;
|
|
15
15
|
}
|
|
16
|
+
export declare function runWithTimeout(promise: Promise<any>, timeout: number): Promise<any>;
|
|
16
17
|
export declare function waitWithTimeout(promise: Promise<any>, timeout: number, onTimeout?: () => void): Promise<any>;
|
package/lib/utils/utils.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.waitWithTimeout = exports.Queue = exports.hexstr = exports.intVal = exports.floatVal = exports.runWithRetries = exports.resolveNextTick = exports.sleep = void 0;
|
|
12
|
+
exports.waitWithTimeout = exports.runWithTimeout = exports.Queue = exports.hexstr = exports.intVal = exports.floatVal = exports.runWithRetries = exports.resolveNextTick = exports.sleep = void 0;
|
|
13
13
|
const sleep = (ms) => {
|
|
14
14
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
15
15
|
};
|
|
@@ -116,7 +116,19 @@ class Queue {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
exports.Queue = Queue;
|
|
119
|
+
function runWithTimeout(promise, timeout) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
return yield doWaitWithTimeout(promise, timeout, true);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
exports.runWithTimeout = runWithTimeout;
|
|
119
125
|
function waitWithTimeout(promise, timeout, onTimeout) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
return yield doWaitWithTimeout(promise, timeout, false, onTimeout);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
exports.waitWithTimeout = waitWithTimeout;
|
|
131
|
+
function doWaitWithTimeout(promise, timeout, throwError, onTimeout) {
|
|
120
132
|
return __awaiter(this, void 0, void 0, function* () {
|
|
121
133
|
let to;
|
|
122
134
|
let hasTimedOut = false;
|
|
@@ -124,7 +136,7 @@ function waitWithTimeout(promise, timeout, onTimeout) {
|
|
|
124
136
|
return new Promise((resolve, reject) => {
|
|
125
137
|
to = setTimeout(() => {
|
|
126
138
|
hasTimedOut = true;
|
|
127
|
-
if (!onTimeout) {
|
|
139
|
+
if (!onTimeout || throwError) {
|
|
128
140
|
reject(new Error('Timeout'));
|
|
129
141
|
}
|
|
130
142
|
else {
|
|
@@ -144,11 +156,17 @@ function waitWithTimeout(promise, timeout, onTimeout) {
|
|
|
144
156
|
res = yield Promise.race([promise, toPromise(timeout)]);
|
|
145
157
|
}
|
|
146
158
|
catch (err) {
|
|
147
|
-
if (err.message === 'Timeout' && hasTimedOut)
|
|
159
|
+
if (err.message === 'Timeout' && hasTimedOut) {
|
|
148
160
|
throw err;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
if (throwError) {
|
|
164
|
+
clearTimeout(to);
|
|
165
|
+
throw err;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
149
168
|
}
|
|
150
169
|
clearTimeout(to);
|
|
151
170
|
return res;
|
|
152
171
|
});
|
|
153
172
|
}
|
|
154
|
-
exports.waitWithTimeout = waitWithTimeout;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "incyclist-devices",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@serialport/bindings-interface": "^1.2.2",
|
|
6
6
|
"@serialport/parser-byte-length": "^9.0.1",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"scripts": {
|
|
28
28
|
"lint": "eslint . --ext .ts",
|
|
29
29
|
"build": "tsc",
|
|
30
|
-
"test": "jest --coverage",
|
|
31
|
-
"test:ci": "jest --coverage --forceExit",
|
|
30
|
+
"test": "npx jest --coverage",
|
|
31
|
+
"test:ci": "npx jest --coverage --forceExit",
|
|
32
32
|
"dev": "tsc --watch",
|
|
33
33
|
"postversion": "git push && git push --tags"
|
|
34
34
|
},
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ControllableDeviceAdapter } from "../..";
|
|
2
|
-
import FtmsCyclingMode from "../../modes/ble-st-mode";
|
|
3
|
-
import { UpdateRequest } from "../../modes/cycling-mode";
|
|
4
|
-
export default class AntAdvSimCyclingMode extends FtmsCyclingMode {
|
|
5
|
-
constructor(adapter: ControllableDeviceAdapter, props?: any);
|
|
6
|
-
getName(): string;
|
|
7
|
-
getDescription(): string;
|
|
8
|
-
sendBikeUpdate(request: UpdateRequest): UpdateRequest;
|
|
9
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const ble_st_mode_1 = __importDefault(require("../../modes/ble-st-mode"));
|
|
7
|
-
const MAX_DEVIATION = 10;
|
|
8
|
-
class AntAdvSimCyclingMode extends ble_st_mode_1.default {
|
|
9
|
-
constructor(adapter, props) {
|
|
10
|
-
super(adapter, props);
|
|
11
|
-
this.initLogger('AntAdvSimMode');
|
|
12
|
-
}
|
|
13
|
-
getName() {
|
|
14
|
-
return 'Advanced Smart Trainer';
|
|
15
|
-
}
|
|
16
|
-
getDescription() {
|
|
17
|
-
return 'Sends Slope to device. Respects Limits (from workout or settings). Calculates speed based on power and slope. ';
|
|
18
|
-
}
|
|
19
|
-
sendBikeUpdate(request) {
|
|
20
|
-
const getData = () => {
|
|
21
|
-
if (!this.data)
|
|
22
|
-
return {};
|
|
23
|
-
const { gear, pedalRpm, slope, power, speed } = this.data;
|
|
24
|
-
return { gear, pedalRpm, slope, power, speed };
|
|
25
|
-
};
|
|
26
|
-
this.logger.logEvent({ message: "processing update request", request, prev: this.prevRequest, data: getData() });
|
|
27
|
-
let newRequest = {};
|
|
28
|
-
if (request.slope === undefined && request.targetPower === undefined && request.refresh && this.prevRequest) {
|
|
29
|
-
return this.prevRequest;
|
|
30
|
-
}
|
|
31
|
-
if (request.slope !== undefined) {
|
|
32
|
-
newRequest.slope = parseFloat(request.slope.toFixed(1));
|
|
33
|
-
this.data.slope = newRequest.slope;
|
|
34
|
-
}
|
|
35
|
-
if (this.data && this.data.power) {
|
|
36
|
-
const { minPower, maxPower } = request;
|
|
37
|
-
let { targetPower } = request;
|
|
38
|
-
if (minPower !== undefined && maxPower !== undefined && minPower === maxPower)
|
|
39
|
-
targetPower = maxPower;
|
|
40
|
-
if (targetPower !== undefined && Math.abs(this.data.power - targetPower) > MAX_DEVIATION)
|
|
41
|
-
newRequest.targetPower = targetPower;
|
|
42
|
-
else if (minPower !== undefined && this.data.power < minPower)
|
|
43
|
-
newRequest.targetPower = minPower;
|
|
44
|
-
else if (request.maxPower !== undefined && this.data.power > request.maxPower)
|
|
45
|
-
newRequest.targetPower = maxPower;
|
|
46
|
-
}
|
|
47
|
-
this.prevRequest = JSON.parse(JSON.stringify(newRequest));
|
|
48
|
-
return newRequest;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.default = AntAdvSimCyclingMode;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ControllableDeviceAdapter } from "../..";
|
|
2
|
-
import BleERGCyclingMode from "../../modes/ble-erg-mode";
|
|
3
|
-
export default class AntFeERGCyclingMode extends BleERGCyclingMode {
|
|
4
|
-
static isERG: boolean;
|
|
5
|
-
constructor(adapter: ControllableDeviceAdapter, props?: any);
|
|
6
|
-
}
|