incyclist-devices 2.2.10-beta.0 → 2.3.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/lib/antv2/base/interface.js +2 -2
- package/lib/antv2/factories/index.d.ts +1 -0
- package/lib/antv2/factories/index.js +17 -0
- package/lib/antv2/fe/adapter.js +5 -4
- package/lib/antv2/index.d.ts +1 -0
- package/lib/antv2/index.js +12 -8
- package/lib/base/adpater.js +1 -1
- package/lib/ble/adapter-factory.d.ts +20 -24
- package/lib/ble/adapter-factory.js +13 -36
- package/lib/ble/base/adapter.d.ts +16 -5
- package/lib/ble/base/adapter.js +169 -52
- package/lib/ble/base/comms.d.ts +2 -74
- package/lib/ble/base/comms.js +3 -596
- package/lib/ble/base/interface.d.ts +96 -0
- package/lib/ble/base/interface.js +544 -0
- package/lib/ble/base/peripheral.d.ts +34 -0
- package/lib/ble/base/peripheral.js +286 -0
- package/lib/ble/base/sensor.d.ts +31 -0
- package/lib/ble/base/sensor.js +130 -0
- package/lib/ble/base/types.d.ts +7 -0
- package/lib/ble/base/types.js +7 -0
- package/lib/ble/bindings/mock.js +6 -0
- package/lib/ble/bindings/types.d.ts +3 -4
- package/lib/ble/ble-interface.d.ts +7 -4
- package/lib/ble/ble-interface.js +16 -2
- package/lib/ble/ble-peripheral.d.ts +1 -0
- package/lib/ble/ble-peripheral.js +7 -11
- package/lib/ble/consts.d.ts +0 -6
- package/lib/ble/consts.js +1 -7
- package/lib/ble/cp/adapter.d.ts +3 -3
- package/lib/ble/cp/adapter.js +12 -13
- package/lib/ble/cp/comm.d.ts +1 -1
- package/lib/ble/cp/comm.js +2 -2
- package/lib/ble/cp/index.d.ts +1 -1
- package/lib/ble/cp/index.js +2 -2
- package/lib/ble/cp/sensor.d.ts +27 -0
- package/lib/ble/cp/sensor.js +107 -0
- package/lib/ble/elite/comms.d.ts +1 -1
- package/lib/ble/elite/comms.js +2 -2
- package/lib/ble/factories/adapter-factory.d.ts +32 -0
- package/lib/ble/factories/adapter-factory.js +104 -0
- package/lib/ble/factories/index.d.ts +2 -0
- package/lib/ble/factories/index.js +18 -0
- package/lib/ble/factories/interface-factory.d.ts +7 -0
- package/lib/ble/factories/interface-factory.js +18 -0
- package/lib/ble/fm/adapter.d.ts +9 -4
- package/lib/ble/fm/adapter.js +104 -108
- package/lib/ble/fm/comms.d.ts +1 -1
- package/lib/ble/fm/comms.js +3 -3
- package/lib/ble/fm/consts.d.ts +93 -0
- package/lib/ble/fm/consts.js +55 -1
- package/lib/ble/fm/index.d.ts +1 -1
- package/lib/ble/fm/index.js +2 -2
- package/lib/ble/fm/sensor.d.ts +44 -0
- package/lib/ble/fm/sensor.js +384 -0
- package/lib/ble/hr/adapter.d.ts +3 -3
- package/lib/ble/hr/adapter.js +5 -8
- package/lib/ble/hr/comm.d.ts +1 -1
- package/lib/ble/hr/comm.js +2 -2
- package/lib/ble/hr/index.d.ts +1 -1
- package/lib/ble/hr/index.js +2 -2
- package/lib/ble/hr/sensor.d.ts +17 -0
- package/lib/ble/hr/sensor.js +52 -0
- package/lib/ble/index.d.ts +4 -3
- package/lib/ble/index.js +29 -13
- package/lib/ble/tacx/adapter.d.ts +4 -2
- package/lib/ble/tacx/adapter.js +26 -66
- package/lib/ble/tacx/comms.d.ts +1 -1
- package/lib/ble/tacx/comms.js +2 -2
- package/lib/ble/tacx/consts.d.ts +23 -0
- package/lib/ble/tacx/consts.js +27 -0
- package/lib/ble/tacx/index.d.ts +1 -1
- package/lib/ble/tacx/index.js +2 -2
- package/lib/ble/tacx/sensor.d.ts +63 -0
- package/lib/ble/tacx/sensor.js +596 -0
- package/lib/ble/types.d.ts +81 -52
- package/lib/ble/utils.d.ts +7 -2
- package/lib/ble/utils.js +84 -9
- package/lib/ble/wahoo/adapter.d.ts +2 -2
- package/lib/ble/wahoo/adapter.js +4 -72
- package/lib/ble/wahoo/comms.d.ts +1 -1
- package/lib/ble/wahoo/comms.js +2 -2
- package/lib/ble/wahoo/consts.d.ts +16 -0
- package/lib/ble/wahoo/consts.js +7 -0
- package/lib/ble/wahoo/index.d.ts +1 -1
- package/lib/ble/wahoo/index.js +2 -2
- package/lib/ble/wahoo/sensor.d.ts +48 -0
- package/lib/ble/wahoo/sensor.js +356 -0
- package/lib/direct-connect/base/comms.d.ts +3 -0
- package/lib/direct-connect/base/comms.js +7 -0
- package/lib/direct-connect/base/interface.d.ts +75 -0
- package/lib/direct-connect/base/interface.js +306 -0
- package/lib/direct-connect/base/peripheral.d.ts +50 -0
- package/lib/direct-connect/base/peripheral.js +413 -0
- package/lib/direct-connect/base/sensor.d.ts +3 -0
- package/lib/direct-connect/base/sensor.js +7 -0
- package/lib/direct-connect/bindings/index.d.ts +1 -0
- package/lib/direct-connect/bindings/index.js +17 -0
- package/lib/direct-connect/bindings/types.d.ts +36 -0
- package/lib/direct-connect/bindings/types.js +2 -0
- package/lib/direct-connect/consts.d.ts +17 -0
- package/lib/direct-connect/consts.js +20 -0
- package/lib/direct-connect/index.d.ts +3 -0
- package/lib/direct-connect/index.js +22 -0
- package/lib/direct-connect/messages/CharacteristicNotification.d.ts +12 -0
- package/lib/direct-connect/messages/CharacteristicNotification.js +23 -0
- package/lib/direct-connect/messages/DiscoverCharacteristics.d.ts +22 -0
- package/lib/direct-connect/messages/DiscoverCharacteristics.js +43 -0
- package/lib/direct-connect/messages/DiscoverServices.d.ts +15 -0
- package/lib/direct-connect/messages/DiscoverServices.js +33 -0
- package/lib/direct-connect/messages/EnableCharacteristicNotifications.d.ts +18 -0
- package/lib/direct-connect/messages/EnableCharacteristicNotifications.js +35 -0
- package/lib/direct-connect/messages/ReadCharacteristic.d.ts +18 -0
- package/lib/direct-connect/messages/ReadCharacteristic.js +34 -0
- package/lib/direct-connect/messages/WriteCharacteristic.d.ts +18 -0
- package/lib/direct-connect/messages/WriteCharacteristic.js +36 -0
- package/lib/direct-connect/messages/error.d.ts +5 -0
- package/lib/direct-connect/messages/error.js +18 -0
- package/lib/direct-connect/messages/factory.d.ts +6 -0
- package/lib/direct-connect/messages/factory.js +44 -0
- package/lib/direct-connect/messages/index.d.ts +9 -0
- package/lib/direct-connect/messages/index.js +25 -0
- package/lib/direct-connect/messages/message.d.ts +20 -0
- package/lib/direct-connect/messages/message.js +90 -0
- package/lib/direct-connect/types.d.ts +24 -0
- package/lib/direct-connect/types.js +9 -0
- package/lib/direct-connect/utils.d.ts +5 -0
- package/lib/direct-connect/utils.js +73 -0
- package/lib/factories/adapters.js +16 -4
- package/lib/factories/interfaces.d.ts +2 -1
- package/lib/factories/interfaces.js +10 -7
- package/lib/index.d.ts +5 -4
- package/lib/index.js +6 -2
- package/lib/modes/antble-smarttrainer.d.ts +2 -16
- package/lib/modes/antble-smarttrainer.js +1 -98
- package/lib/modes/types.d.ts +1 -5
- package/lib/serial/bindings/tcp.d.ts +5 -4
- package/lib/serial/bindings/tcp.js +16 -23
- package/lib/types/device.d.ts +2 -1
- package/lib/types/device.js +1 -0
- package/lib/utils/calculations.d.ts +0 -1
- package/lib/utils/calculations.js +6 -22
- package/lib/utils/operation.d.ts +17 -0
- package/lib/utils/operation.js +20 -0
- package/lib/utils/task.d.ts +44 -0
- package/lib/utils/task.js +127 -0
- package/package.json +3 -1
|
@@ -16,7 +16,7 @@ const events_1 = __importDefault(require("events"));
|
|
|
16
16
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
17
17
|
const sensor_factory_1 = __importDefault(require("../factories/sensor-factory"));
|
|
18
18
|
const utils_1 = require("../../utils/utils");
|
|
19
|
-
const
|
|
19
|
+
const adapter_factory_1 = __importDefault(require("../factories/adapter-factory"));
|
|
20
20
|
class AntInterface extends events_1.default {
|
|
21
21
|
static getInstance(props = {}) {
|
|
22
22
|
if (AntInterface._instance === undefined)
|
|
@@ -300,7 +300,7 @@ class AntInterface extends events_1.default {
|
|
|
300
300
|
this.logger.logEvent({ message: 'stopping devices' });
|
|
301
301
|
let promises = [];
|
|
302
302
|
detected.forEach((settings) => {
|
|
303
|
-
const adapter =
|
|
303
|
+
const adapter = adapter_factory_1.default.getInstance().createInstance(settings);
|
|
304
304
|
promises.push(adapter.stop().catch(err => {
|
|
305
305
|
this.logger.logEvent({ message: 'could not stop device', error: err.message, deviceID: settings.deviceID, stack: err.stack });
|
|
306
306
|
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './adapter-factory';
|
|
@@ -0,0 +1,17 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./adapter-factory"), exports);
|
package/lib/antv2/fe/adapter.js
CHANGED
|
@@ -88,16 +88,17 @@ class AntFEAdapter extends adapter_1.default {
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
mapData(deviceData) {
|
|
91
|
+
var _a, _b, _c, _d;
|
|
91
92
|
const data = {
|
|
92
93
|
isPedalling: false,
|
|
93
94
|
power: 0,
|
|
94
95
|
pedalRpm: 0,
|
|
95
96
|
speed: 0,
|
|
96
97
|
};
|
|
97
|
-
data.speed = (deviceData
|
|
98
|
-
data.slope = (deviceData
|
|
99
|
-
data.power = (deviceData
|
|
100
|
-
data.pedalRpm = (deviceData.Cadence !==
|
|
98
|
+
data.speed = ((_a = deviceData === null || deviceData === void 0 ? void 0 : deviceData.VirtualSpeed) !== null && _a !== void 0 ? _a : (deviceData.RealSpeed || 0)) * 3.6;
|
|
99
|
+
data.slope = (_b = deviceData === null || deviceData === void 0 ? void 0 : deviceData.Incline) !== null && _b !== void 0 ? _b : data.slope;
|
|
100
|
+
data.power = (_c = deviceData === null || deviceData === void 0 ? void 0 : deviceData.InstantaneousPower) !== null && _c !== void 0 ? _c : data.power;
|
|
101
|
+
data.pedalRpm = (_d = deviceData.Cadence) !== null && _d !== void 0 ? _d : data.pedalRpm;
|
|
101
102
|
data.isPedalling = data.pedalRpm > 0 || data.power > 0;
|
|
102
103
|
if (deviceData.HeartRate !== undefined)
|
|
103
104
|
data.heartrate = deviceData.HeartRate;
|
package/lib/antv2/index.d.ts
CHANGED
|
@@ -8,4 +8,5 @@ import { AntInterfaceProps } from "./types";
|
|
|
8
8
|
import AntSpdAdapter from "./spd";
|
|
9
9
|
import AntScAdapter from "./sc";
|
|
10
10
|
export { AntDeviceSettings, AntDeviceProperties, AntScanProps } from "./types";
|
|
11
|
+
export declare const initAntFactory: () => void;
|
|
11
12
|
export { AntAdapterFactory, AntFEAdapter, AntHrAdapter, AntPwrAdapter, AntScAdapter, AntSpdAdapter, AntCadAdapter, AntInterface, AntInterfaceProps };
|
package/lib/antv2/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.AntInterface = exports.AntCadAdapter = exports.AntSpdAdapter = exports.AntScAdapter = exports.AntPwrAdapter = exports.AntHrAdapter = exports.AntFEAdapter = exports.AntAdapterFactory = void 0;
|
|
6
|
+
exports.AntInterface = exports.AntCadAdapter = exports.AntSpdAdapter = exports.AntScAdapter = exports.AntPwrAdapter = exports.AntHrAdapter = exports.AntFEAdapter = exports.AntAdapterFactory = exports.initAntFactory = void 0;
|
|
7
7
|
const pwr_1 = __importDefault(require("./pwr"));
|
|
8
8
|
exports.AntPwrAdapter = pwr_1.default;
|
|
9
9
|
const fe_1 = __importDefault(require("./fe"));
|
|
@@ -20,10 +20,14 @@ const spd_1 = __importDefault(require("./spd"));
|
|
|
20
20
|
exports.AntSpdAdapter = spd_1.default;
|
|
21
21
|
const sc_1 = __importDefault(require("./sc"));
|
|
22
22
|
exports.AntScAdapter = sc_1.default;
|
|
23
|
-
const
|
|
24
|
-
af
|
|
25
|
-
af.register('
|
|
26
|
-
af.register('
|
|
27
|
-
af.register('
|
|
28
|
-
af.register('
|
|
29
|
-
af.register('
|
|
23
|
+
const initAntFactory = () => {
|
|
24
|
+
const af = adapter_factory_1.default.getInstance();
|
|
25
|
+
af.register('PWR', 'Power Meter', pwr_1.default);
|
|
26
|
+
af.register('HR', 'Heartrate Monitor', hr_1.default);
|
|
27
|
+
af.register('FE', 'Smart Trainer', fe_1.default);
|
|
28
|
+
af.register('CAD', 'Cadence Sensor', cad_1.default);
|
|
29
|
+
af.register('SPD', 'Speed Sensor', spd_1.default);
|
|
30
|
+
af.register('SC', 'Speed + Cadence Sensor', sc_1.default);
|
|
31
|
+
};
|
|
32
|
+
exports.initAntFactory = initAntFactory;
|
|
33
|
+
(0, exports.initAntFactory)();
|
package/lib/base/adpater.js
CHANGED
|
@@ -200,7 +200,7 @@ class IncyclistDevice extends events_1.default {
|
|
|
200
200
|
if (!request.enforced && (this.isPaused() || this.isStopped()))
|
|
201
201
|
return;
|
|
202
202
|
if (!this.hasCapability(types_1.IncyclistCapability.Control))
|
|
203
|
-
return
|
|
203
|
+
return this.getCyclingMode().sendBikeUpdate(request);
|
|
204
204
|
else
|
|
205
205
|
throw new Error('method not implemented');
|
|
206
206
|
});
|
|
@@ -1,34 +1,30 @@
|
|
|
1
1
|
import BleAdapter from "./base/adapter";
|
|
2
|
-
import { BleDeviceSettings, BleProtocol } from "./types";
|
|
2
|
+
import { BleDeviceSettings, BleProtocol, TBleSensor } from "./types";
|
|
3
3
|
import { DeviceProperties } from "../types";
|
|
4
|
-
import { BleComms } from "./base/comms";
|
|
5
4
|
import { BleDeviceData } from "./base/types";
|
|
6
|
-
export interface BleAdapterInfo {
|
|
5
|
+
export interface BleAdapterInfo<T extends TBleSensor> {
|
|
7
6
|
protocol: BleProtocol;
|
|
8
|
-
Adapter: typeof BleAdapter<BleDeviceData,
|
|
9
|
-
Comm: typeof
|
|
7
|
+
Adapter: typeof BleAdapter<BleDeviceData, T>;
|
|
8
|
+
Comm: typeof TBleSensor;
|
|
10
9
|
}
|
|
11
|
-
export default class BleAdapterFactory {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
export default class BleAdapterFactory<T extends TBleSensor> {
|
|
11
|
+
transport: string;
|
|
12
|
+
static readonly _instances: Record<string, BleAdapterFactory<any>>;
|
|
13
|
+
implementations: BleAdapterInfo<any>[];
|
|
14
|
+
instances: Array<BleAdapter<BleDeviceData, T>>;
|
|
15
|
+
static getInstance(transport: string): BleAdapterFactory<any>;
|
|
16
|
+
constructor(transport: string);
|
|
17
|
+
getAdapterInfo(protocol: BleProtocol): BleAdapterInfo<T>;
|
|
18
|
+
getAll(): BleAdapterInfo<T>[];
|
|
19
|
+
createInstance(settings: BleDeviceSettings, props?: DeviceProperties): BleAdapter<BleDeviceData, T>;
|
|
20
20
|
removeInstance(query: {
|
|
21
21
|
settings?: BleDeviceSettings;
|
|
22
|
-
adapter?: BleAdapter<BleDeviceData,
|
|
22
|
+
adapter?: BleAdapter<BleDeviceData, T>;
|
|
23
23
|
}): void;
|
|
24
|
-
find(settings?: BleDeviceSettings): BleAdapter<BleDeviceData,
|
|
25
|
-
register(protocol: BleProtocol, Adapter: typeof BleAdapter<BleDeviceData,
|
|
26
|
-
getAllInstances(): Array<BleAdapter<BleDeviceData,
|
|
27
|
-
getAllSupportedComms(): (typeof
|
|
28
|
-
getAllSupportedAdapters(): Array<(typeof BleAdapter<BleDeviceData,
|
|
24
|
+
find(settings?: BleDeviceSettings): BleAdapter<BleDeviceData, T>;
|
|
25
|
+
register(protocol: BleProtocol, Adapter: typeof BleAdapter<BleDeviceData, T>, Comm: typeof TBleSensor): void;
|
|
26
|
+
getAllInstances(): Array<BleAdapter<BleDeviceData, T>>;
|
|
27
|
+
getAllSupportedComms(): (typeof TBleSensor)[];
|
|
28
|
+
getAllSupportedAdapters(): Array<(typeof BleAdapter<BleDeviceData, T>)>;
|
|
29
29
|
getAllSupportedServices(): string[];
|
|
30
|
-
getDeviceClasses(peripheral: any, props?: {
|
|
31
|
-
protocol?: BleProtocol;
|
|
32
|
-
services?: string[];
|
|
33
|
-
}): (typeof BleComms)[];
|
|
34
30
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const comms_utils_1 = require("./base/comms-utils");
|
|
4
3
|
const utils_1 = require("./utils");
|
|
5
4
|
class BleAdapterFactory {
|
|
6
|
-
static getInstance() {
|
|
7
|
-
if (!BleAdapterFactory.
|
|
8
|
-
BleAdapterFactory.
|
|
9
|
-
return BleAdapterFactory.
|
|
5
|
+
static getInstance(transport) {
|
|
6
|
+
if (!BleAdapterFactory._instances[transport])
|
|
7
|
+
BleAdapterFactory._instances[transport] = new BleAdapterFactory(transport);
|
|
8
|
+
return BleAdapterFactory._instances[transport];
|
|
10
9
|
}
|
|
11
|
-
constructor() {
|
|
10
|
+
constructor(transport) {
|
|
11
|
+
this.transport = transport;
|
|
12
12
|
this.implementations = [];
|
|
13
13
|
this.instances = [];
|
|
14
14
|
}
|
|
@@ -37,7 +37,8 @@ class BleAdapterFactory {
|
|
|
37
37
|
return existing;
|
|
38
38
|
}
|
|
39
39
|
const info = this.getAdapterInfo(protocol);
|
|
40
|
-
|
|
40
|
+
console.log('~~~~ INFO:', info);
|
|
41
|
+
if (!(info === null || info === void 0 ? void 0 : info.Adapter))
|
|
41
42
|
return;
|
|
42
43
|
const adapter = new info.Adapter(adapterSettings, props);
|
|
43
44
|
this.instances.push(adapter);
|
|
@@ -69,42 +70,18 @@ class BleAdapterFactory {
|
|
|
69
70
|
return this.instances;
|
|
70
71
|
}
|
|
71
72
|
getAllSupportedComms() {
|
|
72
|
-
const supported =
|
|
73
|
+
const supported = this.getAll();
|
|
73
74
|
return supported.map(info => info.Comm);
|
|
74
75
|
}
|
|
75
76
|
getAllSupportedAdapters() {
|
|
76
|
-
const supported =
|
|
77
|
+
const supported = this.getAll();
|
|
77
78
|
return supported.map(info => info.Adapter);
|
|
78
79
|
}
|
|
79
80
|
getAllSupportedServices() {
|
|
80
|
-
const supported =
|
|
81
|
-
const res = [];
|
|
82
|
-
if (supported && supported.length > 0) {
|
|
83
|
-
supported.forEach(info => {
|
|
84
|
-
if (info && info.Comm && info.Comm.services) {
|
|
85
|
-
info.Comm.services.forEach(s => {
|
|
86
|
-
if (!res.includes(s))
|
|
87
|
-
res.push(s);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
81
|
+
const supported = this.getAll();
|
|
82
|
+
const res = ['180d', '1818', '1826', '6e40fec1'];
|
|
92
83
|
return res;
|
|
93
84
|
}
|
|
94
|
-
getDeviceClasses(peripheral, props = {}) {
|
|
95
|
-
let DeviceClasses;
|
|
96
|
-
const { protocol, services = peripheral.advertisement.serviceUuids } = props;
|
|
97
|
-
const classes = this.getAllSupportedComms();
|
|
98
|
-
DeviceClasses = (0, comms_utils_1.getDevicesFromServices)(classes, services);
|
|
99
|
-
if (protocol && DeviceClasses && DeviceClasses.length > 0) {
|
|
100
|
-
DeviceClasses = DeviceClasses.filter((C) => {
|
|
101
|
-
const device = new C({ peripheral });
|
|
102
|
-
if (device.getProtocol() !== protocol)
|
|
103
|
-
return false;
|
|
104
|
-
return true;
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
return DeviceClasses;
|
|
108
|
-
}
|
|
109
85
|
}
|
|
86
|
+
BleAdapterFactory._instances = {};
|
|
110
87
|
exports.default = BleAdapterFactory;
|
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import IncyclistDevice from "../../base/adpater";
|
|
2
|
-
import {
|
|
3
|
-
import BleInterface from "../ble-interface";
|
|
4
|
-
import { BleDeviceProperties, BleDeviceSettings, BleStartProperties } from "../types";
|
|
2
|
+
import { BleDeviceProperties, BleDeviceSettings, BleStartProperties, IBlePeripheral } from "../types";
|
|
5
3
|
import { IAdapter, IncyclistBikeData, IncyclistAdapterData, DeviceProperties } from "../../types";
|
|
6
4
|
import { BleDeviceData } from "./types";
|
|
7
5
|
import { LegacyProfile } from "../../antv2/types";
|
|
8
6
|
import ICyclingMode from "../../modes/types";
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
import { InteruptableTask, TaskState } from "../../utils/task";
|
|
8
|
+
import { TBleSensor } from "./sensor";
|
|
9
|
+
export default class BleAdapter<TDeviceData extends BleDeviceData, TDevice extends TBleSensor> extends IncyclistDevice<BleDeviceProperties> {
|
|
11
10
|
protected deviceData: TDeviceData;
|
|
12
11
|
protected data: IncyclistAdapterData;
|
|
13
12
|
protected dataMsgCount: number;
|
|
14
13
|
protected lastDataTS: number;
|
|
15
14
|
protected device: TDevice;
|
|
16
15
|
protected onDeviceDataHandler: any;
|
|
16
|
+
protected startTask: InteruptableTask<TaskState, boolean>;
|
|
17
17
|
constructor(settings: BleDeviceSettings, props?: DeviceProperties);
|
|
18
18
|
getUniqueName(): string;
|
|
19
19
|
connect(): Promise<boolean>;
|
|
20
|
+
getPeripheral(): IBlePeripheral;
|
|
21
|
+
waitForPeripheral(): Promise<void>;
|
|
22
|
+
updateSensor(peripheral: IBlePeripheral): void;
|
|
20
23
|
close(): Promise<boolean>;
|
|
21
24
|
getComms(): TDevice;
|
|
22
25
|
isEqual(settings: BleDeviceSettings): boolean;
|
|
@@ -35,8 +38,16 @@ export default class BleAdapter<TDeviceData extends BleDeviceData, TDevice exten
|
|
|
35
38
|
getSettings(): BleDeviceSettings;
|
|
36
39
|
setProperties(props: BleDeviceProperties): void;
|
|
37
40
|
check(): Promise<boolean>;
|
|
41
|
+
getDefaultStartupTimeout(): number;
|
|
38
42
|
startPreChecks(props: BleStartProperties): Promise<'done' | 'connected' | 'connection-failed'>;
|
|
39
43
|
start(startProps?: BleStartProperties): Promise<boolean>;
|
|
44
|
+
protected isStarting(): boolean;
|
|
45
|
+
protected hasData(): boolean;
|
|
46
|
+
protected waitForInitialData(startupTimeout: any): Promise<void>;
|
|
47
|
+
protected checkCapabilities(): void;
|
|
48
|
+
protected initControl(_props?: BleStartProperties): Promise<void>;
|
|
49
|
+
protected startAdapter(startProps?: BleStartProperties): Promise<boolean>;
|
|
50
|
+
startSensor(): Promise<boolean>;
|
|
40
51
|
stop(): Promise<boolean>;
|
|
41
52
|
pause(): Promise<boolean>;
|
|
42
53
|
resume(): Promise<boolean>;
|
package/lib/ble/base/adapter.js
CHANGED
|
@@ -13,24 +13,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const adpater_1 = __importDefault(require("../../base/adpater"));
|
|
16
|
-
const
|
|
17
|
-
const
|
|
16
|
+
const types_1 = require("../../types");
|
|
17
|
+
const interface_factory_1 = require("../factories/interface-factory");
|
|
18
|
+
const task_1 = require("../../utils/task");
|
|
19
|
+
const utils_1 = require("../../utils/utils");
|
|
18
20
|
class BleAdapter extends adpater_1.default {
|
|
19
21
|
constructor(settings, props) {
|
|
20
22
|
super(settings, props);
|
|
21
23
|
this.onDeviceDataHandler = this.onDeviceData.bind(this);
|
|
22
|
-
if (this.settings.interface !== INTERFACE_NAME)
|
|
23
|
-
throw new Error('Incorrect interface');
|
|
24
24
|
this.deviceData = {};
|
|
25
25
|
this.data = {};
|
|
26
26
|
this.dataMsgCount = 0;
|
|
27
27
|
this.updateFrequency = 1000;
|
|
28
|
-
this.ble = ble_interface_1.default.getInstance();
|
|
29
28
|
}
|
|
30
29
|
getUniqueName() {
|
|
31
30
|
var _a;
|
|
32
31
|
const settings = this.settings;
|
|
33
|
-
if (((_a = settings.name) === null || _a === void 0 ? void 0 : _a.match(/
|
|
32
|
+
if (((_a = settings.name) === null || _a === void 0 ? void 0 : _a.match(/\d/g)) || settings.address === undefined)
|
|
34
33
|
return this.getName();
|
|
35
34
|
else {
|
|
36
35
|
const addressHash = settings.address.substring(0, 2) + settings.address.slice(-2);
|
|
@@ -39,26 +38,29 @@ class BleAdapter extends adpater_1.default {
|
|
|
39
38
|
}
|
|
40
39
|
connect() {
|
|
41
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
if (this.isConnected())
|
|
46
|
-
return true;
|
|
47
|
-
let connected = false;
|
|
48
|
-
try {
|
|
49
|
-
connected = yield this.device.connect();
|
|
50
|
-
}
|
|
51
|
-
catch (err) {
|
|
52
|
-
this.logEvent({ message: 'error', fn: 'connect()', error: err.message, stack: err.stack });
|
|
53
|
-
}
|
|
54
|
-
return connected;
|
|
41
|
+
const iface = interface_factory_1.BleMultiTransportInterfaceFactory.createInstance(this.getInterface());
|
|
42
|
+
return yield iface.connect();
|
|
55
43
|
});
|
|
56
44
|
}
|
|
45
|
+
getPeripheral() {
|
|
46
|
+
const iface = interface_factory_1.BleMultiTransportInterfaceFactory.createInstance(this.getInterface());
|
|
47
|
+
const p = iface === null || iface === void 0 ? void 0 : iface.createPeripheralFromSettings(this.settings);
|
|
48
|
+
return p;
|
|
49
|
+
}
|
|
50
|
+
waitForPeripheral() {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
this.logEvent({ message: 'waiting for sensor ...' });
|
|
53
|
+
const iface = interface_factory_1.BleMultiTransportInterfaceFactory.createInstance(this.getInterface());
|
|
54
|
+
const peripheral = yield iface.waitForPeripheral(this.settings);
|
|
55
|
+
this.updateSensor(peripheral);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
updateSensor(peripheral) {
|
|
59
|
+
throw new Error('method not implemented');
|
|
60
|
+
}
|
|
57
61
|
close() {
|
|
58
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
|
|
60
|
-
return true;
|
|
61
|
-
return yield this.device.disconnect();
|
|
63
|
+
return true;
|
|
62
64
|
});
|
|
63
65
|
}
|
|
64
66
|
getComms() {
|
|
@@ -81,7 +83,8 @@ class BleAdapter extends adpater_1.default {
|
|
|
81
83
|
return this.isEqual(adapter.getSettings());
|
|
82
84
|
}
|
|
83
85
|
isConnected() {
|
|
84
|
-
|
|
86
|
+
var _a;
|
|
87
|
+
return (_a = this.device) === null || _a === void 0 ? void 0 : _a.isConnected();
|
|
85
88
|
}
|
|
86
89
|
resetData() {
|
|
87
90
|
this.dataMsgCount = 0;
|
|
@@ -90,7 +93,13 @@ class BleAdapter extends adpater_1.default {
|
|
|
90
93
|
this.lastDataTS = undefined;
|
|
91
94
|
}
|
|
92
95
|
getInterface() {
|
|
93
|
-
|
|
96
|
+
const iface = this.settings.interface;
|
|
97
|
+
if (typeof iface === 'string')
|
|
98
|
+
return this.settings.interface;
|
|
99
|
+
else {
|
|
100
|
+
const i = this.settings.interface;
|
|
101
|
+
return i.getName();
|
|
102
|
+
}
|
|
94
103
|
}
|
|
95
104
|
getProfile() {
|
|
96
105
|
const C = this.constructor;
|
|
@@ -164,6 +173,9 @@ class BleAdapter extends adpater_1.default {
|
|
|
164
173
|
check() {
|
|
165
174
|
return this.start({ scanOnly: true });
|
|
166
175
|
}
|
|
176
|
+
getDefaultStartupTimeout() {
|
|
177
|
+
return 30000;
|
|
178
|
+
}
|
|
167
179
|
startPreChecks(props) {
|
|
168
180
|
return __awaiter(this, void 0, void 0, function* () {
|
|
169
181
|
const wasPaused = this.paused;
|
|
@@ -185,45 +197,150 @@ class BleAdapter extends adpater_1.default {
|
|
|
185
197
|
}
|
|
186
198
|
start(startProps) {
|
|
187
199
|
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
-
|
|
200
|
+
if (this.isStarting()) {
|
|
201
|
+
yield this.stop();
|
|
202
|
+
}
|
|
203
|
+
this.startTask = new task_1.InteruptableTask(this.startAdapter(startProps), {
|
|
204
|
+
timeout: startProps === null || startProps === void 0 ? void 0 : startProps.timeout,
|
|
205
|
+
name: 'start',
|
|
206
|
+
errorOnTimeout: false,
|
|
207
|
+
log: this.logEvent.bind(this)
|
|
208
|
+
});
|
|
209
|
+
const res = yield this.startTask.run();
|
|
210
|
+
return res;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
isStarting() {
|
|
214
|
+
var _a;
|
|
215
|
+
return (_a = this.startTask) === null || _a === void 0 ? void 0 : _a.isRunning();
|
|
216
|
+
}
|
|
217
|
+
hasData() {
|
|
218
|
+
return this.dataMsgCount > 0;
|
|
219
|
+
}
|
|
220
|
+
waitForInitialData(startupTimeout) {
|
|
221
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
222
|
+
let waitTask;
|
|
223
|
+
let iv;
|
|
224
|
+
const wait = () => {
|
|
225
|
+
const res = new Promise((resolve) => {
|
|
226
|
+
iv = setInterval(() => {
|
|
227
|
+
if (this.hasData()) {
|
|
228
|
+
clearInterval(iv);
|
|
229
|
+
resolve(true);
|
|
230
|
+
}
|
|
231
|
+
else if (!this.isStarting() || !(waitTask === null || waitTask === void 0 ? void 0 : waitTask.isRunning)) {
|
|
232
|
+
resolve(false);
|
|
233
|
+
clearInterval(iv);
|
|
234
|
+
}
|
|
235
|
+
}, 10);
|
|
236
|
+
});
|
|
237
|
+
return res;
|
|
238
|
+
};
|
|
239
|
+
waitTask = new task_1.InteruptableTask(wait(), {
|
|
240
|
+
errorOnTimeout: false,
|
|
241
|
+
timeout: startupTimeout
|
|
242
|
+
});
|
|
243
|
+
this.logEvent({ message: 'wait for sensor data', device: this.getName() });
|
|
244
|
+
const hasData = yield waitTask.run();
|
|
245
|
+
clearInterval(iv);
|
|
246
|
+
if (hasData)
|
|
247
|
+
this.logEvent({ message: 'sensor data received', device: this.getName() });
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
checkCapabilities() {
|
|
251
|
+
}
|
|
252
|
+
initControl(_props) {
|
|
253
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
startAdapter(startProps) {
|
|
257
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
189
258
|
const props = this.getStartProps(startProps);
|
|
259
|
+
const { timeout = this.getDefaultStartupTimeout() } = startProps;
|
|
260
|
+
const wasPaused = this.paused;
|
|
190
261
|
const preCheckResult = yield this.startPreChecks(props);
|
|
191
|
-
if (preCheckResult === 'done')
|
|
262
|
+
if (preCheckResult === 'done') {
|
|
263
|
+
yield (0, utils_1.resolveNextTick)();
|
|
192
264
|
return this.started;
|
|
193
|
-
|
|
194
|
-
|
|
265
|
+
}
|
|
266
|
+
if (preCheckResult === 'connection-failed') {
|
|
267
|
+
this.logEvent({ message: 'start result: error', error: 'could not start device, reason:could not connect', protocol: this.getProtocolName() });
|
|
268
|
+
yield (0, utils_1.resolveNextTick)();
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
195
271
|
this.logEvent({ message: 'starting device', device: this.getName(), props, isStarted: this.started });
|
|
196
272
|
try {
|
|
197
|
-
const
|
|
198
|
-
if (
|
|
199
|
-
|
|
200
|
-
this.resetData();
|
|
201
|
-
this.stopped = false;
|
|
202
|
-
this.started = true;
|
|
203
|
-
this.paused = false;
|
|
204
|
-
return true;
|
|
273
|
+
const connected = yield this.startSensor();
|
|
274
|
+
if (connected) {
|
|
275
|
+
this.logEvent({ message: 'peripheral connected', device: this.getName(), props });
|
|
205
276
|
}
|
|
277
|
+
else {
|
|
278
|
+
this.logEvent({ message: 'peripheral connection failed', device: this.getName(), reason: 'unknown', props });
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
yield this.waitForInitialData(timeout);
|
|
282
|
+
yield this.checkCapabilities();
|
|
283
|
+
if (this.hasCapability(types_1.IncyclistCapability.Control))
|
|
284
|
+
yield this.initControl(startProps);
|
|
285
|
+
this.resetData();
|
|
286
|
+
this.stopped = false;
|
|
287
|
+
this.started = true;
|
|
288
|
+
if (wasPaused)
|
|
289
|
+
this.resume();
|
|
290
|
+
return true;
|
|
206
291
|
}
|
|
207
292
|
catch (err) {
|
|
208
|
-
this.
|
|
209
|
-
|
|
210
|
-
throw new Error(`could not start device, reason:${err.message}`);
|
|
293
|
+
this.logEvent({ message: 'start result: error', error: err.message, protocol: this.getProtocolName() });
|
|
294
|
+
return false;
|
|
211
295
|
}
|
|
212
296
|
});
|
|
213
297
|
}
|
|
298
|
+
startSensor() {
|
|
299
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
300
|
+
var _a;
|
|
301
|
+
if (!((_a = this.getComms()) === null || _a === void 0 ? void 0 : _a.hasPeripheral())) {
|
|
302
|
+
yield this.waitForPeripheral();
|
|
303
|
+
}
|
|
304
|
+
if (!this.getComms()) {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
const connected = yield this.getComms().startSensor();
|
|
308
|
+
if (connected) {
|
|
309
|
+
this.getComms().on('data', this.onDeviceDataHandler);
|
|
310
|
+
this.getComms().on('disconnected', this.emit.bind(this));
|
|
311
|
+
this.getComms().on('error', console.log);
|
|
312
|
+
}
|
|
313
|
+
return connected;
|
|
314
|
+
});
|
|
315
|
+
}
|
|
214
316
|
stop() {
|
|
215
317
|
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
-
this.
|
|
217
|
-
this.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
this.
|
|
318
|
+
this.logEvent({ message: 'stopping device', device: this.getName() });
|
|
319
|
+
if (this.isStarting()) {
|
|
320
|
+
yield this.startTask.stop();
|
|
321
|
+
}
|
|
322
|
+
let reason = 'unknown';
|
|
323
|
+
let stopped = false;
|
|
324
|
+
if (!this.getComms()) {
|
|
325
|
+
this.logEvent({ message: 'device stopped - not started yet', device: this.getName() });
|
|
224
326
|
return true;
|
|
225
327
|
}
|
|
226
|
-
|
|
328
|
+
this.getComms().reset();
|
|
329
|
+
try {
|
|
330
|
+
stopped = yield this.getComms().stopSensor();
|
|
331
|
+
}
|
|
332
|
+
catch (err) {
|
|
333
|
+
reason = err.message;
|
|
334
|
+
}
|
|
335
|
+
if (stopped) {
|
|
336
|
+
this.logEvent({ message: 'device stopped', device: this.getName() });
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
this.logEvent({ message: 'stopping device failed', device: this.getName(), reason });
|
|
340
|
+
}
|
|
341
|
+
this.started = false;
|
|
342
|
+
this.stopped = true;
|
|
343
|
+
return stopped;
|
|
227
344
|
});
|
|
228
345
|
}
|
|
229
346
|
pause() {
|
|
@@ -231,9 +348,9 @@ class BleAdapter extends adpater_1.default {
|
|
|
231
348
|
pause: { get: () => super.pause }
|
|
232
349
|
});
|
|
233
350
|
return __awaiter(this, void 0, void 0, function* () {
|
|
234
|
-
var _a;
|
|
235
351
|
const res = yield _super.pause.call(this);
|
|
236
|
-
|
|
352
|
+
const iface = interface_factory_1.BleMultiTransportInterfaceFactory.createInstance(this.getInterface());
|
|
353
|
+
iface.pauseLogging();
|
|
237
354
|
return res;
|
|
238
355
|
});
|
|
239
356
|
}
|
|
@@ -242,9 +359,9 @@ class BleAdapter extends adpater_1.default {
|
|
|
242
359
|
resume: { get: () => super.resume }
|
|
243
360
|
});
|
|
244
361
|
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
-
|
|
362
|
+
const iface = interface_factory_1.BleMultiTransportInterfaceFactory.createInstance(this.getInterface());
|
|
363
|
+
iface.resumeLogging();
|
|
246
364
|
const res = yield _super.resume.call(this);
|
|
247
|
-
(_a = this.getComms()) === null || _a === void 0 ? void 0 : _a.resume();
|
|
248
365
|
return res;
|
|
249
366
|
});
|
|
250
367
|
}
|