incyclist-devices 2.3.0-beta.19 → 2.3.0-beta.20
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 +55 -0
- package/lib/ble/adapter-factory.d.ts +24 -20
- package/lib/ble/adapter-factory.js +36 -13
- package/lib/ble/base/comms.d.ts +74 -2
- package/lib/ble/base/comms.js +596 -3
- package/lib/ble/ble-interface.d.ts +4 -7
- package/lib/ble/ble-interface.js +2 -16
- package/lib/ble/ble-peripheral.d.ts +0 -1
- package/lib/ble/ble-peripheral.js +11 -7
- package/lib/ble/characteristics/csc/features.d.ts +10 -0
- package/lib/ble/characteristics/csc/features.js +19 -0
- package/lib/ble/characteristics/csc/measurement.d.ts +33 -0
- package/lib/ble/characteristics/csc/measurement.js +109 -0
- package/lib/ble/characteristics/types.d.ts +6 -0
- package/lib/ble/characteristics/types.js +2 -0
- package/lib/ble/consts.d.ts +1 -0
- package/lib/ble/consts.js +2 -1
- package/lib/ble/cp/comm.d.ts +1 -1
- package/lib/ble/cp/comm.js +2 -2
- package/lib/ble/csc/adapter.d.ts +17 -0
- package/lib/ble/csc/adapter.js +66 -0
- package/lib/ble/csc/index.d.ts +3 -0
- package/lib/ble/csc/index.js +19 -0
- package/lib/ble/csc/sensor.d.ts +21 -0
- package/lib/ble/csc/sensor.js +64 -0
- package/lib/ble/csc/types.d.ts +6 -0
- package/lib/ble/csc/types.js +2 -0
- package/lib/ble/elite/comms.d.ts +1 -1
- package/lib/ble/elite/comms.js +2 -2
- package/lib/ble/fm/comms.d.ts +1 -1
- package/lib/ble/fm/comms.js +3 -3
- package/lib/ble/hr/comm.d.ts +1 -1
- package/lib/ble/hr/comm.js +2 -2
- package/lib/ble/index.js +2 -0
- package/lib/ble/tacx/comms.d.ts +1 -1
- package/lib/ble/tacx/comms.js +2 -2
- package/lib/ble/tacx/sensor.js +1 -1
- package/lib/ble/types.d.ts +1 -1
- package/lib/ble/utils.d.ts +1 -0
- package/lib/ble/utils.js +5 -1
- package/lib/ble/wahoo/comms.d.ts +1 -1
- package/lib/ble/wahoo/comms.js +2 -2
- package/package.json +1 -1
|
@@ -18,7 +18,6 @@ export default class BlePeripheralConnector implements IBlePeripheralConnector {
|
|
|
18
18
|
private emitter;
|
|
19
19
|
constructor(peripheral: BlePeripheral);
|
|
20
20
|
logEvent(event: any): void;
|
|
21
|
-
logError(err: Error, fn: string, args?: any): void;
|
|
22
21
|
connect(): Promise<void>;
|
|
23
22
|
reconnect(): Promise<void>;
|
|
24
23
|
onDisconnect(): void;
|
|
@@ -12,12 +12,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const ble_interface_1 = __importDefault(require("./ble-interface"));
|
|
16
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
15
17
|
const events_1 = __importDefault(require("events"));
|
|
16
18
|
const utils_1 = require("./utils");
|
|
17
|
-
const interface_1 = require("./base/interface");
|
|
18
19
|
class BlePeripheralConnector {
|
|
19
20
|
constructor(peripheral) {
|
|
20
|
-
this.ble =
|
|
21
|
+
this.ble = ble_interface_1.default.getInstance();
|
|
21
22
|
this.peripheral = peripheral;
|
|
22
23
|
this.emitter = new events_1.default();
|
|
23
24
|
if (!this.peripheral || !this.ble)
|
|
@@ -25,13 +26,16 @@ class BlePeripheralConnector {
|
|
|
25
26
|
this.state = { subscribed: [], isConnected: false, isConnecting: false, isInitialized: false, isInitializing: false, isSubscribing: false };
|
|
26
27
|
this.services = [];
|
|
27
28
|
this.characteristics = [];
|
|
28
|
-
this.logger =
|
|
29
|
+
this.logger = new gd_eventlog_1.EventLogger('BLE');
|
|
29
30
|
}
|
|
30
31
|
logEvent(event) {
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
if (this.logger) {
|
|
33
|
+
this.logger.logEvent(event);
|
|
34
|
+
}
|
|
35
|
+
const w = global.window;
|
|
36
|
+
if ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || process.env.BLE_DEBUG) {
|
|
37
|
+
console.log('~~~ BLE', event);
|
|
38
|
+
}
|
|
35
39
|
}
|
|
36
40
|
connect() {
|
|
37
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CharacteristicParser } from "../types";
|
|
2
|
+
export type BleCSCFeatures = {
|
|
3
|
+
wheelRevolutionData?: boolean;
|
|
4
|
+
crankRevolutionData?: boolean;
|
|
5
|
+
multipleSensorLocations?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare class CscFeatures implements CharacteristicParser<BleCSCFeatures> {
|
|
8
|
+
parse(buffer: Buffer): BleCSCFeatures;
|
|
9
|
+
reset(): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CscFeatures = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
class CscFeatures {
|
|
6
|
+
parse(buffer) {
|
|
7
|
+
const data = Buffer.from(buffer);
|
|
8
|
+
const value = data.readUInt8(0);
|
|
9
|
+
const bool = (bitNo) => (value & (0, utils_1.bit)(bitNo)) > 0;
|
|
10
|
+
return {
|
|
11
|
+
wheelRevolutionData: bool(0),
|
|
12
|
+
crankRevolutionData: bool(1),
|
|
13
|
+
multipleSensorLocations: bool(2)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
reset() {
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.CscFeatures = CscFeatures;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CrankData } from "../../cp";
|
|
2
|
+
import { CharacteristicParser, Feature } from "../types";
|
|
3
|
+
export type CyclingCadenceAndSpeed = {
|
|
4
|
+
cadence?: number;
|
|
5
|
+
speed?: number;
|
|
6
|
+
};
|
|
7
|
+
export declare class CscMeasurement implements CharacteristicParser<CyclingCadenceAndSpeed> {
|
|
8
|
+
protected data: CyclingCadenceAndSpeed;
|
|
9
|
+
protected prevCrankData: CrankData;
|
|
10
|
+
protected currentCrankData: CrankData;
|
|
11
|
+
protected prevWheelData: CrankData;
|
|
12
|
+
protected currentWheelData: CrankData;
|
|
13
|
+
protected timeOffset: number;
|
|
14
|
+
protected cw: number;
|
|
15
|
+
constructor(data?: CyclingCadenceAndSpeed);
|
|
16
|
+
setWheelCircumference(wheelCircumference: any): void;
|
|
17
|
+
parse(buffer: Buffer, features?: Feature): CyclingCadenceAndSpeed;
|
|
18
|
+
protected parseCrankData(crankData: any): {
|
|
19
|
+
rpm?: undefined;
|
|
20
|
+
time?: undefined;
|
|
21
|
+
} | {
|
|
22
|
+
rpm: number;
|
|
23
|
+
time: any;
|
|
24
|
+
};
|
|
25
|
+
protected parseWheelData(wheelData: any): {
|
|
26
|
+
speed?: undefined;
|
|
27
|
+
time?: undefined;
|
|
28
|
+
} | {
|
|
29
|
+
speed: number;
|
|
30
|
+
time: any;
|
|
31
|
+
};
|
|
32
|
+
reset(): void;
|
|
33
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CscMeasurement = void 0;
|
|
4
|
+
class CscMeasurement {
|
|
5
|
+
constructor(data = {}) {
|
|
6
|
+
this.data = data;
|
|
7
|
+
this.prevCrankData = undefined;
|
|
8
|
+
this.currentCrankData = undefined;
|
|
9
|
+
this.prevWheelData = undefined;
|
|
10
|
+
this.currentWheelData = undefined;
|
|
11
|
+
this.timeOffset = 0;
|
|
12
|
+
this.cw = 2.1;
|
|
13
|
+
}
|
|
14
|
+
setWheelCircumference(wheelCircumference) {
|
|
15
|
+
this.cw = wheelCircumference;
|
|
16
|
+
}
|
|
17
|
+
parse(buffer, features) {
|
|
18
|
+
const data = Buffer.from(buffer);
|
|
19
|
+
let offset = 0;
|
|
20
|
+
const flags = data.readUInt8(offset);
|
|
21
|
+
offset++;
|
|
22
|
+
if (flags & 0x01) {
|
|
23
|
+
const wheelData = {
|
|
24
|
+
revolutions: data.readUInt32LE(offset),
|
|
25
|
+
time: data.readUInt16LE(offset + 4)
|
|
26
|
+
};
|
|
27
|
+
const { speed } = this.parseWheelData(wheelData);
|
|
28
|
+
this.data.speed = speed;
|
|
29
|
+
offset += 6;
|
|
30
|
+
}
|
|
31
|
+
if (flags & 0x02) {
|
|
32
|
+
const crankData = {
|
|
33
|
+
revolutions: data.readUInt16LE(offset),
|
|
34
|
+
time: data.readUInt16LE(offset + 2)
|
|
35
|
+
};
|
|
36
|
+
const { rpm } = this.parseCrankData(crankData);
|
|
37
|
+
this.data.cadence = rpm;
|
|
38
|
+
}
|
|
39
|
+
return this.data;
|
|
40
|
+
}
|
|
41
|
+
parseCrankData(crankData) {
|
|
42
|
+
if (!this.prevCrankData) {
|
|
43
|
+
this.prevCrankData = Object.assign(Object.assign({}, crankData), { cntUpdateMissing: -1 });
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
46
|
+
const c = this.currentCrankData = crankData;
|
|
47
|
+
const p = this.prevCrankData;
|
|
48
|
+
let rpm = this.data.cadence;
|
|
49
|
+
let hasUpdate = c.time !== p.time;
|
|
50
|
+
if (hasUpdate) {
|
|
51
|
+
let time = c.time - p.time;
|
|
52
|
+
let revs = c.revolutions - p.revolutions;
|
|
53
|
+
if (c.time < p.time) {
|
|
54
|
+
time += 0x10000;
|
|
55
|
+
this.timeOffset += 0x10000;
|
|
56
|
+
}
|
|
57
|
+
if (c.revolutions < p.revolutions)
|
|
58
|
+
revs += 0x10000;
|
|
59
|
+
rpm = 1024 * 60 * revs / time;
|
|
60
|
+
}
|
|
61
|
+
else if (p.cntUpdateMissing < 0 || p.cntUpdateMissing > 2) {
|
|
62
|
+
rpm = 0;
|
|
63
|
+
}
|
|
64
|
+
const cntUpdateMissing = p.cntUpdateMissing;
|
|
65
|
+
this.prevCrankData = this.currentCrankData;
|
|
66
|
+
if (hasUpdate)
|
|
67
|
+
this.prevCrankData.cntUpdateMissing = 0;
|
|
68
|
+
else
|
|
69
|
+
this.prevCrankData.cntUpdateMissing = cntUpdateMissing + 1;
|
|
70
|
+
return { rpm, time: this.timeOffset + c.time };
|
|
71
|
+
}
|
|
72
|
+
parseWheelData(wheelData) {
|
|
73
|
+
if (!this.prevWheelData) {
|
|
74
|
+
this.prevWheelData = Object.assign(Object.assign({}, wheelData), { cntUpdateMissing: -1 });
|
|
75
|
+
return {};
|
|
76
|
+
}
|
|
77
|
+
const c = this.currentWheelData = wheelData;
|
|
78
|
+
const p = this.prevWheelData;
|
|
79
|
+
let speed = this.data.speed;
|
|
80
|
+
let hasUpdate = c.time !== p.time;
|
|
81
|
+
if (hasUpdate) {
|
|
82
|
+
let time = c.time - p.time;
|
|
83
|
+
let revs = c.revolutions - p.revolutions;
|
|
84
|
+
if (c.time < p.time) {
|
|
85
|
+
time += 0x10000;
|
|
86
|
+
this.timeOffset += 0x10000;
|
|
87
|
+
}
|
|
88
|
+
const rps = 1024 * revs / time;
|
|
89
|
+
speed = rps * this.cw;
|
|
90
|
+
}
|
|
91
|
+
else if (p.cntUpdateMissing < 0 || p.cntUpdateMissing > 2) {
|
|
92
|
+
speed = 0;
|
|
93
|
+
}
|
|
94
|
+
const cntUpdateMissing = p.cntUpdateMissing;
|
|
95
|
+
this.prevWheelData = this.currentWheelData;
|
|
96
|
+
if (hasUpdate)
|
|
97
|
+
this.prevWheelData.cntUpdateMissing = 0;
|
|
98
|
+
else
|
|
99
|
+
this.prevWheelData.cntUpdateMissing = cntUpdateMissing + 1;
|
|
100
|
+
return { speed, time: this.timeOffset + c.time };
|
|
101
|
+
}
|
|
102
|
+
reset() {
|
|
103
|
+
this.data = {};
|
|
104
|
+
this.prevCrankData = undefined;
|
|
105
|
+
this.currentCrankData = undefined;
|
|
106
|
+
this.timeOffset = 0;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.CscMeasurement = CscMeasurement;
|
package/lib/ble/consts.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ export declare const CSP_FEATURE = "2a65";
|
|
|
11
11
|
export declare const HR_MEASUREMENT = "2a37";
|
|
12
12
|
export declare const CSC = "1816";
|
|
13
13
|
export declare const CSC_MEASUREMENT = "2a5b";
|
|
14
|
+
export declare const CSC_FEATURE = "2a5c";
|
|
14
15
|
export declare const ELITE_TRAINER_SVC = "347b0001";
|
package/lib/ble/consts.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ELITE_TRAINER_SVC = exports.CSC_MEASUREMENT = exports.CSC = exports.HR_MEASUREMENT = exports.CSP_FEATURE = exports.CSP_MEASUREMENT = exports.CSP = exports.POWER_RANGE = exports.RES_LEVEL_RANGE = exports.FTMS_FEATURE = exports.INDOOR_BIKE_DATA = exports.FTMS_STATUS = exports.FTMS_CP = exports.FTMS = void 0;
|
|
3
|
+
exports.ELITE_TRAINER_SVC = exports.CSC_FEATURE = exports.CSC_MEASUREMENT = exports.CSC = exports.HR_MEASUREMENT = exports.CSP_FEATURE = exports.CSP_MEASUREMENT = exports.CSP = exports.POWER_RANGE = exports.RES_LEVEL_RANGE = exports.FTMS_FEATURE = exports.INDOOR_BIKE_DATA = exports.FTMS_STATUS = exports.FTMS_CP = exports.FTMS = void 0;
|
|
4
4
|
exports.FTMS = '1826';
|
|
5
5
|
exports.FTMS_CP = '2ad9';
|
|
6
6
|
exports.FTMS_STATUS = '2ada';
|
|
@@ -14,4 +14,5 @@ exports.CSP_FEATURE = '2a65';
|
|
|
14
14
|
exports.HR_MEASUREMENT = '2a37';
|
|
15
15
|
exports.CSC = '1816';
|
|
16
16
|
exports.CSC_MEASUREMENT = '2a5b';
|
|
17
|
+
exports.CSC_FEATURE = '2a5c';
|
|
17
18
|
exports.ELITE_TRAINER_SVC = '347b0001';
|
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/comms';
|
|
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 comms_1 = require("../base/comms");
|
|
6
|
+
class BleCyclingPowerDevice extends comms_1.BleComms {
|
|
7
7
|
constructor() {
|
|
8
8
|
super(...arguments);
|
|
9
9
|
this.instantaneousPower = undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import BleAdapter from '../base/adapter';
|
|
2
|
+
import { BleDeviceSettings, IBlePeripheral } from '../types';
|
|
3
|
+
import { DeviceProperties, IncyclistCapability, IAdapter, IncyclistAdapterData } from '../../types';
|
|
4
|
+
import { LegacyProfile } from '../../antv2/types';
|
|
5
|
+
import { BleCyclingSpeedCadenceDevice } from './sensor';
|
|
6
|
+
import { CSCData } from './types';
|
|
7
|
+
export declare class BleCSCAdapter extends BleAdapter<CSCData, BleCyclingSpeedCadenceDevice> {
|
|
8
|
+
protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
|
|
9
|
+
protected static CAPABILITIES: IncyclistCapability[];
|
|
10
|
+
constructor(settings: BleDeviceSettings, props?: DeviceProperties);
|
|
11
|
+
protected checkCapabilities(): Promise<void>;
|
|
12
|
+
isSame(device: IAdapter): boolean;
|
|
13
|
+
updateSensor(peripheral: IBlePeripheral): void;
|
|
14
|
+
getProfile(): LegacyProfile;
|
|
15
|
+
getDisplayName(): string;
|
|
16
|
+
mapData(deviceData: CSCData): IncyclistAdapterData;
|
|
17
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.BleCSCAdapter = void 0;
|
|
16
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
17
|
+
const adapter_1 = __importDefault(require("../base/adapter"));
|
|
18
|
+
const types_1 = require("../../types");
|
|
19
|
+
const sensor_1 = require("./sensor");
|
|
20
|
+
class BleCSCAdapter extends adapter_1.default {
|
|
21
|
+
constructor(settings, props) {
|
|
22
|
+
super(settings, props);
|
|
23
|
+
this.logger = new gd_eventlog_1.EventLogger('Ble-CSC');
|
|
24
|
+
this.device = new sensor_1.BleCyclingSpeedCadenceDevice(this.getPeripheral(), { logger: this.logger });
|
|
25
|
+
this.capabilities = BleCSCAdapter.CAPABILITIES;
|
|
26
|
+
}
|
|
27
|
+
checkCapabilities() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const before = this.capabilities.join(',');
|
|
30
|
+
const sensor = this.getSensor();
|
|
31
|
+
if (!sensor)
|
|
32
|
+
return;
|
|
33
|
+
const features = yield sensor.getFeatures();
|
|
34
|
+
if (!(features === null || features === void 0 ? void 0 : features.wheelRevolutionData))
|
|
35
|
+
this.capabilities = this.capabilities.filter(c => c !== types_1.IncyclistCapability.Speed);
|
|
36
|
+
if (!(features === null || features === void 0 ? void 0 : features.crankRevolutionData))
|
|
37
|
+
this.capabilities = this.capabilities.filter(c => c !== types_1.IncyclistCapability.Cadence);
|
|
38
|
+
const after = this.capabilities.join(',');
|
|
39
|
+
if (before !== after) {
|
|
40
|
+
this.logEvent({ message: 'device capabilities updated', name: this.getSettings().name, interface: this.getSettings().interface, capabilities: this.capabilities });
|
|
41
|
+
this.emit('device-info', this.getSettings(), { capabilities: this.capabilities });
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
isSame(device) {
|
|
46
|
+
if (!(device instanceof BleCSCAdapter))
|
|
47
|
+
return false;
|
|
48
|
+
return this.isEqual(device.settings);
|
|
49
|
+
}
|
|
50
|
+
updateSensor(peripheral) {
|
|
51
|
+
this.device = new sensor_1.BleCyclingSpeedCadenceDevice(peripheral, { logger: this.logger });
|
|
52
|
+
}
|
|
53
|
+
getProfile() {
|
|
54
|
+
return BleCSCAdapter.INCYCLIST_PROFILE_NAME;
|
|
55
|
+
}
|
|
56
|
+
getDisplayName() {
|
|
57
|
+
return this.getName();
|
|
58
|
+
}
|
|
59
|
+
mapData(deviceData) {
|
|
60
|
+
const { cadence, speed } = deviceData;
|
|
61
|
+
return { cadence, speed };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.BleCSCAdapter = BleCSCAdapter;
|
|
65
|
+
BleCSCAdapter.INCYCLIST_PROFILE_NAME = 'Speed + Cadence Sensor';
|
|
66
|
+
BleCSCAdapter.CAPABILITIES = [types_1.IncyclistCapability.Speed, types_1.IncyclistCapability.Cadence];
|
|
@@ -0,0 +1,19 @@
|
|
|
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"), exports);
|
|
18
|
+
__exportStar(require("./sensor"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LegacyProfile } from '../../antv2/types';
|
|
2
|
+
import { BleProtocol } from '../types';
|
|
3
|
+
import { TBleSensor } from '../base/sensor';
|
|
4
|
+
import { CharacteristicParser } from '../characteristics/types';
|
|
5
|
+
import { CyclingCadenceAndSpeed } from '../characteristics/csc/measurement';
|
|
6
|
+
import { BleCSCFeatures, CscFeatures } from '../characteristics/csc/features';
|
|
7
|
+
export declare class BleCyclingSpeedCadenceDevice extends TBleSensor {
|
|
8
|
+
static readonly profile: LegacyProfile;
|
|
9
|
+
static readonly protocol: BleProtocol;
|
|
10
|
+
static readonly services: string[];
|
|
11
|
+
static readonly characteristics: string[];
|
|
12
|
+
static readonly detectionPriority = 1;
|
|
13
|
+
protected data: CyclingCadenceAndSpeed;
|
|
14
|
+
protected parsers: Record<string, CharacteristicParser<any>>;
|
|
15
|
+
protected featureParser: CscFeatures;
|
|
16
|
+
constructor(peripheral: any, props?: any);
|
|
17
|
+
protected getRequiredCharacteristics(): Array<string>;
|
|
18
|
+
getFeatures(): Promise<BleCSCFeatures>;
|
|
19
|
+
onData(characteristic: string, data: Buffer): boolean;
|
|
20
|
+
reset(): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.BleCyclingSpeedCadenceDevice = void 0;
|
|
13
|
+
const consts_1 = require("../consts");
|
|
14
|
+
const utils_1 = require("../utils");
|
|
15
|
+
const sensor_1 = require("../base/sensor");
|
|
16
|
+
const measurement_1 = require("../characteristics/csc/measurement");
|
|
17
|
+
const features_1 = require("../characteristics/csc/features");
|
|
18
|
+
class BleCyclingSpeedCadenceDevice extends sensor_1.TBleSensor {
|
|
19
|
+
constructor(peripheral, props) {
|
|
20
|
+
super(peripheral, props);
|
|
21
|
+
this.parsers = {};
|
|
22
|
+
this.data = {};
|
|
23
|
+
const measurement = new measurement_1.CscMeasurement();
|
|
24
|
+
this.featureParser = new features_1.CscFeatures();
|
|
25
|
+
this.parsers[(0, utils_1.beautifyUUID)(consts_1.CSC_MEASUREMENT)] = measurement;
|
|
26
|
+
}
|
|
27
|
+
getRequiredCharacteristics() {
|
|
28
|
+
return [consts_1.CSC_MEASUREMENT];
|
|
29
|
+
}
|
|
30
|
+
getFeatures() {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
try {
|
|
33
|
+
const data = yield this.read(consts_1.CSC_FEATURE);
|
|
34
|
+
return this.featureParser.parse(data);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
this.logEvent({ message: 'read failed', characteristic: consts_1.CSC_FEATURE, reason: err.message });
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
onData(characteristic, data) {
|
|
42
|
+
const hasData = super.onData(characteristic, data);
|
|
43
|
+
if (!hasData)
|
|
44
|
+
return false;
|
|
45
|
+
const uuid = (0, utils_1.beautifyUUID)(characteristic);
|
|
46
|
+
const parser = this.parsers[uuid];
|
|
47
|
+
if (!parser) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
const parsed = parser.parse(data);
|
|
51
|
+
this.data = Object.assign(Object.assign({}, this.data), parsed);
|
|
52
|
+
this.emit('data', this.data);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
reset() {
|
|
56
|
+
this.data = {};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.BleCyclingSpeedCadenceDevice = BleCyclingSpeedCadenceDevice;
|
|
60
|
+
BleCyclingSpeedCadenceDevice.profile = 'Speed + Cadence Sensor';
|
|
61
|
+
BleCyclingSpeedCadenceDevice.protocol = 'csc';
|
|
62
|
+
BleCyclingSpeedCadenceDevice.services = [consts_1.CSC];
|
|
63
|
+
BleCyclingSpeedCadenceDevice.characteristics = [consts_1.CSC_MEASUREMENT, consts_1.CSC_FEATURE];
|
|
64
|
+
BleCyclingSpeedCadenceDevice.detectionPriority = 1;
|
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/comms";
|
|
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 comms_1 = require("../base/comms");
|
|
5
5
|
const consts_1 = require("../consts");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
|
-
class BleEliteDevice extends
|
|
7
|
+
class BleEliteDevice extends comms_1.BleComms {
|
|
8
8
|
constructor(props) {
|
|
9
9
|
super(props);
|
|
10
10
|
this.instantaneousPower = undefined;
|
package/lib/ble/fm/comms.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BleProtocol, BleWriteProps, IBlePeripheralConnector } from "../types";
|
|
2
2
|
import { IndoorBikeData, IndoorBikeFeatures } from "./types";
|
|
3
|
-
import { BleComms } from "../base/
|
|
3
|
+
import { BleComms } from "../base/comms";
|
|
4
4
|
import { LegacyProfile } from "../../antv2/types";
|
|
5
5
|
export default class BleFitnessMachineDevice extends BleComms {
|
|
6
6
|
static protocol: BleProtocol;
|
package/lib/ble/fm/comms.js
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const consts_1 = require("../consts");
|
|
13
|
-
const
|
|
13
|
+
const comms_1 = require("../base/comms");
|
|
14
14
|
const utils_1 = require("../utils");
|
|
15
15
|
const bit = (nr) => (1 << nr);
|
|
16
16
|
const IndoorBikeDataFlag = {
|
|
@@ -66,7 +66,7 @@ const TargetSettingFeatureFlag = {
|
|
|
66
66
|
SpinDownControlSupported: bit(15),
|
|
67
67
|
TargetedCadenceConfigurationSupported: bit(16)
|
|
68
68
|
};
|
|
69
|
-
class BleFitnessMachineDevice extends
|
|
69
|
+
class BleFitnessMachineDevice extends comms_1.BleComms {
|
|
70
70
|
constructor(props) {
|
|
71
71
|
super(props);
|
|
72
72
|
this.features = undefined;
|
|
@@ -92,7 +92,7 @@ class BleFitnessMachineDevice extends sensor_1.BleComms {
|
|
|
92
92
|
subscribeWriteResponse(cuuid) {
|
|
93
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
94
|
this.logEvent({ message: 'subscribe to CP response', characteristics: cuuid });
|
|
95
|
-
const connector = this.
|
|
95
|
+
const connector = this.ble.peripheralCache.getConnector(this.peripheral);
|
|
96
96
|
const isAlreadySubscribed = connector.isSubscribed(cuuid);
|
|
97
97
|
if (!isAlreadySubscribed) {
|
|
98
98
|
connector.removeAllListeners(cuuid);
|
package/lib/ble/hr/comm.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LegacyProfile } from '../../antv2/types';
|
|
2
|
-
import { BleComms } from '../base/
|
|
2
|
+
import { BleComms } from '../base/comms';
|
|
3
3
|
import { BleProtocol } from '../types';
|
|
4
4
|
import { HrmData } from './types';
|
|
5
5
|
export default class BleHrmDevice extends BleComms {
|
package/lib/ble/hr/comm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const comms_1 = require("../base/comms");
|
|
4
4
|
const consts_1 = require("../consts");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
-
class BleHrmDevice extends
|
|
6
|
+
class BleHrmDevice extends comms_1.BleComms {
|
|
7
7
|
constructor(props) {
|
|
8
8
|
super(props);
|
|
9
9
|
this.heartrate = undefined;
|
package/lib/ble/index.js
CHANGED
|
@@ -30,6 +30,7 @@ Object.defineProperty(exports, "BleInterface", { enumerable: true, get: function
|
|
|
30
30
|
const factories_1 = require("./factories");
|
|
31
31
|
Object.defineProperty(exports, "BleInterfaceFactory", { enumerable: true, get: function () { return factories_1.BleMultiTransportInterfaceFactory; } });
|
|
32
32
|
Object.defineProperty(exports, "BleAdapterFactory", { enumerable: true, get: function () { return factories_1.BleAdapterFactory; } });
|
|
33
|
+
const csc_1 = require("./csc");
|
|
33
34
|
['ble', 'wifi'].forEach(i => {
|
|
34
35
|
const af = factories_1.BleAdapterFactory.getInstance(i);
|
|
35
36
|
af.register('hr', hr_1.BleHrmAdapter, hr_1.BleHrmComms);
|
|
@@ -37,6 +38,7 @@ Object.defineProperty(exports, "BleAdapterFactory", { enumerable: true, get: fun
|
|
|
37
38
|
af.register('fm', fm_1.BleFmAdapter, fm_1.BleFmComms);
|
|
38
39
|
af.register('wahoo', wahoo_1.BleWahooAdapter, wahoo_1.BleWahooComms);
|
|
39
40
|
af.register('tacx', tacx_1.BleTacxAdapter, tacx_1.BleTacxComms);
|
|
41
|
+
af.register('csc', csc_1.BleCSCAdapter, csc_1.BleCyclingSpeedCadenceDevice);
|
|
40
42
|
});
|
|
41
43
|
factories_1.BleMultiTransportInterfaceFactory.register('ble', interface_1.BleInterfaceFactory);
|
|
42
44
|
__exportStar(require("./utils"), exports);
|
package/lib/ble/tacx/comms.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LegacyProfile } from "../../antv2/types";
|
|
2
2
|
import { CrankData } from "../cp";
|
|
3
3
|
import { IndoorBikeData } from "../fm";
|
|
4
|
-
import BleFitnessMachineDevice from "../fm/
|
|
4
|
+
import BleFitnessMachineDevice from "../fm/comms";
|
|
5
5
|
import { BleProtocol, IBlePeripheralConnector } from "../types";
|
|
6
6
|
import { BleFeBikeData } from "./types";
|
|
7
7
|
export default class TacxAdvancedFitnessMachineDevice extends BleFitnessMachineDevice {
|
package/lib/ble/tacx/comms.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 consts_1 = require("../consts");
|
|
16
|
-
const
|
|
16
|
+
const comms_1 = __importDefault(require("../fm/comms"));
|
|
17
17
|
const utils_1 = require("../utils");
|
|
18
18
|
var ANTMessages;
|
|
19
19
|
(function (ANTMessages) {
|
|
@@ -37,7 +37,7 @@ const PROFILE_ID = 'Tacx SmartTrainer';
|
|
|
37
37
|
const SYNC_BYTE = 0xA4;
|
|
38
38
|
const DEFAULT_CHANNEL = 5;
|
|
39
39
|
const ACKNOWLEDGED_DATA = 0x4F;
|
|
40
|
-
class TacxAdvancedFitnessMachineDevice extends
|
|
40
|
+
class TacxAdvancedFitnessMachineDevice extends comms_1.default {
|
|
41
41
|
constructor(props) {
|
|
42
42
|
super(props);
|
|
43
43
|
this.prevCrankData = undefined;
|
package/lib/ble/tacx/sensor.js
CHANGED
|
@@ -43,7 +43,7 @@ class TacxAdvancedFitnessMachineDevice extends sensor_1.default {
|
|
|
43
43
|
}
|
|
44
44
|
this.messageCnt++;
|
|
45
45
|
try {
|
|
46
|
-
const uuid = characteristic.
|
|
46
|
+
const uuid = (0, utils_1.beautifyUUID)(characteristic).toLowerCase();
|
|
47
47
|
let res = undefined;
|
|
48
48
|
if (uuid && (0, utils_1.matches)(uuid, this.tacxRx)) {
|
|
49
49
|
res = this.parseFECMessage(data);
|
package/lib/ble/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import EventEmitter from "events";
|
|
2
2
|
import { EventLogger } from "gd-eventlog";
|
|
3
3
|
import { DeviceProperties, DeviceSettings, DeviceStartProperties, IncyclistInterface, IncyclistScanProps, InterfaceProps } from "../types";
|
|
4
|
-
export type BleProtocol = 'hr' | 'fm' | 'cp' | 'tacx' | 'wahoo' | 'elite';
|
|
4
|
+
export type BleProtocol = 'hr' | 'fm' | 'cp' | 'tacx' | 'wahoo' | 'elite' | 'csc';
|
|
5
5
|
export type BleInterfaceState = 'unknown' | 'resetting' | 'unsupported' | 'unauthorized' | 'poweredOff' | 'poweredOn';
|
|
6
6
|
export interface BleBinding extends EventEmitter {
|
|
7
7
|
startScanning(serviceUUIDs?: string[], allowDuplicates?: boolean, callback?: (error?: Error) => void): void;
|
package/lib/ble/utils.d.ts
CHANGED
|
@@ -19,4 +19,5 @@ export declare const beautifyUUID: (str: string, withX?: boolean) => string;
|
|
|
19
19
|
export declare const fullUUID: (str: string) => string;
|
|
20
20
|
export declare const propertyVal: (properties: BleProperty[]) => number;
|
|
21
21
|
export declare const propertyFromVal: (val: number) => BleProperty[];
|
|
22
|
+
export declare const bit: (nr: any) => number;
|
|
22
23
|
export {};
|