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 _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()
'device': b, 'channel': tx_ch, 'freq': tx_freq, 'rate': tx_rate, 'gain': tx_gain, 'tx_start': None, 'rx_done': None, 'txfile': tx_file, 'repeat': tx_rpt }).get() if (status < 0): print("Transmit operation failed with error " + str(status)) elif (s == board_name + '-rx'): rx_ch = _bladerf.CHANNEL_RX(config.getint(s, 'rx_channel')) rx_freq = int(config.getfloat(s, 'rx_frequency')) rx_rate = int(config.getfloat(s, 'rx_samplerate')) rx_gain = int(config.getfloat(s, 'rx_gain')) rx_ns = int(config.getfloat(s, 'rx_num_samples')) rx_file = config.get(s, 'rx_file') # Make this blocking for now ... status = rx_pool.apply_async( receive, (), { 'device': b, 'channel': rx_ch, 'freq': rx_freq, 'rate': rx_rate, 'gain': rx_gain, 'tx_start': None,