Commit graph

94 commits

Author SHA1 Message Date
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
Jan Mulder
76a38b6326 More optimal search
The linear search to determine that a just downloaded dive was already
downloaded, started from the oldest dive in the logbook. It is, however
more likely that a just downloaded dive is one of the most recently
downloaded. So, just search backwards. Just a trivial performance
improvement.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-05-29 08:57:04 -07:00
Dirk Hohndel
6399eaf271 Add SPDX header to core C files
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29 13:32:55 -07:00
Jan Mulder
9b5d3b60ab Do not carry po2 setpoint data over dive boundaries
The file static po2 value, used to set the setpoint data, was not re-initialized
at the parsing of a dive during import from the divecomputer. So, in one import session,
the po2 was transferred from one dive to the next, obviously resulting in weird bugs, due
to possible wrong po2 settings.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-04-24 07:51:12 -07:00
Jef Driesen
f8203b8efe Cleanup some unnecessary include statements
Some of these header files are no longer necessary, and will be removed
from libdivecomputer in the near future.

Signed-off-by: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-13 18:02:47 -07:00
Dirk Hohndel
34a42d7f04 Shift fake tank pressures up by 30bar
This is a rather arbitrary value, intended to create actually valid
pressure values for Uwatec Memomouse users - since we treat 0bar as
invalid pressure value, this simply creates an arbitrary '30bar + delta'
to '30bar' consumption graph (since all the Memomouse devices give us is
the pressure delta that was used during the dive).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-30 11:44:45 +02:00
Dirk Hohndel
09b5f9b99c Accept 0 as valid endpressure for Uwatec devices
Instead of delivering the actual start and end pressure, memomouse
gives you a start pressure that matches the delta between actual
start and end pressure, and an end pressure of zero. Who the heck
knows why it does that, but the information is better than nothing,
so we should accept it.

Fixes #286

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-29 14:00:16 +02:00
Lubomir I. Ivanov
bcad5ddd38 Only enable -Wmissing-field-initializers for Clang
The following pragma is Clang specific:

It produces a warning:
warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]

Only enable it for Clang by checking the __clang__ macro.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-12 09:18:59 -07:00
Dirk Hohndel
08284275e7 Merge branch 'master' of https://github.com/dje29/subsurface 2017-03-11 08:41:41 -08:00
Martin Měřinský
f24e0ba5ec divemode > dive mode 2017-03-11 08:09:07 -08:00
Jeremie Guichard
2b06a0b223 Fix potential double/float to int rounding errors
Not using lrint(f) when converting double/float to int
creates rounding errors.
This error was detected by TestParse::testParseDM4 failure
on Windows. It was creating rounding inconsistencies
on Linux too, see change in TestDiveDM4.xml.

Enable -Wfloat-conversion for gcc version greater than 4.9.0

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2017-03-09 23:07:30 +07:00
Jeremie Guichard
406e4287eb Change calls to rint into lrint avoiding conversion warnings
Using gcc option "-Wfloat-conversion" is useful to catch
potential conversion errors (where lrint should be used).
rint returns double and still raises the same warning,
this is why this change updates all rint calls to lrint.
In few places, where input type is a float, corresponding
lrinf is used.

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2017-03-08 14:04:17 +07:00
Robert Helling
67de8f3a49 Correct: Handle more tanks than gasmixes
When Suunto Vytecs are used in gauge mode they don't record gasmixes.
If a tank pressure sensor is present they nevertheless record the
pressures. This patch handles this situation by assuming the tanks
contain air (and warning the user about this).

[Dirk Hohndel: I had mistakenly pushed out an earlier version of this
               commit, so this fixes things up to the final version]

Reported-by: antonnorth@gmail.com
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-02-03 07:43:00 -08:00
Robert C. Helling
99595542ec Handle more tanks than gasmixes
When Suunto Vytecs are used in gauge mode they don't record gasmixes.
If a tank pressure sensor is present they nevertheless record the
pressures. This patch handles this situation by assuming the tanks
contain air (and warning the user about this).

Reported-by: antonnorth@gmail.com
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-02-02 12:35:58 -08:00
Linus Torvalds
e1ee577c4f Make event string translation when downloading from libdivecomputer more obvious
We had hardcoded the exact translation of the event numbers.  They
haven't changed (although we did have what appears to be a spurious
entry for "non stop time" at the end that libdivecomputer doesn't have
an enum for).

Instead, use an explicit array index initializer array, so that it's
obvious that the two match up (and if the sample event numbers ever
change, we should cope with it gracefully).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-01-17 09:15:50 -08:00
Linus Torvalds
fe5f15bdc5 Add support for libdivecomputer using DC_SAMPLE_GASMIX
New libdivecomputer versions use DC_SAMPLE_GASMIX to indicate a gas
change (which contains the cylinder index we're changing to) rather than
SAMPLE_EVENT_GASCHANGE*.

Unlike the old GASCHANGE model, and despite the name, DC_SAMPLE_GASMIX
does not actually say what the mix is, it only specifies a cylinder
index.  We had already extended SAMPLE_EVENT_GASCHANGE2 to have the
cylinder index in the otherwise unused "flags" field, so this is not all
that different from what we used to do.

And subsurface internally already had the logic that "if we know what
the cylinder index is, take the gas mix from the cylinder data", so
we've already been able to transparently use _either_ the actual gas mix
or the cylinder index to show the event.

But we do want to make it an event rather than some sample data, because
we want to show it as such in the profile.  But because we are happy
with just the cylinder index, we'll just translate the DC_SAMPLE_GASMIX
thing to the SAMPLE_EVENT_GASCHANGE2 event, and nothing really changes
for subsurface.

libdivecomputer has made other changes, like indicating the initial
cylinder index with an early DC_SAMPLE_GASMIX report, but we've seen
that before too (in the form of early SAMPLE_EVENT_GASCHANGE events), so
that doesn't really end up changing anything for us either.

HOWEVER, one thing that is worth noticing: do *not* apply this patch and
then use an old libdivecomputer library that sends both the
DC_SAMPLE_GASMIX samples _and_ the deprecated SAMPLE_EVENT_GASCHANGE
events.  It will all *work*, but since subsurface will take either,
you'll then get duplicate gas mix events.

It's not like that is in any way fatal, but it might be a bit confusing.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-01-16 17:45:00 -08:00
Anton Lundin
983561b353 ostctools_import: Switch to using dc_parser_new2
Instead of creating the individual parsers, and keeping track of their
arguments, this just uses the "new" dc_parser_new2 function ment for
buffer parsing.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2017-01-12 14:15:53 -08:00
Anton Lundin
70e2404492 Stop accessing the internals of dc_descriptor_t
This removes our own declaration of dc_descriptor_t and all our accesses
to its internals, and switches to use the libdivecomputer functions to
access those instead.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2017-01-12 14:15:53 -08:00
Anton Lundin
00629c861c Rename ostc_get_data_descriptor to get_descriptor
This renames and cleans up ostc_get_data_descriptor into get_descriptor,
for more generic use.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-12-28 22:40:18 -08:00
Anton Lundin
db8e786f85 Lift ostc_get_data_descriptor out from ostctools.c
This is for later reuse of that function in other source files.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-12-28 22:40:18 -08:00
Dirk Hohndel
78dc3a3efe Revert "Add a simple cp2130 libusb driver"
This reverts commit 93ef223a31.
2016-09-22 14:56:31 -07:00
Dirk Hohndel
c809a8873c Second attempt to fix crash
Linus pointed out that it might be another call site (and looking at his
proposed patch I noticed a logic error in my earlier attempt)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-20 09:26:35 -07:00
Dirk Hohndel
076d8966f0 Prevent possible NULL pointer dereference
Not sure if this will fix the crash for Henrik, but it's worth
a try.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-20 08:47:08 -07:00
Anton Lundin
93ef223a31 Add a simple cp2130 libusb driver
This adds a simple cp2130 userspace driver. Its probably unusable in the
real world but its a great base to build upon.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-18 07:12:16 -07:00
Anton Lundin
ffa3c48593 Rewrite libdivecomputer custom serial code
This rewrites the custom serial code to use the new api which I
implemented in the Subsurface-branch of libdivecomputer.

This is a bit to big patch but I haven't had the time to break it down
into more sensible patches.

This rewrite enables us to support more ftdi based divecomputer
communication and is tested with both a OSTC3, OSTC2N and a Suunto
Vyper, all over the libftdi driver.

The bluetooth code paths are tested to, and should work as before.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-17 15:47:37 -07:00
Linus Torvalds
5a66ac7698 Make sure DC_FIELD_TANK starts from a clean slate for each cylinder
We used to clear the 'dc_tank_t' for each dive, but then only clear the
volume field in between each cylinder.  That means that if the
libdivecomputer back-end does not touch a field, it might contain the
stale value from the previous tank information.

I'm not sure this is actually much of an issue, since I'd expect
back-ends do seem to initialize the fields fully (at least the EON Steel
back-end does).  But it's inconsistent.

Also, the code was actually buggy because of the odd indentation: it
would only ask for new tank information up to 'ntanks' tanks, but
because of the final fixup that was done outside of the conditional, it
would actually update the cylinder begin/end pressure data *beyond*
'ntanks', and just re-use the last libdivecomputer data for the rest of
the cylinders.

Again, in practice, that probably never really happened, but it is a
real bug.

The fixed-up code actually looks better too, imho, and is one line
shorter because of the initialization now being done in one place rather
than two.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-08-29 21:43:17 -07:00
Linus Torvalds
99d1cecf06 Hacky workaround for multiple gas pressures per sample
In subsurface, we only have one cylinder pressure per sample (well,
technically two: we have a separate o2 pressure for rebreather diving).

Which makes things "interesting" if the dive computer can actually have
multiple pressure sensors, and can report them all concurrently.  Like
the Suunto EON Steel.

We used to just take the last one (each sensor reading would just
overwrite any previous ones), and this quick hack just changes the logic
to prefer the "current" cylinder instead.

It's wrong, and it's stupid, but it's the best we can do without major
surgery.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-08-29 21:43:14 -07:00
Linus Torvalds
a0aaadd50b Add support for SAMPLE_EVENT_STRING event type
Instead of having fixed numbers and trying to translate them into
strings, a dive computer could just give us the string directly.  Like
the new EON Steel backend does.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-21 20:00:04 +09:00
Linus Torvalds
b2f2a865eb Get the cylinder use data from libdivecomputer if provided
This uses the extended tank type information to fill in the cylinder use
(OC gas, CC Diluent or CC O2) from libdivecomputer when available.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-21 20:00:04 +09:00
Dirk Hohndel
cb20da7de3 Avoid unused argument warnings
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-06-20 18:44:16 -07:00
Linus Torvalds
d918289a04 Preferentially use existing device ID when setting serial number
We have two different models for setting the deviceid associated with a
dive computer: either take the value from the libdivecomputer 'devinfo'
field (from the DC_EVENT_DEVINFO event), or generate the device ID by
just hashing the serial number string.

The one thing we do *not* want to have, is to use both methods, so that
the same device generates different device IDs.  Because then we'll
think we have two different dive computers even though they are one and
the same.

Usually, this is not an issue, because libdivecomputer either sends the
DEVINFO event or gives us the serial number string, and we'll always
just pick one or the other.

However, in the case of at least the Suunto EON Steel, I intentionally
did *not* send the DC_EVENT_DEVINFO event, because it gives no useful
information.  We used the serial number string to generate a device ID,
and everything was fine.

However, in commit d40cdb4755ee ("Add the devinfo event") in the
libdivecomputer tree, Jeff started generating those DC_EVENT_DEVINFO
events for the EON Steel too, and suddenly subsurface would start using
a device ID based on that instead.

The situation is inherently ambiguous - for the EON Steel, we want to
use the hash of the serial number (because that is what we've
historically done), but other dive computers might want to use the
DEVINFO data (because that is what _those_ backends have historically
done, even if they might also implement the new serial string model).

This commit makes subsurface resolve this ambiguity by simply preferring
whatever previous device ID it has associated with that particular
serial number string.  If you have no previous device IDs, it doesn't
matter which one you pick.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-06-20 18:39:21 -07:00
Linus Torvalds
7bbd8cc974 Don't ignore surface events from libdivecomputer
There are cases where we actually want to keep them, as exemplified by
this situation from Richard Yorke:

  "I have just come across a situation when ignoring the surface marker
   is a disadvantage.  I have just had a problem with my BC feed
   seeping, slowly filling my BC and as I control my buoyancy on the
   bottom using the air in my drysuit, I did not notice, so that when I
   came to ascend the expanding air in my BC caused a loss of control.

   Fortunately not from a great depth and no untoward consequences.
   However, the Subsurface profile only shows me rising to 4m and
   descending to 5.5m for my safety stop.  However I actually broke the
   surface and descented to 5.5 but the frequency of recording depth was
   not fast enough to show this as it was so brief"

so remove the code that ignores the surface events entirely.

I think we'll have to come up with some smarter filtering model for
showing them, but that is predicated on getting these events to come
through in the first place.

Reported-by: Richard Yorke <yorke.richard@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-05-31 10:16:20 -07:00
Dirk Hohndel
7be962bfc2 Move subsurface-core to core and qt-mobile to mobile-widgets
Having subsurface-core as a directory name really messes with
autocomplete and is obviously redundant. Simmilarly, qt-mobile caused an
autocomplete conflict and also was inconsistent with the desktop-widget
name for the directory containing the "other" UI.

And while cleaning up the resulting change in the path name for include
files, I decided to clean up those even more to make them consistent
overall.

This could have been handled in more commits, but since this requires a
make clean before the build, it seemed more sensible to do it all in one.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04 22:33:58 -07:00
Renamed from subsurface-core/libdivecomputer.c (Browse further)