Files
skyplot/gnss_thread.py
T
2026-05-17 17:00:48 +02:00

52 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ---------------------------------------------------------------------------
# GNSS Lese-Thread
# ---------------------------------------------------------------------------
import socket
import serial
from PyQt5.QtCore import QThread, pyqtSignal
from ubx import UbxPacketizer, build_poll, UBX_CLASS_NAV, UBX_ID_NAV_SAT, extract_satellites
class GnssReader(QThread):
satellites_updated = pyqtSignal(list)
error_occurred = pyqtSignal(str)
connected = pyqtSignal(str)
def __init__(self, transport_factory):
super().__init__()
self._factory = transport_factory
self._running = False
self._transport = None
self.packetizer = UbxPacketizer()
def run(self):
self._running = True
buf = b""
try:
self._transport = self._factory()
self.connected.emit("Verbunden")
poll_msg = build_poll(UBX_CLASS_NAV, UBX_ID_NAV_SAT)
self._transport.write(poll_msg)
while self._running:
chunk = self._transport.read(512)
frames = self.packetizer.on_recv(chunk)
sats = extract_satellites(frames)
if sats:
self.satellites_updated.emit(sats)
else:
# Kein Datum erneut pollen
self._transport.write(poll_msg)
except (serial.SerialException, OSError, ConnectionRefusedError,
socket.timeout, socket.gaierror) as exc:
self.error_occurred.emit(str(exc))
finally:
if self._transport:
self._transport.close()
def stop(self):
self._running = False
self.wait(3000)