rubyfit 0.0.11 → 0.0.16

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff3be546cfa7a5482170c47929f530546bcba7ca9ec8f4e2fa8ceb9eb0e4843b
4
- data.tar.gz: 350d14c83dec28be1e45618266fd27d13e4b8e56b32adbbf87948f97c7281e00
3
+ metadata.gz: d4887d7b80c68cf2b4dba3ed78f7495b2a085d3906415012d3a03743d71b2465
4
+ data.tar.gz: bd37458348a2f60fdd2a44f39725ac428c1e5e54c14e0c8d8a638655be2c95b1
5
5
  SHA512:
6
- metadata.gz: e0bef57964095765259e02836bf7f75bb317396e7b4e4bc38cf6f5139d39ff95dec36a199bfbedf49394d728f2655f27001c7704b383c3391ea06984fcf63e9d
7
- data.tar.gz: 35070d9d937a063720a6533d62ce5980d5c9209a926e0759585f0651af40961b46bf10ba5d6efa7471dfa8e3cc9ef88bb0e96e3989616398ca8da62c81eeccc9
6
+ metadata.gz: 405e5114d750281b9b51fa458a4bf5493864b6be8ed3b7a1670daa3329174690884d5610db689eb9fc45c0f0b9282b54700785c4588c2cb8e69e2ed81a684dbd
7
+ data.tar.gz: d2a31ad0cc0ac32ed7958e3ee81bd176f0918183426966bcd6af1ad54a8d03bcb644f319daea400d251d5cd147af55c7e32080911d30b6d19da6ae7a412ab79c
@@ -1,412 +1,418 @@
1
- ////////////////////////////////////////////////////////////////////////////////
2
- // The following FIT Protocol software provided may be used with FIT protocol
3
- // devices only and remains the copyrighted property of Dynastream Innovations Inc.
4
- // The software is being provided on an "as-is" basis and as an accommodation,
5
- // and therefore all warranties, representations, or guarantees of any kind
6
- // (whether express, implied or statutory) including, without limitation,
7
- // warranties of merchantability, non-infringement, or fitness for a particular
8
- // purpose, are specifically disclaimed.
9
- //
10
- // Copyright 2016 Dynastream Innovations Inc.
11
- ////////////////////////////////////////////////////////////////////////////////
12
- // ****WARNING**** This file is auto-generated! Do NOT edit this file.
13
- // Profile Version = 20.16Release
14
- // Tag = production/akw/20.16.00-0-gce20b51
15
- // Product = EXAMPLE
16
- // Alignment = 4 bytes, padding disabled.
17
- ////////////////////////////////////////////////////////////////////////////////
18
-
19
-
20
- #include "string.h"
21
- #include "fit_example.h"
22
-
23
-
24
- ///////////////////////////////////////////////////////////////////////
25
- // Public Constants
26
- ///////////////////////////////////////////////////////////////////////
27
-
28
- const FIT_UINT8 fit_base_type_sizes[FIT_BASE_TYPES] =
29
- {
30
- sizeof(FIT_ENUM),
31
- sizeof(FIT_SINT8),
32
- sizeof(FIT_UINT8),
33
- sizeof(FIT_SINT16),
34
- sizeof(FIT_UINT16),
35
- sizeof(FIT_SINT32),
36
- sizeof(FIT_UINT32),
37
- sizeof(FIT_STRING),
38
- sizeof(FIT_FLOAT32),
39
- sizeof(FIT_FLOAT64),
40
- sizeof(FIT_UINT8Z),
41
- sizeof(FIT_UINT16Z),
42
- sizeof(FIT_UINT32Z),
43
- sizeof(FIT_BYTE),
44
- sizeof(FIT_SINT64),
45
- sizeof(FIT_UINT64),
46
- sizeof(FIT_UINT64Z),
47
- };
48
-
49
-
50
- typedef union
51
- {
52
- FIT_UINT8 uint8_value[8];
53
- FIT_FLOAT64 float64_value;
54
- FIT_FLOAT32 float32_value;
55
- } FIT_INVALID_FLOAT;
56
-
57
- static const FIT_INVALID_FLOAT invalid_float =
58
- {
59
- {
60
- 0xFF,
61
- 0xFF,
62
- 0xFF,
63
- 0xFF,
64
- 0xFF,
65
- 0xFF,
66
- 0xFF,
67
- 0xFF
68
- }
69
- };
70
-
71
- const FIT_ENUM fit_enum_invalid = FIT_ENUM_INVALID;
72
- const FIT_SINT8 fit_sint8_invalid = FIT_SINT8_INVALID;
73
- const FIT_UINT8 fit_uint8_invalid = FIT_UINT8_INVALID;
74
- const FIT_SINT16 fit_sint16_invalid = FIT_SINT16_INVALID;
75
- const FIT_UINT16 fit_uint16_invalid = FIT_UINT16_INVALID;
76
- const FIT_SINT32 fit_sint32_invalid = FIT_SINT32_INVALID;
77
- const FIT_UINT32 fit_uint32_invalid = FIT_UINT32_INVALID;
78
- const FIT_STRING fit_string_invalid = FIT_STRING_INVALID;
79
- const FIT_UINT8Z fit_uint8z_invalid = FIT_UINT8Z_INVALID;
80
- const FIT_UINT16Z fit_uint16z_invalid = FIT_UINT16Z_INVALID;
81
- const FIT_UINT32Z fit_uint32z_invalid = FIT_UINT32Z_INVALID;
82
- const FIT_BYTE fit_byte_invalid = FIT_BYTE_INVALID;
83
- const FIT_SINT64 fit_sint64_invalid = FIT_SINT64_INVALID;
84
- const FIT_UINT64 fit_uint64_invalid = FIT_UINT64_INVALID;
85
- const FIT_UINT64Z fit_uint64z_invalid = FIT_UINT64Z_INVALID;
86
-
87
- const FIT_CONST_UINT8_PTR fit_base_type_invalids[FIT_BASE_TYPES] =
88
- {
89
- (FIT_CONST_UINT8_PTR)&fit_enum_invalid,
90
- (FIT_CONST_UINT8_PTR)&fit_sint8_invalid,
91
- (FIT_CONST_UINT8_PTR)&fit_uint8_invalid,
92
- (FIT_CONST_UINT8_PTR)&fit_sint16_invalid,
93
- (FIT_CONST_UINT8_PTR)&fit_uint16_invalid,
94
- (FIT_CONST_UINT8_PTR)&fit_sint32_invalid,
95
- (FIT_CONST_UINT8_PTR)&fit_uint32_invalid,
96
- (FIT_CONST_UINT8_PTR)&fit_string_invalid,
97
- (FIT_CONST_UINT8_PTR)&invalid_float.float32_value,
98
- (FIT_CONST_UINT8_PTR)&invalid_float.float64_value,
99
- (FIT_CONST_UINT8_PTR)&fit_uint8z_invalid,
100
- (FIT_CONST_UINT8_PTR)&fit_uint16z_invalid,
101
- (FIT_CONST_UINT8_PTR)&fit_uint32z_invalid,
102
- (FIT_CONST_UINT8_PTR)&fit_byte_invalid,
103
- (FIT_CONST_UINT8_PTR)&fit_sint64_invalid,
104
- (FIT_CONST_UINT8_PTR)&fit_uint64_invalid,
105
- (FIT_CONST_UINT8_PTR)&fit_uint64z_invalid,
106
- };
107
-
108
-
109
- ///////////////////////////////////////////////////////////////////////
110
- // Public Functions
111
- ///////////////////////////////////////////////////////////////////////
112
-
113
- FIT_UINT8 Fit_GetArch(void)
114
- {
115
- const FIT_UINT16 arch = 0x0100;
116
- return (*(FIT_UINT8 *)&arch);
117
- }
118
-
119
- const FIT_MESG_DEF *Fit_GetMesgDef(FIT_UINT16 global_mesg_num)
120
- {
121
- FIT_UINT8 index;
122
-
123
- for (index = 0; index < FIT_MESGS; index++)
124
- {
125
- if (fit_mesg_defs[index]->global_mesg_num == global_mesg_num)
126
- return (FIT_MESG_DEF *) fit_mesg_defs[index];
127
- }
128
-
129
- return (FIT_MESG_DEF *) FIT_NULL;
130
- }
131
-
132
- const FIT_MESG_DEF *Fit_GetMesgDefFromEnum(FIT_UINT32 fit_mesg_num)
133
- {
134
- //Verify enum in range
135
- if (FIT_MESGS > fit_mesg_num)
136
- {
137
- return fit_mesg_defs[fit_mesg_num];
138
- }
139
-
140
- return (FIT_MESG_DEF *)FIT_NULL;
141
- }
142
-
143
- FIT_UINT16 Fit_GetMesgDefSize(const FIT_MESG_DEF *mesg_def)
144
- {
145
- if (mesg_def == FIT_NULL)
146
- return 0;
147
-
148
- return FIT_STRUCT_OFFSET(fields, FIT_MESG_DEF) + (FIT_UINT16)mesg_def->num_fields * FIT_FIELD_DEF_SIZE;
149
- }
150
-
151
- FIT_UINT8 Fit_GetMesgSize(FIT_UINT16 global_mesg_num)
152
- {
153
- const FIT_MESG_DEF *mesg_def;
154
- FIT_UINT8 field;
155
- FIT_UINT8 size = 0;
156
-
157
- mesg_def = Fit_GetMesgDef(global_mesg_num);
158
-
159
- if (mesg_def == FIT_NULL)
160
- return 0;
161
-
162
- for (field = 0; field < mesg_def->num_fields; field++)
163
- {
164
- size += mesg_def->fields[FIT_MESG_DEF_FIELD_OFFSET(size, field)];
165
- }
166
-
167
- return size;
168
- }
169
-
170
- FIT_UINT8 Fit_GetMesgSizeFromEnum(FIT_UINT32 fit_mesg_num)
171
- {
172
- const FIT_MESG_DEF *mesg_def;
173
- FIT_UINT8 field;
174
- FIT_UINT8 size = 0;
175
-
176
- mesg_def = Fit_GetMesgDefFromEnum(fit_mesg_num);
177
-
178
- if (mesg_def == FIT_NULL)
179
- return 0;
180
-
181
- for (field = 0; field < mesg_def->num_fields; field++)
182
- {
183
- size += mesg_def->fields[FIT_MESG_DEF_FIELD_OFFSET(size, field)];
184
- }
185
-
186
- return size;
187
- }
188
-
189
- FIT_BOOL Fit_InitMesg(const FIT_MESG_DEF *mesg_def, void *mesg)
190
- {
191
- FIT_UINT8 *mesg_buf = (FIT_UINT8 *) mesg;
192
- FIT_UINT8 field;
193
-
194
- if (mesg_def == FIT_NULL)
195
- return FIT_FALSE;
196
-
197
- for (field = 0; field < mesg_def->num_fields; field++)
198
- {
199
- FIT_UINT8 base_type_num = mesg_def->fields[FIT_MESG_DEF_FIELD_OFFSET(base_type, field)] & FIT_BASE_TYPE_NUM_MASK;
200
- FIT_UINT8 base_type_size;
201
- FIT_UINT8 field_size;
202
-
203
- if (base_type_num >= FIT_BASE_TYPES)
204
- return FIT_FALSE;
205
-
206
- base_type_size = fit_base_type_sizes[base_type_num];
207
-
208
- for (field_size = 0; field_size < mesg_def->fields[FIT_MESG_DEF_FIELD_OFFSET(size, field)]; field_size += base_type_size)
209
- {
210
- memcpy(mesg_buf, fit_base_type_invalids[base_type_num], base_type_size);
211
- mesg_buf += base_type_size;
212
- }
213
- }
214
-
215
- return FIT_TRUE;
216
- }
217
-
218
- FIT_UINT8 Fit_GetFieldOffset(const FIT_MESG_DEF *mesg_def, FIT_UINT8 field_def_num)
219
- {
220
- FIT_UINT8 offset = 0;
221
- FIT_UINT8 field;
222
-
223
- if (mesg_def == FIT_NULL)
224
- return FIT_UINT8_INVALID;
225
-
226
- for (field = 0; field < mesg_def->num_fields; field++)
227
- {
228
- if (mesg_def->fields[FIT_MESG_DEF_FIELD_OFFSET(field_def_num, field)] == field_def_num)
229
- return offset;
230
-
231
- offset += mesg_def->fields[FIT_MESG_DEF_FIELD_OFFSET(size, field)];
232
- }
233
-
234
- return FIT_UINT8_INVALID;
235
- }
236
-
237
- FIT_FIELD_DEF Fit_GetFieldDef(const FIT_MESG_DEF *mesg_def, FIT_UINT8 field_def_num)
238
- {
239
- FIT_FIELD_DEF field_def;
240
- const FIT_UINT8 *field_def_ptr = mesg_def->fields;
241
- FIT_UINT8 field;
242
-
243
- field_def.field_def_num = FIT_FIELD_NUM_INVALID;
244
- field_def.size = 0;
245
- field_def.base_type = FIT_BASE_TYPE_UINT8;
246
-
247
- if (mesg_def != FIT_NULL)
248
- {
249
- for (field = 0; field < mesg_def->num_fields; field++)
250
- {
251
- if (mesg_def->fields[FIT_MESG_DEF_FIELD_OFFSET(field_def_num, field)] == field_def_num)
252
- {
253
- memcpy(&field_def, field_def_ptr, FIT_FIELD_DEF_SIZE);
254
- break;
255
- }
256
-
257
- field_def_ptr += FIT_FIELD_DEF_SIZE;
258
- }
259
- }
260
-
261
- return field_def;
262
- }
263
-
264
- FIT_UINT8 Fit_LookupMessage(FIT_UINT16 global_mesg_num, FIT_UINT16 message_index, FIT_UINT32 *offset, FIT_READ_BYTES_FUNC read_bytes_func, FIT_BOOL read_header)
265
- {
266
- FIT_UINT16 global_mesg_nums[FIT_MAX_LOCAL_MESGS];
267
- FIT_UINT8 sizes[FIT_MAX_LOCAL_MESGS];
268
- FIT_UINT16 current_message_index = FIT_UINT16_INVALID;
269
- #if defined(FIT_MESSAGE_INDEX)
270
- FIT_UINT16 message_index_offset = FIT_UINT16_INVALID;
271
- #endif
272
- FIT_UINT8 i;
273
-
274
- *offset = 0;
275
-
276
- if (read_header)
277
- {
278
- if(read_bytes_func(offset, FIT_STRUCT_OFFSET(header_size, FIT_FILE_HDR), sizeof(FIT_UINT8)) != sizeof(FIT_UINT8))
279
- return FIT_UINT8_INVALID;
280
- }
281
-
282
- for (i = 0; i < FIT_MAX_LOCAL_MESGS; i++)
283
- {
284
- global_mesg_nums[i] = FIT_UINT16_INVALID;
285
- sizes[i] = 0;
286
- }
287
-
288
- for (;;)
289
- {
290
- FIT_UINT8 header;
291
- FIT_UINT8 local_mesg_num;
292
-
293
- if (read_bytes_func(&header, *offset, sizeof(header)) != sizeof(header))
294
- return FIT_UINT8_INVALID;
295
-
296
- *offset += sizeof(header);
297
-
298
- if ((header & (FIT_HDR_TIME_REC_BIT | FIT_HDR_TYPE_DEF_BIT)) == FIT_HDR_TYPE_DEF_BIT)
299
- {
300
- FIT_MESG_DEF mesg_def_header;
301
- FIT_FIELD_DEF field_def;
302
- #if defined(FIT_MESSAGE_INDEX)
303
- FIT_UINT16 current_message_index_offset = FIT_UINT16_INVALID; // Initialize to invalid. If not found, it will remain invalid.
304
- #endif
305
- FIT_UINT8 current_size;
306
- FIT_UINT8 current_field_def;
307
-
308
- local_mesg_num = header & FIT_HDR_TYPE_MASK;
309
-
310
- if (read_bytes_func(&mesg_def_header, *offset, FIT_MESG_DEF_HEADER_SIZE) != FIT_MESG_DEF_HEADER_SIZE)
311
- return FIT_UINT8_INVALID;
312
-
313
- *offset += FIT_MESG_DEF_HEADER_SIZE;
314
- global_mesg_nums[local_mesg_num] = mesg_def_header.global_mesg_num;
315
- current_size = 0;
316
-
317
- for (current_field_def = 0; current_field_def < mesg_def_header.num_fields; current_field_def++)
318
- {
319
- if (read_bytes_func(&field_def, *offset, FIT_FIELD_DEF_SIZE) != FIT_FIELD_DEF_SIZE)
320
- return FIT_UINT8_INVALID;
321
-
322
- #if defined(FIT_MESSAGE_INDEX)
323
- if (field_def.field_def_num == FIT_FIELD_NUM_MESSAGE_INDEX)
324
- current_message_index_offset = current_size;
325
- #endif
326
-
327
- current_size += field_def.size;
328
- *offset += FIT_FIELD_DEF_SIZE;
329
- }
330
-
331
- sizes[local_mesg_num] = current_size;
332
-
333
- #if defined(FIT_MESSAGE_INDEX)
334
- if (global_mesg_nums[local_mesg_num] == global_mesg_num)
335
- message_index_offset = current_message_index_offset;
336
- #endif
337
- }
338
- else
339
- {
340
- if (header & FIT_HDR_TIME_REC_BIT)
341
- local_mesg_num = (header & FIT_HDR_TIME_TYPE_MASK) >> FIT_HDR_TIME_TYPE_SHIFT;
342
- else
343
- local_mesg_num = header & FIT_HDR_TYPE_MASK;
344
-
345
- if (global_mesg_nums[local_mesg_num] == global_mesg_num)
346
- {
347
- // If the requested message index is invalid, we've found a match.
348
- if (message_index == FIT_UINT16_INVALID)
349
- return local_mesg_num;
350
-
351
- #if defined(FIT_MESSAGE_INDEX)
352
- if (message_index_offset != FIT_UINT16_INVALID)
353
- {
354
- // Read the message index.
355
- if (read_bytes_func(&current_message_index, *offset + message_index_offset, sizeof(current_message_index)) != sizeof(current_message_index))
356
- return FIT_UINT8_INVALID;
357
- }
358
- else
359
- #endif
360
- {
361
- current_message_index++;
362
- }
363
-
364
- #if defined(FIT_MESSAGE_INDEX)
365
- if ((message_index & FIT_MESSAGE_INDEX_MASK) == (current_message_index & FIT_MESSAGE_INDEX_MASK))
366
- #else
367
- if (message_index == current_message_index)
368
- #endif
369
- {
370
- return local_mesg_num;
371
- }
372
- }
373
- else if (global_mesg_nums[local_mesg_num] == FIT_UINT16_INVALID)
374
- {
375
- return FIT_UINT8_INVALID;
376
- }
377
-
378
- *offset += sizes[local_mesg_num];
379
- }
380
- }
381
- }
382
-
383
- FIT_UINT32 Fit_GetFileMesgOffset(const FIT_FILE_DEF *file_def, FIT_UINT16 mesg_num, FIT_UINT16 mesg_index)
384
- {
385
- FIT_UINT32 offset = 0;
386
- FIT_UINT16 i = 0;
387
-
388
- while (i < file_def->mesg_count)
389
- {
390
- if (mesg_num == file_def->mesgs[i].num)
391
- {
392
- offset = file_def->mesgs[i].data_file_offset;
393
- break;
394
- }
395
-
396
- i++;
397
- }
398
-
399
- if (i >= file_def->mesg_count)
400
- return FIT_UINT32_INVALID;
401
-
402
- // Make sure mesg_index is valid for this mesg num and file definition
403
- if (mesg_index >= file_def->mesgs[i].count)
404
- return FIT_UINT32_INVALID;
405
-
406
- // Compute size of each message (header byte + data)
407
- i = FIT_HDR_SIZE + Fit_GetMesgSize(mesg_num);
408
-
409
- offset += mesg_index * i;
410
-
411
- return offset;
412
- }
1
+ ////////////////////////////////////////////////////////////////////////////////
2
+ // The following FIT Protocol software provided may be used with FIT protocol
3
+ // devices only and remains the copyrighted property of Garmin Canada Inc.
4
+ // The software is being provided on an "as-is" basis and as an accommodation,
5
+ // and therefore all warranties, representations, or guarantees of any kind
6
+ // (whether express, implied or statutory) including, without limitation,
7
+ // warranties of merchantability, non-infringement, or fitness for a particular
8
+ // purpose, are specifically disclaimed.
9
+ //
10
+ // Copyright 2020 Garmin Canada Inc.
11
+ ////////////////////////////////////////////////////////////////////////////////
12
+ // ****WARNING**** This file is auto-generated! Do NOT edit this file.
13
+ // Profile Version = 21.27Release
14
+ // Tag = production/akw/21.27.00-0-gef9575d
15
+ // Product = EXAMPLE
16
+ // Alignment = 4 bytes, padding disabled.
17
+ ////////////////////////////////////////////////////////////////////////////////
18
+
19
+
20
+ #include "string.h"
21
+ #include "fit_example.h"
22
+
23
+
24
+ ///////////////////////////////////////////////////////////////////////
25
+ // Public Constants
26
+ ///////////////////////////////////////////////////////////////////////
27
+
28
+ const FIT_UINT8 fit_base_type_sizes[FIT_BASE_TYPES] =
29
+ {
30
+ sizeof(FIT_ENUM),
31
+ sizeof(FIT_SINT8),
32
+ sizeof(FIT_UINT8),
33
+ sizeof(FIT_SINT16),
34
+ sizeof(FIT_UINT16),
35
+ sizeof(FIT_SINT32),
36
+ sizeof(FIT_UINT32),
37
+ sizeof(FIT_STRING),
38
+ sizeof(FIT_FLOAT32),
39
+ sizeof(FIT_FLOAT64),
40
+ sizeof(FIT_UINT8Z),
41
+ sizeof(FIT_UINT16Z),
42
+ sizeof(FIT_UINT32Z),
43
+ sizeof(FIT_BYTE),
44
+ sizeof(FIT_SINT64),
45
+ sizeof(FIT_UINT64),
46
+ sizeof(FIT_UINT64Z),
47
+ };
48
+
49
+
50
+ typedef union
51
+ {
52
+ FIT_UINT8 uint8_value[8];
53
+ FIT_FLOAT64 float64_value;
54
+ FIT_FLOAT32 float32_value;
55
+ } FIT_INVALID_FLOAT;
56
+
57
+ static const FIT_INVALID_FLOAT invalid_float =
58
+ {
59
+ {
60
+ 0xFF,
61
+ 0xFF,
62
+ 0xFF,
63
+ 0xFF,
64
+ 0xFF,
65
+ 0xFF,
66
+ 0xFF,
67
+ 0xFF
68
+ }
69
+ };
70
+
71
+ const FIT_ENUM fit_enum_invalid = FIT_ENUM_INVALID;
72
+ const FIT_SINT8 fit_sint8_invalid = FIT_SINT8_INVALID;
73
+ const FIT_UINT8 fit_uint8_invalid = FIT_UINT8_INVALID;
74
+ const FIT_SINT16 fit_sint16_invalid = FIT_SINT16_INVALID;
75
+ const FIT_UINT16 fit_uint16_invalid = FIT_UINT16_INVALID;
76
+ const FIT_SINT32 fit_sint32_invalid = FIT_SINT32_INVALID;
77
+ const FIT_UINT32 fit_uint32_invalid = FIT_UINT32_INVALID;
78
+ const FIT_STRING fit_string_invalid = FIT_STRING_INVALID;
79
+ const FIT_UINT8Z fit_uint8z_invalid = FIT_UINT8Z_INVALID;
80
+ const FIT_UINT16Z fit_uint16z_invalid = FIT_UINT16Z_INVALID;
81
+ const FIT_UINT32Z fit_uint32z_invalid = FIT_UINT32Z_INVALID;
82
+ const FIT_BYTE fit_byte_invalid = FIT_BYTE_INVALID;
83
+ const FIT_SINT64 fit_sint64_invalid = FIT_SINT64_INVALID;
84
+ const FIT_UINT64 fit_uint64_invalid = FIT_UINT64_INVALID;
85
+ const FIT_UINT64Z fit_uint64z_invalid = FIT_UINT64Z_INVALID;
86
+
87
+ const FIT_CONST_UINT8_PTR fit_base_type_invalids[FIT_BASE_TYPES] =
88
+ {
89
+ (FIT_CONST_UINT8_PTR)&fit_enum_invalid,
90
+ (FIT_CONST_UINT8_PTR)&fit_sint8_invalid,
91
+ (FIT_CONST_UINT8_PTR)&fit_uint8_invalid,
92
+ (FIT_CONST_UINT8_PTR)&fit_sint16_invalid,
93
+ (FIT_CONST_UINT8_PTR)&fit_uint16_invalid,
94
+ (FIT_CONST_UINT8_PTR)&fit_sint32_invalid,
95
+ (FIT_CONST_UINT8_PTR)&fit_uint32_invalid,
96
+ (FIT_CONST_UINT8_PTR)&fit_string_invalid,
97
+ (FIT_CONST_UINT8_PTR)&invalid_float.float32_value,
98
+ (FIT_CONST_UINT8_PTR)&invalid_float.float64_value,
99
+ (FIT_CONST_UINT8_PTR)&fit_uint8z_invalid,
100
+ (FIT_CONST_UINT8_PTR)&fit_uint16z_invalid,
101
+ (FIT_CONST_UINT8_PTR)&fit_uint32z_invalid,
102
+ (FIT_CONST_UINT8_PTR)&fit_byte_invalid,
103
+ (FIT_CONST_UINT8_PTR)&fit_sint64_invalid,
104
+ (FIT_CONST_UINT8_PTR)&fit_uint64_invalid,
105
+ (FIT_CONST_UINT8_PTR)&fit_uint64z_invalid,
106
+ };
107
+
108
+
109
+ ///////////////////////////////////////////////////////////////////////
110
+ // Public Functions
111
+ ///////////////////////////////////////////////////////////////////////
112
+
113
+ FIT_UINT8 Fit_GetArch(void)
114
+ {
115
+ const FIT_UINT16 arch = 0x0100;
116
+ return (*(FIT_UINT8 *)&arch);
117
+ }
118
+
119
+ const FIT_MESG_DEF *Fit_GetMesgDef(FIT_UINT16 global_mesg_num)
120
+ {
121
+ FIT_UINT8 index;
122
+
123
+ for (index = 0; index < FIT_MESGS; index++)
124
+ {
125
+ if (fit_mesg_defs[index]->global_mesg_num == global_mesg_num)
126
+ return (FIT_MESG_DEF *) fit_mesg_defs[index];
127
+ }
128
+
129
+ return (FIT_MESG_DEF *) FIT_NULL;
130
+ }
131
+
132
+ const FIT_MESG_DEF *Fit_GetMesgDefFromEnum(FIT_UINT32 fit_mesg_num)
133
+ {
134
+ //Verify enum in range
135
+ if (FIT_MESGS > fit_mesg_num)
136
+ {
137
+ return fit_mesg_defs[fit_mesg_num];
138
+ }
139
+
140
+ return (FIT_MESG_DEF *)FIT_NULL;
141
+ }
142
+
143
+ FIT_UINT16 Fit_GetMesgDefSize(const FIT_MESG_DEF *mesg_def)
144
+ {
145
+ if (mesg_def == FIT_NULL)
146
+ return 0;
147
+
148
+ return FIT_STRUCT_OFFSET(fields, FIT_MESG_DEF) + (FIT_UINT16)mesg_def->num_fields * FIT_FIELD_DEF_SIZE;
149
+ }
150
+
151
+ #if defined(FIT_16BIT_MESG_LENGTH_SUPPORT)
152
+ FIT_UINT16 Fit_GetMesgSize(FIT_UINT16 global_mesg_num)
153
+ {
154
+ const FIT_MESG_DEF *mesg_def;
155
+ FIT_UINT8 field;
156
+ FIT_UINT16 size = 0;
157
+
158
+ mesg_def = Fit_GetMesgDef(global_mesg_num);
159
+
160
+ if (mesg_def == FIT_NULL)
161
+ return 0;
162
+
163
+ for (field = 0; field < mesg_def->num_fields; field++)
164
+ {
165
+ size += mesg_def->fields[FIT_MESG_DEF_FIELD_OFFSET(size, field)];
166
+ }
167
+
168
+ return size;
169
+ }
170
+ #endif // defined(FIT_16BIT_MESG_LENGTH_SUPPORT)
171
+
172
+ #if defined(FIT_16BIT_MESG_LENGTH_SUPPORT)
173
+ FIT_UINT16 Fit_GetMesgSizeFromEnum(FIT_UINT32 fit_mesg_num)
174
+ {
175
+ const FIT_MESG_DEF *mesg_def;
176
+ FIT_UINT8 field;
177
+ FIT_UINT16 size = 0;
178
+
179
+ mesg_def = Fit_GetMesgDefFromEnum(fit_mesg_num);
180
+
181
+ if (mesg_def == FIT_NULL)
182
+ return 0;
183
+
184
+ for (field = 0; field < mesg_def->num_fields; field++)
185
+ {
186
+ size += mesg_def->fields[FIT_MESG_DEF_FIELD_OFFSET(size, field)];
187
+ }
188
+
189
+ return size;
190
+ }
191
+ #endif // defined(FIT_16BIT_MESG_LENGTH_SUPPORT)
192
+
193
+ FIT_BOOL Fit_InitMesg(const FIT_MESG_DEF *mesg_def, void *mesg)
194
+ {
195
+ FIT_UINT8 *mesg_buf = (FIT_UINT8 *) mesg;
196
+ FIT_UINT8 field;
197
+
198
+ if (mesg_def == FIT_NULL)
199
+ return FIT_FALSE;
200
+
201
+ for (field = 0; field < mesg_def->num_fields; field++)
202
+ {
203
+ FIT_UINT8 base_type_num = mesg_def->fields[FIT_MESG_DEF_FIELD_OFFSET(base_type, field)] & FIT_BASE_TYPE_NUM_MASK;
204
+ FIT_UINT8 base_type_size;
205
+ FIT_UINT8 field_size;
206
+
207
+ if (base_type_num >= FIT_BASE_TYPES)
208
+ return FIT_FALSE;
209
+
210
+ base_type_size = fit_base_type_sizes[base_type_num];
211
+
212
+ for (field_size = 0; field_size < mesg_def->fields[FIT_MESG_DEF_FIELD_OFFSET(size, field)]; field_size += base_type_size)
213
+ {
214
+ memcpy(mesg_buf, fit_base_type_invalids[base_type_num], base_type_size);
215
+ mesg_buf += base_type_size;
216
+ }
217
+ }
218
+
219
+ return FIT_TRUE;
220
+ }
221
+
222
+ #if defined(FIT_16BIT_MESG_LENGTH_SUPPORT)
223
+ FIT_UINT16 Fit_GetFieldOffset(const FIT_MESG_DEF *mesg_def, FIT_UINT8 field_def_num)
224
+ {
225
+ FIT_UINT16 offset = 0;
226
+ FIT_UINT8 field;
227
+
228
+ if (mesg_def == FIT_NULL)
229
+ return FIT_UINT16_INVALID;
230
+
231
+ for (field = 0; field < mesg_def->num_fields; field++)
232
+ {
233
+ if (mesg_def->fields[FIT_MESG_DEF_FIELD_OFFSET(field_def_num, field)] == field_def_num)
234
+ return offset;
235
+
236
+ offset += mesg_def->fields[FIT_MESG_DEF_FIELD_OFFSET(size, field)];
237
+ }
238
+
239
+ return FIT_UINT16_INVALID;
240
+ }
241
+ #endif // defined(FIT_16BIT_MESG_LENGTH_SUPPORT)
242
+
243
+ FIT_FIELD_DEF Fit_GetFieldDef(const FIT_MESG_DEF *mesg_def, FIT_UINT8 field_def_num)
244
+ {
245
+ FIT_FIELD_DEF field_def;
246
+ const FIT_UINT8 *field_def_ptr = mesg_def->fields;
247
+ FIT_UINT8 field;
248
+
249
+ field_def.field_def_num = FIT_FIELD_NUM_INVALID;
250
+ field_def.size = 0;
251
+ field_def.base_type = FIT_BASE_TYPE_UINT8;
252
+
253
+ if (mesg_def != FIT_NULL)
254
+ {
255
+ for (field = 0; field < mesg_def->num_fields; field++)
256
+ {
257
+ if (mesg_def->fields[FIT_MESG_DEF_FIELD_OFFSET(field_def_num, field)] == field_def_num)
258
+ {
259
+ memcpy(&field_def, field_def_ptr, FIT_FIELD_DEF_SIZE);
260
+ break;
261
+ }
262
+
263
+ field_def_ptr += FIT_FIELD_DEF_SIZE;
264
+ }
265
+ }
266
+
267
+ return field_def;
268
+ }
269
+
270
+ FIT_UINT8 Fit_LookupMessage(FIT_UINT16 global_mesg_num, FIT_UINT16 message_index, FIT_UINT32 *offset, FIT_READ_BYTES_FUNC read_bytes_func, FIT_BOOL read_header)
271
+ {
272
+ FIT_UINT16 global_mesg_nums[FIT_MAX_LOCAL_MESGS];
273
+ FIT_UINT16 sizes[FIT_MAX_LOCAL_MESGS];
274
+ FIT_UINT16 current_message_index = FIT_UINT16_INVALID;
275
+ #if defined(FIT_MESSAGE_INDEX)
276
+ FIT_UINT16 message_index_offset = FIT_UINT16_INVALID;
277
+ #endif
278
+ FIT_UINT8 i;
279
+
280
+ *offset = 0;
281
+
282
+ if (read_header)
283
+ {
284
+ if(read_bytes_func(offset, FIT_STRUCT_OFFSET(header_size, FIT_FILE_HDR), sizeof(FIT_UINT8)) != sizeof(FIT_UINT8))
285
+ return FIT_UINT8_INVALID;
286
+ }
287
+
288
+ for (i = 0; i < FIT_MAX_LOCAL_MESGS; i++)
289
+ {
290
+ global_mesg_nums[i] = FIT_UINT16_INVALID;
291
+ sizes[i] = 0;
292
+ }
293
+
294
+ for (;;)
295
+ {
296
+ FIT_UINT8 header;
297
+ FIT_UINT8 local_mesg_num;
298
+
299
+ if (read_bytes_func(&header, *offset, sizeof(header)) != sizeof(header))
300
+ return FIT_UINT8_INVALID;
301
+
302
+ *offset += sizeof(header);
303
+
304
+ if ((header & (FIT_HDR_TIME_REC_BIT | FIT_HDR_TYPE_DEF_BIT)) == FIT_HDR_TYPE_DEF_BIT)
305
+ {
306
+ FIT_MESG_DEF mesg_def_header;
307
+ FIT_FIELD_DEF field_def;
308
+ #if defined(FIT_MESSAGE_INDEX)
309
+ FIT_UINT16 current_message_index_offset = FIT_UINT16_INVALID; // Initialize to invalid. If not found, it will remain invalid.
310
+ #endif
311
+ FIT_UINT16 current_size;
312
+ FIT_UINT8 current_field_def;
313
+
314
+ local_mesg_num = header & FIT_HDR_TYPE_MASK;
315
+
316
+ if (read_bytes_func(&mesg_def_header, *offset, FIT_MESG_DEF_HEADER_SIZE) != FIT_MESG_DEF_HEADER_SIZE)
317
+ return FIT_UINT8_INVALID;
318
+
319
+ *offset += FIT_MESG_DEF_HEADER_SIZE;
320
+ global_mesg_nums[local_mesg_num] = mesg_def_header.global_mesg_num;
321
+ current_size = 0;
322
+
323
+ for (current_field_def = 0; current_field_def < mesg_def_header.num_fields; current_field_def++)
324
+ {
325
+ if (read_bytes_func(&field_def, *offset, FIT_FIELD_DEF_SIZE) != FIT_FIELD_DEF_SIZE)
326
+ return FIT_UINT8_INVALID;
327
+
328
+ #if defined(FIT_MESSAGE_INDEX)
329
+ if (field_def.field_def_num == FIT_FIELD_NUM_MESSAGE_INDEX)
330
+ current_message_index_offset = current_size;
331
+ #endif
332
+
333
+ current_size += field_def.size;
334
+ *offset += FIT_FIELD_DEF_SIZE;
335
+ }
336
+
337
+ sizes[local_mesg_num] = current_size;
338
+
339
+ #if defined(FIT_MESSAGE_INDEX)
340
+ if (global_mesg_nums[local_mesg_num] == global_mesg_num)
341
+ message_index_offset = current_message_index_offset;
342
+ #endif
343
+ }
344
+ else
345
+ {
346
+ if (header & FIT_HDR_TIME_REC_BIT)
347
+ local_mesg_num = (header & FIT_HDR_TIME_TYPE_MASK) >> FIT_HDR_TIME_TYPE_SHIFT;
348
+ else
349
+ local_mesg_num = header & FIT_HDR_TYPE_MASK;
350
+
351
+ if (global_mesg_nums[local_mesg_num] == global_mesg_num)
352
+ {
353
+ // If the requested message index is invalid, we've found a match.
354
+ if (message_index == FIT_UINT16_INVALID)
355
+ return local_mesg_num;
356
+
357
+ #if defined(FIT_MESSAGE_INDEX)
358
+ if (message_index_offset != FIT_UINT16_INVALID)
359
+ {
360
+ // Read the message index.
361
+ if (read_bytes_func(&current_message_index, *offset + message_index_offset, sizeof(current_message_index)) != sizeof(current_message_index))
362
+ return FIT_UINT8_INVALID;
363
+ }
364
+ else
365
+ #endif
366
+ {
367
+ current_message_index++;
368
+ }
369
+
370
+ #if defined(FIT_MESSAGE_INDEX)
371
+ if ((message_index & FIT_MESSAGE_INDEX_MASK) == (current_message_index & FIT_MESSAGE_INDEX_MASK))
372
+ #else
373
+ if (message_index == current_message_index)
374
+ #endif
375
+ {
376
+ return local_mesg_num;
377
+ }
378
+ }
379
+ else if (global_mesg_nums[local_mesg_num] == FIT_UINT16_INVALID)
380
+ {
381
+ return FIT_UINT8_INVALID;
382
+ }
383
+
384
+ *offset += sizes[local_mesg_num];
385
+ }
386
+ }
387
+ }
388
+
389
+ FIT_UINT32 Fit_GetFileMesgOffset(const FIT_FILE_DEF *file_def, FIT_UINT16 mesg_num, FIT_UINT16 mesg_index)
390
+ {
391
+ FIT_UINT32 offset = 0;
392
+ FIT_UINT16 i = 0;
393
+
394
+ while (i < file_def->mesg_count)
395
+ {
396
+ if (mesg_num == file_def->mesgs[i].num)
397
+ {
398
+ offset = file_def->mesgs[i].data_file_offset;
399
+ break;
400
+ }
401
+
402
+ i++;
403
+ }
404
+
405
+ if (i >= file_def->mesg_count)
406
+ return FIT_UINT32_INVALID;
407
+
408
+ // Make sure mesg_index is valid for this mesg num and file definition
409
+ if (mesg_index >= file_def->mesgs[i].count)
410
+ return FIT_UINT32_INVALID;
411
+
412
+ // Compute size of each message (header byte + data)
413
+ i = FIT_HDR_SIZE + Fit_GetMesgSize(mesg_num);
414
+
415
+ offset += mesg_index * i;
416
+
417
+ return offset;
418
+ }