From 2c204aec2b1d535e16bb5e54c09d2960a6f3e193 Mon Sep 17 00:00:00 2001 From: AlessandroAU Date: Wed, 16 Oct 2024 18:47:29 +1000 Subject: [PATCH] adds ability to set mavlink send and listen ports add mavlink port set config options fix missing #endif refactor sendResponse and split out modechange add mavlink port config options bump config version gah.. fix.. fix fix2 old config old config config --- html/scan.js | 79 +++++ html/txbp_index.html | 49 +++ lib/MAVLink/MAVLink.h | 4 - lib/WIFI/devWIFI.cpp | 58 +++- lib/config/config.cpp | 750 +++++++++++++++++++++--------------------- lib/config/config.h | 8 +- 6 files changed, 567 insertions(+), 381 deletions(-) diff --git a/html/scan.js b/html/scan.js index ed6c9d41..3a28ee74 100644 --- a/html/scan.js +++ b/html/scan.js @@ -6,6 +6,7 @@ function _(el) { function init() { initAat(); + initMavLink(); // sends XMLHttpRequest, so do it last initOptions(); @@ -25,6 +26,27 @@ function initAat() { ); } +function initMavLink() { + // Fetch initial MavLink configuration + const xmlhttp = new XMLHttpRequest(); + xmlhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + const data = JSON.parse(this.responseText); + updateMavLinkConfig(data); + + // Start periodic updates of MavLink stats + updateMavLinkStats(); + setInterval(updateMavLinkStats, 1000); + + const resetButton = _('mavlink_reset_defaults'); + if (resetButton) { + resetButton.addEventListener('click', resetMavLinkDefaults); + } + } + }; + xmlhttp.open('GET', '/mavlink', true); + xmlhttp.send(); +} function initOptions() { const xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { @@ -38,6 +60,63 @@ function initOptions() { xmlhttp.send(); } +function updateMavLinkConfig(data) { + _('mavlink_listen_port').value = data.ports.listen; + _('mavlink_send_port').value = data.ports.send; +} + +function updateMavLinkStats() { + const xmlhttp = new XMLHttpRequest(); + xmlhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + const data = JSON.parse(this.responseText); + + // Update Stats + _('mavlink_gcs_ip').textContent = data.ip.gcs; + _('mavlink_packets_down').textContent = data.counters.packets_down; + _('mavlink_packets_up').textContent = data.counters.packets_up; + _('mavlink_drops_down').textContent = data.counters.drops_down; + _('mavlink_overflows_down').textContent = data.counters.overflows_down; + } + }; + xmlhttp.open('GET', '/mavlink', true); + xmlhttp.send(); +} + +function resetMavLinkDefaults() { + const defaultSendPort = 14550; + const defaultListenPort = 14555; + + // Update the input fields + _('mavlink_listen_port').value = defaultListenPort; + _('mavlink_send_port').value = defaultSendPort; + + // Send the new values to the server + const xmlhttp = new XMLHttpRequest(); + xmlhttp.onreadystatechange = function() { + if (this.readyState == 4) { + if (this.status == 200) { + cuteAlert({ + type: "success", + title: "Default Settings Applied", + message: "MavLink ports have been reset to default values." + }); + // Refresh the MavLink stats to reflect the changes + updateMavLinkStats(); + } else { + cuteAlert({ + type: "error", + title: "Error", + message: "Failed to apply default settings. Please try again." + }); + } + } + }; + xmlhttp.open('POST', '/setmavlink', true); + xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); + xmlhttp.send(`listen=${defaultListenPort}&send=${defaultSendPort}`); +} + function updateConfig(data) { let config = data.config; if (config.mode==="STA") { diff --git a/html/txbp_index.html b/html/txbp_index.html index 6dd8f934..08c78af2 100644 --- a/html/txbp_index.html +++ b/html/txbp_index.html @@ -25,6 +25,7 @@

ExpressLRS

  • TX
  • Backpack
  • Network
  • +
  • MavLink
  • @@ -97,6 +98,54 @@

    Home Network:

    Disconnect
    + +
    +

    MavLink Configuration

    + +

    MavLink Statistics

    + + + + + + + + + + + + + + + + + + + + + +
    Packets Downlink:
    Packets Uplink:
    Drops Downlink:
    Overflows Downlink:
    GCS IP Adresses:
    +