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
package/lib/ble/cp/adapter.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import BleCyclingPowerDevice from './
|
|
1
|
+
import BleCyclingPowerDevice from './sensor';
|
|
2
2
|
import BleAdapter from '../base/adapter';
|
|
3
3
|
import { PowerData } from './types';
|
|
4
|
-
import { BleDeviceSettings } from '../types';
|
|
4
|
+
import { BleDeviceSettings, IBlePeripheral } from '../types';
|
|
5
5
|
import { DeviceProperties, IncyclistBikeData, IncyclistAdapterData, ControllerConfig, IAdapter } from '../../types';
|
|
6
6
|
import { LegacyProfile } from '../../antv2/types';
|
|
7
7
|
import { UpdateRequest } from '../../modes/types';
|
|
@@ -11,8 +11,8 @@ export default class PwrAdapter extends BleAdapter<PowerData, BleCyclingPowerDev
|
|
|
11
11
|
distanceInternal: number;
|
|
12
12
|
constructor(settings: BleDeviceSettings, props?: DeviceProperties);
|
|
13
13
|
isSame(device: IAdapter): boolean;
|
|
14
|
+
updateSensor(peripheral: IBlePeripheral): void;
|
|
14
15
|
getProfile(): LegacyProfile;
|
|
15
|
-
getName(): string;
|
|
16
16
|
getDisplayName(): string;
|
|
17
17
|
mapData(deviceData: PowerData): IncyclistBikeData;
|
|
18
18
|
transformData(bikeData: IncyclistBikeData): IncyclistAdapterData;
|
package/lib/ble/cp/adapter.js
CHANGED
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
16
|
-
const
|
|
16
|
+
const sensor_1 = __importDefault(require("./sensor"));
|
|
17
17
|
const adapter_1 = __importDefault(require("../base/adapter"));
|
|
18
18
|
const types_1 = require("../../types");
|
|
19
19
|
const power_meter_1 = __importDefault(require("../../modes/power-meter"));
|
|
@@ -22,9 +22,7 @@ class PwrAdapter extends adapter_1.default {
|
|
|
22
22
|
super(settings, props);
|
|
23
23
|
this.distanceInternal = 0;
|
|
24
24
|
this.logger = new gd_eventlog_1.EventLogger('Ble-CP');
|
|
25
|
-
|
|
26
|
-
const logger = this.logger;
|
|
27
|
-
this.device = new comm_1.default({ id, address, name, logger });
|
|
25
|
+
this.device = new sensor_1.default(this.getPeripheral(), { logger: this.logger });
|
|
28
26
|
this.capabilities = [
|
|
29
27
|
types_1.IncyclistCapability.Power, types_1.IncyclistCapability.Cadence, types_1.IncyclistCapability.Speed
|
|
30
28
|
];
|
|
@@ -34,19 +32,20 @@ class PwrAdapter extends adapter_1.default {
|
|
|
34
32
|
return false;
|
|
35
33
|
return this.isEqual(device.settings);
|
|
36
34
|
}
|
|
35
|
+
updateSensor(peripheral) {
|
|
36
|
+
this.device = new sensor_1.default(peripheral, { logger: this.logger });
|
|
37
|
+
}
|
|
37
38
|
getProfile() {
|
|
38
39
|
return 'Power Meter';
|
|
39
40
|
}
|
|
40
|
-
getName() {
|
|
41
|
-
return `${this.device.name}`;
|
|
42
|
-
}
|
|
43
41
|
getDisplayName() {
|
|
44
|
-
const
|
|
42
|
+
const name = this.getName();
|
|
45
43
|
const { instantaneousPower: power } = this.deviceData;
|
|
46
44
|
const powerStr = power ? ` (${power})` : '';
|
|
47
45
|
return `${name}${powerStr}`;
|
|
48
46
|
}
|
|
49
47
|
mapData(deviceData) {
|
|
48
|
+
var _a, _b, _c;
|
|
50
49
|
const data = {
|
|
51
50
|
isPedalling: false,
|
|
52
51
|
power: 0,
|
|
@@ -57,9 +56,9 @@ class PwrAdapter extends adapter_1.default {
|
|
|
57
56
|
slope: undefined,
|
|
58
57
|
time: undefined
|
|
59
58
|
};
|
|
60
|
-
data.power = (deviceData
|
|
61
|
-
data.pedalRpm = (deviceData
|
|
62
|
-
data.time = (deviceData
|
|
59
|
+
data.power = (_a = deviceData === null || deviceData === void 0 ? void 0 : deviceData.instantaneousPower) !== null && _a !== void 0 ? _a : data.power;
|
|
60
|
+
data.pedalRpm = (_b = deviceData === null || deviceData === void 0 ? void 0 : deviceData.rpm) !== null && _b !== void 0 ? _b : data.pedalRpm;
|
|
61
|
+
data.time = (_c = deviceData === null || deviceData === void 0 ? void 0 : deviceData.time) !== null && _c !== void 0 ? _c : data.time;
|
|
63
62
|
data.isPedalling = data.pedalRpm > 0 || (data.pedalRpm === undefined && data.power > 0);
|
|
64
63
|
return data;
|
|
65
64
|
}
|
|
@@ -93,10 +92,10 @@ class PwrAdapter extends adapter_1.default {
|
|
|
93
92
|
try {
|
|
94
93
|
if (this.isPaused() || this.isStopped())
|
|
95
94
|
return;
|
|
96
|
-
return
|
|
95
|
+
return this.getCyclingMode().sendBikeUpdate(request);
|
|
97
96
|
}
|
|
98
97
|
catch (err) {
|
|
99
|
-
this.logEvent({ message: 'Error', fn: 'sendUpdate', error: err.message });
|
|
98
|
+
this.logEvent({ message: 'Error', fn: 'BleCP:sendUpdate', error: err.message });
|
|
100
99
|
}
|
|
101
100
|
});
|
|
102
101
|
}
|
package/lib/ble/cp/comm.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CrankData, PowerData } from './types';
|
|
2
|
-
import { BleComms } from '../base/
|
|
2
|
+
import { BleComms } from '../base/sensor';
|
|
3
3
|
import { LegacyProfile } from '../../antv2/types';
|
|
4
4
|
import { BleProtocol, IBlePeripheralConnector } from '../types';
|
|
5
5
|
export default class BleCyclingPowerDevice extends BleComms {
|
package/lib/ble/cp/comm.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const consts_1 = require("../consts");
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
-
const
|
|
6
|
-
class BleCyclingPowerDevice extends
|
|
5
|
+
const sensor_1 = require("../base/sensor");
|
|
6
|
+
class BleCyclingPowerDevice extends sensor_1.BleComms {
|
|
7
7
|
constructor() {
|
|
8
8
|
super(...arguments);
|
|
9
9
|
this.instantaneousPower = undefined;
|
package/lib/ble/cp/index.d.ts
CHANGED
package/lib/ble/cp/index.js
CHANGED
|
@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.BlePwrComms = exports.BlePwrAdapter = void 0;
|
|
7
7
|
const adapter_1 = __importDefault(require("./adapter"));
|
|
8
8
|
exports.BlePwrAdapter = adapter_1.default;
|
|
9
|
-
const
|
|
10
|
-
exports.BlePwrComms =
|
|
9
|
+
const sensor_1 = __importDefault(require("./sensor"));
|
|
10
|
+
exports.BlePwrComms = sensor_1.default;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CrankData, PowerData } from './types';
|
|
2
|
+
import { LegacyProfile } from '../../antv2/types';
|
|
3
|
+
import { BleProtocol } from '../types';
|
|
4
|
+
import { TBleSensor } from '../base/sensor';
|
|
5
|
+
export default class BleCyclingPowerDevice extends TBleSensor {
|
|
6
|
+
static readonly profile: LegacyProfile;
|
|
7
|
+
static readonly protocol: BleProtocol;
|
|
8
|
+
static readonly services: string[];
|
|
9
|
+
static readonly characteristics: string[];
|
|
10
|
+
static readonly detectionPriority = 1;
|
|
11
|
+
instantaneousPower: number;
|
|
12
|
+
balance: number;
|
|
13
|
+
accTorque: number;
|
|
14
|
+
rpm: number;
|
|
15
|
+
timeOffset: number;
|
|
16
|
+
time: number;
|
|
17
|
+
currentCrankData: CrankData;
|
|
18
|
+
prevCrankData: CrankData;
|
|
19
|
+
parseCrankData(crankData: any): {
|
|
20
|
+
rpm: number;
|
|
21
|
+
time: any;
|
|
22
|
+
};
|
|
23
|
+
parsePower(_data: Uint8Array): PowerData;
|
|
24
|
+
protected getRequiredCharacteristics(): Array<string>;
|
|
25
|
+
onData(characteristic: string, data: Buffer): boolean;
|
|
26
|
+
reset(): void;
|
|
27
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const consts_1 = require("../consts");
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const sensor_1 = require("../base/sensor");
|
|
6
|
+
class BleCyclingPowerDevice extends sensor_1.TBleSensor {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.instantaneousPower = undefined;
|
|
10
|
+
this.balance = undefined;
|
|
11
|
+
this.accTorque = undefined;
|
|
12
|
+
this.rpm = undefined;
|
|
13
|
+
this.timeOffset = 0;
|
|
14
|
+
this.time = undefined;
|
|
15
|
+
this.currentCrankData = undefined;
|
|
16
|
+
this.prevCrankData = undefined;
|
|
17
|
+
}
|
|
18
|
+
parseCrankData(crankData) {
|
|
19
|
+
if (!this.prevCrankData)
|
|
20
|
+
this.prevCrankData = { revolutions: 0, time: 0, cntUpdateMissing: -1 };
|
|
21
|
+
const c = this.currentCrankData = crankData;
|
|
22
|
+
const p = this.prevCrankData;
|
|
23
|
+
let rpm = this.rpm;
|
|
24
|
+
let hasUpdate = c.time !== p.time;
|
|
25
|
+
if (hasUpdate) {
|
|
26
|
+
let time = c.time - p.time;
|
|
27
|
+
let revs = c.revolutions - p.revolutions;
|
|
28
|
+
if (c.time < p.time) {
|
|
29
|
+
time += 0x10000;
|
|
30
|
+
this.timeOffset += 0x10000;
|
|
31
|
+
}
|
|
32
|
+
if (c.revolutions < p.revolutions)
|
|
33
|
+
revs += 0x10000;
|
|
34
|
+
rpm = 1024 * 60 * revs / time;
|
|
35
|
+
}
|
|
36
|
+
else if (p.cntUpdateMissing < 0 || p.cntUpdateMissing > 2) {
|
|
37
|
+
rpm = 0;
|
|
38
|
+
}
|
|
39
|
+
const cntUpdateMissing = p.cntUpdateMissing;
|
|
40
|
+
this.prevCrankData = this.currentCrankData;
|
|
41
|
+
if (hasUpdate)
|
|
42
|
+
this.prevCrankData.cntUpdateMissing = 0;
|
|
43
|
+
else
|
|
44
|
+
this.prevCrankData.cntUpdateMissing = cntUpdateMissing + 1;
|
|
45
|
+
return { rpm, time: this.timeOffset + c.time };
|
|
46
|
+
}
|
|
47
|
+
parsePower(_data) {
|
|
48
|
+
const data = Buffer.from(_data);
|
|
49
|
+
try {
|
|
50
|
+
let offset = 4;
|
|
51
|
+
const flags = data.readUInt16LE(0);
|
|
52
|
+
this.instantaneousPower = data.readUInt16LE(2);
|
|
53
|
+
if (flags & 0x1)
|
|
54
|
+
this.balance = data.readUInt8(offset++);
|
|
55
|
+
if (flags & 0x4) {
|
|
56
|
+
this.accTorque = data.readUInt16LE(offset);
|
|
57
|
+
offset += 2;
|
|
58
|
+
}
|
|
59
|
+
if (flags & 0x10) {
|
|
60
|
+
offset += 6;
|
|
61
|
+
}
|
|
62
|
+
if (flags & 0x20) {
|
|
63
|
+
const crankData = {
|
|
64
|
+
revolutions: data.readUInt16LE(offset),
|
|
65
|
+
time: data.readUInt16LE(offset + 2)
|
|
66
|
+
};
|
|
67
|
+
const { rpm, time } = this.parseCrankData(crankData);
|
|
68
|
+
this.rpm = rpm;
|
|
69
|
+
this.time = time;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
}
|
|
74
|
+
const { instantaneousPower, balance, accTorque, rpm, time } = this;
|
|
75
|
+
return { instantaneousPower, balance, accTorque, rpm, time, raw: `2a63:${data.toString('hex')}` };
|
|
76
|
+
}
|
|
77
|
+
getRequiredCharacteristics() {
|
|
78
|
+
return [consts_1.CSP_MEASUREMENT];
|
|
79
|
+
}
|
|
80
|
+
onData(characteristic, data) {
|
|
81
|
+
const hasData = super.onData(characteristic, data);
|
|
82
|
+
if (!hasData)
|
|
83
|
+
return false;
|
|
84
|
+
if ((0, utils_1.matches)(characteristic, consts_1.CSP_MEASUREMENT)) {
|
|
85
|
+
const res = this.parsePower(data);
|
|
86
|
+
this.emit('data', res);
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
reset() {
|
|
92
|
+
this.instantaneousPower = undefined;
|
|
93
|
+
this.balance = undefined;
|
|
94
|
+
this.accTorque = undefined;
|
|
95
|
+
this.rpm = undefined;
|
|
96
|
+
this.timeOffset = 0;
|
|
97
|
+
this.time = undefined;
|
|
98
|
+
this.currentCrankData = undefined;
|
|
99
|
+
this.prevCrankData = undefined;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
BleCyclingPowerDevice.profile = 'Power Meter';
|
|
103
|
+
BleCyclingPowerDevice.protocol = 'cp';
|
|
104
|
+
BleCyclingPowerDevice.services = [consts_1.CSP];
|
|
105
|
+
BleCyclingPowerDevice.characteristics = [consts_1.CSP_MEASUREMENT, consts_1.CSP_FEATURE, '2a5d', '2a3c'];
|
|
106
|
+
BleCyclingPowerDevice.detectionPriority = 1;
|
|
107
|
+
exports.default = BleCyclingPowerDevice;
|
package/lib/ble/elite/comms.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LegacyProfile } from "../../antv2/types";
|
|
2
|
-
import { BleComms } from "../base/
|
|
2
|
+
import { BleComms } from "../base/sensor";
|
|
3
3
|
import { CrankData, PowerData } from "../cp";
|
|
4
4
|
import { BleProtocol, IBlePeripheralConnector } from "../types";
|
|
5
5
|
export default class BleEliteDevice extends BleComms {
|
package/lib/ble/elite/comms.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const _1 = require(".");
|
|
4
|
-
const
|
|
4
|
+
const sensor_1 = require("../base/sensor");
|
|
5
5
|
const consts_1 = require("../consts");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
|
-
class BleEliteDevice extends
|
|
7
|
+
class BleEliteDevice extends sensor_1.BleComms {
|
|
8
8
|
constructor(props) {
|
|
9
9
|
super(props);
|
|
10
10
|
this.instantaneousPower = undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import BleAdapter from "../base/adapter";
|
|
2
|
+
import { BleDeviceSettings, BleProtocol } from "../types";
|
|
3
|
+
import { DeviceProperties } from "../../types";
|
|
4
|
+
import { BleDeviceData } from "../base/types";
|
|
5
|
+
import { TBleSensor } from "../base/sensor";
|
|
6
|
+
export interface BleAdapterInfo<T extends TBleSensor> {
|
|
7
|
+
protocol: BleProtocol;
|
|
8
|
+
Adapter: typeof BleAdapter<BleDeviceData, T>;
|
|
9
|
+
Sensor: typeof TBleSensor;
|
|
10
|
+
}
|
|
11
|
+
export declare class BleAdapterFactory<T extends TBleSensor> {
|
|
12
|
+
transport: string;
|
|
13
|
+
static readonly _instances: Record<string, BleAdapterFactory<any>>;
|
|
14
|
+
implementations: BleAdapterInfo<any>[];
|
|
15
|
+
instances: Array<BleAdapter<BleDeviceData, T>>;
|
|
16
|
+
static getInstance(transport: string): BleAdapterFactory<any>;
|
|
17
|
+
constructor(transport: string);
|
|
18
|
+
getAdapterInfo(protocol: BleProtocol): BleAdapterInfo<T>;
|
|
19
|
+
getAll(): BleAdapterInfo<T>[];
|
|
20
|
+
createInstance(settings: BleDeviceSettings, props?: DeviceProperties): BleAdapter<BleDeviceData, T>;
|
|
21
|
+
removeInstance(query: {
|
|
22
|
+
settings?: BleDeviceSettings;
|
|
23
|
+
adapter?: BleAdapter<BleDeviceData, T>;
|
|
24
|
+
}): void;
|
|
25
|
+
find(settings?: BleDeviceSettings): BleAdapter<BleDeviceData, T>;
|
|
26
|
+
register(protocol: BleProtocol, Adapter: typeof BleAdapter<BleDeviceData, T>, Sensor: typeof TBleSensor): void;
|
|
27
|
+
getAllInstances(): Array<BleAdapter<BleDeviceData, T>>;
|
|
28
|
+
getAllSupportedSensors(): (typeof TBleSensor)[];
|
|
29
|
+
getAllSupportedAdapters(): Array<(typeof BleAdapter<BleDeviceData, T>)>;
|
|
30
|
+
getServices(info: BleAdapterInfo<T>): string[];
|
|
31
|
+
getAllSupportedServices(): string[];
|
|
32
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BleAdapterFactory = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
class BleAdapterFactory {
|
|
6
|
+
static getInstance(transport) {
|
|
7
|
+
if (!BleAdapterFactory._instances[transport])
|
|
8
|
+
BleAdapterFactory._instances[transport] = new BleAdapterFactory(transport);
|
|
9
|
+
return BleAdapterFactory._instances[transport];
|
|
10
|
+
}
|
|
11
|
+
constructor(transport) {
|
|
12
|
+
this.transport = transport;
|
|
13
|
+
this.implementations = [];
|
|
14
|
+
this.instances = [];
|
|
15
|
+
}
|
|
16
|
+
getAdapterInfo(protocol) {
|
|
17
|
+
return this.implementations.find(a => a.protocol === protocol);
|
|
18
|
+
}
|
|
19
|
+
getAll() {
|
|
20
|
+
return this.implementations;
|
|
21
|
+
}
|
|
22
|
+
createInstance(settings, props) {
|
|
23
|
+
let { profile, protocol } = settings;
|
|
24
|
+
const adapterSettings = Object.assign({}, settings);
|
|
25
|
+
if (profile) {
|
|
26
|
+
try {
|
|
27
|
+
const mapping = (0, utils_1.mapLegacyProfile)(profile);
|
|
28
|
+
protocol = adapterSettings.protocol = mapping.protocol;
|
|
29
|
+
delete adapterSettings.profile;
|
|
30
|
+
}
|
|
31
|
+
catch (_a) {
|
|
32
|
+
delete settings.profile;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const existing = this.find(adapterSettings);
|
|
36
|
+
if (existing) {
|
|
37
|
+
existing.setProperties(props);
|
|
38
|
+
return existing;
|
|
39
|
+
}
|
|
40
|
+
const info = this.getAdapterInfo(protocol);
|
|
41
|
+
if (!(info === null || info === void 0 ? void 0 : info.Adapter))
|
|
42
|
+
return;
|
|
43
|
+
const AdapterClass = info.Adapter;
|
|
44
|
+
const adapter = new AdapterClass(adapterSettings, props);
|
|
45
|
+
this.instances.push(adapter);
|
|
46
|
+
return adapter;
|
|
47
|
+
}
|
|
48
|
+
removeInstance(query) {
|
|
49
|
+
let idx = -1;
|
|
50
|
+
if (query.settings) {
|
|
51
|
+
idx = this.instances.findIndex(a => a.isEqual(query.settings));
|
|
52
|
+
}
|
|
53
|
+
else if (query.adapter) {
|
|
54
|
+
idx = this.instances.findIndex(a => a.isEqual(query.adapter.getSettings()));
|
|
55
|
+
}
|
|
56
|
+
if (idx !== -1)
|
|
57
|
+
this.instances.splice(idx);
|
|
58
|
+
}
|
|
59
|
+
find(settings) {
|
|
60
|
+
return this.instances.find(a => a.isEqual(settings));
|
|
61
|
+
}
|
|
62
|
+
register(protocol, Adapter, Sensor) {
|
|
63
|
+
const info = { protocol, Adapter, Sensor };
|
|
64
|
+
const existing = this.implementations.findIndex(a => a.protocol === protocol);
|
|
65
|
+
if (existing !== -1)
|
|
66
|
+
this.implementations[existing] = info;
|
|
67
|
+
else
|
|
68
|
+
this.implementations.push(info);
|
|
69
|
+
}
|
|
70
|
+
getAllInstances() {
|
|
71
|
+
return this.instances;
|
|
72
|
+
}
|
|
73
|
+
getAllSupportedSensors() {
|
|
74
|
+
const supported = this.getAll();
|
|
75
|
+
return supported.map(info => info.Sensor);
|
|
76
|
+
}
|
|
77
|
+
getAllSupportedAdapters() {
|
|
78
|
+
const supported = this.getAll();
|
|
79
|
+
return supported.map(info => info.Adapter);
|
|
80
|
+
}
|
|
81
|
+
getServices(info) {
|
|
82
|
+
const Sensor = info.Sensor;
|
|
83
|
+
if (!Sensor)
|
|
84
|
+
return [];
|
|
85
|
+
const sensor = new Sensor(null, {});
|
|
86
|
+
return sensor.getServiceUUids().map(utils_1.fullUUID);
|
|
87
|
+
}
|
|
88
|
+
getAllSupportedServices() {
|
|
89
|
+
const supported = this.getAll();
|
|
90
|
+
const res = [];
|
|
91
|
+
if (supported && supported.length > 0) {
|
|
92
|
+
supported.forEach(info => {
|
|
93
|
+
const services = this.getServices(info);
|
|
94
|
+
services.forEach(s => {
|
|
95
|
+
if (!res.includes(s))
|
|
96
|
+
res.push(s);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return res;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.BleAdapterFactory = BleAdapterFactory;
|
|
104
|
+
BleAdapterFactory._instances = {};
|
|
@@ -0,0 +1,18 @@
|
|
|
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);
|
|
18
|
+
__exportStar(require("./interface-factory"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InterfaceFactory } from "../base/types";
|
|
2
|
+
import { IBleInterface } from "../types";
|
|
3
|
+
export declare class BleMultiTransportInterfaceFactory {
|
|
4
|
+
static readonly registered: Record<string, typeof InterfaceFactory>;
|
|
5
|
+
static register(transport: string, Class: typeof InterfaceFactory): void;
|
|
6
|
+
static createInstance(transport: string): IBleInterface<any>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BleMultiTransportInterfaceFactory = void 0;
|
|
4
|
+
class BleMultiTransportInterfaceFactory {
|
|
5
|
+
static register(transport, Class) {
|
|
6
|
+
this.registered[transport] = Class;
|
|
7
|
+
}
|
|
8
|
+
static createInstance(transport) {
|
|
9
|
+
var _a;
|
|
10
|
+
if (this.registered[transport]) {
|
|
11
|
+
const Class = this.registered[transport];
|
|
12
|
+
const iface = (_a = new Class()) === null || _a === void 0 ? void 0 : _a.getInterface();
|
|
13
|
+
return iface;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.BleMultiTransportInterfaceFactory = BleMultiTransportInterfaceFactory;
|
|
18
|
+
BleMultiTransportInterfaceFactory.registered = {};
|
package/lib/ble/fm/adapter.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import BleFitnessMachineDevice from './
|
|
1
|
+
import BleFitnessMachineDevice from './sensor';
|
|
2
2
|
import BleAdapter from '../base/adapter';
|
|
3
3
|
import ICyclingMode, { CyclingMode } from '../../modes/types';
|
|
4
4
|
import { IndoorBikeData } from './types';
|
|
5
|
-
import { BleDeviceProperties, BleDeviceSettings, BleStartProperties } from '../types';
|
|
5
|
+
import { BleDeviceProperties, BleDeviceSettings, BleStartProperties, IBlePeripheral } from '../types';
|
|
6
6
|
import { IAdapter, IncyclistAdapterData, IncyclistBikeData } from '../../types';
|
|
7
7
|
import { LegacyProfile } from '../../antv2/types';
|
|
8
8
|
export default class BleFmAdapter extends BleAdapter<IndoorBikeData, BleFitnessMachineDevice> {
|
|
@@ -10,14 +10,19 @@ export default class BleFmAdapter extends BleAdapter<IndoorBikeData, BleFitnessM
|
|
|
10
10
|
distanceInternal: number;
|
|
11
11
|
connectPromise: Promise<boolean>;
|
|
12
12
|
constructor(settings: BleDeviceSettings, props?: BleDeviceProperties);
|
|
13
|
+
updateSensor(peripheral: IBlePeripheral): void;
|
|
13
14
|
isSame(device: IAdapter): boolean;
|
|
14
|
-
getName(): string;
|
|
15
15
|
isControllable(): boolean;
|
|
16
16
|
getSupportedCyclingModes(): Array<typeof CyclingMode>;
|
|
17
17
|
getDefaultCyclingMode(): ICyclingMode;
|
|
18
18
|
mapData(deviceData: IndoorBikeData): IncyclistBikeData;
|
|
19
19
|
transformData(bikeData: IncyclistBikeData): IncyclistAdapterData;
|
|
20
|
-
|
|
20
|
+
protected checkResume(): boolean[];
|
|
21
|
+
protected initControl(_startProps?: BleStartProperties): Promise<void>;
|
|
22
|
+
protected setConstants(): void;
|
|
23
|
+
protected establishControl(): Promise<boolean>;
|
|
24
|
+
protected sendInitialRequest(): Promise<void>;
|
|
25
|
+
protected checkCapabilities(): void;
|
|
21
26
|
sendUpdate(request: any, enforced?: boolean): Promise<void>;
|
|
22
27
|
sendInitCommands(): Promise<boolean>;
|
|
23
28
|
}
|