@garmin/fitsdk 21.169.0 → 21.171.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -9
- package/package.json +1 -1
- package/src/accumulator.js +2 -2
- package/src/bit-stream.js +2 -2
- package/src/crc-calculator.js +2 -2
- package/src/decoder.js +2 -2
- package/src/encoder.js +15 -5
- package/src/fit.js +11 -2
- package/src/index.js +2 -2
- package/src/mesg-definition.js +3 -3
- package/src/output-stream.js +2 -2
- package/src/profile.js +1393 -1487
- package/src/stream.js +2 -2
- package/src/utils-hr-mesg.js +2 -2
- package/src/utils-internal.js +2 -2
- package/src/utils-memo-glob.js +2 -2
- package/src/utils.js +7 -27
package/README.md
CHANGED
|
@@ -9,7 +9,8 @@ The FIT JavaScript SDK uses ECMAScript module syntax and requires Node.js v14.0
|
|
|
9
9
|
```sh
|
|
10
10
|
npm install @garmin/fitsdk
|
|
11
11
|
```
|
|
12
|
-
##
|
|
12
|
+
## Decoder
|
|
13
|
+
### Usage
|
|
13
14
|
````js
|
|
14
15
|
import { Decoder, Stream, Profile, Utils } from '@garmin/fitsdk';
|
|
15
16
|
|
|
@@ -27,8 +28,6 @@ const { messages, errors } = decoder.read();
|
|
|
27
28
|
console.log(errors);
|
|
28
29
|
console.log(messages);
|
|
29
30
|
````
|
|
30
|
-
## Decoder
|
|
31
|
-
|
|
32
31
|
### Constructor
|
|
33
32
|
|
|
34
33
|
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,16 +36,16 @@ Once a Decoder object is created it can be used to check that the Stream is a FI
|
|
|
37
36
|
|
|
38
37
|
### isFIT Method
|
|
39
38
|
|
|
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
|
|
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.
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
````bash
|
|
43
42
|
Offset: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
|
|
44
43
|
00000000: 0E 10 43 08 78 06 09 00 2E 46 49 54 96 85 40 00 ..C.x....FIT..@.
|
|
45
44
|
00000010: 00 00 00 07 03 04 8C 04 04 86 07 04 86 01 02 84 ................
|
|
46
45
|
00000020: 02 02 84 05 02 84 00 01 00 00 19 28 7E C5 95 B0 ...........(~E.0
|
|
47
|
-
|
|
46
|
+
````
|
|
48
47
|
|
|
49
|
-
The isFIT method reads the file header and returns true if bytes 8–11 are equal to the ACSII values ".FIT
|
|
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.
|
|
50
49
|
|
|
51
50
|
The Decoder class includes a static and instance version of the isFIT method.
|
|
52
51
|
|
|
@@ -54,7 +53,7 @@ The Decoder class includes a static and instance version of the isFIT method.
|
|
|
54
53
|
|
|
55
54
|
The checkIntegrity method performs three checks on a FIT file:
|
|
56
55
|
|
|
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".
|
|
58
57
|
2. Checks that the total file size is equal to Header Size + Data Size + CRC Size.
|
|
59
58
|
3. Reads the contents of the file, computes the CRC, and then checks that the computed CRC matches the file CRC.
|
|
60
59
|
|
|
@@ -83,7 +82,6 @@ const { messages, errors } = decoder.read({
|
|
|
83
82
|
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.
|
|
84
83
|
|
|
85
84
|
Example mesgListener callback that tracks the field names across all Record messages.
|
|
86
|
-
|
|
87
85
|
````js
|
|
88
86
|
const recordFields = new Set();
|
|
89
87
|
|
|
@@ -221,3 +219,65 @@ A convince method for converting FIT Epoch values to JavaScript Date objects.
|
|
|
221
219
|
````js
|
|
222
220
|
const jsDate = Utils.convertDateTimeToDate(fitDateTime);
|
|
223
221
|
````
|
|
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/package.json
CHANGED
package/src/accumulator.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// Transfer (FIT) Protocol License.
|
|
6
6
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
7
|
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
|
|
8
|
-
// Profile Version = 21.
|
|
9
|
-
// Tag = production/release/21.
|
|
8
|
+
// Profile Version = 21.171.0Release
|
|
9
|
+
// Tag = production/release/21.171.0-0-g57fed75
|
|
10
10
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
11
11
|
|
|
12
12
|
|
package/src/bit-stream.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// Transfer (FIT) Protocol License.
|
|
6
6
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
7
|
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
|
|
8
|
-
// Profile Version = 21.
|
|
9
|
-
// Tag = production/release/21.
|
|
8
|
+
// Profile Version = 21.171.0Release
|
|
9
|
+
// Tag = production/release/21.171.0-0-g57fed75
|
|
10
10
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
11
11
|
|
|
12
12
|
|
package/src/crc-calculator.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// Transfer (FIT) Protocol License.
|
|
6
6
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
7
|
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
|
|
8
|
-
// Profile Version = 21.
|
|
9
|
-
// Tag = production/release/21.
|
|
8
|
+
// Profile Version = 21.171.0Release
|
|
9
|
+
// Tag = production/release/21.171.0-0-g57fed75
|
|
10
10
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
11
11
|
|
|
12
12
|
|
package/src/decoder.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// Transfer (FIT) Protocol License.
|
|
6
6
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
7
|
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
|
|
8
|
-
// Profile Version = 21.
|
|
9
|
-
// Tag = production/release/21.
|
|
8
|
+
// Profile Version = 21.171.0Release
|
|
9
|
+
// Tag = production/release/21.171.0-0-g57fed75
|
|
10
10
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
11
11
|
|
|
12
12
|
|
package/src/encoder.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// Transfer (FIT) Protocol License.
|
|
6
6
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
7
|
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
|
|
8
|
-
// Profile Version = 21.
|
|
9
|
-
// Tag = production/release/21.
|
|
8
|
+
// Profile Version = 21.171.0Release
|
|
9
|
+
// Tag = production/release/21.171.0-0-g57fed75
|
|
10
10
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
11
11
|
|
|
12
12
|
|
|
@@ -20,6 +20,9 @@ import Utils from "./utils.js";
|
|
|
20
20
|
const HEADER_WITH_CRC_SIZE = 14;
|
|
21
21
|
const HEADER_WITHOUT_CRC_SIZE = 12;
|
|
22
22
|
|
|
23
|
+
const FIELD_DEFAULT_SCALE = 1;
|
|
24
|
+
const FIELD_DEFAULT_OFFSET = 0;
|
|
25
|
+
|
|
23
26
|
/**
|
|
24
27
|
* A class for encoding FIT files.
|
|
25
28
|
* @class
|
|
@@ -212,10 +215,17 @@ class Encoder {
|
|
|
212
215
|
throw new Error();
|
|
213
216
|
}
|
|
214
217
|
|
|
215
|
-
const scale = fieldDefinition.components.length > 1 ?
|
|
216
|
-
const offset = fieldDefinition.components.length > 1 ?
|
|
218
|
+
const scale = fieldDefinition.components.length > 1 ? FIELD_DEFAULT_SCALE : fieldDefinition.scale;
|
|
219
|
+
const offset = fieldDefinition.components.length > 1 ? FIELD_DEFAULT_OFFSET : fieldDefinition.offset;
|
|
220
|
+
const hasScaleOrOffset = (scale != FIELD_DEFAULT_SCALE || offset != FIELD_DEFAULT_OFFSET);
|
|
221
|
+
|
|
222
|
+
if (hasScaleOrOffset) {
|
|
223
|
+
const scaledValue = (value + offset) * scale;
|
|
217
224
|
|
|
218
|
-
|
|
225
|
+
return FIT.FloatingPointFieldTypes.includes(fieldDefinition.type) ? scaledValue : Math.round(scaledValue);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return value;
|
|
219
229
|
}
|
|
220
230
|
|
|
221
231
|
// Is this a date_time field?
|
package/src/fit.js
CHANGED
|
@@ -5,11 +5,14 @@
|
|
|
5
5
|
// Transfer (FIT) Protocol License.
|
|
6
6
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
7
|
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
|
|
8
|
-
// Profile Version = 21.
|
|
9
|
-
// Tag = production/release/21.
|
|
8
|
+
// Profile Version = 21.171.0Release
|
|
9
|
+
// Tag = production/release/21.171.0-0-g57fed75
|
|
10
10
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
11
11
|
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* FIT Base Type enum
|
|
15
|
+
*/
|
|
13
16
|
const BaseType = {
|
|
14
17
|
ENUM: 0x00,
|
|
15
18
|
SINT8: 0x01,
|
|
@@ -68,6 +71,11 @@ const NumericFieldTypes = [
|
|
|
68
71
|
"uint64z"
|
|
69
72
|
];
|
|
70
73
|
|
|
74
|
+
const FloatingPointFieldTypes = [
|
|
75
|
+
"float32",
|
|
76
|
+
"float64",
|
|
77
|
+
];
|
|
78
|
+
|
|
71
79
|
const FieldTypeToBaseType = {
|
|
72
80
|
"enum": BaseType.UINT8,
|
|
73
81
|
"sint8": BaseType.SINT8,
|
|
@@ -152,6 +160,7 @@ export default {
|
|
|
152
160
|
BaseType,
|
|
153
161
|
BaseTypeDefinitions,
|
|
154
162
|
NumericFieldTypes,
|
|
163
|
+
FloatingPointFieldTypes,
|
|
155
164
|
FieldTypeToBaseType,
|
|
156
165
|
BaseTypeToFieldType,
|
|
157
166
|
isNullOrUndefined,
|
package/src/index.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// Transfer (FIT) Protocol License.
|
|
6
6
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
7
|
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
|
|
8
|
-
// Profile Version = 21.
|
|
9
|
-
// Tag = production/release/21.
|
|
8
|
+
// Profile Version = 21.171.0Release
|
|
9
|
+
// Tag = production/release/21.171.0-0-g57fed75
|
|
10
10
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
11
11
|
|
|
12
12
|
|
package/src/mesg-definition.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// Transfer (FIT) Protocol License.
|
|
6
6
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
7
|
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
|
|
8
|
-
// Profile Version = 21.
|
|
9
|
-
// Tag = production/release/21.
|
|
8
|
+
// Profile Version = 21.171.0Release
|
|
9
|
+
// Tag = production/release/21.171.0-0-g57fed75
|
|
10
10
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
11
11
|
|
|
12
12
|
|
|
@@ -147,7 +147,7 @@ class MesgDefinition {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
equals(other) {
|
|
150
|
-
if (this.
|
|
150
|
+
if (this.globalMessageNumber !== other.globalMessageNumber
|
|
151
151
|
|| this.fieldDefinitions.length !== other.fieldDefinitions.length
|
|
152
152
|
|| this.developerFieldDefinitions.length !== other.developerFieldDefinitions.length) {
|
|
153
153
|
return false;
|
package/src/output-stream.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// Transfer (FIT) Protocol License.
|
|
6
6
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
7
7
|
// ****WARNING**** This file is auto-generated! Do NOT edit this file.
|
|
8
|
-
// Profile Version = 21.
|
|
9
|
-
// Tag = production/release/21.
|
|
8
|
+
// Profile Version = 21.171.0Release
|
|
9
|
+
// Tag = production/release/21.171.0-0-g57fed75
|
|
10
10
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
11
11
|
|
|
12
12
|
|