[PATCH] Cochran: Dump changes; reads fewer config blocks

John Van Ostrand john at vanostrand.com
Sat Jan 17 10:06:42 PST 2015


It's no longer reading the two extra config blocks for Commanders.
These only ever seem to hold FFs. It cleans up some other logic.

ID, config and misc blocks are now sent to the user via vendor events.
The dump file now contains only logbook and sample memory.
---
 src/cochran_commander.c | 72 ++++++++++++++++++++++++++-----------------------
 src/cochran_commander.h |  2 +-
 2 files changed, 39 insertions(+), 35 deletions(-)

diff --git a/src/cochran_commander.c b/src/cochran_commander.c
index c9d7386..2287541 100644
--- a/src/cochran_commander.c
+++ b/src/cochran_commander.c
@@ -461,21 +461,21 @@ cochran_read_config (dc_device_t *abstract, dc_event_progress_t *progress)
 {
 	cochran_device_t *device = (cochran_device_t *) abstract;
 	cochran_data_t *data = &device->data;
+	dc_event_vendor_t vendor;
 
 	dc_status_t rc;
 	unsigned char command[2] = { 0x96, 0x00 };
 
-	if ((data->conf.model & 0xFF0000) == COCHRAN_MODEL_EMC_FAMILY)
-		data->config_count = 2;
-	else
-		data->config_count = 4;
-
 	int n;
-	for (n = 0; n < data->config_count; n++) {
+	for (n = 0; n < 2; n++) {
 		command[1] = n;
 		rc = cochran_packet(device, progress, command, 2, data->config[n], 512, 0);
 		if (rc != DC_STATUS_SUCCESS)
 			return rc;
+
+		vendor.data = data->config[n];
+		vendor.size = 512;
+		device_event_emit (abstract, DC_EVENT_VENDOR, &vendor);
 	}
 
 	return DC_STATUS_SUCCESS;
@@ -486,6 +486,8 @@ static dc_status_t
 cochran_read_misc (dc_device_t *abstract, dc_event_progress_t *progress)
 {
 	cochran_device_t *device = (cochran_device_t *) abstract;
+	dc_status_t rc;
+	dc_event_vendor_t vendor;
 
 	unsigned char command[7] = { 0x89, 0x05, 0x00, 0x00, 0x00, 0xDC, 0x05 };
 
@@ -513,7 +515,16 @@ cochran_read_misc (dc_device_t *abstract, dc_event_progress_t *progress)
 		return EXITCODE (n);
 	}
 
-	return cochran_packet(device, progress, command + 1, 6, device->data.misc, 1500, 0);
+	rc = cochran_packet(device, progress, command + 1, 6, device->data.misc, 1500, 0);
+
+	if (rc != DC_STATUS_SUCCESS)
+		return rc;
+
+	vendor.data = device->data.misc;
+	vendor.size = 1500;
+	device_event_emit (abstract, DC_EVENT_VENDOR, &vendor);
+
+	return DC_STATUS_SUCCESS;
 }
 
 
@@ -733,57 +744,50 @@ 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;
 	dc_event_progress_t progress = {0};
+	dc_event_vendor_t vendor;
 
 	dc_status_t rc;
-	int size, offset;
+	int size;
 
-	// 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;
+	// Make sure buffer is good.
+	if (!dc_buffer_clear(data)) {
+		ERROR (abstract->context, "Uninitialized buffer.");
+		return DC_STATUS_INVALIDARGS;
 	}
 
+	// Determine size for progress
+	size = 512 + 512 + 1500 + d->conf.sample_memory_end_address;
+
 	progress.current = 0;
 	progress.maximum = size;
 	device_event_emit (abstract, DC_EVENT_PROGRESS, &progress);
 
-	// Append id blocks
+	// Emit ID blocks as vendor data
 	if (d->extra_id_flag) {
-		dc_buffer_append (data, d->id0, 67);
-		dc_buffer_append (data, d->id, 67);
-		progress.current += 134;
-	} else {
-		dc_buffer_append (data, d->id, 67);
-		progress.current += 67;
+		vendor.data = d->id0;
+		vendor.size = 67;
+		device_event_emit (abstract, DC_EVENT_VENDOR, &vendor);
 	}
 
-	device_event_emit (abstract, DC_EVENT_PROGRESS, &progress);
+	vendor.data = d->id;
+	vendor.size = 67;
+	device_event_emit (abstract, DC_EVENT_VENDOR, &vendor);
 
 	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);
-	}
-
 	rc = cochran_read_misc (abstract, &progress);
 	if (rc != DC_STATUS_SUCCESS)
 		return rc;
 
-	dc_buffer_append(data, d->misc, 1500);
-
 	// Read logbook and sample memory
 
 	// Reserve space
-	offset = dc_buffer_get_size(data);
-	int rcm;
-	rcm = dc_buffer_resize(data, offset + d->conf.sample_memory_end_address);
-	if (!rcm)
+	if (!dc_buffer_resize(data, d->conf.sample_memory_end_address)) {
+		ERROR(abstract->context, "Insufficient buffer space available.");
 		return DC_STATUS_NOMEMORY;
+	}
 
 	serial_sleep(device->port, 800);
 
@@ -792,7 +796,7 @@ cochran_commander_device_dump (dc_device_t *abstract, dc_buffer_t *data)
 
 	// 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);
+			dc_buffer_get_data(data), d->conf.sample_memory_end_address);
 	if (rc != DC_STATUS_SUCCESS) {
 		ERROR (abstract->context, "Failed to read the sample data.");
 		return rc;
diff --git a/src/cochran_commander.h b/src/cochran_commander.h
index 05b49ed..57962d8 100644
--- a/src/cochran_commander.h
+++ b/src/cochran_commander.h
@@ -73,7 +73,7 @@ typedef struct cochran_config_t {
 typedef struct cochran_data_t {
 	unsigned char id0[67];
 	unsigned char id[67];
-	unsigned char config[4][512];
+	unsigned char config[2][512];
 	unsigned char misc[1500];
 	unsigned char *logbook;
 	unsigned char *sample;
-- 
1.9.3



More information about the devel mailing list