incyclist-devices 2.1.0 → 2.1.2
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 -15
- package/lib/antv2/adapter.d.ts +15 -15
- package/lib/antv2/adapter.js +67 -21
- package/lib/antv2/ant-interface.d.ts +3 -11
- package/lib/antv2/ant-interface.js +1 -1
- package/lib/antv2/base/adapter.d.ts +69 -0
- package/lib/antv2/base/adapter.js +439 -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/base/interface.d.ts +46 -0
- package/lib/antv2/base/interface.js +337 -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 +73 -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 +21 -30
- package/lib/antv2/fe/adapter.js +139 -251
- package/lib/antv2/hr/adapter.d.ts +6 -15
- 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 +5 -3
- package/lib/antv2/pwr/adapter.d.ts +9 -33
- package/lib/antv2/pwr/adapter.js +19 -140
- package/lib/antv2/types.d.ts +32 -4
- package/lib/base/adpater.d.ts +39 -60
- package/lib/base/adpater.js +139 -161
- package/lib/base/consts.d.ts +4 -0
- package/lib/base/consts.js +9 -0
- package/lib/ble/adapter-factory.d.ts +10 -11
- package/lib/ble/base/adapter.d.ts +7 -14
- package/lib/ble/base/adapter.js +2 -36
- package/lib/ble/ble-interface.d.ts +5 -7
- package/lib/ble/cp/adapter.d.ts +6 -8
- package/lib/ble/cp/adapter.js +8 -27
- package/lib/ble/elite/adapter.d.ts +7 -8
- package/lib/ble/elite/adapter.js +5 -25
- package/lib/ble/fm/adapter.d.ts +6 -7
- package/lib/ble/fm/adapter.js +13 -34
- package/lib/ble/hr/adapter.d.ts +5 -8
- package/lib/ble/hr/adapter.js +2 -2
- package/lib/ble/peripheral-cache.d.ts +2 -3
- 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 +5 -6
- package/lib/index.js +4 -9
- package/lib/interfaces.d.ts +1 -1
- package/lib/modes/ant-fe-adv-st-mode.d.ts +1 -1
- package/lib/modes/antble-erg.d.ts +1 -1
- package/lib/modes/antble-smarttrainer.d.ts +2 -2
- package/lib/modes/base.d.ts +5 -5
- package/lib/modes/daum-classic-standard.d.ts +3 -2
- package/lib/modes/daum-erg.d.ts +3 -3
- package/lib/modes/daum-premium-standard.d.ts +3 -2
- package/lib/modes/daum-smarttrainer.d.ts +3 -2
- package/lib/modes/kettler-erg.d.ts +3 -3
- package/lib/modes/power-base.d.ts +3 -3
- package/lib/modes/power-base.js +2 -2
- package/lib/modes/power-meter.d.ts +3 -2
- package/lib/modes/simulator.d.ts +2 -1
- package/lib/modes/types.d.ts +2 -13
- package/lib/serial/SinglePathScanner.d.ts +17 -0
- package/lib/serial/SinglePathScanner.js +87 -0
- package/lib/serial/adapter-factory.d.ts +6 -6
- package/lib/serial/adapter.d.ts +6 -11
- 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 +12 -24
- package/lib/serial/daum/DaumAdapter.js +40 -59
- 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 +8 -20
- package/lib/serial/daum/classic/adapter.js +28 -58
- package/lib/serial/daum/classic/comms.d.ts +4 -6
- package/lib/serial/daum/classic/comms.js +2 -2
- 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.js +5 -4
- 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 -19
- package/lib/serial/daum/consts.js +0 -22
- package/lib/serial/daum/premium/adapter.d.ts +8 -11
- package/lib/serial/daum/premium/adapter.js +27 -53
- package/lib/serial/daum/premium/comms.d.ts +4 -7
- package/lib/serial/daum/premium/comms.js +23 -22
- package/lib/serial/daum/premium/mock.d.ts +1 -1
- package/lib/serial/daum/premium/mock.js +2 -2
- 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 +4 -1
- package/lib/serial/daum/types.js +9 -1
- 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 -18
- package/lib/serial/kettler/ergo-racer/adapter.js +9 -21
- 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 +3 -76
- 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 +10 -13
- package/lib/simulator/Simulator.js +11 -23
- package/lib/types/Command.d.ts +8 -0
- package/lib/types/Command.js +2 -0
- package/lib/types/adapter.d.ts +22 -33
- package/lib/types/adapter.js +0 -68
- 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 -0
- package/lib/utils/utils.js +39 -4
- package/package.json +1 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.SinglePathScanner = void 0;
|
|
16
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
17
|
+
const types_1 = require("../types");
|
|
18
|
+
const adapter_factory_1 = __importDefault(require("../factories/adapter-factory"));
|
|
19
|
+
const utils_1 = require("../../utils/utils");
|
|
20
|
+
class SinglePathScanner {
|
|
21
|
+
constructor(path, serial, props) {
|
|
22
|
+
this.path = path;
|
|
23
|
+
this.serial = serial;
|
|
24
|
+
this.result = undefined;
|
|
25
|
+
this.isScanning = false;
|
|
26
|
+
this.isFound = false;
|
|
27
|
+
this.props = props;
|
|
28
|
+
this.logger = props.logger || new gd_eventlog_1.EventLogger('SerialScanner');
|
|
29
|
+
}
|
|
30
|
+
logEvent(event) {
|
|
31
|
+
if (this.logger) {
|
|
32
|
+
this.logger.logEvent(event);
|
|
33
|
+
}
|
|
34
|
+
const w = global.window;
|
|
35
|
+
if ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || process.env.BLE_DEBUG || process.env.ANT_DEBUG || process.env.SERIAL_DEBUG) {
|
|
36
|
+
console.log('~~~ SerialScanner', event);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
onStopRequest(resolve) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
this.logEvent({ message: 'stopping scan', path: this.path });
|
|
42
|
+
if (!this.isFound)
|
|
43
|
+
yield this.serial.closePort(this.path);
|
|
44
|
+
this.isScanning = false;
|
|
45
|
+
resolve(this.result);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
scan() {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
if (this.isScanning)
|
|
51
|
+
return;
|
|
52
|
+
this.isScanning = true;
|
|
53
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
this.logEvent({ message: 'starting scan', path: this.path, interface: this.serial.getName() });
|
|
55
|
+
this.serial.scanEvents.on('timeout', () => this.onStopRequest(resolve));
|
|
56
|
+
this.serial.scanEvents.on('stop', () => this.onStopRequest(resolve));
|
|
57
|
+
let found = false;
|
|
58
|
+
while (!found && this.isScanning) {
|
|
59
|
+
try {
|
|
60
|
+
const { protocol } = this.props;
|
|
61
|
+
let host, port;
|
|
62
|
+
if (this.serial.getName() === types_1.SerialInterfaceType.TCPIP) {
|
|
63
|
+
[host, port] = this.path.split(':');
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
port = this.path;
|
|
67
|
+
}
|
|
68
|
+
const adapterSettings = { interface: this.serial.getName(), host, port, protocol };
|
|
69
|
+
const adapter = adapter_factory_1.default.getInstance().createInstance(adapterSettings);
|
|
70
|
+
found = yield (adapter === null || adapter === void 0 ? void 0 : adapter.check());
|
|
71
|
+
if (found) {
|
|
72
|
+
this.isFound = true;
|
|
73
|
+
const name = adapter.getName();
|
|
74
|
+
resolve(Object.assign(Object.assign({}, adapterSettings), { name }));
|
|
75
|
+
}
|
|
76
|
+
yield (0, utils_1.sleep)(100);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
this.logEvent({ message: 'error', fn: 'scan()', error: err.message || err, stack: err.stack });
|
|
80
|
+
yield (0, utils_1.sleep)(100);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.SinglePathScanner = SinglePathScanner;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BindingInterface } from '@serialport/bindings-interface';
|
|
2
|
+
import { InterfaceBinding, InterfaceImplementation } from '../types';
|
|
3
|
+
export default class SerialPortProvider {
|
|
4
|
+
static _instance: SerialPortProvider;
|
|
5
|
+
interfaces: InterfaceBinding[];
|
|
6
|
+
implemenations: InterfaceImplementation[];
|
|
7
|
+
static getInstance(): SerialPortProvider;
|
|
8
|
+
constructor();
|
|
9
|
+
setBinding(ifaceName: string, binding: BindingInterface): void;
|
|
10
|
+
getBinding(ifaceName: string): BindingInterface;
|
|
11
|
+
getSerialPort(ifaceName: string, props: any): any;
|
|
12
|
+
list(ifaceName: string): Promise<any>;
|
|
13
|
+
setLegacyClass(ifaceName: string, Serialport: any): void;
|
|
14
|
+
getLegacyInfo(ifaceName: string): InterfaceImplementation;
|
|
15
|
+
getLegacyClass(ifaceName: string): any;
|
|
16
|
+
}
|
|
17
|
+
export declare const useSerialPortProvider: () => SerialPortProvider;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.useSerialPortProvider = void 0;
|
|
13
|
+
const { SerialPortStream } = require('@serialport/stream');
|
|
14
|
+
const DEFAULT_BAUD_RATE = 9600;
|
|
15
|
+
class SerialPortProvider {
|
|
16
|
+
static getInstance() {
|
|
17
|
+
if (!SerialPortProvider._instance)
|
|
18
|
+
SerialPortProvider._instance = new SerialPortProvider();
|
|
19
|
+
return SerialPortProvider._instance;
|
|
20
|
+
}
|
|
21
|
+
constructor() {
|
|
22
|
+
this.interfaces = [];
|
|
23
|
+
this.implemenations = [];
|
|
24
|
+
}
|
|
25
|
+
setBinding(ifaceName, binding) {
|
|
26
|
+
const existing = this.interfaces.find(ib => ib.name === ifaceName);
|
|
27
|
+
if (existing)
|
|
28
|
+
existing.binding = binding;
|
|
29
|
+
else
|
|
30
|
+
this.interfaces.push({ name: ifaceName, binding });
|
|
31
|
+
}
|
|
32
|
+
getBinding(ifaceName) {
|
|
33
|
+
const existing = this.interfaces.find(ib => ib.name === ifaceName);
|
|
34
|
+
if (existing)
|
|
35
|
+
return existing.binding;
|
|
36
|
+
}
|
|
37
|
+
getSerialPort(ifaceName, props) {
|
|
38
|
+
const binding = this.getBinding(ifaceName);
|
|
39
|
+
if (binding) {
|
|
40
|
+
props.binding = binding;
|
|
41
|
+
if (props.autoOpen === undefined)
|
|
42
|
+
props.autoOpen = false;
|
|
43
|
+
if (!props.baudRate)
|
|
44
|
+
props.baudRate = DEFAULT_BAUD_RATE;
|
|
45
|
+
return new SerialPortStream(props);
|
|
46
|
+
}
|
|
47
|
+
const legacy = this.getLegacyInfo(ifaceName);
|
|
48
|
+
if (legacy && legacy.Serialport) {
|
|
49
|
+
const portName = props.path;
|
|
50
|
+
if (props.autoOpen === undefined)
|
|
51
|
+
props.autoOpen = false;
|
|
52
|
+
const settings = Object.assign({}, props);
|
|
53
|
+
delete settings.path;
|
|
54
|
+
return new legacy.Serialport(portName, settings);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
list(ifaceName) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const Binding = this.getBinding(ifaceName);
|
|
60
|
+
if (Binding)
|
|
61
|
+
return yield Binding.list();
|
|
62
|
+
const legacy = this.getLegacyInfo(ifaceName);
|
|
63
|
+
if (legacy && legacy.Serialport && legacy.Serialport.list) {
|
|
64
|
+
return yield legacy.Serialport.list();
|
|
65
|
+
}
|
|
66
|
+
return [];
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
setLegacyClass(ifaceName, Serialport) {
|
|
70
|
+
const existing = this.getLegacyInfo(ifaceName);
|
|
71
|
+
if (existing)
|
|
72
|
+
existing.Serialport = Serialport;
|
|
73
|
+
else
|
|
74
|
+
this.implemenations.push({ name: ifaceName, Serialport });
|
|
75
|
+
}
|
|
76
|
+
getLegacyInfo(ifaceName) {
|
|
77
|
+
return this.implemenations.find(ib => ib.name === ifaceName);
|
|
78
|
+
}
|
|
79
|
+
getLegacyClass(ifaceName) {
|
|
80
|
+
const existing = this.implemenations.find(ib => ib.name === ifaceName);
|
|
81
|
+
if (existing)
|
|
82
|
+
return existing.Serialport;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.default = SerialPortProvider;
|
|
86
|
+
const useSerialPortProvider = () => SerialPortProvider.getInstance();
|
|
87
|
+
exports.useSerialPortProvider = useSerialPortProvider;
|
package/lib/serial/comms.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventLogger } from "gd-eventlog";
|
|
3
|
-
import SerialInterface from "./serial-interface";
|
|
4
|
-
import { SerialCommProps } from "./
|
|
3
|
+
import SerialInterface from "./base/serial-interface";
|
|
4
|
+
import { SerialCommProps } from "./types";
|
|
5
5
|
import { SerialPortStream } from "@serialport/stream";
|
|
6
6
|
import { Queue } from "../utils/utils";
|
|
7
7
|
export type ConnectionState = 'Connecting' | 'Connected' | 'Disconnected' | 'Disconnecting';
|
|
@@ -1,24 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import SerialInterface from '../serial-interface';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export interface IDaumAdapter {
|
|
10
|
-
getCurrentBikeData(): Promise<IncyclistBikeData>;
|
|
11
|
-
}
|
|
12
|
-
export declare class DaumControl<P extends DeviceProperties> extends ControllableDevice<P> {
|
|
13
|
-
getSupportedCyclingModes(): Array<typeof CyclingMode>;
|
|
14
|
-
getDefaultCyclingMode(): ICyclingMode;
|
|
15
|
-
sendInitCommands(): Promise<boolean>;
|
|
16
|
-
}
|
|
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;
|
|
1
|
+
import { IncyclistAdapterData, ControllerConfig, IAdapter, DeviceProperties, IncyclistBikeData } from '../../types';
|
|
2
|
+
import { SerialDeviceSettings } from "../types";
|
|
3
|
+
import { DaumSerialComms } from './types';
|
|
4
|
+
import { SerialIncyclistDevice } from '../base/adapter';
|
|
5
|
+
import SerialInterface from '../base/serial-interface';
|
|
6
|
+
export default class DaumAdapter<S extends SerialDeviceSettings, P extends DeviceProperties, C extends DaumSerialComms> extends SerialIncyclistDevice<P> {
|
|
7
|
+
protected static controllers: ControllerConfig;
|
|
8
|
+
comms: C;
|
|
19
9
|
distanceInternal: number;
|
|
20
|
-
|
|
21
|
-
deviceData: DeviceData;
|
|
10
|
+
deviceData: IncyclistBikeData;
|
|
22
11
|
requests: Array<any>;
|
|
23
12
|
iv: any;
|
|
24
13
|
tsPrevData: number;
|
|
@@ -32,9 +21,9 @@ export default class DaumAdapter<DC extends DaumControl<P>, S extends SerialDevi
|
|
|
32
21
|
getSerialInterface(): SerialInterface;
|
|
33
22
|
sendInitCommands(): Promise<boolean>;
|
|
34
23
|
getCurrentBikeData(): Promise<IncyclistBikeData>;
|
|
35
|
-
|
|
24
|
+
getComms(): C;
|
|
36
25
|
isEqual(settings: SerialDeviceSettings): boolean;
|
|
37
|
-
isSame(device:
|
|
26
|
+
isSame(device: IAdapter): boolean;
|
|
38
27
|
isStopped(): boolean;
|
|
39
28
|
initData(): void;
|
|
40
29
|
pause(): Promise<boolean>;
|
|
@@ -53,13 +42,12 @@ export default class DaumAdapter<DC extends DaumControl<P>, S extends SerialDevi
|
|
|
53
42
|
reconnect(): Promise<boolean>;
|
|
54
43
|
logEvent(event: any): void;
|
|
55
44
|
stop(): Promise<boolean>;
|
|
56
|
-
canSendUpdate(): boolean;
|
|
57
45
|
sendUpdate(request: any): Promise<unknown>;
|
|
58
46
|
update(): Promise<void>;
|
|
59
47
|
sendRequests(): Promise<void>;
|
|
60
48
|
bikeSync(): Promise<void>;
|
|
61
49
|
updateData(bikeData: IncyclistBikeData): IncyclistBikeData;
|
|
62
|
-
transformData(cyclingData: IncyclistBikeData):
|
|
50
|
+
transformData(cyclingData: IncyclistBikeData): IncyclistAdapterData;
|
|
63
51
|
sendRequest(request: any): Promise<any>;
|
|
64
52
|
refreshRequests(): void;
|
|
65
53
|
processClientRequest(request: any): Promise<unknown>;
|
|
@@ -12,28 +12,12 @@ 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.DaumControl = void 0;
|
|
16
15
|
const daum_erg_1 = __importDefault(require("../../modes/daum-erg"));
|
|
16
|
+
const utils_1 = require("../../utils/utils");
|
|
17
|
+
const types_1 = require("../../types");
|
|
18
|
+
const adapter_1 = require("../base/adapter");
|
|
17
19
|
const daum_smarttrainer_1 = __importDefault(require("../../modes/daum-smarttrainer"));
|
|
18
20
|
const daum_power_1 = __importDefault(require("../../modes/daum-power"));
|
|
19
|
-
const utils_1 = require("../../utils/utils");
|
|
20
|
-
const adapter_1 = require("../adapter");
|
|
21
|
-
const capabilities_1 = require("../../types/capabilities");
|
|
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
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.DaumControl = DaumControl;
|
|
37
21
|
class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
38
22
|
constructor(settings, props) {
|
|
39
23
|
super(settings, props);
|
|
@@ -42,7 +26,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
42
26
|
this.requestBusy = false;
|
|
43
27
|
this.updateBusy = false;
|
|
44
28
|
this.iv = undefined;
|
|
45
|
-
this.
|
|
29
|
+
this.deviceData = {
|
|
46
30
|
isPedalling: false,
|
|
47
31
|
time: 0,
|
|
48
32
|
power: 0,
|
|
@@ -51,27 +35,25 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
51
35
|
distanceInternal: 0,
|
|
52
36
|
heartrate: 0
|
|
53
37
|
};
|
|
54
|
-
this.deviceData = {};
|
|
55
38
|
this.capabilities = [
|
|
56
|
-
|
|
57
|
-
|
|
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
|
|
58
41
|
];
|
|
59
|
-
this.setControl(new DaumControl(this, props));
|
|
60
42
|
}
|
|
61
43
|
getPort() {
|
|
62
44
|
var _a;
|
|
63
|
-
return (_a = this.
|
|
45
|
+
return (_a = this.comms) === null || _a === void 0 ? void 0 : _a.getPort();
|
|
64
46
|
}
|
|
65
47
|
getSerialInterface() {
|
|
66
48
|
var _a;
|
|
67
|
-
return (_a = this.
|
|
49
|
+
return (_a = this.comms) === null || _a === void 0 ? void 0 : _a.serial;
|
|
68
50
|
}
|
|
69
51
|
sendInitCommands() {
|
|
70
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
53
|
if (this.started && !this.stopped) {
|
|
72
54
|
try {
|
|
73
55
|
if (this.getCyclingMode() instanceof daum_erg_1.default) {
|
|
74
|
-
const power = this.
|
|
56
|
+
const power = this.data.power;
|
|
75
57
|
const request = power ? { targetPower: power } : this.getCyclingMode().getBikeInitRequest();
|
|
76
58
|
yield this.sendUpdate(request);
|
|
77
59
|
return true;
|
|
@@ -87,8 +69,8 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
87
69
|
getCurrentBikeData() {
|
|
88
70
|
throw new Error('Method not implemented.');
|
|
89
71
|
}
|
|
90
|
-
|
|
91
|
-
return this.
|
|
72
|
+
getComms() {
|
|
73
|
+
return this.comms;
|
|
92
74
|
}
|
|
93
75
|
isEqual(settings) {
|
|
94
76
|
const as = this.settings;
|
|
@@ -111,7 +93,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
111
93
|
this.distanceInternal = undefined;
|
|
112
94
|
this.paused = false;
|
|
113
95
|
this.stopped = false;
|
|
114
|
-
this.
|
|
96
|
+
this.deviceData = {
|
|
115
97
|
isPedalling: false,
|
|
116
98
|
time: 0,
|
|
117
99
|
power: 0,
|
|
@@ -120,7 +102,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
120
102
|
distanceInternal: 0,
|
|
121
103
|
heartrate: 0
|
|
122
104
|
};
|
|
123
|
-
this.
|
|
105
|
+
this.data = {};
|
|
124
106
|
this.requests = [];
|
|
125
107
|
const name = this.getCyclingMode().getName();
|
|
126
108
|
const settings = this.getCyclingMode().getSettings();
|
|
@@ -132,7 +114,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
132
114
|
});
|
|
133
115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
134
116
|
const paused = yield _super.pause.call(this);
|
|
135
|
-
this.
|
|
117
|
+
this.comms.pauseLogging();
|
|
136
118
|
return paused;
|
|
137
119
|
});
|
|
138
120
|
}
|
|
@@ -142,7 +124,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
142
124
|
});
|
|
143
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
144
126
|
const resumed = yield _super.resume.call(this);
|
|
145
|
-
this.
|
|
127
|
+
this.comms.resumeLogging();
|
|
146
128
|
return resumed;
|
|
147
129
|
});
|
|
148
130
|
}
|
|
@@ -249,7 +231,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
249
231
|
}, this.pullFrequency);
|
|
250
232
|
const ivUpdate = setInterval(() => {
|
|
251
233
|
try {
|
|
252
|
-
this.emitData(this.
|
|
234
|
+
this.emitData(this.data);
|
|
253
235
|
this.refreshRequests();
|
|
254
236
|
}
|
|
255
237
|
catch (_a) { }
|
|
@@ -269,33 +251,33 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
269
251
|
}
|
|
270
252
|
connect() {
|
|
271
253
|
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
-
if (!this.
|
|
254
|
+
if (!this.comms)
|
|
273
255
|
return false;
|
|
274
|
-
if (this.
|
|
256
|
+
if (this.comms.isConnected())
|
|
275
257
|
return true;
|
|
276
258
|
try {
|
|
277
|
-
const connected = yield this.
|
|
259
|
+
const connected = yield this.comms.connect();
|
|
278
260
|
return connected;
|
|
279
261
|
}
|
|
280
262
|
catch (err) {
|
|
281
|
-
yield this.
|
|
263
|
+
yield this.comms.close();
|
|
282
264
|
return false;
|
|
283
265
|
}
|
|
284
266
|
});
|
|
285
267
|
}
|
|
286
268
|
close() {
|
|
287
269
|
return __awaiter(this, void 0, void 0, function* () {
|
|
288
|
-
if (!this.
|
|
270
|
+
if (!this.comms)
|
|
289
271
|
return true;
|
|
290
|
-
if (!this.
|
|
272
|
+
if (!this.comms.isConnected())
|
|
291
273
|
return true;
|
|
292
|
-
return yield this.
|
|
274
|
+
return yield this.comms.close();
|
|
293
275
|
});
|
|
294
276
|
}
|
|
295
277
|
verifyConnection() {
|
|
296
278
|
return __awaiter(this, void 0, void 0, function* () {
|
|
297
|
-
if (!this.
|
|
298
|
-
const connected = yield this.
|
|
279
|
+
if (!this.comms.isConnected()) {
|
|
280
|
+
const connected = yield this.comms.connect();
|
|
299
281
|
if (!connected)
|
|
300
282
|
throw new Error('not connected');
|
|
301
283
|
}
|
|
@@ -304,8 +286,8 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
304
286
|
reconnect() {
|
|
305
287
|
return __awaiter(this, void 0, void 0, function* () {
|
|
306
288
|
try {
|
|
307
|
-
yield this.
|
|
308
|
-
const connected = yield this.
|
|
289
|
+
yield this.comms.close();
|
|
290
|
+
const connected = yield this.comms.connect();
|
|
309
291
|
return connected;
|
|
310
292
|
}
|
|
311
293
|
catch (err) {
|
|
@@ -331,7 +313,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
331
313
|
this.resume();
|
|
332
314
|
try {
|
|
333
315
|
this.stopUpdatePull();
|
|
334
|
-
yield this.
|
|
316
|
+
yield this.comms.close();
|
|
335
317
|
this.logEvent({ message: 'stop request completed' });
|
|
336
318
|
this.stopped = true;
|
|
337
319
|
}
|
|
@@ -342,11 +324,6 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
342
324
|
return this.stopped;
|
|
343
325
|
});
|
|
344
326
|
}
|
|
345
|
-
canSendUpdate() {
|
|
346
|
-
if (this.paused || this.stopped)
|
|
347
|
-
return false;
|
|
348
|
-
return super.canSendUpdate();
|
|
349
|
-
}
|
|
350
327
|
sendUpdate(request) {
|
|
351
328
|
return __awaiter(this, void 0, void 0, function* () {
|
|
352
329
|
if (this.paused || this.stopped)
|
|
@@ -357,7 +334,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
357
334
|
}
|
|
358
335
|
update() {
|
|
359
336
|
return __awaiter(this, void 0, void 0, function* () {
|
|
360
|
-
if (!this.
|
|
337
|
+
if (!this.canEmitData() || this.updateBusy)
|
|
361
338
|
return;
|
|
362
339
|
this.updateBusy = true;
|
|
363
340
|
try {
|
|
@@ -370,7 +347,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
370
347
|
catch (err) {
|
|
371
348
|
try {
|
|
372
349
|
this.logEvent({ message: 'bike update error', error: err.message, stack: err.stack });
|
|
373
|
-
const incyclistData = this.updateData(this.
|
|
350
|
+
const incyclistData = this.updateData(this.deviceData);
|
|
374
351
|
this.transformData(incyclistData);
|
|
375
352
|
}
|
|
376
353
|
catch (_a) { }
|
|
@@ -425,8 +402,8 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
425
402
|
data.time = bikeData.time;
|
|
426
403
|
if (bikeData.slope)
|
|
427
404
|
data.slope = bikeData.slope;
|
|
428
|
-
this.
|
|
429
|
-
return this.
|
|
405
|
+
this.deviceData = this.getCyclingMode().updateData(data);
|
|
406
|
+
return this.deviceData;
|
|
430
407
|
}
|
|
431
408
|
transformData(cyclingData) {
|
|
432
409
|
let distance = 0;
|
|
@@ -446,7 +423,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
446
423
|
deviceTime: cyclingData.time,
|
|
447
424
|
deviceDistanceCounter: cyclingData.distanceInternal
|
|
448
425
|
};
|
|
449
|
-
this.
|
|
426
|
+
this.data = data;
|
|
450
427
|
return data;
|
|
451
428
|
}
|
|
452
429
|
sendRequest(request) {
|
|
@@ -454,7 +431,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
454
431
|
this.requestBusy = true;
|
|
455
432
|
try {
|
|
456
433
|
this.logEvent({ message: 'sendRequest', request });
|
|
457
|
-
const bike = this.
|
|
434
|
+
const bike = this.getComms();
|
|
458
435
|
const isReset = (!request || request.reset || Object.keys(request).length === 0);
|
|
459
436
|
if (isReset) {
|
|
460
437
|
this.requestBusy = false;
|
|
@@ -479,7 +456,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
479
456
|
refreshRequests() {
|
|
480
457
|
if (this.isPaused() || this.isStopped())
|
|
481
458
|
return;
|
|
482
|
-
if (!this.
|
|
459
|
+
if (!this.deviceData.isPedalling || this.deviceData.pedalRpm === 0)
|
|
483
460
|
return;
|
|
484
461
|
let bikeRequest = this.getCyclingMode().sendBikeUpdate({ refresh: true }) || {};
|
|
485
462
|
const prev = this.requests[this.requests.length - 1] || {};
|
|
@@ -490,7 +467,7 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
490
467
|
}
|
|
491
468
|
processClientRequest(request) {
|
|
492
469
|
if (request.slope !== undefined) {
|
|
493
|
-
this.
|
|
470
|
+
this.deviceData.slope = request.slope;
|
|
494
471
|
}
|
|
495
472
|
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
496
473
|
let bikeRequest = this.getCyclingMode().sendBikeUpdate(request);
|
|
@@ -505,4 +482,8 @@ class DaumAdapter extends adapter_1.SerialIncyclistDevice {
|
|
|
505
482
|
});
|
|
506
483
|
}
|
|
507
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
|
+
};
|
|
508
489
|
exports.default = DaumAdapter;
|
|
@@ -1,32 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { SerialCommProps } from '../../comm';
|
|
1
|
+
import DaumAdapter from '../DaumAdapter';
|
|
2
|
+
import { DaumClassicProperties } from './types';
|
|
3
|
+
import { SerialDeviceSettings, SerialCommProps } from "../../types";
|
|
4
|
+
import { IncyclistBikeData, ControllerConfig } from "../../../types";
|
|
6
5
|
import Daum8008 from './comms';
|
|
7
|
-
export
|
|
8
|
-
gear?: number;
|
|
9
|
-
}
|
|
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> {
|
|
6
|
+
export default class DaumClassicAdapter extends DaumAdapter<SerialDeviceSettings, DaumClassicProperties, Daum8008> {
|
|
20
7
|
static NAME: string;
|
|
8
|
+
protected static controllers: ControllerConfig;
|
|
21
9
|
protected name: string;
|
|
22
10
|
protected id: string;
|
|
23
|
-
constructor(settings: SerialDeviceSettings, props?:
|
|
11
|
+
constructor(settings: SerialDeviceSettings, props?: DaumClassicProperties);
|
|
24
12
|
getBikeProps(props: SerialDeviceSettings): SerialCommProps;
|
|
25
13
|
getName(): string;
|
|
26
14
|
setName(name: string): void;
|
|
27
15
|
getProtocolName(): string;
|
|
28
16
|
performCheck(): Promise<boolean>;
|
|
29
|
-
performStart(props?:
|
|
17
|
+
performStart(props?: DaumClassicProperties, isRelaunch?: boolean): Promise<boolean>;
|
|
30
18
|
getCurrentBikeData(): Promise<IncyclistBikeData>;
|
|
31
19
|
getDeviceInfo(): Promise<any>;
|
|
32
20
|
}
|