2025-04-06 12:42:10 +02:00

90 lines
2.7 KiB
Python

import Messages.LowLevelMessages as LowLevelMessages
#from Thing import Thing
class IMessage:
id = 0x00
## Serialize the message into the given buffer
#
## @returns: the length of the message
def Serialize(buffer):
return 0
def SendTo(self, participant):
buffer_size = self.Serialize([participant.buffer])
if buffer_size == 0:
return False
return participant.SendBuffer(buffer_size)
def Publish(self, participant):
bufferSize = self.Serialize([participant.buffer])
if bufferSize == 0:
return False
return participant.PublishBuffer(bufferSize)
# class InvestigateMsg():
# id = 0x81
# length = 3
# def __init__(self, buffer):
# self.thing_id = buffer[2]
# class PoseMsg(IMessage):
# """! Message to communicate the pose of the thing
# The pose is in local space relative to the parent.
# If there is not parent (the thing is a root thing), the pose will be in world space.
# """
# ## The message ID
# id = 0x10
# ## The length of the message
# length = 4
# def __init__(self, thing):
# self.thing = thing
# def Serialize(self, buffer_ref):
# if self.thing is None:
# return 0
# buffer: bytearray = buffer_ref[0]
# buffer[0:PoseMsg.length] = [
# PoseMsg.id,
# 0, # Network id
# self.thing.id,
# self.thing.pose_updated
# ]
# ix = [4]
# if self.thing.pose_updated & Thing.Position:
# LowLevelMessages.SendSpherical(buffer, ix, self.thing.position)
# if self.thing.pose_updated & Thing.Orientation:
# LowLevelMessages.SendQuat32(buffer, ix, self.thing.orientation)
# if self.thing.pose_updated & Thing.LinearVelocity:
# LowLevelMessages.SendSpherical(buffer, ix, self.thing.linearVelocity)
# if self.thing.pose_updated & Thing.AngularVelocity:
# LowLevelMessages.SendSpherical(buffer, ix, self.thing.angularVelocity)
# return ix[0]
# class BinaryMsg():
# id = 0xB1
# def __init__(self, buffer):
# self.thing_id = buffer[2]
# self.thing = Thing.Get(self.thing_id)
# self.data = buffer[3:]
# def SendTo(participant, thing, data: bytearray):
# length = 3
# if thing is None or data is None:
# return False
# participant.buffer[0:length] = [
# BinaryMsg.id,
# 0, # network_id,
# thing.id
# ]
# full_length = length + len(data)
# participant.buffer[length:full_length] = data
# participant.SendBuffer(full_length)
# return True