Skip to content

Commit dc76a02

Browse files
authored
Garmin FIT SDK 21.171.0
Garmin FIT SDK 21.171.0
2 parents 5a2864d + 01a85ef commit dc76a02

18 files changed

+106
-42
lines changed

README.md

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ The FIT JavaScript SDK uses ECMAScript module syntax and requires Node.js v14.0
99
```sh
1010
npm install @garmin/fitsdk
1111
```
12-
## Usage
12+
## Decoder
13+
### Usage
1314
````js
1415
import { Decoder, Stream, Profile, Utils } from '@garmin/fitsdk';
1516

@@ -27,8 +28,6 @@ const { messages, errors } = decoder.read();
2728
console.log(errors);
2829
console.log(messages);
2930
````
30-
## Decoder
31-
3231
### Constructor
3332

3433
Decoder objects are created from Streams representing the binary FIT file data to be decoded. See [Creating Streams](#creatingstreams) for more information on constructing Stream objects.
@@ -37,24 +36,24 @@ Once a Decoder object is created it can be used to check that the Stream is a FI
3736

3837
### isFIT Method
3938

40-
All valid FIT files should include a 12 or 14 byte file header. The 14 byte header is the preferred header size and the most common size used. Bytes 8–11 of the header contain the ASCII values ".FIT. This string can easily be spotted when opening a binary FIT file in a text or hex editor.
39+
All valid FIT files should include a 12 or 14 byte file header. The 14 byte header is the preferred header size and the most common size used. Bytes 8–11 of the header contain the ASCII values ".FIT". This string can easily be spotted when opening a binary FIT file in a text or hex editor.
4140

42-
```
41+
````bash
4342
Offset: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
4443
00000000: 0E 10 43 08 78 06 09 00 2E 46 49 54 96 85 40 00 ..C.x....FIT..@.
4544
00000010: 00 00 00 07 03 04 8C 04 04 86 07 04 86 01 02 84 ................
4645
00000020: 02 02 84 05 02 84 00 01 00 00 19 28 7E C5 95 B0 ...........(~E.0
47-
```
46+
````
4847

49-
The isFIT method reads the file header and returns true if bytes 8–11 are equal to the ACSII values ".FIT. isFIT provides a quick way to check that the file is a FIT file before attempting to decode the file.
48+
The isFIT method reads the file header and returns true if bytes 8–11 are equal to the ACSII values ".FIT". isFIT provides a quick way to check that the file is a FIT file before attempting to decode the file.
5049

5150
The Decoder class includes a static and instance version of the isFIT method.
5251

5352
### Check Integrity Method
5453

5554
The checkIntegrity method performs three checks on a FIT file:
5655

57-
1. Checks that bytes 8–11 of the header contain the ASCII values ".FIT.
56+
1. Checks that bytes 8–11 of the header contain the ASCII values ".FIT".
5857
2. Checks that the total file size is equal to Header Size + Data Size + CRC Size.
5958
3. Reads the contents of the file, computes the CRC, and then checks that the computed CRC matches the file CRC.
6059

@@ -83,7 +82,6 @@ const { messages, errors } = decoder.read({
8382
Optional callback function that can be used to inspect or manipulate messages after they are fully decoded and all the options have been applied. The message is mutable and we be returned from the Read method in the messages dictionary.
8483

8584
Example mesgListener callback that tracks the field names across all Record messages.
86-
8785
````js
8886
const recordFields = new Set();
8987

@@ -221,3 +219,65 @@ A convince method for converting FIT Epoch values to JavaScript Date objects.
221219
````js
222220
const jsDate = Utils.convertDateTimeToDate(fitDateTime);
223221
````
222+
## Encoder
223+
### Usage
224+
````js
225+
// Import the SDK
226+
import { Encoder, Profile} from "@garmin/fitsdk";
227+
228+
// Create an Encoder
229+
const encoder = new Encoder();
230+
231+
//
232+
// Write messages to the output-stream
233+
//
234+
// The message data should match the format returned by
235+
// the Decoder. Field names should be camelCase. The fields
236+
// definitions can be found in the Profile.
237+
//
238+
239+
// Pass the MesgNum and message data as separate parameters to the onMesg() method
240+
encoder.onMesg(Profile.MesgNum.FILE_ID, {
241+
manufacturer: "development",
242+
product: 1,
243+
timeCreated: new Date(),
244+
type: "activity",
245+
});
246+
247+
// The writeMesg() method expects the mesgNum to be included in the message data
248+
// Internally, writeMesg() calls onMesg()
249+
encoder.writeMesg({
250+
mesgNum: Profile.MesgNum.FILE_ID,
251+
manufacturer: "development",
252+
product: 1,
253+
timeCreated: new Date(),
254+
type: "activity",
255+
});
256+
257+
// Unknown values in the message will be ignored by the Encoder
258+
encoder.onMesg(Profile.MesgNum.FILE_ID, {
259+
manufacturer: "development",
260+
product: 1,
261+
timeCreated: new Date(),
262+
type: "activity",
263+
customField: 12345, // This value will be ignored by the Encoder
264+
});
265+
266+
// Subfield values in the message will be ignored by the Encoder
267+
encoder.onMesg(Profile.MesgNum.FILE_ID, {
268+
manufacturer: "development",
269+
product: 4440, // This is the main product field, which is a uint16
270+
garminProduct: "edge1050", // This value will be ignored by the Encoder, use the main field value instead
271+
timeCreated: new Date(),
272+
type: "activity",
273+
});
274+
275+
// Closing the encoder returns the file as an UInt8 Array
276+
const uint8Array = encoder.close();
277+
278+
// Write the file to disk,
279+
import * as fs from "fs";
280+
fs.writeFileSync("example.fit", uint8Array);
281+
282+
````
283+
See the [Encode Activity Recipe](https://github.com/garmin/fit-javascript-sdk/blob/main/test/encode-activity-recipe.test.js) for a complete example of encoding a FIT Activity file usine the FIT JavaScript SDK.

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.170.0",
3+
"version": "21.171.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.170.0Release
9-
// Tag = production/release/21.170.0-0-g5991e72
8+
// Profile Version = 21.171.0Release
9+
// Tag = production/release/21.171.0-0-g57fed75
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.170.0Release
9-
// Tag = production/release/21.170.0-0-g5991e72
8+
// Profile Version = 21.171.0Release
9+
// Tag = production/release/21.171.0-0-g57fed75
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.170.0Release
9-
// Tag = production/release/21.170.0-0-g5991e72
8+
// Profile Version = 21.171.0Release
9+
// Tag = production/release/21.171.0-0-g57fed75
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

src/decoder.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.170.0Release
9-
// Tag = production/release/21.170.0-0-g5991e72
8+
// Profile Version = 21.171.0Release
9+
// Tag = production/release/21.171.0-0-g57fed75
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

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.170.0Release
9-
// Tag = production/release/21.170.0-0-g5991e72
8+
// Profile Version = 21.171.0Release
9+
// Tag = production/release/21.171.0-0-g57fed75
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

src/fit.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.170.0Release
9-
// Tag = production/release/21.170.0-0-g5991e72
8+
// Profile Version = 21.171.0Release
9+
// Tag = production/release/21.171.0-0-g57fed75
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

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.170.0Release
9-
// Tag = production/release/21.170.0-0-g5991e72
8+
// Profile Version = 21.171.0Release
9+
// Tag = production/release/21.171.0-0-g57fed75
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

src/mesg-definition.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.170.0Release
9-
// Tag = production/release/21.170.0-0-g5991e72
8+
// Profile Version = 21.171.0Release
9+
// Tag = production/release/21.171.0-0-g57fed75
1010
/////////////////////////////////////////////////////////////////////////////////////////////
1111

1212

0 commit comments

Comments
 (0)