[bfab5ea] | 1 | import sys
|
---|
| 2 | import re
|
---|
| 3 | import sqlite3
|
---|
| 4 | import argparse
|
---|
| 5 | from pathlib import Path
|
---|
| 6 | from ammosreader.AmmosIFReader import AmmosIFReader
|
---|
[6808525] | 7 | from ammosreader.PPDWReader import PPDWReader
|
---|
[bfab5ea] | 8 |
|
---|
| 9 | parser = argparse.ArgumentParser()
|
---|
| 10 | parser.add_argument('-s', '--source', required=True, help='specify source for given signal')
|
---|
| 11 | parser.add_argument('-i', '--input-dir', required=True, help='specify source directory')
|
---|
| 12 | parser.add_argument('-o', '--output-file', required=True, help='specify sqlite3 database file')
|
---|
| 13 | parser.add_argument('-n', '--signal-number', required=True, help='specify number for signal')
|
---|
| 14 | parser.add_argument('-c', '--code', required=True, help='specify code for signal')
|
---|
| 15 |
|
---|
| 16 | args = parser.parse_args()
|
---|
| 17 |
|
---|
| 18 | code = args.code.upper()
|
---|
| 19 | signal_number = args.signal_number
|
---|
| 20 | input_dir = Path(args.input_dir)
|
---|
| 21 | sqlite3_file = Path(args.output_file)
|
---|
| 22 |
|
---|
| 23 | if not re.match('[A-Z][0-9]{3}[A-Z]', code):
|
---|
| 24 | print("ELINT-Code incorrect")
|
---|
| 25 | sys.exit(1)
|
---|
| 26 |
|
---|
| 27 | if not re.match('[0-9]{4}', signal_number):
|
---|
| 28 | print("Signal number incorrect")
|
---|
| 29 | sys.exit(1)
|
---|
| 30 |
|
---|
| 31 | if not input_dir.is_dir():
|
---|
| 32 | print("Input dir invalid")
|
---|
| 33 | sys.exit(1)
|
---|
| 34 |
|
---|
| 35 | dir_name = input_dir.name
|
---|
| 36 |
|
---|
| 37 | files_inside = [each for each in (input_dir.iterdir()) if (each.suffix in ['.idx', '.iqdw', '.ppdw'] and each.stem == dir_name)]
|
---|
| 38 |
|
---|
| 39 | if len(files_inside) != 3:
|
---|
| 40 | print(".idx, .iqdw or .ppdw file missing in", input_dir)
|
---|
| 41 | sys.exit(1)
|
---|
| 42 |
|
---|
| 43 | iqdw_file = (input_dir / input_dir.stem).with_suffix('.iqdw')
|
---|
| 44 | ppdw_file = (input_dir / input_dir.stem).with_suffix('.ppdw')
|
---|
| 45 | idx_file = (input_dir / input_dir.stem).with_suffix('.idx')
|
---|
| 46 |
|
---|
| 47 | #if not sqlite3_file.is_file():
|
---|
| 48 | # print("Sqlite3 database file not found at", sqlite3_file)
|
---|
| 49 | # sys.exit(1)
|
---|
| 50 |
|
---|
| 51 | try:
|
---|
| 52 | connection = sqlite3.connect(str(sqlite3_file))
|
---|
| 53 | cursor = connection.cursor()
|
---|
| 54 | except Exception:
|
---|
| 55 | print("Can not connect to database file", str(sqlite3_file))
|
---|
| 56 | # sys.exit(1)
|
---|
| 57 |
|
---|
[94f7c24] | 58 | ammos_if_reader = AmmosIFReader(str(iqdw_file))
|
---|
| 59 | ammos_if_reader.read_all_frames_left()
|
---|
| 60 | # for each_frame in ammos_if_reader.container.global_frames:
|
---|
| 61 | # print(each_frame)
|
---|
[6808525] | 62 |
|
---|
| 63 | ppdw_reader = PPDWReader(ppdw_file)
|
---|
| 64 | ppdw_reader.read_all_frames_left()
|
---|
| 65 | print(ppdw_reader.container)
|
---|