understanding the sensor values in our samples

Dirk Hohndel dirk at hohndel.org
Thu Apr 28 09:25:42 PDT 2022



> On Apr 28, 2022, at 9:04 AM, Linus Torvalds <torvalds at linux-foundation.org> wrote:
> 
> On Wed, Apr 27, 2022 at 2:27 PM Dirk Hohndel <dirk at hohndel.org> wrote:
>> 
>> Well, turns out that both in load-git.c and parse.c we have essentially this code:
>> 
>>                sample->sensor[0] = sanitize_sensor_id(state->active_dive, !state->o2pressure_sensor);
>>                sample->sensor[1] = sanitize_sensor_id(state->active_dive, state->o2pressure_sensor);
>> 
>> But, if we don't have an o2 pressure sensor, why would we put a valid cylinder number there?
>> That sensor should say "NO_SENSOR" (or -1) unless we have actually identified an O2 sensor...
> 
> 
> Then, to actually explain those two lines you quote, you need a few more hints:
> 
> (1) when loading a dive from XML or git save, we start with the
> default assumption that sensor 0 is diluent, and sensor 1 is O2. So
> look at parse_dive_entry(), and you will find this line
> 
>        state->o2pressure_sensor = 1;
> 
> (2) When er parse cylinders, and find a pure oxygen cylinder listed,
> we will fix it up:
> 
>        if (cylinder.cylinder_use == OXYGEN)
>                state->o2pressure_sensor = state->active_dive->cylinders.nr;
> 
> so now o2pressure_sensor will point to the oxygen cylinder.
> 
> And now, finally, you are ready to read those two lines:
> 
>        sample->sensor[0] = sanitize_sensor_id(state->active_dive,
> !state->o2pressure_sensor);
>        sample->sensor[1] = sanitize_sensor_id(state->active_dive,
> state->o2pressure_sensor);
> 
> because they didn't really say what you thought they said.
> 
> What those two lines say is:
> 
> - sensor 0 is for cylinder 0, *except* if cylinder zero is our O2
> cylinder, in which case it's for cylinder 1
> 
> - sensor 1 is for cylinder 1, *but* will be the O2 cylinder if we had one
> 
> (and then that sanitize_sensor_id() just says that we'll never make a
> sensor ID point to a cylinder we don't even have,
> 
> So basically "!state->o2pressure_sensor" is the expression for that
> "cylinder 0, except if zero was our O2 sensor".
> 
> And state->o2pressure_sensor is "1, or our O2 cylinder".


Yes, I get that part. And assuming we are looking at a CCR dive I can
assign some resemblance of sense to it. But if this is an OC dive, this
is all not at all useful, because there is no O2 cylinder (unless that is
the explicit deco stage that a tech diver happens to take with them).
For the 90+% of all the OC dives that are "single tank, no gas switches,
I'm just having fun" this is actively WRONG, because we use
cylinder_with_sensor_sample() as a way to determine if a tank is used
during this dive. And since by default  the sensor array is filled with 0 
and 1, this prevents us from deleting a tank that is in fact unused.

/D


More information about the subsurface mailing list