opts = sr_dev_options(config_driver, config_sdi, config_channel_group);
- for (guint i = 0; i < opts->len; i++)
- result.insert(ConfigKey::get(g_array_index(opts, uint32_t, i)));
-
- g_array_free(opts, TRUE);
+ if (opts) {
+ for (guint i = 0; i < opts->len; i++)
+ result.insert(ConfigKey::get(g_array_index(opts, uint32_t, i)));
+ g_array_free(opts, TRUE);
+ }
return result;
}
return result;
}
-Trigger::Trigger(shared_ptr<Context> context, string name) :
+Trigger::Trigger(shared_ptr<Context> context, string name) :
_structure(sr_trigger_new(name.c_str())),
_context(move(context))
{
TriggerStage::~TriggerStage()
{
}
-
+
int TriggerStage::number() const
{
return _structure->stage;
return _structure->data;
}
+void Analog::get_data_as_float(float *dest)
+{
+ check(sr_analog_to_float(_structure, dest));
+}
+
unsigned int Analog::num_samples() const
{
return _structure->num_samples;
return result;
}
+unsigned int Analog::unitsize() const
+{
+ return _structure->encoding->unitsize;
+}
+
+bool Analog::is_signed() const
+{
+ return _structure->encoding->is_signed;
+}
+
+bool Analog::is_float() const
+{
+ return _structure->encoding->is_float;
+}
+
+bool Analog::is_bigendian() const
+{
+ return _structure->encoding->is_bigendian;
+}
+
+int Analog::digits() const
+{
+ return _structure->encoding->digits;
+}
+
+bool Analog::is_digits_decimal() const
+{
+ return _structure->encoding->is_digits_decimal;
+}
+
+shared_ptr<Rational> Analog::scale()
+{
+ unique_ptr<Rational> scale;
+ scale.reset(new Rational(&(_structure->encoding->scale)));
+
+ if (scale)
+ return scale->share_owned_by(shared_from_this());
+ else
+ throw Error(SR_ERR_NA);
+}
+
+shared_ptr<Rational> Analog::offset()
+{
+ unique_ptr<Rational> offset;
+ offset.reset(new Rational(&(_structure->encoding->offset)));
+
+ if (offset)
+ return offset->share_owned_by(shared_from_this());
+ else
+ throw Error(SR_ERR_NA);
+}
+
const Quantity *Analog::mq() const
{
return Quantity::get(_structure->meaning->mq);
return QuantityFlag::flags_from_mask(_structure->meaning->mqflags);
}
+Rational::Rational(const struct sr_rational *structure) :
+ _structure(structure)
+{
+}
+
+Rational::~Rational()
+{
+}
+
+shared_ptr<Rational> Rational::share_owned_by(shared_ptr<Analog> _parent)
+{
+ return static_pointer_cast<Rational>(
+ ParentOwned::share_owned_by(_parent));
+}
+
+int64_t Rational::numerator() const
+{
+ return _structure->p;
+}
+
+uint64_t Rational::denominator() const
+{
+ return _structure->q;
+}
+
+float Rational::value() const
+{
+ return (float)(_structure->p) / (float)(_structure->q);
+}
+
InputFormat::InputFormat(const struct sr_input_module *structure) :
_structure(structure)
{
{
auto gstr = g_string_new_len(static_cast<char *>(data), length);
auto ret = sr_input_send(_structure, gstr);
- g_string_free(gstr, false);
+ g_string_free(gstr, true);
check(ret);
}
check(sr_input_end(_structure));
}
+void Input::reset()
+{
+ check(sr_input_reset(_structure));
+}
+
Input::~Input()
{
sr_input_free(_structure);
return result;
}
+Glib::VariantBase Option::parse_string(string value)
+{
+ enum sr_datatype dt;
+ Glib::VariantBase dflt = default_value();
+ GVariant *tmpl = dflt.gobj();
+
+ if (g_variant_is_of_type(tmpl, G_VARIANT_TYPE_UINT64)) {
+ dt = SR_T_UINT64;
+ } else if (g_variant_is_of_type(tmpl, G_VARIANT_TYPE_STRING)) {
+ dt = SR_T_STRING;
+ } else if (g_variant_is_of_type(tmpl, G_VARIANT_TYPE_BOOLEAN)) {
+ dt = SR_T_BOOL;
+ } else if (g_variant_is_of_type(tmpl, G_VARIANT_TYPE_DOUBLE)) {
+ dt = SR_T_FLOAT;
+ } else if (g_variant_is_of_type(tmpl, G_VARIANT_TYPE_INT32)) {
+ dt = SR_T_INT32;
+ } else {
+ throw Error(SR_ERR_BUG);
+ }
+ return ConfigKey::parse_string(value, dt);
+}
+
OutputFormat::OutputFormat(const struct sr_output_module *structure) :
_structure(structure)
{