diff options
author | Anton Lundin <glance@acc.umu.se> | 2015-09-03 22:25:00 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-09-08 12:30:17 -0700 |
commit | 647645d6e458b1ab510fe72a897676f1f1cc0291 (patch) | |
tree | 4e0f1578c45bad13a5525823a2f0bac227412b9a | |
parent | cb1aac0c4d9c08f21c97698ce833af00f325f4a8 (diff) | |
download | subsurface-647645d6e458b1ab510fe72a897676f1f1cc0291.tar.gz |
Better import of libdivecomputer universal xml
This teaches subsurface how to understand more fields in the xml that
libdivecomputers's universal tool generates.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | parse-xml.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/parse-xml.c b/parse-xml.c index 6f8c5f0c2..be5215509 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -153,7 +153,7 @@ static bool in_userid = false; static struct tm cur_tm; static int cur_cylinder_index, cur_ws_index; static int lastndl, laststoptime, laststopdepth, lastcns, lastpo2, lastindeco; -static int lastcylinderindex, lastsensor; +static int lastcylinderindex, lastsensor, next_o2_sensor; static struct extra_data cur_extra_data; /* @@ -571,6 +571,9 @@ static void event_name(char *buffer, char *name) name[size] = 0; } +// We don't use gauge as a mode, and pscr doesn't exist as a libdc divemode +const char *libdc_divemode_text[] = { "oc", "cc", "pscr", "freedive", "gauge"}; + /* Extract the dive computer type from the xml text buffer */ static void get_dc_type(char *buffer, enum dive_comp_type *dct) { @@ -578,6 +581,8 @@ static void get_dc_type(char *buffer, enum dive_comp_type *dct) for (enum dive_comp_type i = 0; i < NUM_DC_TYPE; i++) { if (strcmp(buffer, divemode_text[i]) == 0) *dct = i; + else if (strcmp(buffer, libdc_divemode_text[i]) == 0) + *dct = i; } } } @@ -788,6 +793,18 @@ static void get_sensor(char *buffer, uint8_t *i) lastsensor = *i; } +static void parse_libdc_deco(char *buffer, struct sample *s) +{ + if (strcmp(buffer, "deco") == 0) { + s->in_deco = true; + } else if (strcmp(buffer, "ndl") == 0) { + s->in_deco = false; + // The time wasn't stoptime, it was ndl + s->ndl = s->stoptime; + s->stoptime.seconds = 0; + } +} + static void try_to_fill_dc_settings(const char *name, char *buf) { start_match("divecomputerid", name, buf); @@ -866,6 +883,12 @@ static int match_dc_data_fields(struct divecomputer *dc, const char *name, char return 1; if (MATCH("value.extradata", utf8_string, &cur_extra_data.value)) return 1; + if (MATCH("divemode", get_dc_type, &dc->divemode)) + return 1; + if (MATCH("salinity", salinity, &dc->salinity)) + return 1; + if (MATCH("atmospheric", pressure, &dc->surface_pressure)) + return 1; return 0; } @@ -950,6 +973,18 @@ static void try_to_fill_sample(struct sample *sample, const char *name, char *bu return; if (MATCH("bearing", get_bearing, &sample->bearing)) return; + if (MATCH("setpoint.sample", double_to_o2pressure, &sample->setpoint)) + return; + if (MATCH("ppo2.sample", double_to_o2pressure, &sample->o2sensor[next_o2_sensor])) { + next_o2_sensor++; + return; + } + if (MATCH("deco.sample", parse_libdc_deco, sample)) + return; + if (MATCH("time.deco", sampletime, &sample->stoptime)) + return; + if (MATCH("depth.deco", depth, &sample->stopdepth)) + return; switch (import_source) { case DIVINGLOG: @@ -1666,6 +1701,7 @@ static void sample_start(void) cur_sample->cns = lastcns; cur_sample->setpoint.mbar = lastpo2; cur_sample->sensor = lastsensor; + next_o2_sensor = 0; } static void sample_end(void) |