Skip to content

Commit dfa0584

Browse files
committed
Extend LG290P Data/Radio/Comm inits to work on Flex
1 parent 0059c5e commit dfa0584

File tree

5 files changed

+175
-62
lines changed

5 files changed

+175
-62
lines changed

Firmware/RTK_Everywhere/GNSS.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,14 +337,16 @@ class GNSS
337337
// Inputs:
338338
// baudRate: The desired baudrate
339339
virtual bool setBaudrate(uint32_t baudRate);
340-
340+
341341
// Enable all the valid constellations and bands for this platform
342342
virtual bool setConstellations();
343343

344344
// Enable / disable corrections protocol(s) on the Radio External port
345345
// Always update if force is true. Otherwise, only update if enable has changed state
346346
virtual bool setCorrRadioExtPort(bool enable, bool force);
347347

348+
virtual bool setBaudRate(uint8_t uartNumber, uint32_t baudRate);
349+
348350
virtual bool setDataBaudRate(uint32_t baud);
349351

350352
// Set the elevation in degrees

Firmware/RTK_Everywhere/GNSS.ino

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,19 @@ void gnssDetectReceiverType()
135135
#endif // COMPILE_LGP290P
136136

137137
#ifdef COMPILE_MOSAICX5
138-
// TODO - this uses UART2, but Flex is UART1. We need to make the mosaic send routines flexible to use
139-
// whichever UART we specify.
140-
// if (mosaicIsPresent() == true)
141-
// systemPrintln("Auto-detected GNSS receiver: mosaic-X5");
142-
// settings.detectedGnssReceiver = GNSS_RECEIVER_MOSAIC_X5;
143-
// recordSystemSettings(); // Record the detected GNSS receiver and avoid this test in the future
138+
// TODO - this uses UART2, but Flex is UART1. We need to make the mosaic send routines flexible to use
139+
// whichever UART we specify.
140+
// else if (mosaicIsPresent() == true)
141+
// {
142+
// systemPrintln("Auto-detected GNSS receiver: mosaic-X5");
143+
// settings.detectedGnssReceiver = GNSS_RECEIVER_MOSAIC_X5;
144+
// recordSystemSettings(); // Record the detected GNSS receiver and avoid this test in the future
145+
// }
144146
#else // COMPILE_MOSAICX5
145-
systemPrintln("<<<<<<<<<< !!!!!!!!!! MOSAICX5 NOT COMPILED !!!!!!!!!! >>>>>>>>>>");
147+
else
148+
{
149+
systemPrintln("<<<<<<<<<< !!!!!!!!!! MOSAICX5 NOT COMPILED !!!!!!!!!! >>>>>>>>>>");
150+
}
146151
#endif // COMPILE_MOSAICX5
147152
}
148153

Firmware/RTK_Everywhere/GNSS_LG290P.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,13 @@ class GNSS_LG290P : GNSS
237237
// Returns the altitude in meters or zero if the GNSS is offline
238238
double getAltitude();
239239

240+
uint32_t getBaudRate(uint8_t uartNumber);
241+
240242
// Returns the carrier solution or zero if not online
241243
uint8_t getCarrierSolution();
242244

245+
uint32_t getCommBaudRate();
246+
243247
uint32_t getDataBaudRate();
244248

245249
// Returns the day number or zero if not online
@@ -416,13 +420,12 @@ class GNSS_LG290P : GNSS
416420
// Returns true when the configuration was saved and false upon failure
417421
bool saveConfiguration();
418422

419-
// Set the baud rate on the GNSS port that interfaces between the ESP32 and the GNSS
420-
// This just sets the GNSS side
421-
// Used during Bluetooth testing
422-
// Inputs:
423-
// baudRate: The desired baudrate
424423
bool setBaudrate(uint32_t baudRate);
425424

425+
bool setBaudRate(uint8_t uartNumber, uint32_t baudRate);
426+
427+
bool setCommBaudrate(uint32_t baud);
428+
426429
// Enable all the valid constellations and bands for this platform
427430
bool setConstellations();
428431

@@ -480,9 +483,6 @@ class GNSS_LG290P : GNSS
480483
// we can pass data back into the LG290P library to allow it to update its own variables
481484
void lg290pUpdate(uint8_t *incomingBuffer, int bufferLength);
482485

483-
// Return the baud rate of UART2, connected to the ESP32 UART1
484-
uint32_t getCommBaudRate();
485-
486486
// Poll routine to update the GNSS state
487487
void update();
488488
};

Firmware/RTK_Everywhere/GNSS_LG290P.ino

Lines changed: 139 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,12 @@ bool GNSS_LG290P::configureOnce()
255255
// Set the baud rate for the three UARTs
256256
if (response == true)
257257
{
258-
if (getDataBaudRate() != settings.dataPortBaud)
259-
response &= setDataBaudRate(settings.dataPortBaud); // LG290P UART1 is connected to CH342 (Port B)
258+
response &= setDataBaudRate(settings.dataPortBaud); // If available, set baud of DATA port
260259

261-
if (getCommBaudRate() != (115200 * 4))
262-
response &= setBaudrate(115200 * 4); // LG290P UART2 is connected to the ESP32 UART1
260+
// This is redundant because to get this far, the comm interface must already be working
261+
// response &= setCommBaudrate(115200 * 4); // Set baud for main comm channel
263262

264-
if (getRadioBaudRate() != settings.radioPortBaud)
265-
response &=
266-
setRadioBaudRate(settings.radioPortBaud); // LG290P UART3 is connected to the locking JST connector
263+
response &= setRadioBaudRate(settings.radioPortBaud); // If available, set baud of RADIO port
267264

268265
if (response == false && settings.debugGnss)
269266
systemPrintln("configureOnce: setBauds failed.");
@@ -1078,7 +1075,7 @@ uint8_t GNSS_LG290P::getActiveRtcmMessageCount()
10781075
}
10791076

10801077
//----------------------------------------
1081-
// Returns the altitude in meters or zero if the GNSS is offline
1078+
// Returns the altitude in meters or zero if the GNSS is offline
10821079
//----------------------------------------
10831080
double GNSS_LG290P::getAltitude()
10841081
{
@@ -1114,55 +1111,133 @@ uint8_t GNSS_LG290P::getCarrierSolution()
11141111
}
11151112

11161113
//----------------------------------------
1117-
// UART1 of the LG290P is connected to USB CH342 (Port B)
1118-
// This is nicknamed the DATA port
1119-
// Return the baud rate of UART1
1114+
// Return the baud rate of a given UART
11201115
//----------------------------------------
1121-
uint32_t GNSS_LG290P::getDataBaudRate()
1116+
uint32_t GNSS_LG290P::getBaudRate(uint8_t uartNumber)
11221117
{
1118+
if (uartNumber < 1 || uartNumber > 3)
1119+
{
1120+
systemPrintln("getBaudRate error: out of range");
1121+
return (0);
1122+
}
1123+
11231124
uint32_t baud = 0;
11241125
if (online.gnss)
11251126
{
11261127
uint8_t dataBits, parity, stop, flowControl;
11271128

1128-
_lg290p->getPortInfo(1, baud, dataBits, parity, stop, flowControl, 250);
1129+
_lg290p->getPortInfo(uartNumber, baud, dataBits, parity, stop, flowControl, 250);
11291130
}
11301131
return (baud);
11311132
}
11321133

11331134
//----------------------------------------
1134-
// UART1 of the LG290P is connected to USB CH342 (Port B)
1135-
// This is nicknamed the DATA port
1136-
// Return the baud rate of UART1
1135+
// Set the baud rate of a given UART
1136+
//----------------------------------------
1137+
bool GNSS_LG290P::setBaudRate(uint8_t uartNumber, uint32_t baudRate)
1138+
{
1139+
if (uartNumber < 1 || uartNumber > 3)
1140+
{
1141+
systemPrintln("setBaudRate error: out of range");
1142+
return (false);
1143+
}
1144+
1145+
return (_lg290p->setPortBaudrate(uartNumber, baudRate, 250));
1146+
}
1147+
1148+
// Used only for Bluetooth test
1149+
bool GNSS_LG290P::setBaudrate(uint32_t baudRate)
1150+
{
1151+
return (setBaudRate(2, baudRate));
1152+
}
1153+
1154+
//----------------------------------------
1155+
// Return the baud rate of port nicknamed DATA
1156+
//----------------------------------------
1157+
uint32_t GNSS_LG290P::getDataBaudRate()
1158+
{
1159+
uint8_t dataUart = 0;
1160+
if (productVariant == RTK_POSTCARD)
1161+
{
1162+
// UART1 of the LG290P is connected to USB CH342 (Port B)
1163+
// This is nicknamed the DATA port
1164+
dataUart = 1;
1165+
}
1166+
return (getBaudRate(dataUart));
1167+
}
1168+
1169+
//----------------------------------------
1170+
// Set the baud rate of port nicknamed DATA
11371171
//----------------------------------------
11381172
bool GNSS_LG290P::setDataBaudRate(uint32_t baud)
11391173
{
11401174
if (online.gnss)
11411175
{
1142-
return (_lg290p->setPortBaudrate(1, baud, 250));
1176+
if (productVariant == RTK_POSTCARD)
1177+
{
1178+
if (getDataBaudRate() != baud)
1179+
{
1180+
// UART1 of the LG290P is connected to USB CH342 (Port B)
1181+
// This is nicknamed the DATA port
1182+
return (setBaudRate(1, baud));
1183+
}
1184+
}
1185+
else
1186+
{
1187+
// On products that don't have a DATA port (Flex), act as if we have set the baud successfully
1188+
return (true);
1189+
}
11431190
}
1144-
return (0);
1191+
return (false);
11451192
}
11461193

1147-
// Return the baud rate of UART3, connected to the locking JST connector
1194+
//----------------------------------------
1195+
// Return the baud rate of interface where a radio is connected
11481196
//----------------------------------------
11491197
uint32_t GNSS_LG290P::getRadioBaudRate()
11501198
{
1151-
uint32_t baud = 0;
1152-
if (online.gnss)
1199+
uint8_t radioUart = 0;
1200+
if (productVariant == RTK_POSTCARD)
11531201
{
1154-
uint8_t dataBits, parity, stop, flowControl;
1155-
1156-
_lg290p->getPortInfo(3, baud, dataBits, parity, stop, flowControl, 250);
1202+
// UART3 of the LG290P is connected to the locking JST connector labled RADIO
1203+
radioUart = 3;
11571204
}
1158-
return (baud);
1205+
else if (productVariant == RTK_FLEX)
1206+
{
1207+
// UART2 of the LG290P is connected to SW4, which is connected to LoRa UART0
1208+
radioUart = 2;
1209+
}
1210+
return (getBaudRate(radioUart));
11591211
}
11601212

1161-
// Set the baud rate for UART3, connected to the locking JST connector
1213+
//----------------------------------------
1214+
// Set the baud rate for the Radio connection
11621215
//----------------------------------------
11631216
bool GNSS_LG290P::setRadioBaudRate(uint32_t baud)
11641217
{
1165-
return (_lg290p->setPortBaudrate(3, baud, 250));
1218+
if (online.gnss)
1219+
{
1220+
if (getRadioBaudRate() == baud)
1221+
{
1222+
return (true); // Baud is set!
1223+
}
1224+
else
1225+
{
1226+
uint8_t radioUart = 0;
1227+
if (productVariant == RTK_POSTCARD)
1228+
{
1229+
// UART3 of the LG290P is connected to the locking JST connector labled RADIO
1230+
radioUart = 3;
1231+
}
1232+
else if (productVariant == RTK_FLEX)
1233+
{
1234+
// UART2 of the LG290P is connected to SW4, which is connected to LoRa UART0
1235+
radioUart = 2;
1236+
}
1237+
return (setBaudRate(radioUart, baud));
1238+
}
1239+
}
1240+
return (false);
11661241
}
11671242

11681243
//----------------------------------------
@@ -1222,6 +1297,8 @@ uint8_t GNSS_LG290P::getHour()
12221297
return 0;
12231298
}
12241299

1300+
//----------------------------------------
1301+
// Return the serial number of the LG290P
12251302
//----------------------------------------
12261303
const char *GNSS_LG290P::getId()
12271304
{
@@ -1972,27 +2049,50 @@ bool GNSS_LG290P::saveConfiguration()
19722049
// Set the baud rate on the GNSS port that interfaces between the ESP32 and the GNSS
19732050
// This just sets the GNSS side
19742051
//----------------------------------------
1975-
bool GNSS_LG290P::setBaudrate(uint32_t baud)
2052+
bool GNSS_LG290P::setCommBaudrate(uint32_t baud)
19762053
{
19772054
if (online.gnss)
1978-
// Set the baud rate on UART2 of the LG290P
1979-
return (_lg290p->setPortBaudrate(2, baud, 250));
1980-
return false;
2055+
{
2056+
if (getCommBaudRate() == baud)
2057+
{
2058+
return (true); // Baud is set!
2059+
}
2060+
else
2061+
{
2062+
uint8_t commUart = 0;
2063+
if (productVariant == RTK_POSTCARD)
2064+
{
2065+
// UART2 of the LG290P is connected to the ESP32 for the main config/comm
2066+
commUart = 2;
2067+
}
2068+
else if (productVariant == RTK_FLEX)
2069+
{
2070+
// UART1 of the LG290P is connected to the ESP32 for the main config/comm
2071+
commUart = 1;
2072+
}
2073+
return (setBaudRate(commUart, baud));
2074+
}
2075+
}
2076+
return (false);
19812077
}
19822078

19832079
//----------------------------------------
1984-
// Return the baud rate of UART2, connected to the ESP32 UART1
2080+
// Return the baud rate of the UART connected to the ESP32 UART1
19852081
//----------------------------------------
19862082
uint32_t GNSS_LG290P::getCommBaudRate()
19872083
{
1988-
uint32_t baud = 0;
1989-
if (online.gnss)
2084+
uint8_t commUart = 0;
2085+
if (productVariant == RTK_POSTCARD)
19902086
{
1991-
uint8_t dataBits, parity, stop, flowControl;
1992-
1993-
_lg290p->getPortInfo(2, baud, dataBits, parity, stop, flowControl, 250);
2087+
// On the Postcard, the ESP32 UART1 is connected to LG290P UART2
2088+
commUart = 2;
19942089
}
1995-
return (baud);
2090+
else if (productVariant == RTK_FLEX)
2091+
{
2092+
// On the Flex, the ESP32 UART1 is connected to LG290P UART1
2093+
commUart = 1;
2094+
}
2095+
return (getBaudRate(commUart));
19962096
}
19972097

19982098
//----------------------------------------
@@ -2402,7 +2502,7 @@ bool lg290pIsPresent()
24022502
lg290p.enableDebugging(); // Print all debug to Serial
24032503
lg290p.enablePrintRxMessages(); // Print incoming processed messages from SEMP
24042504
}
2405-
2505+
24062506
if (lg290p.begin(serialTestGNSS) == true) // Give the serial port over to the library
24072507
{
24082508
if (settings.debugGnss)

0 commit comments

Comments
 (0)