incyclist-devices 2.1.0 → 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 -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 +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 +24 -29
- package/lib/antv2/fe/adapter.js +208 -225
- 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 +4 -2
- package/lib/antv2/pwr/adapter.d.ts +9 -33
- package/lib/antv2/pwr/adapter.js +19 -140
- package/lib/antv2/types.d.ts +23 -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 +4 -3
- 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 +1 -0
- package/lib/utils/utils.js +22 -4
- package/package.json +1 -1
|
@@ -12,86 +12,13 @@ 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.SinglePathScanner = exports.SerialInterfaceType = void 0;
|
|
16
15
|
const events_1 = __importDefault(require("events"));
|
|
17
16
|
const serialport_1 = __importDefault(require("./serialport"));
|
|
18
17
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
19
18
|
const utils_1 = require("../utils/utils");
|
|
20
|
-
const
|
|
21
|
-
const
|
|
19
|
+
const adapter_factory_1 = __importDefault(require("./factories/adapter-factory"));
|
|
20
|
+
const serial_scanner_1 = require("./serial-scanner");
|
|
22
21
|
const DEFAULT_SCAN_TIMEOUT = 10000;
|
|
23
|
-
exports.SerialInterfaceType = {
|
|
24
|
-
SERIAL: 'serial',
|
|
25
|
-
TCPIP: 'tcpip'
|
|
26
|
-
};
|
|
27
|
-
class SinglePathScanner {
|
|
28
|
-
constructor(path, serial, props) {
|
|
29
|
-
this.path = path;
|
|
30
|
-
this.serial = serial;
|
|
31
|
-
this.result = undefined;
|
|
32
|
-
this.isScanning = false;
|
|
33
|
-
this.isFound = false;
|
|
34
|
-
this.props = props;
|
|
35
|
-
this.logger = props.logger || new gd_eventlog_1.EventLogger('SerialScanner');
|
|
36
|
-
}
|
|
37
|
-
logEvent(event) {
|
|
38
|
-
if (this.logger) {
|
|
39
|
-
this.logger.logEvent(event);
|
|
40
|
-
}
|
|
41
|
-
const w = global.window;
|
|
42
|
-
if ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || process.env.BLE_DEBUG) {
|
|
43
|
-
console.log('~~~ SerialScanner', event);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
onStopRequest(resolve) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
this.logEvent({ message: 'stopping scan', path: this.path });
|
|
49
|
-
if (!this.isFound)
|
|
50
|
-
yield this.serial.closePort(this.path);
|
|
51
|
-
this.isScanning = false;
|
|
52
|
-
resolve(this.result);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
scan() {
|
|
56
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
if (this.isScanning)
|
|
58
|
-
return;
|
|
59
|
-
this.isScanning = true;
|
|
60
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
this.logEvent({ message: 'starting scan', path: this.path, interface: this.serial.getName() });
|
|
62
|
-
this.serial.scanEvents.on('timeout', () => this.onStopRequest(resolve));
|
|
63
|
-
this.serial.scanEvents.on('stop', () => this.onStopRequest(resolve));
|
|
64
|
-
let found = false;
|
|
65
|
-
while (!found && this.isScanning) {
|
|
66
|
-
try {
|
|
67
|
-
const { protocol } = this.props;
|
|
68
|
-
let host, port;
|
|
69
|
-
if (this.serial.getName() === exports.SerialInterfaceType.TCPIP) {
|
|
70
|
-
[host, port] = this.path.split(':');
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
port = this.path;
|
|
74
|
-
}
|
|
75
|
-
const adapterSettings = { interface: this.serial.getName(), host, port, protocol };
|
|
76
|
-
const adapter = adapters_1.default.create(adapterSettings);
|
|
77
|
-
found = yield adapter.check();
|
|
78
|
-
if (found) {
|
|
79
|
-
this.isFound = true;
|
|
80
|
-
const name = adapter.getName();
|
|
81
|
-
resolve(Object.assign(Object.assign({}, adapterSettings), { name }));
|
|
82
|
-
}
|
|
83
|
-
yield (0, utils_1.sleep)(100);
|
|
84
|
-
}
|
|
85
|
-
catch (err) {
|
|
86
|
-
this.logEvent({ message: 'error', fn: 'scan()', error: err.message || err, stack: err.stack });
|
|
87
|
-
yield (0, utils_1.sleep)(100);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}));
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
exports.SinglePathScanner = SinglePathScanner;
|
|
95
22
|
class SerialInterface extends events_1.default {
|
|
96
23
|
static getInstance(props) {
|
|
97
24
|
const { ifaceName, binding, logger } = props;
|
|
@@ -312,7 +239,7 @@ class SerialInterface extends events_1.default {
|
|
|
312
239
|
return [];
|
|
313
240
|
}
|
|
314
241
|
this.logEvent({ message: 'scanning on ', interface: this.ifaceName, paths: paths.map(p => p.path).join(','), timeout });
|
|
315
|
-
const scanners = paths.map(p => new SinglePathScanner(p.path, this, Object.assign(Object.assign({}, props), { logger: this.logger })));
|
|
242
|
+
const scanners = paths.map(p => new serial_scanner_1.SinglePathScanner(p.path, this, Object.assign(Object.assign({}, props), { logger: this.logger })));
|
|
316
243
|
try {
|
|
317
244
|
yield Promise.all(scanners.map(s => s.scan()
|
|
318
245
|
.then((device) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EventLogger } from "gd-eventlog";
|
|
2
|
+
import SerialInterface from "./serial-interface";
|
|
3
|
+
import { SerialDeviceSettings, SerialScannerProps } from "./types";
|
|
4
|
+
export declare class SinglePathScanner {
|
|
5
|
+
path: string;
|
|
6
|
+
serial: SerialInterface;
|
|
7
|
+
result: SerialDeviceSettings;
|
|
8
|
+
isScanning: boolean;
|
|
9
|
+
props: SerialScannerProps;
|
|
10
|
+
logger: EventLogger;
|
|
11
|
+
isFound: boolean;
|
|
12
|
+
constructor(path: string, serial: SerialInterface, props: SerialScannerProps);
|
|
13
|
+
logEvent(event: any): void;
|
|
14
|
+
onStopRequest(resolve: any): Promise<void>;
|
|
15
|
+
scan(): Promise<SerialDeviceSettings | undefined>;
|
|
16
|
+
}
|
|
@@ -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) {
|
|
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.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;
|
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
import { BindingInterface } from '@serialport/bindings-interface';
|
|
2
|
-
|
|
3
|
-
name: string;
|
|
4
|
-
binding: BindingInterface;
|
|
5
|
-
};
|
|
6
|
-
export type InterfaceImplementation = {
|
|
7
|
-
name: string;
|
|
8
|
-
Serialport: any;
|
|
9
|
-
implementation?: any;
|
|
10
|
-
};
|
|
11
|
-
export type SerialPortProps = {
|
|
12
|
-
interface: string;
|
|
13
|
-
port?: string;
|
|
14
|
-
};
|
|
2
|
+
import { InterfaceBinding, InterfaceImplementation } from './types';
|
|
15
3
|
export default class SerialPortProvider {
|
|
16
4
|
static _instance: SerialPortProvider;
|
|
17
5
|
interfaces: InterfaceBinding[];
|
|
@@ -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,21 +1,18 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import
|
|
3
|
-
import ICyclingMode, { CyclingMode, IncyclistBikeData } from '../modes/types';
|
|
4
|
-
import { DeviceProperties, DeviceSettings } from '../types/device';
|
|
2
|
+
import SimulatorCyclingMode from '../modes/simulator';
|
|
5
3
|
import IncyclistDevice from '../base/adpater';
|
|
6
|
-
import {
|
|
4
|
+
import { IAdapter, IncyclistBikeData, DeviceProperties, DeviceSettings } from '../types';
|
|
7
5
|
interface SimulatorProperties extends DeviceProperties {
|
|
8
6
|
isBot?: boolean;
|
|
9
7
|
settings?: any;
|
|
10
8
|
activity?: any;
|
|
11
9
|
}
|
|
12
|
-
export declare class
|
|
13
|
-
getSupportedCyclingModes(): Array<typeof CyclingMode>;
|
|
14
|
-
getDefaultCyclingMode(): ICyclingMode;
|
|
15
|
-
sendInitCommands(): Promise<boolean>;
|
|
16
|
-
}
|
|
17
|
-
export declare class Simulator extends IncyclistDevice<SimulatorControl, SimulatorProperties> {
|
|
10
|
+
export declare class Simulator extends IncyclistDevice<SimulatorProperties> {
|
|
18
11
|
static NAME: string;
|
|
12
|
+
protected static controllers: {
|
|
13
|
+
modes: (typeof SimulatorCyclingMode)[];
|
|
14
|
+
default: typeof SimulatorCyclingMode;
|
|
15
|
+
};
|
|
19
16
|
speed: number;
|
|
20
17
|
power: number;
|
|
21
18
|
cadence: number;
|
|
@@ -35,7 +32,7 @@ export declare class Simulator extends IncyclistDevice<SimulatorControl, Simulat
|
|
|
35
32
|
};
|
|
36
33
|
constructor(settings: DeviceSettings, props?: SimulatorProperties);
|
|
37
34
|
isEqual(settings: DeviceSettings): boolean;
|
|
38
|
-
isSame(device:
|
|
35
|
+
isSame(device: IAdapter): boolean;
|
|
39
36
|
getID(): string;
|
|
40
37
|
getName(): string;
|
|
41
38
|
getUniqueName(): string;
|
|
@@ -47,8 +44,8 @@ export declare class Simulator extends IncyclistDevice<SimulatorControl, Simulat
|
|
|
47
44
|
faster(): void;
|
|
48
45
|
slower(): void;
|
|
49
46
|
update(): void;
|
|
50
|
-
|
|
47
|
+
canEmitData(): boolean;
|
|
51
48
|
calculateDistance(speedKps: any, timeS: any): number;
|
|
52
|
-
sendUpdate(request: any): import("
|
|
49
|
+
sendUpdate(request: any): import("..").UpdateRequest;
|
|
53
50
|
}
|
|
54
51
|
export {};
|
|
@@ -12,32 +12,16 @@ 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.Simulator =
|
|
16
|
-
const adpater_1 = require("../base/adpater");
|
|
15
|
+
exports.Simulator = void 0;
|
|
17
16
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
18
17
|
const simulator_1 = __importDefault(require("../modes/simulator"));
|
|
19
|
-
const
|
|
20
|
-
const
|
|
18
|
+
const adpater_1 = __importDefault(require("../base/adpater"));
|
|
19
|
+
const types_1 = require("../types");
|
|
21
20
|
const DEFAULT_PROPS = { isBot: false };
|
|
22
|
-
class
|
|
23
|
-
getSupportedCyclingModes() {
|
|
24
|
-
return [simulator_1.default];
|
|
25
|
-
}
|
|
26
|
-
getDefaultCyclingMode() {
|
|
27
|
-
return new simulator_1.default(this.adapter);
|
|
28
|
-
}
|
|
29
|
-
sendInitCommands() {
|
|
30
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
return true;
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.SimulatorControl = SimulatorControl;
|
|
36
|
-
class Simulator extends adpater_2.default {
|
|
21
|
+
class Simulator extends adpater_1.default {
|
|
37
22
|
constructor(settings, props = DEFAULT_PROPS) {
|
|
38
23
|
super(settings, props);
|
|
39
24
|
this.logger = new gd_eventlog_1.EventLogger(Simulator.NAME);
|
|
40
|
-
this.setControl(new SimulatorControl(this, props));
|
|
41
25
|
this.speed = 0;
|
|
42
26
|
this.power = 0;
|
|
43
27
|
this.cadence = 90;
|
|
@@ -51,8 +35,8 @@ class Simulator extends adpater_2.default {
|
|
|
51
35
|
const modeSettings = this.isBot ? props.settings : this.getCyclingMode().getSettings();
|
|
52
36
|
this.setCyclingMode(name, modeSettings);
|
|
53
37
|
this.capabilities = [
|
|
54
|
-
|
|
55
|
-
|
|
38
|
+
types_1.IncyclistCapability.Power, types_1.IncyclistCapability.Speed, types_1.IncyclistCapability.Cadence, types_1.IncyclistCapability.Gear,
|
|
39
|
+
types_1.IncyclistCapability.Control
|
|
56
40
|
];
|
|
57
41
|
}
|
|
58
42
|
isEqual(settings) {
|
|
@@ -187,7 +171,7 @@ class Simulator extends adpater_2.default {
|
|
|
187
171
|
}
|
|
188
172
|
this.emitData(data);
|
|
189
173
|
}
|
|
190
|
-
|
|
174
|
+
canEmitData() {
|
|
191
175
|
return true;
|
|
192
176
|
}
|
|
193
177
|
calculateDistance(speedKps, timeS) {
|
|
@@ -201,3 +185,7 @@ class Simulator extends adpater_2.default {
|
|
|
201
185
|
}
|
|
202
186
|
exports.Simulator = Simulator;
|
|
203
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
|
@@ -2,61 +2,50 @@
|
|
|
2
2
|
import EventEmitter from "events";
|
|
3
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
|
|
8
|
+
export type OnDeviceDataCallback = (data: IncyclistAdapterData) => void;
|
|
9
|
+
export type ControllerConfig = {
|
|
10
|
+
modes?: Array<typeof CyclingMode>;
|
|
11
|
+
default?: typeof CyclingMode;
|
|
12
|
+
};
|
|
10
13
|
export interface IBike {
|
|
11
|
-
isControllable(): boolean;
|
|
12
14
|
setCyclingMode(mode: ICyclingMode | string, settings?: any, sendInitCommands?: boolean): void;
|
|
13
15
|
getSupportedCyclingModes(): Array<typeof CyclingMode>;
|
|
14
16
|
getCyclingMode(): ICyclingMode;
|
|
15
17
|
getDefaultCyclingMode(): ICyclingMode;
|
|
16
18
|
setBikeProps(props: DeviceProperties): void;
|
|
17
19
|
sendInitCommands(): Promise<boolean>;
|
|
20
|
+
sendUpdate(request: any): any;
|
|
18
21
|
setUser(user: User): void;
|
|
19
22
|
getWeight(): number;
|
|
20
23
|
getUser(): User;
|
|
21
24
|
}
|
|
22
|
-
export interface
|
|
23
|
-
|
|
24
|
-
connect(): Promise<boolean>;
|
|
25
|
-
close(): Promise<boolean>;
|
|
26
|
-
check(): Promise<boolean>;
|
|
27
|
-
isEqual(settings: DeviceSettings): boolean;
|
|
25
|
+
export interface ISensor {
|
|
26
|
+
isControllable(): boolean;
|
|
28
27
|
getCapabilities(): IncyclistCapability[];
|
|
29
28
|
hasCapability(capability: IncyclistCapability): boolean;
|
|
30
29
|
addCapability(capability: IncyclistCapability): void;
|
|
31
|
-
|
|
30
|
+
getMaxUpdateFrequency(): any;
|
|
31
|
+
setMaxUpdateFrequency(value: number): any;
|
|
32
|
+
update(): any;
|
|
33
|
+
}
|
|
34
|
+
export interface IAdapter extends EventEmitter, IBike, ISensor {
|
|
32
35
|
getName(): string;
|
|
36
|
+
getID(): string;
|
|
33
37
|
getUniqueName(): string;
|
|
34
|
-
getSettings(): DeviceSettings;
|
|
35
38
|
getDisplayName(): string;
|
|
36
|
-
|
|
39
|
+
getSettings(): DeviceSettings;
|
|
40
|
+
isSame(adapter: IAdapter): boolean;
|
|
41
|
+
isEqual(settings: DeviceSettings): boolean;
|
|
42
|
+
getInterface(): string;
|
|
43
|
+
check(): Promise<boolean>;
|
|
37
44
|
start(props?: DeviceProperties): Promise<boolean>;
|
|
38
45
|
stop(): Promise<boolean>;
|
|
39
46
|
pause(): Promise<boolean>;
|
|
40
47
|
resume(): Promise<boolean>;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
setMaxUpdateFrequency(value: number): any;
|
|
44
|
-
getInterface(): string;
|
|
48
|
+
connect(): Promise<boolean>;
|
|
49
|
+
close(): Promise<boolean>;
|
|
45
50
|
onData(callback: OnDeviceDataCallback): any;
|
|
46
51
|
}
|
|
47
|
-
export declare class Controllable<P extends DeviceProperties> implements IBike {
|
|
48
|
-
protected adapter: IncyclistDeviceAdapter;
|
|
49
|
-
protected props: P;
|
|
50
|
-
protected user: User;
|
|
51
|
-
constructor(adapter: IncyclistDeviceAdapter, props?: P);
|
|
52
|
-
isControllable(): boolean;
|
|
53
|
-
setCyclingMode(mode: string | ICyclingMode, settings?: any, sendInitCommands?: boolean): void;
|
|
54
|
-
getSupportedCyclingModes(): Array<typeof CyclingMode>;
|
|
55
|
-
getCyclingMode(): ICyclingMode;
|
|
56
|
-
getDefaultCyclingMode(): ICyclingMode;
|
|
57
|
-
sendInitCommands(): Promise<boolean>;
|
|
58
|
-
setUser(user: User): void;
|
|
59
|
-
getUser(): User;
|
|
60
|
-
setBikeProps(props: P): void;
|
|
61
|
-
getWeight(): number;
|
|
62
|
-
}
|
package/lib/types/adapter.js
CHANGED
|
@@ -1,70 +1,2 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Controllable = void 0;
|
|
13
|
-
const adpater_1 = require("../base/adpater");
|
|
14
|
-
class Controllable {
|
|
15
|
-
constructor(adapter, props) {
|
|
16
|
-
this.adapter = adapter;
|
|
17
|
-
this.props = props || {};
|
|
18
|
-
this.user = {};
|
|
19
|
-
}
|
|
20
|
-
isControllable() {
|
|
21
|
-
throw new Error("Method not implemented.");
|
|
22
|
-
}
|
|
23
|
-
setCyclingMode(mode, settings, sendInitCommands) {
|
|
24
|
-
throw new Error("Method not implemented.");
|
|
25
|
-
}
|
|
26
|
-
getSupportedCyclingModes() {
|
|
27
|
-
throw new Error("Method not implemented.");
|
|
28
|
-
}
|
|
29
|
-
getCyclingMode() {
|
|
30
|
-
throw new Error("Method not implemented.");
|
|
31
|
-
}
|
|
32
|
-
getDefaultCyclingMode() {
|
|
33
|
-
throw new Error("Method not implemented.");
|
|
34
|
-
}
|
|
35
|
-
sendInitCommands() {
|
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
throw new Error("Method not implemented.");
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
setUser(user) {
|
|
41
|
-
this.user = user;
|
|
42
|
-
if (!user.weight)
|
|
43
|
-
this.user.weight = adpater_1.DEFAULT_USER_WEIGHT;
|
|
44
|
-
}
|
|
45
|
-
getUser() {
|
|
46
|
-
return this.user;
|
|
47
|
-
}
|
|
48
|
-
setBikeProps(props) {
|
|
49
|
-
const { user, userWeight } = props || {};
|
|
50
|
-
if (user)
|
|
51
|
-
this.setUser(user);
|
|
52
|
-
if (userWeight)
|
|
53
|
-
this.user.weight = userWeight;
|
|
54
|
-
const keys = Object.keys(props);
|
|
55
|
-
keys.forEach(k => {
|
|
56
|
-
const p = props[k];
|
|
57
|
-
if (p === null)
|
|
58
|
-
delete this.props[k];
|
|
59
|
-
else if (p !== undefined)
|
|
60
|
-
this.props[k] = p;
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
getWeight() {
|
|
64
|
-
const { user = {}, props = adpater_1.DEFAULT_PROPS } = this;
|
|
65
|
-
const userWeight = user.weight || props.userWeight || adpater_1.DEFAULT_USER_WEIGHT;
|
|
66
|
-
const bikeWeight = props.bikeWeight || adpater_1.DEFAULT_BIKE_WEIGHT;
|
|
67
|
-
return userWeight + bikeWeight;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.Controllable = Controllable;
|
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 = {}));
|