OpenLCB over CAN
Classes for creating, manipulating, and parsing CAN frames as OpenLCB messages.
author: | Dustin C. Hatch |
---|---|
author: | Timothy C. Hatch |
Represents a message sent to a single node
Parameters: |
|
---|
The node alias of the node sending the message
The alias of the node for which the message is intended
Raised when more than one class attempt to use the same MTI
Base class for Controller Area Network messages
Calling str() on CANMessage instances returns a string containing the CAN frame.
The value of the header that would be sent in the frame
The value of the body that would be sent with the frame
Convert a sequence (list, etc.) of strings to Message objects
Parameters: | seq (sequence) – A sequence of OpenLCB frame strings |
---|---|
Yields: | Instances of the CANMessage subclass |
Create a CANMessage instance from a frame string
Parameters: | frame (str) – The complete CAN frame, including control characters |
---|---|
Returns: | A new instance of the CANMessage subclass |
Subclasses of CANMessage should not override this method, but rather parse_frame() instead.
Parse a string containing a CAN frame into its parts
Returns dict: | A dictionary containing the valuable message parts |
---|
Subclasses of CANMessage should override this method and provide their own unique logic for parsing the header and body into usable properties.
Represents a message that contains a full node ID
The full of the ID of the node identified in the message
Represents a message containing an event ID
The ID of the event identified in the message
According to the Event Identifiers Technical Note, a node ID is part of the event ID, however it does not have to have any relationship to the event (i.e. it does not have to refer to the node sending the message).
Represents a message sent to the entire bus
Raised when creating a message from a string with the wrong MTI
Raised when attempting to parse an improperly-formatted frame
Utility class for handling node alias
Represents a message that contains a full node ID
The full of the ID of the node identified in the message
Base class for all OpenLCB CAN messages
Parameters: | src_alias (int) – The alias of the node from which messages originate |
---|
The node alias of the node sending the message
The message type indicator, as an integer. This value should be set by subclasses of CANMessage. See http://www.openlcb.org/trunk/specs/MtiAllocations.pdf for a list of MTI allocations.
Metaclass for OpenLCB message classes
Classes using RegisteredMessage as their metaclass will automatically have their MTIs registered, which creates a reverse mapping from MTI to class. This registration is required for parse_frame() to discover a message class based on the MTI and return an instance of it.
Parse an OpenLCB Message from a CAN frame
Parameters: | frame (str) – CAN frame as a string, including control characters |
---|---|
Returns: | An instance of the class registered for the MTI specified in the frame |
The message type lookup proceeds as follows:
Once a suitable message class has been found (or created), it will be instantiated by calling its from_string classmethod, passing in the original message frame string.