Commit graph

371 commits

Author SHA1 Message Date
Dirk Hohndel
c109b98f19 Change one more spot in divelist.c from locations to dive sites
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-12 21:30:57 -08:00
Dirk Hohndel
7fb35c98d3 Get trip location from dive's dive site
This adds another useful helper function as well.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-12 12:49:25 -08:00
Anton Lundin
58173d711c Have get_dive_gas return air when without cylinders
If we called get_dive_gas on a dive without cylinders, we returned 100%,
which is quite wrong. This makes us return air as default gas instead.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-25 07:23:27 -08:00
Anton Lundin
37830bdb53 Always show deco gas as dive gas
This unifies how we prints Nitrox deco gas dives with Trimix deco gas
dives.

Reviewed-By: Joakim Bygdell <j.bygdell@gmail.com>
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-06 15:04:10 -08:00
Miika Turkia
c2b076548d Fix a crash when dive date is epoch
With a dive that's date is 1970-01-01, starting at 00:00 the assert
causes subsurface to crash when performing auto grouping. This happens
to be a perfectly valid date, and we might end up getting such dates
when importing dives from other software, so removing the assert.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-02 22:42:03 -08:00
Dirk Hohndel
0b31854031 Deselect dives that are no longer shown as the dive list is filtered
This cleans up the way we ensure that all dives are handled as the dive
list is filtered.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-12 14:07:07 -08:00
Dirk Hohndel
71b6de0523 Dive list and filter: when selecting a trip, only select visible dives
Otherwise dives that aren't shown to the user would be included in
statistics or (worse) in edit operations.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-11 13:40:36 -08:00
Robert C. Helling
20a9db779d Offer to save to a copy in replan mode
When replannig a dive, offer another button that creates a new
dive rather than overwriting the old. This should help in creating
several versions of a planned dive (longer/shorter, deeper/shallower
etc). Note that this makes dives that start at the same time not
influcence each other's deco.

Also, only the first of a row of simultaneous dives contributes to
the tissue loadings of later dives.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-04 07:21:34 -08:00
Robert C. Helling
06ddfc0122 Prepare for PSCR calculations
Calculations for passive semi-closed rebreathers are pretty much like OC
except the pO2 is lower bey a certain (SAC dependent) factor. This patch
introduces the corresponding calculations in case dctype == PSCR which is
so far never set and there is currently no UI for these calculations. As
pO2 is SAC dependent it takes a certain attempt at getting it and drops to
defaults from the prefs otherwise.

As there is no UI at this point and I also don't have any dives, this has
not received much testing, yet, but it compiles. At least.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-04 07:13:04 -08:00
Robert C. Helling
5f44fdd9cf Make planner work again for CCR dives
The latest CCR patches had rendered the planner not usable for CCR dives.
This patch corrects this (and reenables the CCR set point column for
segments). The problem was that a new member setpoint of struct divepoint
had been introduced, but there was already po2 which had the same meaning.
This patch merges the two and renames them setpoint to prevent future
confusion.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-19 07:07:07 -07:00
Dirk Hohndel
0f1381f160 Planner: assign a dive number if the right number seems obvious
Use the same logic as we do for newly added dives.
As a side effect this patch appears to fix the issues with getting the
newly planned dive selected.

Fixes #692

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-08-18 14:12:05 -05:00
Dirk Hohndel
da07b4e5d7 Make divelist gas column slightly easier to understand
Since printing EANxx was met with a lot of resistance as it wastes space,
maybe this makes things slightly better at least.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-08-16 15:50:28 -06:00
Anton Lundin
d453d5cb37 Rename dive gas function and defines for clarity
This renames the dive gas functions to not talk about just nitrox, and
to instead talk about gas.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-08-11 08:41:57 -07:00
Dirk Hohndel
17bcd1bc60 get_gas_at_time needs to always give us a valid gas
Before this function was changed it was really supposed to just change a
gas that was passed in in case there was an event that changed the mix -
but with the new name the caller will assume that they get a valid gasmix.
And promptly we had one caller that didn't initialize gas to be based on
the first cylinder before calling get_gas_at_time().

Instead of adding yet one more spot that knows about the oddity of the old
API I simply changed get_gas_at_time() to do what it name appears to imply
and fixed the other callers not to bother to initialize the gasmix.

Fixes #647

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-18 18:46:51 -07:00
Anton Lundin
345b01750a Use get_gas_at_time in active_o2
active_o2 is now just a wrapper to return the o2 part of the active gas at
a certain time.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-18 10:14:27 -07:00
Anton Lundin
950638ec1c Replace cylinder_is_used with is_cylinder_used
is_cylinder_used uses get_cylinder_index as underlaying function that
does the right thing with with respect on how to find the closest
matching cylinder, and handles both types of gaschange events correctly.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-17 08:28:21 -07:00
Robert C. Helling
954d401483 Considering previous dives for tissue loading
This (hopefully) gets the logic to find dives in the previous 48h for
tissue pre-loading right. In particular it handles the case of a planned
dive which has a number of -1.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-08 13:01:34 -07:00
Dirk Hohndel
947d7b77df Don't crash if get_divenr is called with NULL argument
We shouldn't be doing that, but still, let's not crash.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-03 21:18:40 -07:00
Dirk Hohndel
b298306eb1 UI restructure: fix get_divenr to do the right thing on a copy of a dive
We should not care if the dive has the same address in memory. We care if
it is the same dive (by using the unique ID).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-02 12:50:00 -07:00
Robert C. Helling
e38a473a4d Deco artefacts with low GFlow
In a dive, when you choose a very low GFlow (like 5 or 9) and a trimix
with quite some He (12/48 in the example) and descend fast, the ceiling
seems to do strange things in the first minutes of the dive (very very
deep for example or jumping around).

To understand what is going on we have to recall what gradient factors do
in detail: Plain Buehlmann gives you for each tissue a maximal inert gas
pressure that is a straight line when plotted against the ambient
pressure. So for each depth (=ambient pressure) there is a maximally
allowed over-pressure.

The idea of gradient factors is that one does not use all the possible
over-pressure that Buehlmann gives us but only a depth dependent fraction.
GFhigh is the fraction of the possible over-pressure at the surface while
GFlow is the fraction at the first deco stop. In between, the fraction is
linearly interpolated. As the Buehlmann over-pressure is increasing with
depth and typically also the allowed overpressure after applications of
gradient factors increases with depth or said differently: the tissue
saturation has to be lower if the diver wants to ascent.

The main problem is: What is the first stop (where to apply GFlow)? In a
planned dive, we could take the first deco stop, but in a real dive from a
dive computer download it is impossible to say what constitutes a stop and
what is only a slow ascent?

What I have used so far is not exactly the first stop but rather the first
theoretical stop: During all of the dive, I have calculated the ceiling
under the assumption that GFlow applies everywhere (and not just at a
single depth). The deepest of these ceilings I have used as the “first
stop depth”, the depth at which GFlow applies.

Even more, I only wanted to use the information that a diver has during
the dive, so I actually only considered the ceilings in the past (and not
in the future of a given sample).

But this brings with it the problem that early in the dive, in particular
during the descent the lowest ceiling so far is very shallow (as not much
gas has built up in the body so far).

This problem now interferes with a second one: If at the start of the dive
when the all compartments have 790mbar N2 the diver starts breathing a
He-heavy mix (like 12/48) and descents fast the He builds up in the
tissues before the N2 can diffuse out. So right at the start, we already
encounter high tissue loadings.

If now we have a large difference between GFhigh and GFlow but they apply
at very similar depth (the surface and a very shallow depth of the deepest
ceiling (which for a non-decompression dive would be theoretically at
negative depth) so far) it can happen that the linear interpolation as
opposite slope then in the typical case above: The allowed over-pressure
is degreasing with depth, shallower depth do not require lower gas loading
in the tissue (i.e. can be reached after further off-gasing) but but
tolerate higher loadings. In that situation the ceiling disappears (or is
rather a floor).

So far, I got rid of that problem, by stating that the minimum depth for
GFlow was 20m (after all, GFlow is about deep stops, so it should better
not be too shallow). Now the dive reported in ticket #549 takes values to
an extreme in such away that 20m (which is determined by
buehlmann_config.gf_low_position_min in deco.c) was not enough to prevent
this inversion problem (or in a milder form that the interpolation of
gradient factors is in fact an extrapolation with quite extreme values).

This patch that gets rid of the problem for the dive described above but
still it is possible to find (more extreme) parameter choices that lead to
non-realistic ceilings.

Let me close by pointing out that all this is only about the descent, as
it is about too shallow depth for GFlow. So no real deco (i.e. later part
of the dive) is inflicted. This is only about a theoretical ceiling
displayed possibly in the first minutes of a dive. So this is more an
aesthetically than a practical problem.

Fixes #549

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-25 17:57:21 +08:00
Anton Lundin
3f74389b88 CNS doesn't increase when PO2 is below 0.5 atm
When chasing other bug in CNS code i found this.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-18 05:05:54 -07:00
Robert C. Helling
1b2d3c29d3 Correct pO2 formula in CNS calculation.
In commit e58f54cac1 ("Fix ATM-vs-bar confusion") Linus broke the CNS
calculations; The partial pressure is fraction of gas times ambient
pressure, not divided by.

[Dirk Hohndel: identical patch sent by Robert and Anton; I combined the
               commit messages and added the ACK from the perpetrator]

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-12 14:12:30 -07:00
Dirk Hohndel
cbdf3ee042 Fix typo that broke gas reporting in dive list
The brainless idiot who implemented commit c539c8f861 ("Remove the .used
member of the cylinder structure") clearly worked on the basis of "it
compiles, it must be perfect".

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-04 08:52:28 -07:00
Willem Ferguson
eaf6d56487 CCR code: Change to sample structure
1) All the variables in the sample structures are strongly typed
2) Two additional types were declared in units.h:
     o2pressure_t
     bearing_t
3) The following variables were added:
     diluentpressure
     o2setpoint
     o2sensor[3]
4) Changes to a number of files were made to chanf
     sample->po2 to sample->po2.mbar
     bearing to bearring.degrees

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03 17:05:25 -07:00
Dirk Hohndel
c539c8f861 Remove the .used member of the cylinder structure
Instead calculate this information on the fly, taking into account all
dive computers on the dive in questions.

There is one wrinkle to this - previously we abused the '.used' member to
make sure that a manually added cylinder didn't disappear the moment it
was added (think of the workflow: you add a cylinder, then you add a gas
change to that cylinder -> right after you add it it is unused and would
not be shown).

I am thinking that we might have to add the "manually_added" property to
the properties that we store in XML / git.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-01 12:43:40 -07:00
Dirk Hohndel
1a04013453 Encapsulate the horrid gas encoding in gas change events
We should never pass permille values around as integers. And we shouldn't
have to decode the stupid value in more than one place.

This doesn't tackle all the places where we access O2 and He "too early"
and should instead keep passing around a gaxmix. But it's a first step.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-01 12:07:29 -07:00
Dirk Hohndel
e4b8cf89a1 Dive list: move trip merging logic into divelist.c
This also fixes a couple of issues with the existing code:
- removes a memory leak
- treats null and "" the same

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-24 14:03:36 -07:00
Dirk Hohndel
dbb86374e0 Dive list: move trip selection / deselection logic to divelist.c
This is core logic, not UI code.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-24 13:19:05 -07:00
Dirk Hohndel
ba1c4fcec1 Add some helper functions
First step towards getting the "add to trip" logic in the divelist context
menu to be consistent and correct.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-24 08:27:42 -07:00
Anton Lundin
0f0ddf86fe Use get_o2 instead of local version
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-20 11:51:46 +09:00
Dirk Hohndel
4d14059d7c Remove unused variables
These were leftover in commit 90638180d2 ("Use the used flag on
cylinders in get_dive_gas").

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-19 20:12:59 +09:00
Linus Torvalds
a8fbd3d283 Mark new dives "downloaded" when importing new dives
We used to do this just for dive computer downloads, but we should do it
for all imports, so that merging new import data always does the
expected thing: any new dive computers will be added to the end of the
list of preexisting dives, rather than the other way around.

(Of course, if you set the "prefer downloaded" flag, that reverses this
logic, and makes the newly imported dive computer data be the primary
dive computer.  That flag is currently only exported for dive computer
downloads, not for imports).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-14 15:39:29 +09:00
Tomaz Canabrava
c86d055db7 Do not check for null before free.
C specs says that we can safelly free a NULL pointer, so there's no reason
to check if it's null before freeing it.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-13 09:26:50 +09:00
Anton Lundin
90638180d2 Use the used flag on cylinders in get_dive_gas
Now when we have a used flag on every cylinder that are set in
mark_used_tanks we can use it here.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-08 14:58:11 -07:00
Linus Torvalds
0c5ec1d6db Don't calculate SAC-rates for negative pressure changes
They happen - maybe the cylinder actually warmed up, or maybe the user
entered just a ending pressure without a starting pressure.  Regardless,
just ignore cylinder pressure changes that go up.

Also ignore cylinders with a zero ending pressure: that's really a
*missing* pressure rather than an actual zero pressure.  As Dirk says,
the scuba regulators don't even work without a healthy positive pressure
differential, so even when you breathe down a tank to "empty", it won't
be at zero pressure (this is true even with gauge pressure, where zero
means "atmospheric pressure").

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-26 17:24:12 -07:00
Linus Torvalds
eb47b2a8d8 Get rid of crazy empty tag_list element at the start
So this is totally unrelated to the git repository format, except for
the fact that I noticed it while writing the git saving code.

The subsurface divetag list handling is being stupid, and has a
initial dummy entry at the head of the list for no good reason.

I say "no good reason", because there *is* a reason for it: it allows
code to avoid the special case of empty list and adding entries to
before the first entry etc etc.  But that reason is a really *bad*
reason, because it's valid only because people don't understand basic
list manipulation and pointers to pointers.

So get rid of the dummy element, and do things right instead - by
passing a *pointer* to the list, instead of the list. And then when
traversing the list and looking for a place to insert things, don't go
to the next entry - just update the "pointer to pointer" to point to
the address of the next entry. Each entry in a C linked list is no
different than the list itself, so you can use the pointer to the
pointer to the next entry as a pointer to the list.

This is a pet peeve of mine. The real beauty of pointers can never be
understood unless you understand the indirection they allow. People
who grew up with Pascal and were corrupted by that mindset are
mentally stunted. Niklaus Wirth has a lot to answer for!

But never fear. You too can overcome that mental limitation, it just
needs some brain exercise. Reading this patch may help. In particular,
contemplate the new "taglist_add_divetag()".

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-10 11:36:17 -07:00
Dirk Hohndel
0b7c11a597 Another case of 'dereference before NULL check'
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-08 16:49:34 -08:00
Dirk Hohndel
9ee0bfe633 Don't use dive before checking it against NULL
Dive gets dereferenced in get_surface_pressure_in_mbar().

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-08 16:47:06 -08:00
Dirk Hohndel
d24d2288f3 Remove pointless assignments
tissue_tolerance wasn't used after it was assigned.
type was overwritten after it was assigned.
serial was overwritten after the last /= 100.
event is assigned in the for loop.
clear isn't used after the assignment

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-03 21:40:56 -08:00
Dirk Hohndel
7c535452f9 Whitespace cleanup
Minor change to the perl postprocessing script and resulting changes to
the affected source files.

This deals with two issues:
- "foreach"-like structures were not always treated correctly
- some longer calculations that ended on "+ constant" were reformatted in
  a rather unatractive manner

In one source file (divelist.c) I ended up adding braces to the sources...
trying to cascade the indentation further down without having the block
there seemed a lot more trouble than it's worth.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-03 13:29:22 -08:00
Dirk Hohndel
76e6420f6b Massive automated whitespace cleanup
I know everyone will hate it.
Go ahead. Complain. Call me names.
At least now things are consistent and reproducible.
If you want changes, have your complaint come with a patch to
scripts/whitespace.pl so that we can automate it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-27 20:09:57 -08:00
Linus Torvalds
23baf20f56 Use "rint()" instead of rounding manually with "+ 0.5"
rint() is "round to nearest integer", and does a better job than +0.5
(followed by the implicit truncation inherent in integer casting).  We
already used 'rint()' for values that could be negative (where +0.5 is
actively wrong), let's just make it consistent.

Of course, as is usual for the messy C math functions, it depends on the
current rounding mode.  But the default round-to-nearest is what we want
and use, and the functions that explicitly always round to nearest
aren't standard enough to worry about.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-12 17:41:49 -08:00
Linus Torvalds
e58f54cac1 Fix ATM-vs-bar confusion
SAC should be calculated in relationship to surface pressure, not "1 bar".

I also realize that we have a few other cases where we do the same
mistake: the partial pressure calculations do things like

    po2 = o2 / 1000.0 * depth_to_mbar(sample->depth.mm, dive);

which is wrong as well - the partial pressure is also relative to
standard atmospheric pressures.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-11 14:05:54 -08:00
Boris Barbulovski
772c9fb0b1 Fix calloc parameter order.
* Set correct calloc parameters order(num, size)

Signed-off-by: Boris Barbulovski <bbarbulovski@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-10 07:56:09 -08:00
Anton Lundin
33391a77e9 Convert the C code to using stdbool and true/false
Earlier we converted the C++ code to using true/false, and this converts
the C code to using the same style.

We already depended on stdbool.h in subsurfacestartup.[ch], and we build
with -std=gnu99 so nobody could build subsurface without a c99 compiler.

[Dirk Hohndel: small change suggested by Thiago Macieira: don't include
               stdbool.h for C++]

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16 09:34:50 +07:00
Dirk Hohndel
9c617534a0 When merging dives, keep dive ids in mind
We try to do the most reasonable thing. If you have an existing dive and
merge a just downloaded dive with it - the you want the existing id.
If you merge two consecutive dives, then the start of the merged dive is
the earlier of those two dives so we keep that id.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-07 12:03:49 +08:00
Rodrigo Severo
763c64d0da Typos on comments
Fixing 2 typos on comments.

Signed-off-by: Rodrigo Severo <rodrigo@fabricadeideias.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-01 09:44:51 -08:00
Dirk Hohndel
719b732230 Fix incorrect handling of autogrouped trips
When toggling autogroup in the menu we ended up setting the NO_TRIP flag
for dives that were removed from a trip that was created by autogroup. So
toggling things on and off and on again meant no more auto grouping.

Fixes #337

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-12 15:03:25 -08:00
Lubomir I. Ivanov
f09afad5a0 divelist.c: Fix possible NULL pointer deref.
calculate_cns():
The check if prev_dive is NULL should be before calling
prev_dive->when.

Reported by the program cppcheck.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-11 16:29:02 +01:00
Anton Lundin
1e92a8e648 Remove extra local variable declaration
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-11 03:13:30 +01:00