Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NTRIP: use pynmeagps for correct gga generation #1323

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 27 additions & 36 deletions MAVProxy/modules/lib/ntrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
from MAVProxy.modules.lib import rtcm3
import ssl
from optparse import OptionParser
from pynmeagps import NMEAMessage, GET

version = 0.1
version = 0.2
useragent = "NTRIP MAVProxy/%.1f" % version


Expand Down Expand Up @@ -70,26 +71,8 @@ def __init__(self,
self.ssl = True

def setPosition(self, lat, lon):
self.flagN = "N"
self.flagE = "E"
if lon > 180:
lon = (lon-360)*-1
self.flagE = "W"
elif lon < 0 and lon >= -180:
lon = lon*-1
self.flagE = "W"
elif lon < -180:
lon = lon+360
self.flagE = "E"
else:
self.lon = lon
if lat < 0:
lat = lat*-1
self.flagN = "S"
self.lonDeg = int(lon)
self.latDeg = int(lat)
self.lonMin = (lon-self.lonDeg)*60
self.latMin = (lat-self.latDeg)*60
self.lon = lon
self.lat = lat

def getMountPointString(self):
userstr = self.user
Expand All @@ -105,19 +88,28 @@ def getMountPointString(self):
mountPointString += "\r\n"
return mountPointString

def getGGAString(self):
now = datetime.datetime.utcnow()
ggaString = "GPGGA,%02d%02d%04.2f,%02d%011.8f,%1s,%03d%011.8f,%1s,1,05,0.19,+00400,M,%5.3f,M,," % (
now.hour, now.minute, now.second, self.latDeg, self.latMin, self.flagN,
self.lonDeg, self.lonMin, self.flagE, self.height)
checksum = self.calculateCheckSum(ggaString)
return "$%s*%s\r\n" % (ggaString, checksum)
def getGGAByteString(self):
gga_msg = NMEAMessage(
"GP",
"GGA",
GET, # msgmode is expected by this lib
lat=self.lat,
NS="S" if self.lat < 0 else "N",
lon=self.lon,
EW="W" if self.lon < 0 else "E",
quality=1,
numSV=15,
HDOP=0,
alt=self.height,
altUnit="M",
sep=0,
sepUnit="M",
diffAge="",
diffStation=0,
)

def calculateCheckSum(self, stringToCheck):
xsum_calc = 0
for char in stringToCheck:
xsum_calc = xsum_calc ^ ord(char)
return "%02X" % xsum_calc
raw_gga: bytes = gga_msg.serialize()
return raw_gga

def get_ID(self):
'''get ID of last packet'''
Expand Down Expand Up @@ -248,9 +240,8 @@ def readLoop(self):
print("got: ", len(data))

def send_gga(self):
gga = self.getGGAString()
if sys.version_info.major >= 3:
gga = bytearray(gga, "ascii")
gga = self.getGGAByteString()

try:
self.socket.sendall(gga)
self.dt_last_gga_sent = time.time()
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def package_files(directory):
# large numbers of modules like numpy etc which may be already installed
requirements=['pymavlink>=2.4.14',
'pyserial>=3.0',
'numpy']
'numpy',
'pynmeagps']

if platform.system() == "Darwin":
# on MacOS we can have a more complete requirements list
Expand Down
Loading