File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments