aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-19 14:09:21 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-19 15:05:12 -0800
commitddebdc09825f5eacc9b9c61b8eec98e1fdbebc1e (patch)
tree53427ac23f30f3730e2e69a085c8cf6598454a03
parenta32f3857cbcece71aeda2a12e13858233c8fffb8 (diff)
downloadsubsurface-ddebdc09825f5eacc9b9c61b8eec98e1fdbebc1e.tar.gz
Improve Uemis timeout handling
Start every step with much longer timeouts (until we get the first response back), but then use shorter timeouts once we have started receiving data. This uses up fewer of the ANS files and allows us to get more dives downloaded before the SDA has to be unplugged to reset communications, yet at the same time it still improves the overall download time. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--uemis-downloader.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/uemis-downloader.c b/uemis-downloader.c
index a4eccb7ba..90f41620d 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;
@@ -452,6 +455,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)
@@ -468,6 +478,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);
@@ -494,7 +505,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) {
@@ -542,7 +553,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;
@@ -561,6 +572,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);
}
}