incyclist-devices 1.5.38 → 2.0.0
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 +7 -0
- package/lib/adapters.js +49 -0
- package/lib/antv2/adapter-factory.d.ts +21 -10
- package/lib/antv2/adapter-factory.js +51 -33
- package/lib/antv2/adapter.d.ts +65 -0
- package/lib/antv2/adapter.js +310 -0
- package/lib/antv2/ant-interface.d.ts +17 -11
- package/lib/antv2/ant-interface.js +41 -31
- package/lib/antv2/{ant-binding.d.ts → binding.d.ts} +1 -1
- package/lib/antv2/{ant-binding.js → binding.js} +1 -1
- package/lib/antv2/fe/adapter.d.ts +28 -0
- package/lib/antv2/{fe.js → fe/adapter.js} +106 -90
- package/lib/antv2/fe/index.d.ts +2 -0
- package/lib/antv2/fe/index.js +7 -0
- package/lib/antv2/hr/adapter.d.ts +15 -0
- package/lib/antv2/hr/adapter.js +76 -0
- package/lib/antv2/hr/index.d.ts +2 -0
- package/lib/antv2/hr/index.js +7 -0
- package/lib/antv2/index.d.ts +7 -0
- package/lib/antv2/index.js +20 -0
- package/lib/antv2/modes/ant-fe-adv-st-mode.d.ts +9 -0
- package/lib/{ant/antfe → antv2/modes}/ant-fe-adv-st-mode.js +1 -1
- package/lib/antv2/modes/ant-fe-erg-mode.d.ts +6 -0
- package/lib/{ant/antfe → antv2/modes}/ant-fe-erg-mode.js +1 -1
- package/lib/antv2/modes/ant-fe-st-mode.d.ts +5 -0
- package/lib/{ant/antfe → antv2/modes}/ant-fe-st-mode.js +1 -1
- package/lib/antv2/pwr/adapter.d.ts +24 -0
- package/lib/antv2/pwr/adapter.js +141 -0
- package/lib/antv2/pwr/index.d.ts +2 -0
- package/lib/antv2/pwr/index.js +7 -0
- package/lib/antv2/sensor-factory.d.ts +2 -2
- package/lib/antv2/types.d.ts +22 -0
- package/lib/antv2/types.js +5 -0
- package/lib/antv2/utils.d.ts +4 -0
- package/lib/antv2/utils.js +192 -0
- package/lib/base/adpater.d.ts +68 -0
- package/lib/base/adpater.js +183 -0
- package/lib/ble/adapter-factory.d.ts +33 -0
- package/lib/ble/adapter-factory.js +105 -0
- package/lib/ble/base/adapter.d.ts +53 -0
- package/lib/ble/base/adapter.js +290 -0
- package/lib/ble/base/comms-utils.d.ts +7 -0
- package/lib/ble/base/comms-utils.js +91 -0
- package/lib/ble/{ble-device.d.ts → base/comms.d.ts} +31 -16
- package/lib/ble/{ble-device.js → base/comms.js} +193 -55
- 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 +38 -59
- package/lib/ble/ble-interface.js +254 -462
- package/lib/ble/ble-peripheral.d.ts +7 -5
- package/lib/ble/ble-peripheral.js +52 -21
- package/lib/ble/consts.d.ts +3 -0
- package/lib/ble/consts.js +4 -1
- package/lib/ble/cp/adapter.d.ts +22 -0
- package/lib/ble/cp/adapter.js +111 -0
- package/lib/ble/cp/comm.d.ts +31 -0
- package/lib/ble/cp/comm.js +125 -0
- package/lib/ble/cp/index.d.ts +4 -0
- package/lib/ble/cp/index.js +10 -0
- package/lib/ble/cp/types.d.ts +13 -0
- package/lib/ble/cp/types.js +2 -0
- package/lib/ble/elite/adapter.d.ts +19 -0
- package/lib/ble/elite/adapter.js +120 -0
- package/lib/ble/elite/comms.d.ts +32 -0
- package/lib/ble/elite/comms.js +126 -0
- package/lib/ble/elite/index.d.ts +3 -0
- package/lib/ble/elite/index.js +10 -0
- package/lib/ble/fm/adapter.d.ts +22 -0
- package/lib/ble/fm/adapter.js +249 -0
- package/lib/ble/fm/comms.d.ts +50 -0
- package/lib/ble/{fm.js → fm/comms.js} +34 -277
- package/lib/ble/fm/consts.d.ts +6 -0
- package/lib/ble/fm/consts.js +9 -0
- package/lib/ble/fm/index.d.ts +5 -0
- package/lib/ble/fm/index.js +13 -0
- package/lib/ble/fm/types.d.ts +30 -0
- package/lib/ble/fm/types.js +2 -0
- package/lib/ble/hr/adapter.d.ts +14 -0
- package/lib/ble/hr/adapter.js +45 -0
- package/lib/ble/hr/comm.d.ts +19 -0
- package/lib/ble/hr/comm.js +56 -0
- package/lib/ble/hr/index.d.ts +4 -0
- package/lib/ble/hr/index.js +10 -0
- package/lib/ble/hr/mock.d.ts +7 -0
- package/lib/ble/hr/mock.js +47 -0
- package/lib/ble/hr/types.d.ts +5 -0
- package/lib/ble/hr/types.js +2 -0
- package/lib/ble/index.d.ts +9 -0
- package/lib/ble/index.js +26 -0
- package/lib/ble/peripheral-cache.d.ts +43 -0
- package/lib/ble/peripheral-cache.js +107 -0
- package/lib/ble/tacx/adapter.d.ts +10 -0
- package/lib/ble/tacx/adapter.js +99 -0
- package/lib/ble/{tacx.d.ts → tacx/comms.d.ts} +11 -43
- package/lib/ble/{tacx.js → tacx/comms.js} +23 -155
- package/lib/ble/tacx/index.d.ts +4 -0
- package/lib/ble/tacx/index.js +10 -0
- package/lib/ble/tacx/types.d.ts +25 -0
- package/lib/ble/tacx/types.js +2 -0
- package/lib/ble/types.d.ts +128 -0
- package/lib/ble/types.js +2 -0
- package/lib/ble/utils.d.ts +17 -0
- package/lib/ble/utils.js +54 -0
- package/lib/ble/wahoo/adapter.d.ts +9 -0
- package/lib/ble/wahoo/adapter.js +95 -0
- package/lib/ble/{wahoo-kickr.d.ts → wahoo/comms.d.ts} +11 -44
- package/lib/ble/{wahoo-kickr.js → wahoo/comms.js} +29 -129
- package/lib/ble/wahoo/index.d.ts +4 -0
- package/lib/ble/wahoo/index.js +10 -0
- package/lib/ble/wahoo/types.d.ts +19 -0
- package/lib/ble/wahoo/types.js +2 -0
- package/lib/index.d.ts +15 -0
- package/lib/index.js +34 -0
- package/lib/interfaces.d.ts +7 -0
- package/lib/interfaces.js +27 -0
- package/lib/{ble → modes}/ble-erg-mode.d.ts +4 -4
- package/lib/{ble → modes}/ble-erg-mode.js +2 -2
- package/lib/{ble → modes}/ble-st-mode.d.ts +3 -3
- package/lib/{ble → modes}/ble-st-mode.js +1 -1
- package/lib/{cycling-mode.d.ts → modes/cycling-mode.d.ts} +8 -8
- package/lib/modes/power-base.d.ts +3 -3
- package/lib/modes/power-base.js +8 -4
- package/lib/modes/power-meter.d.ts +3 -3
- package/lib/modes/simulator.d.ts +2 -2
- package/lib/modes/simulator.js +1 -1
- package/lib/serial/adapter-factory.d.ts +12 -0
- package/lib/serial/adapter-factory.js +30 -0
- package/lib/serial/adapter.d.ts +21 -0
- package/lib/serial/adapter.js +61 -0
- package/lib/serial/bindings/tcp.d.ts +45 -0
- package/lib/serial/bindings/tcp.js +284 -0
- package/lib/serial/comm.d.ts +7 -0
- package/lib/serial/comm.js +2 -0
- package/lib/{daum → serial/daum}/DaumAdapter.d.ts +14 -23
- package/lib/{daum → serial/daum}/DaumAdapter.js +57 -97
- package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.d.ts +2 -2
- package/lib/{daum → serial/daum}/DaumPowerMeterCyclingMode.js +1 -1
- package/lib/{daum → serial/daum}/ERGCyclingMode.d.ts +3 -3
- package/lib/{daum → serial/daum}/ERGCyclingMode.js +3 -3
- package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.d.ts +3 -3
- package/lib/{daum → serial/daum}/SmartTrainerCyclingMode.js +4 -3
- package/lib/serial/daum/classic/adapter.d.ts +29 -0
- package/lib/{daum/classic/DaumClassicAdapter.js → serial/daum/classic/adapter.js} +77 -50
- package/lib/{daum/classic/bike.d.ts → serial/daum/classic/comms.d.ts} +14 -16
- package/lib/{daum/classic/bike.js → serial/daum/classic/comms.js} +68 -152
- package/lib/serial/daum/classic/mock.d.ts +96 -0
- package/lib/serial/daum/classic/mock.js +365 -0
- package/lib/{daum/classic/DaumClassicCyclingMode.d.ts → serial/daum/classic/modes/daum-classic.d.ts} +3 -3
- package/lib/{daum/classic/DaumClassicCyclingMode.js → serial/daum/classic/modes/daum-classic.js} +2 -2
- package/lib/{daum → serial/daum}/classic/utils.d.ts +1 -1
- package/lib/serial/daum/premium/adapter.d.ts +25 -0
- package/lib/{daum/premium/DaumPremiumAdapter.js → serial/daum/premium/adapter.js} +107 -47
- package/lib/{daum/premium/bike.d.ts → serial/daum/premium/comms.d.ts} +26 -54
- package/lib/{daum/premium/bike.js → serial/daum/premium/comms.js} +215 -420
- package/lib/serial/daum/premium/mock.d.ts +75 -0
- package/lib/serial/daum/premium/mock.js +289 -0
- package/lib/{daum/premium/DaumClassicCyclingMode.d.ts → serial/daum/premium/modes/daum-classic.d.ts} +3 -3
- package/lib/{daum/premium/DaumClassicCyclingMode.js → serial/daum/premium/modes/daum-classic.js} +2 -2
- package/lib/serial/daum/premium/types.d.ts +12 -0
- package/lib/serial/daum/premium/types.js +2 -0
- package/lib/{daum → serial/daum}/premium/utils.d.ts +8 -11
- package/lib/{daum → serial/daum}/premium/utils.js +22 -63
- package/lib/serial/index.d.ts +9 -0
- package/lib/serial/index.js +49 -0
- package/lib/{kettler → serial/kettler}/comms.d.ts +8 -6
- package/lib/{kettler → serial/kettler}/comms.js +71 -32
- package/lib/{kettler → serial/kettler}/ergo-racer/adapter.d.ts +14 -28
- package/lib/{kettler → serial/kettler}/ergo-racer/adapter.js +102 -169
- package/lib/serial/kettler/ergo-racer/mock.d.ts +66 -0
- package/lib/serial/kettler/ergo-racer/mock.js +216 -0
- package/lib/{kettler/ergo-racer/ERGCyclingMode.d.ts → serial/kettler/ergo-racer/modes/erg.d.ts} +4 -4
- package/lib/{kettler/ergo-racer/ERGCyclingMode.js → serial/kettler/ergo-racer/modes/erg.js} +2 -2
- package/lib/serial/serial-interface.d.ts +60 -0
- package/lib/serial/serial-interface.js +309 -0
- package/lib/simulator/Simulator.d.ts +12 -25
- package/lib/simulator/Simulator.js +26 -87
- package/lib/types/adapter.d.ts +39 -0
- package/lib/types/adapter.js +2 -0
- package/lib/types/capabilities.d.ts +8 -0
- package/lib/types/capabilities.js +12 -0
- package/lib/types/data.d.ts +12 -0
- package/lib/types/data.js +2 -0
- package/lib/types/device.d.ts +32 -0
- package/lib/types/device.js +11 -0
- package/lib/types/interface.d.ts +18 -0
- package/lib/types/interface.js +2 -0
- package/lib/types/route.d.ts +2 -2
- package/lib/types/user.d.ts +1 -1
- package/lib/{utils.d.ts → utils/utils.d.ts} +1 -0
- package/lib/{utils.js → utils/utils.js} +5 -1
- package/package.json +16 -14
- package/lib/DeviceSupport.d.ts +0 -36
- package/lib/DeviceSupport.js +0 -82
- package/lib/ant/AntAdapter.d.ts +0 -50
- package/lib/ant/AntAdapter.js +0 -109
- package/lib/ant/AntScanner.d.ts +0 -60
- package/lib/ant/AntScanner.js +0 -651
- package/lib/ant/antfe/AntFEAdapter.d.ts +0 -83
- package/lib/ant/antfe/AntFEAdapter.js +0 -652
- package/lib/ant/antfe/ant-fe-adv-st-mode.d.ts +0 -9
- package/lib/ant/antfe/ant-fe-erg-mode.d.ts +0 -6
- package/lib/ant/antfe/ant-fe-st-mode.d.ts +0 -5
- package/lib/ant/anthrm/AntHrmAdapter.d.ts +0 -16
- package/lib/ant/anthrm/AntHrmAdapter.js +0 -130
- package/lib/ant/antpwr/pwr-adapter.d.ts +0 -49
- package/lib/ant/antpwr/pwr-adapter.js +0 -251
- package/lib/ant/utils.d.ts +0 -1
- package/lib/ant/utils.js +0 -23
- package/lib/antv2/AntAdapter.d.ts +0 -48
- package/lib/antv2/AntAdapter.js +0 -104
- package/lib/antv2/ant-device.d.ts +0 -59
- package/lib/antv2/ant-device.js +0 -161
- package/lib/antv2/fe.d.ts +0 -32
- package/lib/antv2/hr.d.ts +0 -18
- package/lib/antv2/hr.js +0 -102
- package/lib/antv2/incyclist-protocol.d.ts +0 -37
- package/lib/antv2/incyclist-protocol.js +0 -126
- package/lib/antv2/pwr.d.ts +0 -28
- package/lib/antv2/pwr.js +0 -171
- package/lib/ble/ble.d.ts +0 -129
- package/lib/ble/ble.js +0 -86
- package/lib/ble/elite.d.ts +0 -90
- package/lib/ble/elite.js +0 -322
- package/lib/ble/fm.d.ts +0 -125
- package/lib/ble/hrm.d.ts +0 -48
- package/lib/ble/hrm.js +0 -134
- package/lib/ble/incyclist-protocol.d.ts +0 -31
- package/lib/ble/incyclist-protocol.js +0 -153
- package/lib/ble/pwr.d.ts +0 -89
- package/lib/ble/pwr.js +0 -322
- package/lib/daum/classic/DaumClassicAdapter.d.ts +0 -28
- package/lib/daum/classic/DaumClassicProtocol.d.ts +0 -27
- package/lib/daum/classic/DaumClassicProtocol.js +0 -185
- package/lib/daum/premium/DaumPremiumAdapter.d.ts +0 -16
- package/lib/daum/premium/DaumPremiumProtocol.d.ts +0 -32
- package/lib/daum/premium/DaumPremiumProtocol.js +0 -207
- package/lib/daum/premium/tcpserial.d.ts +0 -33
- package/lib/daum/premium/tcpserial.js +0 -123
- package/lib/device.d.ts +0 -94
- package/lib/device.js +0 -76
- package/lib/kettler/ergo-racer/protocol.d.ts +0 -41
- package/lib/kettler/ergo-racer/protocol.js +0 -203
- package/lib/protocol.d.ts +0 -74
- package/lib/protocol.js +0 -41
- package/lib/registry.d.ts +0 -8
- package/lib/registry.js +0 -33
- package/lib/serialport/bindings/tcp.d.ts +0 -20
- package/lib/serialport/bindings/tcp.js +0 -33
- package/lib/serialport/index.d.ts +0 -2
- package/lib/serialport/index.js +0 -29
- package/lib/serialport/serialport.d.ts +0 -29
- package/lib/serialport/serialport.js +0 -87
- /package/lib/{cycling-mode.js → modes/cycling-mode.js} +0 -0
- /package/lib/{daum → serial/daum}/classic/utils.js +0 -0
- /package/lib/{daum → serial/daum}/constants.d.ts +0 -0
- /package/lib/{daum → serial/daum}/constants.js +0 -0
- /package/lib/{serialport.d.ts → serial/serialport.d.ts} +0 -0
- /package/lib/{serialport.js → serial/serialport.js} +0 -0
- /package/lib/{calculations.d.ts → utils/calculations.d.ts} +0 -0
- /package/lib/{calculations.js → utils/calculations.js} +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { BleCharacteristic, BlePeripheral } from
|
|
2
|
-
|
|
3
|
-
export declare type ConnectorState = {
|
|
1
|
+
import { BleCharacteristic, BlePeripheral, IBlePeripheralConnector } from './types';
|
|
2
|
+
export type ConnectorState = {
|
|
4
3
|
isConnected: boolean;
|
|
5
4
|
isConnecting: boolean;
|
|
6
5
|
isInitialized: boolean;
|
|
@@ -8,7 +7,7 @@ export declare type ConnectorState = {
|
|
|
8
7
|
isSubscribing: boolean;
|
|
9
8
|
subscribed?: string[];
|
|
10
9
|
};
|
|
11
|
-
export default class BlePeripheralConnector {
|
|
10
|
+
export default class BlePeripheralConnector implements IBlePeripheralConnector {
|
|
12
11
|
private state;
|
|
13
12
|
private services;
|
|
14
13
|
private characteristics;
|
|
@@ -16,7 +15,7 @@ export default class BlePeripheralConnector {
|
|
|
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 {
|
|
|
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
|
|
15
|
+
const ble_interface_1 = __importDefault(require("./ble-interface"));
|
|
16
16
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
17
17
|
const events_1 = __importDefault(require("events"));
|
|
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', () => { console.log('~~~ peripheral connected', this.peripheral); });
|
|
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 });
|
|
@@ -57,7 +58,7 @@ class BlePeripheralConnector {
|
|
|
57
58
|
}
|
|
58
59
|
reconnect() {
|
|
59
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
this.connect();
|
|
61
|
+
yield this.connect();
|
|
61
62
|
});
|
|
62
63
|
}
|
|
63
64
|
onDisconnect() {
|
|
@@ -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,17 +84,26 @@ 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) {
|
|
94
|
-
return this.state.subscribed.find(c => c === characteristicUuid || (0,
|
|
106
|
+
return this.state.subscribed.find(c => c === characteristicUuid || (0, utils_1.uuid)(c) === characteristicUuid || c === (0, utils_1.uuid)(characteristicUuid)) !== undefined;
|
|
95
107
|
}
|
|
96
108
|
subscribeAll(callback) {
|
|
97
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -106,12 +118,12 @@ class BlePeripheralConnector {
|
|
|
106
118
|
const isNotify = c.properties.find(p => p === 'notify');
|
|
107
119
|
if (isNotify && subscribed.find(uuid => uuid === c.uuid) === undefined) {
|
|
108
120
|
c.on('data', (data, _isNotification) => {
|
|
109
|
-
this.onData((0,
|
|
121
|
+
this.onData((0, utils_1.uuid)(c.uuid), data);
|
|
110
122
|
});
|
|
111
123
|
if (callback) {
|
|
112
|
-
this.on((0,
|
|
124
|
+
this.on((0, utils_1.uuid)(c.uuid), callback);
|
|
113
125
|
}
|
|
114
|
-
this.logEvent({ message: 'subscribe', peripheral: this.peripheral.address, characteristic: c.uuid, uuid: (0,
|
|
126
|
+
this.logEvent({ message: 'subscribe', peripheral: this.peripheral.address, characteristic: c.uuid, uuid: (0, utils_1.uuid)(c.uuid) });
|
|
115
127
|
if (this.state.subscribed.find(uuid => uuid === c.uuid) === undefined) {
|
|
116
128
|
try {
|
|
117
129
|
yield this.subscribe(c.uuid, 3000);
|
|
@@ -133,10 +145,10 @@ class BlePeripheralConnector {
|
|
|
133
145
|
});
|
|
134
146
|
}
|
|
135
147
|
subscribe(characteristicUuid, timeout) {
|
|
136
|
-
this.logEvent({ message: 'subscribe attempt', characteristic: characteristicUuid, characteristics: this.characteristics.map(c => ({ characteristic: c.uuid, uuid: (0,
|
|
148
|
+
this.logEvent({ message: 'subscribe attempt', characteristic: characteristicUuid, characteristics: this.characteristics.map(c => ({ characteristic: c.uuid, uuid: (0, utils_1.uuid)(c.uuid) })) });
|
|
137
149
|
return new Promise((resolve, reject) => {
|
|
138
150
|
try {
|
|
139
|
-
const characteristic = this.characteristics.find(c => (0,
|
|
151
|
+
const characteristic = this.characteristics.find(c => (0, utils_1.uuid)(c.uuid) === (0, utils_1.uuid)(characteristicUuid) || (0, utils_1.uuid)(c.uuid) === (0, utils_1.uuid)(characteristicUuid));
|
|
140
152
|
if (!characteristic) {
|
|
141
153
|
reject(new Error('Characteristic not found'));
|
|
142
154
|
return;
|
|
@@ -144,7 +156,7 @@ class BlePeripheralConnector {
|
|
|
144
156
|
this.logEvent({ message: 'subscribe', peripheral: this.peripheral.address, characteristic: characteristic.uuid });
|
|
145
157
|
characteristic.removeAllListeners('data');
|
|
146
158
|
characteristic.on('data', (data, _isNotification) => {
|
|
147
|
-
this.onData((0,
|
|
159
|
+
this.onData((0, utils_1.uuid)(characteristicUuid), data);
|
|
148
160
|
});
|
|
149
161
|
let to;
|
|
150
162
|
if (timeout) {
|
|
@@ -170,19 +182,38 @@ 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
|
-
this.emitter.emit((0,
|
|
201
|
+
this.emitter.emit((0, utils_1.uuid)(characteristicUuid), characteristicUuid, data);
|
|
175
202
|
}
|
|
176
203
|
on(characteristicUuid, callback) {
|
|
177
204
|
if (callback)
|
|
178
|
-
this.emitter.on((0,
|
|
205
|
+
this.emitter.on((0, utils_1.uuid)(characteristicUuid), callback);
|
|
206
|
+
}
|
|
207
|
+
once(characteristicUuid, callback) {
|
|
208
|
+
if (callback)
|
|
209
|
+
this.emitter.once((0, utils_1.uuid)(characteristicUuid), callback);
|
|
179
210
|
}
|
|
180
211
|
off(characteristicUuid, callback) {
|
|
181
212
|
if (callback)
|
|
182
|
-
this.emitter.off((0,
|
|
213
|
+
this.emitter.off((0, utils_1.uuid)(characteristicUuid), callback);
|
|
183
214
|
}
|
|
184
215
|
removeAllListeners(characteristicUuid) {
|
|
185
|
-
this.emitter.removeAllListeners((0,
|
|
216
|
+
this.emitter.removeAllListeners((0, utils_1.uuid)(characteristicUuid));
|
|
186
217
|
}
|
|
187
218
|
getState() {
|
|
188
219
|
return this.peripheral.state;
|
package/lib/ble/consts.d.ts
CHANGED
|
@@ -8,7 +8,10 @@ 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";
|
|
15
|
+
export declare const WAHOO_ADVANCED_FTMS = "a026ee0b";
|
|
14
16
|
export declare const WAHOO_ADVANCED_TRAINER_CP_FULL = "A026E005-0A7D-4AB3-97FA-F1500F9FEB8B";
|
|
17
|
+
export declare const ELITE_TRAINER_SVC = "347b0001";
|
package/lib/ble/consts.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WAHOO_ADVANCED_TRAINER_CP_FULL = 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,7 +11,10 @@ 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';
|
|
18
|
+
exports.WAHOO_ADVANCED_FTMS = 'a026ee0b';
|
|
17
19
|
exports.WAHOO_ADVANCED_TRAINER_CP_FULL = 'A026E005-0A7D-4AB3-97FA-F1500F9FEB8B';
|
|
20
|
+
exports.ELITE_TRAINER_SVC = '347b0001';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import CyclingMode from '../../modes/cycling-mode';
|
|
2
|
+
import { IncyclistBikeData } from '../../modes/cycling-mode';
|
|
3
|
+
import { BleControllableAdapter } from '../base/adapter';
|
|
4
|
+
import { DeviceProperties } from '../../types/device';
|
|
5
|
+
import { PowerData } from './types';
|
|
6
|
+
import { DeviceData } from '../../types/data';
|
|
7
|
+
import { BleDeviceSettings } from '../types';
|
|
8
|
+
import IncyclistDevice from '../../base/adpater';
|
|
9
|
+
export default class PwrAdapter extends BleControllableAdapter {
|
|
10
|
+
distanceInternal: number;
|
|
11
|
+
constructor(settings: BleDeviceSettings, props?: DeviceProperties);
|
|
12
|
+
isSame(device: IncyclistDevice): boolean;
|
|
13
|
+
getProfile(): string;
|
|
14
|
+
getName(): string;
|
|
15
|
+
getDisplayName(): string;
|
|
16
|
+
getDefaultCyclingMode(): CyclingMode;
|
|
17
|
+
getSupportedCyclingModes(): any[];
|
|
18
|
+
mapData(deviceData: PowerData): IncyclistBikeData;
|
|
19
|
+
transformData(bikeData: IncyclistBikeData): DeviceData;
|
|
20
|
+
sendUpdate(request: any): Promise<void>;
|
|
21
|
+
stop(): Promise<boolean>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
16
|
+
const power_meter_1 = __importDefault(require("../../modes/power-meter"));
|
|
17
|
+
const comm_1 = __importDefault(require("./comm"));
|
|
18
|
+
const adapter_1 = require("../base/adapter");
|
|
19
|
+
const capabilities_1 = require("../../types/capabilities");
|
|
20
|
+
class PwrAdapter extends adapter_1.BleControllableAdapter {
|
|
21
|
+
constructor(settings, props) {
|
|
22
|
+
super(settings, props);
|
|
23
|
+
this.distanceInternal = 0;
|
|
24
|
+
this.logger = new gd_eventlog_1.EventLogger('Ble-CP');
|
|
25
|
+
const { id, address, name } = settings;
|
|
26
|
+
const logger = this.logger;
|
|
27
|
+
const ble = this.ble;
|
|
28
|
+
this.device = new comm_1.default({ id, address, name, logger });
|
|
29
|
+
this.capabilities = [
|
|
30
|
+
capabilities_1.IncyclistCapability.Power, capabilities_1.IncyclistCapability.Cadence, capabilities_1.IncyclistCapability.Speed
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
isSame(device) {
|
|
34
|
+
if (!(device instanceof PwrAdapter))
|
|
35
|
+
return false;
|
|
36
|
+
return this.isEqual(device.settings);
|
|
37
|
+
}
|
|
38
|
+
getProfile() {
|
|
39
|
+
return 'Power Meter';
|
|
40
|
+
}
|
|
41
|
+
getName() {
|
|
42
|
+
return `${this.device.name}`;
|
|
43
|
+
}
|
|
44
|
+
getDisplayName() {
|
|
45
|
+
const { name } = this.device;
|
|
46
|
+
const { instantaneousPower: power } = this.deviceData;
|
|
47
|
+
const powerStr = power ? ` (${power})` : '';
|
|
48
|
+
return `${name}${powerStr}`;
|
|
49
|
+
}
|
|
50
|
+
getDefaultCyclingMode() {
|
|
51
|
+
return new power_meter_1.default(this);
|
|
52
|
+
}
|
|
53
|
+
getSupportedCyclingModes() {
|
|
54
|
+
return [power_meter_1.default];
|
|
55
|
+
}
|
|
56
|
+
mapData(deviceData) {
|
|
57
|
+
const data = {
|
|
58
|
+
isPedalling: false,
|
|
59
|
+
power: 0,
|
|
60
|
+
pedalRpm: undefined,
|
|
61
|
+
speed: 0,
|
|
62
|
+
heartrate: 0,
|
|
63
|
+
distanceInternal: 0,
|
|
64
|
+
slope: undefined,
|
|
65
|
+
time: undefined
|
|
66
|
+
};
|
|
67
|
+
data.power = (deviceData.instantaneousPower !== undefined ? deviceData.instantaneousPower : data.power);
|
|
68
|
+
data.pedalRpm = (deviceData.rpm !== undefined ? deviceData.rpm : data.pedalRpm);
|
|
69
|
+
data.time = (deviceData.time !== undefined ? deviceData.time : data.time);
|
|
70
|
+
data.isPedalling = data.pedalRpm > 0 || (data.pedalRpm === undefined && data.power > 0);
|
|
71
|
+
return data;
|
|
72
|
+
}
|
|
73
|
+
transformData(bikeData) {
|
|
74
|
+
if (bikeData === undefined)
|
|
75
|
+
return;
|
|
76
|
+
let distance = 0;
|
|
77
|
+
if (this.distanceInternal !== undefined && bikeData.distanceInternal !== undefined) {
|
|
78
|
+
distance = Math.round(bikeData.distanceInternal - this.distanceInternal);
|
|
79
|
+
}
|
|
80
|
+
if (bikeData.distanceInternal !== undefined)
|
|
81
|
+
this.distanceInternal = bikeData.distanceInternal;
|
|
82
|
+
let data = {
|
|
83
|
+
speed: bikeData.speed,
|
|
84
|
+
slope: bikeData.slope,
|
|
85
|
+
power: bikeData.power !== undefined ? Math.round(bikeData.power) : undefined,
|
|
86
|
+
cadence: bikeData.pedalRpm !== undefined ? Math.round(bikeData.pedalRpm) : undefined,
|
|
87
|
+
distance,
|
|
88
|
+
timestamp: Date.now()
|
|
89
|
+
};
|
|
90
|
+
return data;
|
|
91
|
+
}
|
|
92
|
+
sendUpdate(request) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
if (this.paused)
|
|
95
|
+
return;
|
|
96
|
+
this.getCyclingMode().sendBikeUpdate(request);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
stop() {
|
|
100
|
+
const _super = Object.create(null, {
|
|
101
|
+
stop: { get: () => super.stop }
|
|
102
|
+
});
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const stopped = yield _super.stop.call(this);
|
|
105
|
+
if (stopped)
|
|
106
|
+
this.distanceInternal = 0;
|
|
107
|
+
return stopped;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.default = PwrAdapter;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { CrankData, PowerData } from './types';
|
|
3
|
+
import { BleComms } from '../base/comms';
|
|
4
|
+
import { LegacyProfile } from '../../antv2/types';
|
|
5
|
+
import { BleProtocol, IBlePeripheralConnector } from '../types';
|
|
6
|
+
export default class BleCyclingPowerDevice extends BleComms {
|
|
7
|
+
static protocol: BleProtocol;
|
|
8
|
+
static services: string[];
|
|
9
|
+
static characteristics: string[];
|
|
10
|
+
static detectionPriority: number;
|
|
11
|
+
instantaneousPower: number;
|
|
12
|
+
balance: number;
|
|
13
|
+
accTorque: number;
|
|
14
|
+
rpm: number;
|
|
15
|
+
timeOffset: number;
|
|
16
|
+
time: number;
|
|
17
|
+
currentCrankData: CrankData;
|
|
18
|
+
prevCrankData: CrankData;
|
|
19
|
+
static isMatching(characteristics: string[]): boolean;
|
|
20
|
+
getProfile(): LegacyProfile;
|
|
21
|
+
getProtocol(): BleProtocol;
|
|
22
|
+
getServiceUUids(): string[];
|
|
23
|
+
subscribeAll(conn?: IBlePeripheralConnector): Promise<void>;
|
|
24
|
+
parseCrankData(crankData: any): {
|
|
25
|
+
rpm: number;
|
|
26
|
+
time: any;
|
|
27
|
+
};
|
|
28
|
+
parsePower(_data: Uint8Array): PowerData;
|
|
29
|
+
onData(characteristic: string, data: Buffer): boolean;
|
|
30
|
+
reset(): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const consts_1 = require("../consts");
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const comms_1 = require("../base/comms");
|
|
6
|
+
class BleCyclingPowerDevice extends comms_1.BleComms {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.instantaneousPower = undefined;
|
|
10
|
+
this.balance = undefined;
|
|
11
|
+
this.accTorque = undefined;
|
|
12
|
+
this.rpm = undefined;
|
|
13
|
+
this.timeOffset = 0;
|
|
14
|
+
this.time = undefined;
|
|
15
|
+
this.currentCrankData = undefined;
|
|
16
|
+
this.prevCrankData = undefined;
|
|
17
|
+
}
|
|
18
|
+
static isMatching(characteristics) {
|
|
19
|
+
if (!characteristics)
|
|
20
|
+
return false;
|
|
21
|
+
const hasCPMeasurement = characteristics.find(c => c === consts_1.CSP_MEASUREMENT) !== undefined;
|
|
22
|
+
const hasCPFeature = characteristics.find(c => c === consts_1.CSP_FEATURE) !== undefined;
|
|
23
|
+
return hasCPMeasurement && hasCPFeature;
|
|
24
|
+
}
|
|
25
|
+
getProfile() {
|
|
26
|
+
return 'Power Meter';
|
|
27
|
+
}
|
|
28
|
+
getProtocol() {
|
|
29
|
+
return BleCyclingPowerDevice.protocol;
|
|
30
|
+
}
|
|
31
|
+
getServiceUUids() {
|
|
32
|
+
return BleCyclingPowerDevice.services;
|
|
33
|
+
}
|
|
34
|
+
subscribeAll(conn) {
|
|
35
|
+
return this.subscribeMultiple([consts_1.CSP_MEASUREMENT], conn);
|
|
36
|
+
}
|
|
37
|
+
parseCrankData(crankData) {
|
|
38
|
+
if (!this.prevCrankData)
|
|
39
|
+
this.prevCrankData = { revolutions: 0, time: 0, cntUpdateMissing: -1 };
|
|
40
|
+
const c = this.currentCrankData = crankData;
|
|
41
|
+
const p = this.prevCrankData;
|
|
42
|
+
let rpm = this.rpm;
|
|
43
|
+
let hasUpdate = c.time !== p.time;
|
|
44
|
+
if (hasUpdate) {
|
|
45
|
+
let time = c.time - p.time;
|
|
46
|
+
let revs = c.revolutions - p.revolutions;
|
|
47
|
+
if (c.time < p.time) {
|
|
48
|
+
time += 0x10000;
|
|
49
|
+
this.timeOffset += 0x10000;
|
|
50
|
+
}
|
|
51
|
+
if (c.revolutions < p.revolutions)
|
|
52
|
+
revs += 0x10000;
|
|
53
|
+
rpm = 1024 * 60 * revs / time;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
if (p.cntUpdateMissing < 0 || p.cntUpdateMissing > 2) {
|
|
57
|
+
rpm = 0;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const cntUpdateMissing = p.cntUpdateMissing;
|
|
61
|
+
this.prevCrankData = this.currentCrankData;
|
|
62
|
+
if (hasUpdate)
|
|
63
|
+
this.prevCrankData.cntUpdateMissing = 0;
|
|
64
|
+
else
|
|
65
|
+
this.prevCrankData.cntUpdateMissing = cntUpdateMissing + 1;
|
|
66
|
+
return { rpm, time: this.timeOffset + c.time };
|
|
67
|
+
}
|
|
68
|
+
parsePower(_data) {
|
|
69
|
+
const data = Buffer.from(_data);
|
|
70
|
+
try {
|
|
71
|
+
let offset = 4;
|
|
72
|
+
const flags = data.readUInt16LE(0);
|
|
73
|
+
this.instantaneousPower = data.readUInt16LE(2);
|
|
74
|
+
if (flags & 0x1)
|
|
75
|
+
this.balance = data.readUInt8(offset++);
|
|
76
|
+
if (flags & 0x4) {
|
|
77
|
+
this.accTorque = data.readUInt16LE(offset);
|
|
78
|
+
offset += 2;
|
|
79
|
+
}
|
|
80
|
+
if (flags & 0x10) {
|
|
81
|
+
offset += 6;
|
|
82
|
+
}
|
|
83
|
+
if (flags & 0x20) {
|
|
84
|
+
const crankData = {
|
|
85
|
+
revolutions: data.readUInt16LE(offset),
|
|
86
|
+
time: data.readUInt16LE(offset + 2)
|
|
87
|
+
};
|
|
88
|
+
const { rpm, time } = this.parseCrankData(crankData);
|
|
89
|
+
this.rpm = rpm;
|
|
90
|
+
this.time = time;
|
|
91
|
+
offset += 4;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
}
|
|
96
|
+
const { instantaneousPower, balance, accTorque, rpm, time } = this;
|
|
97
|
+
return { instantaneousPower, balance, accTorque, rpm, time, raw: `2a63:${data.toString('hex')}` };
|
|
98
|
+
}
|
|
99
|
+
onData(characteristic, data) {
|
|
100
|
+
const hasData = super.onData(characteristic, data);
|
|
101
|
+
if (!hasData)
|
|
102
|
+
return false;
|
|
103
|
+
if ((0, utils_1.matches)(characteristic, consts_1.CSP_MEASUREMENT)) {
|
|
104
|
+
const res = this.parsePower(data);
|
|
105
|
+
this.emit('data', res);
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
reset() {
|
|
111
|
+
this.instantaneousPower = undefined;
|
|
112
|
+
this.balance = undefined;
|
|
113
|
+
this.accTorque = undefined;
|
|
114
|
+
this.rpm = undefined;
|
|
115
|
+
this.timeOffset = 0;
|
|
116
|
+
this.time = undefined;
|
|
117
|
+
this.currentCrankData = undefined;
|
|
118
|
+
this.prevCrankData = undefined;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.default = BleCyclingPowerDevice;
|
|
122
|
+
BleCyclingPowerDevice.protocol = 'cp';
|
|
123
|
+
BleCyclingPowerDevice.services = [consts_1.CSP];
|
|
124
|
+
BleCyclingPowerDevice.characteristics = [consts_1.CSP_MEASUREMENT, consts_1.CSP_FEATURE, '2a5d', '2a3c'];
|
|
125
|
+
BleCyclingPowerDevice.detectionPriority = 1;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BlePwrComms = exports.BlePwrAdapter = void 0;
|
|
7
|
+
const adapter_1 = __importDefault(require("./adapter"));
|
|
8
|
+
exports.BlePwrAdapter = adapter_1.default;
|
|
9
|
+
const comm_1 = __importDefault(require("./comm"));
|
|
10
|
+
exports.BlePwrComms = comm_1.default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type PowerData = {
|
|
2
|
+
instantaneousPower?: number;
|
|
3
|
+
balance?: number;
|
|
4
|
+
accTorque?: number;
|
|
5
|
+
time: number;
|
|
6
|
+
rpm: number;
|
|
7
|
+
raw?: string;
|
|
8
|
+
};
|
|
9
|
+
export type CrankData = {
|
|
10
|
+
revolutions?: number;
|
|
11
|
+
time?: number;
|
|
12
|
+
cntUpdateMissing?: number;
|
|
13
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import BleAdapter, { BleControllableAdapter } from '../base/adapter';
|
|
2
|
+
import CyclingMode, { IncyclistBikeData } from '../../modes/cycling-mode';
|
|
3
|
+
import { PowerData } from '../cp';
|
|
4
|
+
import { DeviceProperties } from '../../types/device';
|
|
5
|
+
import { DeviceData } from '../../types/data';
|
|
6
|
+
import { BleDeviceSettings } from '../types';
|
|
7
|
+
export default class BleEliteAdapter extends BleControllableAdapter {
|
|
8
|
+
distanceInternal: number;
|
|
9
|
+
constructor(settings: BleDeviceSettings, props?: DeviceProperties);
|
|
10
|
+
isSame(device: BleAdapter): boolean;
|
|
11
|
+
getProfile(): string;
|
|
12
|
+
getName(): string;
|
|
13
|
+
getDefaultCyclingMode(): CyclingMode;
|
|
14
|
+
getSupportedCyclingModes(): any[];
|
|
15
|
+
mapData(deviceData: PowerData): IncyclistBikeData;
|
|
16
|
+
transformData(bikeData: IncyclistBikeData): DeviceData;
|
|
17
|
+
start(props?: any): Promise<any>;
|
|
18
|
+
sendUpdate(request: any): Promise<void>;
|
|
19
|
+
}
|