Commit graph

354 commits

Author SHA1 Message Date
Dirk Hohndel
2c0223fbb2 Fix missing curly braces that change control flow
Indentation thankfully is not the same as scope.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-21 22:00:21 -07:00
Dirk Hohndel
66375689b8 Prevent null dereference
In each case there are scenarios where we would have dereferenced NULL.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-21 21:53:53 -07:00
Dirk Hohndel
f5726c3d18 Fix a number of resource leaks
Free memory returned from parse_mkvi_value()
Free memory returned from printGPSCoords()
Free memory allocated in added_list and removed_list
Free memory allocated when adding suffix to dive site name
Free memory allocated in cache_deco_state()
Free memory allocated in build_filename()
Free memory allocated in get_utf8()
Free memory allocated in alloc_dive()
Free memory allocated as cache but never used

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-21 21:13:32 -07:00
Dirk Hohndel
de35c88683 Track minimum datafile version
Add infrastructure and helper functions to track minimum datafile version.
To make this information useful we need to keep the XML and git data
format versions in track moving forward.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-20 06:45:12 -07:00
Dirk Hohndel
c897b857fb We don't really need a long to count the dive sites
At least I hope not.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-17 11:42:15 -07:00
Dirk Hohndel
ccc9d80015 Remove all the no longer necessary code that aborts read of first V2 file
This was a poorly implemented hack when we executed the reverse geo lookup
in the main thread and opening a V2 file could take a very long time. We
need to do the "Welcome" message quite differently.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-16 14:41:56 -07:00
Dirk Hohndel
b0fc00694d Add "additional name" to the correct dive site
Adding the name to its own dive site was kind of silly.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-10 13:03:37 -07:00
Dirk Hohndel
2c22b24ef6 When parsing V2 XML files try to be smarter when creating dive sites
Two "locations" from a V2 file are the same site if they have the same
name AND if their GPS coordinates are within 20 meters of each other.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-10 11:52:18 -07:00
Dirk Hohndel
53806c265c Create unique dive sites when downloading from webservice
The Subsurface Webservice (as backend for the companion app) will usually
send a lot of gps fixes encoded as dives, all with the same dive site
name. When parsing the XML file it sends we need to make the dive site
names unique so that we can then match them to the existing dives.

The fake dives with all the dives sites will all be discarded, but without
creating the unique dive sites we can't successfully add the GPS
coordinates to the existing dives.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-09 12:50:17 -07:00
Miika Turkia
16ac0bc45d Support for changed DM5 sample blob
Block size for sample is now variable, so detect the version and parse
proper blocks.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-02 10:48:46 -07:00
Robert C. Helling
22bfc4936f Add explicit casts to silence compiler warnings
clang complais when converting (char *) to (unsigned char *), so tell
it it's fine.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-05-28 08:16:37 -07:00
Paul-Erik Törrönen
cfa5403192 Fix typo
Loockup -> Lookup

Signed-off-by: Paul-Erik Törrönen <poltsi@777-team.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-05-21 16:05:09 -07:00
Miika Turkia
f7e86b5838 Import surface event from Suunto DB
This is actually relevant information when someone surfaces
accidentally, thus we should not ignore it.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-05-21 08:47:19 -07:00
Miika Turkia
21d1903656 Correct dive time in DLF import
Divesoft Freedom records the dive time in count of seconds since
1.1.2000 00:00:00, not noon.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-05-17 13:39:26 -07:00
Tomaz Canabrava
627de38c01 Get the location information in a separate thread
This makes Subsurface usable faster for those without a good internet
connection when they are opening an older data file.

While parsing, we are only feeding an vector of locations, after the
parsing is done, we traverse the vector searching for the information on
the web.

I need to also add a way to stop if there`s no internet connection - but
this will be another patch.

Also, fixed two small memory leaks from the old imp.

[Dirk Hohndel: cleaned up the whitespace mess]

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-05-10 11:14:20 -07:00
Dirk Hohndel
6f7e3d04cb Handle XSLT based imports correctly
XSLT conversions create V2 XML files, but we shouldn't abort when we parse
those without having the user informed about the potential slowness - all
XSLT based imports are slow, anyway.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-22 13:20:27 -07:00
Dirk Hohndel
216fa8d543 Don't crash if add_gas_switch_event() gets called with invalid index
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-20 23:28:51 -07:00
Claudiu Olteanu
dc32d447c3 Fix a memory leak in parser-xml
Free the temporary memory alocated for a cobalt location.

Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-03-24 09:46:56 -07:00
Robert C. Helling
b02bf002a6 Add hashes to images
Upon successfull reading an image file, this computes a SHA1 hash of the
image and saves it with the picture tag in the log file. When a file is
not successfully loaded (for example because the log was created on a
different computer) we look up the hash in a dictionary that maps hashes
to local file names.

That dictionary (actually two for both directions), is loaded on startup
and saved upon destruction of the main window.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-27 06:29:44 +01:00
Dirk Hohndel
0ed4356fc2 Display slowness warning before opening a V2 file
This is somewhat invasive as aborting the XML file read requires us to
report things up the recursive parsing chain.

What we really need to do here is to ask the user how they want to use the
data from reverse geo lookup. But for now we only warn about the fact that
this can take a while.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-25 10:05:37 +01:00
Miika Turkia
0f6f1c7ccf Include DC information on Cobalt import
Note that I use the serial number as device ID as is done with the
Suunto DM5 import.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-22 10:02:41 -08:00
Miika Turkia
f9cb443c73 Ignore deleted dives on Cobalt import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-22 10:02:31 -08:00
Miika Turkia
44b4ae00ed Discard deleted dives on DM5 import
I had some double profiles with slight differences in them, until I
realized that this was caused by including deleted dives in the import.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-22 07:48:33 -08:00
Miika Turkia
ad5503fec5 Clean DM5 sql query
We don't use the data coming from DiveMixture so removing the join. The
join did also generate extra rows of the same dive (with differing gas
info).

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-22 07:48:22 -08:00
Miika Turkia
27d0cd68fc Import DC info properly from DM5 log
Using serial number as device ID here for simplicity. We also need the
DC info for the divecomputer tag per dive. And it seems that serial
number is in SerialNumber, SourceSerialNumber or both.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-22 07:47:54 -08:00
Miika Turkia
5330a612c5 Support for gas changes in DM5 import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-22 07:46:44 -08:00
Miika Turkia
a76d5fb966 Fix surface pressure on DM5 import
Seems that DM5 uses pascal as pressure unit for surface pressure.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-22 07:46:14 -08:00
Dirk Hohndel
6a2efd9ff6 The callback function has to return 0 or sql processing fails
Which means we report an error even if there wasn't a problem.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-19 19:52:58 -08:00
Dirk Hohndel
4682002474 Braces are better than indentation to scope if / if / else
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-19 19:47:06 -08:00
Miika Turkia
1301cb9664 Use 12 liter default on DM5 import
As the comment says, default to 12 liters if cylinder size is zero.
This is done only when cylinder has start pressure given.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-19 19:45:32 -08:00
Miika Turkia
5d18876e78 Support multiple cylinders on DM5 import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-19 19:45:25 -08:00
Miika Turkia
6c0a6af4aa Adding more Suunto events
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-17 14:07:29 -08:00
Miika Turkia
5632c0b357 Add limits to cylinder maximum pressures on DM5 import
DM5 seems to have occasionally bogus data for cylinder start and end
pressures. Need to validate that.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-17 14:07:11 -08:00
Miika Turkia
56f6df4cd8 Hook up DiveLog import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-17 14:07:01 -08:00
Lubomir I. Ivanov
7d045dd0d9 parse-xml.c: remove unused variables in divinglog_place()
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-15 13:29:44 -08:00
Dirk Hohndel
5bf86f6042 Proof of concept for reverse geo location
When reading a pre-v3 XML file, we now do reverse geo lookups on the GPS
coordinates and add the country to the dive site notes. Eventually this
wants to be a tag (once we implement tags for dive sites).

This is going to add quite a bit of delay when people open a V2 XML file -
depending on how many distinct GPS fixes they have. In my case with 127
GPS fixes it took about 20 seconds to open the file...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-14 20:26:09 -08:00
Dirk Hohndel
57d5a40e95 Keep conflicting information around when converting v2 to v3 on the fly
When reading a v2 XML or git divelog it can happen that we get multiple
names for the same GPS fix or multiple GPS fixes for the same name. We'll
still consolidate them to one entry, but we should not throw away the
conflicting information - instead we should just add this to the notes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-14 18:00:35 -08:00
Miika Turkia
92f514b081 Associate existing dive site to current dive
If the dive site exists, we need to associate the uuid to current dive.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-14 11:37:33 -08:00
Dirk Hohndel
6dd6e90684 Don't force the first divecomputer to CCR just because there's po2 value
The existing code was bogus as it used cur_dive->dc instead of cur_dc
(i.e., it always changed the first dive computer, even if the po2 was
found in a different one).

But fundamentally I consider this bogus. We are not doing the right thing
here - some dive computer send us pO2 values that are just the calculated
pO2 at a depth and NOT a setpoint, yet we pretend those are setpoints and
then turn these dives into CCR dives.

This needs to done differently.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-13 21:07:22 -08:00
Dirk Hohndel
1527cd0d05 More useful debug prints
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-13 14:45:38 -08:00
Dirk Hohndel
8c3efd2a22 Improve parsing of older XML files in order to auto create dive sites
While the existing code worked with a couple of hand crafted examples it
turns out it did a poor job with most of my files. Oops.

Depending on whether we find name or coordinates first, we need to
identify existing sites in either case and do the right thing.

The challeng here are multiple dives at the same site with slightly
different GPS coordinates. If the name is read first, these all get merged
into one (and we warn about the different GPS data). But if GPS gets read
first, we create separate dive sites with the same name.

We need a sane UI to consolidate these - but we can't completely automate
this... it's possible that these ARE the same site and the GPS data is
just imprecise (for example, multiple dives at the same time with GPS
locations from the Subsurface companion app). The user should be able to
either pick one of the GPS locations, or keep multiple (for example,
different buoyes for the same site and you want to keep the different
markers).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-13 12:42:44 -08:00
Dirk Hohndel
d4f2b72148 Make special backup when switching XML versions
Since the last few dozen commits change the format in irreversible ways
and could therefore be destructive and lose data for testers of the
development version, let's try to be extra careful and create "special"
backup files that aren't overwritten by subsequent backups. At least this
way people can go back to the previous state.

Of course people using the git backend don't have to worry about this as
they always can go back to any earlier save.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-12 23:35:52 -08:00
Dirk Hohndel
9ca600e114 Fix remaining gps references when parsing XML files
Clearly I didn't run into these before in my testing.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-12 21:30:57 -08:00
Dirk Hohndel
cd28e88bee Improve helper functions
Sometimes we want to create a dive site just based on a name, sometimes we
have both a name and GPS coordinates. Let's make a helper for either case.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-12 11:19:27 -08:00
Dirk Hohndel
4b15b9dfe9 Save and parse dive site structures to XML
Read and write divesite sections in the XML file.

Read divelogs of version 2 and create dive site structures on the fly.
Read version 3 files that have divesiteid instead of location / gps.

Saves version 3 files where dives no longer have location and gps but
instead refer to a divesiteid

The commit contains quite a few fprintf(stderr,...) in order to allow
better monitoring of the parsing / transforming of locations and gps to
dive sites. This will need to be removed later.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-12 11:19:27 -08:00
Anton Lundin
4a8e1485e1 DLF import: Correct format for NDL/TTS/Temp
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-24 12:33:49 +12:00
Anton Lundin
a4e06bb68e DLF import: Parse CNS value from event to.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-24 12:33:42 +12:00
Anton Lundin
87153cefaa DLF import: Add bailout flag to GF-changed event
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-24 12:33:38 +12:00
Anton Lundin
f0e68137d7 DLF import: parse and import surfacepressure
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-24 12:33:32 +12:00
Anton Lundin
bc3b56a969 DLF import: cleanup start mode decoding
As i thought, only 3 bits there where dive mode. Only look at those.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-24 12:33:23 +12:00