Skip to content

Commit 24bae0d

Browse files
authored
feat(radio): prefer UBX over NMEA when both supported (#4857)
1 parent 147bd1d commit 24bae0d

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

Diff for: radio/src/gps.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,20 @@ static void autodetectProtocol(uint8_t c)
106106
{
107107
static tmr10ms_t time;
108108
static uint8_t state = 0;
109+
static tmr10ms_t firstPacketNMEA = 0;
109110

110111
switch (state) {
111112
case 0: // Init
112113
time = get_tmr10ms();
113114
state = 1;
114115
case 1: // Wait for a valid packet
115116
if (gpsNewFrameNMEA(c)) {
116-
gpsProtocol = GPS_PROTOCOL_NMEA;
117+
if (!firstPacketNMEA) {
118+
firstPacketNMEA = time;
119+
} else if (time - firstPacketNMEA > 200) {
120+
// continuous stream of NMEA packets for 2 seconds, but no UBX packets
121+
gpsProtocol = GPS_PROTOCOL_NMEA;
122+
}
117123
state = 0;
118124
return;
119125
}
@@ -125,8 +131,9 @@ static void autodetectProtocol(uint8_t c)
125131
}
126132

127133
uint32_t new_time = get_tmr10ms();
128-
if (new_time - time > 20) {
134+
if (new_time - time > 50) {
129135
// No message received
136+
firstPacketNMEA = 0;
130137
changeBaudrate();
131138
time = new_time;
132139
}

Diff for: radio/src/gps_ubx.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,7 @@ static void configureGps(bool detect)
129129
{
130130
static int state = 0;
131131

132-
if (detect) {
133-
state = 0;
134-
return;
135-
}
132+
if (detect) state = 0;
136133

137134
auto txCompleted = gpsSerialDrv->txCompleted;
138135
if (txCompleted && !txCompleted(gpsSerialCtx)) return;

0 commit comments

Comments
 (0)