filedef

package
v0.19.2 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package filedef contains general implementation of known common file types retrieved from Garmin or its affiliates website and a listener building block convert decoded FIT file into the desired common file type as soon as the message is decoded.

You may find that the common file types declared here are not sufficient for your need, but don't worry, you can always create your own common file types that suit your need more; whether creating a fresh one or embedding the existing; and still be able to use listener building block as long as it satisfy the File interface.

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. The following rules will apply:

  • Any message without timestamp field will be placed to the beginning of the slice to enable these messages to be retrieved early such as UserProfile.
  • Any message with invalid timestamp will be places at the end of the slices.

Special Case:

All timestamp fields should have num 253, except:

  • Course Point's Timestamp num: 1
  • Set's Timestamp num: 254

We will sort these timestamps accordingly since the messages' order matters.

For details, see github.com/muktihari/fit/proto.FieldNumTimestamp doc.

Types

type Activity

type Activity struct {
	FileId mesgdef.FileId // required fields: type, manufacturer, product, serial_number, time_created

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

	// Required Messages
	Activity *mesgdef.Activity  // required fields: timestamp, num_sessions, type, event, event_type
	Sessions []*mesgdef.Session // required fields: timestamp, start_time, total_elapsed_time, sport, event, event_type
	Laps     []*mesgdef.Lap     // required fields: timestamp, event, event_type
	Records  []*mesgdef.Record  // required fields: timestamp

	// Optional Messages
	UserProfile  *mesgdef.UserProfile
	DeviceInfos  []*mesgdef.DeviceInfo // required fields: timestamp
	Events       []*mesgdef.Event
	Lengths      []*mesgdef.Length // required fields: timestamp, event, event_type
	SegmentLaps  []*mesgdef.SegmentLap
	ZonesTargets []*mesgdef.ZonesTarget
	Workouts     []*mesgdef.Workout
	WorkoutSteps []*mesgdef.WorkoutStep
	HRs          []*mesgdef.Hr
	HRVs         []*mesgdef.Hrv // required fields: time

	// 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

NewActivity creates new Activity File.

func (*Activity) Add

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

Add adds mesg to the Activity.

func (*Activity) ToFIT added in v0.12.0

func (f *Activity) ToFIT(options *mesgdef.Options) proto.FIT

ToFIT converts Activity to proto.FIT. If options is nil, default options will be used.

type ActivitySummary added in v0.8.0

type ActivitySummary struct {
	FileId mesgdef.FileId // required fields: type, manufacturer, product, serial_number, time_created

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

	Activity *mesgdef.Activity
	Sessions []*mesgdef.Session
	Laps     []*mesgdef.Lap

	UnrelatedMessages []proto.Message
}

ActivitySummary is a compact version of the activity file and contain only activity, session and lap messages

func NewActivitySummary added in v0.8.0

func NewActivitySummary(mesgs ...proto.Message) *ActivitySummary

NewActivitySummary creates new ActivitySummary File.

func (*ActivitySummary) Add added in v0.8.0

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

Add adds mesg to the ActivitySummary.

func (*ActivitySummary) ToFIT added in v0.12.0

func (f *ActivitySummary) ToFIT(options *mesgdef.Options) proto.FIT

ToFIT converts ActivitySummary to proto.FIT. If options is nil, default options will be used.

type BloodPressure added in v0.8.0

type BloodPressure struct {
	FileId mesgdef.FileId // required fields: type, manufacturer, product, serial_number

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

	UserProfile    *mesgdef.UserProfile
	BloodPressures []*mesgdef.BloodPressure
	DeviceInfos    []*mesgdef.DeviceInfo

	UnrelatedMessages []proto.Message
}

BloodPressure files contain time-stamped discrete measurement data of blood pressure.

func NewBloodPressure added in v0.8.0

func NewBloodPressure(mesgs ...proto.Message) *BloodPressure

NewBloodPressure creates new BloodPressure File.

func (*BloodPressure) Add added in v0.8.0

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

Add adds mesg to the BloodPressure.

func (*BloodPressure) ToFIT added in v0.12.0

func (f *BloodPressure) ToFIT(options *mesgdef.Options) proto.FIT

ToFIT converts BloodPressure to proto.FIT. If options is nil, default options will be used.

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

NewCourse creates new Course File.

func (*Course) Add added in v0.2.0

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

Add adds mesg to the Course.

func (*Course) ToFIT added in v0.12.0

func (f *Course) ToFIT(options *mesgdef.Options) proto.FIT

ToFIT converts Course to proto.FIT. If options is nil, default options will be used.

type Device added in v0.8.0

type Device struct {
	FileId mesgdef.FileId // required fields: type, manufacturer, product, serial_number

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

	Softwares         []*mesgdef.Software
	Capabilities      []*mesgdef.Capabilities
	FileCapabilities  []*mesgdef.FileCapabilities
	MesgCapabilities  []*mesgdef.MesgCapabilities
	FieldCapabilities []*mesgdef.FieldCapabilities

	UnrelatedMessages []proto.Message
}

Device files contain information about a device’s file structure/capabilities.

func NewDevice added in v0.8.0

func NewDevice(mesgs ...proto.Message) *Device

NewDevice creates new Device File.

func (*Device) Add added in v0.8.0

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

Add adds mesg to the Device.

func (*Device) ToFIT added in v0.12.0

func (f *Device) ToFIT(options *mesgdef.Options) proto.FIT

ToFIT converts Device to proto.FIT. If options is nil, default options will be used.

type File

type File interface {
	// Add adds message into file structure.
	Add(mesg proto.Message)
	// ToFIT converts file back to proto.FIT structure.
	ToFIT(options *mesgdef.Options) 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. This alias is created for documentation purpose.

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 Goals added in v0.8.0

type Goals struct {
	FileId mesgdef.FileId

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

	Goals []*mesgdef.Goal

	UnrelatedMessages []proto.Message
}

Goals files allow a user to communicate their exercise/health goals.

func NewGoals added in v0.8.0

func NewGoals(mesgs ...proto.Message) *Goals

NewGoals creates new Goals File.

func (*Goals) Add added in v0.8.0

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

Add adds mesg to the Goals.

func (*Goals) ToFIT added in v0.12.0

func (f *Goals) ToFIT(options *mesgdef.Options) proto.FIT

ToFIT converts Goals to proto.FIT. If options is nil, default options will be used.

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 MonitoringAB added in v0.8.0

type MonitoringAB struct {
	FileId mesgdef.FileId

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

	MonitoringInfo *mesgdef.MonitoringInfo
	Monitorings    []*mesgdef.Monitoring
	DeviceInfos    []*mesgdef.DeviceInfo

	UnrelatedMessages []proto.Message
}

MonitoringAB (Monitoring A and Monitoring B) files are used to store data that is logged over varying time intervals. The two monitoring file formats are identical apart from supporting different conventions for file_id.number and the start of accumulating data values.

The FIT file_id.type = 15 for a monitoring_a file and the FIT file_id.type = 32 for a monitoring_b file

func NewMonitoringAB added in v0.8.0

func NewMonitoringAB(mesgs ...proto.Message) *MonitoringAB

NewMonitoringAB creates new MonitoringAB File.

func (*MonitoringAB) Add added in v0.8.0

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

Add adds mesg to the MonitoringAB.

func (*MonitoringAB) ToFIT added in v0.12.0

func (f *MonitoringAB) ToFIT(options *mesgdef.Options) proto.FIT

ToFIT converts MonitoringAB to proto.FIT. If options is nil, default options will be used.

type MonitoringDaily added in v0.8.0

type MonitoringDaily struct {
	FileId mesgdef.FileId // required fields: type, manufacturer, product, serial_number, time_created, number

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

	MonitoringInfo *mesgdef.MonitoringInfo
	Monitorings    []*mesgdef.Monitoring // required fields: timestamp
	DeviceInfos    []*mesgdef.DeviceInfo

	UnrelatedMessages []proto.Message
}

MonitoringDaily files follow the same format as monitoring files, however data is logged at 24 hour time intervals.

func NewMonitoringDaily added in v0.8.0

func NewMonitoringDaily(mesgs ...proto.Message) *MonitoringDaily

NewMonitoringDaily creates new MonitoringDaily File.

func (*MonitoringDaily) Add added in v0.8.0

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

Add adds mesg to the MonitoringDaily.

func (*MonitoringDaily) ToFIT added in v0.12.0

func (f *MonitoringDaily) ToFIT(options *mesgdef.Options) proto.FIT

ToFIT converts MonitoringDaily to proto.FIT. If options is nil, default options will be used.

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 128.

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 Schedules added in v0.8.0

type Schedules struct {
	FileId mesgdef.FileId

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

	Schedules []*mesgdef.Schedule

	UnrelatedMessages []proto.Message
}

Schedules files are used to schedule a user’s workouts and may contain multiple schedule messages each representing the start time of a workout.

func NewSchedules added in v0.8.0

func NewSchedules(mesgs ...proto.Message) *Schedules

NewSchedules creates new Schedules File.

func (*Schedules) Add added in v0.8.0

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

Add adds mesg to the Schedules.

func (*Schedules) ToFIT added in v0.12.0

func (f *Schedules) ToFIT(options *mesgdef.Options) proto.FIT

ToFIT converts Schedules to proto.FIT. If options is nil, default options will be used.

type Segment added in v0.8.0

type Segment struct {
	FileId mesgdef.FileId

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

	SegmentId               *mesgdef.SegmentId
	SegmentLeaderboardEntry *mesgdef.SegmentLeaderboardEntry
	SegmentLap              *mesgdef.SegmentLap
	SegmentPoints           []*mesgdef.SegmentPoint

	UnrelatedMessages []proto.Message
}

Segment files contain data defining a route and timing information to gauge progress against previous performances or other users

func NewSegment added in v0.8.0

func NewSegment(mesgs ...proto.Message) *Segment

NewSegment creates new Segment File.

func (*Segment) Add added in v0.8.0

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

Add adds mesg to the Segment.

func (*Segment) ToFIT added in v0.12.0

func (f *Segment) ToFIT(options *mesgdef.Options) proto.FIT

ToFIT converts Segment to proto.FIT. If options is nil, default options will be used.

type SegmentList added in v0.8.0

type SegmentList struct {
	FileId mesgdef.FileId

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

	FileCreator  *mesgdef.FileCreator
	SegmentFiles []*mesgdef.SegmentFile

	UnrelatedMessages []proto.Message
}

SegmentList files maintain a list of available segments on the device.

func NewSegmentList added in v0.8.0

func NewSegmentList(mesgs ...proto.Message) *SegmentList

NewSegmentList creates new SegmentList File.

func (*SegmentList) Add added in v0.8.0

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

Add adds mesg to the SegmentList.

func (*SegmentList) ToFIT added in v0.12.0

func (f *SegmentList) ToFIT(options *mesgdef.Options) proto.FIT

ToFIT converts SegmentList to proto.FIT. If options is nil, default options will be used.

type Settings added in v0.8.0

type Settings struct {
	FileId mesgdef.FileId // required fields: type, manufacturer, product, serial_number

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

	UserProfiles   []*mesgdef.UserProfile
	HrmProfiles    []*mesgdef.HrmProfile
	SdmProfiles    []*mesgdef.SdmProfile
	BikeProfiles   []*mesgdef.BikeProfile
	DeviceSettings []*mesgdef.DeviceSettings

	UnrelatedMessages []proto.Message
}

Settings files contain user and device information in the form of profiles.

func NewSettings added in v0.8.0

func NewSettings(mesgs ...proto.Message) *Settings

NewSettings creates new Settings File.

func (*Settings) Add added in v0.8.0

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

Add adds mesg to the Settings.

func (*Settings) ToFIT added in v0.12.0

func (f *Settings) ToFIT(options *mesgdef.Options) proto.FIT

ToFIT converts Settings to proto.FIT. If options is nil, default options will be used.

type Sport added in v0.8.0

type Sport struct {
	FileId mesgdef.FileId // required fields: type, manufacturer, product, serial_number

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

	ZonesTargets []*mesgdef.ZonesTarget
	Sport        *mesgdef.Sport
	HrZones      []*mesgdef.HrZone
	PowerZones   []*mesgdef.PowerZone
	MetZones     []*mesgdef.MetZone
	SpeedZones   []*mesgdef.SpeedZone
	CadenceZones []*mesgdef.CadenceZone

	UnrelatedMessages []proto.Message
}

Sport files contain information about the user’s desired target zones.

func NewSport added in v0.8.0

func NewSport(mesgs ...proto.Message) *Sport

NewSport creates new Sport File.

func (*Sport) Add added in v0.8.0

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

Add adds mesg to the Sport.

func (*Sport) ToFIT added in v0.12.0

func (f *Sport) ToFIT(options *mesgdef.Options) proto.FIT

ToFIT converts Sport to proto.FIT. If options is nil, default options will be used.

type Totals added in v0.8.0

type Totals struct {
	FileId mesgdef.FileId

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

	Totals []*mesgdef.Totals

	UnrelatedMessages []proto.Message
}

Totals files are used to summarize a user’s activities and may contain multiple totals messages each representing summaries of a different activity type/sport

func NewTotals added in v0.8.0

func NewTotals(mesgs ...proto.Message) *Totals

NewTotals creates new Totals File.

func (*Totals) Add added in v0.8.0

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

Add adds mesg to the Totals.

func (*Totals) ToFIT added in v0.12.0

func (f *Totals) ToFIT(options *mesgdef.Options) proto.FIT

ToFIT converts Totals to proto.FIT. If options is nil, default options will be used.

type Weight added in v0.8.0

type Weight struct {
	FileId mesgdef.FileId // required fields: type, manufacturer, product, serial_number

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

	UserProfile  *mesgdef.UserProfile
	WeightScales []*mesgdef.WeightScale
	DeviceInfos  []*mesgdef.DeviceInfo

	UnrelatedMessages []proto.Message
}

Weight contains time-stamped discrete measurement data of weight.

func NewWeight added in v0.8.0

func NewWeight(mesgs ...proto.Message) *Weight

NewWeight creates new Weight File.

func (*Weight) Add added in v0.8.0

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

Add adds mesg to the Weight.

func (*Weight) ToFIT added in v0.12.0

func (f *Weight) ToFIT(options *mesgdef.Options) proto.FIT

ToFIT converts Weight to proto.FIT. If options is nil, default options will be used.

type Workout added in v0.2.0

type Workout struct {
	FileId mesgdef.FileId // required fields: type, manufacturer, product, serial_number, time_created

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

	// Required Messages
	Workout      *mesgdef.Workout       // required fields: num_valid_steps
	WorkoutSteps []*mesgdef.WorkoutStep // required fields: message_index, duration_type, target_type

	// 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

NewWorkout creates new Workout File.

func (*Workout) Add added in v0.2.0

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

Add adds mesg to the Workout.

func (*Workout) ToFIT added in v0.12.0

func (f *Workout) ToFIT(options *mesgdef.Options) proto.FIT

ToFIT converts Workout to proto.FIT. If options is nil, default options will be used.

Jump to

Keyboard shortcuts

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