Uemis patches

Guido Lerch guido.lerch at gmail.com
Mon Sep 7 09:38:11 PDT 2015


redid three patches with the help of Dirk today ...

0001 support of the original dive numbers from the Uemis
0002 support of multiple buddies
0003 cleanup of unused code

hope those are readable as MAC seems to have an issues with the .patch
suffix.

-- 
Best regards,
Guido
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.subsurface-divelog.org/pipermail/subsurface/attachments/20150907/930525e9/attachment-0001.html>
-------------- next part --------------
From fe46d337edfed7a2ec066504da15b64e089700af Mon Sep 17 00:00:00 2001
From: glerch <guido.lerch at gmail.com>
Date: Mon, 7 Sep 2015 18:11:41 +0200
Subject: [PATCH 1/3] supporting original uemis dive numbers instead of the
 object_id

as per current design the dive_no would always be missed by the parser as the dive_no
appears before the object_id (used to identify a dive), so once the dive struct is instanciated
with the object id the dive_no tag was parsed already.
the code I added creates a copy of the inbuf and looks for the dive_no{int{ marker, extracts
the dive no from it and stores it in dive_no[10] until the object_is was parsed.

Signed-off-by: glerch <guido.lerch at gmail.com>
---
 uemis-downloader.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/uemis-downloader.c b/uemis-downloader.c
index 0cb0f9f..bccd605 100644
--- a/uemis-downloader.c
+++ b/uemis-downloader.c
@@ -792,6 +792,7 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, char *
 	char *sections[10];
 	int s, nr_sections = 0;
 	struct dive *dive = NULL;
+    char dive_no[10];
 
 #if UEMIS_DEBUG & 4
 	fprintf(debugfile, "p_r_b %s\n", inbuf);
@@ -835,6 +836,18 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, char *
 			free(buf);
 			return false;
 		}
+	/* quickhack and workaround to capture the original dive_no
+	 * i am doing this so I dont have to change the original design
+	 * but when parsing a dive we never parse the dive number because
+	 * at the time it's being read the *dive varible is not set because
+	 * the dive_no tag comes before the object_id in the uemis ans file
+	 */
+	char *dive_no_buf = strdup(inbuf);
+	char *dive_no_ptr = strstr(dive_no_buf, "dive_no{int{") + 12;
+	char *dive_no_end = strstr(dive_no_ptr, "{");
+	*dive_no_end = 0;
+	strcpy(dive_no, dive_no_ptr);
+	free(dive_no_buf);
 	}
 	while (!done) {
 		/* the valid buffer ends with a series of delimiters */
@@ -873,14 +886,11 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, char *
 #if UEMIS_DEBUG % 2
 			fprintf(debugfile, "Adding new dive from log with object_id %d.\n", atoi(val));
 #endif
-			/* glerch Sep. 2015
-			 * maybe I am missing something here but this seems wrong
-			if (keep_number)
-				dive->number = atoi(val);
-			*/
 		} else if (is_dive && strcmp(tag, "logfilenr") == 0) {
 			/* this one tells us which dive we are adding data to */
 			dive = get_dive_by_uemis_diveid(devdata, atoi(val));
+	    if (strcmp(dive_no, "0"))
+		dive->number = atoi(dive_no);
 			if (for_dive)
 				*for_dive = atoi(val);
 		} else if (!is_log && dive && !strcmp(tag, "divespot_id")) {
-- 
1.9.5 (Apple Git-50.3)

-------------- next part --------------
From e6e1d6df9d1c4c2013afcfeb8ca63640ec74aea8 Mon Sep 17 00:00:00 2001
From: glerch <guido.lerch at gmail.com>
Date: Mon, 7 Sep 2015 18:25:33 +0200
Subject: [PATCH 2/3] supporting multible buddies

changed uemis_add_string to allow a delimiter passed with the past argument,
this allows to reuse this code to append the dive equipment with a white space
but the buddies with a comma, so they show up as separated buddies.

Signed-off-by: glerch <guido.lerch at gmail.com>
---
 uemis-downloader.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/uemis-downloader.c b/uemis-downloader.c
index bccd605..074d85d 100644
--- a/uemis-downloader.c
+++ b/uemis-downloader.c
@@ -99,7 +99,7 @@ static void uemis_get_index(char *buffer, int *idx)
 }
 
 /* space separated */
-static void uemis_add_string(const char *buffer, char **text)
+static void uemis_add_string(const char *buffer, char **text, const char *delimit)
 {
 	/* do nothing if this is an empty buffer (Uemis sometimes returns a single
 	 * space for empty buffers) */
@@ -110,7 +110,7 @@ static void uemis_add_string(const char *buffer, char **text)
 	} else {
 		char *buf = malloc(strlen(buffer) + strlen(*text) + 2);
 		strcpy(buf, *text);
-		strcat(buf, " ");
+		strcat(buf, delimit);
 		strcat(buf, buffer);
 		free(*text);
 		*text = buf;
@@ -721,18 +721,18 @@ static void parse_tag(struct dive *dive, char *tag, char *val)
 	} else if (!strcmp(tag, "f32Weight")) {
 		uemis_get_weight(val, &dive->weightsystem[0], dive->dc.diveid);
 	} else if (!strcmp(tag, "notes")) {
-		uemis_add_string(val, &dive->notes);
+	uemis_add_string(val, &dive->notes , " ");
 	} else if (!strcmp(tag, "u8DiveSuit")) {
 		if (*suit[atoi(val)])
-			uemis_add_string(translate("gettextFromC", suit[atoi(val)]), &dive->suit);
+	    uemis_add_string(translate("gettextFromC", suit[atoi(val)]), &dive->suit, " ");
 	} else if (!strcmp(tag, "u8DiveSuitType")) {
 		if (*suit_type[atoi(val)])
-			uemis_add_string(translate("gettextFromC", suit_type[atoi(val)]), &dive->suit);
+	    uemis_add_string(translate("gettextFromC", suit_type[atoi(val)]), &dive->suit, " ");
 	} else if (!strcmp(tag, "u8SuitThickness")) {
 		if (*suit_thickness[atoi(val)])
-			uemis_add_string(translate("gettextFromC", suit_thickness[atoi(val)]), &dive->suit);
-	} else if (!strcmp(tag, "dive_no")) {
-		dive->number = atoi(val);
+	    uemis_add_string(translate("gettextFromC", suit_thickness[atoi(val)]), &dive->suit, " ");
+    } else if (!strcmp(tag, "nickname")) {
+      uemis_add_string(val, &dive->buddy, ",");
 	}
 }
 
-- 
1.9.5 (Apple Git-50.3)

-------------- next part --------------
From 66e46594f248aa6325607fedb19b8cd90c1a948e Mon Sep 17 00:00:00 2001
From: glerch <guido.lerch at gmail.com>
Date: Mon, 7 Sep 2015 18:28:49 +0200
Subject: [PATCH 3/3] cleanup of unused code

deleted some code not needed anymore, most likely more to follow.
those are left overs from me trying to make the Uemis import more robust

Signed-off-by: glerch <guido.lerch at gmail.com>
---
 uemis-downloader.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/uemis-downloader.c b/uemis-downloader.c
index 074d85d..7c996e6 100644
--- a/uemis-downloader.c
+++ b/uemis-downloader.c
@@ -1225,13 +1225,6 @@ const char *do_uemis_import(device_data_t *data)
 					break;
 			}
 
-			/*
-			for (int i = iStartCleanup; i < data->download_table->nr; i++)
-			if (!data->download_table->dives[i]->downloaded) {
-				uemis_delete_dive(data, data->download_table->dives[i]->dc.diveid);
-				i = (i > iStartCleanup ? i-- : i = iStartCleanup);
-			}
-			 */
 			start = end;
 
 			/* Do some memory checking here */
-- 
1.9.5 (Apple Git-50.3)



More information about the subsurface mailing list