diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-04-21 20:29:20 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-04-21 20:29:20 -0700 |
commit | df9f233eed58128a762cb69127d936df7d025961 (patch) | |
tree | 02dd61432202d75e2fb6290430accf70ee6c1978 /uemis-downloader.c | |
parent | 7101386cb6334c340e23994505f2afd1e9a6a264 (diff) | |
download | subsurface-df9f233eed58128a762cb69127d936df7d025961.tar.gz |
Uemis downloader: download additional dive data after every batch
This looks like a fairly big change but it mostly just moves a block of
code inside an earlier loop and adjust a few variables around it.
The completely broken and insane Uemis download protocol distributes data
across different "databases" on the dive computer. The "divelogs" are
downloaded in batches of 10 (most of the time), and with this change every
time one of those batches is downloaded we straight away get the matching
"dive" entries.
Hopefully this will avoid having the download abort (for lack of space)
before all components are loaded.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'uemis-downloader.c')
-rw-r--r-- | uemis-downloader.c | 84 |
1 files changed, 44 insertions, 40 deletions
diff --git a/uemis-downloader.c b/uemis-downloader.c index d243bdf4b..be0af2b37 100644 --- a/uemis-downloader.c +++ b/uemis-downloader.c @@ -849,7 +849,8 @@ const char *do_uemis_import(device_data_t *data) const char *mountpath = data->devname; short force_download = data->force_download; char *newmax = NULL; - int start, end = -2, i, offset; + int first, start, end = -2; + int i, offset = 0; uint32_t deviceidnr; char objectid[10]; char *deviceid = NULL; @@ -887,7 +888,7 @@ const char *do_uemis_import(device_data_t *data) newmax = uemis_get_divenr(deviceid); else newmax = strdup("0"); - start = atoi(newmax); + first = start = atoi(newmax); for (;;) { #if UEMIS_DEBUG & 4 fprintf(debugfile, "d_u_i inner loop start %d end %d newmax %s\n", start, end, newmax); @@ -919,6 +920,46 @@ const char *do_uemis_import(device_data_t *data) #if UEMIS_DEBUG & 4 fprintf(debugfile, "d_u_i after download and parse start %d end %d newmax %s progress %4.2f\n", start, end, newmax, progress_bar_fraction); #endif + /* now download the additional dive data with "getDive" for the dives + * we just downloaded - yes, this is completely insane - why isn't all of + * this downloaded in the first place??? */ + for (i = start; i <= end; i++) { + snprintf(objectid, sizeof(objectid), "%d", i + offset); + param_buff[2] = objectid; +#if UEMIS_DEBUG & 2 + fprintf(debugfile, "getDive %d, object_id %s\n", i, objectid); +#endif + /* there is no way I have found to directly get the dive information + * for dive #i as the object_id and logfilenr can be different in the + * getDive call; so we get the first one, compare the actual divenr + * with the one that we wanted, calculate the offset and try again. + * What an insane design... */ + success = uemis_get_answer(mountpath, "getDive", 3, 0, &result); + if (mbuf) { + int divenr; + (void)process_raw_buffer(data, deviceidnr, mbuf, &newmax, false, &divenr); +#if UEMIS_DEBUG & 2 + fprintf(debugfile, "got dive %d, looking for dive %d\n", divenr, i); +#endif + if (divenr != i) { + if (divenr == -1) { + offset--; + } else { + offset += i - divenr; + } +#if UEMIS_DEBUG & 2 + fprintf(debugfile, " -> trying again with offset %d\n", offset); +#endif + i = start - 1; + if (i + offset < 0) + break; + continue; + } + } + if (!success || import_thread_cancelled) + break; + } + start = end + 1; /* if the user clicked cancel, exit gracefully */ if (import_thread_cancelled) goto bail; @@ -934,46 +975,9 @@ const char *do_uemis_import(device_data_t *data) if (end == -2 && sscanf(newmax, "%d", &end) != 1) end = start; #if UEMIS_DEBUG & 2 - fprintf(debugfile, "done: read from object_id %d to %d\n", start, end); + fprintf(debugfile, "done: read from object_id %d to %d\n", first, end); #endif free(newmax); - offset = 0; - for (i = start; i <= end; i++) { - snprintf(objectid, sizeof(objectid), "%d", i + offset); - param_buff[2] = objectid; -#if UEMIS_DEBUG & 2 - fprintf(debugfile, "getDive %d, object_id %s\n", i, objectid); -#endif - /* there is no way I have found to directly get the dive information - * for dive #i as the object_id and logfilenr can be different in the - * getDive call; so we get the first one, compare the actual divenr - * with the one that we wanted, calculate the offset and try again. - * What an insane design... */ - success = uemis_get_answer(mountpath, "getDive", 3, 0, &result); - if (mbuf) { - int divenr; - (void)process_raw_buffer(data, deviceidnr, mbuf, &newmax, false, &divenr); -#if UEMIS_DEBUG & 2 - fprintf(debugfile, "got dive %d, looking for dive %d\n", divenr, i); -#endif - if (divenr != i) { - if (divenr == -1) { - offset--; - } else { - offset += i - divenr; - } -#if UEMIS_DEBUG & 2 - fprintf(debugfile, " -> trying again with offset %d\n", offset); -#endif - i = start - 1; - if (i + offset < 0) - break; - continue; - } - } - if (!success || import_thread_cancelled) - break; - } success = true; for (i = 0; i <= nr_divespots; i++) { char divespotnr[10]; |