blob: 37f78f67553689d06e91ccb6ea9412444a20998f (
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
57
58
59
60
|
/* -*- 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 <gnuradio/logger.h>
#include <iio.h>
#include <stdexcept>
namespace gr {
namespace iio {
std::string get_pluto_uri()
{
GR_LOG_GET_CONFIGURED_LOGGER(d_logger, "pluto_utils::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) {
GR_LOG_INFO(d_logger, "More than one Pluto found:");
for (unsigned int i = 0; i < (size_t)ret; i++) {
GR_LOG_INFO(d_logger,
boost::format("\t%d: %s [%s]") % i %
iio_context_info_get_description(info[i]) %
iio_context_info_get_uri(info[i]));
}
GR_LOG_INFO(d_logger, "We will use the first one.");
}
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
|