Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
roznet authored Dec 23, 2020
1 parent 4e0f975 commit 210e36d
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,29 @@ It's fairly straight forward to use from an xcode project, following the standar

A fit file is loaded using `let fitfile = FitFile(file: URL)` or `let fitfile = FitFile(data : Data)`

The type FitMessageType represent the messages type (mesg_num in the sdk). You can access all the known messages with syntax like `FitMessageType.record`, `FitMessageType.session`, `FitMessageType.sport`, ...

You can then use access function like `fitfile.messages(forMessageType: FitMessageType.session)` to get objects of type `FitMessage`

The type `FitMessageType` represent the messages type (mesg_num in the sdk). You can access all the known messages with syntax like `FitMessageType.record`, `FitMessageType.session`, `FitMessageType.sport`, ...

The function `message.interpretedFields()` provide access to the fields for the message as a dictionary of keys to `FitFieldValue` which can be either a date, a string, a double value, a double value with unit or a gps coordinate.

Here is a full example:

```swift
var gps : [CLLocationCoordinate2D] = []
var hr : [Double] = []
var ts : [Date] = []
for message in fit_fast.messages(forMessageType: FitMessageType.record) {
if let one_gps = message.interpretedField(key: "position")?.coordinate,
let one_hr = message.interpretedField(key: "heart_rate")?.valueUnit?.value,
let one_ts = message.interpretedField(key: "timestamp")?.time {
gps.append( one_gps )
ts.append( one_ts)
hr.append( one_hr )
}
}
```

## Approach

This code builds upon the example c code from the official SDK and integrate it into swift to generate a native object with an array of messages made of native swift dictionaries. It also adds support for developer fields.
Expand All @@ -39,6 +56,8 @@ There are two available approaches to parsing, determined by the `parsingType` a
- `.fast` this method will only parse the fields defined as an example in the `Profile.xlsx` and therefore in `fit_example.h` from the sdk. This approach is the fastest as it relies on pre-defined static parsing of the fields.
- `.generic` this method will blindly convert all the messages found in the files, interpreting as much as possible from the information in `Profile.xlsx` as possible, but also building information from unkonwn messages and types. This approach is a bit slower as tries to interpret each fields dynamically.

All the required code is auto generated by running a python script `fitgenparser.py` that takes as input the `Profile.xlsx` from the sdk.

## Update for a new SDK

When a new SDK is available, after download, use the `diffsdk.py` utility that will generate the diffs for [ksdiff](https://kaleidoscope.app) to merge the new code
Expand Down

0 comments on commit 210e36d

Please sign in to comment.