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>
This commit is contained in:
Linus Torvalds 2017-07-21 13:37:34 -07:00 committed by Dirk Hohndel
parent ea31800f61
commit f2a6a76b3e
4 changed files with 79 additions and 32 deletions

View file

@ -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);
}
/*