Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Garmin: Report correct local time offset #69

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions src/garmin_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,23 @@ DECLARE_FIELD(RECORD, rmv, UINT16) { } // 100 * l/min
DECLARE_FIELD(RECORD, ascent_rate, SINT32) { } // mm/s (negative is down)

// DEVICE_SETTINGS
DECLARE_FIELD(DEVICE_SETTINGS, utc_offset, UINT32) { garmin->dive.utc_offset = (SINT32) data; } // wrong type in FIT
DECLARE_FIELD(DEVICE_SETTINGS, time_offset, UINT32) { garmin->dive.time_offset = (SINT32) data; } // wrong type in FIT
DECLARE_FIELD(DEVICE_SETTINGS, utc_offset, UINT32)
{
garmin->dive.utc_offset = (SINT32) data; // wrong type in FIT
}
DECLARE_FIELD(DEVICE_SETTINGS, time_offset, UINT32)
{
/*
* Crazy FIT files have a zero time offset in DEVICE_SETTINGS,
* but then have a local_timestamp in ACTIVITY and/or in the
* TIME_CORRELATION messages.
*
* So I have no idea what this field means then.
*/
if (!data)
return;
garmin->dive.time_offset = (SINT32) data; // wrong type in FIT
}

// DEVICE_INFO
// collect the data and then use the record if it is for device_index 0
Expand Down Expand Up @@ -677,6 +692,19 @@ DECLARE_FIELD(SPORT, sub_sport, ENUM) {
DC_ASSIGN_FIELD(garmin->cache, DIVEMODE, val);
}

/*
* What is the difference between 'system_timestamp' and the
* actual timestamp of the message itself? Who designs these
* crazy things? What is the meaning of it all? These are the
* kinds of unanswerable questions that keep me up at night.
*/
DECLARE_FIELD(TIMESTAMP_CORRELATION, system_timestamp, UINT32) { }
DECLARE_FIELD(TIMESTAMP_CORRELATION, local_timestamp, UINT32)
{
int time_offset = data - garmin->record_data.timestamp;
garmin->dive.time_offset = time_offset;
}

// DIVE_GAS - uses msg index
DECLARE_FIELD(DIVE_GAS, helium, UINT8)
{
Expand Down Expand Up @@ -988,6 +1016,14 @@ DECLARE_MESG(RECORD) = {
}
};

DECLARE_MESG(TIMESTAMP_CORRELATION) = {
.maxfield = 6,
.field = {
SET_FIELD(TIMESTAMP_CORRELATION, 1, system_timestamp, UINT32),
SET_FIELD(TIMESTAMP_CORRELATION, 3, local_timestamp, UINT32),
}
};

DECLARE_MESG(DIVE_GAS) = {
.maxfield = 4,
.field = {
Expand Down Expand Up @@ -1181,6 +1217,8 @@ static const struct {

SET_MESG(147, SENSOR_PROFILE),

SET_MESG(162, TIMESTAMP_CORRELATION),

SET_MESG(206, FIELD_DESCRIPTION),

SET_MESG(216, WTF_216),
Expand Down
Loading