Commit graph

456 commits

Author SHA1 Message Date
Linus Torvalds
92ecbc8c83 parse-xml: use the right dc for filling in extra data
"cur_dc" may be NULL when the XML source isn't a subsurface XML file,
and xml parsing is supposed to use "get_dc()" to pick a dive computer
when the nesting of the XML may not be proper.

Now, XML sources that don't have the proper dive computer nesting
markers generally also do not end up having the extra-data string
information, but one example of this is the simple XML that the
libdivecomputer 'dctool' program generates.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-22 10:38:11 -07:00
Linus Torvalds
b9f52d0aff Gas usage statistics: don't require gas switch events
Our "get_has_used()" helper only filled in gas usage for cylinders that
had a gas change event associated with them.  That works really badly
for things like CCR, but also simply for cases where the dive computer
wasn't necessarily explicitly notified about usage, like sidemount
diving etc.

Just remove the logic.  If some use ends up particularly wanting to
ignore some cylinder, they can always do it in the caller instead.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-22 10:38:00 -07:00
Linus Torvalds
f2a6a76b3e Fix up o2 pressure sensor handling at load time
Because of how we traditionally did things, the "o2pressure" parsing
depends on implicitly setting the sensor index to the last cylinder that
was marked as being used for oxygen.

We also always defaulted the primary sensor (which is used for the
diluent tank for CCR) to cylinder 0, but that doesn't work when the
oxygen tank is cylinder 0.

This gets that right at file loading time, and unifies the xml and git
sample parsing to make them match. The new defaults are:

 - unless anything else is explicitly specified, the primary sensor is
   associated with the first tank, and the secondary sensor is
   associated with the second tank

 - if we're a CCR dive, and have an explicit oxygen tank, we associate
   the secondary sensor with that oxygen cylinder.  The primary sensor
   will be switched over to the second cylinder if the oxygen cylinder
   is the first one.

   This may sound backwards, but matches our traditional behavior where
   the O2 pressure was the secondary pressure.

This is definitely not pretty, but it gets our historical files working
right, and is at least reasonably sensible.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 16:34:33 -07:00
Linus Torvalds
ea31800f61 git save format: don't save redundant sample information
When we load sample data from a git save-file, we always default to
using the state from the previous sample (except for the special case of
cylinder pressure where an empty value does not mean "same", but
"interpolate", see core/load-git.c: new_sample()).

But the corollary to that is that it's always redundant to save sample
data that hasn't changed since the previous sample.

For some reason, the rbt, bearing and heartrate sample data didn't
follow that rule, and instead saved with lots of extra reduncancy.

(The alternative would be to clear those samples at load time, and make
them act like the pressure data, but it would appear that all these
three values may as well just have the normal "if no change, don't save
them" semantics).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 16:33:45 -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
94d8abd1a2 Correct list of Shearwater BLE dive computers
Some Petrel 2 computers are dual stack. We need to list the Petrel here as well
since the Petrel 2 actually identifies itself via BT/BLE as Petrel and we can't
tell them appart until after we started a download.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-19 06:21:23 -07:00
Dirk Hohndel
08c2f5492a BLE on iOS: use uuid instead of BT address
iOS doesn't give us an address of BT devices.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-19 06:21:23 -07:00
Dirk Hohndel
0e865ef4e7 Move variable into the code block it is used in
Avoids an "unused variable" warning.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-19 06:21:23 -07:00
Dirk Hohndel
a38d440d5e BLE discovery: give the agent some time
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-19 06:21:23 -07:00
Dirk Hohndel
526da269cc iOS BLE support: no localBtDevice, go straight to discovery
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-19 06:21:23 -07:00
Dirk Hohndel
7cc34aec9d iOS build: need to more includes
It's kinda odd this builds fine on other OSs, but whatever.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-19 06:21:23 -07:00
Dirk Hohndel
e23ae817c7 BLE dive computers: add Perdix
This is both correct (many Perdix support BLE) and necessary
as the Perdix AI identifies itself (sadly) as Perdix.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-19 06:21:23 -07:00
Jan Mulder
883063875e BLE serial read/write buffer
The adapted define was confusingly wrong. Apparently, the BUFSIZ
define was coming from some include file, and was dependent on
platform (Linux 8K, Andorid 1K). Simple rewrite to a new define
and a proper value for both Linux and Android. If 4K is big
enhough, is a little uncertain, as its depends on the read
behavior of all libdivecomputer parsers using this serial
BLE interface.

The buffer size needed (on read, as that is the most prominent
direction when interfacing with DCs) is (most likely) 2x the
maximum block the libdc parsers request at once. I did not
study all parsers, but the Shearwater parser request 20 bytes
at once (we know that from the 1 packet at the time read, we
had before). The OSTC parser request 1K blocks for data
that is longer than 1K (like profiles, header tables).

The 1K we had on Android was working for Shearwater,
Eon Steel, but not for OSTC,as its reads 1K at the time
at max, and overflowing the buffer.

So 32k or 64k seems way to big (as in, much bigger than
any libdc read).

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-19 11:12:35 +09:00
Dirk Hohndel
8f0621f733 QML UI: correctly match BT names with products
And remove the remaining references to the "Paired Bluetooth
Devices".

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-18 00:49:31 -07:00
Dirk Hohndel
025efc12d4 QML UI: remove the Paired Bluetooth Devices virtual vendor
We now actually handle connections in a sane manner and don't need
that workaround anymore.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-18 00:49:31 -07:00
Dirk Hohndel
cec3c256e7 Add detection of the Shearwater Predator via BT
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-18 00:49:31 -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
a4f045abaa Add the connections that we find to the model
So far this only deals with BT addresses. We also need to add other
connections that we detect.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-16 21:53:44 -07:00
Dirk Hohndel
c21845aa01 Add ConnectionListModel
We'll use that to do a better job of showing the connection used when
talking to a dive computer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-16 21:53:44 -07:00
Jan Mulder
9397dbb432 Correct BT detect for OSTC Sport
Apparently, OSTC Sport has a BT name like OSTCs<space><serial>.

Small code addition to detect this properly. As long as we
do not have an improved way of detection. Notice that most of
the HWs use the same BT hardware, so simple detection on offered
services will not work.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-15 14:43:13 +09:00
Dirk Hohndel
bec5f3c44f BT support: track if Bluetooth is available
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-12 04:13:25 -07:00
Jan Mulder
fbaaa64a4a Trivial code cleanup
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-11 17:11:49 +02:00
Jan Mulder
8911281593 OSTC over BLE: read a long as needed
See also b409e9fc91 and 709c1df2af. The OSTC parser
cannot handle reads of single 20 byte BLE packages in serial mode.
Instead of doing a deeper down agressive read, we can read on
the serial level more subtile. As the parser is requesting a
specific number of bytes, we just read that number of bytes and
return them. As the 20 byte BLE packets do (obviously) not
align with the reading requirement of the libdc parser, a little
housekeeing needs to be done in between individual reads.

CAVEAT 1: In contradiction to 709c1df2af, this is supposed to
work for all parsers that properly specify the needed bytes to fetch.

CAVEAT 2: All above tested on Linux Desktop with bluez stack.
Subsurface mobile is step 2.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-11 13:41:21 +02:00
Jan Mulder
b409e9fc91 BLE read: remove aggressive read
Commit 709c1df2af introduced a hard blocking read for BLE devices.
This did break BLE reads from multiple DCs, and (in hindsight) was not
a correct implementation. It would require, for example, dynamic
read buffers as especially profile data grows with dive time, and
in addition, and more importantly, also the OSTC libdc parser cannot
process the entire profile of a dive at once (but likes to receive
it in 1K blocks). So, basically, it introduced issues, and did not
solve the OSTC read.

This commit reverts this hard blocking read (and as such will break
OSTC BLE reads). But it enables removal of the special cases for
the EON Steel and G2.

A next commit will solve OSTC BLE reads.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-11 13:29:41 +02:00
Jan Mulder
b7057c414f OSTC over BLE: take care of credits
Handle credits. Do not just ask for maximum credits all the time as this
will stop the download. Also do not let the credits go back to 0 (while
this might work, this is not tested). Getting back the 0 credits stops
the download, and even when it can be restarted, it is less efficient
(and not needed). Notice also that it takes some time before a grant
request is honoured. During testing I saw reception of up to 25 packets
between request and grant. So a lower bound for the request of
32 packets seems resonable.

One aspect the Telit/Stollmann TIO puzzeled me. Sections 4.1 and 4.2
both talk about credits, but my hyphothesis is that there are two
credits counters in play. One for traffic either way. This commit
only deals with credits granted by Subsurface to the OSTC to send
data. Credits granted by the OSTC to allow Subsurface to send new
commands is NOT part of this commit, and is seemingly not needed
in our scenario. As we only send new commands to the OSTC when
a previous one is finished (per HW's interface spec), the OSTC
does not run out of credits to receive commands.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-11 13:17:00 +02: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
55df597994 BLE support: the G2 wants packages one at a time
Just like the EON Steel it doesn't want us to loop until all packages
have been received.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-09 11:57:32 -07:00
Dirk Hohndel
52d5172a70 Automate picking supported DCs on iOS and Android
We use a little script to create the code snippet. This script in return
relies on comments that were added to the latest libdivecomputer source
(in the Subsurface-branch).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-08 16:06:12 -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
4834f51a73 BLE: reduce the noise of debug output
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-06 09:35:04 -07:00
Dirk Hohndel
a8468caaa2 BLE: minor code cleanup
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-06 01:37:21 -07:00
Alex Blasche
bf3cc2f64b Make compile with Qt developer builds
subsurface/core/divesitehelpers.cpp: In member function 'virtual void ReverseGeoLookupThread::run()':
subsurface/core/divesitehelpers.cpp:128:12: error: invalid use of incomplete type 'class QDebug'
     qDebug() << "no reverse geo lookup; geonames returned\n" << fullReply;
            ^

Signed-off-by: Alex Blasche <alexander.blasche@qt.io>
2017-07-06 12:43:42 +09:00
Dirk Hohndel
a4bb61b58a BLE download: EON Steel doesn't want to loop over reads
This seems a bit brutal, but it does the trick and makes EON Steel
downloads work again.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-04 09:30:05 -07:00
Dirk Hohndel
8a1f5b9566 BLE: write confirmation isn't HW only
Happens on the Suunto EON Steel as well.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-04 09:29:31 -07:00
Jan Mulder
3cde4f594d Address code review
Addresses code review by Dirk. No functional changes.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-04 23:46:07 +09:00
Jan Mulder
709c1df2af BLE: read until no more data in coming in
The current BLE read reads just one 20 bype packet. That packet size is set
in ble_serial_ops, so, without being able to test on anything other than
a OSTC3, I assume that this holds for other BLE DCs too. So, I think is
is weird that those interfaces work with the current read() of just one
packet at the time.

As we need a blocking read (at least for the OSTC parser), just read all
data that is available on the input. And when we think we are done, give
the QtEventloop control to see if there is more, and process that incoming
data as well. All this basically implements a blocking read.

CAVEAT 1: This might break the reading from the currently working BLE devices.

CAVEAT 2: With this, I still cannot read the OSTC3 completely. For
developers familiar with the HW transfer protocol: it just stops while
reading the first full dive (header + profile) command 0x66, despite
correctly reading about 5Kb of data before. For some
reason, I do not believe that this is related to this commit.

CAVEAT 3: All above tested on Linux Desktop with bluez stack, and
confirmed NOT to work on Android 7.1.2, build with Qt 5.9.0, And
yes, I know 5.9.1 recommended.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-04 23:46:07 +09:00
Jan Mulder
d6b17fef08 OSTC over BLE: filter and track OSTC credit traffic
1) As the OSTC sends data to the BLE central role (the SSRF client) over 2
characteristics, we have to filter the administrative credit data from
the actual dive data that it received. The characteristcStateChanged
function is adapted for this.

2) We have to be sure that the Terminal Client I/O is fully defined during
opening the connecton to the OSTC. From 6d505b24f0c15 we can see
that the last step in setting up the terminal interface is the grant
of credits. This is done by writing to the proper (the only one, with
id = 0x2902) descriptor of the credits RX characteristic. The here
added slot is triggered on the completion of write of credits marking
the final stage of the setup.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-04 23:46:07 +09:00
Jan Mulder
6031692a39 Use waitFor instead of timer
See e79bede0aa. We rather use wait in combination
with spinning the event loop.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-04 23:46:07 +09:00
Jan Mulder
f6768cedf3 OSTC over BLE: Select the right service
The current "select the correct BLE service to talk to" is flawed.
It assumes that the first found non-standard UUID is the right one
and apparently it is for some DCs. But not for the HW devices.
The HW devices use a "standard" ie. approved by the Bluetooth
SIG, controller, that comes with a UUID that our code currently
considers standard so not to be the right one.

This (simple) commit selects the right service for HW. The UUID
is hard coded, and this is ok, because it is tied to the hardware
used by HW. Futher, it does not change anything for other BLE
devices.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-04 23:46:07 +09:00
Jan Mulder
6fe0388b96 OSTC over BLE: initialize Terminal I/O client
This initalizes the Terminal I/O client as described in paragraph 3 of
http://www.telit.com/fileadmin/user_upload/products/Downloads/sr-rf/BlueMod/TIO_Implementation_Guide_r04.pdf

This is for all Heinrichs Weikamp computers, that use referenced BT/BLE hardware
module from Telit Wireless Solutions (Formerly Stollmann E+V GmbH). The 16 bit
UUID 0xFEFB (or a derived 128 bit UUID starting with 0x0000FEFB is a
clear indication that the OSTC is equipped with this BT/BLE hardware.
Furthermore, most devices equipped with this BT/BLE hardware have BT addresses
starting with 00:80:25:...

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-04 23:46:07 +09:00
Dirk Hohndel
bc1a313c9f Increase the BLE timeout to 12 seconds
This seems really long, but one user appeared to get a response after
almost 10 seconds. So going with 12 for some margin of error.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-03 22:22:16 -07:00
Dirk Hohndel
345e063eb5 Rewrite the matching code for BT devices
This should be much more robust in getting us the correct Bluetooth address
and the correct vendor / product for our selection.

When we pick a paired device, we extract the address right from its name.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-03 21:58:26 -07:00
Dirk Hohndel
bc864c3bce Don't add all discovered BT devices
This really doesn't help us as we can't associate a vendor/product with
devices we don't recognize, so we can't download from them, anyway.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-03 21:58:26 -07:00
Robert C. Helling
d17bb6318e Don't try to dereference empty product/vendor list
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-07-04 07:06:20 +09:00
Jan Mulder
d7b8ad7a44 BT discovery Android: Allow BT/LE devices connect both ways
For DCs that support both BT and LE, allow the user to connect to both
interface layers. Maybe not usefull in the end (as BT is faster
than LE), but as long as BT on Android is WIP is it very useful
to be able to connect to the interface layer we like.

Just add it to the Paired Devices list twice. The normal way, and
the LE: prepend way.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-07-04 05:49:52 +09:00