incyclist-devices 2.0.0-beta.1 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.MD +238 -0
- package/lib/adapters.d.ts +1 -0
- package/lib/adapters.js +19 -0
- package/lib/antv2/adapter-factory.d.ts +8 -7
- package/lib/antv2/adapter-factory.js +4 -2
- package/lib/antv2/adapter.d.ts +3 -2
- package/lib/antv2/adapter.js +15 -4
- package/lib/antv2/ant-interface.d.ts +6 -2
- package/lib/antv2/ant-interface.js +27 -21
- package/lib/antv2/binding.d.ts +1 -1
- package/lib/antv2/binding.js +1 -1
- package/lib/antv2/fe/adapter.d.ts +12 -9
- package/lib/antv2/fe/adapter.js +67 -27
- package/lib/antv2/hr/adapter.d.ts +6 -5
- package/lib/antv2/hr/adapter.js +19 -16
- package/lib/antv2/index.d.ts +2 -2
- package/lib/antv2/pwr/adapter.d.ts +6 -4
- package/lib/antv2/pwr/adapter.js +24 -16
- package/lib/antv2/sensor-factory.d.ts +2 -2
- package/lib/antv2/types.d.ts +5 -2
- package/lib/antv2/types.js +3 -0
- package/lib/antv2/utils.d.ts +3 -0
- package/lib/antv2/utils.js +12 -1
- package/lib/base/adpater.d.ts +14 -2
- package/lib/base/adpater.js +43 -4
- package/lib/ble/adapter-factory.d.ts +18 -16
- package/lib/ble/adapter-factory.js +54 -45
- package/lib/ble/base/adapter.d.ts +53 -0
- package/lib/ble/{adapter.js → base/adapter.js} +111 -9
- package/lib/ble/base/comms-utils.d.ts +7 -0
- package/lib/ble/base/comms-utils.js +91 -0
- package/lib/ble/{ble-comms.d.ts → base/comms.d.ts} +27 -17
- package/lib/ble/{ble-comms.js → base/comms.js} +179 -53
- package/lib/ble/bindings/index.d.ts +2 -0
- package/lib/ble/bindings/index.js +8 -0
- package/lib/ble/bindings/linux.d.ts +15 -0
- package/lib/ble/bindings/linux.js +39 -0
- package/lib/ble/bindings/mock.d.ts +9 -0
- package/lib/ble/bindings/mock.js +108 -0
- package/lib/ble/bindings/types.d.ts +57 -0
- package/lib/ble/bindings/types.js +96 -0
- package/lib/ble/ble-interface.d.ts +34 -46
- package/lib/ble/ble-interface.js +242 -345
- package/lib/ble/ble-peripheral.d.ts +4 -2
- package/lib/ble/ble-peripheral.js +39 -8
- package/lib/ble/consts.d.ts +1 -0
- package/lib/ble/consts.js +2 -1
- package/lib/ble/cp/adapter.d.ts +1 -2
- package/lib/ble/cp/adapter.js +2 -15
- package/lib/ble/cp/comm.d.ts +8 -5
- package/lib/ble/cp/comm.js +12 -27
- package/lib/ble/elite/adapter.d.ts +1 -2
- package/lib/ble/elite/adapter.js +12 -19
- package/lib/ble/elite/comms.d.ts +8 -4
- package/lib/ble/elite/comms.js +12 -25
- package/lib/ble/fm/adapter.d.ts +3 -2
- package/lib/ble/fm/adapter.js +129 -70
- package/lib/ble/fm/comms.d.ts +8 -8
- package/lib/ble/fm/comms.js +33 -55
- package/lib/ble/fm/types.d.ts +5 -0
- package/lib/ble/hr/adapter.d.ts +1 -4
- package/lib/ble/hr/adapter.js +1 -18
- package/lib/ble/hr/comm.d.ts +6 -2
- package/lib/ble/hr/comm.js +6 -2
- package/lib/ble/hr/mock.d.ts +7 -0
- package/lib/ble/hr/mock.js +47 -0
- package/lib/ble/index.d.ts +2 -1
- package/lib/ble/index.js +5 -5
- package/lib/ble/peripheral-cache.d.ts +43 -0
- package/lib/ble/peripheral-cache.js +107 -0
- package/lib/ble/tacx/adapter.d.ts +1 -1
- package/lib/ble/tacx/adapter.js +20 -14
- package/lib/ble/tacx/comms.d.ts +6 -6
- package/lib/ble/tacx/comms.js +10 -43
- package/lib/ble/types.d.ts +54 -27
- package/lib/ble/types.js +0 -17
- package/lib/ble/utils.d.ts +15 -5
- package/lib/ble/utils.js +25 -66
- package/lib/ble/wahoo/adapter.d.ts +1 -1
- package/lib/ble/wahoo/adapter.js +12 -10
- package/lib/ble/wahoo/comms.d.ts +7 -6
- package/lib/ble/wahoo/comms.js +15 -17
- package/lib/index.d.ts +10 -7
- package/lib/index.js +21 -25
- package/lib/interfaces.d.ts +2 -1
- package/lib/interfaces.js +4 -0
- package/lib/modes/power-base.js +4 -0
- package/lib/serial/adapter.d.ts +5 -0
- package/lib/serial/adapter.js +19 -0
- package/lib/serial/bindings/tcp.d.ts +2 -1
- package/lib/serial/bindings/tcp.js +19 -5
- package/lib/serial/daum/DaumAdapter.d.ts +1 -1
- package/lib/serial/daum/DaumAdapter.js +16 -10
- package/lib/serial/daum/premium/adapter.d.ts +1 -0
- package/lib/serial/daum/premium/adapter.js +9 -2
- package/lib/serial/daum/premium/comms.js +10 -3
- package/lib/serial/daum/premium/mock.js +0 -1
- package/lib/serial/index.d.ts +3 -3
- package/lib/serial/index.js +2 -2
- package/lib/serial/kettler/ergo-racer/adapter.d.ts +1 -4
- package/lib/serial/kettler/ergo-racer/adapter.js +15 -39
- package/lib/serial/serial-interface.d.ts +3 -1
- package/lib/serial/serial-interface.js +43 -17
- package/lib/simulator/Simulator.d.ts +2 -0
- package/lib/simulator/Simulator.js +8 -5
- package/lib/types/adapter.d.ts +10 -3
- package/lib/types/device.d.ts +3 -0
- package/lib/types/interface.d.ts +7 -3
- package/package.json +3 -5
- package/lib/ble/adapter.d.ts +0 -41
- package/lib/ble/ble.d.ts +0 -57
- package/lib/ble/ble.js +0 -48
- package/lib/device.d.ts +0 -0
- package/lib/device.js +0 -0
package/lib/ble/wahoo/adapter.js
CHANGED
|
@@ -46,34 +46,36 @@ class BleWahooAdapter extends fm_1.BleFmAdapter {
|
|
|
46
46
|
this.logger.logEvent({ message: 'stop previous scan', isScanning: this.ble.isScanning() });
|
|
47
47
|
yield this.ble.stopScan();
|
|
48
48
|
}
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
|
|
49
|
+
const connected = yield this.connect();
|
|
50
|
+
if (!connected)
|
|
51
|
+
throw new Error(`could not start device, reason:could not connect`);
|
|
52
|
+
const comms = this.device;
|
|
53
|
+
if (comms) {
|
|
52
54
|
const mode = this.getCyclingMode();
|
|
53
55
|
if (mode && mode.getSetting('bikeType')) {
|
|
54
56
|
const bikeType = mode.getSetting('bikeType').toLowerCase();
|
|
55
|
-
|
|
57
|
+
comms.setCrr(fm_1.cRR);
|
|
56
58
|
switch (bikeType) {
|
|
57
59
|
case 'race':
|
|
58
|
-
|
|
60
|
+
comms.setCw(fm_1.cwABike.race);
|
|
59
61
|
break;
|
|
60
62
|
case 'triathlon':
|
|
61
|
-
|
|
63
|
+
comms.setCw(fm_1.cwABike.triathlon);
|
|
62
64
|
break;
|
|
63
65
|
case 'mountain':
|
|
64
|
-
|
|
66
|
+
comms.setCw(fm_1.cwABike.mountain);
|
|
65
67
|
break;
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
const { user, bikeWeight = adpater_1.DEFAULT_BIKE_WEIGHT } = props || {};
|
|
69
71
|
const weight = (user && user.weight ? Number(user.weight) : adpater_1.DEFAULT_USER_WEIGHT) + bikeWeight;
|
|
70
|
-
yield
|
|
72
|
+
yield comms.setSimMode(weight, comms.getCrr(), comms.getCw());
|
|
71
73
|
const startRequest = this.getCyclingMode().getBikeInitRequest();
|
|
72
74
|
yield this.sendUpdate(startRequest);
|
|
73
|
-
|
|
75
|
+
comms.on('data', (data) => {
|
|
74
76
|
this.onDeviceData(data);
|
|
75
77
|
});
|
|
76
|
-
if (
|
|
78
|
+
if (comms.features.heartrate && !this.hasCapability(capabilities_1.IncyclistCapability.HeartRate)) {
|
|
77
79
|
this.capabilities.push(capabilities_1.IncyclistCapability.HeartRate);
|
|
78
80
|
}
|
|
79
81
|
this.resetData();
|
package/lib/ble/wahoo/comms.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { LegacyProfile } from "../../antv2/types";
|
|
2
3
|
import { CrankData } from "../cp";
|
|
3
4
|
import { IndoorBikeData } from "../fm";
|
|
4
5
|
import BleFitnessMachineDevice from "../fm/comms";
|
|
5
|
-
import { BleWriteProps } from "../types";
|
|
6
|
+
import { BleProtocol, BleWriteProps, IBlePeripheralConnector } from "../types";
|
|
6
7
|
export declare const enum OpCode {
|
|
7
8
|
unlock = 32,
|
|
8
9
|
setResistanceMode = 64,
|
|
@@ -16,6 +17,7 @@ export declare const enum OpCode {
|
|
|
16
17
|
setWheelCircumference = 72
|
|
17
18
|
}
|
|
18
19
|
export default class BleWahooDevice extends BleFitnessMachineDevice {
|
|
20
|
+
static protocol: BleProtocol;
|
|
19
21
|
static services: string[];
|
|
20
22
|
static characteristics: string[];
|
|
21
23
|
static detectionPriority: number;
|
|
@@ -34,20 +36,19 @@ export default class BleWahooDevice extends BleFitnessMachineDevice {
|
|
|
34
36
|
cw: number;
|
|
35
37
|
};
|
|
36
38
|
constructor(props?: any);
|
|
37
|
-
isMatching(characteristics: string[]): boolean;
|
|
39
|
+
static isMatching(characteristics: string[]): boolean;
|
|
38
40
|
init(): Promise<boolean>;
|
|
39
41
|
setCharacteristicUUIDs(uuids: string[]): void;
|
|
40
|
-
getProfile():
|
|
42
|
+
getProfile(): LegacyProfile;
|
|
43
|
+
getProtocol(): BleProtocol;
|
|
41
44
|
getServiceUUids(): string[];
|
|
42
|
-
isBike(): boolean;
|
|
43
|
-
isPower(): boolean;
|
|
44
|
-
isHrm(): boolean;
|
|
45
45
|
parseCrankData(crankData: any): {
|
|
46
46
|
rpm: number;
|
|
47
47
|
time: any;
|
|
48
48
|
};
|
|
49
49
|
parsePower(_data: Buffer): IndoorBikeData;
|
|
50
50
|
onData(characteristic: string, data: Buffer): boolean;
|
|
51
|
+
subscribeAll(conn?: IBlePeripheralConnector): Promise<void>;
|
|
51
52
|
writeWahooFtmsMessage(requestedOpCode: number, data: Buffer, props?: BleWriteProps): Promise<boolean>;
|
|
52
53
|
requestControl(): Promise<boolean>;
|
|
53
54
|
setPowerAdjusting(): void;
|
package/lib/ble/wahoo/comms.js
CHANGED
|
@@ -12,6 +12,7 @@ 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 _1 = require(".");
|
|
15
16
|
const adpater_1 = require("../../base/adpater");
|
|
16
17
|
const consts_1 = require("../consts");
|
|
17
18
|
const comms_1 = __importDefault(require("../fm/comms"));
|
|
@@ -30,7 +31,7 @@ class BleWahooDevice extends comms_1.default {
|
|
|
30
31
|
this.data = {};
|
|
31
32
|
this.wahooCP = consts_1.WAHOO_ADVANCED_TRAINER_CP;
|
|
32
33
|
}
|
|
33
|
-
isMatching(characteristics) {
|
|
34
|
+
static isMatching(characteristics) {
|
|
34
35
|
if (!characteristics)
|
|
35
36
|
return false;
|
|
36
37
|
const hasWahooCP = characteristics.find(c => (0, utils_1.matches)(c, consts_1.WAHOO_ADVANCED_TRAINER_CP)) !== undefined;
|
|
@@ -50,8 +51,7 @@ class BleWahooDevice extends comms_1.default {
|
|
|
50
51
|
}
|
|
51
52
|
catch (err) {
|
|
52
53
|
}
|
|
53
|
-
yield _super.initDevice.call(this);
|
|
54
|
-
return true;
|
|
54
|
+
return yield _super.initDevice.call(this);
|
|
55
55
|
}
|
|
56
56
|
catch (err) {
|
|
57
57
|
this.logEvent({ message: 'error', fn: 'WahooAdvancedFitnessMachineDevice.init()', error: err.message || err, stack: err.stack });
|
|
@@ -67,20 +67,14 @@ class BleWahooDevice extends comms_1.default {
|
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
getProfile() {
|
|
70
|
-
return '
|
|
70
|
+
return 'Smart Trainer';
|
|
71
|
+
}
|
|
72
|
+
getProtocol() {
|
|
73
|
+
return _1.BleWahooComms.protocol;
|
|
71
74
|
}
|
|
72
75
|
getServiceUUids() {
|
|
73
76
|
return BleWahooDevice.services;
|
|
74
77
|
}
|
|
75
|
-
isBike() {
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
isPower() {
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
isHrm() {
|
|
82
|
-
return this.hasService('180d');
|
|
83
|
-
}
|
|
84
78
|
parseCrankData(crankData) {
|
|
85
79
|
if (!this.prevCrankData)
|
|
86
80
|
this.prevCrankData = { revolutions: 0, time: 0, cntUpdateMissing: -1 };
|
|
@@ -149,16 +143,16 @@ class BleWahooDevice extends comms_1.default {
|
|
|
149
143
|
const uuid = characteristic.toLowerCase();
|
|
150
144
|
let res = undefined;
|
|
151
145
|
switch (uuid) {
|
|
152
|
-
case
|
|
146
|
+
case consts_1.CSP_MEASUREMENT:
|
|
153
147
|
res = this.parsePower(data);
|
|
154
148
|
break;
|
|
155
|
-
case
|
|
149
|
+
case consts_1.INDOOR_BIKE_DATA:
|
|
156
150
|
res = this.parseIndoorBikeData(data);
|
|
157
151
|
break;
|
|
158
|
-
case
|
|
152
|
+
case consts_1.HR_MEASUREMENT:
|
|
159
153
|
res = this.parseHrm(data);
|
|
160
154
|
break;
|
|
161
|
-
case
|
|
155
|
+
case consts_1.FTMS_STATUS:
|
|
162
156
|
res = this.parseFitnessMachineStatus(data);
|
|
163
157
|
break;
|
|
164
158
|
default:
|
|
@@ -171,6 +165,9 @@ class BleWahooDevice extends comms_1.default {
|
|
|
171
165
|
}
|
|
172
166
|
return true;
|
|
173
167
|
}
|
|
168
|
+
subscribeAll(conn) {
|
|
169
|
+
return this.subscribeMultiple([consts_1.CSP_MEASUREMENT, consts_1.INDOOR_BIKE_DATA, consts_1.HR_MEASUREMENT, consts_1.FTMS_STATUS, this.wahooCP], conn);
|
|
170
|
+
}
|
|
174
171
|
writeWahooFtmsMessage(requestedOpCode, data, props) {
|
|
175
172
|
return __awaiter(this, void 0, void 0, function* () {
|
|
176
173
|
try {
|
|
@@ -395,6 +392,7 @@ class BleWahooDevice extends comms_1.default {
|
|
|
395
392
|
}
|
|
396
393
|
}
|
|
397
394
|
exports.default = BleWahooDevice;
|
|
395
|
+
BleWahooDevice.protocol = 'wahoo';
|
|
398
396
|
BleWahooDevice.services = [consts_1.CSP];
|
|
399
397
|
BleWahooDevice.characteristics = ['2acc', '2ad2', '2ad6', '2ad8', '2ad9', '2ada', consts_1.WAHOO_ADVANCED_TRAINER_CP];
|
|
400
398
|
BleWahooDevice.detectionPriority = 5;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { INTERFACE } from './types/device';
|
|
2
2
|
import InterfaceFactory from './interfaces';
|
|
3
3
|
import AdapterFactory from './adapters';
|
|
4
|
-
import { IncyclistInterface } from './types/interface';
|
|
5
|
-
import { IncyclistDeviceAdapter } from './types/adapter';
|
|
4
|
+
import { IncyclistInterface, InterfaceProps } from './types/interface';
|
|
5
|
+
import { IncyclistDeviceAdapter, Bike as Controllable } from './types/adapter';
|
|
6
|
+
import { ControllableDevice as ControllableDeviceAdapter } from './base/adpater';
|
|
6
7
|
import { IncyclistCapability } from './types/capabilities';
|
|
7
8
|
import { DeviceData } from './types/data';
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
9
|
+
import { DeviceSettings } from './types/device';
|
|
10
|
+
import CyclingMode from './modes/cycling-mode';
|
|
11
|
+
export * from './modes/cycling-mode';
|
|
12
|
+
export * from './serial';
|
|
13
|
+
export * from './ble';
|
|
14
|
+
export * from './antv2';
|
|
15
|
+
export { IncyclistInterface, INTERFACE, InterfaceFactory, InterfaceProps, DeviceSettings, CyclingMode, AdapterFactory, IncyclistDeviceAdapter, Controllable, ControllableDeviceAdapter, DeviceData, IncyclistCapability, };
|
package/lib/index.js
CHANGED
|
@@ -1,38 +1,34 @@
|
|
|
1
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
|
+
};
|
|
2
16
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
18
|
};
|
|
5
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
20
|
+
exports.IncyclistCapability = exports.ControllableDeviceAdapter = exports.AdapterFactory = exports.InterfaceFactory = exports.INTERFACE = void 0;
|
|
7
21
|
const device_1 = require("./types/device");
|
|
8
22
|
Object.defineProperty(exports, "INTERFACE", { enumerable: true, get: function () { return device_1.INTERFACE; } });
|
|
9
23
|
const interfaces_1 = __importDefault(require("./interfaces"));
|
|
10
24
|
exports.InterfaceFactory = interfaces_1.default;
|
|
11
25
|
const adapters_1 = __importDefault(require("./adapters"));
|
|
12
26
|
exports.AdapterFactory = adapters_1.default;
|
|
27
|
+
const adpater_1 = require("./base/adpater");
|
|
28
|
+
Object.defineProperty(exports, "ControllableDeviceAdapter", { enumerable: true, get: function () { return adpater_1.ControllableDevice; } });
|
|
13
29
|
const capabilities_1 = require("./types/capabilities");
|
|
14
30
|
Object.defineProperty(exports, "IncyclistCapability", { enumerable: true, get: function () { return capabilities_1.IncyclistCapability; } });
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Object.defineProperty(exports, "TCPBinding", { enumerable: true, get: function () { return serial_1.TCPBinding; } });
|
|
20
|
-
Object.defineProperty(exports, "DaumPremiumAdapter", { enumerable: true, get: function () { return serial_1.DaumPremiumAdapter; } });
|
|
21
|
-
Object.defineProperty(exports, "DaumClassicAdapter", { enumerable: true, get: function () { return serial_1.DaumClassicAdapter; } });
|
|
22
|
-
Object.defineProperty(exports, "KettlerRacerAdapter", { enumerable: true, get: function () { return serial_1.KettlerRacerAdapter; } });
|
|
23
|
-
const antv2_1 = require("./antv2");
|
|
24
|
-
Object.defineProperty(exports, "AntAdapterFactory", { enumerable: true, get: function () { return antv2_1.AntAdapterFactory; } });
|
|
25
|
-
Object.defineProperty(exports, "AntFEAdapter", { enumerable: true, get: function () { return antv2_1.AntFEAdapter; } });
|
|
26
|
-
Object.defineProperty(exports, "AntHrAdapter", { enumerable: true, get: function () { return antv2_1.AntHrAdapter; } });
|
|
27
|
-
Object.defineProperty(exports, "AntPwrAdapter", { enumerable: true, get: function () { return antv2_1.AntPwrAdapter; } });
|
|
28
|
-
Object.defineProperty(exports, "AntInterface", { enumerable: true, get: function () { return antv2_1.AntInterface; } });
|
|
29
|
-
const ble_1 = require("./ble");
|
|
30
|
-
Object.defineProperty(exports, "BleAdapterFactory", { enumerable: true, get: function () { return ble_1.BleAdapterFactory; } });
|
|
31
|
-
Object.defineProperty(exports, "BleInterface", { enumerable: true, get: function () { return ble_1.BleInterface; } });
|
|
32
|
-
Object.defineProperty(exports, "BleHrmAdapter", { enumerable: true, get: function () { return ble_1.BleHrmAdapter; } });
|
|
33
|
-
Object.defineProperty(exports, "BlePwrAdapter", { enumerable: true, get: function () { return ble_1.BlePwrAdapter; } });
|
|
34
|
-
Object.defineProperty(exports, "BleFmAdapter", { enumerable: true, get: function () { return ble_1.BleFmAdapter; } });
|
|
35
|
-
Object.defineProperty(exports, "BleWahooAdapter", { enumerable: true, get: function () { return ble_1.BleWahooAdapter; } });
|
|
36
|
-
Object.defineProperty(exports, "BleTacxAdapter", { enumerable: true, get: function () { return ble_1.BleTacxAdapter; } });
|
|
37
|
-
const cycling_mode_1 = require("./modes/cycling-mode");
|
|
38
|
-
Object.defineProperty(exports, "CyclingModeProperyType", { enumerable: true, get: function () { return cycling_mode_1.CyclingModeProperyType; } });
|
|
31
|
+
__exportStar(require("./modes/cycling-mode"), exports);
|
|
32
|
+
__exportStar(require("./serial"), exports);
|
|
33
|
+
__exportStar(require("./ble"), exports);
|
|
34
|
+
__exportStar(require("./antv2"), exports);
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { InterfaceProps } from "./types/interface";
|
|
2
2
|
import { SerialInterface } from "./serial";
|
|
3
3
|
import AntInterface from "./antv2/ant-interface";
|
|
4
|
+
import { BleInterface } from "./ble";
|
|
4
5
|
export default class InterfaceFactory {
|
|
5
|
-
static create(ifaceName: string, props?: InterfaceProps): AntInterface | SerialInterface;
|
|
6
|
+
static create(ifaceName: string, props?: InterfaceProps): AntInterface | BleInterface | SerialInterface;
|
|
6
7
|
}
|
package/lib/interfaces.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const serial_1 = require("./serial");
|
|
7
7
|
const ant_interface_1 = __importDefault(require("./antv2/ant-interface"));
|
|
8
8
|
const device_1 = require("./types/device");
|
|
9
|
+
const ble_1 = require("./ble");
|
|
9
10
|
class InterfaceFactory {
|
|
10
11
|
static create(ifaceName, props) {
|
|
11
12
|
switch (ifaceName) {
|
|
@@ -17,6 +18,9 @@ class InterfaceFactory {
|
|
|
17
18
|
case device_1.INTERFACE.ANT:
|
|
18
19
|
const antProps = props;
|
|
19
20
|
return ant_interface_1.default.getInstance(antProps);
|
|
21
|
+
case device_1.INTERFACE.BLE:
|
|
22
|
+
const bleProps = props;
|
|
23
|
+
return ble_1.BleInterface.getInstance(bleProps);
|
|
20
24
|
}
|
|
21
25
|
}
|
|
22
26
|
}
|
package/lib/modes/power-base.js
CHANGED
|
@@ -35,6 +35,10 @@ class PowerBasedCyclingModeBase extends cycling_mode_1.CyclingModeBase {
|
|
|
35
35
|
const vPrev = (prevData.speed || 0) / 3.6;
|
|
36
36
|
const EkinPrev = 1 / 2 * m * vPrev * vPrev;
|
|
37
37
|
let powerToMaintainSpeed = calculations_1.default.calculatePower(m, vPrev, slope, props);
|
|
38
|
+
if (t >= 30) {
|
|
39
|
+
const speed = calculations_1.default.calculateSpeed(m, power, slope, props);
|
|
40
|
+
return { speed, distance: 0 };
|
|
41
|
+
}
|
|
38
42
|
const powerDelta = powerToMaintainSpeed - power;
|
|
39
43
|
const Ekin = EkinPrev - powerDelta * t;
|
|
40
44
|
if (Ekin > 0) {
|
package/lib/serial/adapter.d.ts
CHANGED
|
@@ -8,9 +8,14 @@ export interface SerialDeviceSettings extends DeviceSettings {
|
|
|
8
8
|
interface: string | SerialInterface;
|
|
9
9
|
}
|
|
10
10
|
export declare class SerialIncyclistDevice extends ControllableDevice {
|
|
11
|
+
pullFrequency: number;
|
|
11
12
|
check(): Promise<boolean>;
|
|
12
13
|
constructor(settings: SerialDeviceSettings, props?: DeviceProperties);
|
|
13
14
|
isEqual(settings: SerialDeviceSettings): boolean;
|
|
14
15
|
getPort(): string;
|
|
16
|
+
getUniqueName(): string;
|
|
15
17
|
getInterface(): string;
|
|
18
|
+
setMaxUpdateFrequency(ms: number): void;
|
|
19
|
+
setPullFrequency(ms: number): void;
|
|
20
|
+
getPullFrequency(): number;
|
|
16
21
|
}
|
package/lib/serial/adapter.js
CHANGED
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.SerialIncyclistDevice = void 0;
|
|
13
13
|
const adpater_1 = require("../base/adpater");
|
|
14
|
+
const DEFAULT_PULL_FREQUENCY = 1000;
|
|
14
15
|
class SerialIncyclistDevice extends adpater_1.ControllableDevice {
|
|
15
16
|
check() {
|
|
16
17
|
return __awaiter(this, void 0, void 0, function* () { throw new Error('not implemnted'); });
|
|
@@ -18,6 +19,7 @@ class SerialIncyclistDevice extends adpater_1.ControllableDevice {
|
|
|
18
19
|
;
|
|
19
20
|
constructor(settings, props) {
|
|
20
21
|
super(settings, props);
|
|
22
|
+
this.pullFrequency = DEFAULT_PULL_FREQUENCY;
|
|
21
23
|
}
|
|
22
24
|
isEqual(settings) {
|
|
23
25
|
if (settings.interface !== this.getInterface())
|
|
@@ -35,8 +37,25 @@ class SerialIncyclistDevice extends adpater_1.ControllableDevice {
|
|
|
35
37
|
const settings = this.settings;
|
|
36
38
|
return settings.port;
|
|
37
39
|
}
|
|
40
|
+
getUniqueName() {
|
|
41
|
+
return `${this.getName()} (${this.getPort()})`;
|
|
42
|
+
}
|
|
38
43
|
getInterface() {
|
|
39
44
|
return 'serial';
|
|
40
45
|
}
|
|
46
|
+
setMaxUpdateFrequency(ms) {
|
|
47
|
+
if (ms <= this.pullFrequency)
|
|
48
|
+
this.updateFrequency = -1;
|
|
49
|
+
else
|
|
50
|
+
this.updateFrequency = ms;
|
|
51
|
+
}
|
|
52
|
+
setPullFrequency(ms) {
|
|
53
|
+
this.pullFrequency = ms;
|
|
54
|
+
if (this.updateFrequency <= this.pullFrequency)
|
|
55
|
+
this.updateFrequency = -1;
|
|
56
|
+
}
|
|
57
|
+
getPullFrequency() {
|
|
58
|
+
return this.pullFrequency;
|
|
59
|
+
}
|
|
41
60
|
}
|
|
42
61
|
exports.SerialIncyclistDevice = SerialIncyclistDevice;
|
|
@@ -21,12 +21,13 @@ export declare class TCPPortBinding implements BindingPortInterface {
|
|
|
21
21
|
openOptions: Required<OpenOptions>;
|
|
22
22
|
socket: any;
|
|
23
23
|
logger: EventLogger;
|
|
24
|
-
writeOperation: null | Promise<
|
|
24
|
+
writeOperation: null | Promise<any>;
|
|
25
25
|
data: Buffer;
|
|
26
26
|
private pendingRead;
|
|
27
27
|
constructor(socket: net.Socket, options: Required<OpenOptions>);
|
|
28
28
|
get isOpen(): boolean;
|
|
29
29
|
onData(data: Buffer): void;
|
|
30
|
+
onError(err: Error): void;
|
|
30
31
|
close(): Promise<void>;
|
|
31
32
|
read(buffer: Buffer, offset: number, length: number): Promise<{
|
|
32
33
|
buffer: Buffer;
|
|
@@ -146,6 +146,10 @@ class TCPPortBinding {
|
|
|
146
146
|
this.writeOperation = null;
|
|
147
147
|
this.data = null;
|
|
148
148
|
this.socket.on('data', this.onData.bind(this));
|
|
149
|
+
this.socket.on('error', this.onError.bind(this));
|
|
150
|
+
this.socket.on('close', () => { this.close(); });
|
|
151
|
+
this.socket.on('end', () => { this.close(); });
|
|
152
|
+
this.socket.on('timeout', () => { this.onError(new Error('socket timeout')); });
|
|
149
153
|
}
|
|
150
154
|
get isOpen() {
|
|
151
155
|
return this.socket !== null;
|
|
@@ -153,12 +157,19 @@ class TCPPortBinding {
|
|
|
153
157
|
onData(data) {
|
|
154
158
|
if (!this.data)
|
|
155
159
|
this.data = Buffer.alloc(0);
|
|
156
|
-
|
|
160
|
+
const buffer = Buffer.from(data);
|
|
161
|
+
this.data = Buffer.concat([this.data, buffer]);
|
|
157
162
|
if (this.pendingRead) {
|
|
158
163
|
process.nextTick(this.pendingRead);
|
|
159
164
|
this.pendingRead = null;
|
|
160
165
|
}
|
|
161
166
|
}
|
|
167
|
+
onError(err) {
|
|
168
|
+
if (this.pendingRead) {
|
|
169
|
+
this.pendingRead(err);
|
|
170
|
+
this.socket = null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
162
173
|
close() {
|
|
163
174
|
return __awaiter(this, void 0, void 0, function* () {
|
|
164
175
|
if (!this.isOpen)
|
|
@@ -169,10 +180,10 @@ class TCPPortBinding {
|
|
|
169
180
|
socket.destroy();
|
|
170
181
|
socket.on('error', () => { });
|
|
171
182
|
setTimeout(() => { socket.removeAllListeners(); }, 500);
|
|
183
|
+
this.socket = null;
|
|
172
184
|
if (this.pendingRead) {
|
|
173
185
|
this.pendingRead(new CanceledError('port is closed'));
|
|
174
186
|
}
|
|
175
|
-
this.socket = null;
|
|
176
187
|
});
|
|
177
188
|
}
|
|
178
189
|
read(buffer, offset, length) {
|
|
@@ -207,6 +218,7 @@ class TCPPortBinding {
|
|
|
207
218
|
const toCopy = this.data.slice(0, lengthToRead);
|
|
208
219
|
const bytesRead = toCopy.copy(buffer, offset);
|
|
209
220
|
this.data = this.data.slice(lengthToRead);
|
|
221
|
+
this.pendingRead = null;
|
|
210
222
|
return ({ buffer, bytesRead });
|
|
211
223
|
});
|
|
212
224
|
}
|
|
@@ -214,10 +226,12 @@ class TCPPortBinding {
|
|
|
214
226
|
if (!this.isOpen) {
|
|
215
227
|
throw new Error('Port is not open');
|
|
216
228
|
}
|
|
217
|
-
this.writeOperation = (() => __awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
this.writeOperation = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
218
230
|
yield resolveNextTick();
|
|
219
|
-
this.socket.write(buffer)
|
|
220
|
-
|
|
231
|
+
this.socket.write(buffer, () => {
|
|
232
|
+
resolve();
|
|
233
|
+
});
|
|
234
|
+
}));
|
|
221
235
|
return this.writeOperation;
|
|
222
236
|
}
|
|
223
237
|
update(options) {
|
|
@@ -43,8 +43,8 @@ export default class DaumAdapterBase extends SerialIncyclistDevice implements Da
|
|
|
43
43
|
close(): Promise<boolean>;
|
|
44
44
|
logEvent(event: any): void;
|
|
45
45
|
stop(): Promise<boolean>;
|
|
46
|
+
canSendUpdate(): boolean;
|
|
46
47
|
sendUpdate(request: any): Promise<unknown>;
|
|
47
|
-
sendData(): void;
|
|
48
48
|
update(): Promise<void>;
|
|
49
49
|
sendRequests(): Promise<void>;
|
|
50
50
|
bikeSync(): Promise<void>;
|
|
@@ -81,9 +81,10 @@ class DaumAdapterBase extends adapter_1.SerialIncyclistDevice {
|
|
|
81
81
|
isEqual(settings) {
|
|
82
82
|
const as = this.settings;
|
|
83
83
|
if (settings.interface !== this.getInterface())
|
|
84
|
-
return;
|
|
84
|
+
return false;
|
|
85
85
|
if (settings.protocol !== as.protocol || settings.port !== as.port)
|
|
86
86
|
return false;
|
|
87
|
+
return true;
|
|
87
88
|
}
|
|
88
89
|
isSame(device) {
|
|
89
90
|
if (!(device instanceof DaumAdapterBase))
|
|
@@ -133,11 +134,11 @@ class DaumAdapterBase extends adapter_1.SerialIncyclistDevice {
|
|
|
133
134
|
return;
|
|
134
135
|
const ivSync = setInterval(() => {
|
|
135
136
|
this.bikeSync();
|
|
136
|
-
},
|
|
137
|
+
}, this.pullFrequency);
|
|
137
138
|
const ivUpdate = setInterval(() => {
|
|
138
|
-
this.
|
|
139
|
+
this.emitData(this.deviceData);
|
|
139
140
|
this.refreshRequests();
|
|
140
|
-
},
|
|
141
|
+
}, this.pullFrequency);
|
|
141
142
|
this.iv = {
|
|
142
143
|
sync: ivSync,
|
|
143
144
|
update: ivUpdate
|
|
@@ -182,7 +183,8 @@ class DaumAdapterBase extends adapter_1.SerialIncyclistDevice {
|
|
|
182
183
|
clearInterval(this.iv.update);
|
|
183
184
|
this.iv = undefined;
|
|
184
185
|
}
|
|
185
|
-
this.bike.stopWorker
|
|
186
|
+
if (this.bike.stopWorker && typeof this.bike.stopWorker === 'function')
|
|
187
|
+
this.bike.stopWorker();
|
|
186
188
|
this.logEvent({ message: 'stop request completed' });
|
|
187
189
|
this.paused = undefined;
|
|
188
190
|
resolve(true);
|
|
@@ -193,6 +195,11 @@ class DaumAdapterBase extends adapter_1.SerialIncyclistDevice {
|
|
|
193
195
|
}
|
|
194
196
|
});
|
|
195
197
|
}
|
|
198
|
+
canSendUpdate() {
|
|
199
|
+
if (this.paused || this.stopped)
|
|
200
|
+
return false;
|
|
201
|
+
return super.canSendUpdate();
|
|
202
|
+
}
|
|
196
203
|
sendUpdate(request) {
|
|
197
204
|
return __awaiter(this, void 0, void 0, function* () {
|
|
198
205
|
if (this.paused || this.stopped)
|
|
@@ -201,10 +208,6 @@ class DaumAdapterBase extends adapter_1.SerialIncyclistDevice {
|
|
|
201
208
|
return yield this.processClientRequest(request);
|
|
202
209
|
});
|
|
203
210
|
}
|
|
204
|
-
sendData() {
|
|
205
|
-
if (this.onDataFn)
|
|
206
|
-
this.onDataFn(this.deviceData);
|
|
207
|
-
}
|
|
208
211
|
update() {
|
|
209
212
|
return __awaiter(this, void 0, void 0, function* () {
|
|
210
213
|
if (this.stopped)
|
|
@@ -212,9 +215,11 @@ class DaumAdapterBase extends adapter_1.SerialIncyclistDevice {
|
|
|
212
215
|
this.updateBusy = true;
|
|
213
216
|
this.getCurrentBikeData()
|
|
214
217
|
.then(bikeData => {
|
|
218
|
+
console.log('~~~ bike data', bikeData);
|
|
215
219
|
this.updateData(this.cyclingData, bikeData);
|
|
216
|
-
this.transformData();
|
|
220
|
+
const data = this.transformData();
|
|
217
221
|
this.updateBusy = false;
|
|
222
|
+
this.emitData(data);
|
|
218
223
|
})
|
|
219
224
|
.catch(err => {
|
|
220
225
|
this.logEvent({ message: 'bike update error', error: err.message, stack: err.stack });
|
|
@@ -310,6 +315,7 @@ class DaumAdapterBase extends adapter_1.SerialIncyclistDevice {
|
|
|
310
315
|
data = { heartrate: data.heartrate };
|
|
311
316
|
}
|
|
312
317
|
this.deviceData = data;
|
|
318
|
+
return data;
|
|
313
319
|
}
|
|
314
320
|
sendRequest(request) {
|
|
315
321
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -9,6 +9,7 @@ export default class DaumPremiumAdapter extends DaumAdapter {
|
|
|
9
9
|
_startRetryTimeout: number;
|
|
10
10
|
constructor(settings: SerialDeviceSettings, props?: DeviceProperties);
|
|
11
11
|
getName(): string;
|
|
12
|
+
getUniqueName(): string;
|
|
12
13
|
getPort(): any;
|
|
13
14
|
getInterface(): string;
|
|
14
15
|
getProtocolName(): string;
|
|
@@ -63,6 +63,14 @@ class DaumPremiumAdapter extends DaumAdapter_1.default {
|
|
|
63
63
|
getName() {
|
|
64
64
|
return 'Daum8i';
|
|
65
65
|
}
|
|
66
|
+
getUniqueName() {
|
|
67
|
+
if (this.getInterface() === 'tcpip') {
|
|
68
|
+
const port = this.getPort();
|
|
69
|
+
const [host] = port.split(':');
|
|
70
|
+
return `${this.getName()} (${host})`;
|
|
71
|
+
}
|
|
72
|
+
return super.getUniqueName();
|
|
73
|
+
}
|
|
66
74
|
getPort() {
|
|
67
75
|
return this.bike.getPort();
|
|
68
76
|
}
|
|
@@ -93,8 +101,6 @@ class DaumPremiumAdapter extends DaumAdapter_1.default {
|
|
|
93
101
|
check() {
|
|
94
102
|
return __awaiter(this, void 0, void 0, function* () {
|
|
95
103
|
var info = {};
|
|
96
|
-
if (this.isStopped())
|
|
97
|
-
return false;
|
|
98
104
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
99
105
|
this.logger.logEvent({ message: "checking device", port: this.getPort() });
|
|
100
106
|
try {
|
|
@@ -179,6 +185,7 @@ class DaumPremiumAdapter extends DaumAdapter_1.default {
|
|
|
179
185
|
if (!info.version) {
|
|
180
186
|
info.version = yield this.bike.getProtocolVersion();
|
|
181
187
|
}
|
|
188
|
+
console.log('~~~~ starting Daum8i', this.getCyclingMode().getName(), this.getCyclingMode().getModeProperty('eppSupport'));
|
|
182
189
|
if (this.getCyclingMode().getModeProperty('eppSupport')) {
|
|
183
190
|
const bikeType = this.getCyclingMode().getSetting('bikeType');
|
|
184
191
|
if (!info.upload) {
|
|
@@ -41,7 +41,7 @@ class Daum8i {
|
|
|
41
41
|
const { logger, serial, path } = props;
|
|
42
42
|
this.serial = serial;
|
|
43
43
|
this.path = validatePath(path);
|
|
44
|
-
this.logger = logger || process.env.DEBUG ? DEBUG_LOGGER : new gd_eventlog_1.EventLogger('DaumPremium');
|
|
44
|
+
this.logger = logger || (process.env.DEBUG ? DEBUG_LOGGER : new gd_eventlog_1.EventLogger('DaumPremium'));
|
|
45
45
|
this.isLoggingPaused = false;
|
|
46
46
|
this.connected = false;
|
|
47
47
|
this.blocked = false;
|
|
@@ -147,7 +147,11 @@ class Daum8i {
|
|
|
147
147
|
}
|
|
148
148
|
onPortClose() {
|
|
149
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
|
|
150
|
+
this.connected = false;
|
|
151
|
+
if (this.sp) {
|
|
152
|
+
this.sp.removeAllListeners();
|
|
153
|
+
this.sp = null;
|
|
154
|
+
}
|
|
151
155
|
});
|
|
152
156
|
}
|
|
153
157
|
onPortError(error) {
|
|
@@ -425,7 +429,10 @@ class Daum8i {
|
|
|
425
429
|
done();
|
|
426
430
|
});
|
|
427
431
|
}
|
|
428
|
-
catch (err) {
|
|
432
|
+
catch (err) {
|
|
433
|
+
this.state.writeBusy = false;
|
|
434
|
+
done();
|
|
435
|
+
}
|
|
429
436
|
});
|
|
430
437
|
});
|
|
431
438
|
}
|
|
@@ -279,7 +279,6 @@ class Daum8iMockBinding extends binding_mock_1.MockPortBinding {
|
|
|
279
279
|
}
|
|
280
280
|
onPersonSet(payload) {
|
|
281
281
|
this.simulator.person = (0, utils_2.parsePersonData)(payload);
|
|
282
|
-
console.log('~~~ person', this.simulator.person);
|
|
283
282
|
this.emitData(this.createResponse('M70', Buffer.from('07000000', 'hex')));
|
|
284
283
|
}
|
|
285
284
|
onPersonGet() {
|
package/lib/serial/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import SerialPortProvider, { useSerialPortProvider } from './serialport';
|
|
2
|
-
import SerialInterface from './serial-interface';
|
|
2
|
+
import SerialInterface, { SerialInterfaceProps } from './serial-interface';
|
|
3
3
|
import SerialAdapterFactory from './adapter-factory';
|
|
4
|
-
export { TCPBinding } from './bindings/tcp';
|
|
5
4
|
import { SerialIncyclistDevice, SerialDeviceSettings } from './adapter';
|
|
6
5
|
import DaumClassicAdapter from './daum/classic/adapter';
|
|
7
6
|
import DaumPremiumAdapter from './daum/premium/adapter';
|
|
8
7
|
import KettlerRacerAdapter from './kettler/ergo-racer/adapter';
|
|
9
|
-
export {
|
|
8
|
+
export { TCPBinding } from './bindings/tcp';
|
|
9
|
+
export { SerialPortProvider, useSerialPortProvider, SerialInterface, SerialInterfaceProps, SerialDeviceSettings, SerialAdapterFactory, DaumClassicAdapter, DaumPremiumAdapter, KettlerRacerAdapter, SerialIncyclistDevice };
|