packet Module

cbus.protocol.packet.decode_packet(data: bytes, checksum: bool = True, strict: bool = True, from_pci: bool = True) → Tuple[Union[cbus.protocol.base_packet.BasePacket, cbus.protocol.cal.extended.ExtendedCAL, cbus.protocol.cal.identify.IdentifyCAL, cbus.protocol.cal.reply.ReplyCAL, cbus.protocol.cal.recall.RecallCAL, None], int]

Decodes a single C-Bus Serial Interface packet.

The return value is a tuple:

  1. The packet that was parsed, or None if there was no packet that could be parsed.
  2. The buffer position that we parsed up to. This may be non-zero even if the packet was None (eg: Cancel request).

Note: this decoder does not support unaddressed packets (such as Standard Format Status Replies).

Note: Direct Command Access causes this method to return AnyCAL instead of a BasePacket.

Parameters:
  • data – The data to parse, in encapsulated serial format.
  • checksum – If True, requires a checksum for all packets
  • strict – If True, returns InvalidPacket whenever checksum is incorrect. Otherwise, only emits a warning.
  • from_pci

    If True, parses the packet as if it were sent from/by a PCI – if your software was sent packets by a PCI, this is what you want.

    If False, this parses the packet as if it were sent to a PCI; parsing messages that software expecting to communicate with a PCI sends. This could be used to build a fake PCI, or analyse the behaviour of other C-Bus software.

cbus.protocol.packet.int2byte()

S.pack(v1, v2, …) -> bytes

Return a bytes object containing values v1, v2, … packed according to the format string S.format. See help(struct) for more on format strings.