Post · 2 min read· pp. 146–148

Parsers module

This module defines the message parsing framework. It provides a Register decorator for associating parsing functions to message channel prefixes, a parse() function to dispatch messages to appropriate parsers, and several built-in parsers.

Classes

Register

Decorator to register parser functions under specific message channel prefixes.

class parsers.Register(msg_channels) : Class Attributes

code
func\_map*: dict*
:   Maps message channel prefixes to lists of registered parser functions.

**Constructor**

\_\_init\_\_(*msg\_channels*)

Initialize the decorator with one or more channel prefixes.
:   Parameters:
    :   **msg\_channels** – A string or list of strings representing channel prefixes.

**Call**

\_\_call\_\_(*func*)

Register the decorated function under the configured channel prefixes.
:   Parameters:
    :   **func** – The parser function to register.

    Returns:
    :   The original function.

Functions

parse

parsers.parse(msg_channel, msg_payload) : Dispatch the incoming message to all parser functions whose registered channel prefix matches the start of msg_channel. Each parser yields tuples of (stream_name, timestamp, parsed_message), which are forwarded to the global publisher instance.

code
Parameters:
:   - **msg\_channel** – The channel name of the incoming message.
    - **msg\_payload** – The payload data for the message.

daq_parser

parsers.daq_parser(msg_data) : Parser for “DAQ” messages. Computes the average of each sensor’s data list and yields (sensor, timestamp, average_value) tuples.

code
Parameters:
:   **msg\_data** – Dict with keys `"timestamp"` and `"data"` mapping sensor names to lists of values.

can_parser

parsers.can_parser(payload) : Parser for CAN bus messages. Splits messages based on their type-specific fields, handles timestamp rollovers, and emits one stream per data field plus optional error/reset streams.

code
Parameters:
:   **payload** – Dict representing a CAN message with keys
    `"board_type_id"`, `"board_inst_id"`, `"msg_type"`, and `"data"`.

Returns:
:   List of `(stream_name, timestamp, value)` tuples.

rlcs_parser

parsers.rlcs_parser(payload) : Parser for RLCS messages. Emits one stream per key in the payload.

code
Parameters:
:   **payload** – Dict of RLCS data fields.

parsley_health

parsers.parsley_health(payload) : Health check parser for the Parsley subsystem. Yields a single stream with the healthy status.

code
Parameters:
:   **payload** – Dict with keys `"id"` and `"healthy"`.

state_est_parser

parsers.state_est_parser(payload) : Parser for StateEstimation messages. Emits orientation and position streams.

code
Parameters:
:   **payload** – Dict with keys `"timestamp"` and `"data"` containing `orientation` and `position`.

all_parser

parsers.all_parser(_) : Catch-all parser that emits a single “ALL” stream for any message.

code
Parameters:
:   **\_** – Unused payload.

Module-level Variables

parsers.splits : Dict mapping message types to the field used to split data into separate streams.

parsers.last_timestamp : Dict tracking the last timestamp seen for each board-and-message key to detect rollovers.

parsers.offset_timestamp : Dict tracking cumulative offsets to correct for timestamp rollovers.