]> sigrok.org Git - libsigrok.git/commitdiff
bindings: Add packet constructors.
authorMartin Ling <redacted>
Wed, 12 Nov 2014 12:37:22 +0000 (12:37 +0000)
committerUwe Hermann <redacted>
Thu, 13 Nov 2014 17:37:57 +0000 (18:37 +0100)
bindings/cxx/classes.cpp
bindings/cxx/include/libsigrok/libsigrok.hpp

index bed6bed8529edb170c1cfe5c8a22fd6a2d2a1816..7becfb65e4ae472b44c0843e96d3f26731ea8089 100644 (file)
@@ -221,6 +221,70 @@ shared_ptr<UserDevice> Context::create_user_device(
                new UserDevice(vendor, model, version), UserDevice::Deleter());
 }
 
+shared_ptr<Packet> 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<Packet>(new Packet(nullptr, packet), Packet::Deleter());
+}
+
+shared_ptr<Packet> Context::create_meta_packet(
+       map<const ConfigKey *, Glib::VariantBase> 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<Packet>(new Packet(nullptr, packet), Packet::Deleter());
+}
+
+shared_ptr<Packet> 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<Packet>(new Packet(nullptr, packet), Packet::Deleter());
+}
+
+shared_ptr<Packet> Context::create_analog_packet(
+       vector<shared_ptr<Channel> > channels,
+       float *data_pointer, unsigned int num_samples, const Quantity *mq,
+       const Unit *unit, vector<const QuantityFlag *> 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<Packet>(new Packet(nullptr, packet), Packet::Deleter());
+}
+
 shared_ptr<Session> Context::load_session(string filename)
 {
        return shared_ptr<Session>(
index 6b4fbfc175fb364c57b87c437f0ab00ba9ef51e1..1c99670360c5657a82b62f3f7c4866ecfbf54ce8 100644 (file)
@@ -267,6 +267,19 @@ public:
        /** Create a new user device. */
        shared_ptr<UserDevice> create_user_device(
                string vendor, string model, string version);
+       /** Create a header packet. */
+       shared_ptr<Packet> create_header_packet(Glib::TimeVal start_time);
+       /** Create a meta packet. */
+       shared_ptr<Packet> create_meta_packet(
+               map<const ConfigKey *, Glib::VariantBase> config);
+       /** Create a logic packet. */
+       shared_ptr<Packet> create_logic_packet(
+               void *data_pointer, size_t data_length, unsigned int unit_size);
+       /** Create an analog packet. */
+       shared_ptr<Packet> create_analog_packet(
+               vector<shared_ptr<Channel> > channels,
+               float *data_pointer, unsigned int num_samples, const Quantity *mq,
+               const Unit *unit, vector<const QuantityFlag *> mqflags);
        /** Load a saved session.
         * @param filename File name string. */
        shared_ptr<Session> load_session(string filename);
@@ -470,6 +483,7 @@ protected:
        friend class ChannelGroup;
        friend class Session;
        friend class TriggerStage;
+       friend class Context;
 };
 
 /** A group of channels on a device, which share some configuration */
@@ -741,6 +755,7 @@ protected:
        friend class Meta;
        friend class Logic;
        friend class Analog;
+       friend class Context;
 };
 
 /** Abstract base class for datafeed packet payloads */