summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--gtk-gui.c6
-rw-r--r--uemis-downloader.c48
3 files changed, 45 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index 90403c4f1..ee74d4b98 100644
--- a/Makefile
+++ b/Makefile
@@ -49,7 +49,11 @@ libdc-local64 := $(wildcard /usr/local/lib64/libdivecomputer.a)
libdc-usr := $(wildcard /usr/lib/libdivecomputer.a)
libdc-usr64 := $(wildcard /usr/lib64/libdivecomputer.a)
-ifneq ($(strip $(libdc-local)),)
+ifneq ($(LIBDCDEVEL),)
+ LIBDIVECOMPUTERDIR = ../libdivecomputer
+ LIBDIVECOMPUTERINCLUDES = -I$(LIBDIVECOMPUTERDIR)/include
+ LIBDIVECOMPUTERARCHIVE = $(LIBDIVECOMPUTERDIR)/src/.libs/libdivecomputer.a
+else ifneq ($(strip $(libdc-local)),)
LIBDIVECOMPUTERDIR = /usr/local
LIBDIVECOMPUTERINCLUDES = -I$(LIBDIVECOMPUTERDIR)/include
LIBDIVECOMPUTERARCHIVE = $(LIBDIVECOMPUTERDIR)/lib/libdivecomputer.a
diff --git a/gtk-gui.c b/gtk-gui.c
index 3f7b3bf44..3e9a35f20 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -1680,14 +1680,15 @@ static GError *setup_uemis_import(device_data_t *data)
error = uemis_download(data->devname, &uemis_max_dive_data, &buf, &data->progress, data->force_download);
if (buf && strlen(buf) > 1) {
-#ifdef DEBUGFILE
+#if UEMIS_DEBUG > 3
fprintf(debugfile, "xml buffer \"%s\"\n\n", buf);
#endif
parse_xml_buffer("Uemis Download", buf, strlen(buf), &error);
set_uemis_last_dive(uemis_max_dive_data);
-#if UEMIS_DEBUG
+#if UEMIS_DEBUG > 2
fprintf(debugfile, "uemis_max_dive_data: %s\n", uemis_max_dive_data);
#endif
+ mark_divelist_changed(TRUE);
}
return error;
}
@@ -1819,6 +1820,7 @@ repeat:
*ne = '\0';
devicedata.devname = ns;
devicedata.force_download = force_download;
+ force_download = FALSE; /* when retrying we don't want to restart */
info = import_dive_computer(&devicedata, GTK_DIALOG(dialog));
free((void *)devname);
if (info)
diff --git a/uemis-downloader.c b/uemis-downloader.c
index cf70776c8..fbab3dcef 100644
--- a/uemis-downloader.c
+++ b/uemis-downloader.c
@@ -30,7 +30,10 @@
#define ERR_FS_SHORT_WRITE N_("Short write to req.txt file\nIs the Uemis Zurich plugged in correctly?")
#define BUFLEN 2048
#define NUM_PARAM_BUFS 10
-#define UEMIS_TIMEOUT 100000
+#define UEMIS_TIMEOUT 50000 /* 50ms */
+#define UEMIS_LONG_TIMEOUT 500000 /* 500ms */
+#define UEMIS_MAX_TIMEOUT 2000000 /* 2s */
+
static char *param_buff[NUM_PARAM_BUFS];
static char *reqtxt_path;
static int reqtxt_file;
@@ -109,23 +112,28 @@ static gboolean uemis_init(const char *path)
/* let's check if this is indeed a Uemis DC */
reqtxt_path = g_build_filename(path, "/req.txt", NULL);
reqtxt_file = g_open(reqtxt_path, O_RDONLY, 0666);
- if (!reqtxt_file)
+ if (!reqtxt_file) {
+#if UEMIS_DEBUG
+ fprintf(debugfile, ":EE req.txt can't be opened\n");
+#endif
return FALSE;
+ }
if (bytes_available(reqtxt_file) > 5) {
char tmp[6];
read(reqtxt_file, tmp, 5);
tmp[5] = '\0';
-#if UEMIS_DEBUG > 2
+#if UEMIS_DEBUG > 1
fprintf(debugfile, "::r req.txt \"%s\"\n", tmp);
#endif
if (sscanf(tmp + 1, "%d", &filenr) != 1)
return FALSE;
}
-#if UEMIS_DEBUG > 2
else {
+ filenr = 0;
+#if UEMIS_DEBUG > 1
fprintf(debugfile, "::r req.txt skipped as there were fewer than 5 bytes\n");
- }
#endif
+ }
close (reqtxt_file);
/* It would be nice if we could simply go back to the first set of
@@ -166,7 +174,7 @@ static void trigger_response(int file, char *command, int nr, long tailpos)
snprintf(fl, 8, "%s%04d", command, nr);
#if UEMIS_DEBUG > 2
- fprintf(debugfile,"::: %s (after seeks)\n", fl);
+ fprintf(debugfile,":tr %s (after seeks)\n", fl);
#endif
lseek(file, 0, SEEK_SET);
write(file, fl, strlen(fl));
@@ -448,6 +456,13 @@ static void show_progress(char *buf)
}
}
+static void uemis_increased_timeout(int *timeout)
+{
+ if (*timeout < UEMIS_MAX_TIMEOUT)
+ *timeout += UEMIS_LONG_TIMEOUT;
+ usleep(*timeout);
+}
+
/* send a request to the dive computer and collect the answer */
static gboolean uemis_get_answer(const char *path, char *request, int n_param_in,
int n_param_out, char **error_text)
@@ -464,6 +479,7 @@ static gboolean uemis_get_answer(const char *path, char *request, int n_param_in
gboolean answer_in_mbuf = FALSE;
char *ans_path;
int ans_file;
+ int timeout = UEMIS_LONG_TIMEOUT;
reqtxt_file = g_open(reqtxt_path, O_RDWR | O_CREAT, 0666);
snprintf(sb, BUFLEN, "n%04d12345678", filenr);
@@ -490,7 +506,7 @@ static gboolean uemis_get_answer(const char *path, char *request, int n_param_in
more_files = FALSE;
}
trigger_response(reqtxt_file, "n", filenr, file_length);
- usleep(UEMIS_TIMEOUT);
+ usleep(timeout);
mbuf = NULL;
mbuf_size = 0;
while (searching || assembling_mbuf) {
@@ -503,6 +519,13 @@ static gboolean uemis_get_answer(const char *path, char *request, int n_param_in
#if UEMIS_DEBUG > 3
tmp[100]='\0';
fprintf(debugfile, "::t %s \"%s\"\n", ans_path, tmp);
+#elsif UEMIS_DEBUG > 1
+ char pbuf[4];
+ pbuf[0] = tmp[0];
+ pbuf[1] = tmp[1];
+ pbuf[2] = tmp[2];
+ pbuf[3] = 0;
+ fprintf(debugfile, "::t %s \"%s...\"\n", ans_path, pbuf);
#endif
g_free(ans_path);
if (tmp[0] == '1') {
@@ -531,7 +554,7 @@ static gboolean uemis_get_answer(const char *path, char *request, int n_param_in
}
reqtxt_file = g_open(reqtxt_path, O_RDWR | O_CREAT, 0666);
trigger_response(reqtxt_file, "r", filenr, file_length);
- usleep(UEMIS_TIMEOUT);
+ uemis_increased_timeout(&timeout);
}
if (ismulti && more_files && tmp[0] == '1') {
int size;
@@ -550,6 +573,7 @@ static gboolean uemis_get_answer(const char *path, char *request, int n_param_in
param_buff[3]++;
}
close(ans_file);
+ timeout = UEMIS_TIMEOUT;
usleep(UEMIS_TIMEOUT);
}
}
@@ -567,7 +591,7 @@ static gboolean uemis_get_answer(const char *path, char *request, int n_param_in
lseek(ans_file, 3, SEEK_CUR);
read(ans_file, buf, size - 3);
buf[size - 3] = '\0';
-#if UEMIS_DEBUG > 2
+#if UEMIS_DEBUG > 3
fprintf(debugfile, "::r %s \"%s\"\n", ans_path, buf);
#endif
}
@@ -577,7 +601,7 @@ static gboolean uemis_get_answer(const char *path, char *request, int n_param_in
} else {
ismulti = FALSE;
}
-#if UEMIS_DEBUG > 1
+#if UEMIS_DEBUG > 3
fprintf(debugfile,":r: %s\n", buf);
#endif
if (!answer_in_mbuf)
@@ -688,7 +712,7 @@ static char *process_raw_buffer(char *inbuf, char **max_divenr)
buffer_add(&conv_buffer, &conv_buffer_size, "</dive>\n");
}
free(buf);
-#if UEMIS_DEBUG > 2
+#if UEMIS_DEBUG > 3
fprintf(debugfile,"converted to \"%s\"\n", conv_buffer);
#endif
return strdup(conv_buffer);
@@ -833,7 +857,7 @@ static char *do_uemis_download(struct argument_block *args)
*args->max_dive_data = update_max_dive_data(*max_dive_data, deviceid, newmax);
if (sscanf(newmax, "%d", &end) != 1)
end = start;
-#if UEMIS_DEBUG > 2
+#if UEMIS_DEBUG > 1
fprintf(debugfile, "done: read from object_id %d to %d\n", start, end);
#endif
free(newmax);