From cfe0840863857199c1c4e2a1dcb73b31b19ac908 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 30 Dec 2024 14:57:03 +0100 Subject: [PATCH] Comitting last changes --- Messages.py | 33 ++++++++++++++++++++++----------- SiteServer.py | 22 +++++++++++----------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/Messages.py b/Messages.py index f8baa83..7bfec70 100644 --- a/Messages.py +++ b/Messages.py @@ -46,23 +46,34 @@ class NetworkIdMsg(IMessage): length = 2 def __init__(self, network_id): - self.network_id = None - if isinstance(network_id, int): - self.network_id = network_id - elif isinstance(network_id, bytes): - self.network_id = network_id[1] + # self.network_id = None + # if isinstance(network_id, int): + # self.network_id = network_id + # elif isinstance(network_id, bytes): + self.network_id = network_id[1] - def Serialize(self, buffer_ref): - if self.network_id is None: + # def Serialize(self, buffer_ref): + # if self.network_id is None: + # return 0 + + # buffer: bytearray = buffer_ref[0] + # buffer[0:NetworkIdMsg.length] = [ + # NetworkIdMsg.id, + # self.network_id + # ] + # return NetworkIdMsg.length + + def SendTo(participant, network_id): + if network_id is None: return 0 - buffer: bytearray = buffer_ref[0] - buffer[0:NetworkIdMsg.length] = [ + participant.buffer[0:2] = [ NetworkIdMsg.id, - self.network_id + network_id ] return NetworkIdMsg.length + class InvestigateMsg(): id = 0x81 length = 3 @@ -201,7 +212,7 @@ class BinaryMsg(): return False participant.buffer[0:length] = [ - id, + BinaryMsg.id, participant.network_id, thing.id ] diff --git a/SiteServer.py b/SiteServer.py index 137e4e0..2493004 100644 --- a/SiteServer.py +++ b/SiteServer.py @@ -18,6 +18,17 @@ class SiteServer(Participant): return super().Update(currentTime) + def ProcessNetworkIdMsg(self, thing_msg): + self.network_id = thing_msg.network_id + # HACK: send the root things first + for thing in Thing.allThings: + if thing is not None and thing.parent_id == 0: + self.SendThingInfo(thing) + # then sent the rest + for thing in Thing.allThings: + if thing is not None and thing.parent_id != 0: + self.SendThingInfo(thing) + def SendThingInfo(self, thing, recurse = False): if thing is None: return @@ -35,17 +46,6 @@ class SiteServer(Participant): for child in thing.children: self.SendThingInfo(child, True) - def ProcessNetworkIdMsg(self, thing_msg): - self.network_id = thing_msg.network_id - # HACK: send the root things first - for thing in Thing.allThings: - if thing is not None and thing.parent_id == 0: - self.SendThingInfo(thing) - # then sent the rest - for thing in Thing.allThings: - if thing is not None and thing.parent_id != 0: - self.SendThingInfo(thing) - def ProcessInvestigateMsg(self, msg: Messages.InvestigateMsg): thing = Thing.Get(msg.network_id, msg.thing_id) if thing is not None: