summaryrefslogtreecommitdiffstats
path: root/planner.c
AgeCommit message (Collapse)Author
2015-07-08Planner: update disclamerGravatar Joakim Bygdell
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-06Code cleanupGravatar Dirk Hohndel
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-05Round MOD of gas rather than truncateGravatar Robert C. Helling
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-05Add simple test for the dive plannerGravatar Dirk Hohndel
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-05Planner deco stops are at 10ft increments when measured in feetGravatar Rick Walsh
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-05Read planner preferences when we use themGravatar Rick Walsh
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-04VPM-B: add CVA to the deco planner.Gravatar Jan Darowski
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-03VPM-B: vpm without CVA working.Gravatar Jan Darowski
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-03VPM-B: add vpm-b based deco checking.Gravatar Jan Darowski
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-03VPM-B: add deco choice to the ui.Gravatar Jan Darowski
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-06-26Implement planner option to switch only at required stopsGravatar Rick Walsh
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-26Define gaschange_before and gaschange_after a few lines earlierGravatar Rick Walsh
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-23Fix gaschange_after definitionGravatar Rick Walsh
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-22Refactor to use gaschage_before and gaschange_afterGravatar Robert C. Helling
... for better readability. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-22When displaying transitions show the gaschange at the stop if there is oneGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-22Planner notes - revise logic for gasmix outputGravatar Rick Walsh
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-22Prevent null pointer dereferenceGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-21Fix a number of resource leaksGravatar Dirk Hohndel
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-21Planner: change timestep to 2 secondsGravatar Rick Walsh
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-20Planner - end deco stops at whole minutes of runtimeGravatar Rick Walsh
--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-19Enforce planner minimum gas switch durationGravatar Rick Walsh
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-16Show duration before runtime on planner notes tableGravatar Rick Walsh
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-14Don't compare signed and unsigned valuesGravatar Jan Darowski
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-05-28Add explicit casts to silence compiler warningsGravatar Robert C. Helling
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-21Be more precise about the safety-stop.Gravatar Joakim Bygdell
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-17Allow "oxygen" as a gas nameGravatar Robert C. Helling
...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-11Only add disclaimer and runtime table if we added deco to replanne diveGravatar Robert C. Helling
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-08Only warn when trying to replan a logged diveGravatar Robert C. Helling
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-04-09Recmode: Fix ascent gas consumption.Gravatar Joakim Bygdell
Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-09Recmode: Allow the user to specify gas reserve.Gravatar Joakim Bygdell
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-09Recmode: Take safety stop into account when calculating ascent gas consumption.Gravatar Joakim Bygdell
Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-05Read stored planner prefs when starting.Gravatar Joakim Bygdell
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-04Spelling correctedGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-04Take gas consumption into account for recreational modeGravatar Robert C. Helling
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-02Only do safety stop of dive has at least max depth of 10mGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-02Checkbox and preference for safety stopGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-02Add 3min safety stopGravatar Joakim Bygdell
Fixes #839 Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-02Introduce recreational planner modeGravatar Robert C. Helling
This adopts the planner to the needs of the recreational diver. Rather than immediately starting to ascent doing deco stops this mode, this mode stays at the last manually entered depth for the maximal time before mandantory stops appear (NDL). It does not change gas but keeps using the last used cylinder. TODO: * Grey out unused UI elements of the planner in this mode * Start ascent before gas runs out (or into reserve) * Do a 3min @ 5m safety stop. Fixes #840 Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-03-09Improve gas accounting in the pannerGravatar Joakim Bygdell
When using gasmixes where the difference is less than 2% the planner can't caclulate casconsumptions correctly. This sets the minimum gasdifference to 1%. Fixes #795 Signed-off-by: Joakim Bygdell <j.bygdell@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-03-08Add explicit setpoint change at t=0 when planning CCR divesGravatar Robert C. Helling
As we now have the logic that there is always an explicit setpoint at t=0sec for CCR dives, also the planner should honor that. This fixes a bug that when planning a CCR dive we later add a setpoint change this influenced the ceiling _before_ the setpoint change. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-03Show stops in verbatim diveplanGravatar Robert C. Helling
The position of one curly brace was wrong. Bummer. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-20Adopt planner gas calculation to PSCR mode and include low pO2 warningGravatar Robert C. Helling
[Dirk Hohndel: fixed obvious compile problem] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-17Save predefined SACGravatar Robert C. Helling
When planning a dive, the gas consumption is based on a user configured SAC. Thus we should use that SAC and not try to recompute it from samples. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-10Refactor dctype -> divemodeGravatar Robert C. Helling
... and repair a failed rebase (sorry). Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-10Rebreather type selector UIGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-12-12Set sample setpoint correctlyGravatar Robert C. Helling
Forward the sample set-point setting as otherwise all ascents are planned on OC. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-12-07In diveplan differentiate between last printed depth and last depthGravatar Robert C. Helling
In the decision if a dive segment should lead to a line in the diveplan, we need to differentiate between the lastdepth (the depth of the last dp to tell if we are currently stopping) and the last depth that we printed a line for (needed for gaschange lines). Without this patch, no stops without gas changes were listed anymore in the diveplan. Like the last patch for the diveplan: I hope this time I got this logic right. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-25Assign setpoint to correct sample in plannerGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-21Print gas changes at the correct lines in diveplanGravatar Robert C. Helling
This is a pain. We plan with segments but the plan shows waypoints. If after a constant depth segment the gaschange (or setpoint chenge for that matter) appears, the _next_ line should get the info about the new gas (i.e. change _after_ the constant depth segment). If, however, the gas is changed after a transition, the final waypoint of the transition gets the gas printed. And all is different for a verbatim plan, where the gas change is an event rather than part of a segment. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-21Show the setpoint in the diveplanGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>