def cmd_rx(outfile, frequency, rate, gain, num_samples, device=None, channel=_bladerf.CHANNEL_RX(0), **kwargs): b = _bladerf.BladeRF(device) ch = b.Channel(channel) # Get underlying binary stream for stdout case if isinstance(outfile, io.TextIOWrapper): outfile = outfile.buffer # Configure BladeRF ch.frequency = frequency ch.sample_rate = rate ch.gain = gain # Setup synchronous stream b.sync_config(layout=_bladerf.ChannelLayout.RX_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) num_samples_read = 0 try: while True: if num_samples > 0 and num_samples_read == num_samples: break elif num_samples > 0: num = min(len(buf)//bytes_per_sample, num_samples-num_samples_read) else: num = len(buf)//bytes_per_sample # Read into buffer b.sync_rx(buf, num) num_samples_read += num # Write to file outfile.write(buf[:num*bytes_per_sample]) except KeyboardInterrupt: pass # Disable module ch.enable = False b.close() outfile.close()
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()
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()
def cmd_erase_fpga(device=None, **kwargs): b = _bladerf.BladeRF(device) b.erase_stored_fpga() b.close()
def cmd_flash_fpga(path, device=None, **kwargs): b = _bladerf.BladeRF(device) b.flash_fpga(path) b.close()
else: print("Invalid libbladerf_verbosity specified in configuration file:", verbosity) shutdown(error=-1, board=None) # ============================================================================= # BEGIN !!! # ============================================================================= uut = probe_bladerf() if (uut == None): print("No bladeRFs detected. Exiting.") shutdown(error=-1, board=None) b = _bladerf.BladeRF(uut) board_name = b.board_name fpga_size = b.fpga_size if (config.getboolean(board_name + '-load-fpga', 'enable')): print("Loading FPGA...") try: status = load_fpga( b, config.get(board_name + '-load-fpga', 'image_' + str(fpga_size) + 'kle')) except: print("ERROR loading FPGA.") raise if (status < 0):