From e1f12108cb2521ab023aad6d86fcb7a57f6e0f07 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sat, 3 Nov 2007 20:27:14 +0000 Subject: [PATCH] Handle timeouts while receiving the first package. Instead of ending the transmission, an error is reported. --- suunto_vyper.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/suunto_vyper.c b/suunto_vyper.c index 9308d63..fefa642 100644 --- a/suunto_vyper.c +++ b/suunto_vyper.c @@ -474,10 +474,16 @@ suunto_vyper_read_dive (vyper *device, unsigned char data[], unsigned int size, unsigned char reply = 0; int rc = serial_read (device->port, &reply, 1); if (rc != 1 || memcmp (command, &reply, 1) != 0) { - // If no data is received at this point (timeout), - // we assume the last package was already received - // and the transmission can be finished. - if (rc == 0) + // If no data is received at this point (a timeout occured), + // we assume the last package was already received and the + // transmission should be finished. This is not 100% reliable, + // because there is always a small chance that more data will + // arrive later (especially with a short timeout). But I'm not + // aware of a better method to detect the end of the transmission. + // Only for the very first package, we can be sure there was + // an error, because it makes no sense to end the transmission + // if no data was received so far. + if (rc == 0 && nbytes != 0) break; fprintf (stderr, "%s:%d: Unexpected answer start byte (%d).\n", __FILE__, __LINE__, reply); return -1;