PluginInterface::SamplingDevices BladeRF2OutputPlugin::enumSampleSinks()
{
    SamplingDevices result;
    struct bladerf_devinfo *devinfo = 0;

    int count = bladerf_get_device_list(&devinfo);

    if (devinfo)
    {
        for(int i = 0; i < count; i++)
        {
            struct bladerf *dev;

            int status = bladerf_open_with_devinfo(&dev, &devinfo[i]);

            if (status == BLADERF_ERR_NODEV)
            {
                qCritical("Bladerf2OutputPlugin::enumSampleSinks: No device at index %d", i);
                continue;
            }
            else if (status != 0)
            {
                qCritical("Bladerf2OutputPlugin::enumSampleSinks: Failed to open device at index %d", i);
                continue;
            }

            const char *boardName = bladerf_get_board_name(dev);

            if (strcmp(boardName, "bladerf2") == 0)
            {
                unsigned int nbTxChannels = bladerf_get_channel_count(dev, BLADERF_TX);

                for (unsigned int j = 0; j < nbTxChannels; j++)
                {
                    qDebug("Blderf2InputPlugin::enumSampleSinks: device #%d (%s) channel %u", i, devinfo[i].serial, j);
                    QString displayedName(QString("BladeRF2[%1:%2] %3").arg(devinfo[i].instance).arg(j).arg(devinfo[i].serial));
                    result.append(SamplingDevice(displayedName,
                            m_hardwareID,
                            m_deviceTypeID,
                            QString(devinfo[i].serial),
                            i,
                            PluginInterface::SamplingDevice::PhysicalDevice,
                            false,
                            nbTxChannels,
                            j));
                }
            }

            bladerf_close(dev);
        }

        bladerf_free_device_list(devinfo); // Valgrind memcheck
    }

    return result;
}
PluginInterface::SamplingDevices Blderf1InputPlugin::enumSampleSources()
{
	SamplingDevices result;
	struct bladerf_devinfo *devinfo = 0;

	int count = bladerf_get_device_list(&devinfo);

    if (devinfo)
    {
        for(int i = 0; i < count; i++)
        {
            struct bladerf *dev;

            int status = bladerf_open_with_devinfo(&dev, &devinfo[i]);

            if (status == BLADERF_ERR_NODEV)
            {
                qCritical("BlderfInputPlugin::enumSampleSources: No device at index %d", i);
                continue;
            }
            else if (status != 0)
            {
                qCritical("BlderfInputPlugin::enumSampleSources: Failed to open device at index %d", i);
                continue;
            }

            const char *boardName = bladerf_get_board_name(dev);

            if (strcmp(boardName, "bladerf1") == 0)
            {
                QString displayedName(QString("BladeRF1[%1] %2").arg(devinfo[i].instance).arg(devinfo[i].serial));

                result.append(SamplingDevice(displayedName,
                        m_hardwareID,
                        m_deviceTypeID,
                        QString(devinfo[i].serial),
                        i,
                        PluginInterface::SamplingDevice::PhysicalDevice,
                        true,
                        1,
                        0));
            }

            bladerf_close(dev);
        }

		bladerf_free_device_list(devinfo); // Valgrind memcheck
	}

	return result;
}
Beispiel #3
0
// Return a list of supported devices.
void BladeRFSource::get_device_names(std::vector<std::string>& devices)
{
    struct bladerf_devinfo *devinfo = 0;

    int count = bladerf_get_device_list(&devinfo);

    for (int i = 0; i < count; i++)
    {
        devices.push_back(std::string(devinfo[i].serial));
    }

    if (devinfo)
    {
        bladerf_free_device_list(devinfo);
    }
}
Beispiel #4
0
/* Todo move to cmd_probe.c */
int cmd_probe(struct cli_state *s, int argc, char *argv[])
{
    struct bladerf_devinfo *devices = NULL;
    int n_devices, i;

    n_devices = bladerf_get_device_list(&devices);

    if (n_devices < 0) {
        if (n_devices == BLADERF_ERR_NODEV) {
            cli_err(s, argv[0], "No devices found.");
        } else {
            cli_err(s, argv[0], "Failed to probe for devices: %s",
                    bladerf_strerror(n_devices));
        }

        s->last_lib_error = n_devices;
        return CLI_RET_LIBBLADERF;
    }

    printf("\n");
    for (i = 0; i < n_devices; i++) {
        printf("    Backend:        %s\n", backend2str(devices[i].backend));
        /* printf("    Serial: 0x%016lX\n", devices[i].serial); */
        /* TODO: Fix OTP support for serial readback! */
        printf("    Serial:         %s\n", devices[i].serial);
        printf("    USB Bus:        %d\n", devices[i].usb_bus);
        printf("    USB Address:    %d\n", devices[i].usb_addr);
        /*printf("    Firmware: v%d.%d\n", devices[i].fw_ver_maj,
               devices[i].fw_ver_min);

        if (devices[i].fpga_configured) {
            printf("    FPGA: v%d.%d\n",
                    devices[i].fpga_ver_maj, devices[i].fpga_ver_min);
        } else {
            printf("    FPGA: not configured\n");
        }*/
        printf("\n");
    }

    if (devices) {
        assert(n_devices != 0);
        bladerf_free_device_list(devices);
    }

    return 0;
}
Beispiel #5
0
/* Todo move to cmd_probe.c */
int cmd_probe(struct cli_state *s, int argc, char *argv[])
{
    bool error_on_no_dev = false;
    struct bladerf_devinfo *devices = NULL;
    int n_devices, i;

    n_devices = bladerf_get_device_list(&devices);

    if (argc > 1 && !strcasecmp(argv[1], "strict")) {
        error_on_no_dev = true;
    }

    if (n_devices < 0) {
        if (n_devices == BLADERF_ERR_NODEV) {
            cli_err(s, argv[0], "No devices found.\n");
            if (error_on_no_dev) {
                return CLI_RET_CMD_HANDLED;
            } else {
                return 0;
            }
        } else {
            cli_err(s, argv[0], "Failed to probe for devices: %s\n",
                    bladerf_strerror(n_devices));
            s->last_lib_error = n_devices;
            return CLI_RET_LIBBLADERF;
        }
    }

    putchar('\n');
    for (i = 0; i < n_devices; i++) {
        printf("  Backend:        %s\n", backend2str(devices[i].backend));
        printf("  Serial:         %s\n", devices[i].serial);
        printf("  USB Bus:        %d\n", devices[i].usb_bus);
        printf("  USB Address:    %d\n", devices[i].usb_addr);
        putchar('\n');
    }

    if (devices) {
        assert(n_devices != 0);
        bladerf_free_device_list(devices);
    }

    return 0;
}
static std::vector<SoapySDR::Kwargs> find_bladeRF(const SoapySDR::Kwargs &matchArgs)
{
    const bladerf_devinfo matchinfo = kwargs_to_devinfo(matchArgs);

    std::vector<SoapySDR::Kwargs> results;
    bladerf_devinfo *infos = NULL;
    int ret = 0;
    ret = bladerf_get_device_list(&infos);

    for (int i = 0; i < ret; i++)
    {
        if (bladerf_devinfo_matches(infos+i, &matchinfo))
        {
            results.push_back(devinfo_to_kwargs(infos[i]));
        }
    }

    bladerf_free_device_list(infos);
    return results;
}
Beispiel #7
0
PluginInterface::SamplingDevices BlderfPlugin::enumSampleSources()
{
	SamplingDevices result;
	struct bladerf_devinfo *devinfo = 0;

	int count = bladerf_get_device_list(&devinfo);

	for(int i = 0; i < count; i++)
	{
		QString displayedName(QString("BladeRF[%1] %2").arg(devinfo[i].instance).arg(devinfo[i].serial));

		result.append(SamplingDevice(displayedName,
				m_deviceTypeID,
				QString(devinfo[i].serial),
				i));
	}

	if (devinfo)
	{
		bladerf_free_device_list(devinfo); // Valgrind memcheck
	}

	return result;
}
Beispiel #8
0
/* Initialization and stuff
 */
int main(int argc, char **argv)
{
	struct bladerf_devinfo *devs;
	struct sigaction sigact;
	struct devinfo_s device;
	int show_help = false;
	int n, ret;
	char ch;

	/* Set up default values, bandwidth and num_transfers
	 * are automatically calculated later */
	device.device_id = DEFAULT_DEVICE_ID;
	device.frequency = DEFAULT_FREQUENCY;
	device.samplerate = DEFAULT_SAMPLERATE;
	device.bandwidth = 0;
	device.txvga1 = DEFAULT_TXVGA1;
	device.txvga2 = DEFAULT_TXVGA2;

	device.buffers.gain = DEFAULT_GAIN;
	device.buffers.again = DEFAULT_AGAIN;
	device.buffers.num_buffers = DEFAULT_BUFFERS;
	device.buffers.num_samples = DEFAULT_SAMPLES;
	device.buffers.num_transfers = 0;
	device.buffers.pos = 0;

	/* Evaluate command line options */
	while((ch = getopt(argc, argv, "hd:f:r:b:g:G:a:m:n:s:t:")) != -1)
	{
		switch(ch)
		{
			case 'd':
				device.device_id = optarg; break;
			case 'f':
				device.frequency = atoi(optarg); break;
			case 'r':
				device.samplerate = atoi(optarg); break;
			case 'b':
				device.bandwidth = atoi(optarg); break;
			case 'g':
				device.txvga1 = atoi(optarg); break;
			case 'G':
				device.txvga2 = atoi(optarg); break;
			case 'm':
				device.buffers.gain = atof(optarg); break;
			case 'a':
				device.buffers.again = atof(optarg); break;
			case 'n':
				device.buffers.num_buffers = atoi(optarg); break;
			case 's':
				device.buffers.num_samples = atoi(optarg); break;
			case 't':
				device.buffers.num_transfers = atoi(optarg); break;
			case 'h':
			default:
				show_help = true;
		}
	}

	/* Now calculate bandwidth and num_transfers if the user didn't
	 * configure them manually */
	if(device.bandwidth == 0)
		device.bandwidth = device.samplerate * 3 / 4;
	if(device.buffers.num_transfers == 0)
		device.buffers.num_transfers = device.buffers.num_buffers / 2;

	if(show_help)
	{
		usage(argv[0], &device);
		return EXIT_FAILURE;
	}
	
	argc -= optind;
	argv += optind;

	/* Allocate the float input buffer */
	device.buffers.fbuf =
		malloc(device.buffers.num_samples * 2 * sizeof(float));
	
	/* Set up signal handler to enable clean shutdowns */
	sigact.sa_handler = sighandler;
	sigemptyset(&sigact.sa_mask);
	sigact.sa_flags = 0;
	sigaction(SIGINT, &sigact, NULL);
	sigaction(SIGTERM, &sigact, NULL);
	sigaction(SIGQUIT, &sigact, NULL);
	sigaction(SIGPIPE, &sigact, NULL);



	/* Look for devices attached */
	ret = bladerf_get_device_list(&devs);
	if(ret < 1)
	{
		fprintf(stderr, "No devices found.\n");
		return EXIT_FAILURE;
	}

	/* Print some information about all the devices */
	for(n = 0; n < ret; n++)
	{
		fprintf(stderr, 
			"Serial:\t%s\n"
			"USB bus:\t%i\n"
			"USB address:\t%i\n"
			"Instance:\t%i\n\n",
			devs[n].serial,
			devs[n].usb_bus,
			devs[n].usb_addr,
			devs[n].instance
		);
	}

	/* the list is not needed any more */
	bladerf_free_device_list(devs);



	/* Open a device by given device string
	 */
	ret = bladerf_open(&device.dev, device.device_id);
	if(ret != 0)
	{
		fprintf(stderr, "Error opening device %s: %s.\n",
			device.device_id, bladerf_strerror(ret));
		goto out0;
	}
	else
	{
		fprintf(stderr, "Device \"%s\" opened successfully.\n",
			device.device_id);
	}

	/* Set the device parameters */
	ret = bladerf_set_sample_rate(device.dev,
		BLADERF_MODULE_TX, device.samplerate, &device.samplerate);
	if(ret != 0)
	{
		fprintf(stderr, "Error setting sample rate to %i: %s.\n",
			device.samplerate, bladerf_strerror(ret));
		goto out1;
	}
	else
	{
		fprintf(stderr, "Actual sample rate is %i.\n",
			device.samplerate);
	}

	ret = bladerf_set_frequency(device.dev,
		BLADERF_MODULE_TX, device.frequency);
	if(ret != 0)
	{
		fprintf(stderr, "Error setting frequency to %iHz: %s.\n",
			device.frequency, bladerf_strerror(ret));
		goto out1;
	}
	else
	{
		fprintf(stderr, "Frequency set to %iHz.\n", device.frequency);
	}

	ret = bladerf_set_txvga1(device.dev, device.txvga1);
	if(ret != 0)
	{
		fprintf(stderr, "Error setting gain for txvga1: %s.\n",
			bladerf_strerror(ret));
		goto out1;
	}

	ret = bladerf_set_txvga2(device.dev, device.txvga2);
	if(ret != 0)
	{
		fprintf(stderr, "Error setting gain for txvga2: %s.\n",
			bladerf_strerror(ret));
		goto out1;
	}

	ret = bladerf_set_bandwidth(device.dev,
		BLADERF_MODULE_TX, device.bandwidth, &device.bandwidth);
	if(ret != 0)
	{
		fprintf(stderr, "Error setting LPF bandwidth: %s.\n",
			bladerf_strerror(ret));
		goto out1;
	}
	else
	{
		fprintf(stderr, "Bandwidth set to %iHz.\n", device.bandwidth);
	}

	/* Set up the sample stream */
	ret = bladerf_init_stream(&device.stream,
		device.dev, stream_callback, &device.buffers.sbuf,
		device.buffers.num_buffers,	BLADERF_FORMAT_SC16_Q12,
		device.buffers.num_samples, device.buffers.num_transfers,
		&device.buffers);
	if(ret != 0)
	{
		fprintf(stderr, "Failed setting up stream: %s.\n",
			bladerf_strerror(ret));
		goto out1;
	}
	

	/* Finally enable TX... */
	ret = bladerf_enable_module(device.dev, BLADERF_MODULE_TX, true);
	if(ret != 0)
	{
		fprintf(stderr, "Error enabling TX module: %s.\n",
			bladerf_strerror(ret));
		goto out1;
	}
	else
	{
		fprintf(stderr, "Successfully enabled TX module.\n");
	}

	/* ...and start the stream.
	 * Execution stops here until stream has finished. */
	ret = bladerf_stream(device.stream, BLADERF_MODULE_TX);
	if(ret != 0)
	{
		fprintf(stderr, "Failed starting stream: %s.\n",
			bladerf_strerror(ret));
		goto out2;
	}


	/* Cleanup the mess */
out2:
	bladerf_deinit_stream(device.stream);

out1:
	ret = bladerf_enable_module(device.dev, BLADERF_MODULE_TX, false);
	if(ret != 0)
	{
		fprintf(stderr, "Error disabling TX module: %s.\n",
			bladerf_strerror(ret));
	}
	else
	{
		fprintf(stderr, "Successfully disabled TX module.\n");
	}
	
	bladerf_close(device.dev);
	fprintf(stderr, "Device closed.\n");
	
out0:
	return EXIT_SUCCESS;
}