fit-0.5.1: FIT file decoder

CopyrightCopyright 2014-2015, Matt Giles
LicenseModified BSD License
Maintainermatt.w.giles@gmail.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Fit

Contents

Description

 

Synopsis

Messages API

A high-level view of a FIT file as a sequence of data messages. This is the recommended API for pulling information out of a FIT file, but if you need access to the exact structure of the file you can use the API in Fit.Internal.FitFile and Fit.Internal.Parse.

Some basic lenses are also provided for working with the Messages API. These can make it much easier to extract information from a FIT file, especially since you usually know what sort of data you're expecting to find.

For example, from the FIT global profile we can find that the global message number for record messages is 20, and within a record message the speed field has field number 6. The following code gets the speed field from all record messages in the file:

Right fit <- readFileMessages "file.fit"
let speeds = fit ^.. message 20 . field 6 . int
-- speeds :: [Int]

Note that this package doesn't provide any lens combinators (like (^..)), so you'll need to use ones from a lens package.

readMessages :: ByteString -> Either String Messages Source

Parse a strict ByteString containing the FIT data into its Messages

readFileMessages :: FilePath -> IO (Either String Messages) Source

Parse the given FIT file into its Messages

parseMessages :: Parser Messages Source

An Attoparsec parser for Messages

newtype Messages Source

The collection of data messages from the FIT file.

Constructors

Messages 

Fields

_messages :: Seq Message
 

Instances

data Message Source

A FIT data message

Constructors

Message 

Fields

_mNumber :: !Int

The global message number, as found in the FIT profile

_mFields :: IntMap Field

The fields in the message, mapped from field number to Field

Instances

data Field Source

A single field in a FIT data message

Constructors

Field 

Fields

_fNumber :: !Int

The field number, as found in the FIT profile

_fValue :: Value
 

Instances

data Value Source

FIT values can either contain a single piece of data or an array. FIT arrays are homogenous

Instances

data SingletonValue Source

A singleton value. In the Messages API we abstract over the specific FIT base type of the field. For example, the FIT types uint8, sint8, uint16, etc. are all presented as an IntValue. FIT strings (ie. character arrays) are presented as singleton TextValues. If you need to know the specific base type of a field you can use the API in Fit.Internal.FitFile.

Instances

data ArrayValue Source

Array values. Like singleton values these ignore the specific FIT base type to present a simpler interface. Byte arrays are presented as strict ByteStrings. There are no character arrays, since the singleton TextValue handles that case.

Instances

Lenses for the Messages API

messages :: Applicative f => (Message -> f Message) -> Messages -> f Messages Source

Traverse all the messages in a Messages

messages :: Traversal' Messages Message

message :: (Contravariant f, Applicative f) => Int -> (Message -> f Message) -> Messages -> f Messages Source

A Fold over the messages with the given message number

message :: Int -> Fold Messages Message

messageNumber :: Functor f => (Int -> f Int) -> Message -> f Message Source

Lens on the message number from a Message

messageNumber :: Lens' Message Int

fields :: Applicative f => (Field -> f Field) -> Message -> f Message Source

Traverse all the fields in a Message

fields :: Traversal' Message Field

field :: (Contravariant f, Applicative f) => Int -> (Field -> f Field) -> Message -> f Message Source

A Fold over the fields in a Message with the given field number

field :: Int -> Fold Message Field

fieldNumber :: Functor f => (Int -> f Int) -> Field -> f Field Source

Lens on the field number from a Field

fieldNumber :: Lens Field Int

fieldValue :: Functor f => (Value -> f Value) -> Field -> f Field Source

Lens on the Value from a Field

fieldValue :: Lens Field Value

int :: Applicative f => (Int -> f Int) -> Field -> f Field Source

Traverse the Singleton and IntValue constructors for a field value

int :: Traversal' Field Int

real :: Applicative f => (Double -> f Double) -> Field -> f Field Source

Traverse the Singleton and RealValue constructors for a field value

real :: Traversal' Field Double

text :: Applicative f => (Text -> f Text) -> Field -> f Field Source

Traverse the Singleton and TextValue constructors for a field value

text :: Traversal' Field Text

byte :: Applicative f => (Word8 -> f Word8) -> Field -> f Field Source

Traverse the Singleton and ByteValue constructors for a field value

byte :: Traversal' Field Word8

ints :: Applicative f => (Seq Int -> f (Seq Int)) -> Field -> f Field Source

Traverse the Array and IntArray constructors for a field value

ints :: Traversal' Field (Seq Int)

reals :: Applicative f => (Seq Double -> f (Seq Double)) -> Field -> f Field Source

Traverse the Array and RealArray constructors for a field value

reals :: Traversal' Field (Seq Double)

bytestring :: Applicative f => (ByteString -> f ByteString) -> Field -> f Field Source

Travese the Array and ByteArray constructors for a field value

bytestring :: Traversal' Field ByteString