incyclist-devices 1.4.5 → 1.4.8
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/Device.d.ts +2 -0
- package/lib/Device.js +1 -0
- package/lib/daum/DaumAdapter.js +10 -3
- package/lib/daum/ERGCyclingMode.js +2 -2
- package/lib/daum/classic/DaumClassicAdapter.js +5 -0
- package/lib/daum/premium/DaumPremiumAdapter.d.ts +0 -2
- package/lib/daum/premium/DaumPremiumAdapter.js +10 -24
- package/lib/daum/premium/bike.d.ts +4 -3
- package/lib/daum/premium/bike.js +35 -18
- package/lib/daum/premium/utils.js +37 -36
- package/package.json +1 -1
package/lib/Device.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare type DeviceData = {
|
|
|
12
12
|
deviceDistanceCounter?: number;
|
|
13
13
|
};
|
|
14
14
|
export declare type OnDeviceDataCallback = (data: DeviceData) => void;
|
|
15
|
+
export declare type OnDeviceStartCallback = (completed: number, total: number) => void;
|
|
15
16
|
export interface Bike {
|
|
16
17
|
setCyclingMode(mode: CyclingMode | string, settings?: any): void;
|
|
17
18
|
getSupportedCyclingModes(): Array<any>;
|
|
@@ -60,6 +61,7 @@ export default class DeviceAdapterBase implements DeviceAdapter {
|
|
|
60
61
|
getPort(): string;
|
|
61
62
|
getProtocol(): DeviceProtocol;
|
|
62
63
|
getProtocolName(): string | undefined;
|
|
64
|
+
setCyclingMode(mode: CyclingMode | string, settings?: any): void;
|
|
63
65
|
setIgnoreHrm(ignore: any): void;
|
|
64
66
|
setIgnorePower(ignore: any): void;
|
|
65
67
|
setIgnoreBike(ignore: any): void;
|
package/lib/Device.js
CHANGED
package/lib/daum/DaumAdapter.js
CHANGED
|
@@ -147,13 +147,17 @@ class DaumAdapterBase extends Device_1.default {
|
|
|
147
147
|
return;
|
|
148
148
|
if (this.ignoreBike && this.ignoreHrm && this.ignorePower)
|
|
149
149
|
return;
|
|
150
|
-
|
|
150
|
+
const ivSync = setInterval(() => {
|
|
151
151
|
this.bikeSync();
|
|
152
152
|
}, 1000);
|
|
153
|
-
|
|
153
|
+
const ivUpdate = setInterval(() => {
|
|
154
154
|
this.sendData();
|
|
155
155
|
this.refreshRequests();
|
|
156
156
|
}, 1000);
|
|
157
|
+
this.iv = {
|
|
158
|
+
sync: ivSync,
|
|
159
|
+
update: ivUpdate
|
|
160
|
+
};
|
|
157
161
|
}
|
|
158
162
|
connect() {
|
|
159
163
|
if (!this.bike.isConnected())
|
|
@@ -173,7 +177,10 @@ class DaumAdapterBase extends Device_1.default {
|
|
|
173
177
|
return new Promise((resolve, reject) => {
|
|
174
178
|
try {
|
|
175
179
|
if (this.iv) {
|
|
176
|
-
|
|
180
|
+
if (this.iv.sync)
|
|
181
|
+
clearInterval(this.iv.sync);
|
|
182
|
+
if (this.iv.update)
|
|
183
|
+
clearInterval(this.iv.update);
|
|
177
184
|
this.iv = undefined;
|
|
178
185
|
}
|
|
179
186
|
this.logEvent({ message: 'stop request completed' });
|
|
@@ -159,11 +159,11 @@ class ERGCyclingMode extends CyclingMode_1.CyclingModeBase {
|
|
|
159
159
|
}
|
|
160
160
|
data.speed = parseFloat(speed.toFixed(1));
|
|
161
161
|
data.power = Math.round(power);
|
|
162
|
-
data.distanceInternal =
|
|
162
|
+
data.distanceInternal = distanceInternal;
|
|
163
163
|
data.slope = slope;
|
|
164
164
|
data.pedalRpm = rpm;
|
|
165
165
|
data.gear = gear;
|
|
166
|
-
if (data.time)
|
|
166
|
+
if (data.time !== undefined)
|
|
167
167
|
data.time += duration;
|
|
168
168
|
else
|
|
169
169
|
data.time = 0;
|
|
@@ -99,6 +99,11 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
|
|
|
99
99
|
yield this.getBike().setPerson(user);
|
|
100
100
|
startState.setPerson = true;
|
|
101
101
|
}
|
|
102
|
+
if (!startState.setBikeType) {
|
|
103
|
+
const bikeType = this.getCyclingMode().getSetting('bikeType') || 'race';
|
|
104
|
+
yield this.getBike().setBikeType(bikeType.toLowerCase());
|
|
105
|
+
startState.setBikeType = true;
|
|
106
|
+
}
|
|
102
107
|
if (!startState.startProg) {
|
|
103
108
|
yield this.getBike().startProg();
|
|
104
109
|
startState.startProg = true;
|
|
@@ -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,18 +85,18 @@ 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
|
+
const programId = route ? route.programId : 0;
|
|
94
|
+
info.started = yield this.bike.startProgram(programId);
|
|
95
|
+
}
|
|
104
96
|
}
|
|
105
|
-
|
|
106
|
-
info.init = true;
|
|
107
|
-
}
|
|
108
|
-
if (!info.person && this.getCyclingMode().getModeProperty('eppSupport')) {
|
|
97
|
+
if (!info.person && this.getCyclingMode().getModeProperty('setPersonSupport')) {
|
|
109
98
|
info.person = yield this.bike.setPerson(user);
|
|
110
99
|
}
|
|
111
|
-
else {
|
|
112
|
-
info.person = true;
|
|
113
|
-
}
|
|
114
100
|
if (!this.getCyclingMode().getModeProperty('eppSupport')) {
|
|
115
101
|
const gear = yield this.bike.setGear(this.daumRunData.gear || (opts.gear || 10));
|
|
116
102
|
return gear;
|
|
@@ -121,7 +107,7 @@ class DaumPremiumDevice extends DaumAdapter_1.default {
|
|
|
121
107
|
console.error(err);
|
|
122
108
|
throw (new Error(`could not start device, reason:${err.message}`));
|
|
123
109
|
}
|
|
124
|
-
}), 5,
|
|
110
|
+
}), 5, 1500)
|
|
125
111
|
.then(data => {
|
|
126
112
|
this.startUpdatePull();
|
|
127
113
|
return data;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { ReservedCommands
|
|
2
|
+
import { ReservedCommands } from './utils';
|
|
3
3
|
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;
|
|
@@ -95,10 +96,10 @@ declare class Daum8i {
|
|
|
95
96
|
getPower(power: any): Promise<number>;
|
|
96
97
|
setPerson(person: User): Promise<boolean>;
|
|
97
98
|
programUploadInit(): Promise<boolean>;
|
|
98
|
-
programUploadStart(bikeType:
|
|
99
|
+
programUploadStart(bikeType: string, route?: Route): Promise<Uint8Array>;
|
|
99
100
|
programUploadSendBlock(epp: Uint8Array, offset: number): Promise<boolean>;
|
|
100
101
|
programUploadDone(): Promise<boolean>;
|
|
101
|
-
programUpload(bikeType:
|
|
102
|
+
programUpload(bikeType: string, 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,7 +710,8 @@ class Daum8i {
|
|
|
710
710
|
});
|
|
711
711
|
}
|
|
712
712
|
setPerson(person) {
|
|
713
|
-
|
|
713
|
+
const { sex, age, length, weight } = person;
|
|
714
|
+
this.logger.logEvent({ message: 'setPerson() request', sex, age, length, weight });
|
|
714
715
|
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PERSON_SET, 'BF', (0, utils_1.getPersonData)(person))
|
|
715
716
|
.then((res) => {
|
|
716
717
|
const buffer = Buffer.from(res);
|
|
@@ -735,10 +736,12 @@ class Daum8i {
|
|
|
735
736
|
}
|
|
736
737
|
programUploadStart(bikeType, route) {
|
|
737
738
|
const payload = Buffer.alloc(40);
|
|
738
|
-
const epp = (0, utils_1.routeToEpp)(route);
|
|
739
|
+
const epp = route ? (0, utils_1.routeToEpp)(route) : undefined;
|
|
740
|
+
const eppLength = epp ? epp.length : 0;
|
|
741
|
+
const bikeTypeVal = (0, utils_1.getBikeType)(bikeType);
|
|
739
742
|
payload.writeInt32LE(0, 0);
|
|
740
|
-
payload.writeInt8(
|
|
741
|
-
payload.writeInt8(
|
|
743
|
+
payload.writeInt8(bikeTypeVal, 4);
|
|
744
|
+
payload.writeInt8(0, 5);
|
|
742
745
|
payload.writeInt16LE(0, 6);
|
|
743
746
|
payload.writeInt32LE(0, 8);
|
|
744
747
|
payload.writeInt32LE(0, 12);
|
|
@@ -749,8 +752,8 @@ class Daum8i {
|
|
|
749
752
|
payload.writeInt16LE(0, 28);
|
|
750
753
|
payload.writeInt16LE(0, 30);
|
|
751
754
|
payload.writeInt32LE(7, 32);
|
|
752
|
-
payload.writeInt32LE(
|
|
753
|
-
this.logger.logEvent({ message: 'programUploadStart() request' });
|
|
755
|
+
payload.writeInt32LE(eppLength, 36);
|
|
756
|
+
this.logger.logEvent({ message: 'programUploadStart() request', bikeType, length: eppLength });
|
|
754
757
|
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_NEW_PROGRAM, 'BF', payload)
|
|
755
758
|
.then((res) => {
|
|
756
759
|
const buffer = Buffer.from(res);
|
|
@@ -799,20 +802,34 @@ class Daum8i {
|
|
|
799
802
|
;
|
|
800
803
|
});
|
|
801
804
|
}
|
|
802
|
-
programUpload(bikeType, route) {
|
|
805
|
+
programUpload(bikeType, route, onStatusUpdate) {
|
|
803
806
|
return __awaiter(this, void 0, void 0, function* () {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
807
|
+
try {
|
|
808
|
+
yield this.programUploadInit();
|
|
809
|
+
const epp = yield this.programUploadStart(bikeType, route);
|
|
810
|
+
if (epp) {
|
|
811
|
+
let success = true;
|
|
812
|
+
let done = false;
|
|
813
|
+
let offset = 0;
|
|
814
|
+
if (onStatusUpdate)
|
|
815
|
+
onStatusUpdate(0, epp.length);
|
|
816
|
+
while (success && !done) {
|
|
817
|
+
success = yield this.programUploadSendBlock(epp, offset);
|
|
818
|
+
offset += MAX_DATA_BLOCK_SIZE;
|
|
819
|
+
done = offset >= epp.length;
|
|
820
|
+
if (onStatusUpdate)
|
|
821
|
+
onStatusUpdate(done ? epp.length : offset, epp.length);
|
|
822
|
+
}
|
|
823
|
+
if (done) {
|
|
824
|
+
return yield this.programUploadDone();
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
else {
|
|
828
|
+
return yield this.programUploadDone();
|
|
829
|
+
}
|
|
813
830
|
}
|
|
814
|
-
|
|
815
|
-
|
|
831
|
+
catch (err) {
|
|
832
|
+
console.log('~~~ err', err);
|
|
816
833
|
}
|
|
817
834
|
return false;
|
|
818
835
|
});
|
|
@@ -4,8 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
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
|
-
const user_1 = require("../../types/user");
|
|
8
|
-
const utils_1 = require("../classic/utils");
|
|
9
7
|
const win32filetime_1 = __importDefault(require("win32filetime"));
|
|
10
8
|
const sum = (arr) => arr.reduce((a, b) => a + b, 0);
|
|
11
9
|
function bin2esc(arr) {
|
|
@@ -15,29 +13,29 @@ function bin2esc(arr) {
|
|
|
15
13
|
const res = [];
|
|
16
14
|
arr.forEach(v => {
|
|
17
15
|
switch (v) {
|
|
18
|
-
case
|
|
19
|
-
res.push(
|
|
20
|
-
res.push(
|
|
16
|
+
case 0x12:
|
|
17
|
+
res.push(0x22);
|
|
18
|
+
res.push(0x12);
|
|
21
19
|
break;
|
|
22
|
-
case
|
|
23
|
-
res.push(
|
|
24
|
-
res.push(
|
|
20
|
+
case 0x22:
|
|
21
|
+
res.push(0x22);
|
|
22
|
+
res.push(0x22);
|
|
25
23
|
break;
|
|
26
|
-
case
|
|
27
|
-
res.push(
|
|
28
|
-
res.push(
|
|
24
|
+
case 0x01:
|
|
25
|
+
res.push(0x22);
|
|
26
|
+
res.push(0x11);
|
|
29
27
|
break;
|
|
30
|
-
case
|
|
31
|
-
res.push(
|
|
32
|
-
res.push(
|
|
28
|
+
case 0x17:
|
|
29
|
+
res.push(0x22);
|
|
30
|
+
res.push(0x27);
|
|
33
31
|
break;
|
|
34
|
-
case
|
|
35
|
-
res.push(
|
|
36
|
-
res.push(
|
|
32
|
+
case 0x06:
|
|
33
|
+
res.push(0x22);
|
|
34
|
+
res.push(0x16);
|
|
37
35
|
break;
|
|
38
|
-
case
|
|
39
|
-
res.push(
|
|
40
|
-
res.push(
|
|
36
|
+
case 0x15:
|
|
37
|
+
res.push(0x22);
|
|
38
|
+
res.push(0x25);
|
|
41
39
|
break;
|
|
42
40
|
default:
|
|
43
41
|
res.push(v);
|
|
@@ -56,26 +54,29 @@ function esc2bin(arr) {
|
|
|
56
54
|
if (escaped) {
|
|
57
55
|
escaped = false;
|
|
58
56
|
switch (v) {
|
|
59
|
-
case
|
|
60
|
-
res.push(
|
|
57
|
+
case 0x11:
|
|
58
|
+
res.push(0x1);
|
|
61
59
|
return;
|
|
62
|
-
case
|
|
63
|
-
res.push(
|
|
60
|
+
case 0x27:
|
|
61
|
+
res.push(0x17);
|
|
64
62
|
return;
|
|
65
|
-
case
|
|
66
|
-
res.push(
|
|
63
|
+
case 0x16:
|
|
64
|
+
res.push(0x6);
|
|
67
65
|
return;
|
|
68
|
-
case
|
|
69
|
-
res.push(
|
|
66
|
+
case 0x25:
|
|
67
|
+
res.push(0x15);
|
|
70
68
|
return;
|
|
71
|
-
case
|
|
72
|
-
res.push(
|
|
69
|
+
case 0x12:
|
|
70
|
+
res.push(0x12);
|
|
71
|
+
return;
|
|
72
|
+
case 0x22:
|
|
73
|
+
res.push(0x22);
|
|
73
74
|
return;
|
|
74
75
|
default: res.push(v);
|
|
75
76
|
}
|
|
76
77
|
return;
|
|
77
78
|
}
|
|
78
|
-
if (v ===
|
|
79
|
+
if (v === 0x22) {
|
|
79
80
|
escaped = true;
|
|
80
81
|
}
|
|
81
82
|
else {
|
|
@@ -358,17 +359,17 @@ function getPersonData(user) {
|
|
|
358
359
|
buffer.writeUInt8(0, offset);
|
|
359
360
|
offset += 1;
|
|
360
361
|
}
|
|
361
|
-
buffer.writeInt32LE(
|
|
362
|
+
buffer.writeInt32LE(1, offset);
|
|
362
363
|
offset += 4;
|
|
363
|
-
buffer.writeInt32LE(
|
|
364
|
+
buffer.writeInt32LE(1, offset);
|
|
364
365
|
offset += 4;
|
|
365
|
-
buffer.writeInt32LE(
|
|
366
|
+
buffer.writeInt32LE(175, offset);
|
|
366
367
|
offset += 4;
|
|
367
|
-
buffer.writeFloatLE(
|
|
368
|
+
buffer.writeFloatLE(70, offset);
|
|
368
369
|
offset += 4;
|
|
369
370
|
buffer.writeFloatLE(0, offset);
|
|
370
371
|
offset += 4;
|
|
371
|
-
buffer.writeUInt32LE(
|
|
372
|
+
buffer.writeUInt32LE(1, offset);
|
|
372
373
|
offset += 4;
|
|
373
374
|
return buffer;
|
|
374
375
|
}
|