Commit graph

137 commits

Author SHA1 Message Date
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
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