Skip to content

Commit b9a2f35

Browse files
authored
Merge pull request #69 from torvalds/garmin-localtime
Garmin: Report correct local time offset
2 parents a2a5bb5 + d755238 commit b9a2f35

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

src/garmin_parser.c

+40-2
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,23 @@ DECLARE_FIELD(RECORD, rmv, UINT16) { } // 100 * l/min
617617
DECLARE_FIELD(RECORD, ascent_rate, SINT32) { } // mm/s (negative is down)
618618

619619
// DEVICE_SETTINGS
620-
DECLARE_FIELD(DEVICE_SETTINGS, utc_offset, UINT32) { garmin->dive.utc_offset = (SINT32) data; } // wrong type in FIT
621-
DECLARE_FIELD(DEVICE_SETTINGS, time_offset, UINT32) { garmin->dive.time_offset = (SINT32) data; } // wrong type in FIT
620+
DECLARE_FIELD(DEVICE_SETTINGS, utc_offset, UINT32)
621+
{
622+
garmin->dive.utc_offset = (SINT32) data; // wrong type in FIT
623+
}
624+
DECLARE_FIELD(DEVICE_SETTINGS, time_offset, UINT32)
625+
{
626+
/*
627+
* Crazy FIT files have a zero time offset in DEVICE_SETTINGS,
628+
* but then have a local_timestamp in ACTIVITY and/or in the
629+
* TIME_CORRELATION messages.
630+
*
631+
* So I have no idea what this field means then.
632+
*/
633+
if (!data)
634+
return;
635+
garmin->dive.time_offset = (SINT32) data; // wrong type in FIT
636+
}
622637

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

695+
/*
696+
* What is the difference between 'system_timestamp' and the
697+
* actual timestamp of the message itself? Who designs these
698+
* crazy things? What is the meaning of it all? These are the
699+
* kinds of unanswerable questions that keep me up at night.
700+
*/
701+
DECLARE_FIELD(TIMESTAMP_CORRELATION, system_timestamp, UINT32) { }
702+
DECLARE_FIELD(TIMESTAMP_CORRELATION, local_timestamp, UINT32)
703+
{
704+
int time_offset = data - garmin->record_data.timestamp;
705+
garmin->dive.time_offset = time_offset;
706+
}
707+
680708
// DIVE_GAS - uses msg index
681709
DECLARE_FIELD(DIVE_GAS, helium, UINT8)
682710
{
@@ -988,6 +1016,14 @@ DECLARE_MESG(RECORD) = {
9881016
}
9891017
};
9901018

1019+
DECLARE_MESG(TIMESTAMP_CORRELATION) = {
1020+
.maxfield = 6,
1021+
.field = {
1022+
SET_FIELD(TIMESTAMP_CORRELATION, 1, system_timestamp, UINT32),
1023+
SET_FIELD(TIMESTAMP_CORRELATION, 3, local_timestamp, UINT32),
1024+
}
1025+
};
1026+
9911027
DECLARE_MESG(DIVE_GAS) = {
9921028
.maxfield = 4,
9931029
.field = {
@@ -1181,6 +1217,8 @@ static const struct {
11811217

11821218
SET_MESG(147, SENSOR_PROFILE),
11831219

1220+
SET_MESG(162, TIMESTAMP_CORRELATION),
1221+
11841222
SET_MESG(206, FIELD_DESCRIPTION),
11851223

11861224
SET_MESG(216, WTF_216),

0 commit comments

Comments
 (0)