summaryrefslogtreecommitdiffstats
path: root/core/save-xml.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2017-07-25 19:10:03 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-07-25 22:05:32 -0700
commitefc5f4d9ababda3078a696bec8840a5eb173ee3d (patch)
treeeb6586d59ff6cb4b7a6e77f68bfede0ca7a0f74a /core/save-xml.c
parentc5167f00398ce16daaeb26ceb00ca058b6d1606c (diff)
downloadsubsurface-efc5f4d9ababda3078a696bec8840a5eb173ee3d.tar.gz
Add support for loading and saving multiple pressure samples
This does both the XML and the git save format, because the changes really are the same, even if the actual format differs in some details. See how the two "save_samples()" routines both do the same basic setup, for example. This is fairly straightforward, with the possible exception of the odd sensor = sample->sensor[0]; default in the git pressure loading code. That line just means that if we do *not* have an explicit cylinder index for the pressure reading, we will always end up filling in the new pressure as the first pressure (because the cylinder index will match the first sensor slot). So that makes the "add_sample_pressure()" case always do the same thing it used to do for the legacy case: fill in the first slot. The actual sensor index may later change, since the legacy format has a "sensor=X" key value pair that sets the sensor, but it will also use the first sensor slot, making it all do exactly what it used to do. And on the other hand, if we're loading new-style data with cylinder pressure and sensor index together, we just end up using the new semantics for add_sample_pressure(), which tries to keep the same slot for the same sensor, but does the right thing if we already have other pressure values. The XML code has no such issues at all, since it can't share the cases anyway, and we need to have different node names for the different sensor values and cannot just have multiple "pressure" entries. Have I mentioned how much I despise XML lately? Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/save-xml.c')
-rw-r--r--core/save-xml.c45
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++;
}
}