54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
from RoboidControl.Participants.ParticipantUDP import ParticipantUDP
|
|
from RoboidControl.Messages.ParticipantMsg import ParticipantMsg
|
|
from RoboidControl.Messages.NetworkIdMsg import NetworkIdMsg
|
|
from RoboidControl.Messages.ThingMsg import ThingMsg
|
|
from RoboidControl.Things.TemperatureSensor import TemperatureSensor
|
|
from RoboidControl.Thing import Thing
|
|
|
|
from typing import Optional
|
|
|
|
class SiteServer(ParticipantUDP):
|
|
"""! A site server is a participant which provides a shared simulated environment
|
|
"""
|
|
|
|
name = "Site Server"
|
|
|
|
#region Init
|
|
|
|
def __init__(self, port: int = 7681):
|
|
"""! Create a new site server
|
|
@param port The port of which to receive the messages
|
|
"""
|
|
super().__init__(local_port = port)
|
|
self.isolated = False # site servers are never isolated
|
|
self.publishInterval = 0
|
|
|
|
#endregion Init
|
|
|
|
#region Update
|
|
#endregion Update
|
|
|
|
#region Receive
|
|
|
|
def ProcessParticipantMsg(self, sender, msg):
|
|
ParticipantUDP.ProcessParticipantMsg(self, sender, msg)
|
|
if msg.network_id != sender.network_id:
|
|
self.Send(sender, NetworkIdMsg(sender.network_id))
|
|
|
|
def ProcessNetworkIdMsg(self, sender, msg):
|
|
pass
|
|
|
|
def ProcessThingMsg(self, sender, msg: ThingMsg):
|
|
thing: Optional[Thing] = sender.Get(msg.thing_id)
|
|
if thing is None:
|
|
if msg.parent_id != 0:
|
|
parent = sender.Get(msg.parent_id)
|
|
if parent is not None:
|
|
print(f'Could not find parent [{msg.network_id}/{msg.parent_id}]')
|
|
else:
|
|
parent = None
|
|
|
|
Thing(owner=sender, thing_type=msg.thing_type, thing_id=msg.thing_id, parent = parent)
|
|
|
|
|
|
#endregion Receive |