From 8f6ea4ab3e10b14c8dcbb490e8f5fe4dbd9b26b0 Mon Sep 17 00:00:00 2001 From: DJ2LS Date: Fri, 26 Apr 2024 15:15:23 +0200 Subject: [PATCH] work on swr/tuner --- freedata_gui/src/js/eventHandler.js | 28 ++++++++++++++++++---------- freedata_gui/src/store/stateStore.js | 6 ++++++ freedata_server/radio_manager.py | 14 +++++++------- freedata_server/state_manager.py | 27 ++++++++++++++++++++++++--- 4 files changed, 55 insertions(+), 20 deletions(-) diff --git a/freedata_gui/src/js/eventHandler.js b/freedata_gui/src/js/eventHandler.js index d0a48338..d11ebca6 100644 --- a/freedata_gui/src/js/eventHandler.js +++ b/freedata_gui/src/js/eventHandler.js @@ -51,11 +51,9 @@ export function stateDispatcher(data) { data = JSON.parse(data); //Leave commented when not needed, otherwise can lead to heap overflows due to the amount of data logged //console.debug(data); - if (data["type"] == "state-change" || data["type"] == "state") { + if (data["type"] == "state-change" && data["type"] == "state") { stateStore.modem_connection = "connected"; - stateStore.busy_state = data["is_modem_busy"]; - stateStore.channel_busy = data["channel_busy"]; stateStore.is_codec2_traffic = data["is_codec2_traffic"]; stateStore.is_modem_running = data["is_modem_running"]; @@ -64,23 +62,33 @@ export function stateDispatcher(data) { Math.pow(10, data["audio_dbfs"] / 20) * 100, ); - stateStore.s_meter_strength_raw = Math.round(data["s_meter_strength"]); - stateStore.s_meter_strength_percent = Math.round( - Math.pow(10, data["s_meter_strength"] / 20) * 100, - ); stateStore.channel_busy_slot = data["channel_busy_slot"]; stateStore.beacon_state = data["is_beacon_running"]; stateStore.is_away_from_key = data["is_away_from_key"]; - stateStore.radio_status = data["radio_status"]; - stateStore.frequency = data["radio_frequency"]; - stateStore.mode = data["radio_mode"]; //Reverse entries so most recent is first stateStore.activities = Object.entries(data["activities"]).reverse(); build_HSL(); } + + if (data["type"] == "state-change" && data["type"] == "radio") { + + stateStore.s_meter_strength_raw = Math.round(data["s_meter_strength"]); + stateStore.s_meter_strength_percent = Math.round( + Math.pow(10, data["s_meter_strength"] / 20) * 100, + ); + + + stateStore.radio_status = data["radio_status"]; + stateStore.frequency = data["radio_frequency"]; + stateStore.mode = data["radio_mode"]; + stateStore.swr = data["radio_swr"]; + stateStore.tuner = data["radio_tuner"]; + + + } } export function eventDispatcher(data) { diff --git a/freedata_gui/src/store/stateStore.js b/freedata_gui/src/store/stateStore.js index d3a61245..61e9a98d 100644 --- a/freedata_gui/src/store/stateStore.js +++ b/freedata_gui/src/store/stateStore.js @@ -10,6 +10,10 @@ export const useStateStore = defineStore("stateStore", () => { var mode = ref("-"); var rf_level = ref("10"); var bandwidth = ref("-"); + + var swr = ref(0) + var tuner = ref("-") + var dbfs_level_percent = ref(0); var dbfs_level = ref(0); var radio_status = ref(false); @@ -84,6 +88,8 @@ export const useStateStore = defineStore("stateStore", () => { frequency, mode, bandwidth, + swr, + tuner, dbfs_level, dbfs_level_percent, speed_level, diff --git a/freedata_server/radio_manager.py b/freedata_server/radio_manager.py index a0942b1d..832d277c 100644 --- a/freedata_server/radio_manager.py +++ b/freedata_server/radio_manager.py @@ -47,17 +47,17 @@ class RadioManager: def update_parameters(self): while not self.stop_event.is_set(): parameters = self.radio.get_parameters() - self.state_manager.set("radio_frequency", parameters['frequency']) - self.state_manager.set("radio_mode", parameters['mode']) - self.state_manager.set("radio_bandwidth", parameters['bandwidth']) - self.state_manager.set("radio_rf_level", parameters['rf']) - self.state_manager.set("radio_tuner", parameters['tuner']) + self.state_manager.set_radio("radio_frequency", parameters['frequency']) + self.state_manager.set_radio("radio_mode", parameters['mode']) + self.state_manager.set_radio("radio_bandwidth", parameters['bandwidth']) + self.state_manager.set_radio("radio_rf_level", parameters['rf']) + self.state_manager.set_radio("radio_tuner", parameters['tuner']) if self.state_manager.isTransmitting(): self.radio_alc = parameters['alc'] - self.state_manager.set("radio_swr", parameters['swr']) + self.state_manager.set_radio("radio_swr", parameters['swr']) - self.state_manager.set("s_meter_strength", parameters['strength']) + self.state_manager.set_radio("s_meter_strength", parameters['strength']) time.sleep(self.refresh_rate) def stop(self): self.radio.disconnect() diff --git a/freedata_server/state_manager.py b/freedata_server/state_manager.py index 26577809..d1aeae0e 100644 --- a/freedata_server/state_manager.py +++ b/freedata_server/state_manager.py @@ -7,6 +7,7 @@ class StateManager: # state related settings self.statequeue = statequeue self.newstate = None + self.new_radio = None self.last = time.time() # freedata_server related states @@ -70,6 +71,16 @@ class StateManager: self.newstate = new_state self.sendStateUpdate() + def set_radio(self, key, value): + setattr(self, key, value) + #print(f"State ==> Setting {key} to value {value}") + # only process data if changed + new_radio = self.get_radio_event(True) + if new_radio != self.new_radio: + self.new_radio = new_radio + self.sendStateUpdate() + + def set_channel_slot_busy(self, array): for i in range(0,len(array),1): if not array[i] == self.channel_busy_slot[i]: @@ -89,14 +100,24 @@ class StateManager: "is_beacon_running": self.is_beacon_running, "is_away_from_key": self.is_away_from_key, "radio_status": self.radio_status, - #"radio_frequency": self.radio_frequency, - #"radio_mode": self.radio_mode, - #"s_meter_strength": self.s_meter_strength, "channel_busy_slot": self.channel_busy_slot, "audio_dbfs": self.audio_dbfs, "activities": self.activities_list, "is_modem_busy" : self.getARQ() } + + def get_radio_event(self, isChangedState): + msgtype = "state-change" + if (not isChangedState): + msgtype = "radio" + + return { + "type": msgtype, + "radio_status": self.radio_status, + "radio_frequency": self.radio_frequency, + "radio_mode": self.radio_mode, + "s_meter_strength": self.s_meter_strength, + } # .wait() blocks until the event is set def isTransmitting(self):