Commit graph

147 commits

Author SHA1 Message Date
Robert C. Helling
09bbd846da The planner should not always ascent from the depth of
the last manually entered waypoint but consider the
possibility that it should first top where we are
before the next stop depth has cleared.

Reported-by: David Carron

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2021-05-07 08:16:41 -07:00
Robert C. Helling
6b8a07f0d9 Planner: Depth dependent setpoint changes in CCR mode
We had a user request to allow for setpoint changes
at certain depths for CCR deco.

You can now enter a cylinder with name like
"SP 1.4" ('S' and 'P' and ' ' and a float) with
a switch depth and that cylinder is interpreted as
a depth dependent setpoint switch.

This user interface is a hack. But I believe that such
setpoint changes are similar enough to gas switches during
deco and should thus be handled in a simiar manner.

I would be happy to hear ideas how this could be made
less easter eggish.

Suggested-by: Justin Ashworth
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2021-02-26 08:42:30 -08:00
Berthold Stoeger
642d9c80b3 planner: pass in_planner argument to decoMode()
To remove reliance on global state, pass an "in_planner" argument
to decoMode(). Thus, calls to in_planner() can be removed.

This is a more-or-less automated change. Ultimately it would
probably be better to pass the current deco-mode to the affected
functions instead of calling decoMode() with an in_planner
parameter.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-17 07:26:55 -08:00
Berthold Stoeger
03a7e65cf0 planner: pass in_planner argument to clear_deco()
To remove reliance on global state, pass an "in_planner" argument
to clear_deco(). Thus, calls to in_planner() can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-17 07:26:55 -08:00
Berthold Stoeger
8103e947aa planner: pass in_planner argument to vpmb_next_gradient()
To remove reliance on global state, pass an "in_planner" argument
to vpmb_next_gradient(). Thus, calls to in_planner() can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-17 07:26:55 -08:00
Berthold Stoeger
93ecad1b04 planner: pass in_planner argument to add_segment()
To remove reliance on global state, pass an "in_planner" argument
to add_segment(). Thus, calls to in_planner() can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-17 07:26:55 -08:00
Berthold Stoeger
f728923c79 cleanup: move interpolate inline function to its own header file
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-25 13:59:52 -07:00
Berthold Stoeger
0e196310f9 cleanup: split out divecomputer functions from dive.c
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-25 13:59:52 -07:00
Berthold Stoeger
8212acc992 cleanup: break out event-related code into event.[c|h]
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-10-25 13:59:52 -07:00
Robert C. Helling
ee79080280 Bailout segment is part of bottom time
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-21 11:42:02 -07:00
Robert C. Helling
3426c6440c Disable SAC factor setting for CCR dives
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-09-13 13:51:07 -07:00
Berthold Stoeger
9c70261c0e cleanup: move declaration of utc_mk* functions to new subsurface-time.h header
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-01 09:42:31 -07:00
Berthold Stoeger
95284c026e cleanup: move dive_table from dive.h to divelist.h
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-01 09:42:31 -07:00
Berthold Stoeger
ffc3e598fa core: create fake cylinder at end of cylinder table (hack!)
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-01 12:36:28 +02:00
Berthold Stoeger
b949bad026 core: always keep an empty cylinder at the end of the cylinder array
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-05-01 12:36:28 +02:00
Berthold Stoeger
dee7fd9f30 cleanup: use SAMPLE_EVENT_BOOKMARK in add_event() calls
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-07 00:13:35 +02:00
Berthold Stoeger
36754d3399 cleanup: move fill_default_cylinder from planner.c to equipment.c
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-04-07 00:13:34 +02:00
Dirk Hohndel
cef30619d0 code cleanup: introduce empty_cylinder constant
This deals with the issue of initializing structs in C++.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-01-10 02:37:03 +09:00
Berthold Stoeger
794066b236 Cylinders: access cylinders with get_cylinder()
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-09 19:19:04 +01:00
Berthold Stoeger
7c9f46acd2 Core: remove MAX_CYLINDERS restriction
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-11-09 19:19:04 +01:00
Robert C. Helling
85c31f0303 Analyze gasswitches in CCR bailout
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-10-03 08:38:19 -07:00
Robert C. Helling
00c902d66c Show correct notes entry when switching on stops
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-11 14:55:33 +01:00
Berthold Stoeger
dd423bffb9 Cleanup: remove global disclaimer variable
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-09-10 21:31:21 +02:00
Stefan Fuchs
0e55739f03 Show surface degassing in the planner only when configured time != 0
This prevents from useless "Air" tag in profile when this feature is
not used.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2019-08-26 13:19:06 +02:00
Berthold Stoeger
e921715410 Planner: pass dive to enough_gas()
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-08 16:26:31 -07:00
Berthold Stoeger
7cfe1639b5 Planner: pass dive / cylinder pair to track_ascent_gas()
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-08 16:26:31 -07:00
Berthold Stoeger
ff40afc1d8 Planner: pass dive to analyze_gaslist()
Use the actual planned dive, not the displayed dive in analyze_gaslist().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08 16:26:31 -07:00
Berthold Stoeger
90ea46ff31 Planner: fix comment for create_dive_from_plan()
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-08 16:26:31 -07:00
Berthold Stoeger
00944f7a02 Core: pass dive, cylinder-id to fill_default_cylinder
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-08 16:26:31 -07:00
Berthold Stoeger
6ce4aeb04e Planner: use planner's dive in interpolate_transition()
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-08 16:26:31 -07:00
Berthold Stoeger
ddff68ddae Parser: remove global state
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-08 16:26:31 -07:00
Berthold Stoeger
852239e6de Cleanup: remove unused function printdecotable
It is unclear where this function has ever been used.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08 16:26:31 -07:00
Berthold Stoeger
3d4ef92717 Cleanup: make local functions in planner.c of static linkage
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-08 16:26:31 -07:00
Berthold Stoeger
52e5d9c605 Cleanup: move planner/deco related declarations planner/deco.h
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08 16:26:31 -07:00
Berthold Stoeger
5da09a21bb Cleanup: move error reporting function declarations to errorhelper.h
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-08-08 16:26:30 -07:00
Robert C. Helling
5c1446a87a Planner: Wait minimum switch time when bailing out to OC
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-28 15:58:52 +02:00
Berthold Stoeger
3e88bd686f Cleanup: remove unused parameter used from find_best_gasmix_match()
The last direct user of the used parameter was removed in
16276faa45, the last actual user in
e2bbd0ceec.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19 13:11:10 -07:00
Berthold Stoeger
e2937f0614 Cleanup: move function declaration into header file
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-19 13:11:10 -07:00
Berthold Stoeger
5514047b43 Cleanup: remove unused global variables plangflow and plangfhigh
The last user was removed in 1093d6235b.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19 13:11:10 -07:00
Berthold Stoeger
ef8c5cd9ab Cleanup: make lookup table in planner.c of static linkage
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-06-19 13:11:10 -07:00
Robert C. Helling
30746e5d3f Make sure surface air is not considered a deco gas
it creapt in through the gaschange events.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-03-29 06:51:12 -07:00
Robert C. Helling
178eaa9a67 Add UI element for final surface segment in planner
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-03-29 06:51:12 -07:00
Robert C. Helling
5e494ce761 Show a bit of surface degassing in the planner
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-29 06:51:12 -07:00
Robert C. Helling
3af4164d0c Core: change FIXME language
Addresses LGTM.com issue.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-03-18 19:40:32 -07:00
Robert C. Helling
2c794348c1 Planner: Add checkbox to force OC bailout
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>
2019-01-13 15:02:07 -08:00
Berthold Stoeger
605e1e19ed Cleanup: const-ify functions taking pointers to events
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-23 05:16:38 -07:00
Berthold Stoeger
360f07e453 Cleanup: pass gasmix by value
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-23 05:16:38 -07:00
Berthold Stoeger
5c4569247a Cleanup: unify get_gas_at_time() and get_gasmix()
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-23 05:16:38 -07:00
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