33void identifyBoard ()
44{
55 // Use ADC to check resistor divider
6- int pin_adc_rtk_facet = 35 ;
7- uint16_t idValue = analogReadMilliVolts (pin_adc_rtk_facet);
8- log_d (" Board ADC ID: %d" , idValue);
9-
10- if (idValue > (3300 / 2 * 0.9 ) && idValue < (3300 / 2 * 1.1 ))
6+ // Express: 10/3.3
7+ // Express+: 3.3/10
8+ // Facet: 10/10
9+ // Facet L-Band: 10/20
10+ // Reference Station: 20/10
11+ // Facet L-Band Direct: 10/100
12+ // Surveyor: ID resistors do not exist
13+
14+ const float rtkExpressID = 3.3 / (10 + 3.3 ) * 3300 ; // 819mV
15+ const float rtkExressPlusID = 10.0 / (10 + 3.3 ) * 3300 ; // 2418mV
16+ const float rtkFacetID = 10.0 / (10 + 10 ) * 3300 ; // 1650mV
17+ const float rtkFacetLbandID = 20.0 / (20 + 10 ) * 3300 ; // 2200mV
18+ const float rtkReferenceStationID = 10.0 / (10 + 20 ) * 3300 ; // 1100mV
19+ const float rtkFacetLbandDirectID = 1.0 / (4.7 + 1 ) * 3300 ; // 579mV
20+
21+ const float tolerance = 0.0475 ; // 4.75% Testing shows the combined ADC+resistors is under a 1% window
22+ const float upperThreshold = 1 + tolerance; // 104.75%
23+ const float lowerThreshold = 1 - tolerance; // 95.25%
24+
25+ int pin_deviceID = 35 ;
26+ uint16_t idValue = analogReadMilliVolts (pin_deviceID);
27+ log_d (" Board ADC ID (mV): %d" , idValue);
28+
29+ if (idValue > (rtkFacetID * lowerThreshold) && idValue < (rtkFacetID * upperThreshold))
1130 {
1231 productVariant = RTK_FACET;
1332 }
14- else if (idValue > (3300 * 2 / 3 * 0.9 ) && idValue < (3300 * 2 / 3 * 1.1 ))
33+ else if (idValue > (rtkFacetLbandID * lowerThreshold ) && idValue < (rtkFacetLbandID * upperThreshold ))
1534 {
1635 productVariant = RTK_FACET_LBAND;
1736 }
18- else if (idValue > (3300 * 3.3 / 13.3 * 0.9 ) && idValue < (3300 * 3.3 / 13.3 * 1.1 ))
37+ else if (idValue > (rtkExpressID * lowerThreshold ) && idValue < (rtkExpressID * upperThreshold ))
1938 {
2039 productVariant = RTK_EXPRESS;
2140 }
22- else if (idValue > (3300 * 10 / 13.3 * 0.9 ) && idValue < (3300 * 10 / 13.3 * 1.1 ))
41+ else if (idValue > (rtkExressPlusID * lowerThreshold ) && idValue < (rtkExressPlusID * upperThreshold ))
2342 {
2443 productVariant = RTK_EXPRESS_PLUS;
2544 }
26- else if (idValue > (3300 * 1 / 3 * 0.9 ) && idValue < (3300 * 1 / 3 * 1.1 ))
45+ else if (idValue > (rtkReferenceStationID * lowerThreshold ) && idValue < (rtkReferenceStationID * upperThreshold ))
2746 {
2847 productVariant = REFERENCE_STATION;
2948 // We can't auto-detect the ZED version if the firmware is in configViaEthernet mode,
3049 // so fake it here - otherwise messageSupported always returns false
3150 zedFirmwareVersionInt = 112 ;
3251 }
52+ else if (idValue > (rtkFacetLbandDirectID * lowerThreshold) && idValue < (rtkFacetLbandDirectID * upperThreshold))
53+ {
54+ productVariant = RTK_FACET_LBAND_DIRECT;
55+ }
3356 else
3457 {
3558 productVariant = RTK_UNKNOWN; // Need to wait until the GNSS and Accel have been initialized
@@ -112,10 +135,28 @@ void beginBoard()
112135 }
113136 else
114137 {
115- productVariant = RTK_SURVEYOR;
138+ // Detect RTK Expresses (v1.3 and below) that do not have an accel or device ID resistors
139+
140+ // On a Surveyor, pin 34 is not connected. On Express, 34 is connected to ZED_TX_READY
141+ const int pin_ZedTxReady = 34 ;
142+ uint16_t pinValue = analogReadMilliVolts (pin_ZedTxReady);
143+ log_d (" Alternate ID pinValue (mV): %d\r\n " , pinValue); // Surveyor = 142 to 152, //Express = 3129
144+ if (pinValue > 3000 )
145+ {
146+ if (zedModuleType == PLATFORM_F9P)
147+ productVariant = RTK_EXPRESS;
148+ else if (zedModuleType == PLATFORM_F9R)
149+ productVariant = RTK_EXPRESS_PLUS;
150+ }
151+ else
152+ productVariant = RTK_SURVEYOR;
116153 }
117154 }
118155
156+ // We need some settings before we are completely powered on
157+ // ie, disablePowerFiltering, enableResetDisplay, resetCount, etc
158+ loadSettingsPartial (); // Loads settings from LFS
159+
119160 // Setup hardware pins
120161 if (productVariant == RTK_SURVEYOR)
121162 {
@@ -173,7 +214,8 @@ void beginBoard()
173214 strncpy (platformPrefix, " Express Plus" , sizeof (platformPrefix) - 1 );
174215 }
175216 }
176- else if (productVariant == RTK_FACET || productVariant == RTK_FACET_LBAND)
217+ else if (productVariant == RTK_FACET || productVariant == RTK_FACET_LBAND ||
218+ productVariant == RTK_FACET_LBAND_DIRECT)
177219 {
178220 // v11
179221 pin_muxA = 2 ;
@@ -219,6 +261,15 @@ void beginBoard()
219261 strncpy (platformFilePrefix, " SFE_Facet_LBand" , sizeof (platformFilePrefix) - 1 );
220262 strncpy (platformPrefix, " Facet L-Band" , sizeof (platformPrefix) - 1 );
221263 }
264+ else if (productVariant == RTK_FACET_LBAND_DIRECT)
265+ {
266+ strncpy (platformFilePrefix, " SFE_Facet_LBand_Direct" , sizeof (platformFilePrefix) - 1 );
267+ strncpy (platformPrefix, " Facet L-Band Direct" , sizeof (platformPrefix) - 1 );
268+
269+ // Override the default setting if a user has not explicitly configured the setting
270+ if (settings.useI2cForLbandCorrectionsConfigured == false )
271+ settings.useI2cForLbandCorrections = false ;
272+ }
222273 }
223274 else if (productVariant == REFERENCE_STATION)
224275 {
@@ -244,7 +295,6 @@ void beginBoard()
244295 ethernetMACAddress[5 ] += 3 ; // Convert MAC address to Ethernet MAC (add 3)
245296
246297 // For all boards, check reset reason. If reset was due to wdt or panic, append last log
247- loadSettingsPartial (); // Loads settings from LFS
248298 if ((esp_reset_reason () == ESP_RST_POWERON) || (esp_reset_reason () == ESP_RST_SW))
249299 {
250300 reuseLastLog = false ; // Start new log
@@ -446,13 +496,13 @@ void beginSD()
446496 }
447497 }
448498 }
449- #else // COMPILE_SD_MMC
499+ #else // COMPILE_SD_MMC
450500 else
451501 {
452502 log_d (" SD_MMC not compiled" );
453503 break ; // No SD available.
454504 }
455- #endif // COMPILE_SD_MMC
505+ #endif // COMPILE_SD_MMC
456506
457507 if (createTestFile () == false )
458508 {
@@ -491,7 +541,7 @@ void endSD(bool alreadyHaveSemaphore, bool releaseSemaphore)
491541#ifdef COMPILE_SD_MMC
492542 else
493543 SD_MMC.end ();
494- #endif // COMPILE_SD_MMC
544+ #endif // COMPILE_SD_MMC
495545
496546 online.microSD = false ;
497547 systemPrintln (" microSD: Offline" );
@@ -549,20 +599,38 @@ void resetSPI()
549599// See issue: https://github.com/espressif/arduino-esp32/issues/3386
550600void beginUART2 ()
551601{
552- ringBuffer = (uint8_t *)malloc (settings.gnssHandlerBufferSize );
553-
554- if (pinUART2TaskHandle == nullptr )
555- xTaskCreatePinnedToCore (
556- pinUART2Task,
557- " UARTStart" , // Just for humans
558- 2000 , // Stack Size
559- nullptr , // Task input parameter
560- 0 , // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest
561- &pinUART2TaskHandle, // Task handle
562- settings.gnssUartInterruptsCore ); // Core where task should run, 0=core, 1=Arduino
563-
564- while (uart2pinned == false ) // Wait for task to run once
565- delay (1 );
602+ size_t length;
603+
604+ // Determine the length of data to be retained in the ring buffer
605+ // after discarding the oldest data
606+ length = settings.gnssHandlerBufferSize ;
607+ rbOffsetEntries = (length >> 1 ) / AVERAGE_SENTENCE_LENGTH_IN_BYTES;
608+ length = settings.gnssHandlerBufferSize
609+ + (rbOffsetEntries * sizeof (RING_BUFFER_OFFSET));
610+ ringBuffer = nullptr ;
611+ rbOffsetArray = (RING_BUFFER_OFFSET *)malloc (length);
612+ if (!rbOffsetArray)
613+ {
614+ rbOffsetEntries = 0 ;
615+ systemPrintln (" ERROR: Failed to allocate the ring buffer!" );
616+ }
617+ else
618+ {
619+ ringBuffer = (uint8_t *)&rbOffsetArray[rbOffsetEntries];
620+ rbOffsetArray[0 ] = 0 ;
621+ if (pinUART2TaskHandle == nullptr )
622+ xTaskCreatePinnedToCore (
623+ pinUART2Task,
624+ " UARTStart" , // Just for humans
625+ 2000 , // Stack Size
626+ nullptr , // Task input parameter
627+ 0 , // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest
628+ &pinUART2TaskHandle, // Task handle
629+ settings.gnssUartInterruptsCore ); // Core where task should run, 0=core, 1=Arduino
630+
631+ while (uart2pinned == false ) // Wait for task to run once
632+ delay (1 );
633+ }
566634}
567635
568636// Assign UART2 interrupts to the core that started the task. See:
@@ -877,7 +945,7 @@ void beginInterrupts()
877945 pinMode (pin_Ethernet_Interrupt, INPUT_PULLUP); // Prepare the interrupt pin
878946 attachInterrupt (pin_Ethernet_Interrupt, ethernetISR, FALLING); // Attach the interrupt
879947 }
880- #endif // COMPILE_ETHERNET
948+ #endif // COMPILE_ETHERNET
881949}
882950
883951// Set LEDs for output and configure PWM
@@ -981,7 +1049,7 @@ void beginSystemState()
9811049 if (systemState > STATE_NOT_SET)
9821050 {
9831051 systemPrintln (" Unknown state - factory reset" );
984- factoryReset (false ); // We do not have the SD semaphore
1052+ factoryReset (false ); // We do not have the SD semaphore
9851053 }
9861054
9871055 if (productVariant == RTK_SURVEYOR)
@@ -1002,6 +1070,7 @@ void beginSystemState()
10021070 systemState = STATE_ROVER_NOT_STARTED; // Assume Rover. ButtonCheckTask() will correct as needed.
10031071
10041072 setupBtn = new Button (pin_setupButton); // Create the button in memory
1073+ // Allocation failure handled in ButtonCheckTask
10051074 }
10061075 else if (productVariant == RTK_EXPRESS || productVariant == RTK_EXPRESS_PLUS)
10071076 {
@@ -1020,8 +1089,10 @@ void beginSystemState()
10201089
10211090 setupBtn = new Button (pin_setupButton); // Create the button in memory
10221091 powerBtn = new Button (pin_powerSenseAndControl); // Create the button in memory
1092+ // Allocation failures handled in ButtonCheckTask
10231093 }
1024- else if (productVariant == RTK_FACET || productVariant == RTK_FACET_LBAND)
1094+ else if (productVariant == RTK_FACET || productVariant == RTK_FACET_LBAND ||
1095+ productVariant == RTK_FACET_LBAND_DIRECT)
10251096 {
10261097 if (settings.lastState == STATE_NOT_SET) // Default
10271098 {
@@ -1041,6 +1112,7 @@ void beginSystemState()
10411112 firstRoverStart = false ;
10421113
10431114 powerBtn = new Button (pin_powerSenseAndControl); // Create the button in memory
1115+ // Allocation failure handled in ButtonCheckTask
10441116 }
10451117 else if (productVariant == REFERENCE_STATION)
10461118 {
@@ -1055,6 +1127,7 @@ void beginSystemState()
10551127 .lastState ; // Return to either NTP, Base or Rover Not Started. The last state previous to power down.
10561128
10571129 setupBtn = new Button (pin_setupButton); // Create the button in memory
1130+ // Allocation failure handled in ButtonCheckTask
10581131 }
10591132
10601133 // Starts task for monitoring button presses
0 commit comments