Skip to content

time stamp calculation error with compressed header #6

@biop-zz

Description

@biop-zz

I am dowloading fit files from FR70 using garmin-forerunner-610-extractor.
I have found one issue concerning the time stamp. for hr data, records ares spaced by 5 seconds but I got variable steps using fitparse.

Looking at the specifications, I have found some mistakes and I am proposing the following solution:

def _parse_record_header(self):
    header_data, = self._struct_read(FitFile.RECORD_HEADER_FMT)

    header_type = self._get_bit(header_data, 7)

    if header_type == r.RECORD_HEADER_NORMAL:
        message_type = self._get_bit(header_data, 6)
        local_message_type = header_data & 0b11111  # Bits 0-4
        # TODO: Should we set time_offset to 0?
        return r.RecordHeader(
            header_type, message_type, local_message_type, None,
        )
    else:
        # Compressed timestamp
        local_message_type = (header_data >> 5) & 0b11  # bits 5-6
        #old
        #seconds_offset = header_data & 0b1111  # bits 0-3
        #new
        seconds_offset = header_data & 0b11111  # bits 0-4
        return r.RecordHeader(
            header_type, r.MESSAGE_DATA, local_message_type, seconds_offset)

in base.py,_parse_data_record

    if header.type == r.RECORD_HEADER_COMPRESSED_TS:
        ts_field = definition.type.fields.get(r.TIMESTAMP_FIELD_DEF_NUM)
        if ts_field:
        #new (ref: D00001275 Flexible and Interoperable Data Transfer (FIT) Protocol Rev 1.3.pd, page 17f)
        if header.seconds_offset >=  (self._last_timestamp & 0x0000001F):
               timestamp = (self._last_timestamp & 0xFFFFFFE0)  + header.seconds_offset
            else:
               timestamp = (self._last_timestamp & 0xFFFFFFE0)  + header.seconds_offset + 0x20
            #old
            #timestamp = self._last_timestamp + header.seconds_offset
            fields.append(r.BoundField(timestamp, ts_field))
            self._last_timestamp = timestamp

With these, I can recover my 5 seconds step and proper activity duration. I still have some concern about the initial time stamp to use because I found discrepancies between garmin connect and garmin-extractor/fitparse.

It's a piece of software you've done, thanks

Philippe

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions