X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=inline;f=bindings%2Fcxx%2Fclasses.cpp;h=6c3b15f159018d90e14d57f97fc6f7ca34f51cb1;hb=3f03ffaf2f7c9c65d0bf35e611df8fb720ed0e8c;hp=83f1fbf73567f9ab2a5460e3a73f2668680645de;hpb=80fe524740f28f44111d9f98bbb0e44294bdf3d2;p=libsigrok.git
diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp
index 83f1fbf7..6c3b15f1 100644
--- a/bindings/cxx/classes.cpp
+++ b/bindings/cxx/classes.cpp
@@ -17,7 +17,7 @@
* along with this program. If not, see .
*/
-#include "libsigrok/libsigrok.hpp"
+#include
#include
#include
@@ -77,7 +77,7 @@ Context::Context() :
{
check(sr_init(&_structure));
- struct sr_dev_driver **driver_list = sr_driver_list();
+ struct sr_dev_driver **driver_list = sr_driver_list(_structure);
if (driver_list)
for (int i = 0; driver_list[i]; i++)
_drivers[driver_list[i]->name] =
@@ -214,6 +214,77 @@ shared_ptr Context::create_session()
new Session(shared_from_this()), Session::Deleter());
}
+shared_ptr Context::create_user_device(
+ string vendor, string model, string version)
+{
+ return shared_ptr(
+ new UserDevice(vendor, model, version), UserDevice::Deleter());
+}
+
+shared_ptr Context::create_header_packet(Glib::TimeVal start_time)
+{
+ auto header = g_new(struct sr_datafeed_header, 1);
+ header->feed_version = 1;
+ header->starttime.tv_sec = start_time.tv_sec;
+ header->starttime.tv_usec = start_time.tv_usec;
+ auto packet = g_new(struct sr_datafeed_packet, 1);
+ packet->type = SR_DF_HEADER;
+ packet->payload = header;
+ return shared_ptr(new Packet(nullptr, packet), Packet::Deleter());
+}
+
+shared_ptr Context::create_meta_packet(
+ map config)
+{
+ auto meta = g_new0(struct sr_datafeed_meta, 1);
+ for (auto input : config)
+ {
+ auto key = input.first;
+ auto value = input.second;
+ auto output = g_new(struct sr_config, 1);
+ output->key = key->id();
+ output->data = value.gobj();
+ g_variant_ref(output->data);
+ meta->config = g_slist_append(meta->config, output);
+ }
+ auto packet = g_new(struct sr_datafeed_packet, 1);
+ packet->type = SR_DF_META;
+ packet->payload = meta;
+ return shared_ptr(new Packet(nullptr, packet), Packet::Deleter());
+}
+
+shared_ptr Context::create_logic_packet(
+ void *data_pointer, size_t data_length, unsigned int unit_size)
+{
+ auto logic = g_new(struct sr_datafeed_logic, 1);
+ logic->length = data_length;
+ logic->unitsize = unit_size;
+ logic->data = data_pointer;
+ auto packet = g_new(struct sr_datafeed_packet, 1);
+ packet->type = SR_DF_LOGIC;
+ packet->payload = logic;
+ return shared_ptr(new Packet(nullptr, packet), Packet::Deleter());
+}
+
+shared_ptr Context::create_analog_packet(
+ vector > channels,
+ float *data_pointer, unsigned int num_samples, const Quantity *mq,
+ const Unit *unit, vector mqflags)
+{
+ auto analog = g_new0(struct sr_datafeed_analog, 1);
+ for (auto channel : channels)
+ analog->channels = g_slist_append(analog->channels, channel->_structure);
+ analog->num_samples = num_samples;
+ analog->mq = mq->id();
+ analog->unit = unit->id();
+ analog->mqflags = QuantityFlag::mask_from_flags(mqflags);
+ analog->data = data_pointer;
+ auto packet = g_new(struct sr_datafeed_packet, 1);
+ packet->type = SR_DF_ANALOG;
+ packet->payload = analog;
+ return shared_ptr(new Packet(nullptr, packet), Packet::Deleter());
+}
+
shared_ptr Context::load_session(string filename)
{
return shared_ptr(
@@ -247,6 +318,20 @@ shared_ptr Context::open_stream(string header)
new Input(shared_from_this(), input), Input::Deleter());
}
+map Context::serials(shared_ptr driver)
+{
+ GSList *serial_list = sr_serial_list(driver ? driver->_structure : NULL);
+ map serials;
+
+ for (GSList *serial = serial_list; serial; serial = serial->next) {
+ struct sr_serial_port *port = (sr_serial_port *) serial->data;
+ serials[string(port->name)] = string(port->description);
+ }
+
+ g_slist_free_full(serial_list, (GDestroyNotify)sr_serial_free);
+ return serials;
+}
+
Driver::Driver(struct sr_dev_driver *structure) :
ParentOwned(structure),
Configurable(structure, NULL, NULL),
@@ -400,7 +485,7 @@ bool Configurable::config_check(const ConfigKey *key,
for (gsize i = 0; i < num_opts; i++)
{
- if ((opts[i] & SR_CONF_MASK) == key->id())
+ if ((opts[i] & SR_CONF_MASK) == (uint32_t) key->id())
{
g_variant_unref(gvar_opts);
return true;
@@ -522,6 +607,34 @@ shared_ptr HardwareDevice::driver()
return _driver;
}
+UserDevice::UserDevice(string vendor, string model, string version) :
+ UserOwned(sr_dev_inst_user_new(
+ vendor.c_str(), model.c_str(), version.c_str())),
+ Device(UserOwned::_structure)
+{
+}
+
+UserDevice::~UserDevice()
+{
+}
+
+shared_ptr UserDevice::get_shared_from_this()
+{
+ return static_pointer_cast(shared_from_this());
+}
+
+shared_ptr UserDevice::add_channel(unsigned int index,
+ const ChannelType *type, string name)
+{
+ check(sr_dev_inst_channel_add(Device::_structure,
+ index, type->id(), name.c_str()));
+ struct sr_channel *structure = (struct sr_channel *)
+ g_slist_last(sr_dev_inst_channels_get(Device::_structure))->data;
+ Channel *channel = new Channel(structure);
+ _channels[structure] = channel;
+ return get_channel(structure);
+}
+
Channel::Channel(struct sr_channel *structure) :
ParentOwned(structure),
_type(ChannelType::get(_structure->type))
@@ -539,8 +652,7 @@ string Channel::name()
void Channel::set_name(string name)
{
- check(sr_dev_channel_name_set(_parent->_structure,
- _structure->index, name.c_str()));
+ check(sr_dev_channel_name_set(_structure, name.c_str()));
}
const ChannelType *Channel::type()
@@ -555,7 +667,7 @@ bool Channel::enabled()
void Channel::set_enabled(bool value)
{
- check(sr_dev_channel_enable(_parent->_structure, _structure->index, value));
+ check(sr_dev_channel_enable(_structure, value));
}
unsigned int Channel::index()
@@ -776,7 +888,7 @@ Session::Session(shared_ptr context) :
_context(context),
_saving(false)
{
- check(sr_session_new(&_structure));
+ check(sr_session_new(context->_structure, &_structure));
_context->_session = this;
}
@@ -786,7 +898,7 @@ Session::Session(shared_ptr context, string filename) :
_filename(filename),
_saving(false)
{
- check(sr_session_load(filename.c_str(), &_structure));
+ check(sr_session_load(context->_structure, filename.c_str(), &_structure));
GSList *dev_list;
check(sr_session_dev_list(_structure, &dev_list));
for (GSList *dev = dev_list; dev; dev = dev->next)
@@ -1039,7 +1151,11 @@ shared_ptr Session::trigger()
void Session::set_trigger(shared_ptr trigger)
{
- check(sr_session_trigger_set(_structure, trigger->_structure));
+ if (!trigger)
+ // Set NULL trigger, i.e. remove any trigger from the session.
+ check(sr_session_trigger_set(_structure, NULL));
+ else
+ check(sr_session_trigger_set(_structure, trigger->_structure));
_trigger = trigger;
}
@@ -1048,6 +1164,11 @@ string Session::filename()
return _filename;
}
+shared_ptr Session::context()
+{
+ return _context;
+}
+
Packet::Packet(shared_ptr device,
const struct sr_datafeed_packet *structure) :
UserOwned(structure),
@@ -1263,15 +1384,27 @@ string InputFormat::description()
return valid_string(sr_input_description_get(_structure));
}
+vector InputFormat::extensions()
+{
+ vector exts;
+ for (const char *const *e = sr_input_extensions_get(_structure);
+ e && *e; e++)
+ exts.push_back(*e);
+ return exts;
+}
+
map> InputFormat::options()
{
const struct sr_option **options = sr_input_options_get(_structure);
- auto option_array = shared_ptr(
- options, sr_input_options_free);
map> result;
- for (int i = 0; options[i]; i++)
- result[options[i]->id] = shared_ptr