Skip to content

Commit 783b902

Browse files
blf: interpret object timestamps as signed 64-bit values
Change BLF object header timestamp fields from uint64 (Q) to int64 (q) for both V1 and V2 object headers. Observed CANape-generated BLF files containing messages before the recording start timestamp. When interpreted as unsigned values, these timestamps wrap around and appear approximately 2^64 ns in the future, resulting in invalid timestamps (e.g. year 2611) and NaT values in pandas. Using signed 64-bit timestamps correctly preserves negative recording-relative offsets while still providing a usable range of approximately ±292 years at nanosecond resolution. Root cause:   A timestamp of -60 s was decoded as   2^64 ns - 60 s   which produced timestamps approximately 584 years in the future. The resulting values exceeded the valid pandas datetime range and appeared as NaT.
1 parent b4f82ab commit 783b902

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

‎can/io/blf.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ class BLFParseError(Exception):
4949
OBJ_HEADER_BASE_STRUCT = struct.Struct("<4sHHLL")
5050

5151
# flags, client index, object version, timestamp
52-
OBJ_HEADER_V1_STRUCT = struct.Struct("<LHHQ")
52+
OBJ_HEADER_V1_STRUCT = struct.Struct("<LHHq")
5353

5454
# flags, timestamp status, object version, timestamp, (original timestamp)
55-
OBJ_HEADER_V2_STRUCT = struct.Struct("<LBxHQ8x")
55+
OBJ_HEADER_V2_STRUCT = struct.Struct("<LBxHq8x")
5656

5757
# compression method, size uncompressed
5858
LOG_CONTAINER_STRUCT = struct.Struct("<H6xL4x")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
changed interpretion of blf recording relative timestamps from unsigned to signed int64

0 commit comments

Comments
 (0)