diff options
-rw-r--r-- | display-gtk.h | 2 | ||||
-rw-r--r-- | gtk-gui.c | 19 | ||||
-rw-r--r-- | uemis-downloader.c | 84 | ||||
-rw-r--r-- | uemis.c | 12 |
4 files changed, 20 insertions, 97 deletions
diff --git a/display-gtk.h b/display-gtk.h index e1fd4f5d9..b524f5e50 100644 --- a/display-gtk.h +++ b/display-gtk.h @@ -113,7 +113,7 @@ typedef gint (*sort_func_t)(GtkTreeModel *model, extern GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title, data_func_t data_func, unsigned int flags); -GError *uemis_download(const char *path, char **divenr, char **xml_buffer, +GError *uemis_download(const char *path, char **xml_buffer, progressbar_t *progress, GtkDialog *dialog, gboolean force_download); #endif @@ -42,7 +42,6 @@ partial_pressure_graphs_t partial_pressure_graphs = { FALSE, FALSE, FALSE, 1.6, static const char *default_dive_computer_vendor; static const char *default_dive_computer_product; static const char *default_dive_computer_device; -static char *uemis_max_dive_data; static gboolean force_download; static gboolean prefer_downloaded; @@ -87,12 +86,6 @@ static void set_default_dive_computer_device(const char *name) subsurface_set_conf("dive_computer_device", PREF_STRING, name); } -static void set_uemis_last_dive(char *data) -{ - uemis_max_dive_data = data; - subsurface_set_conf("uemis_max_dive_data", PREF_STRING, data); -} - void repaint_dive(void) { update_dive(current_dive); @@ -1157,12 +1150,6 @@ void init_ui(int *argcp, char ***argvp) default_dive_computer_vendor = subsurface_get_conf("dive_computer_vendor", PREF_STRING); default_dive_computer_product = subsurface_get_conf("dive_computer_product", PREF_STRING); default_dive_computer_device = subsurface_get_conf("dive_computer_device", PREF_STRING); - conf_value = subsurface_get_conf("uemis_max_dive_data", PREF_STRING); - if (!conf_value) - uemis_max_dive_data = strdup(""); - else - uemis_max_dive_data = strdup(conf_value); - free((char *)conf_value); error_info_bar = NULL; win = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_set_application_name ("subsurface"); @@ -1662,16 +1649,12 @@ static GError *setup_uemis_import(device_data_t *data) GError *error = NULL; char *buf = NULL; - error = uemis_download(data->devname, &uemis_max_dive_data, &buf, &data->progress, data->dialog, data->force_download); + error = uemis_download(data->devname, &buf, &data->progress, data->dialog, data->force_download); if (buf && strlen(buf) > 1) { #if UEMIS_DEBUG > 3 fprintf(debugfile, "xml buffer \"%s\"\n\n", buf); #endif parse_xml_buffer("Uemis Download", buf, strlen(buf), TRUE, &error); - set_uemis_last_dive(uemis_max_dive_data); -#if UEMIS_DEBUG > 2 - fprintf(debugfile, "uemis_max_dive_data: %s\n", uemis_max_dive_data); -#endif mark_divelist_changed(TRUE); } return error; diff --git a/uemis-downloader.c b/uemis-downloader.c index ac45940b5..9577c48cc 100644 --- a/uemis-downloader.c +++ b/uemis-downloader.c @@ -44,7 +44,6 @@ static int mbuf_size = 0; struct argument_block { const char *mountpath; - char **max_dive_data; char **xml_buffer; progressbar_t *progress; gboolean force_download; @@ -720,78 +719,26 @@ static char *process_raw_buffer(char *inbuf, char **max_divenr) return strdup(conv_buffer); } -/* to keep track of multiple computers we simply encode the last dive read - in tuples "{deviceid,nr},{deviceid,nr}..." no spaces to make parsing easier */ - -static char *find_deviceid(char *max_dive_data, char *deviceid) +static char *get_divenr(char *deviceidstr) { - char *pattern; - char *result; - if (! deviceid || *deviceid == '\0') - return NULL; - pattern = malloc(3 + strlen(deviceid)); - sprintf(pattern, "{%s,", deviceid); - result = strstr(max_dive_data, pattern); - free(pattern); - return result; -} - -static char *get_divenr(char *max_dive_data, char *deviceid) -{ - char *q, *p = max_dive_data; - char *result = NULL; - - if (!p || !deviceid) - return strdup("0"); - p = find_deviceid(max_dive_data, deviceid); - if (p) { - p += strlen(deviceid) + 2; - q = strchr(p, '}'); - if (!q) - return result; - result = malloc(q - p + 1); - strncpy(result, p, q - p); - result[q - p] = '\0'; + int deviceid, i, maxdiveid = 0; + char divenr[10]; + + if (sscanf(deviceidstr, "%d", &deviceid) != 1) + return "0"; + for (i = 0; i < dive_table.nr; i++) { + struct divecomputer *dc = &dive_table.dives[i]->dc; + if (dc->deviceid == deviceid && dc->diveid > maxdiveid) + maxdiveid = dc->diveid; } - if (!result) - result = strdup("0"); - return result; -} - -static char *update_max_dive_data(char *max_dive_data, char *deviceid, char *newmax) -{ - char *p; - char *result; - int len; + snprintf(divenr, 10, "%d", maxdiveid); - if (! newmax || *newmax == '\0') - return max_dive_data; - p = find_deviceid(max_dive_data, deviceid); - if (p) { - /* if there are more entries after this one, copy them, - otherwise just remove the existing entry for this device */ - char *q = strstr(p, "},{"); - if (q) { - memcpy(p + 1, q + 3, strlen(q + 3) + 1); - } else { - if (p > max_dive_data) - *(p-1) = '\0'; - else - *p = '\0'; - } - } - /* now add the new one at the end */ - len = strlen(max_dive_data) + strlen(deviceid) + strlen(newmax) + 4 + (strlen(max_dive_data) ? 1 : 0); - result = malloc(len); - snprintf(result, len, "%s%s{%s,%s}", max_dive_data, strlen(max_dive_data) ? "," : "", deviceid, newmax); - free(max_dive_data); - return result; + return strdup(divenr); } static char *do_uemis_download(struct argument_block *args) { const char *mountpath = args->mountpath; - char **max_dive_data = args->max_dive_data; char **xml_buffer = args->xml_buffer; int xml_buffer_size; char *newmax = NULL; @@ -827,7 +774,7 @@ static char *do_uemis_download(struct argument_block *args) * the Uemis; otherwise check which was the last dive * downloaded */ if (!args->force_download && dive_table.nr > 0) - newmax = get_divenr(*max_dive_data, deviceid); + newmax = get_divenr(deviceid); else newmax = strdup("0"); @@ -862,7 +809,6 @@ static char *do_uemis_download(struct argument_block *args) if (endptr) *(endptr + 2) = '\0'; } - *args->max_dive_data = update_max_dive_data(*max_dive_data, deviceid, newmax); if (sscanf(newmax, "%d", &end) != 1) end = start; #if UEMIS_DEBUG > 1 @@ -920,12 +866,12 @@ static gboolean timeout_func(gpointer _data) return FALSE; } -GError *uemis_download(const char *mountpath, char **max_dive_data, char **xml_buffer, progressbar_t *progress, +GError *uemis_download(const char *mountpath, char **xml_buffer, progressbar_t *progress, GtkDialog *dialog, gboolean force_download) { pthread_t pthread; void *retval; - struct argument_block args = {mountpath, max_dive_data, xml_buffer, progress, force_download}; + struct argument_block args = {mountpath, xml_buffer, progress, force_download}; /* I'm sure there is some better interface for waiting on a thread in a UI main loop */ import_thread_done = 0; @@ -199,16 +199,10 @@ void uemis_parse_divelog_binary(char *base64, void *datap) { else dive->salinity = 10000; /* grams per 10l fresh water */ + /* this will allow us to find the last dive read so far from this computer */ dc->model = strdup("Uemis Zurich"); - - /* - * FIXME: - * - make the deive ID the first word of the SHA1 sum of the deviceid string - * - do we want to have a dive ID? Without one, we'll just use the dive date, - * which is likely fine. - */ - dc->deviceid = 0; - dc->diveid = 0; + dc->deviceid = *(uint32_t *)(data + 9); + dc->diveid = *(uint16_t *)(data + 7); /* dive template in use: 0 = air |