GPS-Code von NMEA0183 getrennt, NMEA0183 weiterprogrammiert

This commit is contained in:
Thomas Hooge 2025-07-05 10:12:57 +02:00
parent aefd01e0f9
commit 6214d08174
1 changed files with 51 additions and 17 deletions

View File

@ -77,7 +77,7 @@ Version Datum Änderung(en) von
-------- ----------- ------------------------------------------------------ ---- -------- ----------- ------------------------------------------------------ ----
0.1 2024-10-31 Entwicklung begonnen tho 0.1 2024-10-31 Entwicklung begonnen tho
0.2 2024-12-24 Veröffentlichung als Git-Repository tho 0.2 2024-12-24 Veröffentlichung als Git-Repository tho
0.3 2025 WIP tho
""" """
@ -195,13 +195,56 @@ def rxd_n2k(device):
bus.shutdown() bus.shutdown()
def rxd_0183(devname): def rxd_0183(devname):
# Prüfe ob Port vorhanden ist und sich öffnen läßt # Prüfe ob NMEA0183-Port vorhanden ist und sich öffnen läßt
try: try:
ser = serial.Serial(devname, 115200, timeout=3) ser = serial.Serial(devname, 115200, timeout=3)
except serial.SerialException as e: except serial.SerialException as e:
print("NMEA0183 serial port not available") print("NMEA0183 serial port not available")
return return
setthreadtitle("0183listener") setthreadtitle("0183listener")
while not shutdown:
try:
raw = ser.readline().decode('ascii')
msg = pynmea2.parse(raw)
except pynmea2.nmea.ParseError:
print(f"NMEA0183: Parse-Error: {raw}")
continue
# sentence_type kann fehlen
try:
stype = msg.sentence_type
except:
print(f"NMEA0183: Sentence type missing: {raw}")
continue
if stype == 'GLL':
boatdata.setValue("LAT", msg.latitude)
boatdata.setValue("LON", msg.longitude)
elif stype == 'VTG':
boatdata.setValue("COG", int(msg.true_track))
#TODO klären was für Typen hier ankommen können
# bytearray, str, decimal.Decimal?
sog = float(msg.spd_over_grnd_kts)
#str von OpenCPN: sog = float(msg.spd_over_grnd_kts[:-1])
boatdata.setValue("SOG", sog)
elif stype == 'VHW':
boatdata.setValue("STW", float(msg.water_speed_knots))
elif stype == 'WPL':
# Wegepunkt
print(msg.fields)
elif stype == 'RTE':
# Route
print(msg.fields)
else:
print(msg)
ser.close()
def rxd_gps(devname, devspeed):
# Prüfe ob GPS-Port vorhanden ist und sich öffnen läßt
try:
ser = serial.Serial(devname, devspeed, timeout=3)
except serial.SerialException as e:
print("GPS serial port not available")
return
setthreadtitle("GPSlistener")
while not shutdown: while not shutdown:
try: try:
msg = pynmea2.parse(ser.readline().decode('ascii')) msg = pynmea2.parse(ser.readline().decode('ascii'))
@ -210,19 +253,9 @@ def rxd_0183(devname):
if msg.sentence_type == 'GLL': if msg.sentence_type == 'GLL':
boatdata.setValue("LAT", msg.latitude) boatdata.setValue("LAT", msg.latitude)
boatdata.setValue("LON", msg.longitude) boatdata.setValue("LON", msg.longitude)
elif msg.sentence_type == 'VTG':
boatdata.setValue("COG", int(msg.true_track))
boatdata.setValue("SOG", float(msg.spd_over_grnd_kts[:-1]))
elif msg.sentence_type == 'VHW':
boatdata.setValue("STW", float(msg.water_speed_knots))
elif msg.sentence_type == 'WPL':
# Wegepunkt
print(msg.fields)
elif msg.sentence_type == 'RTE':
# Route
print(msg.fields)
else: else:
print(msg) print(msg)
print(msg.fields)
ser.close() ser.close()
def datareader(histpath, history): def datareader(histpath, history):
@ -274,10 +307,6 @@ def datareader(histpath, history):
for k, v in history.series.items(): for k, v in history.series.items():
if n % k == 0: if n % k == 0:
v.add(pval) v.add(pval)
# Lokales GPS abfragen
# TODO
if cfg['gps']:
pass
n += 1 n += 1
for s in history.series.values(): for s in history.series.values():
@ -663,6 +692,9 @@ if __name__ == "__main__":
if cfg['nmea0183']: if cfg['nmea0183']:
t_rxd_0183 = threading.Thread(target=rxd_0183, args=(cfg['0183_port'],)) t_rxd_0183 = threading.Thread(target=rxd_0183, args=(cfg['0183_port'],))
t_rxd_0183.start() t_rxd_0183.start()
if cfg['gps']:
t_rxd_gps = threading.Thread(target=rxd_gps, args=(cfg['gps_port'],))
t_rxd_gps.start()
if not cfg['simulation']: if not cfg['simulation']:
t_data = threading.Thread(target=datareader, args=(cfg['histpath'], history)) t_data = threading.Thread(target=datareader, args=(cfg['histpath'], history))
t_data.start() t_data.start()
@ -674,6 +706,8 @@ if __name__ == "__main__":
t_rxd_n2k.join() t_rxd_n2k.join()
if cfg['nmea0183']: if cfg['nmea0183']:
t_rxd_0183.join() t_rxd_0183.join()
if cfg['gps']:
t_rxd_gps.join()
if not cfg['simulation']: if not cfg['simulation']:
t_data.join() t_data.join()
print("Another fine product of the Sirius Cybernetics Corporation.") print("Another fine product of the Sirius Cybernetics Corporation.")