From 7ee67070475ab49c76201361bfee1898e128329d Mon Sep 17 00:00:00 2001 From: codefactor-io Date: Thu, 9 Nov 2023 14:48:51 +0000 Subject: [PATCH] [CodeFactor] Apply fixes --- gui/src/js/eventHandler.js | 579 ++++++++++++++++++------------------- gui/src/js/event_sock.js | 7 +- gui/src/js/rest.js | 2 - gui/src/js/sock.js | 2 - 4 files changed, 282 insertions(+), 308 deletions(-) diff --git a/gui/src/js/eventHandler.js b/gui/src/js/eventHandler.js index 3e0c4f60..0d2e237d 100644 --- a/gui/src/js/eventHandler.js +++ b/gui/src/js/eventHandler.js @@ -19,102 +19,100 @@ const stateStore = useStateStore(pinia); import { useSettingsStore } from "../store/settingsStore.js"; const settings = useSettingsStore(pinia); +export function eventDispatcher(data) { + console.log(data); + if (data["command"] == "modem_state") { + //console.log(data) -export function eventDispatcher(data){ -console.log(data) -if (data["command"] == "modem_state") { - //console.log(data) + stateStore.rx_buffer_length = data["rx_buffer_length"]; + stateStore.frequency = data["frequency"]; + stateStore.busy_state = data["modem_state"]; + stateStore.arq_state = data["arq_state"]; + stateStore.mode = data["mode"]; + stateStore.bandwidth = data["bandwidth"]; + stateStore.tx_audio_level = data["tx_audio_level"]; + stateStore.rx_audio_level = data["rx_audio_level"]; + // if audio level is different from config one, send new audio level to modem + //console.log(parseInt(stateStore.tx_audio_level)) + //console.log(parseInt(settings.tx_audio_level)) + if ( + parseInt(stateStore.tx_audio_level) !== + parseInt(settings.tx_audio_level) && + setTxAudioLevelOnce === true + ) { + setTxAudioLevelOnce = false; + console.log(setTxAudioLevelOnce); + setTxAudioLevel(settings.tx_audio_level); + } - stateStore.rx_buffer_length = data["rx_buffer_length"]; - stateStore.frequency = data["frequency"]; - stateStore.busy_state = data["modem_state"]; - stateStore.arq_state = data["arq_state"]; - stateStore.mode = data["mode"]; - stateStore.bandwidth = data["bandwidth"]; - stateStore.tx_audio_level = data["tx_audio_level"]; - stateStore.rx_audio_level = data["rx_audio_level"]; - // if audio level is different from config one, send new audio level to modem - //console.log(parseInt(stateStore.tx_audio_level)) - //console.log(parseInt(settings.tx_audio_level)) - if ( - parseInt(stateStore.tx_audio_level) !== - parseInt(settings.tx_audio_level) && - setTxAudioLevelOnce === true - ) { - setTxAudioLevelOnce = false; - console.log(setTxAudioLevelOnce); - setTxAudioLevel(settings.tx_audio_level); - } + if ( + parseInt(stateStore.rx_audio_level) !== + parseInt(settings.rx_audio_level) && + setRxAudioLevelOnce === true + ) { + setRxAudioLevelOnce = false; + console.log(setRxAudioLevelOnce); + setRxAudioLevel(settings.rx_audio_level); + } - if ( - parseInt(stateStore.rx_audio_level) !== - parseInt(settings.rx_audio_level) && - setRxAudioLevelOnce === true - ) { - setRxAudioLevelOnce = false; - console.log(setRxAudioLevelOnce); - setRxAudioLevel(settings.rx_audio_level); - } + stateStore.dbfs_level = data["audio_dbfs"]; + 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"]; - stateStore.dbfs_level = data["audio_dbfs"]; - 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"])); - addDataToWaterfall(JSON.parse(data["fft"])); + if (data["scatter"].length > 0) { + stateStore.scatter = data["scatter"]; + } + // s meter strength + stateStore.s_meter_strength_raw = data["strength"]; + if (stateStore.s_meter_strength_raw == "") { + stateStore.s_meter_strength_raw = "Unsupported"; + stateStore.s_meter_strength_percent = 0; + } else { + // https://www.moellerstudios.org/converting-amplitude-representations/ + stateStore.s_meter_strength_percent = Math.round( + Math.pow(10, stateStore.s_meter_strength_raw / 20) * 100, + ); + } - if (data["scatter"].length > 0) { - stateStore.scatter = data["scatter"]; - } - // s meter strength - stateStore.s_meter_strength_raw = data["strength"]; - if (stateStore.s_meter_strength_raw == "") { - stateStore.s_meter_strength_raw = "Unsupported"; - stateStore.s_meter_strength_percent = 0; - } else { - // https://www.moellerstudios.org/converting-amplitude-representations/ - stateStore.s_meter_strength_percent = Math.round( - Math.pow(10, stateStore.s_meter_strength_raw / 20) * 100, - ); - } + stateStore.dbfs_level_percent = Math.round( + Math.pow(10, stateStore.dbfs_level / 20) * 100, + ); + stateStore.dbfs_level = Math.round(stateStore.dbfs_level); - stateStore.dbfs_level_percent = Math.round( - Math.pow(10, stateStore.dbfs_level / 20) * 100, - ); - stateStore.dbfs_level = Math.round(stateStore.dbfs_level); + stateStore.arq_total_bytes = data["total_bytes"]; + stateStore.heard_stations = data["stations"].sort( + sortByPropertyDesc("timestamp"), + ); + stateStore.dxcallsign = data["dxcallsign"]; - stateStore.arq_total_bytes = data["total_bytes"]; - stateStore.heard_stations = data["stations"].sort( - sortByPropertyDesc("timestamp"), - ); - stateStore.dxcallsign = data["dxcallsign"]; + stateStore.beacon_state = data["beacon_state"]; + stateStore.audio_recording = data["audio_recording"]; - stateStore.beacon_state = data["beacon_state"]; - stateStore.audio_recording = data["audio_recording"]; + stateStore.hamlib_status = data["hamlib_status"]; + stateStore.alc = data["alc"]; + stateStore.rf_level = data["rf_level"]; - stateStore.hamlib_status = data["hamlib_status"]; - stateStore.alc = data["alc"]; - stateStore.rf_level = data["rf_level"]; + stateStore.is_codec2_traffic = data["is_codec2_traffic"]; - stateStore.is_codec2_traffic = data["is_codec2_traffic"]; + stateStore.arq_session_state = data["arq_session"]; + stateStore.arq_state = data["arq_state"]; + stateStore.arq_transmission_percent = data["arq_transmission_percent"]; + stateStore.arq_seconds_until_finish = data["arq_seconds_until_finish"]; + stateStore.arq_seconds_until_timeout = data["arq_seconds_until_timeout"]; + stateStore.arq_seconds_until_timeout_percent = + (stateStore.arq_seconds_until_timeout / 180) * 100; - stateStore.arq_session_state = data["arq_session"]; - stateStore.arq_state = data["arq_state"]; - stateStore.arq_transmission_percent = data["arq_transmission_percent"]; - stateStore.arq_seconds_until_finish = data["arq_seconds_until_finish"]; - stateStore.arq_seconds_until_timeout = - data["arq_seconds_until_timeout"]; - stateStore.arq_seconds_until_timeout_percent = - (stateStore.arq_seconds_until_timeout / 180) * 100; + if (data["speed_list"].length > 0) { + prepareStatsDataForStore(data["speed_list"]); + } - if (data["speed_list"].length > 0) { - prepareStatsDataForStore(data["speed_list"]); - } - - // TODO: Remove ported objects - /* + // TODO: Remove ported objects + /* let Data = { mycallsign: data["mycallsign"], mygrid: data["mygrid"], @@ -139,240 +137,223 @@ if (data["command"] == "modem_state") { //speed_table: [{"bpm" : 5200, "snr": -3, "timestamp":1673555399},{"bpm" : 2315, "snr": 12, "timestamp":1673555500}], }; */ + } - } + var message = ""; + if (data["freedata"] == "modem-message") { + // break early if we received a dummy callsign + // thats a kind of hotfix, as long as the modem isnt handling this better + if (data["dxcallsign"] == "AA0AA-0" || data["dxcallsign"] == "ZZ9YY-0") { + return; + } + console.log(data); - var message = ""; - if (data["freedata"] == "modem-message") { - // break early if we received a dummy callsign - // thats a kind of hotfix, as long as the modem isnt handling this better - if ( - data["dxcallsign"] == "AA0AA-0" || - data["dxcallsign"] == "ZZ9YY-0" - ) { - return; + switch (data["fec"]) { + case "is_writing": + // RX'd FECiswriting + break; + + case "broadcast": + // RX'd FEC BROADCAST + var encoded_data = atob_FD(data["data"]); + var splitted_data = encoded_data.split(split_char); + var messageArray = []; + if (splitted_data[0] == "m") { + messageArray.push(data); + console.log(data); } + break; + } - console.log(data); + switch (data["cq"]) { + case "transmitting": + // CQ TRANSMITTING + displayToast("success", "bi-arrow-left-right", "Transmitting CQ", 5000); + break; - switch (data["fec"]) { - case "is_writing": - // RX'd FECiswriting + case "received": + // CQ RECEIVED + message = "CQ from " + data["dxcallsign"]; + displayToast("success", "bi-person-arms-up", message, 5000); + break; + } + + switch (data["qrv"]) { + case "transmitting": + // QRV TRANSMITTING + displayToast( + "info", + "bi-person-raised-hand", + "Transmitting QRV ", + 5000, + ); + break; + + case "received": + // QRV RECEIVED + message = "QRV from " + data["dxcallsign"] + " | " + data["dxgrid"]; + displayToast("success", "bi-person-raised-hand", message, 5000); + break; + } + + switch (data["beacon"]) { + case "transmitting": + // BEACON TRANSMITTING + displayToast( + "success", + "bi-broadcast-pin", + "Transmitting beacon", + 5000, + ); + break; + + case "received": + // BEACON RECEIVED + newBeaconReceived(data); + + message = "Beacon from " + data["dxcallsign"] + " | " + data["dxgrid"]; + displayToast("info", "bi-broadcast", message, 5000); + break; + } + + switch (data["ping"]) { + case "transmitting": + // PING TRANSMITTING + message = "Sending ping to " + data["dxcallsign"]; + displayToast("success", "bi-arrow-right", message, 5000); + break; + + case "received": + // PING RECEIVED + message = + "Ping request from " + data["dxcallsign"] + " | " + data["dxgrid"]; + displayToast("success", "bi-arrow-right-short", message, 5000); + break; + + case "acknowledge": + // PING ACKNOWLEDGE + message = + "Received ping-ack from " + + data["dxcallsign"] + + " | " + + data["dxgrid"]; + displayToast("success", "bi-arrow-left-right", message, 5000); + break; + } + + // ARQ SESSION && freedata == modem-message + if (data["arq"] == "session") { + switch (data["status"]) { + case "connecting": + // ARQ Open + break; + + case "connected": + // ARQ Opening + break; + + case "waiting": + // ARQ Opening + break; + + case "close": + // ARQ Closing + break; + + case "failed": + // ARQ Failed + break; + } + } + // ARQ TRANSMISSION && freedata == modem-message + if (data["arq"] == "transmission") { + switch (data["status"]) { + case "opened": + // ARQ Open + message = "ARQ session opened: " + data["dxcallsign"]; + displayToast("success", "bi-arrow-left-right", message, 5000); + break; + + case "opening": + // ARQ Opening IRS/ISS + if (data["irs"] == "False") { + message = "ARQ session opening: " + data["dxcallsign"]; + displayToast("info", "bi-arrow-left-right", message, 5000); break; - - case "broadcast": - // RX'd FEC BROADCAST - var encoded_data = atob_FD(data["data"]); - var splitted_data = encoded_data.split(split_char); - var messageArray = []; - if (splitted_data[0] == "m") { - messageArray.push(data); - console.log(data); - } - break; - } - - switch (data["cq"]) { - case "transmitting": - // CQ TRANSMITTING - displayToast( - "success", - "bi-arrow-left-right", - "Transmitting CQ", - 5000, - ); - break; - - case "received": - // CQ RECEIVED - message = "CQ from " + data["dxcallsign"]; - displayToast("success", "bi-person-arms-up", message, 5000); - break; - } - - switch (data["qrv"]) { - case "transmitting": - // QRV TRANSMITTING - displayToast( - "info", - "bi-person-raised-hand", - "Transmitting QRV ", - 5000, - ); - break; - - case "received": - // QRV RECEIVED - message = "QRV from " + data["dxcallsign"] + " | " + data["dxgrid"]; - displayToast("success", "bi-person-raised-hand", message, 5000); - break; - } - - switch (data["beacon"]) { - case "transmitting": - // BEACON TRANSMITTING - displayToast( - "success", - "bi-broadcast-pin", - "Transmitting beacon", - 5000, - ); - break; - - case "received": - // BEACON RECEIVED - newBeaconReceived(data); - - message = - "Beacon from " + data["dxcallsign"] + " | " + data["dxgrid"]; - displayToast("info", "bi-broadcast", message, 5000); - break; - } - - switch (data["ping"]) { - case "transmitting": - // PING TRANSMITTING - message = "Sending ping to " + data["dxcallsign"]; - displayToast("success", "bi-arrow-right", message, 5000); - break; - - case "received": - // PING RECEIVED - message = - "Ping request from " + - data["dxcallsign"] + - " | " + - data["dxgrid"]; - displayToast("success", "bi-arrow-right-short", message, 5000); - break; - - case "acknowledge": - // PING ACKNOWLEDGE - message = - "Received ping-ack from " + - data["dxcallsign"] + - " | " + - data["dxgrid"]; + } else { + message = "ARQ sesson request from: " + data["dxcallsign"]; displayToast("success", "bi-arrow-left-right", message, 5000); break; - } - - // ARQ SESSION && freedata == modem-message - if (data["arq"] == "session") { - switch (data["status"]) { - case "connecting": - // ARQ Open - break; - - case "connected": - // ARQ Opening - break; - - case "waiting": - // ARQ Opening - break; - - case "close": - // ARQ Closing - break; - - case "failed": - // ARQ Failed - break; } - } - // ARQ TRANSMISSION && freedata == modem-message - if (data["arq"] == "transmission") { - switch (data["status"]) { - case "opened": - // ARQ Open - message = "ARQ session opened: " + data["dxcallsign"]; - displayToast("success", "bi-arrow-left-right", message, 5000); - break; - case "opening": - // ARQ Opening IRS/ISS - if (data["irs"] == "False") { - message = "ARQ session opening: " + data["dxcallsign"]; - displayToast("info", "bi-arrow-left-right", message, 5000); - break; - } else { - message = "ARQ sesson request from: " + data["dxcallsign"]; - displayToast("success", "bi-arrow-left-right", message, 5000); - break; - } + case "waiting": + // ARQ waiting + message = "Channel busy | ARQ protocol is waiting"; + displayToast("warning", "bi-hourglass-split", message, 5000); + break; - case "waiting": - // ARQ waiting - message = "Channel busy | ARQ protocol is waiting"; - displayToast("warning", "bi-hourglass-split", message, 5000); - break; + case "receiving": + // ARQ RX + break; - case "receiving": - // ARQ RX - break; + case "failed": + // ARQ TX Failed + if (data["reason"] == "protocol version missmatch") { + message = "Protocol version mismatch!"; + displayToast("danger", "bi-chevron-bar-expand", message, 5000); + setStateFailed(); - case "failed": - // ARQ TX Failed - if (data["reason"] == "protocol version missmatch") { - message = "Protocol version mismatch!"; - displayToast("danger", "bi-chevron-bar-expand", message, 5000); - setStateFailed(); - - break; - } else { - message = "Transmission failed"; - displayToast("danger", "bi-x-octagon", message, 5000); - updateTransmissionStatus(data); - setStateFailed(); - break; - } - switch (data["irs"]) { - case "True": - updateTransmissionStatus(data); - - break; - default: - updateTransmissionStatus(data); - break; - } - break; - - case "received": - // ARQ data received - - console.log(data); - // we need to encode here to do a deep check for checking if file or message - //var encoded_data = atob(data['data']) - var encoded_data = atob_FD(data["data"]); - var splitted_data = encoded_data.split(split_char); - - // new message received - if (splitted_data[0] == "m") { - console.log(splitted_data); - newMessageReceived(splitted_data, data); - } + break; + } else { + message = "Transmission failed"; + displayToast("danger", "bi-x-octagon", message, 5000); + updateTransmissionStatus(data); + setStateFailed(); + break; + } + switch (data["irs"]) { + case "True": + updateTransmissionStatus(data); break; - - case "transmitting": - // ARQ transmitting + default: updateTransmissionStatus(data); break; - - case "transmitted": - // ARQ transmitted - message = "Data transmitted"; - displayToast("success", "bi-check-sqaure", message, 5000); - updateTransmissionStatus(data); - setStateSuccess(); - - break; } - } + break; + + case "received": + // ARQ data received + + console.log(data); + // we need to encode here to do a deep check for checking if file or message + //var encoded_data = atob(data['data']) + var encoded_data = atob_FD(data["data"]); + var splitted_data = encoded_data.split(split_char); + + // new message received + if (splitted_data[0] == "m") { + console.log(splitted_data); + newMessageReceived(splitted_data, data); + } + + break; + + case "transmitting": + // ARQ transmitting + updateTransmissionStatus(data); + break; + + case "transmitted": + // ARQ transmitted + message = "Data transmitted"; + displayToast("success", "bi-check-sqaure", message, 5000); + updateTransmissionStatus(data); + setStateSuccess(); + + break; } - + } + } } - - diff --git a/gui/src/js/event_sock.js b/gui/src/js/event_sock.js index 02e827fa..e8ac41bf 100644 --- a/gui/src/js/event_sock.js +++ b/gui/src/js/event_sock.js @@ -1,7 +1,4 @@ -import { - eventDispatcher -} from "../js/eventHandler.js"; - +import { eventDispatcher } from "../js/eventHandler.js"; let socket; let retries = 0; @@ -19,7 +16,7 @@ function connect() { // handle data socket.addEventListener("message", function (event) { console.log("Message from server:", event.data); - eventDispatcher(event.data) + eventDispatcher(event.data); }); // handle errors diff --git a/gui/src/js/rest.js b/gui/src/js/rest.js index d085b761..35ae0061 100644 --- a/gui/src/js/rest.js +++ b/gui/src/js/rest.js @@ -9,8 +9,6 @@ import { getModemConfigAsJSON, } from "../js/settingsHandler.ts"; - - export async function getFromServer(host, port, endpoint) { // our central function for fetching the modems REST API by a specific endpoint // TODO make this function using the host and port, specified in settings diff --git a/gui/src/js/sock.js b/gui/src/js/sock.js index 7f4cb908..6f236de0 100644 --- a/gui/src/js/sock.js +++ b/gui/src/js/sock.js @@ -733,8 +733,6 @@ export function getRxBuffer() { writeTncCommand(command); } - - // OPEN ARQ SESSION export function connectARQ(dxcallsign) { var command =