Comitting last changes
This commit is contained in:
parent
d23ff21aa9
commit
cfe0840863
33
Messages.py
33
Messages.py
@ -46,23 +46,34 @@ class NetworkIdMsg(IMessage):
|
|||||||
length = 2
|
length = 2
|
||||||
|
|
||||||
def __init__(self, network_id):
|
def __init__(self, network_id):
|
||||||
self.network_id = None
|
# self.network_id = None
|
||||||
if isinstance(network_id, int):
|
# if isinstance(network_id, int):
|
||||||
self.network_id = network_id
|
# self.network_id = network_id
|
||||||
elif isinstance(network_id, bytes):
|
# elif isinstance(network_id, bytes):
|
||||||
self.network_id = network_id[1]
|
self.network_id = network_id[1]
|
||||||
|
|
||||||
def Serialize(self, buffer_ref):
|
# def Serialize(self, buffer_ref):
|
||||||
if self.network_id is None:
|
# 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
|
return 0
|
||||||
|
|
||||||
buffer: bytearray = buffer_ref[0]
|
participant.buffer[0:2] = [
|
||||||
buffer[0:NetworkIdMsg.length] = [
|
|
||||||
NetworkIdMsg.id,
|
NetworkIdMsg.id,
|
||||||
self.network_id
|
network_id
|
||||||
]
|
]
|
||||||
return NetworkIdMsg.length
|
return NetworkIdMsg.length
|
||||||
|
|
||||||
|
|
||||||
class InvestigateMsg():
|
class InvestigateMsg():
|
||||||
id = 0x81
|
id = 0x81
|
||||||
length = 3
|
length = 3
|
||||||
@ -201,7 +212,7 @@ class BinaryMsg():
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
participant.buffer[0:length] = [
|
participant.buffer[0:length] = [
|
||||||
id,
|
BinaryMsg.id,
|
||||||
participant.network_id,
|
participant.network_id,
|
||||||
thing.id
|
thing.id
|
||||||
]
|
]
|
||||||
|
@ -18,6 +18,17 @@ class SiteServer(Participant):
|
|||||||
|
|
||||||
return super().Update(currentTime)
|
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):
|
def SendThingInfo(self, thing, recurse = False):
|
||||||
if thing is None:
|
if thing is None:
|
||||||
return
|
return
|
||||||
@ -35,17 +46,6 @@ class SiteServer(Participant):
|
|||||||
for child in thing.children:
|
for child in thing.children:
|
||||||
self.SendThingInfo(child, True)
|
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):
|
def ProcessInvestigateMsg(self, msg: Messages.InvestigateMsg):
|
||||||
thing = Thing.Get(msg.network_id, msg.thing_id)
|
thing = Thing.Get(msg.network_id, msg.thing_id)
|
||||||
if thing is not None:
|
if thing is not None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user