This was only set but never read. Therefore, remove it. Divecomputer
serial numbers are now handled via a string-based interface.
We can't remove the integer-based firmware number, because that is
still used by the OSTC firmware check in ConfigureDiveComputerDialog.
Let's not risk breaking that.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This dates from 2014 - this should be obsolete: we certainly don't
support such old libdivecomputer versions. Moreover, we bundle our
own anyway.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of just sending this to the user through the progress bar text, also
send things to stderr in verbose mode. That should make it easier to debug
situations where we fail to download from a dive computer.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
I think we only have one dive computer that supports GPS data right now:
the Garmin Descent Mk1. It reports the dive coordinates as "GPS1" and
"GPS2" for the entry point and exit point respectively.
Often GPS1 is missing, because the dive computer may not have gotten a
GPS lock before the diver jumped into the water, so when that happens
we'll use GPS2 for the dive site location. But when GPS1 exists, we
should prefer that.
And that's what we already did in logic in dc_get_gps_location(), but
for the initial dive site created at download time, we just picked any
divecomputer reported string that started with "GPS". And since GPS2 is
reported after GPS1 by the Garmin Descent, it would end up overwriting
the entry point that we _should_ have preferred.
Add the same kind of "explicitly prefer GPS1" logic to the initial dive
download case as we already had elsewhere.
Reported-by: @brysconsulting
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
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>
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>
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>
Apparently libdivecomputer can return DC_GASMIX_UNKNOWN when
fetching tank info with
dc_parser_get_field(parser, DC_FIELD_TANK, i, &tank);
This caused emission of a warning, which was annoying users.
Disable the warning in that case.
Fixes#2866
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
No point in slurping in all of dive.h for translation units that only
want to do some time manipulation without ever touching a dive.
Don't call the header "time.h", because we don't want to end up in a
confusion with the system header of the same name.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This will be temporarilly used by the planner to mark consumption of
air at the surface. Do this by creating a new function add_cylinder,
which replaces add_to_cylinder_table() and takes care of always adding
a dummy cylinder at the end of the table. Make the original
add_to_cylinder_table() local, so that it cannot be accessed anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This finally allows us to download from not just the first device, but specifically
the device that the user picks.
Passing the object through a void pointer is not nice - but since this traverses
C code other solutions (like passing an index into the list) seemed even worse.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Since I learned while trying to implement this that getting sub-second
resolution time in portable C99 is hard (especially for someone who is
used to the comfort of std::chrono and Howard Hinnants date library) the
timer-implemetation from libdivecomputer is now copied to the subsurface
source.
Signed-off-by: Christof Arnosti <charno@charno.ch>
We know that we cannot support native USB, USB HID, IRDA, and USB
storage on Android.
On the flip side, don't try to force the long broken FTDI download.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Implement the libdivecomputer API in Java and create C/JNI translation
layer.
[Dirk Hohndel: whitespace harmonization - yes, some of this is Java,
this still makes it much easier to read for me;
also changed the FTDI conditional compilation to make
sure we can still use that for mobile-on-desktop if
necessary]
Signed-off-by: Christof Arnosti <charno@charno.ch>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Instead of using fixed size arrays, use a new cylinder_table structure.
The code copies the weightsystem code, but is significantly more complex
because cylinders are such an integral part of the core.
Two functions to access the cylinders were added:
get_cylinder() and get_or_create_cylinder()
The former does a simple array access and supposes that the cylinder
exists. The latter is used by the parser(s) and if a cylinder with
the given id does not exist, cylinders up to that id are generated.
One point will make C programmers cringe: the cylinder structure is
passed by value. This is due to the way the table-macros work. A
refactoring of the table macros is planned. It has to be noted that
the size of a cylinder_t is 64 bytes, i.e. 8 long words on a 64-bit
architecture, so passing on the stack is probably not even significantly
slower than passing as reference.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In the previous commit, we just continued downloading dives when
download errors happened, but that also makes problems a lot easier to
miss because now they are possibly just transient reports in the
progress bar that get overwritten by the next dive being downloaded.
So this turns a number of these errors from using 'dev_info()' to use a
new 'download_error()' reporting model, which then uses the generic
subsurface error reporting functionality that is sticky and can handle
multiple errors.
It also adds a few 'dev_info()' calls for actual informational messages
about the state of downloading, although the new ones will probably
mainly end up happening before the progress bar is actually shown. But
it might improve on some of the progress messages.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Eric Charbonnier reported a problem downloading the dives from his
OSTC2, and Jef debugged the libdivecomputer log and says:
"Your ostc has 75 dives, but subsurface downloaded only one, and then
stopped the download. That's because that first dive appears to be
corrupt and fails to parse:
ERROR: Buffer overflow detected! [in /win/subsurface/libdivecomputer/src/hw_ostc_parser.c:981 (hw_ostc_parser_samples_foreach)]
Subsurface (incorrectly) considers that a fatal error and stops the
entire download. From a user point of view, it would be much better to
ignore the problematic dive, and continue downloading the remaining"
Subsurface used to just stop downloading if there were parsing errors,
but Jef further says:
"How parser errors are handled is up to the application. Aborting the
download is probably the worst option here. If a dive fails to parse
(because the dive data is corrupt, the parser contains a bug, etc),
that does not necessary mean the remaining dives can't be downloaded"
so let's change the logic to just continue downloading, and hope other
dives work better.
We might want to do better error reporting, right now the errors tend to
just cause "dev_info()" reports, which just set the progress bar text.
So you'll see it in the progress bar as it happens, but it won't get
really ever noted as an error, and it's easy to miss.
But that error reporting is a separate issue, and this just does the
"continue to the next dive" part.
Reported-by: Eric Charbonnier <eric.charbonnier69@gmail.com>
Suggested-by: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
The fill_default_cylinder() function calculated the MOD based
on the currently displayed dive. This does not seem to make sense:
- When importing dives, why would we care about the altitude and
salinity of the currently displayed dive, possibly from a different
trip.
- The planner is supposed to be thread-safe and should not touch
global variables.
Of course this means that the importing-functions have to fill
out altitude and salinity before creating the default cylinder,
but this is their problem. For a freshly created dive they will
get the default values, which still seems less random than the
values from the displayed dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Move the declarations of the "report_error()" and "set_error_cb()"
functions and the "verbose" variable to errorhelper.h.
Thus, error-reporting translation units don't have to import the
big dive.h header file.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The parsers / downloaders parse into a separate table and do
not directly change the divelist. Therefore, they shouldn't
call mark_divelist_changed().
Likewise split_dive_at() doesn't modify the dive list and
therefore shouldn't call this function.
Calling the function has the unwanted side-effect that undoing
the change will not clear the *-symbol in the title of the
main window.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The parse_location() function was used in three places. In two
of them, the declaration was in the translation unit. Instead,
move the declaration into a header file, to avoid duplication
and the possibility of inconsistencies.
The "units.h" header was chosen as this is where location_t
is defined.
Moreover, make the string argument to parse_location() "const
char *", so that it can be used on non-owned buffers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of setting dive->dive_site directly, call the
add_dive_to_dive_site() and unregister_dive_from_dive_site()
functions. In the parser this turned out to be a bit tricky.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Add a dive site table to each dive site to keep track of dives
that have been added to a dive site. Add two functions to add
dives to / remove dives from dive sites.
Since dive sites now contain a dive table, the order of includes
had to be changed: "divesite.h" now includes "dive.h" and not
vice-versa. This caused some include churn.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since the UUID will be overwritten on save and is only used on save
and load, set it only on save or load. For other created dive sites,
leave the UUID field uninitialized.
This means that the UUID will change between saves. Let's see how
the git saver handles that.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To extend the undo system to dive sites, the importers and downloaders
must not parse directly into the global dive site table. Instead,
pass a dive_site_table argument to parse into.
For now, always pass the global dive_site_table so that this commit
should not cause any functional change.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To enable undo of dive site functions, it is crucial to work
with different dive site tables. Therefore add a dive site table
parameter to dive site functions. For now, always pass the global
dive site table. Thus, this commit shouldn't alter any functionality.
After this change, a simple search for dive_site_table reveals all
places where the global dive site table is accessed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
While in theory the DEVINFO event should give us the correct detected
product, it's also possible that the code that usually detects the
product gave up and returns an unknown model.
Try to have the message reflect that situation more accurately.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Since process_imported_dives() can add dives to a newly generated
trip, this need not be done in the downloading code. This makes
data flow distinctly simpler, as no trip table and no add-new-trip
flag has to be passed down to the libdivecomputer glue code.
Moreover, since now the trip creation is done at the import step
rather than the download step, the latest status of the "add to
new trip" checkbox will be considered.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since recent commits, dive-trips are not added directly to the core,
but into separate trip tables (see ec37c71f5e).
These commits did not finish the work for the download-from-dc
case.
Add an extra trip_table field to device_data_t. If trips are created
(user selected "Download into new trip"), the trip will be created
in that table.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Currently trips are added to the global trip table. If we want to
make dive-import undoable, we should be able to parse trips of a
log-file into a distinct table. Therefore, add a trip_table
parameter to
- insert_trip()
- create_and_hookup_trip_from_dive()
- autogroup_dives()
- unregister_trip()
- remove_dive_from_trip()
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To make data flow more clear, unglobalize the downloadTable object.
Make it a subobject of DownloadThread. The difficult part was making
this compatible with QML, because somehow the pointer to the
download-table has to be passed to the DiveImportedModel. Desktop would
simply pass it to the constructor. But with objects generated in QML
this is not possible. Instead, pass the table in the repopulate()
function. This seems to make sense, but for this to work, we have to
declare pointer-to-dive-table as a Q_METATYPE. And this only works
if we use a typedef, because MOC removes the "struct" from "struct
dive_table". This leads to compilation errors, because dive_table is
the symbol-name of the global dive table! Sigh.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Replace the UUID reference of struct dive by a pointer to dive_site.
This commit is rather large in lines, but nevertheless quite simple
since most of the UUID->pointer work was done in previous commits.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This changes more of the dive-site interface to return pointers
instead of UUIDs. Currently, most call sites directly extract
UUIDs afterwards. Ultimately, the UUIDs will be generally replaced
by pointers, which will then simplify these callers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of having people treat latitude and longitude as separate
things, just add a 'location_t' data structure that contains both.
Almost all cases want to always act on them together.
This is really just prep-work for adding a few more locations that we
track: I want to add a entry/exit location to each dive (independent of
the dive site) because of how the Garmin Descent gives us the
information (and hopefully, some day, other dive computers too).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
We bundle our version of libdivecomputer and don't expect Subsurface to work
with a different version, certainly not with something older than 0.5.
I kept the checks for SAMPLE_EVENT_STRING and DC_FIELD_STRING and DC_SAMPLE_TTS
because maybe there's a situation where being able to compile with a current
upstream version is useful.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This flag had two distinct uses:
- signal that dives were downloaded, not imported
- use to mark imported dives
Both are not used anymore, therefore remove the flag.
The uemis downloaded misused the flag to mark deleted
dives. Instead misuse the "hidden_by_filter" flag.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Dives are now in all cases imported via distinct dive_tables.
Therefore the "preexisting" marker is useless. Remove.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The error handling was incorrect for the case where we successfully
opened the libdivecomputer iostream in divecomputer_device_open(), but
the dc_device_open() call failed.
When the dc_device_open() failed, we would (correctly) not do the
dc_device_close() but we would _also_ not do the dc_iostream_close() to
close the underlying file descriptor, which is wrong.
Normally this isn't all that noticeable, partly because the common case
is that dc_device_open() succeeds if you actually do have a dive
computer connected, but also because most of the time it just leaked a
file descriptor or something like that.
However, particularly for the POSIX serial device case, libdivecomputer
does a
ioctl(device->fd, TIOCEXCL, NULL)
call to make serial opens exclusive. This is what we want - but if we
then fail at closing the serial file descriptor, we won't be able to
retry the import at all because now the next open will fail with EBUSY.
So the error handling was incorrect, and while it doesn't usually matter
all that much, it can be quite noticeable particularly when you have
transient errors.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>
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>
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>
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>
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>
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>
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>