incyclist-devices 1.5.38 → 2.0.0-beta.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 +0 -0
- package/lib/adapters.d.ts +6 -0
- package/lib/adapters.js +30 -0
- package/lib/antv2/adapter-factory.d.ts +20 -10
- package/lib/antv2/adapter-factory.js +49 -33
- package/lib/antv2/adapter.d.ts +64 -0
- package/lib/antv2/adapter.js +299 -0
- package/lib/antv2/ant-interface.d.ts +11 -9
- package/lib/antv2/ant-interface.js +15 -11
- package/lib/antv2/fe/adapter.d.ts +25 -0
- package/lib/antv2/{fe.js → fe/adapter.js} +48 -72
- package/lib/antv2/fe/index.d.ts +2 -0
- package/lib/antv2/fe/index.js +7 -0
- package/lib/antv2/hr/adapter.d.ts +14 -0
- package/lib/antv2/hr/adapter.js +73 -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 +22 -0
- package/lib/antv2/{pwr.js → pwr/adapter.js} +38 -76
- package/lib/antv2/pwr/index.d.ts +2 -0
- package/lib/antv2/pwr/index.js +7 -0
- package/lib/antv2/types.d.ts +19 -0
- package/lib/antv2/types.js +2 -0
- package/lib/antv2/utils.d.ts +1 -0
- package/lib/antv2/utils.js +181 -0
- package/lib/base/adpater.d.ts +56 -0
- package/lib/base/adpater.js +144 -0
- package/lib/ble/adapter-factory.d.ts +31 -0
- package/lib/ble/adapter-factory.js +96 -0
- package/lib/ble/adapter.d.ts +41 -0
- package/lib/ble/adapter.js +188 -0
- package/lib/ble/{ble-device.d.ts → ble-comms.d.ts} +9 -4
- package/lib/ble/{ble-device.js → ble-comms.js} +23 -11
- package/lib/ble/ble-interface.d.ts +15 -24
- package/lib/ble/ble-interface.js +32 -137
- package/lib/ble/ble-peripheral.d.ts +3 -3
- package/lib/ble/ble-peripheral.js +14 -14
- package/lib/ble/ble.d.ts +9 -81
- package/lib/ble/ble.js +1 -39
- package/lib/ble/consts.d.ts +2 -0
- package/lib/ble/consts.js +3 -1
- package/lib/ble/cp/adapter.d.ts +23 -0
- package/lib/ble/cp/adapter.js +124 -0
- package/lib/ble/cp/comm.d.ts +28 -0
- package/lib/ble/cp/comm.js +140 -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 +20 -0
- package/lib/ble/elite/adapter.js +127 -0
- package/lib/ble/elite/comms.d.ts +28 -0
- package/lib/ble/elite/comms.js +139 -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 +21 -0
- package/lib/ble/fm/adapter.js +190 -0
- package/lib/ble/fm/comms.d.ts +50 -0
- package/lib/ble/{fm.js → fm/comms.js} +3 -224
- 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 +25 -0
- package/lib/ble/fm/types.js +2 -0
- package/lib/ble/hr/adapter.d.ts +17 -0
- package/lib/ble/hr/adapter.js +62 -0
- package/lib/ble/hr/comm.d.ts +15 -0
- package/lib/ble/hr/comm.js +52 -0
- package/lib/ble/hr/index.d.ts +4 -0
- package/lib/ble/hr/index.js +10 -0
- package/lib/ble/hr/types.d.ts +5 -0
- package/lib/ble/hr/types.js +2 -0
- package/lib/ble/index.d.ts +8 -0
- package/lib/ble/index.js +26 -0
- package/lib/ble/tacx/adapter.d.ts +10 -0
- package/lib/ble/tacx/adapter.js +93 -0
- package/lib/ble/{tacx.d.ts → tacx/comms.d.ts} +6 -38
- package/lib/ble/{tacx.js → tacx/comms.js} +13 -112
- 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 +101 -0
- package/lib/ble/types.js +19 -0
- package/lib/ble/utils.d.ts +7 -0
- package/lib/ble/utils.js +95 -0
- package/lib/ble/wahoo/adapter.d.ts +9 -0
- package/lib/ble/wahoo/adapter.js +93 -0
- package/lib/ble/{wahoo-kickr.d.ts → wahoo/comms.d.ts} +5 -39
- package/lib/ble/{wahoo-kickr.js → wahoo/comms.js} +14 -112
- 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/device.d.ts +0 -94
- package/lib/device.js +0 -76
- package/lib/index.d.ts +12 -0
- package/lib/index.js +38 -0
- package/lib/interfaces.d.ts +6 -0
- package/lib/interfaces.js +23 -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 +4 -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 +16 -0
- package/lib/serial/adapter.js +42 -0
- package/lib/serial/bindings/tcp.d.ts +44 -0
- package/lib/serial/bindings/tcp.js +270 -0
- package/lib/serial/comm.d.ts +7 -0
- package/lib/serial/comm.js +2 -0
- package/lib/{daum → serial/daum}/DaumAdapter.d.ts +13 -22
- package/lib/{daum → serial/daum}/DaumAdapter.js +44 -90
- 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 +24 -0
- package/lib/{daum/premium/DaumPremiumAdapter.js → serial/daum/premium/adapter.js} +99 -46
- 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} +208 -420
- package/lib/serial/daum/premium/mock.d.ts +75 -0
- package/lib/serial/daum/premium/mock.js +290 -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 +13 -24
- package/lib/{kettler → serial/kettler}/ergo-racer/adapter.js +87 -130
- 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 +58 -0
- package/lib/serial/serial-interface.js +283 -0
- package/lib/simulator/Simulator.d.ts +10 -25
- package/lib/simulator/Simulator.js +19 -83
- package/lib/types/adapter.d.ts +32 -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 +29 -0
- package/lib/types/device.js +11 -0
- package/lib/types/interface.d.ts +14 -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 +15 -11
- 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/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/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/antv2/{ant-binding.d.ts → binding.d.ts} +0 -0
- /package/lib/antv2/{ant-binding.js → binding.js} +0 -0
- /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
package/lib/ble/elite.js
DELETED
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
-
};
|
|
33
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.EliteAdapter = exports.ELITE_TRAINER_SVC = void 0;
|
|
35
|
-
const ble_device_1 = require("./ble-device");
|
|
36
|
-
const ble_interface_1 = __importDefault(require("./ble-interface"));
|
|
37
|
-
const ble_1 = require("./ble");
|
|
38
|
-
const device_1 = __importStar(require("../device"));
|
|
39
|
-
const gd_eventlog_1 = require("gd-eventlog");
|
|
40
|
-
const consts_1 = require("./consts");
|
|
41
|
-
const power_meter_1 = __importDefault(require("../modes/power-meter"));
|
|
42
|
-
exports.ELITE_TRAINER_SVC = '347b0001';
|
|
43
|
-
class BleEliteDevice extends ble_device_1.BleDevice {
|
|
44
|
-
constructor(props) {
|
|
45
|
-
super(props);
|
|
46
|
-
this.instantaneousPower = undefined;
|
|
47
|
-
this.balance = undefined;
|
|
48
|
-
this.accTorque = undefined;
|
|
49
|
-
this.rpm = undefined;
|
|
50
|
-
this.timeOffset = 0;
|
|
51
|
-
this.time = undefined;
|
|
52
|
-
this.currentCrankData = undefined;
|
|
53
|
-
this.prevCrankData = undefined;
|
|
54
|
-
}
|
|
55
|
-
isMatching(characteristics) {
|
|
56
|
-
if (!characteristics)
|
|
57
|
-
return false;
|
|
58
|
-
const hasCPMeasurement = characteristics.find(c => c === consts_1.CSP_MEASUREMENT) !== undefined;
|
|
59
|
-
const hasCPFeature = characteristics.find(c => c === consts_1.CSP_FEATURE) !== undefined;
|
|
60
|
-
return hasCPMeasurement && hasCPFeature;
|
|
61
|
-
}
|
|
62
|
-
init() {
|
|
63
|
-
const _super = Object.create(null, {
|
|
64
|
-
init: { get: () => super.init }
|
|
65
|
-
});
|
|
66
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
try {
|
|
68
|
-
yield _super.init.call(this);
|
|
69
|
-
}
|
|
70
|
-
catch (err) {
|
|
71
|
-
return Promise.resolve(false);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
getProfile() {
|
|
76
|
-
return 'Power Meter';
|
|
77
|
-
}
|
|
78
|
-
getServiceUUids() {
|
|
79
|
-
return BleEliteDevice.services;
|
|
80
|
-
}
|
|
81
|
-
parseCrankData(crankData) {
|
|
82
|
-
if (!this.prevCrankData)
|
|
83
|
-
this.prevCrankData = { revolutions: 0, time: 0, cntUpdateMissing: -1 };
|
|
84
|
-
const c = this.currentCrankData = crankData;
|
|
85
|
-
const p = this.prevCrankData;
|
|
86
|
-
let rpm = this.rpm;
|
|
87
|
-
let hasUpdate = c.time !== p.time;
|
|
88
|
-
if (hasUpdate) {
|
|
89
|
-
let time = c.time - p.time;
|
|
90
|
-
let revs = c.revolutions - p.revolutions;
|
|
91
|
-
if (c.time < p.time) {
|
|
92
|
-
time += 0x10000;
|
|
93
|
-
this.timeOffset += 0x10000;
|
|
94
|
-
}
|
|
95
|
-
if (c.revolutions < p.revolutions)
|
|
96
|
-
revs += 0x10000;
|
|
97
|
-
rpm = 1024 * 60 * revs / time;
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
if (p.cntUpdateMissing < 0 || p.cntUpdateMissing > 2) {
|
|
101
|
-
rpm = 0;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
const cntUpdateMissing = p.cntUpdateMissing;
|
|
105
|
-
this.prevCrankData = this.currentCrankData;
|
|
106
|
-
if (hasUpdate)
|
|
107
|
-
this.prevCrankData.cntUpdateMissing = 0;
|
|
108
|
-
else
|
|
109
|
-
this.prevCrankData.cntUpdateMissing = cntUpdateMissing + 1;
|
|
110
|
-
return { rpm, time: this.timeOffset + c.time };
|
|
111
|
-
}
|
|
112
|
-
parsePower(_data) {
|
|
113
|
-
const data = Buffer.from(_data);
|
|
114
|
-
try {
|
|
115
|
-
let offset = 4;
|
|
116
|
-
const flags = data.readUInt16LE(0);
|
|
117
|
-
this.instantaneousPower = data.readUInt16LE(2);
|
|
118
|
-
if (flags & 0x1)
|
|
119
|
-
this.balance = data.readUInt8(offset++);
|
|
120
|
-
if (flags & 0x4) {
|
|
121
|
-
this.accTorque = data.readUInt16LE(offset);
|
|
122
|
-
offset += 2;
|
|
123
|
-
}
|
|
124
|
-
if (flags & 0x10) {
|
|
125
|
-
}
|
|
126
|
-
if (flags & 0x20) {
|
|
127
|
-
const crankData = {
|
|
128
|
-
revolutions: data.readUInt16LE(offset),
|
|
129
|
-
time: data.readUInt16LE(offset + 2)
|
|
130
|
-
};
|
|
131
|
-
const { rpm, time } = this.parseCrankData(crankData);
|
|
132
|
-
this.rpm = rpm;
|
|
133
|
-
this.time = time;
|
|
134
|
-
offset += 4;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
catch (err) {
|
|
138
|
-
}
|
|
139
|
-
const { instantaneousPower, balance, accTorque, rpm, time } = this;
|
|
140
|
-
return { instantaneousPower, balance, accTorque, rpm, time, raw: `2a63:${data.toString('hex')}` };
|
|
141
|
-
}
|
|
142
|
-
onData(characteristic, data) {
|
|
143
|
-
const hasData = super.onData(characteristic, data);
|
|
144
|
-
if (!hasData)
|
|
145
|
-
return false;
|
|
146
|
-
if ((0, ble_1.matches)(characteristic, consts_1.CSP_MEASUREMENT)) {
|
|
147
|
-
const res = this.parsePower(data);
|
|
148
|
-
this.emit('data', res);
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
153
|
-
reset() {
|
|
154
|
-
this.instantaneousPower = undefined;
|
|
155
|
-
this.balance = undefined;
|
|
156
|
-
this.accTorque = undefined;
|
|
157
|
-
this.rpm = undefined;
|
|
158
|
-
this.timeOffset = 0;
|
|
159
|
-
this.time = undefined;
|
|
160
|
-
this.currentCrankData = undefined;
|
|
161
|
-
this.prevCrankData = undefined;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
exports.default = BleEliteDevice;
|
|
165
|
-
BleEliteDevice.services = [exports.ELITE_TRAINER_SVC];
|
|
166
|
-
BleEliteDevice.characteristics = [consts_1.CSP_MEASUREMENT, consts_1.CSP_FEATURE, '2a5d', '2a3c'];
|
|
167
|
-
BleEliteDevice.detectionPriority = 10;
|
|
168
|
-
ble_interface_1.default.register('BleCyclingPowerDevice', 'cp', BleEliteDevice, BleEliteDevice.services);
|
|
169
|
-
class EliteAdapter extends device_1.default {
|
|
170
|
-
constructor(device, protocol) {
|
|
171
|
-
super(protocol);
|
|
172
|
-
this.ignore = false;
|
|
173
|
-
this.paused = false;
|
|
174
|
-
this.distanceInternal = 0;
|
|
175
|
-
this.device = device;
|
|
176
|
-
this.ble = protocol.ble;
|
|
177
|
-
this.mode = this.getDefaultCyclingMode();
|
|
178
|
-
this.logger = new gd_eventlog_1.EventLogger('Ble-Elite');
|
|
179
|
-
}
|
|
180
|
-
isBike() { return true; }
|
|
181
|
-
isHrm() { return false; }
|
|
182
|
-
isPower() { return true; }
|
|
183
|
-
isSame(device) {
|
|
184
|
-
if (!(device instanceof EliteAdapter))
|
|
185
|
-
return false;
|
|
186
|
-
const adapter = device;
|
|
187
|
-
return (adapter.getName() === this.getName() && adapter.getProfile() === this.getProfile());
|
|
188
|
-
}
|
|
189
|
-
getProfile() {
|
|
190
|
-
return 'Elite Smart Trainer';
|
|
191
|
-
}
|
|
192
|
-
getName() {
|
|
193
|
-
return `${this.device.name}`;
|
|
194
|
-
}
|
|
195
|
-
getDisplayName() {
|
|
196
|
-
const { name, instantaneousPower: power } = this.device;
|
|
197
|
-
const powerStr = power ? ` (${power})` : '';
|
|
198
|
-
return `${name}${powerStr}`;
|
|
199
|
-
}
|
|
200
|
-
getCyclingMode() {
|
|
201
|
-
if (!this.mode)
|
|
202
|
-
this.mode = this.getDefaultCyclingMode();
|
|
203
|
-
return this.mode;
|
|
204
|
-
}
|
|
205
|
-
getDefaultCyclingMode() {
|
|
206
|
-
return new power_meter_1.default(this);
|
|
207
|
-
}
|
|
208
|
-
getSupportedCyclingModes() {
|
|
209
|
-
return [power_meter_1.default];
|
|
210
|
-
}
|
|
211
|
-
getPort() {
|
|
212
|
-
return 'ble';
|
|
213
|
-
}
|
|
214
|
-
getWeight() {
|
|
215
|
-
let userWeight = device_1.DEFAULT_USER_WEIGHT;
|
|
216
|
-
let bikeWeight = device_1.DEFAULT_BIKE_WEIGHT;
|
|
217
|
-
if (this.userSettings && this.userSettings.weight) {
|
|
218
|
-
userWeight = Number(this.userSettings.weight);
|
|
219
|
-
}
|
|
220
|
-
if (this.bikeSettings && this.bikeSettings.weight) {
|
|
221
|
-
bikeWeight = Number(this.bikeSettings.weight);
|
|
222
|
-
}
|
|
223
|
-
return bikeWeight + userWeight;
|
|
224
|
-
}
|
|
225
|
-
setIgnoreBike(ignore) {
|
|
226
|
-
this.ignore = ignore;
|
|
227
|
-
}
|
|
228
|
-
setIgnorePower(ignore) {
|
|
229
|
-
this.ignore = ignore;
|
|
230
|
-
}
|
|
231
|
-
onDeviceData(deviceData) {
|
|
232
|
-
if (this.prevDataTS && Date.now() - this.prevDataTS < 1000)
|
|
233
|
-
return;
|
|
234
|
-
this.prevDataTS = Date.now();
|
|
235
|
-
this.logger.logEvent({ message: 'onDeviceData', data: deviceData });
|
|
236
|
-
let incyclistData = this.mapData(deviceData);
|
|
237
|
-
incyclistData = this.getCyclingMode().updateData(incyclistData);
|
|
238
|
-
const data = this.transformData(incyclistData);
|
|
239
|
-
if (this.onDataFn && !this.ignore && !this.paused)
|
|
240
|
-
this.onDataFn(data);
|
|
241
|
-
}
|
|
242
|
-
mapData(deviceData) {
|
|
243
|
-
const data = {
|
|
244
|
-
isPedalling: false,
|
|
245
|
-
power: 0,
|
|
246
|
-
pedalRpm: undefined,
|
|
247
|
-
speed: 0,
|
|
248
|
-
heartrate: 0,
|
|
249
|
-
distanceInternal: 0,
|
|
250
|
-
slope: undefined,
|
|
251
|
-
time: undefined
|
|
252
|
-
};
|
|
253
|
-
data.power = (deviceData.instantaneousPower !== undefined ? deviceData.instantaneousPower : data.power);
|
|
254
|
-
data.pedalRpm = (deviceData.rpm !== undefined ? deviceData.rpm : data.pedalRpm);
|
|
255
|
-
data.time = (deviceData.time !== undefined ? deviceData.time : data.time);
|
|
256
|
-
data.isPedalling = data.pedalRpm > 0 || (data.pedalRpm === undefined && data.power > 0);
|
|
257
|
-
return data;
|
|
258
|
-
}
|
|
259
|
-
transformData(bikeData) {
|
|
260
|
-
if (this.ignore) {
|
|
261
|
-
return {};
|
|
262
|
-
}
|
|
263
|
-
if (bikeData === undefined)
|
|
264
|
-
return;
|
|
265
|
-
let distance = 0;
|
|
266
|
-
if (this.distanceInternal !== undefined && bikeData.distanceInternal !== undefined) {
|
|
267
|
-
distance = Math.round(bikeData.distanceInternal - this.distanceInternal);
|
|
268
|
-
}
|
|
269
|
-
if (bikeData.distanceInternal !== undefined)
|
|
270
|
-
this.distanceInternal = bikeData.distanceInternal;
|
|
271
|
-
let data = {
|
|
272
|
-
speed: bikeData.speed,
|
|
273
|
-
slope: bikeData.slope,
|
|
274
|
-
power: bikeData.power !== undefined ? Math.round(bikeData.power) : undefined,
|
|
275
|
-
cadence: bikeData.pedalRpm !== undefined ? Math.round(bikeData.pedalRpm) : undefined,
|
|
276
|
-
distance,
|
|
277
|
-
timestamp: Date.now()
|
|
278
|
-
};
|
|
279
|
-
return data;
|
|
280
|
-
}
|
|
281
|
-
start(props) {
|
|
282
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
283
|
-
if (props && props.user)
|
|
284
|
-
this.userSettings = props.user;
|
|
285
|
-
if (props && props.bikeSettings)
|
|
286
|
-
this.bikeSettings = props.bikeSettings;
|
|
287
|
-
this.logger.logEvent({ message: 'csp: start requested', profile: this.getProfile(), props });
|
|
288
|
-
try {
|
|
289
|
-
const bleDevice = yield this.ble.connectDevice(this.device);
|
|
290
|
-
if (bleDevice) {
|
|
291
|
-
this.device = bleDevice;
|
|
292
|
-
bleDevice.on('data', (data) => {
|
|
293
|
-
this.onDeviceData(data);
|
|
294
|
-
});
|
|
295
|
-
return true;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
catch (err) {
|
|
299
|
-
this.logger.logEvent({ message: 'start result: error', error: err.message, profile: this.getProfile() });
|
|
300
|
-
throw new Error(`could not start device, reason:${err.message}`);
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
stop() {
|
|
305
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
306
|
-
this.logger.logEvent({ message: 'stop requested', profile: this.getProfile() });
|
|
307
|
-
this.distanceInternal = 0;
|
|
308
|
-
this.device.reset();
|
|
309
|
-
return this.device.disconnect();
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
sendUpdate(request) {
|
|
313
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
314
|
-
if (this.paused)
|
|
315
|
-
return;
|
|
316
|
-
this.getCyclingMode().sendBikeUpdate(request);
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
pause() { this.paused = true; return Promise.resolve(true); }
|
|
320
|
-
resume() { this.paused = false; return Promise.resolve(true); }
|
|
321
|
-
}
|
|
322
|
-
exports.EliteAdapter = EliteAdapter;
|
package/lib/ble/fm.d.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { BleDevice } from './ble-device';
|
|
3
|
-
import BleInterface from './ble-interface';
|
|
4
|
-
import BleProtocol from './incyclist-protocol';
|
|
5
|
-
import { BleDeviceClass, BleWriteProps } from './ble';
|
|
6
|
-
import DeviceAdapter, { DeviceData } from '../device';
|
|
7
|
-
import { DeviceProtocol } from '../protocol';
|
|
8
|
-
import { EventLogger } from 'gd-eventlog';
|
|
9
|
-
import CyclingMode from '../cycling-mode';
|
|
10
|
-
import { IncyclistBikeData } from '../cycling-mode';
|
|
11
|
-
import BlePeripheralConnector from './ble-peripheral';
|
|
12
|
-
declare type PowerData = {
|
|
13
|
-
instantaneousPower?: number;
|
|
14
|
-
balance?: number;
|
|
15
|
-
accTorque?: number;
|
|
16
|
-
time: number;
|
|
17
|
-
rpm: number;
|
|
18
|
-
raw?: string;
|
|
19
|
-
};
|
|
20
|
-
export declare type IndoorBikeData = {
|
|
21
|
-
speed?: number;
|
|
22
|
-
averageSpeed?: number;
|
|
23
|
-
cadence?: number;
|
|
24
|
-
averageCadence?: number;
|
|
25
|
-
totalDistance?: number;
|
|
26
|
-
resistanceLevel?: number;
|
|
27
|
-
instantaneousPower?: number;
|
|
28
|
-
averagePower?: number;
|
|
29
|
-
totalEnergy?: number;
|
|
30
|
-
energyPerHour?: number;
|
|
31
|
-
energyPerMinute?: number;
|
|
32
|
-
heartrate?: number;
|
|
33
|
-
metabolicEquivalent?: number;
|
|
34
|
-
time?: number;
|
|
35
|
-
remainingTime?: number;
|
|
36
|
-
raw?: string;
|
|
37
|
-
targetPower?: number;
|
|
38
|
-
targetInclination?: number;
|
|
39
|
-
status?: string;
|
|
40
|
-
};
|
|
41
|
-
declare type IndoorBikeFeatures = {
|
|
42
|
-
fitnessMachine: number;
|
|
43
|
-
targetSettings: number;
|
|
44
|
-
};
|
|
45
|
-
export default class BleFitnessMachineDevice extends BleDevice {
|
|
46
|
-
static services: string[];
|
|
47
|
-
static characteristics: string[];
|
|
48
|
-
static detectionPriority: number;
|
|
49
|
-
data: IndoorBikeData;
|
|
50
|
-
features: IndoorBikeFeatures;
|
|
51
|
-
hasControl: boolean;
|
|
52
|
-
isCheckingControl: boolean;
|
|
53
|
-
isCPSubscribed: boolean;
|
|
54
|
-
crr: number;
|
|
55
|
-
cw: number;
|
|
56
|
-
windSpeed: number;
|
|
57
|
-
wheelSize: number;
|
|
58
|
-
constructor(props?: any);
|
|
59
|
-
isMatching(characteristics: string[]): boolean;
|
|
60
|
-
subscribeWriteResponse(cuuid: string): Promise<void>;
|
|
61
|
-
subscribeAll(conn?: BlePeripheralConnector): Promise<void>;
|
|
62
|
-
init(): Promise<boolean>;
|
|
63
|
-
onDisconnect(): void;
|
|
64
|
-
getProfile(): string;
|
|
65
|
-
getServiceUUids(): string[];
|
|
66
|
-
isBike(): boolean;
|
|
67
|
-
isPower(): boolean;
|
|
68
|
-
isHrm(): boolean;
|
|
69
|
-
parseHrm(_data: Uint8Array): IndoorBikeData;
|
|
70
|
-
setCrr(crr: number): void;
|
|
71
|
-
getCrr(): number;
|
|
72
|
-
setCw(cw: number): void;
|
|
73
|
-
getCw(): number;
|
|
74
|
-
setWindSpeed(windSpeed: number): void;
|
|
75
|
-
getWindSpeed(): number;
|
|
76
|
-
parseIndoorBikeData(_data: Uint8Array): IndoorBikeData;
|
|
77
|
-
parseFitnessMachineStatus(_data: Uint8Array): IndoorBikeData;
|
|
78
|
-
getFitnessMachineFeatures(): Promise<IndoorBikeFeatures>;
|
|
79
|
-
onData(characteristic: string, data: Buffer): boolean;
|
|
80
|
-
writeFtmsMessage(requestedOpCode: any, data: any, props?: BleWriteProps): Promise<number>;
|
|
81
|
-
requestControl(): Promise<boolean>;
|
|
82
|
-
setTargetPower(power: number): Promise<boolean>;
|
|
83
|
-
setSlope(slope: any): Promise<boolean>;
|
|
84
|
-
setTargetInclination(inclination: number): Promise<boolean>;
|
|
85
|
-
setIndoorBikeSimulation(windSpeed: number, gradient: number, crr: number, cw: number): Promise<boolean>;
|
|
86
|
-
startRequest(): Promise<boolean>;
|
|
87
|
-
stopRequest(): Promise<boolean>;
|
|
88
|
-
PauseRequest(): Promise<boolean>;
|
|
89
|
-
reset(): void;
|
|
90
|
-
}
|
|
91
|
-
export declare class FmAdapter extends DeviceAdapter {
|
|
92
|
-
device: BleFitnessMachineDevice;
|
|
93
|
-
ignore: boolean;
|
|
94
|
-
ble: BleInterface;
|
|
95
|
-
protocol: DeviceProtocol;
|
|
96
|
-
paused: boolean;
|
|
97
|
-
logger: EventLogger;
|
|
98
|
-
cyclingMode: CyclingMode;
|
|
99
|
-
distanceInternal: number;
|
|
100
|
-
prevDataTS: number;
|
|
101
|
-
constructor(device: BleDeviceClass, protocol: BleProtocol);
|
|
102
|
-
isBike(): boolean;
|
|
103
|
-
isHrm(): boolean;
|
|
104
|
-
isPower(): boolean;
|
|
105
|
-
isSame(device: DeviceAdapter): boolean;
|
|
106
|
-
getProfile(): string;
|
|
107
|
-
getName(): string;
|
|
108
|
-
getDisplayName(): string;
|
|
109
|
-
getSupportedCyclingModes(): Array<any>;
|
|
110
|
-
setCyclingMode(mode: string | CyclingMode, settings?: any): void;
|
|
111
|
-
getCyclingMode(): CyclingMode;
|
|
112
|
-
getDefaultCyclingMode(): CyclingMode;
|
|
113
|
-
getPort(): string;
|
|
114
|
-
setIgnoreBike(ignore: any): void;
|
|
115
|
-
setIgnorePower(ignore: any): void;
|
|
116
|
-
onDeviceData(deviceData: PowerData): void;
|
|
117
|
-
mapData(deviceData: IndoorBikeData): IncyclistBikeData;
|
|
118
|
-
transformData(bikeData: IncyclistBikeData): DeviceData;
|
|
119
|
-
start(props?: any): Promise<any>;
|
|
120
|
-
stop(): Promise<boolean>;
|
|
121
|
-
sendUpdate(request: any): Promise<void>;
|
|
122
|
-
pause(): Promise<boolean>;
|
|
123
|
-
resume(): Promise<boolean>;
|
|
124
|
-
}
|
|
125
|
-
export {};
|
package/lib/ble/hrm.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { BleDevice } from './ble-device';
|
|
3
|
-
import BleInterface from './ble-interface';
|
|
4
|
-
import DeviceAdapter from '../device';
|
|
5
|
-
import { DeviceProtocol } from '../protocol';
|
|
6
|
-
import { BleDeviceClass } from './ble';
|
|
7
|
-
import BleProtocol from './incyclist-protocol';
|
|
8
|
-
import { EventLogger } from 'gd-eventlog';
|
|
9
|
-
declare type HrmData = {
|
|
10
|
-
heartrate: number;
|
|
11
|
-
rr: number;
|
|
12
|
-
raw: string;
|
|
13
|
-
};
|
|
14
|
-
export default class BleHrmDevice extends BleDevice {
|
|
15
|
-
static services: string[];
|
|
16
|
-
static characteristics: string[];
|
|
17
|
-
static detectionPriority: number;
|
|
18
|
-
heartrate: number;
|
|
19
|
-
rr: number;
|
|
20
|
-
constructor(props?: any);
|
|
21
|
-
getProfile(): string;
|
|
22
|
-
getServiceUUids(): string[];
|
|
23
|
-
parseHrm(_data: Uint8Array): HrmData;
|
|
24
|
-
onData(characteristic: string, data: Buffer): boolean;
|
|
25
|
-
}
|
|
26
|
-
export declare class HrmAdapter extends DeviceAdapter {
|
|
27
|
-
device: BleHrmDevice;
|
|
28
|
-
ignore: boolean;
|
|
29
|
-
ble: BleInterface;
|
|
30
|
-
protocol: DeviceProtocol;
|
|
31
|
-
paused: boolean;
|
|
32
|
-
logger: EventLogger;
|
|
33
|
-
constructor(device: BleDeviceClass, protocol: BleProtocol);
|
|
34
|
-
isBike(): boolean;
|
|
35
|
-
isHrm(): boolean;
|
|
36
|
-
isPower(): boolean;
|
|
37
|
-
isSame(device: DeviceAdapter): boolean;
|
|
38
|
-
getProfile(): string;
|
|
39
|
-
getName(): string;
|
|
40
|
-
getDisplayName(): string;
|
|
41
|
-
getPort(): string;
|
|
42
|
-
setIgnoreHrm(ignore: any): void;
|
|
43
|
-
start(props?: any): Promise<any>;
|
|
44
|
-
stop(): Promise<boolean>;
|
|
45
|
-
pause(): Promise<boolean>;
|
|
46
|
-
resume(): Promise<boolean>;
|
|
47
|
-
}
|
|
48
|
-
export {};
|
package/lib/ble/hrm.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
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
|
-
exports.HrmAdapter = void 0;
|
|
16
|
-
const ble_device_1 = require("./ble-device");
|
|
17
|
-
const ble_interface_1 = __importDefault(require("./ble-interface"));
|
|
18
|
-
const device_1 = __importDefault(require("../device"));
|
|
19
|
-
const gd_eventlog_1 = require("gd-eventlog");
|
|
20
|
-
class BleHrmDevice extends ble_device_1.BleDevice {
|
|
21
|
-
constructor(props) {
|
|
22
|
-
super(props);
|
|
23
|
-
this.heartrate = undefined;
|
|
24
|
-
this.rr = undefined;
|
|
25
|
-
}
|
|
26
|
-
getProfile() {
|
|
27
|
-
return 'Heartrate Monitor';
|
|
28
|
-
}
|
|
29
|
-
getServiceUUids() {
|
|
30
|
-
return BleHrmDevice.services;
|
|
31
|
-
}
|
|
32
|
-
parseHrm(_data) {
|
|
33
|
-
const data = Buffer.from(_data);
|
|
34
|
-
try {
|
|
35
|
-
const flags = data.readUInt8(0);
|
|
36
|
-
let offset = 2;
|
|
37
|
-
if (flags % 1 === 0) {
|
|
38
|
-
this.heartrate = data.readUInt8(1);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
this.heartrate = data.readUInt16LE(1);
|
|
42
|
-
offset = 3;
|
|
43
|
-
}
|
|
44
|
-
if (flags % 0xF) {
|
|
45
|
-
this.rr = (data.readUInt16LE(offset)) / 1024;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
catch (err) {
|
|
49
|
-
}
|
|
50
|
-
const { heartrate, rr } = this;
|
|
51
|
-
return { heartrate, rr, raw: data.toString('hex') };
|
|
52
|
-
}
|
|
53
|
-
onData(characteristic, data) {
|
|
54
|
-
const hasData = super.onData(characteristic, data);
|
|
55
|
-
if (!hasData)
|
|
56
|
-
return;
|
|
57
|
-
if (characteristic.toLocaleLowerCase() === '2a37') {
|
|
58
|
-
const res = this.parseHrm(data);
|
|
59
|
-
this.emit('data', res);
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.default = BleHrmDevice;
|
|
66
|
-
BleHrmDevice.services = ['180d'];
|
|
67
|
-
BleHrmDevice.characteristics = ['2a37', '2a38', '2a39', '2a3c'];
|
|
68
|
-
BleHrmDevice.detectionPriority = 1;
|
|
69
|
-
ble_interface_1.default.register('BleHrmDevice', 'hr', BleHrmDevice, BleHrmDevice.services);
|
|
70
|
-
class HrmAdapter extends device_1.default {
|
|
71
|
-
constructor(device, protocol) {
|
|
72
|
-
super(protocol);
|
|
73
|
-
this.ignore = false;
|
|
74
|
-
this.paused = false;
|
|
75
|
-
this.device = device;
|
|
76
|
-
this.ble = protocol.ble;
|
|
77
|
-
this.logger = new gd_eventlog_1.EventLogger('Ble-HR');
|
|
78
|
-
}
|
|
79
|
-
isBike() { return false; }
|
|
80
|
-
isHrm() { return true; }
|
|
81
|
-
isPower() { return false; }
|
|
82
|
-
isSame(device) {
|
|
83
|
-
if (!(device instanceof HrmAdapter))
|
|
84
|
-
return false;
|
|
85
|
-
const adapter = device;
|
|
86
|
-
return (adapter.getName() === this.getName() && adapter.getProfile() === this.getProfile());
|
|
87
|
-
}
|
|
88
|
-
getProfile() {
|
|
89
|
-
return 'Heartrate Monitor';
|
|
90
|
-
}
|
|
91
|
-
getName() {
|
|
92
|
-
return `${this.device.name}`;
|
|
93
|
-
}
|
|
94
|
-
getDisplayName() {
|
|
95
|
-
const { name, heartrate: hrm } = this.device;
|
|
96
|
-
const hrmStr = hrm ? ` (${hrm})` : '';
|
|
97
|
-
return `${name}${hrmStr}`;
|
|
98
|
-
}
|
|
99
|
-
getPort() {
|
|
100
|
-
return 'ble';
|
|
101
|
-
}
|
|
102
|
-
setIgnoreHrm(ignore) {
|
|
103
|
-
this.ignore = ignore;
|
|
104
|
-
}
|
|
105
|
-
start(props) {
|
|
106
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
-
this.logger.logEvent({ message: 'hrm: start requested', profile: this.getProfile(), props });
|
|
108
|
-
try {
|
|
109
|
-
const bleDevice = yield this.ble.connectDevice(this.device);
|
|
110
|
-
if (bleDevice) {
|
|
111
|
-
this.device = bleDevice;
|
|
112
|
-
bleDevice.on('data', (data) => {
|
|
113
|
-
if (this.onDataFn && !this.ignore && !this.paused)
|
|
114
|
-
this.onDataFn(data);
|
|
115
|
-
});
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
catch (err) {
|
|
120
|
-
this.logger.logEvent({ message: 'start result: error', error: err.message, profile: this.getProfile() });
|
|
121
|
-
throw new Error(`could not start device, reason:${err.message}`);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
stop() {
|
|
126
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
this.logger.logEvent({ message: 'stop requested', profile: this.getProfile() });
|
|
128
|
-
return this.device.disconnect();
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
pause() { this.paused = true; return Promise.resolve(true); }
|
|
132
|
-
resume() { this.paused = false; return Promise.resolve(true); }
|
|
133
|
-
}
|
|
134
|
-
exports.HrmAdapter = HrmAdapter;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { EventLogger } from "gd-eventlog";
|
|
2
|
-
import DeviceProtocolBase, { DeviceProtocol, DeviceSettings, ScanProps, Device } from "../protocol";
|
|
3
|
-
import { BleBinding, BleDeviceClass } from "./ble";
|
|
4
|
-
import BleInterface from "./ble-interface";
|
|
5
|
-
interface BleDeviceSettings extends DeviceSettings {
|
|
6
|
-
id?: string;
|
|
7
|
-
profile: string;
|
|
8
|
-
address?: string;
|
|
9
|
-
protocol: string;
|
|
10
|
-
interface: string;
|
|
11
|
-
}
|
|
12
|
-
export default class BleProtocol extends DeviceProtocolBase implements DeviceProtocol {
|
|
13
|
-
static _defaultBinding: BleBinding;
|
|
14
|
-
static _instances: BleProtocol[];
|
|
15
|
-
logger: EventLogger;
|
|
16
|
-
ble: BleInterface;
|
|
17
|
-
constructor(binding?: BleBinding);
|
|
18
|
-
static setDefaultBinding(binding: BleBinding): void;
|
|
19
|
-
setBinding(binding: BleBinding): void;
|
|
20
|
-
createDevice(bleDevice: BleDeviceClass | BleDeviceSettings): Device;
|
|
21
|
-
getName(): string;
|
|
22
|
-
getInterfaces(): Array<string>;
|
|
23
|
-
isBike(): boolean;
|
|
24
|
-
isHrm(): boolean;
|
|
25
|
-
isPower(): boolean;
|
|
26
|
-
add(settings: BleDeviceSettings): Device;
|
|
27
|
-
scan(props: ScanProps): Promise<void>;
|
|
28
|
-
stopScan(): Promise<void>;
|
|
29
|
-
isScanning(): boolean;
|
|
30
|
-
}
|
|
31
|
-
export {};
|