Fix issue with GPSException, handle invalid GPS sentences more gracefully by ignoring them

section_mults
bmo 2018-02-05 22:02:15 -08:00
rodzic cb71674f8b
commit de14310009
3 zmienionych plików z 16 dodań i 7 usunięć

Wyświetl plik

@ -2,7 +2,7 @@
class GPSException(Exception):
def __init__(self,*args):
Exception.__init__(*args)
super(GPSException, self).__init__(*args)
# From K6WRU via stackexchange : see https://ham.stackexchange.com/questions/221/how-can-one-convert-from-lat-long-to-grid-square/244#244
# Convert latitude and longitude to Maidenhead grid locators.

Wyświetl plik

@ -3,7 +3,13 @@ import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
import pywsjtx.extra.simple_server
s = pywsjtx.extra.simple_server.SimpleServer('127.0.0.1','2237',timeout=2.0)
#IP_ADDRESS = '224.1.1.1'
#PORT = 5007
IP_ADDRESS = '127.0.0.1'
PORT = 2237
s = pywsjtx.extra.simple_server.SimpleServer(IP_ADDRESS, PORT, timeout=2.0)
while True:

Wyświetl plik

@ -44,7 +44,7 @@ class NMEALocation(object):
else:
self.valid = False
if self.grid != grid:
if grid != "" and self.grid != grid:
logging.debug("NMEALocation - grid mismatch old: {} new: {}".format(self.grid,grid))
self.grid = grid
if (self.grid_changed_callback):
@ -93,9 +93,12 @@ class SerialGPS(object):
# dispatch the line
# note that bytes are used for readline, vs strings after the decode to utf-8
if line.startswith(b'$'):
str_line = line.decode("utf-8")
for p in self.line_handlers:
p(str_line)
try:
str_line = line.decode("utf-8")
for p in self.line_handlers:
p(str_line)
except UnicodeDecodeError as ex:
logging.debug("serial_worker: {} - line: {}".format(ex,[hex(c) for c in line]))
@classmethod
def example_line_handler(cls, text):
@ -143,7 +146,7 @@ while True:
if gps_grid != "" and the_packet.de_grid != gps_grid:
print("Sending Grid Change to wsjtx-x, old grid:{} new grid: {}".format(the_packet.de_grid, gps_grid))
grid_change_packet = pywsjtx.LocationChangePacket.Builder(wsjtx_id, "GRID:"+gps_grid)
print(pywsjtx.PacketUtil.hexdump(grid_change_packet))
logging.debug(pywsjtx.PacketUtil.hexdump(grid_change_packet))
s.send_packet(the_packet.addr_port, grid_change_packet)
# for fun, change the TX5 message to our grid square, so we don't have to call CQ again
# this only works if the length of the free text message is less than 13 characters.