Commit graph

48 commits

Author SHA1 Message Date
Seppo Takalo
a2a1dfdf9f Use dive ID instead of dive number when importing from Shearwater db
Dive IDs are unique but same dive number can appear multiple times within
the same database. This can happen for example when user changes the
"next log number" from his computer.

Signed-off-by: Seppo Takalo <seppo.takalo@iki.fi>
2017-09-15 08:57:03 -07:00
Seppo Takalo
f7db0c705b Convert usage of atof() to strtod_flags()
The provided strod_flags(str, 0, 0) should work as a drop in replacement
for atof() but does not care about locales which may cause atof() to fail.

strtod_flags() would allow checking of conversion result, but I did not
change the existing logic. This was just regexp search&replace change
to get rid of atof(). I use flags 0 to get more relaxed conversion.

Fixes #574

Signed-off-by: Seppo Takalo <seppo.takalo@iki.fi>
2017-09-15 08:57:03 -07:00
Miika Turkia
5afa5ed9f1 Detect dive mode on Shearwater DB import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-09-13 14:04:31 -07:00
Seppo Takalo
850917d41d Don't assume CCR mode when importing from Shearwater
Logic was assuming CCR mode if field "averagePPO2" was present.

Signed-off-by: Seppo Takalo <seppo.takalo@iki.fi>
2017-09-13 07:57:45 -07:00
Seppo Takalo
ba854a8cc5 Fix cylinder changes when importing from Shearwater database
Re-do the logic to use add_gas_switch_event() instead of creating event
manually.

Fix the SQL query to find the proper dive id from dive log number.

Signed-off-by: Seppo Takalo <seppo.takalo@iki.fi>
2017-09-13 07:57:45 -07:00
Seppo Takalo
83c9ad35a6 Fix Shearwater cylinder detection logic
Fix the SQL query to find proper dive id instead of assuming log number to
be the same as id.

Signed-off-by: Seppo Takalo <seppo.takalo@iki.fi>
2017-09-13 07:57:45 -07:00
Seppo Takalo
6509f2ed9f Ignore missing pressure values when importing from Shearwater
Shearwater seems to report missing AI sensors as a pressure reading
4092 (raw) which is 564 bar.

Signed-off-by: Seppo Takalo <seppo.takalo@iki.fi>
2017-09-13 07:57:45 -07:00
Marc Arndt
48ff047086 adding comments as advised 2017-08-29 06:50:18 -07:00
Marc Arndt
90b9b61ba3 fixing indentation 2017-08-29 06:50:18 -07:00
Marc Arndt
ac7e60b456 Ignore Divesoft Button Press Events
Prevent button press events from showing on the profile
graph when we import divesoft DLF files.

Reported-by: Marc Arndt
Signed-off-by: Marc Arndt <marc@marcarndt.com>
2017-08-29 06:50:18 -07:00
Miika Turkia
fb151df883 Shearwater Perdix
Reportedly the case 2 corresponds to Perdix, so it might be that both
Petrel and Perdix use same model number (or the model is mistaken
before).

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-08-24 13:06:50 -07:00
Miika Turkia
a20aa850da Support for air pressure on Shearwater Desktop import
Fixes #548

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-08-24 13:06:50 -07:00
Miika Turkia
7d22b52afc Grab correct dive number on Shearwater Desktop import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-08-24 13:06:50 -07:00
Anton Lundin
9f290dcdb0 DLF: Parse more measurements, import GPS
This add support for parsing more measurements, and now imports GPS data
to.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2017-08-10 09:09:53 -07:00
Anton Lundin
070c7e545b DLF: Parse Divesoft Liberty data better
There is something with ndl / tts / temp in the Liberty DLF files. If
that bit is set, the values are bogus. There is something more to it
here which I haven't figured out.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2017-08-10 09:09:53 -07:00
Anton Lundin
8f6f9cd39d DLF: Parse diluent changes as a gaschange event
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2017-08-10 09:09:53 -07:00
Anton Lundin
f0303802dd DLF: Import setpoint changes.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2017-08-10 09:09:53 -07:00
Anton Lundin
366ad82a98 DLF: Restructure loop into a for loop
We always step forward 16 bytes, so make it a for loop so a continue
won't throw us into a eternal loop.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2017-08-10 09:09:53 -07:00
Linus Torvalds
efc5f4d9ab Add support for loading and saving multiple pressure samples
This does both the XML and the git save format, because the changes
really are the same, even if the actual format differs in some details.
See how the two "save_samples()" routines both do the same basic setup,
for example.

This is fairly straightforward, with the possible exception of the odd

     sensor = sample->sensor[0];

default in the git pressure loading code.

That line just means that if we do *not* have an explicit cylinder index
for the pressure reading, we will always end up filling in the new
pressure as the first pressure (because the cylinder index will match the
first sensor slot).

So that makes the "add_sample_pressure()" case always do the same thing it
used to do for the legacy case: fill in the first slot. The actual sensor
index may later change, since the legacy format has a "sensor=X" key value
pair that sets the sensor, but it will also use the first sensor slot,
making it all do exactly what it used to do.

And on the other hand, if we're loading new-style data with cylinder
pressure and sensor index together, we just end up using the new semantics
for add_sample_pressure(), which tries to keep the same slot for the same
sensor, but does the right thing if we already have other pressure values.

The XML code has no such issues at all, since it can't share the cases
anyway, and we need to have different node names for the different sensor
values and cannot just have multiple "pressure" entries. Have I mentioned
how much I despise XML lately?

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-25 22:05:32 -07:00
Miika Turkia
1fe22a28ed CCR is now detected from the log data
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-07-24 13:08:04 +09:00
Miika Turkia
685c59214d Map Divinglog's visibility to our stars
good (1) = 5
medium (2) = 3
bad (3) = 1

There seems also to be 0 used in the log, even though it is not
mentioned in the valid selections. This is not giving any stars for this
option...

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-07-24 13:08:04 +09:00
Miika Turkia
a7231be9a0 Detect CCR/PSCR from Divinglog import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-07-24 13:08:04 +09:00
Miika Turkia
0e9e1b6043 Fix CCR detection on Divinglog import
Note that I have not been able to do a positive test for this due to
lack of CCR sample data. But at least OC dives are now categorized
correctly.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-07-24 10:03:07 +09:00
Miika Turkia
27bb76e834 Add visibility support to Divinglog import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-07-24 10:03:07 +09:00
Linus Torvalds
92ecbc8c83 parse-xml: use the right dc for filling in extra data
"cur_dc" may be NULL when the XML source isn't a subsurface XML file,
and xml parsing is supposed to use "get_dc()" to pick a dive computer
when the nesting of the XML may not be proper.

Now, XML sources that don't have the proper dive computer nesting
markers generally also do not end up having the extra-data string
information, but one example of this is the simple XML that the
libdivecomputer 'dctool' program generates.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-22 10:38:11 -07:00
Linus Torvalds
f2a6a76b3e Fix up o2 pressure sensor handling at load time
Because of how we traditionally did things, the "o2pressure" parsing
depends on implicitly setting the sensor index to the last cylinder that
was marked as being used for oxygen.

We also always defaulted the primary sensor (which is used for the
diluent tank for CCR) to cylinder 0, but that doesn't work when the
oxygen tank is cylinder 0.

This gets that right at file loading time, and unifies the xml and git
sample parsing to make them match. The new defaults are:

 - unless anything else is explicitly specified, the primary sensor is
   associated with the first tank, and the secondary sensor is
   associated with the second tank

 - if we're a CCR dive, and have an explicit oxygen tank, we associate
   the secondary sensor with that oxygen cylinder.  The primary sensor
   will be switched over to the second cylinder if the oxygen cylinder
   is the first one.

   This may sound backwards, but matches our traditional behavior where
   the O2 pressure was the secondary pressure.

This is definitely not pretty, but it gets our historical files working
right, and is at least reasonably sensible.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 16:34:33 -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
Miika Turkia
ec40a25007 Parse He when importing from DM5
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-06-13 18:11:22 +09:00
Dirk Hohndel
6399eaf271 Add SPDX header to core C files
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29 13:32:55 -07:00
Miika Turkia
0bce84b09d Support for new DM5 blob format
Currently we do not know what the extra data in the sampleBlob is, but
the block size must be adjusted nevertheless.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-04-20 10:55:19 -07:00
Miika Turkia
58a25d33ce Attempt latin1 parsing on import
We parse input XML using UTF-8 encoding by default. If this fails, try
latin1 instead.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-04-18 18:13:05 -07:00
Miika Turkia
e355037e20 Ignore empty cylinders on Cobalt import
It appears that Cobalt might include additional gas mixes, and only way
to determine what is used appears to be to ensure that start and end
pressures are greater than 0. One would assume there to be something
else available in the database, but I was not able to spot it.

Fixes #297

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-04-11 17:26:31 -07:00
Lubomir I. Ivanov
bcad5ddd38 Only enable -Wmissing-field-initializers for Clang
The following pragma is Clang specific:

It produces a warning:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]

Only enable it for Clang by checking the __clang__ macro.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-12 09:18:59 -07:00
Dirk Hohndel
11a8ab6b1b Undo one lrint change
As here we actually do want the rounded floatingpoint value.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-11 08:52:38 -08:00
Jeremie Guichard
2b06a0b223 Fix potential double/float to int rounding errors
Not using lrint(f) when converting double/float to int
creates rounding errors.
This error was detected by TestParse::testParseDM4 failure
on Windows. It was creating rounding inconsistencies
on Linux too, see change in TestDiveDM4.xml.

Enable -Wfloat-conversion for gcc version greater than 4.9.0

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2017-03-09 23:07:30 +07: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
Linus Torvalds
4a550e4d7d Properly handle dive sites loaded from XML
We used to always create a new dive site structure when loading dive
site data from XML.

That is completely bogus, because it can (and does) create duplicate
dive sites with the same UUID.  Which makes the whole UUID pointless.

So instead, look up the existing dive site associated with the UUID
loaded from the XML, and try to merge the data properly if we already
had dive site information for that UUID.

Reported-by: Alessandro Volpi <volpial@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-02-19 15:23:46 -08:00
Miika Turkia
8766054581 Hooking up av1.xslt for log import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2016-12-31 09:56:08 +02:00
Tomaz Canabrava
81d5d82b7b Settings update: Clean up save user id local
So, prefs.save_userid_local is being set outside of
a preferences set (it's set to true and false while
loading the files via xml or git) and because of that
I had to bypass a few method calls.

When something triggers a preferences change, the
application will be notified that the preferences
changed, thing that I couldn't do while reading the
xml or git because that should be local-only.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-08-27 10:55:40 -07:00
Linus Torvalds
c840ab4332 Fill in divecomputer serial number and firmware version on loading
We have the serial number and firmware version fields in "struct
divecomputer", but we don't actually fill them in when loading the data
from git or xml, because we save all that information in the separate
device table instead.

But in order to always have the serial number associated with a device,
let's make sure to fill those fields in.  It won't hurt, and this way we
have the information available whether we just loaded the dive from a
file, or imported it from the dive computer.  One less semantic
difference to worry about.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-08-14 10:22:41 -07:00
Robert C. Helling
fc213066f8 Only setpoint changes with non-zero SP indicate a CCR dive
There might be some spurious setpoint changes at t=0 without
an actual value (I have no idea where those come from). In
any case, those do not indicate that the dive is a CCR dive.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-06-14 12:04:36 -07:00
Linus Torvalds
5ea16c0bab Don't ignore surface events in xml parsing
I missed the fact that not only did we skip importing surface events
from the dive computer, we had also made our xml parser ignore them when
loading an xml file.  All part of our historical "let's ignore surface
events because dive computers are being very annoying about it".

Signed-off-by: Linus Torvalds <torvalds@linux-foundtion.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-06-01 13:08:22 -07:00
Miika Turkia
47a2e8b1d9 Shearwater import model name for Petrel and Predator
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-05-28 14:23:10 -07:00
Miika Turkia
1aa6bd9904 Set model on Shearwater import
For starters, let's just state that this dive was downloaded from
Shearwater. However, once we have information how model numbers map to
names, we can use that info for the models we know about.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-05-28 14:22:58 -07:00
Miika Turkia
1e5fe4f3fe Use serial as device ID on Shearwater import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-05-28 14:22:51 -07:00
Miika Turkia
61c9b2891c Fix time parsing for Divesoft Freedom
Divesoft uses 17 bits for time so parse accordingly.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-25 11:25:34 -07:00
Dirk Hohndel
7be962bfc2 Move subsurface-core to core and qt-mobile to mobile-widgets
Having subsurface-core as a directory name really messes with
autocomplete and is obviously redundant. Simmilarly, qt-mobile caused an
autocomplete conflict and also was inconsistent with the desktop-widget
name for the directory containing the "other" UI.

And while cleaning up the resulting change in the path name for include
files, I decided to clean up those even more to make them consistent
overall.

This could have been handled in more commits, but since this requires a
make clean before the build, it seemed more sensible to do it all in one.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04 22:33:58 -07:00
Renamed from subsurface-core/parse-xml.c (Browse further)