incyclist-devices 1.4.6 → 1.4.9
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 +1 -0
- package/lib/Device.js +1 -0
- package/lib/daum/DaumAdapter.js +10 -3
- package/lib/daum/ERGCyclingMode.js +2 -1
- package/lib/daum/classic/DaumClassicAdapter.js +5 -0
- package/lib/daum/premium/DaumPremiumAdapter.js +4 -2
- package/lib/daum/premium/bike.d.ts +3 -3
- package/lib/daum/premium/bike.js +38 -22
- package/lib/daum/premium/utils.js +36 -34
- package/package.json +1 -1
package/lib/Device.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export default class DeviceAdapterBase implements DeviceAdapter {
|
|
|
61
61
|
getPort(): string;
|
|
62
62
|
getProtocol(): DeviceProtocol;
|
|
63
63
|
getProtocolName(): string | undefined;
|
|
64
|
+
setCyclingMode(mode: CyclingMode | string, settings?: any): void;
|
|
64
65
|
setIgnoreHrm(ignore: any): void;
|
|
65
66
|
setIgnorePower(ignore: any): void;
|
|
66
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' });
|
|
@@ -131,7 +131,8 @@ class ERGCyclingMode extends CyclingMode_1.CyclingModeBase {
|
|
|
131
131
|
const prevSpeed = prevData.speed;
|
|
132
132
|
const prevRequest = this.prevRequest || {};
|
|
133
133
|
const data = this.data || {};
|
|
134
|
-
const bikeType = this.getSetting('bikeType');
|
|
134
|
+
const bikeType = this.getSetting('bikeType').toLowerCase();
|
|
135
|
+
console.log('~~~ bikeType', bikeType);
|
|
135
136
|
delete this.event.gearUpdated;
|
|
136
137
|
delete this.event.rpmUpdated;
|
|
137
138
|
if (prevData === {} || prevData.speed === undefined || prevData.speed === 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;
|
|
@@ -89,8 +89,10 @@ class DaumPremiumDevice extends DaumAdapter_1.default {
|
|
|
89
89
|
const bikeType = this.getCyclingMode().getSetting('bikeType');
|
|
90
90
|
if (!info.upload)
|
|
91
91
|
info.upload = yield this.bike.programUpload(bikeType, route, props.onStatusUpdate);
|
|
92
|
-
if (!info.started)
|
|
93
|
-
|
|
92
|
+
if (!info.started) {
|
|
93
|
+
const programId = route ? route.programId : 0;
|
|
94
|
+
info.started = yield this.bike.startProgram(programId);
|
|
95
|
+
}
|
|
94
96
|
}
|
|
95
97
|
if (!info.person && this.getCyclingMode().getModeProperty('setPersonSupport')) {
|
|
96
98
|
info.person = yield this.bike.setPerson(user);
|
|
@@ -1,5 +1,5 @@
|
|
|
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";
|
|
@@ -96,10 +96,10 @@ declare class Daum8i {
|
|
|
96
96
|
getPower(power: any): Promise<number>;
|
|
97
97
|
setPerson(person: User): Promise<boolean>;
|
|
98
98
|
programUploadInit(): Promise<boolean>;
|
|
99
|
-
programUploadStart(bikeType:
|
|
99
|
+
programUploadStart(bikeType: string, route?: Route): Promise<Uint8Array>;
|
|
100
100
|
programUploadSendBlock(epp: Uint8Array, offset: number): Promise<boolean>;
|
|
101
101
|
programUploadDone(): Promise<boolean>;
|
|
102
|
-
programUpload(bikeType:
|
|
102
|
+
programUpload(bikeType: string, route: Route, onStatusUpdate?: OnDeviceStartCallback): Promise<boolean>;
|
|
103
103
|
startProgram(programId?: number): Promise<boolean>;
|
|
104
104
|
setGear(gear: any): Promise<number>;
|
|
105
105
|
getGear(): Promise<number>;
|
package/lib/daum/premium/bike.js
CHANGED
|
@@ -26,6 +26,8 @@ const OPEN_TIMEOUT = 1000;
|
|
|
26
26
|
const DAUM_PREMIUM_DEFAULT_PORT = 51955;
|
|
27
27
|
const DAUM_PREMIUM_DEFAULT_HOST = '127.0.0.1';
|
|
28
28
|
const MAX_DATA_BLOCK_SIZE = 512;
|
|
29
|
+
const DS_BITS_OFF = 0;
|
|
30
|
+
const DS_BITS_ENDLESS_RACE = 2;
|
|
29
31
|
var __SerialPort = undefined;
|
|
30
32
|
var net = undefined;
|
|
31
33
|
const DEBUG_LOGGER = {
|
|
@@ -710,7 +712,8 @@ class Daum8i {
|
|
|
710
712
|
});
|
|
711
713
|
}
|
|
712
714
|
setPerson(person) {
|
|
713
|
-
|
|
715
|
+
const { sex, age, length, weight } = person;
|
|
716
|
+
this.logger.logEvent({ message: 'setPerson() request', sex, age, length, weight });
|
|
714
717
|
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PERSON_SET, 'BF', (0, utils_1.getPersonData)(person))
|
|
715
718
|
.then((res) => {
|
|
716
719
|
const buffer = Buffer.from(res);
|
|
@@ -735,10 +738,13 @@ class Daum8i {
|
|
|
735
738
|
}
|
|
736
739
|
programUploadStart(bikeType, route) {
|
|
737
740
|
const payload = Buffer.alloc(40);
|
|
738
|
-
const epp = (0, utils_1.routeToEpp)(route);
|
|
741
|
+
const epp = route ? (0, utils_1.routeToEpp)(route) : undefined;
|
|
742
|
+
const eppLength = epp ? epp.length : 0;
|
|
743
|
+
const bikeTypeVal = (0, utils_1.getBikeType)(bikeType);
|
|
744
|
+
const wBits = route.lapMode ? DS_BITS_ENDLESS_RACE : DS_BITS_OFF;
|
|
739
745
|
payload.writeInt32LE(0, 0);
|
|
740
|
-
payload.writeInt8(
|
|
741
|
-
payload.writeInt8(
|
|
746
|
+
payload.writeInt8(bikeTypeVal, 4);
|
|
747
|
+
payload.writeInt8(0, 5);
|
|
742
748
|
payload.writeInt16LE(0, 6);
|
|
743
749
|
payload.writeInt32LE(0, 8);
|
|
744
750
|
payload.writeInt32LE(0, 12);
|
|
@@ -747,10 +753,10 @@ class Daum8i {
|
|
|
747
753
|
payload.writeInt16LE(0, 24);
|
|
748
754
|
payload.writeInt16LE(0, 26);
|
|
749
755
|
payload.writeInt16LE(0, 28);
|
|
750
|
-
payload.writeInt16LE(
|
|
756
|
+
payload.writeInt16LE(wBits, 30);
|
|
751
757
|
payload.writeInt32LE(7, 32);
|
|
752
|
-
payload.writeInt32LE(
|
|
753
|
-
this.logger.logEvent({ message: 'programUploadStart() request' });
|
|
758
|
+
payload.writeInt32LE(eppLength, 36);
|
|
759
|
+
this.logger.logEvent({ message: 'programUploadStart() request', bikeType, length: eppLength });
|
|
754
760
|
return this.sendReservedDaum8iCommand(utils_1.ReservedCommands.PROGRAM_LIST_NEW_PROGRAM, 'BF', payload)
|
|
755
761
|
.then((res) => {
|
|
756
762
|
const buffer = Buffer.from(res);
|
|
@@ -801,22 +807,32 @@ class Daum8i {
|
|
|
801
807
|
}
|
|
802
808
|
programUpload(bikeType, route, onStatusUpdate) {
|
|
803
809
|
return __awaiter(this, void 0, void 0, function* () {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
810
|
+
try {
|
|
811
|
+
yield this.programUploadInit();
|
|
812
|
+
const epp = yield this.programUploadStart(bikeType, route);
|
|
813
|
+
if (epp) {
|
|
814
|
+
let success = true;
|
|
815
|
+
let done = false;
|
|
816
|
+
let offset = 0;
|
|
817
|
+
if (onStatusUpdate)
|
|
818
|
+
onStatusUpdate(0, epp.length);
|
|
819
|
+
while (success && !done) {
|
|
820
|
+
success = yield this.programUploadSendBlock(epp, offset);
|
|
821
|
+
offset += MAX_DATA_BLOCK_SIZE;
|
|
822
|
+
done = offset >= epp.length;
|
|
823
|
+
if (onStatusUpdate)
|
|
824
|
+
onStatusUpdate(done ? epp.length : offset, epp.length);
|
|
825
|
+
}
|
|
826
|
+
if (done) {
|
|
827
|
+
return yield this.programUploadDone();
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
else {
|
|
831
|
+
return yield this.programUploadDone();
|
|
832
|
+
}
|
|
817
833
|
}
|
|
818
|
-
|
|
819
|
-
|
|
834
|
+
catch (err) {
|
|
835
|
+
console.log('~~~ err', err);
|
|
820
836
|
}
|
|
821
837
|
return false;
|
|
822
838
|
});
|
|
@@ -4,7 +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
7
|
const win32filetime_1 = __importDefault(require("win32filetime"));
|
|
9
8
|
const sum = (arr) => arr.reduce((a, b) => a + b, 0);
|
|
10
9
|
function bin2esc(arr) {
|
|
@@ -14,29 +13,29 @@ function bin2esc(arr) {
|
|
|
14
13
|
const res = [];
|
|
15
14
|
arr.forEach(v => {
|
|
16
15
|
switch (v) {
|
|
17
|
-
case
|
|
18
|
-
res.push(
|
|
19
|
-
res.push(
|
|
16
|
+
case 0x12:
|
|
17
|
+
res.push(0x22);
|
|
18
|
+
res.push(0x12);
|
|
20
19
|
break;
|
|
21
|
-
case
|
|
22
|
-
res.push(
|
|
23
|
-
res.push(
|
|
20
|
+
case 0x22:
|
|
21
|
+
res.push(0x22);
|
|
22
|
+
res.push(0x22);
|
|
24
23
|
break;
|
|
25
|
-
case
|
|
26
|
-
res.push(
|
|
27
|
-
res.push(
|
|
24
|
+
case 0x01:
|
|
25
|
+
res.push(0x22);
|
|
26
|
+
res.push(0x11);
|
|
28
27
|
break;
|
|
29
|
-
case
|
|
30
|
-
res.push(
|
|
31
|
-
res.push(
|
|
28
|
+
case 0x17:
|
|
29
|
+
res.push(0x22);
|
|
30
|
+
res.push(0x27);
|
|
32
31
|
break;
|
|
33
|
-
case
|
|
34
|
-
res.push(
|
|
35
|
-
res.push(
|
|
32
|
+
case 0x06:
|
|
33
|
+
res.push(0x22);
|
|
34
|
+
res.push(0x16);
|
|
36
35
|
break;
|
|
37
|
-
case
|
|
38
|
-
res.push(
|
|
39
|
-
res.push(
|
|
36
|
+
case 0x15:
|
|
37
|
+
res.push(0x22);
|
|
38
|
+
res.push(0x25);
|
|
40
39
|
break;
|
|
41
40
|
default:
|
|
42
41
|
res.push(v);
|
|
@@ -55,26 +54,29 @@ function esc2bin(arr) {
|
|
|
55
54
|
if (escaped) {
|
|
56
55
|
escaped = false;
|
|
57
56
|
switch (v) {
|
|
58
|
-
case
|
|
59
|
-
res.push(
|
|
57
|
+
case 0x11:
|
|
58
|
+
res.push(0x1);
|
|
60
59
|
return;
|
|
61
|
-
case
|
|
62
|
-
res.push(
|
|
60
|
+
case 0x27:
|
|
61
|
+
res.push(0x17);
|
|
63
62
|
return;
|
|
64
|
-
case
|
|
65
|
-
res.push(
|
|
63
|
+
case 0x16:
|
|
64
|
+
res.push(0x6);
|
|
66
65
|
return;
|
|
67
|
-
case
|
|
68
|
-
res.push(
|
|
66
|
+
case 0x25:
|
|
67
|
+
res.push(0x15);
|
|
69
68
|
return;
|
|
70
|
-
case
|
|
71
|
-
res.push(
|
|
69
|
+
case 0x12:
|
|
70
|
+
res.push(0x12);
|
|
71
|
+
return;
|
|
72
|
+
case 0x22:
|
|
73
|
+
res.push(0x22);
|
|
72
74
|
return;
|
|
73
75
|
default: res.push(v);
|
|
74
76
|
}
|
|
75
77
|
return;
|
|
76
78
|
}
|
|
77
|
-
if (v ===
|
|
79
|
+
if (v === 0x22) {
|
|
78
80
|
escaped = true;
|
|
79
81
|
}
|
|
80
82
|
else {
|
|
@@ -357,13 +359,13 @@ function getPersonData(user) {
|
|
|
357
359
|
buffer.writeUInt8(0, offset);
|
|
358
360
|
offset += 1;
|
|
359
361
|
}
|
|
360
|
-
buffer.writeInt32LE(
|
|
362
|
+
buffer.writeInt32LE(1, offset);
|
|
361
363
|
offset += 4;
|
|
362
|
-
buffer.writeInt32LE(
|
|
364
|
+
buffer.writeInt32LE(1, offset);
|
|
363
365
|
offset += 4;
|
|
364
|
-
buffer.writeInt32LE(
|
|
366
|
+
buffer.writeInt32LE(175, offset);
|
|
365
367
|
offset += 4;
|
|
366
|
-
buffer.writeFloatLE(
|
|
368
|
+
buffer.writeFloatLE(70, offset);
|
|
367
369
|
offset += 4;
|
|
368
370
|
buffer.writeFloatLE(0, offset);
|
|
369
371
|
offset += 4;
|