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
@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:
ExtFit.Record.FitHeader
- FIT file headerExtFit.Record.FitDefinition
- definition messageExtFit.Record.FitData
- data messageExtFit.Record.FitCrc
- CRC information encoded in the file
Decode accepts the following options:
expand_components
- (default:true
) - whether to expand components into separate fieldsprocessors
- (default:ExtFit.Processor.DefaultProcessor
andExtFit.Processor.StandardUnitsProcessor
) - list of processors to apply to each record
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)
See decode/2
for details. decode!
raises an error in case decoding fails.