From d113e8150637c15f7a2a6492f6e4ffd5ae0c2375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Paluch?= Date: Tue, 20 Oct 2026 16:51:36 +0200 Subject: [PATCH] =?UTF-8?q?Fallback=20planu=20lotu=20z=20pliku=20(samoloty?= =?UTF-8?q?=20z=20w=C5=82asnym=20FMC:=20Toliss/Zibo)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonPlugins/PI_XSayATC.py | 88 +++++++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 27 deletions(-) diff --git a/PythonPlugins/PI_XSayATC.py b/PythonPlugins/PI_XSayATC.py index 8ab301a..ace8691 100644 --- a/PythonPlugins/PI_XSayATC.py +++ b/PythonPlugins/PI_XSayATC.py @@ -70,6 +70,11 @@ DEFAULT_CONFIG = { "piper_model": "/home/pali112/.local/share/piper-voices/en_US-lessac-medium.onnx", "play_cmd": ["aplay", "-q"], "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) @@ -358,41 +363,65 @@ class XSayATC: return out 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 = [] + # 1) Najpierw natywny FMS/GPS X-Plane try: n = xp.countFMSEntries() except Exception: 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 + # 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: - 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 = "" - if i == dest_idx: - marker = " [DEST]" - 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}") - + 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 # ---------------------------- Komunikacja z LLM ---------------------------- @@ -722,6 +751,11 @@ class XSayATC: _, self.config["piper_model"] = imgui.input_text( "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.text("System prompt (instrukcje ATC):") _, self.config["system_prompt"] = imgui.input_text_multiline(