incyclist-devices 1.4.22 → 1.4.25
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/CyclingMode.js +0 -1
- package/lib/Device.js +0 -1
- package/lib/DeviceProtocol.d.ts +1 -0
- package/lib/DeviceProtocol.js +1 -1
- package/lib/DeviceSupport.js +8 -21
- package/lib/ant/AntAdapter.js +0 -1
- package/lib/ant/AntScanner.js +10 -21
- package/lib/ant/antfe/AntFEAdapter.js +7 -7
- package/lib/ant/anthrm/AntHrmAdapter.js +1 -1
- package/lib/ant/antpwr/AntPWRAdapter.d.ts +24 -0
- package/lib/ant/antpwr/AntPWRAdapter.js +252 -0
- package/lib/ant/antpwr/pwr-adapter.d.ts +48 -0
- package/lib/ant/antpwr/pwr-adapter.js +259 -0
- package/lib/ant/utils.js +1 -3
- package/lib/calculations.js +2 -4
- package/lib/daum/DaumAdapter.d.ts +2 -2
- package/lib/daum/DaumAdapter.js +31 -39
- package/lib/daum/DaumPowerMeterCyclingMode.d.ts +8 -0
- package/lib/daum/DaumPowerMeterCyclingMode.js +21 -0
- package/lib/daum/ERGCyclingMode.d.ts +3 -6
- package/lib/daum/ERGCyclingMode.js +15 -27
- package/lib/daum/SmartTrainerCyclingMode.js +0 -1
- package/lib/daum/classic/DaumClassicAdapter.js +2 -2
- package/lib/daum/classic/DaumClassicProtocol.js +7 -19
- package/lib/daum/classic/bike.js +26 -26
- package/lib/daum/classic/utils.js +0 -1
- package/lib/daum/constants.js +0 -1
- package/lib/daum/premium/DaumClassicCyclingMode.d.ts +2 -2
- package/lib/daum/premium/DaumClassicCyclingMode.js +2 -2
- package/lib/daum/premium/DaumPremiumAdapter.js +2 -2
- package/lib/daum/premium/DaumPremiumProtocol.js +7 -19
- package/lib/daum/premium/bike.js +17 -18
- package/lib/daum/premium/utils.js +0 -1
- package/lib/kettler/comms.js +1 -2
- package/lib/kettler/ergo-racer/adapter.js +10 -22
- package/lib/kettler/ergo-racer/modes/power-meter.d.ts +2 -2
- package/lib/kettler/ergo-racer/modes/power-meter.js +12 -4
- package/lib/kettler/ergo-racer/protocol.js +7 -19
- package/lib/modes/power-base.d.ts +20 -0
- package/lib/modes/power-base.js +60 -0
- package/lib/modes/power-meter.d.ts +20 -0
- package/lib/modes/power-meter.js +70 -0
- package/lib/modes/simulator.d.ts +27 -0
- package/lib/modes/simulator.js +118 -0
- package/lib/simulator/Simulator.js +10 -23
- package/lib/simulator/simulator-mode.js +4 -4
- package/lib/types/route.js +0 -1
- package/lib/types/user.js +0 -1
- package/lib/utils.js +1 -3
- package/package.json +1 -1
package/lib/CyclingMode.js
CHANGED
package/lib/Device.js
CHANGED
package/lib/DeviceProtocol.d.ts
CHANGED
package/lib/DeviceProtocol.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.INTERFACE = void 0;
|
|
4
3
|
exports.INTERFACE = {
|
|
5
4
|
SERIAL: 'serial',
|
|
6
5
|
ANT: 'ant',
|
|
@@ -22,6 +21,7 @@ class DeviceProtocolBase {
|
|
|
22
21
|
scan(props) { throw new Error('not implemented'); }
|
|
23
22
|
stopScan() { throw new Error('not implemented'); }
|
|
24
23
|
isScanning() { throw new Error('not implemented'); }
|
|
24
|
+
add(props) { throw new Error('Method not implemented.'); }
|
|
25
25
|
getDevices() { return this.devices; }
|
|
26
26
|
setAnt(antClass) { DeviceProtocolBase.setAnt(antClass); }
|
|
27
27
|
getAnt() { return DeviceProtocolBase.getAnt(); }
|
package/lib/DeviceSupport.js
CHANGED
|
@@ -1,43 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
14
5
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
6
|
if (mod && mod.__esModule) return mod;
|
|
16
7
|
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (
|
|
18
|
-
|
|
8
|
+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
9
|
+
result["default"] = mod;
|
|
19
10
|
return result;
|
|
20
11
|
};
|
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.CyclingModeProperyType = exports.AntScanner = exports.Protocols = exports.Device = exports.INTERFACE = exports.DeviceRegistry = exports.DeviceProtocolBase = void 0;
|
|
26
13
|
const DeviceRegistry_1 = __importDefault(require("./DeviceRegistry"));
|
|
27
14
|
exports.DeviceRegistry = DeviceRegistry_1.default;
|
|
28
15
|
const Device_1 = __importDefault(require("./Device"));
|
|
29
16
|
exports.Device = Device_1.default;
|
|
30
17
|
const DeviceProtocol_1 = __importStar(require("./DeviceProtocol"));
|
|
31
18
|
exports.DeviceProtocolBase = DeviceProtocol_1.default;
|
|
32
|
-
|
|
19
|
+
exports.INTERFACE = DeviceProtocol_1.INTERFACE;
|
|
33
20
|
const Simulator_1 = __importDefault(require("./simulator/Simulator"));
|
|
34
21
|
const DaumPremiumProtocol_1 = __importDefault(require("./daum/premium/DaumPremiumProtocol"));
|
|
35
22
|
const DaumClassicProtocol_1 = __importDefault(require("./daum/classic/DaumClassicProtocol"));
|
|
36
23
|
const protocol_1 = __importDefault(require("./kettler/ergo-racer/protocol"));
|
|
37
24
|
const AntScanner_1 = require("./ant/AntScanner");
|
|
38
|
-
|
|
25
|
+
exports.AntScanner = AntScanner_1.AntScanner;
|
|
39
26
|
const CyclingMode_1 = require("./CyclingMode");
|
|
40
|
-
|
|
27
|
+
exports.CyclingModeProperyType = CyclingMode_1.CyclingModeProperyType;
|
|
41
28
|
const Protocols = {
|
|
42
29
|
SimulatorProtocol: Simulator_1.default,
|
|
43
30
|
DaumClassicProtocol: DaumClassicProtocol_1.default,
|
package/lib/ant/AntAdapter.js
CHANGED
|
@@ -3,7 +3,6 @@ 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.DEFAULT_UPDATE_FREQUENCY = void 0;
|
|
7
6
|
const Device_1 = __importDefault(require("../Device"));
|
|
8
7
|
exports.DEFAULT_UPDATE_FREQUENCY = 1000;
|
|
9
8
|
class AntAdapter extends Device_1.default {
|
package/lib/ant/AntScanner.js
CHANGED
|
@@ -1,23 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -27,14 +8,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
27
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
9
|
});
|
|
29
10
|
};
|
|
11
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
12
|
+
if (mod && mod.__esModule) return mod;
|
|
13
|
+
var result = {};
|
|
14
|
+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
15
|
+
result["default"] = mod;
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
30
18
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
19
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
20
|
};
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.AntScanner = exports.AntProtocol = void 0;
|
|
35
22
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
36
23
|
const DeviceProtocol_1 = __importStar(require("../DeviceProtocol"));
|
|
37
24
|
const AntHrmAdapter_1 = __importDefault(require("./anthrm/AntHrmAdapter"));
|
|
25
|
+
const pwr_adapter_1 = __importDefault(require("./antpwr/pwr-adapter"));
|
|
38
26
|
const AntFEAdapter_1 = __importDefault(require("./antfe/AntFEAdapter"));
|
|
39
27
|
const LOGGER_NAME = 'ANT+Scanner';
|
|
40
28
|
const DEFAULT_SCAN_TIMEOUT = 30000;
|
|
@@ -102,7 +90,8 @@ class AntProtocol extends DeviceProtocol_1.default {
|
|
|
102
90
|
this.scanning = false;
|
|
103
91
|
this.profiles = [
|
|
104
92
|
{ name: 'Heartrate Monitor', Adapter: AntHrmAdapter_1.default },
|
|
105
|
-
{ name: 'Smart Trainer', Adapter: AntFEAdapter_1.default }
|
|
93
|
+
{ name: 'Smart Trainer', Adapter: AntFEAdapter_1.default },
|
|
94
|
+
{ name: 'Power Meter', Adapter: pwr_adapter_1.default }
|
|
106
95
|
];
|
|
107
96
|
}
|
|
108
97
|
add(settings) {
|
|
@@ -52,7 +52,7 @@ class AntFEAdapter extends AntAdapter_1.default {
|
|
|
52
52
|
getDisplayName() {
|
|
53
53
|
const { DeviceID, ManId, ComputedHeartRate } = this.deviceData;
|
|
54
54
|
const hrmStr = ComputedHeartRate ? ` (${ComputedHeartRate})` : '';
|
|
55
|
-
return `${
|
|
55
|
+
return `${utils_1.getBrand(ManId)} FE ${DeviceID}${hrmStr}`;
|
|
56
56
|
}
|
|
57
57
|
onAttached() {
|
|
58
58
|
this.logger.logEvent({ message: 'Device connected' });
|
|
@@ -233,7 +233,7 @@ class AntFEAdapter extends AntAdapter_1.default {
|
|
|
233
233
|
trackResistanceSent: false,
|
|
234
234
|
userSent: false,
|
|
235
235
|
};
|
|
236
|
-
|
|
236
|
+
utils_2.runWithRetries(() => __awaiter(this, void 0, void 0, function* () {
|
|
237
237
|
if (this.isStopped())
|
|
238
238
|
resolve(false);
|
|
239
239
|
try {
|
|
@@ -318,18 +318,18 @@ class AntFEAdapter extends AntAdapter_1.default {
|
|
|
318
318
|
try {
|
|
319
319
|
const isReset = (!request || request.reset || Object.keys(request).length === 0);
|
|
320
320
|
if (request.slope !== undefined) {
|
|
321
|
-
yield
|
|
321
|
+
yield utils_2.runWithRetries(() => __awaiter(this, void 0, void 0, function* () { return yield this.sendTrackResistance(request.slope); }), 2, 100);
|
|
322
322
|
}
|
|
323
323
|
if (request.targetPower !== undefined) {
|
|
324
|
-
yield
|
|
324
|
+
yield utils_2.runWithRetries(() => __awaiter(this, void 0, void 0, function* () { return yield this.sendTargetPower(request.targetPower); }), 2, 100);
|
|
325
325
|
}
|
|
326
326
|
else if (request.maxPower !== undefined) {
|
|
327
327
|
if (this.data.power && this.data.power > request.maxPower)
|
|
328
|
-
yield
|
|
328
|
+
yield utils_2.runWithRetries(() => __awaiter(this, void 0, void 0, function* () { return yield this.sendTargetPower(request.maxPower); }), 2, 100);
|
|
329
329
|
}
|
|
330
330
|
else if (request.minPower !== undefined) {
|
|
331
331
|
if (this.data.power && this.data.power < request.minPower)
|
|
332
|
-
yield
|
|
332
|
+
yield utils_2.runWithRetries(() => __awaiter(this, void 0, void 0, function* () { return yield this.sendTargetPower(request.minPower); }), 2, 100);
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
catch (err) {
|
|
@@ -414,7 +414,7 @@ class AntFEAdapter extends AntAdapter_1.default {
|
|
|
414
414
|
this.currentCmd = this.queue.dequeue();
|
|
415
415
|
this.currentCmd.tsStart = Date.now();
|
|
416
416
|
const { msg, logStr } = this.currentCmd;
|
|
417
|
-
this.logger.logEvent({ message: "sending", cmd: logStr, msg:
|
|
417
|
+
this.logger.logEvent({ message: "sending", cmd: logStr, msg: utils_2.hexstr(msg), queueSize: this.queue.size() });
|
|
418
418
|
if (this.stick)
|
|
419
419
|
this.stick.write(msg);
|
|
420
420
|
}
|
|
@@ -43,7 +43,7 @@ class AntHrmAdapter extends AntAdapter_1.default {
|
|
|
43
43
|
getDisplayName() {
|
|
44
44
|
const { DeviceID, manID, ComputedHeartRate } = this.deviceData;
|
|
45
45
|
const hrmStr = ComputedHeartRate ? ` (${ComputedHeartRate})` : '';
|
|
46
|
-
return `${
|
|
46
|
+
return `${utils_1.getBrand(manID)} Hrm ${DeviceID}${hrmStr}`;
|
|
47
47
|
}
|
|
48
48
|
onDeviceData(deviceData) {
|
|
49
49
|
if (!this.started)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import AntAdapter from '../AntAdapter';
|
|
2
|
+
export default class AntFEAdapter extends AntAdapter {
|
|
3
|
+
started: boolean;
|
|
4
|
+
starting: boolean;
|
|
5
|
+
connected: boolean;
|
|
6
|
+
distanceInternal?: number;
|
|
7
|
+
workerId?: any;
|
|
8
|
+
currentCmd?: any;
|
|
9
|
+
constructor(DeviceID: any, port: any, stick: any, protocol: any);
|
|
10
|
+
isBike(): boolean;
|
|
11
|
+
isHrm(): boolean;
|
|
12
|
+
isPower(): boolean;
|
|
13
|
+
getProfile(): string;
|
|
14
|
+
getName(): string;
|
|
15
|
+
getDisplayName(): string;
|
|
16
|
+
onAttached(): void;
|
|
17
|
+
getLogData(data: any, excludeList: any): any;
|
|
18
|
+
onDeviceData(deviceData: any): void;
|
|
19
|
+
onDeviceEvent(data: any): void;
|
|
20
|
+
updateData(data: any, deviceData: any): any;
|
|
21
|
+
transformData(bikeData: any): any;
|
|
22
|
+
start(props?: any): Promise<any>;
|
|
23
|
+
stop(): Promise<boolean>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,252 @@
|
|
|
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
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
16
|
+
const AntAdapter_1 = __importDefault(require("../AntAdapter"));
|
|
17
|
+
const utils_1 = require("../utils");
|
|
18
|
+
const floatVal = (d) => d ? parseFloat(d) : d;
|
|
19
|
+
const intVal = (d) => d ? parseInt(d) : d;
|
|
20
|
+
const hex = (v) => Math.abs(v).toString(16).toUpperCase();
|
|
21
|
+
const DEFAULT_START_TIMEOUT = 5000;
|
|
22
|
+
class AntFEAdapter extends AntAdapter_1.default {
|
|
23
|
+
constructor(DeviceID, port, stick, protocol) {
|
|
24
|
+
super(protocol);
|
|
25
|
+
this.logger = new gd_eventlog_1.EventLogger('Ant+PWR');
|
|
26
|
+
this.logger.logEvent({ message: 'Ant+PWR Adapter created', DeviceID, port });
|
|
27
|
+
this.deviceID = DeviceID;
|
|
28
|
+
this.port = port;
|
|
29
|
+
this.stick = stick;
|
|
30
|
+
this.deviceData = {
|
|
31
|
+
DeviceID
|
|
32
|
+
};
|
|
33
|
+
this.data = {};
|
|
34
|
+
this.started = false;
|
|
35
|
+
this.starting = false;
|
|
36
|
+
this.connected = false;
|
|
37
|
+
}
|
|
38
|
+
isBike() { return true; }
|
|
39
|
+
isHrm() { return false; }
|
|
40
|
+
isPower() { return true; }
|
|
41
|
+
getProfile() {
|
|
42
|
+
return 'Power Meter';
|
|
43
|
+
}
|
|
44
|
+
getName() {
|
|
45
|
+
return `Ant+PWR ${this.deviceID}`;
|
|
46
|
+
}
|
|
47
|
+
getDisplayName() {
|
|
48
|
+
const { DeviceID, ManId } = this.deviceData;
|
|
49
|
+
return `${utils_1.getBrand(ManId)} PWR ${DeviceID}`;
|
|
50
|
+
}
|
|
51
|
+
onAttached() {
|
|
52
|
+
this.logger.logEvent({ message: 'Device connected' });
|
|
53
|
+
this.connected = true;
|
|
54
|
+
}
|
|
55
|
+
getLogData(data, excludeList) {
|
|
56
|
+
const logData = JSON.parse(JSON.stringify(data));
|
|
57
|
+
excludeList.forEach((key) => {
|
|
58
|
+
delete logData[key];
|
|
59
|
+
});
|
|
60
|
+
return logData;
|
|
61
|
+
}
|
|
62
|
+
onDeviceData(deviceData) {
|
|
63
|
+
if (!this.started || this.isStopped())
|
|
64
|
+
return;
|
|
65
|
+
this.deviceData = deviceData;
|
|
66
|
+
try {
|
|
67
|
+
if (this.onDataFn && !(this.ignoreBike && this.ignorePower) && !this.paused) {
|
|
68
|
+
if (!this.lastUpdate || (Date.now() - this.lastUpdate) > this.updateFrequency) {
|
|
69
|
+
const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
|
|
70
|
+
this.logger.logEvent({ message: 'onDeviceData', data: logData });
|
|
71
|
+
this.data = this.updateData(this.data, deviceData);
|
|
72
|
+
const data = this.transformData(this.data);
|
|
73
|
+
this.onDataFn(data);
|
|
74
|
+
this.lastUpdate = Date.now();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
onDeviceEvent(data) {
|
|
82
|
+
try {
|
|
83
|
+
const cmdInfo = this.currentCmd;
|
|
84
|
+
if (!cmdInfo)
|
|
85
|
+
return;
|
|
86
|
+
const msg = cmdInfo.msg.readUInt8(2);
|
|
87
|
+
const Constants = this.getProtocol().getAnt().Constants;
|
|
88
|
+
const { expectedResponse } = cmdInfo;
|
|
89
|
+
if (data.message === msg) {
|
|
90
|
+
if (expectedResponse === undefined && data.code === Constants.EVENT_TRANSFER_TX_COMPLETED) {
|
|
91
|
+
this.currentCmd.response = { success: true, message: hex(data.message), code: hex(data.code) };
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (expectedResponse === undefined && data.code !== Constants.EVENT_TRANSFER_TX_COMPLETED) {
|
|
95
|
+
this.currentCmd.response = { success: false, message: hex(data.message), code: hex(data.code) };
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (data.message === 1) {
|
|
100
|
+
if (expectedResponse !== undefined && data.code === expectedResponse) {
|
|
101
|
+
this.currentCmd.response = { success: true, message: hex(data.message), code: hex(data.code) };
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (expectedResponse === undefined && (data.code === Constants.EVENT_TRANSFER_TX_COMPLETED || data.code === 3)) {
|
|
105
|
+
this.currentCmd.response = { success: true, message: hex(data.message), code: hex(data.code) };
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (data.code === Constants.EVENT_TRANSFER_TX_FAILED || data.code === Constants.EVENT_CHANNEL_COLLISION) {
|
|
109
|
+
this.currentCmd.response = { success: false, message: hex(data.message), code: hex(data.code) };
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (this.currentCmd !== undefined && data.message === Constants.MESSAGE_CHANNEL_ACKNOWLEDGED_DATA && data.code === 31) {
|
|
114
|
+
this.logger.log("could not send (TRANSFER_IN_PROGRESS)");
|
|
115
|
+
this.currentCmd.response = { success: false, message: hex(data.message), code: hex(data.code) };
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
this.logger.logEvent({ message: "Incoming Event ", event: { message: hex(data.message), code: hex(data.code) } });
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
this.logger.logEvent({ message: 'Error', fn: 'parseEvent', event: { message: hex(data.message), code: hex(data.code) }, error: err.message || err });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
updateData(data, deviceData) {
|
|
125
|
+
return;
|
|
126
|
+
if (data.distanceOffs === undefined)
|
|
127
|
+
data.distanceOffs = 0;
|
|
128
|
+
data.speed = (deviceData.VirtualSpeed !== undefined ? deviceData.VirtualSpeed : deviceData.RealSpeed) * 3.6;
|
|
129
|
+
data.slope = (deviceData.Incline !== undefined ? deviceData.Incline : data.slope);
|
|
130
|
+
data.power = (deviceData.InstantaneousPower !== undefined ? deviceData.InstantaneousPower : data.power);
|
|
131
|
+
data.pedalRpm = (deviceData.Cadence !== undefined ? deviceData.Cadence : data.pedalRpm);
|
|
132
|
+
data.heartrate = (deviceData.HeartRate !== undefined ? deviceData.HeartRate : data.heartrate);
|
|
133
|
+
if (deviceData.Distance !== undefined && deviceData.Distance !== 0) {
|
|
134
|
+
data.distanceInternal = deviceData.Distance - data.distanceOffs;
|
|
135
|
+
data.distance = data.distanceInternal / 1000;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
if (this.lastUpdate && deviceData.Cadence !== undefined && deviceData.Cadence > 0 && data.speed) {
|
|
139
|
+
const t = (Date.now() - this.lastUpdate) / 1000;
|
|
140
|
+
const prevDistance = data.distanceInternal || 0;
|
|
141
|
+
data.distanceInternal = Math.round(data.speed / 3.6 * t) + prevDistance;
|
|
142
|
+
data.distance = data.distanceInternal / 1000;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return data;
|
|
146
|
+
}
|
|
147
|
+
transformData(bikeData) {
|
|
148
|
+
return;
|
|
149
|
+
if (bikeData === undefined)
|
|
150
|
+
return;
|
|
151
|
+
let distance = 0;
|
|
152
|
+
if (this.distanceInternal !== undefined && bikeData.distanceInternal !== undefined) {
|
|
153
|
+
distance = intVal(bikeData.distanceInternal - this.distanceInternal);
|
|
154
|
+
}
|
|
155
|
+
if (bikeData.distanceInternal !== undefined)
|
|
156
|
+
this.distanceInternal = bikeData.distanceInternal;
|
|
157
|
+
let data = {
|
|
158
|
+
speed: floatVal(bikeData.speed),
|
|
159
|
+
slope: floatVal(bikeData.slope),
|
|
160
|
+
power: intVal(bikeData.power),
|
|
161
|
+
cadence: intVal(bikeData.pedalRpm),
|
|
162
|
+
heartrate: intVal(bikeData.heartrate),
|
|
163
|
+
distance,
|
|
164
|
+
timestamp: Date.now()
|
|
165
|
+
};
|
|
166
|
+
if (this.ignorePower) {
|
|
167
|
+
delete data.power;
|
|
168
|
+
delete data.cadence;
|
|
169
|
+
}
|
|
170
|
+
if (this.ignoreBike) {
|
|
171
|
+
data = { heartrate: data.heartrate };
|
|
172
|
+
}
|
|
173
|
+
if (this.ignoreHrm)
|
|
174
|
+
delete data.heartrate;
|
|
175
|
+
return data;
|
|
176
|
+
}
|
|
177
|
+
start(props) {
|
|
178
|
+
const _super = Object.create(null, {
|
|
179
|
+
start: { get: () => super.start }
|
|
180
|
+
});
|
|
181
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
182
|
+
yield _super.start.call(this, props);
|
|
183
|
+
this.logger.logEvent({ message: 'start()', props });
|
|
184
|
+
const opts = props || {};
|
|
185
|
+
const { args = {} } = opts;
|
|
186
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
if (this.ignoreBike && this.ignorePower) {
|
|
188
|
+
this.logger.logEvent({ message: 'start() not done: bike disabled' });
|
|
189
|
+
return resolve(false);
|
|
190
|
+
}
|
|
191
|
+
if (this.starting) {
|
|
192
|
+
this.logger.logEvent({ message: 'start() not done: bike starting' });
|
|
193
|
+
return resolve(false);
|
|
194
|
+
}
|
|
195
|
+
if (this.started) {
|
|
196
|
+
this.logger.logEvent({ message: 'start() done: bike was already started' });
|
|
197
|
+
return resolve(true);
|
|
198
|
+
}
|
|
199
|
+
this.starting = true;
|
|
200
|
+
const Ant = this.getProtocol().getAnt();
|
|
201
|
+
const protocol = this.getProtocol();
|
|
202
|
+
let start = Date.now();
|
|
203
|
+
let timeout = start + (args.timeout || DEFAULT_START_TIMEOUT);
|
|
204
|
+
const iv = setInterval(() => {
|
|
205
|
+
if (Date.now() > timeout) {
|
|
206
|
+
clearInterval(iv);
|
|
207
|
+
this.starting = false;
|
|
208
|
+
reject(new Error('timeout'));
|
|
209
|
+
}
|
|
210
|
+
if (this.isStopped()) {
|
|
211
|
+
clearInterval(iv);
|
|
212
|
+
this.starting = false;
|
|
213
|
+
reject(new Error('stopped'));
|
|
214
|
+
}
|
|
215
|
+
}, 100);
|
|
216
|
+
protocol.attachSensors(this, Ant.BicyclePowerSensor, 'powerData')
|
|
217
|
+
.then(() => {
|
|
218
|
+
this.starting = false;
|
|
219
|
+
this.started = true;
|
|
220
|
+
clearInterval(iv);
|
|
221
|
+
resolve(true);
|
|
222
|
+
})
|
|
223
|
+
.catch(err => reject(err));
|
|
224
|
+
}));
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
stop() {
|
|
228
|
+
const _super = Object.create(null, {
|
|
229
|
+
stop: { get: () => super.stop }
|
|
230
|
+
});
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
yield _super.stop.call(this);
|
|
233
|
+
this.logger.logEvent({ message: 'stop()' });
|
|
234
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
235
|
+
this.starting = false;
|
|
236
|
+
return resolve(true);
|
|
237
|
+
this.started = false;
|
|
238
|
+
if (this.ignoreHrm)
|
|
239
|
+
return resolve(false);
|
|
240
|
+
try {
|
|
241
|
+
const protocol = this.getProtocol();
|
|
242
|
+
yield protocol.detachSensor(this);
|
|
243
|
+
resolve(true);
|
|
244
|
+
}
|
|
245
|
+
catch (err) {
|
|
246
|
+
reject(err);
|
|
247
|
+
}
|
|
248
|
+
}));
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
exports.default = AntFEAdapter;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import AntAdapter from '../AntAdapter';
|
|
2
|
+
import { IncyclistBikeData } from '../../CyclingMode';
|
|
3
|
+
import CyclingMode from '../../CyclingMode';
|
|
4
|
+
import { DeviceData } from '../../Device';
|
|
5
|
+
export declare type AntPwrData = {
|
|
6
|
+
DeviceID: number;
|
|
7
|
+
PedalPower?: number;
|
|
8
|
+
RightPedalPower?: number;
|
|
9
|
+
LeftPedalPower?: number;
|
|
10
|
+
Cadence?: number;
|
|
11
|
+
AccumulatedPower?: number;
|
|
12
|
+
Power?: number;
|
|
13
|
+
offset?: number;
|
|
14
|
+
EventCount?: number;
|
|
15
|
+
TimeStamp?: number;
|
|
16
|
+
Slope?: number;
|
|
17
|
+
TorqueTicksStamp?: number;
|
|
18
|
+
CalculatedCadence?: number;
|
|
19
|
+
CalculatedTorque?: number;
|
|
20
|
+
CalculatedPower?: number;
|
|
21
|
+
};
|
|
22
|
+
export default class AntFEAdapter extends AntAdapter {
|
|
23
|
+
started: boolean;
|
|
24
|
+
starting: boolean;
|
|
25
|
+
connected: boolean;
|
|
26
|
+
distanceInternal?: number;
|
|
27
|
+
workerId?: any;
|
|
28
|
+
currentCmd?: any;
|
|
29
|
+
mode: CyclingMode;
|
|
30
|
+
constructor(DeviceID: any, port: any, stick: any, protocol: any);
|
|
31
|
+
isBike(): boolean;
|
|
32
|
+
isHrm(): boolean;
|
|
33
|
+
isPower(): boolean;
|
|
34
|
+
getProfile(): string;
|
|
35
|
+
getName(): string;
|
|
36
|
+
getDisplayName(): string;
|
|
37
|
+
getCyclingMode(): CyclingMode;
|
|
38
|
+
getDefaultCyclingMode(): CyclingMode;
|
|
39
|
+
onAttached(): void;
|
|
40
|
+
getLogData(data: any, excludeList: any): any;
|
|
41
|
+
onDeviceData(deviceData: AntPwrData): void;
|
|
42
|
+
onDeviceEvent(data: any): void;
|
|
43
|
+
sendUpdate(request: any): void;
|
|
44
|
+
mapData(deviceData: AntPwrData): IncyclistBikeData;
|
|
45
|
+
transformData(bikeData: IncyclistBikeData): DeviceData;
|
|
46
|
+
start(props?: any): Promise<any>;
|
|
47
|
+
stop(): Promise<boolean>;
|
|
48
|
+
}
|