Daniel Elstner [Sun, 13 Sep 2015 18:12:12 +0000 (20:12 +0200)]
classes.cpp: Define _XOPEN_SOURCE for isascii()
The GNU libstdc++ headers use isascii(), which is not part of any
POSIX standard. On BSD, this breaks the build. It is however part
of XOPEN, which on Linux is apparently enabled implicitly for C++.
Daniel Elstner [Sun, 13 Sep 2015 16:22:17 +0000 (18:22 +0200)]
Build: Include <config.h> first in all source files
Since Autoconf places some important feature flags only into the
configuration header, it is necessary to include it globally to
guarantee a consistent build.
Daniel Elstner [Fri, 11 Sep 2015 21:08:10 +0000 (23:08 +0200)]
serial: Make serial device event sources more robust
Disallow polling for input/error and output-ready events at the
same time, and ensure only a single FD event source is installed.
Also, do not leak if the FD event source is removed by means
other than calling serial_source_remove().
Daniel Elstner [Sun, 13 Sep 2015 13:07:54 +0000 (15:07 +0200)]
Build: Force ISO-conforming format syntax on MinGW
On MinGW, two implementations of printf() are available: either
the Microsoft native one or a standard-conforming replacement from
gnulib. Since we build in C99 mode, headers such as <inttypes.h>
already select the standard-conforming variant. However, MinGW's
GCC does not seem to know about this and assumes MS-style format
syntax by default, which triggers a lot of wrong warnings.
Thus, on MinGW, explicitly decorate sr_log() with the gnu_printf
format flavor attribute. Also use GLib's printf replacements in
the logging implementation to make sure we link to a conforming
printf on any platform, independently of the compiler flags.
This gets rid of the mistaken -Wformat warnings for sr_log(), but
does not cover functions such as g_strdup_printf() which do not
explicitly specify the gnu_printf flavor in the format attribute.
This can be overcome by adding "-D__printf__=__gnu_printf__" to
CPPFLAGS, but it would be inappropriate for libsigrok to define
this on its own.
Daniel Elstner [Sun, 13 Sep 2015 09:58:44 +0000 (11:58 +0200)]
log: Remove sr_log_logdomain_{get,set} from the API
The confusingly named sr_log_logdomain_set() simply set a global
string prefixed to the log message by the default log callback.
This is pretty much useless, misleadingly named, and not used by
either sigrok-cli or PulseView.
Daniel Elstner [Sun, 13 Sep 2015 00:29:38 +0000 (02:29 +0200)]
Fix log varargs bugs indicated by -Wformat
A few of these were pretty serious, like missing arguments,
passing integers where a string was expected, and so on.
In some places, change the types used by the code rather than
just the format strings.
Daniel Elstner [Sat, 12 Sep 2015 22:58:36 +0000 (00:58 +0200)]
log: Output timestamps at level SR_LOG_DBG too
SR_LOG_DBG and above are targeted at developers, so it makes sense
to extend timestamp output to that. Also sanitize the calculation
of the timestamp components a bit.
Daniel Elstner [Sat, 12 Sep 2015 20:41:22 +0000 (22:41 +0200)]
log: Use generalized sr_log() to implement logging helpers
Get rid of the specicialized sr_err(), sr_warn(), etc. functions.
Instead, define the logging helper macros in terms of sr_log(),
and remove the sr_log() helper macro so that no function is hidden
by a macro anymore.
Decorate sr_log() with G_GNUC_PRINTF to detect varargs errors. This
unearthed a gazillion warnings all over the place which will have
to be fixed.
Also convert the helper macros to ISO C99 __VA_ARGS__ style instead
of relying on a GNU C extension. Paste the log prefix directly into
the format string to make this work.
Daniel Elstner [Fri, 11 Sep 2015 17:15:55 +0000 (19:15 +0200)]
session: Return immediately if there are no event sources
Some drivers, such as zeroplus-logic-cube, run everything they do
right away in dev_acquisition_start(), never installing any event
sources. Handle that evilness by returning from sr_session_run()
immediately if there are no sources.
Daniel Elstner [Thu, 10 Sep 2015 07:46:45 +0000 (09:46 +0200)]
session: Port to GLib main loop
Replace the custom session main loop with the GLib main loop.
This is phase one of the port, which leaves the session and
driver APIs unchanged while replacing the internals.
Daniel Glöckner [Mon, 7 Sep 2015 00:18:14 +0000 (02:18 +0200)]
hung-chang-dso-2100: Add driver
The Hung-Chang DSO-2100 is a parallel port PC oscilloscope sold back
in 1999 under brand names like Protek and Voltcraft.
This inital version of the driver has the following limitations:
- Hardcoded calibration values. All parameters are set to 50%.
- No support for auto triggering
- No support for TV sync trigger modes
- No support for the "scroll acquisition" mode
In scroll acquisition mode the device behaves more like a multimeter
and reports the current voltage of a probe on request. While in this
mode the sample rate is limited by the parallel port interface, it is
the only way to capture both channels at the same time (well, sort of).
Calibration would need auto triggering. The calibration values are very
temperature dependent and the device takes literally hours to reach its
final temperature. Every vdiv setting needs its own set of calibration
values. Without hardware modifications, the calibration settings wear
of in less than a second while waiting for a trigger because the
capacitors storing those values are not recharged in state 0x21.
Uwe Hermann [Wed, 9 Sep 2015 06:21:01 +0000 (08:21 +0200)]
Makefile.am: Use @ORDER@ instead of |.
This is set to | (or left empty) by SR_PROG_MAKE_ORDER_ONLY for
portability reasons, since not all Make implementations support
order-only prerequisites.
Daniel Elstner [Mon, 7 Sep 2015 13:01:52 +0000 (15:01 +0200)]
Build: Add configure check for libusb event-abstraction
This is intended to make people notice when libusb is too old
for the new Windows code. However, this is not foolproof, since
the libusb version may be different at runtime.
Daniel Elstner [Mon, 7 Sep 2015 10:41:29 +0000 (12:41 +0200)]
USB: Handle live changes to the set of FDs to poll
Introduce new internal session API for changing the set of polled
file descriptors for an already installed event source. Use the
new API to apply changes to the USB poll FDs when requested to do
so by libusb. Doing so is necessary to make the generic USB code
work on Windows.
Daniel Elstner [Mon, 7 Sep 2015 19:18:50 +0000 (21:18 +0200)]
sigrok.m4: Add generic macro for optional dependencies
Provide SR_ARG_OPT_CHECK, a generalized variant of SRG_ARG_OPT_PKG
that can be used with custom check commands. Implement the latter
in terms of SR_ARG_OPT_CHECK.
There was a problem in scpi_serial.c in the scpi_serial_read_data()
function. Incoming data was written at the read position in the buffer,
although it should be written at the count position in the buffer.
Daniel Elstner [Fri, 4 Sep 2015 16:51:55 +0000 (18:51 +0200)]
USB: On Windows, block to wait for libusb events
This is another attempt at getting the mess that is libusb event
handling on Windows under control. Until libusb makes its HANDLEs
available for polling, we have no choice but to block while waiting
for libusb events. Since we do not want to force drivers to deal
with multi-threading issues, that means we have to block in the
session main loop.
Fortunately, it turns out that our drivers aren't using multiple
event sources, so it is actually possible to block the main loop
without disrupting too much. This also gets rid of the USB thread
on Windows. Thankfully, libusb does not seem to care that we are
now calling libusb_handle_events_timeout_completed() twice per
iteration: first a blocking call (with timeout) in the callback
wrapper, followed by the non-blocking call in the driver-supplied
callback.
Daniel Elstner [Tue, 1 Sep 2015 01:36:03 +0000 (03:36 +0200)]
session: Allow multiple poll FDs per event source
Turns out that having one event source per libusb poll FD is
a bad idea. There is only a single callback for all poll FDs,
and libusb expects to be called only once per poll iteration,
no matter how many FDs triggered.
Also, they should all share the same timeout, which should get
reset on events from any polled FD. The new timeout handling made
this problem apparent, as it caused the callback to be invoked
multiple times on timeouts, once for each separate event source.
In order to fix this, change the implementation to allow for an
arbitrary number of poll FDs per event source. This number is
zero for timer FDs, one for normal I/O sources, and one or more
for libusb sources (Unix only).
Also, on Windows, do not get an additional timeout from libusb
in the event loop. This is only appropriate when polling the
libusb FDs directly, which we aren't doing on Windows.
Daniel Elstner [Mon, 31 Aug 2015 00:35:57 +0000 (02:35 +0200)]
session: Unify handling of I/O and timer sources
Handle I/O sources and timer ("dummy") sources within the same
polling loop, so that both may be used together. Slightly change
the API to improve consistency: a timeout value of -1 now disables
the timeout, and 0 makes the source always time out immediately.
The "dummy" sources already behaved that way, although it wasn't
documented as such.
Make sure that I/O events are processed preferentially: Skip any
timeout callbacks if an I/O event occurred within the same poll
iteration. This applies to both timer/idle sources and timeouts
of I/O sources.
Do not create dummy GPollFDs for timer/idle sources. Instead,
split the sources array into an I/O section and a timer section,
and create corresponding GPollFDs only for the I/O section. Use
GArray to simplify the handling of the dynamic arrays.
Keep track of when source timeouts are due and properly compare
against accumulated elapsed time between invocations. This prevents
sources with short timeouts from blocking other sources with longer
timeouts indefinitely.
Daniel Elstner [Sun, 30 Aug 2015 13:25:33 +0000 (15:25 +0200)]
session: Do not expect meaningful errno on non-UNIX
Looking at the g_poll() implementations for various systems, it
appears that on Windows the return value is 0 if the wait was
interrupted, and errno is never set. Also, the MacOS X wrapper
around select() does not clear revents on timeout.
To deal with these issues, check for EINTR only on Unices, and
assume revents to be invalid unless g_poll() returned a positive
value.
Daniel Elstner [Sun, 30 Aug 2015 12:23:38 +0000 (14:23 +0200)]
session: Check for errors from g_poll()
If the call to g_poll() in sr_session_iteration() fails, report
the error back to the caller. Do not treat EINTR as error though.
Check for session abort only if a source callback was actually
invoked, or at least once if none of the callbacks are invoked.
Stop checking for abort if the session has already been stopped,
just in case a callback sets abort_session again.
Also change the documentation to match the actual behavior.
Daniel Elstner [Sun, 30 Aug 2015 10:20:03 +0000 (12:20 +0200)]
session: Fix USB timeout handling
In sr_session_iteration(), remove the inverted evaluation of the
block parameter if a USB source is present. This stops the deluge
of USB event callbacks due to the timeout always being zero.
Also, just for cleanliness, initialize the revents member of each
GPollFD instance to zero.
Uwe Hermann [Mon, 31 Aug 2015 19:08:08 +0000 (21:08 +0200)]
python: Fix the build for Python >= 3.
SWIG_init() returns void for Python 2.x and 'PyObject *' for Python 3.
Use an #if to handle both cases properly, otherwise the Python bindings
for either Python 2 or 3 will fail to build.
Python 3.x failure:
sigrok/core/classes_wrap.cpp: In function ‘PyObject* PyInit__classes()’:
sigrok/core/classes_wrap.cpp:59002:5: error: return-statement with no
value, in function returning ‘PyObject* {aka _object*}’ [-fpermissive]
return;
^
Python 2.x failure:
In file included from /usr/include/dirent.h:244:0,
from /usr/include/glib-2.0/glib/gdir.h:32,
from /usr/include/glib-2.0/glib.h:45,
from /usr/include/pygobject-3.0/pygobject.h:7,
from sigrok/core/classes_wrap.cpp:3179:
sigrok/core/classes_wrap.cpp: In function ‘void init_classes()’:
sigrok/core/classes_wrap.cpp:59002:12: error: return-statement with a
value, in function returning 'void' [-fpermissive]
return NULL;
^
Bert Vermeulen [Sat, 29 Aug 2015 21:01:02 +0000 (23:01 +0200)]
deree-de5000: Drop SR_CONF_MEASURED_QUANTITY functionality.
This was superfluous -- there is no need to be able to query the
last MQ(s) sent by the device, since they're already being sent
along with the measurements in analog packets.
Since there is also no way to change the MQ (that is done with the
buttons on the device), there is no need to even list the possible
MQs.
Bert Vermeulen [Sat, 29 Aug 2015 20:20:29 +0000 (22:20 +0200)]
Change SR_T_MQLIST to SR_T_MQ.
The need to make this a list no longer applies.
SR_T_MQ is thus a type consisting of a tuple with two elements: the first
item is the MQ (type G_VARIANT_TYPE_UINT32), and the second is the MQ
flags value (G_VARIANT_TYPE_UINT64).
Daniel Glöckner [Sat, 22 Aug 2015 15:39:39 +0000 (17:39 +0200)]
sr_session_send: pass transformed packet to datafeed callbacks
After the packet has been passed through the transformation modules,
the transformed data is in packet_in but the following code uses
the packet variable which still points to the original input.
Uwe Hermann [Sat, 29 Aug 2015 12:50:44 +0000 (14:50 +0200)]
Don't set _POSIX_C_SOURCE for VXI/RPC related files.
Make vxi.h the first #include in all affected files and #undef the
_POSIX_C_SOURCE macro in vxi.h.
This avoids various build issues on e.g. FreeBSD or Mac OS X where
setting _POSIX_C_SOURCE leads to the unavailability of certain types
such as u_long (as used in the VXI/RPC code).
Daniel Elstner [Fri, 28 Aug 2015 23:54:17 +0000 (01:54 +0200)]
Build: Pass compiler flags from make to setup.py
Extend setup.py to allow environment variables to be set on the
command line. Use that functionality to replace the pkg-config
invocations with flags passed on from make. Suppress the annoying
-Wstrict-prototypes warning by overriding the OPT variable.
Also move the "cd bindings/python" from Makefile.am to setup.py
to side-step problems with "cd" in make rules.