const struct sr_datafeed_packet *pkt)
{
auto device = session->devices[sdi];
- auto packet = shared_ptr<Packet>(new Packet(pkt), Packet::Deleter());
+ auto packet = shared_ptr<Packet>(new Packet(device, pkt), Packet::Deleter());
callback(device, packet);
}
this->trigger = trigger;
}
-Packet::Packet(const struct sr_datafeed_packet *structure) :
- structure(structure)
+Packet::Packet(shared_ptr<Device> device,
+ const struct sr_datafeed_packet *structure) :
+ structure(structure),
+ device(device)
{
switch (structure->type)
{
+ case SR_DF_HEADER:
+ payload = new Header(
+ static_cast<const struct sr_datafeed_header *>(
+ structure->payload));
+ break;
+ case SR_DF_META:
+ payload = new Meta(
+ static_cast<const struct sr_datafeed_meta *>(
+ structure->payload));
+ break;
case SR_DF_LOGIC:
payload = new Logic(
static_cast<const struct sr_datafeed_logic *>(
static_cast<const struct sr_datafeed_analog *>(
structure->payload));
break;
- default:
- payload = NULL;
- break;
}
}
return PacketType::get(structure->type);
}
-PacketPayload *Packet::get_payload()
+shared_ptr<PacketPayload> Packet::get_payload()
{
- return payload;
+ return payload->get_shared_pointer(this);
}
PacketPayload::PacketPayload()
{
}
-Logic::Logic(const struct sr_datafeed_logic *structure) : PacketPayload(),
- structure(structure),
- data(static_cast<uint8_t *>(structure->data),
- static_cast<uint8_t *>(structure->data) + structure->length) {}
+Header::Header(const struct sr_datafeed_header *structure) :
+ PacketPayload(),
+ StructureWrapper<Packet, const struct sr_datafeed_header>(structure)
+{
+}
+
+Header::~Header()
+{
+}
+
+int Header::get_feed_version()
+{
+ return structure->feed_version;
+}
+
+Glib::TimeVal Header::get_start_time()
+{
+ return Glib::TimeVal(
+ structure->starttime.tv_sec,
+ structure->starttime.tv_usec);
+}
+
+Meta::Meta(const struct sr_datafeed_meta *structure) :
+ PacketPayload(),
+ StructureWrapper<Packet, const struct sr_datafeed_meta>(structure)
+{
+}
+
+Meta::~Meta()
+{
+}
+
+map<const ConfigKey *, Glib::VariantBase> Meta::get_config()
+{
+ map<const ConfigKey *, Glib::VariantBase> result;
+ for (auto l = structure->config; l; l = l->next)
+ {
+ auto config = (struct sr_config *) l->data;
+ result[ConfigKey::get(config->key)] = Glib::VariantBase(config->data);
+ }
+ return result;
+}
+
+Logic::Logic(const struct sr_datafeed_logic *structure) :
+ PacketPayload(),
+ StructureWrapper<Packet, const struct sr_datafeed_logic>(structure)
+{
+}
Logic::~Logic()
{
}
-void *Logic::get_data()
+void *Logic::get_data_pointer()
{
return structure->data;
}
-size_t Logic::get_data_size()
+size_t Logic::get_data_length()
{
return structure->length;
}
+unsigned int Logic::get_unit_size()
+{
+ return structure->unitsize;
+}
+
Analog::Analog(const struct sr_datafeed_analog *structure) :
PacketPayload(),
- structure(structure)
+ StructureWrapper<Packet, const struct sr_datafeed_analog>(structure)
{
}
{
}
-void *Analog::get_data()
+float *Analog::get_data_pointer()
{
return structure->data;
}
-size_t Analog::get_data_size()
+unsigned int Analog::get_num_samples()
{
- return structure->num_samples * sizeof(float);
+ return structure->num_samples;
}
-unsigned int Analog::get_num_samples()
+vector<shared_ptr<Channel>> Analog::get_channels()
{
- return structure->num_samples;
+ vector<shared_ptr<Channel>> result;
+ for (auto l = structure->channels; l; l = l->next)
+ result.push_back(parent->device->get_channel(
+ (struct sr_channel *)l->data));
+ return result;
}
const Quantity *Analog::get_mq()
friend class Channel;
friend class ChannelGroup;
friend class Output;
+ friend class Analog;
};
/** A real hardware device, connected via a driver */
};
/** A packet on the session datafeed */
-class SR_API Packet
+class SR_API Packet : public enable_shared_from_this<Packet>
{
public:
/** Type of this packet. */
const PacketType *get_type();
/** Payload of this packet. */
- PacketPayload *get_payload();
+ shared_ptr<PacketPayload> get_payload();
protected:
- Packet(const struct sr_datafeed_packet *structure);
+ Packet(shared_ptr<Device> device,
+ const struct sr_datafeed_packet *structure);
~Packet();
const struct sr_datafeed_packet *structure;
+ shared_ptr<Device> device;
PacketPayload *payload;
/** Deleter needed to allow shared_ptr use with protected destructor. */
class Deleter
friend class Session;
friend class Output;
friend class DatafeedCallbackData;
+ friend class Header;
+ friend class Meta;
+ friend class Logic;
+ friend class Analog;
};
/** Abstract base class for datafeed packet payloads */
protected:
PacketPayload();
virtual ~PacketPayload() = 0;
- virtual void *get_data() = 0;
- virtual size_t get_data_size() = 0;
+ shared_ptr<PacketPayload> get_shared_pointer(Packet *parent) {
+ return static_pointer_cast<PacketPayload>(get_shared_pointer(parent));
+ }
+ /** Deleter needed to allow shared_ptr use with protected destructor. */
+ class Deleter
+ {
+ public:
+ void operator()(PacketPayload *payload) { delete payload; }
+ };
+ friend class Deleter;
friend class Packet;
friend class Output;
};
+/** Payload of a datafeed header packet */
+class SR_API Header : public PacketPayload,
+ public StructureWrapper<Packet, const struct sr_datafeed_header>
+{
+public:
+ int get_feed_version();
+ Glib::TimeVal get_start_time();
+protected:
+ Header(const struct sr_datafeed_header *structure);
+ ~Header();
+ const struct sr_datafeed_header *structure;
+ friend class Packet;
+};
+
+/** Payload of a datafeed metadata packet */
+class SR_API Meta : public PacketPayload,
+ public StructureWrapper<Packet, const struct sr_datafeed_meta>
+{
+public:
+ map<const ConfigKey *, Glib::VariantBase> get_config();
+protected:
+ Meta(const struct sr_datafeed_meta *structure);
+ ~Meta();
+ const struct sr_datafeed_meta *structure;
+ map<const ConfigKey *, Glib::VariantBase> config;
+ friend class Packet;
+};
+
/** Payload of a datafeed packet with logic data */
-class SR_API Logic : public PacketPayload
+class SR_API Logic : public PacketPayload,
+ public StructureWrapper<Packet, const struct sr_datafeed_logic>
{
+public:
+ /* Pointer to data. */
+ void *get_data_pointer();
+ /* Data length in bytes. */
+ size_t get_data_length();
+ /* Size of each sample in bytes. */
+ unsigned int get_unit_size();
protected:
Logic(const struct sr_datafeed_logic *structure);
~Logic();
const struct sr_datafeed_logic *structure;
- vector<uint8_t> data;
- void *get_data();
- size_t get_data_size();
friend class Packet;
};
/** Payload of a datafeed packet with analog data */
-class SR_API Analog : public PacketPayload
+class SR_API Analog : public PacketPayload,
+ public StructureWrapper<Packet, const struct sr_datafeed_analog>
{
public:
+ /** Pointer to data. */
+ float *get_data_pointer();
/** Number of samples in this packet. */
unsigned int get_num_samples();
+ /** Channels for which this packet contains data. */
+ vector<shared_ptr<Channel> > get_channels();
/** Measured quantity of the samples in this packet. */
const Quantity *get_mq();
/** Unit of the samples in this packet. */
Analog(const struct sr_datafeed_analog *structure);
~Analog();
const struct sr_datafeed_analog *structure;
- void *get_data();
- size_t get_data_size();
friend class Packet;
};
MAP_COMMON(const sigrok::ConfigKey *, Glib::VariantBase, ConfigKey, Variant)
+%typemap(jni) std::map<const sigrok::ConfigKey, Glib::VariantBase> "jobject"
+%typemap(jtype) std::map<const sigrok::ConfigKey, Glib::VariantBase>
+ "java.util.Map<ConfigKey,Variant>"
+
%typemap(out) std::map<const sigrok::ConfigKey *, Glib::VariantBase> {
jclass HashMap = jenv->FindClass("java/util/HashMap");
jmethodID HashMap_init = jenv->GetMethodID(HashMap, "<init>", "()V");
%shared_ptr(sigrok::Session);
%shared_ptr(sigrok::Packet);
%shared_ptr(sigrok::PacketPayload);
+%shared_ptr(sigrok::Header);
+%shared_ptr(sigrok::Meta);
%shared_ptr(sigrok::Analog);
%shared_ptr(sigrok::Logic);
%shared_ptr(sigrok::InputFormat);
map_string_OutputFormat;
typedef std::map<std::string, std::shared_ptr<sigrok::ChannelGroup> >
map_string_ChannelGroup;
+typedef std::map<const sigrok::ConfigKey *, Glib::VariantBase>
+ map_ConfigKey_Variant;
}
%attributeval(sigrok::Context,
devices, get_devices);
%attributestring(sigrok::Session,
- std::shared_ptr<sigrok::Trigger>, trigger, get_trigger, set_trigger)
+ std::shared_ptr<sigrok::Trigger>, trigger, get_trigger, set_trigger);
-%attribute(sigrok::Packet, sigrok::PacketPayload *, payload, get_payload);
+%attributestring(sigrok::Packet,
+ std::shared_ptr<sigrok::PacketPayload>, payload, get_payload);
+
+%attributeval(sigrok::Meta, map_ConfigKey_Variant, config, get_config);
%attribute(sigrok::Analog, int, num_samples, get_num_samples);
%attribute(sigrok::Analog, const sigrok::Quantity *, mq, get_mq);