Beispiel #1
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)
Beispiel #2
0
def get_stream(args):
    outfile = sys.stdout if args['--file'] == '-' else open(args['--file'], 'wb')
    device = bladeRF.Device(args['--device'])
    device.rx.enabled = True
    device.rx.frequency = int(args['<frequency>'])
    device.rx.bandwidth = int(args['--bandwidth'])
    device.rx.sample_rate = int(args['--sample-rate'])
    device.lna_gain = getattr(bladeRF, args['--lna-gain'])
    device.rx.vga1 = int(args['--rx-vga1'])
    device.rx.vga2 = int(args['--rx-vga2'])
    squelch = float(args['--squelch'])

    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()


    stream = device.rx.stream(
        rx,
        int(args['--num-buffers']),
        bladeRF.FORMAT_SC16_Q11,
        int(args['--num-samples']),
        int(args['--num-transfers']),
        )
    return stream
Beispiel #3
0
def main():
    args = docopt(__doc__, version='bladeRF Transmitter 1.0')
    infile = sys.stdin if args['--file'] == '-' else open(args['--file'], 'rb')

    device = bladeRF.Device(args['--device'])
    device.tx.enabled = True
    device.tx.frequency = int(args['<frequency>'])
    device.tx.bandwidth = int(args['--bandwidth'])
    device.tx.sample_rate = int(args['--sample-rate'])

    def tx(device, stream, meta_data, samples, num_samples, user_data):
        next = stream.next()
        if not infile.readinto(bladeRF.ffi.buffer(next, num_samples)):
            return
        return next

    stream = device.tx.stream(
        tx,
        int(args['--num-buffers']),
        bladeRF.FORMAT_SC16_Q11,
        int(args['--num-samples']),
        int(args['--num-transfers']))

    stream.run()
Beispiel #4
0
import pyqtgraph as pg
import Queue
from pyqtgraph.Qt import QtCore, QtGui
from PyQt4.QtCore import QObject, pyqtSignal, Qt
import scipy.ndimage as ndi
import numpy as np

app = QtGui.QApplication([])
import pyqtgraph.parametertree.parameterTypes as pTypes
from pyqtgraph.parametertree import Parameter, ParameterTree, ParameterItem, registerParameterType

from scipy import signal
import bladeRF

device = bladeRF.Device()
device.rx.enabled = True
device.rx.frequency = 440000000
device.rx.bandwidth = 28000000
device.rx.sample_rate = 40000000



num_buffers = 16
num_transfers = 16
num_samples = 2**16
Nf = 512     # No. of frames
Ns = 1000    # Signal length

params = [
    {'name': 'Frequency',
     'type': 'group',
Beispiel #5
0
def main():
    args = docopt(__doc__, version='bladeRF Repeater 1.0')
    device = bladeRF.Device(args['--device'])

    device.rx.enabled = True
    device.rx.frequency = int(args['<rx_frequency>'])
    device.rx.bandwidth = int(args['--bandwidth'])
    device.rx.sample_rate = int(args['--sample-rate'])
    device.rx.vga1 = int(args['--rx-vga1-gain'])
    device.rx.vga2 = int(args['--rx-vga2-gain'])

    device.lna_gain = getattr(bladeRF, args['--lna-gain'])

    device.tx.enabled = True
    device.tx.frequency = int(args['<rx_frequency>'])
    device.tx.bandwidth = int(args['--bandwidth'])
    device.tx.sample_rate = int(args['--sample-rate'])
    device.rx.vga1 = int(args['--tx-vga1-gain'])
    device.rx.vga2 = int(args['--tx-vga2-gain'])

    squelch = float(args['--squelch'])
    num_buffers = int(args['--num-buffers'])
    num_transfers = int(args['--num-transfers'])
    num_samples = int(args['--num-samples'])

    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

    def tx(dev, stream, meta_data, samples, num_samples, repeater):
        with repeater.samples_available:
            if not stream.running:
                return
            if repeater.num_filled == 0:
                return repeater.zerobuf
            ret = stream.next()
            repeater.num_filled -= 1
        return ret

    repeater = Repeater(num_buffers, num_transfers, num_samples)

    rx_stream = device.rx.stream(rx, num_buffers, bladeRF.FORMAT_SC16_Q11,
                                 num_samples, num_transfers, repeater)

    tx_stream = device.tx.stream(tx, num_buffers, bladeRF.FORMAT_SC16_Q11,
                                 num_samples, num_transfers, repeater)

    tx_stream.buffers = rx_stream.buffers  # wire up tx buffers to rx

    rx_stream.start()
    tx_stream.start()

    i = raw_input('Repeater is running, press enter to exit... ')

    with repeater.samples_available:
        rx_stream.running = tx_stream.running = False

    rx_stream.join()
    tx_stream.join()
    sys.exit(0)