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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const { messages, errors } = decoder.read({
convertDateTimesToDates: true,
includeUnknownData: false,
mergeHeartRates: true
decodeMemoGlobs: false,
});
````
#### mesgListener = (messageNumber, message) => {}
Expand Down Expand Up @@ -178,6 +179,10 @@ When true unknown field values are stored in the message using the field id as t
````
#### mergeHeartRates: true | false
When true automatically merge heart rate values from HR messages into the Record messages. This option requires the applyScaleAndOffset and expandComponents options to be enabled. This option has no effect on the Record messages when no HR messages are present in the decoded messages.

#### decodeMemoGlobs: true | false
When true, the decoder will reconstruct strings from memoGlob messages. Each reconstructed string will overwrite the targeted message field.

## Creating Streams
Stream objects contain the binary FIT data to be decoded. Streams objects can be created from byte-arrays, ArrayBuffers, and Node.js Buffers. Internally the Stream class uses an ArrayBuffer to manage the byte stream.
#### From a Byte Array
Expand Down
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.171.0",
"version": "21.178.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.171.0Release
// Tag = production/release/21.171.0-0-g57fed75
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
/////////////////////////////////////////////////////////////////////////////////////////////


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.171.0Release
// Tag = production/release/21.171.0-0-g57fed75
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
/////////////////////////////////////////////////////////////////////////////////////////////


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.171.0Release
// Tag = production/release/21.171.0-0-g57fed75
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
8 changes: 4 additions & 4 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.171.0Release
// Tag = production/release/21.171.0-0-g57fed75
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down Expand Up @@ -729,8 +729,8 @@ class Decoder {
return rawFieldValue;
}

const scale = Array.isArray(field?.scale ?? 1) ? field?.scale[0] : field?.scale ?? 1;
const offset = Array.isArray(field?.offset ?? 1) ? field?.offset[0] : field?.offset ?? 0;
const scale = Array.isArray(field?.scale ?? FIT.FIELD_DEFAULT_SCALE) ? field?.scale[0] : field?.scale ?? FIT.FIELD_DEFAULT_SCALE;
const offset = Array.isArray(field?.offset ?? FIT.FIELD_DEFAULT_OFFSET) ? field?.offset[0] : field?.offset ?? FIT.FIELD_DEFAULT_OFFSET;

try {
if (Array.isArray(rawFieldValue)) {
Expand Down
17 changes: 6 additions & 11 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.171.0Release
// Tag = production/release/21.171.0-0-g57fed75
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
/////////////////////////////////////////////////////////////////////////////////////////////


Expand All @@ -20,9 +20,6 @@ import Utils from "./utils.js";
const HEADER_WITH_CRC_SIZE = 14;
const HEADER_WITHOUT_CRC_SIZE = 12;

const FIELD_DEFAULT_SCALE = 1;
const FIELD_DEFAULT_OFFSET = 0;

/**
* A class for encoding FIT files.
* @class
Expand Down Expand Up @@ -131,7 +128,7 @@ class Encoder {
throw new Error("addDeveloperField() - one or more developerDataIndex values are null.", {
cause: {
key,
developerDataIdMesg,
developerDataIdMesg,
fieldDescriptionMesg
}
});
Expand All @@ -141,7 +138,7 @@ class Encoder {
throw new Error("addDeveloperField() - developerDataIndex values do not match.", {
cause: {
key,
developerDataIdMesg,
developerDataIdMesg,
fieldDescriptionMesg
}
});
Expand Down Expand Up @@ -215,12 +212,10 @@ class Encoder {
throw new Error();
}

const scale = fieldDefinition.components.length > 1 ? FIELD_DEFAULT_SCALE : fieldDefinition.scale;
const offset = fieldDefinition.components.length > 1 ? FIELD_DEFAULT_OFFSET : fieldDefinition.offset;
const hasScaleOrOffset = (scale != FIELD_DEFAULT_SCALE || offset != FIELD_DEFAULT_OFFSET);
const hasScaleOrOffset = (fieldDefinition.scale != FIT.FIELD_DEFAULT_SCALE || fieldDefinition.offset != FIT.FIELD_DEFAULT_OFFSET);

if (hasScaleOrOffset) {
const scaledValue = (value + offset) * scale;
const scaledValue = (value + fieldDefinition.offset) * fieldDefinition.scale;

return FIT.FloatingPointFieldTypes.includes(fieldDefinition.type) ? scaledValue : Math.round(scaledValue);
}
Expand Down
6 changes: 4 additions & 2 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.171.0Release
// Tag = production/release/21.171.0-0-g57fed75
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down Expand Up @@ -172,6 +172,8 @@ export default {
isNumberStringDateOrBoolean,
isNotNumberStringDateOrBoolean,
MAX_FIELD_SIZE: 255,
FIELD_DEFAULT_SCALE: 1,
FIELD_DEFAULT_OFFSET: 0,
MESG_DEFINITION_MASK: 0x40,
LOCAL_MESG_NUM_MASK: 0x0F,
ARCH_LITTLE_ENDIAN: 0x00,
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.171.0Release
// Tag = production/release/21.171.0-0-g57fed75
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
14 changes: 10 additions & 4 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.171.0Release
// Tag = production/release/21.171.0-0-g57fed75
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down Expand Up @@ -56,14 +56,20 @@ class MesgDefinition {
const baseType = FIT.FieldTypeToBaseType[fieldProfile[1].baseType];
const baseTypeDef = FIT.BaseTypeDefinitions[baseType];

let scale = fieldProfile[1].components.length > 1 ? FIT.FIELD_DEFAULT_SCALE : fieldProfile[1].scale;
let offset = fieldProfile[1].components.length > 1 ? FIT.FIELD_DEFAULT_OFFSET : fieldProfile[1].offset;

scale = Array.isArray(scale) ? scale[0] : scale ?? FIT.FIELD_DEFAULT_SCALE;
offset = Array.isArray(offset) ? offset[0] : offset ?? FIT.FIELD_DEFAULT_OFFSET;

this.fieldDefinitions.push({
name: fieldName,
num: fieldProfile[1].num,
size: this.#fieldSize(mesg[fieldName], baseTypeDef),
baseType: baseType,
type: fieldProfile[1].type,
scale: fieldProfile[1].scale,
offset: fieldProfile[1].offset,
scale,
offset,
components: fieldProfile[1].components,
});
});
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.171.0Release
// Tag = production/release/21.171.0-0-g57fed75
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
108 changes: 105 additions & 3 deletions src/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.171.0Release
// Tag = production/release/21.171.0-0-g57fed75
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
/////////////////////////////////////////////////////////////////////////////////////////////


const Profile = {
version: {
major: 21,
minor: 171,
minor: 178,
patch: 0,
type: "Release"
},
Expand Down Expand Up @@ -22980,6 +22980,95 @@ const Profile = {
subFields: []
},
},
},
470: {
num: 470,
name: "sleepDisruptionSeverityPeriod",
messagesKey: "sleepDisruptionSeverityPeriodMesgs",
fields: {
254: {
num: 254,
name: "messageIndex",
type: "messageIndex",
baseType: "uint16",
array: false,
scale: 1,
offset: 0,
units: "",
bits: [],
components: [],
isAccumulated: false,
hasComponents: false,
subFields: []
},
253: {
num: 253,
name: "timestamp",
type: "dateTime",
baseType: "uint32",
array: false,
scale: 1,
offset: 0,
units: "",
bits: [],
components: [],
isAccumulated: false,
hasComponents: false,
subFields: []
},
0: {
num: 0,
name: "severity",
type: "sleepDisruptionSeverity",
baseType: "enum",
array: false,
scale: 1,
offset: 0,
units: "",
bits: [],
components: [],
isAccumulated: false,
hasComponents: false,
subFields: []
},
},
},
471: {
num: 471,
name: "sleepDisruptionOvernightSeverity",
messagesKey: "sleepDisruptionOvernightSeverityMesgs",
fields: {
253: {
num: 253,
name: "timestamp",
type: "dateTime",
baseType: "uint32",
array: false,
scale: 1,
offset: 0,
units: "",
bits: [],
components: [],
isAccumulated: false,
hasComponents: false,
subFields: []
},
0: {
num: 0,
name: "severity",
type: "sleepDisruptionSeverity",
baseType: "enum",
array: false,
scale: 1,
offset: 0,
units: "",
bits: [],
components: [],
isAccumulated: false,
hasComponents: false,
subFields: []
},
},
},
398: {
num: 398,
Expand Down Expand Up @@ -23216,6 +23305,8 @@ types: {
393: "diveApneaAlarm",
398: "skinTempOvernight",
409: "hsaWristTemperatureData", // Message number for the HSA wrist temperature data message
470: "sleepDisruptionSeverityPeriod",
471: "sleepDisruptionOvernightSeverity",
0xFF00: "mfgRangeMin", // 0xFF00 - 0xFFFE reserved for manufacturer specific messages
0xFFFE: "mfgRangeMax", // 0xFF00 - 0xFFFE reserved for manufacturer specific messages
},
Expand Down Expand Up @@ -24271,6 +24362,7 @@ types: {
333: "tektroRacingProducts",
334: "daradInnovationCorporation",
335: "cycloptim",
337: "runna",
5759: "actigraphcorp",
},
garminProduct: {
Expand Down Expand Up @@ -24716,9 +24808,11 @@ types: {
4586: "instinct3Amoled45mm",
4587: "instinct3Amoled50mm",
4588: "descentG2",
4603: "venuX1",
4606: "hrm200",
4625: "vivoactive6",
4647: "approachS44",
4655: "edgeMtb",
4656: "approachS50",
4666: "fenixE",
4759: "instinct3Solar50mm",
Expand Down Expand Up @@ -27756,6 +27850,12 @@ types: {
2: "threatApproaching",
3: "threatApproachingFast",
},
sleepDisruptionSeverity: {
0: "none",
1: "low",
2: "medium",
3: "high",
},
maxMetSpeedSource: {
0: "onboardGps",
1: "connectedGps",
Expand Down Expand Up @@ -27897,6 +27997,8 @@ MesgNum : {
TANK_UPDATE: 319,
TANK_SUMMARY: 323,
SLEEP_ASSESSMENT: 346,
SLEEP_DISRUPTION_SEVERITY_PERIOD: 470,
SLEEP_DISRUPTION_OVERNIGHT_SEVERITY: 471,
SKIN_TEMP_OVERNIGHT: 398,
PAD: 105,
}
Expand Down
4 changes: 2 additions & 2 deletions src/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.171.0Release
// Tag = production/release/21.171.0-0-g57fed75
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
4 changes: 2 additions & 2 deletions src/utils-hr-mesg.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.171.0Release
// Tag = production/release/21.171.0-0-g57fed75
// Profile Version = 21.178.0Release
// Tag = production/release/21.178.0-0-g3bea629
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
Loading