diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2012-11-28 17:11:19 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2012-11-30 13:41:58 -0700 |
commit | 4c4dff76835a94c571f97dd0730168738501524e (patch) | |
tree | 9947139f905fb2b016b465f536483d24f5ec8b0e /uemis.c | |
parent | a79b74ed36f6a52db947ff24761a3fd331c75cdc (diff) | |
download | subsurface-4c4dff76835a94c571f97dd0730168738501524e.tar.gz |
Convert Uemis downloader to directly create dives
The initial downloader reused the XML parsing of SDA files that was
implemented early in order to support the information extracted from the
SDA with the java applet. But creating this intermediary XML file and
handing it off to the XML import function always seemed like an ugly way
to do things. This became even more obvious when adding more features to
the Uemis downloader.
This commit completely changes the downloader to instead create dives and
record them directly.
This also adds support for divespots (which are stored in a seperate
database that needs to be queried after the divelog and dive entries have
been combined - the Uemis firmware clearly was written by monkeys on
crack - oh wait: I'm trusting these same people to get the deco right?).
This commit leaves the SDA import capability in the XML parser intact.
I'll remove that later. Because of this it actually adds a few lines of
code, but the overall change will be a substantial code deletion.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'uemis.c')
-rw-r--r-- | uemis.c | 77 |
1 files changed, 76 insertions, 1 deletions
@@ -102,6 +102,79 @@ bail: return datalen; } +struct uemis_helper { + int diveid; + int lbs; + int divespot; + char **location; + double *latitude; + double *longitude; + struct uemis_helper *next; +}; +static struct uemis_helper *uemis_helper = NULL; + +static struct uemis_helper *uemis_get_helper(int diveid) +{ + struct uemis_helper **php = &uemis_helper; + struct uemis_helper *hp = *php; + + while(hp) { + if (hp->diveid == diveid) + return hp; + if (hp->next) { + hp = hp->next; + continue; + } + php = &hp->next; + break; + } + hp = *php = malloc(sizeof(struct uemis_helper)); + hp->diveid = diveid; + hp->next = NULL; + return hp; +} + +static void uemis_weight_unit(int diveid, int lbs) +{ + struct uemis_helper *hp = uemis_get_helper(diveid); + if (hp) + hp->lbs = lbs; +} + +int uemis_get_weight_unit(int diveid) +{ + struct uemis_helper *hp = uemis_helper; + while (hp) { + if (hp->diveid == diveid) + return hp->lbs; + hp = hp->next; + } + /* odd - we should have found this; default to kg */ + return 0; +} + +void uemis_mark_divelocation(int diveid, int divespot, char **location, double *longitude, double *latitude) +{ + struct uemis_helper *hp = uemis_get_helper(diveid); + hp->divespot = divespot; + hp->location = location; + hp->longitude = longitude; + hp->latitude = latitude; +} + +void uemis_set_divelocation(int divespot, char *text, double longitude, double latitude) +{ + struct uemis_helper *hp = uemis_helper; + while (hp) { + if (hp->divespot == divespot && hp->location) { + *hp->location = text; + *hp->longitude = longitude; + *hp->latitude = latitude; + } + hp = hp->next; + } +} + /* Create events from the flag bits and other data in the sample; * These bits basically represent what is displayed on screen at sample time. * Many of these 'warnings' are way hyper-active and seriously clutter the @@ -203,7 +276,9 @@ void uemis_parse_divelog_binary(char *base64, void *datap) { dc->model = strdup("Uemis Zurich"); dc->deviceid = *(uint32_t *)(data + 9); dc->diveid = *(uint16_t *)(data + 7); - + /* remember the weight units used in this dive - we may need this later when + * parsing the weight */ + uemis_weight_unit(dc->diveid, *(uint8_t *)(data + 24)); /* dive template in use: 0 = air 1 = nitrox (B) |