tessl install tessl/pypi-pynmea2@1.19.0Python library for parsing and generating NMEA 0183 protocol messages used in GPS and marine navigation systems
Agent Success
Agent success rate when using this tile
77%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.12x
Baseline
Agent success rate without this tile
69%
Build a robust NMEA sentence validator that processes GPS data from multiple sources and handles various types of parsing errors gracefully.
GPS devices and marine navigation equipment transmit data using the NMEA 0183 protocol. In real-world applications, this data can be corrupted due to transmission errors, device malfunctions, or data corruption. Your task is to build a validator that can:
Implement a function validate_nmea_sentence(sentence: str) -> dict that:
{
"valid": bool, # True if parsing succeeded
"error_type": str, # "none", "checksum", "unknown_type", or "parse_error"
"sentence_type": str, # The sentence type (e.g., "GGA", "RMC") or None
"message": str # Human-readable description
}Implement a function process_nmea_batch(sentences: list[str]) -> dict that:
{
"total": int,
"valid": int,
"checksum_errors": int,
"unknown_types": int,
"parse_errors": int,
"sentence_types": dict # Count of each sentence type found
}Add a parameter to both functions to enable strict checksum validation:
validate_nmea_sentence(sentence: str, strict: bool = False) -> dictprocess_nmea_batch(sentences: list[str], strict: bool = False) -> dictWhen strict=True, checksum validation should be enforced. When strict=False, checksum errors should be ignored during parsing but still reported in the results.
# test_validator.py
sentence = "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47"
result = validate_nmea_sentence(sentence, strict=True)
assert result["valid"] == True
assert result["error_type"] == "none"
assert result["sentence_type"] == "GGA"# test_validator.py
sentence = "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*99"
result = validate_nmea_sentence(sentence, strict=True)
assert result["valid"] == False
assert result["error_type"] == "checksum"# test_validator.py
sentence = "$GPXYZ,123519,4807.038,N*2A"
result = validate_nmea_sentence(sentence)
assert result["valid"] == False
assert result["error_type"] == "unknown_type"# test_validator.py
sentences = [
"$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47",
"$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A",
"$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*99",
"$GPXYZ,123519,4807.038,N*2A",
"INVALID DATA"
]
result = process_nmea_batch(sentences, strict=True)
assert result["total"] == 5
assert result["valid"] == 2
assert result["checksum_errors"] >= 1
assert result["unknown_types"] >= 1
assert result["parse_errors"] >= 1Python library for parsing NMEA 0183 protocol sentences.