Skip to content

Commit

Permalink
Merge pull request #62 from semuconsulting/enhance-ntrip-caster
Browse files Browse the repository at this point in the history
RELEASE CANDIDATE 1.0.24
  • Loading branch information
semuadmin committed Apr 12, 2024
2 parents 56a68ca + 98dc262 commit 34d798b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"editor.formatOnSave": true,
"modulename": "${workspaceFolderBasename}",
"distname": "${workspaceFolderBasename}",
"moduleversion": "1.0.23"
"moduleversion": "1.0.24"
}
6 changes: 6 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# pygnssutils Release Notes

### RELEASE 1.0.24

FIXES:

1. Further fixes to socket_server NTRIP caster to return properly formatted HTTP header with RTCM3 data stream.

### RELEASE 1.0.23

FIXES:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "pygnssutils"
authors = [{ name = "semuadmin", email = "[email protected]" }]
maintainers = [{ name = "semuadmin", email = "[email protected]" }]
description = "GNSS Command Line Utilities"
version = "1.0.23"
version = "1.0.24"
license = { file = "LICENSE" }
readme = "README.md"
requires-python = ">=3.8"
Expand Down
2 changes: 1 addition & 1 deletion src/pygnssutils/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
:license: BSD 3-Clause
"""

__version__ = "1.0.23"
__version__ = "1.0.24"
44 changes: 35 additions & 9 deletions src/pygnssutils/socket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
# from pygpsclient import version as PYGPSVERSION

RTCM = b"rtcm"
SRT = b"srt"
BAD = b"bad"
BUFSIZE = 1024
PYGPSMP = "pygnssutils"

Expand Down Expand Up @@ -277,15 +279,20 @@ def handle(self):
try:
if self.server.ntripmode: # NTRIP server mode
self.data = self.request.recv(BUFSIZE)
resp = self._process_ntrip_request(self.data)
if resp is None:
break
if resp == RTCM: # start RTCM3 stream
while True:
resptype, resp = self._process_ntrip_request(self.data)
if resptype == SRT: # sourcetable request
self.wfile.write(resp)
self.wfile.flush()
elif resptype == RTCM: # RTCM3 data request
self.wfile.write(resp)
self.wfile.flush()
while True: # send continuous RTCM data stream
self._write_from_mq()
else: # sourcetable or error response
elif resptype == BAD: # unauthorised
self.wfile.write(resp)
self.wfile.flush()
else:
break

else: # open socket server mode
self._write_from_mq()
Expand Down Expand Up @@ -331,12 +338,13 @@ def _process_ntrip_request(self, data: bytes) -> bytes:
+ f'WWW-Authenticate: Basic realm="{mountpoint}"\r\n'
+ "Connection: close\r\n"
)
return bytes(http, "UTF-8")
return BAD, bytes(http, "UTF-8")
if strreq or (not strreq and not validmp): # respond with nominal sourcetable
http = self._format_sourcetable()
return bytes(http, "UTF-8")
return SRT, bytes(http, "UTF-8")
if validmp: # respond by opening RTCM3 stream
return RTCM
http = self._format_data()
return RTCM, bytes(http, "UTF-8")
return None

def _format_sourcetable(self) -> str:
Expand Down Expand Up @@ -370,6 +378,24 @@ def _format_sourcetable(self) -> str:
)
return http

def _format_data(self) -> str:
"""
Format nominal HTTP data response.
:return: HTTP response string
:rtype: str
"""

http = (
self._format_http_header(200)
+ "Cache-Control: no-store, no-cache, max-age=0\r\n"
+ "Pragma: no-cache\r\n"
+ "Connection: close\r\n"
+ "Content-Type: gnss/data\r\n"
+ "\r\n" # necessary to separate body from header
)
return http

def _format_http_header(self, code: int = 200) -> str:
"""
Format HTTP NTRIP header.
Expand Down

0 comments on commit 34d798b

Please sign in to comment.