First step in cleaning up cylinder pressure sensor logic

Linus Torvalds torvalds at linux-foundation.org
Sun Dec 30 20:19:14 PST 2012


On Sun, Dec 30, 2012 at 8:00 PM, Linus Torvalds
<torvalds at linux-foundation.org> wrote:
>
> This patch renames "cylinderindex" in the samples as "sensor", making it
> quite clear that it's about which sensor index the pressure data in the
> sample is about.

Oh, I forgot to talk about the XML file changes.

So along with renaming "cylinderindex" in the internal samples data
structure, it also renames it in the xml file, and changes the
semantics. Now it outputs a "sensor=X" thing as a sample XML attribute
when (a) there is a pressure reading at all (because a sensor index
without sensor data makes no sense!) _and_ (b) the sensor index is
different from the previous sensor output.

In particular, that explains the changes to "save_sample()": we can't
actually look at the previous actual *sample* to see what the previous
sensor state we wrote was (because the previous sample may not have
had any pressure data!), so the meaning of "prev" has changed. It is
now something that "save_sample()" updates as it goes along, so now
it's not "previous sample", but "old sample information".

That explains this kinds of changes in the patch:

-       if (sample->ndl.seconds != prev->ndl.seconds)
+       if (sample->ndl.seconds != old->ndl.seconds) {
                fprintf(f, " ndl='%u:%02u min'",
FRACTION(sample->ndl.seconds, 60));
+               old->ndl = sample->ndl;
+       }

because we now have to explicitly update what we wrote last.

Anyway, the *result* of all this is that my Uemis XML file that used
to look like this:

   <sample time='20:00 min' depth='28.08 m' />
   <sample time='20:04 min' depth='27.93 m' />
   <sample time='20:09 min' depth='27.83 m' cylinderindex='2' />
   <sample time='20:12 min' depth='27.87 m' cylinderindex='2'
stoptime='1:00 min' cns='4%' />
   <sample time='20:20 min' depth='27.36 m' cylinderindex='2' />

now looks like this instead:

   <event time='20:09 min' type='11' value='80' name='gaschange' />
   <event time='29:55 min' type='11' value='40' name='gaschange' />
  ...
   <sample time='20:00 min' depth='28.08 m' />
   <sample time='20:04 min' depth='27.93 m' />
   <sample time='20:09 min' depth='27.83 m' />
   <sample time='20:12 min' depth='27.87 m' stoptime='1:00 min' cns='4%' />
   <sample time='20:20 min' depth='27.36 m' />

and the samples really do look much cleaner. They no longer contain
those endless redundant and pointless "cylinderindex" things that
don't actually tell us anything useful.

(The above, btw, is the XML conversion, which is buggy:
"cylinderindex=2" is actually supposed to be the 40% cylinder, but
because the Zurich wasn't imported first, cylinder 2 - from my Suunto
HelO2 - is the 80% mix. Doing a re-import gets that right, because it
turns it into the Uemis percentage, and my Uemis had 40% O2 for what
it called cylinder "2". Anyway, you can see how with the old model,
subsurface thought the first gas-change - which should be to the EAN40
bottle - has become a change to EAN80. *Really* doing that at a depth
of 27 meters would be a VERY BAD IDEA, but it's not "real" and comes
purely from the dive computers indexing the bottles differently).

               Linus


More information about the subsurface mailing list