1+ from __future__ import annotations
2+
13import logging
24import zipfile
35from pathlib import Path
46
57from pyarinc .arinc717 .decoder import Arinc717Decoder
8+ from pyarinc .arinc717 .prm_parser import parse_prm_file , prm_to_parameters
69from pyarinc .config .fred_parser import FredXmlParser , StrictMode
710from pyarinc .io .csv_export import export_csv
811from pyarinc .io .datafile import read_binary
912from pyarinc .io .parquet_export import export_parquet
1013from pyarinc .models .parameter import Parameter
1114
12- # Configure logging
1315logging .basicConfig (
1416 level = logging .INFO , format = "%(asctime)s [%(levelname)s] %(name)s: %(message)s"
1517)
1618logger = logging .getLogger (__name__ )
1719
1820
1921def 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"\n Processing 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