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
+42 -8
+42 -8
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,20 +363,18 @@ 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:
return lines
try: try:
dest_idx = xp.getDestinationFMSEntry() dest_idx = xp.getDestinationFMSEntry()
except Exception: except Exception:
dest_idx = -1 dest_idx = -1
for i in range(n): for i in range(n):
try: try:
info = xp.getFMSEntryInfo(i) info = xp.getFMSEntryInfo(i)
@@ -381,9 +384,7 @@ class XSayATC:
continue continue
navid = getattr(info, "navAidID", "") or "" navid = getattr(info, "navAidID", "") or ""
alt = getattr(info, "altitude", 0) or 0 alt = getattr(info, "altitude", 0) or 0
marker = "" marker = " [DEST]" if i == dest_idx else ""
if i == dest_idx:
marker = " [DEST]"
alt_s = f", alt {int(alt)} ft" if alt else "" alt_s = f", alt {int(alt)} ft" if alt else ""
if navid: if navid:
lines.append(f" {i}: {navid}{alt_s}{marker}") lines.append(f" {i}: {navid}{alt_s}{marker}")
@@ -392,7 +393,35 @@ class XSayATC:
lon = getattr(info, "lon", None) lon = getattr(info, "lon", None)
if lat is not None and lon is not None: if lat is not None and lon is not None:
lines.append(f" {i}: lat/lon {lat:.4f}/{lon:.4f}{alt_s}{marker}") lines.append(f" {i}: lat/lon {lat:.4f}/{lon:.4f}{alt_s}{marker}")
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:
with open(fp_file, "r", encoding="utf-8") as f:
for i, raw in enumerate(f):
line = raw.strip()
if not line or line.startswith("#"):
continue
# "NAZWA [WYSOKOSC]" — oddziel nazwe od opcjonalnej wysokosci
parts = line.split()
alt = None
if len(parts) >= 2:
# ostatni token moze byc liczba (wysokosc w stopach)
try:
alt = int(parts[-1])
name = " ".join(parts[:-1])
except ValueError:
alt = None
name = " ".join(parts)
else:
name = " ".join(parts)
alt_s = f", alt {alt} ft" if alt else ""
lines.append(f" {i}: {name}{alt_s}")
except Exception as e:
xp.log(f"[XSayATC] Blad odczytu pliku planu lotu: {e}")
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(