Commit graph

218 commits

Author SHA1 Message Date
Linus Torvalds
a0558a87b4 Get the SHA1 routines from git instead of openssl
..they are of a higher quality anyway, and this way we have one less
library to worry about.  And this way there is nobody who can claim that
openssl is not a system library and thus not compatible with the GPL.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-15 19:26:39 -08:00
Linus Torvalds
c6da79e1b0 Improve the code handling air temperature
Better helper functions make for easier to understand code.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-15 01:11:14 -08:00
Dirk Hohndel
23cfd907de Better handling of manually edited air temperature
We now load and save this in the XML file, we do the right thing when
merging dives and show the edited air temperature in the Dive Info
notebook when a divecomputer doesn't have an air temperature.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-14 09:44:18 -08:00
Dirk Hohndel
0cde0eff10 Rewriting the error handling in planner.c
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-13 23:02:00 -08:00
Dirk Hohndel
5e93469f35 Fix gas handling in planner
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-12 21:12:17 -08:00
Dirk Hohndel
ebcbe5aedd Finish removing accesses to first divecomputer instead of dive
This adds watertemp and airtemp to the dive, populates them in fixup and
uses them elsewhere in the code.

WARNING: as a sideeffect we now edit the airtemp in the dive, but we never
display this in the DIve Info notebook (as that always displays the data
from the specific selected divecomputer). This is likely to cause
confusion. It's consistent behavior, but... odd. This brings back the
desire to have a view of "best data available" for a dive, in addition to
the "per divecomputer" view. This would also allow us to consolidate the
different pressure graphs we may be getting from different divecomputers
(consider the case where you dive with multiple air integrated computers
that are connected to different tanks - now we could have one profile with
all the correct tank pressure plots overlayed - and the best available (or
edited) data in the corresponding Dive Info notebook.

This commit also fixes a few remaining accesses to the first divecomputer
that fell through the cracks earlier and does a couple of other related
cleanups.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09 07:41:15 -08:00
Dirk Hohndel
b9865d6bbc Move duration to dive structure and replace accessor function
When starting on this quest to stop using the first divecomputer instead
of data for the whole dive in commit eb73b5a528c8 ("Duration of a dive is
the maximum duration from all divecomputers") I introduced an accessor
function that calculates the dive duration on the fly as the maximum of
the durations in the divecomputers.

Since then Linus and I have added quite a few of the variables back to the
dive data structure and it makes perfect sense to do the same thing for
the duration as well and simply do the calculation once during fixup.

This commit also replaces accesses to the first divecomputer in
likely_same_dive to use the maxdepth and meandepth of the dive (those two
slipped through the cracks in the previous commits, it seems).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09 07:19:29 -08:00
Dirk Hohndel
c7efcb23a9 Add a meandepth to the dive structure
This is currently only used in one place (in statistics.c), but it
certainly is consistent with the other recent changes to avoid using only
the first divecomputer when trying to make statements about a dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09 07:02:43 -08:00
Dirk Hohndel
1511271201 Add maxdepth back to the dive structure
Populate during dive fixup as the maximum depth shown by all the
divecomputers. Use this value (instead of the one in the first
divecomputer) in printing, statistics, etc.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08 20:44:04 -08:00
Linus Torvalds
926fcef2a1 Do more dive fixup for each dive computer
In commit b6c9301e58 ("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-08 18:22:30 -08:00
Dirk Hohndel
61861d2611 Clean up the handling of surface pressure
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-09 08:01:59 +11:00
Linus Torvalds
9750b0ce06 The 'gasmix' argument to add_segment() is read-only
We'll want to use a 'static const' gasmix for the upcoming no-fly-time
code, so prepare for it by just marking the read-only gasmix argument as
'const'.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08 19:41:45 +11:00
Dirk Hohndel
9846ba9e94 Duration of a dive is the maximum duration from all divecomputers
So far we always used the duration of the first divecomputer. The same fix
needs to be done for some of the other calculations that always use the
first divecomputer.

This commit also removes some obsolete code from the webservice merging.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08 17:48:07 +11:00
Linus Torvalds
f507b05927 Get rid of dive->{start,end}
We had this special logic to not show the end of a dive when a dive
computer shows a series of very shallow samples (basically snorkeling
back to shore after the dive ended).  However, that logic ended up being
global per dive, which is very annoying when you have two or more dive
computers, and it decides to cut off the second one because the first
one surfaces.

So get rid of this per-dive state, and just use the plot-info 'maxtime'
field for this (we never used the 'start' case anyway).  That way we
will properly cut off boring surface entries only when they are past the
end of the interesting entries of *all* dive computers, and we won't be
cutting things short.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-04 06:48:34 +11:00
Jan Schubert
99dbd667bf Fixing SP handling in planner, adding event
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-03 07:07:12 +11:00
Pierre-Yves Chibon
20d3b5f714 Add 'Save As' entry to context menu shown when right clicking on a dive
Something which is nice especially when asked on the list to share an
interesting dive is the possibility to save just some dives into a file.

This commit adds to the context menu shown with right-click the 'Save As'
entry. This entry allows to save selected dives.

[Dirk Hohndel: clean up white space, commit message and remove unused
               variables]

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-02 00:10:14 +11:00
Dirk Hohndel
0f2fac265f Clear the list of events when closing data file
When the data file is closed we should reset the events that we offer for
filtering.

Reported-by: Sergey Starosek <sergey.starosek@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-01 00:07:04 +11:00
Dirk Hohndel
635c28923d Better algorithm to merge gps locations & locations names from webservice
This no longer abuses the dive merging code (which would leave stray
"dives" behind if a gps fix couldn't be merged with any of the dives) and
instead parses the gps fixes into a second table and then walks that table
and tries to find matching dives.

The code tries to be reasonably smart about this. If we have
auto-generated GPS fixes at regular intervals, we look for a fix that is
during a dive (that's likely when the boat where the phone is staying dry
is more or less above the diver having fun). And if we have named entries
(so the user typed in a location name) we try to match them in order to
the dives that happened "that day" (where "that day" is about 6h before
and after the timestamp of the gps fix).

This commit also renames dive_has_location() to dive_has_gps_location() as
the difference between if(!dive->location) and if(dives_has_location) is a
bit too subtle...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-31 14:29:02 +11:00
Dirk Hohndel
8843ee6156 Allow using two different tables to hold dives and gps locations
This only changes the infrastructure and actually loses functionality as
it no longer does the simplistic "just treat the locations as dives and
merge them".

The new code that does something "smart" with the gps_location_table is
yet to be written. But now we can use the XML parser to put the gps
locations downloaded from the webservice into their own data structure.

In the process I noticed that we never used the two delete functions in
parse-xml.c and removed them.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-31 12:01:03 +11:00
Linus Torvalds
9099972c20 Make 'get_dive_by_diveid()' work even for non-primary dive computers
It's only used by the Uemis importer, and Dirk always seems to import
his Uemis data first, so it wasn't very noticeable.  But if the Uemis
data wasn't the first dive computer, it would not find the dive.

Side note: just comparing deviceid is not correct.  We should pass in
the device model too.  But again, that will realistically never really
matter, since non-Uemis importers will generate complex SHA1 hashes of
the dive data for the dive ID, so a collision with the Uemis numbers is
very unlikely.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-30 14:38:07 +11:00
Dirk Hohndel
e3a8ed5183 Massive cleanup
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-30 08:31:53 +11:00
Jan Schubert
9df9fc088d Dive planning for closed circuit rebreather
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-28 18:31:30 -08:00
Dirk Hohndel
332d372b80 Pick GPS coordinates of dive location via map widget
I have some concerns about the way this is implemented - especially the
use of gtk_grab_add to make the map widget work has me worried. But it
seems to work and survived some test cases that I threw at it.

The GtkButton with the Pixmap looks a little off on my screen, but this
way it was easy to implement. Feel free to come up with a better design.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-28 13:07:08 -08:00
Dirk Hohndel
546fecd850 UTF8 aware parser for some more GPS formats
I'm sure there are better ways to do this, but this appears to grok most
rational formats I was able to find. NSEW or positive/negative numbers.
Decimal degrees (WGS84) or degrees and decimal minutes (that's what most
GPSs seem to provide). I'm sure there are still corner cases that confuse
it, but it seemed reasonably robust in testing.

I don't really love the ';' as separator but that solves the obvious
problem with locales that use a decimal comma.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-27 14:42:14 -08:00
Jan Schubert
50d0391dfb Centralization for Kelvin and Standardization to milliKelvin
This centralizes all occurrences of Kelvin to dive.h and standardizes all
usages to milliKelvin.

[Dirk Hohndel: renamed the constant plus minor white space cleanup]

Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24 15:00:52 -08:00
Henrik Brautaset Aronsen
e3088930ab Use actual min and max temperatures in statistics.
The statistics page only used each dive's "watertemp" attribute,
regardless of actual higher/lower temperatures in the samples.  By
finding the actual max/min temperatures, the statistics page utilize
more "real" data, and look better even on single dives.

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24 13:00:03 -08:00
Linus Torvalds
b8efe709a8 Remove saving of dive computer nicnames in system config
We save the (more complete) dive computer information in the XML file
with serial numbers and firmware version if we know about them, so using
a complicated string in the system config was redundant and confusing.

So remove that code.

NOTE! Since the dive computer nicknames are now only saved if the XML
file is saved, we also mark the dive list "changed" when we edit the
nicknames.  That way we'll be prompted to save things before exiting,
even if we don't actually edit any actual dive data.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24 12:59:36 -08:00
Linus Torvalds
52050fdc92 Save all dive computer nicknames - whether used or not
We used to save dive computer information only if that dive computer was
actually used in any of the dives we saved.  But we can simplify the
code if we just always save any dive computers we know about.  And it
does allow for some usage cases where you have nicknames for other
peoples computers that you may not actively use, but you want to see if
you end up loading multiple XML files in one go.

So there's just no compelling reason to not just save all the info we
have.  And this will make it less painful to remove the "use system
config for dive computer nicknames", because you can also use this to
continue to gather dive computer info in a separate XML file if you want
to.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24 12:59:31 -08:00
Linus Torvalds
413b9026dd Fix temperature rounding issues
Temperatures can actually be negative, which means that rounding by
adding 0.5 and casting to 'int' is not correct.

We could use '(int)(rint(val))' instead, but the only place we care
about might as well just print out the floating point representation
with a precision of two digits instead.  So if you have a dive computer
that gives you the precision, you might see '3.5˚C' as the temperature.

Remove the helper functions that nobody uses and that get the rounding
wrong anyway.

Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-23 12:55:39 -08:00
Linus Torvalds
b6c9301e58 Move more dive computer filled data to the divecomputer structure
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-23 12:55:33 -08:00
Linus Torvalds
30d090cee2 Only offer to show dive on map if we have location information
This adds the "Show in map" menu entry to the divelist only if we
actually have a location to show.

Of course, having some way to visually see whether we have a GPS
location even before we show the menu would probably be good. Maybe a
marker in the "location" string or something. But in the meanwhile, at
least we don't have that menu entry if we have nothing to show.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-16 13:04:31 -08:00
Henrik Brautaset Aronsen
e9953fa5e6 Show single dives in map.
This adds a "Show in map" entry in the dive list context menu.  It will
zoom to the dive location if it exists, otherwise the full map will be
displayed.

I've also switched map tiles from OpenStreetMap to Google Maps just to
show off that we can.

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15 17:41:57 -08:00
Dirk Hohndel
c3a08ff056 Add diveplan to the dive notes
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-15 17:34:51 -08:00
Dirk Hohndel
189cba7fd2 Add code to enter SAC rates for dive planning
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 ab7aecf16e ("Simplify dive planning code") which broke the
get_tenth() function.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15 17:31:27 -08:00
Lubomir I. Ivanov
678fffdcf4 Added the OS dependent function subsurface_launch_for_uri()
Opening URI addresses from Subsurface does not work on Windows using
the latest GTK bundle from the Gnome website. The reason lies in GIO
and GLib and how it obtains assigned applications for protocols and MIME
types.

While gtk_show_uri() should be viable for both linux.c and macos.c,
in windows.c ShellExecute() is used, which provides proper support
for the URI calls.

subsurface_launch_for_uri() returns TRUE on success.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-15 08:51:32 -08:00
Jan Schubert
90d3c5614a Centralising and redefining values as integers
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-14 20:12:40 -08:00
Dirk Hohndel
23ce727e62 Add support for MOD, EAD, AND and EADD in the mouse over display
- MOD: Maximum Operation Depth based on a configurable limit
- EAD: Equivalent Air Depth considering N2 and (!) O2 narcotic
- END: Equivalent Nitrogen (Narcotic) Depth considering just N2 narcotic
       (ignoring O2)
- EADD: Equivalent Air Density Depth

Please note that some people and even diving organisations have opposite
definitions for EAD and END. Considering A stands for Air, lets choose the
above. And considering N for Nitrogen it also fits in this scheme.

This patch moves N2_IN_AIR from deco.c to dive.h as this is already used
in several places and might be useful for future use also. It also
respecifies N2_IN_AIR to a more correct value of 78,084%, the former one
also included all other gases than oxygen appearing in air. If someone
needs to use the former value it would be more correct to use 1-O2_IN_AIR
instead.

Signed-off-by: Jan Schubert / Jan.Schubert@GMX.li
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-13 16:26:35 -08:00
Pierre-Yves Chibon
8ff350387d Work on a dive localisation tool using GPS coordinates
For each dive recorded, place their GPS coordinates onto a map using the
OSM-GPS-MAP library.

This map is accessible via the "log" menu or the shortcut ctrl+M (M as map).

We check for the GPS coordinates "0, 0" which are the default when we do not
have real GPS coordinates set.

[Dirk Hohndel: fixed int/float math confusion, fixed some whitespace and
               coding style issues, cleaned up some comments, added a
	       missing cast to prevent a compiler warning]

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
Signed-Off-By: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-13 10:08:07 -08:00
Linus Torvalds
6a10700ca5 Add default filename and divelist font to prefs structure
.. and add the usual logic to not save the default values.

This also simplifies the initial system-specific setup of both of these:
since we have defaults for all the preferences that get set up at
startup, we can just initialize those defaults to the system-specific
fonts then and there.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-11 17:46:00 -08:00
Linus Torvalds
868a2cc090 Split up preference data structure definition into 'pref.h'
.. 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-10 20:30:32 -08:00
Linus Torvalds
ec38d3708d Move device_info handling into a new 'device.c' file
The legacy nickname wrappers (that use the device_info structure) are
left in gtk-gui.c.  We can slowly start moving away from them, we don't
want to start exporting that thing as some kind of generic interface.

This isn't a pure code movement - because we leave the legacy interfaces
alone, there are a few new interfaces in device.c (like "create a new
device_info entry") that were embedded into the legacy "create nickname"
code, and needed to be abstracted out.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-09 16:19:38 -08:00
Linus Torvalds
88313f1077 Clean up duplicated depth interpolation
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-09 16:17:57 -08:00
Robert C. Helling
67d59ff018 Rewrite of the deco code
o) Instead of using gradient factors as means of comparison, I now use
   pressure (as in: maximal ambient pressure).

o) tissue_tolerance_calc() now computes the maximal ambient pressure now
   respecting gradient factors. For this, it needs to know about the
   surface pressure (as refernce for GF_high), thus gets *dive as an
   argument. It is called from add_segment() which this also needs *dive
   as an additional argument.

o) This implies deco_allowed_depth is now mainly a ambient-pressure to
   depth conversion with decorations to avoid negative depth (i.e. no deco
   obliation), implementation of quantization (!smooth => multiples of 3m)
   and explicit setting of last deco depth (e.g. 6m for O2 deco).

o) gf_low_pressure_this_dive (slight change of name), the max depth in
   pressure units is updated in add_segment. I set the minimal value in
   buehlmann_config to the equivalent of 20m as otherwise good values of
   GF_low add a lot of deco to shallow dives which do not need deep stops
   in the first place.

o) The bogus loop is gone as well as actual_gradient_limit() and
   gradient_factor_calculation() and large parts of deco_allowed_depth()
   although I did not delete the code but put it in comments.

o) The meat is in the formula in lines 147-154 of deco.c. Here is the
   rationale:

   Without gradient factors, the M-value (i.e the maximal tissue pressure)
   at a given depth is given by ambient_pressure / buehlmann_b + a.

   According to "Clearing Up The Confusion About "Deep Stops" by Erik C.
   Baker (as found via google) the effect of the gradient factors is no
   replace this by a reduced affine relation (i.e. another line) such that
   at the surface the difference between M-value and ambient pressure is
   reduced by a factor GF_high and at the maximal depth by a factor
   GF_low.

   That is, we are looking for parameters alpha and beta such that

   alpha surface + beta = surface + gf_high * (surface/b + a - surface)

   and

   alpha max_p + beta = max_p + gf_low * (max_p/b + a - max_p)

   This can be solved for alpha and beta and then inverted to obtain the
   max ambient pressure given tissue loadings. The result is the above
   mentioned formula.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08 08:59:20 -08:00
Dirk Hohndel
989cf37fcf Remove the now obsolete hard coded test_plan
This was just a crutch to get something out there for people to play with.
With the ability to input a plan in place this is now obsolete.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07 08:51:26 -08:00
Dirk Hohndel
85ed689dc0 Support relative times in diveplanner input "on the fly" mode
This had gotten lost when updating the profile on the fly.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07 08:13:23 -08:00
Dirk Hohndel
be9be189f7 Display dive profile of the dive we plan, as we plan it
As the user enters data into the entry fields, that data is validated and
as soon as there is enough data we start constructing a dive profile,
including the final ascent to the surface, including required deco stops,
etc.

This commit still has some serious issues.

- when data is input that doesn't validate, we just print a warning to
  stdout - instead we need to change the backgroundcolor of the input
  field or something.
- when we switch to the last dive in order to show the profile we don't
  actually search for the last dive - we just show the first one in the
  tree. This works for the default sort order but is of course wrong
  otherwise

I'm sure there are many other bugs, but I want to push it out where it is
right now for others to be able to take a look.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 22:15:03 -08:00
Dirk Hohndel
c8830ffe48 Add the ability to cache our deco state
We kept reduing all the deco calculations, including the previous dives
(if any) for each segment we add to the dive plan. This simply remembers
the last stage and then just adds to that.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 11:40:21 -08:00
Linus Torvalds
92a8fde9c2 Do a minimal hook-up of the dive plan tree view to the
actual planning

Yes, you can actually enter your segments now.

No, it's not wonderfully user-friendly.  If you don't enter enough
segments to create a dive plan, it will just silently fail, for example.
And the <tab> key that should get you to the next editable segment
doesn't.  And so on.  But it kind of works.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-05 15:51:57 -08:00
Dirk Hohndel
cca847791a First stab at simplistic dive planning
This comes with absolutely no gui - so the plan literally needs to be
compiled into Subsurface. Not exactly a feature, but this allowed me to
focus on the planning part instead of spending time on tedious UI work.

A new menu "Planner" with entry "Test Planner" calls into the hard-coded
function in planner.c. There a simple dive plan can be constructed with
calls to plan_add_segment(&diveplan, duration, depth at the end, fO2, pO2)

Calling plan(&diveplan) does the deco calculations and creates deco stops
that keep us below the ceiling (with the GFlow/high values currently
configured). The stop levels used are defined at the top of planner.c in
the stoplevels array - there is no need to do the traditional multiples of
3m or anything like that.

The dive including the ascents and deco stops all the way to the surface
is completed and then added as simulated dive to the end of the divelist
(I guess we could automatically select it later) and can be viewed.

This is crude but shows the direction we can go with this. Envision a nice
UI that allows you to simply enter the segments and pick the desired
stops.

What is missing is the ability to give the algorithm additional gases that
it can use during the deco phase - right now it simply keeps using the
last gas used in the diveplan.

All that said, there are clear bugs here - and sadly they seem to be in
the deco calculations, as with the example given the ceiling that is
calculated makes no sense. When displayed in smooth mode it has very
strange jumps up and down that I wouldn't expect. For example with GF
35/75 (the default) the deco ceiling when looking at the simulated dive
jumps from 16m back up to 13m around 14:10 into the dive. That seems very
odd.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-04 23:56:55 -08:00
Dirk Hohndel
6dc247ff78 Fix deco calculations to correctly use GF values and add CC support
The old implementation was broken in several ways.

For one thing the GF values are percentages, so they should normally be
0 < GF < 1 (well, some crazy people like to go above that).

With this most of the Bühlmann config constants were wrong.

Furthermore, after we adjust the pressure tolerance based on the gradient
factors, we need to convert this back into a depth (instead of passing
back the unmodified depth - oops).

Finally, this commit adds closed circuit support to the deco calculations.

Major progress and much more useful at this stage.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-04 11:13:14 -08:00