def handleUdpMessage(self, message, clientAddr):
self.logger.debug(" handling decoded UDP message from device")
isNewSession = False
if message.deviceId in self.sessions:
session = self.sessions[message.deviceId]
else:
self.logger.debug(" attemping to create new session for UDP device: %s", binascii.hexlify(message.deviceId))
session = IotSession(message.deviceId, IotSession.TYPE_UDP)
isNewSession = True
counter = self.getCounter(message.deviceId)
self.logger.debug(" Validating counters: local={0}, incoming={1}".format(counter.udpReceivedCounter, message.counter1))
if (message.counter1 > counter.udpReceivedCounter):
self.logger.debug(" Counter OK. updating session for device %s", binascii.hexlify(message.deviceId))
session.lastUdpMessage = message
session.lastPayload = message.payload
session.clientAddr = clientAddr
session.lastUpdateTime = datetime.datetime.now()
counter.udpReceivedCounter = message.counter1
if isNewSession:
self.sessions[message.deviceId] = session
self.logger.info("Received valid UDP message from {0}:{1}, deviceId={2}, payload={3}. Calling server handler.".format(clientAddr[0], clientAddr[1], binascii.hexlify(message.deviceId), message.payload))
self.passToHandler(message.deviceId, message.payload)
else:
self.logger.warning("Invalid counter in message from device {0}, local={1}, incoming={2} - discarding".format(binascii.hexlify(message.deviceId), counter.udpReceivedCounter, message.counter1))
评论列表
文章目录