From: Uwe Hermann Date: Thu, 15 Jun 2017 16:46:14 +0000 (+0200) Subject: Backport recent changes from mainline. X-Git-Tag: libsigrok-0.5.1~6 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8cd15dd4ce2fdbefbcc6e64632c8006e5404f253;p=libsigrok.git Backport recent changes from mainline. This includes all changes from 59cae77e28538120a472aca1aeee6b2c4465e77a serial_stream_detect(): Make a code comment more generic. up to a7600dc5c7712c588f8a940293e50853c88706ca Makefile.am: Install MIME info file in $(datadir)/mime/packages. This is possible since (almost) none of the changes above change or remove public API calls of the library. --- diff --git a/.gitignore b/.gitignore index c2d6b42c..e943562f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ # Editor/IDE cruft *.kate-swp *~ +.*.sw* /*.kdev4 /Makefile.am.user diff --git a/Makefile.am b/Makefile.am index c9842295..148de0ff 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,6 +50,7 @@ lib_LTLIBRARIES = libsigrok.la # Backend files libsigrok_la_SOURCES = \ src/backend.c \ + src/conversion.c \ src/device.c \ src/session.c \ src/session_file.c \ @@ -73,10 +74,12 @@ libsigrok_la_SOURCES += \ src/input/binary.c \ src/input/chronovu_la8.c \ src/input/csv.c \ + src/input/logicport.c \ src/input/raw_analog.c \ src/input/trace32_ad.c \ src/input/vcd.c \ - src/input/wav.c + src/input/wav.c \ + src/input/null.c # Output modules libsigrok_la_SOURCES += \ @@ -91,7 +94,8 @@ libsigrok_la_SOURCES += \ src/output/hex.c \ src/output/ols.c \ src/output/srzip.c \ - src/output/vcd.c + src/output/vcd.c \ + src/output/null.c # Transform modules libsigrok_la_SOURCES += \ @@ -104,7 +108,6 @@ libsigrok_la_SOURCES += \ libsigrok_la_SOURCES += \ src/scpi.h \ src/scpi/scpi.c \ - src/scpi/helpers.c \ src/scpi/scpi_tcp.c if NEED_RPC libsigrok_la_SOURCES += \ @@ -143,18 +146,21 @@ endif # Hardware (DMM chip parsers) libsigrok_la_SOURCES += \ + src/dmm/asycii.c \ + src/dmm/bm25x.c \ + src/dmm/dtm0660.c \ + src/dmm/eev121gw.c \ src/dmm/es519xx.c \ src/dmm/fs9721.c \ src/dmm/fs9922.c \ src/dmm/m2110.c \ src/dmm/metex14.c \ - src/dmm/asycii.c \ + src/dmm/ms8250d.c \ src/dmm/rs9lcd.c \ - src/dmm/bm25x.c \ - src/dmm/ut71x.c \ src/dmm/ut372.c \ + src/dmm/ut71x.c \ src/dmm/vc870.c \ - src/dmm/dtm0660.c + src/dmm/vc96.c # Hardware (LCR chip parsers) if NEED_SERIAL @@ -167,15 +173,22 @@ libsigrok_la_SOURCES += \ src/scale/kern.c # Hardware drivers -noinst_LTLIBRARIES = src/libdrivers.la +noinst_LTLIBRARIES = src/libdrivers.la \ + src/libdrivers_head.la src/libdrivers_tail.la -src/libdrivers.o: src/libdrivers.la - $(AM_V_CCLD)$(LINK) src/libdrivers.la +src/libdrivers.o: src/libdrivers.la \ + src/libdrivers_head.la src/libdrivers_tail.la + $(AM_V_CCLD)$(LINK) src/libdrivers_head.la src/libdrivers.la \ + src/libdrivers_tail.la src/libdrivers.lo: src/libdrivers.o $(AM_V_GEN)echo "# Generated by libtool" > $@ $(AM_V_at)echo "pic_object='libdrivers.o'" >> $@ $(AM_V_at)echo "non_pic_object='libdrivers.o'" >> $@ +src_libdrivers_head_la_SOURCES = src/driver_list_start.c + +src_libdrivers_tail_la_SOURCES = src/driver_list_stop.c + src_libdrivers_la_SOURCES = src/drivers.c if HW_AGILENT_DMM @@ -221,7 +234,9 @@ src_libdrivers_la_SOURCES += \ src/hardware/beaglelogic/beaglelogic.h \ src/hardware/beaglelogic/protocol.h \ src/hardware/beaglelogic/protocol.c \ - src/hardware/beaglelogic/api.c + src/hardware/beaglelogic/api.c \ + src/hardware/beaglelogic/beaglelogic_native.c \ + src/hardware/beaglelogic/beaglelogic_tcp.c endif if HW_BRYMEN_BM86X src_libdrivers_la_SOURCES += \ @@ -272,6 +287,18 @@ src_libdrivers_la_SOURCES += \ src/hardware/demo/protocol.c \ src/hardware/demo/api.c endif +if HW_DREAMSOURCELAB_DSLOGIC +src_libdrivers_la_SOURCES += \ + src/hardware/dreamsourcelab-dslogic/protocol.h \ + src/hardware/dreamsourcelab-dslogic/protocol.c \ + src/hardware/dreamsourcelab-dslogic/api.c +endif +if HW_FLUKE_45 +src_libdrivers_la_SOURCES += \ + src/hardware/fluke-45/protocol.h \ + src/hardware/fluke-45/protocol.c \ + src/hardware/fluke-45/api.c +endif if HW_FLUKE_DMM src_libdrivers_la_SOURCES += \ src/hardware/fluke-dmm/protocol.h \ @@ -288,9 +315,7 @@ if HW_FX2LAFW src_libdrivers_la_SOURCES += \ src/hardware/fx2lafw/protocol.h \ src/hardware/fx2lafw/protocol.c \ - src/hardware/fx2lafw/api.c \ - src/hardware/fx2lafw/dslogic.c \ - src/hardware/fx2lafw/dslogic.h + src/hardware/fx2lafw/api.c endif if HW_GMC_MH_1X_2X src_libdrivers_la_SOURCES += \ @@ -304,12 +329,24 @@ src_libdrivers_la_SOURCES += \ src/hardware/gwinstek-gds-800/protocol.c \ src/hardware/gwinstek-gds-800/api.c endif +if HW_GWINSTEK_GPD +src_libdrivers_la_SOURCES += \ + src/hardware/gwinstek-gpd/protocol.h \ + src/hardware/gwinstek-gpd/protocol.c \ + src/hardware/gwinstek-gpd/api.c +endif if HW_HAMEG_HMO src_libdrivers_la_SOURCES += \ src/hardware/hameg-hmo/protocol.h \ src/hardware/hameg-hmo/protocol.c \ src/hardware/hameg-hmo/api.c endif +if HW_HANTEK_4032L +src_libdrivers_la_SOURCES += \ + src/hardware/hantek-4032l/protocol.h \ + src/hardware/hantek-4032l/protocol.c \ + src/hardware/hantek-4032l/api.c +endif if HW_HANTEK_6XXX src_libdrivers_la_SOURCES += \ src/hardware/hantek-6xxx/protocol.h \ @@ -328,6 +365,12 @@ src_libdrivers_la_SOURCES += \ src/hardware/hp-3457a/protocol.c \ src/hardware/hp-3457a/api.c endif +if HW_HP_3478A +src_libdrivers_la_SOURCES += \ + src/hardware/hp-3478a/protocol.h \ + src/hardware/hp-3478a/protocol.c \ + src/hardware/hp-3478a/api.c +endif if HW_HUNG_CHANG_DSO_2100 src_libdrivers_la_SOURCES += \ src/hardware/hung-chang-dso-2100/protocol.h \ @@ -346,6 +389,12 @@ src_libdrivers_la_SOURCES += \ src/hardware/ikalogic-scanaplus/protocol.c \ src/hardware/ikalogic-scanaplus/api.c endif +if HW_IPDBG_LA +src_libdrivers_la_SOURCES += \ + src/hardware/ipdbg-la/protocol.h \ + src/hardware/ipdbg-la/protocol.c \ + src/hardware/ipdbg-la/api.c +endif if HW_KECHENG_KC_330B src_libdrivers_la_SOURCES += \ src/hardware/kecheng-kc-330b/protocol.h \ @@ -430,6 +479,12 @@ src_libdrivers_la_SOURCES += \ src/hardware/pipistrello-ols/protocol.c \ src/hardware/pipistrello-ols/api.c endif +if HW_RDTECH_DPS +src_libdrivers_la_SOURCES += \ + src/hardware/rdtech-dps/protocol.h \ + src/hardware/rdtech-dps/protocol.c \ + src/hardware/rdtech-dps/api.c +endif if HW_RIGOL_DS src_libdrivers_la_SOURCES += \ src/hardware/rigol-ds/protocol.h \ @@ -448,6 +503,12 @@ src_libdrivers_la_SOURCES += \ src/hardware/saleae-logic16/protocol.c \ src/hardware/saleae-logic16/api.c endif +if HW_SALEAE_LOGIC_PRO +src_libdrivers_la_SOURCES += \ + src/hardware/saleae-logic-pro/protocol.h \ + src/hardware/saleae-logic-pro/protocol.c \ + src/hardware/saleae-logic-pro/api.c +endif if HW_SCPI_PPS src_libdrivers_la_SOURCES += \ src/hardware/scpi-pps/protocol.h \ @@ -465,6 +526,12 @@ if HW_SERIAL_LCR src_libdrivers_la_SOURCES += \ src/hardware/serial-lcr/api.c endif +if HW_SIGLENT_SDS +src_libdrivers_la_SOURCES += \ + src/hardware/siglent-sds/protocol.h \ + src/hardware/siglent-sds/protocol.c \ + src/hardware/siglent-sds/api.c +endif if HW_SYSCLK_LWLA src_libdrivers_la_SOURCES += \ src/hardware/sysclk-lwla/lwla.h \ @@ -529,6 +596,12 @@ src_libdrivers_la_SOURCES += \ src/hardware/zeroplus-logic-cube/protocol.c \ src/hardware/zeroplus-logic-cube/api.c endif +if HW_ZKETECH_EBD_USB +src_libdrivers_la_SOURCES += \ + src/hardware/zketech-ebd-usb/protocol.h \ + src/hardware/zketech-ebd-usb/protocol.c \ + src/hardware/zketech-ebd-usb/api.c +endif libsigrok_la_LIBADD = src/libdrivers.lo $(SR_EXTRA_LIBS) $(LIBSIGROK_LIBS) libsigrok_la_LDFLAGS = -version-info $(SR_LIB_VERSION) -no-undefined @@ -544,7 +617,7 @@ noinst_HEADERS = src/libsigrok-internal.h pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libsigrok.pc -mimeappdir = $(datadir)/mime/application +mimeappdir = $(datadir)/mime/packages mimeapp_DATA = contrib/vnd.sigrok.session.xml mimeicondir = $(datadir)/icons/hicolor/48x48/mimetypes @@ -581,7 +654,9 @@ EXTRA_DIST = \ contrib/libsigrok.png \ contrib/libsigrok.svg \ contrib/vnd.sigrok.session.xml \ - contrib/z60_libsigrok.rules + contrib/60-libsigrok.rules \ + contrib/61-libsigrok-plugdev.rules \ + contrib/61-libsigrok-uaccess.rules if HAVE_CHECK TESTS = tests/main diff --git a/README b/README index f6d9842e..154c4928 100644 --- a/README +++ b/README @@ -41,7 +41,7 @@ Requirements for the C library: - libserialport >= 0.1.1 (optional, used by some drivers) - librevisa >= 0.0.20130412 (optional, used by some drivers) - libusb-1.0 >= 1.0.16 (optional, used by some drivers) - - libftdi >= 0.16 or libftdi1 >= 1.0 (optional, used by some drivers) + - libftdi1 >= 1.0 (optional, used by some drivers) - libgpib (optional, used by some drivers) - libieee1284 (optional, used by some drivers) - check >= 0.9.4 (optional, only needed to run unit tests) diff --git a/README.devices b/README.devices index 584899e2..a64c587f 100644 --- a/README.devices +++ b/README.devices @@ -14,6 +14,7 @@ the device is connected to the PC (usually via USB), before it can be used. The default locations where libsigrok expects the firmware files are: + $SIGROK_FIRMWARE_DIR (environment variable) $HOME/.local/share/sigrok-firmware $prefix/share/sigrok-firmware /usr/local/share/sigrok-firmware @@ -114,6 +115,7 @@ The following drivers/devices do not need any firmware upload: - scpi-pps - serial-dmm (including all subdrivers) - serial-lcr (including all subdrivers) + - siglent-sds - teleinfo - testo - tondaj-sl-814 @@ -138,7 +140,8 @@ Example: $ sigrok-cli --driver :conn=/dev/ttyUSB0 ... -The following drivers/devices require a serial port specification: +The following drivers/devices require a serial port specification. Some of +the drivers implement a default for the connection. - agilent-dmm - appa-55ii @@ -183,6 +186,21 @@ The following drivers/devices do not require a serial port specification: - yokogawa-dlm (USBTMC or TCP) - zeroplus-logic-cube +Beyond strict serial communication over COM ports (e.g. /dev/ttyUSB0), the +conn= property can also address specific USB devices, as well as specify TCP +or VXI communication parameters. See these examples: + + $ sigrok-cli --driver :conn=. ... + $ sigrok-cli --driver :conn=tcp-raw// ... + $ sigrok-cli --driver :conn=vxi/ ... + +The following drivers/devices accept network communication parameters: + + - hameg-hmo + - rigol-ds + - siglent-sds + - yokogawa-dlm + Specifying serial port parameters --------------------------------- @@ -212,33 +230,39 @@ For USB-to-serial based devices, we recommended using our udev rules file (see below for details). -Permissions for USB devices (udev rules file) ---------------------------------------------- +Permissions for USB devices (udev rules files) +---------------------------------------------- When using USB-based devices supported by libsigrok, the user running the libsigrok frontend (e.g. sigrok-cli) has to have (read/write) permissions for the respective USB device. -On Linux, this is accomplished using either 'chmod' (not recommended) or -using the udev rules file shipped with libsigrok (recommended). +On Linux, this is accomplished using udev rules. libsigrok ships a rules +file containing all supported devices which can be detected reliably +(generic USB-to-serial converters are omitted, as these are used for a wide +range of devices, e.g. GPS receivers, which are not handled by libsigrok). -The file is available in contrib/z60_libsigrok.rules. It contains entries -for all libsigrok-supported (USB-based) devices and changes their group -to 'plugdev' and the permissions to '664'. +The file is available in contrib/60-libsigrok.rules. This file just contains +the list of devices and flags these devices with ID_SIGROK="1". Access is +granted by the 61-libsigrok-plugdev.rules or 61-libsigrok-uaccess.rules files, +allowing access to members of the plugdev group or to currently logged in +users, respectively. When using a libsigrok package from your favorite Linux distribution, the -packager will have already taken care of properly installing the udev file -in the correct (distro-specific) place, and you don't have to do anything. -The packager might also have adapted 'plugdev' and '664' as needed. +files should already be installed in /usr/lib/udev/rules.d/, i.e. +60-libsigrok.rules and one of the access granting rules files. Use of +61-libsigrok-uaccess.rules is encouraged on systemd distributions. + +The access policy can be locally overridden by placing appropriate rules in +/etc/udev/rules.d/, disabling or ammending the default policy. See the +udev documentation, e.g. man 7 udev, for details. If you're building from source, you need to copy the file to the place -where your distro expects such files. This is beyond the scope of this README, -but generally the location could be e.g. /etc/udev/rules.d, or maybe -/lib/udev/rules.d, or something else. Afterwards you might have to restart -udev, e.g. via '/etc/init.d/udev restart' or similar, and you'll have to -re-attach your device via USB. +where udev will read these rules. Local rules should go to /etc/udev/rules.d. +Keep the file naming, otherwise interaction between the libsigrok rules and +rules shipped by the system will be broken. -Please consult the udev docs of your distro for details. +Please consult the udev docs for details. Cypress FX2 based devices @@ -349,6 +373,9 @@ a short list for convenience: 'SI232 online' (28-29S) or 'SI232 store' (22-26x). The interface must be configured to the same baud rate as the host (default 9600). Multimeter and interface must be configured to the same address. + - Metrix MX56C: Press the PRINT button to have the meter send acquisition + data via IR. Hold the PRINT button to adjust the meter's transmission + interval. - Norma DM950: If the interface doesn't work (e.g. USB-RS232 converter), power on the device with "FUNC" pressed (to power the interface from the DMM). - PCE PCE-DM32: Briefly press the "RS232" button. diff --git a/bindings/cxx/ConfigKey_methods.cpp b/bindings/cxx/ConfigKey_methods.cpp index 54af62e8..9c3668ff 100644 --- a/bindings/cxx/ConfigKey_methods.cpp +++ b/bindings/cxx/ConfigKey_methods.cpp @@ -1,3 +1,5 @@ +#include + const DataType *ConfigKey::data_type() const { const struct sr_key_info *info = sr_key_info_get(SR_KEY_CONFIG, id()); @@ -30,8 +32,6 @@ const ConfigKey *ConfigKey::get_by_identifier(string identifier) return get(info->key); } -#include - #ifndef HAVE_STOI_STOD /* Fallback implementation of stoi and stod */ @@ -70,12 +70,12 @@ static inline double stod( const std::string& str ) } #endif -Glib::VariantBase ConfigKey::parse_string(string value) const +Glib::VariantBase ConfigKey::parse_string(string value, enum sr_datatype dt) { GVariant *variant; uint64_t p, q; - switch (data_type()->id()) + switch (dt) { case SR_T_UINT64: check(sr_parse_sizestring(value.c_str(), &p)); @@ -90,7 +90,7 @@ Glib::VariantBase ConfigKey::parse_string(string value) const case SR_T_FLOAT: try { variant = g_variant_new_double(stod(value)); - } catch (invalid_argument) { + } catch (invalid_argument&) { throw Error(SR_ERR_ARG); } break; @@ -105,7 +105,7 @@ Glib::VariantBase ConfigKey::parse_string(string value) const case SR_T_INT32: try { variant = g_variant_new_int32(stoi(value)); - } catch (invalid_argument) { + } catch (invalid_argument&) { throw Error(SR_ERR_ARG); } break; @@ -116,3 +116,8 @@ Glib::VariantBase ConfigKey::parse_string(string value) const return Glib::VariantBase(variant, false); } +Glib::VariantBase ConfigKey::parse_string(string value) const +{ + enum sr_datatype dt = (enum sr_datatype)(data_type()->id()); + return parse_string(value, dt); +} diff --git a/bindings/cxx/ConfigKey_methods.hpp b/bindings/cxx/ConfigKey_methods.hpp index f759cc4e..bbc7ce81 100644 --- a/bindings/cxx/ConfigKey_methods.hpp +++ b/bindings/cxx/ConfigKey_methods.hpp @@ -7,4 +7,5 @@ /** Get configuration key by string identifier. */ static const ConfigKey *get_by_identifier(string identifier); /** Parse a string argument into the appropriate type for this key. */ + static Glib::VariantBase parse_string(string value, enum sr_datatype dt); Glib::VariantBase parse_string(string value) const; diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index e4340fdf..5bc5dc2f 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -18,8 +18,9 @@ */ /* 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 @@ -128,19 +129,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.insert(make_pair(driver->name(), move(driver))); + _drivers.emplace(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.insert(make_pair(input->name(), move(input))); + _input_formats.emplace(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.insert(make_pair(output->name(), move(output))); + _output_formats.emplace(output->name(), move(output)); } } @@ -157,11 +158,10 @@ string Context::lib_version() map> Context::drivers() { map> result; - for (const auto &entry: _drivers) - { + for (const auto &entry: _drivers) { const auto &name = entry.first; const auto &driver = entry.second; - result.insert({name, driver->share_owned_by(shared_from_this())}); + result.emplace(name, driver->share_owned_by(shared_from_this())); } return result; } @@ -169,23 +169,47 @@ map> Context::drivers() map> Context::input_formats() { map> result; - for (const auto &entry: _input_formats) - { + for (const auto &entry: _input_formats) { const auto &name = entry.first; const auto &input_format = entry.second; - result.insert({name, input_format->share_owned_by(shared_from_this())}); + result.emplace(name, input_format->share_owned_by(shared_from_this())); } return result; } +shared_ptr 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{new InputFormat{imod}, default_delete{}}; +} + map> Context::output_formats() { map> result; - for (const auto &entry: _output_formats) - { + for (const auto &entry: _output_formats) { const auto &name = entry.first; const auto &output_format = entry.second; - result.insert({name, output_format->share_owned_by(shared_from_this())}); + result.emplace(name, output_format->share_owned_by(shared_from_this())); } return result; } @@ -213,12 +237,9 @@ static int call_log_callback(void *cb_data, int loglevel, auto *const callback = static_cast(cb_data); - try - { + try { (*callback)(LogLevel::get(loglevel), message.get()); - } - catch (Error e) - { + } catch (Error &e) { return e.result; } @@ -281,8 +302,7 @@ shared_ptr Context::create_meta_packet( map config) { auto meta = g_new0(struct sr_datafeed_meta, 1); - for (const auto &input : config) - { + for (const auto &input : config) { const auto &key = input.first; const auto &value = input.second; auto *const output = g_new(struct sr_config, 1); @@ -312,7 +332,7 @@ shared_ptr Context::create_logic_packet( shared_ptr Context::create_analog_packet( vector > 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 mqflags) { auto analog = g_new0(struct sr_datafeed_analog, 1); @@ -350,7 +370,7 @@ shared_ptr Context::create_analog_packet( 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; @@ -446,16 +466,14 @@ vector> Driver::scan( map options) { /* Initialise the driver if not yet done. */ - if (!_initialized) - { + if (!_initialized) { check(sr_driver_init(_parent->_structure, _structure)); _initialized = true; } /* Translate scan options to GSList of struct sr_config pointers. */ GSList *option_list = nullptr; - for (const auto &entry : options) - { + for (const auto &entry : options) { const auto &key = entry.first; const auto &value = entry.second; auto *const config = g_new(struct sr_config, 1); @@ -473,8 +491,7 @@ vector> Driver::scan( /* Create device objects. */ vector> result; - for (GSList *device = device_list; device; device = device->next) - { + for (GSList *device = device_list; device; device = device->next) { auto *const sdi = static_cast(device->data); shared_ptr hwdev { new HardwareDevice{shared_from_this(), sdi}, @@ -570,23 +587,22 @@ Device::Device(struct sr_dev_inst *structure) : Configurable(sr_dev_inst_driver_get(structure), structure, nullptr), _structure(structure) { - for (GSList *entry = sr_dev_inst_channels_get(structure); entry; entry = entry->next) - { + for (GSList *entry = sr_dev_inst_channels_get(structure); entry; entry = entry->next) { auto *const ch = static_cast(entry->data); unique_ptr channel {new Channel{ch}}; - _channels.insert(make_pair(ch, move(channel))); + _channels.emplace(ch, move(channel)); } - for (GSList *entry = sr_dev_inst_channel_groups_get(structure); entry; entry = entry->next) - { + 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.insert(make_pair(group->name(), move(group))); + _channel_groups.emplace(group->name(), move(group)); } } Device::~Device() -{} +{ +} string Device::vendor() const { @@ -632,11 +648,10 @@ map> Device::channel_groups() { map> result; - for (const auto &entry: _channel_groups) - { + for (const auto &entry: _channel_groups) { const auto &name = entry.first; const auto &channel_group = entry.second; - result.insert({name, channel_group->share_owned_by(get_shared_from_this())}); + result.emplace(name, channel_group->share_owned_by(get_shared_from_this())); } return result; } @@ -695,7 +710,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.insert(make_pair(ch, move(channel))); + _channels.emplace(ch, move(channel)); return get_channel(ch); } @@ -918,7 +933,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.insert(make_pair(sdi, move(device))); + _owned_devices.emplace(sdi, move(device)); } _context->_session = this; } @@ -1299,6 +1314,48 @@ vector Analog::mq_flags() const return QuantityFlag::flags_from_mask(_structure->meaning->mqflags); } +shared_ptr 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 = + shared_ptr{new Logic{datafeed}, default_delete{}}; + + check(sr_a2l_threshold(_structure, threshold, + (uint8_t*)datafeed->data, datafeed->length)); + + return logic; +} + +shared_ptr 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 = + shared_ptr{new Logic{datafeed}, default_delete{}}; + + 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) { @@ -1361,15 +1418,14 @@ map> InputFormat::options() { map> result; - if (const struct sr_option **options = sr_input_options_get(_structure)) - { + if (const struct sr_option **options = sr_input_options_get(_structure)) { shared_ptr option_array {options, &sr_input_options_free}; for (int i = 0; options[i]; i++) { shared_ptr