You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+75-5Lines changed: 75 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,7 @@ A file must pass all three of these tests to be considered a valid FIT file. See
58
58
#### Read Method
59
59
The Read method decodes all messages from the input stream and returns an object containing a list of errors encountered during the decoding and a dictionary of decoded messages grouped by message type. Any exceptions encountered during decoding will be caught by the Read method and added to the list of errors.
60
60
61
-
The Read method accepts an optional options object that can be used to customize how field data is represented in the decoded messages. All options are enabled by default. Disabling options may speed up file decoding. Options may also be enabled or disable based on how the decoded data will be used.
61
+
The Read method accepts an optional options object that can be used to customize how field data is represented in the decoded messages. All options are enabled by default. Disabling options may speed up file decoding. Options may also be enabled or disabled based on how the decoded data will be used.
62
62
63
63
```py
64
64
messages, errors = read(
@@ -72,7 +72,7 @@ messages, errors = read(
72
72
mesg_listener=None)
73
73
```
74
74
#### mesg_listener
75
-
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.
75
+
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 will be returned from the Read method in the messages dictionary.
76
76
77
77
Example mesg_listener callback that tracks the field names across all Record messages.
78
78
@@ -107,7 +107,7 @@ When true the scale and offset values as defined in the FIT Profile are applied
107
107
When false the raw field value is used.
108
108
```py
109
109
{
110
-
'altitude': 10435## raw value store in file
110
+
'altitude': 10435## raw value stored in file
111
111
}
112
112
```
113
113
#### enable_crc_check: true | false
@@ -164,7 +164,7 @@ When true FIT Epoch values are converted to Python datetime objects.
164
164
```py
165
165
{ 'time_created': {Python datetime object} }
166
166
```
167
-
When false the FIT Epoch value is used.
167
+
When false the FIT Epoch value is used.
168
168
```py
169
169
{ 'time_created': 995749880 }
170
170
```
@@ -210,8 +210,78 @@ The FIT_EPOCH_S value can be used to convert FIT Epoch values to Python datetime
# e.g. BASE_TYPE_TO_FIELD_TYPE[BASE_TYPE['UINT32']] == 'uint32'
218
+
```
219
+
### FIELD_TYPE_TO_BASE_TYPE Constant
220
+
`FIELD_TYPE_TO_BASE_TYPE` is the inverse mapping of `BASE_TYPE_TO_FIELD_TYPE`. It maps FIT field type name strings to their corresponding base type values as defined in the FIT Profile.
# Pass the MesgNum and message data as separate parameters to the onMesg() method
246
+
encoder.on_mesg(Profile['mesg_num']['FILE_ID'], {
247
+
'manufacturer': 'development',
248
+
'product': 1,
249
+
'time_created': datetime.now(tz=timezone.utc),
250
+
'type': 'activity',
251
+
})
252
+
253
+
# The writeMesg() method expects the mesgNum to be included in the message data
254
+
# Internally, writeMesg() calls onMesg()
255
+
encoder.write_mesg({
256
+
'mesg_num': Profile['mesg_num']['FILE_ID'],
257
+
'manufacturer': 'development',
258
+
'product': 1,
259
+
'time_created': datetime.now(tz=timezone.utc),
260
+
'type': 'activity',
261
+
})
262
+
263
+
# Unknown values in the message will be ignored by the Encoder
264
+
encoder.on_mesg(Profile['mesg_num']['FILE_ID'], {
265
+
'manufacturer': 'development',
266
+
'product': 1,
267
+
'time_created': datetime.now(tz=timezone.utc),
268
+
'type': 'activity',
269
+
'customField': 12345, # This value will be ignored by the Encoder
270
+
})
271
+
272
+
# Subfield values in the message will be ignored by the Encoder
273
+
encoder.on_mesg(Profile['mesg_num']['FILE_ID'], {
274
+
'manufacturer': 'development',
275
+
'product': 4440, # This is the main product field, which is a uint16
276
+
'garmin_product': 'edge_1050', # This value will be ignored by the Encoder, use the main field value instead
277
+
'time_created': datetime.now(tz=timezone.utc),
278
+
'type': 'activity',
279
+
})
280
+
281
+
uint8_array = encoder.close()
282
+
283
+
# Write the bytes to a file
284
+
withopen('example.fit', 'wb') as f:
285
+
f.write(uint8_array)
286
+
```
287
+
See the [Encode Activity Recipe](https://github.com/garmin/fit-python-sdk/blob/main/tests/test_encode_activity_recipe.py) for a complete example of encoding a FIT Activity file using the FIT Python SDK.
0 commit comments