[PATCH 6/4] Fix another cylinder pressure plotting special case

Linus Torvalds torvalds at linux-foundation.org
Sun Jul 30 10:51:51 PDT 2017


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Sun, 30 Jul 2017 10:41:20 -0700
Subject: [PATCH 6/4] Fix another cylinder pressure plotting special case

The core to plot manually entered pressures without any sample data did
the obvious thing: it ended the pressures at the end of the dive as
indicated by the last sample.

However, that obvious thing didn't actually work, because sometimes the
last sample is long long after the dive has actually ended, and we have
no plot_info data for that.

This depends on the dive computer used: most dive computers will not
report samples after the end (even if they may internally remember them
in case the diver just came up to the surface temporarily), but some
definitely do. The OSTC3 is a prime example of that.

Anyway, the code was fragile and wrong - even if passed a time past the
end of the plot_info data, "add_plot_pressure()" should just have
associated that with the last entry instead.  Which also allows us to
simplify the whole endtime logic entirely, and just use INT_MAX for it.

Gaetan Bisson's test-case also showed another oddity: we would plot the
gas pressure even for cylinders that had no has use (ie beginning and
ending pressures were the same).  That's kind of pointless in so many
ways.  So limit the manual pressure population to cylinders that
actually have seen use.

Reported-by: Gaetan Bisson <bisson at archlinux.org>
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---

Gaetan: this obviously does *not* change the fact that one of your dives 
had no gas change information, and so it shows two (but only two) pressure 
lines for the whole dive.

But looking at that dive, I realize that it's actually a CCR dive, and 
that the whole "two cylinders during the whole dive" is entirely correct, 
it's your O2 and Diluent bottle.

So you presumably did actually have four cylinders with you (for bailout) 
and just never used it.

So I think the code now does exactly the right thing for your case. Except 
for the equipment tab side, which doesn't show your two unused cylinders, 
even though you filled in information for them. But that looks like a 
pre-existing bug and probably has nothing to do with the recent pressure 
graph changes.

 core/profile.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/core/profile.c b/core/profile.c
index e9a625d3..7b582741 100644
--- a/core/profile.c
+++ b/core/profile.c
@@ -804,14 +804,14 @@ static void populate_secondary_sensor_data(struct divecomputer *dc, struct plot_
  */
 static void add_plot_pressure(struct plot_info *pi, int time, int cyl, int mbar)
 {
+	struct plot_data *entry;
 	for (int i = 0; i < pi->nr; i++) {
-		struct plot_data *entry = pi->entry + i;
+		entry = pi->entry + i;
 
-		if (entry->sec < time)
-			continue;
-		SENSOR_PRESSURE(entry, cyl) = mbar;
-		return;
+		if (entry->sec >= time)
+			break;
 	}
+	SENSOR_PRESSURE(entry, cyl) = mbar;
 }
 
 static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
@@ -822,10 +822,9 @@ static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc
 	unsigned int first[MAX_CYLINDERS] = { 0, };
 	unsigned int last[MAX_CYLINDERS] = { 0, };
 	struct divecomputer *secondary;
-	int endtime = dc->samples ? dc->sample[dc->samples-1].time.seconds : dive->duration.seconds;
 
 	for (i = 0; i < MAX_CYLINDERS; i++)
-		last[i] = endtime;
+		last[i] = INT_MAX;
 
 	for (ev = get_next_event(dc->events, "gaschange"); ev != NULL; ev = get_next_event(ev->next, "gaschange")) {
 		int cyl = ev->gas.index;
@@ -846,14 +845,14 @@ static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc
 		}
 	}
 	if (prev >= 0)
-		last[prev] = endtime;
+		last[prev] = INT_MAX;
 
 	for (i = 0; i < MAX_CYLINDERS; i++) {
 		cylinder_t *cyl = dive->cylinder + i;
 		int start = cyl->start.mbar;
 		int end = cyl->end.mbar;
 
-		if (start && end) {
+		if (start && end && start != end) {
 			add_plot_pressure(pi, first[i], i, start);
 			add_plot_pressure(pi, last[i], i, end);
 		}
-- 
2.14.0.rc1.2.g4c8247ec3



More information about the subsurface mailing list