Commit graph

108 commits

Author SHA1 Message Date
Linus Torvalds
020154215d Don't match existing dives by date if the dive computers are known to be different
When downloading from a dive computer, we fall back on matching the
exact date of the dive if we can't tell whether we already have that
exact dive computer data some other way.

However, if you have multiple dive computers and they are sufficiently
well synchronized, they might actually have the exact same date,
despite the fact that we do want to download both dive computers. We
do check the dive start to the exact second, so this sounds unlikely,
but with dive computers rounding time to the next minute etc, it's not
as unlikely as you'd think. Dirk hit it.

So when we match against date, do check that the dive computer might
actually be one we've already downloaded from. If we have full model
information, we can dismiss the "match date" logic.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28 14:16:29 -08:00
Dirk Hohndel
df613bf107 Support tank size information download from Atomic Aquatics Cobalt
This should really be done in libdivecomputer, but that can't happen until
the API there gets extended to support tank sizes. So for now with this
code we manually parse the raw dive data (if downloaded via
libdivecomputer from a Cobalt) and setup the tank size ourselves.

This had relatively limited testing so far.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28 08:53:16 -08:00
Linus Torvalds
459696c90c Use dive ID for matching dives during downloads
If we have a dive computer model and dive ID, use that to match newly
downloaded dives against the existing dives.

Otherwise fall back to "exact date match" again, like we've always done.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-16 15:48:09 -10:00
Dirk Hohndel
563af1daa7 Update to the new deco / ndl code in libdivecomputer
Early in the libdivecomputer 0.3 development cycle Jef and I implemented
deco and ndl as events. That wasn't a wise design choice and we agreed to
switch this to be instead new sample types which makes much more sense
(and is much more aligned with the way we are handling them inside
Subsurface). So this commit tracks the change in libdivecomputer. Since
this happened during the development cycle there isn't a way to detect
this at compile time - so you need to make sure you have a matching
version of libdivecomputer when compiling Subsurface.

To make this easier: this commit of Subsurface requires a libdivecomputer
version that includes the libdivecomputer commit d5d44c1e0ffd "Convert
decostop / ndl to samples".

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-11 13:05:08 -08:00
Dirk Hohndel
ef3735eafb Make sure pO2 and cns are filled in all samples
This allows things to work for dive computers like the OSTC that give us
setpoint information in the sample, but not constant pO2 readings.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-08 14:02:31 -08:00
Dirk Hohndel
9d80e7bfe4 Add CNS and pO2 tracking in the samples
This adds the new members to the sample structure and fills them from
supported dive computers (Uemis SDA and OSTC / Shearwater Predator,
assuming you have libdivecomputer 0.3).

Save relvant values of this to the XML file and load it back. Handle the
new fields when merging dives.

At this stage we don't DO anything with this, all we do is extract them
from the dive computer, save them to the XML file and load them back.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07 21:03:39 -08:00
Dirk Hohndel
c1aacc05d1 Fix deco/ndl support for libdivecomputer
Several blatant mistakes prevented this from ever working.
Now we correctly record ndl / stoptime / stopdepth in every sample and no
longer issue bogus events.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-05 14:39:13 -08:00
Dirk Hohndel
dcb6574dc4 Improve deco handling and add NDL support
This commit changes the code that was recently introduced to deal with
deco ceilings. Instead of handling these through events we now store the
ceiling (which in reality is the deepest deco stop with all known dive
computers) and the stop time at that ceiling in the samples.

This also adds support for NDL (non stop dive limit) which both dive
computers that appear to give us ceiling / deco information appear to
give us as well (when the diver isn't in deco).

If the mouse hovers over the profile we now add support for displaying the
NDL, the current deco obligation and (if we are able to tell from the
data) whether we are at a safety stop.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-04 21:05:26 -08:00
Dirk Hohndel
10fac7a6af Updating events for libdivecomputer 0.3 (and tracking uemis support)
I was a little too eager to add the deco feature to Subsurface. Jef and I
went back and forth a few more times and the definition of those events
changed. I guess I shouldn't have commited that code until the
corresponding libdivecomputer code had been pushed.

This commit now brings us in sync with the current master of
libdivecomputer (but should compile with 0.2 as well - only deco events
won't work then).

One issue that I see is that deco / ndl aren't really a good fit for the
event model. I actually disabled the drawing of the little yellow
triangles for ndl events as for example on the Uemis those events are
created whenever the remaining non stop time changes - and that can be
every few seconds.

The correct solution may be to treat this as a function of the samples,
but for now this works and is tested with both OSTC and Uemis SDA.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-28 21:13:21 -07:00
Linus Torvalds
7bfc8de55e Do not set the water salinity of a dive unless libdivecomputer supports it
It's annoying to see water salinity data in the XML that isn't relevant,
and adding the default value just because the dive got downloaded from
libdivecomputer is definitely wrong.

We should set the water salinity explicitly only if we have it
explicitly set on the dive computer.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-25 13:05:14 -08:00
Linus Torvalds
1ca1fe7994 Improve on divecomputer data handling
This simplifies the vendor/product fields into just a single "model"
string for the dive computer, since we can't really validly ever use it
any other way anyway.

Also, add 'deviceid' and 'diveid' fields: they are just 32-bit hex
values that are unique for that particular dive computer model.  For
libdivecomputer, they are basically the first word of the SHA1 of the
data that libdivecomputer gives us.

(Trying to expose it in some other way is insane - different dive
computers use different models for the ID, so don't try to do some kind
of serial number or something like that)

For the Uemis Zurich, which doesn't use the libdivecomputer import, we
currently only set the model name.  The computer does have some kind of
device ID string, and we could/should just do the same "SHA1 over the
ID" to give it a unique ID, but the pseudo-xml parsing confuses me, so
I'll let Dirk fix that up.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-25 13:05:11 -08:00
Linus Torvalds
5a4640cf44 Match newly downloaded dives against dive computer information
Now that we have more complete dive computer information, we can use
that to match the dives we download, and stop with the hacky "Would we
merge this" check.

For XML files without the explicit dive computer information, go back to
checking the exact dive time.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-25 13:05:04 -08:00
Linus Torvalds
c019da8fd5 Add basic divecomputer info setup with xml parsing and saving
This also knows how to save and restore multiple dive computers in the
XML data, but there's no way to actually *create* that kind of
information yet (nor do we display it).  Tested by creating fake XML
files with multiple dive computers by hand so far.

The dive computer information right now contains (apart from the sample
and event data that we've always had):

 - the vendor and product name of the dive computer
 - the date of the dive according to the dive computer (so if you change
   the dive date manually, the dive computer date stays around)

Note that if the dive computer date matches the dive date, we won't
bother saving the redundant information in the XML file.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-25 13:04:59 -08:00
Linus Torvalds
25b4fee655 Move events and samples into a 'struct divecomputer'
For now we only have one fixed divecomputer associated with each dive,
so this doesn't really change any current semantics.  But it will make
it easier for us to associate a dive with multiple dive computers.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-23 19:36:27 -08:00
Linus Torvalds
a9786564c2 Allocate dive samples separately from 'struct dive'
We used to avoid some extra allocations by just allocating the dive
samples as part of the 'struct dive' allocation itself, but that ends up
complicating things, and will make it impossible to have multiple
different sets of samples (for multiple dive computers).

So stop doing it. Just allocate the dive samples array separately.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-23 19:33:39 -08:00
Dirk Hohndel
a8d413551e Allow the user to cancel a dive computer download
The code pretended to support this for libdivecomputer based downloads,
but it had never been hooked up when the native Uemis downloader was
implemented. When I finally decided to close that feature gap I realized
that the original code was, shall we say, "aspirational" or "completely
bogus" and therefore never worked.

So instead of just hooking up the code for the Uemis downloader I instead
implemented this correctly for the first time for both libdivecomputer and
the native Uemis downloader.

In order not to have to mess with multithreaded Gtk development I simply
opted for a helper function that fires on a 100ms timeout and have it end
the dialog without a response. This way we can run the dialog while
waiting for the download to finish, still update the progress bar and
respond in a useful manner to the user clicking cancel.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-20 11:42:01 -08:00
Linus Torvalds
2c3850110b When downloading from a dive computer, stop at mergeable dives
The divecomputer download code will stop at a matching dive (unless
you check the "Download all dives" option when downloading).

However, the matching dive is an *exact* match, which works well when
you have a single dive computer, but is a big pain when you have
multiple. What happens is that the date of the dive will be determined
by whatever dive computer you used first, and then downloading from
other dive computers will not match exactly, but will merge (if the
computers are within a minute of each other).

And that will continue to happen every time you try to download from
that other dive computer.

So use the same logic as for the automatic dive merging: consider
"within one minute" to be a matching dive. So don't download dives
that will be merged - unless the user asks for it.

We do want to have some way of saying "force download of all dives
from today" or something like that, I suspect. Because while I don't
want to re-download *every* dive, I might want to force-merge the last
<N> dives.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-19 20:56:16 -08:00
Linus Torvalds
804b22dcd9 Mark divelist changed as we download dives from a dive computer
"record_dive()" won't do that, since otherwise we'd mark the dive list
changed when we load it from an XML file.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-19 12:01:54 -08:00
Dirk Hohndel
fe4f13f184 Add special download modes to force updates from the divecomputer
This will hopefully not be something we need often, but if we improve
support for a divecomputer (either in libdivecomputer or in our native
Uemis code or even in the way we handle (and potentially discard) events),
then it is extremely useful to be able to say "re-download things
from the divecomputer and for things that were not edited in Subsurface,
don't try to merge the data (which gives BAD results if for example you
fixed a bug in the depth calculation in libdivecomputer) but instead
simply take the samples, the events and some of the other unedited data
straight from the download".

This commit implements just that - a "force download" checkbox in the
download dialog that makes us reimport all dives from the dive computer,
even the ones we already have, and an "always prefer downloaded dive"
checkbox that then tells Subsurface not to merge but simply to take the
data from the downloaded dive - without overwriting the things we have
already edited in Subsurface (like location, buddy, equipment, etc).

This, as a precaution, refuses to merge dives that don't have identical
start times. So if you have edited the date / time of a dive or if you
have previously merged your dive with a different dive computer (and
therefore modified samples and events) you are out of luck.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-11 14:29:26 +01:00
Dirk Hohndel
f53788e5e4 Add support for obtaining salinity from libdivecomputer
This requires a patched libdivecomputer that can return salinity of the
water the dive was conducted in. Experimental patches exist that implement
this for the OSTC. The code is designed so that it simply defaults to salt
water if libdivecomputer doesn't include the feature.

The patch also fixes the dive merge code to merge two other recent
additions to the dive structure (surface_pressure and visibility).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-10 19:22:22 +01:00
Dirk Hohndel
b63a5f0de6 Correct handling of O2 values below 21%
We incorrectly "fixed" those to be 21%. Not useful when diving trimix.

Fixes #4

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-27 18:04:20 -07:00
Dirk Hohndel
016365c5f1 Fix the way we handle translated event names
Here is what Linus reported:

 I think you have made a mistake in trying to translate some of
 libdivecomputer.c

 Translating some of those things based on locale is *wrong*, because
 they are saved in the XML file.

 That covers at least the warnings: they'll get translated when you
 import them, and then saved to the XML file as that translation, but
 now if you start subsurface in another locale, they will not get
 translated back.

 So translating XML file contents is fundamentally buggy. It just
 shouldn't be done.

 So all the "translations" for the event handling are buggy, and
 generate crap. Please don't do that. Leave them as English.

And of course he is absolutely right. However, instead of not translating
them at all, this commit fixes things a better way - we now mark the
strings for translation but store the original English strings everywhere
(in the in-memory data structure as well as in the XML file). Only when we
actually display something on the screen (in a tooltip or in the filter
dialog) do we actually translate the strings into the native language.

This should address both Linus' issue and the desire to have localized
event texts.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-21 11:40:30 -07:00
Dirk Hohndel
f01bfc11a9 Added missing localization macros to libdivecomputer.c
Somehow no one noticed that this file had been skipped in the localization
effort.

Fixes #6

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-20 14:46:30 -07:00
Dirk Hohndel
99846da77f Conversion to gettext to allow localization
This is just the first step - convert the string literals, try to catch
all the places where this isn't possible and the program needs to convert
string constants at runtime (those are the N_ macros).

Add a very rough first German localization so I can at least test what I
have done. Seriously, I have never used a localized OS, so I am certain
that I have many of the 'standard' translations wrong. Someone please take
over :-)

Major issues with this:

- right now it hardcodes the search path for the message catalog to be
  ./locale - that's of course bogus, but it works well while doing initial
  testing. Once the tooling support is there we just should use the OS
  default.

- even though de_DE defaults to ISO-8859-15 (or ISO-8859-1 - the internets
  can't seem to agree) I went with UTF-8 as that is what Gtk appears to
  want to use internally. ISO-8859-15 encoded .mo files create funny
  looking artefacts instead of Umlaute.

- no support at all in the Makefile - I was hoping someone with more
  experience in how to best set this up would contribute a good set of
  Makefile rules - likely this will help fix the first issue in that it
  will also install the .mo file(s) in the correct place(s)

  For now simply run

  msgfmt -c -o subsurface.mo deutsch.po

  to create the subsurface.mo file and then move it to
  ./locale/de_DE.UTF-8/LC_MESSAGES/subsurface.mo

  If you make changes to the sources and need to add new strings to be
  translated, this is what seems to work (again, should be tooled through
  the Makefile):

  xgettext -o subsurface-new.pot -s -k_ -kN_ --add-comments="++GETTEXT" *.c
  msgmerge -s -U po/deutsch.po subsurface-new.pot

  If you do this PLEASE do one commit that just has the new msgid as
  changes in line numbers create a TON of diff-noise. Do changes to
  translations in a SEPARATE commit.

- no testing at all on Windows or Mac
  It builds on Windows :-)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-10-11 10:03:03 +09:00
Linus Torvalds
2f7fa769d4 Don't update the progress bar from the dive computer import thread
There's no guarantee that gtk is thread-safe (apparently it can be
broken at least on Windows, even though it should be fine on top of X).

So don't update the progress bar directly from the dive computer import
code, instead just update the progress information in static variables,
and let the GUI thread update it while it does the idle loop polling
anyway.

Reported-by: Jef Driesen <jefdriesen@telenet.be>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-09-20 12:56:42 -07:00
Linus Torvalds
a44d0049f6 Update for new libdivecomputer interfaces
For this you need to get the current libdivecomputer tree, reconfigure,
build and install it first.  But this cleans up some of the silly error
handling too, and has just a single "dc_device_close()" call etc, rather
than duplicating that (and the new dc_context_free()).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-08-27 15:06:58 -07:00
Linus Torvalds
d4b0ce1c86 Update to new sane libdivecomputer interfaces
This does mean that you have to build subsurface against a new version
of libdivecomputer, and that version is likely going to have various
slightly incompatible changes.  But the new interfaces allow for easily
adding new supported dive computers without subsurface having to be
updated for each new vendor and model, so some slight pain is definitely
worth it this time.

I'm not even going to try to have some backwards-compatible version
here, the libdivecomputer interface changes are so extensive.  Native
enumeration of devices is just the smallest part of it: the constants
and types that libdivecomputer uses now have much nicer names that all
start with DC_ or dc_, so you don't get the kinds of name clashes we had
with "gasmix_t" etc.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-06-22 13:37:39 -07:00
Linus Torvalds
fb504b50d0 divecomputer importing: show the date of the currently importing dive
I'm hoping most other dive computers are quicker to import from than the
Suunto I have, but mine can take minutes to import all the dives.  Sure,
we have that nice progress bar, so it shows that it's doing something,
but it's not really showing *what* it is doing.

So instead of showing just "Parsing dive X", let's show the date of the
dive.  That way, when it takes two minutes to import all the dives, at
least you can see "oh, it's going back to the dives of last year" and it
then feels like you have some good reason for the delay.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-05-03 16:04:07 -07:00
Linus Torvalds
e7a70b6ae8 Show dive import text updates in the progress bar
Instead of using printf() to print the string updates ("Parsing sample
data" etc), introduce a function to show those strings in the graphical
progress bar itself.

Subsurface hasn't been a text-mode application in a long time ;)

This partially fixes the second todo entry from commit b0ba22a068
("Show dive import error messages in the import dialog") and generally
makes for a more helpful import - at least for the largely error-free
cases.

Sadly, the messages that really come from within libdivecomputer itself
(like "suunto_vyper2.c:193: Failed to receive the answer.") when things
go really wrong are not caught.  libdivecomputer does have a notion of a
logfile (set with "message_set_logfile()"), but that ends up being
really inconvenient.

Maybe we could use some pipe setup or something. Oh well.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-05-02 17:42:58 -07:00
Linus Torvalds
b0ba22a068 Show dive import error messages in the import dialog
.. not in the main window.  And leave the import dialog open, so that
you can either try doing it again, or cancel.  This makes it much easier
to re-try a failed dive import, and actually makes the failure more
obvious too.

Todo:

 - make the "Ok" button change to "Retry" when an error happens

 - try to see if we can catch the actual status update messages from
   libdivecomputer and show them too in the import dialog.  Right now
   they are printed out to stderr by the library.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-05-02 12:49:03 -07:00
Linus Torvalds
2d1a316d84 Make subsurface compile with current libdivecomputer git tree
libdivecomputer has the absolute worst interfaces to any library *ever*,
and randomly changes those crappy interfaces when it adds support for
new dive computers.

It would have been much better if the interface was just a "open this
device" with a device descriptor structure pointer, so that when Jef
adds support for new devices, the old descriptors still stay around and
work the same way - there's just a new descriptor structure that you
*can* use if you want.  Along with a data structure to name the devices
and their descriptors, this would actually mean that users could just
support pretty much any random device that LD supports.

But no, that's not how libdivecomputer works.  It has random enums and
crazy different ad-hoc interfaces for different dive computers.  Or,
like in this case, crazy different ad-hoc interfaces for the *same*old*
dive computer.

Right now, for example, the support for the new Heinrichs Weikamp "Frog"
computer added a flag to the interface for the old OSTC_2 support.
Breaking any libdivecomputer users even if you didn't need Frog support.

And is there a version number in the header files to check for? Yes,
there's a version number.  But no, it's not useful, since it doesn't
actually change with the interface changes.  This time, Jef actually did
change the version number (from 0.1.0 to 0.2.0) as part of new
development version, but there's no reason to believe that it will
change in the future  as the interfaces change - it never has before.

So it's actually safer - and easier to understand - to check for the
existence of the new header file inclusion mechanism.  A new version of
libdivecomputer that supports the HW Frog computer will include the
"ostc_frog.h" header file when you include the libdivecomputer device.h
file, and that will result in HW_FROG_H being defined.

So we can check whether libdivecomputer has the new interface and
supports the Frog by doing an "#ifdef HW_FROG_H" hack. Ugh.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-05-02 09:36:55 -07:00
Björn Spruck
f69be7b571 Added support for Mares Darwin, M1, M2, ... from latest libdivecomputer.
Only M1 has been tested.
Darwin Air will most likely not work as an additional model flag seems to be needed.
This is not foreseen in current GUI.
2012-03-25 17:16:21 +02:00
Dirk Hohndel
1d6903c65a Oddly, finishing a sample doesn't require a sample
So let's not pass it around

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-01-05 08:16:50 -08:00
Henrik Brautaset Aronsen
16b6df559f Define O2 permille for air in one spot
Having the O2 permille defined once is more readable.

Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no>
2011-12-31 17:15:59 +01:00
Dirk Hohndel
ff0209a5b4 fix mingw-win32 specific warnings in libdivecomputer.c
1) since %lld is not defined in the MSVC runtime, use
the portable PRId64 macro from inttypes.h for 64bit integers

notice in inttypes.h from mingw-win32:
/* 7.8.1 Macros for format specifiers
 *
 * MS runtime does not yet understand C9x standard "ll"
 * length specifier. It appears to treat "ll" as "l".
 * The non-standard I64 length specifier causes warning in GCC,
 * but understood by MS runtime functions.
 */

2) include unistd.h to disable warning:
warning: implicit declaration of function 'usleep'

Lubomir's code then caused a warning building natively under Linux, which
I fixed as well.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2011-11-27 09:10:37 -08:00
Julian Andres Klode
4c6f142e85 Remove some useless casts from and to void pointers
Remove casts from/to void*.  They are unneeded in C, can hide problems
in the future, and are far too C++ish.  Furthermore, they were
inconsistent with the rest of the code and even with regards to
themselves (at least in terms of whether or not to have space after the
cast).

In this case, we temporarily lose const specifiers in libdivecomputer.c
due to the unneeded cast, so it seems better to avoid the cast at all,
so you get warned about a const->non-const cast if you ever change it to
do something like this.

The casts in gtk-gui.c are just useless semantically, although they
might be useful as a hint to the reader that the void pointers are char
arrays.

Signed-off-by: Julian Andres Klode <jak@jak-linux.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-10-06 12:25:24 -07:00
Linus Torvalds
d6c2236b8a Automatically renumber new dives when they are "obvious".
When importing (or reading xml from files) new dives, we now renumber
them based on preexisting dive data, *if* such re-numbering is obvious.

NOTE! In order to be "obvious", there can be no overlap between old and
new dives: all the new dives have to come at the end.  That's what
happens with a normal libdivecomputer import, since we cut the import
short when we find a preexisting dive.

But if any of the new dives overlap the old dives in any way, or already
have been numbered separately, the automatic renumbering is not done,
and you need to do a manual renumber.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-10-05 08:31:31 -07:00
Dirk Hohndel
c15f798a85 Remove the ability to 'Import' .SDA files
We can instead 'Open' these files as they are just bastardized XML files.

This gets us back to a more consistent point where 'Import' gets data
directly from the dive computer (and hopefully soon we will add the
ability to load a dive directly from a uemis SDA to libdivecomputer),
and 'Open' loads a file from the filesystem of the computer we are
running on (this last sentence phrased so awkwardly as the uemis Zurich
SDA is a computer and presents a file system when connected via USB - it
just doesn't have the dive data in an accessible format in that file
system).

As a bonus we get to throw away quite a bit of code (the uemis specific
file handling, mini-XML parser with helper functions, the file open dialog
in the importer). Yay!

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-10-03 08:34:56 -07:00
Linus Torvalds
8eeeb97b85 Update Mares IconHd parsing to current libdivecomputer interface
The libdivecomputer interfaces are pure crap.  There are no generic
"open the dive computer" or "create a parser for the dive computer"
interfaces, instead each dive computer you support has its own open and
parser generator interface.

And they change.  Happily fairly seldom, but they change.  And two days
ago, Jef changed the interface for the Mares Icon HD computer in order
to support the newer HD Net Ready variant.

I've asked Jef to make a sane interface for "open the dive computer" and
"just create the parser" for libdivecomputer, but he claims that he
cannot just track the device model details internally.  Which is
obviously a completely bogus claim, since the way *we* track the model
details is to just feed it back from the silly event.

libdivecomputer should just do that internally and not bother us with
its crazy internal model numbers.  But whatever.

In the meantime, work around this braindamage, and hope that
libdivecomputer comes to its senses some day.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-26 13:14:41 -07:00
Linus Torvalds
5c8305588b Stop libdivecomputer import when we start seeing old dives
I don't know about other dive computers, but the Suunto Vyper Air is
slow as hell to import all the dives from.  And libdivecomputer seems to
be importing dives "most recent first", so this just makes it stop
importing dives when it finds a dive that we've already seen.

Caveat: libdivecomputer has this fancy notion of "dive fingerprints",
and claims that's the way to do things.  That seems to be overly
complicated, and not worth the bother.

If you worry about the import finishing early due to already having some
dives with the same date in your dive list, just import starting from an
empty state, and thus get a pure "dive computer only" state with no
early out.  Then you can just load the old dives afterwards, and depend
on subsurface merging any duplicates.

But for normal operation, when you just want to import a couple of new
dives from your dive computer, the "exit import early when you see a
duplicate" is the right thing to do.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-26 13:04:14 -07:00
Linus Torvalds
3a77eb8510 Start handling dive events
Parse them, save them, take them from libdivecomputer.

This doesn't merge them or show them in the profile yet, though.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-22 18:02:54 -07:00
Linus Torvalds
d344d15a90 Improve libdivecomputer event printout
Ignore surface events - they are meaningless anyway and just add noise.

Print out other events properly, including correct time offset etc.

We still don't actually *save* the events, but now it might be worth
doign so.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-22 16:55:55 -07:00
Linus Torvalds
d463cace5e Clean up event handling from libdivecomputer
This just moves the event handling out into its own helper function.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-22 16:45:28 -07:00
Linus Torvalds
c0adfdc41b Fix progress bar during libdivecomputer imports
As reported by Mauro Dreissig, the progress bar doesn't work and causes
a SIGSEGV due to a missing allocation.  The code broke when Dirk
separated out the GUI from the core code, and I hadn't tried
divecomputer downloads since.

Reported-by: Mauro Dreissig <mukadr@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-22 16:38:24 -07:00
Dirk Hohndel
682135838f Separate out the UI from the program logic
The following are UI toolkit specific:
gtk-gui.c   - overall layout, main window of the UI
divelist.c  - list of dives subsurface maintains
equipment.c - equipment / tank information for each dive
info.c      - detailed dive info
print.c     - printing

The rest is independent of the UI:
main.c i    - program frame
dive.c i    - creates and maintaines the internal dive list structure
libdivecomputer.c
uemis.c
parse-xml.c
save-xml.c  - interface with dive computers and the XML files
profile.c   - creates the data for the profile and draws it using cairo

This commit should contain NO functional changes, just moving code around
and a couple of minor abstractions.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2011-09-20 12:48:56 -07:00
Linus Torvalds
9cf8d98711 Make 'struct DiveList' entirely internal to divelist.c
Passing it around is just annoying, and we only ever have one.  Let's
not burden all the users with the silly thing.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-20 10:06:24 -07:00
Linus Torvalds
8c18add46b Do libdivecomputer imports in a separate thread
This is the hackiest thing ever, unless you count the previous code that
was even hackier (and just called the gtk main routine at random
places).

The libdivecomputer library is not really set up to be part of the gtk
main loop, and cannot afford (for example) to have lots of mainloop
events while it's parsing.  Some dive computers are very timing
sensitive for the communication.

So just start a thread for doing the libdivecomputer stuff, and just
continually call the gtk main loop while that thread is running.  I'm
sure we could actually use some gtk signalling thing to make the thread
exit do the right thing, but instead we just poll the status every
100ms.

I did say it was hacky.  It does seem to work, though.  No more
temporary graying out of the windows when they don't react in a timely
manner because libdivecomputer does some blocking operation.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-15 22:58:02 -07:00
Linus Torvalds
3a6652634b Rename the project 'subsurface'
I never really liked 'diveclog' as a name - it's not like the C part is
all that important.  And while I could try to just make up another slang
word for despicable person (in the tradition of naming all my projects
after myself), I just can't see it.

So let's just call it "subsurface".

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-15 09:43:14 -07:00
Dirk Hohndel
518ec33ba3 First pass to parse uemis Zurich '.SDA' files
This is missing a ton of the information in the .SDA files It only
parses the divelog.SDA file, not the dive.SDA file It ignores the
information on the gas(es) used and all the data on the tanks.

It still draws some strange artefacts at the end of the dive

But it correctly hooks into the import dialogue, it gives you a file
select box (somewhere, I'm sure, a gtk developer cries quietly) and then
parses enough of this file to serve as a proof of concept.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-15 08:52:55 -07:00
Dirk Hohndel
b35e1bad8e Quick fix to hardcode device name only once
Linus clearly wanted to make SURE that we use /dev/ttyUSB0

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-14 11:37:25 -07:00
Linus Torvalds
4e7161efd6 Do some basic sanity testing on the libdivecomputer gasmix data
It's quite often obvious crap for the "doesn't exist" or "plain air" case.

So if it's reporting 100% O2, we just ignore it.  Sure, it could be
right, but for the dives I have I know it's just libdivecomputer being
wrong.

Same goes for obvious crap like 255% Helium.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-12 13:31:43 -07:00
Linus Torvalds
42f627b8b1 Libdivecomputer: start actually importing the dive data
So this actually reports the dive data that libdivecomputer generates.
It doesn't import special events etc, but neither do we for the xml
importer.

It is also slow as heck, since it doesn't try to do the "hey, I already
have this dive" logic and always imports everything, but the basics are
definitely there.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-12 13:25:05 -07:00
Linus Torvalds
d45db9fac7 libdivecomputer integration: add a progress bar
Instead of writing out the progress events, use them to update a real
progress bar.

Also, we need to handle gtk events while busy with the dive computer
reading.  That should *probably* be done with a threading model, because
libdivecomputer does seem to have some timing sensitivity - I'm getting
"failure to read memory block" if I make that loop do the standard

	while (gtk_events_pending())
		  gtk_main_iteration();

thing.  Besides, even if we did do that loop, it would still cause
problems when the libdivecomputer code is stuck reading a serial line
that doesn't respond or whatever.

But for now this ugly hack is "good enough" to get further.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-12 11:41:26 -07:00
Linus Torvalds
d5b7f7dc06 Libdivecomputer integration, part n+1
This actually gets me far enough that it prints out all the dives on my
dive computer.  It doesn't actually turn them into real dives yet,
though - only a series of ugly 'printf's so far.

And it hangs after printing the last dive. So I'm doing something wrong.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-12 11:05:32 -07:00
Linus Torvalds
7d8fed4eee More libdivecomputer boilerplate stuff
.. fill in the event parsing.  This doesn't generate the fingerprint
like the example does, I just don't care about that yet.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-12 10:37:54 -07:00
Linus Torvalds
6b0bb87f5b Further work on libdivecomputer integration
.. this now registers the dive parsing callback, and starts to parse the
data.  So I can see the last divetime on my Suunto Vyper Air now.

Still a lot more boilerplate stuff to go, though.  The libdivecomputer
interfaces really are pretty insane: why should the caller set up the
dive parsing for each computer type, when libdivecomputer knows what
types it has? IOW, much of that boilerplate should be hidden inside of
libdivecomputer, rather than exposed to the user.

But whatever.  I'm taking pieces from "examples/universal.c" as I go
along (it's under LGPL 2.1).  I want to do it in small chunks just to
feel that I understand what's going on, rather than just blindly copying
it all.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-12 10:27:35 -07:00
Linus Torvalds
a9f74044ae Flesh out the libdivecomputer interfaces some more
.. start some error reporting, and register some early (empty)
callbacks.

This still doesn't actually do anything.  But commit early, commit
often: when I start seriously breaking things, I want to have a "hey,
this still at least compiled" state.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-12 09:50:40 -07:00
Linus Torvalds
9cb60c9106 Start some very initial libdivecomputer integration
Ok, so this is quite broken right now: it doesn't actually really *do*
anything, and it now requires that you have libdivecomputer all set up
and installed.

That is fairly easy:

	mkdir ../src
	cd ../src
	git clone git://libdivecomputer.git.sourceforge.net/gitroot/libdivecomputer/libdivecomputer
	cd libdivecomputer
	autoreconf --install
	./configure
	make
	sudo make install

but you may feel that this is not exactly useful considering that
nothing actually *works* yet.

Some day.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-12 09:27:01 -07:00