pygnssutils 1.2.9__tar.gz → 1.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pygnssutils-1.2.9/src/pygnssutils.egg-info → pygnssutils-1.3.1}/PKG-INFO +11 -11
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/README.md +3 -3
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/pyproject.toml +9 -9
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/__init__.py +3 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/_version.py +1 -1
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/globals.py +1 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/gnssntripclient.py +113 -59
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/gnssreader.py +140 -21
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/gnssstreamer.py +29 -5
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/gnssstreamer_cli.py +32 -2
- {pygnssutils-1.2.9 → pygnssutils-1.3.1/src/pygnssutils.egg-info}/PKG-INFO +11 -11
- pygnssutils-1.3.1/src/pygnssutils.egg-info/requires.txt +10 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/tests/test_gnssstreamer.py +10 -3
- pygnssutils-1.2.9/src/pygnssutils.egg-info/requires.txt +0 -10
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/LICENSE +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/setup.cfg +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/exceptions.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/gnssntripclient_cli.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/gnssserver.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/gnssserver_cli.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/helpers.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/rawnav.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/rawnav_reader.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/rawnav_subframes_bds.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/rawnav_subframes_gal.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/rawnav_subframes_glo.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/rawnav_subframes_gps.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/rawnav_subframes_irn.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/rawnav_subframes_qzs.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/rawnav_subframes_sba.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/rinex_conv.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/rinex_conv_cli.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/rinex_conv_met.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/rinex_conv_nav.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/rinex_conv_obs.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/rinex_globals.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/rinex_helpers.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils/socket_server.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils.egg-info/SOURCES.txt +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils.egg-info/dependency_links.txt +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils.egg-info/entry_points.txt +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/src/pygnssutils.egg-info/top_level.txt +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/tests/test_cli.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/tests/test_rawnav.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/tests/test_rinex.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/tests/test_rinex_defs.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/tests/test_rinex_parse.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/tests/test_socketwrapper.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/tests/test_sourcetable.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/tests/test_static.py +0 -0
- {pygnssutils-1.2.9 → pygnssutils-1.3.1}/tests/test_stream.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pygnssutils
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.1
|
|
4
4
|
Summary: GNSS Command Line Utilities
|
|
5
5
|
Author: Steve Smith
|
|
6
6
|
Author-email: semuadmin@semuconsulting.com
|
|
@@ -34,15 +34,15 @@ Requires-Python: >=3.10
|
|
|
34
34
|
Description-Content-Type: text/markdown
|
|
35
35
|
License-File: LICENSE
|
|
36
36
|
Requires-Dist: certifi>=2026.0.0
|
|
37
|
-
Requires-Dist: pynmeagps>=1.1.
|
|
38
|
-
Requires-Dist: pyqgc>=1.0.
|
|
39
|
-
Requires-Dist: pyrtcm>=1.2.
|
|
40
|
-
Requires-Dist: pysbf2>=1.0.
|
|
37
|
+
Requires-Dist: pynmeagps>=1.1.8
|
|
38
|
+
Requires-Dist: pyqgc>=1.0.1
|
|
39
|
+
Requires-Dist: pyrtcm>=1.2.1
|
|
40
|
+
Requires-Dist: pysbf2>=1.0.7
|
|
41
41
|
Requires-Dist: pyserial>=3.5
|
|
42
|
-
Requires-Dist: pyspartn>=1.0
|
|
43
|
-
Requires-Dist: pyubx2>=1.
|
|
42
|
+
Requires-Dist: pyspartn>=1.1.0
|
|
43
|
+
Requires-Dist: pyubx2>=1.4.0
|
|
44
44
|
Requires-Dist: pyubxutils>=1.0.6
|
|
45
|
-
Requires-Dist: pyunigps>=1.0.
|
|
45
|
+
Requires-Dist: pyunigps>=1.0.1
|
|
46
46
|
Dynamic: license-file
|
|
47
47
|
|
|
48
48
|
pygnssutils
|
|
@@ -73,8 +73,8 @@ pygnssutils is an original series of Python GNSS utility classes and CLI tools b
|
|
|
73
73
|
|
|
74
74
|
Originally developed in support of the [PyGPSClient](https://github.com/semuconsulting/PyGPSClient) GUI GNSS application, the utilities provided by pygnssutils can also be used in their own right:
|
|
75
75
|
|
|
76
|
-
1. `GNSSReader` class. This is essentially an amalgamation of the `*Reader` classes in all the subsidiary parsers listed above, allowing the user to seamlessly stream any of NMEA, UBX, SBF, UNI, QGC and
|
|
77
|
-
1. `GNSSStreamer` class and its associated [`gnssstreamer`](#gnssstreamer) (*formerly `gnssdump`*) CLI utility. This is essentially a configurable bidirectional input/output wrapper around the `GNSSReader` class with flexible message formatting, filtering and output handling options for NMEA, UBX, SBF, UNI, QGC and
|
|
76
|
+
1. `GNSSReader` class. This is essentially an amalgamation of the `*Reader` classes in all the subsidiary parsers listed above, allowing the user to seamlessly stream any of NMEA, UBX, SBF, UNI, QGC, RTCM3 and SPARTN message protocols concurrently from a single stream.
|
|
77
|
+
1. `GNSSStreamer` class and its associated [`gnssstreamer`](#gnssstreamer) (*formerly `gnssdump`*) CLI utility. This is essentially a configurable bidirectional input/output wrapper around the `GNSSReader` class with flexible message formatting, filtering and output handling options for NMEA, UBX, SBF, UNI, QGC, RTCM3 and SPARTN protocols.
|
|
78
78
|
1. `GNSSSocketServer` class and its associated [`gnssserver`](#gnssserver) CLI utility. This implements a TCP Socket Server for GNSS data streams which is also capable of being run as a simple NTRIP Server/Caster.
|
|
79
79
|
1. `GNSSNTRIPClient` class and its associated [`gnssntripclient`](#gnssntripclient) CLI utility. This implements
|
|
80
80
|
a simple NTRIP Client which receives RTCM3 or SPARTN correction data from an NTRIP Server and (optionally) sends this to a
|
|
@@ -154,7 +154,7 @@ Refer to the [Sphinx API documentation](https://www.semuconsulting.com/pygnssuti
|
|
|
154
154
|
class pygnssutils.gnssstreamer.GNSSStreamer(**kwargs)
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
-
`gnssstreamer` (*formerly `gnssdump`*) is a command line utility for concurrent bidirectional communication with a GNSS datastream - typically a GNSS receiver. It supports NMEA, UBX, SBF, UNI, QGC, RTCM3, SPARTN
|
|
157
|
+
`gnssstreamer` (*formerly `gnssdump`*) is a command line utility for concurrent bidirectional communication with a GNSS datastream - typically a GNSS receiver. It supports NMEA, UBX, SBF, UNI, QGC, RTCM3, SPARTN and NTRIP protocols - individual protocols can be filtered via the `protfilter` arguments.
|
|
158
158
|
|
|
159
159
|
- The CLI utility can acquire data from any one of the following sources:
|
|
160
160
|
- `port`: serial port e.g. `COM3` or `/dev/ttyACM1` (can specify `--baudrate` and `--timeout`)
|
|
@@ -26,8 +26,8 @@ pygnssutils is an original series of Python GNSS utility classes and CLI tools b
|
|
|
26
26
|
|
|
27
27
|
Originally developed in support of the [PyGPSClient](https://github.com/semuconsulting/PyGPSClient) GUI GNSS application, the utilities provided by pygnssutils can also be used in their own right:
|
|
28
28
|
|
|
29
|
-
1. `GNSSReader` class. This is essentially an amalgamation of the `*Reader` classes in all the subsidiary parsers listed above, allowing the user to seamlessly stream any of NMEA, UBX, SBF, UNI, QGC and
|
|
30
|
-
1. `GNSSStreamer` class and its associated [`gnssstreamer`](#gnssstreamer) (*formerly `gnssdump`*) CLI utility. This is essentially a configurable bidirectional input/output wrapper around the `GNSSReader` class with flexible message formatting, filtering and output handling options for NMEA, UBX, SBF, UNI, QGC and
|
|
29
|
+
1. `GNSSReader` class. This is essentially an amalgamation of the `*Reader` classes in all the subsidiary parsers listed above, allowing the user to seamlessly stream any of NMEA, UBX, SBF, UNI, QGC, RTCM3 and SPARTN message protocols concurrently from a single stream.
|
|
30
|
+
1. `GNSSStreamer` class and its associated [`gnssstreamer`](#gnssstreamer) (*formerly `gnssdump`*) CLI utility. This is essentially a configurable bidirectional input/output wrapper around the `GNSSReader` class with flexible message formatting, filtering and output handling options for NMEA, UBX, SBF, UNI, QGC, RTCM3 and SPARTN protocols.
|
|
31
31
|
1. `GNSSSocketServer` class and its associated [`gnssserver`](#gnssserver) CLI utility. This implements a TCP Socket Server for GNSS data streams which is also capable of being run as a simple NTRIP Server/Caster.
|
|
32
32
|
1. `GNSSNTRIPClient` class and its associated [`gnssntripclient`](#gnssntripclient) CLI utility. This implements
|
|
33
33
|
a simple NTRIP Client which receives RTCM3 or SPARTN correction data from an NTRIP Server and (optionally) sends this to a
|
|
@@ -107,7 +107,7 @@ Refer to the [Sphinx API documentation](https://www.semuconsulting.com/pygnssuti
|
|
|
107
107
|
class pygnssutils.gnssstreamer.GNSSStreamer(**kwargs)
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
-
`gnssstreamer` (*formerly `gnssdump`*) is a command line utility for concurrent bidirectional communication with a GNSS datastream - typically a GNSS receiver. It supports NMEA, UBX, SBF, UNI, QGC, RTCM3, SPARTN
|
|
110
|
+
`gnssstreamer` (*formerly `gnssdump`*) is a command line utility for concurrent bidirectional communication with a GNSS datastream - typically a GNSS receiver. It supports NMEA, UBX, SBF, UNI, QGC, RTCM3, SPARTN and NTRIP protocols - individual protocols can be filtered via the `protfilter` arguments.
|
|
111
111
|
|
|
112
112
|
- The CLI utility can acquire data from any one of the following sources:
|
|
113
113
|
- `port`: serial port e.g. `COM3` or `/dev/ttyACM1` (can specify `--baudrate` and `--timeout`)
|
|
@@ -39,15 +39,15 @@ classifiers = [
|
|
|
39
39
|
|
|
40
40
|
dependencies = [
|
|
41
41
|
"certifi>=2026.0.0",
|
|
42
|
-
"pynmeagps>=1.1.
|
|
43
|
-
"pyqgc>=1.0.
|
|
44
|
-
"pyrtcm>=1.2.
|
|
45
|
-
"pysbf2>=1.0.
|
|
42
|
+
"pynmeagps>=1.1.8",
|
|
43
|
+
"pyqgc>=1.0.1",
|
|
44
|
+
"pyrtcm>=1.2.1",
|
|
45
|
+
"pysbf2>=1.0.7",
|
|
46
46
|
"pyserial>=3.5",
|
|
47
|
-
"pyspartn>=1.0
|
|
48
|
-
"pyubx2>=1.
|
|
47
|
+
"pyspartn>=1.1.0",
|
|
48
|
+
"pyubx2>=1.4.0",
|
|
49
49
|
"pyubxutils>=1.0.6",
|
|
50
|
-
"pyunigps>=1.0.
|
|
50
|
+
"pyunigps>=1.0.1",
|
|
51
51
|
]
|
|
52
52
|
|
|
53
53
|
[project.scripts]
|
|
@@ -66,7 +66,7 @@ changelog = "https://github.com/semuconsulting/pygnssutils/blob/master/RELEASE_N
|
|
|
66
66
|
build = [
|
|
67
67
|
"build",
|
|
68
68
|
"packaging>=24.2",
|
|
69
|
-
"pip",
|
|
69
|
+
"pip>=25.1",
|
|
70
70
|
"setuptools>=75.0.0",
|
|
71
71
|
"twine>=6.1.0",
|
|
72
72
|
"wheel",
|
|
@@ -83,7 +83,7 @@ test = [
|
|
|
83
83
|
"Sphinx",
|
|
84
84
|
"sphinx-rtd-theme",
|
|
85
85
|
]
|
|
86
|
-
optional = []
|
|
86
|
+
optional = ["cryptography>=45.0.0"]
|
|
87
87
|
deploy = [{ include-group = "build" }, { include-group = "test" }]
|
|
88
88
|
|
|
89
89
|
[tool.setuptools.dynamic]
|
|
@@ -7,6 +7,8 @@ Created on 27 Sep 2020
|
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
9
|
from pynmeagps import SocketWrapper
|
|
10
|
+
from pyspartn import date2timetag, naive2aware
|
|
11
|
+
from pyubx2 import ERR_IGNORE, ERR_LOG, ERR_RAISE
|
|
10
12
|
from pyubxutils.ubxsimulator import UBXSimulator
|
|
11
13
|
|
|
12
14
|
from pygnssutils._version import __version__
|
|
@@ -18,6 +20,7 @@ from pygnssutils.gnssreader import (
|
|
|
18
20
|
QGC_PROTOCOL,
|
|
19
21
|
RTCM3_PROTOCOL,
|
|
20
22
|
SBF_PROTOCOL,
|
|
23
|
+
SPARTN_PROTOCOL,
|
|
21
24
|
UBX_PROTOCOL,
|
|
22
25
|
UNI_PROTOCOL,
|
|
23
26
|
GNSSReader,
|
|
@@ -221,6 +221,7 @@ TOPIC_FREQ = "/pp/frequencies/Lb"
|
|
|
221
221
|
NTRIP_EVENT = "<<ntrip_read>>"
|
|
222
222
|
SPARTN_EVENT = "<<spartn_read>>"
|
|
223
223
|
SPARTN_PPSERVER = "pp.services.u-blox.com"
|
|
224
|
+
SPARTN_DEFAULTKEY = "abcd1234abcd1234abcd1234abcd1234"
|
|
224
225
|
OUTPORT_SPARTN = 8883
|
|
225
226
|
PMP_DATARATES = {
|
|
226
227
|
"B600": 600,
|
|
@@ -39,16 +39,15 @@ from socket import (
|
|
|
39
39
|
gaierror,
|
|
40
40
|
gethostbyname,
|
|
41
41
|
socket,
|
|
42
|
-
timeout,
|
|
43
42
|
)
|
|
43
|
+
from socket import timeout as socktimeout
|
|
44
44
|
from ssl import PROTOCOL_TLS_CLIENT, SSLCertVerificationError, SSLContext, SSLError
|
|
45
45
|
from threading import Event, Thread
|
|
46
46
|
from types import NoneType
|
|
47
|
-
from typing import Any
|
|
47
|
+
from typing import Any, Literal
|
|
48
48
|
|
|
49
49
|
from certifi import where as findcacerts
|
|
50
50
|
from pynmeagps import GET, NMEAMessage, SocketWrapper
|
|
51
|
-
from pyspartn import SPARTNReader
|
|
52
51
|
from serial import Serial
|
|
53
52
|
|
|
54
53
|
from pygnssutils._version import __version__ as VERSION
|
|
@@ -75,9 +74,10 @@ from pygnssutils.globals import (
|
|
|
75
74
|
OUTPORT_NTRIP,
|
|
76
75
|
PYGNSSUTILS_CRT,
|
|
77
76
|
PYGNSSUTILS_CRTPATH,
|
|
77
|
+
SPARTN_DEFAULTKEY,
|
|
78
78
|
VERBOSITY_MEDIUM,
|
|
79
79
|
)
|
|
80
|
-
from pygnssutils.gnssreader import ERR_LOG, RTCM3_PROTOCOL, GNSSReader
|
|
80
|
+
from pygnssutils.gnssreader import ERR_LOG, RTCM3_PROTOCOL, SPARTN_PROTOCOL, GNSSReader
|
|
81
81
|
from pygnssutils.helpers import find_mp_distance, ipprot2int, set_logging
|
|
82
82
|
|
|
83
83
|
TIMEOUT = 3
|
|
@@ -100,25 +100,30 @@ class GNSSNTRIPClient:
|
|
|
100
100
|
def __init__(
|
|
101
101
|
self,
|
|
102
102
|
app: Any | NoneType = None,
|
|
103
|
-
|
|
103
|
+
retries: int = MAX_RETRY,
|
|
104
|
+
retryinterval: int = RETRY_INTERVAL,
|
|
105
|
+
timeout: int = INACTIVITY_TIMEOUT,
|
|
106
|
+
tlscrtpath: str = getenv(PYGNSSUTILS_CRTPATH, PYGNSSUTILS_CRT),
|
|
107
|
+
verbosity: int = VERBOSITY_MEDIUM,
|
|
108
|
+
logtofile: str = "",
|
|
104
109
|
):
|
|
105
110
|
"""
|
|
106
111
|
Constructor.
|
|
107
112
|
|
|
108
113
|
:param Any | NoneType app: application from which this class is invoked (None)
|
|
109
|
-
:param int retries:
|
|
110
|
-
:param int retryinterval:
|
|
111
|
-
:param int timeout:
|
|
112
|
-
:param str tlscrtpath:
|
|
114
|
+
:param int retries: maximum failed connection retries (5)
|
|
115
|
+
:param int retryinterval: retry interval in seconds (10)
|
|
116
|
+
:param int timeout: inactivity timeout in seconds (10)
|
|
117
|
+
:param str tlscrtpath: Path to self-sign TLS certificate ("pygnssutils.crt")
|
|
118
|
+
:param int verbosity: verbosity (1)
|
|
119
|
+
:param str logtofile: fully qualified path to logfile, or "" for none ("")
|
|
113
120
|
"""
|
|
114
121
|
|
|
115
122
|
self.__app = app # Reference to calling application class (if applicable)
|
|
116
123
|
# configure logger with name "pygnssutils" in calling module
|
|
117
|
-
self.verbosity =
|
|
118
|
-
self.logtofile =
|
|
119
|
-
self._tlscrtpath =
|
|
120
|
-
"tlscrtpath", getenv(PYGNSSUTILS_CRTPATH, PYGNSSUTILS_CRT)
|
|
121
|
-
)
|
|
124
|
+
self.verbosity = verbosity
|
|
125
|
+
self.logtofile = logtofile
|
|
126
|
+
self._tlscrtpath = tlscrtpath
|
|
122
127
|
self.logger = getLogger(__name__)
|
|
123
128
|
for module in ("pyrtcm", "pyspartn"):
|
|
124
129
|
set_logging(getLogger(module), self.verbosity, self.logtofile)
|
|
@@ -128,9 +133,9 @@ class GNSSNTRIPClient:
|
|
|
128
133
|
self.settings = self._settings
|
|
129
134
|
|
|
130
135
|
try:
|
|
131
|
-
self._retries =
|
|
132
|
-
self._retryinterval =
|
|
133
|
-
self._timeout =
|
|
136
|
+
self._retries = retries
|
|
137
|
+
self._retryinterval = retryinterval
|
|
138
|
+
self._timeout = timeout
|
|
134
139
|
except (ParameterError, ValueError, TypeError) as err:
|
|
135
140
|
msg = f"Invalid input arguments {err}"
|
|
136
141
|
self._app_update_status(False, (str(err), ERRCOL))
|
|
@@ -163,7 +168,32 @@ class GNSSNTRIPClient:
|
|
|
163
168
|
|
|
164
169
|
self.stop()
|
|
165
170
|
|
|
166
|
-
def run(
|
|
171
|
+
def run(
|
|
172
|
+
self,
|
|
173
|
+
server: str = "",
|
|
174
|
+
port: int = 2101,
|
|
175
|
+
https: bool = False,
|
|
176
|
+
selfsign: bool = False,
|
|
177
|
+
mountpoint: str = "",
|
|
178
|
+
datatype: Literal["RTCM", "SPARTN"] = "RTCM",
|
|
179
|
+
version: Literal["1.0", "2.0"] = "2.0",
|
|
180
|
+
ntripuser: str = "anon",
|
|
181
|
+
ntrippassword: str = "password",
|
|
182
|
+
ggainterval: int = -1, # -1 = None
|
|
183
|
+
ggamode: Literal[0, 1] = 0,
|
|
184
|
+
reflat: float = 0.0,
|
|
185
|
+
reflon: float = 0.0,
|
|
186
|
+
refalt: float = 0.0,
|
|
187
|
+
refsep: float = 0.0,
|
|
188
|
+
spartndecode: bool = False,
|
|
189
|
+
spartnkey: str = SPARTN_DEFAULTKEY,
|
|
190
|
+
spartnbasedate: int | datetime = 0,
|
|
191
|
+
ipprot: str = "IPv4",
|
|
192
|
+
flowinfo: int = 0, # IPv6, redundant
|
|
193
|
+
scopeid: int = 0, # IPv6, redundant
|
|
194
|
+
output: Any | NoneType = None,
|
|
195
|
+
stopevent: Event = Event(),
|
|
196
|
+
) -> bool:
|
|
167
197
|
"""
|
|
168
198
|
Open NTRIP client connection.
|
|
169
199
|
|
|
@@ -174,27 +204,27 @@ class GNSSNTRIPClient:
|
|
|
174
204
|
User login credentials can be obtained from environment variables
|
|
175
205
|
PYGPSCLIENT_USER and PYGPSCLIENT_PASSWORD, or passed as kwargs.
|
|
176
206
|
|
|
177
|
-
:param str server:
|
|
178
|
-
:param int port:
|
|
179
|
-
:param bool https:
|
|
180
|
-
:param bool selfsign:
|
|
181
|
-
:param str mountpoint:
|
|
182
|
-
:param Literal["RTCM","SPARTN"] datatype:
|
|
183
|
-
:param Literal["1.0","2.0"] version:
|
|
184
|
-
:param str ntripuser:
|
|
185
|
-
:param str ntrippassword:
|
|
186
|
-
:param int ggainterval:
|
|
187
|
-
:param Literal[0,1] ggamode:
|
|
207
|
+
:param str server: NTRIP server URL ("")
|
|
208
|
+
:param int port: NTRIP port (2101)
|
|
209
|
+
:param bool https: Enable HTTPS (TLS) connection? (0)
|
|
210
|
+
:param bool selfsign: Allow self-sign TLS certificate (0)
|
|
211
|
+
:param str mountpoint: NTRIP mountpoint ("", leave blank to get sourcetable)
|
|
212
|
+
:param Literal["RTCM","SPARTN"] datatype: Data type - RTCM or SPARTN ("RTCM")
|
|
213
|
+
:param Literal["1.0","2.0"] version: NTRIP protocol version ("2.0")
|
|
214
|
+
:param str ntripuser: NTRIP authentication user ("anon")
|
|
215
|
+
:param str ntrippassword: NTRIP authentication password ("password")
|
|
216
|
+
:param int ggainterval: GGA sentence transmission interval (-1 = None)
|
|
217
|
+
:param Literal[0,1] ggamode: GGA pos source; 0 = live from receiver, \
|
|
188
218
|
1 = fixed reference (0)
|
|
189
|
-
:param str reflat:
|
|
190
|
-
:param str reflon:
|
|
191
|
-
:param str refalt:
|
|
192
|
-
:param str refsep:
|
|
193
|
-
:param bool spartndecode:
|
|
194
|
-
:param str
|
|
195
|
-
:param str | datetime
|
|
196
|
-
:param Any output:
|
|
197
|
-
:param Event stopevent:
|
|
219
|
+
:param str reflat: reference latitude (0.0)
|
|
220
|
+
:param str reflon: reference longitude (0.0)
|
|
221
|
+
:param str refalt: reference altitude (0.0)
|
|
222
|
+
:param str refsep: reference separation (0.0)
|
|
223
|
+
:param bool spartndecode: decode SPARTN messages (0)
|
|
224
|
+
:param str spartnkey: SPARTN decryption key
|
|
225
|
+
:param str | datetime spartnbasedate: SPARTN decryption basedate (now(utc))
|
|
226
|
+
:param Any output: writeable output medium (serial, file, socket, queue) (None)
|
|
227
|
+
:param Event stopevent: stopevent to terminate `run()` (internal `Event()`)
|
|
198
228
|
:returns: boolean flag 0 = stream terminated, 1 = streaming data
|
|
199
229
|
:rtype: bool
|
|
200
230
|
"""
|
|
@@ -202,10 +232,34 @@ class GNSSNTRIPClient:
|
|
|
202
232
|
# pylint: disable=unused-variable
|
|
203
233
|
|
|
204
234
|
try:
|
|
205
|
-
self._stopevent =
|
|
235
|
+
self._stopevent = stopevent
|
|
206
236
|
self._last_gga = datetime.fromordinal(1)
|
|
207
|
-
self.settings =
|
|
208
|
-
|
|
237
|
+
self.settings = {
|
|
238
|
+
"server": server,
|
|
239
|
+
"port": port,
|
|
240
|
+
"https": https,
|
|
241
|
+
"selfsign": selfsign,
|
|
242
|
+
"mountpoint": mountpoint,
|
|
243
|
+
"datatype": datatype,
|
|
244
|
+
"version": version,
|
|
245
|
+
"ntripuser": ntripuser,
|
|
246
|
+
"ntrippassword": ntrippassword,
|
|
247
|
+
"ggainterval": ggainterval,
|
|
248
|
+
"ggamode": ggamode,
|
|
249
|
+
"reflat": reflat,
|
|
250
|
+
"reflon": reflon,
|
|
251
|
+
"refalt": refalt,
|
|
252
|
+
"refsep": refsep,
|
|
253
|
+
"spartndecode": spartndecode,
|
|
254
|
+
"spartnkey": spartnkey,
|
|
255
|
+
"spartnbasedate": spartnbasedate,
|
|
256
|
+
"output": output,
|
|
257
|
+
"stopevent": stopevent,
|
|
258
|
+
"ipprot": ipprot,
|
|
259
|
+
"flowinfo": flowinfo, # redundant
|
|
260
|
+
"scopeid": scopeid, # redundant
|
|
261
|
+
}
|
|
262
|
+
self._output = output
|
|
209
263
|
if self._settings["server"] == "":
|
|
210
264
|
raise ParameterError(f"Invalid server URL {self._settings['server']}")
|
|
211
265
|
if not 1 < self._settings["port"] < MAXPORT:
|
|
@@ -280,7 +334,7 @@ class GNSSNTRIPClient:
|
|
|
280
334
|
ConnectionResetError,
|
|
281
335
|
OverflowError,
|
|
282
336
|
gaierror,
|
|
283
|
-
|
|
337
|
+
socktimeout, # subclass of OSError in Python<=3.9
|
|
284
338
|
TimeoutError,
|
|
285
339
|
) as err:
|
|
286
340
|
errm = str(repr(err))
|
|
@@ -540,24 +594,19 @@ class GNSSNTRIPClient:
|
|
|
540
594
|
|
|
541
595
|
# parser will wrap socket as SocketStream
|
|
542
596
|
if settings["datatype"].lower() == SPARTN:
|
|
543
|
-
|
|
544
|
-
stream,
|
|
545
|
-
quitonerror=ERR_LOG,
|
|
546
|
-
bufsize=DEFAULT_BUFSIZE,
|
|
547
|
-
decode=settings.get("spartndecode", False),
|
|
548
|
-
key=settings.get("spartnkey", "ABCD1234"),
|
|
549
|
-
basedate=settings.get("spartnbasedate", 0),
|
|
550
|
-
errorhandler=self._error_handler,
|
|
551
|
-
)
|
|
597
|
+
protocol = SPARTN_PROTOCOL
|
|
552
598
|
else:
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
599
|
+
protocol = RTCM3_PROTOCOL
|
|
600
|
+
parser = GNSSReader(
|
|
601
|
+
stream,
|
|
602
|
+
protfilter=protocol,
|
|
603
|
+
quitonerror=ERR_LOG,
|
|
604
|
+
bufsize=DEFAULT_BUFSIZE,
|
|
605
|
+
labelmsm=1,
|
|
606
|
+
errorhandler=self._error_handler,
|
|
607
|
+
spartnkey=settings.get("spartnkey", "ABCD1234"),
|
|
608
|
+
spartnbasedate=settings.get("spartnbasedate", 0),
|
|
609
|
+
)
|
|
561
610
|
|
|
562
611
|
while not stopevent.is_set():
|
|
563
612
|
raw_data, parsed_data = parser.read()
|
|
@@ -700,14 +749,19 @@ class GNSSNTRIPClient:
|
|
|
700
749
|
:param Any | NoneType parsed: parsed message
|
|
701
750
|
"""
|
|
702
751
|
|
|
752
|
+
if hasattr(parsed, "identity"):
|
|
753
|
+
self.logger.debug(f"Message received: {type(parsed)} {parsed.identity}")
|
|
754
|
+
|
|
703
755
|
if output is not None:
|
|
704
756
|
# serialize sourcetable if outputting to stream
|
|
705
757
|
if isinstance(raw, list) and not isinstance(output, Queue):
|
|
706
758
|
raw = self._serialize_sourcetable(raw)
|
|
707
759
|
if isinstance(output, (Serial, BufferedWriter)) and raw is not None:
|
|
708
760
|
output.write(raw)
|
|
761
|
+
output.flush()
|
|
709
762
|
elif isinstance(output, TextIOWrapper) and parsed is not None:
|
|
710
763
|
output.write(str(parsed))
|
|
764
|
+
output.flush()
|
|
711
765
|
elif isinstance(output, Queue) and raw is not None:
|
|
712
766
|
output.put(raw if self.__app == CLIAPP else (raw, parsed))
|
|
713
767
|
elif isinstance(output, socket) and raw is not None:
|
|
@@ -3,11 +3,11 @@ gnssreader.py
|
|
|
3
3
|
|
|
4
4
|
Generic GNSS reader / parser class.
|
|
5
5
|
|
|
6
|
-
Reads and parses individual UBX, SBF, QGC, UNI, NMEA or
|
|
7
|
-
GNSS data stream which supports a read(n) -> bytes method.
|
|
6
|
+
Reads and parses individual UBX, SBF, QGC, UNI, NMEA, RTCM3 or SPARTN messages from
|
|
7
|
+
any viable GNSS data stream which supports a read(n) -> bytes method.
|
|
8
8
|
|
|
9
9
|
It is essentially an amalgamation of the Reader classes in the separate pyubx2, pynmeagps,
|
|
10
|
-
pyrtcm, pysbf2, pyqgc
|
|
10
|
+
pyrtcm, pysbf2, pyqgc, pyunigps & pyspartn packages.
|
|
11
11
|
|
|
12
12
|
Returns both the raw binary data (as bytes) and the parsed data.
|
|
13
13
|
|
|
@@ -17,6 +17,7 @@ Returns both the raw binary data (as bytes) and the parsed data.
|
|
|
17
17
|
- 'quitonerror' governs how errors are handled.
|
|
18
18
|
- 'msgmode' indicates the type of UBX datastream (output GET, input SET, query POLL).
|
|
19
19
|
If msgmode is set to SETPOLL, input/query mode will be automatically detected by parser.
|
|
20
|
+
- spartnkey and spartnbasedate are required to decrypt encrypted SPARTN datastreams.
|
|
20
21
|
|
|
21
22
|
Created on 6 Oct 2025
|
|
22
23
|
|
|
@@ -27,10 +28,11 @@ Created on 6 Oct 2025
|
|
|
27
28
|
|
|
28
29
|
# pylint: disable=too-many-positional-arguments
|
|
29
30
|
|
|
31
|
+
from datetime import datetime
|
|
30
32
|
from logging import getLogger
|
|
31
33
|
from socket import socket
|
|
32
|
-
from types import
|
|
33
|
-
from typing import Any, Literal
|
|
34
|
+
from types import NoneType
|
|
35
|
+
from typing import Any, Callable, Literal
|
|
34
36
|
|
|
35
37
|
from pynmeagps import (
|
|
36
38
|
NMEA_HDR,
|
|
@@ -68,6 +70,20 @@ from pysbf2 import (
|
|
|
68
70
|
SBFStreamError,
|
|
69
71
|
SBFTypeError,
|
|
70
72
|
)
|
|
73
|
+
from pyspartn import (
|
|
74
|
+
ALN_ENUM,
|
|
75
|
+
SPARTN_PREB,
|
|
76
|
+
VALCRC,
|
|
77
|
+
SPARTNDecryptionError,
|
|
78
|
+
SPARTNMessage,
|
|
79
|
+
SPARTNMessageError,
|
|
80
|
+
SPARTNParseError,
|
|
81
|
+
SPARTNReader,
|
|
82
|
+
SPARTNStreamError,
|
|
83
|
+
SPARTNTypeError,
|
|
84
|
+
date2timetag,
|
|
85
|
+
valid_crc,
|
|
86
|
+
)
|
|
71
87
|
from pyubx2 import (
|
|
72
88
|
ERR_LOG,
|
|
73
89
|
ERR_RAISE,
|
|
@@ -96,7 +112,7 @@ from pyunigps import (
|
|
|
96
112
|
)
|
|
97
113
|
|
|
98
114
|
from pygnssutils.exceptions import GNSSStreamError
|
|
99
|
-
from pygnssutils.globals import DEFAULT_BUFSIZE
|
|
115
|
+
from pygnssutils.globals import DEFAULT_BUFSIZE, SPARTN_DEFAULTKEY
|
|
100
116
|
|
|
101
117
|
NMEA_PROTOCOL = 1
|
|
102
118
|
"""NMEA Protocol"""
|
|
@@ -110,6 +126,8 @@ QGC_PROTOCOL = 16
|
|
|
110
126
|
"""QGC Protocol (Quectel)"""
|
|
111
127
|
UNI_PROTOCOL = 32
|
|
112
128
|
"""UNI Protocol (Unicore)"""
|
|
129
|
+
SPARTN_PROTOCOL = 256
|
|
130
|
+
"""SPARTN Protocol"""
|
|
113
131
|
PARSE_NONE = 0
|
|
114
132
|
"""No Parsing, raw output only"""
|
|
115
133
|
PARSE_FULL = 1
|
|
@@ -229,14 +247,17 @@ class GNSSReader:
|
|
|
229
247
|
| RTCM3_PROTOCOL
|
|
230
248
|
| SBF_PROTOCOL
|
|
231
249
|
| QGC_PROTOCOL
|
|
232
|
-
| UNI_PROTOCOL
|
|
250
|
+
| UNI_PROTOCOL
|
|
251
|
+
| SPARTN_PROTOCOL,
|
|
233
252
|
quitonerror: Literal[0, 1, 2] = ERR_LOG,
|
|
234
253
|
parsebitfield: bool = True,
|
|
235
254
|
labelmsm: Literal[0, 1] = 1,
|
|
236
255
|
bufsize: int = DEFAULT_BUFSIZE,
|
|
237
256
|
parsing: Literal[0, 1, 2] = PARSE_FULL,
|
|
238
257
|
msgfilter: tuple | int | str = "",
|
|
239
|
-
errorhandler:
|
|
258
|
+
errorhandler: Callable | NoneType = None,
|
|
259
|
+
spartnkey: str = SPARTN_DEFAULTKEY,
|
|
260
|
+
spartnbasedate: int | datetime = 0, # TIMEBASE
|
|
240
261
|
):
|
|
241
262
|
"""Constructor.
|
|
242
263
|
|
|
@@ -244,8 +265,9 @@ class GNSSReader:
|
|
|
244
265
|
:param Literal[0,1,2] msgmode: 0=GET, 1=SET, 2=POLL, 3=SETPOLL (0)
|
|
245
266
|
:param int validate: VALCKSUM (1) = Validate checksum,
|
|
246
267
|
VALNONE (0) = ignore invalid checksum (1)
|
|
247
|
-
:param int protfilter: NMEA_PROTOCOL (1), UBX_PROTOCOL (2), RTCM3_PROTOCOL (4),
|
|
248
|
-
SBF_PROTOCOL (8), QGC_PROTOCOL (16), UNI_PROTOCOL (32)
|
|
268
|
+
:param int protfilter: NMEA_PROTOCOL (1), UBX_PROTOCOL (2), RTCM3_PROTOCOL (4), \
|
|
269
|
+
SBF_PROTOCOL (8), QGC_PROTOCOL (16), UNI_PROTOCOL (32), SPARTN_PROTOCOL (256). \
|
|
270
|
+
Can be OR'd (319)
|
|
249
271
|
:param Literal[0,1,2] quitonerror: ERR_IGNORE (0) = ignore errors, \
|
|
250
272
|
ERR_LOG (1) = log continue, ERR_RAISE (2) = (re)raise (1)
|
|
251
273
|
:param bool parsebitfield: 1 = parse bitfields, 0 = leave as bytes (1)
|
|
@@ -254,7 +276,10 @@ class GNSSReader:
|
|
|
254
276
|
:param Literal[0,1,2] parsing: PARSE_NONE (0) = no parsing (raw only), \
|
|
255
277
|
PARSE_FULL (1) = full parsing, PARSE_META (2) = parse metadata only (1)
|
|
256
278
|
:param tuple | int | str msgfilter: parsed message filter ("" = ALL)
|
|
257
|
-
:param
|
|
279
|
+
:param Callable | NoneType errorhandler: error handling object or function (None)
|
|
280
|
+
:param str spartnkey: SPARTN decryption key
|
|
281
|
+
:param int | datetime spartnbasedate: SPARTN decryption basedate as integer \
|
|
282
|
+
(0 = use datastream, -1 = current UTC; use date2timetag to convert datetime)
|
|
258
283
|
:raises: UBXStreamError (if mode is invalid)
|
|
259
284
|
"""
|
|
260
285
|
# pylint: disable=too-many-arguments
|
|
@@ -271,6 +296,12 @@ class GNSSReader:
|
|
|
271
296
|
self._labelmsm = labelmsm
|
|
272
297
|
self._msgmode = msgmode
|
|
273
298
|
self._parsing = parsing
|
|
299
|
+
self._spartnkey = spartnkey
|
|
300
|
+
if isinstance(spartnbasedate, datetime):
|
|
301
|
+
self._spartnbasedate = date2timetag(spartnbasedate)
|
|
302
|
+
else:
|
|
303
|
+
self._spartnbasedate = int(spartnbasedate)
|
|
304
|
+
self._timetags = {}
|
|
274
305
|
self._msgfilter = (
|
|
275
306
|
(msgfilter,) if not isinstance(msgfilter, tuple) else msgfilter
|
|
276
307
|
)
|
|
@@ -287,22 +318,22 @@ class GNSSReader:
|
|
|
287
318
|
|
|
288
319
|
return self
|
|
289
320
|
|
|
290
|
-
def __next__(self) -> tuple[bytes
|
|
321
|
+
def __next__(self) -> tuple[bytes, Any]:
|
|
291
322
|
"""
|
|
292
323
|
Return next item in iteration.
|
|
293
324
|
|
|
294
325
|
:return: tuple of (raw_data as bytes, parsed_data as UBXMessage)
|
|
295
|
-
:rtype: tuple[bytes
|
|
326
|
+
:rtype: tuple[bytes, Any]
|
|
296
327
|
:raises: StopIteration
|
|
297
328
|
|
|
298
329
|
"""
|
|
299
330
|
|
|
300
331
|
raw_data, parsed_data = self.read()
|
|
301
|
-
if raw_data
|
|
332
|
+
if raw_data == b"" and parsed_data is None:
|
|
302
333
|
raise StopIteration
|
|
303
334
|
return raw_data, parsed_data
|
|
304
335
|
|
|
305
|
-
def read(self) -> tuple[bytes
|
|
336
|
+
def read(self) -> tuple[bytes, Any]:
|
|
306
337
|
"""
|
|
307
338
|
Read a single NMEA, UBX, SBF, QGC, UNI or RTCM3 message from the stream buffer
|
|
308
339
|
and return both raw and parsed data.
|
|
@@ -312,20 +343,26 @@ class GNSSReader:
|
|
|
312
343
|
|
|
313
344
|
:return: tuple of (raw_data as bytes, parsed_data as NMEAMessage, UBXMessage,
|
|
314
345
|
SBFMessage, QGCMessage, UNIMessage, RTCMMessage or (if `parsing=2`) GNSSMessage)
|
|
315
|
-
:rtype: tuple[bytes
|
|
346
|
+
:rtype: tuple[bytes, Any]
|
|
316
347
|
:raises: Exception (if invalid or unrecognised protocol in data stream)
|
|
317
348
|
"""
|
|
318
349
|
|
|
319
|
-
raw_data =
|
|
350
|
+
raw_data = b""
|
|
320
351
|
parsed_data = None
|
|
321
352
|
while True: # loop until end of valid message or EOF
|
|
322
353
|
try:
|
|
323
354
|
|
|
324
|
-
raw_data =
|
|
355
|
+
# raw_data = b""
|
|
325
356
|
parsed_data = None
|
|
326
357
|
byte1 = self._read_bytes(1) # read the first byte
|
|
327
|
-
# if not UBX, SBF, QGC, UNI, NMEA or
|
|
328
|
-
if byte1 not in (b"\xb5", b"\x24", b"\x51", b"\xd3", b"\xaa"):
|
|
358
|
+
# if not UBX, SBF, QGC, UNI, NMEA, RTCM3 or SPARTN, discard and continue
|
|
359
|
+
if byte1 not in (b"\xb5", b"\x24", b"\x51", b"\xd3", b"\xaa", b"\x73"):
|
|
360
|
+
continue
|
|
361
|
+
# if it's a SPARTN message (b'\x73' == b"s")
|
|
362
|
+
if byte1 == SPARTN_PREB:
|
|
363
|
+
raw_data, parsed_data = self._parse_spartn(byte1)
|
|
364
|
+
if self._protfilter & SPARTN_PROTOCOL:
|
|
365
|
+
break
|
|
329
366
|
continue
|
|
330
367
|
byte2 = self._read_bytes(1)
|
|
331
368
|
bytehdr = byte1 + byte2
|
|
@@ -382,10 +419,11 @@ class GNSSReader:
|
|
|
382
419
|
if self._protfilter & RTCM3_PROTOCOL:
|
|
383
420
|
break
|
|
384
421
|
continue
|
|
422
|
+
raw_data = bytehdr
|
|
385
423
|
raise GNSSStreamError(f"Unknown protocol header {escapeall(bytehdr)}.")
|
|
386
424
|
|
|
387
425
|
except EOFError:
|
|
388
|
-
return (
|
|
426
|
+
return (b"", None)
|
|
389
427
|
except (
|
|
390
428
|
UBXMessageError,
|
|
391
429
|
UBXTypeError,
|
|
@@ -411,6 +449,11 @@ class GNSSReader:
|
|
|
411
449
|
UNIParseError,
|
|
412
450
|
UNIStreamError,
|
|
413
451
|
UNITypeError,
|
|
452
|
+
SPARTNMessageError,
|
|
453
|
+
SPARTNParseError,
|
|
454
|
+
SPARTNStreamError,
|
|
455
|
+
SPARTNTypeError,
|
|
456
|
+
SPARTNDecryptionError,
|
|
414
457
|
GNSSStreamError,
|
|
415
458
|
) as err:
|
|
416
459
|
if self._quitonerror:
|
|
@@ -621,6 +664,82 @@ class GNSSReader:
|
|
|
621
664
|
parsed_data = GNSSMessage(RTCM3_PROTOCOL, msgidi, raw_data)
|
|
622
665
|
return raw_data, parsed_data
|
|
623
666
|
|
|
667
|
+
def _parse_spartn(self, preamble: bytes) -> tuple[bytes, SPARTNMessage]:
|
|
668
|
+
"""
|
|
669
|
+
Parse any SPARTN data in the stream. The structure of the transport layer
|
|
670
|
+
depends on encryption type, GNSS timetag format and CRC format.
|
|
671
|
+
|
|
672
|
+
:param preamble hdr: preamble of SPARTN message
|
|
673
|
+
:return: raw_data as bytes, parsed_stub as SPARTNMessage
|
|
674
|
+
:rtype: tuple[bytes, SPARTNMessage]
|
|
675
|
+
:raises: SPARTN...Error if CRC invalid or other parsing error
|
|
676
|
+
"""
|
|
677
|
+
|
|
678
|
+
# pylint: disable=invalid-name
|
|
679
|
+
|
|
680
|
+
def bitsval(bitfield: bytes, position: int, length: int):
|
|
681
|
+
lbb = len(bitfield) * 8
|
|
682
|
+
if position + length > lbb:
|
|
683
|
+
raise SPARTNMessageError(
|
|
684
|
+
f"Attribute size {length} exceeds remaining payload length {lbb - position}"
|
|
685
|
+
)
|
|
686
|
+
return int.from_bytes(bitfield, "big") >> (lbb - position - length) & (
|
|
687
|
+
(1 << length) - 1
|
|
688
|
+
)
|
|
689
|
+
|
|
690
|
+
framestart = self._read_bytes(3)
|
|
691
|
+
# msgType = bitsval(framestart, 0, 7)
|
|
692
|
+
nData = bitsval(framestart, 7, 10)
|
|
693
|
+
eaf = bitsval(framestart, 17, 1)
|
|
694
|
+
crcType = bitsval(framestart, 18, 2)
|
|
695
|
+
# frameCrc = bitsval(framestart, 20, 4)
|
|
696
|
+
|
|
697
|
+
payDesc = self._read_bytes(4)
|
|
698
|
+
# msgSubtype denotes constellation - GPS, GLO, GAL, etc.
|
|
699
|
+
msgSubtype = bitsval(payDesc, 0, 4)
|
|
700
|
+
timeTagtype = bitsval(payDesc, 4, 1)
|
|
701
|
+
if timeTagtype:
|
|
702
|
+
payDesc += self._read_bytes(2)
|
|
703
|
+
gtlen = 32 if timeTagtype else 16
|
|
704
|
+
gnssTimeTag = bitsval(payDesc, 5, gtlen)
|
|
705
|
+
# store 32-bit timetag for this subtype for later use in decryption
|
|
706
|
+
if timeTagtype == 1:
|
|
707
|
+
self._timetags[msgSubtype] = gnssTimeTag
|
|
708
|
+
# solutionId = bitsval(payDesc, gtlen + 5, 7)
|
|
709
|
+
# solutionProcId = bitsval(payDesc, gtlen + 12, 4)
|
|
710
|
+
authInd = 0
|
|
711
|
+
embAuthLen = 0
|
|
712
|
+
if eaf:
|
|
713
|
+
payDesc += self._read_bytes(2)
|
|
714
|
+
# encryptionId = bitsval(payDesc, gtlen + 16, 4)
|
|
715
|
+
# encryptionSeq = bitsval(payDesc, gtlen + 20, 6)
|
|
716
|
+
authInd = bitsval(payDesc, gtlen + 26, 3)
|
|
717
|
+
embAuthLen = bitsval(payDesc, gtlen + 29, 3)
|
|
718
|
+
payload = self._read_bytes(nData)
|
|
719
|
+
embAuth = b""
|
|
720
|
+
if authInd > 1:
|
|
721
|
+
aln = ALN_ENUM.get(embAuthLen, 0)
|
|
722
|
+
embAuth = self._read_bytes(aln)
|
|
723
|
+
crcb = self._read_bytes(crcType + 1)
|
|
724
|
+
crc = int.from_bytes(crcb, "big")
|
|
725
|
+
|
|
726
|
+
# validate CRC
|
|
727
|
+
core = framestart + payDesc + payload + embAuth
|
|
728
|
+
raw_data = preamble + core + crcb
|
|
729
|
+
if self._validate & VALCRC:
|
|
730
|
+
if not valid_crc(core, crc, crcType):
|
|
731
|
+
raise SPARTNParseError(f"Invalid CRC {crc}")
|
|
732
|
+
|
|
733
|
+
parsed_data = SPARTNReader.parse(
|
|
734
|
+
raw_data,
|
|
735
|
+
validate=self._validate,
|
|
736
|
+
decode=True,
|
|
737
|
+
key=self._spartnkey,
|
|
738
|
+
basedate=self._spartnbasedate,
|
|
739
|
+
timetags=self._timetags,
|
|
740
|
+
)
|
|
741
|
+
return (raw_data, parsed_data)
|
|
742
|
+
|
|
624
743
|
def _read_bytes(self, size: int) -> bytes:
|
|
625
744
|
"""
|
|
626
745
|
Read a specified number of bytes from stream.
|
|
@@ -13,6 +13,7 @@ Created on 27 Jul 2023
|
|
|
13
13
|
"""
|
|
14
14
|
|
|
15
15
|
from collections import defaultdict
|
|
16
|
+
from datetime import datetime
|
|
16
17
|
from io import UnsupportedOperation
|
|
17
18
|
from logging import getLogger
|
|
18
19
|
from queue import Empty, Queue
|
|
@@ -25,6 +26,7 @@ from pynmeagps import NMEAMessage
|
|
|
25
26
|
from pyqgc import QGCMessage
|
|
26
27
|
from pyrtcm import RTCMMessage
|
|
27
28
|
from pysbf2 import SBFMessage
|
|
29
|
+
from pyspartn import SPARTNMessage, date2timetag
|
|
28
30
|
from pyubx2 import (
|
|
29
31
|
CARRSOLN,
|
|
30
32
|
ERR_RAISE,
|
|
@@ -35,6 +37,7 @@ from pyubx2 import (
|
|
|
35
37
|
UBXMessage,
|
|
36
38
|
hextable,
|
|
37
39
|
)
|
|
40
|
+
from pyunigps import UNIMessage
|
|
38
41
|
from serial import Serial
|
|
39
42
|
|
|
40
43
|
from pygnssutils.exceptions import ParameterError
|
|
@@ -48,6 +51,7 @@ from pygnssutils.globals import (
|
|
|
48
51
|
FORMAT_JSON,
|
|
49
52
|
FORMAT_PARSED,
|
|
50
53
|
FORMAT_PARSEDSTRING,
|
|
54
|
+
SPARTN_DEFAULTKEY,
|
|
51
55
|
VERBOSITY_MEDIUM,
|
|
52
56
|
)
|
|
53
57
|
from pygnssutils.gnssreader import (
|
|
@@ -56,7 +60,9 @@ from pygnssutils.gnssreader import (
|
|
|
56
60
|
QGC_PROTOCOL,
|
|
57
61
|
RTCM3_PROTOCOL,
|
|
58
62
|
SBF_PROTOCOL,
|
|
63
|
+
SPARTN_PROTOCOL,
|
|
59
64
|
UBX_PROTOCOL,
|
|
65
|
+
UNI_PROTOCOL,
|
|
60
66
|
GNSSMessage,
|
|
61
67
|
GNSSReader,
|
|
62
68
|
)
|
|
@@ -80,7 +86,7 @@ class GNSSStreamer:
|
|
|
80
86
|
|
|
81
87
|
The class implements public methods which can be used by other pygnssutils
|
|
82
88
|
classes:
|
|
83
|
-
|
|
89
|
+
|
|
84
90
|
- `get_coordinates()`, returns current GNSS status.
|
|
85
91
|
- `status` property, returns current GNSS status.
|
|
86
92
|
|
|
@@ -101,7 +107,9 @@ class GNSSStreamer:
|
|
|
101
107
|
| UBX_PROTOCOL
|
|
102
108
|
| RTCM3_PROTOCOL
|
|
103
109
|
| SBF_PROTOCOL
|
|
104
|
-
| QGC_PROTOCOL
|
|
110
|
+
| QGC_PROTOCOL
|
|
111
|
+
| UNI_PROTOCOL
|
|
112
|
+
| SPARTN_PROTOCOL,
|
|
105
113
|
msgfilter: str = "",
|
|
106
114
|
parsing: Literal[0, 1, 2] = PARSE_FULL,
|
|
107
115
|
limit: int = 0,
|
|
@@ -112,6 +120,8 @@ class GNSSStreamer:
|
|
|
112
120
|
stopevent: Event | NoneType = None,
|
|
113
121
|
verbosity: Literal[-1, 0, 1, 2, 3] = VERBOSITY_MEDIUM,
|
|
114
122
|
logtofile: str = "",
|
|
123
|
+
spartnkey: str = SPARTN_DEFAULTKEY,
|
|
124
|
+
spartnbasedate: int | datetime = 0, # TIMEBASE
|
|
115
125
|
**kwargs,
|
|
116
126
|
):
|
|
117
127
|
"""
|
|
@@ -126,7 +136,8 @@ class GNSSStreamer:
|
|
|
126
136
|
16 = parsed as string, 32 = JSON (can be OR'd) (1)
|
|
127
137
|
:param Literal[0,1,2] quitonerror: 0 = ignore errors, 1 = log errors and continue, \
|
|
128
138
|
2 = (re)raise errors (1)
|
|
129
|
-
:param int protfilter: 1 = NMEA, 2 = UBX, 4 = RTCM3, 8 = SBF, 16 = QGC
|
|
139
|
+
:param int protfilter: 1 = NMEA, 2 = UBX, 4 = RTCM3, 8 = SBF, 16 = QGC, \
|
|
140
|
+
32 = UNI, 256 = SPARTN (can be OR'd) (319)
|
|
130
141
|
:param str msgfilter: comma-separated string of message identities to include in output \
|
|
131
142
|
e.g. 'NAV-PVT,GNGSA'. A periodicity clause can be added e.g. NAV-SAT(10), signifying \
|
|
132
143
|
the minimum period in seconds between successive messages of this type ("")
|
|
@@ -141,6 +152,9 @@ class GNSSStreamer:
|
|
|
141
152
|
:param Literal[-1,0,1,2,3] verbosity: log message verbosity -1 = critical, 0 = error, \
|
|
142
153
|
1 = warning, 2 = info, 3 = debug (1)
|
|
143
154
|
:param str logtofile: fully qualified path to logfile ("" = no logfile)
|
|
155
|
+
:param str spartnkey: SPARTN decryption key
|
|
156
|
+
:param int | datetime spartnbasedate: SPARTN decryption basedate as integer \
|
|
157
|
+
(0 = use datastream, -1 = current UTC; use date2timetag to convert datetime)
|
|
144
158
|
:param dict kwargs: user-defined keyword arguments to pass to custom input/output handlers
|
|
145
159
|
:raises ValueError: If invalid arguments
|
|
146
160
|
"""
|
|
@@ -167,6 +181,11 @@ class GNSSStreamer:
|
|
|
167
181
|
self._limit = int(limit)
|
|
168
182
|
self._outqueue = outqueue
|
|
169
183
|
self._inqueue = inqueue
|
|
184
|
+
self._spartnkey = spartnkey
|
|
185
|
+
if isinstance(spartnbasedate, datetime):
|
|
186
|
+
self._spartnbasedate = date2timetag(spartnbasedate)
|
|
187
|
+
else:
|
|
188
|
+
self._spartnbasedate = int(spartnbasedate)
|
|
170
189
|
if outputhandler is None:
|
|
171
190
|
self._outputhandler = self.do_output
|
|
172
191
|
else:
|
|
@@ -314,11 +333,12 @@ class GNSSStreamer:
|
|
|
314
333
|
validate=self._validate,
|
|
315
334
|
quitonerror=self._quitonerror,
|
|
316
335
|
parsebitfield=self._parsebitfield,
|
|
336
|
+
spartnkey=self._spartnkey,
|
|
337
|
+
spartnbasedate=self._spartnbasedate,
|
|
317
338
|
)
|
|
318
339
|
|
|
319
340
|
while not stopevent.is_set():
|
|
320
341
|
try:
|
|
321
|
-
|
|
322
342
|
raw_data, parsed_data = ubr.read()
|
|
323
343
|
if raw_data is None or parsed_data is None:
|
|
324
344
|
stopevent.set()
|
|
@@ -420,6 +440,10 @@ class GNSSStreamer:
|
|
|
420
440
|
protocol = SBF_PROTOCOL
|
|
421
441
|
elif isinstance(parsed_data, QGCMessage):
|
|
422
442
|
protocol = QGC_PROTOCOL
|
|
443
|
+
elif isinstance(parsed_data, UNIMessage):
|
|
444
|
+
protocol = UNI_PROTOCOL
|
|
445
|
+
elif isinstance(parsed_data, SPARTNMessage):
|
|
446
|
+
protocol = SPARTN_PROTOCOL
|
|
423
447
|
elif isinstance(parsed_data, GNSSMessage):
|
|
424
448
|
protocol = parsed_data.protocol
|
|
425
449
|
else:
|
|
@@ -541,7 +565,7 @@ class GNSSStreamer:
|
|
|
541
565
|
- (sourcetable: list, nearest mountpoint, distance: tuple) e.g. NTRIP Sourcetable data
|
|
542
566
|
|
|
543
567
|
In the default input handler, only bytes data is written to datastream,
|
|
544
|
-
but this may be
|
|
568
|
+
but this may be overridden by user to handle other data types.
|
|
545
569
|
|
|
546
570
|
:param object datastream: bidirectional GNSS datastream
|
|
547
571
|
:param Queue inqueue: queue containing data to be sent to GNSS datastream
|
|
@@ -74,10 +74,17 @@ from pygnssutils.globals import (
|
|
|
74
74
|
from pygnssutils.gnssntripclient import GNSSNTRIPClient
|
|
75
75
|
from pygnssutils.gnssreader import (
|
|
76
76
|
ERR_LOG,
|
|
77
|
+
NMEA_PROTOCOL,
|
|
77
78
|
PARSE_FULL,
|
|
78
79
|
PARSE_META,
|
|
79
80
|
PARSE_NONE,
|
|
81
|
+
QGC_PROTOCOL,
|
|
82
|
+
RTCM3_PROTOCOL,
|
|
83
|
+
SBF_PROTOCOL,
|
|
80
84
|
SETPOLL,
|
|
85
|
+
SPARTN_PROTOCOL,
|
|
86
|
+
UBX_PROTOCOL,
|
|
87
|
+
UNI_PROTOCOL,
|
|
81
88
|
GNSSReader,
|
|
82
89
|
)
|
|
83
90
|
from pygnssutils.gnssstreamer import GNSSStreamer
|
|
@@ -468,9 +475,19 @@ def main():
|
|
|
468
475
|
ap.add_argument(
|
|
469
476
|
"--protfilter",
|
|
470
477
|
required=False,
|
|
471
|
-
help=
|
|
478
|
+
help=(
|
|
479
|
+
f"{NMEA_PROTOCOL} = NMEA, {UBX_PROTOCOL} = UBX, {RTCM3_PROTOCOL} = RTCM3, "
|
|
480
|
+
f"{SBF_PROTOCOL} = SBF, {QGC_PROTOCOL} = QGC, {UNI_PROTOCOL} = UNI, "
|
|
481
|
+
f"{SPARTN_PROTOCOL} = SPARTN (can be OR'd)"
|
|
482
|
+
),
|
|
472
483
|
type=int,
|
|
473
|
-
default=
|
|
484
|
+
default=NMEA_PROTOCOL
|
|
485
|
+
| UBX_PROTOCOL
|
|
486
|
+
| RTCM3_PROTOCOL
|
|
487
|
+
| SBF_PROTOCOL
|
|
488
|
+
| QGC_PROTOCOL
|
|
489
|
+
| UNI_PROTOCOL
|
|
490
|
+
| SPARTN_PROTOCOL,
|
|
474
491
|
)
|
|
475
492
|
ap.add_argument(
|
|
476
493
|
"--msgfilter",
|
|
@@ -592,6 +609,19 @@ def main():
|
|
|
592
609
|
type=int,
|
|
593
610
|
default=-1,
|
|
594
611
|
)
|
|
612
|
+
ap.add_argument(
|
|
613
|
+
"--spartnkey",
|
|
614
|
+
help="SPARTN decryption key",
|
|
615
|
+
default="abcd1234",
|
|
616
|
+
)
|
|
617
|
+
ap.add_argument(
|
|
618
|
+
"--spartnbasedate",
|
|
619
|
+
help=(
|
|
620
|
+
"SPARTN decryption basedate as integer (0 = use datastream; -1 = current UTC; "
|
|
621
|
+
"use date2timetag to convert datetime)"
|
|
622
|
+
),
|
|
623
|
+
default=0,
|
|
624
|
+
)
|
|
595
625
|
kwargs = set_common_args("gnssstreamer", ap)
|
|
596
626
|
kwargs["outformat"] = kwargs.pop("format") # avoid 'redefines format' warning
|
|
597
627
|
_setup_output(**kwargs)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pygnssutils
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.1
|
|
4
4
|
Summary: GNSS Command Line Utilities
|
|
5
5
|
Author: Steve Smith
|
|
6
6
|
Author-email: semuadmin@semuconsulting.com
|
|
@@ -34,15 +34,15 @@ Requires-Python: >=3.10
|
|
|
34
34
|
Description-Content-Type: text/markdown
|
|
35
35
|
License-File: LICENSE
|
|
36
36
|
Requires-Dist: certifi>=2026.0.0
|
|
37
|
-
Requires-Dist: pynmeagps>=1.1.
|
|
38
|
-
Requires-Dist: pyqgc>=1.0.
|
|
39
|
-
Requires-Dist: pyrtcm>=1.2.
|
|
40
|
-
Requires-Dist: pysbf2>=1.0.
|
|
37
|
+
Requires-Dist: pynmeagps>=1.1.8
|
|
38
|
+
Requires-Dist: pyqgc>=1.0.1
|
|
39
|
+
Requires-Dist: pyrtcm>=1.2.1
|
|
40
|
+
Requires-Dist: pysbf2>=1.0.7
|
|
41
41
|
Requires-Dist: pyserial>=3.5
|
|
42
|
-
Requires-Dist: pyspartn>=1.0
|
|
43
|
-
Requires-Dist: pyubx2>=1.
|
|
42
|
+
Requires-Dist: pyspartn>=1.1.0
|
|
43
|
+
Requires-Dist: pyubx2>=1.4.0
|
|
44
44
|
Requires-Dist: pyubxutils>=1.0.6
|
|
45
|
-
Requires-Dist: pyunigps>=1.0.
|
|
45
|
+
Requires-Dist: pyunigps>=1.0.1
|
|
46
46
|
Dynamic: license-file
|
|
47
47
|
|
|
48
48
|
pygnssutils
|
|
@@ -73,8 +73,8 @@ pygnssutils is an original series of Python GNSS utility classes and CLI tools b
|
|
|
73
73
|
|
|
74
74
|
Originally developed in support of the [PyGPSClient](https://github.com/semuconsulting/PyGPSClient) GUI GNSS application, the utilities provided by pygnssutils can also be used in their own right:
|
|
75
75
|
|
|
76
|
-
1. `GNSSReader` class. This is essentially an amalgamation of the `*Reader` classes in all the subsidiary parsers listed above, allowing the user to seamlessly stream any of NMEA, UBX, SBF, UNI, QGC and
|
|
77
|
-
1. `GNSSStreamer` class and its associated [`gnssstreamer`](#gnssstreamer) (*formerly `gnssdump`*) CLI utility. This is essentially a configurable bidirectional input/output wrapper around the `GNSSReader` class with flexible message formatting, filtering and output handling options for NMEA, UBX, SBF, UNI, QGC and
|
|
76
|
+
1. `GNSSReader` class. This is essentially an amalgamation of the `*Reader` classes in all the subsidiary parsers listed above, allowing the user to seamlessly stream any of NMEA, UBX, SBF, UNI, QGC, RTCM3 and SPARTN message protocols concurrently from a single stream.
|
|
77
|
+
1. `GNSSStreamer` class and its associated [`gnssstreamer`](#gnssstreamer) (*formerly `gnssdump`*) CLI utility. This is essentially a configurable bidirectional input/output wrapper around the `GNSSReader` class with flexible message formatting, filtering and output handling options for NMEA, UBX, SBF, UNI, QGC, RTCM3 and SPARTN protocols.
|
|
78
78
|
1. `GNSSSocketServer` class and its associated [`gnssserver`](#gnssserver) CLI utility. This implements a TCP Socket Server for GNSS data streams which is also capable of being run as a simple NTRIP Server/Caster.
|
|
79
79
|
1. `GNSSNTRIPClient` class and its associated [`gnssntripclient`](#gnssntripclient) CLI utility. This implements
|
|
80
80
|
a simple NTRIP Client which receives RTCM3 or SPARTN correction data from an NTRIP Server and (optionally) sends this to a
|
|
@@ -154,7 +154,7 @@ Refer to the [Sphinx API documentation](https://www.semuconsulting.com/pygnssuti
|
|
|
154
154
|
class pygnssutils.gnssstreamer.GNSSStreamer(**kwargs)
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
-
`gnssstreamer` (*formerly `gnssdump`*) is a command line utility for concurrent bidirectional communication with a GNSS datastream - typically a GNSS receiver. It supports NMEA, UBX, SBF, UNI, QGC, RTCM3, SPARTN
|
|
157
|
+
`gnssstreamer` (*formerly `gnssdump`*) is a command line utility for concurrent bidirectional communication with a GNSS datastream - typically a GNSS receiver. It supports NMEA, UBX, SBF, UNI, QGC, RTCM3, SPARTN and NTRIP protocols - individual protocols can be filtered via the `protfilter` arguments.
|
|
158
158
|
|
|
159
159
|
- The CLI utility can acquire data from any one of the following sources:
|
|
160
160
|
- `port`: serial port e.g. `COM3` or `/dev/ttyACM1` (can specify `--baudrate` and `--timeout`)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""
|
|
2
|
-
Test GNSSStreamer class
|
|
2
|
+
Test GNSSStreamer class
|
|
3
3
|
|
|
4
|
-
Created on 3 Oct 2020
|
|
4
|
+
Created on 3 Oct 2020
|
|
5
5
|
|
|
6
6
|
@author: semuadmin
|
|
7
7
|
"""
|
|
@@ -13,7 +13,6 @@ import sys
|
|
|
13
13
|
import unittest
|
|
14
14
|
from io import StringIO
|
|
15
15
|
|
|
16
|
-
from pygnssutils import exceptions as pge
|
|
17
16
|
from pygnssutils.gnssstreamer import (
|
|
18
17
|
FORMAT_BINARY,
|
|
19
18
|
FORMAT_HEX,
|
|
@@ -114,6 +113,14 @@ class gnssstreamerTest(unittest.TestCase):
|
|
|
114
113
|
sys.stdout = saved_stdout
|
|
115
114
|
print(f"output = {out.getvalue().strip()}")
|
|
116
115
|
|
|
116
|
+
def testgnssstreamer_filter_uni(self):
|
|
117
|
+
# Unicore messages must pass a protocol filter that includes UNI (32)
|
|
118
|
+
from pyunigps import UNIMessage
|
|
119
|
+
|
|
120
|
+
gns = GNSSStreamer(None, StringIO(), protfilter=63)
|
|
121
|
+
msg = UNIMessage(msgid=102, length=0, payload=b"\x00" * 28)
|
|
122
|
+
self.assertFalse(gns._filtered(msg))
|
|
123
|
+
|
|
117
124
|
def testgnssstreamer_outputhandler(self):
|
|
118
125
|
saved_stdout = sys.stdout
|
|
119
126
|
out = StringIO()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|