CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pynmea2

Python library for parsing and generating NMEA 0183 protocol messages used in GPS and marine navigation systems

77

1.11x
Overview
Eval results
Files

navigation-course.mddocs/

Navigation and Course Sentences

Navigation and course sentences provide heading, bearing, waypoint, and route information for marine and land navigation systems.

Heading Sentences

HDG - Heading, Deviation and Variation

class HDG(TalkerSentence):
    """Heading, Deviation and Variation."""
    
    heading: str              # Magnetic heading in degrees
    deviation: str            # Magnetic deviation in degrees
    dev_dir: str             # Deviation direction ('E' or 'W')
    variation: str           # Magnetic variation in degrees
    var_dir: str             # Variation direction ('E' or 'W')

HDT - Heading True

class HDT(TalkerSentence):
    """Heading True."""
    
    heading: str              # True heading in degrees
    hdg_true: str            # Always 'T' for true

HDM - Heading, Magnetic

class HDM(TalkerSentence):
    """Heading, Magnetic."""
    
    heading: str              # Magnetic heading in degrees
    magnetic: str            # Always 'M' for magnetic

Waypoint and Bearing Sentences

BWC - Bearing & Distance to Waypoint - Great Circle

class BWC(TalkerSentence):
    """Bearing & Distance to Waypoint - Great Circle."""
    
    timestamp: datetime.time
    lat_next: str            # Next waypoint latitude
    lat_next_direction: str  # 'N' or 'S'
    lon_next: str           # Next waypoint longitude  
    lon_next_direction: str # 'E' or 'W'
    true_track: str         # True bearing to waypoint
    true_track_sym: str     # 'T' for true
    mag_track: str          # Magnetic bearing to waypoint
    mag_sym: str            # 'M' for magnetic
    range_next: str         # Distance to waypoint
    range_unit: str         # Distance unit ('N' for nautical miles)
    waypoint_name: str      # Waypoint identifier

WPL - Waypoint Location

class WPL(TalkerSentence):
    """Waypoint Location."""
    
    lat: str                 # Waypoint latitude
    lat_dir: str            # 'N' or 'S'
    lon: str                # Waypoint longitude
    lon_dir: str            # 'E' or 'W'
    waypoint_id: str        # Waypoint identifier

Route Sentences

RTE - Routes

class RTE(TalkerSentence):
    """Routes."""
    
    num_in_seq: str         # Total number of sentences in sequence
    sen_num: str            # Sentence number
    start_type: str         # Message type ('c' = complete route, 'w' = working route)
    active_route_id: str    # Active route identifier
    
    @property
    def waypoint_list(self) -> List[str]:
        """List of waypoint identifiers in the route."""
    
    @waypoint_list.setter
    def waypoint_list(self, waypoints: List[str]):
        """Set the waypoint list."""

Usage Examples

import pynmea2

# Parse heading sentence
msg = pynmea2.parse("$HCHDG,98.3,0.6,E,12.6,W*57")
print(f"Magnetic heading: {msg.heading}°")       # 98.3°
print(f"Deviation: {msg.deviation}°{msg.dev_dir}")  # 0.6°E
print(f"Variation: {msg.variation}°{msg.var_dir}")  # 12.6°W

# Parse waypoint bearing sentence
msg = pynmea2.parse("$GPBWC,220516,5130.02,N,00046.34,W,213.8,T,218.0,M,0004.6,N,EGLM*11")
print(f"Next waypoint: {msg.waypoint_name}")     # EGLM
print(f"Distance: {msg.range_next} {msg.range_unit}")  # 0004.6 N
print(f"True bearing: {msg.true_track}°{msg.true_track_sym}")  # 213.8°T

# Parse route sentence
msg = pynmea2.parse("$GPRTE,2,1,c,0,PBRCPK,PBRTO,PTELGR,PPLAND,PYAMBU,PPFAIR,PWARRN,PMORTL,PLISMR*73")
print(f"Route sentence {msg.sen_num} of {msg.num_in_seq}")  # 1 of 2
print(f"Route type: {msg.start_type}")           # c (complete)
print(f"Waypoints: {msg.waypoint_list}")         # ['PBRCPK', 'PBRTO', ...]

Install with Tessl CLI

npx tessl i tessl/pypi-pynmea2

docs

core-parsing.md

depth-sonar.md

gps-positioning.md

index.md

navigation-course.md

proprietary-sentences.md

stream-processing.md

utilities.md

wind-weather.md

tile.json