Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(radio): prefer UBX over NMEA when both supported #4857

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions radio/src/gps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,20 @@ static void autodetectProtocol(uint8_t c)
{
static tmr10ms_t time;
static uint8_t state = 0;
static tmr10ms_t firstPacketNMEA = 0;

switch (state) {
case 0: // Init
time = get_tmr10ms();
state = 1;
case 1: // Wait for a valid packet
if (gpsNewFrameNMEA(c)) {
gpsProtocol = GPS_PROTOCOL_NMEA;
if (!firstPacketNMEA) {
firstPacketNMEA = time;
} else if (time - firstPacketNMEA > 200) {
// continuous stream of NMEA packets for 2 seconds, but no UBX packets
gpsProtocol = GPS_PROTOCOL_NMEA;
}
state = 0;
return;
}
Expand All @@ -125,8 +131,9 @@ static void autodetectProtocol(uint8_t c)
}

uint32_t new_time = get_tmr10ms();
if (new_time - time > 20) {
if (new_time - time > 50) {
// No message received
firstPacketNMEA = 0;
changeBaudrate();
time = new_time;
}
Expand Down
5 changes: 1 addition & 4 deletions radio/src/gps_ubx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ static void configureGps(bool detect)
{
static int state = 0;

if (detect) {
state = 0;
return;
}
if (detect) state = 0;

auto txCompleted = gpsSerialDrv->txCompleted;
if (txCompleted && !txCompleted(gpsSerialCtx)) return;
Expand Down