[PATCH 2/2] Modified Cochran dump to dump entire memory.

John Van Ostrand john at vanostrand.com
Thu Dec 25 15:40:12 PST 2014


Memory end address is now defined. It may not be accurate for model
which have a memory capacity disabled.
Fixed sample start address for EMC-14.

Signed-off-by: John Van Ostrand <john at vanostrand.com>
---
 src/cochran_commander.c | 148 +++++++++++++++++-------------------------------
 1 file changed, 52 insertions(+), 96 deletions(-)

diff --git a/src/cochran_commander.c b/src/cochran_commander.c
index a1be22f..c9d7386 100644
--- a/src/cochran_commander.c
+++ b/src/cochran_commander.c
@@ -349,6 +349,7 @@ cochran_commander_get_config (const unsigned char *model,
 		conf->model = COCHRAN_MODEL_EMC_20;
 		conf->log_size = 512;
 		conf->sample_memory_start_address = 0x94000;
+		conf->sample_memory_end_address = 0x1000000;	// 16MB
 		conf->dive_num_ptr = 0x56;
 		conf->dive_count_ptr = 0xD2;
 		conf->dive_count_endian = COCHRAN_LE_TYPE;
@@ -366,6 +367,7 @@ cochran_commander_get_config (const unsigned char *model,
 		conf->model = COCHRAN_MODEL_EMC_16;
 		conf->log_size = 512;
 		conf->sample_memory_start_address = 0x94000;
+		conf->sample_memory_end_address = 0x800000;	// 8MB, a guess
 		conf->dive_num_ptr = 0x56;
 		conf->dive_count_ptr = 0xD2;
 		conf->dive_count_endian = COCHRAN_LE_TYPE;
@@ -382,7 +384,8 @@ cochran_commander_get_config (const unsigned char *model,
 	{
 		conf->model = COCHRAN_MODEL_EMC_14;
 		conf->log_size = 512;
-		conf->sample_memory_start_address = 0x20000;
+		conf->sample_memory_start_address = 0x22000;
+		conf->sample_memory_end_address = 0x200000;	// 2MB, a guess
 		conf->dive_num_ptr = 0x56;
 		conf->dive_count_ptr = 0xD2;
 		conf->dive_count_endian = COCHRAN_LE_TYPE;
@@ -400,6 +403,7 @@ cochran_commander_get_config (const unsigned char *model,
 		conf->model = COCHRAN_MODEL_COMMANDER_AIR_NITROX;
 		conf->log_size = 256;
 		conf->sample_memory_start_address = 0x20000;
+		conf->sample_memory_end_address = 0x100000;
 		conf->dive_num_ptr = 0x46;
 		conf->dive_count_ptr = 0x46;
 		conf->dive_count_endian = COCHRAN_BE_TYPE;
@@ -435,6 +439,7 @@ cochran_read_id (dc_device_t *abstract)
 	if (strncmp((const char *)device->data.id, "(C)", 3) != 0) {
 		// It's a Commander, read again
 		memcpy(device->data.id0, device->data.id, 67);
+		device->data.extra_id_flag = 1;
 
 		command[1] = 0xBD;
 		command[2] = 0x7F;
@@ -727,120 +732,71 @@ cochran_commander_device_dump (dc_device_t *abstract, dc_buffer_t *data)
 {
 	cochran_device_t *device = (cochran_device_t *) abstract;
 	cochran_data_t *d = (cochran_data_t *) &device->data;
-	int ptr = 0;
+	dc_event_progress_t progress = {0};
 
 	dc_status_t rc;
-	unsigned char *b;
-	int size;
+	int size, offset;
 
-	rc = cochran_commander_device_read_all (abstract);
-
-	if (rc != DC_STATUS_SUCCESS)
-		return rc;
+	// Determine size for progress
+	if (d->extra_id_flag) {
+		// two ID blocks, 4 config block, misc block
+		size = 67 + 67 + 512 + 512 + 512 + 512 + 1500 + d->conf.sample_memory_end_address;
+	} else {
+		// one ID blocks, 2 config block, misc block
+		size = 67 + 512 + 512 + 1500 + d->conf.sample_memory_end_address;
+	}
 
-	// Reserve space for block pointers
-	// Structure is:
-	// 		int ptr;
-	//		char data_valid_flag;
-	dc_buffer_resize(data, 10 * 5);
-	
-	// Set pointer to first block
-	size = dc_buffer_get_size(data);
-	pack_uint32_array_le(dc_buffer_get_data(data) + ptr, size);
+	progress.current = 0;
+	progress.maximum = size;
+	device_event_emit (abstract, DC_EVENT_PROGRESS, &progress);
 
+	// Append id blocks
 	if (d->extra_id_flag) {
-		dc_buffer_append(data, d->id0, 67);
-		*(dc_buffer_get_data(data) + ptr + 4) = 1;
+		dc_buffer_append (data, d->id0, 67);
+		dc_buffer_append (data, d->id, 67);
+		progress.current += 134;
 	} else {
-		dc_buffer_resize(data, size + 67);
-		b = dc_buffer_get_data(data);
-
-		memset(b + size, 0, 67);
+		dc_buffer_append (data, d->id, 67);
+		progress.current += 67;
 	}
-	
-	// Set pointer to next block
-	ptr += 5;
-	size = dc_buffer_get_size(data);
-	pack_uint32_array_le(dc_buffer_get_data(data) + ptr, size);
 
-	dc_buffer_append (data, d->id, 67);
-	*(dc_buffer_get_data(data) + ptr + 4) = 1;
-	
-	// Add config blocks
-	int n;
-	for (n = 0; n < d->config_count; n++) {
-		// Set pointer to next block
-		ptr += 5;
-		size = dc_buffer_get_size(data);
-		pack_uint32_array_le(dc_buffer_get_data(data) + ptr, size);
+	device_event_emit (abstract, DC_EVENT_PROGRESS, &progress);
 
+	rc = cochran_read_config (abstract, &progress);
+	if (rc != DC_STATUS_SUCCESS)
+		return rc;
+	
+	for (int n = 0; n < d->config_count; n++) {
 		dc_buffer_append (data, d->config[n], 512);
-
-		*(dc_buffer_get_data(data) + ptr + 4) = 1;
 	}
 
-	// Add blank config blocks
-	for (n = d->config_count; n < 4; n++) {
-		// Set pointer to next block
-		ptr += 5;
-		size = dc_buffer_get_size(data);
-		pack_uint32_array_le(dc_buffer_get_data(data) + ptr, size);
+	rc = cochran_read_misc (abstract, &progress);
+	if (rc != DC_STATUS_SUCCESS)
+		return rc;
 
-		dc_buffer_resize(data, size + 512);
+	dc_buffer_append(data, d->misc, 1500);
 
-		b = dc_buffer_get_data(data);
-		memset(b + size, 0, 512);
-	}
-	
-	// Set pointer to next block
-	ptr += 5;
-	size = dc_buffer_get_size(data);
-	pack_uint32_array_le(dc_buffer_get_data(data) + ptr, size);
-
-	if (d->misc) {
-		dc_buffer_append (data, d->misc, 1500);
-		*(dc_buffer_get_data(data) + ptr + 4) = 1;
-	} else {
-		dc_buffer_resize(data, size + 1500);
+	// Read logbook and sample memory
 
-		b = dc_buffer_get_data(data);
-		memset(b + size, 0, 1500);
-	}
-	
-	// Set pointer to next block
-	ptr += 5;
-	size = dc_buffer_get_size(data);
-	pack_uint32_array_le(dc_buffer_get_data(data) + ptr, size);
-
-	if (d->logbook) {
-		dc_buffer_append (data, d->logbook, d->logbook_size);
-		*(dc_buffer_get_data(data) + ptr + 4) = 1;
-	} else {
-		dc_buffer_resize(data, size + d->logbook_size);
+	// Reserve space
+	offset = dc_buffer_get_size(data);
+	int rcm;
+	rcm = dc_buffer_resize(data, offset + d->conf.sample_memory_end_address);
+	if (!rcm)
+		return DC_STATUS_NOMEMORY;
 
-		b = dc_buffer_get_data(data);
-		memset(b + size, 0, d->logbook_size);
-	}
-	
-	// Set pointer to next block
-	ptr += 5;
-	size = dc_buffer_get_size(data);
-	pack_uint32_array_le(dc_buffer_get_data(data) + ptr, size);
-
-	if (d->sample) {
-		dc_buffer_append (data, d->sample, d->sample_size);
-		*(dc_buffer_get_data(data) + ptr + 4) = 1;
-	} else {
-		dc_buffer_resize(data, dc_buffer_get_size(data) + d->sample_size);
+	serial_sleep(device->port, 800);
 
-		b = dc_buffer_get_data(data);
-		memset(b + size, 0, d->logbook_size);
-	}
+	// set back to 9600 baud
+	cochran_commander_serial_setup(device, abstract->context);
 
-	// Set pointer to end
-	ptr += 5;
-	size = dc_buffer_get_size(data);
-	pack_uint32_array_le(dc_buffer_get_data(data) + ptr, size);
+	// Read the sample data, from 0 to sample end will include logbook
+	rc = cochran_commander_read (abstract, &progress, 0, 
+			dc_buffer_get_data(data) + offset, d->conf.sample_memory_end_address);
+	if (rc != DC_STATUS_SUCCESS) {
+		ERROR (abstract->context, "Failed to read the sample data.");
+		return rc;
+	}
 
 	return DC_STATUS_SUCCESS;
 }
-- 
1.9.3



More information about the devel mailing list