|
1 | 1 | ///////////////////////////////////////////////////////////////////////////////////////////// |
2 | | -// Copyright 2025 Garmin International, Inc. |
| 2 | +// Copyright 2026 Garmin International, Inc. |
3 | 3 | // Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you |
4 | 4 | // may not use this file except in compliance with the Flexible and Interoperable Data |
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.188.0Release |
9 | | -// Tag = production/release/21.188.0-0-g55050f8 |
| 8 | +// Profile Version = 21.194.0Release |
| 9 | +// Tag = production/release/21.194.0-0-g65135fc |
10 | 10 | ///////////////////////////////////////////////////////////////////////////////////////////// |
11 | 11 |
|
12 | 12 |
|
@@ -212,12 +212,25 @@ class Encoder { |
212 | 212 | throw new Error(); |
213 | 213 | } |
214 | 214 |
|
| 215 | + // Convert valid numeric strings to the correct type |
| 216 | + if (FIT.isString(value)) { |
| 217 | + value = FIT.BigIntFieldTypes.includes(fieldDefinition.type) |
| 218 | + ? BigInt(value) |
| 219 | + : Number(value); |
| 220 | + } |
| 221 | + |
215 | 222 | const hasScaleOrOffset = (fieldDefinition.scale != FIT.FIELD_DEFAULT_SCALE || fieldDefinition.offset != FIT.FIELD_DEFAULT_OFFSET); |
216 | 223 |
|
| 224 | + if (!hasScaleOrOffset && !this.#isValidType(value, fieldDefinition.type)) { |
| 225 | + throw new Error(); |
| 226 | + } |
| 227 | + |
217 | 228 | if (hasScaleOrOffset) { |
218 | | - const scaledValue = (value + fieldDefinition.offset) * fieldDefinition.scale; |
| 229 | + const scaledValue = this.#unapplyScaleAndOffset(value, fieldDefinition.scale, fieldDefinition.offset); |
| 230 | + |
| 231 | + const roundedValue = FIT.FloatingPointFieldTypes.includes(fieldDefinition.type) || FIT.isBigInt(scaledValue) ? scaledValue : Math.round(scaledValue); |
219 | 232 |
|
220 | | - return FIT.FloatingPointFieldTypes.includes(fieldDefinition.type) ? scaledValue : Math.round(scaledValue); |
| 233 | + return FIT.BigIntFieldTypes.includes(fieldDefinition.type) ? BigInt(roundedValue) : Number(roundedValue); |
221 | 234 | } |
222 | 235 |
|
223 | 236 | return value; |
@@ -265,6 +278,18 @@ class Encoder { |
265 | 278 | } |
266 | 279 | } |
267 | 280 |
|
| 281 | + #isValidType = (value, type) => { |
| 282 | + const jsType = FIT.FieldTypeToJsType[type]; |
| 283 | + |
| 284 | + return typeof value === jsType |
| 285 | + } |
| 286 | + |
| 287 | + #unapplyScaleAndOffset(value, scale, offset) { |
| 288 | + return FIT.isBigInt(value) |
| 289 | + ? (value + BigInt(offset)) * BigInt(scale) |
| 290 | + : (value + offset) * scale; |
| 291 | + } |
| 292 | + |
268 | 293 | /** |
269 | 294 | * Creates a MesgDefinition from the mesgNum and mesg. |
270 | 295 | * @param {Number} mesgNum - The mesg number for this message |
|
0 commit comments