Skip to content

Commit 7ca1d65

Browse files
Initial commit of prototype converter for Rohde and Schwarz IQ.TAR files. See TODOs and project page for more detail.
1 parent 241ed97 commit 7ca1d65

2 files changed

Lines changed: 597 additions & 18 deletions

File tree

sigmf/convert/__main__.py

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import argparse
1010
import logging
11+
import sys
1112
import textwrap
1213
from pathlib import Path
1314

@@ -16,7 +17,8 @@
1617
from ..utils import get_magic_bytes
1718
from .blue import blue_to_sigmf
1819
from .wav import wav_to_sigmf
19-
20+
from .signalhound import signalhound_to_sigmf
21+
from .rohdeschwarz import rohdeschwarz_to_sigmf
2022

2123
def main() -> None:
2224
"""
@@ -60,8 +62,8 @@ def main() -> None:
6062
exclusive_group.add_argument(
6163
"--ncd", action="store_true", help="Output .sigmf-meta only and process as a Non-Conforming Dataset (NCD)"
6264
)
63-
parser.add_argument("--overwrite", action="store_true", help="Overwrite existing output files")
6465
parser.add_argument("--version", action="version", version=f"%(prog)s v{toolversion}")
66+
6567
args = parser.parse_args()
6668

6769
level_lut = {
@@ -85,33 +87,47 @@ def main() -> None:
8587
if output_path.is_dir():
8688
raise SigMFConversionError(f"Output path must be a filename, not a directory: {output_path}")
8789

90+
if input_path.suffix in [".tar"]:
91+
# iq.tar file extensions are used by Rohde & Schwarz for their IQ data, but the .tar extension is also used by other formats.
92+
# But as it truns out the tar files contain different file names, so may need to parse the tar file
93+
# to determine if it is a Rohde & Schwarz file or not.
94+
_ = rohdeschwarz_to_sigmf(rohdeschwarz_path=input_path, out_path=output_path, create_archive=args.archive, create_ncd=args.ncd)
95+
return
96+
8897
# detect file type using magic bytes (same logic as fromfile())
8998
magic_bytes = get_magic_bytes(input_path, count=4, offset=0)
9099

91100
if magic_bytes == b"RIFF":
92101
# WAV file
93-
_ = wav_to_sigmf(
94-
wav_path=input_path,
95-
out_path=output_path,
96-
create_archive=args.archive,
97-
create_ncd=args.ncd,
98-
overwrite=args.overwrite,
99-
)
102+
_ = wav_to_sigmf(wav_path=input_path, out_path=output_path, create_archive=args.archive, create_ncd=args.ncd)
100103

101104
elif magic_bytes == b"BLUE":
102105
# BLUE file
103-
_ = blue_to_sigmf(
104-
blue_path=input_path,
105-
out_path=output_path,
106-
create_archive=args.archive,
107-
create_ncd=args.ncd,
108-
overwrite=args.overwrite,
109-
)
110-
106+
_ = blue_to_sigmf(blue_path=input_path, out_path=output_path, create_archive=args.archive, create_ncd=args.ncd)
107+
108+
## TODO: Determine if there is a better way to integrate Signal Hound files.
109+
elif magic_bytes == b"<?xm": # <?xml version="1.0" encoding="UTF-8"?> <SignalHoundIQFile Version="1.0">
110+
# Signal Hound Spike 1.0 file
111+
# Of the 66 Byte string move 43 bytes in to skip the XML declaration
112+
# and get to the root element and take 18 chars for a more specific detection of Signal Hound Spike files
113+
signalhound_expanded_magic_bytes = get_magic_bytes(input_path, count=17, offset=40)
114+
rohde_schwarz_expanded_magic_bytes = get_magic_bytes(input_path, count=20, offset=314) # <RS_IQ_TAR_FileFormat Version="1.0">
115+
if signalhound_expanded_magic_bytes == b"SignalHoundIQFile":
116+
_ = signalhound_to_sigmf(signalhound_path=input_path, out_path=output_path, create_archive=args.archive, create_ncd=args.ncd)
117+
else:
118+
raise SigMFConversionError(
119+
f"Unsupported XML file format. Expanded R&S Magic bytes: {rohde_schwarz_expanded_magic_bytes}. "
120+
f"Unsupported XML file format. Expanded SignalHound Magic bytes: {signalhound_expanded_magic_bytes}. "
121+
f"Supported formats for conversion are WAV, BLUE/Platinum and Signal Hound Spike."
122+
)
123+
124+
125+
111126
else:
127+
112128
raise SigMFConversionError(
113129
f"Unsupported file format. Magic bytes: {magic_bytes}. "
114-
f"Supported formats for conversion are WAV and BLUE/Platinum."
130+
f"Supported formats for conversion are WAV, BLUE/Platinum, Rohde & Schwarz IQ.TAR, and Signal Hound Spike."
115131
)
116132

117133

0 commit comments

Comments
 (0)