Send state messages semi-frequently even if there's no changes

This commit is contained in:
Mashintime 2023-11-15 17:34:26 -05:00
parent cf522bd41e
commit c19586369e

View file

@ -1,4 +1,4 @@
import time
import ujson as json
class STATES:
def __init__(self, statequeue):
@ -13,15 +13,19 @@ class STATES:
self.is_arq_session = False
self.arq_session_state = 'disconnected'
self.audio_dbfs = 0
self.last = time.time()
def set(self, key, value):
setattr(self, key, value)
updateCandence = 3
# only process data if changed
# but also send an update if more than a 'updateCadence' second(s) has lapsed
# Otherwise GUI can't tell if modem is active due to lack of state messages on startup
new_state = self.getAsJSON()
if new_state != self.newstate:
if new_state != self.newstate or time.time() - self.last > updateCandence:
self.statequeue.put(new_state)
self.newstate = new_state
self.last=time.time()
def getAsJSON(self):
return json.dumps({