From b70f48140a67cf60ada15091305f6e95cb678c1d Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Wed, 24 Apr 2024 13:44:23 -1000 Subject: [PATCH 01/11] Properly separate WiFi state values from WiFi mode values --- Firmware/RTK_Surveyor/Display.ino | 12 ++++---- Firmware/RTK_Surveyor/ESPNOW.ino | 8 ++--- Firmware/RTK_Surveyor/NtripClient.ino | 4 +-- Firmware/RTK_Surveyor/NtripServer.ino | 4 +-- Firmware/RTK_Surveyor/Tasks.ino | 2 +- Firmware/RTK_Surveyor/WiFi.ino | 42 +++++++++++++-------------- Firmware/RTK_Surveyor/menuSystem.ino | 2 +- Firmware/RTK_Surveyor/settings.h | 10 +++---- 8 files changed, 42 insertions(+), 42 deletions(-) diff --git a/Firmware/RTK_Surveyor/Display.ino b/Firmware/RTK_Surveyor/Display.ino index d77e28bbb..7829b012a 100644 --- a/Firmware/RTK_Surveyor/Display.ino +++ b/Firmware/RTK_Surveyor/Display.ino @@ -752,7 +752,7 @@ uint32_t setRadioIcons() // Count the number of radios in use uint8_t numberOfRadios = 1; // Bluetooth always indicated. TODO don't count if BT radio type is OFF. - if (wifiState > WIFI_OFF) + if (wifiState > WIFI_STATE_OFF) numberOfRadios++; if (espnowState > ESPNOW_OFF) numberOfRadios++; @@ -770,7 +770,7 @@ uint32_t setRadioIcons() icons |= setBluetoothIcon_TwoRadios(); // Do we have WiFi or ESP - if (wifiState > WIFI_OFF) + if (wifiState > WIFI_STATE_OFF) icons |= setWiFiIcon_TwoRadios(); else if (espnowState > ESPNOW_OFF) icons |= setESPNowIcon_TwoRadios(); @@ -968,7 +968,7 @@ uint32_t setWiFiIcon_TwoRadios() { uint32_t icons = 0; - if (wifiState == WIFI_CONNECTED) + if (wifiState == WIFI_STATE_CONNECTED) { // Limit how often we update this spot if (millis() - firstRadioSpotTimer > 2000) @@ -1055,7 +1055,7 @@ uint32_t setWiFiIcon_ThreeRadios() { uint32_t icons = 0; - if (wifiState == WIFI_CONNECTED) + if (wifiState == WIFI_STATE_CONNECTED) { // Limit how often we update this spot if (millis() - thirdRadioSpotTimer > 2000) @@ -1144,7 +1144,7 @@ uint32_t setWiFiIcon() if (online.display == true) { - if (wifiState == WIFI_CONNECTED) + if (wifiState == WIFI_STATE_CONNECTED) { icons |= ICON_WIFI_SYMBOL_3_RIGHT; } @@ -3384,7 +3384,7 @@ const uint8_t *getMacAddress() return btMACAddress; #endif // COMPILE_BT #ifdef COMPILE_WIFI - if (wifiState != WIFI_OFF) + if (wifiState != WIFI_STATE_OFF) return wifiMACAddress; #endif // COMPILE_WIFI #ifdef COMPILE_ETHERNET diff --git a/Firmware/RTK_Surveyor/ESPNOW.ino b/Firmware/RTK_Surveyor/ESPNOW.ino index a51547412..820c61cff 100644 --- a/Firmware/RTK_Surveyor/ESPNOW.ino +++ b/Firmware/RTK_Surveyor/ESPNOW.ino @@ -98,7 +98,7 @@ void espnowStart() esp_err_t response; - if (wifiState == WIFI_OFF && espnowState == ESPNOW_OFF) + if (wifiState == WIFI_STATE_OFF && espnowState == ESPNOW_OFF) { if (WiFi.getMode() != WIFI_STA) WiFi.mode(WIFI_STA); @@ -112,7 +112,7 @@ void espnowStart() log_d("WiFi off, ESP-Now added to protocols"); } // If WiFi is on but ESP NOW is off, then enable LR protocol - else if (wifiState > WIFI_OFF && espnowState == ESPNOW_OFF) + else if (wifiState > WIFI_STATE_OFF && espnowState == ESPNOW_OFF) { if (WiFi.getMode() != WIFI_STA) WiFi.mode(WIFI_STA); @@ -239,7 +239,7 @@ void espnowStop() espnowSetState(ESPNOW_OFF); - if (wifiState == WIFI_OFF) + if (wifiState == WIFI_STATE_OFF) { // ESP Now was the only thing using the radio so turn WiFi radio off entirely WiFi.mode(WIFI_OFF); @@ -247,7 +247,7 @@ void espnowStop() log_d("WiFi Radio off entirely"); } // If WiFi is on, then restart WiFi - else if (wifiState > WIFI_OFF) + else if (wifiState > WIFI_STATE_OFF) { log_d("ESP-Now starting WiFi"); wifiStart(); // Force WiFi to restart diff --git a/Firmware/RTK_Surveyor/NtripClient.ino b/Firmware/RTK_Surveyor/NtripClient.ino index fc2c57d72..592049e0e 100644 --- a/Firmware/RTK_Surveyor/NtripClient.ino +++ b/Firmware/RTK_Surveyor/NtripClient.ino @@ -82,7 +82,7 @@ NtripClient.ino /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= NTRIP Client States: NTRIP_CLIENT_OFF: Network off or using NTRIP server - NTRIP_CLIENT_ON: WIFI_START state + NTRIP_CLIENT_ON: WIFI_STATE_START state NTRIP_CLIENT_NETWORK_STARTED: Connecting to the network NTRIP_CLIENT_NETWORK_CONNECTED: Connected to the network NTRIP_CLIENT_CONNECTING: Attempting a connection to the NTRIP caster @@ -152,7 +152,7 @@ static const int NTRIP_CLIENT_CONNECTION_TIME = 5 * 60 * 1000; enum NTRIPClientState { NTRIP_CLIENT_OFF = 0, // Using Bluetooth or NTRIP server - NTRIP_CLIENT_ON, // WIFI_START state + NTRIP_CLIENT_ON, // WIFI_STATE_START state NTRIP_CLIENT_NETWORK_STARTED, // Connecting to WiFi access point or Ethernet NTRIP_CLIENT_NETWORK_CONNECTED, // Connected to an access point or Ethernet NTRIP_CLIENT_CONNECTING, // Attempting a connection to the NTRIP caster diff --git a/Firmware/RTK_Surveyor/NtripServer.ino b/Firmware/RTK_Surveyor/NtripServer.ino index 1c4fc6400..7c4f589f7 100644 --- a/Firmware/RTK_Surveyor/NtripServer.ino +++ b/Firmware/RTK_Surveyor/NtripServer.ino @@ -82,7 +82,7 @@ NtripServer.ino /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= NTRIP Server States: NTRIP_SERVER_OFF: Network off or using NTRIP Client - NTRIP_SERVER_ON: WIFI_START state + NTRIP_SERVER_ON: WIFI_STATE_START state NTRIP_SERVER_NETWORK_STARTED: Connecting to the network NTRIP_SERVER_NETWORK_CONNECTED: Connected to the network NTRIP_SERVER_WAIT_GNSS_DATA: Waiting for correction data from GNSS @@ -145,7 +145,7 @@ static const int NTRIP_SERVER_CONNECTION_TIME = 5 * 60 * 1000; enum NTRIPServerState { NTRIP_SERVER_OFF = 0, // Using Bluetooth or NTRIP client - NTRIP_SERVER_ON, // WIFI_START state + NTRIP_SERVER_ON, // WIFI_STATE_START state NTRIP_SERVER_NETWORK_STARTED, // Connecting to WiFi access point NTRIP_SERVER_NETWORK_CONNECTED, // WiFi connected to an access point NTRIP_SERVER_WAIT_GNSS_DATA, // Waiting for correction data from GNSS diff --git a/Firmware/RTK_Surveyor/Tasks.ino b/Firmware/RTK_Surveyor/Tasks.ino index 99cd15433..35122bd95 100644 --- a/Firmware/RTK_Surveyor/Tasks.ino +++ b/Firmware/RTK_Surveyor/Tasks.ino @@ -1017,7 +1017,7 @@ void updateBTled() ledcWrite(ledBTChannel, 255); // Pulse LED while no BT and we wait for WiFi connection - else if (wifiState == WIFI_CONNECTING || wifiState == WIFI_CONNECTED) + else if (wifiState == WIFI_STATE_CONNECTING || wifiState == WIFI_STATE_CONNECTED) { // Fade in/out the BT LED during WiFi AP mode btFadeLevel += pwmFadeAmount; diff --git a/Firmware/RTK_Surveyor/WiFi.ino b/Firmware/RTK_Surveyor/WiFi.ino index dd23b52c8..e9101f451 100644 --- a/Firmware/RTK_Surveyor/WiFi.ino +++ b/Firmware/RTK_Surveyor/WiFi.ino @@ -14,19 +14,19 @@ WiFi Station States: - WIFI_OFF<--------------------. + WIFI_STATE_OFF<-------------------. | | wifiStart() | | | | WL_CONNECT_FAILED (Bad password) | | WL_NO_SSID_AVAIL (Out of range) v Fail | - WIFI_CONNECTING------------->+ + WIFI_STATE_CONNECTING------------->+ | ^ ^ wifiConnect() | | | wifiShutdown() | | WL_CONNECTION_LOST | | | WL_DISCONNECTED | v | | - WIFI_CONNECTED --------------' + WIFI_STATE_CONNECTED -------------' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ //---------------------------------------- @@ -196,17 +196,17 @@ void wifiSetState(byte newState) default: systemPrintf("Unknown WiFi state: %d\r\n", newState); break; - case WIFI_OFF: - systemPrintln("WIFI_OFF"); + case WIFI_STATE_OFF: + systemPrintln("WIFI_STATE_OFF"); break; - case WIFI_START: - systemPrintln("WIFI_START"); + case WIFI_STATE_START: + systemPrintln("WIFI_STATE_START"); break; - case WIFI_CONNECTING: - systemPrintln("WIFI_CONNECTING"); + case WIFI_STATE_CONNECTING: + systemPrintln("WIFI_STATE_CONNECTING"); break; - case WIFI_CONNECTED: - systemPrintln("WIFI_CONNECTED"); + case WIFI_STATE_CONNECTED: + systemPrintln("WIFI_STATE_CONNECTED"); break; } } @@ -322,11 +322,11 @@ void wifiUpdate() systemPrintf("Unknown wifiState: %d\r\n", wifiState); break; - case WIFI_OFF: + case WIFI_STATE_OFF: // Any service that needs WiFi will call wifiStart() break; - case WIFI_CONNECTING: + case WIFI_STATE_CONNECTING: // Pause until connection timeout has passed if (millis() - wifiLastConnectionAttempt > wifiConnectionAttemptTimeout) { @@ -337,7 +337,7 @@ void wifiUpdate() if (espnowState > ESPNOW_OFF) espnowStart(); - wifiSetState(WIFI_CONNECTED); + wifiSetState(WIFI_STATE_CONNECTED); } else { @@ -353,20 +353,20 @@ void wifiUpdate() { systemPrintln("WiFi connection failed. Giving up."); displayNoWiFi(2000); - WIFI_STOP(); // Move back to WIFI_OFF + WIFI_STOP(); // Move back to WIFI_STATE_OFF } } } break; - case WIFI_CONNECTED: + case WIFI_STATE_CONNECTED: // Verify link is still up if (wifiIsConnected() == false) { systemPrintln("WiFi link lost"); wifiConnectionAttempts = 0; // Reset the timeout - wifiSetState(WIFI_CONNECTING); + wifiSetState(WIFI_STATE_CONNECTING); } // If WiFi is connected, and no services require WiFi, shut it off @@ -383,7 +383,7 @@ void wifiUpdate() } } -// Starts the WiFi connection state machine (moves from WIFI_OFF to WIFI_CONNECTING) +// Starts the WiFi connection state machine (moves from WIFI_STATE_OFF to WIFI_STATE_CONNECTING) // Sets the appropriate protocols (WiFi + ESP-Now) // If radio is off entirely, start WiFi // If ESP-Now is active, only add the LR protocol @@ -400,12 +400,12 @@ void wifiStart() if (wifiIsConnected() == true) return; // We don't need to do anything - if (wifiState > WIFI_OFF) + if (wifiState > WIFI_STATE_OFF) return; // We're in the midst of connecting log_d("Starting WiFi"); - wifiSetState(WIFI_CONNECTING); // This starts the state machine running + wifiSetState(WIFI_STATE_CONNECTING); // This starts the state machine running // Display the heap state reportHeapNow(settings.debugWifiState); @@ -433,7 +433,7 @@ void wifiStop() // If ESP NOW is active, leave WiFi on enough for ESP NOW void wifiShutdown() { - wifiSetState(WIFI_OFF); + wifiSetState(WIFI_STATE_OFF); wifiConnectionAttempts = 0; // Reset the timeout diff --git a/Firmware/RTK_Surveyor/menuSystem.ino b/Firmware/RTK_Surveyor/menuSystem.ino index 3d10cfa98..ae81709a0 100644 --- a/Firmware/RTK_Surveyor/menuSystem.ino +++ b/Firmware/RTK_Surveyor/menuSystem.ino @@ -80,7 +80,7 @@ void menuSystem() systemPrint("WiFi MAC Address: "); systemPrintf("%02X:%02X:%02X:%02X:%02X:%02X\r\n", wifiMACAddress[0], wifiMACAddress[1], wifiMACAddress[2], wifiMACAddress[3], wifiMACAddress[4], wifiMACAddress[5]); - if (wifiState == WIFI_CONNECTED) + if (wifiState == WIFI_STATE_CONNECTED) wifiDisplayIpAddress(); #endif // COMPILE_WIFI diff --git a/Firmware/RTK_Surveyor/settings.h b/Firmware/RTK_Surveyor/settings.h index b7215297b..1ab0614b4 100644 --- a/Firmware/RTK_Surveyor/settings.h +++ b/Firmware/RTK_Surveyor/settings.h @@ -267,12 +267,12 @@ typedef struct _NETWORK_DATA // either WiFi or ESP-Now are active enum WiFiState { - WIFI_OFF = 0, - WIFI_START, - WIFI_CONNECTING, - WIFI_CONNECTED, + WIFI_STATE_OFF = 0, + WIFI_STATE_START, + WIFI_STATE_CONNECTING, + WIFI_STATE_CONNECTED, }; -volatile byte wifiState = WIFI_OFF; +volatile byte wifiState = WIFI_STATE_OFF; typedef enum { From 092daf8d3995a2c5e19908f6a0fb0a4aab1c8836 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Wed, 24 Apr 2024 14:19:10 -1000 Subject: [PATCH 02/11] Add NTRIP_SERVER_DATA structure --- Firmware/RTK_Surveyor/RTK_Surveyor.ino | 45 +++++++++++++------------- Firmware/RTK_Surveyor/settings.h | 33 +++++++++++++++++++ 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/Firmware/RTK_Surveyor/RTK_Surveyor.ino b/Firmware/RTK_Surveyor/RTK_Surveyor.ino index b3d9d7a5c..7cfd677a7 100644 --- a/Firmware/RTK_Surveyor/RTK_Surveyor.ino +++ b/Firmware/RTK_Surveyor/RTK_Surveyor.ino @@ -60,6 +60,28 @@ // the minor firmware version #define RTK_IDENTIFIER (FIRMWARE_VERSION_MAJOR * 0x10 + FIRMWARE_VERSION_MINOR) +#ifdef COMPILE_ETHERNET +#include // http://librarymanager/All#Arduino_Ethernet +#include "SparkFun_WebServer_ESP32_W5500.h" //http://librarymanager/All#SparkFun_WebServer_ESP32_W5500 v1.5.5 +#endif // COMPILE_ETHERNET + +#ifdef COMPILE_WIFI +#include "ESP32OTAPull.h" //http://librarymanager/All#ESP-OTA-Pull Used for getting +#include "esp_wifi.h" //Needed for esp_wifi_set_protocol() +#include //Built-in. +#include //Built-in. +#include //Built-in. Needed for ThingStream API for ZTP +#include //http://librarymanager/All#PubSubClient_MQTT_Lightweight by Nick O'Leary v2.8.0 Used for MQTT obtaining of keys +#include //Built-in. +#include //Built-in. +#include //Built-in. +#endif // COMPILE_WIFI + +#if COMPILE_NETWORK +#include // http://librarymanager/All#SSLClientESP32 +#include "X509_Certificate_Bundle.h" // Root certificates +#endif // COMPILE_NETWORK + #include "settings.h" #define MAX_CPU_CORES 2 @@ -200,10 +222,6 @@ char logFileName[sizeof("SFE_Reference_Station_230101_120101.ubx_plusExtraSpace" // Over-the-Air (OTA) update support //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -#if COMPILE_NETWORK -#include // http://librarymanager/All#SSLClientESP32 -#include "X509_Certificate_Bundle.h" // Root certificates -#endif // COMPILE_NETWORK #include //http://librarymanager/All#Arduino_JSON_messagepack v6.19.4 #include "esp_ota_ops.h" //Needed for partition counting and updateFromSD @@ -216,7 +234,6 @@ char logFileName[sizeof("SFE_Reference_Station_230101_120101.ubx_plusExtraSpace" } #ifdef COMPILE_WIFI -#include "ESP32OTAPull.h" //http://librarymanager/All#ESP-OTA-Pull Used for getting #define WIFI_STOP() \ { \ @@ -237,19 +254,6 @@ unsigned int binBytesSent = 0; // Tracks firmware bytes sent over WiFi O //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- // Connection settings to NTRIP Caster //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -#ifdef COMPILE_WIFI -#include //Built-in. -#include //Built-in. Needed for ThingStream API for ZTP -#include //http://librarymanager/All#PubSubClient_MQTT_Lightweight by Nick O'Leary v2.8.0 Used for MQTT obtaining of keys -#include //Built-in. -#include //Built-in. -#include //Built-in. -#include //Built-in. - -#include "esp_wifi.h" //Needed for esp_wifi_set_protocol() - -#endif // COMPILE_WIFI - #include "base64.h" //Built-in. Needed for NTRIP Client credential encoding. bool enableRCFirmware = false; // Goes true from AP config page @@ -574,7 +578,6 @@ const uint8_t ESPNOW_MAX_PEERS = 5; // Maximum of 5 rovers // Ethernet //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #ifdef COMPILE_ETHERNET -#include // http://librarymanager/All#Arduino_Ethernet IPAddress ethernetIPAddress; IPAddress ethernetDNS; IPAddress ethernetGateway; @@ -591,15 +594,11 @@ class derivedEthernetUDP : public EthernetUDP volatile struct timeval ethernetNtpTv; // This will hold the time the Ethernet NTP packet arrived bool ntpLogIncreasing; -#include "SparkFun_WebServer_ESP32_W5500.h" //http://librarymanager/All#SparkFun_WebServer_ESP32_W5500 v1.5.5 #endif // COMPILE_ETHERNET unsigned long lastEthernetCheck = 0; // Prevents cable checking from continually happening //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -#include "NetworkClient.h" //Supports both WiFiClient and EthernetClient -#include "NetworkUDP.h" //Supports both WiFiUdp and EthernetUdp - // Global variables //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #define lbandMACAddress btMACAddress diff --git a/Firmware/RTK_Surveyor/settings.h b/Firmware/RTK_Surveyor/settings.h index 1ab0614b4..21b9a0c91 100644 --- a/Firmware/RTK_Surveyor/settings.h +++ b/Firmware/RTK_Surveyor/settings.h @@ -1,3 +1,6 @@ +#ifndef __SETTINGS_H__ +#define __SETTINGS_H__ + // System can enter a variety of states // See statemachine diagram at: // https://lucid.app/lucidchart/53519501-9fa5-4352-aa40-673f88ca0c9b/edit?invitationId=inv_ebd4b988-513d-4169-93fd-c291851108f8 @@ -274,6 +277,35 @@ enum WiFiState }; volatile byte wifiState = WIFI_STATE_OFF; +#include "NetworkClient.h" // Built-in - Supports both WiFiClient and EthernetClient +#include "NetworkUDP.h" //Built-in - Supports both WiFiUdp and EthernetUdp + +// NTRIP Server data +typedef struct _NTRIP_SERVER_DATA +{ + // Network connection used to push RTCM to NTRIP caster + NetworkClient *networkClient; + volatile uint8_t state; + + // Count of bytes sent by the NTRIP server to the NTRIP caster + uint32_t bytesSent; + + // Throttle the time between connection attempts + // ms - Max of 4,294,967,295 or 4.3M seconds or 71,000 minutes or 1193 hours or 49 days between attempts + uint32_t connectionAttemptTimeout; + uint32_t lastConnectionAttempt; + int connectionAttempts; // Count the number of connection attempts between restarts + + // NTRIP server timer usage: + // * Reconnection delay + // * Measure the connection response time + // * Receive RTCM correction data timeout + // * Monitor last RTCM byte received for frame counting + uint32_t timer; + uint32_t startTime; + int connectionAttemptsTotal; // Count the number of connection attempts absolutely +} NTRIP_SERVER_DATA; + typedef enum { ESPNOW_OFF, @@ -1177,3 +1209,4 @@ rqXRfboQnoZsG4q5WTP468SQvvG5 )====="; #endif // COMPILE_L_BAND #endif // COMPILE_WIFI +#endif // __SETTINGS_H__ From 2f3060df0c0cd00c5effa87d641950b6b5e8adb8 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Wed, 24 Apr 2024 15:38:36 -1000 Subject: [PATCH 03/11] Switch to using ntripServerArray --- Firmware/RTK_Surveyor/Base.ino | 6 +- Firmware/RTK_Surveyor/Developer.ino | 8 +- Firmware/RTK_Surveyor/Form.ino | 3 +- Firmware/RTK_Surveyor/Network.ino | 20 ++-- Firmware/RTK_Surveyor/NtripServer.ino | 137 ++++++++++++++----------- Firmware/RTK_Surveyor/RTK_Surveyor.ino | 2 + Firmware/RTK_Surveyor/settings.h | 8 +- 7 files changed, 107 insertions(+), 77 deletions(-) diff --git a/Firmware/RTK_Surveyor/Base.ino b/Firmware/RTK_Surveyor/Base.ino index aa5d53a64..c01a4f4a7 100644 --- a/Firmware/RTK_Surveyor/Base.ino +++ b/Firmware/RTK_Surveyor/Base.ino @@ -349,7 +349,8 @@ void DevUBLOXGNSS::processRTCM(uint8_t incoming) rtcmLastReceived = millis(); rtcmBytesSent++; - ntripServerProcessRTCM(incoming); + for (int serverIndex = 0; serverIndex < NTRIP_SERVER_MAX; serverIndex++) + ntripServerProcessRTCM(serverIndex, incoming); espnowProcessRTCM(incoming); } @@ -391,7 +392,8 @@ void processRTCMBuffer() rtcmLastReceived = millis(); rtcmBytesSent++; - ntripServerProcessRTCM(incoming); + for (int serverIndex = 0; serverIndex < NTRIP_SERVER_MAX; serverIndex++) + ntripServerProcessRTCM(serverIndex, incoming); espnowProcessRTCM(incoming); } diff --git a/Firmware/RTK_Surveyor/Developer.ino b/Firmware/RTK_Surveyor/Developer.ino index 6e2bcf114..9922b262e 100644 --- a/Firmware/RTK_Surveyor/Developer.ino +++ b/Firmware/RTK_Surveyor/Developer.ino @@ -59,10 +59,10 @@ void ntripClientValidateTables() {} // NTRIP server //---------------------------------------- -bool ntripServerIsCasting() {return false;} -void ntripServerPrintStatus() {systemPrint("NTRIP Server not compiled");} -void ntripServerProcessRTCM(uint8_t incoming) {} -void ntripServerStop(bool clientAllocated) {online.ntripServer = false;} +bool ntripServerIsCasting(int serverIndex) {return false;} +void ntripServerPrintStatus(int serverIndex) {systemPrintf("**NTRIP Server %d not compiled**\r\n", serverIndex);} +void ntripServerProcessRTCM(int serverIndex, uint8_t incoming) {} +void ntripServerStop(int serverIndex, bool clientAllocated) {online.ntripServer = false;} void ntripServerUpdate() {} void ntripServerValidateTables() {} diff --git a/Firmware/RTK_Surveyor/Form.ino b/Firmware/RTK_Surveyor/Form.ino index 041210333..465b98122 100644 --- a/Firmware/RTK_Surveyor/Form.ino +++ b/Firmware/RTK_Surveyor/Form.ino @@ -60,7 +60,8 @@ bool startWebServer(bool startWiFi = true, int httpPort = 80) do { ntripClientStop(true); // Do not allocate new wifiClient - ntripServerStop(true); // Do not allocate new wifiClient + for (int serverIndex = 0; serverIndex < NTRIP_SERVER_MAX; serverIndex++) + ntripServerStop(serverIndex, true); // Do not allocate new wifiClient if (startWiFi) if (wifiStartAP() == false) // Exits calling wifiConnect() diff --git a/Firmware/RTK_Surveyor/Network.ino b/Firmware/RTK_Surveyor/Network.ino index 7ec5e1ab4..eb069e29f 100644 --- a/Firmware/RTK_Surveyor/Network.ino +++ b/Firmware/RTK_Surveyor/Network.ino @@ -183,11 +183,11 @@ const char * const networkUser[] = { "NTP Server", "NTRIP Client", - "NTRIP Server", "OTA Firmware Update", "PVT Client", "PVT Server", "PVT UDP Server", + "NTRIP Server 0", }; const int networkUserEntries = sizeof(networkUser) / sizeof(networkUser[0]); @@ -838,6 +838,7 @@ void networkStop(uint8_t networkType) { NETWORK_DATA * network; bool restart; + int serverIndex; bool shutdown; int user; @@ -877,6 +878,17 @@ void networkStop(uint8_t networkType) // Stop the network client switch(user) { + default: + if ((user >= NETWORK_USER_NTRIP_SERVER) + && (user < (NETWORK_USER_NTRIP_SERVER + NTRIP_SERVER_MAX))) + { + serverIndex = user - NETWORK_USER_NTRIP_SERVER; + if (settings.debugNetworkLayer) + systemPrintln("Network layer stopping NTRIP server"); + ntripServerRestart(serverIndex); + } + break; + case NETWORK_USER_NTP_SERVER: if (settings.debugNetworkLayer) systemPrintln("Network layer stopping NTP server"); @@ -889,12 +901,6 @@ void networkStop(uint8_t networkType) ntripClientRestart(); break; - case NETWORK_USER_NTRIP_SERVER: - if (settings.debugNetworkLayer) - systemPrintln("Network layer stopping NTRIP server"); - ntripServerRestart(); - break; - case NETWORK_USER_OTA_FIRMWARE_UPDATE: if (settings.debugNetworkLayer) systemPrintln("Network layer stopping OTA firmware update"); diff --git a/Firmware/RTK_Surveyor/NtripServer.ino b/Firmware/RTK_Surveyor/NtripServer.ino index 7c4f589f7..9c987ab98 100644 --- a/Firmware/RTK_Surveyor/NtripServer.ino +++ b/Firmware/RTK_Surveyor/NtripServer.ino @@ -176,8 +176,8 @@ const RtkMode_t ntripServerMode = RTK_MODE_BASE_FIXED; // Locals //---------------------------------------- -// Network connection used to push RTCM to NTRIP caster -static NetworkClient *ntripServer; +// NTRIP Servers +static NTRIP_SERVER_DATA ntripServerArray[NTRIP_SERVER_MAX]; static volatile uint8_t ntripServerState = NTRIP_SERVER_OFF; // Count of bytes sent by the NTRIP server to the NTRIP caster @@ -203,8 +203,9 @@ static int ntripServerConnectionAttemptsTotal; // Count the number of connection //---------------------------------------- // Initiate a connection to the NTRIP caster -bool ntripServerConnectCaster() +bool ntripServerConnectCaster(int serverIndex) { + NTRIP_SERVER_DATA * ntripServer = &ntripServerArray[serverIndex]; const int SERVER_BUFFER_SIZE = 512; char serverBuffer[SERVER_BUFFER_SIZE]; @@ -226,7 +227,7 @@ bool ntripServerConnectCaster() settings.ntripServer_CasterPort); // Attempt a connection to the NTRIP caster - if (!ntripServer->connect(settings.ntripServer_CasterHost, settings.ntripServer_CasterPort)) + if (!ntripServer->networkClient->connect(settings.ntripServer_CasterHost, settings.ntripServer_CasterPort)) { if (settings.debugNtripServerState) systemPrintf("NTRIP Server connection to NTRIP caster %s:%d failed\r\n", @@ -248,12 +249,12 @@ bool ntripServerConnectCaster() getFirmwareVersion(&serverBuffer[length], sizeof(serverBuffer) - length, false); // Send the authorization credentials to the NTRIP caster - ntripServer->write((const uint8_t *)serverBuffer, strlen(serverBuffer)); + ntripServer->networkClient->write((const uint8_t *)serverBuffer, strlen(serverBuffer)); return true; } // Determine if the connection limit has been reached -bool ntripServerConnectLimitReached() +bool ntripServerConnectLimitReached(int serverIndex) { int seconds; @@ -262,10 +263,10 @@ bool ntripServerConnectLimitReached() // Attempt to restart the network if possible if (settings.enableNtripServer && (!limitReached)) - networkRestart(NETWORK_USER_NTRIP_SERVER); + networkRestart(NETWORK_USER_NTRIP_SERVER + serverIndex); // Shutdown the NTRIP server - ntripServerStop(limitReached || (!settings.enableNtripServer)); + ntripServerStop(serverIndex, limitReached || (!settings.enableNtripServer)); ntripServerConnectionAttempts++; ntripServerConnectionAttemptsTotal++; @@ -380,8 +381,9 @@ void ntripServerPrintStatus () } // This function gets called as each RTCM byte comes in -void ntripServerProcessRTCM(uint8_t incoming) +void ntripServerProcessRTCM(int serverIndex, uint8_t incoming) { + NTRIP_SERVER_DATA * ntripServer = &ntripServerArray[serverIndex]; static uint32_t zedBytesSent; if (ntripServerState == NTRIP_SERVER_CASTING) @@ -420,9 +422,9 @@ void ntripServerProcessRTCM(uint8_t incoming) ntripServerBytesSent = 0; } - if (ntripServer->connected()) + if (ntripServer->networkClient->connected()) { - ntripServer->write(incoming); // Send this byte to socket + ntripServer->networkClient->write(incoming); // Send this byte to socket ntripServerBytesSent++; zedBytesSent++; ntripServerTimer = millis(); @@ -439,28 +441,29 @@ void ntripServerProcessRTCM(uint8_t incoming) } // Read the authorization response from the NTRIP caster -void ntripServerResponse(char *response, size_t maxLength) +void ntripServerResponse(int serverIndex, char *response, size_t maxLength) { + NTRIP_SERVER_DATA * ntripServer = &ntripServerArray[serverIndex]; char *responseEnd; // Make sure that we can zero terminate the response responseEnd = &response[maxLength - 1]; // Read bytes from the caster and store them - while ((response < responseEnd) && ntripServer->available()) - *response++ = ntripServer->read(); + while ((response < responseEnd) && ntripServer->networkClient->available()) + *response++ = ntripServer->networkClient->read(); // Zero terminate the response *response = '\0'; } // Restart the NTRIP server -void ntripServerRestart() +void ntripServerRestart(int serverIndex) { // Save the previous uptime value if (ntripServerState == NTRIP_SERVER_CASTING) ntripServerStartTime = ntripServerTimer - ntripServerStartTime; - ntripServerConnectLimitReached(); + ntripServerConnectLimitReached(serverIndex); } // Update the state of the NTRIP server state machine @@ -488,34 +491,36 @@ void ntripServerSetState(uint8_t newState) } // Shutdown the NTRIP server -void ntripServerShutdown() +void ntripServerShutdown(int serverIndex) { - ntripServerStop(true); + ntripServerStop(serverIndex, true); } // Start the NTRIP server -void ntripServerStart() +void ntripServerStart(int serverIndex) { // Display the heap state reportHeapNow(settings.debugNtripServerState); // Start the NTRIP server systemPrintln ("NTRIP Server start"); - ntripServerStop(false); + ntripServerStop(serverIndex, false); } // Shutdown or restart the NTRIP server -void ntripServerStop(bool shutdown) +void ntripServerStop(int serverIndex, bool shutdown) { - if (ntripServer) + NTRIP_SERVER_DATA * ntripServer = &ntripServerArray[serverIndex]; + + if (ntripServer->networkClient) { // Break the NTRIP server connection if necessary - if (ntripServer->connected()) - ntripServer->stop(); + if (ntripServer->networkClient->connected()) + ntripServer->networkClient->stop(); // Free the NTRIP server resources - delete ntripServer; - ntripServer = nullptr; + delete ntripServer->networkClient; + ntripServer->networkClient = nullptr; reportHeapNow(settings.debugNtripServerState); } @@ -526,8 +531,8 @@ void ntripServerStop(bool shutdown) ntripServerTimer = millis(); // Done with the network - if (networkGetUserNetwork(NETWORK_USER_NTRIP_SERVER)) - networkUserClose(NETWORK_USER_NTRIP_SERVER); + if (networkGetUserNetwork(NETWORK_USER_NTRIP_SERVER + serverIndex)) + networkUserClose(NETWORK_USER_NTRIP_SERVER + serverIndex); } // Determine the next NTRIP server state @@ -544,8 +549,11 @@ void ntripServerStop(bool shutdown) } // Update the NTRIP server state machine -void ntripServerUpdate() +void ntripServerUpdate(int serverIndex) { + // Get the NTRIP data structure + NTRIP_SERVER_DATA * ntripServer = &ntripServerArray[serverIndex]; + // For Ref Stn, process any RTCM data waiting in the u-blox library RTCM Buffer // This causes the state change from NTRIP_SERVER_WAIT_GNSS_DATA to NTRIP_SERVER_CONNECTING processRTCMBuffer(); @@ -556,7 +564,7 @@ void ntripServerUpdate() { if (ntripServerState > NTRIP_SERVER_OFF) { - ntripServerStop(false); + ntripServerStop(serverIndex, false); ntripServerConnectionAttempts = 0; ntripServerConnectionAttemptTimeout = 0; ntripServerSetState(NTRIP_SERVER_OFF); @@ -568,32 +576,32 @@ void ntripServerUpdate() { case NTRIP_SERVER_OFF: if (EQ_RTK_MODE(ntripServerMode) && settings.enableNtripServer) - ntripServerStart(); + ntripServerStart(serverIndex); break; // Start the network case NTRIP_SERVER_ON: - if (networkUserOpen(NETWORK_USER_NTRIP_SERVER, NETWORK_TYPE_ACTIVE)) + if (networkUserOpen(NETWORK_USER_NTRIP_SERVER + serverIndex, NETWORK_TYPE_ACTIVE)) ntripServerSetState(NTRIP_SERVER_NETWORK_STARTED); break; // Wait for a network media connection case NTRIP_SERVER_NETWORK_STARTED: // Determine if the network has failed - if (networkIsShuttingDown(NETWORK_USER_NTRIP_SERVER)) + if (networkIsShuttingDown(NETWORK_USER_NTRIP_SERVER + serverIndex)) // Failed to connect to to the network, attempt to restart the network - ntripServerRestart(); + ntripServerRestart(serverIndex); // Determine if the network is connected to the media - else if (networkUserConnected(NETWORK_USER_NTRIP_SERVER)) + else if (networkUserConnected(NETWORK_USER_NTRIP_SERVER + serverIndex)) { // Allocate the ntripServer structure - ntripServer = new NetworkClient(NETWORK_USER_NTRIP_SERVER); - if (!ntripServer) + ntripServer->networkClient = new NetworkClient(NETWORK_USER_NTRIP_SERVER + serverIndex); + if (!ntripServer->networkClient) { // Failed to allocate the ntripServer structure systemPrintln("ERROR: Failed to allocate the ntripServer structure!"); - ntripServerShutdown(); + ntripServerShutdown(serverIndex); } else { @@ -608,9 +616,9 @@ void ntripServerUpdate() // Network available case NTRIP_SERVER_NETWORK_CONNECTED: // Determine if the network has failed - if (networkIsShuttingDown(NETWORK_USER_NTRIP_SERVER)) + if (networkIsShuttingDown(NETWORK_USER_NTRIP_SERVER + serverIndex)) // Failed to connect to to the network, attempt to restart the network - ntripServerRestart(); + ntripServerRestart(serverIndex); else if (settings.enableNtripServer && (millis() - ntripServerLastConnectionAttempt > ntripServerConnectionAttemptTimeout)) @@ -626,9 +634,9 @@ void ntripServerUpdate() // Wait for GNSS correction data case NTRIP_SERVER_WAIT_GNSS_DATA: // Determine if the network has failed - if (networkIsShuttingDown(NETWORK_USER_NTRIP_SERVER)) + if (networkIsShuttingDown(NETWORK_USER_NTRIP_SERVER + serverIndex)) // Failed to connect to to the network, attempt to restart the network - ntripServerRestart(); + ntripServerRestart(serverIndex); // State change handled in ntripServerProcessRTCM break; @@ -636,18 +644,18 @@ void ntripServerUpdate() // Initiate the connection to the NTRIP caster case NTRIP_SERVER_CONNECTING: // Determine if the network has failed - if (networkIsShuttingDown(NETWORK_USER_NTRIP_SERVER)) + if (networkIsShuttingDown(NETWORK_USER_NTRIP_SERVER + serverIndex)) // Failed to connect to to the network, attempt to restart the network - ntripServerRestart(); + ntripServerRestart(serverIndex); // Delay before opening the NTRIP server connection else if ((millis() - ntripServerTimer) >= ntripServerConnectionAttemptTimeout) { // Attempt a connection to the NTRIP caster - if (!ntripServerConnectCaster()) + if (!ntripServerConnectCaster(serverIndex)) { // Assume service not available - if (ntripServerConnectLimitReached()) // Update ntripServerConnectionAttemptTimeout + if (ntripServerConnectLimitReached(serverIndex)) // Update ntripServerConnectionAttemptTimeout systemPrintln("NTRIP Server failed to connect! Do you have your caster address and port correct?"); } else @@ -662,17 +670,17 @@ void ntripServerUpdate() // Wait for authorization response case NTRIP_SERVER_AUTHORIZATION: // Determine if the network has failed - if (networkIsShuttingDown(NETWORK_USER_NTRIP_SERVER)) + if (networkIsShuttingDown(NETWORK_USER_NTRIP_SERVER + serverIndex)) // Failed to connect to to the network, attempt to restart the network - ntripServerRestart(); + ntripServerRestart(serverIndex); // Check if caster service responded - else if (ntripServer->available() < strlen("ICY 200 OK")) // Wait until at least a few bytes have arrived + else if (ntripServer->networkClient->available() < strlen("ICY 200 OK")) // Wait until at least a few bytes have arrived { // Check for response timeout if (millis() - ntripServerTimer > 10000) { - if (ntripServerConnectLimitReached()) + if (ntripServerConnectLimitReached(serverIndex)) systemPrintln("Caster failed to respond. Do you have your caster address and port correct?"); } } @@ -680,7 +688,7 @@ void ntripServerUpdate() { // NTRIP caster's authorization response received char response[512]; - ntripServerResponse(response, sizeof(response)); + ntripServerResponse(serverIndex, response, sizeof(response)); if (settings.debugNtripServerState) systemPrintf("Server Response: %s\r\n", response); @@ -697,7 +705,7 @@ void ntripServerUpdate() response); // Stop NTRIP Server operations - ntripServerShutdown(); + ntripServerShutdown(serverIndex); } else if (strcasestr(response, "sandbox") != nullptr) { @@ -705,7 +713,7 @@ void ntripServerUpdate() response); // Stop NTRIP Server operations - ntripServerShutdown(); + ntripServerShutdown(serverIndex); } systemPrintf("NTRIP Server connected to %s:%d %s\r\n", settings.ntripServer_CasterHost, @@ -728,7 +736,7 @@ void ntripServerUpdate() response); // Give up - Shutdown NTRIP server, no further retries - ntripServerShutdown(); + ntripServerShutdown(serverIndex); } // Other errors returned by the caster @@ -737,7 +745,7 @@ void ntripServerUpdate() systemPrintf("NTRIP Server connected but caster responded with problem: %s\r\n", response); // Check for connection limit - if (ntripServerConnectLimitReached()) + if (ntripServerConnectLimitReached(serverIndex)) systemPrintln("NTRIP Server retry limit reached; do you have your caster address and port correct?"); } } @@ -746,22 +754,22 @@ void ntripServerUpdate() // NTRIP server authorized to send RTCM correction data to NTRIP caster case NTRIP_SERVER_CASTING: // Determine if the network has failed - if (networkIsShuttingDown(NETWORK_USER_NTRIP_SERVER)) + if (networkIsShuttingDown(NETWORK_USER_NTRIP_SERVER + serverIndex)) // Failed to connect to to the network, attempt to restart the network - ntripServerRestart(); + ntripServerRestart(serverIndex); // Check for a broken connection - else if (!ntripServer->connected()) + else if (!ntripServer->networkClient->connected()) { // Broken connection, retry the NTRIP connection systemPrintln("Connection to NTRIP Caster was lost"); - ntripServerRestart(); + ntripServerRestart(serverIndex); } else if ((millis() - ntripServerTimer) > (15 * 1000)) { // GNSS stopped sending RTCM correction data systemPrintln("NTRIP Server breaking connection to caster due to lack of RTCM data!"); - ntripServerRestart(); + ntripServerRestart(serverIndex); } else { @@ -792,11 +800,20 @@ void ntripServerUpdate() ntripServerSetState(ntripServerState); } +// Update the NTRIP server state machine +void ntripServerUpdate() +{ + for (int serverIndex = 0; serverIndex < NTRIP_SERVER_MAX; serverIndex++) + ntripServerUpdate(serverIndex); +} + // Verify the NTRIP server tables void ntripServerValidateTables() { if (ntripServerStateNameEntries != NTRIP_SERVER_STATE_MAX) reportFatalError("Fix ntripServerStateNameEntries to match NTRIPServerState"); + if (NETWORK_USER_MAX > (sizeof(NETWORK_USER) * 8)) + reportFatalError("Increase the NETWORK_USER type"); } #endif // COMPILE_NETWORK diff --git a/Firmware/RTK_Surveyor/RTK_Surveyor.ino b/Firmware/RTK_Surveyor/RTK_Surveyor.ino index 7cfd677a7..d1e3429e2 100644 --- a/Firmware/RTK_Surveyor/RTK_Surveyor.ino +++ b/Firmware/RTK_Surveyor/RTK_Surveyor.ino @@ -60,6 +60,8 @@ // the minor firmware version #define RTK_IDENTIFIER (FIRMWARE_VERSION_MAJOR * 0x10 + FIRMWARE_VERSION_MINOR) +#define NTRIP_SERVER_MAX 1 + #ifdef COMPILE_ETHERNET #include // http://librarymanager/All#Arduino_Ethernet #include "SparkFun_WebServer_ESP32_W5500.h" //http://librarymanager/All#SparkFun_WebServer_ESP32_W5500 v1.5.5 diff --git a/Firmware/RTK_Surveyor/settings.h b/Firmware/RTK_Surveyor/settings.h index 21b9a0c91..6cc9cbe5c 100644 --- a/Firmware/RTK_Surveyor/settings.h +++ b/Firmware/RTK_Surveyor/settings.h @@ -240,16 +240,18 @@ enum NetworkUsers { NETWORK_USER_NTP_SERVER = 0, // NTP server NETWORK_USER_NTRIP_CLIENT, // NTRIP client - NETWORK_USER_NTRIP_SERVER, // NTRIP server NETWORK_USER_OTA_FIRMWARE_UPDATE, // Over-The-Air firmware updates NETWORK_USER_PVT_CLIENT, // PVT client NETWORK_USER_PVT_SERVER, // PVT server NETWORK_USER_PVT_UDP_SERVER, // PVT UDP server + + // Add new users above this line + NETWORK_USER_NTRIP_SERVER, // NTRIP server // Last network user - NETWORK_USER_MAX + NETWORK_USER_MAX = NETWORK_USER_NTRIP_SERVER + NTRIP_SERVER_MAX }; -typedef uint8_t NETWORK_USER; +typedef uint16_t NETWORK_USER; typedef struct _NETWORK_DATA { From cb578a71e5bb82975833eae486c10a91dff653a6 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Fri, 26 Apr 2024 07:54:25 -1000 Subject: [PATCH 04/11] Move NTRIP server data into the data structure --- Firmware/RTK_Surveyor/Display.ino | 2 +- Firmware/RTK_Surveyor/NtripServer.ino | 175 +++++++++++-------------- Firmware/RTK_Surveyor/RTK_Surveyor.ino | 2 + Firmware/RTK_Surveyor/menuSystem.ino | 3 +- 4 files changed, 83 insertions(+), 99 deletions(-) diff --git a/Firmware/RTK_Surveyor/Display.ino b/Firmware/RTK_Surveyor/Display.ino index 7829b012a..435bef340 100644 --- a/Firmware/RTK_Surveyor/Display.ino +++ b/Firmware/RTK_Surveyor/Display.ino @@ -1726,7 +1726,7 @@ void printTextwithKerning(const char *newText, uint8_t xPos, uint8_t yPos, uint8 void paintRTCM() { int yPos = 17; - if (ntripServerIsCasting()) + if (online.ntripServer) printTextCenter("Casting", yPos, QW_FONT_8X16, 1, false); // text, y, font type, kerning, inverted else printTextCenter("Xmitting", yPos, QW_FONT_8X16, 1, false); // text, y, font type, kerning, inverted diff --git a/Firmware/RTK_Surveyor/NtripServer.ino b/Firmware/RTK_Surveyor/NtripServer.ino index 9c987ab98..f2f7f5626 100644 --- a/Firmware/RTK_Surveyor/NtripServer.ino +++ b/Firmware/RTK_Surveyor/NtripServer.ino @@ -178,25 +178,6 @@ const RtkMode_t ntripServerMode = RTK_MODE_BASE_FIXED; // NTRIP Servers static NTRIP_SERVER_DATA ntripServerArray[NTRIP_SERVER_MAX]; -static volatile uint8_t ntripServerState = NTRIP_SERVER_OFF; - -// Count of bytes sent by the NTRIP server to the NTRIP caster -uint32_t ntripServerBytesSent; - -// Throttle the time between connection attempts -// ms - Max of 4,294,967,295 or 4.3M seconds or 71,000 minutes or 1193 hours or 49 days between attempts -static uint32_t ntripServerConnectionAttemptTimeout; -static uint32_t ntripServerLastConnectionAttempt; -static int ntripServerConnectionAttempts; // Count the number of connection attempts between restarts - -// NTRIP server timer usage: -// * Reconnection delay -// * Measure the connection response time -// * Receive RTCM correction data timeout -// * Monitor last RTCM byte received for frame counting -static uint32_t ntripServerTimer; -static uint32_t ntripServerStartTime; -static int ntripServerConnectionAttemptsTotal; // Count the number of connection attempts absolutely //---------------------------------------- // NTRIP Server Routines @@ -256,10 +237,11 @@ bool ntripServerConnectCaster(int serverIndex) // Determine if the connection limit has been reached bool ntripServerConnectLimitReached(int serverIndex) { + NTRIP_SERVER_DATA * ntripServer = &ntripServerArray[serverIndex]; int seconds; // Retry the connection a few times - bool limitReached = (ntripServerConnectionAttempts >= MAX_NTRIP_SERVER_CONNECTION_ATTEMPTS); + bool limitReached = (ntripServer->connectionAttempts >= MAX_NTRIP_SERVER_CONNECTION_ATTEMPTS); // Attempt to restart the network if possible if (settings.enableNtripServer && (!limitReached)) @@ -268,29 +250,29 @@ bool ntripServerConnectLimitReached(int serverIndex) // Shutdown the NTRIP server ntripServerStop(serverIndex, limitReached || (!settings.enableNtripServer)); - ntripServerConnectionAttempts++; - ntripServerConnectionAttemptsTotal++; + ntripServer->connectionAttempts++; + ntripServer->connectionAttemptsTotal++; if (settings.debugNtripServerState) - ntripServerPrintStatus(); + ntripServerPrintStatus(serverIndex); if (limitReached == false) { - if (ntripServerConnectionAttempts == 1) - ntripServerConnectionAttemptTimeout = 15 * 1000L; // Wait 15s - else if (ntripServerConnectionAttempts == 2) - ntripServerConnectionAttemptTimeout = 30 * 1000L; // Wait 30s - else if (ntripServerConnectionAttempts == 3) - ntripServerConnectionAttemptTimeout = 1 * 60 * 1000L; // Wait 1 minute - else if (ntripServerConnectionAttempts == 4) - ntripServerConnectionAttemptTimeout = 2 * 60 * 1000L; // Wait 2 minutes + if (ntripServer->connectionAttempts == 1) + ntripServer->connectionAttemptTimeout = 15 * 1000L; // Wait 15s + else if (ntripServer->connectionAttempts == 2) + ntripServer->connectionAttemptTimeout = 30 * 1000L; // Wait 30s + else if (ntripServer->connectionAttempts == 3) + ntripServer->connectionAttemptTimeout = 1 * 60 * 1000L; // Wait 1 minute + else if (ntripServer->connectionAttempts == 4) + ntripServer->connectionAttemptTimeout = 2 * 60 * 1000L; // Wait 2 minutes else - ntripServerConnectionAttemptTimeout = - (ntripServerConnectionAttempts - 4) * 5 * 60 * 1000L; // Wait 5, 10, 15, etc minutes between attempts + ntripServer->connectionAttemptTimeout = + (ntripServer->connectionAttempts - 4) * 5 * 60 * 1000L; // Wait 5, 10, 15, etc minutes between attempts // Display the delay before starting the NTRIP server - if (settings.debugNtripServerState && ntripServerConnectionAttemptTimeout) + if (settings.debugNtripServerState && ntripServer->connectionAttemptTimeout) { - seconds = ntripServerConnectionAttemptTimeout / 1000; + seconds = ntripServer->connectionAttemptTimeout / 1000; if (seconds < 120) systemPrintf("NTRIP Server trying again in %d seconds.\r\n", seconds); else @@ -303,19 +285,15 @@ bool ntripServerConnectLimitReached(int serverIndex) return limitReached; } -// Determine if the NTRIP server is casting -bool ntripServerIsCasting() -{ - return (ntripServerState == NTRIP_SERVER_CASTING); -} - // Print the NTRIP server state summary -void ntripServerPrintStateSummary() +void ntripServerPrintStateSummary(int serverIndex) { - switch (ntripServerState) + NTRIP_SERVER_DATA * ntripServer = &ntripServerArray[serverIndex]; + + switch (ntripServer->state) { default: - systemPrintf("Unknown: %d", ntripServerState); + systemPrintf("Unknown: %d", ntripServer->state); break; case NTRIP_SERVER_OFF: systemPrint("Disconnected"); @@ -335,8 +313,9 @@ void ntripServerPrintStateSummary() } // Print the NTRIP server status -void ntripServerPrintStatus () +void ntripServerPrintStatus (int serverIndex) { + NTRIP_SERVER_DATA * ntripServer = &ntripServerArray[serverIndex]; uint64_t milliseconds; uint32_t days; byte hours; @@ -347,17 +326,17 @@ void ntripServerPrintStatus () (systemState >= STATE_BASE_NOT_STARTED && systemState <= STATE_BASE_FIXED_TRANSMITTING)) { systemPrint("NTRIP Server "); - ntripServerPrintStateSummary(); + ntripServerPrintStateSummary(serverIndex); systemPrintf(" - %s/%s:%d", settings.ntripServer_CasterHost, settings.ntripServer_MountPoint, settings.ntripServer_CasterPort); - if (ntripServerState == NTRIP_SERVER_CASTING) - // Use ntripServerTimer since it gets reset after each successful data + if (ntripServer->state == NTRIP_SERVER_CASTING) + // Use ntripServer->timer since it gets reset after each successful data // receiption from the NTRIP caster - milliseconds = ntripServerTimer - ntripServerStartTime; + milliseconds = ntripServer->timer - ntripServer->startTime; else { - milliseconds = ntripServerStartTime; + milliseconds = ntripServer->startTime; systemPrint(" Last"); } @@ -376,7 +355,7 @@ void ntripServerPrintStatus () systemPrint(" Uptime: "); systemPrintf("%d %02d:%02d:%02d.%03lld (Reconnects: %d)\r\n", - days, hours, minutes, seconds, milliseconds, ntripServerConnectionAttemptsTotal); + days, hours, minutes, seconds, milliseconds, ntripServer->connectionAttemptsTotal); } } @@ -386,7 +365,7 @@ void ntripServerProcessRTCM(int serverIndex, uint8_t incoming) NTRIP_SERVER_DATA * ntripServer = &ntripServerArray[serverIndex]; static uint32_t zedBytesSent; - if (ntripServerState == NTRIP_SERVER_CASTING) + if (ntripServer->state == NTRIP_SERVER_CASTING) { // Generate and print timestamp if needed uint32_t currentMilliseconds; @@ -397,7 +376,7 @@ void ntripServerProcessRTCM(int serverIndex, uint8_t incoming) currentMilliseconds = millis(); if (((settings.debugNtripServerRtcm && ((currentMilliseconds - previousMilliseconds) > 5)) || PERIODIC_DISPLAY(PD_NTRIP_SERVER_DATA)) && (!settings.enableRtcmMessageChecking) - && (!inMainMenu) && ntripServerBytesSent) + && (!inMainMenu) && ntripServer->bytesSent) { PERIODIC_CLEAR(PD_NTRIP_SERVER_DATA); printTimeStamp(); @@ -414,28 +393,28 @@ void ntripServerProcessRTCM(int serverIndex, uint8_t incoming) } // If we have not gotten new RTCM bytes for a period of time, assume end of frame - if (((millis() - ntripServerTimer) > 100) && (ntripServerBytesSent > 0)) + if (((millis() - ntripServer->timer) > 100) && (ntripServer->bytesSent > 0)) { if ((!inMainMenu) && settings.debugNtripServerState) - systemPrintf("NTRIP Server transmitted %d RTCM bytes to Caster\r\n", ntripServerBytesSent); + systemPrintf("NTRIP Server transmitted %d RTCM bytes to Caster\r\n", ntripServer->bytesSent); - ntripServerBytesSent = 0; + ntripServer->bytesSent = 0; } if (ntripServer->networkClient->connected()) { ntripServer->networkClient->write(incoming); // Send this byte to socket - ntripServerBytesSent++; + ntripServer->bytesSent++; zedBytesSent++; - ntripServerTimer = millis(); + ntripServer->timer = millis(); netOutgoingRTCM = true; } } // Indicate that the GNSS is providing correction data - else if (ntripServerState == NTRIP_SERVER_WAIT_GNSS_DATA) + else if (ntripServer->state == NTRIP_SERVER_WAIT_GNSS_DATA) { - ntripServerSetState(NTRIP_SERVER_CONNECTING); + ntripServerSetState(ntripServer, NTRIP_SERVER_CONNECTING); rtcmParsingState = RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3; } } @@ -460,23 +439,25 @@ void ntripServerResponse(int serverIndex, char *response, size_t maxLength) // Restart the NTRIP server void ntripServerRestart(int serverIndex) { + NTRIP_SERVER_DATA * ntripServer = &ntripServerArray[serverIndex]; + // Save the previous uptime value - if (ntripServerState == NTRIP_SERVER_CASTING) - ntripServerStartTime = ntripServerTimer - ntripServerStartTime; + if (ntripServer->state == NTRIP_SERVER_CASTING) + ntripServer->startTime = ntripServer->timer - ntripServer->startTime; ntripServerConnectLimitReached(serverIndex); } // Update the state of the NTRIP server state machine -void ntripServerSetState(uint8_t newState) +void ntripServerSetState(NTRIP_SERVER_DATA * ntripServer, uint8_t newState) { if (settings.debugNtripServerState || PERIODIC_DISPLAY(PD_NTRIP_SERVER_STATE)) { - if (ntripServerState == newState) + if (ntripServer->state == newState) systemPrint("*"); else - systemPrintf("%s --> ", ntripServerStateName[ntripServerState]); + systemPrintf("%s --> ", ntripServerStateName[ntripServer->state]); } - ntripServerState = newState; + ntripServer->state = newState; if (settings.debugNtripServerState || PERIODIC_DISPLAY(PD_NTRIP_SERVER_STATE)) { PERIODIC_CLEAR(PD_NTRIP_SERVER_STATE); @@ -486,7 +467,7 @@ void ntripServerSetState(uint8_t newState) reportFatalError("Unknown NTRIP Server state"); } else - systemPrintln(ntripServerStateName[ntripServerState]); + systemPrintln(ntripServerStateName[ntripServer->state]); } } @@ -525,10 +506,10 @@ void ntripServerStop(int serverIndex, bool shutdown) } // Increase timeouts if we started the network - if (ntripServerState > NTRIP_SERVER_ON) + if (ntripServer->state > NTRIP_SERVER_ON) { // Mark the Server stop so that we don't immediately attempt re-connect to Caster - ntripServerTimer = millis(); + ntripServer->timer = millis(); // Done with the network if (networkGetUserNetwork(NETWORK_USER_NTRIP_SERVER + serverIndex)) @@ -539,13 +520,13 @@ void ntripServerStop(int serverIndex, bool shutdown) online.ntripServer = false; if (shutdown) { - ntripServerSetState(NTRIP_SERVER_OFF); + ntripServerSetState(ntripServer, NTRIP_SERVER_OFF); settings.enableNtripServer = false; - ntripServerConnectionAttempts = 0; - ntripServerConnectionAttemptTimeout = 0; + ntripServer->connectionAttempts = 0; + ntripServer->connectionAttemptTimeout = 0; } else - ntripServerSetState(NTRIP_SERVER_ON); + ntripServerSetState(ntripServer, NTRIP_SERVER_ON); } // Update the NTRIP server state machine @@ -559,20 +540,20 @@ void ntripServerUpdate(int serverIndex) processRTCMBuffer(); // Shutdown the NTRIP server when the mode or setting changes - DMW_st(ntripServerSetState, ntripServerState); + DMW_ds(ntripServerSetState, ntripServer); if (NEQ_RTK_MODE(ntripServerMode) || (!settings.enableNtripServer)) { - if (ntripServerState > NTRIP_SERVER_OFF) + if (ntripServer->state > NTRIP_SERVER_OFF) { ntripServerStop(serverIndex, false); - ntripServerConnectionAttempts = 0; - ntripServerConnectionAttemptTimeout = 0; - ntripServerSetState(NTRIP_SERVER_OFF); + ntripServer->connectionAttempts = 0; + ntripServer->connectionAttemptTimeout = 0; + ntripServerSetState(ntripServer, NTRIP_SERVER_OFF); } } // Enable the network and the NTRIP server if requested - switch (ntripServerState) + switch (ntripServer->state) { case NTRIP_SERVER_OFF: if (EQ_RTK_MODE(ntripServerMode) && settings.enableNtripServer) @@ -582,7 +563,7 @@ void ntripServerUpdate(int serverIndex) // Start the network case NTRIP_SERVER_ON: if (networkUserOpen(NETWORK_USER_NTRIP_SERVER + serverIndex, NETWORK_TYPE_ACTIVE)) - ntripServerSetState(NTRIP_SERVER_NETWORK_STARTED); + ntripServerSetState(ntripServer, NTRIP_SERVER_NETWORK_STARTED); break; // Wait for a network media connection @@ -608,7 +589,7 @@ void ntripServerUpdate(int serverIndex) reportHeapNow(settings.debugNtripServerState); // The network is available for the NTRIP server - ntripServerSetState(NTRIP_SERVER_NETWORK_CONNECTED); + ntripServerSetState(ntripServer, NTRIP_SERVER_NETWORK_CONNECTED); } } break; @@ -621,13 +602,13 @@ void ntripServerUpdate(int serverIndex) ntripServerRestart(serverIndex); else if (settings.enableNtripServer - && (millis() - ntripServerLastConnectionAttempt > ntripServerConnectionAttemptTimeout)) + && (millis() - ntripServer->lastConnectionAttempt > ntripServer->connectionAttemptTimeout)) { // No RTCM correction data sent yet rtcmPacketsSent = 0; // Open socket to NTRIP caster - ntripServerSetState(NTRIP_SERVER_WAIT_GNSS_DATA); + ntripServerSetState(ntripServer, NTRIP_SERVER_WAIT_GNSS_DATA); } break; @@ -649,20 +630,20 @@ void ntripServerUpdate(int serverIndex) ntripServerRestart(serverIndex); // Delay before opening the NTRIP server connection - else if ((millis() - ntripServerTimer) >= ntripServerConnectionAttemptTimeout) + else if ((millis() - ntripServer->timer) >= ntripServer->connectionAttemptTimeout) { // Attempt a connection to the NTRIP caster if (!ntripServerConnectCaster(serverIndex)) { // Assume service not available - if (ntripServerConnectLimitReached(serverIndex)) // Update ntripServerConnectionAttemptTimeout + if (ntripServerConnectLimitReached(serverIndex)) // Update ntripServer->connectionAttemptTimeout systemPrintln("NTRIP Server failed to connect! Do you have your caster address and port correct?"); } else { // Connection open to NTRIP caster, wait for the authorization response - ntripServerTimer = millis(); - ntripServerSetState(NTRIP_SERVER_AUTHORIZATION); + ntripServer->timer = millis(); + ntripServerSetState(ntripServer, NTRIP_SERVER_AUTHORIZATION); } } break; @@ -678,7 +659,7 @@ void ntripServerUpdate(int serverIndex) else if (ntripServer->networkClient->available() < strlen("ICY 200 OK")) // Wait until at least a few bytes have arrived { // Check for response timeout - if (millis() - ntripServerTimer > 10000) + if (millis() - ntripServer->timer > 10000) { if (ntripServerConnectLimitReached(serverIndex)) systemPrintln("Caster failed to respond. Do you have your caster address and port correct?"); @@ -720,12 +701,12 @@ void ntripServerUpdate(int serverIndex) settings.ntripServer_CasterPort, settings.ntripServer_MountPoint); // Connection is now open, start the RTCM correction data timer - ntripServerTimer = millis(); + ntripServer->timer = millis(); // We don't use a task because we use I2C hardware (and don't have a semphore). online.ntripServer = true; - ntripServerStartTime = millis(); - ntripServerSetState(NTRIP_SERVER_CASTING); + ntripServer->startTime = millis(); + ntripServerSetState(ntripServer, NTRIP_SERVER_CASTING); } // Look for '401 Unauthorized' @@ -765,7 +746,7 @@ void ntripServerUpdate(int serverIndex) systemPrintln("Connection to NTRIP Caster was lost"); ntripServerRestart(serverIndex); } - else if ((millis() - ntripServerTimer) > (15 * 1000)) + else if ((millis() - ntripServer->timer) > (15 * 1000)) { // GNSS stopped sending RTCM correction data systemPrintln("NTRIP Server breaking connection to caster due to lack of RTCM data!"); @@ -779,12 +760,12 @@ void ntripServerUpdate(int serverIndex) // connection. However increasing backoff delays should be // added when the NTRIP caster fails after a short connection // interval. - if (((millis() - ntripServerStartTime) > NTRIP_SERVER_CONNECTION_TIME) - && (ntripServerConnectionAttempts || ntripServerConnectionAttemptTimeout)) + if (((millis() - ntripServer->startTime) > NTRIP_SERVER_CONNECTION_TIME) + && (ntripServer->connectionAttempts || ntripServer->connectionAttemptTimeout)) { // After a long connection period, reset the attempt counter - ntripServerConnectionAttempts = 0; - ntripServerConnectionAttemptTimeout = 0; + ntripServer->connectionAttempts = 0; + ntripServer->connectionAttemptTimeout = 0; if (settings.debugNtripServerState) systemPrintln("NTRIP Server resetting connection attempt counter and timeout"); } @@ -797,7 +778,7 @@ void ntripServerUpdate(int serverIndex) // Periodically display the state if (PERIODIC_DISPLAY(PD_NTRIP_SERVER_STATE)) - ntripServerSetState(ntripServerState); + ntripServerSetState(ntripServer, ntripServer->state); } // Update the NTRIP server state machine diff --git a/Firmware/RTK_Surveyor/RTK_Surveyor.ino b/Firmware/RTK_Surveyor/RTK_Surveyor.ino index d1e3429e2..aa8389f81 100644 --- a/Firmware/RTK_Surveyor/RTK_Surveyor.ino +++ b/Firmware/RTK_Surveyor/RTK_Surveyor.ino @@ -732,6 +732,7 @@ RtkMode_t rtkMode; // Mode of operation volatile bool deadManWalking; #define DMW_if if (deadManWalking) #define DMW_c(string) DMW_if systemPrintf("%s called\r\n", string); +#define DMW_ds(routine, dataStructure) DMW_if routine(dataStructure, dataStructure->state); #define DMW_m(string) DMW_if systemPrintln(string); #define DMW_r(string) DMW_if systemPrintf("%s returning\r\n",string); #define DMW_rs(string, status) DMW_if systemPrintf("%s returning %d\r\n",string, (int32_t)status); @@ -780,6 +781,7 @@ volatile bool deadManWalking; #define deadManWalking 0 #define DMW_if if (0) #define DMW_c(string) +#define DMW_ds(routine, dataStructure) #define DMW_m(string) #define DMW_r(string) #define DMW_rs(string, status) diff --git a/Firmware/RTK_Surveyor/menuSystem.ino b/Firmware/RTK_Surveyor/menuSystem.ino index ae81709a0..ccfbd2bd8 100644 --- a/Firmware/RTK_Surveyor/menuSystem.ino +++ b/Firmware/RTK_Surveyor/menuSystem.ino @@ -136,7 +136,8 @@ void menuSystem() ntripClientPrintStatus(); // Display NTRIP Server status and uptime - ntripServerPrintStatus(); + for (int serverIndex = 0; serverIndex < NTRIP_SERVER_MAX; serverIndex++) + ntripServerPrintStatus(serverIndex); systemPrintf("Filtered by parser: %d NMEA / %d RTCM / %d UBX\r\n", failedParserMessages_NMEA, failedParserMessages_RTCM, failedParserMessages_UBX); From cc5009673d8521c973f138f5ebe381da7366fad4 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Fri, 26 Apr 2024 08:55:07 -1000 Subject: [PATCH 05/11] Add the NTRIP Server number to the error messages --- Firmware/RTK_Surveyor/NtripServer.ino | 63 ++++++++++++++------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/Firmware/RTK_Surveyor/NtripServer.ino b/Firmware/RTK_Surveyor/NtripServer.ino index f2f7f5626..83e1a188a 100644 --- a/Firmware/RTK_Surveyor/NtripServer.ino +++ b/Firmware/RTK_Surveyor/NtripServer.ino @@ -203,7 +203,7 @@ bool ntripServerConnectCaster(int serverIndex) } if (settings.debugNtripServerState) - systemPrintf("NTRIP Server connecting to %s:%d\r\n", + systemPrintf("NTRIP Server %d connecting to %s:%d\r\n", serverIndex, settings.ntripServer_CasterHost, settings.ntripServer_CasterPort); @@ -211,14 +211,15 @@ bool ntripServerConnectCaster(int serverIndex) if (!ntripServer->networkClient->connect(settings.ntripServer_CasterHost, settings.ntripServer_CasterPort)) { if (settings.debugNtripServerState) - systemPrintf("NTRIP Server connection to NTRIP caster %s:%d failed\r\n", + systemPrintf("NTRIP Server %d connection to NTRIP caster %s:%d failed\r\n", + serverIndex, settings.ntripServer_CasterHost, settings.ntripServer_CasterPort); return false; } if (settings.debugNtripServerState) - systemPrintln("NTRIP Server sending authorization credentials"); + systemPrintf("NTRIP Server %d sending authorization credentials\r\n", serverIndex); // Build the authorization credentials message // * Mount point @@ -274,14 +275,14 @@ bool ntripServerConnectLimitReached(int serverIndex) { seconds = ntripServer->connectionAttemptTimeout / 1000; if (seconds < 120) - systemPrintf("NTRIP Server trying again in %d seconds.\r\n", seconds); + systemPrintf("NTRIP Server %d trying again in %d seconds.\r\n", serverIndex, seconds); else - systemPrintf("NTRIP Server trying again in %d minutes.\r\n", seconds / 60); + systemPrintf("NTRIP Server %d trying again in %d minutes.\r\n", serverIndex, seconds / 60); } } else // No more connection attempts - systemPrintln("NTRIP Server connection attempts exceeded!"); + systemPrintf("NTRIP Server %d connection attempts exceeded!\r\n", serverIndex); return limitReached; } @@ -325,7 +326,7 @@ void ntripServerPrintStatus (int serverIndex) if (settings.enableNtripServer == true && (systemState >= STATE_BASE_NOT_STARTED && systemState <= STATE_BASE_FIXED_TRANSMITTING)) { - systemPrint("NTRIP Server "); + systemPrintf("NTRIP Server %d ", serverIndex); ntripServerPrintStateSummary(serverIndex); systemPrintf(" - %s/%s:%d", settings.ntripServer_CasterHost, settings.ntripServer_MountPoint, settings.ntripServer_CasterPort); @@ -386,7 +387,7 @@ void ntripServerProcessRTCM(int serverIndex, uint8_t incoming) struct tm timeinfo = rtc.getTimeStruct(); char timestamp[30]; strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", &timeinfo); - systemPrintf(" Tx RTCM: %s.%03ld, %d bytes sent\r\n", timestamp, rtc.getMillis(), zedBytesSent); + systemPrintf(" Tx%d RTCM: %s.%03ld, %d bytes sent\r\n", serverIndex, timestamp, rtc.getMillis(), zedBytesSent); zedBytesSent = 0; } previousMilliseconds = currentMilliseconds; @@ -396,7 +397,7 @@ void ntripServerProcessRTCM(int serverIndex, uint8_t incoming) if (((millis() - ntripServer->timer) > 100) && (ntripServer->bytesSent > 0)) { if ((!inMainMenu) && settings.debugNtripServerState) - systemPrintf("NTRIP Server transmitted %d RTCM bytes to Caster\r\n", ntripServer->bytesSent); + systemPrintf("NTRIP Server %d transmitted %d RTCM bytes to Caster\r\n", serverIndex, ntripServer->bytesSent); ntripServer->bytesSent = 0; } @@ -450,12 +451,14 @@ void ntripServerRestart(int serverIndex) // Update the state of the NTRIP server state machine void ntripServerSetState(NTRIP_SERVER_DATA * ntripServer, uint8_t newState) { + int serverIndex = ntripServer - &ntripServerArray[0]; + if (settings.debugNtripServerState || PERIODIC_DISPLAY(PD_NTRIP_SERVER_STATE)) { if (ntripServer->state == newState) - systemPrint("*"); + systemPrintf("%d: *", serverIndex); else - systemPrintf("%s --> ", ntripServerStateName[ntripServer->state]); + systemPrintf("%d: %s --> ", serverIndex, ntripServerStateName[ntripServer->state]); } ntripServer->state = newState; if (settings.debugNtripServerState || PERIODIC_DISPLAY(PD_NTRIP_SERVER_STATE)) @@ -463,7 +466,7 @@ void ntripServerSetState(NTRIP_SERVER_DATA * ntripServer, uint8_t newState) PERIODIC_CLEAR(PD_NTRIP_SERVER_STATE); if (newState >= NTRIP_SERVER_STATE_MAX) { - systemPrintf("Unknown NTRIP Server state: %d\r\n", newState); + systemPrintf("Unknown NTRIP Server %d state: %d\r\n", serverIndex, newState); reportFatalError("Unknown NTRIP Server state"); } else @@ -484,7 +487,7 @@ void ntripServerStart(int serverIndex) reportHeapNow(settings.debugNtripServerState); // Start the NTRIP server - systemPrintln ("NTRIP Server start"); + systemPrintf("NTRIP Server %d start\r\n", serverIndex); ntripServerStop(serverIndex, false); } @@ -581,7 +584,7 @@ void ntripServerUpdate(int serverIndex) if (!ntripServer->networkClient) { // Failed to allocate the ntripServer structure - systemPrintln("ERROR: Failed to allocate the ntripServer structure!"); + systemPrintf("ERROR: Failed to allocate the ntripServer %d structure!\r\n", serverIndex); ntripServerShutdown(serverIndex); } else @@ -637,7 +640,7 @@ void ntripServerUpdate(int serverIndex) { // Assume service not available if (ntripServerConnectLimitReached(serverIndex)) // Update ntripServer->connectionAttemptTimeout - systemPrintln("NTRIP Server failed to connect! Do you have your caster address and port correct?"); + systemPrintf("NTRIP Server %d failed to connect! Do you have your caster address and port correct?\r\n", serverIndex); } else { @@ -662,7 +665,7 @@ void ntripServerUpdate(int serverIndex) if (millis() - ntripServer->timer > 10000) { if (ntripServerConnectLimitReached(serverIndex)) - systemPrintln("Caster failed to respond. Do you have your caster address and port correct?"); + systemPrintf("Caster %d failed to respond. Do you have your caster address and port correct?\r\n", serverIndex); } } else @@ -672,9 +675,9 @@ void ntripServerUpdate(int serverIndex) ntripServerResponse(serverIndex, response, sizeof(response)); if (settings.debugNtripServerState) - systemPrintf("Server Response: %s\r\n", response); + systemPrintf("Server %d Response: %s\r\n", serverIndex, response); else - log_d("Server Response: %s", response); + log_d("Server %d Response: %s", serverIndex, response); // Look for various responses if (strstr(response, "200") != nullptr) //'200' found @@ -682,22 +685,22 @@ void ntripServerUpdate(int serverIndex) // We got a response, now check it for possible errors if (strcasestr(response, "banned") != nullptr) { - systemPrintf("NTRIP Server connected to caster but caster responded with banned error: %s\r\n", - response); + systemPrintf("NTRIP Server %d connected to caster but caster responded with banned error: %s\r\n", + serverIndex, response); // Stop NTRIP Server operations ntripServerShutdown(serverIndex); } else if (strcasestr(response, "sandbox") != nullptr) { - systemPrintf("NTRIP Server connected to caster but caster responded with sandbox error: %s\r\n", - response); + systemPrintf("NTRIP Server %d connected to caster but caster responded with sandbox error: %s\r\n", + serverIndex, response); // Stop NTRIP Server operations ntripServerShutdown(serverIndex); } - systemPrintf("NTRIP Server connected to %s:%d %s\r\n", settings.ntripServer_CasterHost, + systemPrintf("NTRIP Server %d connected to %s:%d %s\r\n", serverIndex, settings.ntripServer_CasterHost, settings.ntripServer_CasterPort, settings.ntripServer_MountPoint); // Connection is now open, start the RTCM correction data timer @@ -713,8 +716,8 @@ void ntripServerUpdate(int serverIndex) else if (strstr(response, "401") != nullptr) { systemPrintf( - "NTRIP Caster responded with unauthorized error: %s. Are you sure your caster credentials are correct?\r\n", - response); + "NTRIP Caster %d responded with unauthorized error: %s. Are you sure your caster credentials are correct?\r\n", + serverIndex, response); // Give up - Shutdown NTRIP server, no further retries ntripServerShutdown(serverIndex); @@ -723,11 +726,11 @@ void ntripServerUpdate(int serverIndex) // Other errors returned by the caster else { - systemPrintf("NTRIP Server connected but caster responded with problem: %s\r\n", response); + systemPrintf("NTRIP Server %d connected but caster responded with problem: %s\r\n", serverIndex, response); // Check for connection limit if (ntripServerConnectLimitReached(serverIndex)) - systemPrintln("NTRIP Server retry limit reached; do you have your caster address and port correct?"); + systemPrintf("NTRIP Server %d retry limit reached; do you have your caster address and port correct?\r\n", serverIndex); } } break; @@ -743,13 +746,13 @@ void ntripServerUpdate(int serverIndex) else if (!ntripServer->networkClient->connected()) { // Broken connection, retry the NTRIP connection - systemPrintln("Connection to NTRIP Caster was lost"); + systemPrintf("Connection to NTRIP Caster %d was lost\r\n", serverIndex); ntripServerRestart(serverIndex); } else if ((millis() - ntripServer->timer) > (15 * 1000)) { // GNSS stopped sending RTCM correction data - systemPrintln("NTRIP Server breaking connection to caster due to lack of RTCM data!"); + systemPrintf("NTRIP Server %d breaking connection to caster due to lack of RTCM data!\r\n", serverIndex); ntripServerRestart(serverIndex); } else @@ -767,7 +770,7 @@ void ntripServerUpdate(int serverIndex) ntripServer->connectionAttempts = 0; ntripServer->connectionAttemptTimeout = 0; if (settings.debugNtripServerState) - systemPrintln("NTRIP Server resetting connection attempt counter and timeout"); + systemPrintf("NTRIP Server %d resetting connection attempt counter and timeout\r\n", serverIndex); } // All is well From 033cf37c3a43687304bbee5215222cb252fa1438 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Fri, 26 Apr 2024 10:53:20 -1000 Subject: [PATCH 06/11] Add unique values for each of the NTRIP server settings --- Firmware/RTK_Surveyor/AP-Config/index.html | 28 +- Firmware/RTK_Surveyor/AP-Config/src/main.js | 24 +- Firmware/RTK_Surveyor/Display.ino | 8 +- Firmware/RTK_Surveyor/Form.ino | 131 +- Firmware/RTK_Surveyor/NVM.ino | 123 +- Firmware/RTK_Surveyor/NtripServer.ino | 74 +- Firmware/RTK_Surveyor/form.h | 2725 ++++++++++--------- Firmware/RTK_Surveyor/menuBase.ino | 72 +- Firmware/RTK_Surveyor/settings.h | 33 +- Firmware/Tools/makefile | 4 + 10 files changed, 1750 insertions(+), 1472 deletions(-) diff --git a/Firmware/RTK_Surveyor/AP-Config/index.html b/Firmware/RTK_Surveyor/AP-Config/index.html index ae1f40b2d..8edbc185d 100644 --- a/Firmware/RTK_Surveyor/AP-Config/index.html +++ b/Firmware/RTK_Surveyor/AP-Config/index.html @@ -814,66 +814,66 @@
-
- +

-
- +

-
- +

-
- +

-
-
- +

-