aboutsummaryrefslogtreecommitdiffstats
path: root/core/libdivecomputer.c
AgeCommit message (Collapse)Author
2019-11-09Core: remove MAX_CYLINDERS restrictionGravatar Berthold Stoeger
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>
2019-09-11Add 'download_error()' helper for libdivecomputer download error reportingGravatar Linus Torvalds
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>
2019-09-11Keep parsing dives even if one dive parse failedGravatar Linus Torvalds
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>
2019-08-08Core: pass dive, cylinder-id to fill_default_cylinderGravatar Berthold Stoeger
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>
2019-08-08Cleanup: move error reporting function declarations to errorhelper.hGravatar Berthold Stoeger
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>
2019-07-19Cleanup: remove bogus mark_divelist_changed() callsGravatar Berthold Stoeger
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>
2019-05-11Cleanup: move parse_location() declaration into header fileGravatar Berthold Stoeger
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>
2019-04-15FTDI support: ignore case when comparing magic device nameGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-04-12Dive site: add dive site ref-countingGravatar Berthold Stoeger
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>
2019-04-12Dive sites: prepare for dive site ref-countingGravatar Berthold Stoeger
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>
2019-04-12Cleanup: remove "sha1.h" include in "dive.h"Gravatar Berthold Stoeger
No point in pulling that in for all users of "dive.h" Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Dive site: set UUID only on save or loadGravatar Berthold Stoeger
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>
2019-04-12Parser: parse into custom dive site tableGravatar Berthold Stoeger
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>
2019-04-12Dive site: add dive site table parameter to dive site functionsGravatar Berthold Stoeger
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>
2019-01-22libdivecomputer: small wording change in a warningGravatar Dirk Hohndel
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>
2019-01-19Import: don't add to new trip while downloadingGravatar Berthold Stoeger
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>
2019-01-19Dive download: add trip_table to device_data_tGravatar Berthold Stoeger
Since recent commits, dive-trips are not added directly to the core, but into separate trip tables (see ec37c71f5eeb7d4b0c4b8719b52583fadb0b8f4c). 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>
2019-01-09Core: add trip_table parameter to trip-functionsGravatar Berthold Stoeger
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>
2018-12-17Import: unglobalize downloadTableGravatar Berthold Stoeger
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>
2018-10-29Dive site: replace dive->dive_site_uuid by dive_siteGravatar Berthold Stoeger
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>
2018-10-29Dive site: return pointer to dive_site in create_dive_site_*()Gravatar Berthold Stoeger
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>
2018-10-21Add 'location_t' data structureGravatar Linus Torvalds
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>
2018-10-08libdivecomputer: remove ifdefs for ancient versionsGravatar Dirk Hohndel
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>
2018-10-06Core: remove dive->downloaded flagGravatar Berthold Stoeger
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>
2018-10-06Core: remove preexisting field from struct dive_tableGravatar Berthold Stoeger
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>
2018-10-06Fix error handling for libdivecomputer importGravatar Linus Torvalds
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>
2018-10-05Cleanup: don't produce no-dives error message in libdivecomputer.cGravatar Berthold Stoeger
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>
2018-09-22Actually create a UUID when creating a dive site during downloadGravatar Linus Torvalds
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>
2018-09-16Always return status from ftdi_open when calledGravatar Anton Lundin
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>
2018-09-03libdivecomputer: allow a "zero depth" deco stop depthGravatar Linus Torvalds
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>
2018-09-03libdivecomputer: add support for DC_SAMPLE_TTS if it existsGravatar Linus Torvalds
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>
2018-08-29parse "GPS" string fields and turn them into dive sites when downloadingGravatar Linus Torvalds
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>
2018-08-27Add support for opening a DC_TRANSPORT_USBSTORAGE streamGravatar Linus Torvalds
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>
2018-06-21FTDI support: try ftdi_open first if the device name is 'ftdi'Gravatar Dirk Hohndel
It makes no sense to have the OS try (and fail) to open that device name. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-06-21mobile: better message regarding logfilesGravatar Dirk Hohndel
On mobile those area always created and available for simple cut and paste. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-06-18libdc interface: remove debug messagesGravatar Berthold Stoeger
Don't spill supported transports as error message to the user. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-24core: replace (void) with UNUSED(x) and include ssrf.hGravatar jan Iversen
Unused parameters in C are "silenced" by adding UNUSED(x) Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-14Core: introduce new subsurface-string headerGravatar Dirk Hohndel
First small step to shrinking dive.h. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-12Add Qt header so Q_OS_xxx macros workGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-11iOS: only DC_TRANSPORT_BLE is supportedGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-04-27Create one function to determine the supported transportsGravatar Dirk Hohndel
This should make sure we create a consistent view based on all the information available. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-04-27libdc transport debuggingGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-04-27Do a better job of picking which transport to useGravatar Linus Torvalds
If the user specified bluetooth, we really should pick bluetooth, not probe and possibly fall back to something else. We should also honor the users choice of BLE vs classic BT. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-04-24use libdivecomputer 'fingerprint' to avoid downloading extra dataGravatar Linus Torvalds
This opportunistically uses a cache of 'fingerprints' for already downloaded dives. As we download data from a dive computer, we save the fingerprint and dive ID of the most recent dive in a per-divecopmputer fingerprint cache file. The next time we download from that dive computer, we will load the cache file for that dive computer if it exists, verify that we still have the dive that is referenced in that cachefile, and if so use the fingerprint to let libdivecomputer potentially stop downloading dives early. This doesn't much matter for most dive computers, but some (like the Scubapro G2) are not able to download one dive at a time, and need the fingerprint to avoid doing a full dump. That is particularly noticeable over bluetooth, where a full dump can be very slow. NOTE! The fingerprint cache is a separate entity from the dive log itself. Unlike the dive log, it doesn't synchronize over the cloud, so if you download using different clients (say, your phone and your laptop), the fingerprint cache entries are per device. So you may still end up downloading dives you already have, because the fingerprint code basically only works to avoid duplicate downloads on the same installation. Also, note that we only have a cache of one single entry per dive computer and downloader, so if you download dives and then don't save the end result, the fingerprint will now point to a dive that you don't actually have in your dive list. As a result, next time you download, the fingerprint won't match any existing dive, and we'll resort to the old non-optimized behavior. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-04-24Actually tie in the new libdivecomputer IO model to open the dive computer ↵Gravatar Linus Torvalds
device This creates a new libdivecomputer_device_open() helper, and makes downloading and configuration use it to open the dive computer device using the proper protocol. The IRDA case was tested by Sébastien Dugué - I had initially left it undone believing that "nobody uses IRDA". Reported-and-tested-by: Sébastien Dugué <sebastien.dugue.subsurface@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-04-24Convert our custom IO model to new libdivecomputer IO modelGravatar Linus Torvalds
This converts our old custom IO model to the new model that libdivecomputer introduced. This is partly based on Jef's rough patch to make things build, with further work by me. The FTDI code is temporarily disabled here, because it will need to be integrated with the new way of opening devices. The ble_serial code goes away entirely, since now libdivecomputer knows about BLE transport natively, and doesn't need to have any serial wrapper around it. Signed-off-by: Jef Driesen <jef@libdivecomputer.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-04-11Cleanup: unconstify results of two functionsGravatar Berthold Stoeger
get_dive_date_c_string() and get_current_date() return copied strings. Make this explicit by returning non-const pointers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-17Coding-style: remove superfluous parenthesesGravatar Berthold Stoeger
Mostly replace "return (expression);" by "return expression;" and one case of "function((parameter))" by "function(parameter)". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-11Introduce helper function empty_string()Gravatar Berthold Stoeger
There are ca. 50 constructs of the kind same_string(s, "") to test for empty or null strings. Replace them by the new helper function empty_string(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-05Increase size of name_buffer to fit any integerGravatar Berthold Stoeger
In libdivecomputer.c, name_buffer is formatted with calls like snprintf(name_buffer, 9, "%d cuft", rounded_size); This works fine in the regular case, but it generates compiler warnings, since theoretically the integer might produce up to 11 digits, leading to a truncation of the string. Increasing the size of name_buffer to 17 chars silences these warnings. This may seem like pointless warning-silencing. Nevertheless, in the case of invalid data, it might make debugging easier since, in the above case, the "cuft" is never truncated. In total, it seems that this is a benign change with potential, though in a very unlikely case, positive effects. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>