Update public source

This commit is contained in:
2026-10-17 06:33:57 +03:00
parent bc5a0b42be
commit 2b25a01d45
2 changed files with 68 additions and 10 deletions
+64 -5
View File
@@ -16,6 +16,8 @@ class GPSTestService:
self.cfg = cfg
self.callback = callback
self.source = None
self.source_lock = threading.Lock()
self.thread = None
self.stop_event = threading.Event()
@@ -76,6 +78,34 @@ class GPSTestService:
self.stop_event.set()
with self.source_lock:
source = self.source
if source is None:
return
connection = getattr(
source,
"socket",
None
)
if connection is not None:
try:
connection.shutdown(2)
except OSError:
pass
try:
source.close()
except Exception as error:
self.emit(
f"[GPS TEST] Stop close error: {error}"
)
def worker(self):
@@ -93,11 +123,19 @@ class GPSTestService:
self.cfg
)
with self.source_lock:
self.source = source
if self.stop_event.is_set():
return
self.emit(
"[GPS TEST] Connecting to GPS source..."
)
file = source.open()
if self.stop_event.is_set():
return
self.state = "CONNECTED"
@@ -122,6 +160,10 @@ class GPSTestService:
line = file.readline()
if not line:
if self.stop_event.wait(0.1):
break
continue
self.nmea_count += 1
@@ -199,15 +241,28 @@ class GPSTestService:
except Exception as error:
self.state = "ERROR"
self.error = str(error)
if not self.stop_event.is_set():
self.emit(
f"[GPS TEST] GPS source error: {error}"
)
self.state = "ERROR"
self.error = str(error)
self.emit(
f"[GPS TEST] GPS source error: {error}"
)
finally:
if file is not None:
try:
file.close()
except Exception as error:
self.emit(
f"[GPS TEST] File close error: {error}"
)
if source is not None:
try:
@@ -219,6 +274,10 @@ class GPSTestService:
f"[GPS TEST] Close error: {error}"
)
with self.source_lock:
if self.source is source:
self.source = None
self.running = False
if self.state != "ERROR":