Commit graph

278 commits

Author SHA1 Message Date
Jan Darowski
499ec9af2f VPM-B: Add surface decompression time.
Now, we calculate the volume of free gas not only based on the deco
time but also time on the surface, needed for the full desaturation.

Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-08-15 14:32:36 +02:00
Jan Darowski
c0fde4f50f VPM-B: Add Boyles compensation to the planner.
Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-08-15 14:21:18 +02:00
Jan Darowski
a3e87bf1a1 VPM-B: Fix trial_ascent() for vpm-b.
Previously, current depth was checked, instead of the depth after the move.

Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-08-15 13:45:42 +02:00
Lubomir I. Ivanov
342479586d Planner: use the heap for note buffers
The default stack size on Windows per thread is 1024kb.
Using the heap prevents a stack overflow in add_plan_to_notes().

The alternative is to tell the linker to use N bytes of stack:
-Wl,--stack,N

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-10 00:04:17 -07:00
Robert C. Helling
e79cae577d Decrease gaschange index even if we are already breathing the new mix
This fixes a bug where we would not do any gas changes at all if at the end of
bottom time we were deeper than the MOD of the bottom mix. Instead we would
constantly try to switch to that gas and find we are already breathing it.

A test case would be a dive with air and EAN50 to more than 66m. That would
have never switched to EAN50.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-03 22:23:17 -07:00
Rick Walsh
87c35e19e2 Planner: Add comments to document the code
The purpose of parts of the planner code is not not always obvious.  This is
especially true of the conditional statements in the add_plan_to_notes function.
Annotate the code with comments to explain the logic.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-27 06:31:30 -07:00
Dirk Hohndel
72e6c52b06 Remove bogus fix
In commit 156ad42a3c ("snprintf is happier if it has an explicit string
literal format argument") I got a little too aggressive making sure there
are string literal format strings...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-26 09:14:06 -07:00
Rick Walsh
4d3cefc70b Planner: Add parentheses to output condition
Aids reading the code, doesn't alter the logic.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-26 09:14:06 -07:00
Rick Walsh
90d15c20c4 Planner: Count the minimum stop time towards o2time
When doing backgas breaks, count the minimum stop time towards o2time.
Previously, the initial minimum stop wasn't counted, so the time of the first
segment on oxygen was min_switch_duration + 12 minutes.

E.g. with 1 minute minimum switch duration.

Previously:
depth   duration        runtime gas
40m     1min    1min    air
40m     34min   35min
21m     2min    37min
21m     1min    38min   EAN50
18m     1min    39min
15m     3min    42min
12m     4min    46min
9m      5min    51min
6m      13min   64min   oxygen	<--13 minutes on O2
6m      6min    70min   air
6m      2min    72min   oxygen
0m      1min    73min

Now:
depth	duration	runtime	gas
40m	1min	1min	air
40m	34min	35min	 
21m	2min	37min	 
21m	1min	38min	EAN50
18m	1min	39min	 
15m	3min	42min	 
12m	4min	46min	 
9m	5min	51min	 
6m	12min	63min	oxygen
6m	6min	69min	air
6m	2min	71min	oxygen
0m	1min	72min	 

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-26 09:14:06 -07:00
Rick Walsh
4f05622846 Planner: Hide unwanted transition between deco stops
If display transitions in deco isn't selected, then we shouldn't show the
transition segment between two deco stops, even if there is a gas change.  We
should still show the ascent segment up to the first deco stop.  The
(gaschange_after && !isascent) condition is necessary to pick up backgas breaks.
An example plan is shown below.

Previously:
depth	duration	runtime	gas
40m	1min	1min	air
40m	34min	35min	 
21m	2min	37min	 	<--meaningful ascent segment
21m	1min	38min	EAN50
18m	1min	39min	 
15m	3min	42min	 
12m	4min	46min	 
9m	5min	51min	 
6m	0min	51min	 	<--unnecessary ascent segment
6m	13min	64min	oxygen
6m	6min	70min	air
6m	2min	72min	oxygen
0m	1min	73min	 

depth	duration	runtime	gas
40m	1min	1min	air
40m	34min	35min	 
21m	2min	37min	 	<--meaningful ascent segment
21m	1min	38min	EAN50
18m	1min	39min	 
15m	3min	42min	 
12m	4min	46min	 
9m	5min	51min	 
6m	13min	64min	oxygen
6m	6min	70min	air
6m	2min	72min	oxygen
0m	1min	73min	 

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-26 09:14:06 -07:00
Rick Walsh
1885eccc49 Planner: use pointer to deco stop level array instead of memcpy
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-26 09:14:06 -07:00
Rick Walsh
036e992d14 Planner: Change 3m stop to zero if last stop is 6m
When the last stop at 6m/20ft option is selected, replace the 3m/10ft stop with
zero depth, rather than doubling up on the 6m/20ft stop.  This removes the need
to differentiate between 6m (=6000mm) and 20ft (=6096mm) and saves calling a
helper function.  It does not alter the calculated profile at all.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-26 09:14:05 -07:00
Dirk Hohndel
156ad42a3c snprintf is happier if it has an explicit string literal format argument
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-25 13:43:44 -07:00
Rick Walsh
361ddd9634 Planner: correct output of planner mode
Previously we used strncat to output VPM mode without correctly defining the
length of the string, and didn't do anything for recreational mode.  This
resulted in the output being junk recycled from the previous temp string.

We could use strncat if the string length were defined, but using snprintf will
make it simpler to include the VPM conservatism when that has been implemented.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-23 08:12:29 -07:00
Joakim Bygdell
ff6bf497c8 Planner: update disclamer
Update the disclamer text to reflect which algorithm where used.

[Dirk Hohndel: cleaned up coding style & replaced snprintf with strncat]

Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-08 06:52:02 -07:00
Dirk Hohndel
b1538c809d Code cleanup
Make precedence of && over || explicit.
Explicitly convert between char * and unsigned char *.
Don't assign potentially negative return code to an unsigend variable.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-06 13:59:14 -07:00
Robert C. Helling
a7d18a9fa6 Round MOD of gas rather than truncate
For the proper calculation, we need to take salinity and surface pressure
into account (rather than depth = bar * 10 - 10)

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-05 15:53:49 -07:00
Dirk Hohndel
35dc814105 Add simple test for the dive planner
This sets up a standard dive scenario (30 minutes at 260ft/79m, EAN36 and
Oxygen as deco gases, last stop at 20ft/6m) and calls the planner to set
up a dive plan given certain standard gases.

Instead of trying to verify the complete plans it checks that we switch to
the deco gases at the right depth and the complete duration of the dive
matches our expectation.

The test intentionally fails right now for imperial as we have the wrong
switch depth for Oxygen. See how useful tests are?

On the downside, the test does NOT produce the same plan as Subsurface
when I try to create a consistent setup for both - and I have not been
able to figure out why. There must be some other parameters that I'm not
setting, but I haven't identified them, yet. It's very small differences,
for example in the metric case the stops at 21m, 9m, and 6m are each one
minute shorter in the test than it what Subsurface calculates.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-05 09:42:38 -07:00
Rick Walsh
17ef6774e0 Planner deco stops are at 10ft increments when measured in feet
When using feet as depth unit, deco stop levels should be at 10 ft rather
than 3 m increments.

For shallow stops, rounding means the difference is not apparent. However,
with stops deeper than 30 feet, using 3 m increments leads stops at 39ft,
49ft, ..., 98ft, etc.

Apart from making plans look messy, the old behaviour makes it harder to
benchmark the planner against published profiles in imperial units.

This revised patch uses the help macro M_OR_FT(6, 20) to set the last stop
at the correct depth.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-05 06:50:48 -07:00
Rick Walsh
8c4e1e6bfa Read planner preferences when we use them
Read and use the last_stop preference in the plan function.
Read the plan notes preferences and set variables (plan_verbatim,
plan_display_runtime, plan_display_duration, and plan_display_transitions)
in the add_plan_to_notes function. Don't read the preferences and set
variables otherwise. Both plan and add_plan_to_notes functions are called
on data change.

Previous behaviour was:
- Set variables on declaration
- Reset variables in plan function (even variables that only relate to
  planner notes output)
- Changing a preference triggered set_xxx function which sets variable,
  then plan function, which sets variable again.

Apart from being inefficient, the previous behaviour made it difficult to
track down where and when variables were set.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-05 06:37:01 -07:00
Jan Darowski
ddfd046c8d VPM-B: add CVA to the deco planner.
Added keeping bottom dive state and every deco's time, so we can
run multiple deco simulations with different gradients until they
converge to some optimal value.

Some improvements on the deco time calculation may be needed.

Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-07-04 00:13:34 +02:00
Jan Darowski
02f1339917 VPM-B: vpm without CVA working.
Add call of initial calculation of critical radius and start gradient,
so the VPM could work.
Currently without CVA, so the gradient isn't improved.
Only one iteration is run.

Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-07-03 23:54:57 +02:00
Jan Darowski
e7aa686f16 VPM-B: add vpm-b based deco checking.
Check during the trial_ascent() if existing pressure gradient is
smaller than previously calculated max gradient. If not, ascent
is impossible from the vpm-b's point of view.

Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-07-03 23:24:20 +02:00
Jan Darowski
500fbe4994 VPM-B: add deco choice to the ui.
Removed recreational mode from ui and pref and replaced it with
new deco_mode enum.
Added radio button ui selection.
Set default deco_mode to Buehlmann algorithm.

Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
2015-07-03 23:07:58 +02:00
Rick Walsh
f763da66b3 Implement planner option to switch only at required stops
When option is enabled, if a stop is not otherwise required, a gas switch will be delayed until a stop is reached.  This option is ignored if the current gas is hypoxic.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-26 06:14:28 -07:00
Rick Walsh
cb1b6a3d30 Define gaschange_before and gaschange_after a few lines earlier
This is required so they work in the test for /* do we want to skip this leg as it is devoid of anything useful? */
We were already trying to use gaschange_after (and previously gaschange), but it was duplicating an existing condition (now removed).

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-26 06:10:34 -07:00
Rick Walsh
228eb6ce27 Fix gaschange_after definition
Previously gaschange_after was never being set back to false.  Now it will be.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-23 06:15:07 -07:00
Robert C. Helling
4094e6b233 Refactor to use gaschage_before and gaschange_after
... for better readability.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-22 17:39:17 -07:00
Robert C. Helling
d071ab4537 When displaying transitions show the gaschange at the stop if there is one
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-22 17:28:01 -07:00
Rick Walsh
26622e7e04 Planner notes - revise logic for gasmix output
The logic for when to output a gasmix in the notes table is more
complicated than it seems at first.
- On a descent leg, the gas is the gas used for descent
- At a stop (calculated or user defined), the gas is the gas used for that
  stop
- But on an ascent leg (if displayed), the gas is the gas that is ABOUT TO
  BE USED
- The gas should not be repeated if it's the same gas as used on the last
  row of the table
- Ascent legs should only be displayed if the display transitions option
  is selected, OR if there is a gas change without a stop (the user can
  now set a minimum duration for a gaschange, but zero is still allowed).

The existing code tries to track what gas is being used/switched to at
each waypoint, and whether the gas should be printed or postponed to the
next leg.  It works sometimes but not always.

This patch replaces the postponed gas logic with:
- Is this an ascent leg? (determines whether the applicable gas is the
  preceding or following leg, and whether the leg should be displayed at
  all if the transitions option isn't selected)
- Is it an ascent with a gaschange without a stop?
- Has the gas actually changed from the last output?
- Will the next leg be at the same level and same gas (in which case merge
  them)?

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-22 17:24:56 -07:00
Dirk Hohndel
86b8d796c8 Prevent null pointer dereference
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-22 10:57:56 -07:00
Dirk Hohndel
f5726c3d18 Fix a number of resource leaks
Free memory returned from parse_mkvi_value()
Free memory returned from printGPSCoords()
Free memory allocated in added_list and removed_list
Free memory allocated when adding suffix to dive site name
Free memory allocated in cache_deco_state()
Free memory allocated in build_filename()
Free memory allocated in get_utf8()
Free memory allocated in alloc_dive()
Free memory allocated as cache but never used

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-21 21:13:32 -07:00
Rick Walsh
48aa0bdfd0 Planner: change timestep to 2 seconds
Change the timestep used to calculate tissue pressures and ascents from 3
seconds to 2 seconds. But whats wrong with using 3 seconds?

Deco stops are at 3 m (10') intervals, and our ascent rate is usually
9 m/min (30'/min), or at least multiples of 3 m/min (10'/min).  Hence time
to ascend from one stop to the next stop is 20s (or any factor of 60).
Using 3s increments, we round our ascent interval up to 21 s, which leads
to messy durations and runtimes.

But what about me?  I like SI units and whole decimals.  Don't worry, 2s
timesteps fit nicely when using 10 m/min ascent rate (18 s between stops).

[Dirk Hohndel: edited the commit message to fix minute/second confusion]

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-21 15:29:22 -07:00
Rick Walsh
e5a4b5a618 Planner - end deco stops at whole minutes of runtime
--20cf303ddd3893b1500518e9204e
Content-Type: text/plain; charset=UTF-8

Use an adjusted timestep to calculate length of deco stops, so that they
always end at whole minutes of runtime.  This makes for a cleaner ascent
profile.

<div dir="ltr">Use an adjusted timestep to calculate length of deco stops, so that they always end at whole minutes of runtime.  This makes for a cleaner ascent profile.<br></div>

From 15e08450252f304fc7d46931e2aca5c991c2f3de Mon Sep 17 00:00:00 2001
From: Rick Walsh <rickmwalsh@gmail.com>
Date: Sat, 20 Jun 2015 11:36:07 +1000
Subject: [PATCH 2/2] Planner - end deco stops at whole minutes of runtime

Use an adjusted timestep to calculate length of deco stops, so that they always end at whole minutes of runtime.  This makes for a cleaner ascent profile.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-20 18:20:18 -07:00
Rick Walsh
845030a8ad Enforce planner minimum gas switch duration
Enforce a minimum duration for gas switching in the planner.

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-19 09:15:51 -07:00
Rick Walsh
f66ea4cbb0 Show duration before runtime on planner notes table
Switch the column order of the planner notes table so that duration is displayed before runtime.  This is consistent with:
- the verbatim output order, e.g. "Stay at 12.0 m for 3:00 min - runtime 32:48 on EAN50"
- MultiDeco, e.g. http://www.hhssoftware.com/multideco/view_multideco.html
- Planner on the Shearwater Petrel
- How I have been taught to write out my dive plan in my wetnotes

Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-16 20:32:40 -07:00
Jan Darowski
a524c01c3f Don't compare signed and unsigned values
This fixes a "reproducable hang when using "edit dive in planner" on
non-planned dive".
Comparing unsigned and signed integers isn't a great idea.

Fixes #880

Signed-off-by: Jan Darowski <jan.darowski@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-14 21:20:55 -07:00
Robert C. Helling
22bfc4936f Add explicit casts to silence compiler warnings
clang complais when converting (char *) to (unsigned char *), so tell
it it's fine.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-05-28 08:16:37 -07:00
Joakim Bygdell
9ca033c550 Be more precise about the safety-stop.
There is no point in doing a stop at 5m if the last manual waypoint is shallower.

Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-05-21 13:26:49 -07:00
Robert C. Helling
907ccb0b71 Allow "oxygen" as a gas name
...as this what comes in when the user selects this gas in the
add dive/dive planner contet menu.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-05-17 15:07:02 -07:00
Robert C. Helling
698b2b133f Only add disclaimer and runtime table if we added deco to replanne dive
As a side effect this changes the signature of plan(): Before it
returned an int that was supposed to be possibly an error but
we never bothered to check it. So now it's bool indicating if the
planner did add stops.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-05-11 07:57:09 -07:00
Robert C. Helling
9d8eb10421 Only warn when trying to replan a logged dive
If there are more than 100 samples, average some of them so we end up with no more than 100.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-05-08 10:02:45 -07:00
Joakim Bygdell
68ec73f1b0 Recmode: Fix ascent gas consumption.
Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-09 14:36:33 -07:00
Joakim Bygdell
afea30fd8a Recmode: Allow the user to specify gas reserve.
Since most regulators have an intermediate pressure of 10bar
the minimum value is 10 while the max is 99.

Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-09 14:36:17 -07:00
Joakim Bygdell
695637dcff Recmode: Take safety stop into account when calculating ascent gas consumption.
Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-09 14:35:46 -07:00
Joakim Bygdell
352433723d Read stored planner prefs when starting.
Back in 5bf23381e we started storing planner settings in prefs.
We need to read those settings back when we start the planner.

Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-05 07:40:54 -07:00
Robert C. Helling
004fa9a26b Spelling corrected
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-04 10:25:02 -07:00
Robert C. Helling
e03c5ce8e9 Take gas consumption into account for recreational mode
If there is valid gas information (cylinder size and starting pressure),
also ascent before gas runs out (taking a 40bar reserve into account).

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-04 10:21:40 -07:00
Robert C. Helling
61ff7c5f8b Only do safety stop of dive has at least max depth of 10m
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-02 09:46:10 -07:00
Robert C. Helling
cc8d601422 Checkbox and preference for safety stop
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-02 09:46:10 -07:00