incyclist-devices 2.0.28 → 2.0.30
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/adapter.d.ts +1 -0
- package/lib/antv2/adapter.js +10 -0
- package/lib/antv2/fe/adapter.js +8 -8
- package/lib/antv2/hr/adapter.js +2 -0
- package/lib/base/adpater.js +1 -1
- package/lib/serial/daum/DaumAdapter.js +2 -1
- package/lib/serial/daum/classic/adapter.d.ts +2 -0
- package/lib/serial/daum/classic/adapter.js +26 -1
- package/lib/serial/daum/classic/comms.js +19 -10
- package/lib/serial/serial-interface.js +4 -4
- package/package.json +1 -1
package/lib/antv2/adapter.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export default class AntAdapter<TDeviceData extends BaseDeviceData, TData> exten
|
|
|
33
33
|
protected dataMsgCount: number;
|
|
34
34
|
protected ivWaitForData: NodeJS.Timeout;
|
|
35
35
|
constructor(settings: AntDeviceSettings, props?: DeviceProperties);
|
|
36
|
+
logEvent(event: any): void;
|
|
36
37
|
createSensor(settings: AntDeviceSettings): ISensor;
|
|
37
38
|
isEqual(settings: AntDeviceSettings): boolean;
|
|
38
39
|
connect(): Promise<boolean>;
|
package/lib/antv2/adapter.js
CHANGED
|
@@ -63,6 +63,16 @@ class AntAdapter extends adpater_1.default {
|
|
|
63
63
|
this.channel = undefined;
|
|
64
64
|
this.ant = ant_interface_1.default.getInstance();
|
|
65
65
|
}
|
|
66
|
+
logEvent(event) {
|
|
67
|
+
if (!this.logger || this.paused)
|
|
68
|
+
return;
|
|
69
|
+
this.logger.logEvent(event);
|
|
70
|
+
const w = global.window;
|
|
71
|
+
if ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || process.env.BLE_DEBUG || process.env.ANT_DEBUG) {
|
|
72
|
+
const logText = '~~~ ANT:' + this.logger.getName();
|
|
73
|
+
console.log(logText, event);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
66
76
|
createSensor(settings) {
|
|
67
77
|
throw new Error('Method not implemented.');
|
|
68
78
|
}
|
package/lib/antv2/fe/adapter.js
CHANGED
|
@@ -90,7 +90,7 @@ class AntFEAdapter extends adapter_1.ControllableAntAdapter {
|
|
|
90
90
|
const update = isReset ? this.getCyclingMode().getBikeInitRequest() : this.getCyclingMode().sendBikeUpdate(request);
|
|
91
91
|
if (!update)
|
|
92
92
|
return;
|
|
93
|
-
this.
|
|
93
|
+
this.logEvent({ message: 'send bike update requested', update, request });
|
|
94
94
|
try {
|
|
95
95
|
const fe = this.sensor;
|
|
96
96
|
if (update.slope !== undefined) {
|
|
@@ -107,7 +107,7 @@ class AntFEAdapter extends adapter_1.ControllableAntAdapter {
|
|
|
107
107
|
yield this.reconnect();
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
this.
|
|
110
|
+
this.logEvent({ message: 'sendBikeUpdate() error', error: err.message });
|
|
111
111
|
}
|
|
112
112
|
});
|
|
113
113
|
}
|
|
@@ -122,7 +122,7 @@ class AntFEAdapter extends adapter_1.ControllableAntAdapter {
|
|
|
122
122
|
}
|
|
123
123
|
try {
|
|
124
124
|
const logData = this.getLogData(deviceData, ['PairedDevices', 'RawData']);
|
|
125
|
-
this.
|
|
125
|
+
this.logEvent({ message: 'onDeviceData', data: logData, paused: this.paused });
|
|
126
126
|
if (!this.canSendUpdate())
|
|
127
127
|
return;
|
|
128
128
|
let incyclistData = this.mapToCycleModeData(deviceData);
|
|
@@ -131,7 +131,7 @@ class AntFEAdapter extends adapter_1.ControllableAntAdapter {
|
|
|
131
131
|
this.emitData(this.data);
|
|
132
132
|
}
|
|
133
133
|
catch (err) {
|
|
134
|
-
this.
|
|
134
|
+
this.logEvent({ message: 'error', fn: 'onDeviceData()', error: err.message || err, stack: err.stack });
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
canSendUpdate() {
|
|
@@ -274,7 +274,7 @@ class AntFEAdapter extends adapter_1.ControllableAntAdapter {
|
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
276
|
catch (err) {
|
|
277
|
-
this.
|
|
277
|
+
this.logEvent({ message: 'sending FE message error', error: err.message });
|
|
278
278
|
this.started = false;
|
|
279
279
|
}
|
|
280
280
|
success = status.userSent && status.slopeSent;
|
|
@@ -318,18 +318,18 @@ class AntFEAdapter extends adapter_1.ControllableAntAdapter {
|
|
|
318
318
|
}
|
|
319
319
|
reconnect() {
|
|
320
320
|
return __awaiter(this, void 0, void 0, function* () {
|
|
321
|
-
this.
|
|
321
|
+
this.logEvent({ message: 'reconnect to device' });
|
|
322
322
|
this.isReconnecting = true;
|
|
323
323
|
try {
|
|
324
324
|
yield this.stop();
|
|
325
325
|
yield this.start(this.startProps);
|
|
326
326
|
this.started = true;
|
|
327
327
|
this.isReconnecting = false;
|
|
328
|
-
this.
|
|
328
|
+
this.logEvent({ message: 'reconnect success' });
|
|
329
329
|
return true;
|
|
330
330
|
}
|
|
331
331
|
catch (err) {
|
|
332
|
-
this.
|
|
332
|
+
this.logEvent({ message: 'reconnect failed' });
|
|
333
333
|
this.isReconnecting = false;
|
|
334
334
|
return false;
|
|
335
335
|
}
|
package/lib/antv2/hr/adapter.js
CHANGED
package/lib/base/adpater.js
CHANGED
|
@@ -67,7 +67,7 @@ class IncyclistDevice extends events_1.default {
|
|
|
67
67
|
this.logger.logEvent(event);
|
|
68
68
|
const w = global.window;
|
|
69
69
|
if ((w === null || w === void 0 ? void 0 : w.DEVICE_DEBUG) || process.env.BLE_DEBUG || process.env.ANT_DEBUG) {
|
|
70
|
-
const logText = '~~~ ' + this.
|
|
70
|
+
const logText = '~~~ ' + this.logger.getName();
|
|
71
71
|
console.log(logText, event);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
@@ -148,7 +148,7 @@ class DaumAdapterBase extends adapter_1.SerialIncyclistDevice {
|
|
|
148
148
|
this.iv = undefined;
|
|
149
149
|
}
|
|
150
150
|
startUpdatePull() {
|
|
151
|
-
this.
|
|
151
|
+
this.logEvent({ message: 'start update pull', iv: this.iv, ignoreBike: this.ignoreBike, ignoreHrm: this.ignoreHrm, ignorePower: this.ignorePower });
|
|
152
152
|
if (this.iv)
|
|
153
153
|
return;
|
|
154
154
|
if (this.ignoreBike && this.ignoreHrm && this.ignorePower)
|
|
@@ -174,6 +174,7 @@ class DaumAdapterBase extends adapter_1.SerialIncyclistDevice {
|
|
|
174
174
|
return connected;
|
|
175
175
|
}
|
|
176
176
|
catch (err) {
|
|
177
|
+
yield this.bike.close();
|
|
177
178
|
return false;
|
|
178
179
|
}
|
|
179
180
|
});
|
|
@@ -11,6 +11,7 @@ export default class DaumClassicAdapter extends DaumAdapter {
|
|
|
11
11
|
id: string;
|
|
12
12
|
started: boolean;
|
|
13
13
|
startPromise: Promise<unknown>;
|
|
14
|
+
checkPromise: Promise<boolean>;
|
|
14
15
|
constructor(settings: SerialDeviceSettings, props?: DeviceProperties);
|
|
15
16
|
setID(id: any): void;
|
|
16
17
|
getID(): string;
|
|
@@ -21,6 +22,7 @@ export default class DaumClassicAdapter extends DaumAdapter {
|
|
|
21
22
|
getSupportedCyclingModes(): Array<any>;
|
|
22
23
|
getDefaultCyclingMode(): CyclingMode;
|
|
23
24
|
check(): Promise<boolean>;
|
|
25
|
+
performCheck(): Promise<boolean>;
|
|
24
26
|
pause(): Promise<boolean>;
|
|
25
27
|
resume(): Promise<boolean>;
|
|
26
28
|
startRide(props?: DaumClassicDeviceProperties): Promise<boolean>;
|
|
@@ -51,6 +51,7 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
51
51
|
this.iv = undefined;
|
|
52
52
|
this.distanceInternal = undefined;
|
|
53
53
|
this.startPromise = undefined;
|
|
54
|
+
this.checkPromise = undefined;
|
|
54
55
|
this.initData();
|
|
55
56
|
}
|
|
56
57
|
setID(id) {
|
|
@@ -81,9 +82,32 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
81
82
|
}
|
|
82
83
|
check() {
|
|
83
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
var info = {};
|
|
85
85
|
if (this.isStopped())
|
|
86
86
|
return false;
|
|
87
|
+
if (this.checkPromise) {
|
|
88
|
+
this.logEvent({ message: "waiting for previous check device", port: this.getPort() });
|
|
89
|
+
try {
|
|
90
|
+
yield this.checkPromise;
|
|
91
|
+
}
|
|
92
|
+
catch (_a) { }
|
|
93
|
+
this.logEvent({ message: "previous check device completed", port: this.getPort() });
|
|
94
|
+
this.checkPromise = undefined;
|
|
95
|
+
}
|
|
96
|
+
this.checkPromise = this.performCheck();
|
|
97
|
+
try {
|
|
98
|
+
const res = yield this.checkPromise;
|
|
99
|
+
this.checkPromise = undefined;
|
|
100
|
+
return res;
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
this.checkPromise = undefined;
|
|
104
|
+
throw err;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
performCheck() {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
var info = {};
|
|
87
111
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
88
112
|
this.logEvent({ message: "checking device", port: this.getPort() });
|
|
89
113
|
const iv = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -109,6 +133,7 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
109
133
|
resolve(true);
|
|
110
134
|
}
|
|
111
135
|
catch (err) {
|
|
136
|
+
clearTimeout(iv);
|
|
112
137
|
this.logEvent({ message: "checking device failed", port: this.getPort(), reason: err.message || err });
|
|
113
138
|
resolve(false);
|
|
114
139
|
}
|
|
@@ -94,20 +94,27 @@ class Daum8008 {
|
|
|
94
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
95
95
|
if (!this.serial)
|
|
96
96
|
return;
|
|
97
|
+
this.closing = true;
|
|
97
98
|
this.stopWorker();
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
if (this.isConnected()) {
|
|
100
|
+
try {
|
|
101
|
+
yield this.flush();
|
|
102
|
+
}
|
|
103
|
+
catch (_a) { }
|
|
104
|
+
try {
|
|
105
|
+
yield this.serial.closePort(this.portName);
|
|
106
|
+
}
|
|
107
|
+
catch (_b) { }
|
|
101
108
|
}
|
|
102
|
-
catch (_a) { }
|
|
103
109
|
this.connected = false;
|
|
104
|
-
|
|
110
|
+
this.cmdBusy = false;
|
|
111
|
+
if (this.sp) {
|
|
105
112
|
this.sp.removeAllListeners();
|
|
106
|
-
|
|
113
|
+
this.sp = null;
|
|
114
|
+
}
|
|
107
115
|
this.error = undefined;
|
|
108
116
|
this.closing = false;
|
|
109
117
|
this.closed = true;
|
|
110
|
-
this.cmdBusy = false;
|
|
111
118
|
return;
|
|
112
119
|
});
|
|
113
120
|
}
|
|
@@ -116,8 +123,9 @@ class Daum8008 {
|
|
|
116
123
|
if (!this.cmdBusy)
|
|
117
124
|
return;
|
|
118
125
|
return new Promise(done => {
|
|
126
|
+
const tsStart = Date.now();
|
|
119
127
|
const iv = setInterval(() => {
|
|
120
|
-
if (!this.cmdBusy) {
|
|
128
|
+
if (!this.cmdBusy || (Date.now() - tsStart > TIMEOUT_SEND + 500)) {
|
|
121
129
|
clearInterval(iv);
|
|
122
130
|
done();
|
|
123
131
|
}
|
|
@@ -176,7 +184,7 @@ class Daum8008 {
|
|
|
176
184
|
}
|
|
177
185
|
}
|
|
178
186
|
}
|
|
179
|
-
if (this.connected && this.cmdBusy) {
|
|
187
|
+
if (this.connected && this.cmdBusy && !this.closing) {
|
|
180
188
|
if (this.cmdCurrent !== undefined && this.cmdCurrent.start !== undefined) {
|
|
181
189
|
const cmdInfo = this.cmdCurrent;
|
|
182
190
|
const timeout = (cmdInfo.options && cmdInfo.options.timeout) ? cmdInfo.options.timeout : this._timeoutSend;
|
|
@@ -205,7 +213,8 @@ class Daum8008 {
|
|
|
205
213
|
return;
|
|
206
214
|
}
|
|
207
215
|
const cmd = this.queue.dequeue();
|
|
208
|
-
this.
|
|
216
|
+
if (this.connected && !this.closing && !this.closed)
|
|
217
|
+
this.send(cmd);
|
|
209
218
|
}
|
|
210
219
|
sendDaum8008Command(logStr, payload, expected, callback, callbackErr, options) {
|
|
211
220
|
let cmdInfo = {
|
|
@@ -175,12 +175,12 @@ class SerialInterface extends events_1.default {
|
|
|
175
175
|
}
|
|
176
176
|
openPort(path) {
|
|
177
177
|
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
-
this.logEvent({ message: 'opening port', path });
|
|
178
|
+
this.logEvent({ message: 'opening port', port: path });
|
|
179
179
|
const existing = this.ports.findIndex(p => p.path === path);
|
|
180
180
|
if (existing !== -1) {
|
|
181
181
|
const port = this.ports[existing].port;
|
|
182
182
|
if (port.isOpen) {
|
|
183
|
-
this.logEvent({ message: 'opening port - port already exists', path });
|
|
183
|
+
this.logEvent({ message: 'opening port - port already exists', port: path });
|
|
184
184
|
return port;
|
|
185
185
|
}
|
|
186
186
|
else {
|
|
@@ -189,7 +189,7 @@ class SerialInterface extends events_1.default {
|
|
|
189
189
|
}
|
|
190
190
|
const port = serialport_1.default.getInstance().getSerialPort(this.ifaceName, { path });
|
|
191
191
|
if (!port) {
|
|
192
|
-
this.logEvent({ message: 'opening port - port does not exist', path });
|
|
192
|
+
this.logEvent({ message: 'opening port - port does not exist', port: path });
|
|
193
193
|
return null;
|
|
194
194
|
}
|
|
195
195
|
return new Promise((resolve) => {
|
|
@@ -210,7 +210,7 @@ class SerialInterface extends events_1.default {
|
|
|
210
210
|
}
|
|
211
211
|
closePort(path) {
|
|
212
212
|
return __awaiter(this, void 0, void 0, function* () {
|
|
213
|
-
this.logEvent({ message: 'closing port' });
|
|
213
|
+
this.logEvent({ message: 'closing port', port: path });
|
|
214
214
|
const existing = this.ports.findIndex(p => p.path === path);
|
|
215
215
|
if (existing === -1)
|
|
216
216
|
return true;
|