Skip to content

Commit

Permalink
docs: update README.md and docs/usage.md (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
muktihari authored Apr 18, 2024
1 parent f652565 commit e84adbb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Please see [Usage](/docs/usage.md).

Version 2.0 introduced [**Developer Fields**](https://developer.garmin.com/fit/cookbook/developer-data) as a way to add custom data fields to existing messages. We strives to support **Developer Fields** and carefully thought about how to implement it since the inception of the SDK. While this may still need to be battle-tested to ensure correctness, this is generally work and usable.

Here is the sample of what **Developer Fields** would look like in a **.fit** that have been converted to **.csv** by `fitconv`. The **device_info** message has some **Developer Fields** defined in **field_description** (the ones that are being bold):
Here is the sample of what **Developer Fields** would look like in a **.fit** that have been converted to **.csv** by [fitconv](/cmd/fitconv/README.md). The **device_info** message has some **Developer Fields** defined in **field_description** (the ones that are being bold):

<table class="table table-bordered table-hover table-condensed">
<thead>
Expand Down Expand Up @@ -289,12 +289,14 @@ Here is the sample of what **Developer Fields** would look like in a **.fit** th

## CLIs

We provide some CLI programs to interact with FIT files that can be found in `cmd` folder.
We provide some CLI programs to interact with FIT files that can be found in [cmd](/cmd/doc.go) folder.

1. `fitactivity`: Combines multiple FIT activity files into one continuous FIT activity (and conceal the start and end GPS positions for privacy). [README.md](/cmd/fitactivity/README.md)
2. `fitconv`: Converts FIT files to CSV format, enabling us to read the FIT data in a human-readable format. Conversely, it also converts CSV files back to FIT format, enabling us to create or edit FIT files in CSV form. [README.md](/cmd/fitconv/README.md)
1. **fitactivity**: Combines multiple FIT activity files into one continuous FIT activity (and conceal the start and end GPS positions for privacy). [README.md](/cmd/fitactivity/README.md)
2. **fitconv**: Converts FIT files to CSV format, enabling us to read the FIT data in a human-readable format. Conversely, it also converts CSV files back to FIT format, enabling us to create or edit FIT files in CSV form. The programs is designed to work seamlessly with CSVs produced by the Official FIT SDK's _FitCSVTool.jar_. [README.md](/cmd/fitconv/README.md)
3. **fitprint**: Generates comprehensive human-readable **\*.txt** file containing details extracted from FIT files. [README.md](/cmd/fitprint/README.md)
4. **fitdump**: Dumps the FIT file(s) into segmented bytes in a **\*.txt** file format. [README.md](/cmd/fitdump/README.md)

The programs are automatically built during release; for Linux, Windows, and macOS platforms. They are available for download in [Release's Assets](https://github.com/muktihari/fit/releases).
Some programs are automatically built during release; for Linux, Windows, and macOS platforms. They are available for download in [Release's Assets](https://github.com/muktihari/fit/releases).

## Custom FIT SDK

Expand Down
35 changes: 35 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Table of Contents:
1. [Dicoding](./usage.md#Decoding)
- [Decode RAW Protocol Messages](#Decode-RAW-Protocol-Messages)
- [Decode to Common File Types](#Decode-to-Common-File-Types)
- [Peek FileHeader](#Peek-FileHeader)
- [Peek FileId](#Peek-FileId)
- [Discard FIT File Sequences](#Discard-FIT-File-Sequences)
- [Check Integrity](#Check-Integrity)
Expand Down Expand Up @@ -219,6 +220,40 @@ func main() {

**The ability to broadcast every message as it is decoded is one of biggest advantage of using this SDK, we can define custom listener to process the message as we like and in a streaming fashion, as long as it satisfies the [Listener](https://github.com/muktihari/fit/blob/master/decoder/listener.go) interface.**

### Peek FileHeader

We can verify whether the given file is a FIT file by checking the File Header (first 12-14 bytes). PeekFileHeader decodes only up to FileHeader (first 12-14 bytes) without decoding the whole reader. After this method is invoked, Decode picks up where this left then continue decoding next messages instead of starting from zero. This method is idempotent and can be invoked even after Decode has been invoked.

```go
package main

import (
"fmt"
"os"

"github.com/muktihari/fit/decoder"
)

func main() {
f, err := os.Open("Activity.fit")
if err != nil {
panic(err)
}
defer f.Close()
dec := decoder.New(f)

fileHeader, err := dec.PeekFileHeader()
if err != nil {
panic(err)
}

fmt.Printf("%v\n", fileHeader)

// Output:
// &{14 32 2147 94080 .FIT 17310}
}
```

### Peek FileId

We don't need to decode the entire FIT file to verify its type. Instead, we can use the 'PeekFileId' method to check the corresponding type. After invoking this method, we can decide whether to proceed with decoding the file or to stop. If we choose to continue, Decode picks up where this left then continue decoding next messages instead of starting from zero.
Expand Down

0 comments on commit e84adbb

Please sign in to comment.