-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reorganize the nmea drivers by message type
- Loading branch information
Showing
8 changed files
with
136 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import logging | ||
from hyo2.soundspeed.formats.nmea_0183.nmea_0183_nav_abstract import Nmea0183NavAbstract | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Nmea0183GGA(Nmea0183NavAbstract): | ||
|
||
def __init__(self, data: str) -> None: | ||
super(Nmea0183GGA, self).__init__(data) | ||
|
||
def _parse(self) -> None: | ||
|
||
self._timestamp = self.msg[1] | ||
self._lat = self.msg[2] | ||
self._lat_dir = self.msg[3] | ||
self._lon = self.msg[4] | ||
self._lon_dir = self.msg[5] | ||
self._gps_qual = self.msg[6] | ||
self._num_sats = self.msg[7] | ||
self._horizontal_dil = self.msg[8] | ||
self._altitude = self.msg[9] | ||
self._altitude_units = self.msg[10] | ||
self._geo_sep = self.msg[11] | ||
self._geo_sep_units = self.msg[12] | ||
self._age_gps_data = self.msg[13] | ||
self._ref_station_id = self.msg[14] | ||
|
||
try: | ||
self._latitude = int(self._lat[:2]) + float(self._lat[2:]) / 60. | ||
if self._lat_dir == 'S': | ||
self._latitude = -1.0 * self.latitude | ||
# logger.debug("NMEA 0183 $$GGA lat: {}".format(self.latitude)) | ||
|
||
except Exception as e: | ||
logger.warning("unable to interpret latitude from %s and %s: %s" % (self._lat, self._lat_dir, e)) | ||
|
||
try: | ||
self._longitude = int(self._lon[:3]) + float(self._lon[3:]) / 60. | ||
if self._lon_dir == 'W': | ||
self._longitude = -1.0 * self.longitude | ||
# logger.debug("NMEA 0183 $$GGA lon: {}".format(self.longitude)) | ||
|
||
except Exception as e: | ||
logger.warning("unable to interpret longitude from %s and %s: %s" % (self._lon, self._lon_dir, e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import logging | ||
from typing import Optional | ||
from hyo2.soundspeed.formats.nmea_0183.nmea_0183_nav_abstract import Nmea0183NavAbstract | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Nmea0183GLL(Nmea0183NavAbstract): | ||
|
||
def __init__(self, data: str) -> None: | ||
super(Nmea0183GLL, self).__init__(data) | ||
|
||
self._lat = Optional[str] | ||
self._lat_dir = Optional[str] | ||
self._lon = Optional[str] | ||
self._lon_dir = Optional[str] | ||
self._timestamp = Optional[str] | ||
self._status = Optional[str] | ||
|
||
def _parse(self) -> None: | ||
|
||
self._lat = self.msg[1] | ||
self._lat_dir = self.msg[2] | ||
self._lon = self.msg[3] | ||
self._lon_dir = self.msg[4] | ||
self._timestamp = self.msg[5] | ||
self._status = self.msg[6] | ||
|
||
try: | ||
self._latitude = int(self._lat[:2]) + float(self._lat[2:]) / 60. | ||
if self._lat_dir == 'S': | ||
self._latitude = -1.0 * self.latitude | ||
# logger.debug("NMEA 0183 $$GLL lat: {}".format(self.latitude)) | ||
|
||
except Exception as e: | ||
logger.warning("unable to interpret latitude from %s and %s: %s" % (self._lat, self._lat_dir, e)) | ||
|
||
try: | ||
self._longitude = int(self._lon[:3]) + float(self._lon[3:]) / 60. | ||
if self._lon_dir == 'W': | ||
self._longitude = -1.0 * self.longitude | ||
# logger.debug("NMEA 0183 $$GLL lon: {}".format(self.longitude)) | ||
|
||
except Exception as e: | ||
logger.warning("unable to interpret longitude from %s and %s: %s" % (self._lon, self._lon_dir, e)) |
34 changes: 34 additions & 0 deletions
34
hyo2/soundspeed/formats/nmea_0183/nmea_0183_nav_abstract.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import logging | ||
from abc import ABCMeta, abstractmethod | ||
from typing import Optional | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Nmea0183NavAbstract(metaclass=ABCMeta): | ||
|
||
def __init__(self, data: str) -> None: | ||
self.data = data | ||
self.msg = None # type: Optional[list[str]] | ||
|
||
self._latitude = None # type: Optional[float] | ||
self._longitude = None # type: Optional[float] | ||
|
||
self.msg = self.data.split(',') | ||
|
||
self._parse() | ||
|
||
@abstractmethod | ||
def _parse(self) -> None: | ||
pass | ||
|
||
@property | ||
def latitude(self) -> Optional[float]: | ||
return self._latitude | ||
|
||
@property | ||
def longitude(self) -> Optional[float]: | ||
return self._longitude | ||
|
||
def __str__(self) -> str: | ||
return "Latitude: %s, longitude: %s" % (self._latitude, self._longitude) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters