Use the ACK/NAK error correction for all commands.
This commit is contained in:
parent
067a6c630a
commit
cf009cf18b
@ -105,8 +105,6 @@ oceanic_veo250_send (oceanic_veo250_device_t *device, const unsigned char comman
|
|||||||
static device_status_t
|
static device_status_t
|
||||||
oceanic_veo250_transfer (oceanic_veo250_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize)
|
oceanic_veo250_transfer (oceanic_veo250_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize)
|
||||||
{
|
{
|
||||||
assert (asize == OCEANIC_VEO250_PACKET_SIZE + 2);
|
|
||||||
|
|
||||||
// Send the command to the device. If the device responds with an
|
// Send the command to the device. If the device responds with an
|
||||||
// ACK byte, the command was received successfully and the answer
|
// ACK byte, the command was received successfully and the answer
|
||||||
// (if any) follows after the ACK byte. If the device responds with
|
// (if any) follows after the ACK byte. If the device responds with
|
||||||
@ -147,22 +145,14 @@ oceanic_veo250_transfer (oceanic_veo250_device_t *device, const unsigned char co
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Receive the answer of the dive computer.
|
// Receive the answer of the dive computer.
|
||||||
int n = serial_read (device->port, answer, OCEANIC_VEO250_PACKET_SIZE + 2);
|
int n = serial_read (device->port, answer, asize);
|
||||||
if (n != OCEANIC_VEO250_PACKET_SIZE + 2) {
|
if (n != asize) {
|
||||||
WARNING ("Failed to receive the answer.");
|
WARNING ("Failed to receive the answer.");
|
||||||
return EXITCODE (n);
|
return EXITCODE (n);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the checksum of the answer.
|
|
||||||
unsigned char crc = answer[OCEANIC_VEO250_PACKET_SIZE];
|
|
||||||
unsigned char ccrc = checksum_add_uint8 (answer, OCEANIC_VEO250_PACKET_SIZE, 0x00);
|
|
||||||
if (crc != ccrc) {
|
|
||||||
WARNING ("Unexpected answer CRC.");
|
|
||||||
return DEVICE_STATUS_PROTOCOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify the last byte of the answer.
|
// Verify the last byte of the answer.
|
||||||
if (answer[OCEANIC_VEO250_PACKET_SIZE + 1] != NAK) {
|
if (answer[asize - 1] != NAK) {
|
||||||
WARNING ("Unexpected answer byte.");
|
WARNING ("Unexpected answer byte.");
|
||||||
return DEVICE_STATUS_PROTOCOL;
|
return DEVICE_STATUS_PROTOCOL;
|
||||||
}
|
}
|
||||||
@ -337,27 +327,17 @@ oceanic_veo250_device_keepalive (device_t *abstract)
|
|||||||
if (! device_is_oceanic_veo250 (abstract))
|
if (! device_is_oceanic_veo250 (abstract))
|
||||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||||
|
|
||||||
// Send the command to the dive computer.
|
unsigned char answer[2] = {0};
|
||||||
unsigned char command[4] = {0x91,
|
unsigned char command[4] = {0x91,
|
||||||
(device->last ) & 0xFF, // low
|
(device->last ) & 0xFF, // low
|
||||||
(device->last >> 8) & 0xFF, // high
|
(device->last >> 8) & 0xFF, // high
|
||||||
0x00};
|
0x00};
|
||||||
device_status_t rc = oceanic_veo250_send (device, command, sizeof (command));
|
device_status_t rc = oceanic_veo250_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
if (rc != DEVICE_STATUS_SUCCESS)
|
||||||
WARNING ("Failed to send the command.");
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
|
||||||
|
|
||||||
// Receive the answer of the dive computer.
|
|
||||||
unsigned char answer[3] = {0};
|
|
||||||
int n = serial_read (device->port, answer, sizeof (answer));
|
|
||||||
if (n != sizeof (answer)) {
|
|
||||||
WARNING ("Failed to receive the answer.");
|
|
||||||
return EXITCODE (n);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify the answer.
|
// Verify the answer.
|
||||||
if (answer[0] != ACK || answer[1] != NAK || answer[2] != NAK) {
|
if (answer[0] != NAK) {
|
||||||
WARNING ("Unexpected answer byte(s).");
|
WARNING ("Unexpected answer byte(s).");
|
||||||
return DEVICE_STATUS_PROTOCOL;
|
return DEVICE_STATUS_PROTOCOL;
|
||||||
}
|
}
|
||||||
@ -383,6 +363,14 @@ oceanic_veo250_device_version (device_t *abstract, unsigned char data[], unsigne
|
|||||||
if (rc != DEVICE_STATUS_SUCCESS)
|
if (rc != DEVICE_STATUS_SUCCESS)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
|
// Verify the checksum of the answer.
|
||||||
|
unsigned char crc = answer[OCEANIC_VEO250_PACKET_SIZE];
|
||||||
|
unsigned char ccrc = checksum_add_uint8 (answer, OCEANIC_VEO250_PACKET_SIZE, 0x00);
|
||||||
|
if (crc != ccrc) {
|
||||||
|
WARNING ("Unexpected answer CRC.");
|
||||||
|
return DEVICE_STATUS_PROTOCOL;
|
||||||
|
}
|
||||||
|
|
||||||
memcpy (data, answer, OCEANIC_VEO250_PACKET_SIZE);
|
memcpy (data, answer, OCEANIC_VEO250_PACKET_SIZE);
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
@ -423,10 +411,18 @@ oceanic_veo250_device_read (device_t *abstract, unsigned int address, unsigned c
|
|||||||
if (rc != DEVICE_STATUS_SUCCESS)
|
if (rc != DEVICE_STATUS_SUCCESS)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
memcpy (data, answer, OCEANIC_VEO250_PACKET_SIZE);
|
|
||||||
|
|
||||||
device->last = number;
|
device->last = number;
|
||||||
|
|
||||||
|
// Verify the checksum of the answer.
|
||||||
|
unsigned char crc = answer[OCEANIC_VEO250_PACKET_SIZE];
|
||||||
|
unsigned char ccrc = checksum_add_uint8 (answer, OCEANIC_VEO250_PACKET_SIZE, 0x00);
|
||||||
|
if (crc != ccrc) {
|
||||||
|
WARNING ("Unexpected answer CRC.");
|
||||||
|
return DEVICE_STATUS_PROTOCOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy (data, answer, OCEANIC_VEO250_PACKET_SIZE);
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
message ("VEO250Read(0x%04x,%d)=\"", address, OCEANIC_VEO250_PACKET_SIZE);
|
message ("VEO250Read(0x%04x,%d)=\"", address, OCEANIC_VEO250_PACKET_SIZE);
|
||||||
for (unsigned int i = 0; i < OCEANIC_VEO250_PACKET_SIZE; ++i) {
|
for (unsigned int i = 0; i < OCEANIC_VEO250_PACKET_SIZE; ++i) {
|
||||||
|
|||||||
@ -40,6 +40,7 @@
|
|||||||
|
|
||||||
#define ACK 0x5A
|
#define ACK 0x5A
|
||||||
#define NAK 0xA5
|
#define NAK 0xA5
|
||||||
|
#define END 0x51
|
||||||
|
|
||||||
typedef struct oceanic_vtpro_device_t {
|
typedef struct oceanic_vtpro_device_t {
|
||||||
oceanic_common_device_t base;
|
oceanic_common_device_t base;
|
||||||
@ -187,23 +188,14 @@ static device_status_t
|
|||||||
oceanic_vtpro_quit (oceanic_vtpro_device_t *device)
|
oceanic_vtpro_quit (oceanic_vtpro_device_t *device)
|
||||||
{
|
{
|
||||||
// Send the command to the dive computer.
|
// Send the command to the dive computer.
|
||||||
|
unsigned char answer[1] = {0};
|
||||||
unsigned char command[4] = {0x6A, 0x05, 0xA5, 0x00};
|
unsigned char command[4] = {0x6A, 0x05, 0xA5, 0x00};
|
||||||
device_status_t rc = oceanic_vtpro_send (device, command, sizeof (command));
|
device_status_t rc = oceanic_vtpro_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
if (rc != DEVICE_STATUS_SUCCESS)
|
||||||
WARNING ("Failed to send the command.");
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
|
||||||
|
|
||||||
// Receive the answer of the dive computer.
|
// Verify the last byte of the answer.
|
||||||
unsigned char answer[2] = {0};
|
if (answer[0] != END) {
|
||||||
int n = serial_read (device->port, answer, sizeof (answer));
|
|
||||||
if (n != sizeof (answer)) {
|
|
||||||
WARNING ("Failed to receive the answer.");
|
|
||||||
return EXITCODE (n);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify the answer.
|
|
||||||
if (answer[0] != 0x5A || answer[1] != 0x51) {
|
|
||||||
WARNING ("Unexpected answer byte(s).");
|
WARNING ("Unexpected answer byte(s).");
|
||||||
return DEVICE_STATUS_PROTOCOL;
|
return DEVICE_STATUS_PROTOCOL;
|
||||||
}
|
}
|
||||||
@ -216,27 +208,18 @@ static device_status_t
|
|||||||
oceanic_vtpro_calibrate (oceanic_vtpro_device_t *device)
|
oceanic_vtpro_calibrate (oceanic_vtpro_device_t *device)
|
||||||
{
|
{
|
||||||
// Send the command to the dive computer.
|
// Send the command to the dive computer.
|
||||||
|
// The timeout is temporary increased, because the
|
||||||
|
// device needs approximately 6 seconds to respond.
|
||||||
|
unsigned char answer[2] = {0};
|
||||||
unsigned char command[2] = {0x18, 0x00};
|
unsigned char command[2] = {0x18, 0x00};
|
||||||
device_status_t rc = oceanic_vtpro_send (device, command, sizeof (command));
|
|
||||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
|
||||||
WARNING ("Failed to send the command.");
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Receive the answer of the dive computer. The timeout
|
|
||||||
// is temporary increased, because the device needs
|
|
||||||
// approximately 6 seconds to respond.
|
|
||||||
unsigned char answer[3] = {0};
|
|
||||||
serial_set_timeout (device->port, 9000);
|
serial_set_timeout (device->port, 9000);
|
||||||
int n = serial_read (device->port, answer, sizeof (answer));
|
device_status_t rc = oceanic_vtpro_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||||
serial_set_timeout (device->port, 3000);
|
serial_set_timeout (device->port, 3000);
|
||||||
if (n != sizeof (answer)) {
|
if (rc != DEVICE_STATUS_SUCCESS)
|
||||||
WARNING ("Failed to receive the answer.");
|
return rc;
|
||||||
return EXITCODE (n);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify the answer.
|
// Verify the last byte of the answer.
|
||||||
if (answer[0] != ACK || answer[2] != 0x00) {
|
if (answer[1] != 0x00) {
|
||||||
WARNING ("Unexpected answer byte(s).");
|
WARNING ("Unexpected answer byte(s).");
|
||||||
return DEVICE_STATUS_PROTOCOL;
|
return DEVICE_STATUS_PROTOCOL;
|
||||||
}
|
}
|
||||||
@ -368,23 +351,14 @@ oceanic_vtpro_device_keepalive (device_t *abstract)
|
|||||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||||
|
|
||||||
// Send the command to the dive computer.
|
// Send the command to the dive computer.
|
||||||
|
unsigned char answer[1] = {0};
|
||||||
unsigned char command[4] = {0x6A, 0x08, 0x00, 0x00};
|
unsigned char command[4] = {0x6A, 0x08, 0x00, 0x00};
|
||||||
device_status_t rc = oceanic_vtpro_send (device, command, sizeof (command));
|
device_status_t rc = oceanic_vtpro_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
if (rc != DEVICE_STATUS_SUCCESS)
|
||||||
WARNING ("Failed to send the command.");
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
|
||||||
|
|
||||||
// Receive the answer of the dive computer.
|
// Verify the last byte of the answer.
|
||||||
unsigned char answer[2] = {0};
|
if (answer[0] != END) {
|
||||||
int n = serial_read (device->port, answer, sizeof (answer));
|
|
||||||
if (n != sizeof (answer)) {
|
|
||||||
WARNING ("Failed to receive the answer.");
|
|
||||||
return EXITCODE (n);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify the answer.
|
|
||||||
if (answer[0] != ACK || answer[1] != 0x51) {
|
|
||||||
WARNING ("Unexpected answer byte(s).");
|
WARNING ("Unexpected answer byte(s).");
|
||||||
return DEVICE_STATUS_PROTOCOL;
|
return DEVICE_STATUS_PROTOCOL;
|
||||||
}
|
}
|
||||||
@ -446,7 +420,7 @@ oceanic_vtpro_device_version (device_t *abstract, unsigned char data[], unsigned
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify the last byte of the answer.
|
// Verify the last byte of the answer.
|
||||||
if (answer[OCEANIC_VTPRO_PACKET_SIZE / 2 + 1] != 0x51) {
|
if (answer[OCEANIC_VTPRO_PACKET_SIZE / 2 + 1] != END) {
|
||||||
WARNING ("Unexpected answer byte.");
|
WARNING ("Unexpected answer byte.");
|
||||||
return DEVICE_STATUS_PROTOCOL;
|
return DEVICE_STATUS_PROTOCOL;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user