Fallback planu lotu z pliku (samoloty z własnym FMC: Toliss/Zibo)
This commit is contained in:
1 parent
dcfc572c02
commit
d113e81506
1 file changed
+61
-27
+61
-27
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user