[PATCH 6/8] Cleaned up Cochran read functions.

John Van Ostrand john at vanostrand.com
Sun Nov 2 18:52:32 PST 2014


Moved memory address calculation outside the read functions.
---
 src/cochran_common.c | 62 ++++++++++++++++++++++++++++------------------------
 1 file changed, 33 insertions(+), 29 deletions(-)

diff --git a/src/cochran_common.c b/src/cochran_common.c
index 22630c6..4fcd751 100644
--- a/src/cochran_common.c
+++ b/src/cochran_common.c
@@ -490,15 +490,6 @@ cochran_read_logbook (dc_device_t *abstract)
 	cochran_data_t *d = &(device->data);
 	dc_status_t rc;
 
-	// Determine size of dive list to read. Round up to nearest 16K
-	if (d->dive_count_endian == COCHRAN_LE_TYPE)
-		d->dive_count = array_uint16_le (d->config[0] + d->dive_count_ptr);
-	else 
-		d->dive_count = array_uint16_be (d->config[0] + d->dive_count_ptr);
-	
-	d->logbook_size = ((d->dive_count * d->log_size) & 0xFFFFC000)
-		 + 0x4000;
-
 	if (d->logbook)
 		free(d->logbook);
 
@@ -554,15 +545,16 @@ cochran_find_fingerprint(dc_device_t *abstract)
 
 
 static void
-cochran_read_parms(dc_device_t *abstract, int *low_offset, int *high_offset)
+cochran_get_sample_parms(dc_device_t *abstract)
 {
 	cochran_device_t *device = (cochran_device_t *) abstract;
 	cochran_data_t *d = (cochran_data_t *) &(device->data);
 	unsigned int pre_dive_offset, end_dive_offset;
+	unsigned int low_offset, high_offset;
 
 	// Find lowest and highest offsets into sample data
-	*low_offset = 0xFFFFFFFF;
-	*high_offset = 0;
+	low_offset = 0xFFFFFFFF;
+	high_offset = 0;
 
 	int i;
 	for (i = d->fp_dive_num + 1; i < d->dive_count; i++) {
@@ -575,26 +567,26 @@ cochran_read_parms(dc_device_t *abstract, int *low_offset, int *high_offset)
 		if (pre_dive_offset > end_dive_offset)
 			break;
 	
-		if (pre_dive_offset < *low_offset)
-			*low_offset = pre_dive_offset;
-		if (end_dive_offset > *high_offset && end_dive_offset != 0xFFFFFFFF )
-			*high_offset = end_dive_offset;
+		if (pre_dive_offset < low_offset)
+			low_offset = pre_dive_offset;
+		if (end_dive_offset > high_offset && end_dive_offset != 0xFFFFFFFF )
+			high_offset = end_dive_offset;
 	}
 
 	if (pre_dive_offset > end_dive_offset) {
 		// Since I can't tell how much memory it has, I'll round.
 		// I'll round to 128K, dives longer than 12 hrs aren't likely
 		// and memory in sizes not rounded to 128K might be odd.
-		*high_offset = ((pre_dive_offset - 1) & 0xE0000) + 0x20000;
-		d->sample_memory_end_address = *high_offset;
-		*low_offset = d->sample_memory_start_address;
-		d->sample_data_offset = *low_offset;
-		d->sample_size = *high_offset - *low_offset;
-	} else if (*low_offset < 0xFFFFFFFF && *high_offset > 0) {
+		high_offset = ((pre_dive_offset - 1) & 0xE0000) + 0x20000;
+		d->sample_memory_end_address = high_offset;
+		low_offset = d->sample_memory_start_address;
+		d->sample_data_offset = low_offset;
+		d->sample_size = high_offset - low_offset;
+	} else if (low_offset < 0xFFFFFFFF && high_offset > 0) {
 		// Round offset and size to 16K boundary
-		d->sample_data_offset = *low_offset & 0xFFFFC000;
-		*high_offset = ((*high_offset  - 1) & 0xFFFFC000) + 0x4000;
-		d->sample_size = *high_offset - d->sample_data_offset;
+		d->sample_data_offset = low_offset & 0xFFFFC000;
+		high_offset = ((high_offset  - 1) & 0xFFFFC000) + 0x4000;
+		d->sample_size = high_offset - d->sample_data_offset;
 	} else {
 		d->sample_data_offset = 0;
 		d->sample_size = 0;
@@ -607,13 +599,9 @@ cochran_read_samples(dc_device_t *abstract)
 {
 	cochran_device_t *device = (cochran_device_t *) abstract;
 	cochran_data_t *d = (cochran_data_t *) &(device->data);
-	int low_offset, high_offset;
 	dc_status_t rc;
 
 
-	cochran_find_fingerprint(abstract);	
-	cochran_read_parms(abstract, &low_offset, &high_offset);
-
 	if (d->sample_size > 0) {
 		if (d->sample)
 			free(d->sample);
@@ -661,6 +649,9 @@ cochran_read_samples(dc_device_t *abstract)
 static dc_status_t
 cochran_common_device_read_all (dc_device_t *abstract)
 {
+	cochran_device_t *device = (cochran_device_t *) abstract;
+	cochran_data_t *d = (cochran_data_t *) &(device->data);
+
 	dc_status_t rc;
 
 	// Read config
@@ -672,10 +663,23 @@ cochran_common_device_read_all (dc_device_t *abstract)
 	if (rc != DC_STATUS_SUCCESS)
 		return rc;
 
+	// Determine size of dive list to read. Round up to nearest 16K
+	if (d->dive_count_endian == COCHRAN_LE_TYPE)
+		d->dive_count = array_uint16_le (d->config[0] + d->dive_count_ptr);
+	else 
+		d->dive_count = array_uint16_be (d->config[0] + d->dive_count_ptr);
+	
+	d->logbook_size = ((d->dive_count * d->log_size) & 0xFFFFC000)
+		 + 0x4000;
+
 	rc = cochran_read_logbook(abstract);
 	if (rc != DC_STATUS_SUCCESS)
 		return rc;
 
+	// Determine sample memory to read
+	cochran_find_fingerprint(abstract);	
+	cochran_get_sample_parms(abstract);
+
 	rc = cochran_read_samples(abstract);
 	if (rc != DC_STATUS_SUCCESS)
 		return rc;
-- 
1.8.3.1



More information about the devel mailing list