Exemple #1
0
def cmd_tx(infile,
           frequency,
           rate,
           gain,
           device=None,
           channel=_bladerf.CHANNEL_TX(0),
           **kwargs):
    b = _bladerf.BladeRF(device)
    ch = b.Channel(channel)

    # Get underlying binary stream for stdin case
    infile = infile.buffer if isinstance(infile, io.TextIOWrapper) else infile

    # Configure BladeRF
    ch.frequency = frequency
    ch.sample_rate = rate
    ch.gain = gain

    # Setup stream
    b.sync_config(layout=_bladerf.ChannelLayout.TX_X1,
                  fmt=_bladerf.Format.SC16_Q11,
                  num_buffers=16,
                  buffer_size=8192,
                  num_transfers=8,
                  stream_timeout=3500)

    # Enable module
    ch.enable = True

    # Create buffer
    bytes_per_sample = 4
    buf = bytearray(1024 * bytes_per_sample)

    try:
        while True:
            # Read samples from file into buf
            num = infile.readinto(buf)
            if num == 0:
                break

            # Convert number of bytes read to samples
            num //= bytes_per_sample

            # Write to bladeRF
            b.sync_tx(buf, num)
    except KeyboardInterrupt:
        pass

    # Disable module
    ch.enable = False

    b.close()
    infile.close()
Exemple #2
0
def _print_cmd_info(device=None, devinfo=None, verbose=False):
    b = _bladerf.BladeRF(device, devinfo)

    devinfo = b.get_devinfo()

    flash_size, fs_guessed = b.flash_size

    if verbose:
        print("Object           ", repr(b))
    print("Board Name       ", b.board_name)
    print("Device Speed     ", b.device_speed.name)
    print("FPGA Size        ", b.fpga_size)
    print("FPGA Configured  ", b.fpga_configured)
    if b.is_fpga_configured():
        print("FPGA Version     ", b.fpga_version)
    else:
        print("FPGA Version     ", "Not Configured")
    print("Flash Size       ", (flash_size>>17), "Mbit",
          "(assumed)" if fs_guessed else "")
    print("Firmware Version ", b.fw_version)

    if verbose:
        print("Clock Select     ", b.clock_select)
        print("Clock Output     ", _bool_to_onoff(b.clock_output))
        print("Power Source     ", b.power_source)
        print("Bus Voltage       {:.3f} V".format(b.bus_voltage or 0))
        print("Bus Current       {:.3f} A".format(b.bus_current or 0))
        print("Bus Power         {:.3f} W".format(b.bus_power or 0))
        print("RFIC temperature  {:.3f} C".format(b.rfic_temperature or 0))

        print("Loopback         ", b.loopback)
        print("    Modes        ", _strify_list(b.loopback_modes))
        print("RX Mux           ", b.rx_mux)

        print("PLL Mode         ", _bool_to_onoff(b.pll_enable))
        if b.pll_enable:
            print("PLL Refclk       ", b.pll_refclk)
            print("PLL Locked       ", _bool_to_onoff(b.pll_locked))

    print("RX Channel Count ", b.rx_channel_count)
    for c in range(b.rx_channel_count):
        ch = b.Channel(_bladerf.CHANNEL_RX(c))
        _print_channel_details(ch, verbose)

    print("TX Channel Count ", b.tx_channel_count)
    for c in range(b.tx_channel_count):
        ch = b.Channel(_bladerf.CHANNEL_TX(c))
        _print_channel_details(ch, verbose)

    b.close()
for s in [ss for ss in config.sections() if board_name + '-' in ss]:

    if (s == board_name + "-load-fpga"):
        # Don't re-loading the FPGA!
        continue

    # Print the section name
    print("{:<35s} : ".format(s), end='')

    if (config.getboolean(s, 'enable')):

        print("RUNNING")

        if (s == board_name + '-tx'):

            tx_ch = _bladerf.CHANNEL_TX(config.getint(s, 'tx_channel'))
            tx_freq = int(config.getfloat(s, 'tx_frequency'))
            tx_rate = int(config.getfloat(s, 'tx_samplerate'))
            tx_gain = int(config.getfloat(s, 'tx_gain'))
            tx_rpt = int(config.getfloat(s, 'tx_repeats'))
            tx_file = config.get(s, 'tx_file')

            # Make this blocking for now ...
            status = tx_pool.apply_async(
                transmit, (), {
                    'device': b,
                    'channel': tx_ch,
                    'freq': tx_freq,
                    'rate': tx_rate,
                    'gain': tx_gain,
                    'tx_start': None,