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/index.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { INTERFACE } from './types/device';
|
|
1
|
+
import { INTERFACE, DeviceSettings, DeviceProperties } from './types/device';
|
|
2
2
|
import { IncyclistInterface, InterfaceProps } from './types/interface';
|
|
3
3
|
import { IncyclistCapability } from './types/capabilities';
|
|
4
4
|
import { IncyclistAdapterData } from './types/data';
|
|
5
|
-
import { DeviceSettings, DeviceProperties } from './types/device';
|
|
6
5
|
import ICyclingMode from './modes/types';
|
|
7
6
|
import calc from './utils/calculations';
|
|
8
7
|
import IncyclistDevice, { IncyclistDeviceAdapter } from './base/adpater';
|
|
9
8
|
import { IAdapter } from './types/adapter';
|
|
10
|
-
|
|
9
|
+
import AdapterFactory from './factories/adapters';
|
|
10
|
+
import InterfaceFactory from './factories/interfaces';
|
|
11
11
|
export * from './modes/types';
|
|
12
12
|
export * from './serial';
|
|
13
13
|
export * from './ble';
|
|
14
14
|
export * from './antv2';
|
|
15
|
-
export
|
|
15
|
+
export * from './direct-connect';
|
|
16
|
+
export { IAdapter, IncyclistDevice, IncyclistDeviceAdapter, DeviceSettings, DeviceProperties, AdapterFactory, InterfaceFactory, IncyclistInterface, INTERFACE, InterfaceProps, ICyclingMode, IncyclistAdapterData as DeviceData, IncyclistCapability, calc, };
|
package/lib/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.calc = exports.IncyclistCapability = exports.INTERFACE = exports.IncyclistDevice = void 0;
|
|
20
|
+
exports.calc = exports.IncyclistCapability = exports.INTERFACE = exports.InterfaceFactory = exports.AdapterFactory = exports.IncyclistDevice = void 0;
|
|
21
21
|
const device_1 = require("./types/device");
|
|
22
22
|
Object.defineProperty(exports, "INTERFACE", { enumerable: true, get: function () { return device_1.INTERFACE; } });
|
|
23
23
|
const capabilities_1 = require("./types/capabilities");
|
|
@@ -26,8 +26,12 @@ const calculations_1 = __importDefault(require("./utils/calculations"));
|
|
|
26
26
|
exports.calc = calculations_1.default;
|
|
27
27
|
const adpater_1 = __importDefault(require("./base/adpater"));
|
|
28
28
|
exports.IncyclistDevice = adpater_1.default;
|
|
29
|
-
|
|
29
|
+
const adapters_1 = __importDefault(require("./factories/adapters"));
|
|
30
|
+
exports.AdapterFactory = adapters_1.default;
|
|
31
|
+
const interfaces_1 = __importDefault(require("./factories/interfaces"));
|
|
32
|
+
exports.InterfaceFactory = interfaces_1.default;
|
|
30
33
|
__exportStar(require("./modes/types"), exports);
|
|
31
34
|
__exportStar(require("./serial"), exports);
|
|
32
35
|
__exportStar(require("./ble"), exports);
|
|
33
36
|
__exportStar(require("./antv2"), exports);
|
|
37
|
+
__exportStar(require("./direct-connect"), exports);
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import ICyclingMode, { CyclingModeProperyType,
|
|
1
|
+
import ICyclingMode, { CyclingModeProperyType, UpdateRequest } from "./types";
|
|
2
2
|
import PowerBasedCyclingModeBase from "./power-base";
|
|
3
3
|
import { IAdapter } from "../types";
|
|
4
|
-
export
|
|
5
|
-
chainConfig: number[];
|
|
6
|
-
cassetteConfig: number[];
|
|
7
|
-
wheelCirc: number;
|
|
8
|
-
numGears: number;
|
|
9
|
-
};
|
|
10
|
-
export default class SmartTrainerCyclingMode extends PowerBasedCyclingModeBase implements ICyclingMode, IVirtualShifting {
|
|
4
|
+
export default class SmartTrainerCyclingMode extends PowerBasedCyclingModeBase implements ICyclingMode {
|
|
11
5
|
protected static config: {
|
|
12
6
|
name: string;
|
|
13
7
|
isSIM: boolean;
|
|
@@ -32,18 +26,10 @@ export default class SmartTrainerCyclingMode extends PowerBasedCyclingModeBase i
|
|
|
32
26
|
options?: undefined;
|
|
33
27
|
})[];
|
|
34
28
|
};
|
|
35
|
-
protected gear: any;
|
|
36
29
|
constructor(adapter: IAdapter, props?: any);
|
|
37
30
|
getBikeInitRequest(): UpdateRequest;
|
|
38
31
|
checkForResetOrEmpty(request: UpdateRequest): UpdateRequest | undefined;
|
|
39
32
|
protected checkSlope(request: UpdateRequest, newRequest?: UpdateRequest): void;
|
|
40
33
|
protected checkEmptyRequest(newRequest: UpdateRequest): void;
|
|
41
34
|
sendBikeUpdate(incoming: UpdateRequest): UpdateRequest;
|
|
42
|
-
initGears(): Promise<number>;
|
|
43
|
-
gearUp(numGears: number): Promise<number>;
|
|
44
|
-
protected switchGear: (gear: any, prevGear: any) => number;
|
|
45
|
-
protected findBestGear(): any;
|
|
46
|
-
getCurrentGearConfig(): GearConfigEntry;
|
|
47
|
-
protected getDefaultCadence(): number;
|
|
48
|
-
protected getDefaultPower(): number;
|
|
49
35
|
}
|
|
@@ -1,45 +1,13 @@
|
|
|
1
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
6
|
const types_1 = require("./types");
|
|
16
7
|
const power_base_1 = __importDefault(require("./power-base"));
|
|
17
|
-
const calculations_1 = __importDefault(require("../utils/calculations"));
|
|
18
|
-
const NUM_GEARS = 30;
|
|
19
|
-
const GearConfig = {
|
|
20
|
-
race: { chainConfig: [34, 50], cassetteConfig: [11, 36], wheelCirc: 2125, numGears: NUM_GEARS },
|
|
21
|
-
mountain: { chainConfig: [26, 36], cassetteConfig: [10, 44], wheelCirc: 2344, numGears: NUM_GEARS },
|
|
22
|
-
triathlon: { chainConfig: [36, 52], cassetteConfig: [11, 30], wheelCirc: 2125, numGears: NUM_GEARS },
|
|
23
|
-
};
|
|
24
8
|
class SmartTrainerCyclingMode extends power_base_1.default {
|
|
25
9
|
constructor(adapter, props) {
|
|
26
10
|
super(adapter, props);
|
|
27
|
-
this.switchGear = (gear, prevGear) => {
|
|
28
|
-
var _a;
|
|
29
|
-
const { chainConfig, cassetteConfig, wheelCirc, numGears } = this.getCurrentGearConfig();
|
|
30
|
-
const { pedalRpm, speed, power, slope } = (_a = this.getData()) !== null && _a !== void 0 ? _a : {};
|
|
31
|
-
const m = this.getWeight();
|
|
32
|
-
let cadence = pedalRpm !== null && pedalRpm !== void 0 ? pedalRpm : this.getDefaultCadence();
|
|
33
|
-
let currentPower = power !== null && power !== void 0 ? power : this.getDefaultPower();
|
|
34
|
-
const prevGearSpeed = calculations_1.default.calculateSpeedBike(prevGear, cadence, chainConfig, cassetteConfig, { numGears, wheelCirc });
|
|
35
|
-
const targetGearSpeed = calculations_1.default.calculateSpeedBike(gear, cadence, chainConfig, cassetteConfig, { numGears, wheelCirc });
|
|
36
|
-
const targetGearPower = calculations_1.default.calculatePower(m, targetGearSpeed / 3.6, 0);
|
|
37
|
-
const prevGearPower = calculations_1.default.calculatePower(m, prevGearSpeed / 3.6, 0);
|
|
38
|
-
const targetPower = currentPower + (targetGearPower - prevGearPower);
|
|
39
|
-
const slopeTarget = calculations_1.default.calculateSlope(m, targetPower, speed / 3.6);
|
|
40
|
-
console.log('Gear', gear, 'power', targetPower, 'speed', speed.toFixed(1), 'slope', slope.toFixed(1), 'virtual slope', slopeTarget.toFixed(1));
|
|
41
|
-
return slopeTarget;
|
|
42
|
-
};
|
|
43
11
|
this.initLogger('SmartTrainerMode');
|
|
44
12
|
}
|
|
45
13
|
getBikeInitRequest() {
|
|
@@ -60,16 +28,11 @@ class SmartTrainerCyclingMode extends power_base_1.default {
|
|
|
60
28
|
newRequest.slope = parseFloat(request.slope.toFixed(1));
|
|
61
29
|
this.data.slope = newRequest.slope;
|
|
62
30
|
try {
|
|
63
|
-
if (this.gear !== undefined) {
|
|
64
|
-
const slopeTarget = this.switchGear(this.gear, this.gear);
|
|
65
|
-
newRequest.slope = slopeTarget;
|
|
66
|
-
}
|
|
67
31
|
const slopeAdj = this.getSetting('slopeAdj');
|
|
68
32
|
if (slopeAdj !== undefined)
|
|
69
33
|
newRequest.slope = newRequest.slope * slopeAdj / 100;
|
|
70
34
|
}
|
|
71
|
-
catch (
|
|
72
|
-
this.logger.logEvent({ message: "error", fn: '', error: err.message, request, prev: this.prevRequest, data: this.getData() });
|
|
35
|
+
catch (_a) {
|
|
73
36
|
}
|
|
74
37
|
}
|
|
75
38
|
}
|
|
@@ -98,66 +61,6 @@ class SmartTrainerCyclingMode extends power_base_1.default {
|
|
|
98
61
|
}
|
|
99
62
|
return newRequest;
|
|
100
63
|
}
|
|
101
|
-
initGears() {
|
|
102
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
this.gear = this.findBestGear();
|
|
104
|
-
return this.gear;
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
gearUp(numGears) {
|
|
108
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
-
let target = this.gear + numGears;
|
|
110
|
-
if (target > NUM_GEARS)
|
|
111
|
-
target = NUM_GEARS;
|
|
112
|
-
if (target < 1)
|
|
113
|
-
target = 1;
|
|
114
|
-
this.gear = target;
|
|
115
|
-
return this.gear;
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
findBestGear() {
|
|
119
|
-
var _a;
|
|
120
|
-
const { chainConfig, cassetteConfig, wheelCirc, numGears } = this.getCurrentGearConfig();
|
|
121
|
-
const { pedalRpm, speed, power, slope } = (_a = this.getData()) !== null && _a !== void 0 ? _a : {};
|
|
122
|
-
const m = this.getWeight();
|
|
123
|
-
let cadence = pedalRpm !== null && pedalRpm !== void 0 ? pedalRpm : this.getDefaultCadence();
|
|
124
|
-
let currentPower = power !== null && power !== void 0 ? power : this.getDefaultPower();
|
|
125
|
-
let minDiff, gearInitial;
|
|
126
|
-
if (speed === 0) {
|
|
127
|
-
const speedInitial = calculations_1.default.calculateSpeed(m, currentPower, slope);
|
|
128
|
-
for (let i = 1; i <= numGears; i++) {
|
|
129
|
-
const speed = calculations_1.default.calculateSpeedBike(i, cadence, chainConfig, cassetteConfig, { numGears, wheelCirc });
|
|
130
|
-
const diff = Math.abs(speed - speedInitial);
|
|
131
|
-
if (!minDiff || diff < minDiff) {
|
|
132
|
-
minDiff = diff;
|
|
133
|
-
gearInitial = i;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
for (let i = 1; i <= numGears; i++) {
|
|
139
|
-
const speed = calculations_1.default.calculateSpeedBike(i, cadence, chainConfig, cassetteConfig, { numGears, wheelCirc });
|
|
140
|
-
const targetPower = calculations_1.default.calculatePower(m, speed / 3.6, slope);
|
|
141
|
-
const diff = Math.abs(currentPower - targetPower);
|
|
142
|
-
if (!minDiff || diff < minDiff) {
|
|
143
|
-
minDiff = diff;
|
|
144
|
-
gearInitial = i;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return gearInitial;
|
|
149
|
-
}
|
|
150
|
-
getCurrentGearConfig() {
|
|
151
|
-
var _a;
|
|
152
|
-
const type = (_a = this.getSetting('bikeType')) !== null && _a !== void 0 ? _a : 'Race';
|
|
153
|
-
return GearConfig[type.toLowerCase()];
|
|
154
|
-
}
|
|
155
|
-
getDefaultCadence() {
|
|
156
|
-
return 90;
|
|
157
|
-
}
|
|
158
|
-
getDefaultPower() {
|
|
159
|
-
return 120;
|
|
160
|
-
}
|
|
161
64
|
}
|
|
162
65
|
SmartTrainerCyclingMode.config = {
|
|
163
66
|
name: "Smart Trainer",
|
package/lib/modes/types.d.ts
CHANGED
|
@@ -47,10 +47,6 @@ export default interface ICyclingMode {
|
|
|
47
47
|
setModeProperty(name: string, value: any): void;
|
|
48
48
|
getModeProperty(name: string): any;
|
|
49
49
|
}
|
|
50
|
-
export interface IVirtualShifting {
|
|
51
|
-
initGears(): Promise<number>;
|
|
52
|
-
gearUp(numGears: number): Promise<number>;
|
|
53
|
-
}
|
|
54
50
|
export type CyclingModeConfig = {
|
|
55
51
|
isERG?: boolean;
|
|
56
52
|
isSIM?: boolean;
|
|
@@ -73,7 +69,7 @@ export declare class CyclingMode implements ICyclingMode {
|
|
|
73
69
|
getSetting(_name: string): void;
|
|
74
70
|
getSettings(): Settings;
|
|
75
71
|
setModeProperty(_name: string, _value: any): void;
|
|
76
|
-
getModeProperty(_name: string):
|
|
72
|
+
getModeProperty(_name: string): void;
|
|
77
73
|
getConfig(): CyclingModeConfig;
|
|
78
74
|
isERG(): boolean;
|
|
79
75
|
isSIM(): boolean;
|
|
@@ -6,6 +6,7 @@ export interface TCPOpenOptions extends OpenOptions {
|
|
|
6
6
|
}
|
|
7
7
|
export declare interface TCPBindingInterface<T extends BindingPortInterface = BindingPortInterface, R extends OpenOptions = OpenOptions, P extends PortInfo = PortInfo> extends BindingInterface<TCPPortBinding, TCPOpenOptions> {
|
|
8
8
|
list(port?: number, excludeList?: string[]): Promise<P[]>;
|
|
9
|
+
open(options: TCPOpenOptions): Promise<TCPPortBinding>;
|
|
9
10
|
}
|
|
10
11
|
export declare class CanceledError extends Error {
|
|
11
12
|
canceled: true;
|
|
@@ -22,10 +23,10 @@ export declare class TCPPortBinding implements BindingPortInterface {
|
|
|
22
23
|
writeOperation: null | Promise<any>;
|
|
23
24
|
data: Buffer;
|
|
24
25
|
private pendingRead;
|
|
25
|
-
private onDataHandler;
|
|
26
|
-
private onErrorHandler;
|
|
27
|
-
private onTimeoutHandler;
|
|
28
|
-
private onCloseHandler;
|
|
26
|
+
private readonly onDataHandler;
|
|
27
|
+
private readonly onErrorHandler;
|
|
28
|
+
private readonly onTimeoutHandler;
|
|
29
|
+
private readonly onCloseHandler;
|
|
29
30
|
constructor(socket: net.Socket, options: Required<OpenOptions>);
|
|
30
31
|
get isOpen(): boolean;
|
|
31
32
|
onData(data: Buffer): void;
|
|
@@ -55,23 +55,13 @@ function scanPort(host, port) {
|
|
|
55
55
|
function scanSubNet(sn, port, excludeHosts) {
|
|
56
56
|
const range = [];
|
|
57
57
|
for (let i = 1; i < 255; i++)
|
|
58
|
-
if (!excludeHosts ||
|
|
58
|
+
if (!(excludeHosts === null || excludeHosts === void 0 ? void 0 : excludeHosts.includes(`${sn}.${i}`)))
|
|
59
59
|
range.push(i);
|
|
60
60
|
return Promise.all(range.map(j => scanPort(`${sn}.${j}`, port).then(success => success ? `${sn}.${j}` : null).catch()))
|
|
61
61
|
.then(hosts => hosts.filter(h => h !== null))
|
|
62
62
|
.catch();
|
|
63
63
|
}
|
|
64
64
|
function getSubnets() {
|
|
65
|
-
const nets = (0, os_1.networkInterfaces)();
|
|
66
|
-
const results = [];
|
|
67
|
-
const names = Object.keys(nets);
|
|
68
|
-
names.forEach(name => {
|
|
69
|
-
for (const net of nets[name]) {
|
|
70
|
-
if (net.family === 'IPv4' && !net.internal) {
|
|
71
|
-
results.push(net.address);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
65
|
const address = Object.keys((0, os_1.networkInterfaces)())
|
|
76
66
|
.reduce((a, key) => [
|
|
77
67
|
...a,
|
|
@@ -93,7 +83,7 @@ exports.TCPBinding = {
|
|
|
93
83
|
return [];
|
|
94
84
|
const subnets = getSubnets();
|
|
95
85
|
let hosts = [];
|
|
96
|
-
const excludeHosts = excludeList.map(e => e
|
|
86
|
+
const excludeHosts = excludeList.map(e => (e === null || e === void 0 ? void 0 : e.includes(':')) ? e.split(':')[0] : e);
|
|
97
87
|
yield Promise.all(subnets.map(sn => scanSubNet(sn, port, excludeHosts).then(found => { hosts.push(...found); })));
|
|
98
88
|
return hosts.map(host => ({
|
|
99
89
|
path: `${host}:${port}`,
|
|
@@ -253,17 +243,20 @@ class TCPPortBinding {
|
|
|
253
243
|
if (!this.isOpen) {
|
|
254
244
|
throw new Error('Port is not open');
|
|
255
245
|
}
|
|
256
|
-
this.writeOperation = new Promise((resolve
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
246
|
+
this.writeOperation = new Promise((resolve) => {
|
|
247
|
+
const run = () => __awaiter(this, void 0, void 0, function* () {
|
|
248
|
+
yield resolveNextTick();
|
|
249
|
+
try {
|
|
250
|
+
this.socket.write(buffer, () => {
|
|
251
|
+
resolve();
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
catch (err) {
|
|
255
|
+
this.onError(err);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
run();
|
|
259
|
+
});
|
|
267
260
|
return this.writeOperation;
|
|
268
261
|
}
|
|
269
262
|
update(options) {
|
package/lib/types/device.d.ts
CHANGED
package/lib/types/device.js
CHANGED
|
@@ -3,7 +3,6 @@ export declare class IllegalArgumentException extends Error {
|
|
|
3
3
|
}
|
|
4
4
|
export default class C {
|
|
5
5
|
static calculateSpeed(m: number, power: number, slope: number, props?: any): number;
|
|
6
|
-
static calculateSlope(m: number, P: number, v: number, props?: any): number;
|
|
7
6
|
static calculatePower(m: number, v: number, slope: number, props?: any): number;
|
|
8
7
|
static calculateSpeedDaum(gear: number, rpm: number, bikeType?: string | number): number;
|
|
9
8
|
static calculateSpeedBike(gear: number, rpm: number, chain: number[], cassette: number[], props?: {
|
|
@@ -19,14 +19,13 @@ class IllegalArgumentException extends Error {
|
|
|
19
19
|
exports.IllegalArgumentException = IllegalArgumentException;
|
|
20
20
|
class C {
|
|
21
21
|
static calculateSpeed(m, power, slope, props = {}) {
|
|
22
|
-
var _a, _b, _c, _d;
|
|
23
22
|
if (m === undefined || m === null || m < 0)
|
|
24
23
|
throw new IllegalArgumentException("m must be a positive number");
|
|
25
24
|
if (power === undefined || power === null || power < 0)
|
|
26
25
|
throw new IllegalArgumentException("power must be a positive number");
|
|
27
|
-
const _rho =
|
|
28
|
-
const _cRR =
|
|
29
|
-
const _cwA =
|
|
26
|
+
const _rho = props.rho || rho;
|
|
27
|
+
const _cRR = props.cRR || cRR;
|
|
28
|
+
const _cwA = props.cwA || cwABike[props.bikeType || 'race'] || cwABike.race;
|
|
30
29
|
let sl = Math.atan(slope / 100);
|
|
31
30
|
let c1 = 0.5 * _rho * _cwA;
|
|
32
31
|
let c2 = (sl + _cRR) * m * g;
|
|
@@ -59,29 +58,14 @@ class C {
|
|
|
59
58
|
}
|
|
60
59
|
return 0;
|
|
61
60
|
}
|
|
62
|
-
static calculateSlope(m, P, v, props = {}) {
|
|
63
|
-
var _a, _b, _c;
|
|
64
|
-
if (m === undefined || m === null || m < 0)
|
|
65
|
-
throw new IllegalArgumentException("m must be a positive number");
|
|
66
|
-
if (P === undefined || P === null || P < 0)
|
|
67
|
-
throw new IllegalArgumentException("power must be a positive number");
|
|
68
|
-
if (v === undefined || v === null || v === 0)
|
|
69
|
-
throw new IllegalArgumentException("v must be a positive number");
|
|
70
|
-
const _rho = (_a = props.rho) !== null && _a !== void 0 ? _a : rho;
|
|
71
|
-
const _cRR = (_b = props.cRR) !== null && _b !== void 0 ? _b : cRR;
|
|
72
|
-
const _cwA = (_c = props.cwA) !== null && _c !== void 0 ? _c : (cwABike[props.bikeType || 'race'] || cwABike.race);
|
|
73
|
-
const sl = (P - (0.5 * _rho * _cwA) * Math.pow(v, 3.0)) / (m * g * v) - _cRR;
|
|
74
|
-
return Math.tan(Math.asin(sl)) * 100;
|
|
75
|
-
}
|
|
76
61
|
static calculatePower(m, v, slope, props = {}) {
|
|
77
|
-
var _a, _b, _c;
|
|
78
62
|
if (m === undefined || m === null || m < 0)
|
|
79
63
|
throw new IllegalArgumentException("m must be a positive number");
|
|
80
64
|
if (v === undefined || v === null || v < 0)
|
|
81
65
|
throw new IllegalArgumentException("v must be a positive number");
|
|
82
|
-
let _rho =
|
|
83
|
-
let _cRR =
|
|
84
|
-
let _cwA =
|
|
66
|
+
let _rho = props.rho || rho;
|
|
67
|
+
let _cRR = props.cRR || cRR;
|
|
68
|
+
let _cwA = props.cwA || cwABike[props.bikeType || 'race'];
|
|
85
69
|
let sl = Math.sin(Math.atan(slope / 100));
|
|
86
70
|
let P = (0.5 * _rho * _cwA) * Math.pow(v, 3.0) + (sl + _cRR) * m * g * v;
|
|
87
71
|
return P;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface TaskState {
|
|
2
|
+
isRunning: boolean;
|
|
3
|
+
timeout?: NodeJS.Timeout;
|
|
4
|
+
onTimeout: () => void;
|
|
5
|
+
promise: Promise<any>;
|
|
6
|
+
}
|
|
7
|
+
export interface TaskProps {
|
|
8
|
+
timeout?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class Task<T extends TaskState> {
|
|
11
|
+
protected _state: T;
|
|
12
|
+
constructor(_state: T, props: TaskProps);
|
|
13
|
+
get state(): T;
|
|
14
|
+
get promise(): Promise<any>;
|
|
15
|
+
start(promise: Promise<any>): void;
|
|
16
|
+
isRunning(): boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Task = void 0;
|
|
4
|
+
class Task {
|
|
5
|
+
constructor(_state, props) {
|
|
6
|
+
this._state = _state;
|
|
7
|
+
}
|
|
8
|
+
get state() {
|
|
9
|
+
return this._state;
|
|
10
|
+
}
|
|
11
|
+
get promise() {
|
|
12
|
+
return this._state.promise;
|
|
13
|
+
}
|
|
14
|
+
start(promise) {
|
|
15
|
+
}
|
|
16
|
+
isRunning() {
|
|
17
|
+
return this._state.isRunning;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.Task = Task;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import EventEmitter from "events";
|
|
2
|
+
export interface TaskState {
|
|
3
|
+
result?: 'completed' | 'timeout' | 'stopped' | 'error' | 'paused';
|
|
4
|
+
error?: Error;
|
|
5
|
+
tsStart?: number;
|
|
6
|
+
tsTimeout?: number;
|
|
7
|
+
promise?: Promise<any>;
|
|
8
|
+
}
|
|
9
|
+
export interface TaskProps<T, P> {
|
|
10
|
+
timeout?: number;
|
|
11
|
+
state?: any;
|
|
12
|
+
name?: string;
|
|
13
|
+
errorOnTimeout?: boolean;
|
|
14
|
+
log?: (event: any) => void;
|
|
15
|
+
onDone?: (state: T) => P;
|
|
16
|
+
}
|
|
17
|
+
interface InternalTaskState<P> {
|
|
18
|
+
tsStart?: number;
|
|
19
|
+
tsTimeout?: number;
|
|
20
|
+
isRunning: boolean;
|
|
21
|
+
timeout?: NodeJS.Timeout;
|
|
22
|
+
promise?: Promise<P>;
|
|
23
|
+
onDone?: (result: P) => void;
|
|
24
|
+
onError?: (error: Error) => void;
|
|
25
|
+
onTimeout?: () => void;
|
|
26
|
+
}
|
|
27
|
+
export declare class InteruptableTask<T extends TaskState, P> {
|
|
28
|
+
protected state: T;
|
|
29
|
+
protected internalState: InternalTaskState<P>;
|
|
30
|
+
protected props?: TaskProps<T, P>;
|
|
31
|
+
protected internalEvents: EventEmitter<[never]>;
|
|
32
|
+
protected promise?: Promise<P>;
|
|
33
|
+
constructor(promise: Promise<any>, props?: TaskProps<T, P>);
|
|
34
|
+
getPromise(): Promise<P>;
|
|
35
|
+
getState(): T;
|
|
36
|
+
run(): Promise<P>;
|
|
37
|
+
start(): void;
|
|
38
|
+
stop(): Promise<boolean>;
|
|
39
|
+
isRunning(): boolean;
|
|
40
|
+
protected clearTimeout(): void;
|
|
41
|
+
protected onTimeout(): void;
|
|
42
|
+
protected logEvent(event: any): void;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,127 @@
|
|
|
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.InteruptableTask = void 0;
|
|
16
|
+
const events_1 = __importDefault(require("events"));
|
|
17
|
+
const utils_1 = require("./utils");
|
|
18
|
+
class InteruptableTask {
|
|
19
|
+
constructor(promise, props) {
|
|
20
|
+
var _a;
|
|
21
|
+
this.internalState = { isRunning: false };
|
|
22
|
+
this.internalEvents = new events_1.default();
|
|
23
|
+
this.state = ((_a = props === null || props === void 0 ? void 0 : props.state) !== null && _a !== void 0 ? _a : {});
|
|
24
|
+
this.props = props;
|
|
25
|
+
delete this.props.state;
|
|
26
|
+
this.promise = promise;
|
|
27
|
+
this.start();
|
|
28
|
+
}
|
|
29
|
+
getPromise() {
|
|
30
|
+
return this.internalState.promise;
|
|
31
|
+
}
|
|
32
|
+
getState() {
|
|
33
|
+
return this.state;
|
|
34
|
+
}
|
|
35
|
+
run() {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
if (!this.internalState.isRunning)
|
|
38
|
+
yield (0, utils_1.resolveNextTick)();
|
|
39
|
+
return this.internalState.promise;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
start() {
|
|
43
|
+
this.internalState.promise = new Promise((resolve, reject) => {
|
|
44
|
+
var _a;
|
|
45
|
+
this.internalState.isRunning = true;
|
|
46
|
+
this.internalState.onDone = resolve;
|
|
47
|
+
this.internalState.onError = reject;
|
|
48
|
+
this.internalState.tsStart = Date.now();
|
|
49
|
+
const { timeout } = this.props;
|
|
50
|
+
if (timeout) {
|
|
51
|
+
this.internalState.tsTimeout = this.internalState.tsStart + timeout;
|
|
52
|
+
this.internalState.onTimeout = this.onTimeout.bind(this);
|
|
53
|
+
this.internalState.timeout = setTimeout(() => { this.internalEvents.emit('timeout'); }, timeout);
|
|
54
|
+
this.internalEvents.on('timeout', this.internalState.onTimeout);
|
|
55
|
+
}
|
|
56
|
+
this.internalEvents.once('stopped', () => {
|
|
57
|
+
this.clearTimeout();
|
|
58
|
+
this.internalState = {
|
|
59
|
+
isRunning: false,
|
|
60
|
+
};
|
|
61
|
+
this.internalEvents.removeAllListeners();
|
|
62
|
+
if (this.getState().result === 'completed' || this.getState().result === 'error')
|
|
63
|
+
return;
|
|
64
|
+
if (this.props.onDone)
|
|
65
|
+
resolve(this.props.onDone(this.getState()));
|
|
66
|
+
else
|
|
67
|
+
resolve(null);
|
|
68
|
+
});
|
|
69
|
+
(_a = this.promise) === null || _a === void 0 ? void 0 : _a.then((res) => {
|
|
70
|
+
this.clearTimeout();
|
|
71
|
+
this.internalState = {
|
|
72
|
+
isRunning: false,
|
|
73
|
+
};
|
|
74
|
+
this.getState().result = 'completed';
|
|
75
|
+
this.internalEvents.emit('stopped');
|
|
76
|
+
resolve(res);
|
|
77
|
+
}).catch((err) => {
|
|
78
|
+
this.getState().result = 'error';
|
|
79
|
+
this.getState().error = err;
|
|
80
|
+
this.internalEvents.emit('stopped');
|
|
81
|
+
reject(err);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
stop() {
|
|
86
|
+
return new Promise((resolve) => {
|
|
87
|
+
this.internalEvents.emit('stopped');
|
|
88
|
+
(0, utils_1.resolveNextTick)().then(() => {
|
|
89
|
+
resolve(true);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
isRunning() {
|
|
94
|
+
return this.internalState.isRunning === true;
|
|
95
|
+
}
|
|
96
|
+
clearTimeout() {
|
|
97
|
+
if (this.internalState.timeout) {
|
|
98
|
+
clearTimeout(this.internalState.timeout);
|
|
99
|
+
this.internalEvents.off('timeout', this.internalState.onTimeout);
|
|
100
|
+
}
|
|
101
|
+
delete this.internalState.timeout;
|
|
102
|
+
}
|
|
103
|
+
onTimeout() {
|
|
104
|
+
var _a;
|
|
105
|
+
if (!this.internalState.timeout)
|
|
106
|
+
return;
|
|
107
|
+
const message = this.props.name ? `${this.props.name} timeout` : 'timeout';
|
|
108
|
+
this.logEvent({ message, active: this.isRunning() });
|
|
109
|
+
this.clearTimeout();
|
|
110
|
+
this.getState().result = 'timeout';
|
|
111
|
+
const resolve = this.internalState.onDone;
|
|
112
|
+
const reject = this.internalState.onError;
|
|
113
|
+
this.internalState = { isRunning: false };
|
|
114
|
+
if ((_a = this.props.errorOnTimeout) !== null && _a !== void 0 ? _a : true) {
|
|
115
|
+
reject(new Error('timeout'));
|
|
116
|
+
}
|
|
117
|
+
if (this.props.onDone)
|
|
118
|
+
resolve(this.props.onDone(this.getState()));
|
|
119
|
+
else
|
|
120
|
+
resolve(null);
|
|
121
|
+
}
|
|
122
|
+
logEvent(event) {
|
|
123
|
+
if (this.props.log)
|
|
124
|
+
this.props.log(event);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.InteruptableTask = InteruptableTask;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "incyclist-devices",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@serialport/bindings-interface": "^1.2.2",
|
|
6
6
|
"@serialport/parser-byte-length": "^9.0.1",
|
|
@@ -16,8 +16,10 @@
|
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@serialport/binding-mock": "^10.2.2",
|
|
18
18
|
"@serialport/bindings-cpp": "^10.8.0",
|
|
19
|
+
"@stoprocent/noble": "^1.15.2",
|
|
19
20
|
"@types/jest": "^29.5.12",
|
|
20
21
|
"@types/node": "^22.5.0",
|
|
22
|
+
"bonjour-service": "^1.3.0",
|
|
21
23
|
"eslint": "^8.47.0",
|
|
22
24
|
"eslint-config-react-app": "^7.0.1",
|
|
23
25
|
"jest": "^29.7.0",
|