Fallback planu lotu z pliku (samoloty z własnym FMC: Toliss/Zibo)

This commit is contained in:
pali112 committed 2026-10-20 16:51:36 +02:00
1 parent dcfc572c02
commit d113e81506
1 file changed
+61 -27
+61 -27
View File
@@ -70,6 +70,11 @@ DEFAULT_CONFIG = {
"piper_model": "/home/pali112/.local/share/piper-voices/en_US-lessac-medium.onnx", "piper_model": "/home/pali112/.local/share/piper-voices/en_US-lessac-medium.onnx",
"play_cmd": ["aplay", "-q"], "play_cmd": ["aplay", "-q"],
"tts_enabled": True, "tts_enabled": True,
# --- Plan lotu ---
# Fallback dla samolotow z wlasnym FMC (Toliss/Zibo), ktore nie zapisuja
# planu do natywnego FMS X-Plane. Wskaz plik tekstowy; kazda linia to jeden
# punkt: "NAZWA [WYSOKOSC_stop]" (wysokosc opcjonalna), '#' = komentarz.
"flightplan_file": "",
} }
# Dataref -> (nazwa kontekstu, mnoznik, jednostka) # Dataref -> (nazwa kontekstu, mnoznik, jednostka)
@@ -358,41 +363,65 @@ class XSayATC:
return out return out
def _collect_flight_plan(self): def _collect_flight_plan(self):
"""Zbiera plan lotu z FMS/GPS (listę punktów). WYWOLYWAC TYLKO na glownym watku.""" """Zbiera plan lotu z FMS/GPS lub z pliku fallback. TYLKO glowny watek."""
lines = [] lines = []
# 1) Najpierw natywny FMS/GPS X-Plane
try: try:
n = xp.countFMSEntries() n = xp.countFMSEntries()
except Exception: except Exception:
n = 0 n = 0
if not n or n <= 0: if n and n > 0:
try:
dest_idx = xp.getDestinationFMSEntry()
except Exception:
dest_idx = -1
for i in range(n):
try:
info = xp.getFMSEntryInfo(i)
except Exception:
continue
if info is None:
continue
navid = getattr(info, "navAidID", "") or ""
alt = getattr(info, "altitude", 0) or 0
marker = " [DEST]" if i == dest_idx else ""
alt_s = f", alt {int(alt)} ft" if alt else ""
if navid:
lines.append(f" {i}: {navid}{alt_s}{marker}")
else:
lat = getattr(info, "lat", None)
lon = getattr(info, "lon", None)
if lat is not None and lon is not None:
lines.append(f" {i}: lat/lon {lat:.4f}/{lon:.4f}{alt_s}{marker}")
return lines return lines
# 2) Fallback: plik wskazany w konfiguracji (samoloty z wlasnym FMC)
fp_file = self.config.get("flightplan_file", "")
if not fp_file or not os.path.exists(fp_file):
return lines
try: try:
dest_idx = xp.getDestinationFMSEntry() with open(fp_file, "r", encoding="utf-8") as f:
except Exception: for i, raw in enumerate(f):
dest_idx = -1 line = raw.strip()
if not line or line.startswith("#"):
for i in range(n): continue
try: # "NAZWA [WYSOKOSC]" — oddziel nazwe od opcjonalnej wysokosci
info = xp.getFMSEntryInfo(i) parts = line.split()
except Exception: alt = None
continue if len(parts) >= 2:
if info is None: # ostatni token moze byc liczba (wysokosc w stopach)
continue try:
navid = getattr(info, "navAidID", "") or "" alt = int(parts[-1])
alt = getattr(info, "altitude", 0) or 0 name = " ".join(parts[:-1])
marker = "" except ValueError:
if i == dest_idx: alt = None
marker = " [DEST]" name = " ".join(parts)
alt_s = f", alt {int(alt)} ft" if alt else "" else:
if navid: name = " ".join(parts)
lines.append(f" {i}: {navid}{alt_s}{marker}") alt_s = f", alt {alt} ft" if alt else ""
else: lines.append(f" {i}: {name}{alt_s}")
lat = getattr(info, "lat", None) except Exception as e:
lon = getattr(info, "lon", None) xp.log(f"[XSayATC] Blad odczytu pliku planu lotu: {e}")
if lat is not None and lon is not None:
lines.append(f" {i}: lat/lon {lat:.4f}/{lon:.4f}{alt_s}{marker}")
return lines return lines
# ---------------------------- Komunikacja z LLM ---------------------------- # ---------------------------- Komunikacja z LLM ----------------------------
@@ -722,6 +751,11 @@ class XSayATC:
_, self.config["piper_model"] = imgui.input_text( _, self.config["piper_model"] = imgui.input_text(
"Model piper", self.config["piper_model"], 512) "Model piper", self.config["piper_model"], 512)
imgui.separator()
imgui.text("Plan lotu (fallback dla samolotow z wlasnym FMC):")
_, self.config["flightplan_file"] = imgui.input_text(
"Plik planu lotu", self.config["flightplan_file"], 512)
imgui.separator() imgui.separator()
imgui.text("System prompt (instrukcje ATC):") imgui.text("System prompt (instrukcje ATC):")
_, self.config["system_prompt"] = imgui.input_text_multiline( _, self.config["system_prompt"] = imgui.input_text_multiline(