Commit graph

99 commits

Author SHA1 Message Date
Robert C. Helling
b9fcc9543d Allow zero length segments in planner
Those are needed to indicate bailout or set point switches
at the beginning of  the ascend.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-08-09 08:46:57 -07:00
Robert C. Helling
8406cbf187 Fix interpretation of dive mode changes upon replan
... by taking into acount that dive planner points refer
to the sement before the waypoint (while change mode
events are concerned with the future of a waypoint).

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-06-24 09:35:55 +02:00
Lubomir I. Ivanov
769aca9e95 equipment: sanitize 'tank_info' loop limits
In a number of places the global 'tank_info' array
is being iterated based on a 'tank_info[idx].name != NULL'
condition.

This is dangerous because if the user has added a lot of tanks,
such loops can reach 'tank_info[MAX_TANK_INFO]'. This is an
out of bounds read and if the 'name' pointer there happens to be
non-NULL, passing that address to a peace of code that tries
to read it (like strlen()) would either SIGSEGV or have undefined
behavior.

Clamp all loops that iterate 'tank_info' to MAX_TANK_INFO.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2018-06-20 09:30:58 +09:00
Dirk Hohndel
a5380bb741 core: add free_samples helper
And use it in the UI and planner code.

See #1411

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-06-20 09:27:11 +09:00
Robert C. Helling
2c53eef50e Planner: Don't store a setpoint unless we are in CCR mode
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-05-28 09:57:00 +02:00
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
Robert C. Helling
0b836f12fc Planner: Make use divemode for consumed gas calculation
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-05-14 23:47:00 +03:00
Robert C. Helling
d018ceb852 Planner: Honor last manual divemode
Start the decompression schedule in the divemode
of the last manual section.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-05-14 23:47:00 +03:00
Robert C. Helling
09da42f819 Fix divemode detection in planner
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-05-14 23:47:00 +03:00
Willem Ferguson
5bac32a1b5 Fix a bug where the bailout events are not saved correctly.
The bailout events in the planner are not saved correctly.
My oversight. This commits corrects the bug

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-05-14 23:47:00 +03:00
Willem Ferguson
4c73ada121 Adapt the dive planner to do bailout
Ensure that calls to add_segment() all have a appropriate divemode
for that part of the dive plan. In the case of plan(), the existing
variable 'divemode' was directly passed to add_segment. For the
functions interpolate_transition() and trial_ascent(), the divemode
was obtained by including it in the parameter list of the function
and divemode supplied by the calling function.

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-05-14 23:47:00 +03:00
Robert C. Helling
69de9d8f98 Add planner infra structure for bailout
Add a divemode column to the planner model and a
corresponding field to struct divepoint and fill it
in the corresponding functions.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
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
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
Berthold Stoeger
ac1ec486ae Planner: Unify final ascent rates in plan() and fake_dc()
When generating fake profiles for manually entered dives, fake_dc() and
plan() used different final ascent rates of 5 m/min and 4.5 m/min,
respectively. This led to dives that were 6 seconds longer than entered
by the user and to confusion. See #554.

Therefore, use the same ascent rate taken from the preferences field
flag.ascratelast6m in both cases.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-07 21:17:22 +03: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
Robert C. Helling
c6d626c618 Limit recreational dives to 6 hours
Otherwise, with large gradient factors, one can have infinite NDL
which result in an infinite loop when no gas is set.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-01-26 07:04:45 +01:00
Willem Ferguson
9a8bab21c9 Improve profile display in planner
This patch allows the planner to save the last manually-entered
dive planner point of a dive plan. When the plan has been saved
and re-opened for edit, the time of the last-entered dive planner
point is used to ensure that dive planning continues from the same
point in the profile as was when the original dive plan was saved.
Mechanism:

1) In dive.h, create a new dc attribute dc->last_manual_time
   with data type of duration_t.
2) In diveplanner.c, ensure that the last manually-entered
   dive planner point is saved in dc->last_manual_time.
3) In save-xml.c, create a new XML attribute for the <divecomputer>
   element, named last-manual-time. For dive plans, the element would
   now look like:
   <divecomputer model='planned dive' last-manual-time='31:17 min'>
4) In parse-xml.c, insert code that recognises the last-manual-time
   XML attribute, reads the time value and assigns this time to
   dc->last_manual_time.
5) In diveplannermodel.cpp, method DiveplannerPointModel::loadfromdive,
   insert code that sets the appropriate boolean value to dp->entered
   by comparing newtime (i.e. time of dp) with dc->last_manual_time.
6) Diveplannermodel.cpp also accepts profile data from normal dives in
   the dive log, whether hand-entered or loaded from dive computer. It
   looks like the reduction of dive points for dives with >100 points
   continues to work ok.
The result is that when a dive plan is saved with manually entered
points up to e.g. 10 minutes into the dive, it can be re-opened for edit
in the dive planner and the planner re-creates the plan with manually
entered points up to 10 minutes. The rest of the points are "soft"
points, shaped by the deco calculations of the planner.

Improvements: Improve code for profile display in dive planner

This responds to #1052.
Change load-git.c and save-git.c so that the last-manual-time is
also saved in the git-format dive log.

Several stylistic changes in text for consistent C source code.

Improvement of dive planner profile display:

Do some simplification of my alterations to diveplannermodel.cpp

Two small style changes in planner.c and diveplannermodel.cpp
as requested ny @neolit123

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-19 12:38:11 +02:00
Dirk Hohndel
6b80b41c7c Cleanup: durations are now signed
Somehow a whitespace fix snuck in here. Oops.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-17 10:25:01 -08:00
Berthold Stoeger
a748e7f239 Unify float calulations: use double
Internal floating point (FP) calculations should be performed using double
unless there is a very good reason. This avoids headaches with conversions.
Indeed, the vast majority of FP calculations were already done using double.
This patch adapts most remaining calculations. Not converted where things
that were based on binary representations and variables which weren't used
anyway.

An analysis of all instances follows:

core/plannernotes.c, l.404:

This was a comparison between two floats. On the left side, first an integer
was cast to float then multiplied with and integer and divided by a constant
double. The right hand side was an integer cast to a float. Simply divide by
1000.0 first to convert to double and continue with calculations. On the right
hand side, remove the cast, because the integer will be implicitely cast to
double for comparison. This conversion actually emits less instructions,
because no conversion to double and back is performed.

core/planner.c, l.613:

Same analysis as previous case.

subsurface-desktop-main.cpp, l.155:

A local variable representing the version OpenGL version. Turn this into
integer logic. Not only does this avoid dreaded FP rounding issues, it also
works correctly for minor version > 10 (not that such a thing is to be
expected anytime soon).

abstractpreferenceswidget.[h/cpp]:

A widget where the position is described as a float. Turn into double.

desktop-widgets/divelogexportdialog.cpp, l.313:

total_weight is described as float. Use double arithmetics instead. This
instance fixes a truncation warning emitted by gcc.
2017-12-17 09:02:44 -08:00
Robert C. Helling
a9703628c4 Actually compute variations in background
This reenables the computation of plan variations but now in a separate
thread. Once finieshed, a signal is sent to update the notes.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-01 15:47:51 -08:00
Robert C. Helling
f159792b80 Cut off excessive deco times
before we run out of memory. Diving deep with air and small GFhigh
can cause those (try GF 30/70 at 75m with 25+min bottom time)

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-01 15:47:51 -08:00
Stefan Fuchs
3d421584aa In planner.c remove unused variable o2break_done
Reported-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-25 15:40:04 -08: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
Stefan Fuchs
a013e35ff4 Planner don't add minimum gas switch time more than once
Avoid adding the minimum gas switch time more than once even
if we skip some available deco gas.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-09 10:43:03 +01:00
Rick Walsh
13b909cf82 VPMB: calculate time of final ascent properly
Commit d15779a calculates final stop based on stoplevels[2], but if final stop
is 6m/20ft, we should use stoplevels[3].  This fixes it.

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
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
ac25b238dd Disable o2 break option if last stop is not at 6m/20ft
Disable the possibility to plan o2 breaks of option
"last stop at 6m/20ft" is not set.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-04 14:51:02 +01:00
Stefan Fuchs
3ae0b5cbdd O2 breaks code enhancements and cleanup
Remove unused variables o2time and breaktime or convert into boolean.

Never consider minimum gas switch time when switching to o2.
Reflect this behavior also in the UI.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-04 14:51:02 +01:00
Robert C. Helling
eafe19559a When O2 breaking, add segment with current mix not with next
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-10-31 16:33:32 -07:00
Robert C. Helling
c9c90afd3e Don't do the minimal gaschanging stops during O2 breakting
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-10-31 16:33:32 -07:00
Robert C. Helling
0f458023d9 Correct time bookkeeping when doing O2 breaks
These got mangled with previous changes to stop length determination.

Fixes #662

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-10-31 16:33:32 -07:00
Rick Walsh
eb62ced8a1 whitespace (planner.c)
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
Stefan Fuchs
4158a4c7de init_deco correctly identify previous dives and report overlapping dives
When changing the date/time of a dive in the planner the dive may end
up in a totaly new position in respect to date/time of other dives in
dive list table. It can be moved to the past or the future before or after
other existing dives. It also could overlap with an existing dive.

This change enables identification of a new "virtual" dive list position
and based on this starts looking for previous dives.
Then it (as before the change) does init the deco calculation with any
applicable previous dive and surface interval.
If some of these applicable dives overlap it returns a neg. surface time
which is then used in the planner notes to prohibit display of results.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-18 23:19:13 +02:00
Stefan Fuchs
180e51a906 Tidy up code in planner.c - create_dive_from_plan()
Tidy up the code which creates the first sample for time = 0 to make
clear that the info for this does NOT come from the first planner point (dp).
No functional change.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-16 18:23:27 +02:00
Stefan Fuchs
f812dc5d9b Fix dump_plan debug code
This fixes some debug code to dump the diveplan which is usually
not compiled and used.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-16 18:23:27 +02:00
Stefan Fuchs
4fa576526f Planner creating dive from plan: No pressure for 1st sample with new gas
In the planner when a dive is created from the diveplan every first
sample with a new gas shouldn't have a pressure value added.
Otherwise the interpolation code for the pressure graph in the profile
will draw the pressure graph incorrectly.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-16 18:23:27 +02:00
Stefan Fuchs
3e67bfaea6 In planner prefer best_first_ascend_cylinder for gas breaks
Up to now the cylinder for gas breaks was hardcoded to first cylinder.
With this change the best_first_ascend_cylinder is used if its
O2 is <=32%.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-16 17:14:17 +02:00
Stefan Fuchs
80a2cd7b1b Don't confuse cyl with same gasmix with best_first_ascend_gas
When calculating the dive plan in the planner don't accidently use
another gas with same gasmix instead of the gas stored as
"best_first_ascend_gas".
This is important if you have e.g. a bottom stage and back gas with
same gas mix because then you always want to start your ascent with
the gas you used in last entered dive planner point.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-16 17:14:17 +02: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
Robert C. Helling
5b080bedde Remove option to apply GFlow at maxdepth
This option should have never been there. This is not how
gradient factors are supposed to work. It would only trick
users to use the wrong value..

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-09-20 08:54:41 -07:00
Robert C. Helling
2832141d2c Compute variations of plans
Print out partial derivatives of stop times with respect to
variation of depth and duratin of last manual segment.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-08-29 06:49:44 -07:00
Robert C. Helling
e6545a7b0f Store a table of deco stops in planner
... in addition to struct diveplan which combines all kinds
of information

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-08-29 06:49:44 -07:00
Robert C. Helling
456e2cec89 Cache all Buehlmann factors
not just the last one.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-08-29 06:49:44 -07:00
Robert C. Helling
515b7b5fea Allow for o2 breaks in binary search stop time finder
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-08-29 06:49:44 -07:00