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/load-git.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/load-git.c')
-rw-r--r-- | core/load-git.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/core/load-git.c b/core/load-git.c index 87f6ecb25..6a3cc75ce 100644 --- a/core/load-git.c +++ b/core/load-git.c @@ -354,6 +354,7 @@ static char *parse_keyvalue_entry(void (*fn)(void *, const char *, const char *) } static int cylinder_index, weightsystem_index; +static int o2pressure_sensor; static void parse_cylinder_keyvalue(void *_cylinder, const char *key, const char *value) { @@ -397,7 +398,6 @@ static void parse_dive_cylinder(char *line, struct membuffer *str, void *_dive) struct dive *dive = _dive; cylinder_t *cylinder = dive->cylinder + cylinder_index; - cylinder_index++; cylinder->type.description = get_utf8(str); for (;;) { char c; @@ -407,6 +407,9 @@ static void parse_dive_cylinder(char *line, struct membuffer *str, void *_dive) break; line = parse_keyvalue_entry(parse_cylinder_keyvalue, cylinder, line); } + if (cylinder->cylinder_use == OXYGEN) + o2pressure_sensor = cylinder_index; + cylinder_index++; } static void parse_weightsystem_keyvalue(void *_ws, const char *key, const char *value) @@ -540,11 +543,6 @@ static void parse_sample_keyvalue(void *_sample, const char *key, const char *va } if (!strcmp(key, "o2pressure")) { pressure_t p = get_pressure(value); - // - // FIXME!!! What's the O2 cylinder index? - // get_cylinder_idx_by_use(dive, OXYGEN) - // - sample->sensor[1] = 1; sample->pressure[1].mbar = p.mbar; return; } @@ -599,6 +597,13 @@ static char *parse_sample_unit(struct sample *sample, double val, char *unit) * missing sample pressure doesn't mean "same as last * time", but "interpolate". We clear those ones * explicitly. + * + * NOTE! We default sensor use to 0, 1 respetively for + * the two sensors, but for CCR dives with explicit + * OXYGEN bottles we set the secondary sensor to that. + * Then the primary sensor will be either the first + * or the second cylinder depending on what isn't an + * oxygen cylinder. */ static struct sample *new_sample(struct divecomputer *dc) { @@ -606,6 +611,10 @@ static struct sample *new_sample(struct divecomputer *dc) if (sample != dc->sample) { memcpy(sample, sample-1, sizeof(struct sample)); sample->pressure[0].mbar = 0; + sample->pressure[1].mbar = 0; + } else { + sample->sensor[0] = !o2pressure_sensor; + sample->sensor[1] = o2pressure_sensor; } return sample; } @@ -1502,6 +1511,7 @@ static int parse_dive_entry(git_repository *repo, const git_tree_entry *entry, c if (*suffix) dive->number = atoi(suffix+1); cylinder_index = weightsystem_index = 0; + o2pressure_sensor = 1; for_each_line(blob, dive_parser, active_dive); git_blob_free(blob); return 0; |