From 23cd240da4fb19e5ab20b32f9cfb9c710d902357 Mon Sep 17 00:00:00 2001
From: glerch <guido.lerch@gmail.com>
Date: Mon, 7 Sep 2015 15:02:51 +0200
Subject: [PATCH 2/2] Using the original dive number instead of the object_id
 in Uemis - added the capturing of the dive_no tag before the object_id is
 captured - reason why is that once the varible *dive is set to the object_id
 the dive_no isn't read   during process_raw_buffer as it apprears before the
 object_id tag.

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

diff --git a/uemis-downloader.c b/uemis-downloader.c
index 8d81451..c345b98 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)

