incyclist-devices 2.0.25 → 2.0.27
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.
|
@@ -50,7 +50,7 @@ export default class DaumAdapterBase extends SerialIncyclistDevice implements Da
|
|
|
50
50
|
sendRequests(): Promise<void>;
|
|
51
51
|
bikeSync(): Promise<void>;
|
|
52
52
|
updateData(prev: any, bikeData: any): IncyclistBikeData;
|
|
53
|
-
transformData(): DeviceData;
|
|
53
|
+
transformData(cyclingData: IncyclistBikeData): DeviceData;
|
|
54
54
|
sendRequest(request: any): Promise<any>;
|
|
55
55
|
refreshRequests(): void;
|
|
56
56
|
processClientRequest(request: any): Promise<unknown>;
|
|
@@ -148,6 +148,7 @@ class DaumAdapterBase extends adapter_1.SerialIncyclistDevice {
|
|
|
148
148
|
this.iv = undefined;
|
|
149
149
|
}
|
|
150
150
|
startUpdatePull() {
|
|
151
|
+
this.logger.logEvent({ message: 'start update pull', iv: this.iv, ignoreBike: this.ignoreBike, ignoreHrm: this.ignoreHrm, ignorePower: this.ignorePower });
|
|
151
152
|
if (this.iv)
|
|
152
153
|
return;
|
|
153
154
|
if (this.ignoreBike && this.ignoreHrm && this.ignorePower)
|
|
@@ -234,21 +235,23 @@ class DaumAdapterBase extends adapter_1.SerialIncyclistDevice {
|
|
|
234
235
|
}
|
|
235
236
|
update() {
|
|
236
237
|
return __awaiter(this, void 0, void 0, function* () {
|
|
238
|
+
this.logEvent({ message: 'bike update request', stopped: this.stopped, updateBusy: this.updateBusy });
|
|
237
239
|
if (this.stopped)
|
|
238
240
|
return;
|
|
239
241
|
this.updateBusy = true;
|
|
240
242
|
this.getCurrentBikeData()
|
|
241
243
|
.then(bikeData => {
|
|
242
|
-
this.
|
|
243
|
-
const
|
|
244
|
+
this.logEvent({ message: 'bike data', data: bikeData });
|
|
245
|
+
const incyclistData = this.updateData(this.cyclingData, bikeData);
|
|
246
|
+
const data = this.transformData(incyclistData);
|
|
244
247
|
this.updateBusy = false;
|
|
245
248
|
this.emitData(data);
|
|
246
249
|
})
|
|
247
250
|
.catch(err => {
|
|
248
251
|
this.logEvent({ message: 'bike update error', error: err.message, stack: err.stack });
|
|
249
252
|
const { isPedalling, power, pedalRpm, speed, distanceInternal, heartrate, slope } = this.cyclingData;
|
|
250
|
-
this.updateData(this.cyclingData, { isPedalling, power, pedalRpm, speed, distanceInternal, heartrate, slope });
|
|
251
|
-
this.transformData();
|
|
253
|
+
const incyclistData = this.updateData(this.cyclingData, { isPedalling, power, pedalRpm, speed, distanceInternal, heartrate, slope });
|
|
254
|
+
this.transformData(incyclistData);
|
|
252
255
|
this.updateBusy = false;
|
|
253
256
|
});
|
|
254
257
|
});
|
|
@@ -286,7 +289,7 @@ class DaumAdapterBase extends adapter_1.SerialIncyclistDevice {
|
|
|
286
289
|
if (this.updateBusy || this.requestBusy) {
|
|
287
290
|
return;
|
|
288
291
|
}
|
|
289
|
-
this.logEvent({ message: 'bikeSync' });
|
|
292
|
+
this.logEvent({ message: 'bikeSync', ignoreBike: this.ignoreBike });
|
|
290
293
|
if (!this.ignoreBike) {
|
|
291
294
|
yield this.sendRequests();
|
|
292
295
|
}
|
|
@@ -308,25 +311,23 @@ class DaumAdapterBase extends adapter_1.SerialIncyclistDevice {
|
|
|
308
311
|
this.cyclingData = this.getCyclingMode().updateData(data);
|
|
309
312
|
return this.cyclingData;
|
|
310
313
|
}
|
|
311
|
-
transformData() {
|
|
312
|
-
if (this.cyclingData === undefined)
|
|
313
|
-
return;
|
|
314
|
+
transformData(cyclingData) {
|
|
314
315
|
let distance = 0;
|
|
315
|
-
if (this.distanceInternal !== undefined &&
|
|
316
|
-
distance =
|
|
316
|
+
if (this.distanceInternal !== undefined && cyclingData.distanceInternal !== undefined) {
|
|
317
|
+
distance = cyclingData.distanceInternal - this.distanceInternal;
|
|
317
318
|
}
|
|
318
|
-
if (
|
|
319
|
-
this.distanceInternal =
|
|
319
|
+
if (cyclingData.distanceInternal !== undefined)
|
|
320
|
+
this.distanceInternal = cyclingData.distanceInternal;
|
|
320
321
|
let data = {
|
|
321
|
-
speed:
|
|
322
|
-
slope:
|
|
323
|
-
power: (0, utils_1.intVal)(
|
|
324
|
-
cadence: (0, utils_1.intVal)(
|
|
325
|
-
heartrate: (0, utils_1.intVal)(
|
|
322
|
+
speed: cyclingData.speed || 0,
|
|
323
|
+
slope: cyclingData.slope,
|
|
324
|
+
power: (0, utils_1.intVal)(cyclingData.power || 0),
|
|
325
|
+
cadence: (0, utils_1.intVal)(cyclingData.pedalRpm),
|
|
326
|
+
heartrate: (0, utils_1.intVal)(cyclingData.heartrate),
|
|
326
327
|
distance,
|
|
327
328
|
timestamp: Date.now(),
|
|
328
|
-
deviceTime:
|
|
329
|
-
deviceDistanceCounter:
|
|
329
|
+
deviceTime: cyclingData.time,
|
|
330
|
+
deviceDistanceCounter: cyclingData.distanceInternal
|
|
330
331
|
};
|
|
331
332
|
if (this.ignoreHrm)
|
|
332
333
|
delete data.heartrate;
|
|
@@ -9,6 +9,8 @@ export default class DaumClassicAdapter extends DaumAdapter {
|
|
|
9
9
|
static NAME: string;
|
|
10
10
|
name: string;
|
|
11
11
|
id: string;
|
|
12
|
+
started: boolean;
|
|
13
|
+
startPromise: Promise<unknown>;
|
|
12
14
|
constructor(settings: SerialDeviceSettings, props?: DeviceProperties);
|
|
13
15
|
setID(id: any): void;
|
|
14
16
|
getID(): string;
|
|
@@ -45,9 +45,12 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
45
45
|
this.ignoreHrm = false;
|
|
46
46
|
this.ignorePower = false;
|
|
47
47
|
this.ignoreBike = false;
|
|
48
|
+
this.stopped = false;
|
|
49
|
+
this.started = false;
|
|
48
50
|
this.paused = undefined;
|
|
49
51
|
this.iv = undefined;
|
|
50
52
|
this.distanceInternal = undefined;
|
|
53
|
+
this.startPromise = undefined;
|
|
51
54
|
this.initData();
|
|
52
55
|
}
|
|
53
56
|
setID(id) {
|
|
@@ -147,9 +150,11 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
147
150
|
}
|
|
148
151
|
start(props = {}) {
|
|
149
152
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
|
|
153
|
+
const isRelaunch = this.started;
|
|
154
|
+
const message = isRelaunch ? 'relaunch of device' : 'initial start of device';
|
|
155
|
+
this.logEvent({ message });
|
|
151
156
|
try {
|
|
152
|
-
yield this.launch(props,
|
|
157
|
+
yield this.launch(props, isRelaunch);
|
|
153
158
|
return true;
|
|
154
159
|
}
|
|
155
160
|
catch (err) {
|
|
@@ -161,10 +166,18 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
161
166
|
launch(props, isRelaunch = false) {
|
|
162
167
|
return __awaiter(this, void 0, void 0, function* () {
|
|
163
168
|
try {
|
|
164
|
-
if (
|
|
165
|
-
|
|
169
|
+
if (!this.startPromise) {
|
|
170
|
+
if (isRelaunch) {
|
|
171
|
+
yield this.stop();
|
|
172
|
+
this.bike.resumeLogging();
|
|
173
|
+
}
|
|
174
|
+
this.startPromise = this.performStart(props, isRelaunch);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
this.logEvent({ message: 'start already ongoing' });
|
|
166
178
|
}
|
|
167
|
-
yield this.
|
|
179
|
+
yield this.startPromise;
|
|
180
|
+
this.startPromise = undefined;
|
|
168
181
|
if (!isRelaunch) {
|
|
169
182
|
try {
|
|
170
183
|
const version = yield this.bike.getVersion();
|
|
@@ -174,10 +187,13 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
174
187
|
catch (_a) { }
|
|
175
188
|
}
|
|
176
189
|
this.logEvent({ message: 'start result: success' });
|
|
190
|
+
this.started = true;
|
|
177
191
|
return true;
|
|
178
192
|
}
|
|
179
193
|
catch (err) {
|
|
180
194
|
this.logEvent({ message: 'start result: error', error: err.message });
|
|
195
|
+
this.startPromise = undefined;
|
|
196
|
+
this.started = false;
|
|
181
197
|
throw new Error(`could not start device, reason:${err.message}`);
|
|
182
198
|
}
|
|
183
199
|
});
|