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
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.BleControllableAdapter = void 0;
|
|
39
|
+
const adpater_1 = __importStar(require("../base/adpater"));
|
|
40
|
+
const ble_interface_1 = __importDefault(require("./ble-interface"));
|
|
41
|
+
const INTERFACE_NAME = 'ble';
|
|
42
|
+
class BleAdapter extends adpater_1.default {
|
|
43
|
+
constructor(settings, props) {
|
|
44
|
+
super(settings, props);
|
|
45
|
+
if (this.settings.interface !== INTERFACE_NAME)
|
|
46
|
+
throw new Error('Incorrect interface');
|
|
47
|
+
this.deviceData = {};
|
|
48
|
+
this.data = {};
|
|
49
|
+
this.dataMsgCount = 0;
|
|
50
|
+
this.updateFrequency = 1000;
|
|
51
|
+
this.ble = ble_interface_1.default.getInstance();
|
|
52
|
+
}
|
|
53
|
+
isEqual(settings) {
|
|
54
|
+
const as = this.settings;
|
|
55
|
+
if (as.interface !== settings.interface)
|
|
56
|
+
return false;
|
|
57
|
+
if (as.protocol === 'BLE' || settings.protocol === 'BLE') {
|
|
58
|
+
return (as.protocol === settings.protocol && as.profile === settings.profile && as.name === settings.name);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return (as.protocol === settings.protocol && (as.name === settings.name || as.address === settings.address || as.id === settings.id));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
resetData() {
|
|
65
|
+
this.dataMsgCount = 0;
|
|
66
|
+
this.deviceData = {};
|
|
67
|
+
this.data = {};
|
|
68
|
+
this.lastDataTS = undefined;
|
|
69
|
+
}
|
|
70
|
+
getInterface() {
|
|
71
|
+
return INTERFACE_NAME;
|
|
72
|
+
}
|
|
73
|
+
getProtocolName() {
|
|
74
|
+
const settings = this.settings;
|
|
75
|
+
return settings.protocol;
|
|
76
|
+
}
|
|
77
|
+
getID() {
|
|
78
|
+
const settings = this.settings;
|
|
79
|
+
return settings.id;
|
|
80
|
+
}
|
|
81
|
+
getName() {
|
|
82
|
+
const settings = this.settings;
|
|
83
|
+
return settings.name || settings.id || settings.address;
|
|
84
|
+
}
|
|
85
|
+
onDeviceData(deviceData) {
|
|
86
|
+
this.dataMsgCount++;
|
|
87
|
+
this.lastDataTS = Date.now();
|
|
88
|
+
this.deviceData = Object.assign({}, deviceData);
|
|
89
|
+
}
|
|
90
|
+
start(props = {}) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
if (this.started)
|
|
93
|
+
return true;
|
|
94
|
+
this.logger.logEvent({ message: 'start requested', protocol: this.getProtocolName(), props });
|
|
95
|
+
try {
|
|
96
|
+
const bleDevice = yield this.ble.connectDevice(this.device);
|
|
97
|
+
if (bleDevice) {
|
|
98
|
+
this.device = bleDevice;
|
|
99
|
+
bleDevice.on('data', (data) => {
|
|
100
|
+
this.onDeviceData(data);
|
|
101
|
+
});
|
|
102
|
+
this.resetData();
|
|
103
|
+
this.stopped = false;
|
|
104
|
+
this.started = true;
|
|
105
|
+
this.paused = false;
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
this.logger.logEvent({ message: 'start result: error', error: err.message, protocol: this.getProtocolName() });
|
|
111
|
+
throw new Error(`could not start device, reason:${err.message}`);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
stop() {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
this.logger.logEvent({ message: 'stop requested', protocol: this.getProtocolName() });
|
|
118
|
+
this.device.reset();
|
|
119
|
+
const stopped = this.device.disconnect();
|
|
120
|
+
if (stopped) {
|
|
121
|
+
this.stopped = true;
|
|
122
|
+
this.started = false;
|
|
123
|
+
this.paused = false;
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.default = BleAdapter;
|
|
131
|
+
class BleControllableAdapter extends BleAdapter {
|
|
132
|
+
constructor(settings, props) {
|
|
133
|
+
super(settings, props);
|
|
134
|
+
this.cyclingMode = this.getDefaultCyclingMode();
|
|
135
|
+
this.user = {};
|
|
136
|
+
}
|
|
137
|
+
setUser(user) {
|
|
138
|
+
this.user = user;
|
|
139
|
+
if (!user.weight)
|
|
140
|
+
this.user.weight = adpater_1.DEFAULT_USER_WEIGHT;
|
|
141
|
+
}
|
|
142
|
+
setBikeProps(props) {
|
|
143
|
+
const { user, userWeight, bikeWeight } = props || {};
|
|
144
|
+
if (user)
|
|
145
|
+
this.setUser(user);
|
|
146
|
+
if (userWeight)
|
|
147
|
+
this.user.weight = userWeight;
|
|
148
|
+
const keys = Object.keys(props);
|
|
149
|
+
keys.forEach(k => {
|
|
150
|
+
const p = props[k];
|
|
151
|
+
if (p === null)
|
|
152
|
+
delete this.props[k];
|
|
153
|
+
else if (p !== undefined)
|
|
154
|
+
this.props[k] = p;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
getWeight() {
|
|
158
|
+
const { user = {}, props = adpater_1.DEFAULT_PROPS } = this;
|
|
159
|
+
const userWeight = user.weight || props.userWeight || adpater_1.DEFAULT_USER_WEIGHT;
|
|
160
|
+
const bikeWeight = props.bikeWeight || adpater_1.DEFAULT_BIKE_WEIGHT;
|
|
161
|
+
return userWeight + bikeWeight;
|
|
162
|
+
}
|
|
163
|
+
getSupportedCyclingModes() { throw new Error('not implemented'); }
|
|
164
|
+
getDefaultCyclingMode() { throw new Error('not implemented'); }
|
|
165
|
+
setCyclingMode(mode, settings) {
|
|
166
|
+
let selectedMode;
|
|
167
|
+
if (typeof mode === 'string') {
|
|
168
|
+
const supported = this.getSupportedCyclingModes();
|
|
169
|
+
const CyclingModeClass = supported.find(M => { const m = new M(this); return m.getName() === mode; });
|
|
170
|
+
if (CyclingModeClass) {
|
|
171
|
+
this.cyclingMode = new CyclingModeClass(this, settings);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
selectedMode = this.getDefaultCyclingMode();
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
selectedMode = mode;
|
|
178
|
+
}
|
|
179
|
+
this.cyclingMode = selectedMode;
|
|
180
|
+
this.cyclingMode.setSettings(settings);
|
|
181
|
+
}
|
|
182
|
+
getCyclingMode() {
|
|
183
|
+
if (!this.cyclingMode)
|
|
184
|
+
this.setCyclingMode(this.getDefaultCyclingMode());
|
|
185
|
+
return this.cyclingMode;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
exports.BleControllableAdapter = BleControllableAdapter;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { EventLogger } from "gd-eventlog";
|
|
3
|
-
import { BleInterfaceClass
|
|
4
|
+
import { BleInterfaceClass } from "./ble";
|
|
4
5
|
import BlePeripheralConnector from "./ble-peripheral";
|
|
6
|
+
import { BleDeviceCommsClass, ConnectProps, BleDeviceInfo, BlePeripheral, BleDeviceProps, BleWriteProps } from './types';
|
|
5
7
|
interface BleDeviceConstructProps extends BleDeviceProps {
|
|
6
8
|
log?: boolean;
|
|
7
9
|
logger?: EventLogger;
|
|
10
|
+
peripheral?: BlePeripheral;
|
|
8
11
|
}
|
|
9
|
-
|
|
12
|
+
type CommandQueueItem = {
|
|
10
13
|
uuid: string;
|
|
11
14
|
data: Buffer;
|
|
12
15
|
timeout: number;
|
|
@@ -18,7 +21,7 @@ export interface MessageLog {
|
|
|
18
21
|
timestamp: any;
|
|
19
22
|
data: string;
|
|
20
23
|
}
|
|
21
|
-
export declare
|
|
24
|
+
export declare class BleComms extends BleDeviceCommsClass {
|
|
22
25
|
id: string;
|
|
23
26
|
address: string;
|
|
24
27
|
name: string;
|
|
@@ -35,11 +38,14 @@ export declare abstract class BleDevice extends BleDeviceClass {
|
|
|
35
38
|
workerIv: NodeJS.Timeout;
|
|
36
39
|
prevMessages: MessageLog[];
|
|
37
40
|
constructor(props?: BleDeviceConstructProps);
|
|
41
|
+
getServiceUUids(): string[];
|
|
42
|
+
getProfile(): string;
|
|
38
43
|
getServices(): string[];
|
|
39
44
|
logEvent(event: any): void;
|
|
40
45
|
setLogger(logger: EventLogger): void;
|
|
41
46
|
setInterface(ble: BleInterfaceClass): void;
|
|
42
47
|
isMatching(characteristics: string[]): boolean;
|
|
48
|
+
reset(): void;
|
|
43
49
|
cleanupListeners(): void;
|
|
44
50
|
onDisconnect(): void;
|
|
45
51
|
waitForConnectFinished(timeout: any): Promise<unknown>;
|
|
@@ -50,7 +56,6 @@ export declare abstract class BleDevice extends BleDeviceClass {
|
|
|
50
56
|
subscribeAll(conn?: BlePeripheralConnector): Promise<void>;
|
|
51
57
|
connect(props?: ConnectProps): Promise<boolean>;
|
|
52
58
|
disconnect(): Promise<boolean>;
|
|
53
|
-
abstract getProfile(): string;
|
|
54
59
|
checkForDuplicate(characteristic: string, data: Buffer): boolean;
|
|
55
60
|
onData(characteristic: string, _data: Buffer): boolean;
|
|
56
61
|
timeoutCheck(): void;
|
|
@@ -8,14 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
15
|
+
exports.BleComms = void 0;
|
|
13
16
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
14
|
-
const
|
|
15
|
-
const
|
|
17
|
+
const utils_1 = require("./utils");
|
|
18
|
+
const types_1 = require("./types");
|
|
19
|
+
const ble_interface_1 = __importDefault(require("./ble-interface"));
|
|
16
20
|
const CONNECT_WAIT_TIMEOUT = 10000;
|
|
17
21
|
const BLE_TIMEOUT = 1000;
|
|
18
|
-
class
|
|
22
|
+
class BleComms extends types_1.BleDeviceCommsClass {
|
|
19
23
|
constructor(props) {
|
|
20
24
|
super();
|
|
21
25
|
this.characteristics = [];
|
|
@@ -24,7 +28,7 @@ class BleDevice extends ble_1.BleDeviceClass {
|
|
|
24
28
|
this.address = props.address;
|
|
25
29
|
this.name = props.name;
|
|
26
30
|
this.services = props.services;
|
|
27
|
-
this.ble =
|
|
31
|
+
this.ble = ble_interface_1.default.getInstance();
|
|
28
32
|
this.characteristics = [];
|
|
29
33
|
this.subscribedCharacteristics = [];
|
|
30
34
|
this.isInitialized = false;
|
|
@@ -47,6 +51,12 @@ class BleDevice extends ble_1.BleDeviceClass {
|
|
|
47
51
|
this.logger = new gd_eventlog_1.EventLogger('BleDevice');
|
|
48
52
|
}
|
|
49
53
|
}
|
|
54
|
+
getServiceUUids() {
|
|
55
|
+
throw new Error("Method not implemented.");
|
|
56
|
+
}
|
|
57
|
+
getProfile() {
|
|
58
|
+
throw new Error("Method not implemented.");
|
|
59
|
+
}
|
|
50
60
|
getServices() {
|
|
51
61
|
return this.services;
|
|
52
62
|
}
|
|
@@ -67,6 +77,8 @@ class BleDevice extends ble_1.BleDeviceClass {
|
|
|
67
77
|
isMatching(characteristics) {
|
|
68
78
|
return true;
|
|
69
79
|
}
|
|
80
|
+
reset() {
|
|
81
|
+
}
|
|
70
82
|
cleanupListeners() {
|
|
71
83
|
if (this.characteristics === undefined) {
|
|
72
84
|
this.characteristics = [];
|
|
@@ -74,7 +86,7 @@ class BleDevice extends ble_1.BleDeviceClass {
|
|
|
74
86
|
else {
|
|
75
87
|
const connector = this.ble.getConnector(this.peripheral);
|
|
76
88
|
this.characteristics.forEach(c => {
|
|
77
|
-
connector.removeAllListeners((0,
|
|
89
|
+
connector.removeAllListeners((0, utils_1.uuid)(c.uuid));
|
|
78
90
|
});
|
|
79
91
|
}
|
|
80
92
|
}
|
|
@@ -114,7 +126,7 @@ class BleDevice extends ble_1.BleDeviceClass {
|
|
|
114
126
|
});
|
|
115
127
|
}
|
|
116
128
|
hasService(serviceUuid) {
|
|
117
|
-
return this.services && this.services.find(s => s === serviceUuid || (0,
|
|
129
|
+
return this.services && this.services.find(s => s === serviceUuid || (0, utils_1.uuid)(serviceUuid)) !== undefined;
|
|
118
130
|
}
|
|
119
131
|
init() {
|
|
120
132
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -296,7 +308,7 @@ class BleDevice extends ble_1.BleDeviceClass {
|
|
|
296
308
|
}
|
|
297
309
|
this.logEvent({ message: 'got data', characteristic, data: data.toString('hex'), writeQueue: this.writeQueue.length });
|
|
298
310
|
if (this.writeQueue.length > 0) {
|
|
299
|
-
const writeIdx = this.writeQueue.findIndex(i => (0,
|
|
311
|
+
const writeIdx = this.writeQueue.findIndex(i => (0, utils_1.matches)(i.uuid, characteristic));
|
|
300
312
|
if (writeIdx !== -1) {
|
|
301
313
|
const writeItem = this.writeQueue[writeIdx];
|
|
302
314
|
this.writeQueue.splice(writeIdx, 1);
|
|
@@ -358,7 +370,7 @@ class BleDevice extends ble_1.BleDeviceClass {
|
|
|
358
370
|
this.subscribedCharacteristics.push(characteristicUuid);
|
|
359
371
|
}
|
|
360
372
|
return new Promise((resolve, reject) => {
|
|
361
|
-
const characteristic = this.characteristics.find(c => c.uuid === characteristicUuid || (0,
|
|
373
|
+
const characteristic = this.characteristics.find(c => c.uuid === characteristicUuid || (0, utils_1.uuid)(c.uuid) === characteristicUuid);
|
|
362
374
|
if (!characteristic) {
|
|
363
375
|
reject(new Error('Characteristic not found'));
|
|
364
376
|
return;
|
|
@@ -402,7 +414,7 @@ class BleDevice extends ble_1.BleDeviceClass {
|
|
|
402
414
|
return new Promise((resolve, reject) => {
|
|
403
415
|
if (!this.isConnected())
|
|
404
416
|
return reject(new Error('not connected'));
|
|
405
|
-
const characteristic = this.characteristics.find(c => c.uuid === characteristicUuid || (0,
|
|
417
|
+
const characteristic = this.characteristics.find(c => c.uuid === characteristicUuid || (0, utils_1.uuid)(c.uuid) === characteristicUuid);
|
|
406
418
|
if (!characteristic) {
|
|
407
419
|
reject(new Error('Characteristic not found'));
|
|
408
420
|
return;
|
|
@@ -441,4 +453,4 @@ class BleDevice extends ble_1.BleDeviceClass {
|
|
|
441
453
|
});
|
|
442
454
|
}
|
|
443
455
|
}
|
|
444
|
-
exports.
|
|
456
|
+
exports.BleComms = BleComms;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventLogger } from 'gd-eventlog';
|
|
3
|
-
import { BleInterfaceClass,
|
|
3
|
+
import { BleInterfaceClass, BleScanProps, BleBinding } from './ble';
|
|
4
|
+
import { BleComms } from './ble-comms';
|
|
5
|
+
import BleAdapterFactory from './adapter-factory';
|
|
6
|
+
import { ConnectProps, BlePeripheral, BleCharacteristic, BleDeviceSettings } from './types';
|
|
4
7
|
export interface ScanState {
|
|
5
8
|
isScanning: boolean;
|
|
6
9
|
isConnecting: boolean;
|
|
@@ -19,11 +22,11 @@ export interface PeripheralState {
|
|
|
19
22
|
isInterrupted: boolean;
|
|
20
23
|
}
|
|
21
24
|
export interface BleDeviceInfo {
|
|
22
|
-
device:
|
|
25
|
+
device: BleComms;
|
|
23
26
|
isConnected: boolean;
|
|
24
27
|
}
|
|
25
28
|
export interface BleDeviceClassInfo {
|
|
26
|
-
Class: typeof
|
|
29
|
+
Class: typeof BleComms;
|
|
27
30
|
type: string;
|
|
28
31
|
services: string[];
|
|
29
32
|
id: string;
|
|
@@ -41,7 +44,6 @@ export default class BleInterface extends BleInterfaceClass {
|
|
|
41
44
|
devices: BleDeviceInfo[];
|
|
42
45
|
peripheralCache: any[];
|
|
43
46
|
logger: EventLogger;
|
|
44
|
-
static deviceClasses: BleDeviceClassInfo[];
|
|
45
47
|
static _instance: BleInterface;
|
|
46
48
|
static getInstance(props?: {
|
|
47
49
|
binding?: BleBinding;
|
|
@@ -53,18 +55,13 @@ export default class BleInterface extends BleInterfaceClass {
|
|
|
53
55
|
log?: boolean;
|
|
54
56
|
logger?: EventLogger;
|
|
55
57
|
});
|
|
56
|
-
|
|
58
|
+
getAdapterFactory(): BleAdapterFactory;
|
|
57
59
|
logEvent(event: any): void;
|
|
58
60
|
onStateChange(state: any): void;
|
|
59
61
|
onError(err: any): void;
|
|
60
62
|
connect(props?: ConnectProps): Promise<boolean>;
|
|
61
63
|
disconnect(): Promise<boolean>;
|
|
62
64
|
isConnected(): boolean;
|
|
63
|
-
getDevicesFromServices(deviceTypes: (typeof BleDeviceClass)[], services: string | string[]): (typeof BleDeviceClass)[];
|
|
64
|
-
getAllSupportedServices(): any[];
|
|
65
|
-
getAllSupportedDeviceTypes(): (typeof BleDeviceClass)[];
|
|
66
|
-
getServicesFromDeviceTypes(deviceTypes: (typeof BleDeviceClass)[]): string[];
|
|
67
|
-
getServicesFromDevice(device: BleDeviceClass): string[];
|
|
68
65
|
waitForConnectFinished(timeout: any): Promise<unknown>;
|
|
69
66
|
addPeripheralToCache(peripheral: any, props?: {}): void;
|
|
70
67
|
onDisconnect(peripheral: any): void;
|
|
@@ -75,26 +72,20 @@ export default class BleInterface extends BleInterfaceClass {
|
|
|
75
72
|
name?: string;
|
|
76
73
|
}): BlePeripheral;
|
|
77
74
|
getCharacteristics(peripheral: any): Promise<any>;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
profile?: string;
|
|
81
|
-
services?: string[];
|
|
82
|
-
}): (typeof BleDeviceClass)[];
|
|
83
|
-
createDevice(DeviceClass: (typeof BleDeviceClass), peripheral: BlePeripheral, characteristics?: BleCharacteristic[]): BleDeviceClass;
|
|
84
|
-
connectDevice(requested: BleDeviceClass | BleDeviceDescription, timeout?: number): Promise<BleDeviceClass>;
|
|
75
|
+
createDeviceComms(DeviceClass: (typeof BleComms), peripheral: BlePeripheral, characteristics?: BleCharacteristic[]): any;
|
|
76
|
+
connectDevice(requested: BleComms | BleDeviceSettings, timeout?: number): Promise<BleComms>;
|
|
85
77
|
waitForScanFinished(timeout: any): Promise<unknown>;
|
|
86
|
-
|
|
87
|
-
scan(props: ScanProps): Promise<BleDeviceClass[]>;
|
|
78
|
+
scan(props: BleScanProps): Promise<BleComms[]>;
|
|
88
79
|
stopScan(): Promise<boolean>;
|
|
89
80
|
isScanning(): boolean;
|
|
90
|
-
addConnectedDevice(device:
|
|
91
|
-
addDeviceToCache(device:
|
|
92
|
-
findConnected(device:
|
|
81
|
+
addConnectedDevice(device: BleComms): void;
|
|
82
|
+
addDeviceToCache(device: BleComms, isConnected: boolean): void;
|
|
83
|
+
findConnected(device: BleComms | BlePeripheral): BleComms;
|
|
93
84
|
findDeviceInCache(device: {
|
|
94
85
|
id?: string;
|
|
95
86
|
address?: string;
|
|
96
87
|
name?: string;
|
|
97
88
|
profile: string;
|
|
98
|
-
}):
|
|
99
|
-
removeConnectedDevice(device:
|
|
89
|
+
}): BleComms;
|
|
90
|
+
removeConnectedDevice(device: BleComms): void;
|
|
100
91
|
}
|