-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathIIOInfo.cpp
89 lines (72 loc) · 2.1 KB
/
IIOInfo.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright (c) 2015-2016 Josh Blum
// Copyright (c) 2016 Fiach Antaw
// SPDX-License-Identifier: BSL-1.0
#include <Pothos/Plugin.hpp>
#include <Poco/Error.h>
#include <string>
#include "IIOSupport.hpp"
#include <typeinfo>
#include <json.hpp>
using json = nlohmann::json;
static json getIIOChannelInfo(IIOChannel chn)
{
json infoObject;
// Channel info
infoObject["ID"] = chn.id();
infoObject["Name"] = chn.name();
infoObject["Is Scan Element"] = chn.isScanElement() ? "true" : "false";
infoObject["Direction"] = chn.isOutput() ? "Output" : "Input";
// Channel attributes
auto &attrArray = infoObject["Attributes"];
for (auto a : chn.attributes())
{
json attrObject;
attrObject["Name"] = a.name();
attrObject["Value"] = a.value();
attrArray.push_back(attrObject);
}
return infoObject;
}
static json getIIODeviceInfo(IIODevice dev)
{
json infoObject;
// Device info
infoObject["Device ID"] = dev.id();
infoObject["Device Name"] = dev.name();
infoObject["Is Trigger"] = dev.isTrigger() ? "true" : "false";
// Device attributes
auto &attrArray = infoObject["Attributes"];
for (auto a : dev.attributes())
{
json attrObject;
attrObject["Name"] = a.name();
attrObject["Value"] = a.value();
attrArray.push_back(attrObject);
}
// Channels
auto &chanArray = infoObject["Channels"];
for (auto c : dev.channels())
{
chanArray.push_back(getIIOChannelInfo(c));
}
return infoObject;
}
static std::string enumerateIIODevices(void)
{
json topObject;
IIOContext& ctx = IIOContext::get();
auto &devicesArray = topObject["IIO Devices"];
for (auto d : ctx.devices())
{
devicesArray.push_back(getIIODeviceInfo(d));
}
topObject["IIO Version"] = ctx.version();
topObject["IIO Context Name"] = ctx.name();
topObject["IIO Context Description"] = ctx.description();
return topObject.dump();
}
pothos_static_block(registerIIOInfo)
{
Pothos::PluginRegistry::addCall(
"/devices/iio/info", &enumerateIIODevices);
}