Skip to content

Commit 929c036

Browse files
committed
Improve parsing
This was failing to read whole lines for me. And for some reason my device is putting zeros on the head of strings.
1 parent fe7b5b6 commit 929c036

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

uart/gps_uart/gps_uart.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ bool parse_nmea_gps(char *nmea_string, GPSData *gps_data)
154154
}
155155

156156
// Check if we have enough tokens and data is valid
157-
if (token_count >= 12 && strcmp(tokens[2], "A") == 0)
157+
if (token_count >= 7 && strcmp(tokens[2], "A") == 0)
158158
{
159159
if (strlen(tokens[3]) > 0)
160160
{
@@ -173,6 +173,7 @@ bool parse_nmea_gps(char *nmea_string, GPSData *gps_data)
173173
gps_data->is_valid = true;
174174
return true;
175175
}
176+
return false;
176177
}
177178

178179

@@ -189,9 +190,16 @@ void process_gps_data(GPSData *gps_data)
189190
char nmea_buffer[MAX_NMEA_LENGTH];
190191
int chars_read = 0;
191192

192-
while (uart_is_readable(UART_ID) && chars_read < MAX_NMEA_LENGTH - 1)
193+
while (true)
193194
{
195+
// string too long
196+
if (chars_read >= MAX_NMEA_LENGTH - 1)
197+
break;
194198
char received_char = uart_getc(UART_ID);
199+
// ignore zero bytes
200+
if (received_char == 0) {
201+
continue;
202+
}
195203
nmea_buffer[chars_read] = received_char;
196204

197205
// NMEA strings are terminated by a newline character
@@ -203,8 +211,6 @@ void process_gps_data(GPSData *gps_data)
203211
{
204212
printf("Valid GPS Data Received\n");
205213
}
206-
207-
chars_read = 0;
208214
break;
209215
}
210216
else

0 commit comments

Comments
 (0)