[PATCH 2/4] Cochran: Changed cochran_comander_profile_size function parameters

John Van Ostrand john at vanostrand.com
Fri Jun 30 11:12:57 PDT 2017


This function is much more useful if it works like a
ringbuffer_distance() function. It assumed the wrong values when
calculating profile size and it didn't have easy access to values
it needed to properly calculate profile sizes.

It makes sense to keep since it validates pointers.
---
 src/cochran_commander.c | 30 ++++++++----------------------
 1 file changed, 8 insertions(+), 22 deletions(-)

diff --git a/src/cochran_commander.c b/src/cochran_commander.c
index 3f084d3..247da81 100644
--- a/src/cochran_commander.c
+++ b/src/cochran_commander.c
@@ -44,11 +44,6 @@ typedef enum cochran_endian_t {
 	ENDIAN_WORD_BE,
 } cochran_endian_t;
 
-typedef enum cochran_profile_size_t {
-	PROFILE_SIZE_FULL,
-	PROFILE_SIZE_READ,
-} cochran_profile_size_t;
-
 typedef struct cochran_commander_model_t {
 	unsigned char id[3 + 1];
 	unsigned int model;
@@ -513,21 +508,8 @@ cochran_commander_guess_sample_end_address(cochran_commander_device_t *device, c
 
 
 static unsigned int
-cochran_commander_profile_size(cochran_commander_device_t *device, cochran_data_t *data, int dive_num, cochran_profile_size_t type)
+cochran_commander_profile_size(cochran_commander_device_t *device, cochran_data_t *data, int dive_num, unsigned int sample_start_address, unsigned int sample_end_address)
 {
-
-	const unsigned char *log_entry = data->logbook + dive_num * device->layout->rb_logbook_entry_size;
-	unsigned int sample_start_address = 0xFFFFFFFF;
-	unsigned int sample_end_address = array_uint32_le (log_entry + device->layout->pt_profile_end);
-
-	if (type == PROFILE_SIZE_FULL) {
-		// actual size, includes pre-dive events
-		sample_start_address = array_uint32_le (log_entry + device->layout->pt_profile_pre);
-	} else if (type == PROFILE_SIZE_READ) {
-		// read size, only include dive profile
-		sample_start_address = array_uint32_le (log_entry + device->layout->pt_profile_begin);
-	}
-
 	// Validate addresses
 	if (sample_start_address < device->layout->rb_profile_begin ||
 		sample_start_address > device->layout->rb_profile_end ||
@@ -604,8 +586,12 @@ cochran_commander_find_fingerprint(cochran_commander_device_t *device, cochran_d
 			break;
 		}
 
-		unsigned int sample_size = cochran_commander_profile_size(device, data, i, PROFILE_SIZE_FULL);
-		unsigned int read_size = cochran_commander_profile_size(device, data, i, PROFILE_SIZE_READ);
+		unsigned int profile_pre = array_uint32_le(log_entry + device->layout->pt_profile_pre);
+		unsigned int profile_begin = array_uint32_le(log_entry + device->layout->pt_profile_begin);
+		unsigned int profile_end = array_uint32_le(log_entry + device->layout->pt_profile_end);
+
+		unsigned int sample_size = cochran_commander_profile_size(device, data, i, profile_pre, profile_end);
+		unsigned int read_size = cochran_commander_profile_size(device, data, i, profile_begin, profile_end);
 
 		// Determine if sample exists
 		if (profile_capacity_remaining > 0) {
@@ -985,7 +971,7 @@ cochran_commander_device_foreach (dc_device_t *abstract, dc_dive_callback_t call
 			invalid_profile_flag = 1;
 
 		if (!invalid_profile_flag)
-			sample_size = cochran_commander_profile_size(device, &data, i, PROFILE_SIZE_READ);
+			sample_size = cochran_commander_profile_size(device, &data, i, sample_start_address, sample_end_address);
 
 		// Build dive blob
 		unsigned int dive_size = layout->rb_logbook_entry_size + sample_size;
-- 
2.4.11



More information about the devel mailing list