-
Notifications
You must be signed in to change notification settings - Fork 10
/
SoapyInfo.cpp
53 lines (45 loc) · 1.45 KB
/
SoapyInfo.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
// Copyright (c) 2014-2017 Josh Blum
// SPDX-License-Identifier: BSL-1.0
#include <Pothos/Plugin.hpp>
#include <SoapySDR/Version.hpp>
#include <SoapySDR/Modules.hpp>
#include <SoapySDR/Registry.hpp>
#include <SoapySDR/Device.hpp>
#include <json.hpp>
using json = nlohmann::json;
static std::string enumerateSDRDevices(void)
{
json topObject;
auto &infoObject = topObject["SoapySDR info"];
//install info
infoObject["API Version"] = SoapySDR::getAPIVersion();
infoObject["ABI Version"] = SoapySDR::getABIVersion();
infoObject["Install Root"] = SoapySDR::getRootPath();
//list of device factories
SoapySDR::loadModules();
std::string factories;
for (const auto &factory : SoapySDR::Registry::listFindFunctions())
{
if (not factories.empty()) factories += ", ";
factories += factory.first;
}
infoObject["Factories"] = factories;
//available devices
json devicesArray(json::array());
for (const auto &result : SoapySDR::Device::enumerate())
{
json deviceObject(json::object());
for (const auto &kwarg : result)
{
deviceObject[kwarg.first] = kwarg.second;
}
devicesArray.push_back(deviceObject);
}
if (not devicesArray.empty()) topObject["SDR Device"] = devicesArray;
return topObject.dump();
}
pothos_static_block(registerSoapySDRInfo)
{
Pothos::PluginRegistry::addCall(
"/devices/soapy/info", &enumerateSDRDevices);
}