Change UEMIS infrastructure to use dive sites

Which is actually much more natural to the way the UEMIS stores things...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-02-12 22:08:43 -08:00
parent 9ca600e114
commit d032c2a5c5
3 changed files with 13 additions and 19 deletions

View file

@ -638,12 +638,12 @@ static void parse_divespot(char *buf)
uemis_set_divelocation(divespot, locationstring, latitude, longitude); uemis_set_divelocation(divespot, locationstring, latitude, longitude);
} }
static void track_divespot(char *val, int diveid, char **location, degrees_t *latitude, degrees_t *longitude) static void track_divespot(char *val, int diveid, uint32_t dive_site_uuid)
{ {
int id = atoi(val); int id = atoi(val);
if (id >= 0 && id > nr_divespots) if (id >= 0 && id > nr_divespots)
nr_divespots = id; nr_divespots = id;
uemis_mark_divelocation(diveid, id, location, latitude, longitude); uemis_mark_divelocation(diveid, id, dive_site_uuid);
return; return;
} }
@ -783,7 +783,8 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, char *
if (for_dive) if (for_dive)
*for_dive = atoi(val); *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); dive->dive_site_uuid = create_dive_site("from Uemis");
track_divespot(val, dive->dc.diveid, dive->dive_site_uuid);
} else if (dive) { } else if (dive) {
parse_tag(dive, tag, val); parse_tag(dive, tag, val);
} }

23
uemis.c
View file

@ -103,9 +103,7 @@ struct uemis_helper {
int diveid; int diveid;
int lbs; int lbs;
int divespot; int divespot;
char **location; int dive_site_uuid;
degrees_t *latitude;
degrees_t *longitude;
struct uemis_helper *next; struct uemis_helper *next;
}; };
static struct uemis_helper *uemis_helper = NULL; static struct uemis_helper *uemis_helper = NULL;
@ -150,27 +148,22 @@ int uemis_get_weight_unit(int diveid)
return 0; return 0;
} }
void uemis_mark_divelocation(int diveid, int divespot, char **location, degrees_t *latitude, degrees_t *longitude) void uemis_mark_divelocation(int diveid, int divespot, uint32_t dive_site_uuid)
{ {
struct uemis_helper *hp = uemis_get_helper(diveid); struct uemis_helper *hp = uemis_get_helper(diveid);
hp->divespot = divespot; hp->divespot = divespot;
hp->location = location; hp->dive_site_uuid = dive_site_uuid;
hp->longitude = longitude;
hp->latitude = latitude;
} }
void uemis_set_divelocation(int divespot, char *text, double longitude, double latitude) void uemis_set_divelocation(int divespot, char *text, double longitude, double latitude)
{ {
struct uemis_helper *hp = uemis_helper; struct uemis_helper *hp = uemis_helper;
#if 0 /* seems overkill */
if (!g_utf8_validate(text, -1, NULL))
return;
#endif
while (hp) { while (hp) {
if (hp->divespot == divespot && hp->location) { if (hp->divespot == divespot) {
*hp->location = strdup(text); struct dive_site *ds = get_dive_site_by_uuid(hp->dive_site_uuid);
hp->longitude->udeg = round(longitude * 1000000); ds->name = strdup(text);
hp->latitude->udeg = round(latitude * 1000000); ds->longitude.udeg = round(longitude * 1000000);
ds->latitude.udeg = round(latitude * 1000000);
} }
hp = hp->next; hp = hp->next;
} }

View file

@ -14,7 +14,7 @@ extern "C" {
void uemis_parse_divelog_binary(char *base64, void *divep); void uemis_parse_divelog_binary(char *base64, void *divep);
int uemis_get_weight_unit(int diveid); int uemis_get_weight_unit(int diveid);
void uemis_mark_divelocation(int diveid, int divespot, char **location, degrees_t *latitude, degrees_t *longitude); void uemis_mark_divelocation(int diveid, int divespot, uint32_t dive_site_uuid);
void uemis_set_divelocation(int divespot, char *text, double longitude, double latitude); void uemis_set_divelocation(int divespot, char *text, double longitude, double latitude);
typedef struct typedef struct