Post · 1 min read· pp. 7–8

Logger Data Format Specification

Overview

The logger binary format is organized in pages, each page is 4 KiB size for optimize write sector alignment. The total size of the logger log file shall be a multiple of 4 KiB.

File structure example with 4 pages

Offset (Hex)Data
0x0000 - 0x0fffPage 0
0x1000 - 0x1fffPage 1
0x2000 - 0x2fffPage 2
0x3000 - 0x3fffPage 3

Page Structure

Each page is start with a signature, the signature consist of 4 bytes, the sequence number is page number modulo 256(lower 8 bits of page number)

Page signature

ByteData
00x4C (ASCII of L)
10x4F (ASCII of O)
20x47 (ASCII of G)
3Sequence Number (seq_number = page_number & 0xff)

CAN message data are appended after page signature, up to the page boundry. Unused bytes after last message in the page shall be filled with 0xff

CAN Message Packing Structure

ByteData
0 - 3SID, little endian
4 - 7Timestamp, milli-second, little endian (time when logger received CAN message)
8DLC(Data Length Code)
9 - 16CAN Data Payload

CAN Data Payload shall be DLC bytes, sizeof(packing_structure) = 9 + DLC, for example if DLC == 1 then the size of CAN Message Packing structure shall be 10 bytes. SID[31:29] shall be 0 for valid CAN messages. DLC shall be between 0 to 8 inclusive.

Implementation Note

Writer (Logger Board)

Before each message is written to the page buffer, the firmware shall check to make sure enough space is left in the page buffer, if there’s not enough space left, then firmware shall fill remaining space with 0xff and write the page to SD card, then write the message to the new page buffer.

Reader (Parsley)

text
while(4096-RPTR >= 6):
    sid = read_4_bytes()
    if((sid & 0xe0000000) == 0): # check SID[31:29]
        # Valid CAN message
    else:
        # End of page