Skip to content

Commit

Permalink
update CLI args
Browse files Browse the repository at this point in the history
  • Loading branch information
semuadmin committed May 1, 2024
1 parent 2e2b26f commit 1a524f6
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 13 deletions.
2 changes: 1 addition & 1 deletion examples/spartn_mqtt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def main(**kwargs):
spartndecode=decode,
spartnkey=key,
spartnbasedate=datetime.now(timezone.utc),
output=None,
output=out,
)

try:
Expand Down
8 changes: 7 additions & 1 deletion examples/spartn_ntrip_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ class from pygnssutils library. Can be used with the
:license: BSD 3-Clause
"""

from os import getenv
from os import path, getenv
from sys import argv
from time import sleep
from datetime import datetime, timezone

from pygnssutils import GNSSNTRIPClient

Expand All @@ -46,6 +47,8 @@ def main(**kwargs):

user = kwargs.get("user", getenv("PYGPSCLIENT_USER", "user"))
password = kwargs.get("password", getenv("PYGPSCLIENT_PASSWORD", "password"))
decode = int(kwargs.get("decode", 0))
key = kwargs.get("key", getenv("MQTTKEY", None))
mountpoint = kwargs.get("mountpoint", "EU")
outfile = kwargs.get("outfile", "spartnntrip.log")

Expand All @@ -64,6 +67,9 @@ def main(**kwargs):
ntripuser=user,
ntrippassword=password,
ggainterval=-1,
spartndecode=decode,
spartnkey=key,
spartnbasedate=datetime.now(timezone.utc),
output=out,
)

Expand Down
6 changes: 3 additions & 3 deletions src/pygnssutils/gnssmqttclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,21 +569,21 @@ def main():
default=path.join(Path.home(), f"device-{clientid}-pp-key.pem"),
)
ap.add_argument(
"--decode",
"--spartndecode",
required=False,
help="Decode payload?",
type=int,
choices=[0, 1],
default=0,
)
ap.add_argument(
"--decryptkey",
"--spartnkey",
required=False,
help="Decryption key for encrypted payloads",
default=getenv("MQTTKEY", default=None),
)
ap.add_argument(
"--decryptbasedate",
"--spartnbasedate",
required=False,
help="Decryption basedate for encrypted payloads",
default=datetime.now(timezone.utc),
Expand Down
51 changes: 43 additions & 8 deletions src/pygnssutils/gnssntripclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

# pylint: disable=invalid-name

import os
import socket
import ssl
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
from base64 import b64encode
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from io import BufferedWriter, TextIOWrapper
from os import getenv, path
from queue import Queue
from threading import Event, Thread
from time import sleep
Expand Down Expand Up @@ -107,6 +107,9 @@ def __init__(self, app=None, **kwargs):
"reflon": 0.0,
"refalt": 0.0,
"refsep": 0.0,
"spartndecode": 0,
"spartnkey": getenv("MQTTKEY", default=None),
"spartnbasedate": datetime.now(timezone.utc),
}

try:
Expand Down Expand Up @@ -198,6 +201,9 @@ def run(self, **kwargs) -> bool:
:param str reflon: (kwarg) reference longitude (0.0)
:param str refalt: (kwarg) reference altitude (0.0)
:param str refsep: (kwarg) reference separation (0.0)
:param bool spartndecode: (kwarg) decode SPARTN messages (0)
:param str spartnkey: (kwarg) SPARTN decryption key (None)
:param object datetime: (kwarg) SPARTN decryption basedate (now(utc))
:param object output: (kwarg) writeable output medium (serial, file, socket, queue) (None)
:returns: boolean flag 0 = terminated, 1 = Ok to stream RTCM3 data from server
:rtype: bool
Expand All @@ -220,17 +226,24 @@ def run(self, **kwargs) -> bool:
self._settings["datatype"] = kwargs.get("datatype", RTCM).upper()
self._settings["version"] = kwargs.get("version", "2.0")
self._settings["ntripuser"] = kwargs.get(
"ntripuser", os.getenv("PYGPSCLIENT_USER", "user")
"ntripuser", getenv("PYGPSCLIENT_USER", "user")
)
self._settings["ntrippassword"] = kwargs.get(
"ntrippassword", os.getenv("PYGPSCLIENT_PASSWORD", "password")
"ntrippassword", getenv("PYGPSCLIENT_PASSWORD", "password")
)
self._settings["ggainterval"] = int(kwargs.get("ggainterval", NOGGA))
self._settings["ggamode"] = int(kwargs.get("ggamode", GGALIVE))
self._settings["reflat"] = kwargs.get("reflat", 0.0)
self._settings["reflon"] = kwargs.get("reflon", 0.0)
self._settings["refalt"] = kwargs.get("refalt", 0.0)
self._settings["refsep"] = kwargs.get("refsep", 0.0)
self._settings["spartndecode"] = kwargs.get("spartndecode", 0)
self._settings["spartnkey"] = kwargs.get(
"spartnkey", getenv("MQTTKEY", None)
)
self._settings["spartnbasedate"] = kwargs.get(
"spartbasedate", datetime.now(timezone.utc)
)
output = kwargs.get("output", None)

if server == "":
Expand Down Expand Up @@ -596,7 +609,9 @@ def _do_data(
sock,
quitonerror=ERR_IGNORE,
bufsize=DEFAULT_BUFSIZE,
decode=False,
decode=self._settings["spartndecode"],
key=self._settings["spartnkey"],
basedate=self._settings["spartnbasedate"],
)
else:
parser = UBXReader(
Expand Down Expand Up @@ -710,7 +725,7 @@ def _cycle_log(self):

if not self._loglines % LOGLIMIT:
tim = datetime.now().strftime("%Y%m%d%H%M%S")
self._logfile = os.path.join(self._logpath, f"gnssntripclient-{tim}.log")
self._logfile = path.join(self._logpath, f"gnssntripclient-{tim}.log")
self._loglines = 0


Expand Down Expand Up @@ -789,13 +804,13 @@ def main():
"--ntripuser",
required=False,
help="NTRIP authentication user",
default=os.getenv("PYGPSCLIENT_USER", "anon"),
default=getenv("PYGPSCLIENT_USER", "anon"),
)
ap.add_argument(
"--ntrippassword",
required=False,
help="NTRIP authentication password",
default=os.getenv("PYGPSCLIENT_PASSWORD", "password"),
default=getenv("PYGPSCLIENT_PASSWORD", "password"),
)
ap.add_argument(
"--ggainterval",
Expand Down Expand Up @@ -824,6 +839,26 @@ def main():
ap.add_argument(
"--refsep", required=False, help="reference separation", type=float, default=0.0
)
ap.add_argument(
"--spartndecode",
required=False,
help="Decode SPARTN payload?",
type=int,
choices=[0, 1],
default=0,
)
ap.add_argument(
"--spartnkey",
required=False,
help="Decryption key for encrypted SPARTN payloads",
default=getenv("MQTTKEY", default=None),
)
ap.add_argument(
"--spartnbasedate",
required=False,
help="Decryption basedate for encrypted SPARTN payloads",
default=datetime.now(timezone.utc),
)
ap.add_argument(
"--verbosity",
required=False,
Expand Down

0 comments on commit 1a524f6

Please sign in to comment.