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

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.

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.

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.

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.

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.

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.

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.

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.