Example #1
0
def txrx_burst(freq, samples):
	# Set frequency.
	device.tx.frequency = freq
	device.rx.frequency = freq - rx_offset

	# Setup TX and RX metadata structs.
	metadata_tx = ffi.new("struct bladerf_metadata [1]")
	metadata_tx[0].flags = bladeRF.BLADERF_META_FLAG_TX_BURST_START | bladeRF.BLADERF_META_FLAG_TX_BURST_END

	metadata_rx = ffi.new("struct bladerf_metadata [1]")
	metadata_rx[0].flags = 0

	# Get current timestamp
	current_tx_timestamp = device.tx.timestamp
	current_rx_timestamp = device.rx.timestamp
	print "Timestamps: TX %d, RX %d" % (current_tx_timestamp, current_rx_timestamp)

	# Set scheduled transmit and receive timestamps.
	metadata_tx[0].timestamp = current_tx_timestamp + device.tx.sample_rate/20 # 10ms into the future
	metadata_rx[0].timestamp = current_rx_timestamp + device.tx.sample_rate/20 # 10ms into the future

	# Transmit!
	device.tx(num_samples,samples=tx_samples, metadata=metadata_tx, timeout_ms=timeout_ms)
	rx_samples = device.rx(num_samples, metadata=metadata_rx, timeout_ms = timeout_ms)

	# Wait until all samples have been transmitted.
	while(device.tx.timestamp < metadata_tx[0].timestamp + 2*num_samples):
		pass

	print "RXed %d Samples." % (metadata_rx[0].actual_count)
	return bladeRF.samples_to_narray(rx_samples, metadata_rx[0].actual_count)
Example #2
0
def rx(device, stream, meta_data, samples, num_samples, user_data):
    samples = bladeRF.samples_to_narray(samples, num_samples)
    try:
        queue.put_nowait(samples)
    except Queue.Full:
        pass
    return stream.next()
Example #3
0
def test_device():
    device = bladeRF.Device()
    device.rx.config(bladeRF.FORMAT_SC16_Q11, 64, 16384, 16, 3500)
    device.tx.config(bladeRF.FORMAT_SC16_Q11, 64, 16384, 16, 3500)
    device.rx.enabled = True
    device.tx.enabled = True

    device.rx.frequency = 2**28
    assert device.rx.frequency == 2**28
    device.rx.bandwidth = 1500000
    assert device.rx.bandwidth == 1500000
    device.rx.sample_rate = 2**21
    assert device.rx.sample_rate == 2**21

    device.tx.frequency = 1234000000
    assert device.tx.frequency == 1234000000
    device.tx.bandwidth = 1500000
    assert device.tx.bandwidth == 1500000
    device.tx.sample_rate = 2**20
    assert device.tx.sample_rate == 2**20

    raw = device.rx(1024)
    array = bladeRF.samples_to_narray(raw, 1024)
    assert len(array) == 1024
    samples = bytearray(bladeRF.ffi.buffer(raw))
    assert isinstance(samples, bytearray)
    assert len(samples) == 4096

    device.tx(1024, raw)
Example #4
0
    def rx(device, stream, meta_data, samples, num_samples, user_data):
        if squelch:
            samples = bladeRF.samples_to_narray(samples, num_samples)
            if bladeRF.squelched(samples, squelch):
                return stream.current()

        buff = stream.current_as_buffer()
        outfile.write(buff)
        return stream.next()
Example #5
0
    def rx(device, stream, meta_data, samples, num_samples, user_data):
        if squelch:
            samples = bladeRF.samples_to_narray(samples, num_samples)
            if bladeRF.squelched(samples, squelch):
                return stream.current()

        buff = stream.current_as_buffer()
        outfile.write(buff)
        return stream.next()
Example #6
0
 def rx(dev, stream, meta_data, samples, num_samples, repeater):
     with repeater.samples_available:
         if not stream.running:
             return
         samples = bladeRF.samples_to_narray(samples, num_samples)
         if bladeRF.squelched(samples, squelch):
             return stream.current()
         if repeater.num_filled >= 2 * repeater.num_buffers:
             # "RX Overrun encountered, stop advancing
             return stream.current()
         ret = stream.next()
         repeater.num_filled += 1
         repeater.samples_available.notify()
     return ret
Example #7
0
 def rx(dev, stream, meta_data, samples, num_samples, repeater):
     with repeater.samples_available:
         if not stream.running:
             return
         samples = bladeRF.samples_to_narray(samples, num_samples)
         if bladeRF.squelched(samples, squelch):
             return stream.current()
         if repeater.num_filled >= 2 * repeater.num_buffers:
             # "RX Overrun encountered, stop advancing
             return stream.current()
         ret = stream.next()
         repeater.num_filled += 1
         repeater.samples_available.notify()
     return ret
Example #8
0
def update():
    global metadata, averaging_buffer
    samples = device.rx(buffer_size, metadata=metadata, timeout_ms=timeout_ms)
    num_samples = metadata[0].actual_count
    metadata[0].timestamp = 0
    data = bladeRF.samples_to_narray(samples, num_samples)
    data = data[:nFFT]
    try:
        # For some reason we seem to get a lot of NaNs in our received sample data.
        # This is a bit of a hack to avoid allowing any NaN values into our averaging array.
        data_fft = np.fft.fftshift(10 * np.log10(np.abs(np.fft.fft(data ** 2.0))))
        if not np.isnan(data_fft).any():
            averaging_buffer = np.roll(averaging_buffer, 1, axis=0)
            averaging_buffer[0] = data_fft
            p1_data.setData(p1_freq_range, averaging_buffer.mean(axis=0))
    except:
        pass