From 55c3aae4044ca2115ba12194faa4e834e7899909 Mon Sep 17 00:00:00 2001 From: reinelt Date: Fri, 8 Sep 2006 19:00:46 +0000 Subject: [lcd4linux @ 2006-09-08 19:00:46 by reinelt] give up after 10 write errors to serial device git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@709 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- drv_Trefon.c | 8 +++++--- drv_USBLCD.c | 9 +++++---- drv_generic_serial.c | 35 ++++++++++++++++++++++------------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/drv_Trefon.c b/drv_Trefon.c index 1dfb243..2e02977 100644 --- a/drv_Trefon.c +++ b/drv_Trefon.c @@ -1,4 +1,4 @@ -/* $Id: drv_Trefon.c,v 1.6 2006/01/30 06:25:54 reinelt Exp $ +/* $Id: drv_Trefon.c,v 1.7 2006/09/08 19:00:46 reinelt Exp $ * * driver for TREFON USB LCD displays - http://www.trefon.de * @@ -23,6 +23,9 @@ * * * $Log: drv_Trefon.c,v $ + * Revision 1.7 2006/09/08 19:00:46 reinelt + * give up after 10 write errors to serial device + * * Revision 1.6 2006/01/30 06:25:54 reinelt * added CVS Revision * @@ -97,7 +100,6 @@ static usb_dev_handle *lcd; static int interface; extern int usb_debug; -extern int got_signal; /****************************************/ @@ -351,7 +353,7 @@ int drv_TF_init(const char *section, const int quiet) int asc255bug; int ret; - info("%s: %s", Name, "$Revision: 1.6 $"); + info("%s: %s", Name, "$Revision: 1.7 $"); /* display preferences */ XRES = 5; /* pixel width of one char */ diff --git a/drv_USBLCD.c b/drv_USBLCD.c index f59ca8d..847a99a 100644 --- a/drv_USBLCD.c +++ b/drv_USBLCD.c @@ -1,4 +1,4 @@ -/* $Id: drv_USBLCD.c,v 1.24 2006/01/30 06:25:54 reinelt Exp $ +/* $Id: drv_USBLCD.c,v 1.25 2006/09/08 19:00:46 reinelt Exp $ * * new style driver for USBLCD displays * @@ -26,6 +26,9 @@ * * * $Log: drv_USBLCD.c,v $ + * Revision 1.25 2006/09/08 19:00:46 reinelt + * give up after 10 write errors to serial device + * * Revision 1.24 2006/01/30 06:25:54 reinelt * added CVS Revision * @@ -190,8 +193,6 @@ extern int usb_debug; #endif -extern int got_signal; - /****************************************/ @@ -504,7 +505,7 @@ int drv_UL_init(const char *section, const int quiet) int asc255bug; int ret; - info("%s: %s", Name, "$Revision: 1.24 $"); + info("%s: %s", Name, "$Revision: 1.25 $"); /* display preferences */ XRES = 5; /* pixel width of one char */ diff --git a/drv_generic_serial.c b/drv_generic_serial.c index 4644903..b34d117 100644 --- a/drv_generic_serial.c +++ b/drv_generic_serial.c @@ -1,4 +1,4 @@ -/* $Id: drv_generic_serial.c,v 1.17 2005/05/08 04:32:44 reinelt Exp $ +/* $Id: drv_generic_serial.c,v 1.18 2006/09/08 19:00:46 reinelt Exp $ * * generic driver helper for serial and usbserial displays * @@ -23,6 +23,9 @@ * * * $Log: drv_generic_serial.c,v $ + * Revision 1.18 2006/09/08 19:00:46 reinelt + * give up after 10 write errors to serial device + * * Revision 1.17 2005/05/08 04:32:44 reinelt * CodingStyle added and applied * @@ -153,6 +156,8 @@ #include "drv_generic_serial.h" +extern int got_signal; + static char *Section; static char *Driver; static char *Port; @@ -412,33 +417,37 @@ int drv_generic_serial_read(char *string, const int len) void drv_generic_serial_write(const char *string, const int len) { + static int error = 0; int run, ret; -#if 0 - int i; - for (i = 0; i < len; i++) { - int c = string[i]; - debug("serial_write: %03d %03o 0x%02x %c", c, c, c, iscntrl(c) ? '*' : c); - } -#endif - - if (Device == -1) + if (Device == -1) { + error("%s: write to closed port %s failed!", Driver, Port); return; + } + for (run = 0; run < 10; run++) { ret = write(Device, string, len); - if (ret >= 0 || errno != EAGAIN) + if (ret >= 0 || errno != EAGAIN) { break; - if (run > 0) + } + /* EAGAIN: retry 10 times, emit message after 2nd retry */ + if (run > 0) { info("%s: write(%s): EAGAIN #%d", Driver, Port, run); + } usleep(1000); } if (ret < 0) { error("%s: write(%s) failed: %s", Driver, Port, strerror(errno)); + if (++error > 10) { + error("%s: too much errors, giving up", Driver); + got_signal = -1; + } } else if (ret != len) { error("%s: partial write(%s): len=%d ret=%d", Driver, Port, len, ret); + } else { + error = 0; } - return; } -- cgit v1.2.3