Skip to content

Commit

Permalink
fixed sog/cog NMEA formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
musurca committed Dec 11, 2020
1 parent 96a5d7d commit 5b90564
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions nmea.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def update(self, lat, lon, hdg, sog, cog, twd, tws, curTime):
dateStr = curTime.strftime(NMEA_DATE_FORMAT)
posStr = geo.latlon_to_nmea(lat, lon)
hdgStr = str(round(hdg,1)) + ",T"
sogStr = str(round(sog,1))
cogStr = str(round(cog,1))
sogStr = geo.format_sog(str(round(sog,1)))
cogStr = geo.format_sog(str(round(cog,1)))
# NMEA TWA is bearing, not heading
twaStr = str(round(geo.wrap_angle(twd-hdg),1)) + ",T"
twsStr = str(round(tws,1)) + ",N"
Expand Down Expand Up @@ -144,7 +144,7 @@ def __init__(self, port=SERVER_PORT):
self.serverport = port

def version():
return "(v0.1.4)"
return "(v0.1.4a)"

def start(self):
# start the TCP server
Expand Down
7 changes: 7 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ def deg_to_dms(deg, type='lat', fmt='dms'):
s = (deg - d - m / 60) * 3600.00
return '{}{}º{}\'{:.2f}"'.format(compass_str, abs(d), abs(m), abs(s))

def format_sog(sogStr:str):
decimalLoc = sogStr.find(".")
if decimalLoc == -1 or decimalLoc == (len(sogStr)-1):
return "{}.0".format(sogStr.zfill(3))

return "{}.{}".format(sogStr[:decimalLoc].zfill(3), sogStr[decimalLoc+1:decimalLoc+2])

def latlon_to_nmea(lat, lon):
return geo.deg_to_dms(lat,'lat','nmea')+","+geo.deg_to_dms(lon,'lon','nmea')

Expand Down

0 comments on commit 5b90564

Please sign in to comment.