- rewrite do_cmd() timeout handling
- remove long timeout TUR from v61 (did not help)
- allow config file to set initial tur timeout for DR-X10C (#142)
merge-requests/603/head
m. allan noah 2021-02-28 20:41:21 -05:00
rodzic 6d990e73e9
commit 5819a79ab0
4 zmienionych plików z 70 dodań i 66 usunięć

Wyświetl plik

@ -11,9 +11,7 @@
#define USB_HEADER_LEN 12 #define USB_HEADER_LEN 12
#define USB_COMMAND_LEN 12 #define USB_COMMAND_LEN 12
#define USB_STATUS_LEN 4 #define USB_STATUS_LEN 4
#define USB_COMMAND_TIME 30000 #define USB_PACKET_TIMEOUT 30000
#define USB_DATA_TIME 30000
#define USB_STATUS_TIME 30000
/*static inline void */ /*static inline void */
static void static void

Wyświetl plik

@ -352,6 +352,9 @@
- adjust wait_scanner to try one TUR with a long timeout (#142) - adjust wait_scanner to try one TUR with a long timeout (#142)
v62 2021-02-13, MAN v62 2021-02-13, MAN
- allow config file to set inq and vpd lengths for DR-M1060 (#263) - allow config file to set inq and vpd lengths for DR-M1060 (#263)
- rewrite do_cmd() timeout handling
- remove long timeout TUR from v61 (did not help)
- allow config file to set initial tur timeout for DR-X10C (#142)
SANE FLOW DIAGRAM SANE FLOW DIAGRAM
@ -457,6 +460,8 @@ static int global_duplex_offset;
static int global_duplex_offset_default = 0; static int global_duplex_offset_default = 0;
static int global_inquiry_length; static int global_inquiry_length;
static int global_vpd_length; static int global_vpd_length;
static int global_tur_timeout;
static int global_tur_timeout_default = USB_PACKET_TIMEOUT/60; /* half second */
static char global_vendor_name[9]; static char global_vendor_name[9];
static char global_model_name[17]; static char global_model_name[17];
static char global_version_name[5]; static char global_version_name[5];
@ -736,6 +741,32 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only)
global_vpd_length = buf; global_vpd_length = buf;
} }
/* TUR_TIMEOUT <= 60000 */
else if (!strncmp (lp, "tur-timeout", 11) && isspace (lp[11])) {
int buf;
lp += 11;
lp = sanei_config_skip_whitespace (lp);
buf = atoi (lp);
if (buf > 60000) {
DBG (5, "sane_get_devices: config option \"tur-timeout\" "
"(%d) is > 60000, ignoring!\n", buf);
continue;
}
if (buf < 0) {
DBG (5, "sane_get_devices: config option \"tur-timeout\" "
"(%d) is < 0, ignoring!\n", buf);
continue;
}
DBG (15, "sane_get_devices: setting \"tur-timeout\" to %d\n",
buf);
global_tur_timeout = buf;
}
/* VENDOR: we ingest up to 8 bytes */ /* VENDOR: we ingest up to 8 bytes */
else if (!strncmp (lp, "vendor-name", 11) && isspace (lp[11])) { else if (!strncmp (lp, "vendor-name", 11) && isspace (lp[11])) {
@ -904,6 +935,7 @@ attach_one (const char *device_name, int connType)
s->duplex_offset = global_duplex_offset; s->duplex_offset = global_duplex_offset;
s->inquiry_length = global_inquiry_length; s->inquiry_length = global_inquiry_length;
s->vpd_length = global_vpd_length; s->vpd_length = global_vpd_length;
s->tur_timeout = global_tur_timeout;
/* copy the device name */ /* copy the device name */
strcpy (s->device_name, device_name); strcpy (s->device_name, device_name);
@ -7146,6 +7178,7 @@ default_globals(void)
global_duplex_offset = global_duplex_offset_default; global_duplex_offset = global_duplex_offset_default;
global_inquiry_length = INQUIRY_std_typ_len; global_inquiry_length = INQUIRY_std_typ_len;
global_vpd_length = INQUIRY_vpd_typ_len; global_vpd_length = INQUIRY_vpd_typ_len;
global_tur_timeout = global_tur_timeout_default;
global_vendor_name[0] = 0; global_vendor_name[0] = 0;
global_model_name[0] = 0; global_model_name[0] = 0;
global_version_name[0] = 0; global_version_name[0] = 0;
@ -7399,21 +7432,21 @@ sense_handler (int fd, unsigned char * sensed_data, void *arg)
* take a bunch of pointers, send commands to scanner * take a bunch of pointers, send commands to scanner
*/ */
static SANE_Status static SANE_Status
do_cmd(struct scanner *s, int runRS, int shortTime, do_cmd(struct scanner *s, int runRS, int timeout,
unsigned char * cmdBuff, size_t cmdLen, unsigned char * cmdBuff, size_t cmdLen,
unsigned char * outBuff, size_t outLen, unsigned char * outBuff, size_t outLen,
unsigned char * inBuff, size_t * inLen unsigned char * inBuff, size_t * inLen
) )
{ {
if (s->connection == CONNECTION_SCSI) { if (s->connection == CONNECTION_SCSI) {
return do_scsi_cmd(s, runRS, shortTime, return do_scsi_cmd(s, runRS, timeout,
cmdBuff, cmdLen, cmdBuff, cmdLen,
outBuff, outLen, outBuff, outLen,
inBuff, inLen inBuff, inLen
); );
} }
if (s->connection == CONNECTION_USB) { if (s->connection == CONNECTION_USB) {
return do_usb_cmd(s, runRS, shortTime, return do_usb_cmd(s, runRS, timeout,
cmdBuff, cmdLen, cmdBuff, cmdLen,
outBuff, outLen, outBuff, outLen,
inBuff, inLen inBuff, inLen
@ -7423,7 +7456,7 @@ do_cmd(struct scanner *s, int runRS, int shortTime,
} }
static SANE_Status static SANE_Status
do_scsi_cmd(struct scanner *s, int runRS, int shortTime, do_scsi_cmd(struct scanner *s, int runRS, int timeout,
unsigned char * cmdBuff, size_t cmdLen, unsigned char * cmdBuff, size_t cmdLen,
unsigned char * outBuff, size_t outLen, unsigned char * outBuff, size_t outLen,
unsigned char * inBuff, size_t * inLen unsigned char * inBuff, size_t * inLen
@ -7433,7 +7466,7 @@ do_scsi_cmd(struct scanner *s, int runRS, int shortTime,
/*shut up compiler*/ /*shut up compiler*/
runRS=runRS; runRS=runRS;
shortTime=shortTime; timeout=timeout;
DBG(10, "do_scsi_cmd: start\n"); DBG(10, "do_scsi_cmd: start\n");
@ -7471,7 +7504,7 @@ do_scsi_cmd(struct scanner *s, int runRS, int shortTime,
} }
static SANE_Status static SANE_Status
do_usb_cmd(struct scanner *s, int runRS, int shortTime, do_usb_cmd(struct scanner *s, int runRS, int timeout,
unsigned char * cmdBuff, size_t cmdLen, unsigned char * cmdBuff, size_t cmdLen,
unsigned char * outBuff, size_t outLen, unsigned char * outBuff, size_t outLen,
unsigned char * inBuff, size_t * inLen unsigned char * inBuff, size_t * inLen
@ -7481,21 +7514,19 @@ do_usb_cmd(struct scanner *s, int runRS, int shortTime,
size_t cmdLength = 0; size_t cmdLength = 0;
size_t cmdActual = 0; size_t cmdActual = 0;
unsigned char * cmdBuffer = NULL; unsigned char * cmdBuffer = NULL;
int cmdTimeout = 0;
size_t outOffset = 0; size_t outOffset = 0;
size_t outLength = 0; size_t outLength = 0;
size_t outActual = 0; size_t outActual = 0;
unsigned char * outBuffer = NULL; unsigned char * outBuffer = NULL;
int outTimeout = 0;
size_t inOffset = 0; size_t inOffset = 0;
size_t inLength = 0; size_t inLength = 0;
size_t inActual = 0; size_t inActual = 0;
unsigned char * inBuffer = NULL; unsigned char * inBuffer = NULL;
int inTimeout = 0;
size_t extraLength = 0; size_t extraLength = 0;
int actTimeout = timeout ? timeout : USB_PACKET_TIMEOUT;
int ret = 0; int ret = 0;
int ret2 = 0; int ret2 = 0;
@ -7505,18 +7536,15 @@ do_usb_cmd(struct scanner *s, int runRS, int shortTime,
DBG (10, "do_usb_cmd: start %lu %lu\n", (long unsigned int)timer.tv_sec, (long unsigned int)timer.tv_usec); DBG (10, "do_usb_cmd: start %lu %lu\n", (long unsigned int)timer.tv_sec, (long unsigned int)timer.tv_usec);
/* change timeout */
sanei_usb_set_timeout(actTimeout);
/****************************************************************/ /****************************************************************/
/* the command stage */ /* the command stage */
{ {
cmdOffset = USB_HEADER_LEN; cmdOffset = USB_HEADER_LEN;
cmdLength = cmdOffset+USB_COMMAND_LEN; cmdLength = cmdOffset+USB_COMMAND_LEN;
cmdActual = cmdLength; cmdActual = cmdLength;
cmdTimeout = USB_COMMAND_TIME;
/* change timeout */
if(shortTime)
cmdTimeout/=60;
sanei_usb_set_timeout(cmdTimeout);
/* build buffer */ /* build buffer */
cmdBuffer = calloc(cmdLength,1); cmdBuffer = calloc(cmdLength,1);
@ -7532,7 +7560,7 @@ do_usb_cmd(struct scanner *s, int runRS, int shortTime,
memcpy(cmdBuffer+cmdOffset,cmdBuff,cmdLen); memcpy(cmdBuffer+cmdOffset,cmdBuff,cmdLen);
/* write the command out */ /* write the command out */
DBG(25, "cmd: writing %d bytes, timeout %d\n", (int)cmdLength, cmdTimeout); DBG(25, "cmd: writing %d bytes, timeout %d\n", (int)cmdLength, actTimeout);
hexdump(30, "cmd: >>", cmdBuffer, cmdLength); hexdump(30, "cmd: >>", cmdBuffer, cmdLength);
ret = sanei_usb_write_bulk(s->fd, cmdBuffer, &cmdActual); ret = sanei_usb_write_bulk(s->fd, cmdBuffer, &cmdActual);
DBG(25, "cmd: wrote %d bytes, retVal %d\n", (int)cmdActual, ret); DBG(25, "cmd: wrote %d bytes, retVal %d\n", (int)cmdActual, ret);
@ -7555,7 +7583,7 @@ do_usb_cmd(struct scanner *s, int runRS, int shortTime,
/* this is like the regular status block, with an additional */ /* this is like the regular status block, with an additional */
/* length component at the end */ /* length component at the end */
if(s->extra_status){ if(s->extra_status){
ret2 = do_usb_status(s,runRS,shortTime,&extraLength); ret2 = do_usb_status(s,runRS,timeout,&extraLength);
/* bail out on bad RS status */ /* bail out on bad RS status */
if(ret2){ if(ret2){
@ -7571,12 +7599,6 @@ do_usb_cmd(struct scanner *s, int runRS, int shortTime,
outOffset = USB_HEADER_LEN; outOffset = USB_HEADER_LEN;
outLength = outOffset+outLen; outLength = outOffset+outLen;
outActual = outLength; outActual = outLength;
outTimeout = USB_DATA_TIME;
/* change timeout */
if(shortTime)
outTimeout/=60;
sanei_usb_set_timeout(outTimeout);
/* build outBuffer */ /* build outBuffer */
outBuffer = calloc(outLength,1); outBuffer = calloc(outLength,1);
@ -7592,7 +7614,7 @@ do_usb_cmd(struct scanner *s, int runRS, int shortTime,
memcpy(outBuffer+outOffset,outBuff,outLen); memcpy(outBuffer+outOffset,outBuff,outLen);
/* write the command out */ /* write the command out */
DBG(25, "out: writing %d bytes, timeout %d\n", (int)outLength, outTimeout); DBG(25, "out: writing %d bytes, timeout %d\n", (int)outLength, actTimeout);
hexdump(30, "out: >>", outBuffer, outLength); hexdump(30, "out: >>", outBuffer, outLength);
ret = sanei_usb_write_bulk(s->fd, outBuffer, &outActual); ret = sanei_usb_write_bulk(s->fd, outBuffer, &outActual);
DBG(25, "out: wrote %d bytes, retVal %d\n", (int)outActual, ret); DBG(25, "out: wrote %d bytes, retVal %d\n", (int)outActual, ret);
@ -7630,13 +7652,6 @@ do_usb_cmd(struct scanner *s, int runRS, int shortTime,
/*blast caller's copy in case we error out*/ /*blast caller's copy in case we error out*/
*inLen = 0; *inLen = 0;
inTimeout = USB_DATA_TIME;
/* change timeout */
if(shortTime)
inTimeout/=60;
sanei_usb_set_timeout(inTimeout);
/* build inBuffer */ /* build inBuffer */
inBuffer = calloc(inActual,1); inBuffer = calloc(inActual,1);
if(!inBuffer){ if(!inBuffer){
@ -7644,7 +7659,7 @@ do_usb_cmd(struct scanner *s, int runRS, int shortTime,
return SANE_STATUS_NO_MEM; return SANE_STATUS_NO_MEM;
} }
DBG(25, "in: reading %d bytes, timeout %d\n", (int)inActual, inTimeout); DBG(25, "in: reading %d bytes, timeout %d\n", (int)inActual, actTimeout);
ret = sanei_usb_read_bulk(s->fd, inBuffer, &inActual); ret = sanei_usb_read_bulk(s->fd, inBuffer, &inActual);
DBG(25, "in: read %d bytes, retval %d\n", (int)inActual, ret); DBG(25, "in: read %d bytes, retval %d\n", (int)inActual, ret);
hexdump(31, "in: <<", inBuffer, inActual); hexdump(31, "in: <<", inBuffer, inActual);
@ -7670,7 +7685,7 @@ do_usb_cmd(struct scanner *s, int runRS, int shortTime,
/****************************************************************/ /****************************************************************/
/* the normal status stage */ /* the normal status stage */
ret2 = do_usb_status(s,runRS,shortTime,&extraLength); ret2 = do_usb_status(s,runRS,timeout,&extraLength);
/* if status said EOF, adjust input with remainder count */ /* if status said EOF, adjust input with remainder count */
if(ret2 == SANE_STATUS_EOF && inBuffer){ if(ret2 == SANE_STATUS_EOF && inBuffer){
@ -7718,7 +7733,7 @@ do_usb_cmd(struct scanner *s, int runRS, int shortTime,
} }
static SANE_Status static SANE_Status
do_usb_status(struct scanner *s, int runRS, int shortTime, size_t * extraLength) do_usb_status(struct scanner *s, int runRS, int timeout, size_t * extraLength)
{ {
#define EXTRA_READ_len 4 #define EXTRA_READ_len 4
@ -7728,7 +7743,8 @@ do_usb_status(struct scanner *s, int runRS, int shortTime, size_t * extraLength)
size_t statLength = 0; size_t statLength = 0;
size_t statActual = 0; size_t statActual = 0;
unsigned char * statBuffer = NULL; unsigned char * statBuffer = NULL;
int statTimeout = 0;
int actTimeout = timeout ? timeout : USB_PACKET_TIMEOUT;
int ret = 0; int ret = 0;
@ -7742,12 +7758,9 @@ do_usb_status(struct scanner *s, int runRS, int shortTime, size_t * extraLength)
statLength += EXTRA_READ_len; statLength += EXTRA_READ_len;
statActual = statLength; statActual = statLength;
statTimeout = USB_STATUS_TIME;
/* change timeout */ /* change timeout */
if(shortTime) sanei_usb_set_timeout(timeout ? timeout : USB_PACKET_TIMEOUT);
statTimeout/=60;
sanei_usb_set_timeout(statTimeout);
/* build statBuffer */ /* build statBuffer */
statBuffer = calloc(statLength,1); statBuffer = calloc(statLength,1);
@ -7756,7 +7769,7 @@ do_usb_status(struct scanner *s, int runRS, int shortTime, size_t * extraLength)
return SANE_STATUS_NO_MEM; return SANE_STATUS_NO_MEM;
} }
DBG(25, "stat: reading %d bytes, timeout %d\n", (int)statLength, statTimeout); DBG(25, "stat: reading %d bytes, timeout %d\n", (int)statLength, actTimeout);
ret = sanei_usb_read_bulk(s->fd, statBuffer, &statActual); ret = sanei_usb_read_bulk(s->fd, statBuffer, &statActual);
DBG(25, "stat: read %d bytes, retval %d\n", (int)statActual, ret); DBG(25, "stat: read %d bytes, retval %d\n", (int)statActual, ret);
hexdump(30, "stat: <<", statBuffer, statActual); hexdump(30, "stat: <<", statBuffer, statActual);
@ -7863,7 +7876,7 @@ wait_scanner(struct scanner *s)
set_SCSI_opcode(cmd,TEST_UNIT_READY_code); set_SCSI_opcode(cmd,TEST_UNIT_READY_code);
ret = do_cmd ( ret = do_cmd (
s, 0, 1, s, 0, s->tur_timeout,
cmd, cmdLen, cmd, cmdLen,
NULL, 0, NULL, 0,
NULL, NULL NULL, NULL
@ -7872,7 +7885,7 @@ wait_scanner(struct scanner *s)
if (ret != SANE_STATUS_GOOD) { if (ret != SANE_STATUS_GOOD) {
DBG(5,"WARNING: Brain-dead scanner. Hitting with stick.\n"); DBG(5,"WARNING: Brain-dead scanner. Hitting with stick.\n");
ret = do_cmd ( ret = do_cmd (
s, 0, 1, s, 0, s->tur_timeout,
cmd, cmdLen, cmd, cmdLen,
NULL, 0, NULL, 0,
NULL, NULL NULL, NULL
@ -7881,7 +7894,7 @@ wait_scanner(struct scanner *s)
if (ret != SANE_STATUS_GOOD) { if (ret != SANE_STATUS_GOOD) {
DBG(5,"WARNING: Brain-dead scanner. Hitting with stick again.\n"); DBG(5,"WARNING: Brain-dead scanner. Hitting with stick again.\n");
ret = do_cmd ( ret = do_cmd (
s, 0, 1, s, 0, s->tur_timeout,
cmd, cmdLen, cmd, cmdLen,
NULL, 0, NULL, 0,
NULL, NULL NULL, NULL
@ -7890,18 +7903,9 @@ wait_scanner(struct scanner *s)
// some scanners (such as DR-F120) are OK but will not respond to commands // some scanners (such as DR-F120) are OK but will not respond to commands
// when in sleep mode. By checking the sense it wakes them up. // when in sleep mode. By checking the sense it wakes them up.
if (ret != SANE_STATUS_GOOD) { if (ret != SANE_STATUS_GOOD) {
DBG(5,"WARNING: Brain-dead scanner. Hitting with request sense.\n"); DBG(5,"WARNING: Brain-dead scanner. Hitting with stick and request sense.\n");
ret = do_cmd ( ret = do_cmd (
s, 1, 1, s, 1, s->tur_timeout,
cmd, cmdLen,
NULL, 0,
NULL, NULL
);
}
if (ret != SANE_STATUS_GOOD) {
DBG(5,"WARNING: Brain-dead scanner. Hitting with a slow stick.\n");
ret = do_cmd (
s, 0, 0,
cmd, cmdLen, cmd, cmdLen,
NULL, 0, NULL, 0,
NULL, NULL NULL, NULL
@ -7910,7 +7914,7 @@ wait_scanner(struct scanner *s)
if (ret != SANE_STATUS_GOOD) { if (ret != SANE_STATUS_GOOD) {
DBG(5,"WARNING: Brain-dead scanner. Hitting with stick a fourth time.\n"); DBG(5,"WARNING: Brain-dead scanner. Hitting with stick a fourth time.\n");
ret = do_cmd ( ret = do_cmd (
s, 0, 1, s, 0, s->tur_timeout,
cmd, cmdLen, cmd, cmdLen,
NULL, 0, NULL, 0,
NULL, NULL NULL, NULL

Wyświetl plik

@ -103,6 +103,7 @@ option duplex-offset 400
usb 0x1083 0x1617 usb 0x1083 0x1617
# DR-X10C # DR-X10C
option tur-timeout 5000
usb 0x1083 0x1618 usb 0x1083 0x1618
# CR-25 # CR-25

Wyświetl plik

@ -116,12 +116,18 @@ struct scanner
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* immutable values which are set during reading of config file. */ /* immutable values which are set during reading of config file. */
int buffer_size;
int connection; /* hardware interface type */ int connection; /* hardware interface type */
int buffer_size;
int duplex_offset; /* number of lines of padding added to front (1/1200)*/
int extra_status; /* some machines need extra status read after cmd */
int inquiry_length; /* some models are particular about inquiry size */
int padded_read; /* some machines need extra 12 bytes on reads */
int tur_timeout; /* some models are slow to wake up */
int vpd_length; /* some models are particular about vpd size */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* immutable values which are set during inquiry probing of the scanner. */ /* immutable values which are set during inquiry probing of the scanner. */
/* members in order found in scsi data... */ /* members in order found in scsi data. These can also be in config file */
char vendor_name[9]; /* raw data as returned by SCSI inquiry. */ char vendor_name[9]; /* raw data as returned by SCSI inquiry. */
char model_name[17]; /* raw data as returned by SCSI inquiry. */ char model_name[17]; /* raw data as returned by SCSI inquiry. */
char version_name[5]; /* raw data as returned by SCSI inquiry. */ char version_name[5]; /* raw data as returned by SCSI inquiry. */
@ -207,8 +213,6 @@ struct scanner
int always_op; /* send object pos between pages */ int always_op; /* send object pos between pages */
int invert_tly; /* weird bug in some smaller scanners */ int invert_tly; /* weird bug in some smaller scanners */
int unknown_byte2; /* weird byte, required, meaning unknown */ int unknown_byte2; /* weird byte, required, meaning unknown */
int padded_read; /* some machines need extra 12 bytes on reads */
int extra_status; /* some machines need extra status read after cmd */
int fixed_width; /* some machines always scan full width */ int fixed_width; /* some machines always scan full width */
int even_Bpl; /* some machines require even bytes per line */ int even_Bpl; /* some machines require even bytes per line */
@ -217,10 +221,7 @@ struct scanner
int color_inter_by_res[16]; /* and some even change by resolution */ int color_inter_by_res[16]; /* and some even change by resolution */
int duplex_interlace; /* different models interlace sides differently */ int duplex_interlace; /* different models interlace sides differently */
int jpeg_interlace; /* different models interlace jpeg sides differently */ int jpeg_interlace; /* different models interlace jpeg sides differently */
int duplex_offset; /* number of lines of padding added to front (1/1200)*/
int duplex_offset_side; /* padding added to front or back? */ int duplex_offset_side; /* padding added to front or back? */
int inquiry_length; /* some models are particular about inquiry/vpd size */
int vpd_length;
int sw_lut; /* no hardware brightness/contrast support */ int sw_lut; /* no hardware brightness/contrast support */
int bg_color; /* needed to fill in after rotation */ int bg_color; /* needed to fill in after rotation */