Commit graph

248 commits

Author SHA1 Message Date
Miika Turkia
7bbe71ff33 Detect proper event type based on helium content
Select proper SAMPLE_EVENT_GASCHANGE "version" based on helium content
on the mix.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-12 08:05:09 -07:00
Miika Turkia
97597dfd97 Add type for gaschange events, if missing
Subsurface has saved gas change events without type attribute at some
point. Thus we need to add the type when reading in log files, if it is
missing. (Gas change logic relies on the type field nowadays.)

Fixes #617
Fixes #600

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-12 08:04:55 -07:00
Anton Lundin
848a5352c7 Add support divecomputer based TTS
Since earlier have we had support for our own calculated TTS. This adds
support for holding TTS values reported by a dive computer.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-09 13:22:00 -07:00
Dirk Hohndel
f297d9f91e Fix picture loading
Signed vs unsigned comparisons are such a pain. Since we want offsets to
be +/- 30 minutes around the dive we need to allow negative offsets - but
duration_t was defined as uint32_t.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-08 12:29:06 -07:00
Henrik Brautaset Aronsen
630ec88dd4 Be more consistent in partial pressure naming
Lets just use pO₂ instead of PO2, ppO2, ppO₂, PO₂.
They all mean the same, but it's better to be
consistent

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-23 06:48:54 +08:00
Dirk Hohndel
0c8dbc2061 Simplify code
Since trimspace() null terminates the string, we can simply use strdup()
here.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-11 19:02:49 -07:00
Willem Ferguson
a0f5a74847 Provide for a dive_computer_type variable within dc structure
This patch lays the foundation for differentiating
 between open-circuit(OC)dives and rebreather dives
 (CCR). The following were done:
 1) In dive.h add an enum type dive_computer_type
 2) In dive.h add two more fields to the dc structure:
    a) dctype  (an enum field indicating dc type)
    b) no_o2sensor (indicating number of o2 sensors for this dc)
 3) In parse-xml.c add a function trimspace that strips any
    whitespace from a string. This is used by two functions:
    utf8_string as well as by get_dc_type, described below.
    The pointer to buffer is not changed in order to ensure
    consistency when the buffer is freed.
 4) In parse-xml.c add a function get_dc_type. This parses the
    dc_type string from xml and assigns an enum value which will
    later be returned to the function that parses
    the dc variables.

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-11 18:49:28 -07:00
Dirk Hohndel
a26719c541 Picture handling: switch to stronger typed offset
Also change the on file XML to be even easier to read by making it a
duration as well (which gets us '32:34 min' instead of un-typed seconds).
This is backwards compatible, it will happily read what was written with
the previous commit).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-09 09:38:50 -07:00
Dirk Hohndel
b0983d9d13 Picture handling: parse and convert old style picture events
Speacial case handling for event type '123' to instead add a picture to
the picture_list of the dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-09 09:21:26 -07:00
Dirk Hohndel
98e1b36a98 Picture handling: parse XML data
Using XML data files we can now save picture data and load it back in
again. The corresponding code for save-git and load-git is still missing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-08 17:44:01 -07:00
Linus Torvalds
f46f9139a8 Make parse-xml callbacks be type-safe
.. and fix the type breakage brought in by commit eaf6d56487 ("CCR code:
Change to sample structure")

The XML parsing callbacks pass a "void *" around, because the helper
function that matches the XML node names ("match()") does so for all the
different dive/sample/dc member nodes that all have different types.

But that also hid the fact that it very much depended on the various types
being regular "int" etc, rather than the denser types that were introduced
so that the CCR data wouldn't expand memory use excessively. As a result,
XML loading would overwrite other members, and possibly even the
allocation, when it wrote an "int" value to something that only was a
8-bit allocation.

I left the "utf8_string()" without type checking - so it still uses
"void *_res" for the result type, with the cast happening inside the
function.

That's because the result destination ends up being a bit mixed-up wrt
"const char **" and just plain "char **". Note that the thing we modify
itself isn't const (it's not "char *const *"), but the pointer, but we
basically sometimes assign a "const char *", and sometimes a "char *".

I considered making two different versions of the callback, but it just
wasn't worth it. So "utf8_string()" users still aren't type-checked, and
you'd better give it a pointer to something that is some kind of "char *"

This patch doesn't really change the calling convention of the matching
function itself, but it makes the wrapper macro ("MATCH()") take a
properly type-checked function pointer instead (with a dummy call to do
type checking), and then casts the pointer to the "void *" type for the
actual real call.

The function pointer call is not really portable (although it works on
all sane architectures, particularly since the cast only changes one
argument from one type of pointer to another), and to make matters worse
uses the gcc statement-expression extension. But all the compilers we use
seem to support that gcc'ism, so in practice this gives us type-safety
with no downsides.

(If we ever want to use MSVC to compile subsurface, I suspect we'll have
to ifdef out the statement expression use and not type-check things. Or
perhaps re-write the thing as a ternary expression instead, or something).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-07 19:40: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
Linus Torvalds
33223fb2cc Fix dive water temperature XML parsing
We parsed it rigth for dive computers, but not for the manually filled
per-dive case. The git save seems to have gotten it right.

I think this has been broken since the whole "move as much as possible to
the dive computer sections", but I didn't actually check.

Reported-by: roberto forini <forini.r@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03 16:36:14 -07:00
Tomaz Canabrava
9598462830 Removed the globals 'userid' and 'save_userid_local' variables
This is a preferences setting, it should belong to the preferences
structure.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:37:31 -07:00
Venkatesh Shukla
3abcde9a2a Add option to save userid in data files
The userid of Subsurface Webservice can be included in locally saved xml
files and git repository.
For xml files, it is stored in userid tag. For git repo, it is stored
in 00-Subsurface file present in the repo.
Preference dialog and webservice dialog modified to include option
for saving userid locally.

In case of difference in default userid and userid in local file,
some semantics are followed. These can be referred to here:
http://lists.hohndel.org/pipermail/subsurface/2014-April/011422.html

Fixes #473

Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-14 09:40:30 -07:00
Linus Torvalds
609715ab69 Convert other users of showError() to the new world order
The "report_error()" interface is a lot simpler, although some of the
C++ code uses QStrings which make them a bit annoying, especially for
the varargs model.  Still, even with the explicit conversion to UTF8 and
"char *", the report_error() model is much nicer.

This also just makes refreshDisplay() do the error reporting in the UI
automatically, so a number of error paths don't even have to worry.  And
the multi-line model of error reporting means that it all automatically
does the right thing, and reports errors for each file rather than just
for the last file that failed to open.

So this removes closer to a hundred lines of cruft, while being a
simpler interface and doing better error reporting.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-14 12:36:06 -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
Linus Torvalds
5fcb36f5a8 Parse basic trip and dive data from the git blobs
Some things are still missing: samples and events, and cylinder and
weightsystem information.  But most of the basics are there (although
the lack of sample data makes a big visual impact)

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-09 19:36:35 -07:00
Dirk Hohndel
1b103c5c69 Another small tweak to whitespace tool
clang-format doesn't appear to reindent multi line #define statements
correctly - so this hopefully will clean those up.

The included whitespace corrections to the code should stay in place when
using the updated tool.

This includes cleaning up some multi-line comments that were messed up the
last time around as well as a few other minor changes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-05 13:02:23 -08:00
Dirk Hohndel
e80a6822d5 Whitespace cleanup for parse-xml.c and save-xml.c
This is looking really good. Done using our whitespace tool.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-16 15:58:13 -08:00
Dirk Hohndel
cdb69aea09 Remove some unused variables
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-15 17:45:22 -08:00
Miika Turkia
bbda9dd108 Import gas info for Shearwater Desktop
Used gas mixes and gas changes are imported. Also po2, ndl, cns and
ceiling are added to profile samples. As far as I can tell, the Searwater
Desktop shows ceiling in 3 meter (or feet equivalent) steps, but stores in feet
(or probably meters). I just use the value reported, no conversion to 3 meter
steps.

Fixes #432

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-14 22:47:10 -08:00
Miika Turkia
62e313df35 Import Shearwater Desktop divelog database
Sqlite database from Shearwater Desktop log software is imported. Just
the basic information like location, buddy, notes and dive profile
(depth and temperature).

This is tested with a DB in Imperial units, thus metric input might
contain errors.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-14 22:46:35 -08:00
Miika Turkia
4b949936c2 Refactoring sqlite import support
Move the opening of DB connection to occur before DC dependent code.
This way we can try to detect log software before calling the DC
dependent import function. This prepares for adding support for
Shearwater sqlite database.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-14 22:45:07 -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
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
Linus Torvalds
22f66501ac Add support for heartrate and bearing information in samples
libdivecomputer already supports this, but we didn't save it.

Tested-by: Oscar Isoz <jan.oscar.isoz@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-10 07:03:24 -08:00
Lubomir I. Ivanov
a8823c1793 parse-xml.c: Fix a warning about missing braces
warning: suggest explicit braces to avoid ambiguous 'else'

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-09 14:03:57 -08:00
Miika Turkia
361f8ede76 Check XML attribute to detect correct XSLT
Very few dive log files can be identified by the name of the root
element in the XML log. As same element names are used between different
software, we need to use attributes as well to identify correct XSLT to
convert the log to Subsurface format. I would not be surprised if at
some point we'll just have to present a dialog to the user and ask which
software is in use...but this is enough for now.

This also adds the shearwater.xslt to the list.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-08 07:12:35 -08:00
Miika Turkia
b6ef5198f2 Hook up XSLT and include it in resources
XSLT to import manually kept CSV logs is hooked up and included in
resources.

Fixes #427

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-25 06:52:50 -08:00
Robert C. Helling
162d674c5b Don't compare floats for equality
Now that we have a macro to replace float equality testing, we should use
it in places where floating point jitter might bite use otherwise.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-21 14:11:52 -08:00
Miika Turkia
2167088f1c Add Sensus XSLT as a resource and enable it
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-17 05:57:42 +07:00
Dirk Hohndel
a27f67c026 Whitespace and coding style updates
Another futile attempt to cleanup the code and make coding style and
whitespace consistent. I tried to add a file that describes the key points
of our coding style. I have no illusions that this will help the least
bit...

This commit should ONLY change whitespace

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16 11:50:56 +07: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
Miika Turkia
6037be946f Add a few more Suunto events
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-10 16:13:32 +07:00
Miika Turkia
18e625129e Import tags from Suunto database file
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-10 16:13:29 +07:00
Miika Turkia
b79ef63388 Do not plot temperatures on DM4 import if no info
If we do not have temperature readings, we do not want to plot the
temperature samples either.

See #415

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-10 16:13:22 +07:00
Linus Torvalds
2d1d78ebfe const'ify our strtod() helper functions
The C library doesn't use const char pointers for legacy reasons (and
because you *can* modify the string the end pointer points to), but
let's do it in our internal implementation just because it's a nice
guarantee to have.

We actually used to have a non-const end pointer and replace a decimal
comma with a decimal dot, but that was because we didn't have the fancy
"allow commas" flags.  So by using our own strtod_flags() function, we
can now keep all the strings we parse read-only rather than modify them
as we parse them.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-08 16:38:47 +08:00
Linus Torvalds
cb53a78674 Make our 'ascii_strtod()' helper more generic
We'll want to do sane parsing of strings, but the C library makes it
hard to handle user input sanely and the Qt toDouble() function
interface was designed by a retarded chipmunk.

So just extend our existing hacky "ascii_strtod()" to allow a more
generic interface.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-02 21:17:41 -08:00
Dirk Hohndel
0421a161b4 Silence a few warnings
None of these are actual bugs. But none of the fixes are harmful, either.
And much as I hate adding the 'default' clauses, I'd rather not have the
build output cluttered by invalid warnings.

The exception is the fix in divelistview.cpp - while I don't think it is
possible for this function to be called with no dive selected,
initializing pd to NULL is cheap insurance in case that does happen for
some weird reason.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-20 09:53:06 -08:00
Lubomir I. Ivanov
22b8d95d58 Fix a small coding style issue
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-19 07:28:23 -08:00
Thiago Macieira
397898434e Remove the xslt_path now that all XSLT files are kept in a resource
Signed-off-by: Thiago Macieira <thiago@macieira.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-16 16:20:54 -08:00
Thiago Macieira
ca8aee4701 Move the XSLT files into a Qt resource
This means we no longer need to keep them on disk and worry about
installing / uninstalling them. They will always be kept in-memory
(compressed).

Signed-off-by: Thiago Macieira <thiago@macieira.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-16 16:20:52 -08:00
Dirk Hohndel
89a58e23e0 Correctly parse multiple tags in the divelog
The old parsing code overwrote the first comma with a '\0' and then
checked the index against the length of the buffer - which was changed by
replacing the ',' with the '\0'.

This means that since commit 78acf20848 ("Don't crash on loading tags
longer than 127 chars") Subsurface has potentially damaged / lost data in
dive files!

Added a test dive that shows the issue if opened by a Subsurface version
after the commit mentioned above but before this commit.

Reported-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-12 16:29:06 -08:00
Anton Lundin
2419e074f4 Fix some whitespace damage
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-11 22:19:37 +01:00
Anton Lundin
78acf20848 Don't crash on loading tags longer than 127 chars
We didn't enforce a limit on tag length, but we would crash on a tag
longer than 127 chars.
This uses the xml buffer as scratch space. Don't really know if this is
fair, but it looks like it works.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-11 22:19:15 +01:00
Anton Lundin
d0c7b3bf7d Plug memory leak in duration()
Strdup should be followed by a free()...

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
Linus Torvalds
4d0d5f8c07 Quiet down valgrind warnings
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-28 12:15:24 -08:00
Anton Lundin
3fd39a7a87 Remove some constants and use helpers instead
We have allot of helpers, use them instead of local variants.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-27 08:30:12 -08:00
Dirk Hohndel
a6b35141e4 Don't parse 32bit hex values with strtol
On a 32bit machine this will truncate values with MSB set to 0x7fffffff

Fixes #164

(thanks to Linus for pointing me in the right direction)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-22 13:31:52 -08:00