X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=bindings%2Fcxx%2Fclasses.cpp;h=03b81edb3cc0da0b0256ea751199e976cc5aa631;hb=176d785d33a28a1bb24f2ee483595ec54f7b52b6;hp=3be1d99477d45818bd94598ff7a3b5391ff5599a;hpb=8141a0325c2d31a37ecaeef6532d932112700f01;p=libsigrok.git diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index 3be1d994..03b81edb 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -101,7 +101,7 @@ SR_PRIV int ResourceReader::close_callback(struct sr_resource *res, return SR_OK; } -SR_PRIV ssize_t ResourceReader::read_callback(const struct sr_resource *res, +SR_PRIV gssize ResourceReader::read_callback(const struct sr_resource *res, void *buf, size_t count, void *cb_data) noexcept { try { @@ -128,19 +128,19 @@ Context::Context() : if (struct sr_dev_driver **driver_list = sr_driver_list(_structure)) for (int i = 0; driver_list[i]; i++) { unique_ptr driver {new Driver{driver_list[i]}}; - _drivers.emplace(driver->name(), move(driver)); + _drivers.insert(make_pair(driver->name(), move(driver))); } if (const struct sr_input_module **input_list = sr_input_list()) for (int i = 0; input_list[i]; i++) { unique_ptr input {new InputFormat{input_list[i]}}; - _input_formats.emplace(input->name(), move(input)); + _input_formats.insert(make_pair(input->name(), move(input))); } if (const struct sr_output_module **output_list = sr_output_list()) for (int i = 0; output_list[i]; i++) { unique_ptr output {new OutputFormat{output_list[i]}}; - _output_formats.emplace(output->name(), move(output)); + _output_formats.insert(make_pair(output->name(), move(output))); } } @@ -161,7 +161,7 @@ map> Context::drivers() { const auto &name = entry.first; const auto &driver = entry.second; - result.emplace(name, driver->share_owned_by(shared_from_this())); + result.insert({name, driver->share_owned_by(shared_from_this())}); } return result; } @@ -173,7 +173,7 @@ map> Context::input_formats() { const auto &name = entry.first; const auto &input_format = entry.second; - result.emplace(name, input_format->share_owned_by(shared_from_this())); + result.insert({name, input_format->share_owned_by(shared_from_this())}); } return result; } @@ -185,7 +185,7 @@ map> Context::output_formats() { const auto &name = entry.first; const auto &output_format = entry.second; - result.emplace(name, output_format->share_owned_by(shared_from_this())); + result.insert({name, output_format->share_owned_by(shared_from_this())}); } return result; } @@ -317,15 +317,39 @@ shared_ptr Context::create_analog_packet( { auto analog = g_new0(struct sr_datafeed_analog, 1); auto meaning = g_new0(struct sr_analog_meaning, 1); + auto encoding = g_new0(struct sr_analog_encoding, 1); + auto spec = g_new0(struct sr_analog_spec, 1); analog->meaning = meaning; for (const auto &channel : channels) meaning->channels = g_slist_append(meaning->channels, channel->_structure); - analog->num_samples = num_samples; meaning->mq = static_cast(mq->id()); meaning->unit = static_cast(unit->id()); meaning->mqflags = static_cast(QuantityFlag::mask_from_flags(move(mqflags))); + + analog->encoding = encoding; + + encoding->unitsize = sizeof(float); + encoding->is_signed = TRUE; + encoding->is_float = TRUE; +#ifdef WORDS_BIGENDIAN + encoding->is_bigendian = TRUE; +#else + encoding->is_bigendian = FALSE; +#endif + encoding->digits = 0; + encoding->is_digits_decimal = FALSE; + encoding->scale.p = 1; + encoding->scale.q = 1; + encoding->offset.p = 0; + encoding->offset.q = 1; + + analog->spec = spec; + + spec->spec_digits = 0; + + analog->num_samples = num_samples; analog->data = data_pointer; auto packet = g_new(struct sr_datafeed_packet, 1); packet->type = SR_DF_ANALOG; @@ -410,9 +434,11 @@ set Driver::scan_options() const { GArray *opts = sr_driver_scan_options_list(_structure); set result; - 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; } @@ -483,10 +509,11 @@ set Configurable::config_keys() const 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; } @@ -547,14 +574,14 @@ Device::Device(struct sr_dev_inst *structure) : { auto *const ch = static_cast(entry->data); unique_ptr channel {new Channel{ch}}; - _channels.emplace(ch, move(channel)); + _channels.insert(make_pair(ch, move(channel))); } for (GSList *entry = sr_dev_inst_channel_groups_get(structure); entry; entry = entry->next) { auto *const cg = static_cast(entry->data); unique_ptr group {new ChannelGroup{this, cg}}; - _channel_groups.emplace(group->name(), move(group)); + _channel_groups.insert(make_pair(group->name(), move(group))); } } @@ -609,7 +636,7 @@ Device::channel_groups() { const auto &name = entry.first; const auto &channel_group = entry.second; - result.emplace(name, channel_group->share_owned_by(get_shared_from_this())); + result.insert({name, channel_group->share_owned_by(get_shared_from_this())}); } return result; } @@ -668,7 +695,7 @@ shared_ptr UserDevice::add_channel(unsigned int index, GSList *const last = g_slist_last(sr_dev_inst_channels_get(Device::_structure)); auto *const ch = static_cast(last->data); unique_ptr channel {new Channel{ch}}; - _channels.emplace(ch, move(channel)); + _channels.insert(make_pair(ch, move(channel))); return get_channel(ch); } @@ -741,7 +768,7 @@ vector> ChannelGroup::channels() return result; } -Trigger::Trigger(shared_ptr context, string name) : +Trigger::Trigger(shared_ptr context, string name) : _structure(sr_trigger_new(name.c_str())), _context(move(context)) { @@ -785,7 +812,7 @@ TriggerStage::TriggerStage(struct sr_trigger_stage *structure) : TriggerStage::~TriggerStage() { } - + int TriggerStage::number() const { return _structure->stage; @@ -891,7 +918,7 @@ Session::Session(shared_ptr context, string filename) : for (GSList *dev = dev_list; dev; dev = dev->next) { auto *const sdi = static_cast(dev->data); unique_ptr device {new SessionDevice{sdi}}; - _owned_devices.emplace(sdi, move(device)); + _owned_devices.insert(make_pair(sdi, move(device))); } _context->_session = this; } @@ -1185,6 +1212,11 @@ void *Analog::data_pointer() 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; @@ -1200,6 +1232,58 @@ vector> Analog::channels() 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 Analog::scale() +{ + unique_ptr 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 Analog::offset() +{ + unique_ptr 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); @@ -1215,6 +1299,36 @@ vector Analog::mq_flags() const return QuantityFlag::flags_from_mask(_structure->meaning->mqflags); } +Rational::Rational(const struct sr_rational *structure) : + _structure(structure) +{ +} + +Rational::~Rational() +{ +} + +shared_ptr Rational::share_owned_by(shared_ptr _parent) +{ + return static_pointer_cast( + 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) { @@ -1255,7 +1369,7 @@ map> InputFormat::options() shared_ptr