Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Using UDP communication, some statements fail to match because line breaks are not cleanly filtered #174

Open
wants to merge 2 commits into
base: ros2
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/libnmea_navsat_driver/nodes/nmea_socket_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,22 @@ def main(args=None):
sys.exit(1)

# recv-loop: When we're connected, keep receiving stuff until that fails
partial = ""
while rclpy.ok():
try:
data, remote_address = socket_.recvfrom(buffer_size)

partial += data.decode("ascii")

# strip the data
data_list = data.decode("ascii").strip().split("\n")
zymouse marked this conversation as resolved.
Show resolved Hide resolved

for data in data_list:

lines = partial.splitlines()
if partial.endswith('\n'):
full_lines = lines
partial = ""
else:
full_lines = lines[:-1]
partial = lines[-1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

If there's no data decoded and partial is an empty string, lines will be an empty list, and this line will raise an IndexError.

Copy link
Collaborator

Choose a reason for hiding this comment

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

A solution would be to add a continue on line 84:

if not partial:
  continue


for data in full_lines:
try:
driver.add_sentence(data, frame_id)
except ValueError as e:
Expand Down