@garmin/fitsdk 21.115.1
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 +339 -0
- package/README.md +217 -0
- package/package.json +27 -0
- package/src/accumulator.js +48 -0
- package/src/bit-stream.js +85 -0
- package/src/crc-calculator.js +56 -0
- package/src/decoder.js +738 -0
- package/src/fit.js +95 -0
- package/src/index.js +18 -0
- package/src/profile.js +24102 -0
- package/src/stream.js +259 -0
- package/src/utils-hr-mesg.js +175 -0
- package/src/utils-internal.js +35 -0
- package/src/utils.js +31 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright 2023 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.115Release
|
|
9
|
+
// Tag = production/release/21.115.00-0-gfe0a7f8
|
|
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;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright 2023 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.115Release
|
|
9
|
+
// Tag = production/release/21.115.00-0-gfe0a7f8
|
|
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
|
+
export default CrcCalculator;
|