aboutsummaryrefslogtreecommitdiffstats
path: root/core/planner.c
AgeCommit message (Collapse)Author
2020-10-25cleanup: move interpolate inline function to its own header fileGravatar Berthold Stoeger
This is not really related to struct dive, so let's move it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: split out divecomputer functions from dive.cGravatar Berthold Stoeger
Since dive.c is so huge, split out divecomputer-related functions into divecomputer.[c|h], sample.[c|h] and extradata.[c|h]. This does not give huge compile time improvements, since struct dive contains a struct divecomputer and therefore dive.h has to include divecomputer.h. However, it make things distinctly more clear. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: break out event-related code into event.[c|h]Gravatar Berthold Stoeger
In an effort to reduce the size of dive.h and dive.c, break out the event related functions. Moreover event-names were handled by the profile-code, collect that also in the new source files. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-21Bailout segment is part of bottom timeGravatar Robert C. Helling
The clock is only valid in ascent. In each cycle of the 'critial volume algorithm' it re-initialized to the bottom time at the beginning of deco. So the time spent on bailout should be added to this bottom time. Thanks to Coverty for spotting this. Coverity-scan: CID-362079 Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-09-13Disable SAC factor setting for CCR divesGravatar Robert C. Helling
The SAC factor is only used for minimal gas calculations which don't make sense in the CCR context. Additionally, make bailout stop for at least minimum switch time or problem solving time. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-05-01cleanup: move declaration of utc_mk* functions to new subsurface-time.h headerGravatar Berthold Stoeger
No point in slurping in all of dive.h for translation units that only want to do some time manipulation without ever touching a dive. Don't call the header "time.h", because we don't want to end up in a confusion with the system header of the same name. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01cleanup: move dive_table from dive.h to divelist.hGravatar Berthold Stoeger
This allows us to decouple dive.h and divelist.h, a small step in include disentangling. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01core: create fake cylinder at end of cylinder table (hack!)Gravatar Berthold Stoeger
When we had fixed-sized cylinder arrays, the planner used the last empty cylinder for "surface air". This was not recognized by the UI as a separate cylinder, because "empty cylinder" was the sentinel for the end of the table. The conversion to dynamically sized cylinder tables broke this code: everytime the surface segment is changed, a new dummy cylinder is added, which is visible in the UI. As a very temporary stop-gap fix, emulate the old code by creating a cylinder and then setting the end-of-table to before that cylinder. This means that we have to loosen the out-of-bound checks. That's all very scary and should be removed as soon as possible. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01core: always keep an empty cylinder at the end of the cylinder arrayGravatar Berthold Stoeger
This will be temporarilly used by the planner to mark consumption of air at the surface. Do this by creating a new function add_cylinder, which replaces add_to_cylinder_table() and takes care of always adding a dummy cylinder at the end of the table. Make the original add_to_cylinder_table() local, so that it cannot be accessed anymore. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: use SAMPLE_EVENT_BOOKMARK in add_event() callsGravatar Berthold Stoeger
In two cases we were passing the magic value 8 instead of the symbolic SAMPLE_EVENT_BOOKMARK. Use the symbolic version instead. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: move fill_default_cylinder from planner.c to equipment.cGravatar Berthold Stoeger
Moreover, move the declaration from dive.h to equipment.h. The result is a) more consistent and b) more logical. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-01-10code cleanup: introduce empty_cylinder constantGravatar Dirk Hohndel
This deals with the issue of initializing structs in C++. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-11-09Cylinders: access cylinders with get_cylinder()Gravatar Berthold Stoeger
Instead of accessing the cylinder table directly, use the get_cylinder() function. This gives less unwieldy expressions. But more importantly, the function does bound checking. This is crucial for now as the code hasn't be properly audited since the change to arbitrarily sized cylinder tables. Accesses of invalid cylinder indexes may lead to silent data-corruption that is sometimes not even noticed by valgrind. Returning NULL instead of an invalid pointer will make debugging much easier. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Core: remove MAX_CYLINDERS restrictionGravatar Berthold Stoeger
Instead of using fixed size arrays, use a new cylinder_table structure. The code copies the weightsystem code, but is significantly more complex because cylinders are such an integral part of the core. Two functions to access the cylinders were added: get_cylinder() and get_or_create_cylinder() The former does a simple array access and supposes that the cylinder exists. The latter is used by the parser(s) and if a cylinder with the given id does not exist, cylinders up to that id are generated. One point will make C programmers cringe: the cylinder structure is passed by value. This is due to the way the table-macros work. A refactoring of the table macros is planned. It has to be noted that the size of a cylinder_t is 64 bytes, i.e. 8 long words on a 64-bit architecture, so passing on the stack is probably not even significantly slower than passing as reference. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-03Analyze gasswitches in CCR bailoutGravatar Robert C. Helling
The test if we have to create gas switches wasn't yet aware of the bailout option. Reported-by: Dennis Arreborg <dennis@arreborg.eu> Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-09-11Show correct notes entry when switching on stopsGravatar Robert C. Helling
When gas switching only on stops is selected, the notes showed an extra line at the not realized stop depth. This eliminates it. It also makes sure there are no 0 second spurious entries. And gas switching takes more than zero time (otherwise we would have to print a line of zero duration for at the gas switch depth). Reported-by: tormento <turment@gmail.com> Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-09-10Cleanup: remove global disclaimer variableGravatar Berthold Stoeger
That was used to store the disclaimer of the last plan. The functionality was disfunctional for a long time, therefore remove the variable. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-26Show surface degassing in the planner only when configured time != 0Gravatar Stefan Fuchs
This prevents from useless "Air" tag in profile when this feature is not used. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2019-08-08Planner: pass dive to enough_gas()Gravatar Berthold Stoeger
Enough gas was checking the currently displayed dive instead of the dive to be planned. Not good in a multi-threaded context. Pass the actual dive instead. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08Planner: pass dive / cylinder pair to track_ascent_gas()Gravatar Berthold Stoeger
Pass the dive to be planned to track_ascent_gas and don't use the displayed_dive. For convenience, pass the cylinder-id, since the function can now access the cylinder of the dive by itself. This makes the callers less verbose. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08Planner: pass dive to analyze_gaslist()Gravatar Berthold Stoeger
Use the actual planned dive, not the displayed dive in analyze_gaslist(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08Planner: fix comment for create_dive_from_plan()Gravatar Berthold Stoeger
The function comment talks about overwriting displayed_dive, when in reality the function overwrites a passed in dive. Also fix a debug-call which dumped the displayed_dive, not the actual dive to stdout. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08Core: pass dive, cylinder-id to fill_default_cylinderGravatar Berthold Stoeger
The fill_default_cylinder() function calculated the MOD based on the currently displayed dive. This does not seem to make sense: - When importing dives, why would we care about the altitude and salinity of the currently displayed dive, possibly from a different trip. - The planner is supposed to be thread-safe and should not touch global variables. Of course this means that the importing-functions have to fill out altitude and salinity before creating the default cylinder, but this is their problem. For a freshly created dive they will get the default values, which still seems less random than the values from the displayed dive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08Planner: use planner's dive in interpolate_transition()Gravatar Berthold Stoeger
Instead of passing the global displayed_dive to calc_crushing_pressure(), use the dive the planner is working on. A small step in making the planner thread-safe. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08Parser: remove global stateGravatar Berthold Stoeger
The parser had global state in the form of a linear regression and the "plot_depth" variable. Collect that in the deco_state struct and pass it down the call-chain. Move out the code to update the regression data to not bother other callers of tissue_tolerance_calc(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-08-08Cleanup: remove unused function printdecotableGravatar Berthold Stoeger
It is unclear where this function has ever been used. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08Cleanup: make local functions in planner.c of static linkageGravatar Berthold Stoeger
A number of functions were not used outside of planner.c. Make them static. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08Cleanup: move planner/deco related declarations planner/deco.hGravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08Cleanup: move error reporting function declarations to errorhelper.hGravatar Berthold Stoeger
Move the declarations of the "report_error()" and "set_error_cb()" functions and the "verbose" variable to errorhelper.h. Thus, error-reporting translation units don't have to import the big dive.h header file. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-28Planner: Wait minimum switch time when bailing out to OCGravatar Robert C. Helling
Bailing out does not happen instantly. Rather wait for the minimum stop switch duration before ascending. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-06-19Cleanup: remove unused parameter used from find_best_gasmix_match()Gravatar Berthold Stoeger
The last direct user of the used parameter was removed in 16276faa45279817e363367550a6a37c179251f7, the last actual user in e2bbd0ceecff7193bb272430fbebfc4b02dd67c3. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19Cleanup: move function declaration into header fileGravatar Berthold Stoeger
The function declarations of regressiona(), regressionb() and reset_regression() were given in an independent translation unit. Move them into the proper header file. To ensure consistent function signatures is the whole point of header files, after all. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19Cleanup: remove unused global variables plangflow and plangfhighGravatar Berthold Stoeger
The last user was removed in 1093d6235b5657746f2cb4524ed08cf13c80c3bb. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19Cleanup: make lookup table in planner.c of static linkageGravatar Berthold Stoeger
The lookup tables decostoplevels_metric and decostoplevels_imperial in planner.c were not used outside the translation unit. Make them static. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-03-29Make sure surface air is not considered a deco gasGravatar Robert C. Helling
it creapt in through the gaschange events. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-03-29Add UI element for final surface segment in plannerGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-03-29Show a bit of surface degassing in the plannerGravatar Robert C. Helling
to display the deco parameters at the surface, in particular tissue saturation and heat map. Suggeted-by: Matthias Heinrichs <info@heinrichsweikamp.com> Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-03-18Core: change FIXME languageGravatar Robert C. Helling
Addresses LGTM.com issue. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-01-13Planner: Add checkbox to force OC bailoutGravatar Robert C. Helling
This adds a checkbox for rebreather modes of the planner that force the ascent to be in OC mode. Before, one had to add a one minute last segment with the mode change but this is not practical when manually searching for the maximal bottom time given gas reserves. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-08-23Cleanup: const-ify functions taking pointers to eventsGravatar Berthold Stoeger
This is another entry in the series to make more things "const-clean" with the ultimate goal of merge_dive() take const pointers. This concerns functions taking pointers to events and the fallout from making these const. The somewhat debatable part of this commit might be that get_next_event() is split in a two distinct (const and non-const) versions with different names, since C doesn't allow overloading. The linker should recognize that these functions are identical and remove one of them. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23Cleanup: pass gasmix by valueGravatar Berthold Stoeger
In a previous commit, the get_gasmix_* functions were changed to return by value. For consistency, also pass gasmix by value. Note that on common 64-bit platforms struct gasmix is the size of a pointer [2 * 32 bit vs. 64 bit] and therefore uses the same space on the stack. On 32-bit platforms, the stack use is probably doubled, but in return a dereference is avoided. Supporting arbitrary gas-mixes (H2, Ar, ...) will be such an invasive change that going back to pointers is probably the least of our worries. This commit is a step in const-ifying input parameters (passing by value is the ultimate way of signaling that the input parameter will not be changed [unless there are references to said parameter]). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23Cleanup: unify get_gas_at_time() and get_gasmix()Gravatar Berthold Stoeger
There were two functions for getting gas-mixes at a certain timestamp: - get_gasmix() for repeated queries. - get_gas_at_time() for a single query. Since the latter is a special case of the former, simply call the former in the latter. Moreover, rename to get_gasmix_at_time() for consistency. Replace on get_gasmix() call, which was outside of a loop by the corresponding get_gasmix_at_time() call. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>