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>
This commit is contained in:
Dirk Hohndel 2015-04-21 20:29:20 -07:00
parent 122111402d
commit 7643d4ea7b

View file

@ -847,7 +847,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;
@ -883,7 +884,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);
@ -915,25 +916,9 @@ 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
/* if the user clicked cancel, exit gracefully */
if (import_thread_cancelled)
goto bail;
/* if we got an error or got nothing back, stop trying */
if (!success || !param_buff[3])
break;
/* finally, if the memory is getting too full, maybe we better stop, too */
if (progress_bar_fraction > 0.85) {
result = translate("gettextFromC", ERR_FS_ALMOST_FULL);
break;
}
}
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);
#endif
free(newmax);
offset = 0;
/* 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;
@ -970,6 +955,25 @@ const char *do_uemis_import(device_data_t *data)
if (!success || import_thread_cancelled)
break;
}
start = end + 1;
/* if the user clicked cancel, exit gracefully */
if (import_thread_cancelled)
goto bail;
/* if we got an error or got nothing back, stop trying */
if (!success || !param_buff[3])
break;
/* finally, if the memory is getting too full, maybe we better stop, too */
if (progress_bar_fraction > 0.85) {
result = translate("gettextFromC", ERR_FS_ALMOST_FULL);
break;
}
}
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", first, end);
#endif
free(newmax);
success = true;
for (i = 0; i <= nr_divespots; i++) {
char divespotnr[10];