incyclist-devices 1.5.11 → 1.5.12
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/LICENSE +0 -0
- package/lib/DeviceSupport.d.ts +36 -36
- package/lib/DeviceSupport.js +82 -82
- package/lib/ant/AntAdapter.d.ts +50 -50
- package/lib/ant/AntAdapter.js +109 -109
- package/lib/ant/AntScanner.d.ts +60 -60
- package/lib/ant/AntScanner.js +651 -651
- package/lib/ant/antfe/AntFEAdapter.d.ts +83 -83
- package/lib/ant/antfe/AntFEAdapter.js +652 -652
- package/lib/ant/antfe/ant-fe-adv-st-mode.d.ts +9 -9
- package/lib/ant/antfe/ant-fe-adv-st-mode.js +51 -51
- package/lib/ant/antfe/ant-fe-erg-mode.d.ts +6 -6
- package/lib/ant/antfe/ant-fe-erg-mode.js +14 -14
- package/lib/ant/antfe/ant-fe-st-mode.d.ts +5 -5
- package/lib/ant/antfe/ant-fe-st-mode.js +13 -13
- package/lib/ant/anthrm/AntHrmAdapter.d.ts +16 -16
- package/lib/ant/anthrm/AntHrmAdapter.js +130 -130
- package/lib/ant/antpwr/pwr-adapter.d.ts +49 -49
- package/lib/ant/antpwr/pwr-adapter.js +251 -251
- package/lib/ant/utils.d.ts +1 -1
- package/lib/ant/utils.js +23 -23
- package/lib/antv2/AntAdapter.d.ts +48 -0
- package/lib/antv2/AntAdapter.js +104 -0
- package/lib/antv2/adapter-factory.d.ts +11 -11
- package/lib/antv2/adapter-factory.js +40 -40
- package/lib/antv2/ant-binding.d.ts +13 -13
- package/lib/antv2/ant-binding.js +27 -27
- package/lib/antv2/ant-device.d.ts +51 -51
- package/lib/antv2/ant-device.js +115 -115
- package/lib/antv2/ant-interface.d.ts +37 -37
- package/lib/antv2/ant-interface.js +255 -255
- package/lib/antv2/fe.d.ts +29 -29
- package/lib/antv2/fe.js +262 -262
- package/lib/antv2/hr.d.ts +18 -18
- package/lib/antv2/hr.js +93 -93
- package/lib/antv2/incyclist-protocol.d.ts +37 -37
- package/lib/antv2/incyclist-protocol.js +126 -126
- package/lib/antv2/pwr.d.ts +28 -28
- package/lib/antv2/pwr.js +163 -163
- package/lib/antv2/sensor-factory.d.ts +5 -5
- package/lib/antv2/sensor-factory.js +20 -20
- package/lib/ble/ble-device.d.ts +63 -63
- package/lib/ble/ble-device.js +444 -444
- package/lib/ble/ble-erg-mode.d.ts +18 -18
- package/lib/ble/ble-erg-mode.js +132 -132
- package/lib/ble/ble-interface.d.ts +100 -100
- package/lib/ble/ble-interface.js +721 -721
- package/lib/ble/ble-peripheral.d.ts +36 -36
- package/lib/ble/ble-peripheral.js +200 -200
- package/lib/ble/ble-st-mode.d.ts +15 -15
- package/lib/ble/ble-st-mode.js +95 -95
- package/lib/ble/ble.d.ts +129 -129
- package/lib/ble/ble.js +86 -86
- package/lib/ble/consts.d.ts +14 -14
- package/lib/ble/consts.js +17 -17
- package/lib/ble/elite.d.ts +90 -90
- package/lib/ble/elite.js +322 -322
- package/lib/ble/fm.d.ts +125 -125
- package/lib/ble/fm.js +745 -745
- package/lib/ble/hrm.d.ts +48 -48
- package/lib/ble/hrm.js +134 -134
- package/lib/ble/incyclist-protocol.d.ts +31 -31
- package/lib/ble/incyclist-protocol.js +153 -153
- package/lib/ble/pwr.d.ts +89 -89
- package/lib/ble/pwr.js +321 -321
- package/lib/ble/tacx.d.ts +92 -90
- package/lib/ble/tacx.js +763 -731
- package/lib/ble/wahoo-kickr.d.ts +98 -98
- package/lib/ble/wahoo-kickr.js +496 -496
- package/lib/calculations.d.ts +13 -13
- package/lib/calculations.js +150 -150
- package/lib/cycling-mode.d.ts +76 -76
- package/lib/cycling-mode.js +79 -79
- package/lib/daum/DaumAdapter.d.ts +66 -66
- package/lib/daum/DaumAdapter.js +396 -396
- package/lib/daum/DaumPowerMeterCyclingMode.d.ts +8 -8
- package/lib/daum/DaumPowerMeterCyclingMode.js +21 -21
- package/lib/daum/ERGCyclingMode.d.ts +26 -26
- package/lib/daum/ERGCyclingMode.js +201 -201
- package/lib/daum/SmartTrainerCyclingMode.d.ts +41 -41
- package/lib/daum/SmartTrainerCyclingMode.js +344 -344
- package/lib/daum/classic/DaumClassicAdapter.d.ts +22 -22
- package/lib/daum/classic/DaumClassicAdapter.js +183 -183
- package/lib/daum/classic/DaumClassicCyclingMode.d.ts +13 -13
- package/lib/daum/classic/DaumClassicCyclingMode.js +97 -97
- package/lib/daum/classic/DaumClassicProtocol.d.ts +27 -27
- package/lib/daum/classic/DaumClassicProtocol.js +185 -185
- package/lib/daum/classic/bike.d.ts +68 -68
- package/lib/daum/classic/bike.js +467 -467
- package/lib/daum/classic/utils.d.ts +13 -13
- package/lib/daum/classic/utils.js +143 -143
- package/lib/daum/constants.d.ts +19 -19
- package/lib/daum/constants.js +22 -22
- package/lib/daum/premium/DaumClassicCyclingMode.d.ts +14 -14
- package/lib/daum/premium/DaumClassicCyclingMode.js +86 -86
- package/lib/daum/premium/DaumPremiumAdapter.d.ts +16 -16
- package/lib/daum/premium/DaumPremiumAdapter.js +163 -163
- package/lib/daum/premium/DaumPremiumProtocol.d.ts +32 -32
- package/lib/daum/premium/DaumPremiumProtocol.js +207 -207
- package/lib/daum/premium/bike.d.ts +127 -127
- package/lib/daum/premium/bike.js +904 -904
- package/lib/daum/premium/tcpserial.d.ts +33 -33
- package/lib/daum/premium/tcpserial.js +123 -123
- package/lib/daum/premium/utils.d.ts +62 -62
- package/lib/daum/premium/utils.js +376 -376
- package/lib/device.d.ts +92 -92
- package/lib/device.js +71 -71
- package/lib/kettler/comms.d.ts +59 -59
- package/lib/kettler/comms.js +242 -242
- package/lib/kettler/ergo-racer/ERGCyclingMode.d.ts +25 -25
- package/lib/kettler/ergo-racer/ERGCyclingMode.js +144 -144
- package/lib/kettler/ergo-racer/adapter.d.ts +101 -101
- package/lib/kettler/ergo-racer/adapter.js +639 -639
- package/lib/kettler/ergo-racer/protocol.d.ts +41 -41
- package/lib/kettler/ergo-racer/protocol.js +203 -203
- package/lib/modes/power-base.d.ts +20 -20
- package/lib/modes/power-base.js +70 -70
- package/lib/modes/power-meter.d.ts +20 -20
- package/lib/modes/power-meter.js +78 -78
- package/lib/modes/simulator.d.ts +29 -29
- package/lib/modes/simulator.js +140 -140
- package/lib/protocol.d.ts +74 -74
- package/lib/protocol.js +41 -41
- package/lib/registry.d.ts +8 -8
- package/lib/registry.js +33 -33
- package/lib/simulator/Simulator.d.ts +69 -69
- package/lib/simulator/Simulator.js +288 -288
- package/lib/types/command.d.ts +8 -8
- package/lib/types/command.js +2 -2
- package/lib/types/route.d.ts +24 -24
- package/lib/types/route.js +9 -9
- package/lib/types/user.d.ts +11 -11
- package/lib/types/user.js +9 -9
- package/lib/utils.d.ts +14 -14
- package/lib/utils.js +114 -114
- package/package.json +47 -47
|
@@ -1,376 +1,376 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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 win32filetime_1 = __importDefault(require("win32filetime"));
|
|
8
|
-
const sum = (arr) => arr.reduce((a, b) => a + b, 0);
|
|
9
|
-
function bin2esc(arr) {
|
|
10
|
-
if (arr === undefined) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
const res = [];
|
|
14
|
-
arr.forEach(v => {
|
|
15
|
-
switch (v) {
|
|
16
|
-
case 0x12:
|
|
17
|
-
res.push(0x22);
|
|
18
|
-
res.push(0x12);
|
|
19
|
-
break;
|
|
20
|
-
case 0x22:
|
|
21
|
-
res.push(0x22);
|
|
22
|
-
res.push(0x22);
|
|
23
|
-
break;
|
|
24
|
-
case 0x01:
|
|
25
|
-
res.push(0x22);
|
|
26
|
-
res.push(0x11);
|
|
27
|
-
break;
|
|
28
|
-
case 0x17:
|
|
29
|
-
res.push(0x22);
|
|
30
|
-
res.push(0x27);
|
|
31
|
-
break;
|
|
32
|
-
case 0x06:
|
|
33
|
-
res.push(0x22);
|
|
34
|
-
res.push(0x16);
|
|
35
|
-
break;
|
|
36
|
-
case 0x15:
|
|
37
|
-
res.push(0x22);
|
|
38
|
-
res.push(0x25);
|
|
39
|
-
break;
|
|
40
|
-
default:
|
|
41
|
-
res.push(v);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
return res;
|
|
45
|
-
}
|
|
46
|
-
exports.bin2esc = bin2esc;
|
|
47
|
-
function esc2bin(arr) {
|
|
48
|
-
if (arr === undefined) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const res = [];
|
|
52
|
-
let escaped = false;
|
|
53
|
-
arr.forEach((v, idx) => {
|
|
54
|
-
if (escaped) {
|
|
55
|
-
escaped = false;
|
|
56
|
-
switch (v) {
|
|
57
|
-
case 0x11:
|
|
58
|
-
res.push(0x1);
|
|
59
|
-
return;
|
|
60
|
-
case 0x27:
|
|
61
|
-
res.push(0x17);
|
|
62
|
-
return;
|
|
63
|
-
case 0x16:
|
|
64
|
-
res.push(0x6);
|
|
65
|
-
return;
|
|
66
|
-
case 0x25:
|
|
67
|
-
res.push(0x15);
|
|
68
|
-
return;
|
|
69
|
-
case 0x12:
|
|
70
|
-
res.push(0x12);
|
|
71
|
-
return;
|
|
72
|
-
case 0x22:
|
|
73
|
-
res.push(0x22);
|
|
74
|
-
return;
|
|
75
|
-
default: res.push(v);
|
|
76
|
-
}
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
if (v === 0x22) {
|
|
80
|
-
escaped = true;
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
res.push(v);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
return res;
|
|
87
|
-
}
|
|
88
|
-
exports.esc2bin = esc2bin;
|
|
89
|
-
function checkSum(cmdArr, payload) {
|
|
90
|
-
const total = sum(cmdArr) + sum(payload);
|
|
91
|
-
const checkSumVal = total % 100;
|
|
92
|
-
let checkSumStr = checkSumVal.toString();
|
|
93
|
-
while (checkSumStr.length < 2)
|
|
94
|
-
checkSumStr = '0' + checkSumStr;
|
|
95
|
-
return checkSumStr;
|
|
96
|
-
}
|
|
97
|
-
exports.checkSum = checkSum;
|
|
98
|
-
function buildMessage(command, payload) {
|
|
99
|
-
const cmdArr = getAsciiArrayFromStr(command);
|
|
100
|
-
let data = payload || [];
|
|
101
|
-
if (typeof (payload) === 'number')
|
|
102
|
-
data = [payload];
|
|
103
|
-
if (typeof (payload) === 'string')
|
|
104
|
-
data = getAsciiArrayFromStr(payload);
|
|
105
|
-
const checkSumVals = getAsciiArrayFromStr(checkSum(cmdArr, data));
|
|
106
|
-
const message = [];
|
|
107
|
-
message.push(0x01);
|
|
108
|
-
message.push(...cmdArr);
|
|
109
|
-
if (data.length > 0)
|
|
110
|
-
message.push(...data);
|
|
111
|
-
message.push(...checkSumVals);
|
|
112
|
-
message.push(0x17);
|
|
113
|
-
return message;
|
|
114
|
-
}
|
|
115
|
-
exports.buildMessage = buildMessage;
|
|
116
|
-
function getMessageData(command) {
|
|
117
|
-
const res = [...command];
|
|
118
|
-
res.splice(0, 4);
|
|
119
|
-
res.splice(-3, 3);
|
|
120
|
-
return res;
|
|
121
|
-
}
|
|
122
|
-
exports.getMessageData = getMessageData;
|
|
123
|
-
function hexstr(arr, start, len) {
|
|
124
|
-
const isArr = Array.isArray(arr) || arr instanceof Uint8Array;
|
|
125
|
-
if (!arr)
|
|
126
|
-
return '';
|
|
127
|
-
var str = "";
|
|
128
|
-
if (start === undefined)
|
|
129
|
-
start = 0;
|
|
130
|
-
if (len === undefined || (start + len > arr.length)) {
|
|
131
|
-
len = arr.length - start;
|
|
132
|
-
}
|
|
133
|
-
if (len < 0)
|
|
134
|
-
return '';
|
|
135
|
-
var j = start;
|
|
136
|
-
for (var i = 0; i < len; i++) {
|
|
137
|
-
const c = isArr ? arr[j++] : ascii(arr.charAt(j++));
|
|
138
|
-
var hex = Math.abs(c).toString(16);
|
|
139
|
-
if (hex.length < 2)
|
|
140
|
-
hex = '0' + hex;
|
|
141
|
-
if (i !== 0)
|
|
142
|
-
str += " ";
|
|
143
|
-
str += hex;
|
|
144
|
-
}
|
|
145
|
-
return str;
|
|
146
|
-
}
|
|
147
|
-
exports.hexstr = hexstr;
|
|
148
|
-
function getHex(i) { return ('00' + i.toString(16)).slice(-2); }
|
|
149
|
-
exports.getHex = getHex;
|
|
150
|
-
function append(cmd, arr) { cmd.push(...arr); }
|
|
151
|
-
exports.append = append;
|
|
152
|
-
function ascii(c) {
|
|
153
|
-
if (c === undefined || c === null)
|
|
154
|
-
return;
|
|
155
|
-
return c.charCodeAt(0);
|
|
156
|
-
}
|
|
157
|
-
exports.ascii = ascii;
|
|
158
|
-
function charArrayToString(arr) {
|
|
159
|
-
if (arr === undefined || arr == null)
|
|
160
|
-
return undefined;
|
|
161
|
-
let str = '';
|
|
162
|
-
arr.forEach(c => str += c);
|
|
163
|
-
return str;
|
|
164
|
-
}
|
|
165
|
-
exports.charArrayToString = charArrayToString;
|
|
166
|
-
function asciiArrayToString(arr) {
|
|
167
|
-
if (arr === undefined || arr == null)
|
|
168
|
-
return undefined;
|
|
169
|
-
let str = '';
|
|
170
|
-
arr.forEach(c => str += String.fromCharCode(c));
|
|
171
|
-
return str;
|
|
172
|
-
}
|
|
173
|
-
exports.asciiArrayToString = asciiArrayToString;
|
|
174
|
-
function getAsciiArrayFromStr(str) {
|
|
175
|
-
if (str === undefined || str === null)
|
|
176
|
-
return undefined;
|
|
177
|
-
const n = str.length;
|
|
178
|
-
let result = [];
|
|
179
|
-
for (let i = 0; i < n; i++) {
|
|
180
|
-
result.push(str.charCodeAt(i));
|
|
181
|
-
}
|
|
182
|
-
return result;
|
|
183
|
-
}
|
|
184
|
-
exports.getAsciiArrayFromStr = getAsciiArrayFromStr;
|
|
185
|
-
function Float32ToHex(float32) {
|
|
186
|
-
var view = new DataView(new ArrayBuffer(4));
|
|
187
|
-
view.setFloat32(0, float32);
|
|
188
|
-
return Array.apply(null, { length: 4 }).map((_, i) => getHex(view.getUint8(i))).join('');
|
|
189
|
-
}
|
|
190
|
-
exports.Float32ToHex = Float32ToHex;
|
|
191
|
-
function Float32ToIntArray(float32) {
|
|
192
|
-
var view = new DataView(new ArrayBuffer(4));
|
|
193
|
-
view.setFloat32(0, float32);
|
|
194
|
-
var arr = [];
|
|
195
|
-
for (let i = 0; i < 4; i++) {
|
|
196
|
-
arr.push(view.getUint8(i));
|
|
197
|
-
}
|
|
198
|
-
return arr;
|
|
199
|
-
}
|
|
200
|
-
exports.Float32ToIntArray = Float32ToIntArray;
|
|
201
|
-
function Int16ToIntArray(int16) {
|
|
202
|
-
var view = new DataView(new ArrayBuffer(2));
|
|
203
|
-
view.setInt16(0, int16);
|
|
204
|
-
var arr = [];
|
|
205
|
-
for (let i = 0; i < 2; i++) {
|
|
206
|
-
arr.push(view.getUint8(i));
|
|
207
|
-
}
|
|
208
|
-
return arr;
|
|
209
|
-
}
|
|
210
|
-
exports.Int16ToIntArray = Int16ToIntArray;
|
|
211
|
-
function Int32ToIntArray(int32) {
|
|
212
|
-
var view = new DataView(new ArrayBuffer(4));
|
|
213
|
-
view.setInt32(0, int32);
|
|
214
|
-
var arr = [];
|
|
215
|
-
for (let i = 0; i < 4; i++) {
|
|
216
|
-
arr.push(view.getUint8(i));
|
|
217
|
-
}
|
|
218
|
-
return arr;
|
|
219
|
-
}
|
|
220
|
-
exports.Int32ToIntArray = Int32ToIntArray;
|
|
221
|
-
var ReservedCommands;
|
|
222
|
-
(function (ReservedCommands) {
|
|
223
|
-
ReservedCommands[ReservedCommands["RESULT_RESET"] = 0] = "RESULT_RESET";
|
|
224
|
-
ReservedCommands[ReservedCommands["RESULT_GET"] = 1] = "RESULT_GET";
|
|
225
|
-
ReservedCommands[ReservedCommands["NETRACE_START"] = 2] = "NETRACE_START";
|
|
226
|
-
ReservedCommands[ReservedCommands["NETRACE_STOP"] = 3] = "NETRACE_STOP";
|
|
227
|
-
ReservedCommands[ReservedCommands["NETRACE_USERNAME"] = 4] = "NETRACE_USERNAME";
|
|
228
|
-
ReservedCommands[ReservedCommands["NETRACE_USERDATA"] = 5] = "NETRACE_USERDATA";
|
|
229
|
-
ReservedCommands[ReservedCommands["PERSON_GET"] = 6] = "PERSON_GET";
|
|
230
|
-
ReservedCommands[ReservedCommands["PERSON_SET"] = 7] = "PERSON_SET";
|
|
231
|
-
ReservedCommands[ReservedCommands["PROGRAM_LIST_BEGIN"] = 8] = "PROGRAM_LIST_BEGIN";
|
|
232
|
-
ReservedCommands[ReservedCommands["PROGRAM_LIST_NEW_PROGRAM"] = 9] = "PROGRAM_LIST_NEW_PROGRAM";
|
|
233
|
-
ReservedCommands[ReservedCommands["PROGRAM_LIST_CONTINUE_PROGRAM"] = 10] = "PROGRAM_LIST_CONTINUE_PROGRAM";
|
|
234
|
-
ReservedCommands[ReservedCommands["PROGRAM_LIST_END"] = 11] = "PROGRAM_LIST_END";
|
|
235
|
-
ReservedCommands[ReservedCommands["PROGRAM_LIST_START"] = 12] = "PROGRAM_LIST_START";
|
|
236
|
-
ReservedCommands[ReservedCommands["RELAX_START"] = 12] = "RELAX_START";
|
|
237
|
-
ReservedCommands[ReservedCommands["RELAX_STOP"] = 14] = "RELAX_STOP";
|
|
238
|
-
ReservedCommands[ReservedCommands["RELAX_GET_DATA"] = 15] = "RELAX_GET_DATA";
|
|
239
|
-
ReservedCommands[ReservedCommands["KEY_PRESSED"] = 16] = "KEY_PRESSED";
|
|
240
|
-
ReservedCommands[ReservedCommands["PROGRAM_CONTROL"] = 17] = "PROGRAM_CONTROL";
|
|
241
|
-
})(ReservedCommands = exports.ReservedCommands || (exports.ReservedCommands = {}));
|
|
242
|
-
var BikeType;
|
|
243
|
-
(function (BikeType) {
|
|
244
|
-
BikeType[BikeType["ALLROUND"] = 0] = "ALLROUND";
|
|
245
|
-
BikeType[BikeType["RACE"] = 1] = "RACE";
|
|
246
|
-
BikeType[BikeType["MOUNTAIN"] = 2] = "MOUNTAIN";
|
|
247
|
-
})(BikeType = exports.BikeType || (exports.BikeType = {}));
|
|
248
|
-
function getBikeType(bikeTypeStr) {
|
|
249
|
-
if (bikeTypeStr === undefined || bikeTypeStr === null)
|
|
250
|
-
return BikeType.RACE;
|
|
251
|
-
if (bikeTypeStr.toLowerCase() === 'mountain')
|
|
252
|
-
return BikeType.MOUNTAIN;
|
|
253
|
-
return BikeType.RACE;
|
|
254
|
-
}
|
|
255
|
-
exports.getBikeType = getBikeType;
|
|
256
|
-
function routeToEpp(route, date) {
|
|
257
|
-
const buffer = Buffer.alloc(376 + route.points.length * 12);
|
|
258
|
-
const fileTime = win32filetime_1.default.fromUnix(date ? date : Date.now());
|
|
259
|
-
let offset = 0;
|
|
260
|
-
const name = route.name || '';
|
|
261
|
-
const description = route.description || '';
|
|
262
|
-
const minElevation = route.minElevation ? route.minElevation : 0;
|
|
263
|
-
const maxElevation = route.maxElevation ? route.minElevation : Math.max(...route.points.map(p => p.elevation));
|
|
264
|
-
const sampleRate = route.points.length !== 0 ? Math.round(route.totalDistance / route.points.length) : 0;
|
|
265
|
-
buffer.writeUInt32LE(fileTime.low, offset);
|
|
266
|
-
offset += 4;
|
|
267
|
-
buffer.writeUInt32LE(fileTime.high, offset);
|
|
268
|
-
offset += 4;
|
|
269
|
-
buffer.write(name, offset, name.length, 'ascii');
|
|
270
|
-
offset += 64;
|
|
271
|
-
buffer.write(description, offset, description.length, 'ascii');
|
|
272
|
-
offset += 256;
|
|
273
|
-
buffer.writeInt32LE(0x10, offset);
|
|
274
|
-
offset += 4;
|
|
275
|
-
buffer.writeInt32LE(0x0, offset);
|
|
276
|
-
offset += 4;
|
|
277
|
-
buffer.writeInt32LE(minElevation, offset);
|
|
278
|
-
offset += 4;
|
|
279
|
-
buffer.writeInt32LE(maxElevation, offset);
|
|
280
|
-
offset += 4;
|
|
281
|
-
buffer.writeInt32LE(route.points.length, offset);
|
|
282
|
-
offset += 4;
|
|
283
|
-
buffer.writeInt32LE(sampleRate, offset);
|
|
284
|
-
offset += 4;
|
|
285
|
-
buffer.writeInt32LE(0x01, offset);
|
|
286
|
-
offset += 4;
|
|
287
|
-
buffer.writeInt32LE(0x0, offset);
|
|
288
|
-
offset += 4;
|
|
289
|
-
buffer.writeInt16LE(0x0, offset);
|
|
290
|
-
offset += 2;
|
|
291
|
-
buffer.writeInt16LE(0x0, offset);
|
|
292
|
-
offset += 2;
|
|
293
|
-
buffer.writeInt32LE(0x0, offset);
|
|
294
|
-
offset += 4;
|
|
295
|
-
buffer.writeInt32LE(0x0, offset);
|
|
296
|
-
offset += 4;
|
|
297
|
-
buffer.writeInt32LE(0x0, offset);
|
|
298
|
-
offset += 4;
|
|
299
|
-
route.points.forEach(p => {
|
|
300
|
-
buffer.writeUInt32LE(sampleRate, offset);
|
|
301
|
-
offset += 4;
|
|
302
|
-
buffer.writeFloatLE(p.elevation, offset);
|
|
303
|
-
offset += 4;
|
|
304
|
-
buffer.writeFloatLE(0, offset);
|
|
305
|
-
offset += 4;
|
|
306
|
-
});
|
|
307
|
-
return new Uint8Array(buffer);
|
|
308
|
-
}
|
|
309
|
-
exports.routeToEpp = routeToEpp;
|
|
310
|
-
function parseTrainingData(payload) {
|
|
311
|
-
const GS = 0x1D;
|
|
312
|
-
const speedVals = ['ok', 'too low', 'too high'];
|
|
313
|
-
const gearVal = (v) => v > 0 ? v - 1 : undefined;
|
|
314
|
-
const vals = payload.split(String.fromCharCode(GS));
|
|
315
|
-
const data = {
|
|
316
|
-
time: parseInt(vals[0]),
|
|
317
|
-
heartrate: parseInt(vals[1]),
|
|
318
|
-
speed: parseFloat(vals[2]) * 3.6,
|
|
319
|
-
slope: parseFloat(vals[3]),
|
|
320
|
-
distanceInternal: parseInt(vals[4]),
|
|
321
|
-
cadence: parseFloat(vals[5]),
|
|
322
|
-
power: parseInt(vals[6]),
|
|
323
|
-
physEnergy: parseFloat(vals[7]),
|
|
324
|
-
realEnergy: parseFloat(vals[8]),
|
|
325
|
-
torque: parseFloat(vals[9]),
|
|
326
|
-
gear: gearVal(parseInt(vals[10])),
|
|
327
|
-
deviceState: parseInt(vals[11]),
|
|
328
|
-
speedStatus: speedVals[parseInt(vals[12])],
|
|
329
|
-
};
|
|
330
|
-
return data;
|
|
331
|
-
}
|
|
332
|
-
exports.parseTrainingData = parseTrainingData;
|
|
333
|
-
function getPersonData(user) {
|
|
334
|
-
const buffer = Buffer.alloc(136);
|
|
335
|
-
let offset = 0;
|
|
336
|
-
for (let i = 0; i < 4; i++) {
|
|
337
|
-
buffer.writeInt32LE(0, offset);
|
|
338
|
-
offset += 4;
|
|
339
|
-
buffer.writeFloatLE(-100, offset);
|
|
340
|
-
offset += 4;
|
|
341
|
-
buffer.writeFloatLE(0, offset);
|
|
342
|
-
offset += 4;
|
|
343
|
-
buffer.writeFloatLE(0, offset);
|
|
344
|
-
offset += 4;
|
|
345
|
-
buffer.writeUInt16LE(0, offset);
|
|
346
|
-
offset += 2;
|
|
347
|
-
buffer.writeUInt16LE(0, offset);
|
|
348
|
-
offset += 2;
|
|
349
|
-
buffer.writeUInt16LE(0, offset);
|
|
350
|
-
offset += 2;
|
|
351
|
-
buffer.writeUInt16LE(0, offset);
|
|
352
|
-
offset += 2;
|
|
353
|
-
buffer.writeUInt8(0, offset);
|
|
354
|
-
offset += 1;
|
|
355
|
-
buffer.writeUInt8(0, offset);
|
|
356
|
-
offset += 1;
|
|
357
|
-
buffer.writeUInt8(0, offset);
|
|
358
|
-
offset += 1;
|
|
359
|
-
buffer.writeUInt8(0, offset);
|
|
360
|
-
offset += 1;
|
|
361
|
-
}
|
|
362
|
-
buffer.writeInt32LE(1, offset);
|
|
363
|
-
offset += 4;
|
|
364
|
-
buffer.writeInt32LE(1, offset);
|
|
365
|
-
offset += 4;
|
|
366
|
-
buffer.writeInt32LE(175, offset);
|
|
367
|
-
offset += 4;
|
|
368
|
-
buffer.writeFloatLE(70, offset);
|
|
369
|
-
offset += 4;
|
|
370
|
-
buffer.writeFloatLE(0, offset);
|
|
371
|
-
offset += 4;
|
|
372
|
-
buffer.writeUInt32LE(1, offset);
|
|
373
|
-
offset += 4;
|
|
374
|
-
return buffer;
|
|
375
|
-
}
|
|
376
|
-
exports.getPersonData = getPersonData;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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 win32filetime_1 = __importDefault(require("win32filetime"));
|
|
8
|
+
const sum = (arr) => arr.reduce((a, b) => a + b, 0);
|
|
9
|
+
function bin2esc(arr) {
|
|
10
|
+
if (arr === undefined) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const res = [];
|
|
14
|
+
arr.forEach(v => {
|
|
15
|
+
switch (v) {
|
|
16
|
+
case 0x12:
|
|
17
|
+
res.push(0x22);
|
|
18
|
+
res.push(0x12);
|
|
19
|
+
break;
|
|
20
|
+
case 0x22:
|
|
21
|
+
res.push(0x22);
|
|
22
|
+
res.push(0x22);
|
|
23
|
+
break;
|
|
24
|
+
case 0x01:
|
|
25
|
+
res.push(0x22);
|
|
26
|
+
res.push(0x11);
|
|
27
|
+
break;
|
|
28
|
+
case 0x17:
|
|
29
|
+
res.push(0x22);
|
|
30
|
+
res.push(0x27);
|
|
31
|
+
break;
|
|
32
|
+
case 0x06:
|
|
33
|
+
res.push(0x22);
|
|
34
|
+
res.push(0x16);
|
|
35
|
+
break;
|
|
36
|
+
case 0x15:
|
|
37
|
+
res.push(0x22);
|
|
38
|
+
res.push(0x25);
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
res.push(v);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return res;
|
|
45
|
+
}
|
|
46
|
+
exports.bin2esc = bin2esc;
|
|
47
|
+
function esc2bin(arr) {
|
|
48
|
+
if (arr === undefined) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const res = [];
|
|
52
|
+
let escaped = false;
|
|
53
|
+
arr.forEach((v, idx) => {
|
|
54
|
+
if (escaped) {
|
|
55
|
+
escaped = false;
|
|
56
|
+
switch (v) {
|
|
57
|
+
case 0x11:
|
|
58
|
+
res.push(0x1);
|
|
59
|
+
return;
|
|
60
|
+
case 0x27:
|
|
61
|
+
res.push(0x17);
|
|
62
|
+
return;
|
|
63
|
+
case 0x16:
|
|
64
|
+
res.push(0x6);
|
|
65
|
+
return;
|
|
66
|
+
case 0x25:
|
|
67
|
+
res.push(0x15);
|
|
68
|
+
return;
|
|
69
|
+
case 0x12:
|
|
70
|
+
res.push(0x12);
|
|
71
|
+
return;
|
|
72
|
+
case 0x22:
|
|
73
|
+
res.push(0x22);
|
|
74
|
+
return;
|
|
75
|
+
default: res.push(v);
|
|
76
|
+
}
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (v === 0x22) {
|
|
80
|
+
escaped = true;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
res.push(v);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return res;
|
|
87
|
+
}
|
|
88
|
+
exports.esc2bin = esc2bin;
|
|
89
|
+
function checkSum(cmdArr, payload) {
|
|
90
|
+
const total = sum(cmdArr) + sum(payload);
|
|
91
|
+
const checkSumVal = total % 100;
|
|
92
|
+
let checkSumStr = checkSumVal.toString();
|
|
93
|
+
while (checkSumStr.length < 2)
|
|
94
|
+
checkSumStr = '0' + checkSumStr;
|
|
95
|
+
return checkSumStr;
|
|
96
|
+
}
|
|
97
|
+
exports.checkSum = checkSum;
|
|
98
|
+
function buildMessage(command, payload) {
|
|
99
|
+
const cmdArr = getAsciiArrayFromStr(command);
|
|
100
|
+
let data = payload || [];
|
|
101
|
+
if (typeof (payload) === 'number')
|
|
102
|
+
data = [payload];
|
|
103
|
+
if (typeof (payload) === 'string')
|
|
104
|
+
data = getAsciiArrayFromStr(payload);
|
|
105
|
+
const checkSumVals = getAsciiArrayFromStr(checkSum(cmdArr, data));
|
|
106
|
+
const message = [];
|
|
107
|
+
message.push(0x01);
|
|
108
|
+
message.push(...cmdArr);
|
|
109
|
+
if (data.length > 0)
|
|
110
|
+
message.push(...data);
|
|
111
|
+
message.push(...checkSumVals);
|
|
112
|
+
message.push(0x17);
|
|
113
|
+
return message;
|
|
114
|
+
}
|
|
115
|
+
exports.buildMessage = buildMessage;
|
|
116
|
+
function getMessageData(command) {
|
|
117
|
+
const res = [...command];
|
|
118
|
+
res.splice(0, 4);
|
|
119
|
+
res.splice(-3, 3);
|
|
120
|
+
return res;
|
|
121
|
+
}
|
|
122
|
+
exports.getMessageData = getMessageData;
|
|
123
|
+
function hexstr(arr, start, len) {
|
|
124
|
+
const isArr = Array.isArray(arr) || arr instanceof Uint8Array;
|
|
125
|
+
if (!arr)
|
|
126
|
+
return '';
|
|
127
|
+
var str = "";
|
|
128
|
+
if (start === undefined)
|
|
129
|
+
start = 0;
|
|
130
|
+
if (len === undefined || (start + len > arr.length)) {
|
|
131
|
+
len = arr.length - start;
|
|
132
|
+
}
|
|
133
|
+
if (len < 0)
|
|
134
|
+
return '';
|
|
135
|
+
var j = start;
|
|
136
|
+
for (var i = 0; i < len; i++) {
|
|
137
|
+
const c = isArr ? arr[j++] : ascii(arr.charAt(j++));
|
|
138
|
+
var hex = Math.abs(c).toString(16);
|
|
139
|
+
if (hex.length < 2)
|
|
140
|
+
hex = '0' + hex;
|
|
141
|
+
if (i !== 0)
|
|
142
|
+
str += " ";
|
|
143
|
+
str += hex;
|
|
144
|
+
}
|
|
145
|
+
return str;
|
|
146
|
+
}
|
|
147
|
+
exports.hexstr = hexstr;
|
|
148
|
+
function getHex(i) { return ('00' + i.toString(16)).slice(-2); }
|
|
149
|
+
exports.getHex = getHex;
|
|
150
|
+
function append(cmd, arr) { cmd.push(...arr); }
|
|
151
|
+
exports.append = append;
|
|
152
|
+
function ascii(c) {
|
|
153
|
+
if (c === undefined || c === null)
|
|
154
|
+
return;
|
|
155
|
+
return c.charCodeAt(0);
|
|
156
|
+
}
|
|
157
|
+
exports.ascii = ascii;
|
|
158
|
+
function charArrayToString(arr) {
|
|
159
|
+
if (arr === undefined || arr == null)
|
|
160
|
+
return undefined;
|
|
161
|
+
let str = '';
|
|
162
|
+
arr.forEach(c => str += c);
|
|
163
|
+
return str;
|
|
164
|
+
}
|
|
165
|
+
exports.charArrayToString = charArrayToString;
|
|
166
|
+
function asciiArrayToString(arr) {
|
|
167
|
+
if (arr === undefined || arr == null)
|
|
168
|
+
return undefined;
|
|
169
|
+
let str = '';
|
|
170
|
+
arr.forEach(c => str += String.fromCharCode(c));
|
|
171
|
+
return str;
|
|
172
|
+
}
|
|
173
|
+
exports.asciiArrayToString = asciiArrayToString;
|
|
174
|
+
function getAsciiArrayFromStr(str) {
|
|
175
|
+
if (str === undefined || str === null)
|
|
176
|
+
return undefined;
|
|
177
|
+
const n = str.length;
|
|
178
|
+
let result = [];
|
|
179
|
+
for (let i = 0; i < n; i++) {
|
|
180
|
+
result.push(str.charCodeAt(i));
|
|
181
|
+
}
|
|
182
|
+
return result;
|
|
183
|
+
}
|
|
184
|
+
exports.getAsciiArrayFromStr = getAsciiArrayFromStr;
|
|
185
|
+
function Float32ToHex(float32) {
|
|
186
|
+
var view = new DataView(new ArrayBuffer(4));
|
|
187
|
+
view.setFloat32(0, float32);
|
|
188
|
+
return Array.apply(null, { length: 4 }).map((_, i) => getHex(view.getUint8(i))).join('');
|
|
189
|
+
}
|
|
190
|
+
exports.Float32ToHex = Float32ToHex;
|
|
191
|
+
function Float32ToIntArray(float32) {
|
|
192
|
+
var view = new DataView(new ArrayBuffer(4));
|
|
193
|
+
view.setFloat32(0, float32);
|
|
194
|
+
var arr = [];
|
|
195
|
+
for (let i = 0; i < 4; i++) {
|
|
196
|
+
arr.push(view.getUint8(i));
|
|
197
|
+
}
|
|
198
|
+
return arr;
|
|
199
|
+
}
|
|
200
|
+
exports.Float32ToIntArray = Float32ToIntArray;
|
|
201
|
+
function Int16ToIntArray(int16) {
|
|
202
|
+
var view = new DataView(new ArrayBuffer(2));
|
|
203
|
+
view.setInt16(0, int16);
|
|
204
|
+
var arr = [];
|
|
205
|
+
for (let i = 0; i < 2; i++) {
|
|
206
|
+
arr.push(view.getUint8(i));
|
|
207
|
+
}
|
|
208
|
+
return arr;
|
|
209
|
+
}
|
|
210
|
+
exports.Int16ToIntArray = Int16ToIntArray;
|
|
211
|
+
function Int32ToIntArray(int32) {
|
|
212
|
+
var view = new DataView(new ArrayBuffer(4));
|
|
213
|
+
view.setInt32(0, int32);
|
|
214
|
+
var arr = [];
|
|
215
|
+
for (let i = 0; i < 4; i++) {
|
|
216
|
+
arr.push(view.getUint8(i));
|
|
217
|
+
}
|
|
218
|
+
return arr;
|
|
219
|
+
}
|
|
220
|
+
exports.Int32ToIntArray = Int32ToIntArray;
|
|
221
|
+
var ReservedCommands;
|
|
222
|
+
(function (ReservedCommands) {
|
|
223
|
+
ReservedCommands[ReservedCommands["RESULT_RESET"] = 0] = "RESULT_RESET";
|
|
224
|
+
ReservedCommands[ReservedCommands["RESULT_GET"] = 1] = "RESULT_GET";
|
|
225
|
+
ReservedCommands[ReservedCommands["NETRACE_START"] = 2] = "NETRACE_START";
|
|
226
|
+
ReservedCommands[ReservedCommands["NETRACE_STOP"] = 3] = "NETRACE_STOP";
|
|
227
|
+
ReservedCommands[ReservedCommands["NETRACE_USERNAME"] = 4] = "NETRACE_USERNAME";
|
|
228
|
+
ReservedCommands[ReservedCommands["NETRACE_USERDATA"] = 5] = "NETRACE_USERDATA";
|
|
229
|
+
ReservedCommands[ReservedCommands["PERSON_GET"] = 6] = "PERSON_GET";
|
|
230
|
+
ReservedCommands[ReservedCommands["PERSON_SET"] = 7] = "PERSON_SET";
|
|
231
|
+
ReservedCommands[ReservedCommands["PROGRAM_LIST_BEGIN"] = 8] = "PROGRAM_LIST_BEGIN";
|
|
232
|
+
ReservedCommands[ReservedCommands["PROGRAM_LIST_NEW_PROGRAM"] = 9] = "PROGRAM_LIST_NEW_PROGRAM";
|
|
233
|
+
ReservedCommands[ReservedCommands["PROGRAM_LIST_CONTINUE_PROGRAM"] = 10] = "PROGRAM_LIST_CONTINUE_PROGRAM";
|
|
234
|
+
ReservedCommands[ReservedCommands["PROGRAM_LIST_END"] = 11] = "PROGRAM_LIST_END";
|
|
235
|
+
ReservedCommands[ReservedCommands["PROGRAM_LIST_START"] = 12] = "PROGRAM_LIST_START";
|
|
236
|
+
ReservedCommands[ReservedCommands["RELAX_START"] = 12] = "RELAX_START";
|
|
237
|
+
ReservedCommands[ReservedCommands["RELAX_STOP"] = 14] = "RELAX_STOP";
|
|
238
|
+
ReservedCommands[ReservedCommands["RELAX_GET_DATA"] = 15] = "RELAX_GET_DATA";
|
|
239
|
+
ReservedCommands[ReservedCommands["KEY_PRESSED"] = 16] = "KEY_PRESSED";
|
|
240
|
+
ReservedCommands[ReservedCommands["PROGRAM_CONTROL"] = 17] = "PROGRAM_CONTROL";
|
|
241
|
+
})(ReservedCommands = exports.ReservedCommands || (exports.ReservedCommands = {}));
|
|
242
|
+
var BikeType;
|
|
243
|
+
(function (BikeType) {
|
|
244
|
+
BikeType[BikeType["ALLROUND"] = 0] = "ALLROUND";
|
|
245
|
+
BikeType[BikeType["RACE"] = 1] = "RACE";
|
|
246
|
+
BikeType[BikeType["MOUNTAIN"] = 2] = "MOUNTAIN";
|
|
247
|
+
})(BikeType = exports.BikeType || (exports.BikeType = {}));
|
|
248
|
+
function getBikeType(bikeTypeStr) {
|
|
249
|
+
if (bikeTypeStr === undefined || bikeTypeStr === null)
|
|
250
|
+
return BikeType.RACE;
|
|
251
|
+
if (bikeTypeStr.toLowerCase() === 'mountain')
|
|
252
|
+
return BikeType.MOUNTAIN;
|
|
253
|
+
return BikeType.RACE;
|
|
254
|
+
}
|
|
255
|
+
exports.getBikeType = getBikeType;
|
|
256
|
+
function routeToEpp(route, date) {
|
|
257
|
+
const buffer = Buffer.alloc(376 + route.points.length * 12);
|
|
258
|
+
const fileTime = win32filetime_1.default.fromUnix(date ? date : Date.now());
|
|
259
|
+
let offset = 0;
|
|
260
|
+
const name = route.name || '';
|
|
261
|
+
const description = route.description || '';
|
|
262
|
+
const minElevation = route.minElevation ? route.minElevation : 0;
|
|
263
|
+
const maxElevation = route.maxElevation ? route.minElevation : Math.max(...route.points.map(p => p.elevation));
|
|
264
|
+
const sampleRate = route.points.length !== 0 ? Math.round(route.totalDistance / route.points.length) : 0;
|
|
265
|
+
buffer.writeUInt32LE(fileTime.low, offset);
|
|
266
|
+
offset += 4;
|
|
267
|
+
buffer.writeUInt32LE(fileTime.high, offset);
|
|
268
|
+
offset += 4;
|
|
269
|
+
buffer.write(name, offset, name.length, 'ascii');
|
|
270
|
+
offset += 64;
|
|
271
|
+
buffer.write(description, offset, description.length, 'ascii');
|
|
272
|
+
offset += 256;
|
|
273
|
+
buffer.writeInt32LE(0x10, offset);
|
|
274
|
+
offset += 4;
|
|
275
|
+
buffer.writeInt32LE(0x0, offset);
|
|
276
|
+
offset += 4;
|
|
277
|
+
buffer.writeInt32LE(minElevation, offset);
|
|
278
|
+
offset += 4;
|
|
279
|
+
buffer.writeInt32LE(maxElevation, offset);
|
|
280
|
+
offset += 4;
|
|
281
|
+
buffer.writeInt32LE(route.points.length, offset);
|
|
282
|
+
offset += 4;
|
|
283
|
+
buffer.writeInt32LE(sampleRate, offset);
|
|
284
|
+
offset += 4;
|
|
285
|
+
buffer.writeInt32LE(0x01, offset);
|
|
286
|
+
offset += 4;
|
|
287
|
+
buffer.writeInt32LE(0x0, offset);
|
|
288
|
+
offset += 4;
|
|
289
|
+
buffer.writeInt16LE(0x0, offset);
|
|
290
|
+
offset += 2;
|
|
291
|
+
buffer.writeInt16LE(0x0, offset);
|
|
292
|
+
offset += 2;
|
|
293
|
+
buffer.writeInt32LE(0x0, offset);
|
|
294
|
+
offset += 4;
|
|
295
|
+
buffer.writeInt32LE(0x0, offset);
|
|
296
|
+
offset += 4;
|
|
297
|
+
buffer.writeInt32LE(0x0, offset);
|
|
298
|
+
offset += 4;
|
|
299
|
+
route.points.forEach(p => {
|
|
300
|
+
buffer.writeUInt32LE(sampleRate, offset);
|
|
301
|
+
offset += 4;
|
|
302
|
+
buffer.writeFloatLE(p.elevation, offset);
|
|
303
|
+
offset += 4;
|
|
304
|
+
buffer.writeFloatLE(0, offset);
|
|
305
|
+
offset += 4;
|
|
306
|
+
});
|
|
307
|
+
return new Uint8Array(buffer);
|
|
308
|
+
}
|
|
309
|
+
exports.routeToEpp = routeToEpp;
|
|
310
|
+
function parseTrainingData(payload) {
|
|
311
|
+
const GS = 0x1D;
|
|
312
|
+
const speedVals = ['ok', 'too low', 'too high'];
|
|
313
|
+
const gearVal = (v) => v > 0 ? v - 1 : undefined;
|
|
314
|
+
const vals = payload.split(String.fromCharCode(GS));
|
|
315
|
+
const data = {
|
|
316
|
+
time: parseInt(vals[0]),
|
|
317
|
+
heartrate: parseInt(vals[1]),
|
|
318
|
+
speed: parseFloat(vals[2]) * 3.6,
|
|
319
|
+
slope: parseFloat(vals[3]),
|
|
320
|
+
distanceInternal: parseInt(vals[4]),
|
|
321
|
+
cadence: parseFloat(vals[5]),
|
|
322
|
+
power: parseInt(vals[6]),
|
|
323
|
+
physEnergy: parseFloat(vals[7]),
|
|
324
|
+
realEnergy: parseFloat(vals[8]),
|
|
325
|
+
torque: parseFloat(vals[9]),
|
|
326
|
+
gear: gearVal(parseInt(vals[10])),
|
|
327
|
+
deviceState: parseInt(vals[11]),
|
|
328
|
+
speedStatus: speedVals[parseInt(vals[12])],
|
|
329
|
+
};
|
|
330
|
+
return data;
|
|
331
|
+
}
|
|
332
|
+
exports.parseTrainingData = parseTrainingData;
|
|
333
|
+
function getPersonData(user) {
|
|
334
|
+
const buffer = Buffer.alloc(136);
|
|
335
|
+
let offset = 0;
|
|
336
|
+
for (let i = 0; i < 4; i++) {
|
|
337
|
+
buffer.writeInt32LE(0, offset);
|
|
338
|
+
offset += 4;
|
|
339
|
+
buffer.writeFloatLE(-100, offset);
|
|
340
|
+
offset += 4;
|
|
341
|
+
buffer.writeFloatLE(0, offset);
|
|
342
|
+
offset += 4;
|
|
343
|
+
buffer.writeFloatLE(0, offset);
|
|
344
|
+
offset += 4;
|
|
345
|
+
buffer.writeUInt16LE(0, offset);
|
|
346
|
+
offset += 2;
|
|
347
|
+
buffer.writeUInt16LE(0, offset);
|
|
348
|
+
offset += 2;
|
|
349
|
+
buffer.writeUInt16LE(0, offset);
|
|
350
|
+
offset += 2;
|
|
351
|
+
buffer.writeUInt16LE(0, offset);
|
|
352
|
+
offset += 2;
|
|
353
|
+
buffer.writeUInt8(0, offset);
|
|
354
|
+
offset += 1;
|
|
355
|
+
buffer.writeUInt8(0, offset);
|
|
356
|
+
offset += 1;
|
|
357
|
+
buffer.writeUInt8(0, offset);
|
|
358
|
+
offset += 1;
|
|
359
|
+
buffer.writeUInt8(0, offset);
|
|
360
|
+
offset += 1;
|
|
361
|
+
}
|
|
362
|
+
buffer.writeInt32LE(1, offset);
|
|
363
|
+
offset += 4;
|
|
364
|
+
buffer.writeInt32LE(1, offset);
|
|
365
|
+
offset += 4;
|
|
366
|
+
buffer.writeInt32LE(175, offset);
|
|
367
|
+
offset += 4;
|
|
368
|
+
buffer.writeFloatLE(70, offset);
|
|
369
|
+
offset += 4;
|
|
370
|
+
buffer.writeFloatLE(0, offset);
|
|
371
|
+
offset += 4;
|
|
372
|
+
buffer.writeUInt32LE(1, offset);
|
|
373
|
+
offset += 4;
|
|
374
|
+
return buffer;
|
|
375
|
+
}
|
|
376
|
+
exports.getPersonData = getPersonData;
|