incyclist-devices 2.0.0-beta.1 → 2.0.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/README.MD +238 -0
- package/lib/adapters.d.ts +1 -0
- package/lib/adapters.js +19 -0
- package/lib/antv2/adapter-factory.d.ts +8 -7
- package/lib/antv2/adapter-factory.js +4 -2
- package/lib/antv2/adapter.d.ts +3 -2
- package/lib/antv2/adapter.js +15 -4
- package/lib/antv2/ant-interface.d.ts +6 -2
- package/lib/antv2/ant-interface.js +27 -21
- package/lib/antv2/binding.d.ts +1 -1
- package/lib/antv2/binding.js +1 -1
- package/lib/antv2/fe/adapter.d.ts +12 -9
- package/lib/antv2/fe/adapter.js +67 -27
- package/lib/antv2/hr/adapter.d.ts +6 -5
- package/lib/antv2/hr/adapter.js +19 -16
- package/lib/antv2/index.d.ts +2 -2
- package/lib/antv2/pwr/adapter.d.ts +6 -4
- package/lib/antv2/pwr/adapter.js +24 -16
- package/lib/antv2/sensor-factory.d.ts +2 -2
- package/lib/antv2/types.d.ts +5 -2
- package/lib/antv2/types.js +3 -0
- package/lib/antv2/utils.d.ts +3 -0
- package/lib/antv2/utils.js +12 -1
- package/lib/base/adpater.d.ts +14 -2
- package/lib/base/adpater.js +43 -4
- package/lib/ble/adapter-factory.d.ts +18 -16
- package/lib/ble/adapter-factory.js +54 -45
- package/lib/ble/base/adapter.d.ts +53 -0
- package/lib/ble/{adapter.js → base/adapter.js} +111 -9
- package/lib/ble/base/comms-utils.d.ts +7 -0
- package/lib/ble/base/comms-utils.js +91 -0
- package/lib/ble/{ble-comms.d.ts → base/comms.d.ts} +27 -17
- package/lib/ble/{ble-comms.js → base/comms.js} +179 -53
- package/lib/ble/bindings/index.d.ts +2 -0
- package/lib/ble/bindings/index.js +8 -0
- package/lib/ble/bindings/linux.d.ts +15 -0
- package/lib/ble/bindings/linux.js +39 -0
- package/lib/ble/bindings/mock.d.ts +9 -0
- package/lib/ble/bindings/mock.js +108 -0
- package/lib/ble/bindings/types.d.ts +57 -0
- package/lib/ble/bindings/types.js +96 -0
- package/lib/ble/ble-interface.d.ts +34 -46
- package/lib/ble/ble-interface.js +242 -345
- package/lib/ble/ble-peripheral.d.ts +4 -2
- package/lib/ble/ble-peripheral.js +39 -8
- package/lib/ble/consts.d.ts +1 -0
- package/lib/ble/consts.js +2 -1
- package/lib/ble/cp/adapter.d.ts +1 -2
- package/lib/ble/cp/adapter.js +2 -15
- package/lib/ble/cp/comm.d.ts +8 -5
- package/lib/ble/cp/comm.js +12 -27
- package/lib/ble/elite/adapter.d.ts +1 -2
- package/lib/ble/elite/adapter.js +12 -19
- package/lib/ble/elite/comms.d.ts +8 -4
- package/lib/ble/elite/comms.js +12 -25
- package/lib/ble/fm/adapter.d.ts +3 -2
- package/lib/ble/fm/adapter.js +129 -70
- package/lib/ble/fm/comms.d.ts +8 -8
- package/lib/ble/fm/comms.js +33 -55
- package/lib/ble/fm/types.d.ts +5 -0
- package/lib/ble/hr/adapter.d.ts +1 -4
- package/lib/ble/hr/adapter.js +1 -18
- package/lib/ble/hr/comm.d.ts +6 -2
- package/lib/ble/hr/comm.js +6 -2
- package/lib/ble/hr/mock.d.ts +7 -0
- package/lib/ble/hr/mock.js +47 -0
- package/lib/ble/index.d.ts +2 -1
- package/lib/ble/index.js +5 -5
- package/lib/ble/peripheral-cache.d.ts +43 -0
- package/lib/ble/peripheral-cache.js +107 -0
- package/lib/ble/tacx/adapter.d.ts +1 -1
- package/lib/ble/tacx/adapter.js +20 -14
- package/lib/ble/tacx/comms.d.ts +6 -6
- package/lib/ble/tacx/comms.js +10 -43
- package/lib/ble/types.d.ts +54 -27
- package/lib/ble/types.js +0 -17
- package/lib/ble/utils.d.ts +15 -5
- package/lib/ble/utils.js +25 -66
- package/lib/ble/wahoo/adapter.d.ts +1 -1
- package/lib/ble/wahoo/adapter.js +12 -10
- package/lib/ble/wahoo/comms.d.ts +7 -6
- package/lib/ble/wahoo/comms.js +15 -17
- package/lib/index.d.ts +10 -7
- package/lib/index.js +21 -25
- package/lib/interfaces.d.ts +2 -1
- package/lib/interfaces.js +4 -0
- package/lib/modes/power-base.js +4 -0
- package/lib/serial/adapter.d.ts +5 -0
- package/lib/serial/adapter.js +19 -0
- package/lib/serial/bindings/tcp.d.ts +2 -1
- package/lib/serial/bindings/tcp.js +19 -5
- package/lib/serial/daum/DaumAdapter.d.ts +1 -1
- package/lib/serial/daum/DaumAdapter.js +16 -10
- package/lib/serial/daum/premium/adapter.d.ts +1 -0
- package/lib/serial/daum/premium/adapter.js +9 -2
- package/lib/serial/daum/premium/comms.js +10 -3
- package/lib/serial/daum/premium/mock.js +0 -1
- package/lib/serial/index.d.ts +3 -3
- package/lib/serial/index.js +2 -2
- package/lib/serial/kettler/ergo-racer/adapter.d.ts +1 -4
- package/lib/serial/kettler/ergo-racer/adapter.js +15 -39
- package/lib/serial/serial-interface.d.ts +3 -1
- package/lib/serial/serial-interface.js +43 -17
- package/lib/simulator/Simulator.d.ts +2 -0
- package/lib/simulator/Simulator.js +8 -5
- package/lib/types/adapter.d.ts +10 -3
- package/lib/types/device.d.ts +3 -0
- package/lib/types/interface.d.ts +7 -3
- package/package.json +3 -5
- package/lib/ble/adapter.d.ts +0 -41
- package/lib/ble/ble.d.ts +0 -57
- package/lib/ble/ble.js +0 -48
- package/lib/device.d.ts +0 -0
- package/lib/device.js +0 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BleCharacteristic, BlePeripheral, IBlePeripheralConnector } from './types';
|
|
2
|
-
import BleInterface from "./ble-interface";
|
|
3
2
|
export type ConnectorState = {
|
|
4
3
|
isConnected: boolean;
|
|
5
4
|
isConnecting: boolean;
|
|
@@ -16,7 +15,7 @@ export default class BlePeripheralConnector implements IBlePeripheralConnector {
|
|
|
16
15
|
private peripheral;
|
|
17
16
|
private logger?;
|
|
18
17
|
private emitter;
|
|
19
|
-
constructor(
|
|
18
|
+
constructor(peripheral: BlePeripheral);
|
|
20
19
|
logEvent(event: any): void;
|
|
21
20
|
connect(): Promise<void>;
|
|
22
21
|
reconnect(): Promise<void>;
|
|
@@ -25,8 +24,11 @@ export default class BlePeripheralConnector implements IBlePeripheralConnector {
|
|
|
25
24
|
isSubscribed(characteristicUuid: string): boolean;
|
|
26
25
|
subscribeAll(callback: (characteristicUuid: string, data: any) => void): Promise<string[]>;
|
|
27
26
|
subscribe(characteristicUuid: string, timeout?: number): Promise<boolean>;
|
|
27
|
+
unsubscribeAll(): void;
|
|
28
|
+
unubscribe(c: BleCharacteristic): void;
|
|
28
29
|
onData(characteristicUuid: string, data: any): void;
|
|
29
30
|
on(characteristicUuid: string, callback: (characteristicUuid: string, data: any) => void): void;
|
|
31
|
+
once(characteristicUuid: string, callback: (characteristicUuid: string, data: any) => void): void;
|
|
30
32
|
off(characteristicUuid: string, callback: (characteristicUuid: string, data: any) => void): void;
|
|
31
33
|
removeAllListeners(characteristicUuid: string): void;
|
|
32
34
|
getState(): string;
|
|
@@ -12,12 +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
|
+
const ble_interface_1 = __importDefault(require("./ble-interface"));
|
|
15
16
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
16
17
|
const events_1 = __importDefault(require("events"));
|
|
17
18
|
const utils_1 = require("./utils");
|
|
18
19
|
class BlePeripheralConnector {
|
|
19
|
-
constructor(
|
|
20
|
-
this.ble =
|
|
20
|
+
constructor(peripheral) {
|
|
21
|
+
this.ble = ble_interface_1.default.getInstance();
|
|
21
22
|
this.peripheral = peripheral;
|
|
22
23
|
this.emitter = new events_1.default();
|
|
23
24
|
if (!this.peripheral || !this.ble)
|
|
@@ -39,15 +40,15 @@ class BlePeripheralConnector {
|
|
|
39
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
41
|
if (this.state.isConnected)
|
|
41
42
|
return;
|
|
42
|
-
this.logEvent({ message: 'connect', peripheral: this.peripheral.address, state: this.state });
|
|
43
|
+
this.logEvent({ message: 'connect peripheral', peripheral: this.peripheral.address, state: this.state, peripheralState: this.peripheral.state });
|
|
43
44
|
this.state.isConnecting = true;
|
|
44
45
|
try {
|
|
45
|
-
this.peripheral.on('connect', () => { });
|
|
46
46
|
this.peripheral.on('disconnect', () => { this.onDisconnect(); });
|
|
47
47
|
if (!this.state.isConnected || (this.peripheral && this.peripheral.state !== 'connected')) {
|
|
48
48
|
yield this.peripheral.connectAsync();
|
|
49
49
|
}
|
|
50
50
|
this.state.isConnected = this.peripheral.state === 'connected';
|
|
51
|
+
return;
|
|
51
52
|
}
|
|
52
53
|
catch (err) {
|
|
53
54
|
this.logEvent({ message: 'Error', fn: 'connect()', error: err.message });
|
|
@@ -66,6 +67,8 @@ class BlePeripheralConnector {
|
|
|
66
67
|
this.logEvent({ message: 'onDisconnected', peripheral: this.peripheral.address, state: this.state });
|
|
67
68
|
this.state.isConnected = false;
|
|
68
69
|
this.state.isConnecting = false;
|
|
70
|
+
this.state.isInitialized = false;
|
|
71
|
+
this.state.isInitializing = false;
|
|
69
72
|
this.emitter.emit('disconnect');
|
|
70
73
|
}
|
|
71
74
|
initialize(enforce = false) {
|
|
@@ -81,13 +84,22 @@ class BlePeripheralConnector {
|
|
|
81
84
|
this.services = undefined;
|
|
82
85
|
try {
|
|
83
86
|
const res = yield this.peripheral.discoverSomeServicesAndCharacteristicsAsync([], []);
|
|
84
|
-
this.
|
|
85
|
-
|
|
87
|
+
if (this.state.isInitializing) {
|
|
88
|
+
this.characteristics = res.characteristics;
|
|
89
|
+
this.services = res.services.map(s => typeof (s) === 'string' ? s : s.uuid);
|
|
90
|
+
this.state.isInitializing = false;
|
|
91
|
+
this.state.isInitialized = this.characteristics !== undefined && this.services !== undefined;
|
|
92
|
+
this.logEvent({ message: 'initialize done', peripheral: this.peripheral.address, state: this.state });
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
this.logEvent({ message: 'initialize interrupted', peripheral: this.peripheral.address });
|
|
96
|
+
}
|
|
86
97
|
}
|
|
87
98
|
catch (err) {
|
|
99
|
+
this.logEvent({ message: 'error', fn: 'initialize', error: err.message, stack: err.stack });
|
|
100
|
+
this.state.isInitializing = false;
|
|
101
|
+
this.state.isInitialized = false;
|
|
88
102
|
}
|
|
89
|
-
this.state.isInitializing = false;
|
|
90
|
-
this.state.isInitialized = this.characteristics !== undefined && this.services !== undefined;
|
|
91
103
|
});
|
|
92
104
|
}
|
|
93
105
|
isSubscribed(characteristicUuid) {
|
|
@@ -170,6 +182,21 @@ class BlePeripheralConnector {
|
|
|
170
182
|
}
|
|
171
183
|
});
|
|
172
184
|
}
|
|
185
|
+
unsubscribeAll() {
|
|
186
|
+
var _a;
|
|
187
|
+
(_a = this.characteristics) === null || _a === void 0 ? void 0 : _a.forEach(c => {
|
|
188
|
+
const isNotify = c.properties.find(p => p === 'notify');
|
|
189
|
+
if (isNotify) {
|
|
190
|
+
this.unubscribe(c);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
this.state.isSubscribing = false;
|
|
194
|
+
this.state.subscribed = [];
|
|
195
|
+
}
|
|
196
|
+
unubscribe(c) {
|
|
197
|
+
c.unsubscribe(undefined);
|
|
198
|
+
c.removeAllListeners();
|
|
199
|
+
}
|
|
173
200
|
onData(characteristicUuid, data) {
|
|
174
201
|
this.emitter.emit((0, utils_1.uuid)(characteristicUuid), characteristicUuid, data);
|
|
175
202
|
}
|
|
@@ -177,6 +204,10 @@ class BlePeripheralConnector {
|
|
|
177
204
|
if (callback)
|
|
178
205
|
this.emitter.on((0, utils_1.uuid)(characteristicUuid), callback);
|
|
179
206
|
}
|
|
207
|
+
once(characteristicUuid, callback) {
|
|
208
|
+
if (callback)
|
|
209
|
+
this.emitter.once((0, utils_1.uuid)(characteristicUuid), callback);
|
|
210
|
+
}
|
|
180
211
|
off(characteristicUuid, callback) {
|
|
181
212
|
if (callback)
|
|
182
213
|
this.emitter.off((0, utils_1.uuid)(characteristicUuid), callback);
|
package/lib/ble/consts.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare const INDOOR_BIKE_DATA = "2ad2";
|
|
|
8
8
|
export declare const CSP = "1818";
|
|
9
9
|
export declare const CSP_MEASUREMENT = "2a63";
|
|
10
10
|
export declare const CSP_FEATURE = "2a65";
|
|
11
|
+
export declare const HR_MEASUREMENT = "2a37";
|
|
11
12
|
export declare const CSC = "1816";
|
|
12
13
|
export declare const CSC_MEASUREMENT = "2a5b";
|
|
13
14
|
export declare const WAHOO_ADVANCED_TRAINER_CP = "a026e005";
|
package/lib/ble/consts.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ELITE_TRAINER_SVC = exports.WAHOO_ADVANCED_TRAINER_CP_FULL = exports.WAHOO_ADVANCED_FTMS = exports.WAHOO_ADVANCED_TRAINER_CP = exports.CSC_MEASUREMENT = exports.CSC = exports.CSP_FEATURE = exports.CSP_MEASUREMENT = exports.CSP = exports.INDOOR_BIKE_DATA = exports.FTMS_STATUS = exports.FTMS_CP = exports.FTMS = exports.TACX_FE_C_TX = exports.TACX_FE_C_RX = exports.TACX_FE_C_BLE = void 0;
|
|
3
|
+
exports.ELITE_TRAINER_SVC = exports.WAHOO_ADVANCED_TRAINER_CP_FULL = exports.WAHOO_ADVANCED_FTMS = exports.WAHOO_ADVANCED_TRAINER_CP = exports.CSC_MEASUREMENT = exports.CSC = exports.HR_MEASUREMENT = exports.CSP_FEATURE = exports.CSP_MEASUREMENT = exports.CSP = exports.INDOOR_BIKE_DATA = exports.FTMS_STATUS = exports.FTMS_CP = exports.FTMS = exports.TACX_FE_C_TX = exports.TACX_FE_C_RX = exports.TACX_FE_C_BLE = void 0;
|
|
4
4
|
exports.TACX_FE_C_BLE = '6e40fec1';
|
|
5
5
|
exports.TACX_FE_C_RX = '6e40fec2';
|
|
6
6
|
exports.TACX_FE_C_TX = '6e40fec3';
|
|
@@ -11,6 +11,7 @@ exports.INDOOR_BIKE_DATA = '2ad2';
|
|
|
11
11
|
exports.CSP = '1818';
|
|
12
12
|
exports.CSP_MEASUREMENT = '2a63';
|
|
13
13
|
exports.CSP_FEATURE = '2a65';
|
|
14
|
+
exports.HR_MEASUREMENT = '2a37';
|
|
14
15
|
exports.CSC = '1816';
|
|
15
16
|
exports.CSC_MEASUREMENT = '2a5b';
|
|
16
17
|
exports.WAHOO_ADVANCED_TRAINER_CP = 'a026e005';
|
package/lib/ble/cp/adapter.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import CyclingMode from '../../modes/cycling-mode';
|
|
2
2
|
import { IncyclistBikeData } from '../../modes/cycling-mode';
|
|
3
|
-
import { BleControllableAdapter } from '../adapter';
|
|
3
|
+
import { BleControllableAdapter } from '../base/adapter';
|
|
4
4
|
import { DeviceProperties } from '../../types/device';
|
|
5
5
|
import { PowerData } from './types';
|
|
6
6
|
import { DeviceData } from '../../types/data';
|
|
@@ -15,7 +15,6 @@ export default class PwrAdapter extends BleControllableAdapter {
|
|
|
15
15
|
getDisplayName(): string;
|
|
16
16
|
getDefaultCyclingMode(): CyclingMode;
|
|
17
17
|
getSupportedCyclingModes(): any[];
|
|
18
|
-
onDeviceData(deviceData: PowerData): void;
|
|
19
18
|
mapData(deviceData: PowerData): IncyclistBikeData;
|
|
20
19
|
transformData(bikeData: IncyclistBikeData): DeviceData;
|
|
21
20
|
sendUpdate(request: any): Promise<void>;
|
package/lib/ble/cp/adapter.js
CHANGED
|
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
16
16
|
const power_meter_1 = __importDefault(require("../../modes/power-meter"));
|
|
17
17
|
const comm_1 = __importDefault(require("./comm"));
|
|
18
|
-
const adapter_1 = require("../adapter");
|
|
18
|
+
const adapter_1 = require("../base/adapter");
|
|
19
19
|
const capabilities_1 = require("../../types/capabilities");
|
|
20
20
|
class PwrAdapter extends adapter_1.BleControllableAdapter {
|
|
21
21
|
constructor(settings, props) {
|
|
@@ -25,7 +25,7 @@ class PwrAdapter extends adapter_1.BleControllableAdapter {
|
|
|
25
25
|
const { id, address, name } = settings;
|
|
26
26
|
const logger = this.logger;
|
|
27
27
|
const ble = this.ble;
|
|
28
|
-
this.device = new comm_1.default({ id, address, name,
|
|
28
|
+
this.device = new comm_1.default({ id, address, name, logger });
|
|
29
29
|
this.capabilities = [
|
|
30
30
|
capabilities_1.IncyclistCapability.Power, capabilities_1.IncyclistCapability.Cadence, capabilities_1.IncyclistCapability.Speed
|
|
31
31
|
];
|
|
@@ -53,19 +53,6 @@ class PwrAdapter extends adapter_1.BleControllableAdapter {
|
|
|
53
53
|
getSupportedCyclingModes() {
|
|
54
54
|
return [power_meter_1.default];
|
|
55
55
|
}
|
|
56
|
-
onDeviceData(deviceData) {
|
|
57
|
-
super.onDeviceData(deviceData);
|
|
58
|
-
if (!this.started || this.paused || !this.onDataFn)
|
|
59
|
-
return;
|
|
60
|
-
if (!this.lastUpdate || (Date.now() - this.lastUpdate) > this.updateFrequency) {
|
|
61
|
-
this.logger.logEvent({ message: 'onDeviceData', data: deviceData });
|
|
62
|
-
let incyclistData = this.mapData(deviceData);
|
|
63
|
-
incyclistData = this.getCyclingMode().updateData(incyclistData);
|
|
64
|
-
this.data = this.transformData(incyclistData);
|
|
65
|
-
this.onDataFn(this.data);
|
|
66
|
-
this.lastUpdate = Date.now();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
56
|
mapData(deviceData) {
|
|
70
57
|
const data = {
|
|
71
58
|
isPedalling: false,
|
package/lib/ble/cp/comm.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { BleComms } from '../ble-comms';
|
|
3
2
|
import { CrankData, PowerData } from './types';
|
|
3
|
+
import { BleComms } from '../base/comms';
|
|
4
|
+
import { LegacyProfile } from '../../antv2/types';
|
|
5
|
+
import { BleProtocol, IBlePeripheralConnector } from '../types';
|
|
4
6
|
export default class BleCyclingPowerDevice extends BleComms {
|
|
7
|
+
static protocol: BleProtocol;
|
|
5
8
|
static services: string[];
|
|
6
9
|
static characteristics: string[];
|
|
7
10
|
static detectionPriority: number;
|
|
@@ -13,11 +16,11 @@ export default class BleCyclingPowerDevice extends BleComms {
|
|
|
13
16
|
time: number;
|
|
14
17
|
currentCrankData: CrankData;
|
|
15
18
|
prevCrankData: CrankData;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
getProfile(): string;
|
|
19
|
+
static isMatching(characteristics: string[]): boolean;
|
|
20
|
+
getProfile(): LegacyProfile;
|
|
21
|
+
getProtocol(): BleProtocol;
|
|
20
22
|
getServiceUUids(): string[];
|
|
23
|
+
subscribeAll(conn?: IBlePeripheralConnector): Promise<void>;
|
|
21
24
|
parseCrankData(crankData: any): {
|
|
22
25
|
rpm: number;
|
|
23
26
|
time: any;
|
package/lib/ble/cp/comm.js
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
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
|
-
const ble_comms_1 = require("../ble-comms");
|
|
13
3
|
const consts_1 = require("../consts");
|
|
14
4
|
const utils_1 = require("../utils");
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
const comms_1 = require("../base/comms");
|
|
6
|
+
class BleCyclingPowerDevice extends comms_1.BleComms {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
18
9
|
this.instantaneousPower = undefined;
|
|
19
10
|
this.balance = undefined;
|
|
20
11
|
this.accTorque = undefined;
|
|
@@ -24,32 +15,25 @@ class BleCyclingPowerDevice extends ble_comms_1.BleComms {
|
|
|
24
15
|
this.currentCrankData = undefined;
|
|
25
16
|
this.prevCrankData = undefined;
|
|
26
17
|
}
|
|
27
|
-
isMatching(characteristics) {
|
|
18
|
+
static isMatching(characteristics) {
|
|
28
19
|
if (!characteristics)
|
|
29
20
|
return false;
|
|
30
21
|
const hasCPMeasurement = characteristics.find(c => c === consts_1.CSP_MEASUREMENT) !== undefined;
|
|
31
22
|
const hasCPFeature = characteristics.find(c => c === consts_1.CSP_FEATURE) !== undefined;
|
|
32
23
|
return hasCPMeasurement && hasCPFeature;
|
|
33
24
|
}
|
|
34
|
-
init() {
|
|
35
|
-
const _super = Object.create(null, {
|
|
36
|
-
init: { get: () => super.init }
|
|
37
|
-
});
|
|
38
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
try {
|
|
40
|
-
yield _super.init.call(this);
|
|
41
|
-
}
|
|
42
|
-
catch (err) {
|
|
43
|
-
return Promise.resolve(false);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
25
|
getProfile() {
|
|
48
26
|
return 'Power Meter';
|
|
49
27
|
}
|
|
28
|
+
getProtocol() {
|
|
29
|
+
return BleCyclingPowerDevice.protocol;
|
|
30
|
+
}
|
|
50
31
|
getServiceUUids() {
|
|
51
32
|
return BleCyclingPowerDevice.services;
|
|
52
33
|
}
|
|
34
|
+
subscribeAll(conn) {
|
|
35
|
+
return this.subscribeMultiple([consts_1.CSP_MEASUREMENT], conn);
|
|
36
|
+
}
|
|
53
37
|
parseCrankData(crankData) {
|
|
54
38
|
if (!this.prevCrankData)
|
|
55
39
|
this.prevCrankData = { revolutions: 0, time: 0, cntUpdateMissing: -1 };
|
|
@@ -135,6 +119,7 @@ class BleCyclingPowerDevice extends ble_comms_1.BleComms {
|
|
|
135
119
|
}
|
|
136
120
|
}
|
|
137
121
|
exports.default = BleCyclingPowerDevice;
|
|
122
|
+
BleCyclingPowerDevice.protocol = 'cp';
|
|
138
123
|
BleCyclingPowerDevice.services = [consts_1.CSP];
|
|
139
124
|
BleCyclingPowerDevice.characteristics = [consts_1.CSP_MEASUREMENT, consts_1.CSP_FEATURE, '2a5d', '2a3c'];
|
|
140
125
|
BleCyclingPowerDevice.detectionPriority = 1;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import BleAdapter, { BleControllableAdapter } from '../adapter';
|
|
1
|
+
import BleAdapter, { BleControllableAdapter } from '../base/adapter';
|
|
2
2
|
import CyclingMode, { IncyclistBikeData } from '../../modes/cycling-mode';
|
|
3
3
|
import { PowerData } from '../cp';
|
|
4
4
|
import { DeviceProperties } from '../../types/device';
|
|
@@ -12,7 +12,6 @@ export default class BleEliteAdapter extends BleControllableAdapter {
|
|
|
12
12
|
getName(): string;
|
|
13
13
|
getDefaultCyclingMode(): CyclingMode;
|
|
14
14
|
getSupportedCyclingModes(): any[];
|
|
15
|
-
onDeviceData(deviceData: PowerData): void;
|
|
16
15
|
mapData(deviceData: PowerData): IncyclistBikeData;
|
|
17
16
|
transformData(bikeData: IncyclistBikeData): DeviceData;
|
|
18
17
|
start(props?: any): Promise<any>;
|
package/lib/ble/elite/adapter.js
CHANGED
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
16
|
-
const adapter_1 = require("../adapter");
|
|
16
|
+
const adapter_1 = require("../base/adapter");
|
|
17
17
|
const comms_1 = __importDefault(require("./comms"));
|
|
18
18
|
const power_meter_1 = __importDefault(require("../../modes/power-meter"));
|
|
19
19
|
const capabilities_1 = require("../../types/capabilities");
|
|
@@ -48,19 +48,6 @@ class BleEliteAdapter extends adapter_1.BleControllableAdapter {
|
|
|
48
48
|
getSupportedCyclingModes() {
|
|
49
49
|
return [power_meter_1.default];
|
|
50
50
|
}
|
|
51
|
-
onDeviceData(deviceData) {
|
|
52
|
-
super.onDeviceData(deviceData);
|
|
53
|
-
if (!this.started || this.paused || !this.onDataFn)
|
|
54
|
-
return;
|
|
55
|
-
this.logger.logEvent({ message: 'onDeviceData', data: deviceData });
|
|
56
|
-
if (!this.lastUpdate || (Date.now() - this.lastUpdate) > this.updateFrequency) {
|
|
57
|
-
let incyclistData = this.mapData(deviceData);
|
|
58
|
-
incyclistData = this.getCyclingMode().updateData(incyclistData);
|
|
59
|
-
const data = this.transformData(incyclistData);
|
|
60
|
-
this.onDataFn(data);
|
|
61
|
-
this.lastUpdate = Date.now();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
51
|
mapData(deviceData) {
|
|
65
52
|
const data = {
|
|
66
53
|
isPedalling: false,
|
|
@@ -99,12 +86,18 @@ class BleEliteAdapter extends adapter_1.BleControllableAdapter {
|
|
|
99
86
|
}
|
|
100
87
|
start(props) {
|
|
101
88
|
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
this.
|
|
89
|
+
if (this.ble.isScanning()) {
|
|
90
|
+
this.logger.logEvent({ message: 'stop previous scan', isScanning: this.ble.isScanning() });
|
|
91
|
+
yield this.ble.stopScan();
|
|
92
|
+
}
|
|
93
|
+
const connected = yield this.connect();
|
|
94
|
+
if (!connected)
|
|
95
|
+
throw new Error(`could not start device, reason:could not connect`);
|
|
96
|
+
const comms = this.device;
|
|
97
|
+
this.logger.logEvent({ message: 'start requested', profile: this.getProfile(), props });
|
|
103
98
|
try {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
this.device = bleDevice;
|
|
107
|
-
bleDevice.on('data', (data) => {
|
|
99
|
+
if (comms) {
|
|
100
|
+
comms.on('data', (data) => {
|
|
108
101
|
this.onDeviceData(data);
|
|
109
102
|
});
|
|
110
103
|
return true;
|
package/lib/ble/elite/comms.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
2
|
+
import { LegacyProfile } from "../../antv2/types";
|
|
3
|
+
import { BleComms } from "../base/comms";
|
|
3
4
|
import { CrankData, PowerData } from "../cp";
|
|
5
|
+
import { BleProtocol, IBlePeripheralConnector } from "../types";
|
|
4
6
|
export default class BleEliteDevice extends BleComms {
|
|
7
|
+
static protocol: BleProtocol;
|
|
5
8
|
static services: string[];
|
|
6
9
|
static characteristics: string[];
|
|
7
10
|
static detectionPriority: number;
|
|
@@ -14,9 +17,9 @@ export default class BleEliteDevice extends BleComms {
|
|
|
14
17
|
currentCrankData: CrankData;
|
|
15
18
|
prevCrankData: CrankData;
|
|
16
19
|
constructor(props?: any);
|
|
17
|
-
isMatching(characteristics: string[]): boolean;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
static isMatching(characteristics: string[]): boolean;
|
|
21
|
+
getProfile(): LegacyProfile;
|
|
22
|
+
getProtocol(): BleProtocol;
|
|
20
23
|
getServiceUUids(): string[];
|
|
21
24
|
parseCrankData(crankData: any): {
|
|
22
25
|
rpm: number;
|
|
@@ -24,5 +27,6 @@ export default class BleEliteDevice extends BleComms {
|
|
|
24
27
|
};
|
|
25
28
|
parsePower(_data: Uint8Array): PowerData;
|
|
26
29
|
onData(characteristic: string, data: Buffer): boolean;
|
|
30
|
+
subscribeAll(conn?: IBlePeripheralConnector): Promise<void>;
|
|
27
31
|
reset(): void;
|
|
28
32
|
}
|
package/lib/ble/elite/comms.js
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
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
|
-
const
|
|
3
|
+
const _1 = require(".");
|
|
4
|
+
const comms_1 = require("../base/comms");
|
|
13
5
|
const consts_1 = require("../consts");
|
|
14
6
|
const utils_1 = require("../utils");
|
|
15
|
-
class BleEliteDevice extends
|
|
7
|
+
class BleEliteDevice extends comms_1.BleComms {
|
|
16
8
|
constructor(props) {
|
|
17
9
|
super(props);
|
|
18
10
|
this.instantaneousPower = undefined;
|
|
@@ -24,29 +16,19 @@ class BleEliteDevice extends ble_comms_1.BleComms {
|
|
|
24
16
|
this.currentCrankData = undefined;
|
|
25
17
|
this.prevCrankData = undefined;
|
|
26
18
|
}
|
|
27
|
-
isMatching(characteristics) {
|
|
19
|
+
static isMatching(characteristics) {
|
|
28
20
|
if (!characteristics)
|
|
29
21
|
return false;
|
|
30
22
|
const hasCPMeasurement = characteristics.find(c => c === consts_1.CSP_MEASUREMENT) !== undefined;
|
|
31
23
|
const hasCPFeature = characteristics.find(c => c === consts_1.CSP_FEATURE) !== undefined;
|
|
32
24
|
return hasCPMeasurement && hasCPFeature;
|
|
33
25
|
}
|
|
34
|
-
init() {
|
|
35
|
-
const _super = Object.create(null, {
|
|
36
|
-
init: { get: () => super.init }
|
|
37
|
-
});
|
|
38
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
try {
|
|
40
|
-
yield _super.init.call(this);
|
|
41
|
-
}
|
|
42
|
-
catch (err) {
|
|
43
|
-
return Promise.resolve(false);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
26
|
getProfile() {
|
|
48
27
|
return 'Power Meter';
|
|
49
28
|
}
|
|
29
|
+
getProtocol() {
|
|
30
|
+
return _1.BleEliteComms.protocol;
|
|
31
|
+
}
|
|
50
32
|
getServiceUUids() {
|
|
51
33
|
return BleEliteDevice.services;
|
|
52
34
|
}
|
|
@@ -122,6 +104,10 @@ class BleEliteDevice extends ble_comms_1.BleComms {
|
|
|
122
104
|
}
|
|
123
105
|
return true;
|
|
124
106
|
}
|
|
107
|
+
subscribeAll(conn) {
|
|
108
|
+
const characteristics = [consts_1.CSP_MEASUREMENT];
|
|
109
|
+
return this.subscribeMultiple(characteristics, conn);
|
|
110
|
+
}
|
|
125
111
|
reset() {
|
|
126
112
|
this.instantaneousPower = undefined;
|
|
127
113
|
this.balance = undefined;
|
|
@@ -134,6 +120,7 @@ class BleEliteDevice extends ble_comms_1.BleComms {
|
|
|
134
120
|
}
|
|
135
121
|
}
|
|
136
122
|
exports.default = BleEliteDevice;
|
|
123
|
+
BleEliteDevice.protocol = 'elite';
|
|
137
124
|
BleEliteDevice.services = [consts_1.ELITE_TRAINER_SVC];
|
|
138
125
|
BleEliteDevice.characteristics = [consts_1.CSP_MEASUREMENT, consts_1.CSP_FEATURE, '2a5d', '2a3c'];
|
|
139
126
|
BleEliteDevice.detectionPriority = 10;
|
package/lib/ble/fm/adapter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import BleAdapter, { BleControllableAdapter } from '../adapter';
|
|
1
|
+
import BleAdapter, { BleControllableAdapter } from '../base/adapter';
|
|
2
2
|
import CyclingMode, { IncyclistBikeData } from '../../modes/cycling-mode';
|
|
3
3
|
import { DeviceProperties } from '../../types/device';
|
|
4
4
|
import { IndoorBikeData } from './types';
|
|
@@ -6,6 +6,7 @@ import { DeviceData } from '../../types/data';
|
|
|
6
6
|
import { BleDeviceSettings, BleStartProperties } from '../types';
|
|
7
7
|
export default class BleFmAdapter extends BleControllableAdapter {
|
|
8
8
|
distanceInternal: number;
|
|
9
|
+
connectPromise: Promise<boolean>;
|
|
9
10
|
constructor(settings: BleDeviceSettings, props?: DeviceProperties);
|
|
10
11
|
isSame(device: BleAdapter): boolean;
|
|
11
12
|
getProfile(): string;
|
|
@@ -13,9 +14,9 @@ export default class BleFmAdapter extends BleControllableAdapter {
|
|
|
13
14
|
getDisplayName(): string;
|
|
14
15
|
getSupportedCyclingModes(): Array<any>;
|
|
15
16
|
getDefaultCyclingMode(): CyclingMode;
|
|
16
|
-
onDeviceData(deviceData: IndoorBikeData): void;
|
|
17
17
|
mapData(deviceData: IndoorBikeData): IncyclistBikeData;
|
|
18
18
|
transformData(bikeData: IncyclistBikeData): DeviceData;
|
|
19
19
|
start(props?: BleStartProperties): Promise<any>;
|
|
20
20
|
sendUpdate(request: any): Promise<void>;
|
|
21
|
+
setCyclingMode(mode: string | CyclingMode, settings?: any): void;
|
|
21
22
|
}
|