Skip to content

Conversation

@chenzihan0416
Copy link
Contributor

Summary

Fix GNSS NMEA parser buffer overflow handling by resetting parse position after error.

When the NMEA parser detects a buffer overflow (line exceeds GNSS_PARSE_BUFFERSIZE), it logs an error message but fails to reset parsenext to 0. This causes subsequent NMEA sentences to be appended to the corrupted buffer, leading to:

Continuous buffer overflow errors for all following sentences
Loss of valid GNSS data until the next '$' character is encountered
Potential memory corruption if overflow detection fails

Impact

Improves GNSS data reliability when receiving malformed or oversized NMEA sentences
Prevents data loss from cascading parse errors
No API or behavior changes for normal operation

Testing

nsh> echo "$GPGGA,<300_char_garbage...>*00" > /dev/ttyGNSS0
nsh> echo "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47" > /dev/ttyGNSS0

before fix:

ERROR: NMEA buffer overflow, invalid statement:$GPGGA,<truncated>
ERROR: NMEA buffer overflow, invalid statement:GPGGA,123519,4807...
ERROR: NMEA buffer overflow, invalid statement:807.038,N,01131...
(repeating errors, no valid data parsed)

after fix:

ERROR: NMEA buffer overflow, invalid statement:$GPGGA,<truncated>
INFO: Parsed GPGGA: lat=48.1173, lon=11.5167, alt=545.4
(valid sentence parsed correctly after recovery)

@github-actions github-actions bot added Area: Sensors Sensors issues Size: XS The size of the change in this PR is very small labels Jan 5, 2026
@acassis
Copy link
Contributor

acassis commented Jan 5, 2026

@chenzihan0416 you don't need close the previous PR to fix it.

BTW, this one is wrong, you added a merge here. Please rebase with upstream to fix it.

When the last data sent by the driver does not contain \n\r,
it will cause a GAA parsing error

Signed-off-by: chenzihan1 <chenzihan1@xiaomi.com>
@chenzihan0416
Copy link
Contributor Author

@acassis : ( sorry, I encountered a problem when submitting the patch, which has now been rebased.

@acassis acassis merged commit 258e81f into apache:master Jan 5, 2026
40 checks passed
@chenzihan0416 chenzihan0416 deleted the gnss_uorb branch January 6, 2026 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Sensors Sensors issues Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants