Commit graph

79 commits

Author SHA1 Message Date
jan Iversen
061be82e31 core: replace (void) with UNUSED(x) and include ssrf.h
Unused parameters in C are "silenced" by adding UNUSED(x)

Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-24 08:34:14 -07:00
Robert C. Helling
969dfee9ec Rename enum dive_comp_type to divemode_t
...as the usuage is not anymore about a computer but
a momentary dive mode. Rename the end indicator as well.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-05-14 23:47:00 +03:00
Willem Ferguson
2a2098bab2 Implement get_divemode() to find the divemode at a particular time
Replaced a rather cumbersome function that that did the above. Upon
the suggestion of Robert Helling who proposed a much shorter way,
this new function replaced the previous ones. This necessitated
changes to divelist.c, profile.c and plannernotes.c, as well as
dive.c/h.

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-05-14 23:47:00 +03:00
Willem Ferguson
cad4eb39c4 Implement get_divemode() to find the divemode at a particular time
Replaced a rather cumbersome function that that did the above. Upon
the suggestion of Robert Helling who proposed a much shorter way,
this new function replaced the previous ones. This necessitated
changes to divelist.c, profile.c and plannernotes.c, as well as
dive.c/h.

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-05-14 23:47:00 +03:00
Willem Ferguson
0e08c0870a Simplify the bailout detection functions.
Function peek_next_divemodechange() is redundant if get_next_divemodechange()
has one additional parameter. Calls to get_next_divemodechange() were
updated in divelist.c, plannernotes.c and profile.c.

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-05-14 23:47:00 +03:00
Willem Ferguson
27a0542220 Implement bailout outside of the dive planner
This is the second step for implementing bailout. The indirect
calls to fill_pressures through add_segment() (in deco.c) are
addressed. Bailout is now fully implemented in the dive log but
not in the dive planner.
1) The parameters to add_segment() are changed to take a
   divemode as the second last parameter, and not a *dive.
2) Call to add_segment() in profile.c and in divelist.c are
   adapted. In divelist.c some calls to add_segment were left
   using dc-> divemode instead of possible bailout. This appears
   tp be the most appropriate route.
3) The functions get_divemode_from_time() and get_next_divemodechange()
   in dive.c have had some small changes.
4) The calls to get_segment(0 in planner.c were changed to reflect
   the new parameter list, but not updated to reflect bailout. This
   is the next step.

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-05-14 23:47:00 +03:00
Willem Ferguson
cf377beb2e Incorporate bailout events in CCR & PSCR gas calculations.
This is a first step to interpret bailout events.
1) The event structures have a new attribute: divemode.
   Currently interpreted dive modes are OC, CCR, PSCR.
2) When doing fill_pressures(), the calculation is aware
   of divemode. When divemode is OC (==bailout), then
   the appropriate calculations of gas pressures are done.
3) Two new functions get_next_divemodechange() and
   get_divemode_at_time() are created to find divemode
   changes in the events linked list and to determine
   the dive mode at any point during the dive.
4) fill_pressures gets a small amendment to facilitate
   the correct calculations, depending on divemode.
The cases where fill_pressures() is used *outside the planner*
are changed. The result is that, for dives with bailout, the
correct gas pressures are shown on the dive profile. The
deco for bailout dives is not yet correct. This is the
next step.

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-05-14 23:47:00 +03:00
Dirk Hohndel
d577467f97 Core: introduce new subsurface-string header
First small step to shrinking dive.h.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-14 10:13:39 -07:00
Willem Ferguson
81a812539c Plot OC-pO2 graph for SCR dives
This commit allows plotting the OC-equivalent pO2 graph for PSCR
dives. This happens in both the cases where there is no external
O2-monitoring AND when there is external pO2 monitoring. The
calculations are only done for PSCR dives and is achieved as
follows:

1) Within plot-info create a pressure-t called OC_pO2 in
   profile.h and populate this variable with the open-circuit
   pO2 values in profile.c.
2) Create a new partialPressureGasItem ocpo2GasItem in
   profilewidget2.h and, in profilewidget2.cpp, initialise it
   to read the plot-info OC_pO2 values and enable its
   display by using the setVisible method. The
   diveplotdatamodel was also touched in order to achieve
   this.
3) Create a pref button that controls the display of OC-pO2 for SCR dives
4) Change the colour of the OC-pO2 grpah to orange
5) Change the connection of the crr_OC_pO2 signal to be appropriate
6) rename the OC_pO2 attribute to scr_OC-pO2

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-04-28 20:11:22 +03:00
Robert C. Helling
ece714556f Look for actual isobaric counter diffusion
Identify segements that fullfill the folllowing criteria for
the leading compartment:

He is off-gasing while N2 is on-gasing
Overall there is on-gasing

Add a line to the info box for those segments

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-04-11 21:15:38 +02:00
Berthold Stoeger
5afe1a53d8 Cleanup: Move *_loc formatting functions into new format.cpp file
qthelper.cpp is already quite voluminous. Move the recently
introduced localized versions of (v)snprintf() and put_format()
into their own translation unit.

Moreover, adopt C-style semantics for asprintf_loc(). This function
will be used to remove fixed-size buffers in core/plannernotes.c.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-09 11:29:43 -07:00
Stefan Fuchs
b38eb45b29 Profile heartrate: Nicer min/max values and tic distance
Correct a bug in finding the minimum heartrate.

Use the minimum and maximum heartrate value to set min/max and
tic distance for the heartrate axis in the profile.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-03-19 15:44:02 -07:00
Anton Lundin
8de887c8ee Treat a PSCR dive with sensors more like a CCR dive
PSCR dives with o2 sensors are more like CCR dives. The math is exactly
the same, its just a different diluent and a different po2.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2018-03-13 18:54:16 +02:00
Stefan Fuchs
5d32fd0723 Cosmetic modifications in profile delta sample string
Consistently do not use a space between value and unit.
Consistently do not use a space between "name:" and value.
Add "/min" for SAC rate.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-03-06 13:06:52 +02:00
Berthold Stoeger
57c3e43df9 Localization: implement *_loc() functions in profile.c
Replace snprintf() and put_format() by snprintf_loc() and
put_format_loc(), respectively to localize formatting of
integers and floats.

Acked-by: Stefan Fuchs <sfuchs@gmx.de>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 16:23:55 +01:00
Berthold Stoeger
cd5e17cf79 Cleanup: Unify qthelper.h and qthelperfromc.h
Since all qt-helpers are defined in qthelper.cpp, there seems to be
no reason to have two include files. By unifying the two files,
duplication and inconsistencies are removed. The C++-only part is
simply compiled away with #ifdefs.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-26 19:06:02 +02:00
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