From 2abd5164f4861ab2ee619c017fe2f022ad019457 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 2 Jan 2012 08:01:08 +0100 Subject: [PATCH] Add a delay between sending the commands. When trying to send the commands as fast as possible, without any delay, the failure rate is very high. Almost every single packet fails with a timeout at first. Retrying the packet works, but those many timeouts make the download extremely slow. Adding a small delay avoids the much more expensive timeout and speeds up the transfer significantly. --- src/mares_common.c | 5 +++++ src/mares_common.h | 1 + src/mares_darwin.c | 1 + 3 files changed, 7 insertions(+) diff --git a/src/mares_common.c b/src/mares_common.c index 85800cb..51e0722 100644 --- a/src/mares_common.c +++ b/src/mares_common.c @@ -49,6 +49,7 @@ mares_common_device_init (mares_common_device_t *device, const device_backend_t // Set the default values. device->port = NULL; device->echo = 0; + device->delay = 0; } @@ -128,6 +129,10 @@ mares_common_packet (mares_common_device_t *device, const unsigned char command[ if (device_is_cancelled (abstract)) return DEVICE_STATUS_CANCELLED; + if (device->delay) { + serial_sleep (device->delay); + } + // Send the command to the device. int n = serial_write (device->port, command, csize); if (n != csize) { diff --git a/src/mares_common.h b/src/mares_common.h index 3b312ac..6e4cb2a 100644 --- a/src/mares_common.h +++ b/src/mares_common.h @@ -43,6 +43,7 @@ typedef struct mares_common_device_t { device_t base; serial_t *port; unsigned int echo; + unsigned int delay; } mares_common_device_t; void diff --git a/src/mares_darwin.c b/src/mares_darwin.c index afe4f45..ab1766d 100644 --- a/src/mares_darwin.c +++ b/src/mares_darwin.c @@ -162,6 +162,7 @@ mares_darwin_device_open (device_t **out, const char* name, unsigned int model) // Override the base class values. device->base.echo = 1; + device->base.delay = 50; *out = (device_t *) device;