incyclist-devices 2.0.35 → 2.0.36
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/antv2/modes/ant-fe-adv-st-mode.d.ts +2 -2
- package/lib/antv2/modes/ant-fe-erg-mode.d.ts +2 -2
- package/lib/antv2/modes/ant-fe-st-mode.d.ts +2 -2
- package/lib/base/adpater.d.ts +2 -1
- package/lib/base/adpater.js +7 -6
- package/lib/interfaces.d.ts +1 -1
- package/lib/modes/ble-erg-mode.d.ts +2 -2
- package/lib/modes/ble-st-mode.d.ts +2 -2
- package/lib/modes/cycling-mode.d.ts +7 -7
- package/lib/modes/power-base.d.ts +3 -3
- package/lib/modes/power-base.js +3 -2
- package/lib/modes/power-meter.d.ts +2 -2
- package/lib/serial/comms.d.ts +62 -0
- package/lib/serial/comms.js +280 -0
- package/lib/serial/daum/DaumAdapter.d.ts +13 -8
- package/lib/serial/daum/DaumAdapter.js +49 -12
- package/lib/serial/daum/ERGCyclingMode.d.ts +2 -2
- package/lib/serial/daum/ERGCyclingMode.js +1 -1
- package/lib/serial/daum/SmartTrainerCyclingMode.d.ts +3 -2
- package/lib/serial/daum/SmartTrainerCyclingMode.js +10 -5
- package/lib/serial/daum/classic/adapter.d.ts +4 -6
- package/lib/serial/daum/classic/adapter.js +5 -23
- package/lib/serial/daum/classic/comms.d.ts +33 -65
- package/lib/serial/daum/classic/comms.js +148 -332
- package/lib/serial/daum/classic/mock.js +5 -3
- package/lib/serial/daum/classic/modes/daum-classic.d.ts +2 -2
- package/lib/serial/daum/classic/modes/daum-classic.js +1 -1
- package/lib/serial/daum/classic/types.d.ts +59 -0
- package/lib/serial/daum/classic/types.js +2 -0
- package/lib/serial/daum/classic/utils.d.ts +11 -10
- package/lib/serial/daum/classic/utils.js +33 -68
- package/lib/serial/daum/premium/adapter.d.ts +4 -7
- package/lib/serial/daum/premium/adapter.js +7 -30
- package/lib/serial/daum/premium/comms.d.ts +28 -105
- package/lib/serial/daum/premium/comms.js +262 -466
- package/lib/serial/daum/premium/consts.d.ts +6 -0
- package/lib/serial/daum/premium/consts.js +9 -0
- package/lib/serial/daum/premium/mock.d.ts +32 -1
- package/lib/serial/daum/premium/mock.js +131 -8
- package/lib/serial/daum/premium/modes/daum-classic.d.ts +2 -2
- package/lib/serial/daum/premium/modes/daum-classic.js +1 -1
- package/lib/serial/daum/premium/types.d.ts +35 -1
- package/lib/serial/daum/premium/types.js +29 -0
- package/lib/serial/daum/premium/utils.d.ts +11 -18
- package/lib/serial/daum/premium/utils.js +25 -18
- package/lib/serial/serial-interface.js +3 -2
- package/lib/types/adapter.d.ts +2 -0
- package/lib/types/device.d.ts +11 -0
- package/lib/types/route.d.ts +0 -5
- package/lib/types/route.js +0 -7
- package/lib/utils/calculations.js +1 -5
- package/lib/utils/utils.d.ts +2 -1
- package/lib/utils/utils.js +39 -3
- package/package.json +3 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { ControllableDeviceAdapter } from "../..";
|
|
1
2
|
import FtmsCyclingMode from "../../modes/ble-st-mode";
|
|
2
3
|
import { UpdateRequest } from "../../modes/cycling-mode";
|
|
3
|
-
import { IncyclistDeviceAdapter } from "../../types/adapter";
|
|
4
4
|
export default class AntAdvSimCyclingMode extends FtmsCyclingMode {
|
|
5
|
-
constructor(adapter:
|
|
5
|
+
constructor(adapter: ControllableDeviceAdapter, props?: any);
|
|
6
6
|
getName(): string;
|
|
7
7
|
getDescription(): string;
|
|
8
8
|
sendBikeUpdate(request: UpdateRequest): UpdateRequest;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { ControllableDeviceAdapter } from "../..";
|
|
1
2
|
import BleERGCyclingMode from "../../modes/ble-erg-mode";
|
|
2
|
-
import { IncyclistDeviceAdapter } from "../../types/adapter";
|
|
3
3
|
export default class AntFeERGCyclingMode extends BleERGCyclingMode {
|
|
4
4
|
static isERG: boolean;
|
|
5
|
-
constructor(adapter:
|
|
5
|
+
constructor(adapter: ControllableDeviceAdapter, props?: any);
|
|
6
6
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { ControllableDeviceAdapter } from "../..";
|
|
1
2
|
import FtmsCyclingMode from "../../modes/ble-st-mode";
|
|
2
|
-
import { IncyclistDeviceAdapter } from "../../types/adapter";
|
|
3
3
|
export default class AntStCyclingMode extends FtmsCyclingMode {
|
|
4
|
-
constructor(adapter:
|
|
4
|
+
constructor(adapter: ControllableDeviceAdapter, props?: any);
|
|
5
5
|
}
|
package/lib/base/adpater.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export default class IncyclistDevice extends EventEmitter implements IncyclistDe
|
|
|
25
25
|
connect(): Promise<boolean>;
|
|
26
26
|
close(): Promise<boolean>;
|
|
27
27
|
check(): Promise<boolean>;
|
|
28
|
+
getLogger(): EventLogger;
|
|
28
29
|
isControllable(): boolean;
|
|
29
30
|
isEqual(settings: DeviceSettings): boolean;
|
|
30
31
|
getCapabilities(): IncyclistCapability[];
|
|
@@ -60,10 +61,10 @@ export declare class ControllableDevice extends IncyclistDevice implements Bike
|
|
|
60
61
|
isControllable(): boolean;
|
|
61
62
|
setUser(user: User): void;
|
|
62
63
|
setBikeProps(props: DeviceProperties): void;
|
|
63
|
-
getWeight(): number;
|
|
64
64
|
getSupportedCyclingModes(): any[];
|
|
65
65
|
getDefaultCyclingMode(): CyclingMode;
|
|
66
66
|
setCyclingMode(mode: CyclingMode | string, settings?: any): void;
|
|
67
67
|
sendInitCommands(): Promise<boolean>;
|
|
68
68
|
getCyclingMode(): CyclingMode;
|
|
69
|
+
getWeight(): number;
|
|
69
70
|
}
|
package/lib/base/adpater.js
CHANGED
|
@@ -34,6 +34,7 @@ class IncyclistDevice extends events_1.default {
|
|
|
34
34
|
connect() { throw new Error('not implemented'); }
|
|
35
35
|
close() { throw new Error('not implemented'); }
|
|
36
36
|
check() { throw new Error("Method not implemented."); }
|
|
37
|
+
getLogger() { return undefined; }
|
|
37
38
|
isControllable() {
|
|
38
39
|
return false;
|
|
39
40
|
}
|
|
@@ -154,12 +155,6 @@ class ControllableDevice extends IncyclistDevice {
|
|
|
154
155
|
this.props[k] = p;
|
|
155
156
|
});
|
|
156
157
|
}
|
|
157
|
-
getWeight() {
|
|
158
|
-
const { user = {}, props = exports.DEFAULT_PROPS } = this;
|
|
159
|
-
const userWeight = user.weight || props.userWeight || exports.DEFAULT_USER_WEIGHT;
|
|
160
|
-
const bikeWeight = props.bikeWeight || exports.DEFAULT_BIKE_WEIGHT;
|
|
161
|
-
return userWeight + bikeWeight;
|
|
162
|
-
}
|
|
163
158
|
getSupportedCyclingModes() { throw new Error('not implemented'); }
|
|
164
159
|
getDefaultCyclingMode() { throw new Error('not implemented'); }
|
|
165
160
|
setCyclingMode(mode, settings) {
|
|
@@ -189,5 +184,11 @@ class ControllableDevice extends IncyclistDevice {
|
|
|
189
184
|
this.setCyclingMode(this.getDefaultCyclingMode());
|
|
190
185
|
return this.cyclingMode;
|
|
191
186
|
}
|
|
187
|
+
getWeight() {
|
|
188
|
+
const { user = {}, props = exports.DEFAULT_PROPS } = this;
|
|
189
|
+
const userWeight = user.weight || props.userWeight || exports.DEFAULT_USER_WEIGHT;
|
|
190
|
+
const bikeWeight = props.bikeWeight || exports.DEFAULT_BIKE_WEIGHT;
|
|
191
|
+
return userWeight + bikeWeight;
|
|
192
|
+
}
|
|
192
193
|
}
|
|
193
194
|
exports.ControllableDevice = ControllableDevice;
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ import { SerialInterface } from "./serial";
|
|
|
3
3
|
import AntInterface from "./antv2/ant-interface";
|
|
4
4
|
import { BleInterface } from "./ble";
|
|
5
5
|
export default class InterfaceFactory {
|
|
6
|
-
static create(ifaceName: string, props?: InterfaceProps):
|
|
6
|
+
static create(ifaceName: string, props?: InterfaceProps): SerialInterface | BleInterface | AntInterface;
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ControllableDeviceAdapter } from "..";
|
|
2
2
|
import CyclingMode, { CyclingModeProperty, IncyclistBikeData, UpdateRequest } from "./cycling-mode";
|
|
3
3
|
import PowerBasedCyclingModeBase from "./power-base";
|
|
4
4
|
export default class BleERGCyclingMode extends PowerBasedCyclingModeBase implements CyclingMode {
|
|
@@ -7,7 +7,7 @@ export default class BleERGCyclingMode extends PowerBasedCyclingModeBase impleme
|
|
|
7
7
|
hasBikeUpdate: boolean;
|
|
8
8
|
chain: number[];
|
|
9
9
|
cassette: number[];
|
|
10
|
-
constructor(adapter:
|
|
10
|
+
constructor(adapter: ControllableDeviceAdapter, props?: any);
|
|
11
11
|
getName(): string;
|
|
12
12
|
getDescription(): string;
|
|
13
13
|
getProperties(): CyclingModeProperty[];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { ControllableDeviceAdapter } from "..";
|
|
1
2
|
import CyclingMode, { CyclingModeProperty, IncyclistBikeData, UpdateRequest } from "../modes/cycling-mode";
|
|
2
3
|
import PowerBasedCyclingModeBase from "../modes/power-base";
|
|
3
|
-
import { IncyclistDeviceAdapter } from "../types/adapter";
|
|
4
4
|
export default class FtmsCyclingMode extends PowerBasedCyclingModeBase implements CyclingMode {
|
|
5
5
|
prevRequest: UpdateRequest;
|
|
6
6
|
hasBikeUpdate: boolean;
|
|
7
|
-
constructor(adapter:
|
|
7
|
+
constructor(adapter: ControllableDeviceAdapter, props?: any);
|
|
8
8
|
getName(): string;
|
|
9
9
|
getDescription(): string;
|
|
10
10
|
getProperties(): CyclingModeProperty[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ControllableDeviceAdapter } from "..";
|
|
2
2
|
export type UpdateRequest = {
|
|
3
3
|
slope?: number;
|
|
4
4
|
minPower?: number;
|
|
@@ -28,12 +28,12 @@ export type CyclingModeProperty = {
|
|
|
28
28
|
options?: any[];
|
|
29
29
|
};
|
|
30
30
|
export type IncyclistBikeData = {
|
|
31
|
-
isPedalling
|
|
31
|
+
isPedalling?: boolean;
|
|
32
32
|
power: number;
|
|
33
33
|
pedalRpm: number;
|
|
34
34
|
speed: number;
|
|
35
|
-
heartrate
|
|
36
|
-
distanceInternal
|
|
35
|
+
heartrate?: number;
|
|
36
|
+
distanceInternal?: number;
|
|
37
37
|
time?: number;
|
|
38
38
|
gear?: number;
|
|
39
39
|
slope?: number;
|
|
@@ -57,11 +57,11 @@ export default interface CyclingMode {
|
|
|
57
57
|
getModeProperty(name: string): any;
|
|
58
58
|
}
|
|
59
59
|
export declare class CyclingModeBase implements CyclingMode {
|
|
60
|
-
adapter:
|
|
60
|
+
adapter: ControllableDeviceAdapter;
|
|
61
61
|
settings: Settings;
|
|
62
62
|
properties: Settings;
|
|
63
|
-
constructor(adapter:
|
|
64
|
-
setAdapter(adapter:
|
|
63
|
+
constructor(adapter: ControllableDeviceAdapter, props?: any);
|
|
64
|
+
setAdapter(adapter: ControllableDeviceAdapter): void;
|
|
65
65
|
getBikeInitRequest(): UpdateRequest;
|
|
66
66
|
getName(): string;
|
|
67
67
|
getDescription(): string;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { IncyclistBikeData, Settings, CyclingModeBase } from './cycling-mode';
|
|
2
2
|
import { EventLogger } from 'gd-eventlog';
|
|
3
|
-
import {
|
|
3
|
+
import { ControllableDeviceAdapter } from '..';
|
|
4
4
|
export default class PowerBasedCyclingModeBase extends CyclingModeBase {
|
|
5
5
|
data: IncyclistBikeData;
|
|
6
6
|
prevUpdateTS: number;
|
|
7
7
|
logger: EventLogger;
|
|
8
|
-
constructor(adapter:
|
|
8
|
+
constructor(adapter: ControllableDeviceAdapter, props?: Settings);
|
|
9
9
|
initLogger(defaultLogName: any): void;
|
|
10
|
-
getWeight():
|
|
10
|
+
getWeight(): number;
|
|
11
11
|
getTimeSinceLastUpdate(): number;
|
|
12
12
|
calculateSpeedAndDistance(power: number, slope: number, m: number, t: number, props?: {}): {
|
|
13
13
|
speed: number;
|
package/lib/modes/power-base.js
CHANGED
|
@@ -15,13 +15,14 @@ class PowerBasedCyclingModeBase extends cycling_mode_1.CyclingModeBase {
|
|
|
15
15
|
}
|
|
16
16
|
initLogger(defaultLogName) {
|
|
17
17
|
const a = this.adapter;
|
|
18
|
-
this.logger =
|
|
18
|
+
this.logger = a.getLogger();
|
|
19
19
|
if (!this.logger)
|
|
20
20
|
this.logger = new gd_eventlog_1.EventLogger(defaultLogName);
|
|
21
21
|
}
|
|
22
22
|
getWeight() {
|
|
23
23
|
const a = this.adapter;
|
|
24
|
-
const
|
|
24
|
+
const defaultWeight = adpater_1.DEFAULT_BIKE_WEIGHT + adpater_1.DEFAULT_USER_WEIGHT;
|
|
25
|
+
const m = (a) ? a.getWeight() || defaultWeight : defaultWeight;
|
|
25
26
|
return m;
|
|
26
27
|
}
|
|
27
28
|
getTimeSinceLastUpdate() {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import CyclingMode, { CyclingModeProperty, IncyclistBikeData, Settings, UpdateRequest } from '../modes/cycling-mode';
|
|
2
2
|
import PowerBasedCyclingModeBase from './power-base';
|
|
3
|
-
import {
|
|
3
|
+
import { ControllableDeviceAdapter } from '..';
|
|
4
4
|
export declare const config: {
|
|
5
5
|
name: string;
|
|
6
6
|
description: string;
|
|
7
7
|
properties: any[];
|
|
8
8
|
};
|
|
9
9
|
export default class PowerMeterCyclingMode extends PowerBasedCyclingModeBase implements CyclingMode {
|
|
10
|
-
constructor(adapter:
|
|
10
|
+
constructor(adapter: ControllableDeviceAdapter, props?: Settings);
|
|
11
11
|
getName(): string;
|
|
12
12
|
getDescription(): string;
|
|
13
13
|
getProperties(): CyclingModeProperty[];
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventLogger } from "gd-eventlog";
|
|
3
|
+
import SerialInterface from "./serial-interface";
|
|
4
|
+
import { SerialCommProps } from "./comm";
|
|
5
|
+
import { SerialPortStream } from "@serialport/stream";
|
|
6
|
+
import { Queue } from "../utils/utils";
|
|
7
|
+
export type ConnectionState = 'Connecting' | 'Connected' | 'Disconnected' | 'Disconnecting';
|
|
8
|
+
export type Request = {
|
|
9
|
+
logString?: string;
|
|
10
|
+
isBinary?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type Response = {};
|
|
13
|
+
export interface CommsState {
|
|
14
|
+
data?: Queue<Response>;
|
|
15
|
+
}
|
|
16
|
+
export default class SerialPortComms<T extends CommsState, C extends Request, R extends Response> {
|
|
17
|
+
logger: EventLogger;
|
|
18
|
+
serial: SerialInterface;
|
|
19
|
+
protected path: string;
|
|
20
|
+
protected props: SerialCommProps;
|
|
21
|
+
protected sp: SerialPortStream;
|
|
22
|
+
protected connectState: ConnectionState;
|
|
23
|
+
protected connectPromise: Promise<SerialPortStream>;
|
|
24
|
+
protected disconnectPromise: Promise<boolean>;
|
|
25
|
+
protected writePromise: Promise<void>;
|
|
26
|
+
protected sendCmdPromise: Promise<R>;
|
|
27
|
+
protected actualBikeType?: string;
|
|
28
|
+
protected recvState: T;
|
|
29
|
+
protected isLoggingPaused: boolean;
|
|
30
|
+
constructor(props: SerialCommProps);
|
|
31
|
+
getBusyTimeout(): number;
|
|
32
|
+
getDefaultLoggerName(): string;
|
|
33
|
+
getInitialCommsState(): T;
|
|
34
|
+
validatePath(path: string): string;
|
|
35
|
+
getInterface(): string;
|
|
36
|
+
getPort(): string;
|
|
37
|
+
isConnected(): boolean;
|
|
38
|
+
pauseLogging(): void;
|
|
39
|
+
resumeLogging(): void;
|
|
40
|
+
logEvent(e: any): void;
|
|
41
|
+
connect(): Promise<boolean>;
|
|
42
|
+
onConnected(): void;
|
|
43
|
+
portFlush(): void;
|
|
44
|
+
portPipe(destination: any, options?: any): any;
|
|
45
|
+
portUnpipe(destination?: any): void;
|
|
46
|
+
closePort(): Promise<boolean>;
|
|
47
|
+
resetState(isDisconnected?: boolean): void;
|
|
48
|
+
cleanupPort(isDisconnected?: boolean): void;
|
|
49
|
+
close(): Promise<boolean>;
|
|
50
|
+
flush(): Promise<void>;
|
|
51
|
+
onPortClose(): Promise<void>;
|
|
52
|
+
onPortError(error: Error): Promise<void>;
|
|
53
|
+
isSending(): boolean;
|
|
54
|
+
rejectCurrent(error: Error): void;
|
|
55
|
+
getTimeoutValue(): number;
|
|
56
|
+
onData(data: any, depth?: number): Promise<void>;
|
|
57
|
+
send(command: C): Promise<R>;
|
|
58
|
+
portWrite(buffer: Buffer): Promise<void>;
|
|
59
|
+
write(buffer: Buffer): Promise<void>;
|
|
60
|
+
ensurePrevCmdFinish(logPayload: any): Promise<void>;
|
|
61
|
+
ensureConnection(): Promise<void>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,280 @@
|
|
|
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
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
13
|
+
const utils_1 = require("./daum/premium/utils");
|
|
14
|
+
const utils_2 = require("../utils/utils");
|
|
15
|
+
const DEFAULT_BUSY_TIMEOUT = 5000;
|
|
16
|
+
class SerialPortComms {
|
|
17
|
+
constructor(props) {
|
|
18
|
+
this.props = props;
|
|
19
|
+
const { logger, serial, path } = props;
|
|
20
|
+
this.serial = serial;
|
|
21
|
+
this.path = this.validatePath(path);
|
|
22
|
+
const w = global.window;
|
|
23
|
+
this.logger = logger || ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || process.env.DEBUG ? utils_1.DEBUG_LOGGER : new gd_eventlog_1.EventLogger(this.getDefaultLoggerName()));
|
|
24
|
+
this.resetState();
|
|
25
|
+
}
|
|
26
|
+
getBusyTimeout() {
|
|
27
|
+
return DEFAULT_BUSY_TIMEOUT;
|
|
28
|
+
}
|
|
29
|
+
getDefaultLoggerName() {
|
|
30
|
+
return 'Serial';
|
|
31
|
+
}
|
|
32
|
+
getInitialCommsState() {
|
|
33
|
+
return { data: new utils_2.Queue() };
|
|
34
|
+
}
|
|
35
|
+
validatePath(path) {
|
|
36
|
+
return path;
|
|
37
|
+
}
|
|
38
|
+
getInterface() {
|
|
39
|
+
var _a;
|
|
40
|
+
return (_a = this.serial) === null || _a === void 0 ? void 0 : _a.ifaceName;
|
|
41
|
+
}
|
|
42
|
+
getPort() {
|
|
43
|
+
return this.path;
|
|
44
|
+
}
|
|
45
|
+
isConnected() {
|
|
46
|
+
return this.connectState === 'Connected' || this.connectState === 'Disconnecting';
|
|
47
|
+
}
|
|
48
|
+
pauseLogging() {
|
|
49
|
+
this.isLoggingPaused = true;
|
|
50
|
+
}
|
|
51
|
+
resumeLogging() {
|
|
52
|
+
this.isLoggingPaused = false;
|
|
53
|
+
}
|
|
54
|
+
logEvent(e) {
|
|
55
|
+
if (this.isLoggingPaused)
|
|
56
|
+
return;
|
|
57
|
+
this.logger.logEvent(e);
|
|
58
|
+
const w = global.window;
|
|
59
|
+
if (w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) {
|
|
60
|
+
console.log(`~~~ ${this.getDefaultLoggerName()}`, e);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
connect() {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
if (this.isConnected() && this.sp) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
if (this.connectState === 'Connecting') {
|
|
69
|
+
if (this.connectPromise) {
|
|
70
|
+
try {
|
|
71
|
+
yield this.connectPromise;
|
|
72
|
+
}
|
|
73
|
+
catch (_a) {
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return this.isConnected();
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
this.connectState = 'Connecting';
|
|
80
|
+
this.connectPromise = this.serial.openPort(this.path);
|
|
81
|
+
const port = yield this.connectPromise;
|
|
82
|
+
this.connectPromise = null;
|
|
83
|
+
if (port !== null) {
|
|
84
|
+
this.connectState = 'Connected';
|
|
85
|
+
this.sp = port;
|
|
86
|
+
this.sp.on('close', this.onPortClose.bind(this));
|
|
87
|
+
this.sp.on('error', this.onPortError.bind(this));
|
|
88
|
+
this.onConnected();
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.connectState = 'Disconnected';
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch (_b) {
|
|
97
|
+
this.connectState = 'Disconnected';
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
onConnected() {
|
|
103
|
+
}
|
|
104
|
+
portFlush() {
|
|
105
|
+
if (this.sp)
|
|
106
|
+
this.sp.flush();
|
|
107
|
+
}
|
|
108
|
+
portPipe(destination, options) {
|
|
109
|
+
if (this.sp)
|
|
110
|
+
return this.sp.pipe(destination, options);
|
|
111
|
+
}
|
|
112
|
+
portUnpipe(destination) {
|
|
113
|
+
if (this.sp)
|
|
114
|
+
this.sp.unpipe(destination);
|
|
115
|
+
}
|
|
116
|
+
closePort() {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
if (!this.sp)
|
|
119
|
+
return true;
|
|
120
|
+
try {
|
|
121
|
+
yield this.flush();
|
|
122
|
+
yield this.serial.closePort(this.path);
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
this.logEvent({ message: 'could not close ', reason: err.message });
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
resetState(isDisconnected = true) {
|
|
132
|
+
this.isLoggingPaused = false;
|
|
133
|
+
this.recvState = this.getInitialCommsState();
|
|
134
|
+
this.connectPromise = null;
|
|
135
|
+
this.disconnectPromise = null;
|
|
136
|
+
this.writePromise = null;
|
|
137
|
+
this.sendCmdPromise = null;
|
|
138
|
+
if (isDisconnected)
|
|
139
|
+
this.connectState = 'Disconnected';
|
|
140
|
+
}
|
|
141
|
+
cleanupPort(isDisconnected = true) {
|
|
142
|
+
if (this.sp) {
|
|
143
|
+
this.sp.removeAllListeners();
|
|
144
|
+
}
|
|
145
|
+
this.sp = null;
|
|
146
|
+
this.resetState(isDisconnected);
|
|
147
|
+
}
|
|
148
|
+
close() {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
let isDisconnected = false;
|
|
151
|
+
if (this.disconnectPromise) {
|
|
152
|
+
try {
|
|
153
|
+
isDisconnected = yield this.disconnectPromise;
|
|
154
|
+
}
|
|
155
|
+
catch (_a) {
|
|
156
|
+
}
|
|
157
|
+
return isDisconnected;
|
|
158
|
+
}
|
|
159
|
+
if (this.connectState === 'Disconnected') {
|
|
160
|
+
this.cleanupPort();
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
else if (this.connectState === 'Disconnecting' || this.connectState === 'Connected' || this.connectState === 'Connecting') {
|
|
164
|
+
this.connectState = 'Disconnecting';
|
|
165
|
+
this.disconnectPromise = this.closePort();
|
|
166
|
+
isDisconnected = yield this.disconnectPromise;
|
|
167
|
+
if (isDisconnected) {
|
|
168
|
+
this.connectState = 'Disconnected';
|
|
169
|
+
this.logEvent({ message: "port closed:", port: this.path });
|
|
170
|
+
}
|
|
171
|
+
this.cleanupPort(isDisconnected);
|
|
172
|
+
}
|
|
173
|
+
return isDisconnected;
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
flush() {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
if (this.writePromise) {
|
|
179
|
+
yield (0, utils_2.waitWithTimeout)(this.writePromise, 1000);
|
|
180
|
+
this.writePromise = null;
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
onPortClose() {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
if (this.connectState !== 'Disconnected' && this.connectState !== 'Disconnecting')
|
|
187
|
+
this.logEvent({ message: "port closed:", port: this.path });
|
|
188
|
+
this.connectState = 'Disconnected';
|
|
189
|
+
this.cleanupPort();
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
onPortError(error) {
|
|
193
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
+
if (this.connectState === 'Disconnecting' || this.connectState === 'Disconnected') {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
this.logEvent({ message: "port error:", port: this.path, error: error.message, connected: this.isConnected(), state: this.connectState });
|
|
198
|
+
if (this.isSending()) {
|
|
199
|
+
this.rejectCurrent(error);
|
|
200
|
+
}
|
|
201
|
+
if (this.connectState === 'Connected')
|
|
202
|
+
this.close();
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
isSending() {
|
|
206
|
+
return (this.writePromise !== undefined && this.writePromise !== null) || (this.sendCmdPromise !== null && this.sendCmdPromise !== undefined);
|
|
207
|
+
}
|
|
208
|
+
rejectCurrent(error) {
|
|
209
|
+
this.recvState.data.enqueue({ type: 'Error', error });
|
|
210
|
+
}
|
|
211
|
+
getTimeoutValue() {
|
|
212
|
+
throw new Error('method not implemented');
|
|
213
|
+
}
|
|
214
|
+
onData(data, depth = 0) {
|
|
215
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
send(command) {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
throw new Error('method not implemented');
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
portWrite(buffer) {
|
|
224
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
+
if (!this.sp) {
|
|
226
|
+
this.logEvent({ message: 'write failed', error: 'port is not opened' });
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
yield this.sp.write(buffer);
|
|
231
|
+
}
|
|
232
|
+
catch (err) {
|
|
233
|
+
this.logEvent({ message: 'write failed', error: err.message });
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
write(buffer) {
|
|
238
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
if (this.writePromise) {
|
|
240
|
+
try {
|
|
241
|
+
yield this.writePromise;
|
|
242
|
+
}
|
|
243
|
+
catch (_a) {
|
|
244
|
+
}
|
|
245
|
+
this.writePromise = null;
|
|
246
|
+
}
|
|
247
|
+
this.writePromise = this.portWrite(buffer);
|
|
248
|
+
yield this.writePromise;
|
|
249
|
+
this.writePromise = null;
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
ensurePrevCmdFinish(logPayload) {
|
|
253
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
+
if (this.sendCmdPromise) {
|
|
255
|
+
const tsRequest = Date.now();
|
|
256
|
+
this.logEvent(Object.assign({ message: 'sendCommand:waiting:' }, logPayload));
|
|
257
|
+
let busyTimedOut = false;
|
|
258
|
+
const onTimeout = () => {
|
|
259
|
+
this.logEvent(Object.assign(Object.assign({ message: 'sendCommand:error:' }, logPayload), { error: 'BUSY timeout', duration: Date.now() - tsRequest }));
|
|
260
|
+
busyTimedOut = true;
|
|
261
|
+
};
|
|
262
|
+
yield (0, utils_2.waitWithTimeout)(this.sendCmdPromise, this.getBusyTimeout(), onTimeout);
|
|
263
|
+
this.sendCmdPromise = null;
|
|
264
|
+
if (busyTimedOut)
|
|
265
|
+
throw new Error('BUSY timeout');
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
ensureConnection() {
|
|
270
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
+
if (!this.isConnected()) {
|
|
272
|
+
const connected = yield this.connect();
|
|
273
|
+
if (!connected) {
|
|
274
|
+
throw new Error('not connected');
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
exports.default = SerialPortComms;
|
|
@@ -4,10 +4,13 @@ import { Bike } from '../../types/adapter';
|
|
|
4
4
|
import { DeviceProperties } from '../../types/device';
|
|
5
5
|
import { SerialDeviceSettings, SerialIncyclistDevice } from '../adapter';
|
|
6
6
|
import { DeviceData } from '../../types/data';
|
|
7
|
-
interface
|
|
8
|
-
getCurrentBikeData(): Promise<
|
|
7
|
+
export interface IDaumAdapter {
|
|
8
|
+
getCurrentBikeData(): Promise<IncyclistBikeData>;
|
|
9
9
|
}
|
|
10
|
-
export
|
|
10
|
+
export declare abstract class AbstractDaumAdapter extends SerialIncyclistDevice implements IDaumAdapter {
|
|
11
|
+
abstract getCurrentBikeData(): Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
export default class DaumAdapter<S extends SerialDeviceSettings, P extends DeviceProperties> extends AbstractDaumAdapter implements Bike {
|
|
11
14
|
bike: any;
|
|
12
15
|
ignoreHrm: boolean;
|
|
13
16
|
ignoreBike: boolean;
|
|
@@ -25,35 +28,37 @@ export default class DaumAdapterBase extends SerialIncyclistDevice implements Da
|
|
|
25
28
|
adapterTime: number;
|
|
26
29
|
requestBusy: boolean;
|
|
27
30
|
updateBusy: boolean;
|
|
28
|
-
constructor(settings:
|
|
31
|
+
constructor(settings: S, props?: P);
|
|
29
32
|
setCyclingMode(mode: CyclingMode | string, settings?: any): void;
|
|
30
33
|
sendInitCommands(): Promise<boolean>;
|
|
31
34
|
getSupportedCyclingModes(): Array<any>;
|
|
32
35
|
getCyclingMode(): CyclingMode;
|
|
33
36
|
getDefaultCyclingMode(): CyclingMode;
|
|
34
|
-
getCurrentBikeData(): Promise<
|
|
37
|
+
getCurrentBikeData(): Promise<IncyclistBikeData>;
|
|
35
38
|
getBike(): any;
|
|
36
39
|
isEqual(settings: SerialDeviceSettings): boolean;
|
|
37
40
|
isSame(device: SerialIncyclistDevice): boolean;
|
|
38
41
|
isStopped(): boolean;
|
|
39
42
|
initData(): void;
|
|
40
|
-
|
|
43
|
+
pause(): Promise<boolean>;
|
|
44
|
+
resume(): Promise<boolean>;
|
|
45
|
+
start(props?: P): Promise<any>;
|
|
41
46
|
stopUpdatePull(): void;
|
|
42
47
|
startUpdatePull(): void;
|
|
43
48
|
connect(): Promise<boolean>;
|
|
44
49
|
close(): Promise<boolean>;
|
|
45
50
|
logEvent(event: any): void;
|
|
51
|
+
reconnect(): Promise<boolean>;
|
|
46
52
|
stop(): Promise<boolean>;
|
|
47
53
|
canSendUpdate(): boolean;
|
|
48
54
|
sendUpdate(request: any): Promise<unknown>;
|
|
49
55
|
update(): Promise<void>;
|
|
50
56
|
sendRequests(): Promise<void>;
|
|
51
57
|
bikeSync(): Promise<void>;
|
|
52
|
-
updateData(
|
|
58
|
+
updateData(bikeData: IncyclistBikeData): IncyclistBikeData;
|
|
53
59
|
transformData(cyclingData: IncyclistBikeData): DeviceData;
|
|
54
60
|
sendRequest(request: any): Promise<any>;
|
|
55
61
|
refreshRequests(): void;
|
|
56
62
|
processClientRequest(request: any): Promise<unknown>;
|
|
57
63
|
check(): Promise<boolean>;
|
|
58
64
|
}
|
|
59
|
-
export {};
|