Commit graph

79 commits

Author SHA1 Message Date
Anton Lundin
b48eb47178 Fix up CCR/PSCR dives with sensors values without no_o2sensors
This introduces a fixup function that walks all the samples and
populates the no_o2sensors if its zero and supposed to be something
else.

There is a bug somewhere which Willem hit, causing this to never be set.

Reported-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2018-03-13 18:54:16 +02:00
Anton Lundin
15b6953438 Use the current dive mode instead of constant
In the if case above, we already conclude its a OC dive, but its cleaner
to actually pass the current mode instead of a hard coded value.

This also makes the code less prune to future bugs.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2018-03-13 18:54:16 +02:00
Berthold Stoeger
bdc470a80e Cleanup: Remove hash field from picture-structure
The hash field in the picture-structure was in principle non-operational.
It was set on loading, but never actually changed. The authoritative
hash comes from the filename->hash map.

Therefore, make this explicit by removing the hash field from the
picture structure.

Instead of filling the picture structure on loading, add the
hash directly to the filename->hash map. This is done in the
register_hash() function, which does not overwrite old entries.
I.e. the local hash has priority over the save-file. This
policy might be refined in the future.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 18:04:57 +02:00
Stefan Fuchs
4cbf8b87a3 Updated strategy for removing cylinders
Change the strategy when to allow cylinder removal from a dive:
- Not remove when cylinder has gas switch events, in any other cases
  allow removal
- Remove this whole "cylinder with same gas" thing being a criteria
  for cylinder removal

When removing a cylinder which has corresponding pressure info in
samples, also remove this pressure info from the samples.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-27 09:17:57 +01:00
Berthold Stoeger
cd5e17cf79 Cleanup: Unify qthelper.h and qthelperfromc.h
Since all qt-helpers are defined in qthelper.cpp, there seems to be
no reason to have two include files. By unifying the two files,
duplication and inconsistencies are removed. The C++-only part is
simply compiled away with #ifdefs.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-26 19:06:02 +02:00
Berthold Stoeger
5c248d91cd Coding-style: remove superfluous parentheses
Mostly replace "return (expression);" by "return expression;" and one
case of "function((parameter))" by "function(parameter)".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-17 19:38:52 -08:00
Robert C. Helling
920aa613c9 Add a preference to turn on ICD warnings
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-02-10 10:26:34 +01:00
Robert C. Helling
c89cfcccbe Only give ICD warning if pN2 increases
as otherwise there are warning on the descent.

The ICD line in the info box is generated for all
gas switches with decreasing He content.

Also change the presentation in the info box to align it
with the notes.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-01-21 15:24:46 +01:00
Willem Ferguson
f2fe389abd Move function isobaric_counterdiffusion()
Move the above function from plannernotes.c to dive.c so that
it is available to be called from the dive log part of the
software, and not only from the planner. The following was done:

1) Edit the comment above the code to make it more accurate
2) Move the structure icd_data to dive.h
3) Create an external reference in dive.h for the above function
4) Copy the body of isobaric_counterdiffusion() to dive.c

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-20 10:10:09 +01:00
Berthold Stoeger
e85ecdd925 Introduce helper function empty_string()
There are ca. 50 constructs of the kind
  same_string(s, "")
to test for empty or null strings. Replace them by the new helper
function empty_string().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-11 06:07:13 +01:00
Jan Mulder
5faf3f9410 Unused code: has_hr_data()
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10 16:45:42 +01:00
Jan Mulder
1c03075f24 Unused code: remove taglist_contains_all()
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10 16:45:42 +01:00
Jan Mulder
3cd3653972 Unused code: remove taglist_equal()
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10 16:45:42 +01:00
Jan Mulder
768f0db991 Unused code: remove shift_times()
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2018-01-10 16:45:42 +01:00
Dirk Hohndel
f4237bf843 Cleanup: prevent out of bounds read
Don't access cylinder[MAX_CYLINDERS]

Coverity CID 208324

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 14:25:57 -08:00
Stefan Fuchs
82170579ad Enable removal of pictures from different dives at the same moment
Suggested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-13 05:48:20 -08:00
Dirk Hohndel
39ed1b657a Cleanup: remove unused parameter
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-08 16:29:49 +01:00
Berthold Stoeger
03e87437e3 Gracefully handle deletion of a picture that doesn't exist
The list iteration in dive_remove_picture() was buggy and would
crash if handled a picture that is not in the list.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-04 18:34:03 +01:00
Stefan Fuchs
a95cc2b1c5 Merging dives: Improve merging of divemaster, buddy and notes
Change the merging behavior for the following information:

Divemaster, buddy, suit:
From "(a) or (b)" to "a, b"

Notes:
From "(a) or (b)" to "a\n--\nb"

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-28 23:58:35 +01:00
Stefan Fuchs
b17f1e2d30 Use MAX_SENSORS define everywhere
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-27 22:40:16 +01:00
Berthold Stoeger
6ae16b87d0 Constify strings in pref.h
Make all char * pointers in pref.h const to make it clear that these
strings are not mutable. This meant adding a number of (void *) casts
in calls to free(). Apart from being the right thing to do, this commit
makes the code more consistent, as many of the strings in pref.h were
already const.

While touching core/qthelper.cpp turn three instances of (void*) into
(void *).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-18 21:57:33 +01:00
Stefan Fuchs
85d00d1e7c For surface samples init ndl and compass bearing from prev sample
This avoids printing useless info to the XML file.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-16 08:32:46 +01:00
Stefan Fuchs
a8d4ff308d New fixup function fixup_dc_ndl
Fixup the NDL value to '-1' at the very beginning of a dive.
Some dive computer report a NDL of 0 at the very beginning of a dive
and then only some 10 seconds later they report the correct value
like 240 min for the first time.
Translate this 0 at the beginning of a dive into our internal '-1'
for no info available.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-13 20:50:10 -08:00
Stefan Fuchs
adbc71f9da Init every struct sample with default values
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-13 20:50:10 -08:00
Stefan Fuchs
1f8506ce64 Display values in info box only if value is interesting
Type duration_t changed from uint to int.

Default value of '-1' introduced for some of the values in struct sample:
NDL used -1 as default.
Bearing uses -1 as default (no bearing set).

Display pXX, EAD, END, density, MOD only if values are larger than 0.

In profile don't display data from two first and two last plot_data
entries in info box.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-13 20:50:10 -08:00
Miika Turkia
4fe8eb6f65 Do not overwrite start and end pressures on cylinder
The pressure information of cylinder should be kept intact when
copy-pasting other cylinder related information from other dive.

According to Dirk, the gas mix is wanted to be changed as technical
divers might have always the same multiple cylinders and wish to copy
the gasmix information over.

Fixes #689

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-10-20 15:16:11 +02:00
Stefan Fuchs
df6933326d In dive.c make cylinder_renumber an external function...
instead of dc_cylinder_renumber() because it is the one which is really
useful elsewhere.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-16 17:14:17 +02:00
Stefan Fuchs
c29456f0bb Used gas in dive planner points: Support for multiple cyl with same gas
In the planner if one adds two or more cylinders with the same gasmix
(e.g. back gas and bottom stage 18/45) the drop down and data in the
used gas column of the planner points table will be filled with a more
verbose string mentioning also the cyl number and the cyl type
description.
Makes it easier in such a case to select the right cylinder.

Introduces also a helper function which tells you if there is another
cylinder with the same gasmix as the provided cylinder.
This also has an option if it should consider unused cylinders or not.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-16 17:14:17 +02:00
Stefan Fuchs
c127a92e8e Explicitly copy a cylinder which was marked as "unused" in the planner
When planning a new dive (not replan!!!) based on an existing (planned)
dive, the cylinders from the existing selected dive are copied.
This patch guarantees that cylinders which had been marked as "unused"
are indeed copied as well. Sounds strange at the first moment but makes
sense because if one marks a cylinder explicitly as "unused" in the
planner instead of deleting it that does mean that one wants to keep
this cylinder to have it available and be able to reenable it later-on.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-05 20:32:35 +02:00
Miika Turkia
325c4459ad Update sample_start and sample_end pressures
When we merge dives, the sample_start and sample_end pressures are only
used in-memory for displaying data to the user. However, we should
update them as well as this will show the user the correct data in the
equipment/cylinder and i.e. SAC calculation.

Fixes #577

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-10-01 11:31:18 +03:00
Miika Turkia
5b5cab2905 Do not merge dives with zero duration
As these are probably manually entered dives with incomplete data, it is
better not to merge them.

See #561

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-09-11 07:19:57 -07:00
Linus Torvalds
df1bd0015a Calculate momentary SAC rates with the right gases
The momentary SAC rate got broken by the multiple ressure handling too,
and always used just the first cylinder.

This uses the new "get_gasmix()" helper to see what you're breathing,
and will do the SAC rate over all the cylinders that contain that gas.
So it should now DTRT even for sidemount diving (assuming you had the
same gas in the sidemount cylinders).

NOTE! We could just do the SAC rate over *all* the gases you have
pressures for, and maybe that's the right thing to do.  The ones you are
not breating from shouldn't have their pressure change.  But maybe some
people add their drysuit argon gas to the gas list?

So this may need more work, but it's a step in the right direction.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-28 21:50:23 -07:00
Linus Torvalds
e1b880f444 Profile support for multiple concurrent pressure sensors
This finally handles multiple cylinder pressures, both overlapping and
consecutive, and it seems to work on the nasty cases I've thrown at it.

Want to just track five different cylinders all at once, without any
pesky gas switch events? Sure, you can do that.  It will show five
different gas pressures for your five cylinders, and they will go down
as you breathe down the cylinders.

I obviously don't have any real data for that case, but I do have a test
file with five actual cylinders that all have samples over the whole
course of the dive.  The end result looks messy as hell, but what did
you expect?

HOWEVER.

The only way to do this sanely was

 - actually make the "struct plot_info" have all the cylinder pressures
   (so no "sensor index and pressure" - every cylinder has a pressure for
   every plot info entry)

   This obviously makes the plot_info much bigger. We used to have
   MAX_CYLINDERS be a fairly generous 8, which seems sane. The planning
   code made that 8 be 20. That seems questionable. But whatever.

   The good news is that the plot-info should hopefully get freed, and
   only be allocated one dive at a time, so the fact that it is big and
   nasty shouldn't be a scaling issue, though.

 - the "populate_pressure_information()" function had to be rewritten
   quite a bit. The good news is that it's actually simpler now, although
   I would not go so far as to really call it simple. It's still
   complicated and suble, but now it explicitly just does one cylinder at
   a time.

   It *used* to have this insanely complicated "keep track of the pressure
   ranges for every cylinder at once". I just couldn't stand that model
   and keep my sanity, so it now just tracks one cylinder at a time, and
   doesn't have an array of live data, instead the caller will just call
   it for each cylinder.

 - get rid of some of our hackier stuff, like the code that populates the
   plot_info data code with the currently selected cylinder number, and
   clears out any other pressures. That obviously does *not* work when you
   may not have a single primary cylinder any more.

Now, the above sounds like all good things. Yeah, it mostly is.

BUT.

There's a few big downsides from the above:

 - there's no sane way to do this as a series of small changes.

   The change to make the plot_info take an array of cylinder pressures
   rather than the sensor+pressure model really isn't amenable to "fix up
   one use at a time". When you switch over to the new data structure
   model, you have to switch over to the new way of populating the
   pressure ranges. The two just go hand in hand.

 - Some of our code *depended* on the "sensor+pressure" model. I fixed all
   the ones I could sanely fix. There was one particular case that I just
   couldn't sanely fix, and I didn't care enough about it to do something
   insane.

   So the only _known_ breakage is the "TankItem" profile widget. That's
   the bar at the bottom of the profile that shows which cylinder is in
   use right now. You'd think that would be trivial to fix up, and yes it
   would be - I could just use the regular model of

     firstcyl = explicit_first_cylinder(dive, dc)
     .. then iterate over the gas change events to see the others ..

   but the problem with the "TankItem" widget is that it does its own
   model, and it has thrown away the dive and the dive computer
   information. It just doesn't even know. It only knows what cylinders
   there are, and the plot_info. And it just used to look at the sensor
   number in the plot_info, and be done with that. That number no longer
   exists.

 - I have tested it, and I think the code is better, but hey, it's a
   fairly large patch to some of the more complex code in our code base.
   That "interpolate missing pressure fields" code really isn't pretty. It
   may be prettier, but..

Anyway, without further ado, here's the patch. No sign-off yet, because I
do think people should look and comment. But I think the patch is fine,
and I'll fix anythign that anybody can find, *except* for that TankItem
thing that I will refuse to touch. That class is ugly. It needs to have
access to the actual dive.

Note how it actually does remove more lines than it adds, and that's
despite added comments etc. The code really is simpler, but there may be
cases in there that need more work.

Known missing pieces that don't currently take advantage of concurrent
cylinder pressure data:

 - the momentary SAC rate coloring for dives will need more work

 - dive merging (but we expect to generally normally not merge dive
   computers, which is the main source of sensor data)

 - actually taking advantage of different sensor data from different
   dive computers

But most of all: Testing.  Lots and lots of testing to find all the
corner cases.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-27 14:45:58 -07:00
Linus Torvalds
c5167f0039 Make sample pressure helper functions available to everybody
We had a "add_sample_pressure()" helper functions that was local to just
the libdivecomputer downloading code, but it really is applicable to
pretty much any code that adds cylinder pressure data to a sample.

Also add another helper: "legacy_format_o2pressures()" which checks the
sample data to see if we can use the legacy format, and returns the o2
pressure sensor to use for that legacy format.

Because both the XML and the git save format will need a way to save the
compatible old-style information, when possible, but save an extended
format for when we have data from multiple concurrent sensors.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-25 22:04:56 -07:00
Linus Torvalds
adb4b66a05 Try to sanely download multiple concurrent cylinder pressures
This tries to sanely handle the case of a dive computer reporting
multiple cylinder pressures concurrently.

NOTE! There are various "interesting" situations that this whole issue
brings up:

 - some dive computers may report more cylinder pressures than we have
   slots for.

   Currently we will drop such pressures on the floor if they come for
   the same sample, but if they end up being spread across multiple
   samples we will end up re-using the slots with different sensor
   indexes.

   That kind of slot re-use may or may not end up confusing other
   subsurface logic - for example, make things believe there was a
   cylidner change event.

 - some dive computers might send only one sample at a time, but switch
   *which* sample they send on a gas switch event.  If they also report
   the correct sensor number, we'll now start reporting that pressure in
   the second slot.

   This should all be fine, and is the RightThing(tm) to do, but is
   different from what we used to do when we only ever used a single
   slot.

 - When people actually use multiple sensors, our old save format will
   start to need fixing.  Right now our save format comes from the CCR
   model where the second sensor was always the Oxygen sensor.

   We save that pressure fine (except we save it as "o2pressure" - just
   an odd historical naming artifact), but we do *not* save the actual
   sensor index, because in our traditional format that was always
   implicit in the data ("it's the oxygen cylinder").

so while this code hopefully makes our libdivecomputer download do the
right thing, there *will* be further fallout from having multiple
cylinder pressure sensors.  We're not done yet.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-25 06:11:10 -07:00
Linus Torvalds
1e38d9239a Start cleaning up sensor indexing for multiple sensors
This is a very timid start at making us actually use multiple sensors
without the magical special case for just CCR oxygen tracking.

It mainly does:

 - turn the "sample->sensor" index into an array of two indexes, to
   match the pressures themselves.

 - get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index},
   since a CCR dive should now simply set the sample->sensor[] indices
   correctly instead.

 - in a couple of places, start actually looping over the sensors rather
   than special-case the O2 case (although often the small "loops" are
   just unrolled, since it's just two cases.

but in many cases we still end up only covering the zero sensor case,
because the CCR O2 sensor code coverage was fairly limited.

It's entirely possible (even likely) that this migth break some existing
case: it tries to be a fairly direct ("stupid") translation of the old
code, but unlike the preparatory patch this does actually does change
some semantics.

For example, right now the git loader code assumes that if the git save
data contains a o2pressure entry, it just hardcodes the O2 sensor index
to 1.

In fact, one issue is going to simply be that our file formats do not
have that multiple sensor format, but instead had very clearly encoded
things as being the CCR O2 pressure sensor.

But this is hopefully close to usable, and I will need feedback (and
maybe test cases) from people who have existing CCR dives with pressure
data.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 16:33:19 -07:00
Linus Torvalds
11a0c0cc70 Unify sample pressure and o2pressure as pressure[2] array
We currently carry two pressures around for all the samples and plot
info, but the second pressure is reserved for CCR dives as the O2
cylinder pressure.

That's kind of annoying when we *could* use it for regular sidemount
dives as the secondary pressure.

So start prepping for that instead: don't make it "pressure" and
"o2pressure", make it just be an array of two pressure values.

NOTE! This is purely mindless prepwork.  It literally just does a
search-and-replace, keeping the exact same semantics, so "pressure[1]"
is still just O2 pressure.

But at some future date, we can now start using it for a second sensor
value for sidemount instead.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-20 17:32:54 -07:00
Linus Torvalds
9084bbae57 Fix event merging when interleaving dives
The core to avoid adding redundant gas switch events was completely
buggered, and caused the result list to be corrupted if it ever
triggered.  This should fix it.

Fixes: b5de08b7 ("No gas change event on merging dives with same gas")
Reported-by: Jan Mulder <jlmulder@xs4all.nl>
Cc: Miika Turkia <miika.turkia@gmail.com>
Cc: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-30 12:38:09 -07:00
Dirk Hohndel
b368ecd5aa Add SPDX header to remaining core files
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29 13:32:55 -07:00
Dirk Hohndel
16276faa45 Remove unused static functions
These became obsolete with commit e2bbd0ceec ("Rewrite cylinder
merging code from scratch").

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-11 08:51:16 -08:00
Dirk Hohndel
a733aaf967 Remove unused variable
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-11 08:43:24 -08:00
Dirk Hohndel
08284275e7 Merge branch 'master' of https://github.com/dje29/subsurface 2017-03-11 08:41:41 -08:00
Martin Měřinský
dcf2542215 Use abbreviations with dots. 2017-03-11 08:09:07 -08:00
Robert C. Helling
eae4bd82a5 Change type of divedatepoint.depth to depth_t
... for consistency, while we are at it.

There are still some internal depth variables which are ints
somebody might take a go at those.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-03-11 08:03:25 -08:00
Robert C. Helling
295b1b78d8 Make depth conversion work for negative depths
This is needed in the altitude pressure conversion as there
negative altitudes are possible (for diving in the netherlands
or the Dead Sea).

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-03-11 08:03:25 -08:00
Jeremie Guichard
406e4287eb Change calls to rint into lrint avoiding conversion warnings
Using gcc option "-Wfloat-conversion" is useful to catch
potential conversion errors (where lrint should be used).
rint returns double and still raises the same warning,
this is why this change updates all rint calls to lrint.
In few places, where input type is a float, corresponding
lrinf is used.

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2017-03-08 14:04:17 +07:00
Dirk Hohndel
da50bb1ae5 Dive merge: don't pick an empty dive site
When merging, we should treat an empty dive site (which will be deleted
on save) the same as not having a dive site.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-02-21 18:22:56 -08:00
Robert C. Helling
dbd99f706e Many filenames are const strings
So we can use string constants for those

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-02-21 13:14:56 -08:00
Linus Torvalds
fc55620d2d dive merging: merge water temperature too, not just air temperature
I have no idea why we only merged air temperatures.  But it was very
explicit (even the function doing the merging was named
"merge_airtemp()"), and water temperatures were left alone.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-02-19 15:23:46 -08:00
Linus Torvalds
83aff9f777 Fix crash when merging dives with a missing dive computer model
The test for the dive being a planned dive was completely bogus:

 - it should use "same_string()" which correctly checks for NULL

 - the string it checks for is obviously spelled wrong anyway.

Reported-by: Alessandro Volpi <volpial@gmail.com>
Fixes: a031dbbbd ("When merging planned dives keep all cylinders")
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-02-15 21:46:15 -08:00