Skip to content

Commit

Permalink
use pynmeagps for gga generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard authored and tridge committed Feb 28, 2024
1 parent 2f83d16 commit 7efff6d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 37 deletions.
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

0 comments on commit 7efff6d

Please sign in to comment.