View Source ExtFit.Decode (ExtFit v0.1.0)

Decodes FIT file into a list of records. If binary data has multiple FIT files stiched together it will process them all.

See decode/2 for details.

Summary

Functions

See decode/2 for details

Decodes FIT binary data.

See decode/2 for details. decode! raises an error in case decoding fails.

Functions

@spec decode(binary()) ::
  {:ok, [ExtFit.Record.t()]}
  | {:error, String.t(), [ExtFit.Record.t()], binary()}

See decode/2 for details

@spec decode(
  binary(),
  keyword()
) ::
  {:ok, [ExtFit.Record.t()]}
  | {:error, String.t(), [ExtFit.Record.t()], binary()}

Decodes FIT binary data.

Each record is one of the following types:

Decode accepts the following options:

Examples

iex> alias ExtFit.Record.{FitHeader, FitDefinition, FitData}
iex> alias ExtFit.Types.{FieldData, Field}
iex> {:ok, records} = ExtFit.Decode.decode(File.read!("test/support/files/2023-06-04-garmin-955-running.fit"))
iex> # Every FIT file starts with a FitHeader
iex> %FitHeader{body_size: 409401} = hd(records)
iex> # Then is followed by FileId definition and data
iex> %FitData{
...>   def_mesg: %FitDefinition{mesg_type: %ExtFit.Profile.Messages.FileId{}},
...>   fields: [
...>     %FieldData{field: %Field{name: :serial_number}, value: 3442024736}
...>     | _rest_of_fields
...>   ]
...> } = Enum.at(records, 2)
Link to this function

decode!(data, opts \\ [])

View Source

See decode/2 for details. decode! raises an error in case decoding fails.