incyclist-devices 2.1.19 → 2.1.21
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 +3 -0
- package/lib/antv2/base/adapter.d.ts +2 -1
- package/lib/antv2/base/adapter.js +9 -3
- package/lib/antv2/factories/sensor-factory.js +2 -0
- package/lib/antv2/index.d.ts +4 -1
- package/lib/antv2/index.js +8 -1
- package/lib/antv2/sc/adapter.d.ts +11 -0
- package/lib/antv2/sc/adapter.js +30 -0
- package/lib/antv2/sc/index.d.ts +2 -0
- package/lib/antv2/sc/index.js +7 -0
- package/lib/antv2/spd/adapter.d.ts +11 -0
- package/lib/antv2/spd/adapter.js +25 -0
- package/lib/antv2/spd/index.d.ts +2 -0
- package/lib/antv2/spd/index.js +7 -0
- package/lib/serial/base/serial-interface.js +8 -0
- package/lib/serial/base/serial-scanner.js +10 -7
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -3,7 +3,7 @@ import { IChannel, ISensor, Profile } from 'incyclist-ant-plus';
|
|
|
3
3
|
import AntInterface from './interface';
|
|
4
4
|
import IncyclistDevice from '../../base/adpater';
|
|
5
5
|
import { AntDeviceProperties, AntDeviceSettings, LegacyProfile, BaseDeviceData, AdapterStartStatus } from '../types';
|
|
6
|
-
import { IAdapter, IncyclistAdapterData, IncyclistBikeData } from '../../types';
|
|
6
|
+
import { IAdapter, IncyclistAdapterData, IncyclistBikeData, IncyclistCapability } from '../../types';
|
|
7
7
|
export default class AntAdapter<TDeviceData extends BaseDeviceData> extends IncyclistDevice<AntDeviceProperties> {
|
|
8
8
|
sensor: ISensor;
|
|
9
9
|
data: IncyclistAdapterData;
|
|
@@ -29,6 +29,7 @@ export default class AntAdapter<TDeviceData extends BaseDeviceData> extends Incy
|
|
|
29
29
|
constructor(settings: AntDeviceSettings, props?: AntDeviceProperties);
|
|
30
30
|
getProfileName(): Profile;
|
|
31
31
|
getLegacyProfileName(): LegacyProfile;
|
|
32
|
+
protected getStaticCapabilities(): Array<IncyclistCapability>;
|
|
32
33
|
createSensor(settings: AntDeviceSettings): ISensor;
|
|
33
34
|
isEqual(settings: AntDeviceSettings): boolean;
|
|
34
35
|
getDefaultReconnectDelay(): number;
|
|
@@ -51,15 +51,22 @@ class AntAdapter extends adpater_1.default {
|
|
|
51
51
|
if (this.isDebugEnabled()) {
|
|
52
52
|
this.ant.setLogger(this);
|
|
53
53
|
}
|
|
54
|
+
if (this.getStaticCapabilities())
|
|
55
|
+
this.capabilities = this.getStaticCapabilities();
|
|
54
56
|
}
|
|
55
57
|
getProfileName() {
|
|
58
|
+
var _a;
|
|
56
59
|
const C = this.constructor;
|
|
57
|
-
return C['ANT_PROFILE_NAME'];
|
|
60
|
+
return ((_a = this.sensor) === null || _a === void 0 ? void 0 : _a.getProfile()) || C['ANT_PROFILE_NAME'];
|
|
58
61
|
}
|
|
59
62
|
getLegacyProfileName() {
|
|
60
63
|
const C = this.constructor;
|
|
61
64
|
return C['INCYCLIST_PROFILE_NAME'];
|
|
62
65
|
}
|
|
66
|
+
getStaticCapabilities() {
|
|
67
|
+
const C = this.constructor;
|
|
68
|
+
return C['CAPABILITIES'];
|
|
69
|
+
}
|
|
63
70
|
createSensor(settings) {
|
|
64
71
|
return sensor_factory_1.default.create(this.getProfileName(), Number(settings.deviceID));
|
|
65
72
|
}
|
|
@@ -190,11 +197,10 @@ class AntAdapter extends adpater_1.default {
|
|
|
190
197
|
return id.toString();
|
|
191
198
|
}
|
|
192
199
|
getName() {
|
|
193
|
-
var _a;
|
|
194
200
|
if (this.settings.name)
|
|
195
201
|
return this.settings.name;
|
|
196
202
|
const deviceID = this.getID();
|
|
197
|
-
const profile =
|
|
203
|
+
const profile = this.getProfileName();
|
|
198
204
|
return `Ant+${profile} ${deviceID}`;
|
|
199
205
|
}
|
|
200
206
|
getUniqueName() {
|
|
@@ -7,6 +7,8 @@ const profiles = [
|
|
|
7
7
|
{ profile: 'HR', Class: incyclist_ant_plus_2.HeartRateSensor },
|
|
8
8
|
{ profile: 'FE', Class: incyclist_ant_plus_2.FitnessEquipmentSensor },
|
|
9
9
|
{ profile: 'CAD', Class: incyclist_ant_plus_1.CadenceSensor },
|
|
10
|
+
{ profile: 'SPD', Class: incyclist_ant_plus_1.SpeedSensor },
|
|
11
|
+
{ profile: 'SC', Class: incyclist_ant_plus_1.SpeedCadenceSensor },
|
|
10
12
|
];
|
|
11
13
|
class SensorFactory {
|
|
12
14
|
static create(profile, deviceID) {
|
package/lib/antv2/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import AntPwrAdapter from "./pwr";
|
|
2
2
|
import AntFEAdapter from "./fe";
|
|
3
3
|
import AntHrAdapter from "./hr";
|
|
4
|
+
import AntCadAdapter from "./cad";
|
|
4
5
|
import AntAdapterFactory from "./factories/adapter-factory";
|
|
5
6
|
import AntInterface from "./base/interface";
|
|
6
7
|
import { AntInterfaceProps } from "./types";
|
|
8
|
+
import AntSpdAdapter from "./spd";
|
|
9
|
+
import AntScAdapter from "./sc";
|
|
7
10
|
export { AntDeviceSettings, AntDeviceProperties, AntScanProps } from "./types";
|
|
8
|
-
export { AntAdapterFactory, AntFEAdapter, AntHrAdapter, AntPwrAdapter, AntInterface, AntInterfaceProps };
|
|
11
|
+
export { AntAdapterFactory, AntFEAdapter, AntHrAdapter, AntPwrAdapter, AntScAdapter, AntSpdAdapter, AntCadAdapter, AntInterface, AntInterfaceProps };
|
package/lib/antv2/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.AntInterface = exports.AntPwrAdapter = exports.AntHrAdapter = exports.AntFEAdapter = exports.AntAdapterFactory = void 0;
|
|
6
|
+
exports.AntInterface = exports.AntCadAdapter = exports.AntSpdAdapter = exports.AntScAdapter = exports.AntPwrAdapter = exports.AntHrAdapter = exports.AntFEAdapter = exports.AntAdapterFactory = void 0;
|
|
7
7
|
const pwr_1 = __importDefault(require("./pwr"));
|
|
8
8
|
exports.AntPwrAdapter = pwr_1.default;
|
|
9
9
|
const fe_1 = __importDefault(require("./fe"));
|
|
@@ -11,12 +11,19 @@ exports.AntFEAdapter = fe_1.default;
|
|
|
11
11
|
const hr_1 = __importDefault(require("./hr"));
|
|
12
12
|
exports.AntHrAdapter = hr_1.default;
|
|
13
13
|
const cad_1 = __importDefault(require("./cad"));
|
|
14
|
+
exports.AntCadAdapter = cad_1.default;
|
|
14
15
|
const adapter_factory_1 = __importDefault(require("./factories/adapter-factory"));
|
|
15
16
|
exports.AntAdapterFactory = adapter_factory_1.default;
|
|
16
17
|
const interface_1 = __importDefault(require("./base/interface"));
|
|
17
18
|
exports.AntInterface = interface_1.default;
|
|
19
|
+
const spd_1 = __importDefault(require("./spd"));
|
|
20
|
+
exports.AntSpdAdapter = spd_1.default;
|
|
21
|
+
const sc_1 = __importDefault(require("./sc"));
|
|
22
|
+
exports.AntScAdapter = sc_1.default;
|
|
18
23
|
const af = adapter_factory_1.default.getInstance();
|
|
19
24
|
af.register('PWR', 'Power Meter', pwr_1.default);
|
|
20
25
|
af.register('HR', 'Heartrate Monitor', hr_1.default);
|
|
21
26
|
af.register('FE', 'Smart Trainer', fe_1.default);
|
|
22
27
|
af.register('CAD', 'Cadence Sensor', cad_1.default);
|
|
28
|
+
af.register('SPD', 'Speed Sensor', spd_1.default);
|
|
29
|
+
af.register('SC', 'Speed + Cadence Sensor', sc_1.default);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SpeedCadenceSensorState, Profile } from "incyclist-ant-plus";
|
|
2
|
+
import AntAdapter from "../base/adapter";
|
|
3
|
+
import { LegacyProfile } from "../types";
|
|
4
|
+
import { IncyclistCapability } from "../../types";
|
|
5
|
+
export default class AntSpdAdapter extends AntAdapter<SpeedCadenceSensorState> {
|
|
6
|
+
protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
|
|
7
|
+
protected static ANT_PROFILE_NAME: Profile;
|
|
8
|
+
protected static CAPABILITIES: IncyclistCapability[];
|
|
9
|
+
mapToAdapterData(deviceData: SpeedCadenceSensorState): void;
|
|
10
|
+
hasData(): boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const adapter_1 = __importDefault(require("../base/adapter"));
|
|
7
|
+
const types_1 = require("../../types");
|
|
8
|
+
class AntSpdAdapter extends adapter_1.default {
|
|
9
|
+
mapToAdapterData(deviceData) {
|
|
10
|
+
if (deviceData.CalculatedSpeed !== undefined) {
|
|
11
|
+
this.data.speed = deviceData.CalculatedSpeed;
|
|
12
|
+
this.data.timestamp = Date.now();
|
|
13
|
+
}
|
|
14
|
+
if (deviceData.CalculatedDistance !== undefined) {
|
|
15
|
+
this.data.deviceDistanceCounter = deviceData.CalculatedDistance;
|
|
16
|
+
}
|
|
17
|
+
if (deviceData.CalculatedCadence) {
|
|
18
|
+
this.data.cadence = deviceData.CalculatedCadence;
|
|
19
|
+
this.data.timestamp = Date.now();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
hasData() {
|
|
23
|
+
return ((this.deviceData.CalculatedSpeed !== undefined && this.deviceData.CalculatedSpeed !== null) ||
|
|
24
|
+
(this.deviceData.CalculatedCadence !== undefined && this.deviceData.CalculatedCadence !== null));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
AntSpdAdapter.INCYCLIST_PROFILE_NAME = 'Speed + Cadence Sensor';
|
|
28
|
+
AntSpdAdapter.ANT_PROFILE_NAME = 'SC';
|
|
29
|
+
AntSpdAdapter.CAPABILITIES = [types_1.IncyclistCapability.Speed, types_1.IncyclistCapability.Cadence];
|
|
30
|
+
exports.default = AntSpdAdapter;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const adapter_1 = __importDefault(require("./adapter"));
|
|
7
|
+
exports.default = adapter_1.default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SpeedSensorState, Profile } from "incyclist-ant-plus";
|
|
2
|
+
import AntAdapter from "../base/adapter";
|
|
3
|
+
import { LegacyProfile } from "../types";
|
|
4
|
+
import { IncyclistCapability } from "../../types";
|
|
5
|
+
export default class AntSpdAdapter extends AntAdapter<SpeedSensorState> {
|
|
6
|
+
protected static INCYCLIST_PROFILE_NAME: LegacyProfile;
|
|
7
|
+
protected static ANT_PROFILE_NAME: Profile;
|
|
8
|
+
protected static CAPABILITIES: IncyclistCapability[];
|
|
9
|
+
mapToAdapterData(deviceData: SpeedSensorState): void;
|
|
10
|
+
hasData(): boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const adapter_1 = __importDefault(require("../base/adapter"));
|
|
7
|
+
const types_1 = require("../../types");
|
|
8
|
+
class AntSpdAdapter extends adapter_1.default {
|
|
9
|
+
mapToAdapterData(deviceData) {
|
|
10
|
+
if (deviceData.CalculatedSpeed !== undefined) {
|
|
11
|
+
this.data.speed = deviceData.CalculatedSpeed;
|
|
12
|
+
this.data.timestamp = Date.now();
|
|
13
|
+
}
|
|
14
|
+
if (deviceData.CalculatedDistance !== undefined) {
|
|
15
|
+
this.data.deviceDistanceCounter = deviceData.CalculatedDistance;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
hasData() {
|
|
19
|
+
return this.deviceData.CalculatedSpeed !== undefined && this.deviceData.CalculatedSpeed !== null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
AntSpdAdapter.INCYCLIST_PROFILE_NAME = 'Speed Sensor';
|
|
23
|
+
AntSpdAdapter.ANT_PROFILE_NAME = 'SPD';
|
|
24
|
+
AntSpdAdapter.CAPABILITIES = [types_1.IncyclistCapability.Speed];
|
|
25
|
+
exports.default = AntSpdAdapter;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const adapter_1 = __importDefault(require("./adapter"));
|
|
7
|
+
exports.default = adapter_1.default;
|
|
@@ -19,6 +19,7 @@ const utils_1 = require("../../utils/utils");
|
|
|
19
19
|
const adapter_factory_1 = __importDefault(require("../factories/adapter-factory"));
|
|
20
20
|
const serial_scanner_1 = require("./serial-scanner");
|
|
21
21
|
const DEFAULT_SCAN_TIMEOUT = 10000;
|
|
22
|
+
const MAX_PARALLEL_SCANS = 5;
|
|
22
23
|
class SerialInterface extends events_1.default {
|
|
23
24
|
static getInstance(props) {
|
|
24
25
|
const { ifaceName, binding, logger } = props;
|
|
@@ -237,6 +238,10 @@ class SerialInterface extends events_1.default {
|
|
|
237
238
|
return [];
|
|
238
239
|
}
|
|
239
240
|
this.logEvent({ message: 'scanning on ', interface: this.ifaceName, paths: paths.map(p => p.path).join(','), timeout });
|
|
241
|
+
let listReduced = false;
|
|
242
|
+
if (paths.length > MAX_PARALLEL_SCANS) {
|
|
243
|
+
paths = paths.filter((p, idx) => idx < MAX_PARALLEL_SCANS);
|
|
244
|
+
}
|
|
240
245
|
const scanners = paths.map(p => new serial_scanner_1.SinglePathScanner(p.path, this, Object.assign(Object.assign({}, props), { logger: this.logger })));
|
|
241
246
|
try {
|
|
242
247
|
yield Promise.all(scanners.map(s => s.scan()
|
|
@@ -259,6 +264,9 @@ class SerialInterface extends events_1.default {
|
|
|
259
264
|
clearTimeout(this.toScan);
|
|
260
265
|
this.toScan = null;
|
|
261
266
|
}
|
|
267
|
+
if (listReduced) {
|
|
268
|
+
paths.forEach(p => this.inUse.push(p.path));
|
|
269
|
+
}
|
|
262
270
|
this.isScanning = false;
|
|
263
271
|
this.logEvent({ message: 'scan finished on', interface: this.ifaceName, paths: paths.map(p => p.path), devices: detected.map(d => {
|
|
264
272
|
const res = Object.assign({}, d);
|
|
@@ -67,17 +67,20 @@ class SinglePathScanner {
|
|
|
67
67
|
}
|
|
68
68
|
const adapterSettings = { interface: this.serial.getName(), host, port, protocol };
|
|
69
69
|
const adapter = adapter_factory_1.default.getInstance().createInstance(adapterSettings);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
if (this.isScanning) {
|
|
71
|
+
found = yield (adapter === null || adapter === void 0 ? void 0 : adapter.check());
|
|
72
|
+
if (found) {
|
|
73
|
+
this.isFound = true;
|
|
74
|
+
const name = adapter.getName();
|
|
75
|
+
resolve(Object.assign(Object.assign({}, adapterSettings), { name }));
|
|
76
|
+
}
|
|
77
|
+
yield adapter.close();
|
|
78
|
+
yield (0, utils_1.sleep)(1000);
|
|
75
79
|
}
|
|
76
|
-
yield (0, utils_1.sleep)(100);
|
|
77
80
|
}
|
|
78
81
|
catch (err) {
|
|
79
82
|
this.logEvent({ message: 'error', fn: 'scan()', error: err.message || err, stack: err.stack });
|
|
80
|
-
yield (0, utils_1.sleep)(
|
|
83
|
+
yield (0, utils_1.sleep)(2000);
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
86
|
}));
|