incyclist-devices 1.4.3 → 1.4.6
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.d.ts +0 -1
- package/lib/Device.d.ts +13 -1
- package/lib/daum/DaumAdapter.d.ts +5 -4
- package/lib/daum/DaumAdapter.js +40 -33
- package/lib/daum/ERGCyclingMode.js +2 -5
- package/lib/daum/PowerMeterCyclingMode.js +0 -1
- package/lib/daum/classic/DaumClassicAdapter.js +1 -1
- package/lib/daum/classic/DaumClassicCyclingMode.js +0 -1
- package/lib/daum/classic/utils.js +1 -1
- package/lib/daum/premium/DaumClassicCyclingMode.js +1 -1
- package/lib/daum/premium/DaumPremiumAdapter.d.ts +0 -2
- package/lib/daum/premium/DaumPremiumAdapter.js +12 -25
- package/lib/daum/premium/bike.d.ts +3 -2
- package/lib/daum/premium/bike.js +38 -6
- package/lib/daum/premium/utils.d.ts +1 -1
- package/lib/daum/premium/utils.js +9 -10
- package/lib/types/route.d.ts +3 -0
- package/package.json +1 -1
package/lib/CyclingMode.d.ts
CHANGED
package/lib/Device.d.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { DeviceProtocol, Device } from './DeviceProtocol';
|
|
2
2
|
import CyclingMode from './CyclingMode';
|
|
3
|
-
export declare type
|
|
3
|
+
export declare type DeviceData = {
|
|
4
|
+
speed?: number;
|
|
5
|
+
slope?: number;
|
|
6
|
+
power?: number;
|
|
7
|
+
cadence?: number;
|
|
8
|
+
heartrate?: number;
|
|
9
|
+
distance?: number;
|
|
10
|
+
timestamp?: number;
|
|
11
|
+
deviceTime?: number;
|
|
12
|
+
deviceDistanceCounter?: number;
|
|
13
|
+
};
|
|
14
|
+
export declare type OnDeviceDataCallback = (data: DeviceData) => void;
|
|
15
|
+
export declare type OnDeviceStartCallback = (completed: number, total: number) => void;
|
|
4
16
|
export interface Bike {
|
|
5
17
|
setCyclingMode(mode: CyclingMode | string, settings?: any): void;
|
|
6
18
|
getSupportedCyclingModes(): Array<any>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventLogger } from 'gd-eventlog';
|
|
2
|
-
import CyclingMode from '../CyclingMode';
|
|
3
|
-
import DeviceAdapterBase, { Bike, DeviceAdapter } from '../Device';
|
|
2
|
+
import CyclingMode, { IncyclistBikeData } from '../CyclingMode';
|
|
3
|
+
import DeviceAdapterBase, { Bike, DeviceAdapter, DeviceData } from '../Device';
|
|
4
4
|
import { User } from '../types/user';
|
|
5
5
|
interface DaumAdapter {
|
|
6
6
|
getCurrentBikeData(): Promise<any>;
|
|
@@ -13,7 +13,8 @@ export default class DaumAdapterBase extends DeviceAdapterBase implements Device
|
|
|
13
13
|
distanceInternal: number;
|
|
14
14
|
paused: boolean;
|
|
15
15
|
stopped: boolean;
|
|
16
|
-
|
|
16
|
+
daumRunData: IncyclistBikeData;
|
|
17
|
+
deviceData: DeviceData;
|
|
17
18
|
currentRequest: any;
|
|
18
19
|
requests: Array<any>;
|
|
19
20
|
iv: any;
|
|
@@ -56,7 +57,7 @@ export default class DaumAdapterBase extends DeviceAdapterBase implements Device
|
|
|
56
57
|
sendRequests(): Promise<void>;
|
|
57
58
|
bikeSync(): Promise<void>;
|
|
58
59
|
updateData(prev: any, bikeData: any): void;
|
|
59
|
-
transformData():
|
|
60
|
+
transformData(): DeviceData;
|
|
60
61
|
sendRequest(request: any): Promise<any>;
|
|
61
62
|
refreshRequests(): void;
|
|
62
63
|
processClientRequest(request: any): Promise<unknown>;
|
package/lib/daum/DaumAdapter.js
CHANGED
|
@@ -29,7 +29,16 @@ class DaumAdapterBase extends Device_1.default {
|
|
|
29
29
|
this.bike = bike;
|
|
30
30
|
this.stopped = false;
|
|
31
31
|
this.paused = false;
|
|
32
|
-
this.
|
|
32
|
+
this.daumRunData = {
|
|
33
|
+
isPedalling: false,
|
|
34
|
+
time: 0,
|
|
35
|
+
power: 0,
|
|
36
|
+
pedalRpm: 0,
|
|
37
|
+
speed: 0,
|
|
38
|
+
distanceInternal: 0,
|
|
39
|
+
heartrate: 0
|
|
40
|
+
};
|
|
41
|
+
this.deviceData = {};
|
|
33
42
|
const options = props || {};
|
|
34
43
|
this.cyclingMode = options.cyclingMode;
|
|
35
44
|
this.setUserSettings(options.userSettings);
|
|
@@ -114,15 +123,16 @@ class DaumAdapterBase extends Device_1.default {
|
|
|
114
123
|
this.distanceInternal = undefined;
|
|
115
124
|
this.paused = false;
|
|
116
125
|
this.stopped = false;
|
|
117
|
-
this.
|
|
118
|
-
time: 0,
|
|
119
|
-
slope: 0,
|
|
120
|
-
distance: 0,
|
|
121
|
-
speed: 0,
|
|
126
|
+
this.daumRunData = {
|
|
122
127
|
isPedalling: false,
|
|
128
|
+
time: 0,
|
|
123
129
|
power: 0,
|
|
124
|
-
|
|
130
|
+
pedalRpm: 0,
|
|
131
|
+
speed: 0,
|
|
132
|
+
distanceInternal: 0,
|
|
133
|
+
heartrate: 0
|
|
125
134
|
};
|
|
135
|
+
this.deviceData = {};
|
|
126
136
|
this.currentRequest = {};
|
|
127
137
|
this.requests = [];
|
|
128
138
|
const name = this.getCyclingMode().getName();
|
|
@@ -200,14 +210,14 @@ class DaumAdapterBase extends Device_1.default {
|
|
|
200
210
|
}
|
|
201
211
|
sendData() {
|
|
202
212
|
if (this.onDataFn)
|
|
203
|
-
this.onDataFn(this.
|
|
213
|
+
this.onDataFn(this.deviceData);
|
|
204
214
|
}
|
|
205
215
|
update() {
|
|
206
216
|
return __awaiter(this, void 0, void 0, function* () {
|
|
207
217
|
this.updateBusy = true;
|
|
208
218
|
this.getCurrentBikeData()
|
|
209
219
|
.then(bikeData => {
|
|
210
|
-
this.updateData(this.
|
|
220
|
+
this.updateData(this.daumRunData, bikeData);
|
|
211
221
|
this.transformData();
|
|
212
222
|
this.updateBusy = false;
|
|
213
223
|
})
|
|
@@ -262,35 +272,32 @@ class DaumAdapterBase extends Device_1.default {
|
|
|
262
272
|
data.pedalRpm = bikeData.cadence;
|
|
263
273
|
data.speed = bikeData.speed;
|
|
264
274
|
data.heartrate = bikeData.heartrate;
|
|
265
|
-
data.
|
|
266
|
-
data.distanceInternal = bikeData.distance;
|
|
275
|
+
data.distanceInternal = bikeData.distanceInternal;
|
|
267
276
|
data.gear = bikeData.gear;
|
|
268
|
-
|
|
269
|
-
this.adapterTime = Date.now() - this.tsPrevData;
|
|
270
|
-
}
|
|
271
|
-
this.tsPrevData = Date.now();
|
|
272
|
-
data.time = Math.round(this.adapterTime || 0);
|
|
277
|
+
data.time = bikeData.time;
|
|
273
278
|
if (bikeData.slope)
|
|
274
279
|
data.slope = bikeData.slope;
|
|
275
|
-
this.
|
|
280
|
+
this.daumRunData = this.getCyclingMode().updateData(data);
|
|
276
281
|
}
|
|
277
282
|
transformData() {
|
|
278
|
-
if (this.
|
|
283
|
+
if (this.daumRunData === undefined)
|
|
279
284
|
return;
|
|
280
285
|
let distance = 0;
|
|
281
|
-
if (this.distanceInternal !== undefined && this.
|
|
282
|
-
distance = (0, utils_1.intVal)(this.
|
|
286
|
+
if (this.distanceInternal !== undefined && this.daumRunData.distanceInternal !== undefined) {
|
|
287
|
+
distance = (0, utils_1.intVal)(this.daumRunData.distanceInternal - this.distanceInternal);
|
|
283
288
|
}
|
|
284
|
-
if (this.
|
|
285
|
-
this.distanceInternal = this.
|
|
289
|
+
if (this.daumRunData.distanceInternal !== undefined)
|
|
290
|
+
this.distanceInternal = this.daumRunData.distanceInternal;
|
|
286
291
|
let data = {
|
|
287
|
-
speed: (0, utils_1.floatVal)(this.
|
|
288
|
-
slope: (0, utils_1.floatVal)(this.
|
|
289
|
-
power: (0, utils_1.intVal)(this.
|
|
290
|
-
cadence: (0, utils_1.intVal)(this.
|
|
291
|
-
heartrate: (0, utils_1.intVal)(this.
|
|
292
|
+
speed: (0, utils_1.floatVal)(this.daumRunData.speed),
|
|
293
|
+
slope: (0, utils_1.floatVal)(this.daumRunData.slope),
|
|
294
|
+
power: (0, utils_1.intVal)(this.daumRunData.power),
|
|
295
|
+
cadence: (0, utils_1.intVal)(this.daumRunData.pedalRpm),
|
|
296
|
+
heartrate: (0, utils_1.intVal)(this.daumRunData.heartrate),
|
|
292
297
|
distance,
|
|
293
|
-
timestamp: Date.now()
|
|
298
|
+
timestamp: Date.now(),
|
|
299
|
+
deviceTime: this.daumRunData.time,
|
|
300
|
+
deviceDistanceCounter: this.daumRunData.distanceInternal
|
|
294
301
|
};
|
|
295
302
|
if (this.ignoreHrm)
|
|
296
303
|
delete data.heartrate;
|
|
@@ -301,7 +308,7 @@ class DaumAdapterBase extends Device_1.default {
|
|
|
301
308
|
if (this.ignoreBike) {
|
|
302
309
|
data = { heartrate: data.heartrate };
|
|
303
310
|
}
|
|
304
|
-
this.
|
|
311
|
+
this.deviceData = data;
|
|
305
312
|
}
|
|
306
313
|
sendRequest(request) {
|
|
307
314
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -331,10 +338,10 @@ class DaumAdapterBase extends Device_1.default {
|
|
|
331
338
|
});
|
|
332
339
|
}
|
|
333
340
|
refreshRequests() {
|
|
334
|
-
if (!this.
|
|
341
|
+
if (!this.daumRunData.isPedalling || this.daumRunData.pedalRpm === 0)
|
|
335
342
|
return;
|
|
336
|
-
let bikeRequest = this.getCyclingMode().sendBikeUpdate({ refresh: true });
|
|
337
|
-
const prev = this.requests[this.requests.length - 1];
|
|
343
|
+
let bikeRequest = this.getCyclingMode().sendBikeUpdate({ refresh: true }) || {};
|
|
344
|
+
const prev = this.requests[this.requests.length - 1] || {};
|
|
338
345
|
if (bikeRequest.targetPower !== undefined && bikeRequest.targetPower !== prev.targetPower) {
|
|
339
346
|
this.logEvent({ message: 'add request', request: bikeRequest });
|
|
340
347
|
this.requests.push(bikeRequest);
|
|
@@ -342,7 +349,7 @@ class DaumAdapterBase extends Device_1.default {
|
|
|
342
349
|
}
|
|
343
350
|
processClientRequest(request) {
|
|
344
351
|
if (request.slope !== undefined) {
|
|
345
|
-
this.
|
|
352
|
+
this.daumRunData.slope = request.slope;
|
|
346
353
|
}
|
|
347
354
|
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
348
355
|
let bikeRequest = this.getCyclingMode().sendBikeUpdate(request);
|
|
@@ -146,7 +146,6 @@ class ERGCyclingMode extends CyclingMode_1.CyclingModeBase {
|
|
|
146
146
|
let speed;
|
|
147
147
|
let m = this.adapter.getWeight();
|
|
148
148
|
let distanceInternal = prevData.distanceInternal || 0;
|
|
149
|
-
let distance = Math.round(distanceInternal / 100);
|
|
150
149
|
let ts = Date.now();
|
|
151
150
|
let duration = this.prevUpdateTS === 0 ? 0 : ((ts - this.prevUpdateTS) / 1000);
|
|
152
151
|
if (rpm === 0 || bikeData.isPedalling === false) {
|
|
@@ -157,16 +156,14 @@ class ERGCyclingMode extends CyclingMode_1.CyclingModeBase {
|
|
|
157
156
|
speed = calculations_1.default.calculateSpeed(m, power, slope, { bikeType });
|
|
158
157
|
let v = speed / 3.6;
|
|
159
158
|
distanceInternal += Math.round(v * duration);
|
|
160
|
-
distance = Math.round(distanceInternal / 100);
|
|
161
159
|
}
|
|
162
160
|
data.speed = parseFloat(speed.toFixed(1));
|
|
163
161
|
data.power = Math.round(power);
|
|
164
|
-
data.distanceInternal =
|
|
165
|
-
data.distance = distance;
|
|
162
|
+
data.distanceInternal = distanceInternal;
|
|
166
163
|
data.slope = slope;
|
|
167
164
|
data.pedalRpm = rpm;
|
|
168
165
|
data.gear = gear;
|
|
169
|
-
if (data.time)
|
|
166
|
+
if (data.time !== undefined)
|
|
170
167
|
data.time += duration;
|
|
171
168
|
else
|
|
172
169
|
data.time = 0;
|
|
@@ -64,7 +64,6 @@ class PowerMeterCyclingMode extends CyclingMode_1.CyclingModeBase {
|
|
|
64
64
|
data.speed = parseFloat(speed.toFixed(1));
|
|
65
65
|
data.power = Math.round(power);
|
|
66
66
|
data.distanceInternal = Math.round(distanceInternal);
|
|
67
|
-
data.distance = Math.round(distanceInternal / 100);
|
|
68
67
|
data.slope = slope;
|
|
69
68
|
this.logger.logEvent({ message: "updateData result", data, bikeData, prevRequest: {}, prevSpeed: prevData.speed });
|
|
70
69
|
this.data = JSON.parse(JSON.stringify(data));
|
|
@@ -104,7 +104,7 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
104
104
|
startState.startProg = true;
|
|
105
105
|
}
|
|
106
106
|
if (!startState.setGear) {
|
|
107
|
-
yield this.bike.setGear(this.
|
|
107
|
+
yield this.bike.setGear(this.daumRunData.gear || (opts.gear || 10));
|
|
108
108
|
startState.setGear = true;
|
|
109
109
|
}
|
|
110
110
|
const startRequest = this.getCyclingMode().getBikeInitRequest();
|
|
@@ -84,7 +84,6 @@ class DaumClassicCyclingMode extends SmartTrainerCyclingMode_1.default {
|
|
|
84
84
|
data.power = Math.round(power);
|
|
85
85
|
data.slope = slope;
|
|
86
86
|
data.distanceInternal = distanceInternal;
|
|
87
|
-
data.distance = Math.round(distanceInternal / 100);
|
|
88
87
|
this.logger.logEvent({ message: "updateData result", data, bikeData, prevRequest: this.prevRequest || {}, prevSpeed: prevData.speed, event: this.event });
|
|
89
88
|
this.data = JSON.parse(JSON.stringify(data));
|
|
90
89
|
this.prevUpdateTS = ts;
|
|
@@ -123,7 +123,7 @@ function hexstr(arr, start, len) {
|
|
|
123
123
|
}
|
|
124
124
|
exports.hexstr = hexstr;
|
|
125
125
|
function Float32ToHex(float32) {
|
|
126
|
-
function getHex(i) { return ('00' + i.toString(16)).slice(-2); }
|
|
126
|
+
function getHex(i) { return ('00' + i.toString(16)).slice(-2).toUpperCase(); }
|
|
127
127
|
var view = new DataView(new ArrayBuffer(4));
|
|
128
128
|
view.setFloat32(0, float32);
|
|
129
129
|
return Array.apply(null, { length: 4 }).map((_, i) => getHex(view.getUint8(i))).join('');
|
|
@@ -64,6 +64,7 @@ class DaumClassicCyclingMode extends PowerMeterCyclingMode_1.default {
|
|
|
64
64
|
power = 0;
|
|
65
65
|
}
|
|
66
66
|
if (distanceBike < distancePrev) {
|
|
67
|
+
this.logger.logEvent({ message: '~~~ distance overflow', distanceBike, distancePrev });
|
|
67
68
|
let v = speed / 3.6;
|
|
68
69
|
let duration = this.prevUpdateTS === 0 ? 0 : ((ts - this.prevUpdateTS) / 1000);
|
|
69
70
|
distanceInternal = distancePrev + Math.round(v * duration);
|
|
@@ -71,7 +72,6 @@ class DaumClassicCyclingMode extends PowerMeterCyclingMode_1.default {
|
|
|
71
72
|
data.speed = parseFloat(speed.toFixed(1));
|
|
72
73
|
data.power = Math.round(power);
|
|
73
74
|
data.distanceInternal = Math.round(distanceInternal);
|
|
74
|
-
data.distance = Math.round(distanceInternal / 100);
|
|
75
75
|
data.slope = slope;
|
|
76
76
|
this.logger.logEvent({ message: "updateData result", data, bikeData, prevRequest: {}, prevSpeed: prevData.speed });
|
|
77
77
|
this.data = JSON.parse(JSON.stringify(data));
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Route } from '../../types/route';
|
|
2
1
|
import DaumAdapter from '../DaumAdapter';
|
|
3
2
|
export default class DaumPremiumDevice extends DaumAdapter {
|
|
4
3
|
static NAME: string;
|
|
@@ -8,7 +7,6 @@ export default class DaumPremiumDevice extends DaumAdapter {
|
|
|
8
7
|
getInterface(): any;
|
|
9
8
|
getSupportedCyclingModes(): Array<any>;
|
|
10
9
|
check(): Promise<unknown>;
|
|
11
|
-
initClassic(route: Route): Promise<boolean>;
|
|
12
10
|
start(props: any): Promise<unknown>;
|
|
13
11
|
getCurrentBikeData(): Promise<any>;
|
|
14
12
|
}
|
|
@@ -62,20 +62,6 @@ class DaumPremiumDevice extends DaumAdapter_1.default {
|
|
|
62
62
|
}
|
|
63
63
|
}));
|
|
64
64
|
}
|
|
65
|
-
initClassic(route) {
|
|
66
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
if (!route)
|
|
68
|
-
return true;
|
|
69
|
-
let res;
|
|
70
|
-
const bikeType = this.getCyclingMode().getSetting('bikeType');
|
|
71
|
-
res = yield this.bike.programUpload(bikeType, route);
|
|
72
|
-
if (!res)
|
|
73
|
-
return false;
|
|
74
|
-
res = yield this.bike.startProgram(route.programId);
|
|
75
|
-
if (!res)
|
|
76
|
-
return false;
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
65
|
start(props) {
|
|
80
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
67
|
this.logger.logEvent({ message: 'start()' });
|
|
@@ -99,26 +85,27 @@ class DaumPremiumDevice extends DaumAdapter_1.default {
|
|
|
99
85
|
if (!info.version) {
|
|
100
86
|
info.version = yield this.bike.getProtocolVersion();
|
|
101
87
|
}
|
|
102
|
-
if (
|
|
103
|
-
|
|
88
|
+
if (this.getCyclingMode().getModeProperty('eppSupport')) {
|
|
89
|
+
const bikeType = this.getCyclingMode().getSetting('bikeType');
|
|
90
|
+
if (!info.upload)
|
|
91
|
+
info.upload = yield this.bike.programUpload(bikeType, route, props.onStatusUpdate);
|
|
92
|
+
if (!info.started)
|
|
93
|
+
info.started = yield this.bike.startProgram(route.programId);
|
|
104
94
|
}
|
|
105
|
-
|
|
106
|
-
info.init = true;
|
|
107
|
-
}
|
|
108
|
-
if (!info.person && this.getCyclingMode().getModeProperty('eppSupport')) {
|
|
95
|
+
if (!info.person && this.getCyclingMode().getModeProperty('setPersonSupport')) {
|
|
109
96
|
info.person = yield this.bike.setPerson(user);
|
|
110
97
|
}
|
|
111
|
-
|
|
112
|
-
|
|
98
|
+
if (!this.getCyclingMode().getModeProperty('eppSupport')) {
|
|
99
|
+
const gear = yield this.bike.setGear(this.daumRunData.gear || (opts.gear || 10));
|
|
100
|
+
return gear;
|
|
113
101
|
}
|
|
114
|
-
|
|
115
|
-
return gear;
|
|
102
|
+
return;
|
|
116
103
|
}
|
|
117
104
|
catch (err) {
|
|
118
105
|
console.error(err);
|
|
119
106
|
throw (new Error(`could not start device, reason:${err.message}`));
|
|
120
107
|
}
|
|
121
|
-
}), 5,
|
|
108
|
+
}), 5, 1500)
|
|
122
109
|
.then(data => {
|
|
123
110
|
this.startUpdatePull();
|
|
124
111
|
return data;
|
|
@@ -4,6 +4,7 @@ import { Queue } from '../../utils';
|
|
|
4
4
|
import { EventLogger } from 'gd-eventlog';
|
|
5
5
|
import { User } from "../../types/user";
|
|
6
6
|
import { Route } from "../../types/route";
|
|
7
|
+
import { OnDeviceStartCallback } from "../../Device";
|
|
7
8
|
declare class Daum8i {
|
|
8
9
|
portName: string;
|
|
9
10
|
logger: EventLogger;
|
|
@@ -78,7 +79,7 @@ declare class Daum8i {
|
|
|
78
79
|
heartrate: number;
|
|
79
80
|
speed: number;
|
|
80
81
|
slope: number;
|
|
81
|
-
|
|
82
|
+
distanceInternal: number;
|
|
82
83
|
cadence: number;
|
|
83
84
|
power: number;
|
|
84
85
|
physEnergy: number;
|
|
@@ -98,7 +99,7 @@ declare class Daum8i {
|
|
|
98
99
|
programUploadStart(bikeType: BikeType, route: Route): Promise<Uint8Array>;
|
|
99
100
|
programUploadSendBlock(epp: Uint8Array, offset: number): Promise<boolean>;
|
|
100
101
|
programUploadDone(): Promise<boolean>;
|
|
101
|
-
programUpload(bikeType: BikeType, route: Route): Promise<boolean>;
|
|
102
|
+
programUpload(bikeType: BikeType, route: Route, onStatusUpdate?: OnDeviceStartCallback): Promise<boolean>;
|
|
102
103
|
startProgram(programId?: number): Promise<boolean>;
|
|
103
104
|
setGear(gear: any): Promise<number>;
|
|
104
105
|
getGear(): Promise<number>;
|
package/lib/daum/premium/bike.js
CHANGED
|
@@ -710,17 +710,27 @@ class Daum8i {
|
|
|
710
710
|
});
|
|
711
711
|
}
|
|
712
712
|
setPerson(person) {
|
|
713
|
+
this.logger.logEvent({ message: 'setPerson() request' });
|
|
713
714
|
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PERSON_SET, 'BF', (0, utils_1.getPersonData)(person))
|
|
714
715
|
.then((res) => {
|
|
715
716
|
const buffer = Buffer.from(res);
|
|
716
|
-
|
|
717
|
+
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PERSON_SET;
|
|
718
|
+
this.logger.logEvent({ message: 'setPerson() response', success, buffer });
|
|
719
|
+
if (!success)
|
|
720
|
+
throw new Error('Illegal Response');
|
|
721
|
+
return true;
|
|
717
722
|
});
|
|
718
723
|
}
|
|
719
724
|
programUploadInit() {
|
|
725
|
+
this.logger.logEvent({ message: 'programUploadInit() request' });
|
|
720
726
|
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_BEGIN, 'BF')
|
|
721
727
|
.then((res) => {
|
|
722
728
|
const buffer = Buffer.from(res);
|
|
723
|
-
|
|
729
|
+
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_BEGIN;
|
|
730
|
+
this.logger.logEvent({ message: 'programUploadInit() response', success, buffer });
|
|
731
|
+
if (!success)
|
|
732
|
+
throw new Error('Illegal Response');
|
|
733
|
+
return true;
|
|
724
734
|
});
|
|
725
735
|
}
|
|
726
736
|
programUploadStart(bikeType, route) {
|
|
@@ -740,12 +750,15 @@ class Daum8i {
|
|
|
740
750
|
payload.writeInt16LE(0, 30);
|
|
741
751
|
payload.writeInt32LE(7, 32);
|
|
742
752
|
payload.writeInt32LE(epp.length, 36);
|
|
753
|
+
this.logger.logEvent({ message: 'programUploadStart() request' });
|
|
743
754
|
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_NEW_PROGRAM, 'BF', payload)
|
|
744
755
|
.then((res) => {
|
|
745
756
|
const buffer = Buffer.from(res);
|
|
746
757
|
if (buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_NEW_PROGRAM) {
|
|
758
|
+
this.logger.logEvent({ message: 'programUploadStart() response', success: true });
|
|
747
759
|
return epp;
|
|
748
760
|
}
|
|
761
|
+
this.logger.logEvent({ message: 'programUploadStart() response', success: false });
|
|
749
762
|
throw new Error('Illegal Response');
|
|
750
763
|
});
|
|
751
764
|
}
|
|
@@ -759,35 +772,48 @@ class Daum8i {
|
|
|
759
772
|
payload.writeInt32LE(offset, 4);
|
|
760
773
|
const chunk = Buffer.from(epp.slice(offset, offset + size));
|
|
761
774
|
chunk.copy(payload, 8);
|
|
775
|
+
this.logger.logEvent({ message: 'programUploadSendBlock() request', offset, size });
|
|
762
776
|
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_CONTINUE_PROGRAM, 'BF', payload)
|
|
763
777
|
.then((res) => {
|
|
764
778
|
const buffer = Buffer.from(res);
|
|
765
779
|
let success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_CONTINUE_PROGRAM;
|
|
766
780
|
success = success && (buffer.readInt16LE(2) === 1);
|
|
767
781
|
success = success && (buffer.readInt8(4) === 1);
|
|
782
|
+
this.logger.logEvent({ message: 'programUploadSendBlock() response' });
|
|
768
783
|
if (!success)
|
|
769
784
|
throw new Error('Illegal Response');
|
|
770
|
-
return
|
|
785
|
+
return true;
|
|
786
|
+
;
|
|
771
787
|
});
|
|
772
788
|
}
|
|
773
789
|
programUploadDone() {
|
|
790
|
+
this.logger.logEvent({ message: 'programUploadDone() request' });
|
|
774
791
|
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_END, 'BF')
|
|
775
792
|
.then((res) => {
|
|
776
793
|
const buffer = Buffer.from(res);
|
|
777
|
-
|
|
794
|
+
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_END;
|
|
795
|
+
this.logger.logEvent({ message: 'programUploadDone() response', success });
|
|
796
|
+
if (!success)
|
|
797
|
+
throw new Error('Illegal Response');
|
|
798
|
+
return true;
|
|
799
|
+
;
|
|
778
800
|
});
|
|
779
801
|
}
|
|
780
|
-
programUpload(bikeType, route) {
|
|
802
|
+
programUpload(bikeType, route, onStatusUpdate) {
|
|
781
803
|
return __awaiter(this, void 0, void 0, function* () {
|
|
782
804
|
yield this.programUploadInit();
|
|
783
805
|
const epp = yield this.programUploadStart(bikeType, route);
|
|
784
806
|
let success = true;
|
|
785
807
|
let done = false;
|
|
786
808
|
let offset = 0;
|
|
809
|
+
if (onStatusUpdate)
|
|
810
|
+
onStatusUpdate(0, epp.length);
|
|
787
811
|
while (success && !done) {
|
|
788
812
|
success = yield this.programUploadSendBlock(epp, offset);
|
|
789
813
|
offset += MAX_DATA_BLOCK_SIZE;
|
|
790
814
|
done = offset >= epp.length;
|
|
815
|
+
if (onStatusUpdate)
|
|
816
|
+
onStatusUpdate(done ? epp.length : offset, epp.length);
|
|
791
817
|
}
|
|
792
818
|
if (done) {
|
|
793
819
|
return yield this.programUploadDone();
|
|
@@ -798,10 +824,16 @@ class Daum8i {
|
|
|
798
824
|
startProgram(programId = 1) {
|
|
799
825
|
const payload = Buffer.alloc(2);
|
|
800
826
|
payload.writeInt16LE(programId, 0);
|
|
827
|
+
this.logger.logEvent({ message: 'startProgram() request', programId });
|
|
801
828
|
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_START, 'BF', payload)
|
|
802
829
|
.then((res) => {
|
|
803
830
|
const buffer = Buffer.from(res);
|
|
804
|
-
|
|
831
|
+
const success = buffer.readInt16LE(0) === utils_1.ReservedCommands.PROGRAM_LIST_START;
|
|
832
|
+
this.logger.logEvent({ message: 'startProgram() request', programId, success });
|
|
833
|
+
if (!success)
|
|
834
|
+
throw new Error('Illegal Response');
|
|
835
|
+
return true;
|
|
836
|
+
;
|
|
805
837
|
});
|
|
806
838
|
}
|
|
807
839
|
setGear(gear) {
|
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getPersonData = exports.parseTrainingData = exports.routeToEpp = exports.getBikeType = exports.BikeType = exports.ReservedCommands = exports.Int32ToIntArray = exports.Int16ToIntArray = exports.Float32ToIntArray = exports.Float32ToHex = exports.getAsciiArrayFromStr = exports.asciiArrayToString = exports.charArrayToString = exports.ascii = exports.append = exports.getHex = exports.hexstr = exports.getMessageData = exports.buildMessage = exports.checkSum = exports.esc2bin = exports.bin2esc = void 0;
|
|
7
7
|
const user_1 = require("../../types/user");
|
|
8
|
-
const utils_1 = require("../classic/utils");
|
|
9
8
|
const win32filetime_1 = __importDefault(require("win32filetime"));
|
|
10
9
|
const sum = (arr) => arr.reduce((a, b) => a + b, 0);
|
|
11
10
|
function bin2esc(arr) {
|
|
@@ -258,9 +257,9 @@ function routeToEpp(route, date) {
|
|
|
258
257
|
let offset = 0;
|
|
259
258
|
const name = route.name || '';
|
|
260
259
|
const description = route.description || '';
|
|
261
|
-
const minElevation =
|
|
262
|
-
const maxElevation = Math.max(...route.points.map(p => p.elevation));
|
|
263
|
-
const sampleRate = route.points.length !== 0 ? route.totalDistance / route.points.length : 0;
|
|
260
|
+
const minElevation = route.minElevation ? route.minElevation : 0;
|
|
261
|
+
const maxElevation = route.maxElevation ? route.minElevation : Math.max(...route.points.map(p => p.elevation));
|
|
262
|
+
const sampleRate = route.points.length !== 0 ? Math.round(route.totalDistance / route.points.length) : 0;
|
|
264
263
|
buffer.writeUInt32LE(fileTime.low, offset);
|
|
265
264
|
offset += 4;
|
|
266
265
|
buffer.writeUInt32LE(fileTime.high, offset);
|
|
@@ -314,9 +313,9 @@ function parseTrainingData(payload) {
|
|
|
314
313
|
const data = {
|
|
315
314
|
time: parseInt(vals[0]),
|
|
316
315
|
heartrate: parseInt(vals[1]),
|
|
317
|
-
speed: parseFloat(vals[2]),
|
|
316
|
+
speed: parseFloat(vals[2]) * 3.6,
|
|
318
317
|
slope: parseFloat(vals[3]),
|
|
319
|
-
|
|
318
|
+
distanceInternal: parseInt(vals[4]),
|
|
320
319
|
cadence: parseFloat(vals[5]),
|
|
321
320
|
power: parseInt(vals[6]),
|
|
322
321
|
physEnergy: parseFloat(vals[7]),
|
|
@@ -360,15 +359,15 @@ function getPersonData(user) {
|
|
|
360
359
|
}
|
|
361
360
|
buffer.writeInt32LE(user.sex === user_1.Gender.FEMALE ? 2 : 1, offset);
|
|
362
361
|
offset += 4;
|
|
363
|
-
buffer.writeInt32LE(user.age !== undefined ? user.age :
|
|
362
|
+
buffer.writeInt32LE(user.age !== undefined ? user.age : 1, offset);
|
|
364
363
|
offset += 4;
|
|
365
|
-
buffer.writeInt32LE(user.length !== undefined ? user.length :
|
|
364
|
+
buffer.writeInt32LE(user.length !== undefined ? user.length : 175, offset);
|
|
366
365
|
offset += 4;
|
|
367
|
-
buffer.writeFloatLE(user.weight !== undefined ? user.weight :
|
|
366
|
+
buffer.writeFloatLE(user.weight !== undefined ? user.weight : 70, offset);
|
|
368
367
|
offset += 4;
|
|
369
368
|
buffer.writeFloatLE(0, offset);
|
|
370
369
|
offset += 4;
|
|
371
|
-
buffer.writeUInt32LE(
|
|
370
|
+
buffer.writeUInt32LE(1, offset);
|
|
372
371
|
offset += 4;
|
|
373
372
|
return buffer;
|
|
374
373
|
}
|
package/lib/types/route.d.ts
CHANGED