record.py 3.96 KB
Newer Older
1
#!/usr/bin/env python3
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
2
3
4

from argparse import ArgumentParser
import subprocess
5
import os
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
6
from make_sigmf import make_sigmf, dataformat_to_str
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
7
from datetime import datetime
8

Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
9
10
11
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")
    parser.add_argument("--args", help="multi uhd device address args", default="")
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
12
    parser.add_argument("--file", help="name of the file to write binary samples to (default deduced from date)")
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
13
14
15
16
17
18
19
20
21
22
23
    parser.add_argument("--type", help="sample type", choices=["double", "float", "short"], default="short")
    parser.add_argument("--nsamps", help="total number of samples to receive", default=0)
    parser.add_argument("--duration", help="total number of seconds to receive", default=0)
    parser.add_argument("--spb", help="sample per buffer", default=10000)
    parser.add_argument("--rate", help="rate of incoming samples", default=1e6)
    parser.add_argument("--freq", help="RF center frequency in Hz", required=True, default=0.0)
    parser.add_argument("--lo-offset", help="offset for frontent LO in Hz (optional)")
    parser.add_argument("--gain", help="gain for the RF chain", required=True, default=40)
    parser.add_argument("--ant", help="antena selection", default="TX/RX")
    parser.add_argument("--subdev", help="subdevice specification", default="")
    parser.add_argument("--channel", help="which channel to use", default=0)
24
    parser.add_argument("--bw", help="analog frontend filter bandwidth in Hz")
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
25
    parser.add_argument("--ref", help="reference source", choices=["internal", "external", "mimo", "gpsdo"], default="gpsdo")
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
26
27
28
29
30
    parser.add_argument("--wirefmt", help="wire format", choices=["sc8", "sc16", "s16"])
    parser.add_argument("--setup", help="seconds of setup time", default=1.0)
    parser.add_argument("--progress", help="periodically display short-term bandwidth", action="store_true")
    parser.add_argument("--stats", help="show average bandwidth on exit", action="store_true")
    parser.add_argument("--pps", help="use external pps signal", action="store_true")
31
    parser.add_argument("--int-second", help="align start of reception to integer second", action="store_true")
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
32
33
34
35
36
37
38
    parser.add_argument("--null", help="run without writing to file", action="store_true")
    parser.add_argument("--continue", help="don't abort on a bad packet", action="store_true")
    parser.add_argument("--ski-lo", help="skip checking LO lock status", action="store_true")
    parser.add_argument("--int-n", help="tune USRP with integer-N tuning", action="store_true")

    args = parser.parse_args()

Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
39
    if args.file is None:
40
41
42
43
44
        datatype = dataformat_to_str(args.type)
        args.file = f"camras-{datetime.utcnow():%Y_%m_%d_%H_%M_%S}" + \
                    f"_{float(args.freq)/1e6:.3f}MHz" + \
                    f"_{float(args.rate)/1e6:.1f}Msps" + \
                    f"_{datatype}.sigmf-data"
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
45

Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
46
47
48
49
    args_dict = vars(args)

    bool_args = [key for key, value in args_dict.items() if value == True and isinstance(value, bool)]

Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
50
51
52
    print("Running set_70cm_device.py B210")
    subprocess.check_output(["set_70cm_device.py", "B210"])

Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
53
54
55
56
    arg_list = []
    for key, value in args_dict.items():
        if isinstance(value, bool):
            if value == True:
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
57
                arg_list += ["--" + key.replace('_', '-')]
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
58
59
60
        elif value == "" or value is None:
            continue
        else:
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
61
            arg_list += ["--" + key.replace('_', '-'), str(value)]
Tammo Jan Dijkema's avatar
Tammo Jan Dijkema committed
62

63
    print("Running usrp_to_file " + " ".join(arg_list))
64
    try:
65
        exit_code = subprocess.call(["usrp_to_file"] + arg_list)
66
67
68
69
70
71
72
73
74
    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)

75
    sigmf_meta_filename = make_sigmf(args.file + ".metadata")
76
77
78
79

    os.remove(args.file + ".metadata")

    print("Created " + sigmf_meta_filename)