incyclist-devices 2.0.38 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/adapters.d.ts +1 -1
- package/lib/antv2/adapter-factory.d.ts +4 -13
- package/lib/antv2/adapter.d.ts +16 -33
- package/lib/antv2/adapter.js +68 -112
- package/lib/antv2/ant-interface.d.ts +3 -11
- package/lib/antv2/ant-interface.js +1 -1
- package/lib/antv2/base/adapter.d.ts +62 -0
- package/lib/antv2/base/adapter.js +360 -0
- package/lib/antv2/base/ant-interface.d.ts +35 -0
- package/lib/antv2/base/ant-interface.js +285 -0
- package/lib/antv2/base/binding.d.ts +13 -0
- package/lib/antv2/base/binding.js +27 -0
- package/lib/antv2/cad/adapter.d.ts +10 -0
- package/lib/antv2/cad/adapter.js +25 -0
- package/lib/antv2/cad/index.d.ts +2 -0
- package/lib/antv2/cad/index.js +7 -0
- package/lib/antv2/consts.d.ts +2 -0
- package/lib/antv2/consts.js +5 -0
- package/lib/antv2/factories/adapter-factory.d.ts +14 -0
- package/lib/antv2/factories/adapter-factory.js +65 -0
- package/lib/antv2/factories/sensor-factory.d.ts +5 -0
- package/lib/antv2/factories/sensor-factory.js +22 -0
- package/lib/antv2/fe/adapter.d.ts +25 -26
- package/lib/antv2/fe/adapter.js +212 -218
- package/lib/antv2/hr/adapter.d.ts +6 -14
- package/lib/antv2/hr/adapter.js +7 -55
- package/lib/antv2/hr copy/adapter.d.ts +11 -0
- package/lib/antv2/hr copy/adapter.js +30 -0
- package/lib/antv2/hr copy/index.d.ts +2 -0
- package/lib/antv2/hr copy/index.js +7 -0
- package/lib/antv2/index.d.ts +5 -4
- package/lib/antv2/index.js +4 -2
- package/lib/antv2/pwr/adapter.d.ts +9 -29
- package/lib/antv2/pwr/adapter.js +20 -130
- package/lib/antv2/types.d.ts +23 -3
- package/lib/base/adpater.d.ts +42 -45
- package/lib/base/adpater.js +144 -110
- package/lib/base/consts.d.ts +4 -0
- package/lib/base/consts.js +9 -0
- package/lib/ble/adapter-factory.d.ts +4 -4
- package/lib/ble/base/adapter.d.ts +6 -24
- package/lib/ble/base/adapter.js +4 -94
- package/lib/ble/ble-interface.d.ts +2 -3
- package/lib/ble/cp/adapter.d.ts +6 -11
- package/lib/ble/cp/adapter.js +9 -12
- package/lib/ble/elite/adapter.d.ts +8 -8
- package/lib/ble/elite/adapter.js +6 -2
- package/lib/ble/fm/adapter.d.ts +11 -11
- package/lib/ble/fm/adapter.js +26 -20
- package/lib/ble/hr/adapter.d.ts +3 -4
- package/lib/ble/hr/adapter.js +2 -2
- package/lib/ble/tacx/adapter.d.ts +2 -3
- package/lib/ble/tacx/adapter.js +8 -8
- package/lib/ble/types.d.ts +1 -2
- package/lib/ble/wahoo/adapter.d.ts +2 -2
- package/lib/ble/wahoo/adapter.js +6 -6
- package/lib/ble/wahoo/comms.js +16 -16
- package/lib/factories/adapters.d.ts +7 -0
- package/lib/factories/adapters.js +49 -0
- package/lib/factories/index.d.ts +3 -0
- package/lib/factories/index.js +10 -0
- package/lib/factories/interfaces.d.ts +7 -0
- package/lib/factories/interfaces.js +27 -0
- package/lib/index.d.ts +8 -9
- package/lib/index.js +5 -8
- package/lib/interfaces.d.ts +1 -1
- package/lib/modes/ant-fe-adv-st-mode.d.ts +12 -0
- package/lib/modes/ant-fe-adv-st-mode.js +83 -0
- package/lib/modes/antble-erg.d.ts +31 -0
- package/lib/modes/antble-erg.js +28 -0
- package/lib/modes/antble-smarttrainer.d.ts +23 -0
- package/lib/modes/antble-smarttrainer.js +65 -0
- package/lib/modes/base.d.ts +29 -0
- package/lib/modes/{cycling-mode.js → base.js} +23 -26
- package/lib/modes/daum-classic-standard.d.ts +17 -0
- package/lib/modes/daum-classic-standard.js +54 -0
- package/lib/modes/daum-erg.d.ts +49 -0
- package/lib/{serial/daum/ERGCyclingMode.js → modes/daum-erg.js} +45 -73
- package/lib/modes/daum-power.d.ts +5 -0
- package/lib/{serial/daum/DaumPowerMeterCyclingMode.js → modes/daum-power.js} +1 -10
- package/lib/modes/daum-premium-standard.d.ts +24 -0
- package/lib/{serial/daum/premium/modes/daum-classic.js → modes/daum-premium-standard.js} +26 -38
- package/lib/modes/daum-smarttrainer.d.ts +83 -0
- package/lib/{serial/daum/SmartTrainerCyclingMode.js → modes/daum-smarttrainer.js} +23 -26
- package/lib/modes/kettler-erg.d.ts +44 -0
- package/lib/{serial/kettler/ergo-racer/modes/erg.js → modes/kettler-erg.js} +12 -23
- package/lib/modes/power-base.d.ts +28 -3
- package/lib/modes/power-base.js +184 -7
- package/lib/modes/power-meter.d.ts +11 -16
- package/lib/modes/power-meter.js +15 -54
- package/lib/modes/simulator.d.ts +38 -10
- package/lib/modes/simulator.js +14 -46
- package/lib/modes/{cycling-mode.d.ts → types.d.ts} +22 -30
- package/lib/modes/types.js +56 -0
- package/lib/serial/SinglePathScanner.d.ts +17 -0
- package/lib/serial/SinglePathScanner.js +87 -0
- package/lib/serial/adapter-factory.d.ts +8 -6
- package/lib/serial/adapter.d.ts +6 -11
- package/lib/serial/adapter.js +5 -2
- package/lib/serial/base/adapter.d.ts +17 -0
- package/lib/serial/base/adapter.js +67 -0
- package/lib/serial/base/comms.d.ts +62 -0
- package/lib/serial/base/comms.js +280 -0
- package/lib/serial/base/serial-interface.d.ts +36 -0
- package/lib/serial/base/serial-interface.js +288 -0
- package/lib/serial/base/serial-scanner.d.ts +16 -0
- package/lib/serial/base/serial-scanner.js +87 -0
- package/lib/serial/base/serialport.d.ts +17 -0
- package/lib/serial/base/serialport.js +87 -0
- package/lib/serial/comms.d.ts +2 -2
- package/lib/serial/daum/DaumAdapter.d.ts +26 -35
- package/lib/serial/daum/DaumAdapter.js +214 -161
- package/lib/serial/daum/classic/PROTOCOL_NAME.d.ts +2 -0
- package/lib/serial/daum/classic/PROTOCOL_NAME.js +5 -0
- package/lib/serial/daum/classic/adapter.d.ts +13 -26
- package/lib/serial/daum/classic/adapter.js +72 -176
- package/lib/serial/daum/classic/comms.d.ts +21 -17
- package/lib/serial/daum/classic/comms.js +41 -14
- package/lib/serial/daum/classic/consts.d.ts +2 -0
- package/lib/serial/daum/classic/consts.js +5 -0
- package/lib/serial/daum/classic/mock.d.ts +4 -0
- package/lib/serial/daum/classic/mock.js +18 -7
- package/lib/serial/daum/classic/types.d.ts +8 -10
- package/lib/serial/daum/classic/utils.d.ts +1 -2
- package/lib/serial/daum/consts.d.ts +0 -0
- package/lib/serial/daum/consts.js +0 -0
- package/lib/serial/daum/premium/adapter.d.ts +17 -15
- package/lib/serial/daum/premium/adapter.js +86 -109
- package/lib/serial/daum/premium/comms.d.ts +7 -7
- package/lib/serial/daum/premium/comms.js +25 -16
- package/lib/serial/daum/premium/mock.d.ts +5 -1
- package/lib/serial/daum/premium/mock.js +17 -7
- package/lib/serial/daum/premium/types.d.ts +32 -17
- package/lib/serial/daum/premium/types.js +8 -8
- package/lib/serial/daum/premium/utils.d.ts +2 -3
- package/lib/serial/daum/premium/utils.js +3 -3
- package/lib/serial/daum/types.d.ts +14 -0
- package/lib/serial/daum/types.js +13 -0
- package/lib/serial/factories/adapter-factory.d.ts +14 -0
- package/lib/serial/factories/adapter-factory.js +30 -0
- package/lib/serial/index.d.ts +8 -5
- package/lib/serial/index.js +15 -15
- package/lib/serial/kettler/comms.d.ts +1 -1
- package/lib/serial/kettler/ergo-racer/adapter.d.ts +11 -16
- package/lib/serial/kettler/ergo-racer/adapter.js +10 -12
- package/lib/serial/kettler/types.d.ts +8 -0
- package/lib/serial/kettler/types.js +2 -0
- package/lib/serial/serial-interface.d.ts +2 -32
- package/lib/serial/serial-interface.js +4 -78
- package/lib/serial/serial-scanner.d.ts +16 -0
- package/lib/serial/serial-scanner.js +87 -0
- package/lib/serial/serialport.d.ts +1 -13
- package/lib/serial/types.d.ts +45 -0
- package/lib/serial/types.js +9 -0
- package/lib/simulator/Simulator.d.ts +13 -19
- package/lib/simulator/Simulator.js +10 -51
- package/lib/types/Command.d.ts +8 -0
- package/lib/types/Command.js +2 -0
- package/lib/types/adapter.d.ts +34 -24
- package/lib/types/command.d.ts +0 -8
- package/lib/types/command.js +0 -2
- package/lib/types/data.d.ts +12 -1
- package/lib/types/device.d.ts +8 -23
- package/lib/types/device.js +9 -8
- package/lib/types/index.d.ts +6 -0
- package/lib/types/index.js +22 -0
- package/lib/types/route.d.ts +0 -19
- package/lib/types/route.js +0 -2
- package/lib/types/types.d.ts +8 -0
- package/lib/types/types.js +2 -0
- package/lib/utils/utils.d.ts +2 -1
- package/lib/utils/utils.js +22 -4
- package/package.json +3 -3
- package/lib/antv2/modes/ant-fe-adv-st-mode.d.ts +0 -9
- package/lib/antv2/modes/ant-fe-adv-st-mode.js +0 -51
- package/lib/antv2/modes/ant-fe-erg-mode.d.ts +0 -6
- package/lib/antv2/modes/ant-fe-erg-mode.js +0 -14
- package/lib/antv2/modes/ant-fe-st-mode.d.ts +0 -5
- package/lib/antv2/modes/ant-fe-st-mode.js +0 -13
- package/lib/modes/ble-erg-mode.d.ts +0 -18
- package/lib/modes/ble-erg-mode.js +0 -148
- package/lib/modes/ble-st-mode.d.ts +0 -15
- package/lib/modes/ble-st-mode.js +0 -96
- package/lib/serial/daum/DaumPowerMeterCyclingMode.d.ts +0 -8
- package/lib/serial/daum/ERGCyclingMode.d.ts +0 -26
- package/lib/serial/daum/SmartTrainerCyclingMode.d.ts +0 -42
- package/lib/serial/daum/classic/modes/daum-classic.d.ts +0 -13
- package/lib/serial/daum/classic/modes/daum-classic.js +0 -97
- package/lib/serial/daum/constants.d.ts +0 -19
- package/lib/serial/daum/constants.js +0 -22
- package/lib/serial/daum/premium/modes/daum-classic.d.ts +0 -14
- package/lib/serial/kettler/ergo-racer/modes/erg.d.ts +0 -25
package/lib/adapters.d.ts
CHANGED
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import { Profile } from "incyclist-ant-plus";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
export type AntAdapterInfo = {
|
|
6
|
-
antProfile: Profile;
|
|
7
|
-
incyclistProfile: LegacyProfile;
|
|
8
|
-
Adapter: typeof AntAdapter<BaseDeviceData, DeviceData>;
|
|
9
|
-
};
|
|
10
|
-
export type AdapterQuery = {
|
|
11
|
-
antProfile?: Profile;
|
|
12
|
-
incyclistProfile?: LegacyProfile;
|
|
13
|
-
};
|
|
2
|
+
import AntAdapter from "./base/adapter";
|
|
3
|
+
import { AntDeviceProperties, AntDeviceSettings, LegacyProfile, BaseDeviceData } from "./types";
|
|
4
|
+
import { AntAdapterInfo, AdapterQuery } from "./types";
|
|
14
5
|
export default class AntAdapterFactory {
|
|
15
6
|
static _instance: AntAdapterFactory;
|
|
16
7
|
adapters: AntAdapterInfo[];
|
|
17
8
|
static getInstance(): AntAdapterFactory;
|
|
18
9
|
constructor();
|
|
19
|
-
register<TDeviceData extends BaseDeviceData
|
|
10
|
+
register<TDeviceData extends BaseDeviceData>(antProfile: Profile, incyclistProfile: LegacyProfile, Adapter: typeof AntAdapter<TDeviceData>): void;
|
|
20
11
|
getAdapter(query?: AdapterQuery): any;
|
|
21
12
|
createInstance(settings: AntDeviceSettings, props?: AntDeviceProperties): any;
|
|
22
13
|
createFromDetected(profile: Profile, deviceID: number, props?: AntDeviceProperties): any;
|
package/lib/antv2/adapter.d.ts
CHANGED
|
@@ -2,20 +2,11 @@
|
|
|
2
2
|
import { IChannel, ISensor, Profile } from 'incyclist-ant-plus';
|
|
3
3
|
import AntInterface from './ant-interface';
|
|
4
4
|
import IncyclistDevice from '../base/adpater';
|
|
5
|
-
import { AntDeviceProperties, AntDeviceSettings } from './types';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import CyclingMode from '../modes/cycling-mode';
|
|
9
|
-
import { User } from '../types/user';
|
|
10
|
-
export declare const DEFAULT_UPDATE_FREQUENCY = 1000;
|
|
11
|
-
export type BaseDeviceData = {
|
|
12
|
-
DeviceID: number;
|
|
13
|
-
ManId?: number;
|
|
14
|
-
};
|
|
15
|
-
export default class AntAdapter<TDeviceData extends BaseDeviceData, TData> extends IncyclistDevice {
|
|
5
|
+
import { AntDeviceProperties, AntDeviceSettings, BaseDeviceData } from './types';
|
|
6
|
+
import { IAdapter, IncyclistAdapterData, IncyclistBikeData } from '../types';
|
|
7
|
+
export default class AntAdapter<TDeviceData extends BaseDeviceData> extends IncyclistDevice<AntDeviceProperties> {
|
|
16
8
|
sensor: ISensor;
|
|
17
|
-
|
|
18
|
-
data: TData;
|
|
9
|
+
data: IncyclistAdapterData;
|
|
19
10
|
deviceData: TDeviceData;
|
|
20
11
|
updateFrequency: number;
|
|
21
12
|
channel: IChannel;
|
|
@@ -26,46 +17,38 @@ export default class AntAdapter<TDeviceData extends BaseDeviceData, TData> exten
|
|
|
26
17
|
bikeSettings: {
|
|
27
18
|
weight?: number;
|
|
28
19
|
};
|
|
29
|
-
onDataFn: (data:
|
|
20
|
+
onDataFn: (data: IncyclistAdapterData) => void;
|
|
30
21
|
startupRetryPause: number;
|
|
31
22
|
protected ivDataTimeout: NodeJS.Timeout;
|
|
32
23
|
protected lastDataTS: number;
|
|
33
24
|
protected dataMsgCount: number;
|
|
34
25
|
protected ivWaitForData: NodeJS.Timeout;
|
|
35
|
-
constructor(settings: AntDeviceSettings, props?:
|
|
36
|
-
logEvent(event: any): void;
|
|
26
|
+
constructor(settings: AntDeviceSettings, props?: AntDeviceProperties);
|
|
37
27
|
createSensor(settings: AntDeviceSettings): ISensor;
|
|
38
28
|
isEqual(settings: AntDeviceSettings): boolean;
|
|
39
29
|
connect(): Promise<boolean>;
|
|
40
30
|
close(): Promise<boolean>;
|
|
41
31
|
resetData(): void;
|
|
42
|
-
isSame(device:
|
|
32
|
+
isSame(device: IAdapter): boolean;
|
|
43
33
|
hasData(): boolean;
|
|
44
|
-
|
|
45
|
-
|
|
34
|
+
mapData(deviceData: TDeviceData): IncyclistBikeData;
|
|
35
|
+
transformData(data: IncyclistBikeData): void;
|
|
36
|
+
mapToAdapterData(deviceData: any): void;
|
|
37
|
+
onDeviceData(deviceData: TDeviceData): void;
|
|
38
|
+
isWaitingForData(): boolean;
|
|
39
|
+
waitForData(timeout: number): Promise<boolean>;
|
|
46
40
|
getID(): string;
|
|
47
41
|
getName(): string;
|
|
48
42
|
getInterface(): string;
|
|
49
43
|
getProfile(): Profile;
|
|
44
|
+
getLogData(data: any, excludeList: any): any;
|
|
45
|
+
triggerTimeoutCheck(): void;
|
|
50
46
|
startDataTimeoutCheck(): void;
|
|
51
47
|
stopDataTimeoutCheck(): void;
|
|
52
48
|
check(): Promise<boolean>;
|
|
53
49
|
checkCapabilities(): Promise<void>;
|
|
54
50
|
initControl(): Promise<void>;
|
|
51
|
+
sendUpdate(request: any): void;
|
|
55
52
|
start(props?: AntDeviceProperties): Promise<boolean>;
|
|
56
53
|
stop(): Promise<boolean>;
|
|
57
54
|
}
|
|
58
|
-
export declare class ControllableAntAdapter<TDeviceData extends BaseDeviceData, TData> extends AntAdapter<TDeviceData, TData> implements Bike {
|
|
59
|
-
cyclingMode: CyclingMode;
|
|
60
|
-
user?: User;
|
|
61
|
-
constructor(settings: AntDeviceSettings, props?: AntDeviceProperties);
|
|
62
|
-
isControllable(): boolean;
|
|
63
|
-
setUser(user: User): void;
|
|
64
|
-
setBikeProps(props: DeviceProperties): void;
|
|
65
|
-
getWeight(): number;
|
|
66
|
-
getSupportedCyclingModes(): any[];
|
|
67
|
-
getDefaultCyclingMode(): CyclingMode;
|
|
68
|
-
setCyclingMode(mode: CyclingMode | string, settings?: any): void;
|
|
69
|
-
sendInitCommands(): Promise<boolean>;
|
|
70
|
-
getCyclingMode(): CyclingMode;
|
|
71
|
-
}
|
package/lib/antv2/adapter.js
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -35,16 +12,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
13
|
};
|
|
37
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.ControllableAntAdapter = exports.DEFAULT_UPDATE_FREQUENCY = void 0;
|
|
39
15
|
const ant_interface_1 = __importDefault(require("./ant-interface"));
|
|
40
|
-
const adpater_1 =
|
|
16
|
+
const adpater_1 = __importDefault(require("../base/adpater"));
|
|
41
17
|
const types_1 = require("./types");
|
|
18
|
+
const types_2 = require("../types");
|
|
42
19
|
const utils_1 = require("../utils/utils");
|
|
43
|
-
const capabilities_1 = require("../types/capabilities");
|
|
44
|
-
const adpater_2 = require("../base/adpater");
|
|
45
20
|
const utils_2 = require("./utils");
|
|
46
|
-
|
|
47
|
-
const NO_DATA_TIMEOUT = 5000;
|
|
21
|
+
const consts_1 = require("./consts");
|
|
48
22
|
const INTERFACE_NAME = 'ant';
|
|
49
23
|
class AntAdapter extends adpater_1.default {
|
|
50
24
|
constructor(settings, props) {
|
|
@@ -59,20 +33,10 @@ class AntAdapter extends adpater_1.default {
|
|
|
59
33
|
this.deviceData = {};
|
|
60
34
|
this.data = {};
|
|
61
35
|
this.dataMsgCount = 0;
|
|
62
|
-
this.updateFrequency =
|
|
36
|
+
this.updateFrequency = consts_1.DEFAULT_UPDATE_FREQUENCY;
|
|
63
37
|
this.channel = undefined;
|
|
64
38
|
this.ant = ant_interface_1.default.getInstance();
|
|
65
39
|
}
|
|
66
|
-
logEvent(event) {
|
|
67
|
-
if (!this.logger || this.paused)
|
|
68
|
-
return;
|
|
69
|
-
this.logger.logEvent(event);
|
|
70
|
-
const w = global.window;
|
|
71
|
-
if ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || process.env.BLE_DEBUG || process.env.ANT_DEBUG) {
|
|
72
|
-
const logText = '~~~ ANT:' + this.logger.getName();
|
|
73
|
-
console.log(logText, event);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
40
|
createSensor(settings) {
|
|
77
41
|
throw new Error('Method not implemented.');
|
|
78
42
|
}
|
|
@@ -110,13 +74,49 @@ class AntAdapter extends adpater_1.default {
|
|
|
110
74
|
hasData() {
|
|
111
75
|
return this.dataMsgCount > 0;
|
|
112
76
|
}
|
|
77
|
+
mapData(deviceData) {
|
|
78
|
+
throw new Error('message not implemented');
|
|
79
|
+
}
|
|
80
|
+
transformData(data) {
|
|
81
|
+
throw new Error('message not implemented');
|
|
82
|
+
}
|
|
83
|
+
mapToAdapterData(deviceData) {
|
|
84
|
+
throw new Error('message not implemented');
|
|
85
|
+
}
|
|
113
86
|
onDeviceData(deviceData) {
|
|
114
|
-
|
|
115
|
-
this.
|
|
116
|
-
|
|
117
|
-
|
|
87
|
+
this.dataMsgCount++;
|
|
88
|
+
this.lastDataTS = Date.now();
|
|
89
|
+
try {
|
|
90
|
+
const { ManId } = this.deviceData;
|
|
91
|
+
this.deviceData = Object.assign({}, deviceData);
|
|
92
|
+
if (!ManId && deviceData.ManId) {
|
|
93
|
+
this.emit('device-info', { device: this.getSettings(), manufacturer: (0, utils_2.getBrand)(deviceData.ManId) });
|
|
94
|
+
}
|
|
95
|
+
if (!this.started || this.isStopped())
|
|
96
|
+
return;
|
|
97
|
+
this.triggerTimeoutCheck();
|
|
98
|
+
if (!this.canEmitData())
|
|
99
|
+
return;
|
|
100
|
+
const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
|
|
101
|
+
this.logEvent({ message: 'onDeviceData', data: logData, paused: this.paused });
|
|
102
|
+
if (this.isControllable()) {
|
|
103
|
+
let incyclistData = this.mapData(deviceData);
|
|
104
|
+
incyclistData = this.getCyclingMode().updateData(incyclistData);
|
|
105
|
+
this.transformData(incyclistData);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
this.mapToAdapterData(deviceData);
|
|
109
|
+
}
|
|
110
|
+
this.emitData(this.data);
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
console.log('~~~ERROR', err);
|
|
114
|
+
this.logEvent({ message: 'error', fn: 'onDeviceData()', error: err.message || err, stack: err.stack });
|
|
118
115
|
}
|
|
119
116
|
}
|
|
117
|
+
isWaitingForData() {
|
|
118
|
+
return this.ivWaitForData !== undefined && this.ivWaitForData !== null;
|
|
119
|
+
}
|
|
120
120
|
waitForData(timeout) {
|
|
121
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
122
|
const startTs = Date.now();
|
|
@@ -162,13 +162,25 @@ class AntAdapter extends adpater_1.default {
|
|
|
162
162
|
return (0, utils_2.mapLegacyProfile)(settings.profile);
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
+
getLogData(data, excludeList) {
|
|
166
|
+
const logData = JSON.parse(JSON.stringify(data));
|
|
167
|
+
excludeList.forEach((key) => {
|
|
168
|
+
delete logData[key];
|
|
169
|
+
});
|
|
170
|
+
return logData;
|
|
171
|
+
}
|
|
172
|
+
triggerTimeoutCheck() {
|
|
173
|
+
if (!this.ivDataTimeout && this.dataMsgCount > 0) {
|
|
174
|
+
this.startDataTimeoutCheck();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
165
177
|
startDataTimeoutCheck() {
|
|
166
178
|
if (this.ivDataTimeout)
|
|
167
179
|
return;
|
|
168
180
|
this.ivDataTimeout = setInterval(() => {
|
|
169
181
|
if (!this.lastDataTS)
|
|
170
182
|
return;
|
|
171
|
-
if (this.lastDataTS + NO_DATA_TIMEOUT < Date.now()) {
|
|
183
|
+
if (this.lastDataTS + consts_1.NO_DATA_TIMEOUT < Date.now()) {
|
|
172
184
|
this.emit('disconnected', Date.now() - this.lastDataTS);
|
|
173
185
|
}
|
|
174
186
|
}, 1000);
|
|
@@ -201,6 +213,16 @@ class AntAdapter extends adpater_1.default {
|
|
|
201
213
|
return;
|
|
202
214
|
});
|
|
203
215
|
}
|
|
216
|
+
sendUpdate(request) {
|
|
217
|
+
if (!this.isControllable())
|
|
218
|
+
return;
|
|
219
|
+
if (this.isPaused() || this.isStopped())
|
|
220
|
+
return;
|
|
221
|
+
if (!this.hasCapability(types_2.IncyclistCapability.Control))
|
|
222
|
+
this.getCyclingMode().sendBikeUpdate(request);
|
|
223
|
+
else
|
|
224
|
+
throw new Error('method not implemented');
|
|
225
|
+
}
|
|
204
226
|
start(props = {}) {
|
|
205
227
|
return __awaiter(this, void 0, void 0, function* () {
|
|
206
228
|
if (this.started && !this.stopped) {
|
|
@@ -236,7 +258,7 @@ class AntAdapter extends adpater_1.default {
|
|
|
236
258
|
try {
|
|
237
259
|
yield this.waitForData(startupTimeout - 100);
|
|
238
260
|
yield this.checkCapabilities();
|
|
239
|
-
if (this.hasCapability(
|
|
261
|
+
if (this.hasCapability(types_2.IncyclistCapability.Control))
|
|
240
262
|
yield this.initControl();
|
|
241
263
|
this.started = true;
|
|
242
264
|
if (to)
|
|
@@ -267,69 +289,3 @@ class AntAdapter extends adpater_1.default {
|
|
|
267
289
|
}
|
|
268
290
|
}
|
|
269
291
|
exports.default = AntAdapter;
|
|
270
|
-
class ControllableAntAdapter extends AntAdapter {
|
|
271
|
-
constructor(settings, props) {
|
|
272
|
-
super(settings, props);
|
|
273
|
-
this.cyclingMode = this.getDefaultCyclingMode();
|
|
274
|
-
this.user = {};
|
|
275
|
-
}
|
|
276
|
-
isControllable() {
|
|
277
|
-
return true;
|
|
278
|
-
}
|
|
279
|
-
setUser(user) {
|
|
280
|
-
this.user = user;
|
|
281
|
-
if (!user.weight)
|
|
282
|
-
this.user.weight = adpater_2.DEFAULT_USER_WEIGHT;
|
|
283
|
-
}
|
|
284
|
-
setBikeProps(props) {
|
|
285
|
-
const { user, userWeight } = props || {};
|
|
286
|
-
if (user)
|
|
287
|
-
this.setUser(user);
|
|
288
|
-
if (userWeight)
|
|
289
|
-
this.user.weight = userWeight;
|
|
290
|
-
const keys = Object.keys(props);
|
|
291
|
-
keys.forEach(k => {
|
|
292
|
-
const p = props[k];
|
|
293
|
-
if (p === null)
|
|
294
|
-
delete this.props[k];
|
|
295
|
-
else if (p !== undefined)
|
|
296
|
-
this.props[k] = p;
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
getWeight() {
|
|
300
|
-
const { user = {}, props = adpater_2.DEFAULT_PROPS } = this;
|
|
301
|
-
const userWeight = user.weight || props.userWeight || adpater_2.DEFAULT_USER_WEIGHT;
|
|
302
|
-
const bikeWeight = props.bikeWeight || adpater_1.DEFAULT_BIKE_WEIGHT;
|
|
303
|
-
return userWeight + bikeWeight;
|
|
304
|
-
}
|
|
305
|
-
getSupportedCyclingModes() { throw new Error('not implemented'); }
|
|
306
|
-
getDefaultCyclingMode() { throw new Error('not implemented'); }
|
|
307
|
-
setCyclingMode(mode, settings) {
|
|
308
|
-
let selectedMode;
|
|
309
|
-
if (typeof mode === 'string') {
|
|
310
|
-
const supported = this.getSupportedCyclingModes();
|
|
311
|
-
const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
|
|
312
|
-
if (CyclingModeClass) {
|
|
313
|
-
this.cyclingMode = new CyclingModeClass(this, settings);
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
selectedMode = this.getDefaultCyclingMode();
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
selectedMode = mode;
|
|
320
|
-
}
|
|
321
|
-
this.cyclingMode = selectedMode;
|
|
322
|
-
this.cyclingMode.setSettings(settings);
|
|
323
|
-
}
|
|
324
|
-
sendInitCommands() {
|
|
325
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
326
|
-
return true;
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
getCyclingMode() {
|
|
330
|
-
if (!this.cyclingMode)
|
|
331
|
-
this.setCyclingMode(this.getDefaultCyclingMode());
|
|
332
|
-
return this.cyclingMode;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
exports.ControllableAntAdapter = ControllableAntAdapter;
|
|
@@ -2,17 +2,9 @@
|
|
|
2
2
|
import EventEmitter from "events";
|
|
3
3
|
import { EventLogger } from "gd-eventlog";
|
|
4
4
|
import { IAntDevice, IChannel, ISensor } from "incyclist-ant-plus";
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import { AntDeviceSettings, AntScanProps } from "./types";
|
|
9
|
-
export interface AntInterfaceProps extends InterfaceProps {
|
|
10
|
-
startupTimeout?: number;
|
|
11
|
-
}
|
|
12
|
-
export interface ConnectState {
|
|
13
|
-
connected: boolean;
|
|
14
|
-
connecting: boolean;
|
|
15
|
-
}
|
|
5
|
+
import { AntDeviceSettings, AntScanProps, AntInterfaceProps, ConnectState } from "./types";
|
|
6
|
+
import { IncyclistInterface } from "../types";
|
|
7
|
+
import AntDeviceBinding from "./base/binding";
|
|
16
8
|
export default class AntInterface extends EventEmitter implements IncyclistInterface {
|
|
17
9
|
static _instance: AntInterface;
|
|
18
10
|
static INTERFACE_NAME: string;
|
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const events_1 = __importDefault(require("events"));
|
|
16
16
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
17
|
-
const sensor_factory_1 = __importDefault(require("./sensor-factory"));
|
|
17
|
+
const sensor_factory_1 = __importDefault(require("./factories/sensor-factory"));
|
|
18
18
|
class AntInterface extends events_1.default {
|
|
19
19
|
static getInstance(props = {}) {
|
|
20
20
|
if (AntInterface._instance === undefined)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IChannel, ISensor, Profile } from 'incyclist-ant-plus';
|
|
3
|
+
import AntInterface from './ant-interface';
|
|
4
|
+
import IncyclistDevice from '../../base/adpater';
|
|
5
|
+
import { AntDeviceProperties, AntDeviceSettings, LegacyProfile, BaseDeviceData } from '../types';
|
|
6
|
+
import { IAdapter, IncyclistAdapterData, IncyclistBikeData } from '../../types';
|
|
7
|
+
export default class AntAdapter<TDeviceData extends BaseDeviceData> extends IncyclistDevice<AntDeviceProperties> {
|
|
8
|
+
sensor: ISensor;
|
|
9
|
+
data: IncyclistAdapterData;
|
|
10
|
+
deviceData: TDeviceData;
|
|
11
|
+
updateFrequency: number;
|
|
12
|
+
channel: IChannel;
|
|
13
|
+
ant: AntInterface;
|
|
14
|
+
userSettings: {
|
|
15
|
+
weight?: number;
|
|
16
|
+
};
|
|
17
|
+
bikeSettings: {
|
|
18
|
+
weight?: number;
|
|
19
|
+
};
|
|
20
|
+
onDataFn: (data: IncyclistAdapterData) => void;
|
|
21
|
+
startupRetryPause: number;
|
|
22
|
+
protected ivDataTimeout: NodeJS.Timeout;
|
|
23
|
+
protected lastDataTS: number;
|
|
24
|
+
protected dataMsgCount: number;
|
|
25
|
+
protected ivWaitForData: NodeJS.Timeout;
|
|
26
|
+
protected promiseWaitForData: Promise<boolean>;
|
|
27
|
+
constructor(settings: AntDeviceSettings, props?: AntDeviceProperties);
|
|
28
|
+
getProfileName(): Profile;
|
|
29
|
+
getLegacyProfileName(): LegacyProfile;
|
|
30
|
+
createSensor(settings: AntDeviceSettings): ISensor;
|
|
31
|
+
isEqual(settings: AntDeviceSettings): boolean;
|
|
32
|
+
connect(): Promise<boolean>;
|
|
33
|
+
close(): Promise<boolean>;
|
|
34
|
+
resetData(): void;
|
|
35
|
+
isSame(device: IAdapter): boolean;
|
|
36
|
+
hasData(): boolean;
|
|
37
|
+
mapData(deviceData: TDeviceData): IncyclistBikeData;
|
|
38
|
+
transformData(data: IncyclistBikeData, deviceData: TDeviceData): void;
|
|
39
|
+
mapToAdapterData(deviceData: any): void;
|
|
40
|
+
onDeviceData(deviceData: TDeviceData): void;
|
|
41
|
+
isWaitingForData(): boolean;
|
|
42
|
+
_wait(): Promise<boolean>;
|
|
43
|
+
waitForData(timeout: number): Promise<boolean>;
|
|
44
|
+
getID(): string;
|
|
45
|
+
getName(): string;
|
|
46
|
+
getUniqueName(): string;
|
|
47
|
+
getDisplayName(): string;
|
|
48
|
+
getInterface(): string;
|
|
49
|
+
getProfile(): Profile;
|
|
50
|
+
getLogData(data: any, excludeList: any): any;
|
|
51
|
+
triggerTimeoutCheck(): void;
|
|
52
|
+
startDataTimeoutCheck(): void;
|
|
53
|
+
stopDataTimeoutCheck(): void;
|
|
54
|
+
check(): Promise<boolean>;
|
|
55
|
+
checkCapabilities(): Promise<void>;
|
|
56
|
+
initControl(): Promise<void>;
|
|
57
|
+
getDefaultStartupTimeout(): number;
|
|
58
|
+
sendUpdate(request: any): void;
|
|
59
|
+
start(props?: AntDeviceProperties): Promise<boolean>;
|
|
60
|
+
stop(): Promise<boolean>;
|
|
61
|
+
startSensor(): Promise<boolean>;
|
|
62
|
+
}
|