From 8ab3ad3b63504faf36e8df688d236d9274625d24 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 5 Sep 2017 15:06:40 +0200 Subject: [PATCH] PlutoSDR: added read param method to device box --- devices/plutosdr/deviceplutosdrbox.cpp | 36 ++++++++++++++++++++++++++ devices/plutosdr/deviceplutosdrbox.h | 1 + 2 files changed, 37 insertions(+) diff --git a/devices/plutosdr/deviceplutosdrbox.cpp b/devices/plutosdr/deviceplutosdrbox.cpp index c5c1d294d..5c58782b8 100644 --- a/devices/plutosdr/deviceplutosdrbox.cpp +++ b/devices/plutosdr/deviceplutosdrbox.cpp @@ -106,6 +106,42 @@ void DevicePlutoSDRBox::set_params(DeviceType devType, } } +bool DevicePlutoSDRBox::get_param(DeviceType devType, const std::string ¶m, std::string &value) +{ + struct iio_channel *chn = 0; + const char *attr = 0; + char valuestr[256]; + int ret; + ssize_t nchars; + + ret = iio_device_identify_filename(dev, param.c_str(), &chn, &attr); + + if (ret) + { + std::cerr << "PlutoSDRDevice::get_param: Parameter not recognized: " << param << std::endl; + return false; + } + + if (chn) { + nchars = iio_channel_attr_read(chn, attr, valuestr, 256); + } else if (iio_device_find_attr(dev, attr)) { + nchars = iio_device_attr_read(dev, attr, valuestr, 256); + } else { + nchars = iio_device_debug_attr_read(dev, attr, valuestr, 256); + } + + if (nchars < 0) + { + std::cerr << "PlutoSDRDevice::get_param: Unable to read attribute " << param << ": " << nchars << std::endl; + return false; + } + else + { + value.assign(valuestr); + return true; + } +} + bool DevicePlutoSDRBox::openRx() { if (!m_chnRx0) { diff --git a/devices/plutosdr/deviceplutosdrbox.h b/devices/plutosdr/deviceplutosdrbox.h index 71c12ce3b..11cdb1bfb 100644 --- a/devices/plutosdr/deviceplutosdrbox.h +++ b/devices/plutosdr/deviceplutosdrbox.h @@ -39,6 +39,7 @@ public: bool isValid() const { return m_valid; } void set_params(DeviceType devType, const std::vector ¶ms); + bool get_param(DeviceType devType, const std::string ¶m, std::string &value); bool openRx(); bool openTx(); void closeRx();