Schnittstellenverwaltung für u.a NMEA0183 verbessert

This commit is contained in:
Thomas Hooge 2025-07-05 09:19:14 +02:00
parent b06d88d0ec
commit aefd01e0f9
2 changed files with 33 additions and 11 deletions

View File

@ -11,6 +11,14 @@ mouseptr = on
win_x = -1 win_x = -1
win_y = -1 win_y = -1
[can]
enabled = false
interface = can0
[nmea0183]
enabled = false
port = /dev/ttyV1
[bme280] [bme280]
enabled = false enabled = false
port = 1 port = 1
@ -21,7 +29,6 @@ enabled = false
port = /dev/ttyACM0 port = /dev/ttyACM0
[opencpn] [opencpn]
port = /dev/ttyV1
navobj = ~/.opencpn/navobj.xml navobj = ~/.opencpn/navobj.xml
config = ~/.opencpn/opencpn.conf config = ~/.opencpn/opencpn.conf

View File

@ -8,6 +8,9 @@ Zwei Displayvarianten
2. Fullscreen Display skaliert mit 1,6 ergibt 640x480 2. Fullscreen Display skaliert mit 1,6 ergibt 640x480
mit Platz für große Touch-Flächen am rechten Rand mit Platz für große Touch-Flächen am rechten Rand
Das Gerät kann Daten von NMEA2000 und NMEA0183 empfangen, sowie von
einem lokal angeschlossenen GPS-Empfänger.
NMEA2000 NMEA2000
deviceclass: 120 - Display deviceclass: 120 - Display
devicefunction: 130 - Display devicefunction: 130 - Display
@ -120,9 +123,9 @@ cfg = {
'bme280': False 'bme280': False
} }
def rxd_n2k(): def rxd_n2k(device):
setthreadtitle("N2Klistener") setthreadtitle("N2Klistener")
bus = can.Bus(interface='socketcan', channel='can0', bitrate=250000); bus = can.Bus(interface='socketcan', channel=device, bitrate=250000);
wip = False wip = False
sc = 0 sc = 0
nf = 0 nf = 0
@ -196,7 +199,7 @@ def rxd_0183(devname):
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("OpenCPN serial port not available") print("NMEA0183 serial port not available")
return return
setthreadtitle("0183listener") setthreadtitle("0183listener")
while not shutdown: while not shutdown:
@ -218,6 +221,8 @@ def rxd_0183(devname):
elif msg.sentence_type == 'RTE': elif msg.sentence_type == 'RTE':
# Route # Route
print(msg.fields) print(msg.fields)
else:
print(msg)
ser.close() ser.close()
def datareader(histpath, history): def datareader(histpath, history):
@ -625,6 +630,14 @@ if __name__ == "__main__":
cfg['win_x'] = -1 cfg['win_x'] = -1
cfg['win_y'] = -1 cfg['win_y'] = -1
cfg['can'] = config.getboolean('can', 'enabled')
if cfg['can']:
cfg['can_intf'] = config.get('can', 'interface')
cfg['nmea0183'] = config.getboolean('nmea0183', 'enabled')
if cfg['nmea0183']:
cfg['0183_port'] = config.get('nmea0183', 'port')
cfg['gps'] = config.getboolean('gps', 'enabled') cfg['gps'] = config.getboolean('gps', 'enabled')
if cfg['gps']: if cfg['gps']:
cfg['gps_port'] = config.get('gps', 'port') cfg['gps_port'] = config.get('gps', 'port')
@ -638,27 +651,29 @@ if __name__ == "__main__":
history = History("press", 75) history = History("press", 75)
boatdata.addHistory(history, "press") boatdata.addHistory(history, "press")
cfg['ocpn_port'] = config.get('opencpn', 'port')
if cfg['simulation']: if cfg['simulation']:
boatdata.enableSimulation() boatdata.enableSimulation()
profile = init_profile(config, cfg, boatdata) profile = init_profile(config, cfg, boatdata)
if not cfg['simulation']: # Schnittstellen aktivieren
t_rxd_n2k = threading.Thread(target=rxd_n2k) if cfg['can']:
t_rxd_n2k = threading.Thread(target=rxd_n2k, args=(cfg['can_intf'],))
t_rxd_n2k.start() t_rxd_n2k.start()
t_rxd_0183 = threading.Thread(target=rxd_0183, args=(cfg['ocpn_port'],)) if cfg['nmea0183']:
t_rxd_0183 = threading.Thread(target=rxd_0183, args=(cfg['0183_port'],))
t_rxd_0183.start() t_rxd_0183.start()
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()
app = Frontend(cfg, owndevice, boatdata, profile) app = Frontend(cfg, owndevice, boatdata, profile)
app.run() app.run()
shutdown = True shutdown = True
if not cfg['simulation']: if cfg['can']:
t_rxd_n2k.join() t_rxd_n2k.join()
if cfg['nmea0183']:
t_rxd_0183.join() t_rxd_0183.join()
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.")