From f74e17068f5c0ed69bd456ade71dc4b0e03e93e5 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 18 Feb 2008 14:26:46 +0000 Subject: [PATCH] Removed the suunto_vyper2_recv and suunto_d9_recv functions. --- suunto_d9.c | 39 +++++++++++++++------------------------ suunto_vyper2.c | 27 +++++---------------------- 2 files changed, 20 insertions(+), 46 deletions(-) diff --git a/suunto_d9.c b/suunto_d9.c index 7f052e0..704e886 100644 --- a/suunto_d9.c +++ b/suunto_d9.c @@ -14,13 +14,6 @@ message ("%s:%d: %s\n", __FILE__, __LINE__, expr); \ } -#define EXITCODE(rc, n) \ -( \ - rc == -1 ? \ - SUUNTO_ERROR_IO : \ - (rc != n ? SUUNTO_ERROR_TIMEOUT : SUUNTO_ERROR_PROTOCOL) \ -) - struct d9 { struct serial *port; @@ -133,9 +126,17 @@ suunto_d9_send (d9 *device, const unsigned char command[], unsigned int csize) unsigned char echo[128] = {0}; assert (sizeof (echo) >= csize); int rc = serial_read (device->port, echo, csize); - if (rc != csize || memcmp (command, echo, csize) != 0) { + if (rc != csize) { + WARNING ("Failed to receive the echo."); + if (rc == -1) + return SUUNTO_ERROR_IO; + return SUUNTO_ERROR_TIMEOUT; + } + + // Verify the echo. + if (memcmp (command, echo, csize) != 0) { WARNING ("Unexpected echo."); - return EXITCODE (rc, csize); + return SUUNTO_ERROR_PROTOCOL; } // Set RTS to receive the reply. @@ -145,18 +146,6 @@ suunto_d9_send (d9 *device, const unsigned char command[], unsigned int csize) } -static int -suunto_d9_recv (d9 *device, unsigned char data[], unsigned int size) -{ - int rc = serial_read (device->port, data, size); - if (rc != size) { - return EXITCODE (rc, size); - } - - return SUUNTO_SUCCESS; -} - - static int suunto_d9_transfer (d9 *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, unsigned int size) { @@ -170,10 +159,12 @@ suunto_d9_transfer (d9 *device, const unsigned char command[], unsigned int csiz } // Receive the answer of the dive computer. - rc = suunto_d9_recv (device, answer, asize); - if (rc != SUUNTO_SUCCESS) { + rc = serial_read (device->port, answer, asize); + if (rc != asize) { WARNING ("Failed to receive the answer."); - return rc; + if (rc == -1) + return SUUNTO_ERROR_IO; + return SUUNTO_ERROR_TIMEOUT; } // Verify the header of the package. diff --git a/suunto_vyper2.c b/suunto_vyper2.c index 3bf0191..a7a381c 100644 --- a/suunto_vyper2.c +++ b/suunto_vyper2.c @@ -14,13 +14,6 @@ message ("%s:%d: %s\n", __FILE__, __LINE__, expr); \ } -#define EXITCODE(rc, n) \ -( \ - rc == -1 ? \ - SUUNTO_ERROR_IO : \ - (rc != n ? SUUNTO_ERROR_TIMEOUT : SUUNTO_ERROR_PROTOCOL) \ -) - struct vyper2 { struct serial *port; @@ -140,18 +133,6 @@ suunto_vyper2_send (vyper2 *device, const unsigned char command[], unsigned int } -static int -suunto_vyper2_recv (vyper2 *device, unsigned char data[], unsigned int size) -{ - int rc = serial_read (device->port, data, size); - if (rc != size) { - return EXITCODE (rc, size); - } - - return SUUNTO_SUCCESS; -} - - static int suunto_vyper2_transfer (vyper2 *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, unsigned int size) { @@ -165,10 +146,12 @@ suunto_vyper2_transfer (vyper2 *device, const unsigned char command[], unsigned } // Receive the answer of the dive computer. - rc = suunto_vyper2_recv (device, answer, asize); - if (rc != SUUNTO_SUCCESS) { + rc = serial_read (device->port, answer, asize); + if (rc != asize) { WARNING ("Failed to receive the answer."); - return rc; + if (rc == -1) + return SUUNTO_ERROR_IO; + return SUUNTO_ERROR_TIMEOUT; } // Verify the header of the package.