Skip to content

Commit 9ee7fa7

Browse files
committed
Added .beginAutoBaudDetect()
1 parent 73c995f commit 9ee7fa7

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

USERGUIDE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ This library provides an interface for controlling and configuring an LG290P GNS
2424
- **`bool begin(HardwareSerial &serialPort, Print *parserDebug = nullptr, Print *parserError = &Serial);`**
2525
Initialize communication with the GNSS module using a serial port. Optional debugging and error printing can be specified.
2626

27+
- **`bool beginAutoBaudDetect(HardwareSerial &serialPort, int rxPin, int txPin, Print *parserDebug = nullptr, Print *parserError = &Serial);`**
28+
Auto-detect which baud rate the port is connected at. Repeatedly calls 'begin()' above, trying all the various baud rates that the LG290P supports, starting with the default, 480600. Optional debugging and error printing can be specified.
29+
2730
- **`bool isConnected();`**
2831
Check if the GNSS module is connected.
2932

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ LG290P KEYWORD1
1313
#######################################
1414

1515
begin KEYWORD2
16+
beginAutoBaudDetect KEYWORD2
1617
isConnected KEYWORD2
1718
isBlocking KEYWORD2
1819
update KEYWORD2

src/SparkFun_LG290P_GNSS.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,35 @@ bool LG290P::begin(HardwareSerial &serialPort, Print *parserDebug, Print *parser
128128
ok = ok && getMode(devState.mode);
129129
ok = ok && scanForMsgsEnabled();
130130

131-
debugPrintf("Starting with %s mode, GGA %d RMC %d EPE %d PVT %d PL %d SVIN %d GSV %d",
132-
devState.mode == BASEMODE ? "BASE" : "ROVER", devState.ggaRate, devState.rmcRate, devState.epeRate,
133-
devState.pvtRate, devState.plRate, devState.svinstatusRate, devState.gsvRate);
134-
if (!ok)
131+
if (ok)
132+
{
133+
debugPrintf("Starting with %s mode, GGA %d RMC %d EPE %d PVT %d PL %d SVIN %d GSV %d",
134+
devState.mode == BASEMODE ? "BASE" : "ROVER", devState.ggaRate, devState.rmcRate, devState.epeRate,
135+
devState.pvtRate, devState.plRate, devState.svinstatusRate, devState.gsvRate);
136+
}
137+
else
135138
{
139+
debugPrintf("begin() failed.");
136140
sempStopParser(&_sempParse);
137141
}
138142

139143
return ok;
140144
}
141145

146+
bool LG290P::beginAutoBaudDetect(HardwareSerial &serialPort, int rxPin, int txPin, Print *parserDebug /* = nullptr */, Print *parserError /* = &Serial */)
147+
{
148+
serialPort.setRxBufferSize(4096);
149+
150+
for (int baud: {460800, 921600, 230400, 115200, 9600})
151+
{
152+
debugPrintf("Trying baud rate %d...", baud);
153+
serialPort.begin(baud, SERIAL_8N1, rxPin, txPin);
154+
if (begin(serialPort, parserDebug, parserError))
155+
return true;
156+
}
157+
return false;
158+
}
159+
142160
// Query the device with 'UNIQID', expect OK response
143161
// Device may be booting and outputting other messages (ie, PQTMVER)
144162
// Try a few times

src/SparkFun_LG290P_GNSS.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ class LG290P
7272
*/
7373
bool begin(HardwareSerial &serialPort, Print *parserDebug = nullptr, Print *parserError = &Serial);
7474

75+
/**
76+
* @brief Starts the LG290P engine. Does not require open serial port. Tests various likely baud rates
77+
* @param serialPort a port that is connected to the LG290P module
78+
* @param rxPin the pin that receives data from the LG290P
79+
* @param txPin the pin that sends data to the LG290P
80+
* @param parserDebug if provided, show debugging for the parser
81+
* @param parserError if provided, show error messages for the parser
82+
* @return true if the initialization succeeded
83+
*/
84+
bool beginAutoBaudDetect(HardwareSerial &serialPort, int rxPin, int txPin, Print *parserDebug = nullptr, Print *parserError = &Serial);
85+
7586
/**
7687
* @brief Poll the device with the PQTMUNIQID command to see if it is responding
7788
* @return true if the device responds within 10 seconds

0 commit comments

Comments
 (0)