[PATCH] Fix Poseidon MkVI txt file import sensor pressures

Linus Torvalds torvalds at linux-foundation.org
Thu Aug 3 11:40:03 PDT 2017


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Thu, 3 Aug 2017 11:34:20 -0700
Subject: [PATCH] Fix Poseidon MkVI txt file import sensor pressures

When I unified the sample pressures in commit 11a0c0cc7018 ("Unify
sample pressure and o2pressure as pressure[2] array") I did all the
obvious conversions, including the conversion of the Poseidon txt file
import:

        case POSEIDON_PRESSURE:
-               sample->cylinderpressure.mbar = lrint(val * 1000);
+               sample->pressure[0].mbar = lrint(val * 1000);
                break;
        case POSEIDON_O2CYLINDER:
-               sample->o2cylinderpressure.mbar = lrint(val * 1000);
+               sample->pressure[1].mbar = lrint(val * 1000);
                break;

which was ObviouslyCorrect(tm).

But as so often is the case, obvious doesn't actually exist.  The old
"o2cylinderpressure[]" model had an implicit sensor associated with it,
and that implicit sensor mapping wasn't obvious, and didn't get fixed.

It turns out that the way the Poseidon sensor mapping works, the O2
cylinder is cylinder 0, and the diluent cylinder is cylinder 1, so just
use the add_sample_pressure() helper to set both sensor index and
pressure value.

And since we now do all the sensor indexing right, we can also get rid
of some manual cylinder sample pressure code, because the generic dive
fixup will just DTRT.  It used to screw up because the diluent sensor
number was wrong before, and the import code tried to work around that
by hand.

Reported-by: Anton Lundin <glance at acc.umu.se>
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---

This does not have a whole lot of testing, but it's once again obvious. 
And the import now looks correct.

That test file does show that we now don't do the alignment of pressure 
text depending on which pressure line is higher, but that's a separate 
issue. Maybe Anton cares enough to want to make it prettier again ;)

 core/file.c | 28 +++-------------------------
 1 file changed, 3 insertions(+), 25 deletions(-)

diff --git a/core/file.c b/core/file.c
index b2ff56f4..dddc7782 100644
--- a/core/file.c
+++ b/core/file.c
@@ -275,8 +275,6 @@ enum csv_format {
 	POSEIDON_SETPOINT,
 	POSEIDON_SENSOR1,
 	POSEIDON_SENSOR2,
-	POSEIDON_PRESSURE,
-	POSEIDON_O2CYLINDER,
 	POSEIDON_NDL,
 	POSEIDON_CEILING
 };
@@ -308,12 +306,6 @@ static void add_sample_data(struct sample *sample, enum csv_format type, double
 	case POSEIDON_SENSOR2:
 		sample->o2sensor[1].mbar = lrint(val * 10);
 		break;
-	case POSEIDON_PRESSURE:
-		sample->pressure[0].mbar = lrint(val * 1000);
-		break;
-	case POSEIDON_O2CYLINDER:
-		sample->pressure[1].mbar = lrint(val * 1000);
-		break;
 	case POSEIDON_NDL:
 		sample->ndl.seconds = lrint(val * 60);
 		break;
@@ -609,7 +601,7 @@ int parse_txt_file(const char *filename, const char *csv)
 		int prev_depth = 0, cur_sampletime = 0, prev_setpoint = -1, prev_ndl = -1;
 		bool has_depth = false, has_setpoint = false, has_ndl = false;
 		char *lineptr, *key, *value;
-		int o2cylinder_pressure = 0, cylinder_pressure = 0, cur_cylinder_index = 0;
+		int cur_cylinder_index = 0;
 		unsigned int prev_time = 0;
 
 		struct dive *dive;
@@ -780,21 +772,11 @@ int parse_txt_file(const char *filename, const char *csv)
 						break;
 					case 13:
 						//O2 Tank Pressure
-						add_sample_data(sample, POSEIDON_O2CYLINDER, value);
-						if (!o2cylinder_pressure) {
-							dive->cylinder[0].sample_start.mbar = value * 1000;
-							o2cylinder_pressure = value;
-						} else
-							o2cylinder_pressure = value;
+						add_sample_pressure(sample, 0, lrint(value * 1000));
 						break;
 					case 14:
 						//Diluent Tank Pressure
-						add_sample_data(sample, POSEIDON_PRESSURE, value);
-						if (!cylinder_pressure) {
-							dive->cylinder[1].sample_start.mbar = value * 1000;
-							cylinder_pressure = value;
-						} else
-							cylinder_pressure = value;
+						add_sample_pressure(sample, 1, lrint(value * 1000));
 						break;
 						//16 Remaining dive time #1?
 						//17 related to O2 injection
@@ -874,10 +856,6 @@ int parse_txt_file(const char *filename, const char *csv)
 				add_sample_data(sample, POSEIDON_SETPOINT, prev_setpoint);
 			if (!has_ndl && prev_ndl >= 0)
 				add_sample_data(sample, POSEIDON_NDL, prev_ndl);
-			if (cylinder_pressure)
-				dive->cylinder[1].sample_end.mbar = cylinder_pressure * 1000;
-			if (o2cylinder_pressure)
-				dive->cylinder[0].sample_end.mbar = o2cylinder_pressure * 1000;
 			finish_sample(dc);
 
 			if (!lineptr || !*lineptr)
-- 
2.14.0.rc1.2.g4c8247ec3



More information about the subsurface mailing list