From 7b3810db8fa333a053329ae13c0d8c081b22840f Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Fri, 28 Dec 2012 10:03:51 +0000 Subject: [PATCH] Implemented HwCap binding --- pv/prop/binding/hwcap.cpp | 123 ++++++++++++++++++++++++++++++++++++++ pv/prop/binding/hwcap.h | 14 +++++ 2 files changed, 137 insertions(+) diff --git a/pv/prop/binding/hwcap.cpp b/pv/prop/binding/hwcap.cpp index c21d4587..de3c6e9d 100644 --- a/pv/prop/binding/hwcap.cpp +++ b/pv/prop/binding/hwcap.cpp @@ -18,8 +18,15 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include "hwcap.h" +#include + +using namespace boost; +using namespace std; + namespace pv { namespace prop { namespace binding { @@ -27,6 +34,122 @@ namespace binding { HwCap::HwCap(struct sr_dev_inst *sdi) : _sdi(sdi) { + const int *hwcaps; + + if ((sr_info_get(sdi->driver, SR_DI_HWCAPS, (const void **)&hwcaps, + sdi) != SR_OK) || !hwcaps) + /* Driver supports no device instance options. */ + return; + + for (int cap = 0; hwcaps[cap]; cap++) { + const struct sr_hwcap_option *const hwo = + sr_devopt_get(hwcaps[cap]); + + if (!hwo) + continue; + + switch(hwo->hwcap) + { + case SR_HWCAP_PATTERN_MODE: + bind_stropt(hwo, SR_DI_PATTERNS, + SR_HWCAP_PATTERN_MODE); + break; + + case SR_HWCAP_BUFFERSIZE: + bind_buffer_size(hwo); + break; + + case SR_HWCAP_TIMEBASE: + bind_time_base(hwo); + break; + + case SR_HWCAP_TRIGGER_SOURCE: + bind_stropt(hwo, SR_DI_TRIGGER_SOURCES, + SR_HWCAP_TRIGGER_SOURCE); + break; + + case SR_HWCAP_FILTER: + bind_stropt(hwo, SR_DI_FILTERS, SR_HWCAP_FILTER); + break; + + case SR_HWCAP_VDIV: + bind_vdiv(hwo); + break; + + case SR_HWCAP_COUPLING: + bind_stropt(hwo, SR_DI_COUPLING, SR_HWCAP_FILTER); + break; + } + } +} + +void HwCap::expose_enum(const struct sr_hwcap_option *hwo, + const vector< pair > &values, int opt) +{ + _properties.push_back(shared_ptr( + new Enum(QString(hwo->shortname), values, + function(), + bind(sr_dev_config_set, _sdi, opt, _1)))); +} + +void HwCap::bind_stropt(const struct sr_hwcap_option *hwo, int id, int opt) +{ + const char **stropts; + if (sr_info_get(_sdi->driver, id, + (const void **)&stropts, _sdi) != SR_OK) + return; + + vector< pair > values; + for (int i = 0; stropts[i]; i++) + values.push_back(make_pair(stropts[i], stropts[i])); + + expose_enum(hwo, values, opt); +} + +void HwCap::bind_buffer_size(const struct sr_hwcap_option *hwo) +{ + const uint64_t *sizes; + if (sr_info_get(_sdi->driver, SR_DI_BUFFERSIZES, + (const void **)&sizes, _sdi) != SR_OK) + return; + + vector< pair > values; + for (int i = 0; sizes[i]; i++) + values.push_back(make_pair(sizes + i, + QString("%1").arg(sizes[i]))); + + expose_enum(hwo, values, SR_HWCAP_BUFFERSIZE); +} + +void HwCap::bind_time_base(const struct sr_hwcap_option *hwo) +{ + struct sr_rational *timebases; + if (sr_info_get(_sdi->driver, SR_DI_TIMEBASES, + (const void **)&timebases, _sdi) != SR_OK) + return; + + vector< pair > values; + for (int i = 0; timebases[i].p && timebases[i].q; i++) + values.push_back(make_pair(timebases + i, + QString(sr_period_string( + timebases[i].p * timebases[i].q)))); + + expose_enum(hwo, values, SR_HWCAP_TIMEBASE); +} + +void HwCap::bind_vdiv(const struct sr_hwcap_option *hwo) +{ + struct sr_rational *vdivs; + if (sr_info_get(_sdi->driver, SR_DI_VDIVS, + (const void **)&vdivs, _sdi) != SR_OK) + return; + + vector< pair > values; + for (int i = 0; vdivs[i].p && vdivs[i].q; i++) + values.push_back(make_pair(vdivs + i, + QString(sr_voltage_string(vdivs + i)))); + + expose_enum(hwo, values, SR_HWCAP_VDIV); } } // binding diff --git a/pv/prop/binding/hwcap.h b/pv/prop/binding/hwcap.h index 68487201..27c7c1eb 100644 --- a/pv/prop/binding/hwcap.h +++ b/pv/prop/binding/hwcap.h @@ -21,6 +21,8 @@ #ifndef PULSEVIEW_PV_PROP_BINDING_HWCAP_H #define PULSEVIEW_PV_PROP_BINDING_HWCAP_H +#include + extern "C" { #include } @@ -36,6 +38,18 @@ class HwCap : public Binding public: HwCap(struct sr_dev_inst *sdi); +private: + void expose_enum(const struct sr_hwcap_option *hwo, + const std::vector > &values, + int opt); + + void bind_stropt(const struct sr_hwcap_option *hwo, int id, + int opt); + + void bind_buffer_size(const struct sr_hwcap_option *hwo); + void bind_time_base(const struct sr_hwcap_option *hwo); + void bind_vdiv(const struct sr_hwcap_option *hwo); + protected: const struct sr_dev_inst *_sdi; }; -- 2.30.2