tslumd.messages
- class tslumd.messages.Display(index: int, rh_tally: TallyColor = <TallyColor.OFF: 0>, txt_tally: TallyColor = <TallyColor.OFF: 0>, lh_tally: TallyColor = <TallyColor.OFF: 0>, brightness: int = 3, text: str = '', control: bytes = b'', type: MessageType = MessageType.display, text_length: int | None = None)[source]
Bases:
objectA single tally “display”
- rh_tally: TallyColor = 0
Right hand tally indicator
- txt_tally: TallyColor = 0
Text tally indicator
- lh_tally: TallyColor = 0
Left hand tally indicator
- type: MessageType = 1
The message type. One of
displayorcontrol.For
display(the default), the message containstextinformation and thecontrolfield must be empty.For
control, the message containscontroldata and thetextfield must be empty
Added in version 0.0.2.
- is_broadcast: bool
Trueif the display is to a “broadcast”, meaning sent to all display indices.(if the
indexis0xffff)Added in version 0.0.2.
- text_length: int | None = None
Length of the
textfieldIf provided, the text output will be zero-padded or truncated to this length. If
None(the default), the text length is variable.Note
This is mainly for internal use during test runs to match the fixed-length text field in actual message bytes.
Added in version 0.0.8.
- classmethod broadcast(**kwargs) Display[source]
Create a
broadcastdisplay(with
indexset to0xffff)Added in version 0.0.2.
- classmethod from_dmsg(flags: Flags, dmsg: bytes, retain_text_length: bool = False) Tuple[Display, bytes][source]
Construct an instance from a
DMSGportion of received message.Any remaining message data after the relevant
DMSGis returned along with the instance.- Parameters:
flags – The message
Flagsfielddmsg – The portion of the message containing the
DMSGdataretain_text_length – If
True, thetext_lengthattribute will be set to the length of the text field as found in the message bytes. Otherwise (the default), it will be set toNoneand the text length will be variable.
Changed in version 0.0.8: The retain_text_length argument was added.
- static _unpack_control_data(data: bytes) Tuple[bytes, bytes][source]
Unpack control data (if control bit 15 is set)
- Parameters:
data – The portion of the
dmsgat the start of the “Control Data” field- Returns:
- remaining
The remaining message data after the control data field
- Return type:
Note
This is undefined as of UMDv5.0 and its implementation is the author’s “best guess” based off of other areas of the protocol
Added in version 0.0.2.
- static _pack_control_data(data: bytes) bytes[source]
Pack control data (if control bit 15 is set)
- Parameters:
data – The control data to pack
- Returns:
- packed
The packed control data
- Return type:
Note
This is undefined as of UMDv5.0 and its implementation is the author’s “best guess” based off of other areas of the protocol
Added in version 0.0.2.
- to_dmsg() bytes[source]
Build
dmsgbytes to be included in a message (called fromMessage.build_message())
- to_common_dict() DisplayTallyCommonDict[source]
Return a dict of the common fields between
DisplayandTallyobjectsAdded in version 0.0.8.
- class tslumd.messages.Message(version: int = 0, flags: Flags = <Flags.NO_FLAGS: 0>, screen: int = 0, displays: list[Display] = <factory>, scontrol: bytes = b'', type: MessageType = MessageType.display)[source]
Bases:
objectA single UMDv5 message packet
- flags: Flags = 0
The message
Flagsfield
- type: MessageType = 1
The message type. One of
displayorcontrol.For
display(the default), the contents ofdisplaysare used and thescontrolfield must be empty.For
control, thescontrolfield is used anddisplaysmust be empty.
Added in version 0.0.2.
- is_broadcast: bool
Trueif the message is to be “broadcast” to all screens.(if
screenis0xffff)Added in version 0.0.2.
- classmethod broadcast(**kwargs) Message[source]
Create a
broadcastmessage(with
screenset to0xffff)Added in version 0.0.2.
- classmethod parse(msg: bytes, retain_text_length: bool = False) Tuple[Message, bytes][source]
Parse incoming message data to create a
Messageinstance.Any remaining message data after parsing is returned along with the instance.
- Parameters:
msg – The incoming message bytes to parse
retain_text_length – Value to pass to
Display.from_dmsg()
Changed in version 0.0.8: The retain_text_length argument was added.
- build_message(ignore_packet_length: bool = False) bytes[source]
Build a message packet from data in this instance
- Parameters:
ignore_packet_length (bool, optional) – If
False, the message limit of 2048 bytes is respected, and if exceeded, an exception is raised. Otherwise, the limit is ignored. (default is False)- Raises:
MessageLengthError – If the message packet is larger than 2048 bytes (and
ignore_packet_lengthis False)
Note
This method is retained for backwards compatability. To properly handle the message limit, use
build_messages()Changed in version 0.0.4:
The
ignore_packet_lengthparameter was addedMessage length is limited to 2048 bytes
- build_messages(ignore_packet_length: bool = False) Iterator[bytes][source]
Build message packet(s) from data in this instance as an iterator
The specified maximum packet length of 2048 is respected and if necessary, the data will be split into separate messages.
This method will always function as a generator, regardless of the number of message packets produced.
Added in version 0.0.4.
- exception tslumd.messages.ParseError(msg: str, value: bytes)[source]
Bases:
ExceptionRaised on errors during message parsing
Added in version 0.0.2.
- exception tslumd.messages.MessageParseError(msg: str, value: bytes)[source]
Bases:
ParseErrorRaised on errors while parsing
MessageobjectsAdded in version 0.0.2.
- exception tslumd.messages.DmsgParseError(msg: str, value: bytes)[source]
Bases:
ParseErrorRaised on errors while parsing
DisplayobjectsAdded in version 0.0.2.
- exception tslumd.messages.DmsgControlParseError(msg: str, value: bytes)[source]
Bases:
ParseErrorRaised on errors when parsing
Display.controldataAdded in version 0.0.2.
- exception tslumd.messages.MessageLengthError[source]
Bases:
ValueErrorRaised when message length is larger than 2048 bytes
Added in version 0.0.4.