FreeDATA/gui/preload-mesh.js

232 lines
7.2 KiB
JavaScript
Raw Normal View History

2023-05-28 15:19:21 +00:00
const path = require("path");
const { ipcRenderer } = require("electron");
// https://stackoverflow.com/a/26227660
var appDataFolder =
process.env.APPDATA ||
(process.platform == "darwin"
? process.env.HOME + "/Library/Application Support"
: process.env.HOME + "/.config");
var configFolder = path.join(appDataFolder, "FreeDATA");
var configPath = path.join(configFolder, "config.json");
const config = require(configPath);
var callsignPath = path.join(configFolder, "callsigns.json");
const callsigns = require(callsignPath);
2023-05-28 15:19:21 +00:00
// WINDOW LISTENER
window.addEventListener("DOMContentLoaded", () => {
2023-06-11 07:12:40 +00:00
// startPing button clicked
2023-07-05 16:43:56 +00:00
document
.getElementById("transmit_mesh_ping")
.addEventListener("click", () => {
var dxcallsign = document
.getElementById("dxCallMesh")
.value.toUpperCase();
if (dxcallsign == "" || dxcallsign == null || dxcallsign == undefined)
return;
//pauseButton(document.getElementById("transmit_mesh_ping"), 2000);
ipcRenderer.send("run-tnc-command", {
command: "mesh_ping",
dxcallsign: dxcallsign,
});
2023-06-11 07:12:40 +00:00
});
2023-05-28 15:19:21 +00:00
});
ipcRenderer.on("action-update-mesh-table", (event, arg) => {
var routes = arg.routing_table;
2023-06-11 07:12:40 +00:00
2023-07-05 16:43:56 +00:00
if (typeof routes == "undefined") {
2023-06-11 07:12:40 +00:00
return;
}
2023-07-05 16:43:56 +00:00
var tbl = document.getElementById("mesh-table");
if (tbl !== null) {
tbl.innerHTML = "";
2023-06-11 07:12:40 +00:00
}
2023-07-05 16:43:56 +00:00
for (i = 0; i < routes.length; i++) {
var row = document.createElement("tr");
2023-05-29 16:49:50 +00:00
var datetime = new Date(routes[i]["timestamp"] * 1000).toLocaleString(
2023-07-05 16:43:56 +00:00
navigator.language,
{
hourCycle: "h23",
2023-05-29 16:49:50 +00:00
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
2023-07-05 16:43:56 +00:00
second: "2-digit",
},
2023-05-29 16:49:50 +00:00
);
2023-07-05 16:43:56 +00:00
var timestamp = document.createElement("td");
var timestampText = document.createElement("span");
timestampText.innerText = datetime;
timestamp.appendChild(timestampText);
var dxcall = document.createElement("td");
var dxcallText = document.createElement("span");
2023-07-08 15:32:07 +00:00
dxcallText.innerText = routes[i]["dxcall"];
// check for callsign in callsign list, else use checksum
2023-07-08 15:32:07 +00:00
for (let call in callsigns) {
2023-07-10 08:22:44 +00:00
if (callsigns[call] == routes[i]["dxcall"]) {
dxcallText.innerText += " (" + call + ")";
continue;
}
2023-07-08 15:32:07 +00:00
}
dxcall.appendChild(dxcallText);
2023-07-05 16:43:56 +00:00
var router = document.createElement("td");
var routerText = document.createElement("span");
routerText.innerText = routes[i]["router"];
2023-07-10 08:22:44 +00:00
// check for callsign in callsign list, else use checksum
2023-07-08 15:32:07 +00:00
for (let call in callsigns) {
2023-07-11 06:38:14 +00:00
if (callsigns[call] == routes[i]["router"]) {
routerText.innerHTML += `<span class="badge ms-2 bg-secondary">${call}</span>`;
continue;
}
2023-07-08 15:32:07 +00:00
}
router.appendChild(routerText);
2023-07-05 16:43:56 +00:00
var hops = document.createElement("td");
var hopsText = document.createElement("span");
hopsText.innerText = routes[i]["hops"];
hops.appendChild(hopsText);
2023-05-28 15:19:21 +00:00
var score = document.createElement("td");
2023-07-05 16:43:56 +00:00
var scoreText = document.createElement("span");
scoreText.innerText = routes[i]["score"];
score.appendChild(scoreText);
2023-05-28 15:19:21 +00:00
var snr = document.createElement("td");
2023-07-05 16:43:56 +00:00
var snrText = document.createElement("span");
snrText.innerText = routes[i]["snr"];
snr.appendChild(snrText);
row.appendChild(timestamp);
row.appendChild(dxcall);
row.appendChild(router);
row.appendChild(hops);
row.appendChild(score);
row.appendChild(snr);
tbl.appendChild(row);
}
2023-06-13 12:03:36 +00:00
/*-------------------------------------------*/
2023-07-05 16:43:56 +00:00
var routes = arg.mesh_signalling_table;
2023-06-13 12:03:36 +00:00
//console.log(routes);
2023-07-05 16:43:56 +00:00
if (typeof routes == "undefined") {
2023-06-13 12:03:36 +00:00
return;
}
2023-07-05 16:43:56 +00:00
var tbl = document.getElementById("mesh-signalling-table");
if (tbl !== null) {
tbl.innerHTML = "";
2023-06-13 12:03:36 +00:00
}
2023-07-05 16:43:56 +00:00
for (i = 0; i < routes.length; i++) {
var row = document.createElement("tr");
2023-06-13 12:03:36 +00:00
var datetime = new Date(routes[i]["timestamp"] * 1000).toLocaleString(
2023-07-05 16:43:56 +00:00
navigator.language,
{
hourCycle: "h23",
2023-06-13 12:03:36 +00:00
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
2023-07-05 16:43:56 +00:00
second: "2-digit",
},
2023-06-13 12:03:36 +00:00
);
2023-07-05 16:43:56 +00:00
var timestamp = document.createElement("td");
var timestampText = document.createElement("span");
timestampText.innerText = datetime;
timestamp.appendChild(timestampText);
var destination = document.createElement("td");
var destinationText = document.createElement("span");
destinationText.innerText = routes[i]["destination"];
// check for callsign in callsign list, else use checksum
2023-07-08 15:32:07 +00:00
for (let call in callsigns) {
2023-07-11 06:38:14 +00:00
if (callsigns[call] == routes[i]["destination"]) {
destinationText.innerHTML += `<span class="badge ms-2 bg-secondary">${call}</span>`;
continue;
}
}
2023-07-05 16:43:56 +00:00
destination.appendChild(destinationText);
2023-07-09 07:48:50 +00:00
var origin = document.createElement("td");
var originText = document.createElement("span");
originText.innerText = routes[i]["origin"];
// check for callsign in callsign list, else use checksum
for (let call in callsigns) {
2023-07-11 06:38:14 +00:00
if (callsigns[call] == routes[i]["origin"]) {
originText.innerHTML += `<span class="badge ms-2 bg-secondary">${call}</span>`;
continue;
}
}
2023-07-09 07:48:50 +00:00
origin.appendChild(originText);
2023-07-05 16:43:56 +00:00
var frametype = document.createElement("td");
var frametypeText = document.createElement("span");
frametypeText.innerText = routes[i]["frametype"];
frametype.appendChild(frametypeText);
2023-06-13 12:03:36 +00:00
var payload = document.createElement("td");
2023-07-05 16:43:56 +00:00
var payloadText = document.createElement("span");
payloadText.innerText = routes[i]["payload"];
payload.appendChild(payloadText);
2023-06-13 12:03:36 +00:00
var attempt = document.createElement("td");
2023-07-05 16:43:56 +00:00
var attemptText = document.createElement("span");
attemptText.innerText = routes[i]["attempt"];
attempt.appendChild(attemptText);
2023-06-13 12:03:36 +00:00
var status = document.createElement("td");
2023-07-05 16:43:56 +00:00
var statusText = document.createElement("span");
2023-07-10 14:07:52 +00:00
//statusText.innerText = routes[i]["status"];
switch (routes[i]["status"]) {
case "acknowledged":
2023-07-11 06:38:14 +00:00
var status_icon = '<i class="bi bi-check-circle-fill"></i>';
var status_color = "bg-success";
2023-07-10 14:07:52 +00:00
break;
case "acknowledging":
2023-07-11 06:38:14 +00:00
var status_icon = '<i class="bi bi-check-circle"></i>';
var status_color = "bg-warning";
2023-07-10 14:07:52 +00:00
break;
case "forwarding":
2023-07-11 06:38:14 +00:00
var status_icon = '<i class="bi bi-arrow-left-right"></i>';
var status_color = "bg-secondary";
2023-07-10 14:07:52 +00:00
break;
2023-07-10 14:14:28 +00:00
case "awaiting_ack":
2023-07-11 06:38:14 +00:00
var status_icon = '<i class="bi bi-clock-history"></i>';
var status_color = "bg-info";
2023-07-10 14:14:28 +00:00
break;
2023-07-10 14:07:52 +00:00
default:
2023-07-11 06:38:14 +00:00
var status_icon = '<i class="bi bi-question-circle-fill"></i>';
var status_color = "bg-primary";
2023-07-10 14:07:52 +00:00
break;
}
statusText.innerHTML = `
<span class="badge ${status_color}">${status_icon}</span>
<span class="badge ${status_color}">${routes[i]["status"]}</span>
2023-07-11 06:38:14 +00:00
`;
2023-07-05 16:43:56 +00:00
status.appendChild(statusText);
row.appendChild(timestamp);
row.appendChild(destination);
2023-07-09 07:48:50 +00:00
row.appendChild(origin);
2023-07-05 16:43:56 +00:00
row.appendChild(frametype);
row.appendChild(payload);
row.appendChild(attempt);
row.appendChild(status);
tbl.appendChild(row);
}
2023-05-28 15:19:21 +00:00
});