From 793b06b4e3eba659894561724efe4d0223dbc03f Mon Sep 17 00:00:00 2001 From: Roby Date: Sat, 31 Oct 2026 13:58:04 +0100 Subject: [PATCH] feat: aggiunta Focus Mode e tab decodifica traffico APRS --- services/mqtt_service.py | 32 +- static/js/app.js | 741 +++++++++++++++++++++++++-------------- static/js/modals.js | 4 +- templates/index.html | 124 ++++++- 4 files changed, 619 insertions(+), 282 deletions(-) diff --git a/services/mqtt_service.py b/services/mqtt_service.py index 0eb8f83..8ea4fb1 100644 --- a/services/mqtt_service.py +++ b/services/mqtt_service.py @@ -1,5 +1,6 @@ import json import re +import datetime from paho.mqtt import client as mqtt_client from core.config import config, logger from core.database import save_to_sqlite @@ -18,7 +19,7 @@ def on_connect(client, userdata, flags, reason_code, properties=None): default_topics = [ "servizi/+/stat", "dmr-gateway/+/json", "devices/+/services", "nxdn-gateway/+/json", "ysf-gateway/+/json", "p25-gateway/+/json", - "dstar-gateway/+/json", "mmdvm/+/json", "data/#" + "dstar-gateway/+/json", "mmdvm/+/json", "data/#", "aprs-gateway/aprs" ] topics_list = config.get('mqtt', {}).get('topics', default_topics) @@ -42,6 +43,35 @@ def on_message(client, userdata, msg): try: topic = msg.topic payload = msg.payload.decode('utf-8', errors='replace').strip() + + # NUOVO BLOCCO APRS + if topic == "aprs-gateway/aprs": + try: + raw_aprs = payload + # Formato atteso: SOURCE>DEST,PATH:PAYLOAD + if ">" in raw_aprs and ":" in raw_aprs: + header, aprs_payload = raw_aprs.split(":", 1) + source, rest = header.split(">", 1) + + if "," in rest: + dest, path = rest.split(",", 1) + else: + dest = rest + path = "" + + aprs_data = { + "time": datetime.datetime.now().strftime("%H:%M:%S"), + "source": source.strip(), + "dest": dest.strip(), + "path": path.strip(), + "payload": aprs_payload.strip() + } + + state.socketio.emit('aprs_msg', aprs_data) + except Exception as e: + logger.error(f"Errore decodifica APRS: {e}") + return # Esci per non processare il resto della logica su questo topic + parts = topic.split('/') if len(parts) < 2: return diff --git a/static/js/app.js b/static/js/app.js index 046c90c..876f4d1 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -16,27 +16,56 @@ let viewMode = localStorage.getItem('fleetViewMode') || 'grid'; let fleetMap = null; let mapMarkers = {}; +let currentFocusedNode = null; + function switchView(viewName) { + currentFocusedNode = null; + document.getElementById('view-focus').style.display = 'none'; + document.getElementById('view-home').style.display = 'none'; document.getElementById('view-nodes').style.display = 'none'; document.getElementById('view-map').style.display = 'none'; + document.getElementById('view-aprs').style.display = 'none'; + document.getElementById('tab-home').classList.remove('active'); document.getElementById('tab-nodes').classList.remove('active'); document.getElementById('tab-map').classList.remove('active'); + document.getElementById('tab-aprs').classList.remove('active'); document.getElementById(`view-${viewName}`).style.display = 'block'; document.getElementById(`tab-${viewName}`).classList.add('active'); localStorage.setItem('fleetDefaultView', viewName); - // Riporta la pagina in cima con un'animazione fluida window.scrollTo({ top: 0, behavior: 'smooth' }); if (viewName === 'nodes') { applyViewMode(); } - else if (viewName === 'map') { - setTimeout(() => { - initOrUpdateMap(); - }, 100); - } + else if (viewName === 'map') { setTimeout(() => { initOrUpdateMap(); }, 100); } +} + +function openNodeFocus(clientId) { + currentFocusedNode = clientId; + + document.getElementById('view-home').style.display = 'none'; + document.getElementById('view-nodes').style.display = 'none'; + document.getElementById('view-map').style.display = 'none'; + document.getElementById('view-aprs').style.display = 'none'; + + document.getElementById('tab-home').classList.remove('active'); + document.getElementById('tab-nodes').classList.remove('active'); + document.getElementById('tab-map').classList.remove('active'); + document.getElementById('tab-aprs').classList.remove('active'); + + document.getElementById('view-focus').style.display = 'block'; + window.scrollTo({ top: 0, behavior: 'smooth' }); + + refreshStates(); + refreshLogs(); +} + +function closeNodeFocus() { + currentFocusedNode = null; + document.getElementById('view-focus').style.display = 'none'; + switchView(localStorage.getItem('fleetDefaultView') || 'home'); } window.addEventListener('DOMContentLoaded', () => { @@ -48,6 +77,7 @@ window.addEventListener('DOMContentLoaded', () => { setInterval(() => { refreshLogs(); refreshStats(); }, 60000); checkServerUpdate(); setInterval(checkServerUpdate, 3600000); + refreshAprs(); // Fetch iniziale APRS }); // --- FUNZIONI FILTRO E LAYOUT --- @@ -165,18 +195,18 @@ function confirmSwitch(id, mode) { const data = globalHealthData[id.toLowerCase()]; let profileName = mode === 'A' ? "PROF A" : "PROF B"; if (data && data.profiles && data.profiles[mode]) profileName = data.profiles[mode]; - const title = `๐Ÿ”„ ${t('titleSwitch')}`; + const title = `[ SW_PROFILE ]`; const msg = `${t('confSwitch')} ${esc(profileName)} -> ${id.toUpperCase()}?`; const color = mode === 'A' ? "var(--accent)" : "var(--primary)"; sendCommand(id, mode, title, msg, color); } -function confirmReboot(id) { sendCommand(id, 'REBOOT', `๐Ÿ”„ ${t('titleBoot')}`, `${t('confBoot')}${id.toUpperCase()}?`, "var(--danger)"); } -function confirmUpdateAgent(id) { sendCommand(id, 'UPDATE_AGENT', `โฌ‡๏ธ UPDATE OTA`, `Confermi l'aggiornamento dello script tramite git pull sul nodo ${id.toUpperCase()}?`, "var(--primary)"); } +function confirmReboot(id) { sendCommand(id, 'REBOOT', `[ REBOOT ]`, `${t('confBoot')}${id.toUpperCase()}?`, "var(--danger)"); } +function confirmUpdateAgent(id) { sendCommand(id, 'UPDATE_AGENT', `[ OTA_UPDATE ]`, `${t('confOta')}${id.toUpperCase()}?`, "var(--primary)"); } function sendTgCommand(clientId, comando) { const msg = (comando === 'TG:ON') ? t('confTgOn') : t('confTgOff'); - customConfirm("๐Ÿ’ฌ TELEGRAM", `${msg}${clientId.toUpperCase()}?`, "var(--primary)", async () => { + customConfirm("[ TELEGRAM ]", `${msg}${clientId.toUpperCase()}?`, "var(--primary)", async () => { try { const res = await fetch('/api/command', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ clientId: clientId, type: comando }) }); const data = await res.json(); @@ -234,7 +264,7 @@ async function initUI() { return `
- ${esc(c.name)} + ${esc(c.name)}
NET-ID: ${c.id.toUpperCase()} @@ -272,7 +302,7 @@ async function initUI() {
-
${t('waitNet')}
+
> AWAITING_STREAM...