mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Fix Uemis downloader to download all matching dive infomration
The Uemis SDA returns the data for each dive from several different databases. And oddly, the getDive data uses a different key than the getDivelog data. We have always compensated for that by looking up the correct key and applying the data to that dive, but unfortunately we didn't adjust the loop to correctly retrieve the getDive data for the dives that were downloaded. So depending on how big the offset between those two keys was we wouldn't get all of the necessary data. With this change we try one, calculate the offset and then restart the loop. Insane, but appears to be the only way to make this work. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
b18c34373f
commit
5692131a79
1 changed files with 28 additions and 8 deletions
|
@ -631,7 +631,7 @@ static void parse_tag(struct dive *dive, char *tag, char *val)
|
||||||
* index into yet another data store that we read out later. In order to
|
* index into yet another data store that we read out later. In order to
|
||||||
* correctly populate the location and gps data from that we need to remember
|
* correctly populate the location and gps data from that we need to remember
|
||||||
* the adresses of those fields for every dive that references the divespot. */
|
* the adresses of those fields for every dive that references the divespot. */
|
||||||
static void process_raw_buffer(uint32_t deviceid, char *inbuf, char **max_divenr, gboolean keep_number)
|
static void process_raw_buffer(uint32_t deviceid, char *inbuf, char **max_divenr, gboolean keep_number, int *for_dive)
|
||||||
{
|
{
|
||||||
char *buf = strdup(inbuf);
|
char *buf = strdup(inbuf);
|
||||||
char *tp, *bp, *tag, *type, *val;
|
char *tp, *bp, *tag, *type, *val;
|
||||||
|
@ -643,6 +643,8 @@ static void process_raw_buffer(uint32_t deviceid, char *inbuf, char **max_divenr
|
||||||
int s, nr_sections = 0;
|
int s, nr_sections = 0;
|
||||||
struct dive *dive = NULL;
|
struct dive *dive = NULL;
|
||||||
|
|
||||||
|
if (for_dive)
|
||||||
|
*for_dive = -1;
|
||||||
bp = buf + 1;
|
bp = buf + 1;
|
||||||
tp = next_token(&bp);
|
tp = next_token(&bp);
|
||||||
if (strcmp(tp, "divelog") == 0) {
|
if (strcmp(tp, "divelog") == 0) {
|
||||||
|
@ -697,6 +699,8 @@ static void process_raw_buffer(uint32_t deviceid, char *inbuf, char **max_divenr
|
||||||
} else if (!log && ! strcmp(tag, "logfilenr")) {
|
} else if (!log && ! strcmp(tag, "logfilenr")) {
|
||||||
/* this one tells us which dive we are adding data to */
|
/* this one tells us which dive we are adding data to */
|
||||||
dive = get_dive_by_diveid(atoi(val), deviceid);
|
dive = get_dive_by_diveid(atoi(val), deviceid);
|
||||||
|
if (for_dive)
|
||||||
|
*for_dive = atoi(val);
|
||||||
} else if (!log && dive && ! strcmp(tag, "divespot_id")) {
|
} else if (!log && dive && ! strcmp(tag, "divespot_id")) {
|
||||||
track_divespot(val, dive->dc.diveid, &dive->location, &dive->latitude, &dive->longitude);
|
track_divespot(val, dive->dc.diveid, &dive->location, &dive->latitude, &dive->longitude);
|
||||||
} else if (dive) {
|
} else if (dive) {
|
||||||
|
@ -752,7 +756,7 @@ static char *do_uemis_download(struct argument_block *args)
|
||||||
{
|
{
|
||||||
const char *mountpath = args->mountpath;
|
const char *mountpath = args->mountpath;
|
||||||
char *newmax = NULL;
|
char *newmax = NULL;
|
||||||
int start, end, i;
|
int start, end, i, offset;
|
||||||
uint32_t deviceidnr;
|
uint32_t deviceidnr;
|
||||||
char objectid[10];
|
char objectid[10];
|
||||||
char *deviceid = NULL;
|
char *deviceid = NULL;
|
||||||
|
@ -795,7 +799,7 @@ static char *do_uemis_download(struct argument_block *args)
|
||||||
success = uemis_get_answer(mountpath, "getDivelogs", 3, 0, &result);
|
success = uemis_get_answer(mountpath, "getDivelogs", 3, 0, &result);
|
||||||
/* process the buffer we have assembled */
|
/* process the buffer we have assembled */
|
||||||
if (mbuf)
|
if (mbuf)
|
||||||
process_raw_buffer(deviceidnr, mbuf, &newmax, keep_number);
|
process_raw_buffer(deviceidnr, mbuf, &newmax, keep_number, NULL);
|
||||||
if (once) {
|
if (once) {
|
||||||
char *t = first_object_id_val(mbuf);
|
char *t = first_object_id_val(mbuf);
|
||||||
if (t && atoi(t) > start)
|
if (t && atoi(t) > start)
|
||||||
|
@ -825,15 +829,31 @@ static char *do_uemis_download(struct argument_block *args)
|
||||||
fprintf(debugfile, "done: read from object_id %d to %d\n", start, end);
|
fprintf(debugfile, "done: read from object_id %d to %d\n", start, end);
|
||||||
#endif
|
#endif
|
||||||
free(newmax);
|
free(newmax);
|
||||||
for (i = start; i < end; i++) {
|
offset = 0;
|
||||||
snprintf(objectid, sizeof(objectid), "%d", i);
|
for (i = start; i <= end; i++) {
|
||||||
|
snprintf(objectid, sizeof(objectid), "%d", i + offset);
|
||||||
param_buff[2] = objectid;
|
param_buff[2] = objectid;
|
||||||
#if UEMIS_DEBUG & 2
|
#if UEMIS_DEBUG & 2
|
||||||
fprintf(debugfile, "getDive %d\n", i);
|
fprintf(debugfile, "getDive %d, object_id %s\n", i, objectid);
|
||||||
#endif
|
#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);
|
success = uemis_get_answer(mountpath, "getDive", 3, 0, &result);
|
||||||
if (mbuf)
|
if (mbuf) {
|
||||||
process_raw_buffer(deviceidnr, mbuf, &newmax, FALSE);
|
int divenr;
|
||||||
|
process_raw_buffer(deviceidnr, mbuf, &newmax, FALSE, &divenr);
|
||||||
|
if (divenr > -1 && divenr != i) {
|
||||||
|
offset = i - divenr;
|
||||||
|
#if UEMIS_DEBUG & 2
|
||||||
|
fprintf(debugfile, "got dive %d -> trying again with offset %d\n", divenr, offset);
|
||||||
|
#endif
|
||||||
|
i = start - 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!success || import_thread_cancelled)
|
if (!success || import_thread_cancelled)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue