diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-21 13:37:34 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-07-21 16:34:33 -0700 |
commit | f2a6a76b3e64858691dda623873b2d40c1e98add (patch) | |
tree | 10c0c14792c448c99cadb4aa9545f047175b198b /core/save-xml.c | |
parent | ea31800f6194dbf45b530ab21049add076de52bd (diff) | |
download | subsurface-f2a6a76b3e64858691dda623873b2d40c1e98add.tar.gz |
Fix up o2 pressure sensor handling at load time
Because of how we traditionally did things, the "o2pressure" parsing
depends on implicitly setting the sensor index to the last cylinder that
was marked as being used for oxygen.
We also always defaulted the primary sensor (which is used for the
diluent tank for CCR) to cylinder 0, but that doesn't work when the
oxygen tank is cylinder 0.
This gets that right at file loading time, and unifies the xml and git
sample parsing to make them match. The new defaults are:
- unless anything else is explicitly specified, the primary sensor is
associated with the first tank, and the secondary sensor is
associated with the second tank
- if we're a CCR dive, and have an explicit oxygen tank, we associate
the secondary sensor with that oxygen cylinder. The primary sensor
will be switched over to the second cylinder if the oxygen cylinder
is the first one.
This may sound backwards, but matches our traditional behavior where
the O2 pressure was the secondary pressure.
This is definitely not pretty, but it gets our historical files working
right, and is at least reasonably sensible.
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.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/core/save-xml.c b/core/save-xml.c index 151ebf0a3..73a00f54a 100644 --- a/core/save-xml.c +++ b/core/save-xml.c @@ -331,10 +331,22 @@ static void show_date(struct membuffer *b, timestamp_t when) tm.tm_hour, tm.tm_min, tm.tm_sec); } -static void save_samples(struct membuffer *b, int nr, struct sample *s) +static void save_samples(struct membuffer *b, struct dive *dive, struct divecomputer *dc) { + int nr; + int o2sensor; + struct sample *s; 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; + + s = dc->sample; + nr = dc->samples; while (--nr >= 0) { save_sample(b, s, &dummy); s++; @@ -368,7 +380,7 @@ static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer put_duration(b, dc->surfacetime, " <surfacetime>", " min</surfacetime>\n"); save_extra_data(b, dc->extra_data); save_events(b, dive, dc->events); - save_samples(b, dc->samples, dc->sample); + save_samples(b, dive, dc); put_format(b, " </divecomputer>\n"); } |