Skip to content

Commit 60384e9

Browse files
committed
integrate PRM/JSON configuration parser into ARINC 717 batch script
1 parent 14c3fe5 commit 60384e9

1 file changed

Lines changed: 30 additions & 11 deletions

File tree

‎examples/process_flight_717_batch.py‎

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1+
from __future__ import annotations
2+
13
import logging
24
import zipfile
35
from pathlib import Path
46

57
from pyarinc.arinc717.decoder import Arinc717Decoder
8+
from pyarinc.arinc717.prm_parser import parse_prm_file, prm_to_parameters
69
from pyarinc.config.fred_parser import FredXmlParser, StrictMode
710
from pyarinc.io.csv_export import export_csv
811
from pyarinc.io.datafile import read_binary
912
from pyarinc.io.parquet_export import export_parquet
1013
from pyarinc.models.parameter import Parameter
1114

12-
# Configure logging
1315
logging.basicConfig(
1416
level=logging.INFO, format="%(asctime)s [%(levelname)s] %(name)s: %(message)s"
1517
)
1618
logger = logging.getLogger(__name__)
1719

1820

1921
def process_zip_archive(zip_path: Path, output_dir: Path) -> None:
20-
"""Extract, dynamically parse configuration, and decode ARINC 717 data inside a ZIP archive."""
22+
"""Extract, dynamically parse configuration (XML or PRM/JSON), and decode ARINC 717 data inside a ZIP archive."""
2123
print(f"\nProcessing archive: {zip_path.name}")
2224

2325
with zipfile.ZipFile(zip_path, "r") as zf:
@@ -27,7 +29,7 @@ def process_zip_archive(zip_path: Path, output_dir: Path) -> None:
2729
extract_dir = output_dir / "extracted" / zip_path.stem
2830
extract_dir.mkdir(parents=True, exist_ok=True)
2931

30-
# Extract all contents so configuration and raw.dat are accessible together
32+
# Extract all contents so configuration files and raw.dat are accessible together
3133
zf.extractall(extract_dir)
3234

3335
# 1. Locate raw.dat for binary flight data
@@ -38,14 +40,14 @@ def process_zip_archive(zip_path: Path, output_dir: Path) -> None:
3840
)
3941
return
4042

41-
# 2. Try loading configuration XML file if available
42-
xml_files = list(extract_dir.glob("*.xml"))
4343
parameters = []
4444

45+
# 2. Try loading configuration XML file if available
46+
xml_files = list(extract_dir.glob("*.xml"))
4547
if xml_files:
4648
target_xml = xml_files[0]
4749
print(
48-
f"-> Found configuration file: {target_xml.name}. Parsing parameters..."
50+
f"-> Found XML configuration file: {target_xml.name}. Parsing parameters..."
4951
)
5052
try:
5153
fred_doc = FredXmlParser.parse_file(
@@ -58,14 +60,31 @@ def process_zip_archive(zip_path: Path, output_dir: Path) -> None:
5860
]
5961
if parameters:
6062
print(
61-
f" Successfully loaded {len(parameters)} parameters from configuration."
63+
f" Successfully loaded {len(parameters)} parameters from XML configuration."
6264
)
63-
else:
64-
print(f" XML file is metadata-only (0 parameters found).")
6565
except Exception as e:
6666
print(f" Warning: Failed to parse XML configuration ({e}).")
6767

68-
# 3. Fallback to an expanded list of common flight parameters if XML didn't provide any
68+
# 3. Try loading PRM or JSON configuration files if no XML parameters were found
69+
if not parameters:
70+
prm_files = list(extract_dir.glob("*.prm")) + list(extract_dir.glob("*.json"))
71+
if prm_files:
72+
target_prm = prm_files[0]
73+
print(
74+
f"-> Found PRM/JSON configuration file: {target_prm.name}. Parsing mapping..."
75+
)
76+
try:
77+
prm_mapping = parse_prm_file(target_prm)
78+
param_dict = prm_to_parameters(prm_mapping)
79+
parameters = list(param_dict.values())
80+
if parameters:
81+
print(
82+
f" Successfully loaded {len(parameters)} parameters from PRM configuration."
83+
)
84+
except Exception as e:
85+
print(f" Warning: Failed to parse PRM configuration ({e}).")
86+
87+
# 4. Fallback to default hardcoded flight parameters if no config files found
6988
if not parameters:
7089
print("-> Using expanded default flight parameters mapping (Fallback).")
7190
parameters = [
@@ -119,7 +138,7 @@ def process_zip_archive(zip_path: Path, output_dir: Path) -> None:
119138
),
120139
]
121140

122-
# 4. Decode binary stream using parameters
141+
# 5. Decode binary stream using parameters
123142
print(f"-> Decoding raw.dat...")
124143
try:
125144
raw_bytes = read_binary(raw_dat_path)

0 commit comments

Comments
 (0)