From: Gerhard Sittig Date: Sun, 28 Jan 2018 17:07:38 +0000 (+0100) Subject: serial: prepare for the absence of libserialport X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=1ac8c2181b0390c601278ad05bab93dd1c801734;hp=bb15350e594bcbf5e25e30df0a8ceb31a795a36a serial: prepare for the absence of libserialport Only reference the libserialport header when the library is available. Allow to always compile the serial.c source file, but optionally end up with an empty implementation. Make the sr_serial_dev_inst symbol available outside of HAVE_SERIAL_COMM such that empty stub code can compile. This prepares the introduction of alternative transports for serial communication, while all of them remain optional. The libsigrok serial layer internally uses parity and flow control symbols which are provided by libserialport. Optionally locally declare these symbols when libserialport is not available. --- diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 3ea3590a..6fbc1d24 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -723,6 +723,7 @@ struct sr_usb_dev_inst { }; #endif +struct sr_serial_dev_inst; #ifdef HAVE_SERIAL_COMM struct ser_lib_functions; struct sr_serial_dev_inst { @@ -843,6 +844,30 @@ SR_PRIV void sr_usb_dev_inst_free(struct sr_usb_dev_inst *usb); #endif #ifdef HAVE_SERIAL_COMM +#ifndef HAVE_LIBSERIALPORT +/* + * Some identifiers which initially got provided by libserialport are + * used internally within the libsigrok serial layer's implementation, + * while libserialport no longer is the exclusive provider of serial + * communication support. Declare the identifiers here so they remain + * available across all build configurations. + */ +enum libsp_parity { + SP_PARITY_NONE = 0, + SP_PARITY_ODD = 1, + SP_PARITY_EVEN = 2, + SP_PARITY_MARK = 3, + SP_PARITY_SPACE = 4, +}; + +enum libsp_flowcontrol { + SP_FLOWCONTROL_NONE = 0, + SP_FLOWCONTROL_XONXOFF = 1, + SP_FLOWCONTROL_RTSCTS = 2, + SP_FLOWCONTROL_DTRDSR = 3, +}; +#endif + /* Serial-specific instances */ SR_PRIV struct sr_serial_dev_inst *sr_serial_dev_inst_new(const char *port, const char *serialcomm); diff --git a/src/serial.c b/src/serial.c index dc6e0126..aca99d99 100644 --- a/src/serial.c +++ b/src/serial.c @@ -25,7 +25,9 @@ #include #include #include +#ifdef HAVE_LIBSERIALPORT #include +#endif #include #include "libsigrok-internal.h" #ifdef _WIN32 @@ -50,6 +52,8 @@ * @{ */ +#ifdef HAVE_SERIAL_COMM + /* See if a (assumed opened) serial port is of any supported type. */ static int dev_is_supported(struct sr_serial_dev_inst *serial) { @@ -870,4 +874,10 @@ SR_PRIV int serial_timeout(struct sr_serial_dev_inst *port, int num_bytes) return timeout_ms; } +#else + +/* TODO Put fallback.c content here? */ + +#endif + /** @} */