[PATCH 2/2] OSTCTools - change management of model and dc family

Salvador Cuñat salvador.cunat at gmail.com
Sun Jul 12 11:30:06 PDT 2015


H&W introduced some changes in dc's data structures with FROG and OSTC3
families (types 0x22 and 0x23 in H&W's terms) that I didn't take into
account as we lacked of .dive files to test.

BTW I previously set the model to "0" as it was not stored in the file
but wasn't relevant for the data parsing in MK2, OSTC and OSTC2N/2C
models.

Thanks to Anton's advice we have got some OSTC3 dives to test, so this
patch takes into account the different data structures for different
families, and try to stablish a model number based on device's serial
number, as libdc does.

Signed-off-by: Salvador Cuñat <salvador.cunat at gmail.com>
---
 ostctools.c | 50 +++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 37 insertions(+), 13 deletions(-)

diff --git a/ostctools.c b/ostctools.c
index 0bb00ee..fa7cb65 100644
--- a/ostctools.c
+++ b/ostctools.c
@@ -108,20 +108,44 @@ void ostctools_import(const char *file, struct dive_table *divetable)
 	}
 
 	// Try to determine the dc family based on the header type
-	switch (buffer[2]) {
-	case 0x20:
-	case 0x21:
+	if (buffer[2] == 0x20 || buffer[2] == 0x21)
 		dc_fam = DC_FAMILY_HW_OSTC;
-		break;
-	case 0x22:
-		dc_fam = DC_FAMILY_HW_FROG;
-		break;
-	case 0x23:
-		dc_fam = DC_FAMILY_HW_OSTC3;
-		break;
-	default:
-		fprintf(stderr, "got unknown dc family %x\n", buffer[2]);
-		dc_fam = DC_FAMILY_NULL;
+	else {
+		switch (buffer[8]) {
+			case 0x22:
+				dc_fam = DC_FAMILY_HW_FROG;
+				break;
+			case 0x23:
+				dc_fam = DC_FAMILY_HW_OSTC3;
+				break;
+			default:
+				report_error(translate("gettextFromC", "Unknown DC in dive %d"), ostcdive->number);
+				free(ostcdive);
+				fclose(archive);
+				goto out;
+		}
+	}
+
+	// Try to determine the model based on serial number
+	switch (dc_fam) {
+		case DC_FAMILY_HW_OSTC:
+			if (serial > 7000)
+				model = 3; //2C
+			else if (serial > 2048)
+				model = 2; //2N
+			else if (serial > 300)
+				model = 1; //MK2
+			else
+				model = 0; //OSTC
+			break;
+		case DC_FAMILY_HW_FROG:
+			model = 0;
+			break;
+		default:
+			if (serial > 10000)
+				model = 0x12; //Sport
+			else
+				model = 0x0A; //OSTC3
 	}
 
 	// Prepare data to pass to libdivecomputer.
-- 
2.1.4



More information about the subsurface mailing list