Uemis patch 10-12

Guido Lerch guido.lerch at gmail.com
Fri Sep 11 00:12:18 PDT 2015


some code optimisation and cleanup

-- 
Best regards,
Guido
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.subsurface-divelog.org/pipermail/subsurface/attachments/20150911/947f216f/attachment.html>
-------------- next part --------------
From b487bcfa559b0435ddd1bd2b3ca43b292322a8ed Mon Sep 17 00:00:00 2001
From: glerch <guido.lerch at gmail.com>
Date: Thu, 10 Sep 2015 21:23:47 +0200
Subject: [PATCH 11/12] Uemis - cleaning up debug bits

Dirk, at some point I would like to understand the logic behind
the debug bits, so I am not messing around with them.

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

diff --git a/uemis-downloader.c b/uemis-downloader.c
index e1fb92a..cfdb9a8 100644
--- a/uemis-downloader.c
+++ b/uemis-downloader.c
@@ -1028,7 +1028,7 @@ static bool load_uemis_divespot(const char *mountpath, int divespot_id) {
 #endif
 	bool success = uemis_get_answer(mountpath, "getDivespot", 3, 0, NULL);
 	if (mbuf && success) {
-#if UEMIS_DEBUG & 2
+#if UEMIS_DEBUG & 16
 		do_dump_buffer_to_file(mbuf, "Spot", round);
 #endif
 		return parse_divespot(mbuf);
@@ -1042,7 +1042,6 @@ const char *do_uemis_import(device_data_t *data)
 	short force_download = data->force_download;
 	char *newmax = NULL;
 	int first, start, end = -2;
-	int i = 0;
 	uint32_t deviceidnr;
 	//char objectid[10];
 	char *deviceid = NULL;
@@ -1116,7 +1115,7 @@ const char *do_uemis_import(device_data_t *data)
 		success = uemis_get_answer(mountpath, "getDivelogs", 3, 0, &result);
 		uemis_mem_status = get_memory(data->download_table);
 		if (success && mbuf && uemis_mem_status != UEMIS_MEM_FULL) {
-#if UEMIS_DEBUG % 2
+#if UEMIS_DEBUG & 16
 			do_dump_buffer_to_file(mbuf, "Divelogs", round);
 #endif
 			/* process the buffer we have assembled */
@@ -1162,7 +1161,7 @@ const char *do_uemis_import(device_data_t *data)
 					snprintf(dive_to_read_buf, sizeof(dive_to_read_buf), "%d", dive_to_read);
 					param_buff[2] = dive_to_read_buf;
 					success = uemis_get_answer(mountpath, "getDive", 3, 0, &result);
-#if UEMIS_DEBUG % 2
+#if UEMIS_DEBUG & 16
 					do_dump_buffer_to_file(mbuf, "Dive", round);
 #endif
 					uemis_mem_status = get_memory(data->download_table);
-- 
1.9.5 (Apple Git-50.3)

-------------- next part --------------
From 37ce64ae860910d32c46fbd44892ccbfefbda990 Mon Sep 17 00:00:00 2001
From: glerch <guido.lerch at gmail.com>
Date: Fri, 11 Sep 2015 08:32:52 +0200
Subject: [PATCH 12/12] Uemis - code optimization

Cleaned up the code in do_uemis_import, this way it should
run a little faster as I am doing the check if the returned
divespot is valid at an earlier point

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

diff --git a/uemis-downloader.c b/uemis-downloader.c
index cfdb9a8..1808db4 100644
--- a/uemis-downloader.c
+++ b/uemis-downloader.c
@@ -1177,8 +1177,8 @@ const char *do_uemis_import(device_data_t *data)
 								/* we found the logfilenr that matches our object_id from the divelog we were looking for
 								 * we mark the search sucessfull even if the dive has been deleted. */
 								found = true;
-								process_raw_buffer(data, deviceidnr, mbuf, &newmax, false, NULL);
 								if (strstr(mbuf, "deleted{bool{true") == NULL) {
+									process_raw_buffer(data, deviceidnr, mbuf, &newmax, false, NULL);
 									/* remember the last log file number as it is very likely that subsequent dives
 									 * have the same or higher logfile number.
 									 * UEMIS unfortunately deletes dives by deleting the dive details and not the logs. */
-- 
1.9.5 (Apple Git-50.3)

-------------- next part --------------
From 4274b51be390e6bcfc1811313d16ef21a52e153a Mon Sep 17 00:00:00 2001
From: glerch <guido.lerch at gmail.com>
Date: Thu, 10 Sep 2015 20:54:03 +0200
Subject: [PATCH 10/12] Uemis - bug fix in uemis set dive location

Assuring that ds isn't NULL, had a few cases
that made SubSurface crash. Have not investigated
the root cause but it's likely that it is related to
the Uemis specific code. Nevertheless, checking ds
non NULL is certainly not a bad thing to do.

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

diff --git a/uemis.c b/uemis.c
index 0e55a8e..9b39b54 100644
--- a/uemis.c
+++ b/uemis.c
@@ -175,9 +175,11 @@ void uemis_set_divelocation(int divespot, char *text, double longitude, double l
 	while (hp) {
 		if (hp->divespot == divespot) {
 			struct dive_site *ds = get_dive_site_by_uuid(hp->dive_site_uuid);
-			ds->name = strdup(text);
-			ds->longitude.udeg = round(longitude * 1000000);
-			ds->latitude.udeg = round(latitude * 1000000);
+			if (ds) {
+				ds->name = strdup(text);
+				ds->longitude.udeg = round(longitude * 1000000);
+				ds->latitude.udeg = round(latitude * 1000000);
+			}
 		}
 		hp = hp->next;
 	}
-- 
1.9.5 (Apple Git-50.3)



More information about the subsurface mailing list