incyclist-devices 2.2.10-beta.0 → 2.3.0-beta.10
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.d.ts +4 -0
- package/lib/base/adpater.js +17 -3
- package/lib/ble/adapter-factory.d.ts +20 -24
- package/lib/ble/adapter-factory.js +13 -36
- package/lib/ble/base/adapter.d.ts +19 -5
- package/lib/ble/base/adapter.js +211 -62
- package/lib/ble/base/comms.d.ts +2 -74
- package/lib/ble/base/comms.js +3 -596
- package/lib/ble/base/interface.d.ts +102 -0
- package/lib/ble/base/interface.js +591 -0
- package/lib/ble/base/peripheral.d.ts +35 -0
- package/lib/ble/base/peripheral.js +311 -0
- package/lib/ble/base/sensor.d.ts +32 -0
- package/lib/ble/base/sensor.js +135 -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 +34 -0
- package/lib/ble/factories/adapter-factory.js +137 -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/factories/types.d.ts +18 -0
- package/lib/ble/factories/types.js +2 -0
- package/lib/ble/fm/adapter.d.ts +12 -6
- package/lib/ble/fm/adapter.js +100 -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 +87 -52
- package/lib/ble/utils.d.ts +7 -2
- package/lib/ble/utils.js +93 -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 +311 -0
- package/lib/direct-connect/base/peripheral.d.ts +50 -0
- package/lib/direct-connect/base/peripheral.js +522 -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 +37 -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 +21 -0
- package/lib/direct-connect/messages/message.js +105 -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 +14 -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/adapter.d.ts +3 -0
- 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 +47 -0
- package/lib/utils/task.js +139 -0
- package/package.json +3 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.propertyFromVal = exports.propertyVal = exports.beautifyUUID = exports.parseUUID = void 0;
|
|
4
|
+
const parseUUID = (str) => {
|
|
5
|
+
const uuid = str.toUpperCase();
|
|
6
|
+
if (str.startsWith('0x')) {
|
|
7
|
+
const hex = uuid.slice(2);
|
|
8
|
+
if (hex.length === 4) {
|
|
9
|
+
return `0000${hex}00001000800000805F9B34FB`;
|
|
10
|
+
}
|
|
11
|
+
if (hex.length === 8) {
|
|
12
|
+
return `${hex}00001000800000805F9B34FB`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
else if (uuid.length === 4) {
|
|
16
|
+
return `0000${uuid}00001000800000805F9B34FB`;
|
|
17
|
+
}
|
|
18
|
+
else if (uuid.length === 8) {
|
|
19
|
+
return `${uuid}00001000800000805F9B34FB`;
|
|
20
|
+
}
|
|
21
|
+
else if (uuid.length === 32) {
|
|
22
|
+
return uuid;
|
|
23
|
+
}
|
|
24
|
+
else if (uuid.length === 36) {
|
|
25
|
+
return uuid.replace(/-/g, '');
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`Invalid UUID: ${uuid}`);
|
|
28
|
+
};
|
|
29
|
+
exports.parseUUID = parseUUID;
|
|
30
|
+
const beautifyUUID = (str, withX = false) => {
|
|
31
|
+
const uuid = (0, exports.parseUUID)(str);
|
|
32
|
+
const parts = [
|
|
33
|
+
uuid.substring(0, 8),
|
|
34
|
+
uuid.substring(8, 12),
|
|
35
|
+
uuid.substring(12, 16),
|
|
36
|
+
uuid.substring(16, 20),
|
|
37
|
+
uuid.substring(20),
|
|
38
|
+
];
|
|
39
|
+
if (uuid.substring(8) === '00001000800000805F9B34FB') {
|
|
40
|
+
let short;
|
|
41
|
+
if (parts[0].startsWith('0000')) {
|
|
42
|
+
short = parts[0].substring(4);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
short = parts[0];
|
|
46
|
+
}
|
|
47
|
+
return withX ? `0x${short}` : short;
|
|
48
|
+
}
|
|
49
|
+
return parts.join('-');
|
|
50
|
+
};
|
|
51
|
+
exports.beautifyUUID = beautifyUUID;
|
|
52
|
+
const propertyVal = (properties) => {
|
|
53
|
+
let res = 0;
|
|
54
|
+
if (properties.includes('read'))
|
|
55
|
+
res |= 0x01;
|
|
56
|
+
if (properties.includes('write'))
|
|
57
|
+
res |= 0x02;
|
|
58
|
+
if (properties.includes('notify'))
|
|
59
|
+
res |= 0x04;
|
|
60
|
+
return res;
|
|
61
|
+
};
|
|
62
|
+
exports.propertyVal = propertyVal;
|
|
63
|
+
const propertyFromVal = (val) => {
|
|
64
|
+
const res = [];
|
|
65
|
+
if (val & 0x01)
|
|
66
|
+
res.push('read');
|
|
67
|
+
if (val & 0x02)
|
|
68
|
+
res.push('write');
|
|
69
|
+
if (val & 0x04)
|
|
70
|
+
res.push('notify');
|
|
71
|
+
return res;
|
|
72
|
+
};
|
|
73
|
+
exports.propertyFromVal = propertyFromVal;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
6
|
+
const adapter_factory_1 = __importDefault(require("../antv2/factories/adapter-factory"));
|
|
4
7
|
const ble_1 = require("../ble");
|
|
5
8
|
const serial_1 = require("../serial");
|
|
6
9
|
const Simulator_1 = require("../simulator/Simulator");
|
|
@@ -8,7 +11,8 @@ const device_1 = require("../types/device");
|
|
|
8
11
|
class AdapterFactory {
|
|
9
12
|
static reset() {
|
|
10
13
|
AdapterFactory.adapters = [];
|
|
11
|
-
ble_1.BleAdapterFactory.getInstance().instances = [];
|
|
14
|
+
ble_1.BleAdapterFactory.getInstance('ble').instances = [];
|
|
15
|
+
ble_1.BleAdapterFactory.getInstance('wifi').instances = [];
|
|
12
16
|
}
|
|
13
17
|
static create(settings, props) {
|
|
14
18
|
const adapters = AdapterFactory.adapters;
|
|
@@ -30,10 +34,16 @@ class AdapterFactory {
|
|
|
30
34
|
adapter = serial_1.SerialAdapterFactory.getInstance().createInstance(settings, props);
|
|
31
35
|
break;
|
|
32
36
|
case device_1.INTERFACE.ANT:
|
|
33
|
-
adapter =
|
|
37
|
+
adapter = adapter_factory_1.default.getInstance().createInstance(settings, props);
|
|
34
38
|
break;
|
|
35
39
|
case device_1.INTERFACE.BLE:
|
|
36
|
-
adapter = ble_1.BleAdapterFactory.getInstance().createInstance(settings, props);
|
|
40
|
+
adapter = ble_1.BleAdapterFactory.getInstance('ble').createInstance(settings, props);
|
|
41
|
+
break;
|
|
42
|
+
case device_1.INTERFACE.DC:
|
|
43
|
+
{
|
|
44
|
+
const factory = ble_1.BleAdapterFactory.getInstance('wifi');
|
|
45
|
+
adapter = ble_1.BleAdapterFactory.getInstance('wifi').createInstance(settings, props);
|
|
46
|
+
}
|
|
37
47
|
break;
|
|
38
48
|
case device_1.INTERFACE.SIMULATOR:
|
|
39
49
|
adapter = new Simulator_1.Simulator(settings, props);
|
|
@@ -2,6 +2,7 @@ import { InterfaceProps } from "../types/interface";
|
|
|
2
2
|
import { SerialInterface } from "../serial";
|
|
3
3
|
import AntInterface from "../antv2/base/interface";
|
|
4
4
|
import { BleInterface } from "../ble";
|
|
5
|
+
import DirectConnectInterface from "../direct-connect/base/interface";
|
|
5
6
|
export default class InterfaceFactory {
|
|
6
|
-
static create(ifaceName: string, props?: InterfaceProps): AntInterface | BleInterface | SerialInterface;
|
|
7
|
+
static create(ifaceName: string, props?: InterfaceProps): AntInterface | BleInterface | SerialInterface | DirectConnectInterface;
|
|
7
8
|
}
|
|
@@ -7,20 +7,23 @@ const serial_1 = require("../serial");
|
|
|
7
7
|
const interface_1 = __importDefault(require("../antv2/base/interface"));
|
|
8
8
|
const device_1 = require("../types/device");
|
|
9
9
|
const ble_1 = require("../ble");
|
|
10
|
+
const interface_2 = __importDefault(require("../direct-connect/base/interface"));
|
|
10
11
|
class InterfaceFactory {
|
|
11
12
|
static create(ifaceName, props) {
|
|
12
13
|
switch (ifaceName) {
|
|
13
14
|
case device_1.INTERFACE.SERIAL:
|
|
14
15
|
case device_1.INTERFACE.TCPIP:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
{
|
|
17
|
+
const serialProps = (props || {});
|
|
18
|
+
serialProps.ifaceName = ifaceName;
|
|
19
|
+
return serial_1.SerialInterface.getInstance(serialProps);
|
|
20
|
+
}
|
|
18
21
|
case device_1.INTERFACE.ANT:
|
|
19
|
-
|
|
20
|
-
return interface_1.default.getInstance(antProps);
|
|
22
|
+
return interface_1.default.getInstance(props);
|
|
21
23
|
case device_1.INTERFACE.BLE:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
return ble_1.BleInterface.getInstance(props);
|
|
25
|
+
case device_1.INTERFACE.DC:
|
|
26
|
+
return interface_2.default.getInstance(props);
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
29
|
}
|
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/adapter.d.ts
CHANGED
|
@@ -46,5 +46,8 @@ export interface IAdapter extends EventEmitter, IBike, ISensor {
|
|
|
46
46
|
resume(): Promise<boolean>;
|
|
47
47
|
connect(): Promise<boolean>;
|
|
48
48
|
close(): Promise<boolean>;
|
|
49
|
+
resetData(): void;
|
|
50
|
+
onScanStart(): void;
|
|
51
|
+
onScanStop(): void;
|
|
49
52
|
onData(callback: OnDeviceDataCallback): any;
|
|
50
53
|
}
|
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,47 @@
|
|
|
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
|
+
protected onStopNotifiers: Array<() => void>;
|
|
34
|
+
constructor(promise: Promise<any>, props?: TaskProps<T, P>);
|
|
35
|
+
getPromise(): Promise<P>;
|
|
36
|
+
getState(): T;
|
|
37
|
+
run(): Promise<P>;
|
|
38
|
+
notifyOnStop(cb: () => void): void;
|
|
39
|
+
start(): void;
|
|
40
|
+
stop(): Promise<boolean>;
|
|
41
|
+
isRunning(): boolean;
|
|
42
|
+
protected clearTimeout(): void;
|
|
43
|
+
protected onTimeout(): void;
|
|
44
|
+
protected sendStopNotification(): void;
|
|
45
|
+
protected logEvent(event: any): void;
|
|
46
|
+
}
|
|
47
|
+
export {};
|