common: Add ability to override USB transfer limit and timeouts.

This commit is contained in:
Solomon Peachy 2017-04-19 23:04:27 -04:00
parent 3b4ecb818a
commit e6d700a7c7
2 changed files with 31 additions and 7 deletions

18
README
View file

@ -178,6 +178,12 @@
variable. This is the default behavior when using this backend
with CUPS.
Finally, some backends support additional arguments; see their details
below.
***************************************************************************
Other Environment Variables:
If you have multiple models of the same printer family connected
simultaneously, the backend will choose the first one it finds.
If you wish to target a specific device, you may specify its
@ -201,9 +207,17 @@
please let us know so we can add the apppriate entry to the
internal database.
Finally, some backends support additional arguments; see below:
For debugging USB operation, there following environment variables
can be set:
***************************************************************************
MAX_XFER_SIZE Maximum transfer size, in bytes.
XFER_TIMEOUT Timeout, in milliseconds, for all USB operations
for example:
MAX_XFER_SIZE=32768 XFER_TIMEOUT=30000 backend filename
***************************************************************************
BACKEND=canonselphy
Verified supported printers:

View file

@ -27,13 +27,16 @@
#include "backend_common.h"
#define BACKEND_VERSION "0.71"
#define BACKEND_VERSION "0.72"
#ifndef URI_PREFIX
#error "Must Define URI_PREFIX"
#endif
#define NUM_CLAIM_ATTEMPTS 10
#define URB_XFER_SIZE (64*1024)
#define XFER_TIMEOUT 15000
/* Global Variables */
int dyesub_debug = 0;
int terminate = 0;
@ -43,6 +46,9 @@ int extra_pid = -1;
int extra_type = -1;
int copies = 1;
static int max_xfer_size = URB_XFER_SIZE;
static int xfer_timeout = XFER_TIMEOUT;
/* Support Functions */
static int backend_claim_interface(struct libusb_device_handle *dev, int iface)
{
@ -194,7 +200,7 @@ int read_data(struct libusb_device_handle *dev, uint8_t endp,
buf,
buflen,
readlen,
10000);
xfer_timeout);
if (ret < 0) {
ERROR("Failure to receive data from printer (libusb error %d: (%d/%d from 0x%02x))\n", ret, *readlen, buflen, endp);
@ -236,10 +242,10 @@ int send_data(struct libusb_device_handle *dev, uint8_t endp,
}
while (len) {
int len2 = (len > 65536) ? 65536: len;
int len2 = (len > max_xfer_size) ? max_xfer_size: len;
int ret = libusb_bulk_transfer(dev, endp,
buf, len2,
&num, 15000);
buf, len2,
&num, xfer_timeout);
if ((dyesub_debug > 1 && len < 4096) ||
dyesub_debug > 2) {
@ -791,6 +797,10 @@ int main (int argc, char **argv)
backend = find_backend(getenv("BACKEND"));
if (getenv("FAST_RETURN"))
fast_return++;
if (getenv("MAX_XFER_SIZE"))
max_xfer_size = atoi(getenv("MAX_XFER_SIZE"));
if (getenv("XFER_TIMEOUT"))
xfer_timeout = atoi(getenv("XFER_TIMEOUT"));
use_serno = getenv("SERIAL");
uri = getenv("DEVICE_URI"); /* CUPS backend mode? */