Commit graph

82 commits

Author SHA1 Message Date
Berthold Stoeger
420aab9454 Cleanup: don't produce no-dives error message in libdivecomputer.c
If no dives were downloaded in do_libdivecomputer_import(), an
error message would be produced. To check for downloaded dives,
the function would access the global downloadTable instead of
the actual table the dives are imported to (at the moment the
same - but the interface allows for a different table).

Move the error-creation to the caller to avoid this situation.
An alternative option would be to check the actual table the
dives were supposed to be downloaded to. But from a program-logic
point of view "no dives" does not seem like an error condition.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-05 04:09:02 +03:00
Linus Torvalds
d2b8088cd8 Actually create a UUID when creating a dive site during download
The existing code creates a deterministic ID (not exactly "unique") in order to
help us avoid merge conflicts in git-storage mode. But as a side effect, if we
re-download the same dive twice from a dive computer that supports GPS (right
now only the Garmin Descent Mk1) we are guaranteed to create the same dive site
uuid when we do this. So when we download a dive - whether we will actually
*use* that dive later or not - we will be filling in the dive site information
with the data we got from the dive computer.

... and in the process we will be overwriting any data that was filled in
manually. The name of the dive site, but also possibly even the GPS of the dive
site (maybe the user decided to edit that using the map, because while the
automatically downloaded GPS data was "correct", maybe the user wanted to
change it to be the actual under-water location using the satellite data,
rather than the place where you started the dive or where you surfaced).

In order to avoid this collision, this patch just makes the libdivecomputer
download not use the dive time, but "time of download" for the dive site time,
and thus effectively generate a new uuid for every download.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-22 14:17:24 -07:00
Anton Lundin
1da9235cdf Always return status from ftdi_open when called
Using dc_serial_open as a fallback to ftdi_open is just wrong, and will
never work, just mask the real error and introduce read herrings.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2018-09-16 08:09:24 -07:00
Linus Torvalds
5c2bca048f libdivecomputer: allow a "zero depth" deco stop depth
That just means that we're not in deco, the same way as giving a nonzero
NDL value does.  But if you don't have NDL, this is a much more
convenient way of saying "not in deco".

The Garmin Descent gives us stop information, but not necessarily NDL,
and really wants this.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-03 13:29:40 -07:00
Linus Torvalds
faea11e4fb libdivecomputer: add support for DC_SAMPLE_TTS if it exists
libdivecomputer didn't use to have a TTS sample value, but we're adding
one, so add conditional support for it if it exists.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-03 13:29:40 -07:00
Linus Torvalds
f59679320a parse "GPS" string fields and turn them into dive sites when downloading
Dive computers that do GPS can report their GPS data as one or more
string fields, and if the first tree letters of the description is
"GPS", then we'll take the string and turn it into a dive site for that
dive.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-08-29 21:40:19 -07:00
Linus Torvalds
80fe8fb331 Add support for opening a DC_TRANSPORT_USBSTORAGE stream
This is part of the whole "let's support the notion of dive computers
being exported as USB storage devices" push.

With an older libdivecomputer, we'll just fall back on failing the
operation, but we still want to support the generic notion of
DC_TRANSPORT_USBSTORAGE since we have our own internal Uemis downloader.
That one won't ever get to the open phase, since it's caught earlier.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-08-27 22:11:05 -07:00
Dirk Hohndel
5377706aca FTDI support: try ftdi_open first if the device name is 'ftdi'
It makes no sense to have the OS try (and fail) to open that device name.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-06-21 16:16:29 +09:00
Dirk Hohndel
05a00f31e9 mobile: better message regarding logfiles
On mobile those area always created and available for simple cut and paste.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-06-21 15:49:23 +09:00
Berthold Stoeger
3932c97af7 libdc interface: remove debug messages
Don't spill supported transports as error message to the user.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-18 06:25:40 +09:00
jan Iversen
061be82e31 core: replace (void) with UNUSED(x) and include ssrf.h
Unused parameters in C are "silenced" by adding UNUSED(x)

Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-24 08:34:14 -07:00
Dirk Hohndel
d577467f97 Core: introduce new subsurface-string header
First small step to shrinking dive.h.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-14 10:13:39 -07:00
Dirk Hohndel
2d253c71ff Add Qt header so Q_OS_xxx macros work
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-12 21:09:14 -07:00
Dirk Hohndel
e6cb98ea4b iOS: only DC_TRANSPORT_BLE is supported
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-11 21:32:04 -07:00
Dirk Hohndel
028299193a Create one function to determine the supported transports
This should make sure we create a consistent view based on all the
information available.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-04-27 11:52:48 -07:00
Dirk Hohndel
5faa167e9f libdc transport debugging
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-04-27 11:52:48 -07:00
Linus Torvalds
901991afbe Do a better job of picking which transport to use
If the user specified bluetooth, we really should pick bluetooth, not
probe and possibly fall back to something else.

We should also honor the users choice of BLE vs classic BT.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-04-27 11:52:13 -07:00
Linus Torvalds
c60d2ec3e3 use libdivecomputer 'fingerprint' to avoid downloading extra data
This opportunistically uses a cache of 'fingerprints' for already
downloaded dives.

As we download data from a dive computer, we save the fingerprint and
dive ID of the most recent dive in a per-divecopmputer fingerprint cache
file.

The next time we download from that dive computer, we will load the
cache file for that dive computer if it exists, verify that we still
have the dive that is referenced in that cachefile, and if so use the
fingerprint to let libdivecomputer potentially stop downloading dives
early.

This doesn't much matter for most dive computers, but some (like the
Scubapro G2) are not able to download one dive at a time, and need the
fingerprint to avoid doing a full dump.  That is particularly noticeable
over bluetooth, where a full dump can be very slow.

NOTE! The fingerprint cache is a separate entity from the dive log
itself.  Unlike the dive log, it doesn't synchronize over the cloud, so
if you download using different clients (say, your phone and your
laptop), the fingerprint cache entries are per device.

So you may still end up downloading dives you already have, because the
fingerprint code basically only works to avoid duplicate downloads on
the same installation.

Also, note that we only have a cache of one single entry per dive
computer and downloader, so if you download dives and then don't save
the end result, the fingerprint will now point to a dive that you don't
actually have in your dive list.  As a result, next time you download,
the fingerprint won't match any existing dive, and we'll resort to the
old non-optimized behavior.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-04-24 17:54:08 -07:00
Linus Torvalds
acc343834a Actually tie in the new libdivecomputer IO model to open the dive computer device
This creates a new libdivecomputer_device_open() helper, and makes
downloading and configuration use it to open the dive computer device
using the proper protocol.

The IRDA case was tested by Sébastien Dugué - I had initially left it
undone believing that "nobody uses IRDA".

Reported-and-tested-by: Sébastien Dugué <sebastien.dugue.subsurface@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-04-24 17:54:08 -07:00
Linus Torvalds
13f5c75ac4 Convert our custom IO model to new libdivecomputer IO model
This converts our old custom IO model to the new model that
libdivecomputer introduced.  This is partly based on Jef's rough patch
to make things build, with further work by me.

The FTDI code is temporarily disabled here, because it will need to be
integrated with the new way of opening devices.

The ble_serial code goes away entirely, since now libdivecomputer knows
about BLE transport natively, and doesn't need to have any serial
wrapper around it.

Signed-off-by: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-04-24 17:54:08 -07:00
Berthold Stoeger
f7b2355ced Cleanup: unconstify results of two functions
get_dive_date_c_string() and get_current_date() return copied strings.
Make this explicit by returning non-const pointers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-11 14:01:51 +03:00
Berthold Stoeger
5c248d91cd Coding-style: remove superfluous parentheses
Mostly replace "return (expression);" by "return expression;" and one
case of "function((parameter))" by "function(parameter)".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-17 19:38:52 -08:00
Berthold Stoeger
e85ecdd925 Introduce helper function empty_string()
There are ca. 50 constructs of the kind
  same_string(s, "")
to test for empty or null strings. Replace them by the new helper
function empty_string().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-11 06:07:13 +01:00
Berthold Stoeger
c4c57b287e Increase size of name_buffer to fit any integer
In libdivecomputer.c, name_buffer is formatted with calls like
 snprintf(name_buffer, 9, "%d cuft", rounded_size);
This works fine in the regular case, but it generates compiler
warnings, since theoretically the integer might produce up to
11 digits, leading to a truncation of the string.

Increasing the size of name_buffer to 17 chars silences these
warnings. This may seem like pointless warning-silencing.
Nevertheless, in the case of invalid data, it might make debugging
easier since, in the above case, the "cuft" is never truncated.
In total, it seems that this is a benign change with potential,
though in a very unlikely case, positive effects.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-05 00:29:20 +01:00
Dirk Hohndel
da1d6e97f6 Cleanup: avoid memory leak
Coverity CID 208337

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 14:10:53 -08:00
Dirk Hohndel
0e94c21a55 Cleanup: prevent potential out of bounds write
Since we cannot store tanks / gases past MAX_CYLINDERS (currently 20),
there is no point in analyzing those data.

Coverity CID 208339

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 14:04:10 -08:00
Jan Mulder
9d2c52f692 Add pSCR divemode detection
In libdivecomputer, a new divemode is added (DC_DIVEMODE_SCR) useful
for dive computers that have specfic functionality for semi-closed
rebreathers. At this moment, only the HW computers seem to provide
this.

This commit takes care of proper recognition of this new divemode
when importing data from a dive computer.

Tested on an actual import from an OSTC3 that contained
dives in this new mode.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-13 05:03:36 -08:00
Jan Mulder
78d1a3ed58 Rename DC_DIVEMODE_CC to DC_DIVEMODE_CCR
This is just code cleanup. Jef renamed the CCR divemode constant
in libdivecomputer, but added a define to be backward compatible as
as well (so this rename did not break our Subsurface build).

Obviously, this breaks the build for people that build against an older
libdivecomputer, but I see no reason to do that.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-13 05:03:36 -08:00
Stefan Fuchs
72129289a8 During DC import reset cns, ndl, other values inbetween dives
Reset cns and heartbeat to 0
Reset ndl and bearing to -1

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-16 08:32:46 +01:00
Stefan Fuchs
0895bccf49 libdivecomputer.c init sticky values for samples for current sample
When filling samples with values during DC import fill sticky values
like CNS, NDL, stoptime,... immediately into current sample.
Otherwise we will not fill the sticky values into the last sample
created.
Add two new sticky values: heartbeat and bearing

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-16 08:32:46 +01:00
Miika Turkia
2a29d4a4ba Save Subsurface version to libdivecomputer logfile
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-09-28 08:51:34 +02:00
Dirk Hohndel
16d9b0c790 DC download: fix 'no new dives' message
Stupidly, commit 731d9dc9bd ("DC download: tell user when no new dives
were found") was missing the conditional when to show that messages.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-09-20 18:44:14 -04:00
Dirk Hohndel
731d9dc9bd DC download: tell user when no new dives were found
Otherwise it almost looks like something went wrong with the download.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-09-17 14:46:44 -07:00
Dirk Hohndel
5de49401c8 Improve error message when opening dive computer fails
Instead of the (usually incorrect) text about insufficient privileges,
just mention a generic error and suggest that the user creates a
libdivecomputer log file.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-08-21 08:13:19 -07:00
Linus Torvalds
c5167f0039 Make sample pressure helper functions available to everybody
We had a "add_sample_pressure()" helper functions that was local to just
the libdivecomputer downloading code, but it really is applicable to
pretty much any code that adds cylinder pressure data to a sample.

Also add another helper: "legacy_format_o2pressures()" which checks the
sample data to see if we can use the legacy format, and returns the o2
pressure sensor to use for that legacy format.

Because both the XML and the git save format will need a way to save the
compatible old-style information, when possible, but save an extended
format for when we have data from multiple concurrent sensors.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-25 22:04:56 -07:00
Linus Torvalds
adb4b66a05 Try to sanely download multiple concurrent cylinder pressures
This tries to sanely handle the case of a dive computer reporting
multiple cylinder pressures concurrently.

NOTE! There are various "interesting" situations that this whole issue
brings up:

 - some dive computers may report more cylinder pressures than we have
   slots for.

   Currently we will drop such pressures on the floor if they come for
   the same sample, but if they end up being spread across multiple
   samples we will end up re-using the slots with different sensor
   indexes.

   That kind of slot re-use may or may not end up confusing other
   subsurface logic - for example, make things believe there was a
   cylidner change event.

 - some dive computers might send only one sample at a time, but switch
   *which* sample they send on a gas switch event.  If they also report
   the correct sensor number, we'll now start reporting that pressure in
   the second slot.

   This should all be fine, and is the RightThing(tm) to do, but is
   different from what we used to do when we only ever used a single
   slot.

 - When people actually use multiple sensors, our old save format will
   start to need fixing.  Right now our save format comes from the CCR
   model where the second sensor was always the Oxygen sensor.

   We save that pressure fine (except we save it as "o2pressure" - just
   an odd historical naming artifact), but we do *not* save the actual
   sensor index, because in our traditional format that was always
   implicit in the data ("it's the oxygen cylinder").

so while this code hopefully makes our libdivecomputer download do the
right thing, there *will* be further fallout from having multiple
cylinder pressure sensors.  We're not done yet.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-25 06:11:10 -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
Dirk Hohndel
2f84a85dc9 Resolve type confusion
No idea why this now shows up as an error in the iOS build.
We need to refer to the typedef, not the underlying struct.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-17 16:50:03 -07:00
Dirk Hohndel
e8b46039f6 Tell user if we reached a dive that was already there
This way it's more obvious why no dives were downloaded.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-09 16:29:16 -07:00
Dirk Hohndel
e6c2b14588 More meaningful device info display
While it's nice to have the numerical model in the logfile,
on the screen the user wants to see the dive computer product
name. And none of those hex numbers that make the text so long
that it becomes useless.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-09 16:09:04 -07:00
Dirk Hohndel
8e5c211e21 Revert "Add support for tank sensor battery for Perdix AI"
This reverts commit ed43b5dced ("Add
support for tank sensor battery for Perdix AI") since a much better
solution to get to that information has been implemented in
libdivecomputer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-09 14:46:42 -07:00
Dirk Hohndel
d2a5bf87c4 QML UI: add dev_info data to AppLog
This should make it easier to tell how far we get downloading data
from dive computers.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-09 12:50:22 -07:00
Dirk Hohndel
d5793ea6af If we detect a different model than expected, use it
This is useful if the underlying code in libdivecomputer can reliably
detect specific hardware models.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-08 09:57:21 -07:00
Dirk Hohndel
ed43b5dced Add support for tank sensor battery for Perdix AI
This is a bit awkward with a VENDOR event - but at the time the strings
are generated, we don't have the information, yet, that we need to
determine these values (we need the last sample parsed, but the strings
are created as part of the dive headers.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-07 13:48:24 -07:00
Dirk Hohndel
fbdba88dec Update Subsurface-branch of libdivecomputer check
We now require the Subsurface-branch, and at least version 2 of the
Subsurface API of libdivecomputer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-27 20:52:12 -07:00
Linus Torvalds
d01b7bf891 Switch over to SSRF_CUSTOM_IO v2
I hate changing the IO interfaces this often, but when I converted the
custom serial interface to the more generic custom IO interface, I
intentionally left the legacy serial operations alone, because I didn't
want to change something I didn't care about.

But it turns out that leaving them with the old calling convention
caused extra problems when converting the bluetooth serial code to have
the BLE GATT packet fall-back, which requires mixing two kinds of
operations.

Also, the packet_open() routine was passed a copy of the 'dc_context_t',
which makes it possible to update the 'dc_custom_io_t' field on the fly
at open time.  That makes a lot of chaining operations much simpler,
since now you can chain the 'custom_io_t' at open time and then
libdivecomputer will automatically call the new routines instead of the
old ones.

That dc_context_t availability gets rid of all the

	if (device && device->ops)
		return device->ops->serial_xyz(..);

hackery inside the rfcomm routines - now we can just at open time do a simple

	dc_context_set_custom_io(context, &ble_serial_ops);

to switch things over to the BLE version of the serial code instead.

Finally, SSRF_CUSTOM_IO v2 added an opaque "dc_user_device_t" pointer
argument to the custom_io descriptor, which gets filled in as the
custom_io is registered with the download context.  Note that unlike
most opaque pointers, this one is opaque to *libdivecomputer*, and the
type is supposed to be supplied by the user.

We define the "dc_user_device_t" as our old "struct device_data_t",
making it "struct user_device_t" instead.  That means that the IO
routines now get passed the device info showing what device they are
supposed to download for.

That, in turn, means that now our BLE GATT open code can take the device
type it opens for into account if it wants to.  And it will want to,
since the rules for Shearwater are different from the rules for Suunto,
for example.

NOTE! Because of the interface change with libdivecomputer, this will
need a flag-day again where libdivecomputer and subsurface are updated
together. It may not be the last time, either.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-27 13:58:15 -07:00
Dirk Hohndel
63a4a755a3 Warn when not compiling against the matching libdc version
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-22 17:53:53 -07:00
Linus Torvalds
add253ca9e Convert to new libdivecomputer custom IO model
Instead of being "custom serial", it's a IO model that allows serial or
packet modes, independently of each other (ie you can have a bluetooth
device that does serial over BT rfcomm and packet-based communication
over BLE GATT with the same serial operations that describe both cases).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-22 08:43:47 -07:00
Dirk Hohndel
cbe03fd88d FTDI support: add minimal debugging output
Copied the libdivecomputer macros for convenience.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-29 21:55:49 -07:00