incyclist-devices 1.5.15 → 1.5.17
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/ant-device.d.ts +5 -0
- package/lib/antv2/ant-device.js +20 -0
- package/lib/antv2/fe.js +3 -0
- package/lib/antv2/hr.js +3 -0
- package/lib/antv2/pwr.js +3 -1
- package/lib/ble/fm.js +2 -1
- package/lib/daum/classic/DaumClassicAdapter.d.ts +2 -2
- package/lib/daum/classic/DaumClassicAdapter.js +25 -12
- package/lib/daum/premium/DaumPremiumAdapter.d.ts +1 -1
- package/lib/daum/premium/DaumPremiumAdapter.js +19 -6
- package/lib/device.d.ts +3 -1
- package/lib/device.js +6 -1
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { Device } from '../protocol';
|
|
2
3
|
import { IChannel, ISensor } from 'incyclist-ant-plus';
|
|
3
4
|
import AntProtocol from './incyclist-protocol';
|
|
@@ -28,6 +29,8 @@ export default class AntAdapter extends IncyclistDevice implements Device {
|
|
|
28
29
|
selected: boolean;
|
|
29
30
|
settings: any;
|
|
30
31
|
onDataFn: OnDeviceDataCallback;
|
|
32
|
+
protected ivDataTimeout: NodeJS.Timer;
|
|
33
|
+
protected lastDataTS: number;
|
|
31
34
|
constructor(sensor: ISensor, protocol: AntProtocol, settings?: any);
|
|
32
35
|
isBike(): boolean;
|
|
33
36
|
isPower(): boolean;
|
|
@@ -45,6 +48,8 @@ export default class AntAdapter extends IncyclistDevice implements Device {
|
|
|
45
48
|
setIgnorePower(ignore: any): void;
|
|
46
49
|
pause(): Promise<boolean>;
|
|
47
50
|
resume(): Promise<boolean>;
|
|
51
|
+
startDataTimeoutCheck(): void;
|
|
52
|
+
stopDataTimeoutCheck(): void;
|
|
48
53
|
start(props?: any): Promise<any>;
|
|
49
54
|
stop(): Promise<boolean>;
|
|
50
55
|
isStopped(): boolean;
|
package/lib/antv2/ant-device.js
CHANGED
|
@@ -17,6 +17,7 @@ const incyclist_protocol_1 = require("./incyclist-protocol");
|
|
|
17
17
|
const ant_interface_1 = __importDefault(require("./ant-interface"));
|
|
18
18
|
const device_1 = __importDefault(require("../device"));
|
|
19
19
|
exports.DEFAULT_UPDATE_FREQUENCY = 1000;
|
|
20
|
+
const NO_DATA_TIMEOUT = 5000;
|
|
20
21
|
class AntAdapter extends device_1.default {
|
|
21
22
|
constructor(sensor, protocol, settings) {
|
|
22
23
|
super(protocol, settings);
|
|
@@ -92,6 +93,24 @@ class AntAdapter extends device_1.default {
|
|
|
92
93
|
resolve(true);
|
|
93
94
|
});
|
|
94
95
|
}
|
|
96
|
+
startDataTimeoutCheck() {
|
|
97
|
+
if (this.ivDataTimeout)
|
|
98
|
+
return;
|
|
99
|
+
this.ivDataTimeout = setInterval(() => {
|
|
100
|
+
console.log('~~~ check', this.lastDataTS);
|
|
101
|
+
if (!this.lastDataTS)
|
|
102
|
+
return;
|
|
103
|
+
if (this.lastDataTS + NO_DATA_TIMEOUT < Date.now()) {
|
|
104
|
+
this.emit('disconnected', Date.now() - this.lastDataTS);
|
|
105
|
+
}
|
|
106
|
+
}, 1000);
|
|
107
|
+
}
|
|
108
|
+
stopDataTimeoutCheck() {
|
|
109
|
+
if (!this.ivDataTimeout)
|
|
110
|
+
return;
|
|
111
|
+
clearInterval(this.ivDataTimeout);
|
|
112
|
+
this.ivDataTimeout = undefined;
|
|
113
|
+
}
|
|
95
114
|
start(props) {
|
|
96
115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
97
116
|
if (props && props.user)
|
|
@@ -104,6 +123,7 @@ class AntAdapter extends device_1.default {
|
|
|
104
123
|
}
|
|
105
124
|
stop() {
|
|
106
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
this.stopDataTimeoutCheck();
|
|
107
127
|
this.stopped = true;
|
|
108
128
|
return true;
|
|
109
129
|
});
|
package/lib/antv2/fe.js
CHANGED
|
@@ -112,6 +112,9 @@ class AntFEAdapter extends ant_device_1.default {
|
|
|
112
112
|
if (!this.started || this.isStopped())
|
|
113
113
|
return;
|
|
114
114
|
this.deviceData = deviceData;
|
|
115
|
+
this.lastDataTS = Date.now();
|
|
116
|
+
if (!this.ivDataTimeout)
|
|
117
|
+
this.startDataTimeoutCheck();
|
|
115
118
|
try {
|
|
116
119
|
const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
|
|
117
120
|
this.logger.logEvent({ message: 'onDeviceData', data: logData });
|
package/lib/antv2/hr.js
CHANGED
|
@@ -40,6 +40,9 @@ class AntHrAdapter extends ant_device_1.default {
|
|
|
40
40
|
if (!this.started)
|
|
41
41
|
return;
|
|
42
42
|
this.deviceData = deviceData;
|
|
43
|
+
this.lastDataTS = Date.now();
|
|
44
|
+
if (!this.ivDataTimeout)
|
|
45
|
+
this.startDataTimeoutCheck();
|
|
43
46
|
try {
|
|
44
47
|
if (this.onDataFn && !this.ignoreHrm && !this.paused) {
|
|
45
48
|
if (this.lastUpdate === undefined || (Date.now() - this.lastUpdate) > this.updateFrequency) {
|
package/lib/antv2/pwr.js
CHANGED
|
@@ -58,7 +58,9 @@ class AntPwrAdapter extends ant_device_1.default {
|
|
|
58
58
|
if (!this.started)
|
|
59
59
|
return;
|
|
60
60
|
this.deviceData = deviceData;
|
|
61
|
-
this.
|
|
61
|
+
this.lastDataTS = Date.now();
|
|
62
|
+
if (!this.ivDataTimeout)
|
|
63
|
+
this.startDataTimeoutCheck();
|
|
62
64
|
try {
|
|
63
65
|
if (this.onDataFn && !(this.ignoreBike && this.ignorePower) && !this.paused) {
|
|
64
66
|
if (!this.lastUpdate || (Date.now() - this.lastUpdate) > this.updateFrequency) {
|
package/lib/ble/fm.js
CHANGED
|
@@ -554,7 +554,7 @@ class FmAdapter extends device_1.default {
|
|
|
554
554
|
if (this.device)
|
|
555
555
|
this.device.setLogger(this.logger);
|
|
556
556
|
}
|
|
557
|
-
isBike() { return this.device.isBike(); }
|
|
557
|
+
isBike() { return this.device.isBike() || this.device.isPower(); }
|
|
558
558
|
isHrm() { return this.device.isHrm(); }
|
|
559
559
|
isPower() { return this.device.isPower(); }
|
|
560
560
|
isSame(device) {
|
|
@@ -708,6 +708,7 @@ class FmAdapter extends device_1.default {
|
|
|
708
708
|
bleDevice.on('data', (data) => {
|
|
709
709
|
this.onDeviceData(data);
|
|
710
710
|
});
|
|
711
|
+
bleDevice.on('disconnected', this.emit);
|
|
711
712
|
return true;
|
|
712
713
|
}
|
|
713
714
|
}
|
|
@@ -15,10 +15,10 @@ export default class DaumClassicAdapter extends DaumAdapter {
|
|
|
15
15
|
pause(): Promise<boolean>;
|
|
16
16
|
resume(): Promise<boolean>;
|
|
17
17
|
check(): Promise<unknown>;
|
|
18
|
-
|
|
18
|
+
startRide(props: any): Promise<boolean>;
|
|
19
19
|
start(props: any): Promise<boolean>;
|
|
20
20
|
launch(props: any, isRelaunch?: boolean): Promise<boolean>;
|
|
21
|
-
|
|
21
|
+
performStart(props?: {
|
|
22
22
|
user?: any;
|
|
23
23
|
bikeSettings?: any;
|
|
24
24
|
gear?: any;
|
|
@@ -58,7 +58,6 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
58
58
|
pause: { get: () => super.pause }
|
|
59
59
|
});
|
|
60
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
console.log('~~~~~~~~~~ PAUSE');
|
|
62
61
|
const paused = yield _super.pause.call(this);
|
|
63
62
|
this.bike.pauseLogging();
|
|
64
63
|
return paused;
|
|
@@ -100,34 +99,46 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
100
99
|
}
|
|
101
100
|
}));
|
|
102
101
|
}
|
|
103
|
-
|
|
102
|
+
startRide(props) {
|
|
104
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
this.logger.logEvent({ message: 'relaunch
|
|
104
|
+
this.logger.logEvent({ message: 'relaunch of device' });
|
|
106
105
|
return yield this.launch(props, true);
|
|
107
106
|
});
|
|
108
107
|
}
|
|
109
108
|
start(props) {
|
|
110
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
-
this.logger.logEvent({ message: 'start
|
|
110
|
+
this.logger.logEvent({ message: 'initial start of device' });
|
|
112
111
|
return yield this.launch(props, false);
|
|
113
112
|
});
|
|
114
113
|
}
|
|
115
114
|
launch(props, isRelaunch = false) {
|
|
116
115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
.
|
|
116
|
+
try {
|
|
117
|
+
if (isRelaunch) {
|
|
118
|
+
yield this.stop();
|
|
119
|
+
}
|
|
120
|
+
yield this.performStart(props);
|
|
121
|
+
if (!isRelaunch) {
|
|
122
|
+
try {
|
|
123
|
+
const version = yield this.bike.getVersion();
|
|
124
|
+
const { serialNo, cockpit } = version || {};
|
|
125
|
+
this.logEvent({ message: 'device info', deviceInfo: { serialNo, cockpit } });
|
|
126
|
+
}
|
|
127
|
+
catch (_a) { }
|
|
128
|
+
}
|
|
122
129
|
this.stopped = false;
|
|
123
130
|
this.paused = false;
|
|
124
131
|
this.startUpdatePull();
|
|
125
132
|
return true;
|
|
126
|
-
}
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
this.logger.logEvent({ message: 'start result: error', error: err.message });
|
|
136
|
+
throw new Error(`could not start device, reason:${err.message}`);
|
|
137
|
+
}
|
|
127
138
|
});
|
|
128
139
|
}
|
|
129
|
-
|
|
130
|
-
this.
|
|
140
|
+
performStart(props = {}) {
|
|
141
|
+
this.stop();
|
|
131
142
|
const { user, bikeSettings } = props;
|
|
132
143
|
if (user && user.weight)
|
|
133
144
|
this.userSettings.weight = user.weight;
|
|
@@ -182,6 +193,8 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
182
193
|
}), 5, 1000);
|
|
183
194
|
}
|
|
184
195
|
getCurrentBikeData() {
|
|
196
|
+
if (this.stopped)
|
|
197
|
+
return;
|
|
185
198
|
return this.getBike().runData();
|
|
186
199
|
}
|
|
187
200
|
}
|
|
@@ -9,7 +9,7 @@ export default class DaumPremiumDevice extends DaumAdapter {
|
|
|
9
9
|
check(): Promise<unknown>;
|
|
10
10
|
pause(): Promise<boolean>;
|
|
11
11
|
resume(): Promise<boolean>;
|
|
12
|
-
|
|
12
|
+
startRide(props: any): Promise<boolean>;
|
|
13
13
|
start(props: any): Promise<boolean>;
|
|
14
14
|
launch(props: any, isRelaunch?: boolean): Promise<boolean>;
|
|
15
15
|
getCurrentBikeData(): Promise<any>;
|
|
@@ -82,16 +82,30 @@ class DaumPremiumDevice extends DaumAdapter_1.default {
|
|
|
82
82
|
return resumed;
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
|
-
|
|
85
|
+
startRide(props) {
|
|
86
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
this.logger.logEvent({ message: 'relaunch
|
|
88
|
-
|
|
87
|
+
this.logger.logEvent({ message: 'relaunch of device' });
|
|
88
|
+
try {
|
|
89
|
+
yield this.launch(props, true);
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
this.logger.logEvent({ message: 'start result: error', error: err.message });
|
|
94
|
+
throw new Error(`could not start device, reason:${err.message}`);
|
|
95
|
+
}
|
|
89
96
|
});
|
|
90
97
|
}
|
|
91
98
|
start(props) {
|
|
92
99
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
this.logger.logEvent({ message: 'start
|
|
94
|
-
|
|
100
|
+
this.logger.logEvent({ message: 'initial start of device' });
|
|
101
|
+
try {
|
|
102
|
+
yield this.launch(props, false);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
this.logger.logEvent({ message: 'start result: error', error: err.message });
|
|
107
|
+
throw new Error(`could not start device, reason:${err.message}`);
|
|
108
|
+
}
|
|
95
109
|
});
|
|
96
110
|
}
|
|
97
111
|
launch(props, isRelaunch = false) {
|
|
@@ -138,7 +152,6 @@ class DaumPremiumDevice extends DaumAdapter_1.default {
|
|
|
138
152
|
return;
|
|
139
153
|
}
|
|
140
154
|
catch (err) {
|
|
141
|
-
console.error(err);
|
|
142
155
|
throw (new Error(`could not start device, reason:${err.message}`));
|
|
143
156
|
}
|
|
144
157
|
}), 5, 1500)
|
package/lib/device.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { DeviceProtocol, Device } from './protocol';
|
|
2
3
|
import CyclingMode from './cycling-mode';
|
|
4
|
+
import EventEmitter from 'events';
|
|
3
5
|
export declare const DEFAULT_BIKE_WEIGHT = 10;
|
|
4
6
|
export declare const DEFAULT_USER_WEIGHT = 75;
|
|
5
7
|
export declare type DeviceData = {
|
|
@@ -50,7 +52,7 @@ export interface DeviceAdapter extends Device {
|
|
|
50
52
|
sendUpdate(request: any): void;
|
|
51
53
|
onData(callback: OnDeviceDataCallback): void;
|
|
52
54
|
}
|
|
53
|
-
export default class IncyclistDevice implements DeviceAdapter {
|
|
55
|
+
export default class IncyclistDevice extends EventEmitter implements DeviceAdapter {
|
|
54
56
|
protocol: DeviceProtocol;
|
|
55
57
|
detected: boolean;
|
|
56
58
|
selected: boolean;
|
package/lib/device.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
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
6
|
exports.DEFAULT_USER_WEIGHT = exports.DEFAULT_BIKE_WEIGHT = void 0;
|
|
7
|
+
const events_1 = __importDefault(require("events"));
|
|
4
8
|
exports.DEFAULT_BIKE_WEIGHT = 10;
|
|
5
9
|
exports.DEFAULT_USER_WEIGHT = 75;
|
|
6
|
-
class IncyclistDevice {
|
|
10
|
+
class IncyclistDevice extends events_1.default {
|
|
7
11
|
constructor(proto, settings) {
|
|
12
|
+
super();
|
|
8
13
|
this.protocol = proto;
|
|
9
14
|
this.detected = false;
|
|
10
15
|
this.selected = false;
|