From a6aabd1bc48c698dc328ac5e79b91f6a27e195ac Mon Sep 17 00:00:00 2001 From: DJ2LS Date: Thu, 9 Nov 2023 13:52:27 +0100 Subject: [PATCH] adjusted some command handling --- gui/src/components/main_active_broadcasts.vue | 3 +- gui/src/js/event_sock.js | 55 ++++++++++--------- gui/src/js/rest.js | 2 +- gui/src/js/sock.js | 2 +- modem/modem.py | 3 +- modem/server_commands.py | 2 +- 6 files changed, 34 insertions(+), 33 deletions(-) diff --git a/gui/src/components/main_active_broadcasts.vue b/gui/src/components/main_active_broadcasts.vue index e0ebfdc3..d07db1b7 100644 --- a/gui/src/components/main_active_broadcasts.vue +++ b/gui/src/components/main_active_broadcasts.vue @@ -11,12 +11,11 @@ const settings = useSettingsStore(pinia); import { useStateStore } from "../store/stateStore.js"; const state = useStateStore(pinia); -import { sendCQ, sendPing, startBeacon, stopBeacon } from "../js/sock.js"; +import { sendPing, startBeacon, stopBeacon } from "../js/sock.js"; import { postToServer } from "../js/rest.js"; function transmitCQ() { - sendCQ(); postToServer("localhost", 5000, "modem/cqcqcq", null); } diff --git a/gui/src/js/event_sock.js b/gui/src/js/event_sock.js index 8da387e4..4b77e4ab 100644 --- a/gui/src/js/event_sock.js +++ b/gui/src/js/event_sock.js @@ -3,37 +3,40 @@ let retries = 0; let maxRetries = 15; function connect() { - socket = new WebSocket("ws://localhost:5000/events"); - // handle opening - socket.addEventListener("open", function (event) { - console.log("Connected to the WebSocket server"); - retries = 0; // Reset the retries back to 0 since the connection was successful - }); + socket = new WebSocket("ws://localhost:5000/events"); - // handle data - socket.addEventListener("message", function (event) { - console.log("Message from server:", event.data); - }); + // handle opening + socket.addEventListener('open', function (event) { + console.log('Connected to the WebSocket server'); + retries = 0; // Reset the retries back to 0 since the connection was successful + }); - // handle errors - socket.addEventListener("error", function (event) { - console.error("WebSocket error:", event); - }); + // handle data + socket.addEventListener('message', function (event) { + console.log('Message from server:', event.data); + console.log('Message from server:', event); - // handle closing and reconnect - socket.addEventListener("close", function (event) { - console.log("WebSocket connection closed:", event.code); + }); - // Reconnect handler - if (!event.wasClean && retries < maxRetries) { - setTimeout(() => { - console.log("Reconnecting to websocket. Attempt: " + retries); - connect(); - }, 1000); - retries++; - } - }); + // handle errors + socket.addEventListener('error', function (event) { + console.error('WebSocket error:', event); + }); + + // handle closing and reconnect + socket.addEventListener('close', function (event) { + console.log('WebSocket connection closed:', event.code); + + // Reconnect handler + if (!event.wasClean && retries < maxRetries) { + setTimeout(() => { + console.log("Reconnecting to websocket. Attempt: " + retries) + connect(); + }, 1000); + retries++; + } + }); } // Initial connection attempt diff --git a/gui/src/js/rest.js b/gui/src/js/rest.js index fcecbb02..d7afa170 100644 --- a/gui/src/js/rest.js +++ b/gui/src/js/rest.js @@ -19,7 +19,7 @@ export async function getFromServer(host, port, endpoint) { const data = await response.json(); // move received data to our data dispatcher - restDataDispatcher(endpoint, data.data); + restDataDispatcher(endpoint, data); } export async function postToServer(host, port, endpoint, data) { diff --git a/gui/src/js/sock.js b/gui/src/js/sock.js index cc1316b5..910e05ef 100644 --- a/gui/src/js/sock.js +++ b/gui/src/js/sock.js @@ -34,7 +34,7 @@ var setTxAudioLevelOnce = true; var setRxAudioLevelOnce = true; // network connection Timeout -setTimeout(connectModem, 2000); +//setTimeout(connectModem, 2000); function connectModem() { //exports.connectModem = function(){ diff --git a/modem/modem.py b/modem/modem.py index d5661229..577318f8 100644 --- a/modem/modem.py +++ b/modem/modem.py @@ -583,7 +583,6 @@ class RF: tci_timeout_reached = False else: tci_timeout_reached = True - threading.Event().wait(0.01) # if we're transmitting FreeDATA signals, reset channel busy state ModemParam.channel_busy = False @@ -598,7 +597,6 @@ class RF: self.modem_transmit_queue.task_done() Modem.transmitting = False - threading.Event().set() end_of_transmission = time.time() transmission_time = end_of_transmission - start_of_transmission @@ -843,6 +841,7 @@ class RF: ) except Exception as e: self.log.warning("[MDM] [demod_audio] Stream not active anymore", e=e) + return nin def init_codec2(self): diff --git a/modem/server_commands.py b/modem/server_commands.py index eed6a0cc..8040f21b 100644 --- a/modem/server_commands.py +++ b/modem/server_commands.py @@ -1,4 +1,4 @@ from queues import DATA_QUEUE_TRANSMIT def cqcqcq(): - DATA_QUEUE_TRANSMIT.put(["CQ"]) \ No newline at end of file + DATA_QUEUE_TRANSMIT.put(["CQ"])