summaryrefslogtreecommitdiffstats
path: root/core/gaspressures.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/gaspressures.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/gaspressures.c')
-rw-r--r--core/gaspressures.c50
1 files changed, 17 insertions, 33 deletions
diff --git a/core/gaspressures.c b/core/gaspressures.c
index 77a19429f..86ea8de7a 100644
--- a/core/gaspressures.c
+++ b/core/gaspressures.c
@@ -197,7 +197,7 @@ static struct pr_interpolate_struct get_pr_interpolate_data(pr_track_t *segment,
return interpolate;
}
-static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi, pr_track_t **track_pr, bool o2_flag)
+static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi, pr_track_t **track_pr, int sensoridx)
{
int cyl, i;
struct plot_data *entry;
@@ -243,20 +243,12 @@ static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi,
entry = pi->entry + i;
- if (o2_flag) {
- // Find the cylinder index (cyl) and pressure
- cyl = dive->oxygen_cylinder_index;
- if (cyl < 0)
- return; // Can we do this?!?
- pressure = O2CYLINDER_PRESSURE(entry);
- save_pressure = &(entry->pressure[1][SENSOR_PR]);
- save_interpolated = &(entry->pressure[1][INTERPOLATED_PR]);
- } else {
- pressure = SENSOR_PRESSURE(entry);
- save_pressure = &(entry->pressure[0][SENSOR_PR]);
- save_interpolated = &(entry->pressure[0][INTERPOLATED_PR]);
- cyl = entry->cylinderindex;
- }
+ cyl = entry->sensor[sensoridx];
+ if (cyl < 0)
+ continue;
+ save_pressure = &(entry->pressure[sensoridx][SENSOR_PR]);
+ save_interpolated = &(entry->pressure[sensoridx][INTERPOLATED_PR]);
+ pressure = *save_pressure ? *save_pressure : *save_interpolated;
if (pressure) { // If there is a valid pressure value,
last_segment = NULL; // get rid of interpolation data,
@@ -346,7 +338,7 @@ static void debug_print_pressures(struct plot_info *pi)
* in the pr_track_alloc structures. If diluent_flag = 1, then DILUENT_PRESSURE(entry) is used instead of SENSOR_PRESSURE.
* This function is called by create_plot_info_new() in profile.c
*/
-void populate_pressure_information(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, int o2_flag)
+void populate_pressure_information(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, int sensoridx)
{
(void) dc;
int i, cylinderid, cylinderindex = -1;
@@ -369,15 +361,12 @@ void populate_pressure_information(struct dive *dive, struct divecomputer *dc, s
for (i = 0; i < pi->nr; i++) {
struct plot_data *entry = pi->entry + i;
unsigned pressure;
- if (o2_flag) { // if this is a diluent cylinder:
- pressure = O2CYLINDER_PRESSURE(entry);
- cylinderid = dive->oxygen_cylinder_index;
- if (cylinderid < 0)
- goto GIVE_UP;
- } else {
- pressure = SENSOR_PRESSURE(entry);
- cylinderid = entry->cylinderindex;
- }
+
+ pressure = SENSOR_PRESSURE(entry, sensoridx);
+ cylinderid = entry->sensor[sensoridx];
+ if (cylinderid < 0)
+ goto GIVE_UP;
+
/* If track_pr structure already exists, then update it: */
/* discrete integration of pressure over time to get the SAC rate equivalent */
if (current) {
@@ -389,10 +378,7 @@ void populate_pressure_information(struct dive *dive, struct divecomputer *dc, s
/* If 1st record or different cylinder: Create a new track_pr structure: */
/* track the segments per cylinder and their pressure/time integral */
if (cylinderid != cylinderindex) {
- if (o2_flag) // For CCR dives:
- cylinderindex = dive->oxygen_cylinder_index; // indicate o2 cylinder
- else
- cylinderindex = entry->cylinderindex;
+ cylinderindex = entry->sensor[sensoridx];
current = pr_track_alloc(pressure, entry->sec);
track_pr[cylinderindex] = list_add(track_pr[cylinderindex], current);
continue;
@@ -406,9 +392,7 @@ void populate_pressure_information(struct dive *dive, struct divecomputer *dc, s
current->end = pressure;
/* Was it continuous? */
- if ((o2_flag) && (O2CYLINDER_PRESSURE(entry - 1))) // in the case of CCR o2 pressure
- continue;
- else if (SENSOR_PRESSURE(entry - 1)) // for all other cylinders
+ if (SENSOR_PRESSURE(entry - 1, sensoridx))
continue;
/* transmitter stopped transmitting cylinder pressure data */
@@ -418,7 +402,7 @@ void populate_pressure_information(struct dive *dive, struct divecomputer *dc, s
}
if (missing_pr) {
- fill_missing_tank_pressures(dive, pi, track_pr, o2_flag);
+ fill_missing_tank_pressures(dive, pi, track_pr, sensoridx);
}
#ifdef PRINT_PRESSURES_DEBUG