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:

  1. Continuous buffer overflow errors for all following sentences
  2. Loss of valid GNSS data until the next '$' character is encountered
  3. 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)

  "Sensor procfs - Dynamic sensor debugging tool\n"
  "\n"
  "Usage:\n"
  "  cat /proc/sensor_monitor - Show currently monitored topics\n"
  "  echo <level> <topic> > /proc/sensor_monitor - Add topic(s)\n"
  "  echo rm <topic> > /proc/sensor_monitor - Remove topic(s)\n"
  "  echo add <topic> <topic> > /proc/sensor_monitor"
  " - add/remove topics\n"
  "  echo clean > /proc/sensor_monitor      - Remove all topics\n"
  "\n"
  "Examples:\n"
  "  echo sensor_accel > /proc/sensor_monitor\n"
  "  echo \"sensor_accel sensor_compass\" > /proc/sensor_monitor\n"
  "  echo \"1 sensor_accel sensor_compass\" > /proc/sensor_monitor\n"
  "  echo \"2 sensor_accel sensor_compass\" > /proc/sensor_monitor\n"
  "  echo \"rm sensor_accel\" > /proc/sensor_monitor\n"
  "  echo \"rm sensor_accel sensor_compass\" > /proc/sensor_monitor\n"
  "  echo clean > /proc/sensor_monitor\n"
  "  echo \"add 1 sensor_a rm sensor_b\" > /proc/sensor_monitor\n"
  "\n"
  "Note:\n"
  "  If <level> is not specified, it defaults to 1.\n";

Signed-off-by: chenzihan1 <chenzihan1@xiaomi.com>
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>
@github-actions github-actions bot added Area: Sensors Sensors issues Size: L The size of the change in this PR is large labels Jan 5, 2026
@chenzihan0416 chenzihan0416 deleted the gnss_uorb branch January 5, 2026 11:53
@acassis
Copy link
Contributor

acassis commented Jan 5, 2026

@chenzihan0416 why did you close it? Since like a good fix

{
if (*buffer == '$')
{
upper->parsenext = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix! Isn't this the only required line for this bug fix? I think the sensor monitor stuff is accidentally mixed in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Sensors Sensors issues Size: L The size of the change in this PR is large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants