diff options
Diffstat (limited to 'core/save-xml.c')
-rw-r--r-- | core/save-xml.c | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/core/save-xml.c b/core/save-xml.c index 73a00f54a..19b4e79b7 100644 --- a/core/save-xml.c +++ b/core/save-xml.c @@ -192,24 +192,45 @@ static void show_index(struct membuffer *b, int value, const char *pre, const ch show_integer(b, value, pre, post); } -static void save_sample(struct membuffer *b, struct sample *sample, struct sample *old) +static void save_sample(struct membuffer *b, struct sample *sample, struct sample *old, int o2sensor) { + int idx; + put_format(b, " <sample time='%u:%02u min'", FRACTION(sample->time.seconds, 60)); put_milli(b, " depth='", sample->depth.mm, " m'"); if (sample->temperature.mkelvin && sample->temperature.mkelvin != old->temperature.mkelvin) { put_temperature(b, sample->temperature, " temp='", " C'"); old->temperature = sample->temperature; } - put_pressure(b, sample->pressure[0], " pressure='", " bar'"); - put_pressure(b, sample->pressure[1], " o2pressure='", " bar'"); /* * We only show sensor information for samples with pressure, and only if it * changed from the previous sensor we showed. */ - if (sample->pressure[0].mbar && sample->sensor[0] != old->sensor[0]) { - put_format(b, " sensor='%d'", sample->sensor[0]); - old->sensor[0] = sample->sensor[0]; + for (idx = 0; idx < MAX_SENSORS; idx++) { + pressure_t p = sample->pressure[idx]; + int sensor = sample->sensor[idx]; + + if (!p.mbar) + continue; + + /* Legacy o2pressure format? */ + if (o2sensor >= 0) { + if (sensor == o2sensor) { + put_pressure(b, p, " o2pressure='", " bar'"); + continue; + } + put_pressure(b, sample->pressure[0], " pressure='", " bar'"); + if (sensor != old->sensor[0]) { + put_format(b, " sensor='%d'", sensor); + old->sensor[0] = sensor; + } + continue; + } + + /* The new-style format is much simpler: the sensor is always encoded */ + put_format(b, " pressure%d=", sensor); + put_pressure(b, p, "'", " bar'"); } /* the deco/ndl values are stored whenever they change */ @@ -339,16 +360,16 @@ static void save_samples(struct membuffer *b, struct dive *dive, struct divecomp struct sample dummy = {}; /* Set up default pressure sensor indexes */ - o2sensor = get_cylinder_idx_by_use(dive, OXYGEN); - if (o2sensor < 0) - o2sensor = 1; - dummy.sensor[0] = !o2sensor; - dummy.sensor[1] = o2sensor; + o2sensor = legacy_format_o2pressures(dive, dc); + if (o2sensor >= 0) { + dummy.sensor[0] = !o2sensor; + dummy.sensor[1] = o2sensor; + } s = dc->sample; nr = dc->samples; while (--nr >= 0) { - save_sample(b, s, &dummy); + save_sample(b, s, &dummy, o2sensor); s++; } } |