Skip to content

Commit 4921b4c

Browse files
pryhodaJenkins
andauthored
Garmin FIT SDK 21.94.00 (#1)
Change-Id: Ia86a53bdd303c198cdbaed94fcd9534fc4b5369e Co-authored-by: Jenkins <avn.hudson@garmin.com>
1 parent 574a13c commit 4921b4c

25 files changed

+40988
-0
lines changed

LICENSE.txt

Lines changed: 339 additions & 0 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "@garmin-fit/sdk",
3+
"version": "0.94.0",
4+
"description": "FIT Node SDK",
5+
"main": "src/index.js",
6+
"type": "module",
7+
"scripts": {
8+
"build": "node .",
9+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
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+
"jest": "^28.1.2",
22+
"jsdoc": "^3.6.11"
23+
},
24+
"jest": {
25+
"transform": {}
26+
}
27+
}

src/accumulator.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/////////////////////////////////////////////////////////////////////////////////////////////
2+
// Copyright 2022 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.94Release
9+
// Tag = production/akw/21.94.00-0-g0f668193
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+
add(mesgNum, fieldNum, value) {
36+
if (this.#messages[mesgNum] == null) {
37+
this.#messages[mesgNum] = {};
38+
}
39+
40+
this.#messages[mesgNum][fieldNum] = new AccumulatedField(value);
41+
}
42+
43+
accumulate(mesgNum, fieldNum, value, bits) {
44+
return this.#messages[mesgNum]?.[fieldNum]?.accumulate(value, bits) ?? value;
45+
}
46+
}
47+
48+
export default Accumulator;

src/bit-stream.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/////////////////////////////////////////////////////////////////////////////////////////////
2+
// Copyright 2022 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.94Release
9+
// Tag = production/akw/21.94.00-0-g0f668193
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;

src/crc-calculator.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/////////////////////////////////////////////////////////////////////////////////////////////
2+
// Copyright 2022 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.94Release
9+
// Tag = production/akw/21.94.00-0-g0f668193
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;

0 commit comments

Comments
 (0)