Commit graph

70 commits

Author SHA1 Message Date
Berthold Stoeger
0fa6422a04 Warning Fix: add missing include to core/parse-xml.c
Fallout from commit #cd5e17cf79c2f1eb896efd0436c103221de446ae

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-02 02:46:31 +02: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
Willem Ferguson
9a8bab21c9 Improve profile display in planner
This patch allows the planner to save the last manually-entered
dive planner point of a dive plan. When the plan has been saved
and re-opened for edit, the time of the last-entered dive planner
point is used to ensure that dive planning continues from the same
point in the profile as was when the original dive plan was saved.
Mechanism:

1) In dive.h, create a new dc attribute dc->last_manual_time
   with data type of duration_t.
2) In diveplanner.c, ensure that the last manually-entered
   dive planner point is saved in dc->last_manual_time.
3) In save-xml.c, create a new XML attribute for the <divecomputer>
   element, named last-manual-time. For dive plans, the element would
   now look like:
   <divecomputer model='planned dive' last-manual-time='31:17 min'>
4) In parse-xml.c, insert code that recognises the last-manual-time
   XML attribute, reads the time value and assigns this time to
   dc->last_manual_time.
5) In diveplannermodel.cpp, method DiveplannerPointModel::loadfromdive,
   insert code that sets the appropriate boolean value to dp->entered
   by comparing newtime (i.e. time of dp) with dc->last_manual_time.
6) Diveplannermodel.cpp also accepts profile data from normal dives in
   the dive log, whether hand-entered or loaded from dive computer. It
   looks like the reduction of dive points for dives with >100 points
   continues to work ok.
The result is that when a dive plan is saved with manually entered
points up to e.g. 10 minutes into the dive, it can be re-opened for edit
in the dive planner and the planner re-creates the plan with manually
entered points up to 10 minutes. The rest of the points are "soft"
points, shaped by the deco calculations of the planner.

Improvements: Improve code for profile display in dive planner

This responds to #1052.
Change load-git.c and save-git.c so that the last-manual-time is
also saved in the git-format dive log.

Several stylistic changes in text for consistent C source code.

Improvement of dive planner profile display:

Do some simplification of my alterations to diveplannermodel.cpp

Two small style changes in planner.c and diveplannermodel.cpp
as requested ny @neolit123

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-19 12:38:11 +02:00
Berthold Stoeger
afeb2e3652 Make a few functions of static linkage
Make functions in core/file.c, core/parse.c and core/import-csv.c
that were not used outside their translation unit of static linkage.

parse_date is moved from core/file.c to core/import-csv.c, since it
is used only there.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-08 09:52:55 +02:00
Berthold Stoeger
fa5865a566 Remove unused function parse_mkvi_buffer()
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-08 09:52:55 +02:00
Berthold Stoeger
5960718075 parse-xml.c: add get_bool() function
The boolean "autogroup" was parsed as an integer. In principle OK, but
let's make the type more explicit by introducing a get_bool() function.

Suggested-by: "Lubomir I. Ivanov" <neolit123@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-04 08:21:43 -08:00
Dirk Hohndel
169a55d6e8 Cleanup: avoid memory leak
Coverity CID 208314

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 15:57:44 -08:00
Miika Turkia
b1b2638720 Move Cobalt and Divinglog DB parsing to parse-db.c
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-11-27 13:42:10 -08:00
Miika Turkia
8be626d2c1 Move atoi_n to parse.c
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-11-27 13:42:10 -08:00
Miika Turkia
b3605de93e Move Shearwater DB parsing into parse-db.c
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-11-27 13:42:10 -08:00
Miika Turkia
568db03228 Move metric variable to parse.c
This is required when moving Shearwater DB parsing into parse-db.c

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-11-27 13:42:10 -08:00
Miika Turkia
ddb9dba66c Move add_dive_site to parse.c
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-11-27 13:42:10 -08:00
Miika Turkia
1c6e189c2b Move Suunto DB imports into parse-db.c
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-11-27 13:42:10 -08:00
Miika Turkia
02c80a60b0 Refactore parse-xml.c into parse.c and parse-xml.c
This should help us to move parsing that is not XML related to other
files, hopefully making the code cleaner.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-11-27 13:42:10 -08:00
Stefan Fuchs
46004c39e2 Store and load the planner related depth info of a cylinder in logfile
Store cylinder.depth in XML files and in git storage.
This info is in fact the gas switch depth of a specific gas/cylinder
in the planner.
This change avoids the need of typing in a user specific depth value
again when replanning an existing planned dive.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-27 11:49:08 -08:00
Jan Mulder
f1437cfec7 Fix warning
Commit 9771255919 introduces a compiler warning due to mismatched
pointer types. Fixed here.

Reported-by: Stefan Fuchs <sfuchs@gmx.de>
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-11-10 10:31:19 +01:00
Dirk Hohndel
27c49fe3ad Silence random warnings
None of these seem to point to actual issues, so let's quiet them.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-20 17:25:18 -04:00
Miika Turkia
6573132307 Store RBT value on DivingLog import
Fixed-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-10-07 22:38:49 -07:00
Linus Torvalds
d5a0184f71 Fix divinglog import temperature truncation
The code incorrectly divided the temperature by 10 as an integer,
causing unnecessary precision loss due to truncation.

Fix it, and update the test results for the now improved temperature
import.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-07 14:52:57 -07:00
Linus Torvalds
03b10383c9 Fix divinglog import limit checking
The divinglog import did horrible things with the strings returned from
the sqlite queries, and ended up using uninitialized values at the end
of the secondary profile data strings.

This rewrites the import logic to track the length of the strings
properly when importing the divinglog data.

We should run 'valgrind' a whole lot more than we do, I suspect.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-07 14:52:48 -07:00
Dirk Hohndel
21d78121ad Don't add separate country field, use taxonomy
The more I looked at the code that added the country to the dive site,
the more it seemed redundant given what we have with the taxonomy.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-04 08:05:09 -07:00
Tomaz Canabrava
32e6ca4919 [Divesite] Save / Load the country from xml
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-02 09:52:33 -07:00
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