CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/pypi-pynmea2

tessl install tessl/pypi-pynmea2@1.19.0

Python 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%

task.mdevals/scenario-9/

NMEA Sentence Validator

Build a robust NMEA sentence validator that processes GPS data from multiple sources and handles various types of parsing errors gracefully.

Background

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:

  1. Parse NMEA sentences from various sources
  2. Detect and categorize different types of errors
  3. Generate reports on data quality
  4. Handle both valid and invalid data without crashing

Requirements

1. Parse and Validate NMEA Sentences

Implement a function validate_nmea_sentence(sentence: str) -> dict that:

  • Accepts a raw NMEA sentence string
  • Attempts to parse the sentence
  • Returns a dictionary with the following structure:
    {
        "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
    }

2. Process a Batch of Sentences

Implement a function process_nmea_batch(sentences: list[str]) -> dict that:

  • Accepts a list of NMEA sentence strings
  • Processes each sentence using the validator
  • Returns a summary dictionary:
    {
        "total": int,
        "valid": int,
        "checksum_errors": int,
        "unknown_types": int,
        "parse_errors": int,
        "sentence_types": dict    # Count of each sentence type found
    }

3. Enable Strict Validation Mode

Add a parameter to both functions to enable strict checksum validation:

  • validate_nmea_sentence(sentence: str, strict: bool = False) -> dict
  • process_nmea_batch(sentences: list[str], strict: bool = False) -> dict

When strict=True, checksum validation should be enforced. When strict=False, checksum errors should be ignored during parsing but still reported in the results.

Test Cases { .test-cases }

Test 1: Valid GGA Sentence { .test-case @test }

# 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 2: Checksum Error { .test-case @test }

# 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 3: Unknown Sentence Type { .test-case @test }

# 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 4: Batch Processing { .test-case @test }

# 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"] >= 1

Implementation Notes

  • Handle all error cases without raising unhandled exceptions
  • Differentiate between checksum errors, unknown sentence types, and general parsing errors
  • Ensure the strict mode properly validates checksums when enabled
  • Track statistics accurately across batches

Dependencies { .dependencies }

pynmea2 { .dependency }

Python library for parsing NMEA 0183 protocol sentences.

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pynmea2@1.19.x
tile.json