summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-12-30 20:00:51 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-12-30 20:44:47 -0800
commitd720e133d84d6d468ffab48698d5105849f7d14c (patch)
tree78b531ab868c901f8077a49d5d8304422698f6a0 /dive.c
parentdf0ea072920668de4517ad85c742c7169bd24f22 (diff)
downloadsubsurface-d720e133d84d6d468ffab48698d5105849f7d14c.tar.gz
First step in cleaning up cylinder pressure sensor logic
This clarifies/changes the meaning of our "cylinderindex" entry in our samples. It has been rather confused, because different dive computers have done things differently, and the naming really hasn't helped. There are two totally different - and independent - cylinder "indexes": - the pressure sensor index, which indicates which cylinder the sensor data is from. - the "active cylinder" index, which indicates which cylinder we actually breathe from. These two values really are totally independent, and have nothing what-so-ever to do with each other. The sensor index may well be fixed: many dive computers only support a single pressure sensor (whether wireless or wired), and the sensor index is thus always zero. Other dive computers may support multiple pressure sensors, and the gas switch event may - or may not - indicate that the sensor changed too. A dive computer might give the sensor data for *all* cylinders it can read, regardless of which one is the one we're actively breathing. In fact, some dive computers might give sensor data for not just *your* cylinder, but your buddies. This patch renames "cylinderindex" in the samples as "sensor", making it quite clear that it's about which sensor index the pressure data in the sample is about. The way we figure out which is the currently active gas is with an explicit has change event. If a computer (like the Uemis Zurich) joins the two concepts together, then a sensor change should also create a gas switch event. This patch also changes the Uemis importer to do that. Finally, it should be noted that the plot info works totally separately from the sample data, and is about what we actually *display*, not about the sample pressures etc. In the plot info, the "cylinderindex" does in fact mean the currently active cylinder, and while it is initially set to match the sensor information from the samples, we then walk the gas change events and fix it up - and if the active cylinder differs from the sensor cylinder, we clear the sensor data. [Dirk Hohndel: this conflicted with some of my recent changes - I think I merged things correctly...] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/dive.c b/dive.c
index 98b96b3ff..7457cc5fc 100644
--- a/dive.c
+++ b/dive.c
@@ -237,7 +237,9 @@ static void fixup_pressure(struct dive *dive, struct sample *sample)
pressure = sample->cylinderpressure.mbar;
if (!pressure)
return;
- index = sample->cylinderindex;
+ index = sample->sensor;
+
+ /* FIXME! sensor -> cylinder mapping? */
if (index >= MAX_CYLINDERS)
return;
cyl = dive->cylinder + index;
@@ -427,7 +429,7 @@ struct dive *fixup_dive(struct dive *dive)
int depth = sample->depth.mm;
int temp = sample->temperature.mkelvin;
int pressure = sample->cylinderpressure.mbar;
- int index = sample->cylinderindex;
+ int index = sample->sensor;
if (index == lastindex) {
/* Remove duplicate redundant pressure information */
@@ -502,7 +504,7 @@ struct dive *fixup_dive(struct dive *dive)
if (abs(pressure_delta[j]) != INT_MAX) {
cylinder_t *cyl = dive->cylinder + j;
for (i = 0; i < dc->samples; i++)
- if (dc->sample[i].cylinderindex == j)
+ if (dc->sample[i].sensor == j)
dc->sample[i].cylinderpressure.mbar = 0;
if (! cyl->start.mbar)
cyl->start.mbar = cyl->sample_start.mbar;
@@ -709,8 +711,8 @@ add_sample_b:
sample.temperature = as->temperature;
if (as->cylinderpressure.mbar)
sample.cylinderpressure = as->cylinderpressure;
- if (as->cylinderindex)
- sample.cylinderindex = as->cylinderindex;
+ if (as->sensor)
+ sample.sensor = as->sensor;
if (as->cns)
sample.cns = as->cns;
if (as->po2)
@@ -1291,7 +1293,7 @@ static int same_sample(struct sample *a, struct sample *b)
return 0;
if (a->cylinderpressure.mbar != b->cylinderpressure.mbar)
return 0;
- return a->cylinderindex == b->cylinderindex;
+ return a->sensor == b->sensor;
}
static int same_dc(struct divecomputer *a, struct divecomputer *b)