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
|
@@ -0,0 +1,120 @@
|
|
|
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 adapter_1 = require("../base/adapter");
|
|
17
|
+
const comms_1 = __importDefault(require("./comms"));
|
|
18
|
+
const power_meter_1 = __importDefault(require("../../modes/power-meter"));
|
|
19
|
+
const capabilities_1 = require("../../types/capabilities");
|
|
20
|
+
class BleEliteAdapter 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-Elite');
|
|
25
|
+
const { id, address, name } = settings;
|
|
26
|
+
const logger = this.logger;
|
|
27
|
+
const ble = this.ble;
|
|
28
|
+
this.device = new comms_1.default({ id, address, name, ble, logger });
|
|
29
|
+
this.capabilities = [
|
|
30
|
+
capabilities_1.IncyclistCapability.Power, capabilities_1.IncyclistCapability.Speed, capabilities_1.IncyclistCapability.Cadence,
|
|
31
|
+
capabilities_1.IncyclistCapability.Control
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
isSame(device) {
|
|
35
|
+
if (!(device instanceof BleEliteAdapter))
|
|
36
|
+
return false;
|
|
37
|
+
return this.isEqual(device.settings);
|
|
38
|
+
}
|
|
39
|
+
getProfile() {
|
|
40
|
+
return 'Smart Trainer';
|
|
41
|
+
}
|
|
42
|
+
getName() {
|
|
43
|
+
return `${this.device.name}`;
|
|
44
|
+
}
|
|
45
|
+
getDefaultCyclingMode() {
|
|
46
|
+
return new power_meter_1.default(this);
|
|
47
|
+
}
|
|
48
|
+
getSupportedCyclingModes() {
|
|
49
|
+
return [power_meter_1.default];
|
|
50
|
+
}
|
|
51
|
+
mapData(deviceData) {
|
|
52
|
+
const data = {
|
|
53
|
+
isPedalling: false,
|
|
54
|
+
power: 0,
|
|
55
|
+
pedalRpm: undefined,
|
|
56
|
+
speed: 0,
|
|
57
|
+
heartrate: 0,
|
|
58
|
+
distanceInternal: 0,
|
|
59
|
+
slope: undefined,
|
|
60
|
+
time: undefined
|
|
61
|
+
};
|
|
62
|
+
data.power = (deviceData.instantaneousPower !== undefined ? deviceData.instantaneousPower : data.power);
|
|
63
|
+
data.pedalRpm = (deviceData.rpm !== undefined ? deviceData.rpm : data.pedalRpm);
|
|
64
|
+
data.time = (deviceData.time !== undefined ? deviceData.time : data.time);
|
|
65
|
+
data.isPedalling = data.pedalRpm > 0 || (data.pedalRpm === undefined && data.power > 0);
|
|
66
|
+
return data;
|
|
67
|
+
}
|
|
68
|
+
transformData(bikeData) {
|
|
69
|
+
if (bikeData === undefined)
|
|
70
|
+
return;
|
|
71
|
+
let distance = 0;
|
|
72
|
+
if (this.distanceInternal !== undefined && bikeData.distanceInternal !== undefined) {
|
|
73
|
+
distance = Math.round(bikeData.distanceInternal - this.distanceInternal);
|
|
74
|
+
}
|
|
75
|
+
if (bikeData.distanceInternal !== undefined)
|
|
76
|
+
this.distanceInternal = bikeData.distanceInternal;
|
|
77
|
+
let data = {
|
|
78
|
+
speed: bikeData.speed,
|
|
79
|
+
slope: bikeData.slope,
|
|
80
|
+
power: bikeData.power !== undefined ? Math.round(bikeData.power) : undefined,
|
|
81
|
+
cadence: bikeData.pedalRpm !== undefined ? Math.round(bikeData.pedalRpm) : undefined,
|
|
82
|
+
distance,
|
|
83
|
+
timestamp: Date.now()
|
|
84
|
+
};
|
|
85
|
+
return data;
|
|
86
|
+
}
|
|
87
|
+
start(props) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
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 });
|
|
98
|
+
try {
|
|
99
|
+
if (comms) {
|
|
100
|
+
comms.on('data', (data) => {
|
|
101
|
+
this.onDeviceData(data);
|
|
102
|
+
});
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
this.logger.logEvent({ message: 'start result: error', error: err.message, profile: this.getProfile() });
|
|
108
|
+
throw new Error(`could not start device, reason:${err.message}`);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
sendUpdate(request) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
if (this.paused)
|
|
115
|
+
return;
|
|
116
|
+
this.getCyclingMode().sendBikeUpdate(request);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.default = BleEliteAdapter;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { LegacyProfile } from "../../antv2/types";
|
|
3
|
+
import { BleComms } from "../base/comms";
|
|
4
|
+
import { CrankData, PowerData } from "../cp";
|
|
5
|
+
import { BleProtocol, IBlePeripheralConnector } from "../types";
|
|
6
|
+
export default class BleEliteDevice 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
|
+
constructor(props?: any);
|
|
20
|
+
static isMatching(characteristics: string[]): boolean;
|
|
21
|
+
getProfile(): LegacyProfile;
|
|
22
|
+
getProtocol(): BleProtocol;
|
|
23
|
+
getServiceUUids(): string[];
|
|
24
|
+
parseCrankData(crankData: any): {
|
|
25
|
+
rpm: number;
|
|
26
|
+
time: any;
|
|
27
|
+
};
|
|
28
|
+
parsePower(_data: Uint8Array): PowerData;
|
|
29
|
+
onData(characteristic: string, data: Buffer): boolean;
|
|
30
|
+
subscribeAll(conn?: IBlePeripheralConnector): Promise<void>;
|
|
31
|
+
reset(): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const _1 = require(".");
|
|
4
|
+
const comms_1 = require("../base/comms");
|
|
5
|
+
const consts_1 = require("../consts");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
class BleEliteDevice extends comms_1.BleComms {
|
|
8
|
+
constructor(props) {
|
|
9
|
+
super(props);
|
|
10
|
+
this.instantaneousPower = undefined;
|
|
11
|
+
this.balance = undefined;
|
|
12
|
+
this.accTorque = undefined;
|
|
13
|
+
this.rpm = undefined;
|
|
14
|
+
this.timeOffset = 0;
|
|
15
|
+
this.time = undefined;
|
|
16
|
+
this.currentCrankData = undefined;
|
|
17
|
+
this.prevCrankData = undefined;
|
|
18
|
+
}
|
|
19
|
+
static isMatching(characteristics) {
|
|
20
|
+
if (!characteristics)
|
|
21
|
+
return false;
|
|
22
|
+
const hasCPMeasurement = characteristics.find(c => c === consts_1.CSP_MEASUREMENT) !== undefined;
|
|
23
|
+
const hasCPFeature = characteristics.find(c => c === consts_1.CSP_FEATURE) !== undefined;
|
|
24
|
+
return hasCPMeasurement && hasCPFeature;
|
|
25
|
+
}
|
|
26
|
+
getProfile() {
|
|
27
|
+
return 'Power Meter';
|
|
28
|
+
}
|
|
29
|
+
getProtocol() {
|
|
30
|
+
return _1.BleEliteComms.protocol;
|
|
31
|
+
}
|
|
32
|
+
getServiceUUids() {
|
|
33
|
+
return BleEliteDevice.services;
|
|
34
|
+
}
|
|
35
|
+
parseCrankData(crankData) {
|
|
36
|
+
if (!this.prevCrankData)
|
|
37
|
+
this.prevCrankData = { revolutions: 0, time: 0, cntUpdateMissing: -1 };
|
|
38
|
+
const c = this.currentCrankData = crankData;
|
|
39
|
+
const p = this.prevCrankData;
|
|
40
|
+
let rpm = this.rpm;
|
|
41
|
+
let hasUpdate = c.time !== p.time;
|
|
42
|
+
if (hasUpdate) {
|
|
43
|
+
let time = c.time - p.time;
|
|
44
|
+
let revs = c.revolutions - p.revolutions;
|
|
45
|
+
if (c.time < p.time) {
|
|
46
|
+
time += 0x10000;
|
|
47
|
+
this.timeOffset += 0x10000;
|
|
48
|
+
}
|
|
49
|
+
if (c.revolutions < p.revolutions)
|
|
50
|
+
revs += 0x10000;
|
|
51
|
+
rpm = 1024 * 60 * revs / time;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
if (p.cntUpdateMissing < 0 || p.cntUpdateMissing > 2) {
|
|
55
|
+
rpm = 0;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const cntUpdateMissing = p.cntUpdateMissing;
|
|
59
|
+
this.prevCrankData = this.currentCrankData;
|
|
60
|
+
if (hasUpdate)
|
|
61
|
+
this.prevCrankData.cntUpdateMissing = 0;
|
|
62
|
+
else
|
|
63
|
+
this.prevCrankData.cntUpdateMissing = cntUpdateMissing + 1;
|
|
64
|
+
return { rpm, time: this.timeOffset + c.time };
|
|
65
|
+
}
|
|
66
|
+
parsePower(_data) {
|
|
67
|
+
const data = Buffer.from(_data);
|
|
68
|
+
try {
|
|
69
|
+
let offset = 4;
|
|
70
|
+
const flags = data.readUInt16LE(0);
|
|
71
|
+
this.instantaneousPower = data.readUInt16LE(2);
|
|
72
|
+
if (flags & 0x1)
|
|
73
|
+
this.balance = data.readUInt8(offset++);
|
|
74
|
+
if (flags & 0x4) {
|
|
75
|
+
this.accTorque = data.readUInt16LE(offset);
|
|
76
|
+
offset += 2;
|
|
77
|
+
}
|
|
78
|
+
if (flags & 0x10) {
|
|
79
|
+
}
|
|
80
|
+
if (flags & 0x20) {
|
|
81
|
+
const crankData = {
|
|
82
|
+
revolutions: data.readUInt16LE(offset),
|
|
83
|
+
time: data.readUInt16LE(offset + 2)
|
|
84
|
+
};
|
|
85
|
+
const { rpm, time } = this.parseCrankData(crankData);
|
|
86
|
+
this.rpm = rpm;
|
|
87
|
+
this.time = time;
|
|
88
|
+
offset += 4;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
}
|
|
93
|
+
const { instantaneousPower, balance, accTorque, rpm, time } = this;
|
|
94
|
+
return { instantaneousPower, balance, accTorque, rpm, time, raw: `2a63:${data.toString('hex')}` };
|
|
95
|
+
}
|
|
96
|
+
onData(characteristic, data) {
|
|
97
|
+
const hasData = super.onData(characteristic, data);
|
|
98
|
+
if (!hasData)
|
|
99
|
+
return false;
|
|
100
|
+
if ((0, utils_1.matches)(characteristic, consts_1.CSP_MEASUREMENT)) {
|
|
101
|
+
const res = this.parsePower(data);
|
|
102
|
+
this.emit('data', res);
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
subscribeAll(conn) {
|
|
108
|
+
const characteristics = [consts_1.CSP_MEASUREMENT];
|
|
109
|
+
return this.subscribeMultiple(characteristics, conn);
|
|
110
|
+
}
|
|
111
|
+
reset() {
|
|
112
|
+
this.instantaneousPower = undefined;
|
|
113
|
+
this.balance = undefined;
|
|
114
|
+
this.accTorque = undefined;
|
|
115
|
+
this.rpm = undefined;
|
|
116
|
+
this.timeOffset = 0;
|
|
117
|
+
this.time = undefined;
|
|
118
|
+
this.currentCrankData = undefined;
|
|
119
|
+
this.prevCrankData = undefined;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.default = BleEliteDevice;
|
|
123
|
+
BleEliteDevice.protocol = 'elite';
|
|
124
|
+
BleEliteDevice.services = [consts_1.ELITE_TRAINER_SVC];
|
|
125
|
+
BleEliteDevice.characteristics = [consts_1.CSP_MEASUREMENT, consts_1.CSP_FEATURE, '2a5d', '2a3c'];
|
|
126
|
+
BleEliteDevice.detectionPriority = 10;
|
|
@@ -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.BleEliteComms = exports.BleEliteAdapter = void 0;
|
|
7
|
+
const adapter_1 = __importDefault(require("./adapter"));
|
|
8
|
+
exports.BleEliteAdapter = adapter_1.default;
|
|
9
|
+
const comms_1 = __importDefault(require("./comms"));
|
|
10
|
+
exports.BleEliteComms = comms_1.default;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import BleAdapter, { BleControllableAdapter } from '../base/adapter';
|
|
2
|
+
import CyclingMode, { IncyclistBikeData } from '../../modes/cycling-mode';
|
|
3
|
+
import { DeviceProperties } from '../../types/device';
|
|
4
|
+
import { IndoorBikeData } from './types';
|
|
5
|
+
import { DeviceData } from '../../types/data';
|
|
6
|
+
import { BleDeviceSettings, BleStartProperties } from '../types';
|
|
7
|
+
export default class BleFmAdapter extends BleControllableAdapter {
|
|
8
|
+
distanceInternal: number;
|
|
9
|
+
connectPromise: Promise<boolean>;
|
|
10
|
+
constructor(settings: BleDeviceSettings, props?: DeviceProperties);
|
|
11
|
+
isSame(device: BleAdapter): boolean;
|
|
12
|
+
getProfile(): string;
|
|
13
|
+
getName(): string;
|
|
14
|
+
getDisplayName(): string;
|
|
15
|
+
getSupportedCyclingModes(): Array<any>;
|
|
16
|
+
getDefaultCyclingMode(): CyclingMode;
|
|
17
|
+
mapData(deviceData: IndoorBikeData): IncyclistBikeData;
|
|
18
|
+
transformData(bikeData: IncyclistBikeData): DeviceData;
|
|
19
|
+
start(props?: BleStartProperties): Promise<any>;
|
|
20
|
+
sendUpdate(request: any): Promise<void>;
|
|
21
|
+
setCyclingMode(mode: string | CyclingMode, settings?: any): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
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 ble_st_mode_1 = __importDefault(require("../../modes/ble-st-mode"));
|
|
18
|
+
const ble_erg_mode_1 = __importDefault(require("../../modes/ble-erg-mode"));
|
|
19
|
+
const comms_1 = __importDefault(require("./comms"));
|
|
20
|
+
const adapter_1 = require("../base/adapter");
|
|
21
|
+
const consts_1 = require("./consts");
|
|
22
|
+
const utils_1 = require("../../utils/utils");
|
|
23
|
+
const capabilities_1 = require("../../types/capabilities");
|
|
24
|
+
class BleFmAdapter extends adapter_1.BleControllableAdapter {
|
|
25
|
+
constructor(settings, props) {
|
|
26
|
+
super(settings, props);
|
|
27
|
+
this.distanceInternal = 0;
|
|
28
|
+
this.logger = new gd_eventlog_1.EventLogger('BLE-FM');
|
|
29
|
+
const { id, address, name } = settings;
|
|
30
|
+
const logger = this.logger;
|
|
31
|
+
const ble = this.ble;
|
|
32
|
+
this.device = new comms_1.default({ id, address, name, ble, logger });
|
|
33
|
+
this.capabilities = [
|
|
34
|
+
capabilities_1.IncyclistCapability.Power, capabilities_1.IncyclistCapability.Speed, capabilities_1.IncyclistCapability.Cadence,
|
|
35
|
+
capabilities_1.IncyclistCapability.Control
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
isSame(device) {
|
|
39
|
+
if (!(device instanceof BleFmAdapter))
|
|
40
|
+
return false;
|
|
41
|
+
return this.isEqual(device.settings);
|
|
42
|
+
}
|
|
43
|
+
getProfile() {
|
|
44
|
+
return 'Smart Trainer';
|
|
45
|
+
}
|
|
46
|
+
getName() {
|
|
47
|
+
return `${this.device.name}`;
|
|
48
|
+
}
|
|
49
|
+
getDisplayName() {
|
|
50
|
+
return this.getName();
|
|
51
|
+
}
|
|
52
|
+
getSupportedCyclingModes() {
|
|
53
|
+
var _a;
|
|
54
|
+
const modes = [power_meter_1.default];
|
|
55
|
+
const features = (_a = this.getComms()) === null || _a === void 0 ? void 0 : _a.features;
|
|
56
|
+
if (!features)
|
|
57
|
+
return [power_meter_1.default, ble_st_mode_1.default, ble_erg_mode_1.default];
|
|
58
|
+
if (features.setPower === undefined || features.setPower)
|
|
59
|
+
modes.push(ble_erg_mode_1.default);
|
|
60
|
+
if (features.setSlope === undefined || features.setSlope)
|
|
61
|
+
modes.push(ble_st_mode_1.default);
|
|
62
|
+
return modes;
|
|
63
|
+
}
|
|
64
|
+
getDefaultCyclingMode() {
|
|
65
|
+
var _a;
|
|
66
|
+
const features = (_a = this.getComms()) === null || _a === void 0 ? void 0 : _a.features;
|
|
67
|
+
if (!features)
|
|
68
|
+
return new ble_st_mode_1.default(this);
|
|
69
|
+
if (features.setSlope === undefined || features.setSlope)
|
|
70
|
+
return new ble_st_mode_1.default(this);
|
|
71
|
+
if (features.setPower === undefined || features.setPower)
|
|
72
|
+
return new ble_erg_mode_1.default(this);
|
|
73
|
+
return new power_meter_1.default(this);
|
|
74
|
+
}
|
|
75
|
+
mapData(deviceData) {
|
|
76
|
+
const data = {
|
|
77
|
+
isPedalling: false,
|
|
78
|
+
power: 0,
|
|
79
|
+
pedalRpm: undefined,
|
|
80
|
+
speed: 0,
|
|
81
|
+
heartrate: 0,
|
|
82
|
+
distanceInternal: 0,
|
|
83
|
+
slope: undefined,
|
|
84
|
+
time: undefined
|
|
85
|
+
};
|
|
86
|
+
data.power = (deviceData.instantaneousPower !== undefined ? deviceData.instantaneousPower : data.power);
|
|
87
|
+
data.pedalRpm = (deviceData.cadence !== undefined ? deviceData.cadence : data.pedalRpm);
|
|
88
|
+
data.time = (deviceData.time !== undefined ? deviceData.time : data.time);
|
|
89
|
+
data.isPedalling = data.pedalRpm > 0 || (data.pedalRpm === undefined && data.power > 0);
|
|
90
|
+
data.heartrate = deviceData.heartrate || data.heartrate;
|
|
91
|
+
return data;
|
|
92
|
+
}
|
|
93
|
+
transformData(bikeData) {
|
|
94
|
+
if (bikeData === undefined)
|
|
95
|
+
return;
|
|
96
|
+
let distance = 0;
|
|
97
|
+
if (this.distanceInternal !== undefined && bikeData.distanceInternal !== undefined) {
|
|
98
|
+
distance = Math.round(bikeData.distanceInternal - this.distanceInternal);
|
|
99
|
+
}
|
|
100
|
+
if (bikeData.distanceInternal !== undefined)
|
|
101
|
+
this.distanceInternal = bikeData.distanceInternal;
|
|
102
|
+
let data = {
|
|
103
|
+
speed: bikeData.speed,
|
|
104
|
+
slope: bikeData.slope,
|
|
105
|
+
power: bikeData.power !== undefined ? Math.round(bikeData.power) : undefined,
|
|
106
|
+
cadence: bikeData.pedalRpm !== undefined ? Math.round(bikeData.pedalRpm) : undefined,
|
|
107
|
+
distance,
|
|
108
|
+
heartrate: bikeData.heartrate,
|
|
109
|
+
timestamp: Date.now()
|
|
110
|
+
};
|
|
111
|
+
return data;
|
|
112
|
+
}
|
|
113
|
+
start(props = {}) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
const wasPaused = this.paused;
|
|
116
|
+
this.resume();
|
|
117
|
+
if (this.started && !wasPaused)
|
|
118
|
+
return true;
|
|
119
|
+
this.logEvent(Object.assign(Object.assign({ message: 'start requested' }, this.getSettings()), { protocol: this.getProtocolName(), props }));
|
|
120
|
+
const { restart = wasPaused } = props;
|
|
121
|
+
if (!restart && this.ble.isScanning() && !this.getComms().isConnected()) {
|
|
122
|
+
}
|
|
123
|
+
let scanOnly = props.scanOnly;
|
|
124
|
+
if (this.ble.isScanning() && this.getComms().isConnected()) {
|
|
125
|
+
scanOnly = true;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
const { timeout = 20000 } = props || {};
|
|
129
|
+
if (!this.connectPromise)
|
|
130
|
+
this.connectPromise = this.connect();
|
|
131
|
+
const res = yield Promise.race([
|
|
132
|
+
this.connectPromise.then((connected) => {
|
|
133
|
+
this.connectPromise = undefined;
|
|
134
|
+
return { connected, reason: connected ? null : 'could not connect' };
|
|
135
|
+
}),
|
|
136
|
+
(0, utils_1.sleep)(timeout).then(() => ({ connected: false, reason: 'timeout' }))
|
|
137
|
+
]);
|
|
138
|
+
const connected = res.connected;
|
|
139
|
+
if (!connected) {
|
|
140
|
+
throw new Error(`could not start device, reason:${res.reason}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
const comms = this.device;
|
|
145
|
+
if (comms) {
|
|
146
|
+
if (!scanOnly) {
|
|
147
|
+
const mode = this.getCyclingMode();
|
|
148
|
+
if (mode && mode.getSetting('bikeType')) {
|
|
149
|
+
const bikeType = mode.getSetting('bikeType').toLowerCase();
|
|
150
|
+
comms.setCrr(consts_1.cRR);
|
|
151
|
+
switch (bikeType) {
|
|
152
|
+
case 'race':
|
|
153
|
+
comms.setCw(consts_1.cwABike.race);
|
|
154
|
+
break;
|
|
155
|
+
case 'triathlon':
|
|
156
|
+
comms.setCw(consts_1.cwABike.triathlon);
|
|
157
|
+
break;
|
|
158
|
+
case 'mountain':
|
|
159
|
+
comms.setCw(consts_1.cwABike.mountain);
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
let hasControl = yield comms.requestControl();
|
|
164
|
+
if (!hasControl) {
|
|
165
|
+
let retry = 1;
|
|
166
|
+
while (!hasControl && retry < 3) {
|
|
167
|
+
yield (0, utils_1.sleep)(1000);
|
|
168
|
+
hasControl = yield comms.requestControl();
|
|
169
|
+
retry++;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (!hasControl)
|
|
173
|
+
throw new Error('could not establish control');
|
|
174
|
+
const startRequest = this.getCyclingMode().getBikeInitRequest();
|
|
175
|
+
yield this.sendUpdate(startRequest);
|
|
176
|
+
}
|
|
177
|
+
if (!this.started && !wasPaused) {
|
|
178
|
+
comms.on('data', (data) => {
|
|
179
|
+
this.onDeviceData(data);
|
|
180
|
+
});
|
|
181
|
+
comms.on('disconnected', this.emit);
|
|
182
|
+
}
|
|
183
|
+
const before = this.capabilities.join(',');
|
|
184
|
+
if (comms.features.heartrate && !this.hasCapability(capabilities_1.IncyclistCapability.HeartRate)) {
|
|
185
|
+
this.capabilities.push(capabilities_1.IncyclistCapability.HeartRate);
|
|
186
|
+
}
|
|
187
|
+
if (comms.features.cadence && !this.hasCapability(capabilities_1.IncyclistCapability.Cadence)) {
|
|
188
|
+
this.capabilities.push(capabilities_1.IncyclistCapability.Cadence);
|
|
189
|
+
}
|
|
190
|
+
if (comms.features.power && !this.hasCapability(capabilities_1.IncyclistCapability.Power)) {
|
|
191
|
+
this.capabilities.push(capabilities_1.IncyclistCapability.Power);
|
|
192
|
+
}
|
|
193
|
+
const after = this.capabilities.join(',');
|
|
194
|
+
if (before !== after) {
|
|
195
|
+
this.emit('device-info', this.getSettings(), { capabilities: this.capabilities });
|
|
196
|
+
}
|
|
197
|
+
this.resetData();
|
|
198
|
+
this.stopped = false;
|
|
199
|
+
this.started = true;
|
|
200
|
+
this.resume();
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
catch (err) {
|
|
205
|
+
this.logEvent({ message: 'start result: error', error: err.message, profile: this.getProfile() });
|
|
206
|
+
throw new Error(`could not start device, reason:${err.message}`);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
sendUpdate(request) {
|
|
211
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
+
if (this.paused || !this.device)
|
|
213
|
+
return;
|
|
214
|
+
try {
|
|
215
|
+
const update = this.getCyclingMode().sendBikeUpdate(request);
|
|
216
|
+
this.logEvent({ message: 'send bike update requested', profile: this.getProfile(), update, request });
|
|
217
|
+
const device = this.device;
|
|
218
|
+
if (update.slope !== undefined) {
|
|
219
|
+
yield device.setSlope(update.slope);
|
|
220
|
+
}
|
|
221
|
+
if (update.targetPower !== undefined) {
|
|
222
|
+
yield device.setTargetPower(update.targetPower);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
catch (err) {
|
|
226
|
+
this.logEvent({ message: 'error', fn: 'sendUpdate()', request, error: err.message, stack: err.stack });
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
setCyclingMode(mode, settings) {
|
|
231
|
+
const modeChange = this.cyclingMode.getName() !== mode;
|
|
232
|
+
const prevMode = this.getCyclingMode();
|
|
233
|
+
super.setCyclingMode(mode, settings);
|
|
234
|
+
const isPaused = this.isPaused();
|
|
235
|
+
if (modeChange && this.started && !this.stopped) {
|
|
236
|
+
if (prevMode instanceof ble_st_mode_1.default) {
|
|
237
|
+
const power = this.data.power;
|
|
238
|
+
const request = power ? { targetPower: power } : this.getCyclingMode().getBikeInitRequest();
|
|
239
|
+
if (isPaused)
|
|
240
|
+
this.resume();
|
|
241
|
+
this.sendUpdate(request).then().catch().finally(() => {
|
|
242
|
+
if (isPaused)
|
|
243
|
+
this.pause();
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
exports.default = BleFmAdapter;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { BleProtocol, BleWriteProps, IBlePeripheralConnector } from "../types";
|
|
3
|
+
import { IndoorBikeData, IndoorBikeFeatures } from "./types";
|
|
4
|
+
import { BleComms } from "../base/comms";
|
|
5
|
+
import { LegacyProfile } from "../../antv2/types";
|
|
6
|
+
export default class BleFitnessMachineDevice extends BleComms {
|
|
7
|
+
static protocol: BleProtocol;
|
|
8
|
+
static services: string[];
|
|
9
|
+
static characteristics: string[];
|
|
10
|
+
static detectionPriority: number;
|
|
11
|
+
data: IndoorBikeData;
|
|
12
|
+
features: IndoorBikeFeatures;
|
|
13
|
+
hasControl: boolean;
|
|
14
|
+
isCheckingControl: boolean;
|
|
15
|
+
isCPSubscribed: boolean;
|
|
16
|
+
crr: number;
|
|
17
|
+
cw: number;
|
|
18
|
+
windSpeed: number;
|
|
19
|
+
wheelSize: number;
|
|
20
|
+
constructor(props?: any);
|
|
21
|
+
static isMatching(characteristics: string[]): boolean;
|
|
22
|
+
subscribeWriteResponse(cuuid: string): Promise<void>;
|
|
23
|
+
subscribeAll(conn?: IBlePeripheralConnector): Promise<void>;
|
|
24
|
+
init(): Promise<boolean>;
|
|
25
|
+
onDisconnect(): Promise<void>;
|
|
26
|
+
getProfile(): LegacyProfile;
|
|
27
|
+
getProtocol(): BleProtocol;
|
|
28
|
+
getServiceUUids(): string[];
|
|
29
|
+
parseHrm(_data: Uint8Array): IndoorBikeData;
|
|
30
|
+
setCrr(crr: number): void;
|
|
31
|
+
getCrr(): number;
|
|
32
|
+
setCw(cw: number): void;
|
|
33
|
+
getCw(): number;
|
|
34
|
+
setWindSpeed(windSpeed: number): void;
|
|
35
|
+
getWindSpeed(): number;
|
|
36
|
+
parseIndoorBikeData(_data: Uint8Array): IndoorBikeData;
|
|
37
|
+
parseFitnessMachineStatus(_data: Uint8Array): IndoorBikeData;
|
|
38
|
+
getFitnessMachineFeatures(): Promise<IndoorBikeFeatures>;
|
|
39
|
+
onData(characteristic: string, data: Buffer): boolean;
|
|
40
|
+
writeFtmsMessage(requestedOpCode: any, data: any, props?: BleWriteProps): Promise<number>;
|
|
41
|
+
requestControl(): Promise<boolean>;
|
|
42
|
+
setTargetPower(power: number): Promise<boolean>;
|
|
43
|
+
setSlope(slope: any): Promise<boolean>;
|
|
44
|
+
setTargetInclination(inclination: number): Promise<boolean>;
|
|
45
|
+
setIndoorBikeSimulation(windSpeed: number, gradient: number, crr: number, cw: number): Promise<boolean>;
|
|
46
|
+
startRequest(): Promise<boolean>;
|
|
47
|
+
stopRequest(): Promise<boolean>;
|
|
48
|
+
PauseRequest(): Promise<boolean>;
|
|
49
|
+
reset(): void;
|
|
50
|
+
}
|