From d4b94cb77c0f8bf1cc922b724514af1c6d3f4ab4 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 5 Mar 2012 21:20:07 +0100 Subject: [PATCH] Improve the communication with Darwin Air devices. We received a report of a Darwin Air device which has a very high error rate. The majority of the echo packets is incorrect, but since this doesn't seem to have any effect on the actual data packet, we can just ignore this error. If there happens to be a more serious error, it will be detect in the data packet. Sometimes there were also a some garbage bytes received at startup. Adding a small delay seems to fix this. --- src/mares_common.c | 4 +++- src/mares_darwin.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mares_common.c b/src/mares_common.c index 51e0722..94e71b7 100644 --- a/src/mares_common.c +++ b/src/mares_common.c @@ -152,7 +152,6 @@ mares_common_packet (mares_common_device_t *device, const unsigned char command[ // Verify the echo. if (memcmp (echo, command, csize) != 0) { WARNING ("Unexpected echo."); - return DEVICE_STATUS_PROTOCOL; } } @@ -196,6 +195,9 @@ mares_common_transfer (mares_common_device_t *device, const unsigned char comman // Abort if the maximum number of retries is reached. if (nretries++ >= MAXRETRIES) return rc; + + // Discard any garbage bytes. + serial_flush (device->port, SERIAL_QUEUE_INPUT); } return rc; diff --git a/src/mares_darwin.c b/src/mares_darwin.c index ab1766d..e41f99a 100644 --- a/src/mares_darwin.c +++ b/src/mares_darwin.c @@ -158,6 +158,7 @@ mares_darwin_device_open (device_t **out, const char* name, unsigned int model) } // Make sure everything is in a sane state. + serial_sleep (100); serial_flush (device->base.port, SERIAL_QUEUE_BOTH); // Override the base class values.