aboutsummaryrefslogtreecommitdiffstats
path: root/core/dive.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2017-07-20 19:49:45 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-07-21 16:33:19 -0700
commit1e38d9239a7bac621eedcb2bab98b90d78b988af (patch)
tree55d30d369aadeb58d19ce5d580fc414b10cfa94c /core/dive.c
parent11a0c0cc701806ccec975c67d27dec97fbb13b1f (diff)
downloadsubsurface-1e38d9239a7bac621eedcb2bab98b90d78b988af.tar.gz
Start cleaning up sensor indexing for multiple sensors
This is a very timid start at making us actually use multiple sensors without the magical special case for just CCR oxygen tracking. It mainly does: - turn the "sample->sensor" index into an array of two indexes, to match the pressures themselves. - get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index}, since a CCR dive should now simply set the sample->sensor[] indices correctly instead. - in a couple of places, start actually looping over the sensors rather than special-case the O2 case (although often the small "loops" are just unrolled, since it's just two cases. but in many cases we still end up only covering the zero sensor case, because the CCR O2 sensor code coverage was fairly limited. It's entirely possible (even likely) that this migth break some existing case: it tries to be a fairly direct ("stupid") translation of the old code, but unlike the preparatory patch this does actually does change some semantics. For example, right now the git loader code assumes that if the git save data contains a o2pressure entry, it just hardcodes the O2 sensor index to 1. In fact, one issue is going to simply be that our file formats do not have that multiple sensor format, but instead had very clearly encoded things as being the CCR O2 pressure sensor. But this is hopefully close to usable, and I will need feedback (and maybe test cases) from people who have existing CCR dives with pressure data. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/dive.c')
-rw-r--r--core/dive.c73
1 files changed, 35 insertions, 38 deletions
diff --git a/core/dive.c b/core/dive.c
index 229a04eba..6406242bf 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -1207,12 +1207,6 @@ unsigned int dc_airtemp(struct divecomputer *dc)
return (sum + nr / 2) / nr;
}
-static void fixup_cylinder_use(struct dive *dive) // for CCR dives, store the indices
-{ // of the oxygen and diluent cylinders
- dive->oxygen_cylinder_index = get_cylinder_idx_by_use(dive, OXYGEN);
- dive->diluent_cylinder_index = get_cylinder_idx_by_use(dive, DILUENT);
-}
-
static void fixup_airtemp(struct dive *dive)
{
if (!dive->airtemp.mkelvin)
@@ -1354,26 +1348,25 @@ static void fixup_dc_temp(struct dive *dive, struct divecomputer *dc)
static void simplify_dc_pressures(struct divecomputer *dc)
{
int i;
- int lastindex = -1;
- int lastpressure = 0, lasto2pressure = 0;
+ int lastindex[2] = { -1, -1 };
+ int lastpressure[2] = { 0 };
for (i = 0; i < dc->samples; i++) {
+ int j;
struct sample *sample = dc->sample + i;
- int pressure = sample->pressure[0].mbar;
- int o2_pressure = sample->pressure[1].mbar;
- int index;
-
- index = sample->sensor;
- if (index == lastindex) {
- /* Remove duplicate redundant pressure information */
- if (pressure == lastpressure)
- sample->pressure[0].mbar = 0;
- if (o2_pressure == lasto2pressure)
- sample->pressure[1].mbar = 0;
+
+ for (j = 0; j < 2; j++) {
+ int pressure = sample->pressure[j].mbar;
+ int index = sample->sensor[j];
+
+ if (index == lastindex[j]) {
+ /* Remove duplicate redundant pressure information */
+ if (pressure == lastpressure[j])
+ sample->pressure[j].mbar = 0;
+ }
+ lastindex[j] = index;
+ lastpressure[j] = pressure;
}
- lastindex = index;
- lastpressure = pressure;
- lasto2pressure = o2_pressure;
}
}
@@ -1411,10 +1404,7 @@ static void fixup_end_pressure(struct dive *dive, int idx, pressure_t p)
*/
static void fixup_dive_pressures(struct dive *dive, struct divecomputer *dc)
{
- int i, o2index = -1;
-
- if (dive->dc.divemode == CCR)
- o2index = get_cylinder_idx_by_use(dive, OXYGEN);
+ int i;
/* Walk the samples from the beginning to find starting pressures.. */
for (i = 0; i < dc->samples; i++) {
@@ -1423,8 +1413,8 @@ static void fixup_dive_pressures(struct dive *dive, struct divecomputer *dc)
if (sample->depth.mm < SURFACE_THRESHOLD)
continue;
- fixup_start_pressure(dive, sample->sensor, sample->pressure[0]);
- fixup_start_pressure(dive, o2index, sample->pressure[1]);
+ fixup_start_pressure(dive, sample->sensor[0], sample->pressure[0]);
+ fixup_start_pressure(dive, sample->sensor[1], sample->pressure[1]);
}
/* ..and from the end for ending pressures */
@@ -1434,8 +1424,8 @@ static void fixup_dive_pressures(struct dive *dive, struct divecomputer *dc)
if (sample->depth.mm < SURFACE_THRESHOLD)
continue;
- fixup_end_pressure(dive, sample->sensor, sample->pressure[0]);
- fixup_end_pressure(dive, o2index, sample->pressure[1]);
+ fixup_end_pressure(dive, sample->sensor[0], sample->pressure[0]);
+ fixup_end_pressure(dive, sample->sensor[1], sample->pressure[1]);
}
simplify_dc_pressures(dc);
@@ -1575,7 +1565,6 @@ struct dive *fixup_dive(struct dive *dive)
fixup_duration(dive);
fixup_watertemp(dive);
fixup_airtemp(dive);
- fixup_cylinder_use(dive); // store indices for CCR oxygen and diluent cylinders
for (i = 0; i < MAX_CYLINDERS; i++) {
cylinder_t *cyl = dive->cylinder + i;
add_cylinder_description(&cyl->type);
@@ -1715,8 +1704,12 @@ static void merge_samples(struct divecomputer *res, struct divecomputer *a, stru
sample.temperature = as->temperature;
if (as->pressure[0].mbar)
sample.pressure[0] = as->pressure[0];
- if (as->sensor)
- sample.sensor = as->sensor;
+ if (as->sensor[0])
+ sample.sensor[0] = as->sensor[0];
+ if (as->pressure[1].mbar)
+ sample.pressure[1] = as->pressure[1];
+ if (as->sensor[1])
+ sample.sensor[1] = as->sensor[1];
if (as->cns)
sample.cns = as->cns;
if (as->setpoint.mbar)
@@ -1950,11 +1943,15 @@ void dc_cylinder_renumber(struct dive *dive, struct divecomputer *dc, int mappin
/* Remap the sensor indexes */
for (i = 0; i < dc->samples; i++) {
struct sample *s = dc->sample + i;
- int sensor;
+ int j;
- sensor = mapping[s->sensor];
- if (sensor >= 0)
- s->sensor = sensor;
+ for (j = 0; j < 2; j++) {
+ int sensor;
+
+ sensor = mapping[s->sensor[j]];
+ if (sensor >= 0)
+ s->sensor[j] = sensor;
+ }
}
/* Remap the gas change indexes */
@@ -2627,7 +2624,7 @@ static int same_sample(struct sample *a, struct sample *b)
return 0;
if (a->pressure[0].mbar != b->pressure[0].mbar)
return 0;
- return a->sensor == b->sensor;
+ return a->sensor[0] == b->sensor[0];
}
static int same_dc(struct divecomputer *a, struct divecomputer *b)