-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add example showing how to forward position as NMEA over UDP #171
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to change the port, other that than it seems like it will work. Have you been able to test it at all?
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #171 +/- ##
=======================================
Coverage 73.77% 73.77%
=======================================
Files 11 11
Lines 1266 1266
=======================================
Hits 934 934
Misses 332 332
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
I don't have an actual device to test with, but I (CoPilot really) made a test script that uses an parser to check the validity and it seems to work fine with that. import socket
import pynmea2
# UDP configuration
UDP_IP = "0.0.0.0"
UDP_PORT = 10111
# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((UDP_IP, UDP_PORT))
print(f"Listening for UDP packets on {UDP_IP}:{UDP_PORT}")
def validate_nmea_sentence(sentence: str) -> bool:
"""Validate the NMEA sentence using pynmea2."""
try:
parsed_sentence = pynmea2.parse(sentence)
return isinstance(parsed_sentence, pynmea2.types.talker.GLL)
except pynmea2.nmea.ChecksumError:
print("Checksum error")
return False
except pynmea2.nmea.ParseError:
print("Parse error")
return False
try:
while True:
data, addr = sock.recvfrom(1024) # Buffer size is 1024 bytes
message = data.decode("utf-8").strip()
print(f"Received message: {message} from {addr}")
if validate_nmea_sentence(message):
print("Valid NMEA sentence")
else:
print("Invalid NMEA sentence")
except KeyboardInterrupt:
print("Exiting...")
finally:
sock.close() |
I'm not really familiar with the NMEA stuff, so would be great if you @aviggen or @haavardsyslak could take a look and see if everything makes sense.
Fixes #170