From 0d800dba959a7bcd930daba1a1b7823bc18a2f6e Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 24 Jan 2008 10:48:11 +0000 Subject: [PATCH] Do not return the checksum bytes to the user. --- uwatec_aladin.c | 17 ++++++++++------- uwatec_aladin.h | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/uwatec_aladin.c b/uwatec_aladin.c index 781b014..d44eadf 100644 --- a/uwatec_aladin.c +++ b/uwatec_aladin.c @@ -143,21 +143,24 @@ uwatec_aladin_read (aladin *device, unsigned char data[], unsigned int size) } // Receive the contents of the package. - int rc = serial_read (device->port, data + 4, 2046); - if (rc != 2046) { + int rc = serial_read (device->port, data + 4, UWATEC_ALADIN_MEMORY_SIZE - 4); + if (rc != UWATEC_ALADIN_MEMORY_SIZE - 4) { WARNING ("Unexpected EOF in answer."); return UWATEC_ERROR; } // Reverse the bit order. - uwatec_aladin_reverse (data, 2050); + uwatec_aladin_reverse (data, UWATEC_ALADIN_MEMORY_SIZE); // Calculate the checksum. - unsigned short ccrc = uwatec_aladin_checksum (data, 2048); + unsigned short ccrc = uwatec_aladin_checksum (data, UWATEC_ALADIN_MEMORY_SIZE); - // Verify the checksum of the package. - unsigned short crc = (data[2049] << 8) + data[2048]; - if (ccrc != crc) { + // Receive (and verify) the checksum of the package. + unsigned char checksum[2] = {0}; + rc = serial_read (device->port, checksum, sizeof (checksum)); + uwatec_aladin_reverse (checksum, sizeof (checksum)); + unsigned short crc = (checksum[1] << 8) + checksum[0]; + if (rc != sizeof (checksum) || ccrc != crc) { WARNING ("Unexpected answer CRC."); return UWATEC_ERROR; } diff --git a/uwatec_aladin.h b/uwatec_aladin.h index 3273149..cfbd561 100644 --- a/uwatec_aladin.h +++ b/uwatec_aladin.h @@ -7,7 +7,7 @@ extern "C" { typedef struct aladin aladin; -#define UWATEC_ALADIN_MEMORY_SIZE 2050 +#define UWATEC_ALADIN_MEMORY_SIZE 2048 int uwatec_aladin_open (aladin **device, const char* name);