Skip to content

Commit 8515c3a

Browse files
committed
add ARINC 647A FRED XML parser and example script
1 parent 4366563 commit 8515c3a

4 files changed

Lines changed: 819 additions & 47 deletions

File tree

‎README.md‎

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# **pyarinc — ARINC 717 / ARINC 767 decoding library**
1+
# **pyarinc — ARINC 717 / ARINC 747 / ARINC 767 decoding library**
22

3-
`pyarinc` is a modern, typed Python library for decoding ARINC 717 and ARINC 767 flight‑data recorder formats.
4-
It provides deterministic bit‑extraction utilities, clean parameter models, PRM/VEC configuration parsing, and end‑to‑end decoding into pandas DataFrames.
3+
`pyarinc` is a modern, typed Python library for decoding ARINC 717, ARINC 747, and ARINC 767 flight‑data recorder formats.
4+
It provides deterministic bit‑extraction utilities, clean parameter models, PRM/VEC/FRED configuration parsing, and end‑to‑end decoding into pandas DataFrames.
55

66
The library is designed for analysis pipelines, automated QA tooling, and research workflows that require reliable, test‑covered decoding of FDR/QAR data.
77

@@ -54,7 +54,7 @@ Tests cover:
5454
- Data‑type decoding (BNR, BCD, DISCRETE, PACKED, CHAR/ASCII, UTC, COB)
5555
- Frame reconstruction (717) and frame parsing (767)
5656
- Scheduling and superframes
57-
- PRM/VEC parsing
57+
- PRM/VEC and ARINC 647A FRED XML parsing
5858
- End‑to‑end decoding for both ARINC 717 and ARINC 767
5959

6060
---
@@ -79,7 +79,7 @@ Tests cover:
7979
- Frame boundary detection (sync word, header, trailer)
8080
- Timestamp extraction with wrap‑around handling
8181
- Parameter extraction using **absolute bit indexing** (`start_bit`)
82-
- VEC/PRM‑based configuration
82+
- VEC/PRM/FRED‑based configuration
8383
- Raw‑byte convenience decoding via `decode_raw_bytes()`
8484
- Full data‑type support:
8585
- BNR (signed/unsigned)
@@ -126,9 +126,10 @@ Parameter.from_717(
126126
```
127127

128128
### **ARINC 767 parameters**
129-
- Absolute bit indexing (`start_bit`)
130-
- Optional `frame_id_767` for multi‑frame configurations
131-
- Decoded via `decode_raw_from_bytes()`
129+
130+
* Absolute bit indexing (`start_bit`)
131+
* Optional `frame_id_767` for multi‑frame configurations
132+
* Decoded via `decode_raw_from_bytes()`
132133

133134
```python
134135
Parameter.from_767(
@@ -145,76 +146,90 @@ Parameter.from_767(
145146
## **Configuration Support**
146147

147148
### **ARINC 717 fields**
148-
- subframe index
149-
- word index
150-
- bit offset
151-
- bit length
152-
- rate
153-
- superframe index
154-
- scale and offset
149+
150+
* subframe index
151+
* word index
152+
* bit offset
153+
* bit length
154+
* rate
155+
* superframe index
156+
* scale and offset
155157

156158
### **ARINC 767 fields**
157-
- `start_bit`
158-
- `frame_id_767`
159-
- bit length
160-
- rate
161-
- scale and offset
162-
- COB formulas
163159

164-
Both JSON and text formats are supported.
160+
* `start_bit`
161+
* `frame_id_767`
162+
* bit length
163+
* rate
164+
* scale and offset
165+
* COB formulas
166+
167+
### **ARINC 647A FRED XML Support**
168+
169+
* Schema-agnostic element discovery for Flight Recorder Electronic Documentation
170+
* Parent-child metadata fallback and subparameter unit inheritance
171+
* Strict, warning, and lenient validation modes (`StrictMode`) via `FredXmlParser`
172+
* Automated extraction and mapping into core library parameter models
173+
174+
Both JSON, text, VEC/PRM, and FRED XML formats are supported.
165175

166176
---
167177

168178
## **VEC Parsing Enhancements**
169179

170180
### **ARINC 717**
171-
- `TYPE=`, `SIGNED=`, `SCALE=`, `OFFSET=`
172-
- Bare type tokens (`BNR`, `BCD`, `CHAR`)
173-
- `CONV=` and `OPT=` tokens retained for future use
181+
182+
* `TYPE=`, `SIGNED=`, `SCALE=`, `OFFSET=`
183+
* Bare type tokens (`BNR`, `BCD`, `CHAR`)
184+
* `CONV=` and `OPT=` tokens retained for future use
174185

175186
### **ARINC 767**
176-
- Bare type tokens
177-
- `SIGNED=`, `SCALE=`, `OFFSET=`
178-
- Decimal `FID=` supported
179-
- COB formulas stored without overriding declared type
180-
- Absolute bit indexing preserved
187+
188+
* Bare type tokens
189+
* `SIGNED=`, `SCALE=`, `OFFSET=`
190+
* Decimal `FID=` supported
191+
* COB formulas stored without overriding declared type
192+
* Absolute bit indexing preserved
181193

182194
### **General**
183-
- Unified token handling across 717/767
184-
- Expanded test coverage
185-
- No changes to the public `Parameter` API
195+
196+
* Unified token handling across 717/767
197+
* Expanded test coverage
198+
* No changes to the public `Parameter` API
186199

187200
---
188201

189202
## **Workflow**
190203

191-
1. Load raw data (aligned, bitstream, or ARINC 767 frames)
192-
2. Convert bitstream → aligned frames if needed (717)
193-
3. Load PRM or VEC configuration
194-
4. Construct parameters using `from_717()` or `from_767()`
195-
5. Decode using scheduling and superframe rules
196-
6. Export DataFrame to CSV or Parquet
204+
1. Load raw data (aligned, bitstream, or ARINC 767 frames)
205+
2. Convert bitstream → aligned frames if needed (717)
206+
3. Load PRM, VEC, or ARINC 647A FRED XML configurations
207+
4. Construct parameters using `from_717()` or `from_767()`
208+
5. Decode using scheduling and superframe rules
209+
6. Export DataFrame to CSV or Parquet
197210

198211
Reference examples:
199212

200-
- `examples/process_flight.py` (ARINC 717)
201-
- `examples/process_flight_767.py` (ARINC 767)
213+
* `examples/process_flight.py` (ARINC 717)
214+
* `examples/process_flight_767.py` (ARINC 767)
215+
* `examples/parse_fred_example.py` (ARINC 647A FRED XML Parsing)
202216

203217
---
204218

205219
## **Reference Source**
206220

207221
This project is a clean rewrite inspired by:
208222

209-
<https://github.com/osnosn/FlightDataDecode>
223+
[https://github.com/osnosn/FlightDataDecode](https://github.com/osnosn/FlightDataDecode)
210224

211225
`pyarinc` re‑implements the core logic with a modern architecture, strict typing, and full test coverage.
212226

213227
---
214228

215229
## **Notes**
216-
- No Lua integration
217-
- No legacy `.dat` formats
218-
- No `print()` statements — uses Python logging
219-
- Fully typed (Python 3.12+)
220-
- Deterministic, testable, modular design
230+
231+
* No Lua integration
232+
* No legacy `.dat` formats
233+
* No `print()` statements — uses Python logging
234+
* Fully typed (Python 3.12+)
235+
* Deterministic, testable, modular design

‎examples/parse_fred_example.py‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import logging
2+
import tempfile
3+
import zipfile
4+
from pathlib import Path
5+
6+
from pyarinc.config.fred_parser import FredXmlParser, StrictMode
7+
8+
# Configure logging to see parser warnings and debug details
9+
logging.basicConfig(
10+
level=logging.INFO, format="%(asctime)s [%(levelname)s] %(name)s: %(message)s"
11+
)
12+
13+
14+
def main():
15+
# Path to your ARINC 647A FRED ZIP fixture
16+
zip_path = Path("tests/fixtures/ags767/647a-1.zip")
17+
18+
if not zip_path.exists():
19+
print(f"Error: Fixture not found at {zip_path.absolute()}")
20+
return
21+
22+
# Alternatively, you can use StrictMode.FAIL or StrictMode.LENIENT
23+
strict_setting = StrictMode.WARN
24+
25+
print(f"Opening archive fixture: {zip_path.name}...")
26+
27+
try:
28+
# Extract the inner XML file from the ZIP archive safely
29+
with zipfile.ZipFile(zip_path, "r") as zf:
30+
xml_files = [f for f in zf.namelist() if f.lower().endswith(".xml")]
31+
if not xml_files:
32+
print("Error: No XML files found inside the zip archive.")
33+
return
34+
35+
target_xml = xml_files[0]
36+
print(f"Extracting inner XML file: {target_xml}")
37+
xml_content = zf.read(target_xml)
38+
39+
# Parse via a temporary file so FredXmlParser can read it smoothly
40+
with tempfile.TemporaryDirectory() as tmpdir:
41+
temp_xml_path = Path(tmpdir) / target_xml
42+
temp_xml_path.write_bytes(xml_content)
43+
44+
print(f"Parsing FRED configuration from {target_xml}...")
45+
fred_doc = FredXmlParser.parse_file(
46+
file_path=temp_xml_path, strict_mode=strict_setting
47+
)
48+
49+
# Print extracted aircraft/recorder metadata
50+
print("\n--- Document Metadata ---")
51+
for key, value in fred_doc.metadata.items():
52+
print(f" {key}: {value}")
53+
54+
print(
55+
f"\nSuccessfully extracted {len(fred_doc.parameters)} total parameters (including subparameters)."
56+
)
57+
58+
# Inspect the first few parameters
59+
print("\n--- Sample Parameters ---")
60+
for fp in fred_doc.parameters[:5]:
61+
p = fp.parameter
62+
print(f" - Name: {p.name}")
63+
print(
64+
f" DataType: {p.data_type} | BitLength: {p.bit_length} | StartBit: {p.start_bit}"
65+
)
66+
print(
67+
f" Units: {fp.units} | Resolution: {fp.resolution} | SampleRate: {fp.sample_rate}"
68+
)
69+
if fp.description:
70+
print(f" Description: {fp.description}")
71+
print("-" * 40)
72+
73+
# Optional: Run manual validation if using LENIENT or WARN mode
74+
fred_doc.validate()
75+
print("\nValidation check passed successfully!")
76+
77+
except Exception as exc:
78+
print(f"\nFailed to parse FRED file due to error: {exc}")
79+
80+
81+
if __name__ == "__main__":
82+
main()

0 commit comments

Comments
 (0)