summaryrefslogtreecommitdiffstats
path: root/core/save-git.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2017-07-21 13:37:34 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-07-21 16:34:33 -0700
commitf2a6a76b3e64858691dda623873b2d40c1e98add (patch)
tree10c0c14792c448c99cadb4aa9545f047175b198b /core/save-git.c
parentea31800f6194dbf45b530ab21049add076de52bd (diff)
downloadsubsurface-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-git.c')
-rw-r--r--core/save-git.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/core/save-git.c b/core/save-git.c
index 2647b88ae..b734f59f4 100644
--- a/core/save-git.c
+++ b/core/save-git.c
@@ -321,10 +321,22 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl
put_format(b, "\n");
}
-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++;
@@ -379,7 +391,7 @@ static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer
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);
}
/*