|
| 1 | +from .pybladerf_tools import ( |
| 2 | + pybladerf_sweep, |
| 3 | + pybladerf_info, |
| 4 | +) |
| 5 | +from .pylibbladerf import pybladerf |
| 6 | +import argparse |
| 7 | +import sys |
| 8 | + |
| 9 | + |
| 10 | +def main(): |
| 11 | + parser = argparse.ArgumentParser( |
| 12 | + description="python_bladerf is a Python wrapper for libbladerf. It also contains some additional tools.", |
| 13 | + usage="python_bladerf [-h] {info, sweep} ..." |
| 14 | + ) |
| 15 | + subparsers = parser.add_subparsers(dest="command", title="Available commands") |
| 16 | + subparsers.required = True |
| 17 | + pybladerf_info_parser = subparsers.add_parser( |
| 18 | + 'info', help='Read device information from Bladerf such as serial number and FPGA version.', usage="python_bladerf info [-h] [-f] [-s]" |
| 19 | + ) |
| 20 | + pybladerf_info_parser.add_argument('-f', '--full', action='store_true', help='show full info') |
| 21 | + pybladerf_info_parser.add_argument('-i', '--device_identifiers', action='store_true', help='show only founded device_identifiers') |
| 22 | + |
| 23 | + pybladerf_sweep_parser = subparsers.add_parser( |
| 24 | + 'sweep', help='a command-line spectrum analyzer.', usage='python_bladerf sweep [-h] [-d] [-f] [-g] [-w] [-ch] [-1] [-N] [-o] [-B] [-s] [-SR] [-BW] -[FIR] [-r]' |
| 25 | + ) |
| 26 | + pybladerf_sweep_parser.add_argument('-d', action='store', help='device_identifier. device identifier of desired BladeRF', metavar='', default='') |
| 27 | + pybladerf_sweep_parser.add_argument('-f', action='store', help='freq_min:freq_max. minimum and maximum frequencies in MHz start:stop. Default is 71:5999', metavar='', default='71:5999') |
| 28 | + pybladerf_sweep_parser.add_argument('-g', action='store', help='gain_db. RX gain, -15 - 60dB, 1dB steps', metavar='', default=20) |
| 29 | + pybladerf_sweep_parser.add_argument('-w', action='store', help='bin_width. FFT bin width (frequency resolution) in Hz, 245-30000000', metavar='', default=1000000) |
| 30 | + pybladerf_sweep_parser.add_argument('-ch', action='store', help='RX channel. which channel to use (0, 1). Default is 0', metavar='', default=0) |
| 31 | + pybladerf_sweep_parser.add_argument('-1', action='store_true', help='one shot mode. If specified = Enable') |
| 32 | + pybladerf_sweep_parser.add_argument('-N', action='store', help='num_sweeps. Number of sweeps to perform', metavar='') |
| 33 | + pybladerf_sweep_parser.add_argument('-o', action='store_true', help='oversample. If specified = Enable') |
| 34 | + pybladerf_sweep_parser.add_argument('-B', action='store_true', help='binary output. If specified = Enable') |
| 35 | + pybladerf_sweep_parser.add_argument('-s', action='store', help='sweep style ("L" - LINEAR, "I" - INTERLEAVED). Default is INTERLEAVED', metavar='', default='I') |
| 36 | + pybladerf_sweep_parser.add_argument('-SR', action='store', help='sample rate in Hz (0.5 MHz - 122 MHz). Default is 57. To use a sample rate higher than 61, specify oversample', metavar='', default=57) |
| 37 | + pybladerf_sweep_parser.add_argument('-BW', action='store', help='bandwidth in Hz (0.2 MHz - 56 MHz). Default is 56000000', metavar='', default=56.0) |
| 38 | + pybladerf_sweep_parser.add_argument('-FIR', action='store', help='RFIC RX FIR filter ("1" - Enable, "0" - Disable). Default is Disable', metavar='', default='0') |
| 39 | + pybladerf_sweep_parser.add_argument('-r', action='store', help='filename. output file', metavar='') |
| 40 | + |
| 41 | + if len(sys.argv) == 1: |
| 42 | + parser.print_help() |
| 43 | + sys.exit(0) |
| 44 | + |
| 45 | + args, unparsed_args = parser.parse_known_args() |
| 46 | + if args.command == 'info': |
| 47 | + if args.device_identifiers: |
| 48 | + pybladerf_info.pybladerf_device_identifiers_list_info() |
| 49 | + else: |
| 50 | + pybladerf_info.pybladerf_info() |
| 51 | + |
| 52 | + elif args.command == 'sweep': |
| 53 | + frequency_range = args.f.split(':') |
| 54 | + frequencies = [71, 5999] |
| 55 | + freq_min, freq_max = None, None |
| 56 | + try: |
| 57 | + freq_min = int(frequency_range[0]) |
| 58 | + except Exception: |
| 59 | + pass |
| 60 | + try: |
| 61 | + freq_max = int(frequency_range[1]) |
| 62 | + except Exception: |
| 63 | + pass |
| 64 | + if freq_min is not None and freq_max is not None: |
| 65 | + frequencies = [freq_min, freq_max] |
| 66 | + |
| 67 | + pybladerf_sweep.pybladerf_sweep(frequencies=frequencies, |
| 68 | + gain=int(args.g), |
| 69 | + bin_width=int(args.w), |
| 70 | + sample_rate=float(args.SR) * 1e6, |
| 71 | + bandwidth=float(args.BW) * 1e6, |
| 72 | + channel=int(args.ch), |
| 73 | + oversample=args.o, |
| 74 | + num_sweeps=int(args.N) if args.N is not None else None, |
| 75 | + binary_output=args.B, |
| 76 | + one_shot=args.__dict__.get('1'), |
| 77 | + filename=args.r, |
| 78 | + device_identifier=args.d, |
| 79 | + rxfir=pybladerf.pybladerf_rfic_rxfir.PYBLADERF_RFIC_RXFIR_DEC1 if args.FIR == '1' else (pybladerf.pybladerf_rfic_rxfir.PYBLADERF_RFIC_RXFIR_BYPASS if args.FIR == '0' else -1), |
| 80 | + sweep_style=pybladerf.pybladerf_sweep_style.PYBLADERF_SWEEP_STYLE_LINEAR if args.s == 'L' else (pybladerf.pybladerf_sweep_style.PYBLADERF_SWEEP_STYLE_INTERLEAVED if args.s == 'I' else -1), |
| 81 | + print_to_console=True) |
| 82 | + |
| 83 | + |
| 84 | +if __name__ == '__main__': |
| 85 | + main() |
0 commit comments