Added a checksum function for the Oceanic VT Pro version string.

This commit is contained in:
Jef Driesen 2009-02-05 10:05:15 +00:00
parent fe78347584
commit e5fea5a370
3 changed files with 31 additions and 4 deletions

View File

@ -21,6 +21,20 @@
#include "checksum.h"
unsigned char
checksum_add_uint4 (const unsigned char data[], unsigned int size, unsigned char init)
{
unsigned char crc = init;
for (unsigned int i = 0; i < size; ++i) {
crc += (data[i] & 0xF0) >> 4;
crc += (data[i] & 0x0F);
}
return crc;
}
unsigned char
checksum_add_uint8 (const unsigned char data[], unsigned int size, unsigned char init)
{

View File

@ -26,6 +26,9 @@
extern "C" {
#endif /* __cplusplus */
unsigned char
checksum_add_uint4 (const unsigned char data[], unsigned int size, unsigned char init);
unsigned char
checksum_add_uint8 (const unsigned char data[], unsigned int size, unsigned char init);

View File

@ -396,8 +396,13 @@ oceanic_vtpro_device_version (device_t *abstract, unsigned char data[], unsigned
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
// FIXME: The answer seems to contain a checksum byte,
// but the correct checksum function is not known.
// Verify the checksum of the answer.
unsigned char crc = ans[OCEANIC_VTPRO_PACKET_SIZE / 2];
unsigned char ccrc = checksum_add_uint4 (ans, OCEANIC_VTPRO_PACKET_SIZE / 2, 0x00);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
return DEVICE_STATUS_PROTOCOL;
}
#ifndef NDEBUG
ans[OCEANIC_VTPRO_PACKET_SIZE / 2] = 0;
@ -414,8 +419,13 @@ oceanic_vtpro_device_version (device_t *abstract, unsigned char data[], unsigned
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
// FIXME: The answer seems to contain a checksum byte,
// but the correct checksum function is not known.
// Verify the checksum of the answer.
unsigned char crc = answer[OCEANIC_VTPRO_PACKET_SIZE / 2];
unsigned char ccrc = checksum_add_uint4 (answer, OCEANIC_VTPRO_PACKET_SIZE / 2, 0x00);
if (crc != ccrc) {
WARNING ("Unexpected answer CRC.");
return DEVICE_STATUS_PROTOCOL;
}
// Verify the last byte of the answer.
if (answer[OCEANIC_VTPRO_PACKET_SIZE / 2 + 1] != 0x51) {