Skip to content

Commit 9b67561

Browse files
authored
Garmin FIT SDK 21.161.0
* Garmin FIT SDK 21.161.0 * Adds Encoder feature * Update versions of Node tested
1 parent c83bf42 commit 9b67561

29 files changed

+3228
-72
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

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

1919
steps:

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ The Read method accepts an optional options object that can be used to customize
6868
````js
6969
const { messages, errors } = decoder.read({
7070
mesgListener: (messageNumber, message) => {},
71+
mesgDefinitionListener: (mesgDefinition) => {},
72+
fieldDescriptionListener: (key, developerDataIdMesg, fieldDescriptionMesg) => {},
7173
applyScaleAndOffset: true,
7274
expandSubFields: true,
7375
expandComponents: true,
@@ -97,6 +99,10 @@ const { messages, errors } = decoder.read({
9799

98100
console.log(recordFields);
99101
````
102+
#### mesgDefinitionListener: (mesgDefinition) => {}
103+
Optional callback function that can be used to inspect message defintions as they are decoded from the file.
104+
#### fieldDescriptionListener: (key, developerDataIdMesg, fieldDescriptionMesg) => {}
105+
Optional callback function that can be used to inspect developer field descriptions as they are decoded from the file.
100106
#### applyScaleAndOffset: true | false
101107
When true the scale and offset values as defined in the FIT Profile are applied to the raw field values.
102108
````js

package.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "@garmin/fitsdk",
3-
"version": "21.158.0",
3+
"version": "21.161.0",
44
"description": "FIT JavaScript SDK",
55
"main": "src/index.js",
66
"type": "module",
77
"scripts": {
88
"build": "node .",
9-
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
9+
"test": "vitest run"
1010
},
1111
"author": "Garmin International, Inc.",
1212
"license": "SEE LICENSE IN LICENSE.txt",
@@ -18,9 +18,6 @@
1818
"src/"
1919
],
2020
"devDependencies": {
21-
"jest": "^28.1.2"
22-
},
23-
"jest": {
24-
"transform": {}
21+
"vitest": "^2.1.8"
2522
}
26-
}
23+
}

src/accumulator.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/////////////////////////////////////////////////////////////////////////////////////////////
2-
// Copyright 2024 Garmin International, Inc.
2+
// Copyright 2025 Garmin International, Inc.
33
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
44
// may not use this file except in compliance with the Flexible and Interoperable Data
55
// Transfer (FIT) Protocol License.
66
/////////////////////////////////////////////////////////////////////////////////////////////
77
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
8-
// Profile Version = 21.158.0Release
9-
// Tag = production/release/21.158.0-0-gc9428aa
8+
// Profile Version = 21.161.0Release
9+
// Tag = production/release/21.161.0-0-g58854c0
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

src/bit-stream.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/////////////////////////////////////////////////////////////////////////////////////////////
2-
// Copyright 2024 Garmin International, Inc.
2+
// Copyright 2025 Garmin International, Inc.
33
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
44
// may not use this file except in compliance with the Flexible and Interoperable Data
55
// Transfer (FIT) Protocol License.
66
/////////////////////////////////////////////////////////////////////////////////////////////
77
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
8-
// Profile Version = 21.158.0Release
9-
// Tag = production/release/21.158.0-0-gc9428aa
8+
// Profile Version = 21.161.0Release
9+
// Tag = production/release/21.161.0-0-g58854c0
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

src/crc-calculator.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/////////////////////////////////////////////////////////////////////////////////////////////
2-
// Copyright 2024 Garmin International, Inc.
2+
// Copyright 2025 Garmin International, Inc.
33
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
44
// may not use this file except in compliance with the Flexible and Interoperable Data
55
// Transfer (FIT) Protocol License.
66
/////////////////////////////////////////////////////////////////////////////////////////////
77
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
8-
// Profile Version = 21.158.0Release
9-
// Tag = production/release/21.158.0-0-gc9428aa
8+
// Profile Version = 21.161.0Release
9+
// Tag = production/release/21.161.0-0-g58854c0
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

src/decoder.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/////////////////////////////////////////////////////////////////////////////////////////////
2-
// Copyright 2024 Garmin International, Inc.
2+
// Copyright 2025 Garmin International, Inc.
33
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
44
// may not use this file except in compliance with the Flexible and Interoperable Data
55
// Transfer (FIT) Protocol License.
66
/////////////////////////////////////////////////////////////////////////////////////////////
77
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
8-
// Profile Version = 21.158.0Release
9-
// Tag = production/release/21.158.0-0-gc9428aa
8+
// Profile Version = 21.161.0Release
9+
// Tag = production/release/21.161.0-0-g58854c0
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

@@ -48,6 +48,8 @@ class Decoder {
4848
#decodeMode = DecodeMode.NORMAL;
4949

5050
#mesgListener = null;
51+
#mesgDefinitionListener = null;
52+
#fieldDescriptionListener = null;
5153
#optExpandSubFields = true;
5254
#optExpandComponents = true;
5355
#optApplyScaleAndOffset = true;
@@ -149,11 +151,28 @@ class Decoder {
149151
* @param {Object} message - The message
150152
*/
151153

154+
/**
155+
* Message Definition Listener Callback
156+
*
157+
* @callback Decoder~mesgDefinitionListener
158+
* @param {Object} messageDefinition - The message Definition
159+
*/
160+
161+
/**
162+
* Developer Field Description Listener Callback
163+
*
164+
* @callback Decoder~fieldDescriptionListener
165+
* @param {Number} key - The key associated with this pairing of of Developer Data Id and Field Description Mesgs
166+
* @param {Object} developerDataIdMesg - The Developer Data Id Mesg associated with this pairing
167+
* @param {Object} fieldDescriptionMesg - The Field Description Mesg associated with this pairing
168+
*/
152169

153170
/**
154171
* Read the messages from the stream.
155172
* @param {Object=} [options] - Read options (optional)
156173
* @param {Decoder~mesgListener} [options.mesgListener=null] - (optional, default null) mesgListener(mesgNum, message)
174+
* @param {Decoder~mesgDefinitionListener} [options.mesgDefinitionListener=null] - (optional, default null) mesgDefinitionListener(mesgDefinition)
175+
* @param {Decoder~fieldDescriptionListener} [options.fieldDescriptionListener=null] - (optional, default null) fieldDescriptionListener(key, developerDataIdMesg, fieldDescriptionMesg)
157176
* @param {Boolean} [options.expandSubFields=true] - (optional, default true)
158177
* @param {Boolean} [options.expandComponents=true] - (optional, default true)
159178
* @param {Boolean} [options.applyScaleAndOffset=true] - (optional, default true)
@@ -167,6 +186,8 @@ class Decoder {
167186
*/
168187
read({
169188
mesgListener = null,
189+
mesgDefinitionListener = null,
190+
fieldDescriptionListener = null,
170191
expandSubFields = true,
171192
expandComponents = true,
172193
applyScaleAndOffset = true,
@@ -178,6 +199,8 @@ class Decoder {
178199
dataOnly = false,} = {}) {
179200

180201
this.#mesgListener = mesgListener;
202+
this.#mesgDefinitionListener = mesgDefinitionListener;
203+
this.#fieldDescriptionListener = fieldDescriptionListener;
181204
this.#optExpandSubFields = expandSubFields
182205
this.#optExpandComponents = expandComponents;
183206
this.#optApplyScaleAndOffset = applyScaleAndOffset;
@@ -310,6 +333,8 @@ class Decoder {
310333
}
311334
}
312335

336+
this.#mesgDefinitionListener?.({...messageDefinition});
337+
313338
let messageProfile = Profile.messages[messageDefinition.globalMessageNumber];
314339

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

415440
this.#messages[messageDefinition.messagesKey].push(message);
416441
this.#mesgListener?.(messageDefinition.globalMessageNumber, message);
442+
443+
if (mesgNum === Profile.MesgNum.FIELD_DESCRIPTION && this.#fieldDescriptionListener != null) {
444+
const developerDataIdMesg = this.#messages.developerDataIdMesgs?.find((developerDataIdMesg) => {
445+
return developerDataIdMesg.developerDataIndex === message.developerDataIndex;
446+
}) ?? {};
447+
448+
this.#fieldDescriptionListener(message.key, {...developerDataIdMesg}, {...message});
449+
}
417450
}
418451
}
419452

0 commit comments

Comments
 (0)