Commit graph

2241 commits

Author SHA1 Message Date
Dirk Hohndel
780cb4fce7 core/bluetooth: only Linux / Windows are supported by libdc rfcomm
For Android the Qt Bluetooth code seems to work just fine. And for macOS
nothing appears to work right now, but at least the Qt implementation compiles
and links.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-19 19:26:56 -07:00
Linus Torvalds
e1befbea0a core/bluetooth: switch to use libdivecomputer rfcomm support
The Qt based implementation apparently got broken at some point and now fails
to connect to rfcomm dive computers like the Shearwater Petrel.

This uses the libdivecomputer rfcomm backend. Tested to work with bluez on
Linux as well as with the native Windows implementation.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-19 19:26:26 -07:00
Miika Turkia
db6acfdd27 Update Shearwater sample time calculation
At least Shearwater Cloud seems to use multiple formats for sample time
recorded in the database. Sometimes the time is in seconds, sometimes in
milliseconds, and sometime it is something I have no idea about. Thus
switching to calculating the sample id myself and using sample interval
to calculate the actual sample time. Seems to be more reliable than
trying to guess what format Shearwater is using for this specific dive.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-19 11:20:27 -07:00
Berthold Stoeger
75be59c76d media: read timestamp from mvhd header of MP4/QuickTime videos
ExifTools (and probably other meta-data editors) modifies the
mvhd creation date, but leaves the individual creation dates
in the tracks unchanged. Therefore, use the mvhd atom.

Reported-by: Eric Tanguy <erictanguy2@orange.fr>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-19 11:11:16 -07:00
Linus Torvalds
aa95a9a744 Extend BLE uuid matching to the characteristics, add ignore-list
This extends the uuid matching to the low-level characteristics too, so
that we can ignore the McLean Extreme characteristics that aren't
interesting.

It also renames the uuid matching to be about a "uuid_list" rather than
being about the service we're matching, since we're now using it for
other uuid's than just services.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-09-17 07:54:35 -07:00
Linus Torvalds
981c1cb1d3 Fix 'uud' typo in BLE uuid matching code
Silly typo with a missing 'i' in 'uuid' that happened when I wrote this
code originally, and that compiled fine thanks to the error being
duplicated with cut-and-paste to all relevant places.

Fix it now, since I'll extend the uuid matching to the actual
characteristics for the McLean Extreme.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-09-17 07:54:35 -07:00
Dirk Hohndel
ff14ca4dd5 translations: use the right Qt translations (part 2)
It turns out that contrary to what the documentation states, a few languages
are still only using the 'qt' translation. But those exist for all languages,
so we need to first search for the 'qtbase' translations, and only if that
fails do we try to load the 'qt' translations.

And even that will fail for languages in which Qt simply isn't localized (like
Dutch).

To make the code more readable, the check for 'US English' was moved earlier as
there is no point to look for a Qt translation for that (simply doesn't exist).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-15 11:54:36 -07:00
Dirk Hohndel
1ed8cb373f translations: use the right Qt translations and try harder to find them
We were still using the 'qt' translations instead of 'qtbase' as we should have
been using since forever - it's a little unclear from reading the documentation
when in the Qt5 life cycle this happened, but definitely several years ago.
These are the strings used in situations where Qt already provides us with text
(e.g., the entries in the 'Subsurface' menu on Mac, or the button labels in
many dialogs).

Additionally we didn't try hard enough to find those translations in cases
where they are bundled with the app; so basically all scenarios except for
Linux distro specific packages or 'build from source' on macOS or Linux were
not going to work, even after addressing the qt->qtbase conversion.

But of course the developers pretty much all fall into those last two
categories. Still, I cannot believe we never fixed this in all those years...

To make it more obvious if we still aren't finding the Qt translations this
commit also makes that warning be shown in all cases, not just when running in
verbose mode.

Fixes #2954

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-15 10:50:28 -07:00
Miika Turkia
a7bed157b5 Grab the first gas on Shearwater import
The logic to retrieve gas changes from Shearwater cloud database is
detecting only when the O2/He chnages. This change will grab the initial
gas. (Problem was only shown when there was a gas changee in the log, so
cingle cylinder dives were working fine.)

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-15 08:47:51 -07:00
Miika Turkia
23efcef58a Fix a bug on Shearwater cloud gas changes
Gas change is done to the cylinder we just found and not the last
cylinder. Also switching the variable name to index as we are actually
using that value outside the loop.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-15 08:47:51 -07:00
Miika Turkia
b5c00c89e6 Import cylinder pressure correctly
Shearwater apparently stores correct pressures nowadays, so getting rid
of a hack to import double pressures.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-15 08:47:51 -07:00
Miika Turkia
dee2b510bb Ignore gas changes if we one line contains bogus O2
This will ignore the gas changes that would be caused by Shearwater
cloud saving rows with 0 values in them.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-15 08:47:51 -07:00
Miika Turkia
b8b67f239b New field for timestamp in shearwater cloud DB
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-15 08:47:51 -07:00
Miika Turkia
06e6bcecb7 Shearwater cloud import: ignore bogus rows
A sample log I received contains a lot of rows with 0 values in it. This
will ignore the obviously bogus ones. (However, we might miss the first
sample if that is recorded at time 0.)

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-15 08:47:51 -07:00
Berthold Stoeger
a01ab81713 cleanup: fold core/divecomputer.cpp into core/device.c
core/device.h was declaring a number of functions that were related
to divecomputers (dcs): creating a fake dc for manually entered dives
and registering / accessing dc nicknames. On could argue whether
these should be lumped together, but it is what it is.

However, part of that was implemented in C++/Qt code in a separate
core/divecomputer.cpp file. Some function therein where only
accessible to C++ and declared in core/divecomputer.h.

All in all, a big mess. Let's simply combine the files and
conditionally compile the C++-only functions depending on
the __cplusplus define.

Yes, that means turning device.c into device.cpp. A brave soul
might turn the C++/Qt code into C code if they whish later on.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-13 13:54:59 -07:00
Berthold Stoeger
fcdb48779b cleanup: remove unused declarations in class DiveComputerList
The functions matchDC() and matchModel() were never implemented.
Remove their declarations.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-13 13:54:59 -07:00
Berthold Stoeger
34286f328d cleanup: remove unused function DiveComputerNode::changesValues()
This was not used anywhere - let's remove it!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-13 13:54:59 -07:00
Berthold Stoeger
936cf453f9 cleanup: move set_dc_nickname() declaration from dive.h to device.h
The function *looks* like it is a dive function. However, in reality
it implicitly works on the global device list. Therefore, it is
thematically more aptly located in device.h with the other device
functions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-13 13:54:59 -07:00
Robert C. Helling
3426c6440c Disable SAC factor setting for CCR dives
The SAC factor is only used for minimal gas calculations which
don't make sense in the CCR context.

Additionally, make bailout stop for at least minimum switch
time or problem solving time.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-09-13 13:51:07 -07:00
Berthold Stoeger
6ea0cc62b8 desktop: refine auto-fill of weights
In a previous commit, auto-filling of weight based on type was
changed to be only performed if the user hadn't already set a
weight, by testing for weight=0.

However, when the user edited the type and tabbed back and forth,
that counted as an edit and therefore the weight would not
change anymore.

To refine this, introduce an "auto_filled" flag to the weightsystem,
which is set if the weight is automatically filled and cleared if
the weight is edited. Update the weight if it was zero *or* auto-filled.

The flag is not saved to disk, but that should be acceptable. If the
user saves and reloads, we can assume that they meant the weight
to be set to the default value.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-12 10:36:36 -07:00
Berthold Stoeger
bee2dea7cc cleanup: remove invalidate_dive_cache() call in clone_delete_divecomputer()
The function was called on a freshly copied dive, which has its git cache
invalidated automatically in copy_dive().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-08 17:20:09 -07:00
Berthold Stoeger
0a747608b1 cleanup: remove dead code from delete_divecomputer()
delete_divecomputer had legacy code, which
1) invalidated the git dive cache
2) made sure that the dive computer was not displayed anymore

However, both callers called on a freshly copied dive, which
has its dive cache invalidated in copy_dive() and can't be
the currently displayed dive. Therefore, this code is dead
code and can be removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-08 17:20:09 -07:00
Berthold Stoeger
048cdcaa31 cleanup: remove count_divecomputers() function
There is a number_of_computers() function which does
the same thing with two exceptions:
1) checks for null-dive
2) returns an unsigned int

Replace calls to count_divecomputers() by calls to number_of_computers().
In one case, the return type makes a different - add a cast to int there.
Ultimately, we should probably change the dc_number to signed int
throughout the code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-08 17:20:09 -07:00
Berthold Stoeger
83c56bc34c cleanup: make taxonomy_index_for_category() local to taxonomy.c
This helper function is not used outside taxonomy.c anymore.
Let's hide this implementation detail.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06 12:59:54 -07:00
Berthold Stoeger
ee2f466470 cleanup: use taxonomy_get_value() instead of taxonomy_get_index()
Instead of getting the index and using that to access values, use
the taxonomy_get_value() helper function. Two places are affected:
1) reverse geo-lookup
2) location filter delegate

The behavior of reverse geo-lookup is changed slightly: now an
empty string is likewise recognized as missing "TC_ADMIN_L3".
Before, only a missing category was interpreted as such.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06 12:59:54 -07:00
Berthold Stoeger
1f1fd78f78 cleanup: create taxonomy_get_value() function
This is the counter-part to taxonomy_set_value(). Let taxonomy_get_country() be the
first user of the function. If a category doesn't exist, return NULL.

Small addition: make taxonomy_get_countr() take a const argument.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06 12:59:54 -07:00
Berthold Stoeger
e5923a105a cleanup: use taxonomy_get_country() in get_dive_country()
get_dive_country() was essentially a reimplementation of taxonomy_get_country().
Let's just use the already existing function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06 12:59:54 -07:00
Berthold Stoeger
754b4a5c9d cleanup: use taxonomy_index_for_category() in taxonomy_set_category()
Instead of recoding the "search for category" loop, reuse the already
existing functionality.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06 12:59:54 -07:00
Berthold Stoeger
f93acdace7 cleanup: make alloc_taxonomy local to taxonomy.c
The alloc_taxonomy()/free_taxonomy() interface was exceedingly strange.
The former gave a "struct taxonomy", the latter took a "struct taxonomy_data".
To make things worse, is appears as if the names "taxonomy" and "taxonoma_data"
are reversed: the latter contains the former.

In any case, the alloc_taxonomy() call is not needed anymore from outside
taxonomy.c, as these memory-management details are now hidden in accessor
functions. Therefore, make the function local to taxonomy.c. Moreover,
rename it to "alloc_taxonomy_table()" and let it take a "taxonomy_data"
structure for symmetry with "free_taxonomy()".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06 12:59:54 -07:00
Berthold Stoeger
7f1def8602 cleanup: use taxonomy_set_category() function
Instead of manipulating the taxonomy structures directly, use the
taxonomy_set_category() function. This improves encapsulation and
gives us the possibility to improve the taxonomy data structures.

This concerns three places:
1) git parser
2) XML parser
3) reverse geo-lookup

This improves the XML parser code slightly: The parser assumes that
the value-attribute comes last (after origin and category). While
it still does that, it now at least generates a warning if it encounters
a value-attribute without origin- or category-attribute.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06 12:59:54 -07:00
Berthold Stoeger
55e4237306 cleanup: copy string in taxonomy_set_[country|category]
These functions were taking a const char *, yet taking ownership
of the value. Moreover, taking ownership of strings is rather
unusual in C-style APIs. Let's copy the string instead.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06 12:59:54 -07:00
Berthold Stoeger
6da78a29c4 cleanup: add helper function to set taxonomy category
Setting a taxonomy category was cumbersome: the caller had to
make sure that the category-table was allocated. Introduce
a helper function to make that simpler.

Make taxonomy_set_country() the first caller of the new function,
since it is just a special case with category = TC_COUNTRY.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06 12:59:54 -07:00
Berthold Stoeger
86c24dd832 cleanup: leak fix in taxonomy_set_country()
When overwriting a country, the old string was not freed. Fix this.
Contains an unrelated coding-style fix: use braces if code block
contains more than one line.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-06 12:59:54 -07:00
Robert C. Helling
b1a1dc3639 Function for "gravity conversion"
This adds a common macro to convert salinity (which is
given as a density in terms of g per 10l) to a specific
weight with units of mbar / mm = bar / m that is used
to translate between pressures and depths.

The weired factor of 10 (from the unusual unit of salinity)
is included in the macro. It is there for historical reasons,
as it goes back to 05b55542c8 from 2012 where it was introduced
in code for downloading from Uemis dive computers.

Now, salinity appears in too many places to easily remove
this unconventional factor of 10 everywhere without breaking
to many things (including various dive computer downloads).

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-09-06 12:50:59 -07:00
Michael Werle
d404aa767f [Bug #2934] Geo Lookup - support for remote dive sites
Some remote dive sites have no populated places (towns, cities)
nearby. For such sites, we now fall back to looking up
unpopulated place names, such as the reef or island name.

Also some code refactorisation:
the actual network access is now encapsulated in its own
function removing some duplicated code handling in the
reverseGeoLookup function and making it more readable.

Furthermore, reverseGeoLookup() was completely refactored as
most of its functionality was due to legacy requirements; the
current code-base only calls this function from a single
location and only with an empty taxonomy_data object. This
makes the function more focussed and much simpler and more
readable.

Finally, a resource leak in reverseGeocde introduced in
4f3b26f9b6 was fixed.

Signed-off-by: Michael Werle <micha@michaelwerle.com>
2020-09-05 17:34:15 +02:00
James Wobser
4f3b26f9b6 Implement Seac SeacSync databaser parser.
Dives for the seac action computer are imported by the seacsync
program into two tables in an sqlite3 database.

The dive information is read from the headers_dive table.
The dive_data table is then queried for each dive to get samples.

The seac action computer is the only current supported computer
by the seacsync program. It only supports two gas mixes, so the
parser will toggle between two cylinders whenever it detects a
change in the active O2 mix.

Dive start time is stored in UTC with a timezone offset.
A helper function to read this was added to qthelper.

Default cases have been added to some switch statements
to assist in future development for other dive types and
salinity.

Example database has been added to ./dives/TestDiveSeacSync.db

Signed-off-by: James Wobser <james.wobser@gmail.com>
2020-09-04 15:54:08 +03:00
Salvador Cuñat
158c3c0b0e datatrak.c: return const string for tank type
As Berthold points out, this string shouldn't be modifiable.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2020-09-03 11:38:13 -07:00
Salvador Cuñat
080a7f1a17 datatrak.c: Do not duplicate string as it's not being freed
It is cloned later by add_cloned_cylinder(), anyway.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2020-09-03 11:38:13 -07:00
Salvador Cuñat
c9c38394c0 datatrak.c: use two_bytes_to_int() to get little endian values
And use memcmp() call to avoid conversion + comparison.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2020-09-03 11:38:13 -07:00
Salvador Cuñat
80ff092533 datatrak.c - Do not return unsigned negative values
We don't really expect to get Nº of dives greater than the biggest
integer value.

Signed-off-by: Salvador Cuñat <salvador,cunat@gmail.com>
Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2020-09-03 11:38:13 -07:00
Salvador Cuñat
c888a1727e DataTrak import: Add support for WLog extensions.
WLog is a Win32 based ancient shareware program whose target was:
1) fully support divelogs coming from DataTrak (DOS or Win)
2) fill some meaningful data which wasn't supported by Uwatec software
3) have a more user-friendly GUI than Datatrak had
The problem achieving goals 1) and 2) at the same time was solved by
adding a complementary file with .add extension and - mandatory - same
base name than .log file (including directory tree).

This .add file has a fixed structure composed of a 12 bytes header,
including file type check and Nº of dives following; then a fixed 850
bytes size for each dive in the log file. Data fields size and position
are fixed inside these blocks and heavily zero padded, so they are easy
to parse.

A serious restriction imposed to the WLog user was *Do not edit the logs
with other software than Wlog*; this was due the order of dives in .log
file being the same than the order of dives in .add file. Thought you
could show a WLog divelog in Datatrak, editing it resulted in mixing all
extended data for dives following the edited one.
Thus, we have to trust files are correct and is to the user ensure this
is so. If extended data are mangled, they are mangled in WLog too and we
are not trying to fix the mess, just importing.

On the technical side, we try to be smart about tank names as neither
DataTrak nor WLog record them. So we just take the first tank in users
list matching the volume recorded in WLog.
For weights we add a translatable "unknown" string as an empty string
results in weight not being shown in subsurface-mobile (which could be a
reportable issue, BTW).

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2020-09-03 11:38:13 -07:00
Robert C. Helling
7e82205e9b Planner: Properly initialize salinity
When the dive has no explicity salinity, our conversion
between pressure and depth assumed salt water. Make this
explicity by using the corresponding macro.

When the planner starts and no salinity is set explicity,
set the water type chooser to salt water to reflect
our default assumption.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-09-02 09:43:38 -07:00
Dirk Hohndel
91557f79cd core/BLE: delay characteristics discovery until service discovery complete
While this code was added as I was trying to work through issues with a BLE
stack that turned out to be broken, the failure behavior of that device showed
that Qt doesn't like it when we start discovering the details of
characteristics while it is still busy discovering services.

So instead of handling the services as we find them, let's instead wait until
we are done discovering services and then discover the details for all those
services.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-08-22 19:35:58 -07:00
Dirk Hohndel
f74328df0b core/BLE: provide state and error updates during BLE discovery
This simply helps us see some possible errors while trying to talk to a device.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-08-22 19:35:58 -07:00
Dirk Hohndel
c87e028602 core/bluetooth: stop discovery once the dive computer has been found
There is no need to continue to look, and at least with the Shearwater
Peregrine having the scan run while we are trying to discover characteristics
appeared to cause issues.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-08-22 19:35:58 -07:00
Dirk Hohndel
ba3efae6e8 macOS/bluetooth: remove the forced rescan
I can no longer reproduce the case where this rescan was necessary.
So let's remove it as it causes additional wait time for BT/BLE users on macOS.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-08-22 19:35:58 -07:00
Dirk Hohndel
adeade5581 core/BLE: correct the reference for the Shearwater characteristic
They use that same UUID on the Peregrine as well.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-08-22 19:35:58 -07:00
Dirk Hohndel
b3c88d4def core/BLE: detect Sherwater Peregrine
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-08-22 19:35:58 -07:00
Berthold Stoeger
fe3021b88a cleanup: consistently use get_cylinder() accessor
get_cylinder(d, i) is more readable than d->cylinders.cylinders[i].
Moreover, it does bound checking and is more flexible with respect to
changing the core data structures. Most places already used this accessor,
but some still accessed the cylinders directly.

This patch unifies the accesses by consistently switching to get_cylinder().
The affected code is in C++ and accesses the cylinder as reference or
object, whereas the get_cylinder() function is C and returns a pointer.
This results in funky looking "*get_cylinder(d, i)" expressions.
Arguably still better than the original.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-08-21 08:48:22 -07:00
Linus Torvalds
efc1b4f31a Update to current libdivecomputer
The libdivecomputer internals changed for USB devices, and now we need
to scan the USB devices before calling libdivecomputer.  That's the same
pattern as for USBHID and IRDA, so let's just regularize this all.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-08-21 08:47:08 -07:00