Skip to content

Commit

Permalink
Garmin FIT SDK 21.161.0
Browse files Browse the repository at this point in the history
* Garmin FIT SDK 21.161.0
* Adds Encoder feature
* Update versions of Node tested
  • Loading branch information
pryhoda authored Jan 14, 2025
1 parent c83bf42 commit 9b67561
Show file tree
Hide file tree
Showing 29 changed files with 3,228 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x]
node-version: [16.x, 18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ The Read method accepts an optional options object that can be used to customize
````js
const { messages, errors } = decoder.read({
mesgListener: (messageNumber, message) => {},
mesgDefinitionListener: (mesgDefinition) => {},
fieldDescriptionListener: (key, developerDataIdMesg, fieldDescriptionMesg) => {},
applyScaleAndOffset: true,
expandSubFields: true,
expandComponents: true,
Expand Down Expand Up @@ -97,6 +99,10 @@ const { messages, errors } = decoder.read({

console.log(recordFields);
````
#### mesgDefinitionListener: (mesgDefinition) => {}
Optional callback function that can be used to inspect message defintions as they are decoded from the file.
#### fieldDescriptionListener: (key, developerDataIdMesg, fieldDescriptionMesg) => {}
Optional callback function that can be used to inspect developer field descriptions as they are decoded from the file.
#### applyScaleAndOffset: true | false
When true the scale and offset values as defined in the FIT Profile are applied to the raw field values.
````js
Expand Down
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@garmin/fitsdk",
"version": "21.158.0",
"version": "21.161.0",
"description": "FIT JavaScript SDK",
"main": "src/index.js",
"type": "module",
"scripts": {
"build": "node .",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
"test": "vitest run"
},
"author": "Garmin International, Inc.",
"license": "SEE LICENSE IN LICENSE.txt",
Expand All @@ -18,9 +18,6 @@
"src/"
],
"devDependencies": {
"jest": "^28.1.2"
},
"jest": {
"transform": {}
"vitest": "^2.1.8"
}
}
}
6 changes: 3 additions & 3 deletions src/accumulator.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/////////////////////////////////////////////////////////////////////////////////////////////
// Copyright 2024 Garmin International, Inc.
// Copyright 2025 Garmin International, Inc.
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
// may not use this file except in compliance with the Flexible and Interoperable Data
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.158.0Release
// Tag = production/release/21.158.0-0-gc9428aa
// Profile Version = 21.161.0Release
// Tag = production/release/21.161.0-0-g58854c0
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
6 changes: 3 additions & 3 deletions src/bit-stream.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/////////////////////////////////////////////////////////////////////////////////////////////
// Copyright 2024 Garmin International, Inc.
// Copyright 2025 Garmin International, Inc.
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
// may not use this file except in compliance with the Flexible and Interoperable Data
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.158.0Release
// Tag = production/release/21.158.0-0-gc9428aa
// Profile Version = 21.161.0Release
// Tag = production/release/21.161.0-0-g58854c0
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
6 changes: 3 additions & 3 deletions src/crc-calculator.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/////////////////////////////////////////////////////////////////////////////////////////////
// Copyright 2024 Garmin International, Inc.
// Copyright 2025 Garmin International, Inc.
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
// may not use this file except in compliance with the Flexible and Interoperable Data
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.158.0Release
// Tag = production/release/21.158.0-0-gc9428aa
// Profile Version = 21.161.0Release
// Tag = production/release/21.161.0-0-g58854c0
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down
39 changes: 36 additions & 3 deletions src/decoder.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/////////////////////////////////////////////////////////////////////////////////////////////
// Copyright 2024 Garmin International, Inc.
// Copyright 2025 Garmin International, Inc.
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
// may not use this file except in compliance with the Flexible and Interoperable Data
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
// Profile Version = 21.158.0Release
// Tag = production/release/21.158.0-0-gc9428aa
// Profile Version = 21.161.0Release
// Tag = production/release/21.161.0-0-g58854c0
/////////////////////////////////////////////////////////////////////////////////////////////


Expand Down Expand Up @@ -48,6 +48,8 @@ class Decoder {
#decodeMode = DecodeMode.NORMAL;

#mesgListener = null;
#mesgDefinitionListener = null;
#fieldDescriptionListener = null;
#optExpandSubFields = true;
#optExpandComponents = true;
#optApplyScaleAndOffset = true;
Expand Down Expand Up @@ -149,11 +151,28 @@ class Decoder {
* @param {Object} message - The message
*/

/**
* Message Definition Listener Callback
*
* @callback Decoder~mesgDefinitionListener
* @param {Object} messageDefinition - The message Definition
*/

/**
* Developer Field Description Listener Callback
*
* @callback Decoder~fieldDescriptionListener
* @param {Number} key - The key associated with this pairing of of Developer Data Id and Field Description Mesgs
* @param {Object} developerDataIdMesg - The Developer Data Id Mesg associated with this pairing
* @param {Object} fieldDescriptionMesg - The Field Description Mesg associated with this pairing
*/

/**
* Read the messages from the stream.
* @param {Object=} [options] - Read options (optional)
* @param {Decoder~mesgListener} [options.mesgListener=null] - (optional, default null) mesgListener(mesgNum, message)
* @param {Decoder~mesgDefinitionListener} [options.mesgDefinitionListener=null] - (optional, default null) mesgDefinitionListener(mesgDefinition)
* @param {Decoder~fieldDescriptionListener} [options.fieldDescriptionListener=null] - (optional, default null) fieldDescriptionListener(key, developerDataIdMesg, fieldDescriptionMesg)
* @param {Boolean} [options.expandSubFields=true] - (optional, default true)
* @param {Boolean} [options.expandComponents=true] - (optional, default true)
* @param {Boolean} [options.applyScaleAndOffset=true] - (optional, default true)
Expand All @@ -167,6 +186,8 @@ class Decoder {
*/
read({
mesgListener = null,
mesgDefinitionListener = null,
fieldDescriptionListener = null,
expandSubFields = true,
expandComponents = true,
applyScaleAndOffset = true,
Expand All @@ -178,6 +199,8 @@ class Decoder {
dataOnly = false,} = {}) {

this.#mesgListener = mesgListener;
this.#mesgDefinitionListener = mesgDefinitionListener;
this.#fieldDescriptionListener = fieldDescriptionListener;
this.#optExpandSubFields = expandSubFields
this.#optExpandComponents = expandComponents;
this.#optApplyScaleAndOffset = applyScaleAndOffset;
Expand Down Expand Up @@ -310,6 +333,8 @@ class Decoder {
}
}

this.#mesgDefinitionListener?.({...messageDefinition});

let messageProfile = Profile.messages[messageDefinition.globalMessageNumber];

if (messageProfile == null && this.#optIncludeUnknownData) {
Expand Down Expand Up @@ -414,6 +439,14 @@ class Decoder {

this.#messages[messageDefinition.messagesKey].push(message);
this.#mesgListener?.(messageDefinition.globalMessageNumber, message);

if (mesgNum === Profile.MesgNum.FIELD_DESCRIPTION && this.#fieldDescriptionListener != null) {
const developerDataIdMesg = this.#messages.developerDataIdMesgs?.find((developerDataIdMesg) => {
return developerDataIdMesg.developerDataIndex === message.developerDataIndex;
}) ?? {};

this.#fieldDescriptionListener(message.key, {...developerDataIdMesg}, {...message});
}
}
}

Expand Down
Loading

0 comments on commit 9b67561

Please sign in to comment.