work on swr/tuner

This commit is contained in:
DJ2LS 2024-04-26 15:15:23 +02:00
parent b3e1e63cdd
commit 8f6ea4ab3e
4 changed files with 55 additions and 20 deletions

View file

@ -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) {

View file

@ -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,

View file

@ -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()

View file

@ -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):