*/
/* Needed for isascii(), as used in the GNU libstdc++ headers */
+/* Needed in strutil.c for POSIX.1-2008 locale functions */
#ifndef _XOPEN_SOURCE
-#define _XOPEN_SOURCE 600
+#define _XOPEN_SOURCE 700
#endif
#include <config.h>
return result;
}
+shared_ptr<InputFormat> Context::input_format_match(string filename)
+{
+ const struct sr_input *input;
+ const struct sr_input_module *imod;
+ int rc;
+
+ /*
+ * Have the input module looked up for the specified file.
+ * Failed lookup (or "successful lookup" with an empty result)
+ * are non-fatal. Free the sr_input that was created by the
+ * lookup routine, but grab the input module kind and return an
+ * InputFormat instance to the application. This works because
+ * the application passes a filename, no input data got buffered
+ * in the sr_input that we release.
+ */
+ input = NULL;
+ rc = sr_input_scan_file(filename.c_str(), &input);
+ if (rc != SR_OK)
+ return nullptr;
+ if (!input)
+ return nullptr;
+ imod = sr_input_module_get(input);
+ sr_input_free(input);
+ return shared_ptr<InputFormat>{new InputFormat{imod}, default_delete<InputFormat>{}};
+}
+
map<string, shared_ptr<OutputFormat>> Context::output_formats()
{
map<string, shared_ptr<OutputFormat>> result;
try {
(*callback)(LogLevel::get(loglevel), message.get());
- } catch (Error e) {
+ } catch (Error &e) {
return e.result;
}
shared_ptr<Packet> Context::create_analog_packet(
vector<shared_ptr<Channel> > channels,
- float *data_pointer, unsigned int num_samples, const Quantity *mq,
+ const 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);
spec->spec_digits = 0;
analog->num_samples = num_samples;
- analog->data = data_pointer;
+ analog->data = (float*)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}, default_delete<Packet>{}};
}
+shared_ptr<Packet> Context::create_end_packet()
+{
+ auto packet = g_new(struct sr_datafeed_packet, 1);
+ packet->type = SR_DF_END;
+ return shared_ptr<Packet>{new Packet{nullptr, packet},
+ default_delete<Packet>{}};
+}
+
shared_ptr<Session> Context::load_session(string filename)
{
return shared_ptr<Session>{
_owned_devices.emplace(sdi, move(device));
}
_context->_session = this;
+ g_slist_free(dev_list);
}
Session::~Session()
auto *const sdi = static_cast<struct sr_dev_inst *>(dev->data);
result.push_back(get_device(sdi));
}
+ g_slist_free(dev_list);
return result;
}
return QuantityFlag::flags_from_mask(_structure->meaning->mqflags);
}
+shared_ptr<Logic> Analog::get_logic_via_threshold(float threshold,
+ uint8_t *data_ptr) const
+{
+ auto datafeed = g_new(struct sr_datafeed_logic, 1);
+ datafeed->length = num_samples();
+ datafeed->unitsize = 1;
+
+ if (data_ptr)
+ datafeed->data = data_ptr;
+ else
+ datafeed->data = g_malloc(datafeed->length);
+
+ shared_ptr<Logic> logic =
+ shared_ptr<Logic>{new Logic{datafeed}, default_delete<Logic>{}};
+
+ check(sr_a2l_threshold(_structure, threshold,
+ (uint8_t*)datafeed->data, datafeed->length));
+
+ return logic;
+}
+
+shared_ptr<Logic> Analog::get_logic_via_schmitt_trigger(float lo_thr,
+ float hi_thr, uint8_t *state, uint8_t *data_ptr) const
+{
+ auto datafeed = g_new(struct sr_datafeed_logic, 1);
+ datafeed->length = num_samples();
+ datafeed->unitsize = 1;
+
+ if (data_ptr)
+ datafeed->data = data_ptr;
+ else
+ datafeed->data = g_malloc(datafeed->length);
+
+ shared_ptr<Logic> logic =
+ shared_ptr<Logic>{new Logic{datafeed}, default_delete<Logic>{}};
+
+ check(sr_a2l_schmitt_trigger(_structure, lo_thr, hi_thr, state,
+ (uint8_t*)datafeed->data, datafeed->length));
+
+ return logic;
+}
+
Rational::Rational(const struct sr_rational *structure) :
_structure(structure)
{
check(sr_output_free(_structure));
}
+shared_ptr<OutputFormat> Output::format()
+{
+ return _format;
+}
+
string Output::receive(shared_ptr<Packet> packet)
{
GString *out;