Changed the device_dump() function to use the new memory buffer class.
Using a resizable memory buffer allows to allocate the right amount of memory inside the backend, avoiding having to know the required buffer size in advance.
This commit is contained in:
parent
69727bf855
commit
a49d2c7b36
@ -28,7 +28,6 @@ device_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
unsigned char data[MARES_NEMO_MEMORY_SIZE] = {0};
|
||||
|
||||
message ("mares_nemo_device_open\n");
|
||||
device_status_t rc = mares_nemo_device_open (&device, name);
|
||||
@ -37,11 +36,13 @@ test_dump_memory (const char* name, const char* filename)
|
||||
return rc;
|
||||
}
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
|
||||
message ("device_dump\n");
|
||||
unsigned int nbytes = 0;
|
||||
rc = device_dump (device, data, sizeof (data), &nbytes);
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
return rc;
|
||||
}
|
||||
@ -49,10 +50,12 @@ 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), nbytes, fp);
|
||||
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
|
||||
@ -28,7 +28,6 @@ device_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
unsigned char data[MARES_PUCK_MEMORY_SIZE] = {0};
|
||||
|
||||
message ("mares_puck_device_open\n");
|
||||
device_status_t rc = mares_puck_device_open (&device, name);
|
||||
@ -37,11 +36,13 @@ test_dump_memory (const char* name, const char* filename)
|
||||
return rc;
|
||||
}
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
|
||||
message ("device_dump\n");
|
||||
unsigned int nbytes = 0;
|
||||
rc = device_dump (device, data, sizeof (data), &nbytes);
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
return rc;
|
||||
}
|
||||
@ -49,10 +50,12 @@ 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), nbytes, fp);
|
||||
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
|
||||
@ -27,7 +27,6 @@
|
||||
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");
|
||||
@ -37,11 +36,13 @@ test_dump_memory (const char* name, const char* filename)
|
||||
return rc;
|
||||
}
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
|
||||
message ("device_dump\n");
|
||||
unsigned int nbytes = 0;
|
||||
rc = device_dump (device, data, sizeof (data), &nbytes);
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
return rc;
|
||||
}
|
||||
@ -49,10 +50,12 @@ 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), nbytes, fp);
|
||||
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
message ("device_foreach\n");
|
||||
rc = device_foreach (device, NULL, NULL);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
|
||||
@ -27,7 +27,6 @@
|
||||
device_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
unsigned char data[OCEANIC_VEO250_MEMORY_SIZE] = {0};
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("oceanic_veo250_device_open\n");
|
||||
@ -37,11 +36,13 @@ test_dump_memory (const char* name, const char* filename)
|
||||
return rc;
|
||||
}
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
|
||||
message ("device_dump\n");
|
||||
unsigned int nbytes = 0;
|
||||
rc = device_dump (device, data, sizeof (data), &nbytes);
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
return rc;
|
||||
}
|
||||
@ -49,10 +50,12 @@ 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), nbytes, fp);
|
||||
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
message ("device_foreach\n");
|
||||
rc = device_foreach (device, NULL, NULL);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
|
||||
@ -27,7 +27,6 @@
|
||||
device_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
unsigned char data[OCEANIC_VTPRO_MEMORY_SIZE] = {0};
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("oceanic_vtpro_device_open\n");
|
||||
@ -37,11 +36,13 @@ test_dump_memory (const char* name, const char* filename)
|
||||
return rc;
|
||||
}
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
|
||||
message ("device_dump\n");
|
||||
unsigned int nbytes = 0;
|
||||
rc = device_dump (device, data, sizeof (data), &nbytes);
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
return rc;
|
||||
}
|
||||
@ -49,10 +50,12 @@ 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), nbytes, fp);
|
||||
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
|
||||
@ -29,7 +29,6 @@ device_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
unsigned char data[REEFNET_SENSUS_MEMORY_SIZE] = {0};
|
||||
|
||||
message ("reefnet_sensus_device_open\n");
|
||||
device_status_t rc = reefnet_sensus_device_open (&device, name);
|
||||
@ -43,11 +42,13 @@ test_dump_memory (const char* name, const char* filename)
|
||||
strftime (datetime, sizeof (datetime), "%Y-%m-%dT%H:%M:%SZ", gmtime (&now));
|
||||
message ("time=%lu (%s)\n", (unsigned long)now, datetime);
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
|
||||
message ("device_dump\n");
|
||||
unsigned int nbytes = 0;
|
||||
rc = device_dump (device, data, sizeof (data), &nbytes);
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
return rc;
|
||||
}
|
||||
@ -55,10 +56,12 @@ 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), nbytes, fp);
|
||||
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
|
||||
@ -29,7 +29,6 @@ device_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
unsigned char data[REEFNET_SENSUSPRO_MEMORY_SIZE] = {0};
|
||||
|
||||
message ("reefnet_sensuspro_device_open\n");
|
||||
device_status_t rc = reefnet_sensuspro_device_open (&device, name);
|
||||
@ -43,11 +42,13 @@ test_dump_memory (const char* name, const char* filename)
|
||||
strftime (datetime, sizeof (datetime), "%Y-%m-%dT%H:%M:%SZ", gmtime (&now));
|
||||
message ("time=%lu (%s)\n", (unsigned long)now, datetime);
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
|
||||
message ("device_dump\n");
|
||||
unsigned int nbytes = 0;
|
||||
rc = device_dump (device, data, sizeof (data), &nbytes);
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
return rc;
|
||||
}
|
||||
@ -55,10 +56,12 @@ 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), nbytes, fp);
|
||||
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
|
||||
@ -65,7 +65,6 @@ 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};
|
||||
|
||||
message ("reefnet_sensusultra_device_open\n");
|
||||
device_status_t rc = reefnet_sensusultra_device_open (&device, name);
|
||||
@ -79,11 +78,13 @@ test_dump_memory_data (const char* name, const char* filename)
|
||||
strftime (datetime, sizeof (datetime), "%Y-%m-%dT%H:%M:%SZ", gmtime (&now));
|
||||
message ("time=%lu (%s)\n", (unsigned long)now, datetime);
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
|
||||
message ("device_dump\n");
|
||||
unsigned int nbytes = 0;
|
||||
rc = device_dump (device, data, sizeof (data), &nbytes);
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
return rc;
|
||||
}
|
||||
@ -91,10 +92,12 @@ 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), nbytes, fp);
|
||||
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
|
||||
@ -67,7 +67,6 @@ test_dump_sdm (const char* name)
|
||||
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");
|
||||
@ -86,11 +85,13 @@ test_dump_memory (const char* name, const char* filename)
|
||||
return rc;
|
||||
}
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
|
||||
message ("device_dump\n");
|
||||
unsigned int nbytes = 0;
|
||||
rc = device_dump (device, data, sizeof (data), &nbytes);
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
return rc;
|
||||
}
|
||||
@ -98,10 +99,12 @@ 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), nbytes, fp);
|
||||
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
|
||||
@ -28,7 +28,6 @@ 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");
|
||||
device_status_t rc = suunto_eon_device_open (&device, name);
|
||||
@ -37,11 +36,13 @@ test_dump_memory (const char* name, const char* filename)
|
||||
return rc;
|
||||
}
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
|
||||
message ("device_dump\n");
|
||||
unsigned int nbytes = 0;
|
||||
rc = device_dump (device, data, sizeof (data), &nbytes);
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
return rc;
|
||||
}
|
||||
@ -49,10 +50,12 @@ 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), nbytes, fp);
|
||||
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
|
||||
@ -7,7 +7,6 @@ device_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
unsigned char data[SUUNTO_SOLUTION_MEMORY_SIZE] = {0};
|
||||
|
||||
message ("suunto_solution_device_open\n");
|
||||
int rc = suunto_solution_device_open (&device, name);
|
||||
@ -16,11 +15,13 @@ test_dump_memory (const char* name, const char* filename)
|
||||
return rc;
|
||||
}
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
|
||||
message ("device_dump\n");
|
||||
unsigned int nbytes = 0;
|
||||
rc = device_dump (device, data, sizeof (data), &nbytes);
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
return rc;
|
||||
}
|
||||
@ -28,10 +29,12 @@ 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), nbytes, fp);
|
||||
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
|
||||
@ -67,7 +67,6 @@ test_dump_sdm (const char* name)
|
||||
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");
|
||||
@ -86,11 +85,13 @@ test_dump_memory (const char* name, const char* filename)
|
||||
return rc;
|
||||
}
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
|
||||
message ("device_dump\n");
|
||||
unsigned int nbytes = 0;
|
||||
rc = device_dump (device, data, sizeof (data), &nbytes);
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
return rc;
|
||||
}
|
||||
@ -98,10 +99,12 @@ 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), nbytes, fp);
|
||||
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
|
||||
@ -61,7 +61,6 @@ test_dump_sdm (const char* name, unsigned int delay)
|
||||
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");
|
||||
@ -73,11 +72,13 @@ test_dump_memory (const char* name, unsigned int delay, const char* filename)
|
||||
|
||||
suunto_vyper_device_set_delay (device, delay);
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
|
||||
message ("device_dump\n");
|
||||
unsigned int nbytes = 0;
|
||||
rc = device_dump (device, data, sizeof (data), &nbytes);
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
return rc;
|
||||
}
|
||||
@ -85,10 +86,12 @@ test_dump_memory (const char* name, unsigned int delay, const char* filename)
|
||||
message ("Dumping data\n");
|
||||
FILE* fp = fopen (filename, "wb");
|
||||
if (fp != NULL) {
|
||||
fwrite (data, sizeof (unsigned char), nbytes, fp);
|
||||
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
|
||||
@ -7,7 +7,6 @@ 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");
|
||||
device_status_t rc = uwatec_aladin_device_open (&device, name);
|
||||
@ -16,11 +15,13 @@ test_dump_memory (const char* name, const char* filename)
|
||||
return rc;
|
||||
}
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
|
||||
message ("device_dump\n");
|
||||
unsigned int nbytes = 0;
|
||||
rc = device_dump (device, data, sizeof (data), &nbytes);
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
return rc;
|
||||
}
|
||||
@ -28,10 +29,12 @@ 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), nbytes, fp);
|
||||
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
|
||||
@ -28,7 +28,6 @@ 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");
|
||||
device_status_t rc = uwatec_memomouse_device_open (&device, name);
|
||||
@ -37,11 +36,13 @@ test_dump_memory (const char* name, const char* filename)
|
||||
return rc;
|
||||
}
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
|
||||
message ("device_dump\n");
|
||||
unsigned int nbytes = 0;
|
||||
rc = device_dump (device, data, sizeof (data), &nbytes);
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
return rc;
|
||||
}
|
||||
@ -49,10 +50,12 @@ 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), nbytes, fp);
|
||||
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
|
||||
@ -31,17 +31,10 @@ test_dump_memory (const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
const unsigned int size = 2 * 1024 * 1024;
|
||||
unsigned char *data = (unsigned char *) malloc (size * sizeof (unsigned char));
|
||||
if (data == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
memset (data, 0, size * sizeof (unsigned char));
|
||||
|
||||
message ("uwatec_smart_device_open\n");
|
||||
device_status_t rc = uwatec_smart_device_open (&device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot open device.");
|
||||
free (data);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -50,7 +43,6 @@ test_dump_memory (const char* filename)
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Handshake failed.");
|
||||
device_close (device);
|
||||
free (data);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -60,37 +52,36 @@ test_dump_memory (const char* filename)
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot identify computer.");
|
||||
device_close (device);
|
||||
free (data);
|
||||
return rc;
|
||||
}
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
|
||||
message ("device_dump\n");
|
||||
unsigned int nbytes = 0;
|
||||
rc = device_dump (device, data, size, &nbytes);
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read data.");
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
free (data);
|
||||
return rc;
|
||||
}
|
||||
|
||||
message ("Dumping data\n");
|
||||
FILE* fp = fopen (filename, "wb");
|
||||
if (fp != NULL) {
|
||||
fwrite (data, sizeof (unsigned char), nbytes, fp);
|
||||
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
free (data);
|
||||
return rc;
|
||||
}
|
||||
|
||||
free (data);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -56,7 +56,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, unsigned int *result);
|
||||
device_status_t (*dump) (device_t *device, dc_buffer_t *buffer);
|
||||
|
||||
device_status_t (*foreach) (device_t *device, dive_callback_t callback, void *userdata);
|
||||
|
||||
|
||||
@ -113,7 +113,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, unsigned int *result)
|
||||
device_dump (device_t *device, dc_buffer_t *buffer)
|
||||
{
|
||||
if (device == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
@ -121,7 +121,7 @@ device_dump (device_t *device, unsigned char data[], unsigned int size, unsigned
|
||||
if (device->backend->dump == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
|
||||
return device->backend->dump (device, data, size, result);
|
||||
return device->backend->dump (device, buffer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -22,6 +22,8 @@
|
||||
#ifndef DEVICE_H
|
||||
#define DEVICE_H
|
||||
|
||||
#include "buffer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
@ -92,7 +94,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, unsigned int *result);
|
||||
device_status_t device_dump (device_t *device, dc_buffer_t *buffer);
|
||||
|
||||
device_status_t device_foreach (device_t *device, dive_callback_t callback, void *userdata);
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ typedef struct mares_nemo_device_t {
|
||||
} mares_nemo_device_t;
|
||||
|
||||
static device_status_t mares_nemo_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t mares_nemo_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result);
|
||||
static device_status_t mares_nemo_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t mares_nemo_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t mares_nemo_device_close (device_t *abstract);
|
||||
|
||||
@ -174,14 +174,16 @@ mares_nemo_device_set_fingerprint (device_t *abstract, const unsigned char data[
|
||||
|
||||
|
||||
static device_status_t
|
||||
mares_nemo_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result)
|
||||
mares_nemo_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
mares_nemo_device_t *device = (mares_nemo_device_t *) abstract;
|
||||
|
||||
if (! device_is_mares_nemo (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
if (size < MARES_NEMO_MEMORY_SIZE) {
|
||||
// Erase the current contents of the buffer and
|
||||
// pre-allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, MARES_NEMO_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
@ -231,15 +233,15 @@ mares_nemo_device_dump (device_t *abstract, unsigned char data[], unsigned int s
|
||||
WARNING ("Both packets are not equal.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
}
|
||||
memcpy (data + nbytes, packet, MARES_NEMO_PACKET_SIZE);
|
||||
dc_buffer_append (buffer, packet, MARES_NEMO_PACKET_SIZE);
|
||||
} else if (crc1 == ccrc1) {
|
||||
// Only the first packet has a correct checksum.
|
||||
WARNING ("Only the first packet has a correct checksum.");
|
||||
memcpy (data + nbytes, packet, MARES_NEMO_PACKET_SIZE);
|
||||
dc_buffer_append (buffer, packet, MARES_NEMO_PACKET_SIZE);
|
||||
} else if (crc2 == ccrc2) {
|
||||
// Only the second packet has a correct checksum.
|
||||
WARNING ("Only the second packet has a correct checksum.");
|
||||
memcpy (data + nbytes, packet + MARES_NEMO_PACKET_SIZE + 1, MARES_NEMO_PACKET_SIZE);
|
||||
dc_buffer_append (buffer, packet + MARES_NEMO_PACKET_SIZE + 1, MARES_NEMO_PACKET_SIZE);
|
||||
} else {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
@ -252,9 +254,6 @@ mares_nemo_device_dump (device_t *abstract, unsigned char data[], unsigned int s
|
||||
nbytes += MARES_NEMO_PACKET_SIZE;
|
||||
}
|
||||
|
||||
if (result)
|
||||
*result = MARES_NEMO_MEMORY_SIZE;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -265,13 +264,22 @@ mares_nemo_device_foreach (device_t *abstract, dive_callback_t callback, void *u
|
||||
if (! device_is_mares_nemo (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
unsigned char data[MARES_NEMO_MEMORY_SIZE] = {0};
|
||||
dc_buffer_t *buffer = dc_buffer_new (MARES_NEMO_MEMORY_SIZE);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
|
||||
device_status_t rc = mares_nemo_device_dump (abstract, data, sizeof (data), NULL);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
device_status_t rc = mares_nemo_device_dump (abstract, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return mares_nemo_extract_dives (abstract, data, sizeof (data), callback, userdata);
|
||||
rc = mares_nemo_extract_dives (abstract,
|
||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), callback, userdata);
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ typedef struct mares_puck_device_t {
|
||||
|
||||
static device_status_t mares_puck_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t mares_puck_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
static device_status_t mares_puck_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result);
|
||||
static device_status_t mares_puck_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t mares_puck_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t mares_puck_device_close (device_t *abstract);
|
||||
|
||||
@ -339,23 +339,23 @@ mares_puck_device_read (device_t *abstract, unsigned int address, unsigned char
|
||||
|
||||
|
||||
static device_status_t
|
||||
mares_puck_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result)
|
||||
mares_puck_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
if (! device_is_mares_puck (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
if (size < MARES_PUCK_MEMORY_SIZE) {
|
||||
// Erase the current contents of the buffer and
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, MARES_PUCK_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
|
||||
device_status_t rc = mares_puck_device_read (abstract, 0x00, data, MARES_PUCK_MEMORY_SIZE);
|
||||
device_status_t rc = mares_puck_device_read (abstract, 0x00,
|
||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer));
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
if (result)
|
||||
*result = MARES_PUCK_MEMORY_SIZE;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -366,13 +366,22 @@ mares_puck_device_foreach (device_t *abstract, dive_callback_t callback, void *u
|
||||
if (! device_is_mares_puck (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
unsigned char data[MARES_PUCK_MEMORY_SIZE] = {0};
|
||||
dc_buffer_t *buffer = dc_buffer_new (MARES_PUCK_MEMORY_SIZE);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
|
||||
device_status_t rc = mares_puck_device_dump (abstract, data, sizeof (data), NULL);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
device_status_t rc = mares_puck_device_dump (abstract, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return mares_puck_extract_dives (abstract, data, sizeof (data), callback, userdata);
|
||||
rc = mares_puck_extract_dives (abstract,
|
||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), callback, userdata);
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ static device_status_t oceanic_atom2_device_set_fingerprint (device_t *abstract,
|
||||
static device_status_t oceanic_atom2_device_version (device_t *abstract, unsigned char data[], unsigned int size);
|
||||
static device_status_t oceanic_atom2_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
static device_status_t oceanic_atom2_device_write (device_t *abstract, unsigned int address, const unsigned char data[], unsigned int size);
|
||||
static device_status_t oceanic_atom2_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result);
|
||||
static device_status_t oceanic_atom2_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t oceanic_atom2_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t oceanic_atom2_device_close (device_t *abstract);
|
||||
|
||||
@ -469,23 +469,23 @@ oceanic_atom2_device_write (device_t *abstract, unsigned int address, const unsi
|
||||
|
||||
|
||||
static device_status_t
|
||||
oceanic_atom2_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result)
|
||||
oceanic_atom2_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
if (! device_is_oceanic_atom2 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
if (size < OCEANIC_ATOM2_MEMORY_SIZE) {
|
||||
// Erase the current contents of the buffer and
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, OCEANIC_ATOM2_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
|
||||
device_status_t rc = oceanic_atom2_device_read (abstract, 0x00, data, OCEANIC_ATOM2_MEMORY_SIZE);
|
||||
device_status_t rc = oceanic_atom2_device_read (abstract, 0x00,
|
||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer));
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
if (result)
|
||||
*result = OCEANIC_ATOM2_MEMORY_SIZE;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ typedef struct oceanic_veo250_device_t {
|
||||
static device_status_t oceanic_veo250_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t oceanic_veo250_device_version (device_t *abstract, unsigned char data[], unsigned int size);
|
||||
static device_status_t oceanic_veo250_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
static device_status_t oceanic_veo250_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result);
|
||||
static device_status_t oceanic_veo250_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t oceanic_veo250_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t oceanic_veo250_device_close (device_t *abstract);
|
||||
|
||||
@ -445,23 +445,23 @@ oceanic_veo250_device_read (device_t *abstract, unsigned int address, unsigned c
|
||||
|
||||
|
||||
static device_status_t
|
||||
oceanic_veo250_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result)
|
||||
oceanic_veo250_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
if (! device_is_oceanic_veo250 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
if (size < OCEANIC_VEO250_MEMORY_SIZE) {
|
||||
// Erase the current contents of the buffer and
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, OCEANIC_VEO250_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
|
||||
device_status_t rc = oceanic_veo250_device_read (abstract, 0x00, data, OCEANIC_VEO250_MEMORY_SIZE);
|
||||
device_status_t rc = oceanic_veo250_device_read (abstract, 0x00,
|
||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer));
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
if (result)
|
||||
*result = OCEANIC_VEO250_MEMORY_SIZE;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -50,7 +50,7 @@ typedef struct oceanic_vtpro_device_t {
|
||||
static device_status_t oceanic_vtpro_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t oceanic_vtpro_device_version (device_t *abstract, unsigned char data[], unsigned int size);
|
||||
static device_status_t oceanic_vtpro_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
static device_status_t oceanic_vtpro_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result);
|
||||
static device_status_t oceanic_vtpro_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t oceanic_vtpro_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t oceanic_vtpro_device_close (device_t *abstract);
|
||||
|
||||
@ -521,23 +521,23 @@ oceanic_vtpro_device_read (device_t *abstract, unsigned int address, unsigned ch
|
||||
|
||||
|
||||
static device_status_t
|
||||
oceanic_vtpro_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result)
|
||||
oceanic_vtpro_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
if (! device_is_oceanic_vtpro (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
if (size < OCEANIC_VTPRO_MEMORY_SIZE) {
|
||||
// Erase the current contents of the buffer and
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, OCEANIC_VTPRO_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
|
||||
device_status_t rc = oceanic_vtpro_device_read (abstract, 0x00, data, OCEANIC_VTPRO_MEMORY_SIZE);
|
||||
device_status_t rc = oceanic_vtpro_device_read (abstract, 0x00,
|
||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer));
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
if (result)
|
||||
*result = OCEANIC_VTPRO_MEMORY_SIZE;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@ typedef struct reefnet_sensus_device_t {
|
||||
} reefnet_sensus_device_t;
|
||||
|
||||
static device_status_t reefnet_sensus_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t reefnet_sensus_device_dump (device_t *abstract, unsigned char *data, unsigned int size, unsigned int *result);
|
||||
static device_status_t reefnet_sensus_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t reefnet_sensus_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t reefnet_sensus_device_close (device_t *abstract);
|
||||
|
||||
@ -295,14 +295,16 @@ reefnet_sensus_handshake (reefnet_sensus_device_t *device)
|
||||
|
||||
|
||||
static device_status_t
|
||||
reefnet_sensus_device_dump (device_t *abstract, unsigned char *data, unsigned int size, unsigned int *result)
|
||||
reefnet_sensus_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
reefnet_sensus_device_t *device = (reefnet_sensus_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensus (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
if (size < REEFNET_SENSUS_MEMORY_SIZE) {
|
||||
// Erase the current contents of the buffer and
|
||||
// pre-allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, REEFNET_SENSUS_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
@ -364,10 +366,7 @@ reefnet_sensus_device_dump (device_t *abstract, unsigned char *data, unsigned in
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
memcpy (data, answer + 4, REEFNET_SENSUS_MEMORY_SIZE);
|
||||
|
||||
if (result)
|
||||
*result = REEFNET_SENSUS_MEMORY_SIZE;
|
||||
dc_buffer_append (buffer, answer + 4, REEFNET_SENSUS_MEMORY_SIZE);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
@ -379,13 +378,22 @@ reefnet_sensus_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
if (! device_is_reefnet_sensus (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
unsigned char data[REEFNET_SENSUS_MEMORY_SIZE] = {0};
|
||||
dc_buffer_t *buffer = dc_buffer_new (REEFNET_SENSUS_MEMORY_SIZE);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
|
||||
device_status_t rc = reefnet_sensus_device_dump (abstract, data, sizeof (data), NULL);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
device_status_t rc = reefnet_sensus_device_dump (abstract, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return reefnet_sensus_extract_dives (abstract, data, sizeof (data), callback, userdata);
|
||||
rc = reefnet_sensus_extract_dives (abstract,
|
||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), callback, userdata);
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ typedef struct reefnet_sensuspro_device_t {
|
||||
} reefnet_sensuspro_device_t;
|
||||
|
||||
static device_status_t reefnet_sensuspro_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t reefnet_sensuspro_device_dump (device_t *abstract, unsigned char *data, unsigned int size, unsigned int *result);
|
||||
static device_status_t reefnet_sensuspro_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t reefnet_sensuspro_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t reefnet_sensuspro_device_close (device_t *abstract);
|
||||
|
||||
@ -280,14 +280,16 @@ reefnet_sensuspro_send (reefnet_sensuspro_device_t *device, unsigned char comman
|
||||
|
||||
|
||||
static device_status_t
|
||||
reefnet_sensuspro_device_dump (device_t *abstract, unsigned char *data, unsigned int size, unsigned int *result)
|
||||
reefnet_sensuspro_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensuspro (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
if (size < REEFNET_SENSUSPRO_MEMORY_SIZE) {
|
||||
// Erase the current contents of the buffer and
|
||||
// pre-allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, REEFNET_SENSUSPRO_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
@ -329,10 +331,7 @@ reefnet_sensuspro_device_dump (device_t *abstract, unsigned char *data, unsigned
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
memcpy (data, answer, REEFNET_SENSUSPRO_MEMORY_SIZE);
|
||||
|
||||
if (result)
|
||||
*result = REEFNET_SENSUSPRO_MEMORY_SIZE;
|
||||
dc_buffer_append (buffer, answer, REEFNET_SENSUSPRO_MEMORY_SIZE);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
@ -344,13 +343,22 @@ reefnet_sensuspro_device_foreach (device_t *abstract, dive_callback_t callback,
|
||||
if (! device_is_reefnet_sensuspro (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
unsigned char data[REEFNET_SENSUSPRO_MEMORY_SIZE] = {0};
|
||||
dc_buffer_t *buffer = dc_buffer_new (REEFNET_SENSUSPRO_MEMORY_SIZE);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
|
||||
device_status_t rc = reefnet_sensuspro_device_dump (abstract, data, sizeof (data), NULL);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
device_status_t rc = reefnet_sensuspro_device_dump (abstract, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return reefnet_sensuspro_extract_dives (abstract, data, sizeof (data), callback, userdata);
|
||||
rc = reefnet_sensuspro_extract_dives (abstract,
|
||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), callback, userdata);
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ typedef struct reefnet_sensusultra_device_t {
|
||||
} reefnet_sensusultra_device_t;
|
||||
|
||||
static device_status_t reefnet_sensusultra_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t reefnet_sensusultra_device_dump (device_t *abstract, unsigned char *data, unsigned int size, unsigned int *result);
|
||||
static device_status_t reefnet_sensusultra_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t reefnet_sensusultra_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t reefnet_sensusultra_device_close (device_t *abstract);
|
||||
|
||||
@ -418,14 +418,16 @@ reefnet_sensusultra_send (reefnet_sensusultra_device_t *device, unsigned short c
|
||||
|
||||
|
||||
static device_status_t
|
||||
reefnet_sensusultra_device_dump (device_t *abstract, unsigned char *data, unsigned int size, unsigned int *result)
|
||||
reefnet_sensusultra_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensusultra (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
if (size < REEFNET_SENSUSULTRA_MEMORY_DATA_SIZE) {
|
||||
// Erase the current contents of the buffer and
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, REEFNET_SENSUSULTRA_MEMORY_DATA_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
@ -442,6 +444,7 @@ reefnet_sensusultra_device_dump (device_t *abstract, unsigned char *data, unsign
|
||||
|
||||
unsigned int nbytes = 0;
|
||||
unsigned int npages = 0;
|
||||
unsigned char *data = dc_buffer_get_data (buffer);
|
||||
while (nbytes < REEFNET_SENSUSULTRA_MEMORY_DATA_SIZE) {
|
||||
// Receive the packet.
|
||||
unsigned int offset = REEFNET_SENSUSULTRA_MEMORY_DATA_SIZE -
|
||||
@ -463,9 +466,6 @@ reefnet_sensusultra_device_dump (device_t *abstract, unsigned char *data, unsign
|
||||
npages++;
|
||||
}
|
||||
|
||||
if (result)
|
||||
*result = REEFNET_SENSUSULTRA_MEMORY_DATA_SIZE;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -221,9 +221,11 @@ suunto_common2_device_write (device_t *abstract, unsigned int address, const uns
|
||||
|
||||
|
||||
device_status_t
|
||||
suunto_common2_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result)
|
||||
suunto_common2_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
if (size < SZ_MEMORY) {
|
||||
// Erase the current contents of the buffer and
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, SZ_MEMORY)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
@ -233,13 +235,11 @@ suunto_common2_device_dump (device_t *abstract, unsigned char data[], unsigned i
|
||||
progress.maximum = SZ_MEMORY;
|
||||
device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress);
|
||||
|
||||
device_status_t rc = suunto_common2_read (abstract, 0x00, data, SZ_MEMORY, &progress);
|
||||
device_status_t rc = suunto_common2_read (abstract, 0x00,
|
||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), &progress);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
if (result)
|
||||
*result = SZ_MEMORY;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -54,7 +54,7 @@ device_status_t
|
||||
suunto_common2_device_write (device_t *device, unsigned int address, const unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t
|
||||
suunto_common2_device_dump (device_t *device, unsigned char data[], unsigned int size, unsigned int *result);
|
||||
suunto_common2_device_dump (device_t *device, dc_buffer_t *buffer);
|
||||
|
||||
device_status_t
|
||||
suunto_common2_device_foreach (device_t *device, dive_callback_t callback, void *userdata);
|
||||
|
||||
@ -42,7 +42,7 @@ typedef struct suunto_eon_device_t {
|
||||
} suunto_eon_device_t;
|
||||
|
||||
static device_status_t suunto_eon_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t suunto_eon_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result);
|
||||
static device_status_t suunto_eon_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t suunto_eon_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t suunto_eon_device_close (device_t *abstract);
|
||||
|
||||
@ -168,14 +168,16 @@ suunto_eon_device_set_fingerprint (device_t *abstract, const unsigned char data[
|
||||
|
||||
|
||||
static device_status_t
|
||||
suunto_eon_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result)
|
||||
suunto_eon_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
suunto_eon_device_t *device = (suunto_eon_device_t*) abstract;
|
||||
|
||||
if (! device_is_suunto_eon (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
if (size < SUUNTO_EON_MEMORY_SIZE) {
|
||||
// Erase the current contents of the buffer and
|
||||
// pre-allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, SUUNTO_EON_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
@ -213,10 +215,7 @@ suunto_eon_device_dump (device_t *abstract, unsigned char data[], unsigned int s
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
memcpy (data, answer, SUUNTO_EON_MEMORY_SIZE);
|
||||
|
||||
if (result)
|
||||
*result = SUUNTO_EON_MEMORY_SIZE;
|
||||
dc_buffer_append (buffer, answer, SUUNTO_EON_MEMORY_SIZE);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
@ -225,20 +224,30 @@ suunto_eon_device_dump (device_t *abstract, unsigned char data[], unsigned int s
|
||||
static device_status_t
|
||||
suunto_eon_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
unsigned char data[SUUNTO_EON_MEMORY_SIZE] = {0};
|
||||
dc_buffer_t *buffer = dc_buffer_new (SUUNTO_EON_MEMORY_SIZE);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
|
||||
device_status_t rc = suunto_eon_device_dump (abstract, data, sizeof (data), NULL);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
device_status_t rc = suunto_eon_device_dump (abstract, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
|
||||
// Emit a device info event.
|
||||
unsigned char *data = dc_buffer_get_data (buffer);
|
||||
device_devinfo_t devinfo;
|
||||
devinfo.model = 0;
|
||||
devinfo.firmware = 0;
|
||||
devinfo.serial = array_uint24_be (data + 244);
|
||||
device_event_emit (abstract, DEVICE_EVENT_DEVINFO, &devinfo);
|
||||
|
||||
return suunto_eon_extract_dives (abstract, data, sizeof (data), callback, userdata);
|
||||
rc = suunto_eon_extract_dives (abstract,
|
||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), callback, userdata);
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ typedef struct suunto_solution_device_t {
|
||||
struct serial *port;
|
||||
} suunto_solution_device_t;
|
||||
|
||||
static device_status_t suunto_solution_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result);
|
||||
static device_status_t suunto_solution_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t suunto_solution_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t suunto_solution_device_close (device_t *abstract);
|
||||
|
||||
@ -147,18 +147,22 @@ suunto_solution_device_close (device_t *abstract)
|
||||
|
||||
|
||||
static device_status_t
|
||||
suunto_solution_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result)
|
||||
suunto_solution_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
suunto_solution_device_t *device = (suunto_solution_device_t*) abstract;
|
||||
|
||||
if (! device_is_suunto_solution (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
if (size < SUUNTO_SOLUTION_MEMORY_SIZE) {
|
||||
// Erase the current contents of the buffer and
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, SUUNTO_SOLUTION_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
|
||||
unsigned char *data = dc_buffer_get_data (buffer);
|
||||
|
||||
// Enable progress notifications.
|
||||
device_progress_t progress = DEVICE_PROGRESS_INITIALIZER;
|
||||
progress.maximum = SUUNTO_SOLUTION_MEMORY_SIZE - 1 + 2;
|
||||
@ -242,9 +246,6 @@ suunto_solution_device_dump (device_t *abstract, unsigned char data[], unsigned
|
||||
progress.current += 1;
|
||||
device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress);
|
||||
|
||||
if (result)
|
||||
*result = SUUNTO_SOLUTION_MEMORY_SIZE;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -255,20 +256,30 @@ suunto_solution_device_foreach (device_t *abstract, dive_callback_t callback, vo
|
||||
if (! device_is_suunto_solution (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
unsigned char data[SUUNTO_SOLUTION_MEMORY_SIZE] = {0};
|
||||
dc_buffer_t *buffer = dc_buffer_new (SUUNTO_SOLUTION_MEMORY_SIZE);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
|
||||
device_status_t rc = suunto_solution_device_dump (abstract, data, sizeof (data), NULL);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
device_status_t rc = suunto_solution_device_dump (abstract, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
|
||||
// Emit a device info event.
|
||||
unsigned char *data = dc_buffer_get_data (buffer);
|
||||
device_devinfo_t devinfo;
|
||||
devinfo.model = 0;
|
||||
devinfo.firmware = 0;
|
||||
devinfo.serial = array_uint24_be (data + 0x1D);
|
||||
device_event_emit (abstract, DEVICE_EVENT_DEVINFO, &devinfo);
|
||||
|
||||
return suunto_solution_extract_dives (abstract, data, sizeof (data), callback, userdata);
|
||||
rc = suunto_solution_extract_dives (abstract,
|
||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), callback, userdata);
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ typedef struct suunto_vyper_device_t {
|
||||
static device_status_t suunto_vyper_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t suunto_vyper_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
static device_status_t suunto_vyper_device_write (device_t *abstract, unsigned int address, const unsigned char data[], unsigned int size);
|
||||
static device_status_t suunto_vyper_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result);
|
||||
static device_status_t suunto_vyper_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t suunto_vyper_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t suunto_vyper_device_close (device_t *abstract);
|
||||
|
||||
@ -530,12 +530,14 @@ suunto_vyper_device_read_dive (device_t *abstract, unsigned char data[], unsigne
|
||||
|
||||
|
||||
static device_status_t
|
||||
suunto_vyper_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result)
|
||||
suunto_vyper_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
if (! device_is_suunto_vyper (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
if (size < SUUNTO_VYPER_MEMORY_SIZE) {
|
||||
// Erase the current contents of the buffer and
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, SUUNTO_VYPER_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
@ -545,13 +547,11 @@ suunto_vyper_device_dump (device_t *abstract, unsigned char data[], unsigned int
|
||||
progress.maximum = SUUNTO_VYPER_MEMORY_SIZE;
|
||||
device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress);
|
||||
|
||||
device_status_t rc = suunto_vyper_read (abstract, 0x00, data, SUUNTO_VYPER_MEMORY_SIZE, &progress);
|
||||
device_status_t rc = suunto_vyper_read (abstract, 0x00,
|
||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), &progress);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
if (result)
|
||||
*result = SUUNTO_VYPER_MEMORY_SIZE;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -53,7 +53,7 @@ typedef struct uwatec_aladin_device_t {
|
||||
} uwatec_aladin_device_t ;
|
||||
|
||||
static device_status_t uwatec_aladin_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t uwatec_aladin_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result);
|
||||
static device_status_t uwatec_aladin_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t uwatec_aladin_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t uwatec_aladin_device_close (device_t *abstract);
|
||||
|
||||
@ -196,14 +196,16 @@ uwatec_aladin_device_set_fingerprint (device_t *abstract, const unsigned char da
|
||||
|
||||
|
||||
static device_status_t
|
||||
uwatec_aladin_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result)
|
||||
uwatec_aladin_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
uwatec_aladin_device_t *device = (uwatec_aladin_device_t*) abstract;
|
||||
|
||||
if (! device_is_uwatec_aladin (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
if (size < UWATEC_ALADIN_MEMORY_SIZE) {
|
||||
// Erase the current contents of the buffer and
|
||||
// pre-allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, UWATEC_ALADIN_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
@ -263,10 +265,7 @@ uwatec_aladin_device_dump (device_t *abstract, unsigned char data[], unsigned in
|
||||
device->systime = now;
|
||||
device->devtime = array_uint32_be (answer + HEADER + 0x7f8);
|
||||
|
||||
memcpy (data, answer, UWATEC_ALADIN_MEMORY_SIZE);
|
||||
|
||||
if (result)
|
||||
*result = UWATEC_ALADIN_MEMORY_SIZE;
|
||||
dc_buffer_append (buffer, answer, UWATEC_ALADIN_MEMORY_SIZE);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
@ -278,20 +277,30 @@ uwatec_aladin_device_foreach (device_t *abstract, dive_callback_t callback, void
|
||||
if (! device_is_uwatec_aladin (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
unsigned char data[UWATEC_ALADIN_MEMORY_SIZE] = {0};
|
||||
dc_buffer_t *buffer = dc_buffer_new (UWATEC_ALADIN_MEMORY_SIZE);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
|
||||
device_status_t rc = uwatec_aladin_device_dump (abstract, data, sizeof (data), NULL);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
device_status_t rc = uwatec_aladin_device_dump (abstract, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
|
||||
// Emit a device info event.
|
||||
unsigned char *data = dc_buffer_get_data (buffer);
|
||||
device_devinfo_t devinfo;
|
||||
devinfo.model = data[HEADER + 0x7bc];
|
||||
devinfo.firmware = 0;
|
||||
devinfo.serial = array_uint24_be (data + HEADER + 0x7ed);
|
||||
device_event_emit (abstract, DEVICE_EVENT_DEVINFO, &devinfo);
|
||||
|
||||
return uwatec_aladin_extract_dives (abstract, data, sizeof (data), callback, userdata);
|
||||
rc = uwatec_aladin_extract_dives (abstract,
|
||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), callback, userdata);
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ typedef struct uwatec_memomouse_device_t {
|
||||
} uwatec_memomouse_device_t;
|
||||
|
||||
static device_status_t uwatec_memomouse_device_set_fingerprint (device_t *device, const unsigned char data[], unsigned int size);
|
||||
static device_status_t uwatec_memomouse_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result);
|
||||
static device_status_t uwatec_memomouse_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t uwatec_memomouse_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t uwatec_memomouse_device_close (device_t *abstract);
|
||||
|
||||
@ -512,31 +512,33 @@ 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, unsigned int *result)
|
||||
uwatec_memomouse_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
uwatec_memomouse_device_t *device = (uwatec_memomouse_device_t*) abstract;
|
||||
|
||||
if (! device_is_uwatec_memomouse (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
unsigned int length = 0;
|
||||
unsigned char *buffer = NULL;
|
||||
device_status_t rc = uwatec_memomouse_dump (device, &buffer, &length);
|
||||
// Erase the current contents of the buffer.
|
||||
if (!dc_buffer_clear (buffer)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
|
||||
unsigned int len = 0;
|
||||
unsigned char *buf = NULL;
|
||||
device_status_t rc = uwatec_memomouse_dump (device, &buf, &len);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
if (size < length - 3) {
|
||||
if (!dc_buffer_append (buffer, buf + 2, len - 3)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
free (buffer);
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
|
||||
memcpy (data, buffer + 2, length - 3);
|
||||
free (buffer);
|
||||
|
||||
if (result)
|
||||
*result = length - 3;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ typedef struct uwatec_smart_device_t {
|
||||
} uwatec_smart_device_t;
|
||||
|
||||
static device_status_t uwatec_smart_device_set_fingerprint (device_t *device, const unsigned char data[], unsigned int size);
|
||||
static device_status_t uwatec_smart_device_dump (device_t *abstract, unsigned char data[], unsigned int size, unsigned int *result);
|
||||
static device_status_t uwatec_smart_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t uwatec_smart_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t uwatec_smart_device_close (device_t *abstract);
|
||||
|
||||
@ -351,8 +351,19 @@ uwatec_smart_device_version (device_t *abstract, unsigned char data[], unsigned
|
||||
|
||||
|
||||
static device_status_t
|
||||
uwatec_smart_dump (uwatec_smart_device_t *device, unsigned char *data[], unsigned int *size)
|
||||
uwatec_smart_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
uwatec_smart_device_t *device = (uwatec_smart_device_t*) abstract;
|
||||
|
||||
if (! device_is_uwatec_smart (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
// Erase the current contents of the buffer.
|
||||
if (!dc_buffer_clear (buffer)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
|
||||
// Enable progress notifications.
|
||||
device_progress_t progress = DEVICE_PROGRESS_INITIALIZER;
|
||||
device_event_emit (&device->base, DEVICE_EVENT_PROGRESS, &progress);
|
||||
@ -432,12 +443,14 @@ uwatec_smart_dump (uwatec_smart_device_t *device, unsigned char *data[], unsigne
|
||||
if (length == 0)
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
|
||||
unsigned char *package = (unsigned char *) malloc (length * sizeof (unsigned char));
|
||||
if (package == NULL) {
|
||||
WARNING ("Memory allocation error.");
|
||||
// Allocate the required amount of memory.
|
||||
if (!dc_buffer_resize (buffer, length)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
|
||||
unsigned char *data = dc_buffer_get_data (buffer);
|
||||
|
||||
// Data.
|
||||
|
||||
command[0] = 0xC4;
|
||||
@ -451,10 +464,8 @@ uwatec_smart_dump (uwatec_smart_device_t *device, unsigned char *data[], unsigne
|
||||
command[8] = 0;
|
||||
|
||||
rc = uwatec_smart_transfer (device, command, 9, answer, 4);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
free (package);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
return rc;
|
||||
}
|
||||
|
||||
unsigned int total = array_uint32_le (answer);
|
||||
message ("handshake: total=%u\n", total);
|
||||
@ -470,10 +481,9 @@ uwatec_smart_dump (uwatec_smart_device_t *device, unsigned char *data[], unsigne
|
||||
unsigned int len = length - nbytes;
|
||||
if (len > 32)
|
||||
len = 32;
|
||||
int n = irda_socket_read (device->socket, package + nbytes, len);
|
||||
int n = irda_socket_read (device->socket, data + nbytes, len);
|
||||
if (n < 0) {
|
||||
WARNING ("Failed to receive the answer.");
|
||||
free (package);
|
||||
return EXITCODE (n);
|
||||
}
|
||||
|
||||
@ -484,39 +494,6 @@ uwatec_smart_dump (uwatec_smart_device_t *device, unsigned char *data[], unsigne
|
||||
nbytes += n;
|
||||
}
|
||||
|
||||
*data = package;
|
||||
*size = length;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
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;
|
||||
|
||||
if (! device_is_uwatec_smart (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
unsigned int length = 0;
|
||||
unsigned char *buffer = NULL;
|
||||
device_status_t rc = uwatec_smart_dump (device, &buffer, &length);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
if (size < length) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
free (buffer);
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
|
||||
memcpy (data, buffer, length);
|
||||
free (buffer);
|
||||
|
||||
if (result)
|
||||
*result = length;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -524,24 +501,23 @@ uwatec_smart_device_dump (device_t *abstract, unsigned char data[], unsigned int
|
||||
static device_status_t
|
||||
uwatec_smart_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
uwatec_smart_device_t *device = (uwatec_smart_device_t*) abstract;
|
||||
|
||||
if (! device_is_uwatec_smart (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
unsigned int length = 0;
|
||||
unsigned char *buffer = NULL;
|
||||
device_status_t rc = uwatec_smart_dump (device, &buffer, &length);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
return rc;
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
|
||||
rc = uwatec_smart_extract_dives (abstract, buffer, length, callback, userdata);
|
||||
device_status_t rc = uwatec_smart_device_dump (abstract, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
free (buffer);
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
|
||||
free (buffer);
|
||||
rc = uwatec_smart_extract_dives (abstract,
|
||||
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), callback, userdata);
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user