[CodeFactor] Apply fixes

This commit is contained in:
codefactor-io 2023-11-09 14:48:51 +00:00
parent 165fb9588b
commit 7ee6707047
No known key found for this signature in database
GPG key ID: B66B2D63282C190F
4 changed files with 282 additions and 308 deletions

View file

@ -19,102 +19,100 @@ const stateStore = useStateStore(pinia);
import { useSettingsStore } from "../store/settingsStore.js"; import { useSettingsStore } from "../store/settingsStore.js";
const settings = useSettingsStore(pinia); const settings = useSettingsStore(pinia);
export function eventDispatcher(data) {
console.log(data);
if (data["command"] == "modem_state") {
//console.log(data)
export function eventDispatcher(data){ stateStore.rx_buffer_length = data["rx_buffer_length"];
console.log(data) stateStore.frequency = data["frequency"];
if (data["command"] == "modem_state") { stateStore.busy_state = data["modem_state"];
//console.log(data) 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"]; if (
stateStore.frequency = data["frequency"]; parseInt(stateStore.rx_audio_level) !==
stateStore.busy_state = data["modem_state"]; parseInt(settings.rx_audio_level) &&
stateStore.arq_state = data["arq_state"]; setRxAudioLevelOnce === true
stateStore.mode = data["mode"]; ) {
stateStore.bandwidth = data["bandwidth"]; setRxAudioLevelOnce = false;
stateStore.tx_audio_level = data["tx_audio_level"]; console.log(setRxAudioLevelOnce);
stateStore.rx_audio_level = data["rx_audio_level"]; setRxAudioLevel(settings.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 ( stateStore.dbfs_level = data["audio_dbfs"];
parseInt(stateStore.rx_audio_level) !== stateStore.ptt_state = data["ptt_state"];
parseInt(settings.rx_audio_level) && stateStore.speed_level = data["speed_level"];
setRxAudioLevelOnce === true stateStore.fft = JSON.parse(data["fft"]);
) { stateStore.channel_busy = data["channel_busy"];
setRxAudioLevelOnce = false; stateStore.channel_busy_slot = data["channel_busy_slot"];
console.log(setRxAudioLevelOnce);
setRxAudioLevel(settings.rx_audio_level);
}
stateStore.dbfs_level = data["audio_dbfs"]; addDataToWaterfall(JSON.parse(data["fft"]));
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"])); 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.dbfs_level_percent = Math.round(
stateStore.scatter = data["scatter"]; Math.pow(10, stateStore.dbfs_level / 20) * 100,
} );
// s meter strength stateStore.dbfs_level = Math.round(stateStore.dbfs_level);
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( stateStore.arq_total_bytes = data["total_bytes"];
Math.pow(10, stateStore.dbfs_level / 20) * 100, stateStore.heard_stations = data["stations"].sort(
); sortByPropertyDesc("timestamp"),
stateStore.dbfs_level = Math.round(stateStore.dbfs_level); );
stateStore.dxcallsign = data["dxcallsign"];
stateStore.arq_total_bytes = data["total_bytes"]; stateStore.beacon_state = data["beacon_state"];
stateStore.heard_stations = data["stations"].sort( stateStore.audio_recording = data["audio_recording"];
sortByPropertyDesc("timestamp"),
);
stateStore.dxcallsign = data["dxcallsign"];
stateStore.beacon_state = data["beacon_state"]; stateStore.hamlib_status = data["hamlib_status"];
stateStore.audio_recording = data["audio_recording"]; stateStore.alc = data["alc"];
stateStore.rf_level = data["rf_level"];
stateStore.hamlib_status = data["hamlib_status"]; stateStore.is_codec2_traffic = data["is_codec2_traffic"];
stateStore.alc = data["alc"];
stateStore.rf_level = data["rf_level"];
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"]; if (data["speed_list"].length > 0) {
stateStore.arq_state = data["arq_state"]; prepareStatsDataForStore(data["speed_list"]);
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) { // TODO: Remove ported objects
prepareStatsDataForStore(data["speed_list"]); /*
}
// TODO: Remove ported objects
/*
let Data = { let Data = {
mycallsign: data["mycallsign"], mycallsign: data["mycallsign"],
mygrid: data["mygrid"], 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}], //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 = ""; switch (data["fec"]) {
if (data["freedata"] == "modem-message") { case "is_writing":
// break early if we received a dummy callsign // RX'd FECiswriting
// thats a kind of hotfix, as long as the modem isnt handling this better break;
if (
data["dxcallsign"] == "AA0AA-0" || case "broadcast":
data["dxcallsign"] == "ZZ9YY-0" // RX'd FEC BROADCAST
) { var encoded_data = atob_FD(data["data"]);
return; 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 "received":
case "is_writing": // CQ RECEIVED
// RX'd FECiswriting 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; break;
} else {
case "broadcast": message = "ARQ sesson request from: " + data["dxcallsign"];
// 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"];
displayToast("success", "bi-arrow-left-right", message, 5000); displayToast("success", "bi-arrow-left-right", message, 5000);
break; 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": case "waiting":
// ARQ Opening IRS/ISS // ARQ waiting
if (data["irs"] == "False") { message = "Channel busy | ARQ protocol is waiting";
message = "ARQ session opening: " + data["dxcallsign"]; displayToast("warning", "bi-hourglass-split", message, 5000);
displayToast("info", "bi-arrow-left-right", message, 5000); break;
break;
} else {
message = "ARQ sesson request from: " + data["dxcallsign"];
displayToast("success", "bi-arrow-left-right", message, 5000);
break;
}
case "waiting": case "receiving":
// ARQ waiting // ARQ RX
message = "Channel busy | ARQ protocol is waiting"; break;
displayToast("warning", "bi-hourglass-split", message, 5000);
break;
case "receiving": case "failed":
// ARQ RX // ARQ TX Failed
break; if (data["reason"] == "protocol version missmatch") {
message = "Protocol version mismatch!";
displayToast("danger", "bi-chevron-bar-expand", message, 5000);
setStateFailed();
case "failed": break;
// ARQ TX Failed } else {
if (data["reason"] == "protocol version missmatch") { message = "Transmission failed";
message = "Protocol version mismatch!"; displayToast("danger", "bi-x-octagon", message, 5000);
displayToast("danger", "bi-chevron-bar-expand", message, 5000); updateTransmissionStatus(data);
setStateFailed(); setStateFailed();
break;
break; }
} else { switch (data["irs"]) {
message = "Transmission failed"; case "True":
displayToast("danger", "bi-x-octagon", message, 5000); updateTransmissionStatus(data);
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; break;
default:
case "transmitting":
// ARQ transmitting
updateTransmissionStatus(data); updateTransmissionStatus(data);
break; 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;
} }
}
}
} }

View file

@ -1,7 +1,4 @@
import { import { eventDispatcher } from "../js/eventHandler.js";
eventDispatcher
} from "../js/eventHandler.js";
let socket; let socket;
let retries = 0; let retries = 0;
@ -19,7 +16,7 @@ function connect() {
// handle data // handle data
socket.addEventListener("message", function (event) { socket.addEventListener("message", function (event) {
console.log("Message from server:", event.data); console.log("Message from server:", event.data);
eventDispatcher(event.data) eventDispatcher(event.data);
}); });
// handle errors // handle errors

View file

@ -9,8 +9,6 @@ import {
getModemConfigAsJSON, getModemConfigAsJSON,
} from "../js/settingsHandler.ts"; } from "../js/settingsHandler.ts";
export async function getFromServer(host, port, endpoint) { export async function getFromServer(host, port, endpoint) {
// our central function for fetching the modems REST API by a specific 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 // TODO make this function using the host and port, specified in settings

View file

@ -733,8 +733,6 @@ export function getRxBuffer() {
writeTncCommand(command); writeTncCommand(command);
} }
// OPEN ARQ SESSION // OPEN ARQ SESSION
export function connectARQ(dxcallsign) { export function connectARQ(dxcallsign) {
var command = var command =