8000 mf4: derive measurement start from the first record by tomrford · Pull Request #81 · tomrford/gocan · GitHub
[go: up one dir, main page]

Skip to content

mf4: derive measurement start from the first record - #81

Merged
tomrford merged 2 commits into
mainfrom
fix/mf4-first-record-start
Sep 11, 2026
Merged

tomrford merged 2 commits into
mainfrom
fix/mf4-first-record-start

Conversation

@tomrford
@tomrford tomrford commented Sep 11, 2026 •
Copy link
Copy Markdown
Owner

MF4 exports currently require callers to choose a start time before writing records. Exporting buffered capture data can then reject the first record because its timestamp predates that manually chosen start.

Derive the measurement start from the first accepted frame or event, giving that record offset zero. Patch the existing header through the seekable output; empty exports retain file creation time. Invalid records leave the start unset, and header-patch failures remain sticky. Subsequent records before the established start and regressions within a bus/frame-kind group are still rejected.

The constructor is now mf4.NewWriter(output, options); callers must remove the start argument.

Validation:

  • Regression tests cover frame-first and event-first recording, invalid initial records, Unix-epoch timestamps, early Flush, empty exports, writes after Close, and header-patch seek/write/short-write failures.
  • go test -race ./..., go vet ./..., formatting and diff checks passed.
  • Windows amd64, arm64 and 386 compilation passed.
  • asammdf 8.7.2 and python-can 4.6.1 read ten compressed/uncompressed fixtures covering frame-first, event-first, event-only, empty and Unix-epoch exports. Checks verified header nanoseconds, frame/event offsets, reconstructed absolute frame times, IDs, payloads, bus IDs and counts.

Independent-reader acceptance is interoperability evidence; Vector, MATLAB and CANape conformance checks were unavailable.


Note

Medium Risk
Breaking constructor API and changes how MF4 absolute timestamps are chosen, which affects any external callers and downstream tooling that assumed a caller-supplied start.

Overview
mf4 no longer takes an explicit measurement start: NewWriter is now NewWriter(output, options) (callers drop the start argument).

The first accepted frame or event sets the measurement start (offset zero) by patching the MDF header on the seekable output. Until then, and for empty exports, the header uses file creation time (shared with the history block). Rejected or invalid records and early Flush do not establish start; records before the chosen start still fail; per-bus time regression rules are unchanged.

New timeOffset centralizes range checks and lazy start initialization. start_test.go adds regression coverage for frame/event-first starts, epoch origins, empty close, post-close writes, and sticky failures when header patching fails.

Reviewed by Cursor Bugbot for commit 69d2373. Configure here.

@tomrford
tomrford merged commit 433bad0 into main Sep 11, 2026
1 check passed
@tomrford
tomrford deleted the fix/mf4-first-record-start branch September 11, 2026 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0