diff --git a/examples/reefnet_sensuspro_test.c b/examples/reefnet_sensuspro_test.c index 09dc08e..b500aa0 100644 --- a/examples/reefnet_sensuspro_test.c +++ b/examples/reefnet_sensuspro_test.c @@ -36,8 +36,9 @@ int test_dump_memory (const char* name, const char* filename) message ("time=%lu (%s)\n", (unsigned long)now, datetime); message ("device_dump\n"); - rc = device_dump (device, data, sizeof (data)); - if (rc < 0) { + unsigned int nbytes = 0; + rc = device_dump (device, data, sizeof (data), &nbytes); + if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot read memory."); device_close (device); return rc; @@ -46,7 +47,7 @@ int test_dump_memory (const char* name, const char* filename) message ("Dumping data\n"); FILE* fp = fopen (filename, "wb"); if (fp != NULL) { - fwrite (data, sizeof (unsigned char), rc, fp); + fwrite (data, sizeof (unsigned char), nbytes, fp); fclose (fp); } diff --git a/examples/reefnet_sensusultra_test.c b/examples/reefnet_sensusultra_test.c index 136fd0e..92b59aa 100644 --- a/examples/reefnet_sensusultra_test.c +++ b/examples/reefnet_sensusultra_test.c @@ -81,8 +81,9 @@ int test_dump_memory_data (const char* name, const char* filename) message ("time=%lu (%s)\n", (unsigned long)now, datetime); message ("device_dump\n"); - rc = device_dump (device, data, sizeof (data)); - if (rc < 0) { + unsigned int nbytes = 0; + rc = device_dump (device, data, sizeof (data), &nbytes); + if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot read memory."); device_close (device); return rc; @@ -91,7 +92,7 @@ int test_dump_memory_data (const char* name, const char* filename) message ("Dumping data\n"); FILE* fp = fopen (filename, "wb"); if (fp != NULL) { - fwrite (data, sizeof (unsigned char), rc, fp); + fwrite (data, sizeof (unsigned char), nbytes, fp); fclose (fp); } diff --git a/examples/suunto_eon_test.c b/examples/suunto_eon_test.c index 6dffecd..803ba8b 100644 --- a/examples/suunto_eon_test.c +++ b/examples/suunto_eon_test.c @@ -21,8 +21,9 @@ int test_dump_memory (const char* name, const char* filename) } message ("device_dump\n"); - rc = device_dump (device, data, sizeof (data)); - if (rc < 0) { + unsigned int nbytes = 0; + rc = device_dump (device, data, sizeof (data), &nbytes); + if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot read memory."); device_close (device); return rc; @@ -31,7 +32,7 @@ int test_dump_memory (const char* name, const char* filename) message ("Dumping data\n"); FILE* fp = fopen (filename, "wb"); if (fp != NULL) { - fwrite (data, sizeof (unsigned char), rc, fp); + fwrite (data, sizeof (unsigned char), nbytes, fp); fclose (fp); } diff --git a/examples/uwatec_aladin_test.c b/examples/uwatec_aladin_test.c index 8e60cf4..b576b07 100644 --- a/examples/uwatec_aladin_test.c +++ b/examples/uwatec_aladin_test.c @@ -22,8 +22,9 @@ int test_dump_memory (const char* name, const char* filename) } message ("device_dump\n"); - rc = device_dump (device, data, sizeof (data)); - if (rc < 0) { + unsigned int nbytes = 0; + rc = device_dump (device, data, sizeof (data), &nbytes); + if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot read memory."); device_close (device); return rc; @@ -32,7 +33,7 @@ int test_dump_memory (const char* name, const char* filename) message ("Dumping data\n"); FILE* fp = fopen (filename, "wb"); if (fp != NULL) { - fwrite (data, sizeof (unsigned char), rc, fp); + fwrite (data, sizeof (unsigned char), nbytes, fp); fclose (fp); } diff --git a/examples/uwatec_memomouse_test.c b/examples/uwatec_memomouse_test.c index 770d57e..8329d28 100644 --- a/examples/uwatec_memomouse_test.c +++ b/examples/uwatec_memomouse_test.c @@ -22,8 +22,9 @@ int test_dump_memory (const char* name, const char* filename) } message ("device_dump\n"); - rc = device_dump (device, data, sizeof (data)); - if (rc < 0) { + unsigned int nbytes = 0; + rc = device_dump (device, data, sizeof (data), &nbytes); + if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot read memory."); device_close (device); return rc; @@ -32,7 +33,7 @@ int test_dump_memory (const char* name, const char* filename) message ("Dumping data\n"); FILE* fp = fopen (filename, "wb"); if (fp != NULL) { - fwrite (data, sizeof (unsigned char), rc, fp); + fwrite (data, sizeof (unsigned char), nbytes, fp); fclose (fp); } diff --git a/examples/uwatec_smart_test.c b/examples/uwatec_smart_test.c index 761ac0e..136566d 100644 --- a/examples/uwatec_smart_test.c +++ b/examples/uwatec_smart_test.c @@ -49,8 +49,9 @@ int test_dump_memory (const char* filename) } message ("device_dump\n"); - rc = device_dump (device, data, size); - if (rc < 0) { + unsigned int nbytes = 0; + rc = device_dump (device, data, size, &nbytes); + if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Cannot read data."); device_close (device); free (data); @@ -60,7 +61,7 @@ int test_dump_memory (const char* filename) message ("Dumping data\n"); FILE* fp = fopen (filename, "wb"); if (fp != NULL) { - fwrite (data, sizeof (unsigned char), rc, fp); + fwrite (data, sizeof (unsigned char), nbytes, fp); fclose (fp); } diff --git a/src/device-private.h b/src/device-private.h index 056dd41..597a5ef 100644 --- a/src/device-private.h +++ b/src/device-private.h @@ -30,7 +30,7 @@ struct device_backend_t { device_status_t (*write) (device_t *device, unsigned int address, const unsigned char data[], unsigned int size); - device_status_t (*dump) (device_t *device, unsigned char data[], unsigned int size); + device_status_t (*dump) (device_t *device, unsigned char data[], unsigned int size, unsigned int *result); device_status_t (*foreach) (device_t *device, dive_callback_t callback, void *userdata); diff --git a/src/device.c b/src/device.c index 2c1dfd5..ae47cb9 100644 --- a/src/device.c +++ b/src/device.c @@ -90,7 +90,7 @@ device_write (device_t *device, unsigned int address, const unsigned char data[] device_status_t -device_dump (device_t *device, unsigned char data[], unsigned int size) +device_dump (device_t *device, unsigned char data[], unsigned int size, unsigned int *result) { if (device == NULL) return DEVICE_STATUS_UNSUPPORTED; @@ -98,7 +98,7 @@ device_dump (device_t *device, unsigned char data[], unsigned int size) if (device->backend->dump == NULL) return DEVICE_STATUS_UNSUPPORTED; - return device->backend->dump (device, data, size); + return device->backend->dump (device, data, size, result); } diff --git a/src/device.h b/src/device.h index b908425..a9f496d 100644 --- a/src/device.h +++ b/src/device.h @@ -52,7 +52,7 @@ device_status_t device_read (device_t *device, unsigned int address, unsigned ch device_status_t device_write (device_t *device, unsigned int address, const unsigned char data[], unsigned int size); -device_status_t device_dump (device_t *device, unsigned char data[], unsigned int size); +device_status_t device_dump (device_t *device, unsigned char data[], unsigned int size, unsigned int *result); device_status_t device_foreach (device_t *device, dive_callback_t callback, void *userdata); diff --git a/src/oceanic_atom2.c b/src/oceanic_atom2.c index d974e90..378dd0d 100644 --- a/src/oceanic_atom2.c +++ b/src/oceanic_atom2.c @@ -381,7 +381,7 @@ oceanic_atom2_read_ringbuffer (device_t *abstract, unsigned int address, unsigne } static device_status_t -oceanic_atom2_device_dump (device_t *abstract, unsigned char data[], unsigned int size) +oceanic_atom2_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result) { if (! device_is_oceanic_atom2 (abstract)) return DEVICE_STATUS_TYPE_MISMATCH; @@ -393,7 +393,10 @@ oceanic_atom2_device_dump (device_t *abstract, unsigned char data[], unsigned in if (rc != DEVICE_STATUS_SUCCESS) return rc; - return OCEANIC_ATOM2_MEMORY_SIZE; + if (result) + *result = OCEANIC_ATOM2_MEMORY_SIZE; + + return DEVICE_STATUS_SUCCESS; } diff --git a/src/reefnet_sensuspro.c b/src/reefnet_sensuspro.c index 77e6774..1542575 100644 --- a/src/reefnet_sensuspro.c +++ b/src/reefnet_sensuspro.c @@ -187,7 +187,7 @@ reefnet_sensuspro_device_handshake (device_t *abstract, unsigned char *data, uns static device_status_t -reefnet_sensuspro_device_dump (device_t *abstract, unsigned char *data, unsigned int size) +reefnet_sensuspro_device_dump (device_t *abstract, unsigned char *data, unsigned int size, unsigned int *result) { reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t*) abstract; @@ -239,7 +239,10 @@ reefnet_sensuspro_device_dump (device_t *abstract, unsigned char *data, unsigned return DEVICE_STATUS_MEMORY; } - return REEFNET_SENSUSPRO_MEMORY_SIZE; + if (result) + *result = REEFNET_SENSUSPRO_MEMORY_SIZE; + + return DEVICE_STATUS_SUCCESS; } @@ -253,8 +256,8 @@ 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)); - if (rc < 0) + int rc = reefnet_sensuspro_device_dump (abstract, data, sizeof (data), NULL); + if (rc != DEVICE_STATUS_SUCCESS) return rc; return reefnet_sensuspro_extract_dives (data, sizeof (data), callback, userdata, device->timestamp); diff --git a/src/reefnet_sensusultra.c b/src/reefnet_sensusultra.c index 5f47f0b..9136642 100644 --- a/src/reefnet_sensusultra.c +++ b/src/reefnet_sensusultra.c @@ -342,7 +342,7 @@ reefnet_sensusultra_page (reefnet_sensusultra_device_t *device, unsigned char *d static device_status_t -reefnet_sensusultra_device_dump (device_t *abstract, unsigned char *data, unsigned int size) +reefnet_sensusultra_device_dump (device_t *abstract, unsigned char *data, unsigned int size, unsigned int *result) { reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract; @@ -382,7 +382,10 @@ reefnet_sensusultra_device_dump (device_t *abstract, unsigned char *data, unsign npages++; } - return REEFNET_SENSUSULTRA_MEMORY_DATA_SIZE; + if (result) + *result = REEFNET_SENSUSULTRA_MEMORY_DATA_SIZE; + + return DEVICE_STATUS_SUCCESS; } diff --git a/src/suunto_d9.c b/src/suunto_d9.c index db59821..2a64317 100644 --- a/src/suunto_d9.c +++ b/src/suunto_d9.c @@ -365,7 +365,7 @@ suunto_d9_device_write (device_t *abstract, unsigned int address, const unsigned static device_status_t -suunto_d9_device_dump (device_t *abstract, unsigned char data[], unsigned int size) +suunto_d9_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result) { if (! device_is_suunto_d9 (abstract)) return DEVICE_STATUS_TYPE_MISMATCH; @@ -381,7 +381,10 @@ suunto_d9_device_dump (device_t *abstract, unsigned char data[], unsigned int si if (rc != DEVICE_STATUS_SUCCESS) return rc; - return SUUNTO_D9_MEMORY_SIZE; + if (result) + *result = SUUNTO_D9_MEMORY_SIZE; + + return DEVICE_STATUS_SUCCESS; } diff --git a/src/suunto_eon.c b/src/suunto_eon.c index 77f97c7..56dc09e 100644 --- a/src/suunto_eon.c +++ b/src/suunto_eon.c @@ -118,7 +118,7 @@ suunto_eon_device_close (device_t *abstract) static device_status_t -suunto_eon_device_dump (device_t *abstract, unsigned char data[], unsigned int size) +suunto_eon_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result) { suunto_eon_device_t *device = (suunto_eon_device_t*) abstract; @@ -162,7 +162,10 @@ suunto_eon_device_dump (device_t *abstract, unsigned char data[], unsigned int s return DEVICE_STATUS_MEMORY; } - return SUUNTO_EON_MEMORY_SIZE; + if (result) + *result = SUUNTO_EON_MEMORY_SIZE; + + return DEVICE_STATUS_SUCCESS; } @@ -171,8 +174,8 @@ 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)); - if (rc < 0) + int rc = suunto_eon_device_dump (abstract, data, sizeof (data), NULL); + if (rc != DEVICE_STATUS_SUCCESS) return rc; return suunto_eon_extract_dives (data, sizeof (data), callback, userdata); diff --git a/src/suunto_vyper.c b/src/suunto_vyper.c index 1f9e0e2..f2fca27 100644 --- a/src/suunto_vyper.c +++ b/src/suunto_vyper.c @@ -405,7 +405,7 @@ suunto_vyper_device_write (device_t *abstract, unsigned int address, const unsig device_status_t -suunto_vyper_read_dive (device_t *abstract, unsigned char data[], unsigned int size, int init, device_progress_state_t *progress) +suunto_vyper_read_dive (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result, int init, device_progress_state_t *progress) { suunto_vyper_device_t *device = (suunto_vyper_device_t*) abstract; @@ -494,7 +494,9 @@ suunto_vyper_read_dive (device_t *abstract, unsigned char data[], unsigned int s } message("\"\n"); #endif - return 0; + if (result) + *result = 0; + return DEVICE_STATUS_SUCCESS; } progress_event (progress, DEVICE_EVENT_PROGRESS, len); @@ -521,19 +523,22 @@ suunto_vyper_read_dive (device_t *abstract, unsigned char data[], unsigned int s message("\"\n"); #endif - return nbytes; + if (result) + *result = nbytes; + + return DEVICE_STATUS_SUCCESS; } device_status_t -suunto_vyper_device_read_dive (device_t *abstract, unsigned char data[], unsigned int size, int init) +suunto_vyper_device_read_dive (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result, int init) { - return suunto_vyper_read_dive (abstract, data, size, init, NULL); + return suunto_vyper_read_dive (abstract, data, size, result, init, NULL); } static device_status_t -suunto_vyper_device_dump (device_t *abstract, unsigned char data[], unsigned int size) +suunto_vyper_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result) { if (! device_is_suunto_vyper (abstract)) return DEVICE_STATUS_TYPE_MISMATCH; @@ -549,7 +554,10 @@ suunto_vyper_device_dump (device_t *abstract, unsigned char data[], unsigned int if (rc != DEVICE_STATUS_SUCCESS) return rc; - return SUUNTO_VYPER_MEMORY_SIZE; + if (result) + *result = SUUNTO_VYPER_MEMORY_SIZE; + + return DEVICE_STATUS_SUCCESS; } @@ -573,18 +581,19 @@ suunto_vyper_device_foreach (device_t *abstract, dive_callback_t callback, void int rc = 0; unsigned int ndives = 0; unsigned int offset = 0; - while ((rc = suunto_vyper_read_dive (abstract, data + offset, sizeof (data) - offset, (ndives == 0), &progress)) > 0) { - if (callback && !callback (data + offset, rc, userdata)) + unsigned int nbytes = 0; + while ((rc = suunto_vyper_read_dive (abstract, data + offset, sizeof (data) - offset, &nbytes, (ndives == 0), &progress)) == DEVICE_STATUS_SUCCESS) { + if (nbytes == 0) + return DEVICE_STATUS_SUCCESS; + + if (callback && !callback (data + offset, nbytes, userdata)) return DEVICE_STATUS_SUCCESS; ndives++; - offset += rc; + offset += nbytes; } - if (rc != 0) - return rc; - - return DEVICE_STATUS_SUCCESS; + return rc; } diff --git a/src/suunto_vyper.h b/src/suunto_vyper.h index 2538e46..883b652 100644 --- a/src/suunto_vyper.h +++ b/src/suunto_vyper.h @@ -20,7 +20,7 @@ device_status_t suunto_vyper_device_detect_interface (device_t *device); device_status_t -suunto_vyper_device_read_dive (device_t *device, unsigned char data[], unsigned int size, int init); +suunto_vyper_device_read_dive (device_t *device, unsigned char data[], unsigned int size, unsigned int *result, int init); device_status_t suunto_vyper_extract_dives (const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata); diff --git a/src/suunto_vyper2.c b/src/suunto_vyper2.c index 1b9bfef..e21bd99 100644 --- a/src/suunto_vyper2.c +++ b/src/suunto_vyper2.c @@ -352,7 +352,7 @@ suunto_vyper2_device_write (device_t *abstract, unsigned int address, const unsi static device_status_t -suunto_vyper2_device_dump (device_t *abstract, unsigned char data[], unsigned int size) +suunto_vyper2_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result) { if (! device_is_suunto_vyper2 (abstract)) return DEVICE_STATUS_TYPE_MISMATCH; @@ -368,7 +368,10 @@ suunto_vyper2_device_dump (device_t *abstract, unsigned char data[], unsigned in if (rc != DEVICE_STATUS_SUCCESS) return rc; - return SUUNTO_VYPER2_MEMORY_SIZE; + if (result) + *result = SUUNTO_VYPER2_MEMORY_SIZE; + + return DEVICE_STATUS_SUCCESS; } diff --git a/src/uwatec_aladin.c b/src/uwatec_aladin.c index 1a44ff8..f6ab5a2 100644 --- a/src/uwatec_aladin.c +++ b/src/uwatec_aladin.c @@ -138,7 +138,7 @@ uwatec_aladin_device_set_timestamp (device_t *abstract, unsigned int timestamp) static device_status_t -uwatec_aladin_device_dump (device_t *abstract, unsigned char data[], unsigned int size) +uwatec_aladin_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result) { uwatec_aladin_device_t *device = (uwatec_aladin_device_t*) abstract; @@ -197,7 +197,10 @@ uwatec_aladin_device_dump (device_t *abstract, unsigned char data[], unsigned in return DEVICE_STATUS_MEMORY; } - return UWATEC_ALADIN_MEMORY_SIZE; + if (result) + *result = UWATEC_ALADIN_MEMORY_SIZE; + + return DEVICE_STATUS_SUCCESS; } @@ -211,8 +214,8 @@ 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)); - if (rc < 0) + int rc = uwatec_aladin_device_dump (abstract, data, sizeof (data), NULL); + if (rc != DEVICE_STATUS_SUCCESS) return rc; return uwatec_aladin_extract_dives (data, sizeof (data), callback, userdata, device->timestamp); diff --git a/src/uwatec_memomouse.c b/src/uwatec_memomouse.c index 199a65e..a1cf3a5 100644 --- a/src/uwatec_memomouse.c +++ b/src/uwatec_memomouse.c @@ -158,7 +158,7 @@ uwatec_memomouse_confirm (uwatec_memomouse_device_t *device, unsigned char value static device_status_t -uwatec_memomouse_read_packet (uwatec_memomouse_device_t *device, unsigned char data[], unsigned int size) +uwatec_memomouse_read_packet (uwatec_memomouse_device_t *device, unsigned char data[], unsigned int size, unsigned int *result) { assert (size >= 126 + 2); @@ -197,16 +197,20 @@ uwatec_memomouse_read_packet (uwatec_memomouse_device_t *device, unsigned char d return DEVICE_STATUS_PROTOCOL; } - return len; + if (result) + *result = len; + + return DEVICE_STATUS_SUCCESS; } static device_status_t -uwatec_memomouse_read_packet_outer (uwatec_memomouse_device_t *device, unsigned char data[], unsigned int size) +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}; - while ((rc = uwatec_memomouse_read_packet (device, package, sizeof (package))) < 0) { + while ((rc = uwatec_memomouse_read_packet (device, package, sizeof (package), &length)) != DEVICE_STATUS_SUCCESS) { // Automatically discard a corrupted packet, // and request a new one. if (rc != DEVICE_STATUS_PROTOCOL) @@ -222,21 +226,24 @@ uwatec_memomouse_read_packet_outer (uwatec_memomouse_device_t *device, unsigned } #ifndef NDEBUG - message ("package(%i)=\"", rc); - for (unsigned int i = 0; i < rc; ++i) { + message ("package(%i)=\"", length); + for (unsigned int i = 0; i < length; ++i) { message ("%02x", package[i + 1]); } message ("\"\n"); #endif - if (size >= rc) { - memcpy (data, package + 1, rc); + if (size >= length) { + memcpy (data, package + 1, length); } else { WARNING ("Insufficient buffer space available."); return DEVICE_STATUS_MEMORY; } - return rc; + if (result) + *result = length; + + return DEVICE_STATUS_SUCCESS; } @@ -244,19 +251,20 @@ static device_status_t uwatec_memomouse_read_packet_inner (uwatec_memomouse_device_t *device, unsigned char *data[], unsigned int *size, device_progress_state_t *progress) { // Read the first package. + unsigned int length = 0; unsigned char package[126] = {0}; - int rca = uwatec_memomouse_read_packet_outer (device, package, sizeof (package)); - if (rca < 0) - return rca; + int rc = uwatec_memomouse_read_packet_outer (device, package, sizeof (package), &length); + if (rc != DEVICE_STATUS_SUCCESS) + return rc; // Accept the package. - int rcb = uwatec_memomouse_confirm (device, ACK); - if (rcb != DEVICE_STATUS_SUCCESS) - return rcb; + rc = uwatec_memomouse_confirm (device, ACK); + if (rc != DEVICE_STATUS_SUCCESS) + return rc; // Verify the first package contains at least // the size of the inner package. - if (rca < 2) { + if (length < 2) { WARNING ("First package is too small."); return DEVICE_STATUS_PROTOCOL; } @@ -265,7 +273,7 @@ uwatec_memomouse_read_packet_inner (uwatec_memomouse_device_t *device, unsigned unsigned int total = package[0] + (package[1] << 8) + 3; progress_set_maximum (progress, total); - progress_event (progress, DEVICE_EVENT_PROGRESS, rca); + progress_event (progress, DEVICE_EVENT_PROGRESS, length); // Allocate memory for the entire package. unsigned char *buffer = malloc (total * sizeof (unsigned char)); @@ -275,28 +283,28 @@ uwatec_memomouse_read_packet_inner (uwatec_memomouse_device_t *device, unsigned } // Copy the first package to the new memory buffer. - memcpy (buffer, package, rca); + memcpy (buffer, package, length); // Read the remaining packages. - unsigned int nbytes = rca; + unsigned int nbytes = length; while (nbytes < total) { // Read the package. - rca = uwatec_memomouse_read_packet_outer (device, buffer + nbytes, total - nbytes); - if (rca < 0) { + rc = uwatec_memomouse_read_packet_outer (device, buffer + nbytes, total - nbytes, &length); + if (rc != DEVICE_STATUS_SUCCESS) { free (buffer); - return rca; + return rc; } // Accept the package. - rcb = uwatec_memomouse_confirm (device, ACK); - if (rcb != DEVICE_STATUS_SUCCESS) { + rc = uwatec_memomouse_confirm (device, ACK); + if (rc != DEVICE_STATUS_SUCCESS) { free (buffer); - return rcb; + return rc; } - progress_event (progress, DEVICE_EVENT_PROGRESS, rca); + progress_event (progress, DEVICE_EVENT_PROGRESS, length); - nbytes += rca; + nbytes += length; } // Verify the checksum. @@ -403,7 +411,7 @@ uwatec_memomouse_dump (uwatec_memomouse_device_t *device, unsigned char *data[], static device_status_t -uwatec_memomouse_device_dump (device_t *abstract, unsigned char data[], unsigned int size) +uwatec_memomouse_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result) { uwatec_memomouse_device_t *device = (uwatec_memomouse_device_t*) abstract; @@ -426,7 +434,10 @@ uwatec_memomouse_device_dump (device_t *abstract, unsigned char data[], unsigned free (buffer); - return length - 3; + if (result) + *result = length - 3; + + return DEVICE_STATUS_SUCCESS; } diff --git a/src/uwatec_smart.c b/src/uwatec_smart.c index cab254a..e46046d 100644 --- a/src/uwatec_smart.c +++ b/src/uwatec_smart.c @@ -392,7 +392,7 @@ uwatec_smart_dump (uwatec_smart_device_t *device, unsigned char *data[], unsigne static device_status_t -uwatec_smart_device_dump (device_t *abstract, unsigned char data[], unsigned int size) +uwatec_smart_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result) { uwatec_smart_device_t *device = (uwatec_smart_device_t*) abstract; @@ -415,7 +415,10 @@ uwatec_smart_device_dump (device_t *abstract, unsigned char data[], unsigned int free (buffer); - return length; + if (result) + *result = length; + + return DEVICE_STATUS_SUCCESS; }