Skip to content

Commit a18bf1e

Browse files
authored
Merge pull request #27 from garmin/production/akw/21.188.0_70
Garmin FIT SDK 21.188.0
2 parents 623c777 + 4ee1499 commit a18bf1e

19 files changed

+231
-76
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@garmin/fitsdk",
3-
"version": "21.178.0",
3+
"version": "21.188.0",
44
"description": "FIT JavaScript SDK",
55
"main": "src/index.js",
66
"type": "module",

src/accumulator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// Transfer (FIT) Protocol License.
66
/////////////////////////////////////////////////////////////////////////////////////////////
77
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
8-
// Profile Version = 21.178.0Release
9-
// Tag = production/release/21.178.0-0-g3bea629
8+
// Profile Version = 21.188.0Release
9+
// Tag = production/release/21.188.0-0-g55050f8
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

src/bit-stream.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// Transfer (FIT) Protocol License.
66
/////////////////////////////////////////////////////////////////////////////////////////////
77
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
8-
// Profile Version = 21.178.0Release
9-
// Tag = production/release/21.178.0-0-g3bea629
8+
// Profile Version = 21.188.0Release
9+
// Tag = production/release/21.188.0-0-g55050f8
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

src/crc-calculator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// Transfer (FIT) Protocol License.
66
/////////////////////////////////////////////////////////////////////////////////////////////
77
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
8-
// Profile Version = 21.178.0Release
9-
// Tag = production/release/21.178.0-0-g3bea629
8+
// Profile Version = 21.188.0Release
9+
// Tag = production/release/21.188.0-0-g55050f8
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

src/decoder.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// Transfer (FIT) Protocol License.
66
/////////////////////////////////////////////////////////////////////////////////////////////
77
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
8-
// Profile Version = 21.178.0Release
9-
// Tag = production/release/21.178.0-0-g3bea629
8+
// Profile Version = 21.188.0Release
9+
// Tag = production/release/21.188.0-0-g55050f8
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

@@ -30,6 +30,7 @@ const LOCAL_MESG_NUM_MASK = 0x0F;
3030
const HEADER_WITH_CRC_SIZE = 14;
3131
const HEADER_WITHOUT_CRC_SIZE = 12;
3232
const CRC_SIZE = 2;
33+
const PROFILE_VERSION_SCALE_CHANGE_VALUE = 2199;
3334

3435
const DecodeMode = Object.freeze({
3536
NORMAL: "normal",
@@ -43,6 +44,7 @@ class Decoder {
4344
#stream = null;
4445
#accumulator = new Accumulator();
4546
#messages = {};
47+
#profileVersion = null;
4648
#fieldsWithSubFields = [];
4749
#fieldsToExpand = [];
4850

@@ -200,7 +202,7 @@ class Decoder {
200202
mergeHeartRates = true,
201203
decodeMemoGlobs = false,
202204
skipHeader = false,
203-
dataOnly = false,} = {}) {
205+
dataOnly = false, } = {}) {
204206

205207
this.#mesgListener = mesgListener;
206208
this.#mesgDefinitionListener = mesgDefinitionListener;
@@ -217,6 +219,7 @@ class Decoder {
217219
this.#localMessageDefinitions = [];
218220
this.#developerDataDefinitions = {};
219221
this.#messages = {};
222+
this.#profileVersion = null;
220223

221224
const errors = [];
222225

@@ -247,7 +250,7 @@ class Decoder {
247250
errors.push(error);
248251
}
249252
finally {
250-
return { messages: this.#messages, errors: errors };
253+
return { messages: this.#messages, profileVersion: this.#profileVersion, errors: errors };
251254
}
252255
}
253256

@@ -260,7 +263,8 @@ class Decoder {
260263

261264
this.#stream.crcCalculator = new CrcCalculator();
262265

263-
const { headerSize, dataSize } = Decoder.#readFileHeader(this.#stream, { decodeMode: this.#decodeMode });
266+
const { headerSize, dataSize, profileVersion, } = Decoder.#readFileHeader(this.#stream, { decodeMode: this.#decodeMode });
267+
this.#profileVersion ??= profileVersion;
264268

265269
// Read data messages and definitions
266270
while (this.#stream.position < (position + headerSize + dataSize)) {
@@ -313,7 +317,7 @@ class Decoder {
313317
const fieldDefinition = {
314318
fieldDefinitionNumber: this.#stream.readByte(),
315319
size: this.#stream.readByte(),
316-
baseType: this.#stream.readByte()
320+
baseType: this.#stream.readByte() & FIT.BaseTypeMask,
317321
};
318322

319323
if (!(fieldDefinition.baseType in FIT.BaseTypeDefinitions)) {
@@ -515,7 +519,7 @@ class Decoder {
515519
this.#developerDataDefinitions[message.developerDataIndex.rawFieldValue].fields.push({
516520
developerDataIndex: message.developerDataIndex?.rawFieldValue,
517521
fieldDefinitionNumber: message.fieldDefinitionNumber?.rawFieldValue,
518-
fitBaseTypeId: message.fitBaseTypeId?.rawFieldValue ?? null,
522+
fitBaseTypeId: message.fitBaseTypeId?.rawFieldValue & FIT.BaseTypeMask ?? null,
519523
fieldName: message.fieldName?.rawFieldValue ?? null,
520524
array: message.array?.rawFieldValue ?? null,
521525
components: message.components?.rawFieldValue ?? null,
@@ -799,26 +803,27 @@ class Decoder {
799803
static #readFileHeader(stream, { resetPosition = false, decodeMode = DecodeMode.NORMAL }) {
800804
const position = stream.position;
801805

802-
if(decodeMode !== DecodeMode.NORMAL) {
803-
if(decodeMode === DecodeMode.SKIP_HEADER) {
806+
if (decodeMode !== DecodeMode.NORMAL) {
807+
if (decodeMode === DecodeMode.SKIP_HEADER) {
804808
stream.seek(HEADER_WITH_CRC_SIZE);
805809
}
806810

807811
const headerSize = decodeMode === DecodeMode.SKIP_HEADER ? HEADER_WITH_CRC_SIZE : 0;
812+
const dataSize = stream.length - headerSize - CRC_SIZE;
808813

809814
return {
810815
headerSize,
811-
dataSize: stream.length - headerSize - CRC_SIZE,
816+
dataSize,
812817
};
813818
}
814819

815820
const fileHeader = {
816821
headerSize: stream.readByte(),
817822
protocolVersion: stream.readByte(),
818-
profileVersion: stream.readUInt16(),
823+
profileVersion: this.#expandProfileVersion(stream.readUInt16()),
819824
dataSize: stream.readUInt32(),
820825
dataType: stream.readString(4),
821-
headerCRC: 0
826+
headerCRC: null
822827
};
823828

824829
if (fileHeader.headerSize === 14) {
@@ -835,6 +840,14 @@ class Decoder {
835840
#throwError(error = "") {
836841
throw Error(`FIT Runtime Error at byte ${this.#stream.position} ${error}`.trimEnd());
837842
}
843+
844+
static #expandProfileVersion = (profileVersion) => {
845+
const scale = profileVersion > PROFILE_VERSION_SCALE_CHANGE_VALUE ? 1000 : 100
846+
return {
847+
major: Math.floor(profileVersion / scale),
848+
minor: profileVersion % scale
849+
}
850+
}
838851
}
839852

840853
export default Decoder;

src/encoder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// Transfer (FIT) Protocol License.
66
/////////////////////////////////////////////////////////////////////////////////////////////
77
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
8-
// Profile Version = 21.178.0Release
9-
// Tag = production/release/21.178.0-0-g3bea629
8+
// Profile Version = 21.188.0Release
9+
// Tag = production/release/21.188.0-0-g55050f8
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

src/fit.js

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// Transfer (FIT) Protocol License.
66
/////////////////////////////////////////////////////////////////////////////////////////////
77
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
8-
// Profile Version = 21.178.0Release
9-
// Tag = production/release/21.178.0-0-g3bea629
8+
// Profile Version = 21.188.0Release
9+
// Tag = production/release/21.188.0-0-g55050f8
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

@@ -17,40 +17,42 @@ const BaseType = {
1717
ENUM: 0x00,
1818
SINT8: 0x01,
1919
UINT8: 0x02,
20-
SINT16: 0x83,
21-
UINT16: 0x84,
22-
SINT32: 0x85,
23-
UINT32: 0x86,
20+
SINT16: 0x03,
21+
UINT16: 0x04,
22+
SINT32: 0x05,
23+
UINT32: 0x06,
2424
STRING: 0x07,
25-
FLOAT32: 0x88,
26-
FLOAT64: 0x89,
25+
FLOAT32: 0x08,
26+
FLOAT64: 0x09,
2727
UINT8Z: 0x0A,
28-
UINT16Z: 0x8B,
29-
UINT32Z: 0x8C,
28+
UINT16Z: 0x0B,
29+
UINT32Z: 0x0C,
3030
BYTE: 0x0D,
31-
SINT64: 0x8E,
32-
UINT64: 0x8F,
33-
UINT64Z: 0x90
31+
SINT64: 0x0E,
32+
UINT64: 0x0F,
33+
UINT64Z: 0x10
3434
};
3535

36+
const BaseTypeMask = 0x1F;
37+
3638
const BaseTypeDefinitions = {
37-
0x00: { size: 1, type: BaseType.ENUM, invalid: 0xFF },
38-
0x01: { size: 1, type: BaseType.SINT8, invalid: 0x7F },
39-
0x02: { size: 1, type: BaseType.UINT8, invalid: 0xFF },
40-
0x83: { size: 2, type: BaseType.SINT16, invalid: 0x7FFF },
41-
0x84: { size: 2, type: BaseType.UINT16, invalid: 0xFFFF },
42-
0x85: { size: 4, type: BaseType.SINT32, invalid: 0x7FFFFFFF },
43-
0x86: { size: 4, type: BaseType.UINT32, invalid: 0xFFFFFFFF },
44-
0x07: { size: 1, type: BaseType.STRING, invalid: 0x00 },
45-
0x88: { size: 4, type: BaseType.FLOAT32, invalid: 0xFFFFFFFF },
46-
0x89: { size: 8, type: BaseType.FLOAT64, invalid: 0xFFFFFFFFFFFFFFFF },
47-
0x0A: { size: 1, type: BaseType.UINT8Z, invalid: 0x00 },
48-
0x8B: { size: 2, type: BaseType.UINT16Z, invalid: 0x0000 },
49-
0x8C: { size: 4, type: BaseType.UINT32Z, invalid: 0x00000000 },
50-
0x0D: { size: 1, type: BaseType.BYTE, invalid: 0xFF },
51-
0x8E: { size: 8, type: BaseType.SINT64, invalid: 0x7FFFFFFFFFFFFFFF },
52-
0x8F: { size: 8, type: BaseType.UINT64, invalid: 0xFFFFFFFFFFFFFFFF },
53-
0x90: { size: 8, type: BaseType.UINT64Z, invalid: 0x0000000000000000 },
39+
0x00: { size: 1, type: BaseType.ENUM, baseTypeEndianFlag: 0x00, invalid: 0xFF },
40+
0x01: { size: 1, type: BaseType.SINT8, baseTypeEndianFlag: 0x00, invalid: 0x7F },
41+
0x02: { size: 1, type: BaseType.UINT8, baseTypeEndianFlag: 0x00, invalid: 0xFF },
42+
0x03: { size: 2, type: BaseType.SINT16, baseTypeEndianFlag: 0x80, invalid: 0x7FFF },
43+
0x04: { size: 2, type: BaseType.UINT16, baseTypeEndianFlag: 0x80, invalid: 0xFFFF },
44+
0x05: { size: 4, type: BaseType.SINT32, baseTypeEndianFlag: 0x80, invalid: 0x7FFFFFFF },
45+
0x06: { size: 4, type: BaseType.UINT32, baseTypeEndianFlag: 0x80, invalid: 0xFFFFFFFF },
46+
0x07: { size: 1, type: BaseType.STRING, baseTypeEndianFlag: 0x00, invalid: 0x00 },
47+
0x08: { size: 4, type: BaseType.FLOAT32, baseTypeEndianFlag: 0x80, invalid: 0xFFFFFFFF },
48+
0x09: { size: 8, type: BaseType.FLOAT64, baseTypeEndianFlag: 0x80, invalid: 0xFFFFFFFFFFFFFFFF },
49+
0x0A: { size: 1, type: BaseType.UINT8Z, baseTypeEndianFlag: 0x00, invalid: 0x00 },
50+
0x0B: { size: 2, type: BaseType.UINT16Z, baseTypeEndianFlag: 0x80, invalid: 0x0000 },
51+
0x0C: { size: 4, type: BaseType.UINT32Z, baseTypeEndianFlag: 0x80, invalid: 0x00000000 },
52+
0x0D: { size: 1, type: BaseType.BYTE, baseTypeEndianFlag: 0x00, invalid: 0xFF },
53+
0x0E: { size: 8, type: BaseType.SINT64, baseTypeEndianFlag: 0x80, invalid: 0x7FFFFFFFFFFFFFFF },
54+
0x0F: { size: 8, type: BaseType.UINT64, baseTypeEndianFlag: 0x80, invalid: 0xFFFFFFFFFFFFFFFF },
55+
0x10: { size: 8, type: BaseType.UINT64Z, baseTypeEndianFlag: 0x80, invalid: 0x0000000000000000 },
5456
};
5557

5658
const NumericFieldTypes = [
@@ -158,6 +160,7 @@ const isNumberStringDateOrBoolean = (obj) => {
158160

159161
export default {
160162
BaseType,
163+
BaseTypeMask,
161164
BaseTypeDefinitions,
162165
NumericFieldTypes,
163166
FloatingPointFieldTypes,

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// Transfer (FIT) Protocol License.
66
/////////////////////////////////////////////////////////////////////////////////////////////
77
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
8-
// Profile Version = 21.178.0Release
9-
// Tag = production/release/21.178.0-0-g3bea629
8+
// Profile Version = 21.188.0Release
9+
// Tag = production/release/21.188.0-0-g55050f8
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

src/mesg-definition.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// Transfer (FIT) Protocol License.
66
/////////////////////////////////////////////////////////////////////////////////////////////
77
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
8-
// Profile Version = 21.178.0Release
9-
// Tag = production/release/21.178.0-0-g3bea629
8+
// Profile Version = 21.188.0Release
9+
// Tag = production/release/21.188.0-0-g55050f8
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

@@ -67,6 +67,7 @@ class MesgDefinition {
6767
num: fieldProfile[1].num,
6868
size: this.#fieldSize(mesg[fieldName], baseTypeDef),
6969
baseType: baseType,
70+
baseTypeEndianFlag: baseTypeDef.baseTypeEndianFlag,
7071
type: fieldProfile[1].type,
7172
scale,
7273
offset,
@@ -77,11 +78,11 @@ class MesgDefinition {
7778
Object.keys(mesg.developerFields ?? {})?.sort()?.forEach((key) => {
7879
const { developerDataIdMesg, fieldDescriptionMesg, } = this.#fieldDescriptionForKey(fieldDescriptions, key);
7980

80-
const baseTypeDef = FIT.BaseTypeDefinitions[fieldDescriptionMesg.fitBaseTypeId];
81+
const baseTypeDef = FIT.BaseTypeDefinitions[fieldDescriptionMesg.fitBaseTypeId & FIT.BaseTypeMask];
8182

8283
this.developerFieldDefinitions.push({
8384
key,
84-
baseType: fieldDescriptionMesg.fitBaseTypeId,
85+
baseType: fieldDescriptionMesg.fitBaseTypeId & FIT.BaseTypeMask,
8586
fieldDefinitionNumber: fieldDescriptionMesg.fieldDefinitionNumber,
8687
size: this.#fieldSize(mesg.developerFields[key], baseTypeDef),
8788
developerDataIndex: developerDataIdMesg.developerDataIndex,
@@ -137,7 +138,7 @@ class MesgDefinition {
137138
this.fieldDefinitions.forEach((fieldDefinition) => {
138139
outputStream.writeUInt8(fieldDefinition.num);
139140
outputStream.writeUInt8(fieldDefinition.size);
140-
outputStream.writeUInt8(fieldDefinition.baseType);
141+
outputStream.writeUInt8(fieldDefinition.baseType | fieldDefinition.baseTypeEndianFlag);
141142
});
142143

143144
// Developer Field Definitions

src/output-stream.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// Transfer (FIT) Protocol License.
66
/////////////////////////////////////////////////////////////////////////////////////////////
77
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
8-
// Profile Version = 21.178.0Release
9-
// Tag = production/release/21.178.0-0-g3bea629
8+
// Profile Version = 21.188.0Release
9+
// Tag = production/release/21.188.0-0-g55050f8
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

0 commit comments

Comments
 (0)