From 4d4b0f141fc2b47b30d0fc417583faaa666d019a Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 3 Dec 2007 13:54:21 +0000 Subject: [PATCH] Do not detect the first package by means of the number of bytes. If the first package was a null package and the transfer was not aborted, it does not work properly. --- suunto_vyper.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/suunto_vyper.c b/suunto_vyper.c index b24c956..8816b5b 100644 --- a/suunto_vyper.c +++ b/suunto_vyper.c @@ -412,7 +412,7 @@ suunto_vyper_read_dive (vyper *device, unsigned char data[], unsigned int size, // of maximum $SUUNTO_VYPER_PACKET_SIZE bytes. unsigned int nbytes = 0; - for (;;) { + for (unsigned int npackages = 0;; ++npackages) { // Initial checksum value. unsigned char ccrc = 0x00; @@ -427,10 +427,9 @@ suunto_vyper_read_dive (vyper *device, unsigned char data[], unsigned int size, // 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) + // Only for the very first package, we can be sure there was + // an error, because the DC always sends at least one package. + if (rc == 0 && npackages != 0) break; WARNING ("Unexpected answer start byte(s)."); return EXITCODE (rc, 2);