filedef

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2023 License: BSD-3-Clause Imports: 8 Imported by: 3

Documentation

Overview

Package filedef contains the implementation of known common file types and its listener to convert decoded FIT file into the desired common file type as soon as the message is decoded.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortMessagesByTimestamp added in v0.2.0

func SortMessagesByTimestamp(messages []proto.Message)

SortMessagesByTimestamp sorts messages by timestamp only if the message has timestamp field. When a message has no timestamp field, its order will not be changed.

func ToMesgs added in v0.3.0

func ToMesgs[S []E, E PutMessage](messages *[]proto.Message, fac mesgdef.Factory, mesgNum typedef.MesgNum, s S)

ToMesgs bulks convert mesgdef into proto.Message and append it to messages

Types

type Activity

type Activity struct {
	FileId mesgdef.FileId // must have mesg

	// Developer Data Lookup
	DeveloperDataIds  []*mesgdef.DeveloperDataId
	FieldDescriptions []*mesgdef.FieldDescription

	// Required Messages
	Activity *mesgdef.Activity
	Sessions []*mesgdef.Session
	Laps     []*mesgdef.Lap
	Records  []*mesgdef.Record

	// Optional Messages
	UserProfile  *mesgdef.UserProfile
	DeviceInfos  []*mesgdef.DeviceInfo
	Events       []*mesgdef.Event
	Lengths      []*mesgdef.Length
	SegmentLap   []*mesgdef.SegmentLap
	ZonesTargets []*mesgdef.ZonesTarget
	Workouts     []*mesgdef.Workout
	WorkoutSteps []*mesgdef.WorkoutStep
	HRs          []*mesgdef.Hr
	HRVs         []*mesgdef.Hrv

	// Messages not related to Activity
	UnrelatedMessages []proto.Message
}

Activity is a common file type that most wearable device or cycling computer uses to record activities.

Please note since we group the same mesgdef types in slices, we lose the arrival order of the messages. But for messages that have timestamp, we can reconstruct the messages by timestamp order.

ref: https://developer.garmin.com/fit/file-types/activity/

func NewActivity

func NewActivity(mesgs ...proto.Message) *Activity

func (*Activity) Add

func (f *Activity) Add(mesg proto.Message)

func (*Activity) ToFit

func (f *Activity) ToFit(fac mesgdef.Factory) proto.Fit

type Course added in v0.2.0

type Course struct {
	FileId mesgdef.FileId // must have mesg

	// Developer Data Lookup
	DeveloperDataIds  []*mesgdef.DeveloperDataId
	FieldDescriptions []*mesgdef.FieldDescription

	// Required Messages
	Course  *mesgdef.Course
	Lap     *mesgdef.Lap
	Records []*mesgdef.Record
	Events  []*mesgdef.Event

	// Optional Messages
	CoursePoints []*mesgdef.CoursePoint

	// Messages not related to Course
	UnrelatedMessages []proto.Message
}

Course is a common file type used as points of courses to assist with on- and off-road navigation, to provide turn by turn directions, or with virtual training applications to simulate real-world activities.

Please note since we group the same mesgdef types in slices, we lose the arrival order of the messages. But for messages that have timestamp, we can reconstruct the messages by timestamp order.

ref: https://developer.garmin.com/fit/file-types/course/

func NewCourse added in v0.2.0

func NewCourse(mesgs ...proto.Message) *Course

func (*Course) Add added in v0.2.0

func (f *Course) Add(mesg proto.Message)

func (*Course) ToFit added in v0.2.0

func (f *Course) ToFit(fac mesgdef.Factory) proto.Fit

type File

type File interface {
	// Add adds message into file structure.
	Add(mesg proto.Message)
	// ToFit converts file back to proto.Fit structure.
	ToFit(fac mesgdef.Factory) proto.Fit
}

File is an interface for defining common type file, any defined common file type should implement the following methods to be able to work with Listener (and other building block in filedef package).

type FileSets added in v0.2.0

type FileSets = map[typedef.File]func() File

FileSets is a set of file type mapped to a function to create that File.

func PredefinedFileSet added in v0.2.0

func PredefinedFileSet() FileSets

PredefinedFileSet is a list of default filesets used in listener, it's exported so user can append their own types and register it as an option.

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

Listener is Message Listener.

func NewListener

func NewListener(opts ...Option) *Listener

NewListener creates mesg listener.

func (*Listener) Close added in v0.2.0

func (l *Listener) Close()

Close closes channel and wait until all messages is consumed.

func (*Listener) File

func (l *Listener) File() File

File returns the resulting file after the a single decode process is completed. If we the current decoded result is not listed in fileSets, nil will be returned, it's recommended to use switch type assertion to check. This will reset fields used by listener and the listener is ready to be used for next chained FIT file.

func (*Listener) OnMesg

func (l *Listener) OnMesg(mesg proto.Message)

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithChannelBuffer

func WithChannelBuffer(size uint) Option

WithChannelBuffer sets the size of buffered channel, default is 1000.

func WithFileSets added in v0.2.0

func WithFileSets(fileSets FileSets) Option

WithFileSets sets what kind of file listener should listen to, when we encounter a file type that is not listed in fileset, that file type will be skipped. This will replace the default filesets registered in listener, if you intend to append your own file types, please call PredefinedFileSet() and add your file types.

type PutMessage

type PutMessage interface {
	ToMesg(fac mesgdef.Factory) proto.Message
}

PutMessage is a type constraint to retrieve all mesgdef structures which implement PutMessage method.

type Workout added in v0.2.0

type Workout struct {
	FileId mesgdef.FileId // must have mesg

	// Developer Data Lookup
	DeveloperDataIds  []*mesgdef.DeveloperDataId
	FieldDescriptions []*mesgdef.FieldDescription

	// Required Messages
	Workout      *mesgdef.Workout
	WorkoutSteps []*mesgdef.WorkoutStep

	// Messages not related to Workout
	UnrelatedMessages []proto.Message
}

Workout is a file contains instructions for performing a structured activity.

ref: https://developer.garmin.com/fit/file-types/workout/

func NewWorkout added in v0.2.0

func NewWorkout(mesgs ...proto.Message) *Workout

func (*Workout) Add added in v0.2.0

func (f *Workout) Add(mesg proto.Message)

func (*Workout) ToFit added in v0.2.0

func (f *Workout) ToFit(fac mesgdef.Factory) proto.Fit

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL