Commit graph

63 commits

Author SHA1 Message Date
Berthold Stoeger
5c248d91cd Coding-style: remove superfluous parentheses
Mostly replace "return (expression);" by "return expression;" and one
case of "function((parameter))" by "function(parameter)".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-17 19:38:52 -08:00
Lubomir I. Ivanov
2b4115d712 dump_tissues: fix missing 'struct deco_state' argument
With DECO_CALC_DEBUG != 0, divelist.c and profile.c have calls
to dump_tissues() without passing a 'struct deco_state' argument.

Fixes #1105

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2018-02-12 07:48:34 +01:00
Berthold Stoeger
22dc7b84f0 Handle plot_info->nr <= 0 gracefully
plot_info->nr should always be > 0. If this is not the case, write a
message to stderr instead of crashing in add_plot_pressure(). This
silences an use-of-uninitialized-variable warning.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-21 00:04:30 +01:00
Berthold Stoeger
0b2d22494c Fix use of uninitialized variable in core/profile.c
last_ceiling was used before initialization in the first iteration
of the loop in calculate_deco_information().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-21 00:04:30 +01:00
Dirk Hohndel
e8278becd2 Fix signed/unsigned issue
Also deal with an unused argument in the case of a Subsurface-mobile
build.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-11-29 14:56:39 -08:00
Robert C. Helling
088db5e12b Hand planner variables to profile
Pass the planner state struct to the profile computation so it can use
deco_time and first ceiling to display VPM-B ceiling.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-11-25 20:13:01 +01:00
Robert C. Helling
8e21a65653 Localize global planner state
For UI responsiveness, we need to be able to run the planner in the background. This needs the
planner state to be localized (and we need to pass a pointer around).

In order to not let too many lines overrun (and to save typing in the future)
I have renamed instances of struct deco_state to ds. Yes this should have gone
to a separate commit but I accidentally commit --amend'ed it.

Computing of planner variations is temporarily disabled.

Unlock the planner when returning early

So we don't deadlock in add dive and recreational mode (which
use the planner without actually planning).

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-11-25 20:13:01 +01:00
Robert C. Helling
a9ceecc2e3 Run variations calculation in background
but there are still side effects and thus it crashes.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-11-25 20:13:01 +01:00
Robert C. Helling
be6b50fce4 Add logic parentheses to make compiler happy
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-11-25 20:13:01 +01:00
Linus Torvalds
7fa5fcfa1d Don't show cylinder pressures for other dive computers
Stefan Fuchs points out that sometimes you get cylinder duplication when
you merge dives, particularly with a planned dive.  For example, if we
had different manual pressures in the two different dives, the cylinders
will be kept separate.

But that also means that we don't want to plot the pressures from those
other cylinders that came from another dive and are now associated with
another dive computer.

Change the "seen" logic for the cylinder to ignore cylinders that are
only mentioned by other dive computers than the active one.

Reported-by: Stefan Fuchs <sfuchs@gmx.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-11-17 15:25:26 +01:00
Linus Torvalds
8136c2d78b Clean up confusing code in setup_gas_sensor_pressure()
The "prev" cylinder can never be negative since commit 56c206d19f
("For more manual gas pressure details"), so remove stale code that
checks for a case that cannot happen any more.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-11-17 15:25:26 +01:00
Stefan Fuchs
1f8506ce64 Display values in info box only if value is interesting
Type duration_t changed from uint to int.

Default value of '-1' introduced for some of the values in struct sample:
NDL used -1 as default.
Bearing uses -1 as default (no bearing set).

Display pXX, EAD, END, density, MOD only if values are larger than 0.

In profile don't display data from two first and two last plot_data
entries in info box.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-13 20:50:10 -08:00
Rick Walsh
05b4113609 VPMB: time_clear_ceiling is only valid after time_deep_ceiling
Some messed up logic was producing negative deco_time values for some no-deco dives. The CVA wouldn't converge and unrealistic VPMB ceilings were displayed in the profile.  This fixes it.

See #762

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-11-08 15:22:32 +01:00
Rick Walsh
8e1ea8cd14 VPMB profile: remember deco_time when restoring deco_state
Otherwise the CVA won't iterate properly.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-11-08 15:22:32 +01:00
Rick Walsh
b3b787db94 VPMB: final_tts may be calculated before final sample
We calculate tts every 30s, not every sample. Consider that when determining
the time that the ceiling would have cleared if it's after the surfacing time.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-11-08 15:22:32 +01:00
Rick Walsh
fe474ac266 VPMB profile: use deco_time rather bottom_time from planner
This makes the calculations in profile.c a little simpler, especially now we
adopt consistent final ascent rate to determine deco_time since d15779a27

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-11-08 15:22:32 +01:00
Rick Walsh
e365cac54e VPMB in profile: deepest ceiling occurs just after bottom time
This lets us calculate deco_time for real dives closer to the planner value.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-11-08 15:22:32 +01:00
Rick Walsh
4a727c64d9 VPMB: calculate deco_time assuming final ascent always takes the same time
If we consider the actual time to ascend from the final stop when calculating
deco_time, then slowing the final ascent can lead to the final stop being
extended, which is completely nonsensical.  For consistency with the original
VPMB implementation, we can't ignore the final ascent time completely, but if
we assume it is always the same (take default ascent rate of 9m/min) then
slower the final ascent won't lead to a longer final stop.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-11-08 15:22:32 +01:00
Rick Walsh
a06848c237 VPM-B: move bottom_time into deco_state
Removing ext variable from profile.c should facilitate future performance
gains

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-11-08 15:22:32 +01:00
Stefan Fuchs
aa5b017bea Fix typo which prevented correct translation of word "Density"
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-06 12:07:06 -08:00
Rick Walsh
68c2b10161 VPM-B ceiling: calculate deco_time similar to planned VPM-B dives
When planning a VPM-B dive, the "deco time" ends at surfacing, which is after
ascending after a full-minute deco stop is complete, after ceiling clears. We
should take this into account when calculating the ceiling outside of the
planner.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-10-30 21:48:15 +01:00
Rick Walsh
f2535995f0 VPM-B ceiling outside of planner: over-estimate deco_time on first iteration
This means the iterations converge from an over-estimate, consistent with
planning VPM-B dives

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-10-30 21:48:15 +01:00
Rick Walsh
04383e27e5 VPMB profile: use bottom_time to calculate deco_time in planner
This corrects the issue where the displayed ceiling in the profile was
"broken" by the planner, especially for shorter and shallower dives.

Also fixes issue outside of planner where the deepest VPM-B ceiling was shown
too early, messing up the deco_time calculation.

VPM-B plans respond to change in O2% in gas as expected (in my testing)

Fixes: #630

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-10-30 21:48:15 +01:00
Rick Walsh
f9d05a8038 VPM-B profile: calculate parameters when in planner mode
Calculating parameters when in the planner mode is necessary to display the correct ceiling.

Fixes #601

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-10-08 23:16:40 +02:00
Robert C. Helling
a163bbc442 When finding deepest ceiling, do not round to multiples of 3m
Fixes #630

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-10-04 12:34:16 +03:00
Rick Walsh
8b5c5674b1 VPM-B profile: initialize first_ceiling_pressure
If we don't set first_ceiling_pressure at start of dive, a shallow ceiling can
be shown when it shouldn't be.

Fixes #584

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-10-01 23:58:55 +03:00
Robert C. Helling
1f50485732 More VPMB state in special structure
... and reset deco information in profile ceiling computation.

The planner test then needs to know about the struct holding the deco
state.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-10-01 23:58:55 +03:00
Linus Torvalds
e94af2c0b7 Properly clear sensor pressure data for synthetic plotinfo entries
We only cleared the first sensor data when we created new synthetic plot
info entries, because we only used to have one (well, we had the o2
data, but apparently nobody ever noticed that it didn't get properly
interpolated, probably because people who have CCR dives with o2
pressures are few, and the pressure drops are gradual anyway).

Clear all the pressure data, so that the interpolation code doesn't
think we have some existing real sensor data for the plot info entries
in between proper sample entries.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-09-15 16:29:00 +02:00
Linus Torvalds
6769e21441 Make the info window show all the pressures we have
We used to only show the first pressure we had, from back when we only
supported a single sensor.

Reported-by: Stefan Fuchs <sfuchs@gmx.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-09-13 14:05:26 -07:00
Dirk Hohndel
0813d2168a Remove some unused variables
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-08-26 12:14:46 -07:00
Linus Torvalds
56c206d19f For more manual gas pressure details
So the manual gas pressure case keeps showing issues, and in many ways it
really is a fairly complex thing, since it needs interpolation of the
intermediate pressures - possibly over several gas changes.

So you might have beginning and ending pressures for one cylinder, but
then use another cylinder in between.

We've historically got all the code to do this, but the big rewrite for
multiple cylinder pressures didn't get all the details right, and so
here's a few more fixes for the case that was shown by a dive by Robert
Helling.  Hopefully we're approaching the old code situation, except now
with concurrent gas pressure handling support.

Reported-by: Robert Helling <helling@atdotde.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-30 21:28:34 -07:00
Linus Torvalds
8f0d71ce2b 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@archlinux.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-30 16:37:45 -07:00
Linus Torvalds
92b1c318bd Fix manual pressures for cylinders with no gas switches
"If it hasn't been tested, it doesn't work".

All my testing of the multiple sensor pressures have been with some
reasonably "interesting" dives: they actually *have* sensor pressures.

But that test coverage means that I missed the truly trivial case of
just having manual pressures for a single cylinder.

Because there's only a single cylinder, it doesn't have any cylinder
changes, and because there were no cylinder changes, it never filled in
the use range for that cylinder.

So then it never showed the pressure profile at all.

Duh.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-28 21:50:25 -07:00
Linus Torvalds
df1bd0015a Calculate momentary SAC rates with the right gases
The momentary SAC rate got broken by the multiple ressure handling too,
and always used just the first cylinder.

This uses the new "get_gasmix()" helper to see what you're breathing,
and will do the SAC rate over all the cylinders that contain that gas.
So it should now DTRT even for sidemount diving (assuming you had the
same gas in the sidemount cylinders).

NOTE! We could just do the SAC rate over *all* the gases you have
pressures for, and maybe that's the right thing to do.  The ones you are
not breating from shouldn't have their pressure change.  But maybe some
people add their drysuit argon gas to the gas list?

So this may need more work, but it's a step in the right direction.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-28 21:50:23 -07:00
Linus Torvalds
defa71256f Use the right gasmix for deco calculations
In commit e1b880f4 "Profile support for multiple concurrent pressure
sensors" I had mindlessly hacked away at some of the sensor lookups from
the plot entries to make it all build, and forgotten about my butchery.

Thankfully Jan and Davide noticed in their multi-cylinder deco dives
that the deco calculations were no longer correct.

This uses the newly introduced "get_gasmix()" helper to look up the
currently breathing gasmix, and fixes the deco calculations.

Reported-and-tested-by: Jan Mulder <jlmulder@xs4all.nl>
Reported-by: Davide DB <dbdavide@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-28 21:50:20 -07:00
Linus Torvalds
e1b880f444 Profile support for multiple concurrent pressure sensors
This finally handles multiple cylinder pressures, both overlapping and
consecutive, and it seems to work on the nasty cases I've thrown at it.

Want to just track five different cylinders all at once, without any
pesky gas switch events? Sure, you can do that.  It will show five
different gas pressures for your five cylinders, and they will go down
as you breathe down the cylinders.

I obviously don't have any real data for that case, but I do have a test
file with five actual cylinders that all have samples over the whole
course of the dive.  The end result looks messy as hell, but what did
you expect?

HOWEVER.

The only way to do this sanely was

 - actually make the "struct plot_info" have all the cylinder pressures
   (so no "sensor index and pressure" - every cylinder has a pressure for
   every plot info entry)

   This obviously makes the plot_info much bigger. We used to have
   MAX_CYLINDERS be a fairly generous 8, which seems sane. The planning
   code made that 8 be 20. That seems questionable. But whatever.

   The good news is that the plot-info should hopefully get freed, and
   only be allocated one dive at a time, so the fact that it is big and
   nasty shouldn't be a scaling issue, though.

 - the "populate_pressure_information()" function had to be rewritten
   quite a bit. The good news is that it's actually simpler now, although
   I would not go so far as to really call it simple. It's still
   complicated and suble, but now it explicitly just does one cylinder at
   a time.

   It *used* to have this insanely complicated "keep track of the pressure
   ranges for every cylinder at once". I just couldn't stand that model
   and keep my sanity, so it now just tracks one cylinder at a time, and
   doesn't have an array of live data, instead the caller will just call
   it for each cylinder.

 - get rid of some of our hackier stuff, like the code that populates the
   plot_info data code with the currently selected cylinder number, and
   clears out any other pressures. That obviously does *not* work when you
   may not have a single primary cylinder any more.

Now, the above sounds like all good things. Yeah, it mostly is.

BUT.

There's a few big downsides from the above:

 - there's no sane way to do this as a series of small changes.

   The change to make the plot_info take an array of cylinder pressures
   rather than the sensor+pressure model really isn't amenable to "fix up
   one use at a time". When you switch over to the new data structure
   model, you have to switch over to the new way of populating the
   pressure ranges. The two just go hand in hand.

 - Some of our code *depended* on the "sensor+pressure" model. I fixed all
   the ones I could sanely fix. There was one particular case that I just
   couldn't sanely fix, and I didn't care enough about it to do something
   insane.

   So the only _known_ breakage is the "TankItem" profile widget. That's
   the bar at the bottom of the profile that shows which cylinder is in
   use right now. You'd think that would be trivial to fix up, and yes it
   would be - I could just use the regular model of

     firstcyl = explicit_first_cylinder(dive, dc)
     .. then iterate over the gas change events to see the others ..

   but the problem with the "TankItem" widget is that it does its own
   model, and it has thrown away the dive and the dive computer
   information. It just doesn't even know. It only knows what cylinders
   there are, and the plot_info. And it just used to look at the sensor
   number in the plot_info, and be done with that. That number no longer
   exists.

 - I have tested it, and I think the code is better, but hey, it's a
   fairly large patch to some of the more complex code in our code base.
   That "interpolate missing pressure fields" code really isn't pretty. It
   may be prettier, but..

Anyway, without further ado, here's the patch. No sign-off yet, because I
do think people should look and comment. But I think the patch is fine,
and I'll fix anythign that anybody can find, *except* for that TankItem
thing that I will refuse to touch. That class is ugly. It needs to have
access to the actual dive.

Note how it actually does remove more lines than it adds, and that's
despite added comments etc. The code really is simpler, but there may be
cases in there that need more work.

Known missing pieces that don't currently take advantage of concurrent
cylinder pressure data:

 - the momentary SAC rate coloring for dives will need more work

 - dive merging (but we expect to generally normally not merge dive
   computers, which is the main source of sensor data)

 - actually taking advantage of different sensor data from different
   dive computers

But most of all: Testing.  Lots and lots of testing to find all the
corner cases.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-27 14:45:58 -07:00
Linus Torvalds
1e38d9239a Start cleaning up sensor indexing for multiple sensors
This is a very timid start at making us actually use multiple sensors
without the magical special case for just CCR oxygen tracking.

It mainly does:

 - turn the "sample->sensor" index into an array of two indexes, to
   match the pressures themselves.

 - get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index},
   since a CCR dive should now simply set the sample->sensor[] indices
   correctly instead.

 - in a couple of places, start actually looping over the sensors rather
   than special-case the O2 case (although often the small "loops" are
   just unrolled, since it's just two cases.

but in many cases we still end up only covering the zero sensor case,
because the CCR O2 sensor code coverage was fairly limited.

It's entirely possible (even likely) that this migth break some existing
case: it tries to be a fairly direct ("stupid") translation of the old
code, but unlike the preparatory patch this does actually does change
some semantics.

For example, right now the git loader code assumes that if the git save
data contains a o2pressure entry, it just hardcodes the O2 sensor index
to 1.

In fact, one issue is going to simply be that our file formats do not
have that multiple sensor format, but instead had very clearly encoded
things as being the CCR O2 pressure sensor.

But this is hopefully close to usable, and I will need feedback (and
maybe test cases) from people who have existing CCR dives with pressure
data.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 16:33:19 -07:00
Linus Torvalds
11a0c0cc70 Unify sample pressure and o2pressure as pressure[2] array
We currently carry two pressures around for all the samples and plot
info, but the second pressure is reserved for CCR dives as the O2
cylinder pressure.

That's kind of annoying when we *could* use it for regular sidemount
dives as the secondary pressure.

So start prepping for that instead: don't make it "pressure" and
"o2pressure", make it just be an array of two pressure values.

NOTE! This is purely mindless prepwork.  It literally just does a
search-and-replace, keeping the exact same semantics, so "pressure[1]"
is still just O2 pressure.

But at some future date, we can now start using it for a second sensor
value for sidemount instead.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-20 17:32:54 -07:00
Robert C. Helling
5f5e52fb46 Preserve VPM-B state in profile display
This fixes a but reported by Willem in the display of VPMB
ceilings for logged dives.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-06-22 10:39:37 +09:00
Dirk Hohndel
c6bc88b50d Fix some warnings
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-27 07:21:37 -07:00
Robert C. Helling
05a7fe1d40 Gas denisity display improvement
This combines the display with EADD since this is the same
value with a different unit. And show it for air dives as
well.

Suggested by Jan Mulder & Anton Lundin

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-05-26 15:52:04 -07:00
Robert C. Helling
bb6ceba4ac Compute and display gas density
This appears to be critical for work of breathing so it might be
worthwhile to compute. So far only in infobox.

For background, see

https://www.youtube.com/watch?v=QBajM3xmOtc

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-05-26 15:52:04 -07:00
Robert C. Helling
7b18be2a50 Adopt planner state caching to new struct
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-05-26 15:44:36 -07:00
Robert C. Helling
57ee5a5477 Assemble global state of planner in a struct
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-05-26 15:44:36 -07:00
Dirk Hohndel
b368ecd5aa Add SPDX header to remaining core files
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29 13:32:55 -07:00
Martin Měřinský
4f96afff99 Safetystop > Safety stop 2017-03-13 10:28:06 -07:00
Dirk Hohndel
08284275e7 Merge branch 'master' of https://github.com/dje29/subsurface 2017-03-11 08:41:41 -08:00
Martin Měřinský
a9d361574e unkn > unknown 2017-03-11 08:09:07 -08:00
Martin Měřinský
9b93397ec2 SAC: %.*f%s/min versus SAC:%.*f %s 2017-03-11 08:09:07 -08:00
Jeremie Guichard
2b06a0b223 Fix potential double/float to int rounding errors
Not using lrint(f) when converting double/float to int
creates rounding errors.
This error was detected by TestParse::testParseDM4 failure
on Windows. It was creating rounding inconsistencies
on Linux too, see change in TestDiveDM4.xml.

Enable -Wfloat-conversion for gcc version greater than 4.9.0

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2017-03-09 23:07:30 +07:00