aboutsummaryrefslogtreecommitdiffstats
path: root/core/planner.c
AgeCommit message (Collapse)Author
2018-08-09Allow zero length segments in plannerGravatar Robert C. Helling
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-06-24Fix interpretation of dive mode changes upon replanGravatar Robert C. Helling
... 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-20equipment: sanitize 'tank_info' loop limitsGravatar Lubomir I. Ivanov
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-20core: add free_samples helperGravatar Dirk Hohndel
And use it in the UI and planner code. See #1411 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-28Planner: Don't store a setpoint unless we are in CCR modeGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-05-24core: replace (void) with UNUSED(x) and include ssrf.hGravatar jan Iversen
Unused parameters in C are "silenced" by adding UNUSED(x) Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-14Rename enum dive_comp_type to divemode_tGravatar Robert C. Helling
...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-14Planner: Make use divemode for consumed gas calculationGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-05-14Planner: Honor last manual divemodeGravatar Robert C. Helling
Start the decompression schedule in the divemode of the last manual section. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-05-14Fix divemode detection in plannerGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-05-14Fix a bug where the bailout events are not saved correctly.Gravatar Willem Ferguson
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-14Adapt the dive planner to do bailoutGravatar Willem Ferguson
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-14Add planner infra structure for bailoutGravatar Robert C. Helling
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-14Implement bailout outside of the dive plannerGravatar Willem Ferguson
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-14Core: introduce new subsurface-string headerGravatar Dirk Hohndel
First small step to shrinking dive.h. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-07Planner: Unify final ascent rates in plan() and fake_dc()Gravatar Berthold Stoeger
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-02-26Cleanup: Unify qthelper.h and qthelperfromc.hGravatar Berthold Stoeger
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-01-26Limit recreational dives to 6 hoursGravatar Robert C. Helling
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-19Improve profile display in plannerGravatar Willem Ferguson
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>
2017-12-17Cleanup: durations are now signedGravatar Dirk Hohndel
Somehow a whitespace fix snuck in here. Oops. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-17Unify float calulations: use doubleGravatar Berthold Stoeger
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-01Actually compute variations in backgroundGravatar Robert C. Helling
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-01Cut off excessive deco timesGravatar Robert C. Helling
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-11-25In planner.c remove unused variable o2break_doneGravatar Stefan Fuchs
Reported-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-25Localize global planner stateGravatar Robert C. Helling
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-25Run variations calculation in backgroundGravatar Robert C. Helling
but there are still side effects and thus it crashes. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-11-09Planner don't add minimum gas switch time more than onceGravatar Stefan Fuchs
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-08VPMB: calculate time of final ascent properlyGravatar Rick Walsh
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-08VPMB profile: use deco_time rather bottom_time from plannerGravatar Rick Walsh
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-08VPMB: calculate deco_time assuming final ascent always takes the same timeGravatar Rick Walsh
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-08VPM-B: move bottom_time into deco_stateGravatar Rick Walsh
Removing ext variable from profile.c should facilitate future performance gains Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-11-04Disable o2 break option if last stop is not at 6m/20ftGravatar Stefan Fuchs
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-04O2 breaks code enhancements and cleanupGravatar Stefan Fuchs
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-10-31When O2 breaking, add segment with current mix not with nextGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-10-31Don't do the minimal gaschanging stops during O2 breaktingGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-10-31Correct time bookkeeping when doing O2 breaksGravatar Robert C. Helling
These got mangled with previous changes to stop length determination. Fixes #662 Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-10-30whitespace (planner.c)Gravatar Rick Walsh
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-10-30VPMB profile: use bottom_time to calculate deco_time in plannerGravatar Rick Walsh
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-18init_deco correctly identify previous dives and report overlapping divesGravatar Stefan Fuchs
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-16Tidy up code in planner.c - create_dive_from_plan()Gravatar Stefan Fuchs
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-16Fix dump_plan debug codeGravatar Stefan Fuchs
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-16Planner creating dive from plan: No pressure for 1st sample with new gasGravatar Stefan Fuchs
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-16In planner prefer best_first_ascend_cylinder for gas breaksGravatar Stefan Fuchs
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-16Don't confuse cyl with same gasmix with best_first_ascend_gasGravatar Stefan Fuchs
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-01More VPMB state in special structureGravatar Robert C. Helling
... 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-09-20Remove option to apply GFlow at maxdepthGravatar Robert C. Helling
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-08-29Compute variations of plansGravatar Robert C. Helling
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-29Store a table of deco stops in plannerGravatar Robert C. Helling
... in addition to struct diveplan which combines all kinds of information Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-08-29Cache all Buehlmann factorsGravatar Robert C. Helling
not just the last one. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-08-29Allow for o2 breaks in binary search stop time finderGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de>