From aef44b1536712164821d2fdc9d31d881e3cf0036 Mon Sep 17 00:00:00 2001 From: DJ2LS Date: Sun, 12 Nov 2023 19:56:15 +0100 Subject: [PATCH] first test with states --- gui/src/js/eventHandler.js | 15 +++++++++++---- gui/src/store/stateStore.js | 4 ++-- modem/server.py | 2 +- modem/service_manager.py | 8 +++++++- modem/state_manager.py | 10 ++++++---- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/gui/src/js/eventHandler.js b/gui/src/js/eventHandler.js index 3c3948c5..dc279e3b 100644 --- a/gui/src/js/eventHandler.js +++ b/gui/src/js/eventHandler.js @@ -20,8 +20,16 @@ import { useSettingsStore } from "../store/settingsStore.js"; const settings = useSettingsStore(pinia); export function stateDispatcher(data) { - if (data["command"] == "modem_state") { - //console.log(data) + console.log(data) + + if (data["freedata-message"] == "state-change") { + + stateStore.channel_busy = data["channel_busy"]; + stateStore.is_codec2_traffic = data["is_codec2_traffic"]; + stateStore.is_modem_running = data["is_modem_running"]; + + + /* stateStore.rx_buffer_length = data["rx_buffer_length"]; stateStore.frequency = data["frequency"]; @@ -58,7 +66,6 @@ export function stateDispatcher(data) { stateStore.ptt_state = data["ptt_state"]; stateStore.speed_level = data["speed_level"]; stateStore.fft = JSON.parse(data["fft"]); - stateStore.channel_busy = data["channel_busy"]; stateStore.channel_busy_slot = data["channel_busy_slot"]; addDataToWaterfall(JSON.parse(data["fft"])); @@ -96,7 +103,6 @@ export function stateDispatcher(data) { stateStore.alc = data["alc"]; stateStore.rf_level = data["rf_level"]; - stateStore.is_codec2_traffic = data["is_codec2_traffic"]; stateStore.arq_session_state = data["arq_session"]; stateStore.arq_state = data["arq_state"]; @@ -109,6 +115,7 @@ export function stateDispatcher(data) { if (data["speed_list"].length > 0) { prepareStatsDataForStore(data["speed_list"]); } + */ } } export function eventDispatcher(data) { diff --git a/gui/src/store/stateStore.js b/gui/src/store/stateStore.js index 8c7d5508..43ab47da 100644 --- a/gui/src/store/stateStore.js +++ b/gui/src/store/stateStore.js @@ -25,7 +25,7 @@ export const useStateStore = defineStore("stateStore", () => { var modem_connection = ref("disconnected"); var modemStartCount = ref(0); - var modem_running_state = ref("--------"); + var is_modem_running = ref(); var arq_total_bytes = ref(0); var arq_transmission_percent = ref(0); @@ -128,7 +128,7 @@ export const useStateStore = defineStore("stateStore", () => { arq_seconds_until_timeout, arq_seconds_until_timeout_percent, modem_connection, - modem_running_state, + is_modem_running, arq_session_state, is_codec2_traffic, rf_level, diff --git a/modem/server.py b/modem/server.py index 3d05b52c..76f2b107 100644 --- a/modem/server.py +++ b/modem/server.py @@ -197,7 +197,7 @@ def sock_states(sock): # it seems we have to keep the logics inside a loop, otherwise connection will be terminated client_list.add(sock) while True: - state = app.states.get() + state = app.state_queue.get() transmit_sock_data(state) diff --git a/modem/service_manager.py b/modem/service_manager.py index 36ca4cac..03916611 100644 --- a/modem/service_manager.py +++ b/modem/service_manager.py @@ -28,12 +28,16 @@ class SM: if cmd in ['start'] and not self.modem: audio_test = audio.test_audio_devices(self.config['AUDIO']['input_device'], self.config['AUDIO']['output_device']) print(audio_test) - if False not in audio_test and None not in audio_test: + if False not in audio_test and None not in audio_test and not self.states.is_modem_running: self.log.info("starting modem....") self.modem = modem.RF(self.config, self.modem_events, self.modem_fft, self.modem_service, self.states) self.data_handler = data_handler.DATA(self.config, self.modem_events) + self.states.set("is_modem_running", True) + else: self.log.warning("starting modem failed", input_test=audio_test[0], output_test=audio_test[1]) + self.states.set("is_modem_running", False) + else: print("--------------------------------------") @@ -42,4 +46,6 @@ class SM: del self.data_handler self.modem = False self.data_handler = False + self.states.set("is_modem_running", False) + threading.Event().wait(0.5) diff --git a/modem/state_manager.py b/modem/state_manager.py index 9f8fad28..174b48eb 100644 --- a/modem/state_manager.py +++ b/modem/state_manager.py @@ -1,5 +1,5 @@ - +import ujson as json class STATES: def __init__(self, statequeue): self.statequeue = statequeue @@ -9,14 +9,16 @@ class STATES: self.channel_busy = False self.channel_busy_slot = [False, False, False, False, False] self.is_codec2_traffic = False + self.is_modem_running = False def set(self, key, value): setattr(self, key, value) self.statequeue.put(self.getAsJSON()) def getAsJSON(self): - return { + return json.dumps({ "freedata-message": "state-change", "channel_busy": self.channel_busy, - "is_codec2_traffic": self.is_codec2_traffic - } \ No newline at end of file + "is_codec2_traffic": self.is_codec2_traffic, + "is_modem_running": self.is_modem_running, + }) \ No newline at end of file