On 22 September 2015 at 15:05, Lubomir I. Ivanov <neolit...@gmail.com> wrote:
>
> so apart from NO_DOCS=0, the only thing i'm not building at the moment
> is FTDISUPPORT=1, but that's probably doable as well.
>

alright,

so libftdi builds (without the EEPROM part as i don't want to install
the other libconfuse dependency thing), but the local serial_ftdi.c
doesn't compile.

Anton, if you are the maintainer of serial_ftdi.c, please review the
attached patch so that Dirk can apply it

timeradd()/timersub() are a BSD thing, not POSIX and Windows has never
heard of them! :-(
i've added replacements, but that's completely untested.

on this:
#define ERROR ...
such a common name is a bad idea. conflicts with the existent
definition in "wingdi.h", which the GDI people took pretentiously.
i'm renaming it to *ERROR_MSG().

there are also a ton of "const char* -> char *" and similar warnings
(+ bad coding style), but i'm not touching that.

lubomir
--
From 105a00fd6529b880bc48946f7513532614fd1fd0 Mon Sep 17 00:00:00 2001
From: "Lubomir I. Ivanov" <neolit...@gmail.com>
Date: Tue, 22 Sep 2015 16:10:09 +0300
Subject: [PATCH 2/2] serial_ftdi: fix missing timeradd()/timersub() on Win32

Said macros are not even POSIX, so a replacement is needed
on Win32 targets.

The patch also addreses a warning about the ERROR() macro
being already defined in wingdi.h. This is solved by renaming
*ERROR() to *ERROR_MSG().

Signed-off-by: Lubomir I. Ivanov <neolit...@gmail.com>
---
 serial_ftdi.c | 83 +++++++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 55 insertions(+), 28 deletions(-)

diff --git a/serial_ftdi.c b/serial_ftdi.c
index cbac026..e1cb4b5 100644
--- a/serial_ftdi.c
+++ b/serial_ftdi.c
@@ -33,14 +33,41 @@
 
 #ifndef __ANDROID__
 #define INFO(context, fmt, ...)	fprintf(stderr, "INFO: " fmt "\n", ##__VA_ARGS__)
-#define ERROR(context, fmt, ...)	fprintf(stderr, "ERROR: " fmt "\n", ##__VA_ARGS__)
+#define ERROR_MSG(context, fmt, ...)	fprintf(stderr, "ERROR: " fmt "\n", ##__VA_ARGS__)
 #else
 #include <android/log.h>
 #define INFO(context, fmt, ...)	__android_log_print(ANDROID_LOG_DEBUG, __FILE__, "INFO: " fmt "\n", ##__VA_ARGS__)
-#define ERROR(context, fmt, ...)	__android_log_print(ANDROID_LOG_DEBUG, __FILE__, "ERROR: " fmt "\n", ##__VA_ARGS__)
+#define ERROR_MSG(context, fmt, ...)	__android_log_print(ANDROID_LOG_DEBUG, __FILE__, "ERROR: " fmt "\n", ##__VA_ARGS__)
+#endif
+//#define SYSERROR_MSG(context, errcode)	ERROR_MSG(__FILE__ ":" __LINE__ ": %s", strerror(errcode))
+#define SYSERROR_MSG(context, errcode)	;
+
+/* copied from here:
+ * http://www.tinyos.net/dist-1.1.0/snapshot-1.1.0/tools/src/uisp/src/timeradd.h
+ */
+#ifndef timeradd
+#define timeradd(_a, _b, _res) \
+	do { \
+		(_res)->tv_usec = (_a)->tv_usec + (_b)->tv_usec; \
+		(_res)->tv_sec = (_a)->tv_sec + (_b)->tv_sec; \
+		if ((_res)->tv_usec >= 1000000) { \
+			(_res)->tv_usec -= 1000000; \
+			(_res)->tv_sec++; \
+		} \
+	} while (0)
+#endif
+
+#ifndef timersub
+#define timersub(_a, _b, _res) \
+	do { \
+		(_res)->tv_usec = (_a)->tv_usec - (_b)->tv_usec; \
+		(_res)->tv_sec = (_a)->tv_sec - (_b)->tv_sec; \
+		if ((_res)->tv_usec < 0) { \
+			(_res)->tv_usec += 1000000; \
+			(_res)->tv_sec--; \
+		} \
+	} while (0)
 #endif
-//#define SYSERROR(context, errcode)	ERROR(__FILE__ ":" __LINE__ ": %s", strerror(errcode))
-#define SYSERROR(context, errcode)	;
 
 #include <libdivecomputer/custom_serial.h>
 
@@ -133,7 +160,7 @@ static int serial_ftdi_sleep (serial_t *device, unsigned long timeout)
 
 	while (nanosleep (&ts, &ts) != 0) {
 		if (errno != EINTR ) {
-			SYSERROR (device->context, errno);
+			SYSERROR_MSG (device->context, errno);
 			return -1;
 		}
 	}
@@ -180,14 +207,14 @@ static dc_status_t serial_ftdi_open (serial_t **out, dc_context_t *context, cons
 	// Allocate memory.
 	serial_t *device = (serial_t *) malloc (sizeof (serial_t));
 	if (device == NULL) {
-		SYSERROR (context, errno);
+		SYSERROR_MSG (context, errno);
 		return DC_STATUS_NOMEMORY;
 	}
 
 	struct ftdi_context *ftdi_ctx = ftdi_new();
 	if (ftdi_ctx == NULL) {
 		free(device);
-		SYSERROR (context, errno);
+		SYSERROR_MSG (context, errno);
 		return DC_STATUS_NOMEMORY;
 	}
 
@@ -207,24 +234,24 @@ static dc_status_t serial_ftdi_open (serial_t **out, dc_context_t *context, cons
 
 	if (ftdi_set_interface(ftdi_ctx,INTERFACE_ANY)) {
 		free(device);
-		ERROR (context, "%s", ftdi_get_error_string(ftdi_ctx));
+		ERROR_MSG (context, "%s", ftdi_get_error_string(ftdi_ctx));
 		return DC_STATUS_IO;
 	}
 
 	if (serial_ftdi_open_device(ftdi_ctx) < 0) {
 		free(device);
-		ERROR (context, "%s", ftdi_get_error_string(ftdi_ctx));
+		ERROR_MSG (context, "%s", ftdi_get_error_string(ftdi_ctx));
 		return DC_STATUS_IO;
 	}
 
 	if (ftdi_usb_reset(ftdi_ctx)) {
-		ERROR (context, "%s", ftdi_get_error_string(ftdi_ctx));
+		ERROR_MSG (context, "%s", ftdi_get_error_string(ftdi_ctx));
 		return DC_STATUS_IO;
 	}
 
 	if (ftdi_usb_purge_buffers(ftdi_ctx)) {
 		free(device);
-		ERROR (context, "%s", ftdi_get_error_string(ftdi_ctx));
+		ERROR_MSG (context, "%s", ftdi_get_error_string(ftdi_ctx));
 		return DC_STATUS_IO;
 	}
 
@@ -251,7 +278,7 @@ static int serial_ftdi_close (serial_t *device)
 
 	int ret = ftdi_usb_close(device->ftdi_ctx);
 	if (ret < 0) {
-		ERROR (device->context, "Unable to close the ftdi device : %d (%s)\n",
+		ERROR_MSG (device->context, "Unable to close the ftdi device : %d (%s)\n",
 		       ret, ftdi_get_error_string(device->ftdi_ctx));
 		return ret;
 	}
@@ -280,7 +307,7 @@ static dc_status_t serial_ftdi_configure (serial_t *device, int baudrate, int da
 	enum ftdi_parity_type ft_parity;
 
 	if (ftdi_set_baudrate(device->ftdi_ctx, baudrate) < 0) {
-		ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
+		ERROR_MSG (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
 		return -1;
 	}
 
@@ -325,7 +352,7 @@ static dc_status_t serial_ftdi_configure (serial_t *device, int baudrate, int da
 
 	// Set the attributes
 	if (ftdi_set_line_property(device->ftdi_ctx, ft_bits, ft_stopbits, ft_parity)) {
-		ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
+		ERROR_MSG (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
 		return DC_STATUS_IO;
 	}
 
@@ -333,19 +360,19 @@ static dc_status_t serial_ftdi_configure (serial_t *device, int baudrate, int da
 	switch (flowcontrol) {
 	case SERIAL_FLOWCONTROL_NONE: // No flow control.
 		if (ftdi_setflowctrl(device->ftdi_ctx, SIO_DISABLE_FLOW_CTRL) < 0) {
-			ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
+			ERROR_MSG (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
 			return DC_STATUS_IO;
 		}
 		break;
 	case SERIAL_FLOWCONTROL_HARDWARE: // Hardware (RTS/CTS) flow control.
 		if (ftdi_setflowctrl(device->ftdi_ctx, SIO_RTS_CTS_HS) < 0) {
-			ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
+			ERROR_MSG (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
 			return DC_STATUS_IO;
 		}
 		break;
 	case SERIAL_FLOWCONTROL_SOFTWARE: // Software (XON/XOFF) flow control.
 		if (ftdi_setflowctrl(device->ftdi_ctx, SIO_XON_XOFF_HS) < 0) {
-			ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
+			ERROR_MSG (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
 			return DC_STATUS_IO;
 		}
 		break;
@@ -406,7 +433,7 @@ static int serial_ftdi_read (serial_t *device, void *data, unsigned int size)
 		if (timeout > 0) {
 			struct timeval now;
 			if (gettimeofday (&now, NULL) != 0) {
-				SYSERROR (device->context, errno);
+				SYSERROR_MSG (device->context, errno);
 				return -1;
 			}
 
@@ -432,12 +459,12 @@ static int serial_ftdi_read (serial_t *device, void *data, unsigned int size)
 		if (n < 0) {
 			if (n == LIBUSB_ERROR_INTERRUPTED)
 				continue; //Retry.
-			ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
+			ERROR_MSG (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
 			return -1; //Error during read call.
 		} else if (n == 0) {
 			// Exponential backoff.
 			if (backoff > MAX_BACKOFF) {
-				ERROR(device->context, "%s", "FTDI read timed out.");
+				ERROR_MSG(device->context, "%s", "FTDI read timed out.");
 				return -1;
 			}
 			serial_ftdi_sleep (device, backoff);
@@ -464,7 +491,7 @@ static int serial_ftdi_write (serial_t *device, const void *data, unsigned int s
 	if (device->halfduplex) {
 		// Get the current time.
 		if (gettimeofday (&tvb, NULL) != 0) {
-			SYSERROR (device->context, errno);
+			SYSERROR_MSG (device->context, errno);
 			return -1;
 		}
 	}
@@ -476,7 +503,7 @@ static int serial_ftdi_write (serial_t *device, const void *data, unsigned int s
 		if (n < 0) {
 			if (n == LIBUSB_ERROR_INTERRUPTED)
 				continue; // Retry.
-			ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
+			ERROR_MSG (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
 			return -1; // Error during write call.
 		} else if (n == 0) {
 			break; // EOF.
@@ -488,7 +515,7 @@ static int serial_ftdi_write (serial_t *device, const void *data, unsigned int s
 	if (device->halfduplex) {
 		// Get the current time.
 		if (gettimeofday (&tve, NULL) != 0) {
-			SYSERROR (device->context, errno);
+			SYSERROR_MSG (device->context, errno);
 			return -1;
 		}
 
@@ -529,19 +556,19 @@ static int serial_ftdi_flush (serial_t *device, int queue)
 	switch (queue) {
 	case SERIAL_QUEUE_INPUT:
 		if (ftdi_usb_purge_tx_buffer(device->ftdi_ctx)) {
-			ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
+			ERROR_MSG (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
 			return -1;
 		}
 		break;
 	case SERIAL_QUEUE_OUTPUT:
 		if (ftdi_usb_purge_rx_buffer(device->ftdi_ctx)) {
-			ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
+			ERROR_MSG (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
 			return -1;
 		}
 		break;
 	default:
 		if (ftdi_usb_purge_buffers(device->ftdi_ctx)) {
-			ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
+			ERROR_MSG (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
 			return -1;
 		}
 		break;
@@ -585,7 +612,7 @@ static int serial_ftdi_set_dtr (serial_t *device, int level)
 	INFO (device->context, "DTR: value=%i", level);
 
 	if (ftdi_setdtr(device->ftdi_ctx, level)) {
-		ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
+		ERROR_MSG (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
 		return -1;
 	}
 
@@ -600,7 +627,7 @@ static int serial_ftdi_set_rts (serial_t *device, int level)
 	INFO (device->context, "RTS: value=%i", level);
 
 	if (ftdi_setrts(device->ftdi_ctx, level)) {
-		ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
+		ERROR_MSG (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
 		return -1;
 	}
 
-- 
1.7.11.msysgit.0

_______________________________________________
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to