From 87f2cbff2ad1d789f9ca9d4284e7e74d0f12ddcf Mon Sep 17 00:00:00 2001 From: DJ2LS Date: Sat, 11 Nov 2023 20:46:49 +0100 Subject: [PATCH] add first attempt of state handler --- gui/src/js/eventHandler.js | 43 +++++++------------------------------- gui/src/js/event_sock.js | 3 ++- modem/server.py | 7 +++++++ 3 files changed, 17 insertions(+), 36 deletions(-) diff --git a/gui/src/js/eventHandler.js b/gui/src/js/eventHandler.js index 59999bbc..fc3f615d 100644 --- a/gui/src/js/eventHandler.js +++ b/gui/src/js/eventHandler.js @@ -19,15 +19,8 @@ const stateStore = useStateStore(pinia); import { useSettingsStore } from "../store/settingsStore.js"; const settings = useSettingsStore(pinia); -export function eventDispatcher(data) { - data = JSON.parse(data); - - // get ptt state as a first test - // Todo we might use a switch function for data dispatching - stateStore.ptt_state = data.ptt; - - // copied directly from sock.js We need to implement these variables step by step - if (data["command"] == "modem_state") { +export function stateDispatcher(data) { +if (data["command"] == "modem_state") { //console.log(data) stateStore.rx_buffer_length = data["rx_buffer_length"]; @@ -116,34 +109,14 @@ export function eventDispatcher(data) { if (data["speed_list"].length > 0) { prepareStatsDataForStore(data["speed_list"]); } +} +} +export function eventDispatcher(data) { + data = JSON.parse(data); - // TODO: Remove ported objects - /* - let Data = { - mycallsign: data["mycallsign"], - mygrid: data["mygrid"], - //channel_state: data['CHANNEL_STATE'], + // get ptt state as a first test + stateStore.ptt_state = data.ptt; - info: data["info"], - rx_msg_buffer_length: data["rx_msg_buffer_length"], - tx_n_max_retries: data["tx_n_max_retries"], - arq_tx_n_frames_per_burst: data["arq_tx_n_frames_per_burst"], - arq_tx_n_bursts: data["arq_tx_n_bursts"], - arq_tx_n_current_arq_frame: data["arq_tx_n_current_arq_frame"], - arq_tx_n_total_arq_frames: data["arq_tx_n_total_arq_frames"], - arq_rx_frame_n_bursts: data["arq_rx_frame_n_bursts"], - arq_rx_n_current_arq_frame: data["arq_rx_n_current_arq_frame"], - arq_n_arq_frames_per_data_frame: - data["arq_n_arq_frames_per_data_frame"], - arq_bytes_per_minute: data["arq_bytes_per_minute"], - arq_compression_factor: data["arq_compression_factor"], - routing_table: data["routing_table"], - mesh_signalling_table: data["mesh_signalling_table"], - listen: data["listen"], - //speed_table: [{"bpm" : 5200, "snr": -3, "timestamp":1673555399},{"bpm" : 2315, "snr": 12, "timestamp":1673555500}], - }; - */ - } var message = ""; if (data["freedata"] == "modem-message") { diff --git a/gui/src/js/event_sock.js b/gui/src/js/event_sock.js index 18ee69e3..798a3a52 100644 --- a/gui/src/js/event_sock.js +++ b/gui/src/js/event_sock.js @@ -1,4 +1,4 @@ -import { eventDispatcher } from "../js/eventHandler.js"; +import { eventDispatcher, stateDispatcher } from "../js/eventHandler.js"; import { addDataToWaterfall } from "../js/waterfallHandler.js"; function connect(endpoint, dispatcher) { @@ -34,5 +34,6 @@ function connect(endpoint, dispatcher) { } // Initial connection attempts to endpoints +connect("states", stateDispatcher); connect("events", eventDispatcher); connect("fft", addDataToWaterfall); diff --git a/modem/server.py b/modem/server.py index 200a82c7..3d05b52c 100644 --- a/modem/server.py +++ b/modem/server.py @@ -192,6 +192,13 @@ def sock_fft(sock): fft = app.modem_fft.get() transmit_sock_data(fft) +@sock.route('/states') +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() + transmit_sock_data(state) # @app.route('/modem/listen', methods=['POST']) # not needed if we are restarting modem on changing settings