2023-11-11 19:01:15 +00:00
|
|
|
|
2023-11-12 18:56:15 +00:00
|
|
|
import ujson as json
|
2023-11-11 19:01:15 +00:00
|
|
|
class STATES:
|
|
|
|
def __init__(self, statequeue):
|
|
|
|
self.statequeue = statequeue
|
2023-11-14 18:26:11 +00:00
|
|
|
self.newstate = None
|
2023-11-11 19:01:15 +00:00
|
|
|
self.channel_busy = False
|
|
|
|
self.channel_busy_slot = [False, False, False, False, False]
|
|
|
|
self.is_codec2_traffic = False
|
2023-11-12 18:56:15 +00:00
|
|
|
self.is_modem_running = False
|
2023-11-12 22:22:53 +00:00
|
|
|
self.is_beacon_running = False
|
2023-11-13 19:26:27 +00:00
|
|
|
self.is_arq_state = False
|
|
|
|
self.is_arq_session = False
|
|
|
|
self.arq_session_state = 'disconnected'
|
2023-11-13 17:11:55 +00:00
|
|
|
self.audio_dbfs = 0
|
2023-11-12 22:22:53 +00:00
|
|
|
|
2023-11-11 19:01:15 +00:00
|
|
|
def set(self, key, value):
|
|
|
|
setattr(self, key, value)
|
2023-11-14 18:26:11 +00:00
|
|
|
|
|
|
|
# only process data if changed
|
|
|
|
new_state = self.getAsJSON()
|
|
|
|
if new_state != self.newstate:
|
|
|
|
self.statequeue.put(new_state)
|
|
|
|
self.newstate = new_state
|
2023-11-11 19:01:15 +00:00
|
|
|
|
|
|
|
def getAsJSON(self):
|
2023-11-12 18:56:15 +00:00
|
|
|
return json.dumps({
|
2023-11-11 19:01:15 +00:00
|
|
|
"freedata-message": "state-change",
|
|
|
|
"channel_busy": self.channel_busy,
|
2023-11-12 18:56:15 +00:00
|
|
|
"is_codec2_traffic": self.is_codec2_traffic,
|
|
|
|
"is_modem_running": self.is_modem_running,
|
2023-11-12 22:22:53 +00:00
|
|
|
"is_beacon_running": self.is_beacon_running,
|
|
|
|
|
2023-11-12 18:56:15 +00:00
|
|
|
})
|