I'm using Python to communicate with with a hardware device. The communications protocol generally follow as such:
{header bytes}
{data bytes}
{CRC bytes}
ctypes works very well for the communication protocol because I can define things like:
class Header( BigEndianStructure ):
_pack_ = 1
_fields_ = [("Address", c_ubyte, 8),
("MessageLength", c_ubyte, 8),
("MessageType", c_ubyte, 8)]
def __init__(self):
pass
This takes care of the header. All message bodies can then inherit this message header, reducing redundancy.
class Body( Header):
_fields_ = [("Data", c_ubyte, 8)]
def __init__(self):
super().__init__()
The problem: I don't want to have to define ("CRC8", c_ubyte, 8) in every single subclass.
I'd like to be able to have each subclass automatically generated when the object is created. That way, I don't have to add the trailing bytes manually for each message.