aboutsummaryrefslogtreecommitdiffstats
path: root/planner.c
AgeCommit message (Collapse)Author
2013-02-23Planner: fix wait time calculationsGravatar Robert C. Helling
The problem is that when we reach the gas change depth and compute the stop time, no gas change event is created yet but time_at_last_depth tries to determine the gas for the stop from events. So instead we pass o2 and he as parameters of that function and calculate the wait time based on that information. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-19Planner: fix incorrect gas change eventGravatar Dirk Hohndel
We stored the He permille instead of the He percentage. But for most casual testing this was hidden by the previous bug. Reported-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-19Planner: Start calculations with gas 0 instead of airGravatar Dirk Hohndel
The planner had a fatal flaw in that it ALWAYS started with AIR, even when clearly claiming to use the correct gas. We only picked up correct gases from events, but not at the beginning of the dive (where there is no event). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-14Ensure that planner warnings get shown before calculations are runGravatar Dirk Hohndel
Linus pointed out that the warning wasn't shown until the main loop got control back, so even a gtk_widget_show_all() doesn't really help to make sure that things are shown right then. This commit adds a little loop to handle all pending gtk_events before exiting the show_error() function. Now the warning should be shown BEFORE a potentially slow calculation gets started. Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-13Make planner.c warning consistentGravatar Dirk Hohndel
Just a tiny change to make them look more consistent. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-13Support deeper stops and longer dive notes in plannerGravatar Dirk Hohndel
Since we now support dives all the way down to 400m we should also support deeper stops. And of course this can create insanely long dive plans, so make sure there is plenty of space for those. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-13Rewriting the error handling in planner.cGravatar Dirk Hohndel
Printf is not a way to issue warnings and errors. This is a very late addition but seems necessary for a viable release of the planner. This also adds one artificial limit and two warnings: a) no dives deeper than 400m b) warning of potentially very long calculation times for dives longer than 3h (180min) before the ascent and dives deeper than 150m It also creates quite a number of new strings that need to be translated (and marks a few existing ones for translation as well). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-12Remove rounded O2 in airGravatar Dirk Hohndel
To quote Linus, gentle as always: Stuff like this is just BS. Don't do it. You already fixed the bug with matching gas change events, so adding this idiotic workaround no longer fixes anything, and its confusing and actively misleading. It's not even percent. It's still permille, just rounded. So it's a nonsensical number and a misleading name. Just delete it as the abortion it is. It is only going to cause more problems later. Just use the correct value. Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-12Fix gas handling in plannerGravatar Dirk Hohndel
Two separate bugs. a) Air cylinders were created with o2=209 and no other value set. sanitize_gasmix() turned that into o2=0 which meant that this cylinder was now identified as "nodata", i.e., unset. We now set a fake cylinder name to deal with that issue. b) the gaschange event is inherited from libdivecomputer and therefore only supports 1 percent granularity for o2 and h2. Since we didn't round when assigning the value we ended up with air being stored as o2=20 he=0 which of course then didn't match air anymore (which we have defined as 208 <= o2 <= 210). We now use o2=210 for air in the planner and carefully round the permille values whenever we convert into percent - and compare gases with percent granularity as well. A better fix for b) would be to change the Subsurface event to not simply copy the libdivecomputer behavior and use percent granularity but support permille instead. But this closely before the 3.0 release that seemed like a far too invasive change to make - the changes to the planner should have no impact outside the planner module. Reported-by: Chris Lewis <chrislewis915@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09Hopefully last change to po filesGravatar Dirk Hohndel
While this is a pain for everyone, I decided not to edit out the code reference noise - after all this is supposed to help translators find where the text is used in case it's unclear how to translate something. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08Do more dive fixup for each dive computerGravatar Linus Torvalds
In commit b6c9301e5847 ("Move more dive computer filled data to the divecomputer structure") we moved the fields that get filled in by the dive computers to be per-divecomputer data structures. This patch re-creates some of those fields back in the "struct dive", but now the fields are initialized to be a reasonable average from the dive computer data. We already did some of this for the temperature min/max fields for the statistics, so this just continues that trend. The goal is to make it easy to look at "dive values" without having to iterate over dive computers every time you do. Just do it once in "fixup_dive()" instead. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09Clean up the handling of surface pressureGravatar Dirk Hohndel
There are two ways to look at surface pressure. One is to say "what was the surface pressure during that dive?" - in that case we now return an average over the pressure reported by the different divecomputers (or the standard 1013mbar if none reported any). Or you want to do specific calculations for a specific divecomputer - in which case we access only the pressure reported by THAT divecomputer, if present (and fall back to the previous case, otherwise). We still have lots of places in Subsurface that only act on the first divecomputer. As a side effect of this change we now make this more obvious as we in those cases pass a pointer to the first divecomputer explicitly to the calculations. Either way, this commit should prevent us from ever mistakenly basing our calculations on a surface pressure of 0 (which is the initial bug in deco.c that triggered all this). Similar changes need to be made for other elements that we currently only use from the first divecomputer, i.e., salinity. Reported-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08Add a more stronly worded warning / disclaimer for dive planningGravatar Dirk Hohndel
This is a late string change, but I think this may be a valid exception of the string freeze... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-03Increase the buffer for the gas text in plannerGravatar Sergey Starosek
UTF-8 strings could create more characters. Signed-off-by: Sergey Starosek <sergey.starosek@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-03Merge branch 'po-files'Gravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org> Conflicts: po/nb_NO.po po/ru_RU.po
2013-02-03Distinguish the two uses of "Gas Used" for translation purposesGravatar Dirk Hohndel
One is about the amount, the other about the specific type of gar that was used. Reported-by: Sergey Starosek <sergey.starosek@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-03Increase the buffer for the gas text in plannerGravatar Dirk Hohndel
Translations that use UTF-8 could easily create more characters than I had initially specified. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-03Fixing SP handling in planner, adding eventGravatar Jan Schubert
This moves some double/floating handling for po2 to plain integer. There are still non int values around (also for phe and po2) in the plot area. Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-03Fixing SP handling in planner, adding eventGravatar Jan Schubert
Fixing the SP change event and introducing a bailout scenario. I decided not to use a event showing SP=0.0 nor using a gaschange event as is in fact there is no gas change related to bailing out itself. If there is also a gaschange for the event it will be displayed anyway. Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-03Fixing SP handling in planner, adding eventGravatar Jan Schubert
Fixes bug in planner which prevents from bailing out (setpoint = 0). Also introduces events for changing setpoints in planner. It also makes the eventtype for gaschange slightly more consistent by changing it from SAMPLE_EVENT_GASCHANGE (O2 only) to SAMPLE_EVENT_GASCHANGE2 (O2/He). But Subsurface treats them both the same (the distinction comes from libdivecomputer). Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-02planner.c: Use g_time_zone_find_interval()Gravatar Lubomir I. Ivanov
current_time_notz(): Attempt to use g_time_zone_find_interval() to retrieve a timezone interval, which is then passed to g_time_zone_get_offset() Reported and tested-by: Sergey Starosek <sergey.starosek@gmail.com> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-31Don't allow to plan dives out of orderGravatar Dirk Hohndel
The planned dive always has to be the last dive in the dive list. To make sure of that we interpret the relative start time to be relative to either the current time or the end of the last dive, whichever is later. This fixes a bug where we would delete the wrong dive and get our data structures confused by planning multiple dives out of order. Reported-by: Sergey Starosek <sergey.starosek@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-30Massive cleanupGravatar Dirk Hohndel
Mostly coding style and whitespace changes plus making lots of functions static that have no need to be extern. This also helped find a bit of code that is actually no longer used. This should have absolutely no functional impact - all changes should be purely cosmetic. But it removes a bunch of lines of code and makes the rest easier to read. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-29Add missing strings for translationsGravatar Dirk Hohndel
Mostly in new code, but some of them are strings in older code that have been missed in the past. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-28Make dive planner more useful for closed circuit divingGravatar Dirk Hohndel
Add a sample at time 0 to allow for a pO2 from the start of the dive. Remember the last pO2 so it doesn't have to be repeated (and the right thing happens for the planned part of the dive). This still doesn't allow us to change the setpoint at a certain depth (which would be analogous to being able to switch to a certain gas at a certain depth in OC plans), but with this commit it's already usable. This commit also fixes a couple of small bugs in commit b8ee3de870fa ("Dive planning for closed circuit rebreather") where a pO2 of 1.1 was hardcoded in one place, throwing off all plan calculations and integer math was used to calculate a floating point value (leading to most pO2 values actually used being 1.0). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-28Dive planning for closed circuit rebreatherGravatar Jan Schubert
This misses a single issue to be used as a base for further discussion: The CC setpoint is used for the next segment, not the one specified for. I also have in mind to modify the existing code to use setpoints specified in mbar and plain integer instead of float values. Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-28Clean up gtk combo box handlingGravatar Linus Torvalds
This cleans up our handling of combo boxes and all the duplicated completion logic, and simplifies the code. In particular, we get rid of the deprecated GtkComboBoxEntry. While it made some things easier, it made other things harder. Just using GtkComboBox and setting that up correctly ends up being simpler, and also makes the logic work with gtk-3. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24Fix compile error in planner.cGravatar Henrik Brautaset Aronsen
Linus seems to have been too eager in the dc refactoring: a diveplan doesn't have a divecomputer. Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-23Move more dive computer filled data to the divecomputer structureGravatar Linus Torvalds
This moves the fields 'duration', 'surfacetime', 'maxdepth', 'meandepth', 'airtemp', 'watertemp', 'salinity' and 'surface_pressure' to the per-divecomputer data structure. They are filled in by the dive computer, and normally not edited. NOTE! All actual *use* of this data was then changed from dive->field to dive->dc.field programmatically with a shell-script and sed, and the result then edited for details. So while the XML save and restore code has been updated, all the displaying etc will currently always just show the first dive computer entry. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-16Add GFlow/GFhigh settings in dive plannerGravatar Dirk Hohndel
The planner interactively responds to changes to the GFlow and GFhigh in the dialog and calculates an appropriate profile. If there is a previous dive within the 48 hours prior to this dive then its saturation is correctly taken into account if the gradient factors are changed - so if they are aggressively lowered it is possible to start the dive with already an existing ceiling (simply increase the surface interval to 'fix' that). Once the plan is accepted the GF values are reset to the current preferences. This can cause the ceiling in the plot to change and the deco stops to no longer match the ceiling - but that's a logical consequence of the ability to change a temporary copy of GFlow/GFhigh during the planning process and not the actual preferences (which would be counter intuitive, I think). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-16Correctly mark divelist changed after accepting dive planGravatar Dirk Hohndel
Commit 293126257b20 ("Mark divelist as changed if user accepts planned dive") had the correct commit message but an incorrect implementation. This moves the mark_divelist_changed() call into the GTK_RESPONSE_ACCEPT clause where it belongs. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15Mark divelist as changed if user accepts planned diveGravatar Dirk Hohndel
When the user clicks OK in the dive planner and the dive is added to the divelist the divelist needs to be marked as changed so Subsurface prompts the user to save the file before quitting. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15Calculate the gas used during the planned diveGravatar Dirk Hohndel
This works on the assumption that the diver uses the deco SAC rate while on a calculated deco stop and the bottom SAC rate during the rest of the dive (including the time they move from deco stop to deco stop). This is making the planning function mostly useful for open circuit diving. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15Add diveplan to the dive notesGravatar Dirk Hohndel
This makes it easy to print out a dive plan - it's simply stored in the notes of the simulated dive we create. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15Add code to enter SAC rates for dive planningGravatar Dirk Hohndel
This just provides the infrastructure to enter the data, nothing is calculated, yet. This adds a new get_thousandths() helper function so we can enter information of the 'mili-' type as decimal values. So things like "14.5 l/min" or "0.75 cuft/min" are parsed correctly and converted into a ml value. In the process of implementing that I also fixed a bug introduced in commit ab7aecf16e96 ("Simplify dive planning code") which broke the get_tenth() function. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15Add small helper function to make planner gui function easier to readGravatar Dirk Hohndel
This is just preparation for the next set of changes. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15Trivial pressure related fixesGravatar Jan Schubert
This patch removes the need for the "string" pressurebuf in planner.c. It also adds a unit to the partial pressures displayed in the mouse overlay which are always displayed in bar. BTW: Has anyone seen a pO2 shown in PSI? Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15Correct the start time of planned divesGravatar Dirk Hohndel
Subsurface follows the lead of most divecomputers to use times without timezone - so all times are implicitly assumed to be local time of the dive location; so in order to give the current time in that way we actually need to add the timezone offset. Instead of relying on OS specific members of struct tm we use the glib timezone functions to get the timezone offset for us. Of course, the function used to do this is only in glib 2.26 or newer, which once again means that Debian stable won't be supported. But since that doesn't build other parts of Subsurface, either, I think I'll live with that. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-14Centralising and redefining values as integersGravatar Jan Schubert
This patch centralizes the definition for surface pressure, oxygen in air, (re)defines all such values as plain integers and adapts calculations. It eliminates 11 (!) occurrences of definitions for surface pressure and also a few for oxygen in air. It also rewrites the calculation for EAD, END and EADD using the new definitons, harmonizing it for OC and CC and fixes a bug for EADD OC calculation. And finally it removes the unneeded variable entry_ead in gtk-gui.c. Jan Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-13Correctly show the planned dive in the divelistGravatar Dirk Hohndel
Previously we would simply show the first dive in the divelist - which worked fine in the default sort by trip setting and assuming that there are no dives from the future in the divelist. With this commit we actually find the correct dive in the divelist and select it instead. If you sort by depth you will see the dive move around in the divelist, but it will stay selected and visible in the profile. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-10Split up preference data structure definition into 'pref.h'Gravatar Linus Torvalds
.. and rename the badly named 'output_units/input_units' variables. We used to have this confusing thing where we had two different units (input vs output) that *look* like they are mirror images, but in fact "output_units" was the user units, and "input_units" are the XML parsing units. So this renames them to be clearer. "output_units" is now just "units" (it's the units a user would ever see), and "input_units" is now "xml_parsing_units" and set by the XML file parsers to reflect the units of the parsed file. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-09Clean up duplicated depth interpolationGravatar Linus Torvalds
We have several places where we interpolate the depth based on two samples and the time between them. Some of them use floating point, some of them don't, some of them meant to do it but didn't. Just use a common helper function for it. I seriously doubt the floating point here really matters, since doing it in integers is not going to overflow unless we're interpolating between two samples that are hours apart at hundreds of meters of depth, but hey, it gives that rounding to the nearest millimeter. Which I'm sure matters. Anyway, we can probably just get rid of the rounding and the floating point math, but it won't really hurt either, so at least do it consistently. The interpolation could be for other things than just depth, but we probably don't have anything else we'd want to interpolate. But make the function naming generic just in case. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-09Add support to planner to use additional gases during the ascentGravatar Dirk Hohndel
This change ended up being quite a bit bigger than expected as it uncovered a number of bugs in the existing code. The planner now handles gas changes correctly by creating (and later parsing) events in the simulated divecomputer. At the end of the dive specified in the input form the algorithm starts with the deepest interesting depth: either the first stop below our ceiling or the deepest depth at which we can change gases. It then traverses all the stop and all the gas change depth and at each stage ensures that we are allowed to ascend further before going on. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Allow special entries in diveplan for available gasesGravatar Dirk Hohndel
An entry with no time is considered special and not considered when constructing the profile. This should allow us to add support for two different ways of adding information about available gas: changedepth 0 gasmix 0 0 gasmix @ po2 The first syntax basically says "during the ascent, switch to this gas at this depth. The second one says "switch to this gas once the pO2 allows for it" Neither of these are implemented, yet, but this commit is necessary in order for the rest of the code to ignore entries with a time field of 0. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Set a default surface pressure for dive plan and allow simplistic printGravatar Dirk Hohndel
This commit makes sure we have a reasonable default surface pressure (we need an input field for that). It also adjusts the debug level settings so that compiling this with make CLCFLAGS=-DDEBUG_PLAN=3 will print out an almost usable dive plan. This is of course still lacking air consumption calculations and will show deco stops that we just transit through (if the ceiling lifts far enough during the transition to an intended stop that this stop can be skipped; this sometimes happens for the first stop (haven't seen it for a later one). But it's better than nothing, I guess. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Do planned deco stops in multiples of 1 minuteGravatar Dirk Hohndel
We may want to make this configurable, but I haven't seen any software that doesn't do deco stops in full minutes. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Fix the deco calculation in the dive plannerGravatar Dirk Hohndel
The existing code incorrectly started all calculation at the depth at the end of the first segment. So if you went to 50m in 5min in your first segment, you incorrectly got 5 minutes at 50m (instead of a progression from 0 to 50m, over 5 minutes). This commit fixes that and now gives us planned dives that then match what is shown in the profile. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Improve travel logic code for the ascent in the plannerGravatar Dirk Hohndel
This shouldn't change the the actual stops we do or the travel time how we get there, but it makes the code more logical. From the end depth of the planned dive we have ONE transition to the first stop depth (which may be the surface). And then for every stop we (potentially) have a wait and travel to the next stop. Once we are in the while loop, we know that we are at a stop level, so there is no point to keep checking if we first need to transition to the stop. It does create one additional improvement: if we don't need any stops at all, then we don't transition to the first stop and then from there to the surface. We do it in one step. The overall profile / traveltime remains the same, we just drop one intermediate sample on the way. This also improves a few ugly (and in one case, wrong) debug statements. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Really prevent time travel in planner dive editGravatar Dirk Hohndel
Commit c92e4535a6de "Prevent time travel in planner dive edit" almost got it right but had a stupid think-o. This commit should fix it the right way. If the duration that is passed in is before the previous timestamp, then this is most likely intended to be a relative time. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Fix deco planning for low oxygen mixesGravatar Jan Schubert
Not sure about the future of the current planner.c as we have new approaches now but as this annoyed me for some days now I just decided to come up with this trivial stuff to make my life easier. More a cosmetic fix than a patch, but actually it fixes a bug one might face planing a dive using low oxygen mixes and where stop levels at just 90m, 60m, 30m and nothing in between will not allow subsurface to finish a deco ceiling which ends before the universe collapses. Allows to plan 20min@130m using a 10/70 now (f.i.). Signed-off-by: Jan Schubert / Jan.Schubert@GMX.li Signed-off-by: Dirk Hohndel <dirk@hohndel.org>