From 02793575d0ec9d95641e6fea0cf57d25533f07a0 Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Fri, 7 Jul 2023 11:56:27 +0200 Subject: [PATCH] initial test with callsign reverse lookup --- gui/main.js | 30 ++++++++++++++++++++++++++++ gui/preload-main.js | 3 +++ gui/preload-mesh.js | 48 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/gui/main.js b/gui/main.js index 75a97f01..903c50ad 100644 --- a/gui/main.js +++ b/gui/main.js @@ -1,4 +1,5 @@ const { app, BrowserWindow, ipcMain, dialog, shell } = require("electron"); +const https = require('https'); const { autoUpdater } = require("electron-updater"); const path = require("path"); const fs = require("fs"); @@ -1048,3 +1049,32 @@ ipcMain.on("request-check-rigctld", (event, data) => { console.log(e); } }); + + + +function downloadJsonUrlToFile(url, callsignPath) { +// https://nodejs.org/api/https.html#httpsgetoptions-callback + +https.get(url, (res) => { + console.log('statusCode:', res.statusCode); + console.log('headers:', res.headers); + + res.on('data', (d) => { + console.log(d); + let json = JSON.parse(d); + fs.writeFileSync(callsignPath, JSON.stringify(json, null, 2)); + }); + + }).on('error', (e) => { + console.error(e); + }); + + +} +function downloadCallsignReverseLookupData(){ + var callsignPath = path.join(configFolder, "callsigns.json"); + downloadJsonUrlToFile('https://api.freedata.app/callsign_lookup.php', callsignPath) +} + +downloadCallsignReverseLookupData(); + diff --git a/gui/preload-main.js b/gui/preload-main.js index 7201775c..de5ff07f 100644 --- a/gui/preload-main.js +++ b/gui/preload-main.js @@ -3865,3 +3865,6 @@ function showOsPopUp(title, message) { const NOTIFICATION_BODY = message; new Notification(NOTIFICATION_TITLE, { body: NOTIFICATION_BODY }); } + + + diff --git a/gui/preload-mesh.js b/gui/preload-mesh.js index 4c3a90d2..048a50fe 100644 --- a/gui/preload-mesh.js +++ b/gui/preload-mesh.js @@ -11,6 +11,10 @@ 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); + + // WINDOW LISTENER window.addEventListener("DOMContentLoaded", () => { // startPing button clicked @@ -63,13 +67,36 @@ ipcRenderer.on("action-update-mesh-table", (event, arg) => { var dxcall = document.createElement("td"); var dxcallText = document.createElement("span"); - dxcallText.innerText = routes[i]["dxcall"]; - dxcall.appendChild(dxcallText); + // check for callsign in callsign list, else use checksum + try{ + for (let call in callsigns) { + if(callsigns[call] == routes[i]["dxcall"]){ + dxcallText.innerText = routes[i]["dxcall"] + ' (' + call + ')'; + } + } + } catch(e){ + dxcallText.innerText = routes[i]["dxcall"]; + } + + dxcallText.appendChild(dxcallText); + var router = document.createElement("td"); var routerText = document.createElement("span"); routerText.innerText = routes[i]["router"]; - router.appendChild(routerText); + // check for callsign in callsign list, else use checksum + try{ + for (let call in callsigns) { + if(callsigns[call] == routes[i]["router"]){ + routerText.innerText = routes[i]["router"] + ' (' + call + ')'; + } + } + } catch(e){ + routerText.innerText = routes[i]["router"]; + } + + routerText.appendChild(routerText); + var hops = document.createElement("td"); var hopsText = document.createElement("span"); @@ -98,7 +125,7 @@ ipcRenderer.on("action-update-mesh-table", (event, arg) => { /*-------------------------------------------*/ var routes = arg.mesh_signalling_table; - console.log(routes); + //console.log(routes); if (typeof routes == "undefined") { return; } @@ -130,8 +157,21 @@ ipcRenderer.on("action-update-mesh-table", (event, arg) => { var destination = document.createElement("td"); var destinationText = document.createElement("span"); destinationText.innerText = routes[i]["destination"]; + // check for callsign in callsign list, else use checksum + try{ + for (let call in callsigns) { + if(callsigns[call] == routes[i]["destination"]){ + destinationText.innerText = routes[i]["destination"] + ' (' + call + ')'; + } + } + } catch(e){ + destinationText.innerText = routes[i]["destination"]; + } + destination.appendChild(destinationText); + + var router = document.createElement("td"); var routerText = document.createElement("span"); routerText.innerText = routes[i]["router"];