Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@garmin/fitsdk",
"version": "21.178.0",
"version": "21.188.0",
"description": "FIT JavaScript SDK",
"main": "src/index.js",
"type": "module",
Expand Down
4 changes: 2 additions & 2 deletions src/accumulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
// Profile Version = 21.188.0Release
// Tag = production/release/21.188.0-0-g55050f8
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
4 changes: 2 additions & 2 deletions src/bit-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
// Profile Version = 21.188.0Release
// Tag = production/release/21.188.0-0-g55050f8
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
4 changes: 2 additions & 2 deletions src/crc-calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
// Profile Version = 21.188.0Release
// Tag = production/release/21.188.0-0-g55050f8
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
37 changes: 25 additions & 12 deletions src/decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
// Profile Version = 21.188.0Release
// Tag = production/release/21.188.0-0-g55050f8
/////////////////////////////////////////////////////////////////////////////////////////////


Expand All @@ -30,6 +30,7 @@ const LOCAL_MESG_NUM_MASK = 0x0F;
const HEADER_WITH_CRC_SIZE = 14;
const HEADER_WITHOUT_CRC_SIZE = 12;
const CRC_SIZE = 2;
const PROFILE_VERSION_SCALE_CHANGE_VALUE = 2199;

const DecodeMode = Object.freeze({
NORMAL: "normal",
Expand All @@ -43,6 +44,7 @@ class Decoder {
#stream = null;
#accumulator = new Accumulator();
#messages = {};
#profileVersion = null;
#fieldsWithSubFields = [];
#fieldsToExpand = [];

Expand Down Expand Up @@ -200,7 +202,7 @@ class Decoder {
mergeHeartRates = true,
decodeMemoGlobs = false,
skipHeader = false,
dataOnly = false,} = {}) {
dataOnly = false, } = {}) {

this.#mesgListener = mesgListener;
this.#mesgDefinitionListener = mesgDefinitionListener;
Expand All @@ -217,6 +219,7 @@ class Decoder {
this.#localMessageDefinitions = [];
this.#developerDataDefinitions = {};
this.#messages = {};
this.#profileVersion = null;

const errors = [];

Expand Down Expand Up @@ -247,7 +250,7 @@ class Decoder {
errors.push(error);
}
finally {
return { messages: this.#messages, errors: errors };
return { messages: this.#messages, profileVersion: this.#profileVersion, errors: errors };
}
}

Expand All @@ -260,7 +263,8 @@ class Decoder {

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

const { headerSize, dataSize } = Decoder.#readFileHeader(this.#stream, { decodeMode: this.#decodeMode });
const { headerSize, dataSize, profileVersion, } = Decoder.#readFileHeader(this.#stream, { decodeMode: this.#decodeMode });
this.#profileVersion ??= profileVersion;

// Read data messages and definitions
while (this.#stream.position < (position + headerSize + dataSize)) {
Expand Down Expand Up @@ -313,7 +317,7 @@ class Decoder {
const fieldDefinition = {
fieldDefinitionNumber: this.#stream.readByte(),
size: this.#stream.readByte(),
baseType: this.#stream.readByte()
baseType: this.#stream.readByte() & FIT.BaseTypeMask,
};

if (!(fieldDefinition.baseType in FIT.BaseTypeDefinitions)) {
Expand Down Expand Up @@ -515,7 +519,7 @@ class Decoder {
this.#developerDataDefinitions[message.developerDataIndex.rawFieldValue].fields.push({
developerDataIndex: message.developerDataIndex?.rawFieldValue,
fieldDefinitionNumber: message.fieldDefinitionNumber?.rawFieldValue,
fitBaseTypeId: message.fitBaseTypeId?.rawFieldValue ?? null,
fitBaseTypeId: message.fitBaseTypeId?.rawFieldValue & FIT.BaseTypeMask ?? null,
fieldName: message.fieldName?.rawFieldValue ?? null,
array: message.array?.rawFieldValue ?? null,
components: message.components?.rawFieldValue ?? null,
Expand Down Expand Up @@ -799,26 +803,27 @@ class Decoder {
static #readFileHeader(stream, { resetPosition = false, decodeMode = DecodeMode.NORMAL }) {
const position = stream.position;

if(decodeMode !== DecodeMode.NORMAL) {
if(decodeMode === DecodeMode.SKIP_HEADER) {
if (decodeMode !== DecodeMode.NORMAL) {
if (decodeMode === DecodeMode.SKIP_HEADER) {
stream.seek(HEADER_WITH_CRC_SIZE);
}

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

return {
headerSize,
dataSize: stream.length - headerSize - CRC_SIZE,
dataSize,
};
}

const fileHeader = {
headerSize: stream.readByte(),
protocolVersion: stream.readByte(),
profileVersion: stream.readUInt16(),
profileVersion: this.#expandProfileVersion(stream.readUInt16()),
dataSize: stream.readUInt32(),
dataType: stream.readString(4),
headerCRC: 0
headerCRC: null
};

if (fileHeader.headerSize === 14) {
Expand All @@ -835,6 +840,14 @@ class Decoder {
#throwError(error = "") {
throw Error(`FIT Runtime Error at byte ${this.#stream.position} ${error}`.trimEnd());
}

static #expandProfileVersion = (profileVersion) => {
const scale = profileVersion > PROFILE_VERSION_SCALE_CHANGE_VALUE ? 1000 : 100
return {
major: Math.floor(profileVersion / scale),
minor: profileVersion % scale
}
}
}

export default Decoder;
4 changes: 2 additions & 2 deletions src/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
// Profile Version = 21.188.0Release
// Tag = production/release/21.188.0-0-g55050f8
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
63 changes: 33 additions & 30 deletions src/fit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
// Profile Version = 21.188.0Release
// Tag = production/release/21.188.0-0-g55050f8
/////////////////////////////////////////////////////////////////////////////////////////////


Expand All @@ -17,40 +17,42 @@ const BaseType = {
ENUM: 0x00,
SINT8: 0x01,
UINT8: 0x02,
SINT16: 0x83,
UINT16: 0x84,
SINT32: 0x85,
UINT32: 0x86,
SINT16: 0x03,
UINT16: 0x04,
SINT32: 0x05,
UINT32: 0x06,
STRING: 0x07,
FLOAT32: 0x88,
FLOAT64: 0x89,
FLOAT32: 0x08,
FLOAT64: 0x09,
UINT8Z: 0x0A,
UINT16Z: 0x8B,
UINT32Z: 0x8C,
UINT16Z: 0x0B,
UINT32Z: 0x0C,
BYTE: 0x0D,
SINT64: 0x8E,
UINT64: 0x8F,
UINT64Z: 0x90
SINT64: 0x0E,
UINT64: 0x0F,
UINT64Z: 0x10
};

const BaseTypeMask = 0x1F;

const BaseTypeDefinitions = {
0x00: { size: 1, type: BaseType.ENUM, invalid: 0xFF },
0x01: { size: 1, type: BaseType.SINT8, invalid: 0x7F },
0x02: { size: 1, type: BaseType.UINT8, invalid: 0xFF },
0x83: { size: 2, type: BaseType.SINT16, invalid: 0x7FFF },
0x84: { size: 2, type: BaseType.UINT16, invalid: 0xFFFF },
0x85: { size: 4, type: BaseType.SINT32, invalid: 0x7FFFFFFF },
0x86: { size: 4, type: BaseType.UINT32, invalid: 0xFFFFFFFF },
0x07: { size: 1, type: BaseType.STRING, invalid: 0x00 },
0x88: { size: 4, type: BaseType.FLOAT32, invalid: 0xFFFFFFFF },
0x89: { size: 8, type: BaseType.FLOAT64, invalid: 0xFFFFFFFFFFFFFFFF },
0x0A: { size: 1, type: BaseType.UINT8Z, invalid: 0x00 },
0x8B: { size: 2, type: BaseType.UINT16Z, invalid: 0x0000 },
0x8C: { size: 4, type: BaseType.UINT32Z, invalid: 0x00000000 },
0x0D: { size: 1, type: BaseType.BYTE, invalid: 0xFF },
0x8E: { size: 8, type: BaseType.SINT64, invalid: 0x7FFFFFFFFFFFFFFF },
0x8F: { size: 8, type: BaseType.UINT64, invalid: 0xFFFFFFFFFFFFFFFF },
0x90: { size: 8, type: BaseType.UINT64Z, invalid: 0x0000000000000000 },
0x00: { size: 1, type: BaseType.ENUM, baseTypeEndianFlag: 0x00, invalid: 0xFF },
0x01: { size: 1, type: BaseType.SINT8, baseTypeEndianFlag: 0x00, invalid: 0x7F },
0x02: { size: 1, type: BaseType.UINT8, baseTypeEndianFlag: 0x00, invalid: 0xFF },
0x03: { size: 2, type: BaseType.SINT16, baseTypeEndianFlag: 0x80, invalid: 0x7FFF },
0x04: { size: 2, type: BaseType.UINT16, baseTypeEndianFlag: 0x80, invalid: 0xFFFF },
0x05: { size: 4, type: BaseType.SINT32, baseTypeEndianFlag: 0x80, invalid: 0x7FFFFFFF },
0x06: { size: 4, type: BaseType.UINT32, baseTypeEndianFlag: 0x80, invalid: 0xFFFFFFFF },
0x07: { size: 1, type: BaseType.STRING, baseTypeEndianFlag: 0x00, invalid: 0x00 },
0x08: { size: 4, type: BaseType.FLOAT32, baseTypeEndianFlag: 0x80, invalid: 0xFFFFFFFF },
0x09: { size: 8, type: BaseType.FLOAT64, baseTypeEndianFlag: 0x80, invalid: 0xFFFFFFFFFFFFFFFF },
0x0A: { size: 1, type: BaseType.UINT8Z, baseTypeEndianFlag: 0x00, invalid: 0x00 },
0x0B: { size: 2, type: BaseType.UINT16Z, baseTypeEndianFlag: 0x80, invalid: 0x0000 },
0x0C: { size: 4, type: BaseType.UINT32Z, baseTypeEndianFlag: 0x80, invalid: 0x00000000 },
0x0D: { size: 1, type: BaseType.BYTE, baseTypeEndianFlag: 0x00, invalid: 0xFF },
0x0E: { size: 8, type: BaseType.SINT64, baseTypeEndianFlag: 0x80, invalid: 0x7FFFFFFFFFFFFFFF },
0x0F: { size: 8, type: BaseType.UINT64, baseTypeEndianFlag: 0x80, invalid: 0xFFFFFFFFFFFFFFFF },
0x10: { size: 8, type: BaseType.UINT64Z, baseTypeEndianFlag: 0x80, invalid: 0x0000000000000000 },
};

const NumericFieldTypes = [
Expand Down Expand Up @@ -158,6 +160,7 @@ const isNumberStringDateOrBoolean = (obj) => {

export default {
BaseType,
BaseTypeMask,
BaseTypeDefinitions,
NumericFieldTypes,
FloatingPointFieldTypes,
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
// Profile Version = 21.188.0Release
// Tag = production/release/21.188.0-0-g55050f8
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
11 changes: 6 additions & 5 deletions src/mesg-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
// Profile Version = 21.188.0Release
// Tag = production/release/21.188.0-0-g55050f8
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down Expand Up @@ -67,6 +67,7 @@ class MesgDefinition {
num: fieldProfile[1].num,
size: this.#fieldSize(mesg[fieldName], baseTypeDef),
baseType: baseType,
baseTypeEndianFlag: baseTypeDef.baseTypeEndianFlag,
type: fieldProfile[1].type,
scale,
offset,
Expand All @@ -77,11 +78,11 @@ class MesgDefinition {
Object.keys(mesg.developerFields ?? {})?.sort()?.forEach((key) => {
const { developerDataIdMesg, fieldDescriptionMesg, } = this.#fieldDescriptionForKey(fieldDescriptions, key);

const baseTypeDef = FIT.BaseTypeDefinitions[fieldDescriptionMesg.fitBaseTypeId];
const baseTypeDef = FIT.BaseTypeDefinitions[fieldDescriptionMesg.fitBaseTypeId & FIT.BaseTypeMask];

this.developerFieldDefinitions.push({
key,
baseType: fieldDescriptionMesg.fitBaseTypeId,
baseType: fieldDescriptionMesg.fitBaseTypeId & FIT.BaseTypeMask,
fieldDefinitionNumber: fieldDescriptionMesg.fieldDefinitionNumber,
size: this.#fieldSize(mesg.developerFields[key], baseTypeDef),
developerDataIndex: developerDataIdMesg.developerDataIndex,
Expand Down Expand Up @@ -137,7 +138,7 @@ class MesgDefinition {
this.fieldDefinitions.forEach((fieldDefinition) => {
outputStream.writeUInt8(fieldDefinition.num);
outputStream.writeUInt8(fieldDefinition.size);
outputStream.writeUInt8(fieldDefinition.baseType);
outputStream.writeUInt8(fieldDefinition.baseType | fieldDefinition.baseTypeEndianFlag);
});

// Developer Field Definitions
Expand Down
4 changes: 2 additions & 2 deletions src/output-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
// Profile Version = 21.188.0Release
// Tag = production/release/21.188.0-0-g55050f8
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
Loading
Loading