Do not return the checksum bytes to the user.

This commit is contained in:
Jef Driesen 2008-01-24 10:48:11 +00:00
parent 6ca4159149
commit 0d800dba95
2 changed files with 11 additions and 8 deletions

View File

@ -143,21 +143,24 @@ uwatec_aladin_read (aladin *device, unsigned char data[], unsigned int size)
} }
// Receive the contents of the package. // Receive the contents of the package.
int rc = serial_read (device->port, data + 4, 2046); int rc = serial_read (device->port, data + 4, UWATEC_ALADIN_MEMORY_SIZE - 4);
if (rc != 2046) { if (rc != UWATEC_ALADIN_MEMORY_SIZE - 4) {
WARNING ("Unexpected EOF in answer."); WARNING ("Unexpected EOF in answer.");
return UWATEC_ERROR; return UWATEC_ERROR;
} }
// Reverse the bit order. // Reverse the bit order.
uwatec_aladin_reverse (data, 2050); uwatec_aladin_reverse (data, UWATEC_ALADIN_MEMORY_SIZE);
// Calculate the checksum. // 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. // Receive (and verify) the checksum of the package.
unsigned short crc = (data[2049] << 8) + data[2048]; unsigned char checksum[2] = {0};
if (ccrc != crc) { 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."); WARNING ("Unexpected answer CRC.");
return UWATEC_ERROR; return UWATEC_ERROR;
} }

View File

@ -7,7 +7,7 @@ extern "C" {
typedef struct aladin aladin; 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); int uwatec_aladin_open (aladin **device, const char* name);