diff --git a/.github/workflows/compile-rtk-firmware.yml b/.github/workflows/compile-rtk-firmware.yml index e2e122770..c471fcbee 100644 --- a/.github/workflows/compile-rtk-firmware.yml +++ b/.github/workflows/compile-rtk-firmware.yml @@ -5,8 +5,8 @@ on: env: FILENAME_PREFIX: RTK_Surveyor_Firmware - FIRMWARE_VERSION_MAJOR: 3 - FIRMWARE_VERSION_MINOR: 10 + FIRMWARE_VERSION_MAJOR: 4 + FIRMWARE_VERSION_MINOR: 0 POINTPERFECT_TOKEN: ${{ secrets.POINTPERFECT_TOKEN }} jobs: diff --git a/Firmware/RTK_Surveyor/Begin.ino b/Firmware/RTK_Surveyor/Begin.ino index 814a8c6ea..fca01687d 100644 --- a/Firmware/RTK_Surveyor/Begin.ino +++ b/Firmware/RTK_Surveyor/Begin.ino @@ -9,43 +9,37 @@ Begin.ino // Constants //---------------------------------------- -#define MAX_ADC_VOLTAGE 3300 // Millivolts +#define MAX_ADC_VOLTAGE 3300 // Millivolts // Testing shows the combined ADC+resistors is under a 1% window -#define TOLERANCE 4.75 // Percent: 95.25% - 104.75% +#define TOLERANCE 5.20 // Percent: 94.8% - 105.2% //---------------------------------------- // Hardware initialization functions //---------------------------------------- - -// ADC input -// Ra KOhms | Rb KOhms -// MAX_ADC_VOLTAGE -----/\/\/\/\-----+-----/\/\/\/\----- Ground -// - // Determine if the measured value matches the product ID value -bool idWithAdc(uint16_t mvMeasured, float resVcc, float resGnd) +// idWithAdc applies resistor tolerance using worst-case tolerances: +// Upper threshold: R1 down by TOLERANCE, R2 up by TOLERANCE +// Lower threshold: R1 up by TOLERANCE, R2 down by TOLERANCE +bool idWithAdc(uint16_t mvMeasured, float r1, float r2) { - uint16_t lowerThreshold; - float raK; - float rbK; - uint16_t upperThreshold; - float voltage; - - // Compute the upper threshold - raK = resVcc * (1.0 - (TOLERANCE / 100.)); - rbK = resGnd * (1.0 + (TOLERANCE / 100.)); - voltage = MAX_ADC_VOLTAGE * rbK / (raK + rbK); - upperThreshold = (int)ceil(voltage); - - // Compute the lower threshold - raK = (double)resVcc * (1.0 + (TOLERANCE / 100.)); - rbK = (double)resGnd * (1.0 - (TOLERANCE / 100.)); - voltage = MAX_ADC_VOLTAGE * rbK / (raK + rbK); - lowerThreshold = (int)floor(voltage); + float lowerThreshold; + float upperThreshold; + + // ADC input + // r1 KOhms | r2 KOhms + // MAX_ADC_VOLTAGE -----/\/\/\/\-----+-----/\/\/\/\----- Ground // Return true if the mvMeasured value is within the tolerance range // of the mvProduct value + upperThreshold = ceil(MAX_ADC_VOLTAGE * (r2 * (1.0 + (TOLERANCE / 100.0))) / + ((r1 * (1.0 - (TOLERANCE / 100.0))) + (r2 * (1.0 + (TOLERANCE / 100.0))))); + lowerThreshold = floor(MAX_ADC_VOLTAGE * (r2 * (1.0 - (TOLERANCE / 100.0))) / + ((r1 * (1.0 + (TOLERANCE / 100.0))) + (r2 * (1.0 - (TOLERANCE / 100.0))))); + + // systemPrintf("r1: %0.2f r2: %0.2f lowerThreshold: %0.0f mvMeasured: %d upperThreshold: %0.0f\r\n", r1, r2, + // lowerThreshold, mvMeasured, upperThreshold); + return (upperThreshold > mvMeasured) && (mvMeasured > lowerThreshold); } @@ -61,13 +55,13 @@ void identifyBoard() uint16_t idValue = analogReadMilliVolts(pin_deviceID); log_d("Board ADC ID (mV): %d", idValue); - // Order checks by millivolt values high to low + // Order the following ID checks, by millivolt values high to low - // Facet L-Band Direct: 4.7/1 --> 534mV < 578mV < 626mV + // Facet L-Band Direct: 4.7/1 --> 534mV < 579mV < 626mV if (idWithAdc(idValue, 4.7, 1)) productVariant = RTK_FACET_LBAND_DIRECT; - // Express: 10/3.3 --> 761mV < 818mV < 879mV + // Express: 10/3.3 --> 761mV < 819mV < 879mV else if (idWithAdc(idValue, 10, 3.3)) productVariant = RTK_EXPRESS; @@ -95,7 +89,10 @@ void identifyBoard() // Surveyor // Unknown else + { + log_d("Out of band or nonexistent resistor IDs"); productVariant = RTK_UNKNOWN; // Need to wait until the GNSS and Accel have been initialized + } } // Setup any essential power pins @@ -611,8 +608,7 @@ void beginUART2() // after discarding the oldest data length = settings.gnssHandlerBufferSize; rbOffsetEntries = (length >> 1) / AVERAGE_SENTENCE_LENGTH_IN_BYTES; - length = settings.gnssHandlerBufferSize - + (rbOffsetEntries * sizeof(RING_BUFFER_OFFSET)); + length = settings.gnssHandlerBufferSize + (rbOffsetEntries * sizeof(RING_BUFFER_OFFSET)); ringBuffer = nullptr; rbOffsetArray = (RING_BUFFER_OFFSET *)malloc(length); if (!rbOffsetArray) @@ -1272,40 +1268,40 @@ void pinI2CTask(void *pvParameters) i2cBusAvailable = true; switch (addr) { - default: { - systemPrintf("0x%02x\r\n", addr); - break; - } + default: { + systemPrintf("0x%02x\r\n", addr); + break; + } - case 0x19: { - systemPrintf("0x%02x - LIS2DH12 Accelerometer\r\n", addr); - break; - } + case 0x19: { + systemPrintf("0x%02x - LIS2DH12 Accelerometer\r\n", addr); + break; + } - case 0x36: { - systemPrintf("0x%02x - MAX17048 Fuel Gauge\r\n", addr); - break; - } + case 0x36: { + systemPrintf("0x%02x - MAX17048 Fuel Gauge\r\n", addr); + break; + } - case 0x3d: { - systemPrintf("0x%02x - SSD1306 (64x48) OLED Driver\r\n", addr); - break; - } + case 0x3d: { + systemPrintf("0x%02x - SSD1306 (64x48) OLED Driver\r\n", addr); + break; + } - case 0x42: { - systemPrintf("0x%02x - u-blox ZED-F9P GNSS Receiver\r\n", addr); - break; - } + case 0x42: { + systemPrintf("0x%02x - u-blox ZED-F9P GNSS Receiver\r\n", addr); + break; + } - case 0x43: { - systemPrintf("0x%02x - u-blox NEO-D9S-00B Correction Data Receiver\r\n", addr); - break; - } + case 0x43: { + systemPrintf("0x%02x - u-blox NEO-D9S-00B Correction Data Receiver\r\n", addr); + break; + } - case 0x60: { - systemPrintf("0x%02x - Crypto Coprocessor\r\n", addr); - break; - } + case 0x60: { + systemPrintf("0x%02x - Crypto Coprocessor\r\n", addr); + break; + } } } else if ((millis() - timer) > 3) diff --git a/Firmware/RTK_Surveyor/Display.ino b/Firmware/RTK_Surveyor/Display.ino index 28cb785ec..d77e28bbb 100644 --- a/Firmware/RTK_Surveyor/Display.ino +++ b/Firmware/RTK_Surveyor/Display.ino @@ -985,10 +985,10 @@ uint32_t setWiFiIcon_TwoRadios() { #ifdef COMPILE_WIFI int wifiRSSI = WiFi.RSSI(); -#else // COMPILE_WIFI - int wifiRSSI = -40; // Dummy -#endif // COMPILE_WIFI - // Based on RSSI, select icon +#else // COMPILE_WIFI + int wifiRSSI = -40; // Dummy +#endif // COMPILE_WIFI + // Based on RSSI, select icon if (wifiRSSI >= -40) icons |= ICON_WIFI_SYMBOL_3_LEFT; else if (wifiRSSI >= -60) @@ -1015,10 +1015,10 @@ uint32_t setWiFiIcon_TwoRadios() { #ifdef COMPILE_WIFI int wifiRSSI = WiFi.RSSI(); -#else // COMPILE_WIFI +#else // COMPILE_WIFI int wifiRSSI = -40; // Dummy -#endif // COMPILE_WIFI - // Based on RSSI, select icon +#endif // COMPILE_WIFI + // Based on RSSI, select icon if (wifiRSSI >= -40) icons |= ICON_WIFI_SYMBOL_3_LEFT; else if (wifiRSSI >= -60) @@ -1072,10 +1072,10 @@ uint32_t setWiFiIcon_ThreeRadios() { #ifdef COMPILE_WIFI int wifiRSSI = WiFi.RSSI(); -#else // COMPILE_WIFI - int wifiRSSI = -40; // Dummy -#endif // COMPILE_WIFI - // Based on RSSI, select icon +#else // COMPILE_WIFI + int wifiRSSI = -40; // Dummy +#endif // COMPILE_WIFI + // Based on RSSI, select icon if (wifiRSSI >= -40) icons |= ICON_WIFI_SYMBOL_3_RIGHT; else if (wifiRSSI >= -60) @@ -1102,10 +1102,10 @@ uint32_t setWiFiIcon_ThreeRadios() { #ifdef COMPILE_WIFI int wifiRSSI = WiFi.RSSI(); -#else // COMPILE_WIFI +#else // COMPILE_WIFI int wifiRSSI = -40; // Dummy -#endif // COMPILE_WIFI - // Based on RSSI, select icon +#endif // COMPILE_WIFI + // Based on RSSI, select icon if (wifiRSSI >= -40) icons |= ICON_WIFI_SYMBOL_3_RIGHT; else if (wifiRSSI >= -60) @@ -1552,9 +1552,9 @@ void paintLogging() loggingIconDisplayed %= 4; // Wrap #ifdef COMPILE_ETHERNET if ((online.logging == true) && (logIncreasing || ntpLogIncreasing)) -#else // COMPILE_ETHERNET +#else // COMPILE_ETHERNET if ((online.logging == true) && (logIncreasing)) -#endif // COMPILE_ETHERNET +#endif // COMPILE_ETHERNET { if (loggingType == LOGGING_STANDARD) { @@ -1625,9 +1625,9 @@ void paintLoggingNTP(bool noPulse) loggingIconDisplayed %= 4; // Wrap #ifdef COMPILE_ETHERNET // Some redundancy here. paintLoggingNTP should only be called if Ethernet is present if ((online.logging == true) && (logIncreasing || ntpLogIncreasing)) -#else // COMPILE_ETHERNET +#else // COMPILE_ETHERNET if ((online.logging == true) && (logIncreasing)) -#endif // COMPILE_ETHERNET +#endif // COMPILE_ETHERNET { if (loggingIconDisplayed == 0) displayBitmap(64 - Logging_0_Width, 48 - Logging_0_Height, Logging_0_Width, Logging_0_Height, Logging_0); @@ -1794,9 +1794,9 @@ void paintIPAddress() snprintf(ipAddress, sizeof(ipAddress), " %d.%d.%d.%d ", #ifdef COMPILE_ETHERNET Ethernet.localIP()[0], Ethernet.localIP()[1], Ethernet.localIP()[2], Ethernet.localIP()[3]); -#else // COMPILE_ETHERNET +#else // COMPILE_ETHERNET 0, 0, 0, 0); -#endif // COMPILE_ETHERNET +#endif // COMPILE_ETHERNET static uint8_t ipAddressPosition = 0; @@ -1883,6 +1883,21 @@ void displayNoWiFi(uint16_t displayTime) displayMessage("No WiFi", displayTime); } +void displayNoSSIDs(uint16_t displayTime) +{ + displayMessage("No SSIDs", displayTime); +} + +void displayAccountExpired(uint16_t displayTime) +{ + displayMessage("Account Expired", displayTime); +} + +void displayNotListed(uint16_t displayTime) +{ + displayMessage("Not Listed", displayTime); +} + void displayRoverStart(uint16_t displayTime) { if (online.display == true) @@ -1911,9 +1926,9 @@ void displayNoRingBuffer(uint16_t displayTime) uint8_t fontHeight = 8; uint8_t yPos = oled.getHeight() / 3 - fontHeight; - printTextCenter("Fix GNSS", yPos, QW_FONT_5X7, 1, false); // text, y, font type, kerning, inverted + printTextCenter("Fix GNSS", yPos, QW_FONT_5X7, 1, false); // text, y, font type, kerning, inverted yPos += fontHeight; - printTextCenter("Handler", yPos, QW_FONT_5X7, 1, false); // text, y, font type, kerning, inverted + printTextCenter("Handler", yPos, QW_FONT_5X7, 1, false); // text, y, font type, kerning, inverted yPos += fontHeight; printTextCenter("Buffer Sz", yPos, QW_FONT_5X7, 1, false); // text, y, font type, kerning, inverted @@ -2026,10 +2041,20 @@ void displayWiFiConfig() if (settings.wifiConfigOverAP == true) snprintf(mySSID, sizeof(mySSID), "%s", "RTK Config"); else - snprintf(mySSID, sizeof(mySSID), "%s", WiFi.SSID().c_str()); -#else // COMPILE_WIFI + { + if(WiFi.getMode() == WIFI_STA) + snprintf(mySSID, sizeof(mySSID), "%s", WiFi.SSID().c_str()); + + //If we failed to connect to a friendly WiFi, and then fell back to AP mode, still display RTK Config + else if(WiFi.getMode() == WIFI_AP) + snprintf(mySSID, sizeof(mySSID), "%s", "RTK Config"); + + else + snprintf(mySSID, sizeof(mySSID), "%s", "Error"); + } +#else // COMPILE_WIFI snprintf(mySSID, sizeof(mySSID), "%s", "!Compiled"); -#endif // COMPILE_WIFI +#endif // COMPILE_WIFI char mySSIDFront[displayMaxCharacters + 1]; // 1 for null terminator char mySSIDBack[displayMaxCharacters + 1]; // 1 for null terminator @@ -2084,9 +2109,9 @@ void displayWiFiConfig() else printTextCenter(myIPBack, yPos, QW_FONT_5X7, 1, false); -#else // COMPILE_AP +#else // COMPILE_AP printTextCenter("!Compiled", yPos, QW_FONT_5X7, 1, false); -#endif // COMPILE_AP +#endif // COMPILE_AP } // When user does a factory reset, let us know @@ -2482,7 +2507,8 @@ void getAngles() accelZ *= -1.0; accelX *= -1.0; } - else if (productVariant == RTK_FACET || productVariant == RTK_FACET_LBAND || productVariant == RTK_FACET_LBAND_DIRECT) + else if (productVariant == RTK_FACET || productVariant == RTK_FACET_LBAND || + productVariant == RTK_FACET_LBAND_DIRECT) { accelZ = accel.getX(); accelX = accel.getY(); @@ -2554,10 +2580,10 @@ void paintDisplaySetupProfile(const char *firstState) // Lookup next available profile, limit to 8 characters getProfileNameFromUnit(index, profileName, sizeof(profileName)); - profileName[6]= 0; //Shorten profileName to 6 characters + profileName[6] = 0; // Shorten profileName to 6 characters char miniProfileName[16] = {0}; - snprintf(miniProfileName, sizeof(miniProfileName), "%d_%s", index, profileName); //Prefix with index # + snprintf(miniProfileName, sizeof(miniProfileName), "%d_%s", index, profileName); // Prefix with index # printTextCenter(miniProfileName, 12 * itemsDisplayed, QW_FONT_8X16, 1, itemsDisplayed == 3); index++; @@ -2701,6 +2727,26 @@ void paintDisplaySetup() printTextCenter("Config", 12 * 3, QW_FONT_8X16, 1, true); } } + + // If we are on an L-Band unit, display GetKeys option + else if (setupState == STATE_KEYS_NEEDED) + { + if (online.accelerometer) + { + printTextCenter("Base", 12 * 0, QW_FONT_8X16, 1, false); + printTextCenter("Bubble", 12 * 1, QW_FONT_8X16, 1, false); + printTextCenter("Config", 12 * 2, QW_FONT_8X16, 1, false); + printTextCenter("GetKeys", 12 * 3, QW_FONT_8X16, 1, true); + } + else + { + printTextCenter("Rover", 12 * 0, QW_FONT_8X16, 1, false); + printTextCenter("Base", 12 * 1, QW_FONT_8X16, 1, false); + printTextCenter("Config", 12 * 2, QW_FONT_8X16, 1, false); + printTextCenter("GetKeys", 12 * 3, QW_FONT_8X16, 1, true); + } + } + else if (setupState == STATE_ESPNOW_PAIRING_NOT_STARTED) { if (productVariant == REFERENCE_STATION) @@ -2710,6 +2756,24 @@ void paintDisplaySetup() printTextCenter("CfgWiFi", 12 * 2, QW_FONT_8X16, 1, false); printTextCenter("E-Pair", 12 * 3, QW_FONT_8X16, 1, true); } + else if (productVariant == RTK_FACET_LBAND || productVariant == RTK_FACET_LBAND_DIRECT) + { + // If we are on an L-Band unit, scroll GetKeys option + if (online.accelerometer) + { + printTextCenter("Bubble", 12 * 0, QW_FONT_8X16, 1, false); + printTextCenter("Config", 12 * 1, QW_FONT_8X16, 1, false); + printTextCenter("GetKeys", 12 * 2, QW_FONT_8X16, 1, false); + printTextCenter("E-Pair", 12 * 3, QW_FONT_8X16, 1, true); + } + else + { + printTextCenter("Base", 12 * 0, QW_FONT_8X16, 1, false); + printTextCenter("Config", 12 * 1, QW_FONT_8X16, 1, false); + printTextCenter("GetKeys", 12 * 2, QW_FONT_8X16, 1, false); + printTextCenter("E-Pair", 12 * 3, QW_FONT_8X16, 1, true); + } + } else if (online.accelerometer) { printTextCenter("Base", 12 * 0, QW_FONT_8X16, 1, false); @@ -2725,6 +2789,7 @@ void paintDisplaySetup() printTextCenter("E-Pair", 12 * 3, QW_FONT_8X16, 1, true); } } + else if (setupState == STATE_PROFILE) paintDisplaySetupProfile("Base"); } // end type F9P @@ -3303,11 +3368,11 @@ void displayConfigViaEthernet() oled.display(); } -#else // COMPILE_ETHERNET +#else // COMPILE_ETHERNET uint8_t fontHeight = 15; uint8_t yPos = oled.getHeight() / 2 - fontHeight; printTextCenter("!Compiled", yPos, QW_FONT_5X7, 1, false); -#endif // COMPILE_ETHERNET +#endif // COMPILE_ETHERNET } const uint8_t *getMacAddress() @@ -3317,14 +3382,14 @@ const uint8_t *getMacAddress() #ifdef COMPILE_BT if (bluetoothState != BT_OFF) return btMACAddress; -#endif // COMPILE_BT +#endif // COMPILE_BT #ifdef COMPILE_WIFI if (wifiState != WIFI_OFF) return wifiMACAddress; -#endif // COMPILE_WIFI +#endif // COMPILE_WIFI #ifdef COMPILE_ETHERNET if ((online.ethernetStatus >= ETH_STARTED_CHECK_CABLE) && (online.ethernetStatus <= ETH_CONNECTED)) return ethernetMACAddress; -#endif // COMPILE_ETHERNET +#endif // COMPILE_ETHERNET return zero; } diff --git a/Firmware/RTK_Surveyor/ESPNOW.ino b/Firmware/RTK_Surveyor/ESPNOW.ino index 4ca5f0f22..a51547412 100644 --- a/Firmware/RTK_Surveyor/ESPNOW.ino +++ b/Firmware/RTK_Surveyor/ESPNOW.ino @@ -32,7 +32,7 @@ void espnowOnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) // else // systemPrintln("Delivery Fail"); } -#endif // COMPILE_ESPNOW +#endif // COMPILE_ESPNOW // Callback when data is received void espnowOnDataReceived(const uint8_t *mac, const uint8_t *incomingData, int len) @@ -73,7 +73,7 @@ void espnowOnDataReceived(const uint8_t *mac, const uint8_t *incomingData, int l espnowIncomingRTCM = true; lastEspnowRssiUpdate = millis(); } -#endif // COMPILE_ESPNOW +#endif // COMPILE_ESPNOW } // Callback for all RX Packets @@ -88,7 +88,7 @@ void promiscuous_rx_cb(void *buf, wifi_promiscuous_pkt_type_t type) const wifi_promiscuous_pkt_t *ppkt = (wifi_promiscuous_pkt_t *)buf; packetRSSI = ppkt->rx_ctrl.rssi; } -#endif // COMPILE_ESPNOW +#endif // COMPILE_ESPNOW // If WiFi is already enabled, simply add the LR protocol // If the radio is off entirely, start the radio, turn on only the LR protocol @@ -100,7 +100,7 @@ void espnowStart() if (wifiState == WIFI_OFF && espnowState == ESPNOW_OFF) { - if (WiFi.getMode() == WIFI_OFF) + if (WiFi.getMode() != WIFI_STA) WiFi.mode(WIFI_STA); // Radio is off, turn it on @@ -114,6 +114,9 @@ void espnowStart() // If WiFi is on but ESP NOW is off, then enable LR protocol else if (wifiState > WIFI_OFF && espnowState == ESPNOW_OFF) { + if (WiFi.getMode() != WIFI_STA) + WiFi.mode(WIFI_STA); + // Enable WiFi + ESP-Now // Enable long range, PHY rate of ESP32 will be 512Kbps or 256Kbps // esp_wifi_set_protocol requires WiFi to be started @@ -188,7 +191,7 @@ void espnowStart() } systemPrintln("ESP-Now Started"); -#endif // COMPILE_ESPNOW +#endif // COMPILE_ESPNOW } // If WiFi is already enabled, simply remove the LR protocol @@ -216,6 +219,9 @@ void espnowStop() for (int x = 0; x < settings.espnowPeerCount; x++) espnowRemovePeer(settings.espnowPeers[x]); + if (WiFi.getMode() != WIFI_STA) + WiFi.mode(WIFI_STA); + // Leave WiFi with default settings (no WIFI_PROTOCOL_LR for ESP NOW) // esp_wifi_set_protocol requires WiFi to be started response = esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N); @@ -247,7 +253,7 @@ void espnowStop() wifiStart(); // Force WiFi to restart } -#endif // COMPILE_ESPNOW +#endif // COMPILE_ESPNOW } // Start ESP-Now if needed, put ESP-Now into broadcast state @@ -300,7 +306,7 @@ bool espnowIsPaired() espnowSetState(ESPNOW_PAIRED); return (true); } -#endif // COMPILE_ESPNOW +#endif // COMPILE_ESPNOW return (false); } @@ -321,9 +327,9 @@ esp_err_t espnowSendPairMessage(uint8_t *sendToMac) pairMessage.crc += wifiMACAddress[x]; return (esp_now_send(sendToMac, (uint8_t *)&pairMessage, sizeof(pairMessage))); // Send packet to given MAC -#else // COMPILE_ESPNOW +#else // COMPILE_ESPNOW return (ESP_OK); -#endif // COMPILE_ESPNOW +#endif // COMPILE_ESPNOW } // Add a given MAC address to the peer list @@ -349,9 +355,9 @@ esp_err_t espnowAddPeer(uint8_t *peerMac, bool encrypt) log_d("Failed to add peer: 0x%02X%02X%02X%02X%02X%02X", peerMac[0], peerMac[1], peerMac[2], peerMac[3], peerMac[4], peerMac[5]); return (result); -#else // COMPILE_ESPNOW +#else // COMPILE_ESPNOW return (ESP_OK); -#endif // COMPILE_ESPNOW +#endif // COMPILE_ESPNOW } // Remove a given MAC address from the peer list @@ -363,9 +369,9 @@ esp_err_t espnowRemovePeer(uint8_t *peerMac) log_d("Failed to remove peer: %s", esp_err_to_name(response)); return (response); -#else // COMPILE_ESPNOW +#else // COMPILE_ESPNOW return (ESP_OK); -#endif // COMPILE_ESPNOW +#endif // COMPILE_ESPNOW } // Update the state of the ESP Now state machine @@ -428,7 +434,7 @@ void espnowProcessRTCM(byte incoming) espnowOutgoingRTCM = true; } } -#endif // COMPILE_ESPNOW +#endif // COMPILE_ESPNOW } // A blocking function that is used to pair two devices diff --git a/Firmware/RTK_Surveyor/FileSdFatMMC.h b/Firmware/RTK_Surveyor/FileSdFatMMC.h index f1eec63d6..a1dbc2a36 100644 --- a/Firmware/RTK_Surveyor/FileSdFatMMC.h +++ b/Firmware/RTK_Surveyor/FileSdFatMMC.h @@ -158,7 +158,7 @@ class FileSdFatMMC : public SdFile void flush() { if (USE_SPI_MICROSD) - _sdFile->flush(); + _sdFile->sync(); #ifdef COMPILE_SD_MMC else _file->flush(); diff --git a/Firmware/RTK_Surveyor/Form.ino b/Firmware/RTK_Surveyor/Form.ino index 496699fd8..041210333 100644 --- a/Firmware/RTK_Surveyor/Form.ino +++ b/Firmware/RTK_Surveyor/Form.ino @@ -69,7 +69,7 @@ bool startWebServer(bool startWiFi = true, int httpPort = 80) if (settings.mdnsEnable == true) { if (MDNS.begin("rtk") == false) // This should make the module findable from 'rtk.local' in browser - log_d("Error setting up MDNS responder!"); + systemPrintln("Error setting up MDNS responder!"); else MDNS.addService("http", "tcp", 80); // Add service to MDNS-SD } @@ -104,7 +104,7 @@ bool startWebServer(bool startWiFi = true, int httpPort = 80) break; } - if(settings.enableCaptivePortal == true) + if (settings.enableCaptivePortal == true) webserver->addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER); // only when requested from AP websocket->onEvent(onWsEvent); @@ -322,7 +322,8 @@ bool startWebServer(bool startWiFi = true, int httpPort = 80) webserver->begin(); - log_d("Web Server Started"); + if (settings.debugWiFiConfig == true) + systemPrintln("Web Server Started"); reportHeapNow(false); return true; } while (0); @@ -359,7 +360,8 @@ void stopWebServer() incomingSettings = nullptr; } - log_d("Web Server Stopped"); + if (settings.debugWiFiConfig == true) + systemPrintln("Web Server Stopped"); reportHeapNow(false); } @@ -585,14 +587,16 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp { if (type == WS_EVT_CONNECT) { - log_d("Websocket client connected"); + if (settings.debugWiFiConfig == true) + systemPrintln("Websocket client connected"); client->text(settingsCSV); lastDynamicDataUpdate = millis(); websocketConnected = true; } else if (type == WS_EVT_DISCONNECT) { - log_d("Websocket client disconnected"); + if (settings.debugWiFiConfig == true) + systemPrintln("Websocket client disconnected"); // User has either refreshed the page or disconnected. Recompile the current settings. createSettingsString(settingsCSV); @@ -611,7 +615,10 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp } } else - log_d("onWsEvent: unrecognised AwsEventType %d", type); + { + if (settings.debugWiFiConfig == true) + systemPrintf("onWsEvent: unrecognised AwsEventType %d\r\n", type); + } } // Create a csv string with current settings void createSettingsString(char *newSettings) @@ -944,7 +951,10 @@ void createSettingsString(char *newSettings) true) // fileName, lineNumber, array, arraySize { trim(stationInfo); // Remove trailing whitespace - // log_d("ECEF SD station %d - found: %s", index, stationInfo); + + if (settings.debugWiFiConfig == true) + systemPrintf("ECEF SD station %d - found: %s\r\n", index, stationInfo); + replaceCharacter(stationInfo, ',', ' '); // Change all , to ' ' for easier parsing on the JS side snprintf(tagText, sizeof(tagText), "stationECEF%d", index); stringRecord(newSettings, tagText, stationInfo); @@ -953,7 +963,10 @@ void createSettingsString(char *newSettings) true) // fileName, lineNumber, array, arraySize { trim(stationInfo); // Remove trailing whitespace - // log_d("ECEF LFS station %d - found: %s", index, stationInfo); + + if (settings.debugWiFiConfig == true) + systemPrintf("ECEF LFS station %d - found: %s\r\n", index, stationInfo); + replaceCharacter(stationInfo, ',', ' '); // Change all , to ' ' for easier parsing on the JS side snprintf(tagText, sizeof(tagText), "stationECEF%d", index); stringRecord(newSettings, tagText, stationInfo); @@ -975,7 +988,10 @@ void createSettingsString(char *newSettings) true) // fileName, lineNumber, array, arraySize { trim(stationInfo); // Remove trailing whitespace - // log_d("Geo SD station %d - found: %s", index, stationInfo); + + if (settings.debugWiFiConfig == true) + systemPrintf("Geo SD station %d - found: %s\r\n", index, stationInfo); + replaceCharacter(stationInfo, ',', ' '); // Change all , to ' ' for easier parsing on the JS side snprintf(tagText, sizeof(tagText), "stationGeodetic%d", index); stringRecord(newSettings, tagText, stationInfo); @@ -984,7 +1000,10 @@ void createSettingsString(char *newSettings) true) // fileName, lineNumber, array, arraySize { trim(stationInfo); // Remove trailing whitespace - // log_d("Geo LFS station %d - found: %s", index, stationInfo); + + if (settings.debugWiFiConfig == true) + systemPrintf("Geo LFS station %d - found: %s\r\n", index, stationInfo); + replaceCharacter(stationInfo, ',', ' '); // Change all , to ' ' for easier parsing on the JS side snprintf(tagText, sizeof(tagText), "stationGeodetic%d", index); stringRecord(newSettings, tagText, stationInfo); @@ -1107,7 +1126,8 @@ void updateSettingWithValue(const char *settingName, const char *settingValueStr // This is one of the first settings to be received. If seen, remove the station files. removeFile(stationCoordinateECEFFileName); removeFile(stationCoordinateGeodeticFileName); - log_d("Station coordinate files removed"); + if (settings.debugWiFiConfig == true) + systemPrintln("Station coordinate files removed"); } else if (strcmp(settingName, "dynamicModel") == 0) settings.dynamicModel = settingValue; @@ -1251,14 +1271,16 @@ void updateSettingWithValue(const char *settingName, const char *settingValueStr replaceCharacter((char *)settingValueStr, ' ', ','); // Replace all ' ' with ',' before recording to file recordLineToSD(stationCoordinateECEFFileName, settingValueStr); recordLineToLFS(stationCoordinateECEFFileName, settingValueStr); - log_d("%s recorded", settingValueStr); + if (settings.debugWiFiConfig == true) + systemPrintf("%s recorded\r\n", settingValueStr); } else if (strstr(settingName, "stationGeodetic") != nullptr) { replaceCharacter((char *)settingValueStr, ' ', ','); // Replace all ' ' with ',' before recording to file recordLineToSD(stationCoordinateGeodeticFileName, settingValueStr); recordLineToLFS(stationCoordinateGeodeticFileName, settingValueStr); - log_d("%s recorded", settingValueStr); + if (settings.debugWiFiConfig == true) + systemPrintf("%s recorded\r\n", settingValueStr); } else if (strcmp(settingName, "pvtServerPort") == 0) settings.pvtServerPort = settingValue; @@ -1418,7 +1440,9 @@ void updateSettingWithValue(const char *settingName, const char *settingValueStr else if (strcmp(settingName, "exitAndReset") == 0) { // Confirm receipt - log_d("Sending reset confirmation"); + if (settings.debugWiFiConfig == true) + systemPrintln("Sending reset confirmation"); + websocket->textAll("confirmReset,1,"); delay(500); // Allow for delivery @@ -1448,7 +1472,8 @@ void updateSettingWithValue(const char *settingName, const char *settingValueStr else if (strcmp(settingName, "setProfile") == 0) { // Change to new profile - log_d("Changing to profile number %d\r\n", settingValue); + if (settings.debugWiFiConfig == true) + systemPrintf("Changing to profile number %d\r\n", settingValue); changeProfileNumber(settingValue); // Load new profile into system @@ -1459,8 +1484,11 @@ void updateSettingWithValue(const char *settingName, const char *settingValueStr createSettingsString(settingsCSV); - log_d("Sending profile %d\r\n", settingValue); - log_d("Profile contents: %s", settingsCSV); + if (settings.debugWiFiConfig == true) + { + systemPrintf("Sending profile %d\r\n", settingValue); + systemPrintf("Profile contents: %s\r\n", settingsCSV); + } websocket->textAll(settingsCSV); } else if (strcmp(settingName, "resetProfile") == 0) @@ -1477,8 +1505,11 @@ void updateSettingWithValue(const char *settingName, const char *settingValueStr createSettingsString(settingsCSV); - log_d("Sending reset profile %d\r\n", settingValue); - log_d("Profile contents: %s", settingsCSV); + if (settings.debugWiFiConfig == true) + { + systemPrintf("Sending reset profile %d\r\n", settingValue); + systemPrintf("Profile contents: %s\r\n", settingsCSV); + } websocket->textAll(settingsCSV); } else if (strcmp(settingName, "forgetEspNowPeers") == 0) @@ -1504,7 +1535,8 @@ void updateSettingWithValue(const char *settingName, const char *settingValueStr } else if (strcmp(settingName, "checkNewFirmware") == 0) { - log_d("Checking for new OTA Pull firmware"); + if (settings.debugWiFiConfig == true) + systemPrintln("Checking for new OTA Pull firmware"); websocket->textAll("checkingNewFirmware,1,"); // Tell the config page we received their request @@ -1519,19 +1551,22 @@ void updateSettingWithValue(const char *settingName, const char *settingValueStr getFirmwareVersion(currentVersion, sizeof(currentVersion), enableRCFirmware); if (isReportedVersionNewer(reportedVersion, currentVersion) == true) { - log_d("New version detected"); + if (settings.debugWiFiConfig == true) + systemPrintln("New version detected"); snprintf(newVersionCSV, sizeof(newVersionCSV), "newFirmwareVersion,%s,", reportedVersion); } else { - log_d("No new firmware available"); + if (settings.debugWiFiConfig == true) + systemPrintln("No new firmware available"); snprintf(newVersionCSV, sizeof(newVersionCSV), "newFirmwareVersion,CURRENT,"); } } else { // Failed to get version number - log_d("Sending error to AP config page"); + if (settings.debugWiFiConfig == true) + systemPrintln("Sending error to AP config page"); snprintf(newVersionCSV, sizeof(newVersionCSV), "newFirmwareVersion,ERROR,"); } @@ -1539,7 +1574,8 @@ void updateSettingWithValue(const char *settingName, const char *settingValueStr } else if (strcmp(settingName, "getNewFirmware") == 0) { - log_d("Getting new OTA Pull firmware"); + if (settings.debugWiFiConfig == true) + systemPrintln("Getting new OTA Pull firmware"); websocket->textAll("gettingNewFirmware,1,"); // Tell the config page we received their request @@ -1750,7 +1786,8 @@ bool parseIncomingSettings() if (counter < maxAttempts) { // Confirm receipt - log_d("Sending receipt confirmation of settings"); + if (settings.debugWiFiConfig == true) + systemPrintln("Sending receipt confirmation of settings"); websocket->textAll("confirmDataReceipt,1,"); } @@ -1843,7 +1880,8 @@ void getFileList(String &returnText) systemPrintf("sdCardSemaphore failed to yield, held by %s, Form.ino line %d\r\n", semaphoreHolder, __LINE__); } - log_d("returnText (%d bytes): %s\r\n", returnText.length(), returnText.c_str()); + if (settings.debugWiFiConfig == true) + systemPrintf("returnText (%d bytes): %s\r\n", returnText.length(), returnText.c_str()); } // When called, responds with the messages supported on this platform @@ -1859,7 +1897,8 @@ void createMessageList(String &returnText) String(settings.ubxMessageRates[messageNumber]) + ","; // UBX_RTCM_1074,4, } - log_d("returnText (%d bytes): %s\r\n", returnText.length(), returnText.c_str()); + if (settings.debugWiFiConfig == true) + systemPrintf("returnText (%d bytes): %s\r\n", returnText.length(), returnText.c_str()); } // When called, responds with the RTCM/Base messages supported on this platform @@ -1877,7 +1916,8 @@ void createMessageListBase(String &returnText) String(settings.ubxMessageRatesBase[messageNumber]) + ","; // UBX_RTCM_1074Base,4, } - log_d("returnText (%d bytes): %s\r\n", returnText.length(), returnText.c_str()); + if (settings.debugWiFiConfig == true) + systemPrintf("returnText (%d bytes): %s\r\n", returnText.length(), returnText.c_str()); } // Handles uploading of user files to SD diff --git a/Firmware/RTK_Surveyor/NVM.ino b/Firmware/RTK_Surveyor/NVM.ino index 69c5724fa..baf3a2ed3 100644 --- a/Firmware/RTK_Surveyor/NVM.ino +++ b/Firmware/RTK_Surveyor/NVM.ino @@ -446,6 +446,8 @@ void recordSystemSettingsToFile(File *settingsFile) settingsFile->printf("%s=%d\r\n", "debugLBand", settings.debugLBand); settingsFile->printf("%s=%d\r\n", "enableCaptivePortal", settings.enableCaptivePortal); + settingsFile->printf("%s=%d\r\n", "enableZedUsb", settings.enableZedUsb); + settingsFile->printf("%s=%d\r\n", "debugWiFiConfig", settings.debugWiFiConfig); //Add new settings above <------------------------------------------------------------> } @@ -1372,8 +1374,10 @@ bool parseLine(char *str, Settings *settings) settings->debugLBand = d; else if (strcmp(settingName, "enableCaptivePortal") == 0) settings->enableCaptivePortal = d; - - + else if (strcmp(settingName, "enableZedUsb") == 0) + settings->enableZedUsb = d; + else if (strcmp(settingName, "debugWiFiConfig") == 0) + settings->debugWiFiConfig = d; //Add new settings above //<------------------------------------------------------------> diff --git a/Firmware/RTK_Surveyor/OtaClient.ino b/Firmware/RTK_Surveyor/OtaClient.ino index b4ac985b8..eaaf1b02f 100644 --- a/Firmware/RTK_Surveyor/OtaClient.ino +++ b/Firmware/RTK_Surveyor/OtaClient.ino @@ -460,12 +460,12 @@ void otaClientUpdate() else if (!otaClient->connect(OTA_SERVER, OTA_SERVER_PORT)) { // if you didn't get a connection to the server: - Serial.println("OTA: Connection failed"); + systemPrintln("OTA: Connection failed"); otaStop(); } else { - Serial.println("OTA: Requesting JSON file"); + systemPrintln("OTA: Requesting JSON file"); // Make the HTTP request: otaClient->print("GET "); @@ -680,12 +680,12 @@ void otaClientUpdate() else if (!otaClient->connect(OTA_SERVER, OTA_SERVER_PORT)) { // if you didn't get a connection to the server: - Serial.println("OTA: Connection failed"); + systemPrintln("OTA: Connection failed"); otaStop(); } else { - Serial.println("OTA: Requesting BIN file"); + systemPrintln("OTA: Requesting BIN file"); // Make the HTTP request: otaClient->print("GET "); diff --git a/Firmware/RTK_Surveyor/RTK_Surveyor.ino b/Firmware/RTK_Surveyor/RTK_Surveyor.ino index 109da6707..ce2cb9868 100644 --- a/Firmware/RTK_Surveyor/RTK_Surveyor.ino +++ b/Firmware/RTK_Surveyor/RTK_Surveyor.ino @@ -374,6 +374,7 @@ uint16_t ARPECEFH = 0; const byte haeNumberOfDecimals = 8; // Used for printing and transmitting lat/lon bool lBandCommunicationEnabled = false; +bool lBandForceGetKeys = false; //Used to allow key update from display unsigned long rtcmLastPacketReceived = 0; //Monitors the last time we received RTCM. Proctors PMP vs RTCM prioritization. //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= diff --git a/Firmware/RTK_Surveyor/States.ino b/Firmware/RTK_Surveyor/States.ino index 60cd15eb8..f278282bd 100644 --- a/Firmware/RTK_Surveyor/States.ino +++ b/Firmware/RTK_Surveyor/States.ino @@ -154,7 +154,8 @@ void updateSystemState() if (carrSoln == 1) // RTK Float { - lbandTimeFloatStarted = millis(); //Restart timer for L-Band. Don't immediately reset ZED to achieve fix. + lbandTimeFloatStarted = + millis(); // Restart timer for L-Band. Don't immediately reset ZED to achieve fix. changeState(STATE_ROVER_RTK_FLOAT); } else if (carrSoln == 2) // RTK Fix @@ -179,7 +180,8 @@ void updateSystemState() changeState(STATE_ROVER_FIX); if (carrSoln == 1) // RTK Float { - lbandTimeFloatStarted = millis(); //Restart timer for L-Band. Don't immediately reset ZED to achieve fix. + lbandTimeFloatStarted = + millis(); // Restart timer for L-Band. Don't immediately reset ZED to achieve fix. changeState(STATE_ROVER_RTK_FLOAT); } } @@ -613,7 +615,7 @@ void updateSystemState() case (STATE_DISPLAY_SETUP): { if (millis() - lastSetupMenuChange > 1500) { - forceSystemStateUpdate = true; // Imediately go to this new state + forceSystemStateUpdate = true; // Immediately go to this new state changeState(setupState); // Change to last setup state if (setupState == STATE_BUBBLE_LEVEL) RTK_MODE(RTK_MODE_BUBBLE_LEVEL); @@ -642,7 +644,7 @@ void updateSystemState() bluetoothStop(); espnowStop(); - tasksStopUART2(); // Delete F9 serial tasks if running + tasksStopUART2(); // Delete F9 serial tasks if running if (!startWebServer()) // Start in AP mode and show config html page changeState(STATE_ROVER_NOT_STARTED); else @@ -731,7 +733,7 @@ void updateSystemState() rtcWaitTime = millis(); // We want an immediate change from this state - forceSystemStateUpdate = true; // Imediately go to this new state + forceSystemStateUpdate = true; // Immediately go to this new state // If user has turned off PointPerfect, skip everything if (settings.enablePointPerfectCorrections == false) @@ -742,6 +744,7 @@ void updateSystemState() // If there is no WiFi setup, and no keys, skip everything else if (wifiNetworkCount() == 0 && strlen(settings.pointPerfectCurrentKey) == 0) { + displayNoSSIDs(2000); changeState(settings.lastState); // Go to either rover or base } @@ -784,11 +787,11 @@ void updateSystemState() break; case (STATE_KEYS_NEEDED): { - forceSystemStateUpdate = true; //immediately go to this new state + forceSystemStateUpdate = true; // immediately go to this new state if (online.rtc == false) { - log_d("Keys Needed RTC off starting WiFi"); + log_d("Keys Needed. RTC offline. Starting WiFi"); // Temporarily limit WiFi connection attempts wifiOriginalMaxConnectionAttempts = wifiMaxConnectionAttempts; @@ -813,6 +816,33 @@ void updateSystemState() wifiStart(); // Starts WiFi state machine changeState(STATE_KEYS_WIFI_STARTED); } + + // Added to display WiFi error if user selects GetKeys from the display + // Normally, this would be caught during STATE_KEYS_STARTED + else if (wifiNetworkCount() == 0) + { + displayNoSSIDs(1000); + changeState( + STATE_KEYS_DAYS_REMAINING); // We have valid keys, we've already tried today. No need to try again. + } + + // Added to allow user to select GetKeys from the display + // This forces a key update + else if (lBandForceGetKeys == true) + { + lBandForceGetKeys = false; + + log_d("Force key update. Starting WiFi"); + + // Temporarily limit WiFi connection attempts + wifiOriginalMaxConnectionAttempts = wifiMaxConnectionAttempts; + wifiMaxConnectionAttempts = 0; // Override setting during key retrieval. Give up after single failure. + + wifiStart(); // Starts WiFi state machine + + changeState(STATE_KEYS_WIFI_STARTED); + } + else { log_d("Already tried to obtain keys for today"); @@ -851,11 +881,11 @@ void updateSystemState() erasePointperfectCredentials(); // Provision device - if(pointperfectProvisionDevice() == true) // Connect to ThingStream API and get keys + if (pointperfectProvisionDevice() == true) // Connect to ThingStream API and get keys displayKeysUpdated(); } - wifiShutdown(); // Turn off WiFi + wifiShutdown(); // Turn off WiFi forceSystemStateUpdate = true; // Imediately go to this new state changeState(STATE_KEYS_DAYS_REMAINING); } @@ -1182,7 +1212,7 @@ void requestChangeState(SystemState requestedState) } // Print the current state -const char * getState(SystemState state, char * buffer) +const char *getState(SystemState state, char *buffer) { switch (state) { @@ -1286,10 +1316,10 @@ void changeState(SystemState newState) { char string1[30]; char string2[30]; - const char * arrow; - const char * asterisk; - const char * initialState; - const char * endingState; + const char *arrow; + const char *asterisk; + const char *initialState; + const char *endingState; // Log the heap size at the state change reportHeapNow(false); diff --git a/Firmware/RTK_Surveyor/System.ino b/Firmware/RTK_Surveyor/System.ino index caf1a54f3..f1fb8ad79 100644 --- a/Firmware/RTK_Surveyor/System.ino +++ b/Firmware/RTK_Surveyor/System.ino @@ -144,19 +144,38 @@ bool configureUbloxModule() } } - // The USB port on the ZED may be used for RTCM to/from the computer (as an NTRIP caster or client) - // So let's be sure all protocols are on for the USB port - response &= theGNSS.addCfgValset(UBLOX_CFG_USBOUTPROT_UBX, 1); - response &= theGNSS.addCfgValset(UBLOX_CFG_USBOUTPROT_NMEA, 1); - if (commandSupported(UBLOX_CFG_USBOUTPROT_RTCM3X) == true) - response &= theGNSS.addCfgValset(UBLOX_CFG_USBOUTPROT_RTCM3X, 1); - response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_UBX, 1); - response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_NMEA, 1); - response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_RTCM3X, 1); - if (commandSupported(UBLOX_CFG_USBINPROT_SPARTN) == true) + if (settings.enableZedUsb == true) { - //See issue: https://github.com/sparkfun/SparkFun_RTK_Firmware/issues/713 - response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_SPARTN, 1); + // The USB port on the ZED may be used for RTCM to/from the computer (as an NTRIP caster or client) + // So let's be sure all protocols are on for the USB port + response &= theGNSS.addCfgValset(UBLOX_CFG_USBOUTPROT_UBX, 1); + response &= theGNSS.addCfgValset(UBLOX_CFG_USBOUTPROT_NMEA, 1); + if (commandSupported(UBLOX_CFG_USBOUTPROT_RTCM3X) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_USBOUTPROT_RTCM3X, 1); + response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_UBX, 1); + response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_NMEA, 1); + response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_RTCM3X, 1); + if (commandSupported(UBLOX_CFG_USBINPROT_SPARTN) == true) + { + // See issue: https://github.com/sparkfun/SparkFun_RTK_Firmware/issues/713 + response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_SPARTN, 1); + } + } + else + { + //Disable all protocols over USB + response &= theGNSS.addCfgValset(UBLOX_CFG_USBOUTPROT_UBX, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_USBOUTPROT_NMEA, 0); + if (commandSupported(UBLOX_CFG_USBOUTPROT_RTCM3X) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_USBOUTPROT_RTCM3X, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_UBX, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_NMEA, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_RTCM3X, 0); + if (commandSupported(UBLOX_CFG_USBINPROT_SPARTN) == true) + { + // See issue: https://github.com/sparkfun/SparkFun_RTK_Firmware/issues/713 + response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_SPARTN, 0); + } } if (commandSupported(UBLOX_CFG_NAVSPG_INFIL_MINCNO) == true) @@ -597,7 +616,7 @@ bool messageSupported(int messageNumber) return (messageSupported); } -// Given a command key, return true if that key is supported on this platform and fimrware version +// Given a command key, return true if that key is supported on this platform and firmware version bool commandSupported(const uint32_t key) { bool commandSupported = false; diff --git a/Firmware/RTK_Surveyor/Tasks.ino b/Firmware/RTK_Surveyor/Tasks.ino index 7bae303c3..f9d4eba0c 100644 --- a/Firmware/RTK_Surveyor/Tasks.ino +++ b/Firmware/RTK_Surveyor/Tasks.ino @@ -38,12 +38,12 @@ Tasks.ino // Macros //---------------------------------------- -#define WRAP_OFFSET(offset, increment, arraySize) \ -{ \ - offset += increment; \ - if (offset >= arraySize) \ - offset -= arraySize; \ -} +#define WRAP_OFFSET(offset, increment, arraySize) \ + { \ + offset += increment; \ + if (offset >= arraySize) \ + offset -= arraySize; \ + } //---------------------------------------- // Constants @@ -60,13 +60,8 @@ enum RingBufferConsumers RBC_MAX }; -const char * const ringBufferConsumer[] = -{ - "Bluetooth", - "PVT Client", - "PVT Server", - "SD Card", - "PVT UDP Server", +const char *const ringBufferConsumer[] = { + "Bluetooth", "PVT Client", "PVT Server", "SD Card", "PVT UDP Server", }; const int ringBufferConsumerEntries = sizeof(ringBufferConsumer) / sizeof(ringBufferConsumer[0]); @@ -75,8 +70,8 @@ const int ringBufferConsumerEntries = sizeof(ringBufferConsumer) / sizeof(ringBu // Locals //---------------------------------------- -volatile static RING_BUFFER_OFFSET dataHead; // Head advances as data comes in from GNSS's UART -volatile int32_t availableHandlerSpace; // settings.gnssHandlerBufferSize - usedSpace +volatile static RING_BUFFER_OFFSET dataHead; // Head advances as data comes in from GNSS's UART +volatile int32_t availableHandlerSpace; // settings.gnssHandlerBufferSize - usedSpace volatile const char *slowConsumer; // Buffer the incoming Bluetooth stream so that it can be passed in bulk over I2C @@ -632,7 +627,7 @@ void updateRingBufferTails(RING_BUFFER_OFFSET previousTail, RING_BUFFER_OFFSET n } // Remove previous messages from the ring buffer -void discardRingBufferBytes(RING_BUFFER_OFFSET * tail, RING_BUFFER_OFFSET previousTail, RING_BUFFER_OFFSET newTail) +void discardRingBufferBytes(RING_BUFFER_OFFSET *tail, RING_BUFFER_OFFSET previousTail, RING_BUFFER_OFFSET newTail) { // The longest tail is being trimmed. Medium length tails may contain // some data within the region begin trimmed. The shortest tails will @@ -1095,7 +1090,8 @@ void ButtonCheckTask(void *e) if (productVariant == RTK_SURVEYOR) { - if (setupBtn && (settings.disableSetupButton == false)) // Allow check of the setup button if not overridden by settings + if (setupBtn && + (settings.disableSetupButton == false)) // Allow check of the setup button if not overridden by settings { setupBtn->read(); @@ -1276,8 +1272,9 @@ void ButtonCheckTask(void *e) } } // End disabdisableSetupButton check } - } // End Platform = RTK Express - else if (productVariant == RTK_FACET || productVariant == RTK_FACET_LBAND || productVariant == RTK_FACET_LBAND_DIRECT) // Check one momentary button + } // End Platform = RTK Express + else if (productVariant == RTK_FACET || productVariant == RTK_FACET_LBAND || + productVariant == RTK_FACET_LBAND_DIRECT) // Check one momentary button { if (powerBtn != nullptr) powerBtn->read(); @@ -1388,8 +1385,20 @@ void ButtonCheckTask(void *e) setupState = STATE_WIFI_CONFIG_NOT_STARTED; break; case STATE_WIFI_CONFIG_NOT_STARTED: + if (productVariant == RTK_FACET_LBAND || productVariant == RTK_FACET_LBAND_DIRECT) + { + lBandForceGetKeys = true; + setupState = STATE_KEYS_NEEDED; + } + else + setupState = STATE_ESPNOW_PAIRING_NOT_STARTED; + break; + + case STATE_KEYS_NEEDED: + lBandForceGetKeys = false; // User has scrolled past the GetKeys option setupState = STATE_ESPNOW_PAIRING_NOT_STARTED; break; + case STATE_ESPNOW_PAIRING_NOT_STARTED: // If only one active profile do not show any profiles index = getProfileNumberFromUnit(0); @@ -1551,7 +1560,7 @@ void ButtonCheckTask(void *e) requestChangeState(STATE_BASE_NOT_STARTED); break; } - } //End disableSetupButton check + } // End disableSetupButton check } } // End Platform = REFERENCE_STATION diff --git a/Firmware/RTK_Surveyor/WiFi.ino b/Firmware/RTK_Surveyor/WiFi.ino index 49640e91c..1b0024688 100644 --- a/Firmware/RTK_Surveyor/WiFi.ino +++ b/Firmware/RTK_Surveyor/WiFi.ino @@ -236,7 +236,7 @@ bool wifiStartAP(bool forceAP) // Before starting AP mode, be sure we have default WiFi protocols enabled. // esp_wifi_set_protocol requires WiFi to be started esp_err_t response = - esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N); + esp_wifi_set_protocol(WIFI_IF_AP, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N); if (response != ESP_OK) systemPrintf("wifiStartAP: Error setting WiFi protocols: %s\r\n", esp_err_to_name(response)); else @@ -392,7 +392,7 @@ void wifiStart() if (wifiNetworkCount() == 0) { systemPrintln("Error: Please enter at least one SSID before using WiFi"); - // paintNoWiFi(2000); //TODO + displayNoSSIDs(2000); WIFI_STOP(); return; } @@ -440,7 +440,7 @@ void wifiShutdown() // If ESP-Now is active, change protocol to only Long Range and re-start WiFi if (espnowState > ESPNOW_OFF) { - if (WiFi.getMode() == WIFI_OFF) + if (WiFi.getMode() != WIFI_STA) WiFi.mode(WIFI_STA); // Enable long range, PHY rate of ESP32 will be 512Kbps or 256Kbps @@ -477,7 +477,7 @@ bool wifiConnect(unsigned long timeout) displayWiFiConnect(); // Before we can issue esp_wifi_() commands WiFi must be started - if (WiFi.getMode() == WIFI_OFF) + if (WiFi.getMode() != WIFI_STA) WiFi.mode(WIFI_STA); // Verify that the necessary protocols are set @@ -506,7 +506,7 @@ bool wifiConnect(unsigned long timeout) esp_err_t response = esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N); // Enable WiFi. if (response != ESP_OK) - systemPrintf("wifiConnect: Error setting WiFi + ESP-NOW protocols: %s\r\n", esp_err_to_name(response)); + systemPrintf("wifiConnect: Error setting WiFi protocols: %s\r\n", esp_err_to_name(response)); } } @@ -529,7 +529,7 @@ bool wifiConnect(unsigned long timeout) if (settings.mdnsEnable == true) { if (MDNS.begin("rtk") == false) // This should make the module findable from 'rtk.local' in browser - log_d("Error setting up MDNS responder!"); + systemPrintln("Error setting up MDNS responder!"); else MDNS.addService("http", "tcp", settings.httpPort); // Add service to MDNS } diff --git a/Firmware/RTK_Surveyor/form.h b/Firmware/RTK_Surveyor/form.h index e3a9ed57b..4d2ba06fb 100644 --- a/Firmware/RTK_Surveyor/form.h +++ b/Firmware/RTK_Surveyor/form.h @@ -26,7 +26,7 @@ // python main_js_zipper.py static const uint8_t main_js[] PROGMEM = { - 0x1F, 0x8B, 0x08, 0x08, 0x80, 0x33, 0x3C, 0x65, 0x02, 0xFF, 0x6D, 0x61, 0x69, 0x6E, 0x2E, 0x6A, + 0x1F, 0x8B, 0x08, 0x08, 0xF4, 0xA7, 0x8C, 0x65, 0x02, 0xFF, 0x6D, 0x61, 0x69, 0x6E, 0x2E, 0x6A, 0x73, 0x2E, 0x67, 0x7A, 0x69, 0x70, 0x00, 0xED, 0x7D, 0xEB, 0x7A, 0xDB, 0x38, 0x92, 0xE8, 0xFF, 0x3C, 0x05, 0x5A, 0x3B, 0xA7, 0x25, 0x4D, 0x64, 0x59, 0x92, 0x2F, 0x89, 0xE3, 0xD8, 0x7B, 0x7C, 0x4D, 0xBC, 0x13, 0x3B, 0xFE, 0xAC, 0xA4, 0xD3, 0x49, 0x4F, 0x8E, 0x97, 0x16, 0x61, 0x99, 0x13, @@ -800,7 +800,7 @@ static const uint8_t main_js[] PROGMEM = { // python index_html_zipper.py static const uint8_t index_html[] PROGMEM = { - 0x1F, 0x8B, 0x08, 0x08, 0x80, 0x33, 0x3C, 0x65, 0x02, 0xFF, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x2E, + 0x1F, 0x8B, 0x08, 0x08, 0xF4, 0xA7, 0x8C, 0x65, 0x02, 0xFF, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x2E, 0x68, 0x74, 0x6D, 0x6C, 0x2E, 0x67, 0x7A, 0x69, 0x70, 0x00, 0xED, 0x7D, 0xD9, 0x72, 0xE3, 0x48, 0x92, 0xE0, 0x7B, 0x7E, 0x45, 0x0C, 0x67, 0x67, 0x52, 0x9A, 0x16, 0x29, 0x92, 0x3A, 0x52, 0xA9, 0xCE, 0xA4, 0x19, 0x25, 0x4A, 0x99, 0xB2, 0x56, 0x2A, 0xB9, 0xA2, 0xB2, 0xB3, 0xAA, 0xD6, 0x76, diff --git a/Firmware/RTK_Surveyor/menuFirmware.ino b/Firmware/RTK_Surveyor/menuFirmware.ino index ecdd16f8f..3e4e7a5da 100644 --- a/Firmware/RTK_Surveyor/menuFirmware.ino +++ b/Firmware/RTK_Surveyor/menuFirmware.ino @@ -41,8 +41,7 @@ void menuFirmware() systemPrintf("e) Allow Beta Firmware: %s\r\n", enableRCFirmware ? "Enabled" : "Disabled"); if (settings.enableAutoFirmwareUpdate) - systemPrintf("i) Automatic firmware check minutes: %d\r\n", - settings.autoFirmwareCheckMinutes); + systemPrintf("i) Automatic firmware check minutes: %d\r\n", settings.autoFirmwareCheckMinutes); if (newOTAFirmwareAvailable) systemPrintf("u) Update to new firmware: v%s\r\n", reportedVersion); @@ -86,8 +85,9 @@ void menuFirmware() char currentVersion[21]; getFirmwareVersion(currentVersion, sizeof(currentVersion), enableRCFirmware); - //Allow update if locally compiled developer version - if (isReportedVersionNewer(reportedVersion, ¤tVersion[1]) == true || FIRMWARE_VERSION_MAJOR == 99) + // Allow update if locally compiled developer version + if (isReportedVersionNewer(reportedVersion, ¤tVersion[1]) == true || + FIRMWARE_VERSION_MAJOR == 99) { systemPrintln("New version detected"); newOTAFirmwareAvailable = true; @@ -108,7 +108,7 @@ void menuFirmware() bool previouslyConnected = wifiIsConnected(); bool bluetoothOriginallyConnected = false; - if(bluetoothState == BT_CONNECTED) + if (bluetoothState == BT_CONNECTED) bluetoothOriginallyConnected = true; bluetoothStop(); // Stop Bluetooth to allow for SSL on the heap @@ -144,10 +144,10 @@ void menuFirmware() if (previouslyConnected == false) WIFI_STOP(); - if(bluetoothOriginallyConnected == true) + if (bluetoothOriginallyConnected == true) bluetoothStart(); // Restart BT according to settings } - } //End wifiNetworkCount() check + } // End wifiNetworkCount() check } else if (incoming == 'c' && btPrintEcho == true) { @@ -159,14 +159,14 @@ void menuFirmware() { enableRCFirmware ^= 1; strncpy(reportedVersion, "", sizeof(reportedVersion) - 1); // Reset to force c) menu + newOTAFirmwareAvailable = false; } else if ((incoming == 'i') && settings.enableAutoFirmwareUpdate) { systemPrint("Enter minutes (1 - 999999) before next firmware check: "); int minutes = getNumber(); // Returns EXIT, TIMEOUT, or long - if ((minutes != INPUT_RESPONSE_GETNUMBER_EXIT) && - (minutes != INPUT_RESPONSE_GETNUMBER_TIMEOUT)) + if ((minutes != INPUT_RESPONSE_GETNUMBER_EXIT) && (minutes != INPUT_RESPONSE_GETNUMBER_TIMEOUT)) { if ((minutes < 1) || (minutes > 999999)) systemPrintln("Error: Out of range (1 - 999999)"); @@ -739,23 +739,30 @@ const char *otaPullErrorText(int code) // Returns true if reportedVersion is newer than currentVersion // Version number comes in as v2.7-Jan 5 2023 // 2.7-Jan 5 2023 is newer than v2.7-Jan 1 2023 +// We can't use just the float number: v3.12 is a greater version than v3.9 but it is a smaller float number bool isReportedVersionNewer(char *reportedVersion, char *currentVersion) { - float currentVersionNumber = 0.0; + int currentVersionNumberMajor = 0; + int currentVersionNumberMinor = 0; int currentDay = 0; int currentMonth = 0; int currentYear = 0; - float reportedVersionNumber = 0.0; + int reportedVersionNumberMajor = 0; + int reportedVersionNumberMinor = 0; int reportedDay = 0; int reportedMonth = 0; int reportedYear = 0; - breakVersionIntoParts(currentVersion, ¤tVersionNumber, ¤tYear, ¤tMonth, ¤tDay); - breakVersionIntoParts(reportedVersion, &reportedVersionNumber, &reportedYear, &reportedMonth, &reportedDay); + breakVersionIntoParts(currentVersion, ¤tVersionNumberMajor, ¤tVersionNumberMinor, ¤tYear, + ¤tMonth, ¤tDay); + breakVersionIntoParts(reportedVersion, &reportedVersionNumberMajor, &reportedVersionNumberMinor, &reportedYear, + &reportedMonth, &reportedDay); - log_d("currentVersion: %f %d %d %d", currentVersionNumber, currentYear, currentMonth, currentDay); - log_d("reportedVersion: %f %d %d %d", reportedVersionNumber, reportedYear, reportedMonth, reportedDay); + log_d("currentVersion (%s): %d.%d %d %d %d", currentVersion, currentVersionNumberMajor, currentVersionNumberMinor, + currentYear, currentMonth, currentDay); + log_d("reportedVersion (%s): %d.%d %d %d %d", reportedVersion, reportedVersionNumberMajor, + reportedVersionNumberMinor, reportedYear, reportedMonth, reportedDay); if (enableRCFirmware) log_d("RC firmware enabled"); @@ -765,15 +772,20 @@ bool isReportedVersionNewer(char *reportedVersion, char *currentVersion) // If the user is not using Release Candidate firmware, then check only the version number if (enableRCFirmware == false) { - // Check only the version number - if (reportedVersionNumber > currentVersionNumber) + if (reportedVersionNumberMajor > currentVersionNumberMajor) + return (true); + if (reportedVersionNumberMajor == currentVersionNumberMajor && + reportedVersionNumberMinor > currentVersionNumberMinor) return (true); return (false); } // For RC firmware, compare firmware date as well // Check version number - if (reportedVersionNumber > currentVersionNumber) + if (reportedVersionNumberMajor > currentVersionNumberMajor) + return (true); + if (reportedVersionNumberMajor == currentVersionNumberMajor && + reportedVersionNumberMinor > currentVersionNumberMinor) return (true); // Check which date is more recent @@ -791,17 +803,18 @@ bool isReportedVersionNewer(char *reportedVersion, char *currentVersion) } // Version number comes in as v2.7-Jan 5 2023 -// Given a char string, break into version number, year, month, day +// Given a char string, break into version number major/minor, year, month, day // Returns false if parsing failed -bool breakVersionIntoParts(char *version, float *versionNumber, int *year, int *month, int *day) +bool breakVersionIntoParts(char *version, int *versionNumberMajor, int *versionNumberMinor, int *year, int *month, + int *day) { char monthStr[20]; int placed = 0; if (enableRCFirmware == false) { - placed = sscanf(version, "%f", versionNumber); - if (placed != 1) + placed = sscanf(version, "%d.%d", versionNumberMajor, versionNumberMinor); + if (placed != 2) { log_d("Failed to sscanf basic"); return (false); // Something went wrong @@ -809,9 +822,9 @@ bool breakVersionIntoParts(char *version, float *versionNumber, int *year, int * } else { - placed = sscanf(version, "%f-%s %d %d", versionNumber, monthStr, day, year); + placed = sscanf(version, "%d.%d-%s %d %d", versionNumberMajor, versionNumberMinor, monthStr, day, year); - if (placed != 4) + if (placed != 5) { log_d("Failed to sscanf RC"); return (false); // Something went wrong diff --git a/Firmware/RTK_Surveyor/menuPP.ino b/Firmware/RTK_Surveyor/menuPP.ino index 864ae883a..00319a1c7 100644 --- a/Firmware/RTK_Surveyor/menuPP.ino +++ b/Firmware/RTK_Surveyor/menuPP.ino @@ -130,10 +130,17 @@ void menuPointPerfectKeys() if (settings.debugLBand == true) { - systemPrintf(" settings.pointPerfectCurrentKeyStart: %lld - %s\r\n", settings.pointPerfectCurrentKeyStart, printDateFromUnixEpoch(settings.pointPerfectCurrentKeyStart / 1000)); - systemPrintf(" settings.pointPerfectCurrentKeyDuration: %lld - %s\r\n", settings.pointPerfectCurrentKeyDuration, printDaysFromDuration(settings.pointPerfectCurrentKeyDuration)); - systemPrintf(" settings.pointPerfectNextKeyStart: %lld - %s\r\n", settings.pointPerfectNextKeyStart, printDateFromUnixEpoch(settings.pointPerfectNextKeyStart / 1000)); - systemPrintf(" settings.pointPerfectNextKeyDuration: %lld - %s\r\n", settings.pointPerfectNextKeyDuration, printDaysFromDuration(settings.pointPerfectNextKeyDuration)); + systemPrintf(" settings.pointPerfectCurrentKeyStart: %lld - %s\r\n", + settings.pointPerfectCurrentKeyStart, + printDateFromUnixEpoch(settings.pointPerfectCurrentKeyStart / 1000)); + systemPrintf(" settings.pointPerfectCurrentKeyDuration: %lld - %s\r\n", + settings.pointPerfectCurrentKeyDuration, + printDaysFromDuration(settings.pointPerfectCurrentKeyDuration)); + systemPrintf(" settings.pointPerfectNextKeyStart: %lld - %s\r\n", settings.pointPerfectNextKeyStart, + printDateFromUnixEpoch(settings.pointPerfectNextKeyStart / 1000)); + systemPrintf(" settings.pointPerfectNextKeyDuration: %lld - %s\r\n", + settings.pointPerfectNextKeyDuration, + printDaysFromDuration(settings.pointPerfectNextKeyDuration)); } } else if (incoming == 4) @@ -189,34 +196,34 @@ char *printDateFromGPSEpoch(long long gpsEpoch) // https://www.epochconverter.com/programming/c char *printDateFromUnixEpoch(long long unixEpoch) { - char *buf = (char *)malloc(strlen("01/01/2023") + 1); //Make room for terminator - time_t rawtime = unixEpoch; + char *buf = (char *)malloc(strlen("01/01/2023") + 1); // Make room for terminator + time_t rawtime = unixEpoch; - struct tm ts; - ts = *localtime(&rawtime); + struct tm ts; + ts = *localtime(&rawtime); - // Format time, "dd/mm/yyyy" - strftime(buf, strlen("01/01/2023") + 1, "%d/%m/%Y", &ts); - return (buf); + // Format time, "dd/mm/yyyy" + strftime(buf, strlen("01/01/2023") + 1, "%d/%m/%Y", &ts); + return (buf); } // Given a duration in ms, print days char *printDaysFromDuration(long long duration) { - float days = duration / (1000.0 * 60 * 60 * 24); //Convert ms to days + float days = duration / (1000.0 * 60 * 60 * 24); // Convert ms to days - char *response = (char *)malloc(strlen("34.9") + 1); //Make room for terminator - sprintf(response, "%0.2f", days); - return (response); + char *response = (char *)malloc(strlen("34.9") + 1); // Make room for terminator + sprintf(response, "%0.2f", days); + return (response); } // Connect to 'home' WiFi and then ThingStream API. This will attach this unique device to the ThingStream network. bool pointperfectProvisionDevice() { #ifdef COMPILE_WIFI - bool bluetoothOriginallyConnected = false; - if (bluetoothState == BT_CONNECTED) - bluetoothOriginallyConnected = true; + bool bluetoothOriginallyStarted = true; + if (bluetoothState == BT_OFF) + bluetoothOriginallyStarted = false; bluetoothStop(); // Free heap before starting secure client (requires ~70KB) @@ -231,7 +238,8 @@ bool pointperfectProvisionDevice() char hardwareID[13]; snprintf(hardwareID, sizeof(hardwareID), "%02X%02X%02X%02X%02X%02X", lbandMACAddress[0], lbandMACAddress[1], - lbandMACAddress[2], lbandMACAddress[3], lbandMACAddress[4], lbandMACAddress[5]); // Get ready for JSON + lbandMACAddress[2], lbandMACAddress[3], lbandMACAddress[4], + lbandMACAddress[5]); // Get ready for JSON #ifdef WHITELISTED_ID // Override ID with testing ID @@ -312,6 +320,39 @@ bool pointperfectProvisionDevice() { systemPrintf("HTTP response error %d: ", httpResponseCode); systemPrintln(response); + + // If a device has been deactivated, response will be: "HTTP response error 403: No plan for device + // device:9f49e97f-e6a7-4a08-8d58-ac7ecdc90e23" + if (response.indexOf("No plan for device") >= 0) + { + char hardwareID[13]; + snprintf(hardwareID, sizeof(hardwareID), "%02X%02X%02X%02X%02X%02X", lbandMACAddress[0], + lbandMACAddress[1], lbandMACAddress[2], lbandMACAddress[3], lbandMACAddress[4], + lbandMACAddress[5]); + + systemPrintf("This device has been deactivated. Please contact " + "support@sparkfun.com to renew the L-Band " + "subscription. Please reference device ID: %s\r\n", + hardwareID); + + displayAccountExpired(5000); + } + // If a device is not whitelisted, reponse will be: "HTTP response error 403: Device hardware code not + // whitelisted" + else if (response.indexOf("not whitelisted") >= 0) + { + char hardwareID[13]; + snprintf(hardwareID, sizeof(hardwareID), "%02X%02X%02X%02X%02X%02X", lbandMACAddress[0], + lbandMACAddress[1], lbandMACAddress[2], lbandMACAddress[3], lbandMACAddress[4], + lbandMACAddress[5]); + + systemPrintf( + "This device is not white-listed. Please contact " + "support@sparkfun.com to get your subscription activated. Please reference device ID: %s\r\n", + hardwareID); + + displayNotListed(5000); + } break; } else @@ -340,13 +381,9 @@ bool pointperfectProvisionDevice() break; } strncpy(tempHolderPtr, (const char *)((*jsonZtp)["certificate"]), MQTT_CERT_SIZE - 1); - // log_d("len of PrivateCert: %d", strlen(tempHolderPtr)); - // log_d("privateCert: %s", tempHolderPtr); recordFile("certificate", tempHolderPtr, strlen(tempHolderPtr)); strncpy(tempHolderPtr, (const char *)((*jsonZtp)["privateKey"]), MQTT_CERT_SIZE - 1); - // log_d("len of privateKey: %d", strlen(tempHolderPtr)); - // log_d("privateKey: %s", tempHolderPtr); recordFile("privateKey", tempHolderPtr, strlen(tempHolderPtr)); // Validate the keys @@ -363,22 +400,31 @@ bool pointperfectProvisionDevice() strcpy(settings.pointPerfectBrokerHost, (const char *)((*jsonZtp)["brokerHost"])); strcpy(settings.pointPerfectLBandTopic, (const char *)((*jsonZtp)["subscriptions"][0]["path"])); - strcpy(settings.pointPerfectCurrentKey, (const char *)((*jsonZtp)["dynamickeys"]["current"]["value"])); + strcpy(settings.pointPerfectCurrentKey, + (const char *)((*jsonZtp)["dynamickeys"]["current"]["value"])); settings.pointPerfectCurrentKeyDuration = (*jsonZtp)["dynamickeys"]["current"]["duration"]; settings.pointPerfectCurrentKeyStart = (*jsonZtp)["dynamickeys"]["current"]["start"]; strcpy(settings.pointPerfectNextKey, (const char *)((*jsonZtp)["dynamickeys"]["next"]["value"])); settings.pointPerfectNextKeyDuration = (*jsonZtp)["dynamickeys"]["next"]["duration"]; settings.pointPerfectNextKeyStart = (*jsonZtp)["dynamickeys"]["next"]["start"]; - + if (settings.debugLBand == true) { systemPrintf(" pointPerfectCurrentKey: %s\r\n", settings.pointPerfectCurrentKey); - systemPrintf(" pointPerfectCurrentKeyStart: %lld - %s\r\n", settings.pointPerfectCurrentKeyStart, printDateFromUnixEpoch(settings.pointPerfectCurrentKeyStart / 1000)); //printDateFromUnixEpoch expects seconds - systemPrintf(" pointPerfectCurrentKeyDuration: %lld - %s\r\n", settings.pointPerfectCurrentKeyDuration, printDaysFromDuration(settings.pointPerfectCurrentKeyDuration)); + systemPrintf(" pointPerfectCurrentKeyStart: %lld - %s\r\n", + settings.pointPerfectCurrentKeyStart, + printDateFromUnixEpoch(settings.pointPerfectCurrentKeyStart / + 1000)); // printDateFromUnixEpoch expects seconds + systemPrintf(" pointPerfectCurrentKeyDuration: %lld - %s\r\n", + settings.pointPerfectCurrentKeyDuration, + printDaysFromDuration(settings.pointPerfectCurrentKeyDuration)); systemPrintf(" pointPerfectNextKey: %s\r\n", settings.pointPerfectNextKey); - systemPrintf(" pointPerfectNextKeyStart: %lld - %s\r\n", settings.pointPerfectNextKeyStart, printDateFromUnixEpoch(settings.pointPerfectNextKeyStart / 1000)); - systemPrintf(" pointPerfectNextKeyDuration: %lld - %s\r\n", settings.pointPerfectNextKeyDuration, printDaysFromDuration(settings.pointPerfectNextKeyDuration)); + systemPrintf(" pointPerfectNextKeyStart: %lld - %s\r\n", settings.pointPerfectNextKeyStart, + printDateFromUnixEpoch(settings.pointPerfectNextKeyStart / 1000)); + systemPrintf(" pointPerfectNextKeyDuration: %lld - %s\r\n", + settings.pointPerfectNextKeyDuration, + printDaysFromDuration(settings.pointPerfectNextKeyDuration)); } } } @@ -396,7 +442,7 @@ bool pointperfectProvisionDevice() if (jsonZtp) delete jsonZtp; - if (bluetoothOriginallyConnected == true) + if (bluetoothOriginallyStarted == true) bluetoothStart(); return (retVal); @@ -454,7 +500,8 @@ bool checkCertificates() if (keyContents) free(keyContents); - systemPrintln("Stored certificates are valid!"); + if (settings.debugPpCertificate) + systemPrintln("Stored certificates are valid!"); return (validCertificates); } @@ -494,10 +541,7 @@ bool checkPrivateKeyValidity(char *privateKey, int privateKeySize) mbedtls_pk_context pk; mbedtls_pk_init(&pk); - int result_code = - mbedtls_pk_parse_key(&pk, - (unsigned char *)privateKey, privateKeySize + 1, - nullptr, 0); + int result_code = mbedtls_pk_parse_key(&pk, (unsigned char *)privateKey, privateKeySize + 1, nullptr, 0); mbedtls_pk_free(&pk); if (result_code < 0) { @@ -527,9 +571,9 @@ void erasePointperfectCredentials() bool pointperfectUpdateKeys() { #ifdef COMPILE_WIFI - bool bluetoothOriginallyConnected = false; - if (bluetoothState == BT_CONNECTED) - bluetoothOriginallyConnected = true; + bool bluetoothOriginallyStarted = true; + if (bluetoothState == BT_OFF) + bluetoothOriginallyStarted = false; bluetoothStop(); // Release available heap to allow room for TLS @@ -567,46 +611,34 @@ bool pointperfectUpdateKeys() mqttClient.setCallback(mqttCallback); mqttClient.setServer(settings.pointPerfectBrokerHost, 8883); - log_d("Connecting to MQTT broker: %s", settings.pointPerfectBrokerHost); + systemPrintf("Attempting to connect to MQTT broker: %s\r\n", settings.pointPerfectBrokerHost); - // Loop until we're connected or until the maximum retries are exceeded - mqttMessageReceived = false; - int maxTries = 3; - do + if (mqttClient.connect(settings.pointPerfectClientID)) { - systemPrint("MQTT connecting..."); - - // Attempt to the key broker - if (mqttClient.connect(settings.pointPerfectClientID)) - { - // Successful connection - systemPrintln("connected"); - - // Originally the provisioning process reported the '/pp/key/Lb' channel which fails to respond with - // keys. Looks like they fixed it to /pp/ubx/0236/Lb. - mqttClient.subscribe(settings.pointPerfectLBandTopic); - break; - } + // Successful connection + systemPrintln("MQTT connected"); - // Retry the connection attempt - if (--maxTries) - { - systemPrint("."); - log_d("failed, status code: %d try again in 1 second", mqttClient.state()); - delay(1000); - } - } while (maxTries); + // Originally the provisioning process reported the '/pp/key/Lb' channel which fails to respond with + // keys. Looks like they fixed it to /pp/ubx/0236/Lb. + mqttClient.subscribe(settings.pointPerfectLBandTopic); + break; + } // Check for connection failure if (mqttClient.connected() == false) { - systemPrintln("failed!"); - log_d("MQTT failed to connect"); + systemPrintln("Failed to connect to MQTT Broker"); + + // MQTT does not provide good error reporting. + // Throw out everything and attempt to provision the device to get better error checking. + pointperfectProvisionDevice(); break; } systemPrint("Waiting for keys"); + mqttMessageReceived = false; + // Wait for callback startTime = millis(); while (1) @@ -616,12 +648,14 @@ bool pointperfectUpdateKeys() break; if (mqttClient.connected() == false) { - log_d("Client disconnected"); + if (settings.debugLBand == true) + systemPrintln("Client disconnected"); break; } if (millis() - startTime > 8000) { - log_d("Channel failed to respond"); + if (settings.debugLBand == true) + systemPrintln("Channel failed to respond"); break; } @@ -648,7 +682,7 @@ bool pointperfectUpdateKeys() if (certificateContents) free(certificateContents); - if (bluetoothOriginallyConnected == true) + if (bluetoothOriginallyStarted == true) bluetoothStart(); // Return the key status @@ -724,11 +758,15 @@ void mqttCallback(char *topic, byte *message, unsigned int length) { systemPrintln(); systemPrintf(" pointPerfectCurrentKey: %s\r\n", settings.pointPerfectCurrentKey); - systemPrintf(" pointPerfectCurrentKeyStart: %lld - %s\r\n", settings.pointPerfectCurrentKeyStart, printDateFromUnixEpoch(settings.pointPerfectCurrentKeyStart)); - systemPrintf(" pointPerfectCurrentKeyDuration: %lld - %s\r\n", settings.pointPerfectCurrentKeyDuration, printDaysFromDuration(settings.pointPerfectCurrentKeyDuration)); + systemPrintf(" pointPerfectCurrentKeyStart: %lld - %s\r\n", settings.pointPerfectCurrentKeyStart, + printDateFromUnixEpoch(settings.pointPerfectCurrentKeyStart)); + systemPrintf(" pointPerfectCurrentKeyDuration: %lld - %s\r\n", settings.pointPerfectCurrentKeyDuration, + printDaysFromDuration(settings.pointPerfectCurrentKeyDuration)); systemPrintf(" pointPerfectNextKey: %s\r\n", settings.pointPerfectNextKey); - systemPrintf(" pointPerfectNextKeyStart: %lld - %s\r\n", settings.pointPerfectNextKeyStart, printDateFromUnixEpoch(settings.pointPerfectNextKeyStart)); - systemPrintf(" pointPerfectNextKeyDuration: %lld - %s\r\n", settings.pointPerfectNextKeyDuration, printDaysFromDuration(settings.pointPerfectNextKeyDuration)); + systemPrintf(" pointPerfectNextKeyStart: %lld - %s\r\n", settings.pointPerfectNextKeyStart, + printDateFromUnixEpoch(settings.pointPerfectNextKeyStart)); + systemPrintf(" pointPerfectNextKeyDuration: %lld - %s\r\n", settings.pointPerfectNextKeyDuration, + printDaysFromDuration(settings.pointPerfectNextKeyDuration)); } } @@ -789,7 +827,8 @@ int daysFromEpoch(long long endEpoch) if (online.rtc == false) { // If we don't have RTC we can't calculate days to expire - log_d("No RTC available"); + if (settings.debugLBand == true) + systemPrintln("No RTC available"); return (0); } @@ -988,7 +1027,8 @@ void pointperfectApplyKeys() { if (online.gnss == false) { - log_d("ZED-F9P not available"); + if (settings.debugLBand == true) + systemPrintln("ZED-F9P not available"); return; } @@ -1036,13 +1076,15 @@ void pointperfectApplyKeys() systemPrintln("setDynamicSPARTNKeys failed"); else { - log_d("PointPerfect keys applied"); + if (settings.debugLBand == true) + systemPrintln("PointPerfect keys applied"); online.lbandCorrections = true; } } else { - log_d("No PointPerfect keys available"); + if (settings.debugLBand == true) + systemPrintln("No PointPerfect keys available"); } } } @@ -1079,7 +1121,8 @@ void beginLBand() // Skip if going into configure-via-ethernet mode if (configureViaEthernet) { - log_d("configureViaEthernet: skipping beginLBand"); + if (settings.debugLBand == true) + systemPrintln("configureViaEthernet: skipping beginLBand"); return; } @@ -1087,7 +1130,8 @@ void beginLBand() if (i2cLBand.begin(Wire, 0x43) == false) // Connect to the u-blox NEO-D9S using Wire port. The D9S default I2C address is 0x43 (not 0x42) { - log_d("L-Band not detected"); + if (settings.debugLBand == true) + systemPrintln("L-Band not detected"); return; } @@ -1112,12 +1156,14 @@ void beginLBand() { if ((longitude > -125 && longitude < -67) && (latitude > -90 && latitude < 90)) { - log_d("Setting L-Band to US"); + if (settings.debugLBand == true) + systemPrintln("Setting L-Band to US"); settings.LBandFreq = 1556290000; // We are in US band } else if ((longitude > -25 && longitude < 70) && (latitude > -90 && latitude < 90)) { - log_d("Setting L-Band to EU"); + if (settings.debugLBand == true) + systemPrintln("Setting L-Band to EU"); settings.LBandFreq = 1545260000; // We are in EU band } else @@ -1128,7 +1174,10 @@ void beginLBand() recordSystemSettings(); } else - log_d("No fix available for L-Band frequency determination"); + { + if (settings.debugLBand == true) + systemPrintln("No fix available for L-Band frequency determination"); + } bool response = true; response &= i2cLBand.newCfgValset(); @@ -1153,7 +1202,8 @@ void beginLBand() i2cLBand.softwareResetGNSSOnly(); // Do a restart - log_d("L-Band online"); + if (settings.debugLBand == true) + systemPrintln("L-Band online"); online.lband = true; #endif // COMPILE_L_BAND @@ -1170,9 +1220,11 @@ void menuPointPerfect() systemPrintln(); systemPrintln("Menu: PointPerfect Corrections"); - log_d("Time to first L-Band fix: %ds Restarts: %d", lbandTimeToFix / 1000, lbandRestarts); + if (settings.debugLBand == true) + systemPrintf("Time to first L-Band fix: %ds Restarts: %d\r\n", lbandTimeToFix / 1000, lbandRestarts); - log_d("settings.pointPerfectLBandTopic: %s", settings.pointPerfectLBandTopic); + if (settings.debugLBand == true) + systemPrintf("settings.pointPerfectLBandTopic: %s\r\n", settings.pointPerfectLBandTopic); systemPrint("Days until keys expire: "); if (strlen(settings.pointPerfectCurrentKey) > 0) @@ -1322,7 +1374,8 @@ void updateLBand() // Skip if in configure-via-ethernet mode if (configureViaEthernet) { - // log_d("configureViaEthernet: skipping updateLBand"); + if (settings.debugLBand == true) + systemPrintln("configureViaEthernet: skipping updateLBand"); return; } @@ -1360,14 +1413,16 @@ void updateLBand() // Hotstart ZED to try to get RTK lock theGNSS.softwareResetGNSSOnly(); - log_d("Restarting ZED. Number of L-Band restarts: %d", lbandRestarts); + if (settings.debugLBand == true) + systemPrintf("Restarting ZED. Number of L-Band restarts: %d\r\n", lbandRestarts); } } } else if (carrSoln == 2 && lbandTimeToFix == 0) { lbandTimeToFix = millis(); - log_d("Time to first L-Band fix: %ds", lbandTimeToFix / 1000); + if (settings.debugLBand == true) + systemPrintf("Time to first L-Band fix: %ds\r\n", lbandTimeToFix / 1000); } if ((millis() - rtcmLastPacketReceived) / 1000 > settings.rtcmTimeoutBeforeUsingLBand_s) @@ -1377,7 +1432,8 @@ void updateLBand() // re-enable L-Band communcation if (lBandCommunicationEnabled == false) { - log_d("Enabling L-Band communication due to RTCM timeout"); + if (settings.debugLBand == true) + systemPrintln("Enabling L-Band communication due to RTCM timeout"); lBandCommunicationEnabled = zedEnableLBandCommunication(); } } @@ -1386,7 +1442,8 @@ void updateLBand() // If we *have* recently received RTCM then disable corrections from then NEO-D9S L-Band receiver if (lBandCommunicationEnabled == true) { - log_d("Disabling L-Band communication due to RTCM reception"); + if (settings.debugLBand == true) + systemPrintln("Disabling L-Band communication due to RTCM reception"); lBandCommunicationEnabled = !zedDisableLBandCommunication(); // zedDisableLBandCommunication() returns // true if we successfully disabled } diff --git a/Firmware/RTK_Surveyor/menuPorts.ino b/Firmware/RTK_Surveyor/menuPorts.ino index 13f06facf..d4e255f2b 100644 --- a/Firmware/RTK_Surveyor/menuPorts.ino +++ b/Firmware/RTK_Surveyor/menuPorts.ino @@ -16,12 +16,26 @@ void menuPortsSurveyor() systemPrintln("Menu: Ports"); systemPrint("1) Set serial baud rate for Radio Port: "); - systemPrint(theGNSS.getVal32(UBLOX_CFG_UART2_BAUDRATE)); - systemPrintln(" bps"); + if (settings.radioPortBaud == 0) + { + systemPrintln("Disabled"); + } + else + { + systemPrint(theGNSS.getVal32(UBLOX_CFG_UART2_BAUDRATE)); + systemPrintln(" bps"); + } systemPrint("2) Set serial baud rate for Data Port: "); - systemPrint(theGNSS.getVal32(UBLOX_CFG_UART1_BAUDRATE)); - systemPrintln(" bps"); + if (settings.dataPortBaud == 0) + { + systemPrintln("Disabled"); + } + else + { + systemPrint(theGNSS.getVal32(UBLOX_CFG_UART1_BAUDRATE)); + systemPrintln(" bps"); + } systemPrint("3) GNSS UART2 UBX Protocol In: "); if (settings.enableUART2UBXIn == true) @@ -35,16 +49,63 @@ void menuPortsSurveyor() if (incoming == 1) { - systemPrint("Enter baud rate (4800 to 921600) for Radio Port: "); + systemPrint("Enter baud rate (4800 to 921600, 0 = disable) for Radio Port: "); int newBaud = getNumber(); // Returns EXIT, TIMEOUT, or long if ((newBaud != INPUT_RESPONSE_GETNUMBER_EXIT) && (newBaud != INPUT_RESPONSE_GETNUMBER_TIMEOUT)) { - if (newBaud == 4800 || newBaud == 9600 || newBaud == 19200 || newBaud == 38400 || newBaud == 57600 || - newBaud == 115200 || newBaud == 230400 || newBaud == 460800 || newBaud == 921600) + if (newBaud == 0 || newBaud == 4800 || newBaud == 9600 || newBaud == 19200 || newBaud == 38400 || + newBaud == 57600 || newBaud == 115200 || newBaud == 230400 || newBaud == 460800 || + newBaud == 921600) { settings.radioPortBaud = newBaud; if (online.gnss == true) - theGNSS.setVal32(UBLOX_CFG_UART2_BAUDRATE, settings.radioPortBaud); + { + if (newBaud == 0) + { + // Disable all protocols in/out of UART2 + bool response = true; + + response &= theGNSS.newCfgValset(); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2OUTPROT_UBX, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2OUTPROT_NMEA, 0); + if (commandSupported(UBLOX_CFG_UART2OUTPROT_RTCM3X) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2OUTPROT_RTCM3X, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2INPROT_UBX, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2INPROT_NMEA, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2INPROT_RTCM3X, 0); + if (commandSupported(UBLOX_CFG_UART2INPROT_SPARTN) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2INPROT_SPARTN, 0); + response &= theGNSS.sendCfgValset(); + + if (response == false) + systemPrintln("Failed to set UART2 settings"); + } + else + { + bool response = true; + + response &= theGNSS.newCfgValset(); + + // Set the baud rate + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2_BAUDRATE, settings.radioPortBaud); + + // Set the UART2 to only do RTCM (in case this device goes into base mode) + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2OUTPROT_UBX, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2OUTPROT_NMEA, 0); + if (commandSupported(UBLOX_CFG_UART2OUTPROT_RTCM3X) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2OUTPROT_RTCM3X, 1); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2INPROT_UBX, settings.enableUART2UBXIn); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2INPROT_NMEA, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2INPROT_RTCM3X, 1); + if (commandSupported(UBLOX_CFG_UART2INPROT_SPARTN) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2INPROT_SPARTN, 0); + + response &= theGNSS.sendCfgValset(); + + if (response == false) + systemPrintln("Failed to set UART2 settings"); + } + } } else { @@ -54,16 +115,62 @@ void menuPortsSurveyor() } else if (incoming == 2) { - systemPrint("Enter baud rate (4800 to 921600) for Data Port: "); + systemPrint("Enter baud rate (4800 to 921600, 0 = disable) for Data Port: "); int newBaud = getNumber(); // Returns EXIT, TIMEOUT, or long if ((newBaud != INPUT_RESPONSE_GETNUMBER_EXIT) && (newBaud != INPUT_RESPONSE_GETNUMBER_TIMEOUT)) { - if (newBaud == 4800 || newBaud == 9600 || newBaud == 19200 || newBaud == 38400 || newBaud == 57600 || - newBaud == 115200 || newBaud == 230400 || newBaud == 460800 || newBaud == 921600) + if (newBaud == 0 || newBaud == 4800 || newBaud == 9600 || newBaud == 19200 || newBaud == 38400 || + newBaud == 57600 || newBaud == 115200 || newBaud == 230400 || newBaud == 460800 || + newBaud == 921600) { settings.dataPortBaud = newBaud; if (online.gnss == true) - theGNSS.setVal32(UBLOX_CFG_UART1_BAUDRATE, settings.dataPortBaud); + { + if (newBaud == 0) + { + // Disable all protocols in/out of UART1 + bool response = true; + + response &= theGNSS.newCfgValset(); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1OUTPROT_UBX, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1OUTPROT_NMEA, 0); + if (commandSupported(UBLOX_CFG_UART1OUTPROT_RTCM3X) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1OUTPROT_RTCM3X, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1INPROT_UBX, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1INPROT_NMEA, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1INPROT_RTCM3X, 0); + if (commandSupported(UBLOX_CFG_UART1INPROT_SPARTN) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1INPROT_SPARTN, 0); + response &= theGNSS.sendCfgValset(); + + if (response == false) + systemPrintln("Failed to set UART1 settings"); + } + else + { + bool response = true; + + response &= theGNSS.newCfgValset(); + + // Set the baud rate + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1_BAUDRATE, settings.dataPortBaud); + + // Turn on all protocols except SPARTN + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1OUTPROT_UBX, 1); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1OUTPROT_NMEA, 1); + if (commandSupported(UBLOX_CFG_UART1OUTPROT_RTCM3X) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1OUTPROT_RTCM3X, 1); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1INPROT_UBX, 1); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1INPROT_NMEA, 1); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1INPROT_RTCM3X, 1); + if (commandSupported(UBLOX_CFG_UART1INPROT_SPARTN) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1INPROT_SPARTN, 0); + response &= theGNSS.sendCfgValset(); + + if (response == false) + systemPrintln("Failed to set UART1 settings"); + } + } } else { @@ -99,8 +206,15 @@ void menuPortsMultiplexed() systemPrintln("Menu: Ports"); systemPrint("1) Set Radio port serial baud rate: "); - systemPrint(theGNSS.getVal32(UBLOX_CFG_UART2_BAUDRATE)); - systemPrintln(" bps"); + if (settings.radioPortBaud == 0) + { + systemPrintln("Disabled"); + } + else + { + systemPrint(theGNSS.getVal32(UBLOX_CFG_UART2_BAUDRATE)); + systemPrintln(" bps"); + } systemPrint("2) Set Data port connections: "); if (settings.dataPortChannel == MUX_UBLOX_NMEA) @@ -120,8 +234,15 @@ void menuPortsMultiplexed() if (settings.dataPortChannel == MUX_UBLOX_NMEA) { systemPrint("3) Set Data port serial baud rate: "); - systemPrint(theGNSS.getVal32(UBLOX_CFG_UART1_BAUDRATE)); - systemPrintln(" bps"); + if (settings.dataPortBaud == 0) + { + systemPrintln("Disabled"); + } + else + { + systemPrint(theGNSS.getVal32(UBLOX_CFG_UART1_BAUDRATE)); + systemPrintln(" bps"); + } } else if (settings.dataPortChannel == MUX_PPS_EVENTTRIGGER) { @@ -153,16 +274,63 @@ void menuPortsMultiplexed() if (incoming == 1) { - systemPrint("Enter baud rate (4800 to 921600) for Radio Port: "); + systemPrint("Enter baud rate (4800 to 921600, 0 = disable) for Radio Port: "); int newBaud = getNumber(); // Returns EXIT, TIMEOUT, or long if ((newBaud != INPUT_RESPONSE_GETNUMBER_EXIT) && (newBaud != INPUT_RESPONSE_GETNUMBER_TIMEOUT)) { - if (newBaud == 4800 || newBaud == 9600 || newBaud == 19200 || newBaud == 38400 || newBaud == 57600 || - newBaud == 115200 || newBaud == 230400 || newBaud == 460800 || newBaud == 921600) + if (newBaud == 0 || newBaud == 4800 || newBaud == 9600 || newBaud == 19200 || newBaud == 38400 || + newBaud == 57600 || newBaud == 115200 || newBaud == 230400 || newBaud == 460800 || + newBaud == 921600) { settings.radioPortBaud = newBaud; if (online.gnss == true) - theGNSS.setVal32(UBLOX_CFG_UART2_BAUDRATE, settings.radioPortBaud); + { + if (newBaud == 0) + { + // Disable all protocols in/out of UART2 + bool response = true; + + response &= theGNSS.newCfgValset(); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2OUTPROT_UBX, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2OUTPROT_NMEA, 0); + if (commandSupported(UBLOX_CFG_UART2OUTPROT_RTCM3X) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2OUTPROT_RTCM3X, 0); + + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2INPROT_UBX, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2INPROT_NMEA, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2INPROT_RTCM3X, 0); + if (commandSupported(UBLOX_CFG_UART2INPROT_SPARTN) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2INPROT_SPARTN, 0); + response &= theGNSS.sendCfgValset(); + + if (response == false) + systemPrintln("Failed to set UART2 settings"); + } + else + { + bool response = true; + + response &= theGNSS.newCfgValset(); + + // Set the baud rate + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2_BAUDRATE, settings.radioPortBaud); + + // Set the UART2 to only do RTCM (in case this device goes into base mode) + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2OUTPROT_UBX, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2OUTPROT_NMEA, 0); + if (commandSupported(UBLOX_CFG_UART2OUTPROT_RTCM3X) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2OUTPROT_RTCM3X, 1); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2INPROT_UBX, settings.enableUART2UBXIn); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2INPROT_NMEA, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2INPROT_RTCM3X, 1); + if (commandSupported(UBLOX_CFG_UART2INPROT_SPARTN) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_UART2INPROT_SPARTN, 0); + response &= theGNSS.sendCfgValset(); + + if (response == false) + systemPrintln("Failed to set UART2 settings"); + } + } } else { @@ -194,16 +362,63 @@ void menuPortsMultiplexed() } else if (incoming == 3 && settings.dataPortChannel == MUX_UBLOX_NMEA) { - systemPrint("Enter baud rate (4800 to 921600) for Data Port: "); + systemPrint("Enter baud rate (4800 to 921600, 0 = disable) for Data Port: "); int newBaud = getNumber(); // Returns EXIT, TIMEOUT, or long if ((newBaud != INPUT_RESPONSE_GETNUMBER_EXIT) && (newBaud != INPUT_RESPONSE_GETNUMBER_TIMEOUT)) { - if (newBaud == 4800 || newBaud == 9600 || newBaud == 19200 || newBaud == 38400 || newBaud == 57600 || - newBaud == 115200 || newBaud == 230400 || newBaud == 460800 || newBaud == 921600) + if (newBaud == 0 || newBaud == 4800 || newBaud == 9600 || newBaud == 19200 || newBaud == 38400 || + newBaud == 57600 || newBaud == 115200 || newBaud == 230400 || newBaud == 460800 || + newBaud == 921600) { settings.dataPortBaud = newBaud; if (online.gnss == true) - theGNSS.setVal32(UBLOX_CFG_UART1_BAUDRATE, settings.dataPortBaud); + { + if (newBaud == 0) + { + // Disable all protocols in/out of UART1 + bool response = true; + + response &= theGNSS.newCfgValset(); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1OUTPROT_UBX, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1OUTPROT_NMEA, 0); + if (commandSupported(UBLOX_CFG_UART1OUTPROT_RTCM3X) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1OUTPROT_RTCM3X, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1INPROT_UBX, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1INPROT_NMEA, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1INPROT_RTCM3X, 0); + if (commandSupported(UBLOX_CFG_UART1INPROT_SPARTN) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1INPROT_SPARTN, 0); + response &= theGNSS.sendCfgValset(); + + if (response == false) + systemPrintln("Failed to set UART1 settings"); + } + else + { + bool response = true; + + response &= theGNSS.newCfgValset(); + + // Set the baud rate + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1_BAUDRATE, settings.dataPortBaud); + + // Turn on all protocols except SPARTN + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1OUTPROT_UBX, 1); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1OUTPROT_NMEA, 1); + if (commandSupported(UBLOX_CFG_UART1OUTPROT_RTCM3X) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1OUTPROT_RTCM3X, 1); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1INPROT_UBX, 1); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1INPROT_NMEA, 1); + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1INPROT_RTCM3X, 1); + if (commandSupported(UBLOX_CFG_UART1INPROT_SPARTN) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_UART1INPROT_SPARTN, 0); + + response &= theGNSS.sendCfgValset(); + + if (response == false) + systemPrintln("Failed to set UART1 settings"); + } + } } else { @@ -222,7 +437,8 @@ void menuPortsMultiplexed() } else if (productVariant == RTK_FACET_LBAND_DIRECT && incoming == 5) { - settings.useI2cForLbandCorrectionsConfigured = true; //Record that the user has manually modified the settings. + settings.useI2cForLbandCorrectionsConfigured = + true; // Record that the user has manually modified the settings. settings.useI2cForLbandCorrections ^= 1; systemPrintln("External radio port updated. Changes will be applied at next restart."); } diff --git a/Firmware/RTK_Surveyor/menuSystem.ino b/Firmware/RTK_Surveyor/menuSystem.ino index 73b415996..940d48548 100644 --- a/Firmware/RTK_Surveyor/menuSystem.ino +++ b/Firmware/RTK_Surveyor/menuSystem.ino @@ -206,40 +206,40 @@ void menuSystem() if (incoming == 'b') { - // Restart Bluetooth - bluetoothStop(); - if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP) - settings.bluetoothRadioType = BLUETOOTH_RADIO_BLE; - else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_BLE) - settings.bluetoothRadioType = BLUETOOTH_RADIO_OFF; - else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_OFF) - settings.bluetoothRadioType = BLUETOOTH_RADIO_SPP; - bluetoothStart(); + // Restart Bluetooth + bluetoothStop(); + if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP) + settings.bluetoothRadioType = BLUETOOTH_RADIO_BLE; + else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_BLE) + settings.bluetoothRadioType = BLUETOOTH_RADIO_OFF; + else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_OFF) + settings.bluetoothRadioType = BLUETOOTH_RADIO_SPP; + bluetoothStart(); } else if (incoming == 'c') { - systemPrint("Enter time in seconds to shutdown unit if not charging (0 to disable): "); - int shutdownNoChargeTimeout_s = getNumber(); // Returns EXIT, TIMEOUT, or long - if ((shutdownNoChargeTimeout_s != INPUT_RESPONSE_GETNUMBER_EXIT) && - (shutdownNoChargeTimeout_s != INPUT_RESPONSE_GETNUMBER_TIMEOUT)) - { - if (shutdownNoChargeTimeout_s < 0 || - shutdownNoChargeTimeout_s > 60 * 60 * 24 * 7) // Arbitrary 7 day limit - systemPrintln("Error: Time out of range"); - else - settings.shutdownNoChargeTimeout_s = - shutdownNoChargeTimeout_s; // Recorded to NVM and file at main menu exit - } + systemPrint("Enter time in seconds to shutdown unit if not charging (0 to disable): "); + int shutdownNoChargeTimeout_s = getNumber(); // Returns EXIT, TIMEOUT, or long + if ((shutdownNoChargeTimeout_s != INPUT_RESPONSE_GETNUMBER_EXIT) && + (shutdownNoChargeTimeout_s != INPUT_RESPONSE_GETNUMBER_TIMEOUT)) + { + if (shutdownNoChargeTimeout_s < 0 || + shutdownNoChargeTimeout_s > 60 * 60 * 24 * 7) // Arbitrary 7 day limit + systemPrintln("Error: Time out of range"); + else + settings.shutdownNoChargeTimeout_s = + shutdownNoChargeTimeout_s; // Recorded to NVM and file at main menu exit + } } else if (incoming == 'd') menuDebugSoftware(); else if (incoming == 'e') { - settings.echoUserInput ^= 1; + settings.echoUserInput ^= 1; } else if ((incoming == 'f') && (settings.enableSD == true) && (online.microSD == true)) { - printFileList(); + printFileList(); } else if (incoming == 'h') menuDebugHardware(); @@ -251,69 +251,68 @@ void menuSystem() menuPeriodicPrint(); else if (incoming == 'r') { - systemPrintln("\r\nResetting to factory defaults. Press 'y' to confirm:"); - byte bContinue = getCharacterNumber(); - if (bContinue == 'y') - { - factoryReset(false); // We do not have the SD semaphore - } - else - systemPrintln("Reset aborted"); + systemPrintln("\r\nResetting to factory defaults. Press 'y' to confirm:"); + byte bContinue = getCharacterNumber(); + if (bContinue == 'y') + { + factoryReset(false); // We do not have the SD semaphore + } + else + systemPrintln("Reset aborted"); } else if (incoming == 'z') { - systemPrint("Enter time zone hour offset (-23 <= offset <= 23): "); - int value = getNumber(); // Returns EXIT, TIMEOUT, or long - if ((value != INPUT_RESPONSE_GETNUMBER_EXIT) && (value != INPUT_RESPONSE_GETNUMBER_TIMEOUT)) + systemPrint("Enter time zone hour offset (-23 <= offset <= 23): "); + int value = getNumber(); // Returns EXIT, TIMEOUT, or long + if ((value != INPUT_RESPONSE_GETNUMBER_EXIT) && (value != INPUT_RESPONSE_GETNUMBER_TIMEOUT)) + { + if (value < -23 || value > 23) + systemPrintln("Error: -24 < hours < 24"); + else { - if (value < -23 || value > 23) - systemPrintln("Error: -24 < hours < 24"); - else - { - settings.timeZoneHours = value; + settings.timeZoneHours = value; - systemPrint("Enter time zone minute offset (-59 <= offset <= 59): "); - int value = getNumber(); // Returns EXIT, TIMEOUT, or long - if ((value != INPUT_RESPONSE_GETNUMBER_EXIT) && (value != INPUT_RESPONSE_GETNUMBER_TIMEOUT)) + systemPrint("Enter time zone minute offset (-59 <= offset <= 59): "); + int value = getNumber(); // Returns EXIT, TIMEOUT, or long + if ((value != INPUT_RESPONSE_GETNUMBER_EXIT) && (value != INPUT_RESPONSE_GETNUMBER_TIMEOUT)) + { + if (value < -59 || value > 59) + systemPrintln("Error: -60 < minutes < 60"); + else { - if (value < -59 || value > 59) - systemPrintln("Error: -60 < minutes < 60"); - else - { - settings.timeZoneMinutes = value; + settings.timeZoneMinutes = value; - systemPrint("Enter time zone second offset (-59 <= offset <= 59): "); - int value = getNumber(); // Returns EXIT, TIMEOUT, or long - if ((value != INPUT_RESPONSE_GETNUMBER_EXIT) && - (value != INPUT_RESPONSE_GETNUMBER_TIMEOUT)) + systemPrint("Enter time zone second offset (-59 <= offset <= 59): "); + int value = getNumber(); // Returns EXIT, TIMEOUT, or long + if ((value != INPUT_RESPONSE_GETNUMBER_EXIT) && (value != INPUT_RESPONSE_GETNUMBER_TIMEOUT)) + { + if (value < -59 || value > 59) + systemPrintln("Error: -60 < seconds < 60"); + else { - if (value < -59 || value > 59) - systemPrintln("Error: -60 < seconds < 60"); - else - { - settings.timeZoneSeconds = value; - online.rtc = false; - syncRTCInterval = - 1000; // Reset syncRTCInterval to 1000ms (tpISR could have set it to 59000) - rtcSyncd = false; - updateRTC(); - } // Succesful seconds - } - } // Succesful minute - } - } // Succesful hours - } + settings.timeZoneSeconds = value; + online.rtc = false; + syncRTCInterval = + 1000; // Reset syncRTCInterval to 1000ms (tpISR could have set it to 59000) + rtcSyncd = false; + updateRTC(); + } // Succesful seconds + } + } // Succesful minute + } + } // Succesful hours + } } else if (incoming == '~') { - settings.disableSetupButton ^= 1; + settings.disableSetupButton ^= 1; } // Support mode switching else if (incoming == 'B') { - forceSystemStateUpdate = true; // Imediately go to this new state - changeState(STATE_BASE_NOT_STARTED); + forceSystemStateUpdate = true; // Imediately go to this new state + changeState(STATE_BASE_NOT_STARTED); } else if ((incoming == 'N') && HAS_ETHERNET) { @@ -322,21 +321,21 @@ void menuSystem() } else if (incoming == 'R') { - forceSystemStateUpdate = true; // Imediately go to this new state - changeState(STATE_ROVER_NOT_STARTED); + forceSystemStateUpdate = true; // Imediately go to this new state + changeState(STATE_ROVER_NOT_STARTED); } else if (incoming == 'W') { - forceSystemStateUpdate = true; // Imediately go to this new state - changeState(STATE_WIFI_CONFIG_NOT_STARTED); + forceSystemStateUpdate = true; // Imediately go to this new state + changeState(STATE_WIFI_CONFIG_NOT_STARTED); } // Menu exit control else if (incoming == 'S') { - systemPrintln("Shutting down..."); - forceDisplayUpdate = true; - powerDown(true); + systemPrintln("Shutting down..."); + forceDisplayUpdate = true; + powerDown(true); } else if (incoming == 'x') break; @@ -535,6 +534,10 @@ void menuDebugNetwork() systemPrint("27) Debug PVT UDP server: "); systemPrintf("%s\r\n", settings.debugPvtUdpServer ? "Enabled" : "Disabled"); + // WiFi Config + systemPrint("28) Debug WiFi Config: "); + systemPrintf("%s\r\n", settings.debugWiFiConfig ? "Enabled" : "Disabled"); + systemPrintln("r) Force system reset"); systemPrintln("x) Exit"); @@ -567,6 +570,8 @@ void menuDebugNetwork() settings.debugPvtServer ^= 1; else if (incoming == 27) settings.debugPvtUdpServer ^= 1; + else if (incoming == 28) + settings.debugWiFiConfig ^= 1; // Menu exit control else if (incoming == 'r') @@ -639,9 +644,7 @@ void menuDebugSoftware() minutes = seconds / SECONDS_IN_A_MINUTE; seconds -= minutes * SECONDS_IN_A_MINUTE; - systemPrintf("%d (%d days %d:%02d:%02d)\r\n", - settings.rebootSeconds, - days, hours, minutes, seconds); + systemPrintf("%d (%d days %d:%02d:%02d)\r\n", settings.rebootSeconds, days, hours, minutes, seconds); } // Tasks @@ -652,8 +655,7 @@ void menuDebugSoftware() systemPrintln("Disabled"); // Automatic Firmware Update - systemPrintf("60) Print firmware update states: %s\r\n", - settings.debugFirmwareUpdate ? "Enabled" : "Disabled"); + systemPrintf("60) Print firmware update states: %s\r\n", settings.debugFirmwareUpdate ? "Enabled" : "Disabled"); // Point Perfect systemPrintf("70) Point Perfect certificate management: %s\r\n", @@ -685,8 +687,7 @@ void menuDebugSoftware() { systemPrint("Enter uptime seconds before reboot, Disabled = 0, Reboot range (30 - 4294967): "); int rebootSeconds = getNumber(); // Returns EXIT, TIMEOUT, or long - if ((rebootSeconds != INPUT_RESPONSE_GETNUMBER_EXIT) - && (rebootSeconds != INPUT_RESPONSE_GETNUMBER_TIMEOUT)) + if ((rebootSeconds != INPUT_RESPONSE_GETNUMBER_EXIT) && (rebootSeconds != INPUT_RESPONSE_GETNUMBER_TIMEOUT)) { if (rebootSeconds < 30 || rebootSeconds > 4294967) // Disable the reboot { @@ -711,8 +712,7 @@ void menuDebugSoftware() minutes = seconds / SECONDS_IN_A_MINUTE; seconds -= minutes * SECONDS_IN_A_MINUTE; - systemPrintf("Reboot after uptime reaches %d days %d:%02d:%02d\r\n", - days, hours, minutes, seconds); + systemPrintf("Reboot after uptime reaches %d days %d:%02d:%02d\r\n", days, hours, minutes, seconds); } } } @@ -803,7 +803,11 @@ void menuOperation() systemPrint("11) Use I2C for L-Band Corrections: "); systemPrintf("%s\r\n", settings.useI2cForLbandCorrections ? "Enabled" : "Disabled"); - systemPrintf("12) RTCM timeout before L-Band override (seconds): %d\r\n", settings.rtcmTimeoutBeforeUsingLBand_s); + systemPrintf("12) RTCM timeout before L-Band override (seconds): %d\r\n", + settings.rtcmTimeoutBeforeUsingLBand_s); + + systemPrint("13) CONFIG UBLOX USB port: "); + systemPrintf("%s\r\n", settings.enableZedUsb ? "Enabled" : "Disabled"); systemPrintln("---- Interrupts ----"); systemPrint("30) Bluetooth Interrupts Core: "); @@ -972,14 +976,16 @@ void menuOperation() } else if (incoming == 11) { - settings.useI2cForLbandCorrectionsConfigured = true; //Record that the user has manually modified the settings. + settings.useI2cForLbandCorrectionsConfigured = + true; // Record that the user has manually modified the settings. settings.useI2cForLbandCorrections ^= 1; } else if (incoming == 12) { systemPrint("Enter the number of seconds before L-Band is used once RTCM is absent (1 to 255): "); int rtcmTimeoutBeforeUsingLBand_s = getNumber(); // Returns EXIT, TIMEOUT, or long - if ((rtcmTimeoutBeforeUsingLBand_s != INPUT_RESPONSE_GETNUMBER_EXIT) && (rtcmTimeoutBeforeUsingLBand_s != INPUT_RESPONSE_GETNUMBER_TIMEOUT)) + if ((rtcmTimeoutBeforeUsingLBand_s != INPUT_RESPONSE_GETNUMBER_EXIT) && + (rtcmTimeoutBeforeUsingLBand_s != INPUT_RESPONSE_GETNUMBER_TIMEOUT)) { if (rtcmTimeoutBeforeUsingLBand_s < 1 || rtcmTimeoutBeforeUsingLBand_s > 255) systemPrintln("Error: RTCM timeout out of range"); @@ -987,6 +993,52 @@ void menuOperation() settings.rtcmTimeoutBeforeUsingLBand_s = rtcmTimeoutBeforeUsingLBand_s; // Recorded to NVM and file } } + else if (incoming == 13) + { + settings.enableZedUsb ^= 1; + + bool response = true; + + response &= theGNSS.newCfgValset(); + + if (settings.enableZedUsb == true) + { + // The USB port on the ZED may be used for RTCM to/from the computer (as an NTRIP caster or client) + // So let's be sure all protocols are on for the USB port + response &= theGNSS.addCfgValset(UBLOX_CFG_USBOUTPROT_UBX, 1); + response &= theGNSS.addCfgValset(UBLOX_CFG_USBOUTPROT_NMEA, 1); + if (commandSupported(UBLOX_CFG_USBOUTPROT_RTCM3X) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_USBOUTPROT_RTCM3X, 1); + response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_UBX, 1); + response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_NMEA, 1); + response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_RTCM3X, 1); + if (commandSupported(UBLOX_CFG_USBINPROT_SPARTN) == true) + { + // See issue: https://github.com/sparkfun/SparkFun_RTK_Firmware/issues/713 + response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_SPARTN, 1); + } + } + else + { + // Disable all protocols over USB + response &= theGNSS.addCfgValset(UBLOX_CFG_USBOUTPROT_UBX, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_USBOUTPROT_NMEA, 0); + if (commandSupported(UBLOX_CFG_USBOUTPROT_RTCM3X) == true) + response &= theGNSS.addCfgValset(UBLOX_CFG_USBOUTPROT_RTCM3X, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_UBX, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_NMEA, 0); + response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_RTCM3X, 0); + if (commandSupported(UBLOX_CFG_USBINPROT_SPARTN) == true) + { + // See issue: https://github.com/sparkfun/SparkFun_RTK_Firmware/issues/713 + response &= theGNSS.addCfgValset(UBLOX_CFG_USBINPROT_SPARTN, 0); + } + } + response &= theGNSS.sendCfgValset(); + + if (response == false) + systemPrintln("Failed to set UART2 settings"); + } else if (incoming == 30) { diff --git a/Firmware/RTK_Surveyor/settings.h b/Firmware/RTK_Surveyor/settings.h index f07b06730..b7215297b 100644 --- a/Firmware/RTK_Surveyor/settings.h +++ b/Firmware/RTK_Surveyor/settings.h @@ -55,21 +55,21 @@ bool newSystemStateRequested = false; SystemState setupState = STATE_MARK_EVENT; // Base modes set with RTK_MODE -#define RTK_MODE_BASE_FIXED 0x0001 -#define RTK_MODE_BASE_SURVEY_IN 0x0002 -#define RTK_MODE_BUBBLE_LEVEL 0x0004 -#define RTK_MODE_ETHERNET_CONFIG 0x0008 -#define RTK_MODE_NTP 0x0010 -#define RTK_MODE_ROVER 0x0020 -#define RTK_MODE_TESTING 0x0040 -#define RTK_MODE_WIFI_CONFIG 0x0080 +#define RTK_MODE_BASE_FIXED 0x0001 +#define RTK_MODE_BASE_SURVEY_IN 0x0002 +#define RTK_MODE_BUBBLE_LEVEL 0x0004 +#define RTK_MODE_ETHERNET_CONFIG 0x0008 +#define RTK_MODE_NTP 0x0010 +#define RTK_MODE_ROVER 0x0020 +#define RTK_MODE_TESTING 0x0040 +#define RTK_MODE_WIFI_CONFIG 0x0080 typedef uint8_t RtkMode_t; -#define RTK_MODE(mode) rtkMode = mode; +#define RTK_MODE(mode) rtkMode = mode; -#define EQ_RTK_MODE(mode) (rtkMode && (rtkMode == (mode & rtkMode))) -#define NEQ_RTK_MODE(mode) (rtkMode && (rtkMode != (mode & rtkMode))) +#define EQ_RTK_MODE(mode) (rtkMode && (rtkMode == (mode & rtkMode))) +#define NEQ_RTK_MODE(mode) (rtkMode && (rtkMode != (mode & rtkMode))) typedef enum { @@ -85,8 +85,7 @@ typedef enum } ProductVariant; ProductVariant productVariant = RTK_SURVEYOR; -const char * const productDisplayNames[] = -{ +const char *const productDisplayNames[] = { "Surveyor", "Express", "Facet", @@ -97,10 +96,9 @@ const char * const productDisplayNames[] = // Add new values just above this line "Unknown", }; -const int productDisplayNamesEntries = sizeof (productDisplayNames) / sizeof(productDisplayNames[0]); +const int productDisplayNamesEntries = sizeof(productDisplayNames) / sizeof(productDisplayNames[0]); -const char * const platformFilePrefixTable[] = -{ +const char *const platformFilePrefixTable[] = { "SFE_Surveyor", "SFE_Express", "SFE_Facet", @@ -111,10 +109,9 @@ const char * const platformFilePrefixTable[] = // Add new values just above this line "SFE_Unknown", }; -const int platformFilePrefixTableEntries = sizeof (platformFilePrefixTable) / sizeof(platformFilePrefixTable[0]); +const int platformFilePrefixTableEntries = sizeof(platformFilePrefixTable) / sizeof(platformFilePrefixTable[0]); -const char * const platformPrefixTable[] = -{ +const char *const platformPrefixTable[] = { "Surveyor", "Express", "Facet", @@ -125,7 +122,7 @@ const char * const platformPrefixTable[] = // Add new values just above this line "Unknown", }; -const int platformPrefixTableEntries = sizeof (platformPrefixTable) / sizeof(platformPrefixTable[0]); +const int platformPrefixTableEntries = sizeof(platformPrefixTable) / sizeof(platformPrefixTable[0]); // Macros to show if the GNSS is I2C or SPI #define USE_SPI_GNSS (productVariant == REFERENCE_STATION) @@ -238,13 +235,13 @@ enum NetworkStates // Define the network users 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 + 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 // Last network user NETWORK_USER_MAX }; @@ -475,52 +472,52 @@ typedef uint32_t PeriodicDisplay_t; enum PeriodDisplayValues { - PD_BLUETOOTH_DATA_RX = 0, // 0 - PD_BLUETOOTH_DATA_TX, // 1 + PD_BLUETOOTH_DATA_RX = 0, // 0 + PD_BLUETOOTH_DATA_TX, // 1 - PD_ETHERNET_IP_ADDRESS, // 2 - PD_ETHERNET_STATE, // 3 + PD_ETHERNET_IP_ADDRESS, // 2 + PD_ETHERNET_STATE, // 3 - PD_NETWORK_STATE, // 4 + PD_NETWORK_STATE, // 4 - PD_NTP_SERVER_DATA, // 5 - PD_NTP_SERVER_STATE, // 6 + PD_NTP_SERVER_DATA, // 5 + PD_NTP_SERVER_STATE, // 6 - PD_NTRIP_CLIENT_DATA, // 7 - PD_NTRIP_CLIENT_GGA, // 8 - PD_NTRIP_CLIENT_STATE, // 9 + PD_NTRIP_CLIENT_DATA, // 7 + PD_NTRIP_CLIENT_GGA, // 8 + PD_NTRIP_CLIENT_STATE, // 9 - PD_NTRIP_SERVER_DATA, // 10 - PD_NTRIP_SERVER_STATE, // 11 + PD_NTRIP_SERVER_DATA, // 10 + PD_NTRIP_SERVER_STATE, // 11 - PD_PVT_CLIENT_DATA, // 12 - PD_PVT_CLIENT_STATE, // 13 + PD_PVT_CLIENT_DATA, // 12 + PD_PVT_CLIENT_STATE, // 13 - PD_PVT_SERVER_DATA, // 14 - PD_PVT_SERVER_STATE, // 15 - PD_PVT_SERVER_CLIENT_DATA, // 16 + PD_PVT_SERVER_DATA, // 14 + PD_PVT_SERVER_STATE, // 15 + PD_PVT_SERVER_CLIENT_DATA, // 16 - PD_PVT_UDP_SERVER_DATA, // 17 - PD_PVT_UDP_SERVER_STATE, // 18 - PD_PVT_UDP_SERVER_BROADCAST_DATA, // 19 + PD_PVT_UDP_SERVER_DATA, // 17 + PD_PVT_UDP_SERVER_STATE, // 18 + PD_PVT_UDP_SERVER_BROADCAST_DATA, // 19 - PD_RING_BUFFER_MILLIS, // 20 + PD_RING_BUFFER_MILLIS, // 20 - PD_SD_LOG_WRITE, // 21 + PD_SD_LOG_WRITE, // 21 - PD_TASK_BLUETOOTH_READ, // 22 - PD_TASK_BUTTON_CHECK, // 23 - PD_TASK_GNSS_READ, // 24 - PD_TASK_HANDLE_GNSS_DATA, // 25 - PD_TASK_SD_SIZE_CHECK, // 26 + PD_TASK_BLUETOOTH_READ, // 22 + PD_TASK_BUTTON_CHECK, // 23 + PD_TASK_GNSS_READ, // 24 + PD_TASK_HANDLE_GNSS_DATA, // 25 + PD_TASK_SD_SIZE_CHECK, // 26 - PD_WIFI_IP_ADDRESS, // 27 - PD_WIFI_STATE, // 28 + PD_WIFI_IP_ADDRESS, // 27 + PD_WIFI_STATE, // 28 - PD_ZED_DATA_RX, // 29 - PD_ZED_DATA_TX, // 30 + PD_ZED_DATA_RX, // 29 + PD_ZED_DATA_TX, // 30 - PD_OTA_CLIENT_STATE, // 31 + PD_OTA_CLIENT_STATE, // 31 // Add new values before this line }; @@ -830,21 +827,24 @@ typedef struct const ubxCmd ubxCommands[] = { {UBLOX_CFG_TMODE_MODE, "CFG_TMODE_MODE", 0, 9999}, // Survey mode is only available on ZED-F9P modules - {UBLOX_CFG_UART1OUTPROT_RTCM3X, "CFG_UART1OUTPROT_RTCM3X", 0, 9999}, // RTCM not supported on F9R + //The F9R is unique WRT RTCM *output*. u-center can correctly enable/disable the RTCM output, but it cannot + //be set with setVal commands. Applies to HPS 120, 121, 130. + + {UBLOX_CFG_UART1OUTPROT_RTCM3X, "CFG_UART1OUTPROT_RTCM3X", 0, 9999}, // F9R: RTCM output not supported {UBLOX_CFG_UART1INPROT_SPARTN, "CFG_UART1INPROT_SPARTN", 120, - 9999}, // Supported on F9P 120 and up. Not supported on F9R 120. + 121}, // Supported on F9P 120 and up. F9R: SPARTN supported starting HPS 121 - {UBLOX_CFG_UART2OUTPROT_RTCM3X, "CFG_UART2OUTPROT_RTCM3X", 0, 9999}, // RTCM not supported on F9R - {UBLOX_CFG_UART2INPROT_SPARTN, "CFG_UART2INPROT_SPARTN", 120, 9999}, // + {UBLOX_CFG_UART2OUTPROT_RTCM3X, "CFG_UART2OUTPROT_RTCM3X", 0, 9999}, // F9R: RTCM output not supported + {UBLOX_CFG_UART2INPROT_SPARTN, "CFG_UART2INPROT_SPARTN", 120, 121}, // F9R: SPARTN supported starting HPS 121 - {UBLOX_CFG_SPIOUTPROT_RTCM3X, "CFG_SPIOUTPROT_RTCM3X", 0, 9999}, // RTCM not supported on F9R - {UBLOX_CFG_SPIINPROT_SPARTN, "CFG_SPIINPROT_SPARTN", 120, 9999}, // + {UBLOX_CFG_SPIOUTPROT_RTCM3X, "CFG_SPIOUTPROT_RTCM3X", 0, 9999}, // F9R: RTCM output not supported + {UBLOX_CFG_SPIINPROT_SPARTN, "CFG_SPIINPROT_SPARTN", 120, 121}, // F9R: SPARTN supported starting HPS 121 - {UBLOX_CFG_I2COUTPROT_RTCM3X, "CFG_I2COUTPROT_RTCM3X", 0, 9999}, // RTCM not supported on F9R - {UBLOX_CFG_I2CINPROT_SPARTN, "CFG_I2CINPROT_SPARTN", 120, 9999}, // + {UBLOX_CFG_I2COUTPROT_RTCM3X, "CFG_I2COUTPROT_RTCM3X", 0, 9999}, // F9R: RTCM output not supported + {UBLOX_CFG_I2CINPROT_SPARTN, "CFG_I2CINPROT_SPARTN", 120, 121}, // F9R: SPARTN supported starting HPS 121 - {UBLOX_CFG_USBOUTPROT_RTCM3X, "CFG_USBOUTPROT_RTCM3X", 0, 9999}, // RTCM not supported on F9R - {UBLOX_CFG_USBINPROT_SPARTN, "CFG_USBINPROT_SPARTN", 120, 9999}, // + {UBLOX_CFG_USBOUTPROT_RTCM3X, "CFG_USBOUTPROT_RTCM3X", 0, 9999}, // F9R: RTCM output not supported + {UBLOX_CFG_USBINPROT_SPARTN, "CFG_USBINPROT_SPARTN", 120, 121}, // F9R: SPARTN supported starting HPS 121 {UBLOX_CFG_NAV2_OUT_ENABLED, "CFG_NAV2_OUT_ENABLED", 130, 130}, // Supported on F9P 130 and up. Supported on F9R 130 and up. @@ -887,7 +887,7 @@ typedef struct bool enableLogging = true; // If an SD card is present, log default sentences bool enableARPLogging = false; // Log the Antenna Reference Position from RTCM 1005/1006 - if available uint16_t ARPLoggingInterval_s = 10; // Log the ARP every 10 seconds - if available - uint16_t sppRxQueueSize = 512 * 2; + uint16_t sppRxQueueSize = 512 * 4; uint16_t sppTxQueueSize = 32; uint8_t dynamicModel = DYN_MODEL_PORTABLE; SystemState lastState = STATE_NOT_SET; // Start unit in last known state @@ -979,11 +979,11 @@ typedef struct bool enablePrintBufferOverrun = false; bool enablePrintSDBuffers = false; - PeriodicDisplay_t periodicDisplay = (PeriodicDisplay_t)0; //Turn off all periodic debug displays by default. + PeriodicDisplay_t periodicDisplay = (PeriodicDisplay_t)0; // Turn off all periodic debug displays by default. uint32_t periodicDisplayInterval = 15 * 1000; uint32_t rebootSeconds = (uint32_t)-1; // Disabled, reboots after uptime reaches this number of seconds - bool forceResetOnSDFail = false; // Set to true to reset system if SD is detected but fails to start. + bool forceResetOnSDFail = false; // Set to true to reset system if SD is detected but fails to start. uint8_t minElev = 10; // Minimum elevation (in deg) for a GNSS satellite to be used in NAV uint8_t ubxMessageRatesBase[MAX_UBX_MSG_RTCM] = { @@ -1016,9 +1016,10 @@ typedef struct 1; // Core where hardware is started and interrupts are assigned to, 0=core, 1=Arduino uint8_t i2cInterruptsCore = 1; // Core where hardware is started and interrupts are assigned to, 0=core, 1=Arduino uint32_t shutdownNoChargeTimeout_s = 0; // If > 0, shut down unit after timeout if not charging - bool disableSetupButton = false; // By default, allow setup through the overlay button(s) - bool useI2cForLbandCorrections = true; //Set to false to stop I2C callback. Corrections will require direct ZED to NEO UART2 connections. - bool useI2cForLbandCorrectionsConfigured = false; //If a user sets useI2cForLbandCorrections, this goes true. + bool disableSetupButton = false; // By default, allow setup through the overlay button(s) + bool useI2cForLbandCorrections = + true; // Set to false to stop I2C callback. Corrections will require direct ZED to NEO UART2 connections. + bool useI2cForLbandCorrectionsConfigured = false; // If a user sets useI2cForLbandCorrections, this goes true. // Ethernet bool enablePrintEthernetDiag = false; @@ -1103,9 +1104,10 @@ typedef struct bool debugPvtUdpServer = false; bool enablePvtUdpServer = false; uint16_t pvtUdpServerPort = - 10110; //https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=nmea + 10110; // https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=nmea - uint8_t rtcmTimeoutBeforeUsingLBand_s = 10; //If 10s have passed without RTCM, enable PMP corrections over L-Band if available + uint8_t rtcmTimeoutBeforeUsingLBand_s = + 10; // If 10s have passed without RTCM, enable PMP corrections over L-Band if available // Automatic Firmware Update bool debugFirmwareUpdate = false; @@ -1114,8 +1116,11 @@ typedef struct bool debugLBand = false; bool enableCaptivePortal = true; + bool enableZedUsb = true; //Can be used to disable ZED USB config + + bool debugWiFiConfig = false; - //Add new settings above <------------------------------------------------------------> + // Add new settings above <------------------------------------------------------------> } Settings; Settings settings;