Improve the type safety by using the device_status_t enum.

This commit is contained in:
Jef Driesen 2008-09-03 08:46:21 +00:00
parent 9f1e100fe8
commit 599827d5a3
20 changed files with 186 additions and 151 deletions

View File

@ -8,13 +8,14 @@
message ("%s:%d: %s\n", __FILE__, __LINE__, expr); \
}
int test_dump_memory (const char* name, const char* filename)
device_status_t
test_dump_memory (const char* name, const char* filename)
{
unsigned char data[OCEANIC_ATOM2_MEMORY_SIZE] = {0};
device_t *device = NULL;
message ("oceanic_atom2_device_open\n");
int rc = oceanic_atom2_device_open (&device, name);
device_status_t rc = oceanic_atom2_device_open (&device, name);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
return rc;
@ -78,7 +79,9 @@ int test_dump_memory (const char* name, const char* filename)
return DEVICE_STATUS_SUCCESS;
}
const char* errmsg (int rc)
const char*
errmsg (device_status_t rc)
{
switch (rc) {
case DEVICE_STATUS_SUCCESS:
@ -118,7 +121,7 @@ int main(int argc, char *argv[])
message ("DEVICE=%s\n", name);
int a = test_dump_memory (name, "ATOM2.DMP");
device_status_t a = test_dump_memory (name, "ATOM2.DMP");
message ("\nSUMMARY\n");
message ("-------\n");

View File

@ -9,14 +9,15 @@
message ("%s:%d: %s\n", __FILE__, __LINE__, expr); \
}
int test_dump_memory (const char* name, const char* filename)
device_status_t
test_dump_memory (const char* name, const char* filename)
{
device_t *device = NULL;
unsigned char data[REEFNET_SENSUSPRO_MEMORY_SIZE] = {0};
unsigned char handshake[REEFNET_SENSUSPRO_HANDSHAKE_SIZE] = {0};
message ("reefnet_sensuspro_device_open\n");
int rc = reefnet_sensuspro_device_open (&device, name);
device_status_t rc = reefnet_sensuspro_device_open (&device, name);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
return rc;
@ -62,7 +63,8 @@ int test_dump_memory (const char* name, const char* filename)
}
const char* errmsg (int rc)
const char*
errmsg (device_status_t rc)
{
switch (rc) {
case DEVICE_STATUS_SUCCESS:
@ -103,7 +105,7 @@ int main(int argc, char *argv[])
message ("DEVICE=%s\n", name);
int a = test_dump_memory (name, "SENSUSPRO.DMP");
device_status_t a = test_dump_memory (name, "SENSUSPRO.DMP");
message ("SUMMARY\n");
message ("-------\n");

View File

@ -10,13 +10,14 @@
}
int test_dump_memory_dives (const char* name, const char* filename)
device_status_t
test_dump_memory_dives (const char* name, const char* filename)
{
device_t *device = NULL;
unsigned char handshake[REEFNET_SENSUSULTRA_HANDSHAKE_SIZE] = {0};
message ("reefnet_sensusultra_device_open\n");
int rc = reefnet_sensusultra_device_open (&device, name);
device_status_t rc = reefnet_sensusultra_device_open (&device, name);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
return rc;
@ -54,14 +55,15 @@ int test_dump_memory_dives (const char* name, const char* filename)
}
int test_dump_memory_data (const char* name, const char* filename)
device_status_t
test_dump_memory_data (const char* name, const char* filename)
{
device_t *device = NULL;
unsigned char data[REEFNET_SENSUSULTRA_MEMORY_DATA_SIZE] = {0};
unsigned char handshake[REEFNET_SENSUSULTRA_HANDSHAKE_SIZE] = {0};
message ("reefnet_sensusultra_device_open\n");
int rc = reefnet_sensusultra_device_open (&device, name);
device_status_t rc = reefnet_sensusultra_device_open (&device, name);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
return rc;
@ -107,14 +109,15 @@ int test_dump_memory_data (const char* name, const char* filename)
}
int test_dump_memory_user (const char* name, const char* filename)
device_status_t
test_dump_memory_user (const char* name, const char* filename)
{
device_t *device = NULL;
unsigned char data[REEFNET_SENSUSULTRA_MEMORY_USER_SIZE] = {0};
unsigned char handshake[REEFNET_SENSUSULTRA_HANDSHAKE_SIZE] = {0};
message ("reefnet_sensusultra_device_open\n");
int rc = reefnet_sensusultra_device_open (&device, name);
device_status_t rc = reefnet_sensusultra_device_open (&device, name);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
return rc;
@ -159,7 +162,8 @@ int test_dump_memory_user (const char* name, const char* filename)
}
const char* errmsg (int rc)
const char*
errmsg (device_status_t rc)
{
switch (rc) {
case DEVICE_STATUS_SUCCESS:
@ -200,9 +204,9 @@ int main(int argc, char *argv[])
message ("DEVICE=%s\n", name);
int a = test_dump_memory_data (name, "SENSUSULTRA_DATA.DMP");
int b = test_dump_memory_user (name, "SENSUSULTRA_USER.DMP");
int c = test_dump_memory_dives (name, "SENSUSULTRA_DIVES.DMP");
device_status_t a = test_dump_memory_data (name, "SENSUSULTRA_DATA.DMP");
device_status_t b = test_dump_memory_user (name, "SENSUSULTRA_USER.DMP");
device_status_t c = test_dump_memory_dives (name, "SENSUSULTRA_DIVES.DMP");
message ("SUMMARY\n");
message ("-------\n");

View File

@ -8,12 +8,13 @@
message ("%s:%d: %s\n", __FILE__, __LINE__, expr); \
}
int test_dump_sdm (const char* name)
device_status_t
test_dump_sdm (const char* name)
{
device_t *device = NULL;
message ("suunto_d9_device_open\n");
int rc = suunto_d9_device_open (&device, name);
device_status_t rc = suunto_d9_device_open (&device, name);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
return rc;
@ -46,13 +47,15 @@ int test_dump_sdm (const char* name)
return DEVICE_STATUS_SUCCESS;
}
int test_dump_memory (const char* name, const char* filename)
device_status_t
test_dump_memory (const char* name, const char* filename)
{
unsigned char data[SUUNTO_D9_MEMORY_SIZE] = {0};
device_t *device = NULL;
message ("suunto_d9_device_open\n");
int rc = suunto_d9_device_open (&device, name);
device_status_t rc = suunto_d9_device_open (&device, name);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
return rc;
@ -92,7 +95,9 @@ int test_dump_memory (const char* name, const char* filename)
return DEVICE_STATUS_SUCCESS;
}
const char* errmsg (int rc)
const char*
errmsg (device_status_t rc)
{
switch (rc) {
case DEVICE_STATUS_SUCCESS:
@ -132,8 +137,8 @@ int main(int argc, char *argv[])
message ("DEVICE=%s\n", name);
int a = test_dump_memory (name, "D9.DMP");
int b = test_dump_sdm (name);
device_status_t a = test_dump_memory (name, "D9.DMP");
device_status_t b = test_dump_sdm (name);
message ("\nSUMMARY\n");
message ("-------\n");

View File

@ -8,13 +8,14 @@
message ("%s:%d: %s\n", __FILE__, __LINE__, expr); \
}
int test_dump_memory (const char* name, const char* filename)
device_status_t
test_dump_memory (const char* name, const char* filename)
{
device_t *device = NULL;
unsigned char data[SUUNTO_EON_MEMORY_SIZE] = {0};
message ("suunto_eon_device_open\n");
int rc = suunto_eon_device_open (&device, name);
device_status_t rc = suunto_eon_device_open (&device, name);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
return rc;
@ -46,7 +47,9 @@ int test_dump_memory (const char* name, const char* filename)
return DEVICE_STATUS_SUCCESS;
}
const char* errmsg (int rc)
const char*
errmsg (device_status_t rc)
{
switch (rc) {
case DEVICE_STATUS_SUCCESS:
@ -87,7 +90,7 @@ int main(int argc, char *argv[])
message ("DEVICE=%s\n", name);
int a = test_dump_memory (name, "EON.DMP");
device_status_t a = test_dump_memory (name, "EON.DMP");
message ("SUMMARY\n");
message ("-------\n");

View File

@ -8,12 +8,14 @@
message ("%s:%d: %s\n", __FILE__, __LINE__, expr); \
}
int test_dump_sdm (const char* name)
device_status_t
test_dump_sdm (const char* name)
{
device_t *device = NULL;
message ("suunto_vyper2_device_open\n");
int rc = suunto_vyper2_device_open (&device, name);
device_status_t rc = suunto_vyper2_device_open (&device, name);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
return rc;
@ -46,13 +48,15 @@ int test_dump_sdm (const char* name)
return DEVICE_STATUS_SUCCESS;
}
int test_dump_memory (const char* name, const char* filename)
device_status_t
test_dump_memory (const char* name, const char* filename)
{
unsigned char data[SUUNTO_VYPER2_MEMORY_SIZE] = {0};
device_t *device = NULL;
message ("suunto_vyper2_device_open\n");
int rc = suunto_vyper2_device_open (&device, name);
device_status_t rc = suunto_vyper2_device_open (&device, name);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
return rc;
@ -92,7 +96,9 @@ int test_dump_memory (const char* name, const char* filename)
return DEVICE_STATUS_SUCCESS;
}
const char* errmsg (int rc)
const char*
errmsg (device_status_t rc)
{
switch (rc) {
case DEVICE_STATUS_SUCCESS:
@ -132,8 +138,8 @@ int main(int argc, char *argv[])
message ("DEVICE=%s\n", name);
int a = test_dump_memory (name, "VYPER2.DMP");
int b = test_dump_sdm (name);
device_status_t a = test_dump_memory (name, "VYPER2.DMP");
device_status_t b = test_dump_sdm (name);
message ("\nSUMMARY\n");
message ("-------\n");

View File

@ -9,12 +9,13 @@
message ("%s:%d: %s\n", __FILE__, __LINE__, expr); \
}
int test_dump_sdm (const char* name, unsigned int delay)
device_status_t
test_dump_sdm (const char* name, unsigned int delay)
{
device_t *device = NULL;
message ("suunto_vyper_device_open\n");
int rc = suunto_vyper_device_open (&device, name);
device_status_t rc = suunto_vyper_device_open (&device, name);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
return rc;
@ -48,13 +49,15 @@ int test_dump_sdm (const char* name, unsigned int delay)
return DEVICE_STATUS_SUCCESS;
}
int test_dump_memory (const char* name, unsigned int delay, const char* filename)
device_status_t
test_dump_memory (const char* name, unsigned int delay, const char* filename)
{
unsigned char data[SUUNTO_VYPER_MEMORY_SIZE] = {0};
device_t *device = NULL;
message ("suunto_vyper_device_open\n");
int rc = suunto_vyper_device_open (&device, name);
device_status_t rc = suunto_vyper_device_open (&device, name);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
return rc;
@ -95,7 +98,9 @@ int test_dump_memory (const char* name, unsigned int delay, const char* filename
return DEVICE_STATUS_SUCCESS;
}
const char* errmsg (int rc)
const char*
errmsg (device_status_t rc)
{
switch (rc) {
case DEVICE_STATUS_SUCCESS:
@ -140,8 +145,8 @@ int main(int argc, char *argv[])
message ("DEVICE=%s, DELAY=%i\n", name, delay);
int a = test_dump_sdm (name, delay);
int b = test_dump_memory (name, delay, "VYPER.DMP");
device_status_t a = test_dump_sdm (name, delay);
device_status_t b = test_dump_memory (name, delay, "VYPER.DMP");
message ("\nSUMMARY\n");
message ("-------\n");

View File

@ -9,13 +9,14 @@
}
int test_dump_memory (const char* name, const char* filename)
device_status_t
test_dump_memory (const char* name, const char* filename)
{
device_t *device = NULL;
unsigned char data[UWATEC_ALADIN_MEMORY_SIZE] = {0};
message ("uwatec_aladin_device_open\n");
int rc = uwatec_aladin_device_open (&device, name);
device_status_t rc = uwatec_aladin_device_open (&device, name);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
return rc;
@ -48,7 +49,8 @@ int test_dump_memory (const char* name, const char* filename)
}
const char* errmsg (int rc)
const char*
errmsg (device_status_t rc)
{
switch (rc) {
case DEVICE_STATUS_SUCCESS:
@ -89,7 +91,7 @@ int main(int argc, char *argv[])
message ("DEVICE=%s\n", name);
int a = test_dump_memory (name, "ALADIN.DMP");
device_status_t a = test_dump_memory (name, "ALADIN.DMP");
message ("\nSUMMARY\n");
message ("-------\n");

View File

@ -9,13 +9,14 @@
}
int test_dump_memory (const char* name, const char* filename)
device_status_t
test_dump_memory (const char* name, const char* filename)
{
device_t *device = NULL;
unsigned char data[0x8000] = {0};
message ("uwatec_memomouse_device_open\n");
int rc = uwatec_memomouse_device_open (&device, name);
device_status_t rc = uwatec_memomouse_device_open (&device, name);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
return rc;
@ -48,7 +49,8 @@ int test_dump_memory (const char* name, const char* filename)
}
const char* errmsg (int rc)
const char*
errmsg (device_status_t rc)
{
switch (rc) {
case DEVICE_STATUS_SUCCESS:
@ -89,7 +91,7 @@ int main(int argc, char *argv[])
message ("DEVICE=%s\n", name);
int a = test_dump_memory (name, "MEMOMOUSE.DMP");
device_status_t a = test_dump_memory (name, "MEMOMOUSE.DMP");
message ("\nSUMMARY\n");
message ("-------\n");

View File

@ -11,7 +11,8 @@
}
int test_dump_memory (const char* filename)
device_status_t
test_dump_memory (const char* filename)
{
device_t *device = NULL;
@ -22,7 +23,7 @@ int test_dump_memory (const char* filename)
memset (data, 0, size * sizeof (unsigned char));
message ("uwatec_smart_device_open\n");
int rc = uwatec_smart_device_open (&device);
device_status_t rc = uwatec_smart_device_open (&device);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Cannot open device.");
free (data);
@ -79,7 +80,8 @@ int test_dump_memory (const char* filename)
}
const char* errmsg (int rc)
const char*
errmsg (device_status_t rc)
{
switch (rc) {
case DEVICE_STATUS_SUCCESS:
@ -108,7 +110,7 @@ int main(int argc, char *argv[])
{
message_set_logfile ("SMART.LOG");
int a = test_dump_memory ("SMART.DMP");
device_status_t a = test_dump_memory ("SMART.DMP");
message ("\nSUMMARY\n");
message ("-------\n");

View File

@ -85,17 +85,17 @@ oceanic_atom2_transfer (oceanic_atom2_device_t *device, const unsigned char comm
unsigned char response = NAK;
while (response == NAK) {
// Send the command to the dive computer.
int rc = oceanic_atom2_send (device, command, csize);
device_status_t rc = oceanic_atom2_send (device, command, csize);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Failed to send the command.");
return rc;
}
// Receive the response (ACK/NAK) of the dive computer.
rc = serial_read (device->port, &response, 1);
if (rc != 1) {
int n = serial_read (device->port, &response, 1);
if (n != 1) {
WARNING ("Failed to receive the answer.");
return EXITCODE (rc);
return EXITCODE (n);
}
#ifndef NDEBUG
@ -222,7 +222,7 @@ oceanic_atom2_device_handshake (device_t *abstract)
// Send the command to the dive computer.
unsigned char command[3] = {0xA8, 0x99, 0x00};
int rc = oceanic_atom2_send (device, command, sizeof (command));
device_status_t rc = oceanic_atom2_send (device, command, sizeof (command));
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Failed to send the command.");
return rc;
@ -230,10 +230,10 @@ oceanic_atom2_device_handshake (device_t *abstract)
// Receive the answer of the dive computer.
unsigned char answer[3] = {0};
rc = serial_read (device->port, answer, sizeof (answer));
if (rc != sizeof (answer)) {
int n = serial_read (device->port, answer, sizeof (answer));
if (n != sizeof (answer)) {
WARNING ("Failed to receive the answer.");
return EXITCODE (rc);
return EXITCODE (n);
}
// Verify the answer.
@ -256,7 +256,7 @@ oceanic_atom2_device_quit (device_t *abstract)
// Send the command to the dive computer.
unsigned char command[4] = {0x6A, 0x05, 0xA5, 0x00};
int rc = oceanic_atom2_send (device, command, sizeof (command));
device_status_t rc = oceanic_atom2_send (device, command, sizeof (command));
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Failed to send the command.");
return rc;
@ -264,10 +264,10 @@ oceanic_atom2_device_quit (device_t *abstract)
// Receive the answer of the dive computer.
unsigned char answer[1] = {0};
rc = serial_read (device->port, answer, sizeof (answer));
if (rc != sizeof (answer)) {
int n = serial_read (device->port, answer, sizeof (answer));
if (n != sizeof (answer)) {
WARNING ("Failed to receive the answer.");
return EXITCODE (rc);
return EXITCODE (n);
}
// Verify the answer.
@ -293,7 +293,7 @@ oceanic_atom2_device_version (device_t *abstract, unsigned char data[], unsigned
unsigned char answer[OCEANIC_ATOM2_PACKET_SIZE + 1] = {0};
unsigned char command[2] = {0x84, 0x00};
int rc = oceanic_atom2_transfer (device, command, sizeof (command), answer, sizeof (answer));
device_status_t rc = oceanic_atom2_transfer (device, command, sizeof (command), answer, sizeof (answer));
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -331,7 +331,7 @@ oceanic_atom2_device_read (device_t *abstract, unsigned int address, unsigned ch
(number >> 8) & 0xFF, // high
(number ) & 0xFF, // low
0};
int rc = oceanic_atom2_transfer (device, command, sizeof (command), answer, sizeof (answer));
device_status_t rc = oceanic_atom2_transfer (device, command, sizeof (command), answer, sizeof (answer));
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -364,7 +364,7 @@ oceanic_atom2_read_ringbuffer (device_t *abstract, unsigned int address, unsigne
unsigned int a = end - address;
unsigned int b = size - a;
int rc = oceanic_atom2_device_read (abstract, address, data, a);
device_status_t rc = oceanic_atom2_device_read (abstract, address, data, a);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -372,7 +372,7 @@ oceanic_atom2_read_ringbuffer (device_t *abstract, unsigned int address, unsigne
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
} else {
int rc = oceanic_atom2_device_read (abstract, address, data, size);
device_status_t rc = oceanic_atom2_device_read (abstract, address, data, size);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
}
@ -389,7 +389,7 @@ oceanic_atom2_device_dump (device_t *abstract, unsigned char data[], unsigned in
if (size < OCEANIC_ATOM2_MEMORY_SIZE)
return DEVICE_STATUS_ERROR;
int rc = oceanic_atom2_device_read (abstract, 0x00, data, OCEANIC_ATOM2_MEMORY_SIZE);
device_status_t rc = oceanic_atom2_device_read (abstract, 0x00, data, OCEANIC_ATOM2_MEMORY_SIZE);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -408,7 +408,7 @@ oceanic_atom2_device_foreach (device_t *abstract, dive_callback_t callback, void
// Read the pointer data.
unsigned char pointers[OCEANIC_ATOM2_PACKET_SIZE] = {0};
int rc = oceanic_atom2_device_read (abstract, 0x0040, pointers, OCEANIC_ATOM2_PACKET_SIZE);
device_status_t rc = oceanic_atom2_device_read (abstract, 0x0040, pointers, OCEANIC_ATOM2_PACKET_SIZE);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Cannot read pointers.");
return rc;

View File

@ -256,7 +256,7 @@ reefnet_sensuspro_device_foreach (device_t *abstract, dive_callback_t callback,
unsigned char data[REEFNET_SENSUSPRO_MEMORY_SIZE] = {0};
int rc = reefnet_sensuspro_device_dump (abstract, data, sizeof (data), NULL);
device_status_t rc = reefnet_sensuspro_device_dump (abstract, data, sizeof (data), NULL);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;

View File

@ -192,7 +192,7 @@ reefnet_sensusultra_send_ushort (reefnet_sensusultra_device_t *device, unsigned
{
// Send the least-significant byte.
unsigned char lsb = value & 0xFF;
int rc = reefnet_sensusultra_send_uchar (device, lsb);
device_status_t rc = reefnet_sensusultra_send_uchar (device, lsb);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -241,7 +241,7 @@ reefnet_sensusultra_device_handshake (device_t *abstract, unsigned char *data, u
// Flush the input and output buffers.
serial_flush (device->port, SERIAL_QUEUE_BOTH);
int rc = 0;
device_status_t rc = DEVICE_STATUS_SUCCESS;
unsigned int nretries = 0;
unsigned char handshake[REEFNET_SENSUSULTRA_HANDSHAKE_SIZE + 2] = {0};
while ((rc = reefnet_sensusultra_packet (device, handshake, sizeof (handshake), 0)) != DEVICE_STATUS_SUCCESS) {
@ -304,7 +304,7 @@ reefnet_sensusultra_page (reefnet_sensusultra_device_t *device, unsigned char *d
if (device == NULL)
return DEVICE_STATUS_ERROR;
int rc = 0;
device_status_t rc = DEVICE_STATUS_SUCCESS;
unsigned int nretries = 0;
unsigned char package[REEFNET_SENSUSULTRA_PACKET_SIZE + 4] = {0};
while ((rc = reefnet_sensusultra_packet (device, package, sizeof (package), 2)) != DEVICE_STATUS_SUCCESS) {
@ -357,7 +357,7 @@ reefnet_sensusultra_device_dump (device_t *abstract, unsigned char *data, unsign
progress_init (&progress, abstract, REEFNET_SENSUSULTRA_MEMORY_DATA_SIZE);
// Send the instruction code to the device.
int rc = reefnet_sensusultra_send_ushort (device, 0xB421);
device_status_t rc = reefnet_sensusultra_send_ushort (device, 0xB421);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -401,7 +401,7 @@ reefnet_sensusultra_device_read_user (device_t *abstract, unsigned char *data, u
return DEVICE_STATUS_ERROR;
// Send the instruction code to the device.
int rc = reefnet_sensusultra_send_ushort (device, 0xB420);
device_status_t rc = reefnet_sensusultra_send_ushort (device, 0xB420);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -437,7 +437,7 @@ reefnet_sensusultra_device_write_user (device_t *abstract, const unsigned char *
assert (size >= REEFNET_SENSUSULTRA_MEMORY_USER_SIZE);
// Send the instruction code to the device.
int rc = reefnet_sensusultra_send_ushort (device, 0xB430);
device_status_t rc = reefnet_sensusultra_send_ushort (device, 0xB430);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -467,7 +467,7 @@ reefnet_sensusultra_write_internal (device_t *abstract, unsigned int code, unsig
return DEVICE_STATUS_TYPE_MISMATCH;
// Send the instruction code to the device.
int rc = reefnet_sensusultra_send_ushort (device, code);
device_status_t rc = reefnet_sensusultra_send_ushort (device, code);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -529,7 +529,7 @@ reefnet_sensusultra_device_sense (device_t *abstract, unsigned char *data, unsig
return DEVICE_STATUS_TYPE_MISMATCH;
// Send the instruction code to the device.
int rc = reefnet_sensusultra_send_ushort (device, 0xB440);
device_status_t rc = reefnet_sensusultra_send_ushort (device, 0xB440);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -641,7 +641,7 @@ reefnet_sensusultra_device_foreach (device_t *abstract, dive_callback_t callback
unsigned int previous = REEFNET_SENSUSULTRA_MEMORY_DATA_SIZE;
// Send the instruction code to the device.
int rc = reefnet_sensusultra_send_ushort (device, 0xB421);
device_status_t rc = reefnet_sensusultra_send_ushort (device, 0xB421);
if (rc != DEVICE_STATUS_SUCCESS) {
free (data);
return rc;

View File

@ -175,17 +175,17 @@ suunto_d9_transfer (suunto_d9_device_t *device, const unsigned char command[], u
for (unsigned int i = 0;; ++i) {
// Send the command to the dive computer.
int rc = suunto_d9_send (device, command, csize);
device_status_t rc = suunto_d9_send (device, command, csize);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Failed to send the command.");
return rc;
}
// Receive the answer of the dive computer.
rc = serial_read (device->port, answer, asize);
if (rc != asize) {
int n = serial_read (device->port, answer, asize);
if (n != asize) {
WARNING ("Failed to receive the answer.");
if (rc == -1)
if (n == -1)
return DEVICE_STATUS_IO;
if (i < MAXRETRIES)
continue; // Retry.
@ -226,7 +226,7 @@ suunto_d9_device_version (device_t *abstract, unsigned char data[], unsigned int
unsigned char answer[SUUNTO_D9_VERSION_SIZE + 4] = {0};
unsigned char command[4] = {0x0F, 0x00, 0x00, 0x0F};
int rc = suunto_d9_transfer (device, command, sizeof (command), answer, sizeof (answer), 4);
device_status_t rc = suunto_d9_transfer (device, command, sizeof (command), answer, sizeof (answer), 4);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -250,7 +250,7 @@ suunto_d9_device_reset_maxdepth (device_t *abstract)
unsigned char answer[4] = {0};
unsigned char command[4] = {0x20, 0x00, 0x00, 0x20};
int rc = suunto_d9_transfer (device, command, sizeof (command), answer, sizeof (answer), 0);
device_status_t rc = suunto_d9_transfer (device, command, sizeof (command), answer, sizeof (answer), 0);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -286,7 +286,7 @@ suunto_d9_read (device_t *abstract, unsigned int address, unsigned char data[],
len, // count
0}; // CRC
command[6] = checksum_xor_uint8 (command, 6, 0x00);
int rc = suunto_d9_transfer (device, command, sizeof (command), answer, len + 7, len);
device_status_t rc = suunto_d9_transfer (device, command, sizeof (command), answer, len + 7, len);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -343,7 +343,7 @@ suunto_d9_device_write (device_t *abstract, unsigned int address, const unsigned
0}; // data + CRC
memcpy (command + 6, data, len);
command[len + 6] = checksum_xor_uint8 (command, len + 6, 0x00);
int rc = suunto_d9_transfer (device, command, len + 7, answer, sizeof (answer), 0);
device_status_t rc = suunto_d9_transfer (device, command, len + 7, answer, sizeof (answer), 0);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -377,7 +377,7 @@ suunto_d9_device_dump (device_t *abstract, unsigned char data[], unsigned int si
device_progress_state_t progress;
progress_init (&progress, abstract, SUUNTO_D9_MEMORY_SIZE);
int rc = suunto_d9_read (abstract, 0x00, data, SUUNTO_D9_MEMORY_SIZE, &progress);
device_status_t rc = suunto_d9_read (abstract, 0x00, data, SUUNTO_D9_MEMORY_SIZE, &progress);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -400,7 +400,7 @@ suunto_d9_device_foreach (device_t *abstract, dive_callback_t callback, void *us
// Read the header bytes.
unsigned char header[8] = {0};
int rc = suunto_d9_read (abstract, 0x0190, header, sizeof (header), NULL);
device_status_t rc = suunto_d9_read (abstract, 0x0190, header, sizeof (header), NULL);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Cannot read memory header.");
return rc;

View File

@ -174,7 +174,7 @@ suunto_eon_device_foreach (device_t *abstract, dive_callback_t callback, void *u
{
unsigned char data[SUUNTO_EON_MEMORY_SIZE] = {0};
int rc = suunto_eon_device_dump (abstract, data, sizeof (data), NULL);
device_status_t rc = suunto_eon_device_dump (abstract, data, sizeof (data), NULL);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -226,7 +226,7 @@ suunto_eon_device_write_interval (device_t *abstract, unsigned char interval)
}
device_status_t
device_status_t
suunto_eon_extract_dives (const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata)
{
assert (size >= SUUNTO_EON_MEMORY_SIZE);

View File

@ -150,7 +150,8 @@ suunto_vyper_device_detect_interface (device_t *abstract)
if (! device_is_suunto_vyper (abstract))
return DEVICE_STATUS_TYPE_MISMATCH;
int rc, detectmode_worked = 1;
device_status_t rc;
int detectmode_worked = 1;
unsigned char command[3] = {'A', 'T', '\r'}, reply[3] = {0}, extra = 0;
// Make sure everything is in a sane state.
@ -166,8 +167,8 @@ suunto_vyper_device_detect_interface (device_t *abstract)
rc = suunto_vyper_send_testcmd (device, command, 3);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
rc = serial_read (device->port, reply, 3);
if (rc != 3 || memcmp (command, reply, 3) != 0) {
int n = serial_read (device->port, reply, 3);
if (n != 3 || memcmp (command, reply, 3) != 0) {
WARNING ("Interface not responding in probe mode.");
detectmode_worked = 0;
}
@ -182,8 +183,8 @@ suunto_vyper_device_detect_interface (device_t *abstract)
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
serial_set_rts (device->port, 0);
rc = serial_read (device->port, reply, 3);
if (rc == 0) {
n = serial_read (device->port, reply, 3);
if (n == 0) {
if (detectmode_worked) {
WARNING ("Detected an original suunto interface with RTS-switching.");
} else {
@ -192,7 +193,7 @@ suunto_vyper_device_detect_interface (device_t *abstract)
device->ifacealwaysechos = 0;
return DEVICE_STATUS_SUCCESS;
}
if (rc != 3 || memcmp (command, reply, 3) != 0) {
if (n != 3 || memcmp (command, reply, 3) != 0) {
WARNING ("Interface not responding in transfer mode.");
}
if (serial_read (device->port, &extra, 1) == 1) {
@ -258,17 +259,17 @@ suunto_vyper_transfer (suunto_vyper_device_t *device, const unsigned char comman
assert (asize >= size + 2);
// Send the command to the dive computer.
int rc = suunto_vyper_send (device, command, csize);
device_status_t rc = suunto_vyper_send (device, command, csize);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Failed to send the command.");
return rc;
}
// Receive the answer of the dive computer.
rc = serial_read (device->port, answer, asize);
if (rc != asize) {
int n = serial_read (device->port, answer, asize);
if (n != asize) {
WARNING ("Failed to receive the answer.");
if (rc == -1)
if (n == -1)
return DEVICE_STATUS_IO;
return DEVICE_STATUS_TIMEOUT;
}
@ -315,7 +316,7 @@ suunto_vyper_read (device_t *abstract, unsigned int address, unsigned char data[
len, // count
0}; // CRC
command[4] = checksum_xor_uint8 (command, 4, 0x00);
int rc = suunto_vyper_transfer (device, command, sizeof (command), answer, len + 5, len);
device_status_t rc = suunto_vyper_transfer (device, command, sizeof (command), answer, len + 5, len);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -366,7 +367,7 @@ suunto_vyper_device_write (device_t *abstract, unsigned int address, const unsig
// Prepare to write the package.
unsigned char panswer[3] = {0};
unsigned char pcommand[3] = {0x07, 0xA5, 0xA2};
int rc = suunto_vyper_transfer (device, pcommand, sizeof (pcommand), panswer, sizeof (panswer), 0);
device_status_t rc = suunto_vyper_transfer (device, pcommand, sizeof (pcommand), panswer, sizeof (panswer), 0);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -415,7 +416,7 @@ suunto_vyper_read_dive (device_t *abstract, unsigned char data[], unsigned int s
// Send the command to the dive computer.
unsigned char command[3] = {init ? 0x08 : 0x09, 0xA5, 0x00};
command[2] = checksum_xor_uint8 (command, 2, 0x00);
int rc = suunto_vyper_send (device, command, 3);
device_status_t rc = suunto_vyper_send (device, command, 3);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Failed to send the command.");
return rc;
@ -428,8 +429,8 @@ suunto_vyper_read_dive (device_t *abstract, unsigned char data[], unsigned int s
for (unsigned int npackages = 0;; ++npackages) {
// Receive the header of the package.
unsigned char answer[SUUNTO_VYPER_PACKET_SIZE + 3] = {0};
rc = serial_read (device->port, answer, 2);
if (rc != 2) {
int n = serial_read (device->port, answer, 2);
if (n != 2) {
// If no data is received because a timeout occured, we assume
// the last package was already received and the transmission
// can be finished. Unfortunately this is not 100% reliable,
@ -438,10 +439,10 @@ suunto_vyper_read_dive (device_t *abstract, unsigned char data[], unsigned int s
// good enough in practice.
// Only for the very first package, we can be sure there was
// an error, because the DC always sends at least one package.
if (rc == 0 && npackages != 0)
if (n == 0 && npackages != 0)
break;
WARNING ("Failed to receive the answer.");
if (rc == -1)
if (n == -1)
return DEVICE_STATUS_IO;
return DEVICE_STATUS_TIMEOUT;
}
@ -455,10 +456,10 @@ suunto_vyper_read_dive (device_t *abstract, unsigned char data[], unsigned int s
// Receive the remaining part of the package.
unsigned char len = answer[1];
rc = serial_read (device->port, answer + 2, len + 1);
if (rc != len + 1) {
n = serial_read (device->port, answer + 2, len + 1);
if (n != len + 1) {
WARNING ("Failed to receive the answer.");
if (rc == -1)
if (n == -1)
return DEVICE_STATUS_IO;
return DEVICE_STATUS_TIMEOUT;
}
@ -550,7 +551,7 @@ suunto_vyper_device_dump (device_t *abstract, unsigned char data[], unsigned int
device_progress_state_t progress;
progress_init (&progress, abstract, SUUNTO_VYPER_MEMORY_SIZE);
int rc = suunto_vyper_read (abstract, 0x00, data, SUUNTO_VYPER_MEMORY_SIZE, &progress);
device_status_t rc = suunto_vyper_read (abstract, 0x00, data, SUUNTO_VYPER_MEMORY_SIZE, &progress);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -578,7 +579,7 @@ suunto_vyper_device_foreach (device_t *abstract, dive_callback_t callback, void
unsigned char data[SUUNTO_VYPER_MEMORY_SIZE - 0x4C] = {0};
int rc = 0;
device_status_t rc = DEVICE_STATUS_SUCCESS;
unsigned int ndives = 0;
unsigned int offset = 0;
unsigned int nbytes = 0;
@ -597,7 +598,7 @@ suunto_vyper_device_foreach (device_t *abstract, dive_callback_t callback, void
}
device_status_t
device_status_t
suunto_vyper_extract_dives (const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata)
{
assert (size >= SUUNTO_VYPER_MEMORY_SIZE);
@ -608,7 +609,7 @@ suunto_vyper_extract_dives (const unsigned char data[], unsigned int size, dive_
}
device_status_t
device_status_t
suunto_spyder_extract_dives (const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata)
{
assert (size >= SUUNTO_VYPER_MEMORY_SIZE);

View File

@ -162,17 +162,17 @@ suunto_vyper2_transfer (suunto_vyper2_device_t *device, const unsigned char comm
for (unsigned int i = 0;; ++i) {
// Send the command to the dive computer.
int rc = suunto_vyper2_send (device, command, csize);
device_status_t rc = suunto_vyper2_send (device, command, csize);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Failed to send the command.");
return rc;
}
// Receive the answer of the dive computer.
rc = serial_read (device->port, answer, asize);
if (rc != asize) {
int n = serial_read (device->port, answer, asize);
if (n != asize) {
WARNING ("Failed to receive the answer.");
if (rc == -1)
if (n == -1)
return DEVICE_STATUS_IO;
if (i < MAXRETRIES)
continue; // Retry.
@ -213,7 +213,7 @@ suunto_vyper2_device_version (device_t *abstract, unsigned char data[], unsigned
unsigned char answer[SUUNTO_VYPER2_VERSION_SIZE + 4] = {0};
unsigned char command[4] = {0x0F, 0x00, 0x00, 0x0F};
int rc = suunto_vyper2_transfer (device, command, sizeof (command), answer, sizeof (answer), 4);
device_status_t rc = suunto_vyper2_transfer (device, command, sizeof (command), answer, sizeof (answer), 4);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -237,7 +237,7 @@ suunto_vyper2_device_reset_maxdepth (device_t *abstract)
unsigned char answer[4] = {0};
unsigned char command[4] = {0x20, 0x00, 0x00, 0x20};
int rc = suunto_vyper2_transfer (device, command, sizeof (command), answer, sizeof (answer), 0);
device_status_t rc = suunto_vyper2_transfer (device, command, sizeof (command), answer, sizeof (answer), 0);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -273,7 +273,7 @@ suunto_vyper2_read (device_t *abstract, unsigned int address, unsigned char data
len, // count
0}; // CRC
command[6] = checksum_xor_uint8 (command, 6, 0x00);
int rc = suunto_vyper2_transfer (device, command, sizeof (command), answer, len + 7, len);
device_status_t rc = suunto_vyper2_transfer (device, command, sizeof (command), answer, len + 7, len);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -330,7 +330,7 @@ suunto_vyper2_device_write (device_t *abstract, unsigned int address, const unsi
0}; // data + CRC
memcpy (command + 6, data, len);
command[len + 6] = checksum_xor_uint8 (command, len + 6, 0x00);
int rc = suunto_vyper2_transfer (device, command, len + 7, answer, sizeof (answer), 0);
device_status_t rc = suunto_vyper2_transfer (device, command, len + 7, answer, sizeof (answer), 0);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -364,7 +364,7 @@ suunto_vyper2_device_dump (device_t *abstract, unsigned char data[], unsigned in
device_progress_state_t progress;
progress_init (&progress, abstract, SUUNTO_VYPER2_MEMORY_SIZE);
int rc = suunto_vyper2_read (abstract, 0x00, data, SUUNTO_VYPER2_MEMORY_SIZE, &progress);
device_status_t rc = suunto_vyper2_read (abstract, 0x00, data, SUUNTO_VYPER2_MEMORY_SIZE, &progress);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -387,7 +387,7 @@ suunto_vyper2_device_foreach (device_t *abstract, dive_callback_t callback, void
// Read the header bytes.
unsigned char header[8] = {0};
int rc = suunto_vyper2_read (abstract, 0x0190, header, sizeof (header), NULL);
device_status_t rc = suunto_vyper2_read (abstract, 0x0190, header, sizeof (header), NULL);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Cannot read memory header.");
return rc;

View File

@ -214,7 +214,7 @@ uwatec_aladin_device_foreach (device_t *abstract, dive_callback_t callback, void
unsigned char data[UWATEC_ALADIN_MEMORY_SIZE] = {0};
int rc = uwatec_aladin_device_dump (abstract, data, sizeof (data), NULL);
device_status_t rc = uwatec_aladin_device_dump (abstract, data, sizeof (data), NULL);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;

View File

@ -207,9 +207,9 @@ uwatec_memomouse_read_packet (uwatec_memomouse_device_t *device, unsigned char d
static device_status_t
uwatec_memomouse_read_packet_outer (uwatec_memomouse_device_t *device, unsigned char data[], unsigned int size, unsigned int *result)
{
int rc = 0;
unsigned int length = 0;
unsigned char package[126 + 2] = {0};
device_status_t rc = DEVICE_STATUS_SUCCESS;
while ((rc = uwatec_memomouse_read_packet (device, package, sizeof (package), &length)) != DEVICE_STATUS_SUCCESS) {
// Automatically discard a corrupted packet,
// and request a new one.
@ -253,7 +253,7 @@ uwatec_memomouse_read_packet_inner (uwatec_memomouse_device_t *device, unsigned
// Read the first package.
unsigned int length = 0;
unsigned char package[126] = {0};
int rc = uwatec_memomouse_read_packet_outer (device, package, sizeof (package), &length);
device_status_t rc = uwatec_memomouse_read_packet_outer (device, package, sizeof (package), &length);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -335,7 +335,7 @@ uwatec_memomouse_dump (uwatec_memomouse_device_t *device, unsigned char *data[],
serial_flush (device->port, SERIAL_QUEUE_INPUT);
// Reject the packet.
int rc = uwatec_memomouse_confirm (device, NAK);
device_status_t rc = uwatec_memomouse_confirm (device, NAK);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -345,7 +345,7 @@ uwatec_memomouse_dump (uwatec_memomouse_device_t *device, unsigned char *data[],
// Read the ID string.
unsigned int id_length = 0;
unsigned char *id_buffer = NULL;
int rc = uwatec_memomouse_read_packet_inner (device, &id_buffer, &id_length, NULL);
device_status_t rc = uwatec_memomouse_read_packet_inner (device, &id_buffer, &id_length, NULL);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -376,19 +376,19 @@ uwatec_memomouse_dump (uwatec_memomouse_device_t *device, unsigned char *data[],
serial_flush (device->port, SERIAL_QUEUE_INPUT);
// Send the command to the device.
rc = serial_write (device->port, command, sizeof (command));
if (rc != sizeof (command)) {
int n = serial_write (device->port, command, sizeof (command));
if (n != sizeof (command)) {
WARNING ("Failed to send the command.");
return EXITCODE (rc);
return EXITCODE (n);
}
serial_drain (device->port);
// Wait for the answer (ACK).
rc = serial_read (device->port, &answer, 1);
if (rc != 1) {
n = serial_read (device->port, &answer, 1);
if (n != 1) {
WARNING ("Failed to recieve the answer.");
return EXITCODE (rc);
return EXITCODE (n);
}
#ifndef NDEBUG
@ -420,7 +420,7 @@ uwatec_memomouse_device_dump (device_t *abstract, unsigned char data[], unsigned
unsigned int length = 0;
unsigned char *buffer = NULL;
int rc = uwatec_memomouse_dump (device, &buffer, &length);
device_status_t rc = uwatec_memomouse_dump (device, &buffer, &length);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -451,7 +451,7 @@ uwatec_memomouse_device_foreach (device_t *abstract, dive_callback_t callback, v
unsigned int length = 0;
unsigned char *buffer = NULL;
int rc = uwatec_memomouse_dump (device, &buffer, &length);
device_status_t rc = uwatec_memomouse_dump (device, &buffer, &length);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;

View File

@ -202,7 +202,7 @@ uwatec_smart_device_handshake (device_t *abstract)
command[0] = 0x1B;
int rc = uwatec_smart_transfer (device, command, 1, answer, 1);
device_status_t rc = uwatec_smart_transfer (device, command, 1, answer, 1);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -251,7 +251,7 @@ uwatec_smart_device_version (device_t *abstract, unsigned char data[], unsigned
command[0] = 0x1A;
int rc = uwatec_smart_transfer (device, command, 1, answer + 0, 4);
device_status_t rc = uwatec_smart_transfer (device, command, 1, answer + 0, 4);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -321,7 +321,7 @@ uwatec_smart_dump (uwatec_smart_device_t *device, unsigned char *data[], unsigne
command[7] = 0;
command[8] = 0;
int rc = uwatec_smart_transfer (device, command, 9, answer, 4);
device_status_t rc = uwatec_smart_transfer (device, command, 9, answer, 4);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -372,16 +372,16 @@ uwatec_smart_dump (uwatec_smart_device_t *device, unsigned char *data[], unsigne
unsigned int len = length - nbytes;
if (len > 32)
len = 32;
rc = irda_socket_read (device->socket, package + nbytes, len);
if (rc < 0) {
int n = irda_socket_read (device->socket, package + nbytes, len);
if (n < 0) {
WARNING ("Failed to receive the answer.");
free (package);
return EXITCODE (rc);
return EXITCODE (n);
}
progress_event (&progress, DEVICE_EVENT_PROGRESS, len);
nbytes += rc;
nbytes += n;
}
*data = package;
@ -401,7 +401,7 @@ uwatec_smart_device_dump (device_t *abstract, unsigned char data[], unsigned int
unsigned int length = 0;
unsigned char *buffer = NULL;
int rc = uwatec_smart_dump (device, &buffer, &length);
device_status_t rc = uwatec_smart_dump (device, &buffer, &length);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;
@ -432,7 +432,7 @@ uwatec_smart_device_foreach (device_t *abstract, dive_callback_t callback, void
unsigned int length = 0;
unsigned char *buffer = NULL;
int rc = uwatec_smart_dump (device, &buffer, &length);
device_status_t rc = uwatec_smart_dump (device, &buffer, &length);
if (rc != DEVICE_STATUS_SUCCESS)
return rc;