Closed sindrehan closed 1 week ago
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 73.77%. Comparing base (
149ee93
) to head (ae0557e
). Report is 1 commits behind head on master.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
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