Skip to content

Commit

Permalink
update prothandling Fixes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
semuadmin committed Mar 7, 2023
1 parent bca3243 commit 42e5429
Showing 1 changed file with 36 additions and 29 deletions.
65 changes: 36 additions & 29 deletions pygnssutils/gnssdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from serial import Serial
from pyubx2 import (
UBXReader,
UBXMessage,
VALCKSUM,
GET,
UBX_PROTOCOL,
Expand All @@ -30,10 +31,11 @@
ERR_LOG,
ERR_RAISE,
hextable,
protocol,
)
from pynmeagps import NMEAMessage
import pynmeagps.exceptions as nme
import pyubx2.exceptions as ube
from pyrtcm import RTCMMessage
import pyrtcm.exceptions as rte
from pygnssutils._version import __version__ as VERSION
from pygnssutils.exceptions import ParameterError
Expand Down Expand Up @@ -219,6 +221,7 @@ def run(self, **kwargs) -> int:
:rtype: int
:raises: ParameterError if socket is not in form host:port
"""
# pylint: disable=consider-using-with

if self._outfile is not None:
ftyp = "wb" if self._format == FORMAT_BINARY else "w"
Expand Down Expand Up @@ -319,15 +322,18 @@ def _do_parse(self):
raise EOFError

# get the message protocol (NMEA or UBX)
msgprot = protocol(raw_data)
handler = self._outputhandler
msgprot = 0
# establish the appropriate handler and identity for this protocol
if msgprot == UBX_PROTOCOL:
if isinstance(parsed_data, UBXMessage):
msgidentity = parsed_data.identity
elif msgprot == NMEA_PROTOCOL:
msgidentity = parsed_data.talker + parsed_data.msgID
elif msgprot == RTCM3_PROTOCOL:
msgprot = UBX_PROTOCOL
elif isinstance(parsed_data, NMEAMessage):
msgidentity = parsed_data.identity
msgprot = NMEA_PROTOCOL
elif isinstance(parsed_data, RTCMMessage):
msgidentity = parsed_data.identity
msgprot = RTCM3_PROTOCOL
# does it pass the protocol filter?
if self._protfilter & msgprot:
# does it pass the message identity filter if there is one?
Expand All @@ -343,7 +349,7 @@ def _do_parse(self):
except EOFError: # end of stream
if not self.ctx_mgr:
self.stop()
# self._do_log("End of file or limit reached", VERBOSITY_LOW)

except Exception as err: # pylint: disable=broad-except
self._quitonerror = ERR_RAISE # don't ignore irrecoverable errors
self._do_error(err)
Expand Down Expand Up @@ -534,16 +540,16 @@ def main():
"""
# pylint: disable=raise-missing-from

ap = ArgumentParser(
arp = ArgumentParser(
description="One of either -P port, -S socket or -F filename must be specified",
epilog=EPILOG,
formatter_class=ArgumentDefaultsHelpFormatter,
)
ap.add_argument("-V", "--version", action="version", version="%(prog)s " + VERSION)
ap.add_argument("-P", "--port", required=False, help="Serial port")
ap.add_argument("-F", "--filename", required=False, help="Input file path/name")
ap.add_argument("-S", "--socket", required=False, help="Input socket host:port")
ap.add_argument(
arp.add_argument("-V", "--version", action="version", version="%(prog)s " + VERSION)
arp.add_argument("-P", "--port", required=False, help="Serial port")
arp.add_argument("-F", "--filename", required=False, help="Input file path/name")
arp.add_argument("-S", "--socket", required=False, help="Input socket host:port")
arp.add_argument(
"-b",
"--baudrate",
required=False,
Expand All @@ -552,23 +558,23 @@ def main():
choices=[4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800],
default=9600,
)
ap.add_argument(
arp.add_argument(
"-t",
"--timeout",
required=False,
help="Serial timeout in seconds",
type=float,
default=3.0,
)
ap.add_argument(
arp.add_argument(
"-f",
"--format",
required=False,
help="Output format 1 = parsed, 2 = binary, 4 = hex, 8 = tabulated hex, 16 = parsed as string, 32 = JSON (can be OR'd)",
type=int,
default=1,
)
ap.add_argument(
arp.add_argument(
"-v",
"--validate",
required=False,
Expand All @@ -577,7 +583,7 @@ def main():
choices=[0, 1],
default=1,
)
ap.add_argument(
arp.add_argument(
"-m",
"--msgmode",
required=False,
Expand All @@ -586,15 +592,15 @@ def main():
choices=[0, 1, 2],
default=0,
)
ap.add_argument(
arp.add_argument(
"--parsebitfield",
required=False,
help="1 = parse UBX 'X' attributes as bitfields, 0 = leave as bytes",
type=int,
choices=[0, 1],
default=1,
)
ap.add_argument(
arp.add_argument(
"-q",
"--quitonerror",
required=False,
Expand All @@ -603,66 +609,67 @@ def main():
choices=[0, 1, 2],
default=1,
)
ap.add_argument(
arp.add_argument(
"--protfilter",
required=False,
help="1 = NMEA, 2 = UBX, 4 = RTCM3 (can be OR'd)",
type=int,
choices=[1, 2, 3, 4, 5, 6, 7],
default=7,
)
ap.add_argument(
arp.add_argument(
"--msgfilter",
required=False,
help="Comma-separated string of message identities e.g. 'NAV-PVT,GNGSA'",
default=None,
)
ap.add_argument(
arp.add_argument(
"--limit",
required=False,
help="Maximum number of messages to read (0 = unlimited)",
type=int,
default=0,
)
ap.add_argument(
arp.add_argument(
"--verbosity",
required=False,
help="Log message verbosity 0 = low, 1 = medium, 2 = high",
type=int,
choices=[0, 1, 2],
default=1,
)
ap.add_argument(
arp.add_argument(
"--outfile",
required=False,
help="Fully qualified path to output file",
default=None,
)
ap.add_argument(
arp.add_argument(
"--logtofile",
required=False,
help="0 = log to stdout, 1 = log to file '/logpath/gnssdump-timestamp.log'",
type=int,
choices=[0, 1],
default=0,
)
ap.add_argument(
arp.add_argument(
"--logpath",
required=False,
help="Fully qualified path to logfile folder",
default=".",
)
ap.add_argument(
arp.add_argument(
"--outputhandler",
required=False,
help="Either writeable output medium or evaluable expression",
)
ap.add_argument(
arp.add_argument(
"--errorhandler",
required=False,
help="Either writeable output medium or evaluable expression",
)

kwargs = vars(ap.parse_args())
kwargs = vars(arp.parse_args())

try:
with GNSSStreamer(**kwargs) as gns:
Expand Down

0 comments on commit 42e5429

Please sign in to comment.