@garmin/fitsdk 21.168.0 → 21.169.0
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.txt +338 -338
- package/package.json +23 -23
- package/src/accumulator.js +58 -58
- package/src/bit-stream.js +85 -85
- package/src/crc-calculator.js +55 -55
- package/src/decoder.js +839 -839
- package/src/encoder.js +323 -323
- package/src/fit.js +170 -170
- package/src/index.js +20 -20
- package/src/mesg-definition.js +270 -270
- package/src/output-stream.js +220 -220
- package/src/profile.js +27999 -27999
- package/src/stream.js +258 -258
- package/src/utils-hr-mesg.js +174 -174
- package/src/utils-internal.js +53 -53
- package/src/utils-memo-glob.js +64 -64
- package/src/utils.js +66 -66
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@garmin/fitsdk",
|
|
3
|
-
"version": "21.
|
|
4
|
-
"description": "FIT JavaScript SDK",
|
|
5
|
-
"main": "src/index.js",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "node .",
|
|
9
|
-
"test": "vitest run"
|
|
10
|
-
},
|
|
11
|
-
"author": "Garmin International, Inc.",
|
|
12
|
-
"license": "SEE LICENSE IN LICENSE.txt",
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "https://github.com/garmin/fit-javascript-sdk"
|
|
16
|
-
},
|
|
17
|
-
"files": [
|
|
18
|
-
"src/"
|
|
19
|
-
],
|
|
20
|
-
"devDependencies": {
|
|
21
|
-
"vitest": "^2.1.8"
|
|
22
|
-
}
|
|
23
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@garmin/fitsdk",
|
|
3
|
+
"version": "21.169.0",
|
|
4
|
+
"description": "FIT JavaScript SDK",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "node .",
|
|
9
|
+
"test": "vitest run"
|
|
10
|
+
},
|
|
11
|
+
"author": "Garmin International, Inc.",
|
|
12
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/garmin/fit-javascript-sdk"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"src/"
|
|
19
|
+
],
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"vitest": "^2.1.8"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/accumulator.js
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// Copyright 2025 Garmin International, Inc.
|
|
3
|
-
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
|
|
4
|
-
// may not use this file except in compliance with the Flexible and Interoperable Data
|
|
5
|
-
// Transfer (FIT) Protocol License.
|
|
6
|
-
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
|
-
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
|
|
8
|
-
// Profile Version = 21.
|
|
9
|
-
// Tag = production/release/21.
|
|
10
|
-
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class AccumulatedField {
|
|
14
|
-
#accumulatedValue = 0;
|
|
15
|
-
#lastValue = 0;
|
|
16
|
-
|
|
17
|
-
constructor(value) {
|
|
18
|
-
this.#accumulatedValue = value;
|
|
19
|
-
this.#lastValue = value;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
accumulate(value, bits) {
|
|
23
|
-
const mask = (1 << bits) - 1;
|
|
24
|
-
|
|
25
|
-
this.#accumulatedValue += (value - this.#lastValue) & mask;
|
|
26
|
-
this.#lastValue = value;
|
|
27
|
-
|
|
28
|
-
return this.#accumulatedValue;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
class Accumulator {
|
|
33
|
-
#messages = {};
|
|
34
|
-
|
|
35
|
-
createAccumulatedField(mesgNum, fieldNum, value) {
|
|
36
|
-
const accumualtedField = new AccumulatedField(value);
|
|
37
|
-
|
|
38
|
-
if (this.#messages[mesgNum] == null) {
|
|
39
|
-
this.#messages[mesgNum] = {};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
this.#messages[mesgNum][fieldNum] = accumualtedField;
|
|
43
|
-
|
|
44
|
-
return accumualtedField;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
accumulate(mesgNum, fieldNum, value, bits) {
|
|
48
|
-
let accumualtedField = this.#messages[mesgNum]?.[fieldNum];
|
|
49
|
-
|
|
50
|
-
if(accumualtedField == null) {
|
|
51
|
-
accumualtedField = this.createAccumulatedField(mesgNum, fieldNum, value);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return accumualtedField.accumulate(value, bits);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export default Accumulator;
|
|
1
|
+
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright 2025 Garmin International, Inc.
|
|
3
|
+
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
|
|
4
|
+
// may not use this file except in compliance with the Flexible and Interoperable Data
|
|
5
|
+
// Transfer (FIT) Protocol License.
|
|
6
|
+
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
|
+
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
|
|
8
|
+
// Profile Version = 21.169.0Release
|
|
9
|
+
// Tag = production/release/21.169.0-0-g7105132
|
|
10
|
+
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AccumulatedField {
|
|
14
|
+
#accumulatedValue = 0;
|
|
15
|
+
#lastValue = 0;
|
|
16
|
+
|
|
17
|
+
constructor(value) {
|
|
18
|
+
this.#accumulatedValue = value;
|
|
19
|
+
this.#lastValue = value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
accumulate(value, bits) {
|
|
23
|
+
const mask = (1 << bits) - 1;
|
|
24
|
+
|
|
25
|
+
this.#accumulatedValue += (value - this.#lastValue) & mask;
|
|
26
|
+
this.#lastValue = value;
|
|
27
|
+
|
|
28
|
+
return this.#accumulatedValue;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
class Accumulator {
|
|
33
|
+
#messages = {};
|
|
34
|
+
|
|
35
|
+
createAccumulatedField(mesgNum, fieldNum, value) {
|
|
36
|
+
const accumualtedField = new AccumulatedField(value);
|
|
37
|
+
|
|
38
|
+
if (this.#messages[mesgNum] == null) {
|
|
39
|
+
this.#messages[mesgNum] = {};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
this.#messages[mesgNum][fieldNum] = accumualtedField;
|
|
43
|
+
|
|
44
|
+
return accumualtedField;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
accumulate(mesgNum, fieldNum, value, bits) {
|
|
48
|
+
let accumualtedField = this.#messages[mesgNum]?.[fieldNum];
|
|
49
|
+
|
|
50
|
+
if(accumualtedField == null) {
|
|
51
|
+
accumualtedField = this.createAccumulatedField(mesgNum, fieldNum, value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return accumualtedField.accumulate(value, bits);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default Accumulator;
|
package/src/bit-stream.js
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// Copyright 2025 Garmin International, Inc.
|
|
3
|
-
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
|
|
4
|
-
// may not use this file except in compliance with the Flexible and Interoperable Data
|
|
5
|
-
// Transfer (FIT) Protocol License.
|
|
6
|
-
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
|
-
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
|
|
8
|
-
// Profile Version = 21.
|
|
9
|
-
// Tag = production/release/21.
|
|
10
|
-
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import FIT from "./fit.js";
|
|
14
|
-
|
|
15
|
-
class BitStream {
|
|
16
|
-
#array = null;
|
|
17
|
-
#currentArrayPosition = 0;
|
|
18
|
-
#bitPerPosition = 0;
|
|
19
|
-
#currentByte = 0;
|
|
20
|
-
#currentBit = 0;
|
|
21
|
-
#bitsAvailable = 0;
|
|
22
|
-
|
|
23
|
-
constructor(data, baseType = FIT.BaseType.UINT8) {
|
|
24
|
-
this.#array = Array.isArray(data) ? data : [data];
|
|
25
|
-
const baseTypeSize = FIT.BaseTypeDefinitions[baseType].size;
|
|
26
|
-
this.#bitPerPosition = baseTypeSize * 8;
|
|
27
|
-
this.reset();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get bitsAvailable() {
|
|
31
|
-
return this.#bitsAvailable;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get hasBitsAvailable() {
|
|
35
|
-
return this.#bitsAvailable > 0;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
reset() {
|
|
39
|
-
this.#currentArrayPosition = 0;
|
|
40
|
-
this.#bitsAvailable = this.#bitPerPosition * this.#array.length;
|
|
41
|
-
this.#nextByte();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
readBit() {
|
|
45
|
-
if (!this.hasBitsAvailable) {
|
|
46
|
-
this.#throwError();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (this.#currentBit >= this.#bitPerPosition) {
|
|
50
|
-
this.#nextByte();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const bit = this.#currentByte & 0x01;
|
|
54
|
-
this.#currentByte = this.#currentByte >> 1;
|
|
55
|
-
this.#currentBit++;
|
|
56
|
-
this.#bitsAvailable--;
|
|
57
|
-
|
|
58
|
-
return bit;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
readBits(nBitsToRead) {
|
|
62
|
-
let value = 0n;
|
|
63
|
-
|
|
64
|
-
for (let i = 0n; i < nBitsToRead; i++) {
|
|
65
|
-
value |= BigInt(this.readBit()) << i;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return Number(value);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
#nextByte() {
|
|
72
|
-
if (this.#currentArrayPosition >= this.#array.length) {
|
|
73
|
-
this.#throwError();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
this.#currentByte = this.#array[this.#currentArrayPosition++];
|
|
77
|
-
this.#currentBit = 0;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
#throwError(error = "") {
|
|
81
|
-
throw Error("FIT Runtime Error no bits available.");
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export default BitStream;
|
|
1
|
+
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright 2025 Garmin International, Inc.
|
|
3
|
+
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
|
|
4
|
+
// may not use this file except in compliance with the Flexible and Interoperable Data
|
|
5
|
+
// Transfer (FIT) Protocol License.
|
|
6
|
+
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
|
+
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
|
|
8
|
+
// Profile Version = 21.169.0Release
|
|
9
|
+
// Tag = production/release/21.169.0-0-g7105132
|
|
10
|
+
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
import FIT from "./fit.js";
|
|
14
|
+
|
|
15
|
+
class BitStream {
|
|
16
|
+
#array = null;
|
|
17
|
+
#currentArrayPosition = 0;
|
|
18
|
+
#bitPerPosition = 0;
|
|
19
|
+
#currentByte = 0;
|
|
20
|
+
#currentBit = 0;
|
|
21
|
+
#bitsAvailable = 0;
|
|
22
|
+
|
|
23
|
+
constructor(data, baseType = FIT.BaseType.UINT8) {
|
|
24
|
+
this.#array = Array.isArray(data) ? data : [data];
|
|
25
|
+
const baseTypeSize = FIT.BaseTypeDefinitions[baseType].size;
|
|
26
|
+
this.#bitPerPosition = baseTypeSize * 8;
|
|
27
|
+
this.reset();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get bitsAvailable() {
|
|
31
|
+
return this.#bitsAvailable;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get hasBitsAvailable() {
|
|
35
|
+
return this.#bitsAvailable > 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
reset() {
|
|
39
|
+
this.#currentArrayPosition = 0;
|
|
40
|
+
this.#bitsAvailable = this.#bitPerPosition * this.#array.length;
|
|
41
|
+
this.#nextByte();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
readBit() {
|
|
45
|
+
if (!this.hasBitsAvailable) {
|
|
46
|
+
this.#throwError();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (this.#currentBit >= this.#bitPerPosition) {
|
|
50
|
+
this.#nextByte();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const bit = this.#currentByte & 0x01;
|
|
54
|
+
this.#currentByte = this.#currentByte >> 1;
|
|
55
|
+
this.#currentBit++;
|
|
56
|
+
this.#bitsAvailable--;
|
|
57
|
+
|
|
58
|
+
return bit;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
readBits(nBitsToRead) {
|
|
62
|
+
let value = 0n;
|
|
63
|
+
|
|
64
|
+
for (let i = 0n; i < nBitsToRead; i++) {
|
|
65
|
+
value |= BigInt(this.readBit()) << i;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return Number(value);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#nextByte() {
|
|
72
|
+
if (this.#currentArrayPosition >= this.#array.length) {
|
|
73
|
+
this.#throwError();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this.#currentByte = this.#array[this.#currentArrayPosition++];
|
|
77
|
+
this.#currentBit = 0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
#throwError(error = "") {
|
|
81
|
+
throw Error("FIT Runtime Error no bits available.");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export default BitStream;
|
package/src/crc-calculator.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// Copyright 2025 Garmin International, Inc.
|
|
3
|
-
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
|
|
4
|
-
// may not use this file except in compliance with the Flexible and Interoperable Data
|
|
5
|
-
// Transfer (FIT) Protocol License.
|
|
6
|
-
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
|
-
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
|
|
8
|
-
// Profile Version = 21.
|
|
9
|
-
// Tag = production/release/21.
|
|
10
|
-
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const crcTable = [
|
|
14
|
-
0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401,
|
|
15
|
-
0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400
|
|
16
|
-
]
|
|
17
|
-
|
|
18
|
-
class CrcCalculator {
|
|
19
|
-
#crc = 0;
|
|
20
|
-
|
|
21
|
-
constructor() {
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
get crc() {
|
|
25
|
-
return this.#crc;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
#updateCRC(value) {
|
|
29
|
-
// compute checksum of lower four bits of byte
|
|
30
|
-
let tmp = crcTable[this.#crc & 0xF];
|
|
31
|
-
this.#crc = (this.#crc >> 4) & 0x0FFF;
|
|
32
|
-
this.#crc = this.#crc ^ tmp ^ crcTable[value & 0xF];
|
|
33
|
-
|
|
34
|
-
// compute checksum of upper four bits of byte
|
|
35
|
-
tmp = crcTable[this.#crc & 0xF];
|
|
36
|
-
this.#crc = (this.#crc >> 4) & 0x0FFF;
|
|
37
|
-
this.#crc = this.#crc ^ tmp ^ crcTable[(value >> 4) & 0xF];
|
|
38
|
-
|
|
39
|
-
return this.#crc;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
addBytes(buf, start, end) {
|
|
43
|
-
for (let i = start; i < end; i++) {
|
|
44
|
-
this.#crc = this.#updateCRC(buf[i]);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return this.#crc;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
static calculateCRC(buf, start, end) {
|
|
51
|
-
const crcCalculator = new CrcCalculator();
|
|
52
|
-
return crcCalculator.addBytes(buf, start, end);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
1
|
+
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright 2025 Garmin International, Inc.
|
|
3
|
+
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
|
|
4
|
+
// may not use this file except in compliance with the Flexible and Interoperable Data
|
|
5
|
+
// Transfer (FIT) Protocol License.
|
|
6
|
+
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
|
+
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
|
|
8
|
+
// Profile Version = 21.169.0Release
|
|
9
|
+
// Tag = production/release/21.169.0-0-g7105132
|
|
10
|
+
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const crcTable = [
|
|
14
|
+
0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401,
|
|
15
|
+
0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
class CrcCalculator {
|
|
19
|
+
#crc = 0;
|
|
20
|
+
|
|
21
|
+
constructor() {
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get crc() {
|
|
25
|
+
return this.#crc;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
#updateCRC(value) {
|
|
29
|
+
// compute checksum of lower four bits of byte
|
|
30
|
+
let tmp = crcTable[this.#crc & 0xF];
|
|
31
|
+
this.#crc = (this.#crc >> 4) & 0x0FFF;
|
|
32
|
+
this.#crc = this.#crc ^ tmp ^ crcTable[value & 0xF];
|
|
33
|
+
|
|
34
|
+
// compute checksum of upper four bits of byte
|
|
35
|
+
tmp = crcTable[this.#crc & 0xF];
|
|
36
|
+
this.#crc = (this.#crc >> 4) & 0x0FFF;
|
|
37
|
+
this.#crc = this.#crc ^ tmp ^ crcTable[(value >> 4) & 0xF];
|
|
38
|
+
|
|
39
|
+
return this.#crc;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
addBytes(buf, start, end) {
|
|
43
|
+
for (let i = start; i < end; i++) {
|
|
44
|
+
this.#crc = this.#updateCRC(buf[i]);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return this.#crc;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static calculateCRC(buf, start, end) {
|
|
51
|
+
const crcCalculator = new CrcCalculator();
|
|
52
|
+
return crcCalculator.addBytes(buf, start, end);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
56
|
export default CrcCalculator;
|