tslumd.messages

class tslumd.messages.Display(index: int, rh_tally: TallyColor = TallyColor.OFF, txt_tally: TallyColor = TallyColor.OFF, lh_tally: TallyColor = TallyColor.OFF, brightness: int = 3, text: str = '', control: bytes = b'', type: MessageType = MessageType.display)[source]

Bases: object

A single tally “display”

index: int

The display index from 0 to 65534 (0xFFFE)

rh_tally: TallyColor = 0

Right hand tally indicator

txt_tally: TallyColor = 0

Text tally indicator

lh_tally: TallyColor = 0

Left hand tally indicator

brightness: int = 3

Display brightness (from 0 to 3)

text: str = ''

Text to display

control: bytes = b''

Control data (if type is control)

New in version 0.0.2.

type: MessageType = 1

The message type. One of display or control.

  • For display (the default), the message contains text information and the control field must be empty.

  • For control, the message contains control data and the text field must be empty

New in version 0.0.2.

is_broadcast: bool

True if the display is to a “broadcast”, meaning sent to all display indices.

(if the index is 0xffff)

New in version 0.0.2.

classmethod broadcast(**kwargs) Display[source]

Create a broadcast display

(with index set to 0xffff)

New in version 0.0.2.

classmethod from_dmsg(flags: Flags, dmsg: bytes) Tuple[Display, bytes][source]

Construct an instance from a DMSG portion of received message.

Any remaining message data after the relevant DMSG is returned along with the instance.

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 dmsg at the start of the “Control Data” field

Returns:

remaining

The remaining message data after the control data field

Return type:

bytes

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

New 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:

bytes

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

New in version 0.0.2.

to_dmsg(flags: Flags) bytes[source]

Build dmsg bytes to be included in a message (called from Message.build_message())

classmethod from_tally(tally: Tally, msg_type: MessageType = MessageType.display) Display[source]

Create a Display from the given Tally

New in version 0.0.2: The msg_type argument

class tslumd.messages.Message(version: int = 0, flags: ~tslumd.messages.Flags = Flags.NO_FLAGS, screen: int = 0, displays: list[~tslumd.messages.Display] = <factory>, scontrol: bytes = b'', type: ~tslumd.common.MessageType = MessageType.display)[source]

Bases: object

A single UMDv5 message packet

version: int = 0

Protocol minor version

flags: Flags = 0

The message Flags field

screen: int = 0

Screen index from 0 to 65534 (0xFFFE)

displays: list[Display]

A list of Display instances

scontrol: bytes = b''

SCONTROL data (if type is control)

type: MessageType = 1

The message type. One of display or control.

New in version 0.0.2.

is_broadcast: bool

True if the message is to be “broadcast” to all screens.

(if screen is 0xffff)

New in version 0.0.2.

classmethod broadcast(**kwargs) Message[source]

Create a broadcast message

(with screen set to 0xffff)

New in version 0.0.2.

classmethod parse(msg: bytes) Tuple[Message, bytes][source]

Parse incoming message data to create a Message instance.

Any remaining message data after parsing is returned along with the instance.

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_length is 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_length parameter was added

  • Message 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.

New in version 0.0.4.

exception tslumd.messages.ParseError(msg: str, value: bytes)[source]

Bases: Exception

Raised on errors during message parsing

New in version 0.0.2.

msg: str

Error message

value: bytes

The relevant message bytes containing the error

exception tslumd.messages.MessageParseError(msg: str, value: bytes)[source]

Bases: ParseError

Raised on errors while parsing Message objects

New in version 0.0.2.

exception tslumd.messages.DmsgParseError(msg: str, value: bytes)[source]

Bases: ParseError

Raised on errors while parsing Display objects

New in version 0.0.2.

exception tslumd.messages.DmsgControlParseError(msg: str, value: bytes)[source]

Bases: ParseError

Raised on errors when parsing Display.control data

New in version 0.0.2.

exception tslumd.messages.MessageLengthError[source]

Bases: ValueError

Raised when message length is larger than 2048 bytes

New in version 0.0.4.