diff --git a/PythonPlugins/PI_XSayATC.py b/PythonPlugins/PI_XSayATC.py index 4081d14..b61522f 100644 --- a/PythonPlugins/PI_XSayATC.py +++ b/PythonPlugins/PI_XSayATC.py @@ -214,6 +214,29 @@ XPLM_TYPE_DATA = 32 # Ile slotow LiveTraffic sprawdzac (domyslnie tablice maja sporo slotow). NUM_LT_SLOTS = 64 +# Mapa fazy lotu LiveTraffic (enum LTFlightPhase z LTAPI.h). +# Kluczowe dla logiki "pas zajety": fazy startu (20-24) i ladowania (70-74). +LT_PHASE_NAMES = { + 0: "Unknown", + 5: "Parked", + 10: "Taxi", + 20: "Take Off", + 21: "Take Off Roll", + 22: "Rotate", + 23: "Lift Off", + 24: "Initial Climb", + 30: "Climb", + 40: "Cruise", + 50: "Descend", + 60: "Approach", + 61: "Final", + 70: "Landing", + 71: "Flare", + 72: "Touch Down", + 73: "Roll Out", + 74: "Stopped on Runway", +} + class XSayATC: def __init__(self): @@ -1301,6 +1324,55 @@ class XSayATC: except Exception: return [] + def _lt_read_ac_scalar(self, index): + """Ustawia ac/key = index i czyta skalarne phase/on_gnd/lat/lon/alt. + + ac/key to indeks (0..num-1): po zapisie LiveTraffic wybiera samolot, + a skalarne ac/* zwracaja jego dane. Zwraca dict lub None.""" + if self._lt_key_ref is None: + return None + try: + xp.setDatai(self._lt_key_ref, int(index)) + def gi(ref): + return int(xp.getDatai(ref)) if ref is not None else None + def gf(ref): + return float(xp.getDataf(ref)) if ref is not None else None + # key po zapisie to Mode-S hex danego samolotu + key = gi(self._lt_key_ref) + return { + "key": key, + "phase": gi(self._lt_phase_ref), + "on_gnd": gi(self._lt_on_gnd_ref), + "lat": gf(self._lt_lat_ref), + "lon": gf(self._lt_lon_ref), + "alt": gf(self._lt_alt_ref), + "heading": gf(self._lt_heading_ref), + "speed": gf(self._lt_speed_ref), + "vsi": gf(self._lt_vsi_ref), + } + except Exception as e: + xp.log(f"[XSayATC] Blad czytania ac/key={index}: {e}") + return None + + def _lt_enumerate(self): + """Zwraca liste dictow z danymi wszystkich samolotow LiveTraffic. + + Iteruje po indeksie 0..num-1 (ac/key = indeks, potem skalary).""" + if not self._lt_available or self._lt_key_ref is None: + return [] + try: + num = int(xp.getDatai(self._lt_num_ref)) + except Exception: + num = 0 + if num <= 0: + return [] + out = [] + for i in range(min(num, NUM_LT_SLOTS)): + d = self._lt_read_ac_scalar(i) + if d is not None: + out.append(d) + return out + def _lt_type_str(self, ref): """Zwraca opis typu datarefu (do debugu).""" if ref is None: @@ -1325,10 +1397,7 @@ class XSayATC: return ",".join(parts) if parts else f"({t})" def _collect_livetraffic_debug(self): - """Zwraca liste linii z surowymi danymi LiveTraffic (do podgladu/debug). - - Pokazuje typy datarefow + probki wartosci, zeby ustalic jak czytac - (scalar+key vs bulk binary).""" + """Zwraca liste linii z danymi LiveTraffic (enumeracja po indeksie ac/key).""" if not self._lt_available: return ["LiveTraffic: brak datarefow livetraffic/ac/*"] num = 0 @@ -1336,45 +1405,24 @@ class XSayATC: num = int(xp.getDatai(self._lt_num_ref)) except Exception: num = 0 - lines = [f"LiveTraffic: {num} samolotow"] - # Typy datarefow - refs = [ - ("ac/key", self._lt_key_ref), - ("ac/num", self._lt_num_ref), - ("ac/phase", self._lt_phase_ref), - ("ac/on_gnd", self._lt_on_gnd_ref), - ("ac/lat", self._lt_lat_ref), - ("ac/lon", self._lt_lon_ref), - ("ac/alt", self._lt_alt_ref), - ("ac/heading", self._lt_heading_ref), - ("ac/speed", self._lt_speed_ref), - ("ac/vsi", self._lt_vsi_ref), - ("ac/dist", self._lt_dist_ref), - ("ac/bearing", self._lt_bearing_ref), - ("bulk/quick", self._lt_bulk_quick_ref), - ("bulk/expensive", self._lt_bulk_expensive_ref), - ] - lines.append("Typy datarefow:") - for name, ref in refs: - lines.append(f" {name}: {self._lt_type_str(ref)}") + ac = self._lt_enumerate() + if not ac: + lines.append("(brak danych — sprawdz, czy ac/key daje sie iterowac po 0..num-1)") + return lines - # Probka odczytu key (string/hex) - if self._lt_key_ref is not None: - try: - key_s = xp.getDatas(self._lt_key_ref) - except Exception as e: - key_s = f"(blad: {e})" - lines.append(f"ac/key wartosc: {key_s!r}") - - # Probka bulk quick (binary) - if self._lt_bulk_quick_ref is not None: - try: - nbytes = xp.getDatab(self._lt_bulk_quick_ref) - lines.append(f"bulk/quick: {nbytes} bajtow (getDatab z count=-1)") - except Exception as e: - lines.append(f"bulk/quick blad: {e}") + lines.append(f"Dane {len(ac)} samolotow (ac/key -> phase, on_gnd, lat, lon, alt):") + for d in ac[:30]: + ph = d.get("phase") + ph_s = LT_PHASE_NAMES.get(ph, str(ph)) if ph is not None else "?" + key = d.get("key") + key_s = f"0x{key:X}" if isinstance(key, int) else str(key) + lines.append( + f" key={key_s} phase={ph}({ph_s}) on_gnd={d['on_gnd']} " + f"lat={d['lat']} lon={d['lon']} alt={d['alt']} " + f"hdg={d['heading']} spd={d['speed']} vsi={d['vsi']}" + ) return lines