forked from jocover/SoapyPlutoSDR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlutoSDR_Registation.cpp
65 lines (53 loc) · 1.76 KB
/
PlutoSDR_Registation.cpp
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
61
62
63
64
65
#include "SoapyPlutoSDR.hpp"
#include <SoapySDR/Registry.hpp>
static std::vector<SoapySDR::Kwargs> find_PlutoSDR(const SoapySDR::Kwargs &args){
std::vector<SoapySDR::Kwargs> results;
ssize_t ret=0;
iio_context *ctx=nullptr;
iio_scan_context *scan_ctx;
iio_context_info **info;
SoapySDR::Kwargs options;
scan_ctx = iio_create_scan_context(NULL, 0);
char label_str[100];
//Skipping broken USB device
ret = iio_scan_context_get_info_list(scan_ctx, &info);
if(ret < 0) {
SoapySDR_logf(SOAPY_SDR_ERROR, "Unable to scan: %li\n", (long)ret);
iio_scan_context_destroy(scan_ctx);
return results;
}
options["device"] = "plutosdr";
if(ret == 0){
ctx=iio_create_network_context(PLUTOSDR_DEFAULT_IP);
if(ctx !=nullptr){
options["hostname"]=PLUTOSDR_DEFAULT_IP;
}else{
ctx=iio_create_network_context(PLUTOSDR_DEFAULT_HOSTNAME);
if(ctx !=nullptr){
options["hostname"]=PLUTOSDR_DEFAULT_HOSTNAME;}
else{
return results;
}
}
sprintf(label_str, "%s #%d %s", options["device"].c_str(), 0, options["hostname"].c_str());
options["label"] = label_str;
results.push_back(options);
if (ctx != nullptr)iio_context_destroy(ctx);
}else{
for (int i = 0; i < ret; i++) {
ctx = iio_create_context_from_uri(iio_context_info_get_uri(info[i]));
if (ctx != nullptr) {
options["uri"] = std::string(iio_context_info_get_uri(info[i]));
sprintf(label_str, "%s #%d %s", options["device"].c_str(), i, options["uri"].c_str());
results.push_back(options);
if (ctx != nullptr)iio_context_destroy(ctx);
}
}
}
return results;
}
static SoapySDR::Device *make_PlutoSDR(const SoapySDR::Kwargs &args)
{
return new SoapyPlutoSDR(args);
}
static SoapySDR::Registry register_plutosdr("plutosdr", &find_PlutoSDR, &make_PlutoSDR, SOAPY_SDR_ABI_VERSION);