[PATCH] Extend SAMPLE_EVENT_GASCHANGE2 to have cylinder index in 'flags' field

Linus Torvalds torvalds at linux-foundation.org
Sat Jan 3 17:45:52 PST 2015


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Sat, 3 Jan 2015 17:21:05 -0800
Subject: [PATCH] Extend SAMPLE_EVENT_GASCHANGE2 to have cylinder index in 'flags' field

A value of zero (which is the normal legacy one) remains "unknown", but
the divecomputer backend can now give both gasmix and cylinder number
this way.

Currently only the EON Steel backend does that, but it should be easy
enough to extend others too.

Also, fix the user-visible cylinder numbering in the cylinder change
tooltip to use a human-friendlier one-based numbering (ie first cylinder
is "cyl 1", not "cyl 0")

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---

This is the subsurface side to take advantage of the gas index in the 
"flags" field of SAMPLE_EVENT_GASCHANGE2.

The main downside is that nobody historically looked at the "flag" field 
before, it is possible that some libdivecomputer backend doesn't fill it 
with zero. But a quick check seems to imply that all backends properly 
clear it (most with an explicit "flag = 0" right around that 
SAMPLE_EVENT_GASCHANGE2, and the Suunto D9 parser that doesn't do that has 
a 

        dc_sample_value_t sample = {0};

to initialize the whole sample with zero, so it all looks fine.

NOTE! In subsurface itself, when we then *save* the data, it looks like we 
don't save a cylinder index of 0 in the git save state. So we lose the 
explicit cylinder value for the first cylinder. I'll take a look at that 
later, but it's independent of this particular patch.

It's also not clear that subsurface should necessarily bother to save the 
cylinder index at all if it's unambiguous and can be calculated from the 
gas mix. None of this code has really gotten much testing, since the whole 
"explicit cylinder index" is all new, and basically nobody has data with 
it (since libdivecomputer imports haven't had the data).

The fact that we showed the cylinder index zero-based in the newly added 
tooltip text is very much an example of that kind of lack of data leading 
to lack of test coverage. This fixes that too (we internally number our 
gas indexes from 0..7 because they are C array indexes, and "unknown" is 
thus -1. But obviously from a human readability we should call the first 
cylinder "cyl 1" rather than "cyl 0".

Ho humm. We probably have tons of small issues like this in this area. 


 dive.c                          | 7 ++++++-
 qt-ui/profile/diveeventitem.cpp | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/dive.c b/dive.c
index 32ac25e2ae83..711392c5adc1 100644
--- a/dive.c
+++ b/dive.c
@@ -57,6 +57,7 @@ int event_gasmix_redundant(struct event *ev)
 
 struct event *add_event(struct divecomputer *dc, int time, int type, int flags, int value, const char *name)
 {
+	int gas_index = -1;
 	struct event *ev, **p;
 	unsigned int size, len = strlen(name);
 
@@ -79,11 +80,15 @@ struct event *add_event(struct divecomputer *dc, int time, int type, int flags,
 	case SAMPLE_EVENT_GASCHANGE2:
 		/* High 16 bits are He percentage */
 		ev->gas.mix.he.permille = (value >> 16) * 10;
+
+		/* Extension to the GASCHANGE2 format: cylinder index in 'flags' */
+		if (flags > 0 && flags <= MAX_CYLINDERS)
+			gas_index = flags-1;
 	/* Fallthrough */
 	case SAMPLE_EVENT_GASCHANGE:
 		/* Low 16 bits are O2 percentage */
 		ev->gas.mix.o2.permille = (value & 0xffff) * 10;
-		ev->gas.index = -1;
+		ev->gas.index = gas_index;
 		break;
 	}
 
diff --git a/qt-ui/profile/diveeventitem.cpp b/qt-ui/profile/diveeventitem.cpp
index 4294dfb29589..1a5e29dda1ee 100644
--- a/qt-ui/profile/diveeventitem.cpp
+++ b/qt-ui/profile/diveeventitem.cpp
@@ -106,7 +106,7 @@ void DiveEventItem::setupToolTipString()
 
 			/* Do we have an explicit cylinder index?  Show it. */
 			if (internalEvent->gas.index >= 0)
-				name += QString(" (cyl %1)").arg(internalEvent->gas.index);
+				name += QString(" (cyl %1)").arg(internalEvent->gas.index+1);
 		} else if (type == SAMPLE_EVENT_PO2 && name == "SP change") {
 			name += QString(":%1").arg((double)value / 1000);
 		} else {
-- 
2.2.1.212.gc5b9256



More information about the devel mailing list