Commit 956c7996 authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema
Browse files

Remove responsibilities from makesigmf

parent 3ff4c433
......@@ -14,13 +14,13 @@ from argparse import ArgumentParser
from telescope import Telescope
def make_sigmf(iqfile, no_rename=False):
def make_sigmf(metadatafilename, no_rename=False):
# time_first_sample, rate, frequency, rx_gain, bandwidth, reference, time_source, format, channel, antenna, sdr_type
filename_metadata = iqfile + ".metadata"
with open(filename_metadata, "r") as file_metadata:
_ = file_metadata.readline()
metadata = file_metadata.readline().strip().split(", ")
with open(metadatafilename, "r") as metadatafile:
_ = metadatafile.readline()
metadata = metadatafile.readline().strip().split(", ")
time_first_sample, rate, frequency, rx_gain, bandwidth, reference, time_source, dataformat, channel, antenna, sdr_type, num_samples = metadata
rate = float(rate)
frequency = float(frequency)
......@@ -37,7 +37,7 @@ def make_sigmf(iqfile, no_rename=False):
else:
datatype = "unknown"
newfilename = iqfile.replace(".iq", "") + "_" + \
newfilename = metadatafilename.replace(".metadata", "") + "_" + \
f"{frequency/1e6:.3f}MHz" + \
f"_{rate/1e6:.1f}Msps" + \
"_" + datatype + \
......@@ -155,11 +155,7 @@ def make_sigmf(iqfile, no_rename=False):
with open(sigmfname_meta, "w") as sigmfmeta:
json.dump(meta, sigmfmeta, indent=4)
if not no_rename:
os.rename(iqfile, newfilename)
os.remove(filename_metadata)
print(sigmfname_meta)
return sigmfname_meta
def is_valid_file(parser, arg):
......@@ -173,8 +169,7 @@ if __name__ == "__main__":
parser = ArgumentParser(
description="Make SIGMF metadata out of IQ dump, "
"metadata CSV and a connection to the telescope console")
parser.add_argument("iqfile",
metavar="IQ file",
parser.add_argument("metadatafile",
type=lambda x: is_valid_file(parser, x))
parser.add_argument(
"-n",
......@@ -184,4 +179,4 @@ if __name__ == "__main__":
args = parser.parse_args()
make_sigmf(args.iqfile, no_rename=args.no_rename)
make_sigmf(args.metadatafile, no_rename=args.no_rename)
#!/usr/bin/env python
#!/usr/bin/env python3
from argparse import ArgumentParser
import subprocess
import os
from make_sigmf import make_sigmf
if __name__ == "__main__":
parser = ArgumentParser(description="This application streams data from a single channel of a USRP device to a file; it wraps a C++ program")
......@@ -46,4 +49,15 @@ if __name__ == "__main__":
else:
arg_list += ["--" + key, str(value)]
subproces.call(["usrp_to_file"] + arg_list)
try:
exit_code = subprocess.call(["./usrp_to_file"] + arg_list)
except KeyboardInterrupt:
if os.path.isfile(args.file):
exit_code = 0
else:
raise
if exit_code != 0:
raise RuntimeError("Exit code of usrp_to_file was " + exit_code)
sigmf_filename = make_sigmf(args.file + ".metadata")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment