RoboidControl-python/ThingMsg.py
Pascal Serrarens e218e0ea51 Event handling
2025-01-20 19:26:30 +01:00

37 lines
1005 B
Python

from .Messages import IMessage
class ThingMsg(IMessage):
id = 0x80
length = 5
network_id = None
thing_id = None
thing_type = None
parent_id = None
def __init__(self, data, thing=None):
if isinstance(data, bytes):
self.network_id = data[1]
self.thing_id = data[2]
self.thing_type = data[3]
self.parent_id = data[4]
else:
self.network_id = data
if thing is not None:
self.thing_id = thing.id
self.thing_type = thing.type
self.parent_id = thing.parent_id
def Serialize(self, buffer_ref):
if self.network_id is None or self.thing_id is None:
return 0
buffer: bytearray = buffer_ref[0]
buffer[0:ThingMsg.length] = [
ThingMsg.id,
self.network_id,
self.thing_id,
self.thing_type,
self.parent_id
]
return ThingMsg.length