[PATCH 1/3] Cochran Commander: get_field would return bad values (xFF) when dive was incomplete.

John Van Ostrand john at vanostrand.com
Thu Feb 4 12:33:56 PST 2016


The commander parser wasn't detecting when dives were incomplete (i.e. dive end
block would be set to all 0xFF). So it returned large max depths, temps and other
fields.
---
 src/cochran_cmdr_parser.c | 36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/src/cochran_cmdr_parser.c b/src/cochran_cmdr_parser.c
index b4e8fb7..73b344f 100644
--- a/src/cochran_cmdr_parser.c
+++ b/src/cochran_cmdr_parser.c
@@ -49,22 +49,40 @@ cochran_cmdr_parser_get_field (dc_parser_t *abstract, dc_field_type_t type,
 		switch (type) {
 		case DC_FIELD_TEMPERATURE_SURFACE:
 			*((unsigned int*) value) = ((float) log[CMD_START_TEMP] - 32) / 1.8;
+			break;
 		case DC_FIELD_TEMPERATURE_MINIMUM:
-			*((unsigned int*) value) = ((float) log[CMD_MIN_TEMP] / 2
-				+ 20 - 32) / 1.8;
+			if (array_uint16_le(log + CMD_MIN_TEMP) == 0xFFFF)
+				*((double *) value) = 0;
+			else
+				*((unsigned int*) value) = ((float) log[CMD_MIN_TEMP] / 2
+					+ 20 - 32) / 1.8;
+			break;
 		case DC_FIELD_TEMPERATURE_MAXIMUM:
-			*((unsigned int*) value) = ((float) log[CMD_MAX_TEMP] / 2
-				+ 20 - 32) / 1.8;
+			if (array_uint16_le(log + CMD_MAX_TEMP) == 0xFFFF)
+				*((double *) value) = 0;
+			else
+				*((unsigned int*) value) = ((float) log[CMD_MAX_TEMP] / 2
+					+ 20 - 32) / 1.8;
+			break;
 		case DC_FIELD_DIVETIME:
-			*((unsigned int *) value) = array_uint16_le (log + CMD_BT) * 60;
+			if (array_uint16_le(log + CMD_BT) == 0xFFFF)
+				*((double *) value) = 0;
+			else
+				*((unsigned int *) value) = array_uint16_le (log + CMD_BT) * 60;
 			break;
 		case DC_FIELD_MAXDEPTH:
-			*((double *) value) = (float) array_uint16_le (log + CMD_MAX_DEPTH)
-				/ 4 * FEET;
+			if (array_uint16_le(log + CMD_MAX_DEPTH) == 0xFFFF)
+				*((double *) value) = 0;
+			else
+				*((double *) value) = (float) array_uint16_le (log
+					+ CMD_MAX_DEPTH) / 4 * FEET;
 			break;
 		case DC_FIELD_AVGDEPTH:
-			*((double *) value) = (float) array_uint16_le (log + CMD_AVG_DEPTH)
-				/ 4 * FEET;
+			if (array_uint16_le(log + CMD_AVG_DEPTH) == 0xFFFF)
+				*((double *) value) = 0;
+			else
+				*((double *) value) = (float) array_uint16_le (log 
+					+ CMD_AVG_DEPTH) / 4 * FEET;
 			break;
 		case DC_FIELD_GASMIX_COUNT:
 			*((unsigned int *) value) = 2;
-- 
2.4.3



More information about the devel mailing list