Skip to content

Commit eb3aed0

Browse files
committed
add AGS fixture folder, minimal AGS I/O module, and basic AGS integration tests
1 parent ecaeef8 commit eb3aed0

6 files changed

Lines changed: 241 additions & 0 deletions

File tree

‎pyarinc/io/ags.py‎

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
from __future__ import annotations
2+
3+
import zipfile
4+
from dataclasses import dataclass
5+
from pathlib import Path
6+
7+
8+
@dataclass
9+
class AircraftRecord:
10+
tail: str
11+
reception_date: str
12+
airline: str
13+
ac_type: str
14+
ac_type_wired_no: str
15+
ac_ident: str
16+
ac_serial_number: str
17+
ac_in_operation: str
18+
qar_model: str
19+
qar2_model: str
20+
fdr_model: str
21+
fdr2_model: str
22+
qar_version: str
23+
qar2_version: str
24+
fdr_version: str
25+
fdr2_version: str
26+
qar_link: str
27+
qar2_link: str
28+
fdr_link: str
29+
fdr2_link: str
30+
qar_serial: str
31+
qar2_serial: str
32+
fdr_serial: str
33+
fdr2_serial: str
34+
eng1_serial: str
35+
eng2_serial: str
36+
eng3_serial: str
37+
eng4_serial: str
38+
eng1_install_date: str
39+
eng2_install_date: str
40+
eng3_install_date: str
41+
eng4_install_date: str
42+
eng1_type: str
43+
eng2_type: str
44+
eng3_type: str
45+
eng4_type: str
46+
# we won’t model all remaining fields; keep raw for now
47+
raw_fields: list[str]
48+
49+
50+
def extract_vec_from_ags_bundle(path: Path) -> dict[str, bytes]:
51+
"""
52+
Extract files from an AGS .vec bundle (ZIP archive).
53+
54+
Returns a mapping {name: data}, typically including .add/.vec/.air.
55+
"""
56+
out: dict[str, bytes] = {}
57+
with zipfile.ZipFile(path, "r") as zf:
58+
for name in zf.namelist():
59+
out[name] = zf.read(name)
60+
return out
61+
62+
63+
def find_text_vec_file(files: dict[str, bytes]) -> tuple[str, str] | None:
64+
"""
65+
Heuristic: pick the first inner file that looks like a text VEC/PRM file.
66+
"""
67+
for name, data in files.items():
68+
# skip obvious binaries
69+
if data.startswith(b"PK\x03\x04"):
70+
continue
71+
text = data.decode("utf-8", errors="ignore")
72+
if "W" in text and "B" in text and "SF=" in text:
73+
return name, text
74+
return None
75+
76+
77+
def parse_aircraft_air(path: Path) -> list[AircraftRecord]:
78+
"""
79+
Parse an AGS aircraft.air file (UTF-16LE, tab-separated, with // comments).
80+
"""
81+
raw = path.read_bytes()
82+
text = raw.decode("utf-16-le", errors="ignore")
83+
84+
lines = [
85+
line.strip()
86+
for line in text.splitlines()
87+
if line.strip() and not line.strip().startswith("//")
88+
]
89+
if not lines:
90+
return []
91+
92+
header = lines[0].split("\t")
93+
records: list[AircraftRecord] = []
94+
95+
for row in lines[1:]:
96+
cols = row.split("\t")
97+
# pad to header length
98+
if len(cols) < len(header):
99+
cols += [""] * (len(header) - len(cols))
100+
101+
# map the first N fields we care about
102+
rec = AircraftRecord(
103+
tail=cols[0],
104+
reception_date=cols[1],
105+
airline=cols[2],
106+
ac_type=cols[3],
107+
ac_type_wired_no=cols[4],
108+
ac_ident=cols[5],
109+
ac_serial_number=cols[6],
110+
ac_in_operation=cols[7],
111+
qar_model=cols[8],
112+
qar2_model=cols[9],
113+
fdr_model=cols[10],
114+
fdr2_model=cols[11],
115+
qar_version=cols[12],
116+
qar2_version=cols[13],
117+
fdr_version=cols[14],
118+
fdr2_version=cols[15],
119+
qar_link=cols[16],
120+
qar2_link=cols[17],
121+
fdr_link=cols[18],
122+
fdr2_link=cols[19],
123+
qar_serial=cols[20],
124+
qar2_serial=cols[21],
125+
fdr_serial=cols[22],
126+
fdr2_serial=cols[23],
127+
eng1_serial=cols[24],
128+
eng2_serial=cols[25],
129+
eng3_serial=cols[26],
130+
eng4_serial=cols[27],
131+
eng1_install_date=cols[28],
132+
eng2_install_date=cols[29],
133+
eng3_install_date=cols[30],
134+
eng4_install_date=cols[31],
135+
eng1_type=cols[32],
136+
eng2_type=cols[33],
137+
eng3_type=cols[34],
138+
eng4_type=cols[35],
139+
raw_fields=cols,
140+
)
141+
records.append(rec)
142+
143+
return records

‎tests/fixtures/ags717/010888.vec‎

93.9 KB
Binary file not shown.

‎tests/fixtures/ags717/README.md‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## vec directory
2+
3+
Used to store:
4+
5+
- `xxxxxx.vec` — DataVer, Parameter, Data Frame configuration files for ARINC 573 / ARINC 717 PCM
6+
- `aircraft.air` — aircraft configuration file
7+
8+
Both `vec` and `air` files come from the AGS software.
9+
10+
Example:
11+
12+
<img src="https://github.com/osnosn/FlightDataDecode/raw/main/wgl/vec/readme01.png" width="300" />
13+
14+
---
15+
16+
AirFASE can export four types of files: FAP, Frame, PRM, FRED.
17+
18+
- **FAP** and **Frame** are encrypted. They cannot be decoded.
19+
- **PRM** is a text file. Its structure is different from the format used here. The decoding logic is similar, but this program cannot use PRM directly. You can write your own parser if needed.
20+
See also: [osnosn/FlightDataDecode2](https://github.com/osnosn/FlightDataDecode2/)
21+
- **FRED** is undocumented. Content unknown.
22+
23+
Other AirFASE screens:
24+
25+
<img src="https://github.com/osnosn/FlightDataDecode/raw/main/wgl/vec/airfase-app.jpg" width="300" />
26+
27+
<img src="https://github.com/osnosn/FlightDataDecode/raw/main/wgl/vec/airfase-FAP.png" width="500" />
28+
29+
<img src="https://github.com/osnosn/FlightDataDecode/raw/main/wgl/vec/airfase-Frame.png" width="300" />
30+
31+
<img src="https://github.com/osnosn/FlightDataDecode/raw/main/wgl/vec/airfase-PRM-header.png" width="300" />
32+
33+
<img src="https://github.com/osnosn/FlightDataDecode/raw/main/wgl/vec/airfase-regular.png" width="500" />
34+
35+
<img src="https://github.com/osnosn/FlightDataDecode/raw/main/wgl/vec/airfase-superframe.png" width="500" />

‎tests/fixtures/ags717/aircraft.air‎

5.45 KB
Binary file not shown.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from pathlib import Path
2+
3+
from pyarinc.io.ags import extract_vec_from_ags_bundle, parse_aircraft_air
4+
5+
FIXTURE_DIR = Path(__file__).parent / "fixtures" / "ags717"
6+
7+
8+
def test_ags_bundle_is_zip_and_contains_files():
9+
"""AGS .vec bundles are ZIP archives containing multiple files."""
10+
path = FIXTURE_DIR / "010888.vec"
11+
files = extract_vec_from_ags_bundle(path)
12+
13+
assert isinstance(files, dict)
14+
assert len(files) > 0
15+
16+
# At least one inner file must exist
17+
assert any(files.keys())
18+
19+
20+
def test_ags_bundle_contains_no_plaintext_vec():
21+
"""
22+
Real AGS .vec bundles usually contain ONLY binary/encrypted files.
23+
There is no plaintext VEC inside the ZIP.
24+
"""
25+
path = FIXTURE_DIR / "010888.vec"
26+
files = extract_vec_from_ags_bundle(path)
27+
28+
# Assert that none of the inner files look like a text VEC
29+
for name, data in files.items():
30+
text = data.decode("utf-8", errors="ignore")
31+
assert not ("W" in text and "B" in text and "SF=" in text)
32+
33+
34+
def test_parse_aircraft_air_utf16():
35+
"""Ensure aircraft.air is readable and parsed correctly."""
36+
path = FIXTURE_DIR / "aircraft.air"
37+
records = parse_aircraft_air(path)
38+
39+
assert isinstance(records, list)
40+
assert len(records) > 0
41+
42+
# Check that known tails appear
43+
tails = {r.tail for r in records}
44+
assert "B-8888" in tails

‎tests/test_fixtures_arinc717.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from pathlib import Path
2+
3+
FIXTURE_DIR = Path(__file__).parent / "fixtures" / "ags717"
4+
5+
6+
def test_fixture_files_exist():
7+
assert (FIXTURE_DIR / "010888.vec").exists()
8+
assert (FIXTURE_DIR / "aircraft.air").exists()
9+
assert (FIXTURE_DIR / "README.md").exists()
10+
11+
12+
def test_010888_vec_is_zip():
13+
data = (FIXTURE_DIR / "010888.vec").read_bytes()
14+
assert data.startswith(b"PK\x03\x04")
15+
16+
17+
def test_aircraft_air_is_utf16():
18+
data = (FIXTURE_DIR / "aircraft.air").read_bytes()
19+
assert data.startswith(b"\xff\xfe")

0 commit comments

Comments
 (0)