Commit graph

415 commits

Author SHA1 Message Date
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
Dirk Hohndel
65f6db6e2c Don't warn about missing en-US translation for Qt
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-03 13:29:25 -07:00
Dirk Hohndel
0482f054a7 QML UI: add more dive computers
This really needs to be done differently - we need a structured way
to associate a transport mechanism with each of the dive computers
we support.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-02 21:57:08 -07:00
Dirk Hohndel
7199ad33e2 BT discovery: detect Scubapro G2
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-02 18:32:16 -07:00
Dirk Hohndel
61fff71391 Android: mark BLE only paired devices
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-30 13:13:38 -07:00
Dirk Hohndel
c145cbd754 QML UI: save BT address as string
And do the same LE: prefix marking as in the desktop version.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-30 13:12:53 -07:00
Dirk Hohndel
6837120bb1 BLE handling: create helper function to add the LE: prefix
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-30 13:12:07 -07:00
Dirk Hohndel
344b9e3234 Fix one call site that hadn't been updated
When updating to the new dc_custom_io_t, this one spot had been
missed.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-27 21:24:00 -07:00
Dirk Hohndel
ea8e3006db Whitespace
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-27 20:53:21 -07:00
Dirk Hohndel
f98fa50c39 BLE code: address some compiler warnings
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-27 20:53:11 -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
526595644f Use SSRF_CUSTOM_IO v2 to implement device data quirks for BLE GATT
Right now we have a quirk for Shearwater devices to set the random
address flag, but also to handle the differences at read/write time.

With this, I can finally download from both the Suunto EON Steel and the
Shearwater Perdix AI with the same binary.

It's not *pretty*, but it works.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-27 15:14:27 -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
Alex Blasche
e79bede0aa Use QLowEnergyController without QEventLoop
We rather use wait in combination with spinning the event loop.

Signed-off-by: Alex Blasche <alexander.blasche@qt.io>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-27 11:03:19 -07:00
Alex Blasche
57753321b0 Ensure all found BLE services are tracked
If a device has more than one service the order of service discovery
determined the selection of the service that we intend to interact
with. This assumption is not accurate and is even platform dependent.

Thinking ahead, it is likely that some devices may require us to keep
track and interact with multiple services at the time.

The new logic still suffers from the fact that there is no way
to select the correct service for interaction. This will require
higher level stack changes.

Signed-off-by: Alex Blasche <alexander.blasche@qt.io>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-27 11:03:19 -07:00
Alex Blasche
81dabe5ace Fix incorrect uuid check due to temporary char* in QString::toUtf8()
toUtf8() creates a temporary char* representation which is assigned to
uuid. As soon the object created by toUtf8() gets destroyed, the uuid
pointer points to releases memory.

The intention is to check that we don't have one of the standard
16bit Bluetooth uuids. That's the purpose of QBluetoothUuid::toUInt16().

Signed-off-by: Alex Blasche <alexander.blasche@qt.io>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-27 11:03:19 -07:00
Linus Torvalds
4f3a9cdb35 BT serial: recognize LE-only devices, and fall back to emulated serial
This is somewhat hacky, but it allows at least the Shearwater
libdivecomputer backend to continue to treat even the BLE GATT model as
just a serial protocol.

What it does is create a special "emulate serial behavior over the
packetized BLE protocol" helper layer, that qtserialbluetooth falls back
on when rfcomm is not available.

NOTE! This still requires some BLE packet code changes to work with the
odd way that Shearwater sets up their BLE GATT communication.  So note
that no further patches are necessary to *libdivecomputer*, but some
updates are needed for the subsurface qt-ble.cpp code.

I have those updates in my tree, and this code is all tested on my
Perdix AI, but those patches are currently too ugly to commit as-is.
I've cleaned up this "fake serial" code sufficiently, that cleanup comes
next.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-26 22:21:14 -07:00
Linus Torvalds
d0c3ef4cf8 Bluetooth: make LE-only devices add "LE:" as an address prefix
This seems a bit odd, but it actually has three different reasons for it:

 - It's a visual indication of BT LE mode for users

 - the rfcomm code only works with legacy BT support, and if we scan a
   device that only does LE, we want the custom serial code to instead
   automatically fall back on a "emulate serial over LE packets" model.

 - we want rfcomm to remain the default for devices that do both legacy
   BT _and_ LE, but we want people to have the ability to override the
   choice manually.  They can now do so by just editing the address
   field and adding the "LE:" prefix manually, and it automatically gets
   saved for next time.

So while a bit hacky, it's actually a very convenient model that not
only works automatically, but allows the manual override.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-26 22:20:01 -07:00
Dirk Hohndel
f5e1df0423 Add the EON Steel as support DC on Android
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-24 22:32:56 -07:00
Dirk Hohndel
6f1590b098 BLE support: convert fprintf(stderr,...) to qDebug()
This way the output can be seen in the AppLog on Android.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-24 22:32:47 -07:00
Dirk Hohndel
63fc06e728 BLE support: add SPDX headers
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-24 22:32:01 -07:00
Linus Torvalds
196adb591b Very early and likely quite broken BLE GATT code
This is some very early and hacky code to be able to access BLE-enabled
dive computers that use the GATT protocol to send packets back and forth
(which seems to be pretty much all of them: a vendor-specific GATT
service with a write characteristic and a notification characteristic
for reading).

For testing only.  But it does successfully let me download dives from
my EON Steel and my Scubapro G2.

NOTE! There are several very hacky pieces in here, including just
"knowing" that the write characteristic is the first one, and the
notification characteristic is second.  The code should actually check
the properties rather than have those kinds of hardcoded assumptions.

It also checks "vendor specific" by looking at the UUID string
representation, and knowing that the standard ones start with zero.
Crazily, there doesn't seem to be any normal way to test for this,
although I guess that maybe the uuid.minimumSize() function could be
used.

There are other nasty corners. Don't complain, send me patches.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-24 21:58:01 -07:00
Dirk Hohndel
d93280f1dc QML UI: DiveList: add date box to trip header
This way you can tell when a trip happened.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-24 13:13:04 -07:00
Stefan Fuchs
b109b51f7f Translate "more than n days" for surface interval
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-06-23 22:43:39 +09: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
Dirk Hohndel
d58de37167 Merge branch 'master' of git://github.com/torvalds/subsurface-for-dirk 2017-06-22 17:41:21 -07:00
Jan Mulder
eb8e3de6da Typo of translated string
Trivial typo.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-06-23 07:55:58 +09: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
1d2bcffbdf Use plural form for cloud connection wait
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-22 04:19:23 -07:00
Dirk Hohndel
ba2b5d8505 Add en_US translation for plurals
This way in the en_US locale we no longer get shown the odd "dive(s)"
and instead get correct singular and plural forms.

Most of the patch is just a reindentation as it removes the if clause
that used to do the special case of NOT loading a translation for the
en_US case.

Right now we start with a trivial en_US translation file. My guess is
that this will be overwritten once we do the next round of "new strings,
new translations".

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-22 04:19:23 -07:00
Dirk Hohndel
6e785a7bfc QML UI: correctly build plural translation
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-22 04:19:23 -07:00
Jan Mulder
ac750bbf20 mobile: prune DC list to download from
Currently, only a small number of dive computers can be downloaded from
the mobile app. Only present the supported ones to the user. So, currently
restricted to classic BT. Not sure about FTDI support at this point.

Version 2 of the same commit after review from Dirk. Fundamentally,
support is as follows: Android: BT, BLE, and FTDI. iOS: BLE only. For
all other OSses, this commit has no changes. As the BLE backend is
not yet ready, no support on iOS yet.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-06-22 20:19:06 +09:00
Robert C. Helling
5f5e52fb46 Preserve VPM-B state in profile display
This fixes a but reported by Willem in the display of VPMB
ceilings for logged dives.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-06-22 10:39:37 +09:00
Dirk Hohndel
8bee7e6172 QML UI: use the short date format
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-18 17:48:04 -07:00
Dirk Hohndel
2b01ab7d50 Clean up git storage update messages
Translate all of them, but also remove some redundant or possibly
misleading messages. These are now seen by users, not just developers
trying to debug the code.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-18 01:00:30 -07:00
Dirk Hohndel
b2b51c833a QML UI: redesign the user notification
The old system of cloud access updates with fake percentages just wasn't
helpful. Even worse, it hid a lot important information from the user.
This should be more useful (but it will require that we localize the
messages sent from the git progress notifications and make them more
'user ready').

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-17 23:22:37 -07:00
Dirk Hohndel
2d5f023b58 Set default cloud timeout to ten seconds for mobile app
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-17 22:56:08 -07:00
Lubomir I. Ivanov
27deb317b0 tankinfomodel.cpp: clamp row index to [0 - MAX_TANK_INFO]
MAX_TANK_INFO is a new macro in dive.h to define the
maximum number of tank_info_t objects.

TankInfoModel's data() and setData() now check for valid
row indexes before accessing the tank_info[] array directly.

Without this patch TankInfoMode::data() can cause a SIGSEGV.

Reported-by: Pedro Neves <nevesdiver@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-15 14:48:49 -07:00
Robert Bodily
85021b94b1 Fix buffer overrun and primary sensor id issues in Liquivision import
This changeset fixes 5 issues specific to importing from Liquivision dive logs:

Issue #1: Buffer overrun causes segmentation fault.
At the end of a dive record, untranslatable data is skipped and the file is
scanned for the start of the next dive.  This scan was implemented without
regard to buffer size and so the scan ran over the buffer boundary when trying
to scan for the next record after importing the last record in the file.

Issue #2: Incorrect identification of the primary sensor.
The primary tank pressure transmitter was being identified by using the sensor
ID reported in the first pressure event record encountered.  When diving with
multiple transmitters (buddy, student, or group transmitters), this is often
not the case and results in the buddy or other group transmitter's pressure
data being imported instead of the primary's.

Through empirical observation of several multi-sensor logs, I identified a
previously unhandled event code (0x10) as marking a sensor identification
event record.  Parsing this record allows the primary and other sensors
to be definitively identified regardless of which one sends the first pressure
event.

Issue #3: Sensor values added to the sample collection regardless of sensor ID.
When processing events, the code previously dropped through to create a sample
for every pressure event record, regardless of which sensor ID that event is
associated with.  Pressure events for sensors other than the primary are now
ignored and omitted from the sample collection.

Issue #4: Duplicate samples when pressure event time syncs with sample time.
The sample index (d) was not incremented in this specific case resulting in
a duplicate sample (for the same sample time) being created when processing
the next pressure event record.

Issue #5: Unsigned time difference results in erroneous interpolated samples.
When interpolating/extrapolating depth and temperature values for a between-
samples pressure event, a signed time value is subtracted from an unsigned time
value, resulting in an unsigned term.  This term is used as a scaling factor
and should be signed to allow for a negative value.  Currently, negative values
are instead treated as large unsigned values which result in erroneous scaled
depth and temperature values.

Signed-off-by: Robert Bodily <robert@bodily.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-15 14:44:18 -07:00
Jan Mulder
db39f1a847 code cleanup: remove 2 unused structs
Luckily these 2 structs in this ugly code are not used. Remove them.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-06-16 05:31:41 +09:00
Miika Turkia
ec40a25007 Parse He when importing from DM5
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-06-13 18:11:22 +09:00
Jan Mulder
8cd711f8e2 BT Discovery: add Shearwater Petrel and Perdix
Add Shearwater Petrel and Perdix to automatic detection

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-06-12 19:12:40 -07:00