blob: 2d8f2fed35c47275d5331e175220f0ebc42abd63 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
/* -*- c++ -*- */
/*
* Copyright 2017 Analog Devices Inc.
* Author: Paul Cercueil <paul.cercueil@analog.com>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#include <gnuradio/iio/pluto_utils.h>
#include <iio.h>
#include <stdexcept>
namespace gr {
namespace iio {
std::string get_pluto_uri()
{
iio_scan_context* ctx = iio_create_scan_context("usb", 0);
if (!ctx)
throw std::runtime_error("Unable to create scan context");
iio_context_info** info;
int ret = iio_scan_context_get_info_list(ctx, &info);
if (ret < 0) {
iio_scan_context_destroy(ctx);
throw std::runtime_error("Unable to scan for Pluto devices");
}
if (ret == 0) {
iio_context_info_list_free(info);
iio_scan_context_destroy(ctx);
throw std::runtime_error("No Pluto device found");
}
if (ret > 1) {
printf("More than one Pluto found:\n");
for (unsigned int i = 0; i < (size_t)ret; i++) {
printf("\t%d: %s [%s]\n",
i,
iio_context_info_get_description(info[i]),
iio_context_info_get_uri(info[i]));
}
printf("We will use the first one.\n");
}
std::string uri(iio_context_info_get_uri(info[0]));
iio_context_info_list_free(info);
iio_scan_context_destroy(ctx);
return uri;
}
} // namespace iio
} // namespace gr
|