aboutsummaryrefslogtreecommitdiffstats
path: root/core/libdivecomputer.c
AgeCommit message (Collapse)Author
2020-10-26cleanup: remove unused function argumentGravatar Dirk Hohndel
Also, only compile the static function where it is used. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-25cleanup: split out divecomputer functions from dive.cGravatar Berthold Stoeger
Since dive.c is so huge, split out divecomputer-related functions into divecomputer.[c|h], sample.[c|h] and extradata.[c|h]. This does not give huge compile time improvements, since struct dive contains a struct divecomputer and therefore dive.h has to include divecomputer.h. However, it make things distinctly more clear. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: break out event-related code into event.[c|h]Gravatar Berthold Stoeger
In an effort to reduce the size of dive.h and dive.c, break out the event related functions. Moreover event-names were handled by the profile-code, collect that also in the new source files. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24divecomputer: add device to provided table instead of global tableGravatar Berthold Stoeger
In the specuial case of suunto, where we may add a device directly instead of via dive->dc, add the device to the provided table. The caller will then pass on the new device to the undo system. This makes downloading finally really undoable (at least I hope so). So far, the dives and dive sites were removed, but any new device remained. However, when setting the device-id via serial, we now have to check both, the global and the downloaded list of devices. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-23libdc: free value strings given by libdc's dc_parser_get_field()Gravatar Berthold Stoeger
Apparently libdc gives us copies of strings. The API is very scary, because (at least according to my reading of the code), the key/value pair may be stored in a cache. Thus on free()ing the string in the cache becomes invalid and we must not access it twice. Very obscure. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16cleanup: use correct printf formatGravatar Dirk Hohndel
This fixes a warning from the CodeQL scan. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-16core: add device_table parameter to device table functionsGravatar Berthold Stoeger
Instead of accessing the global device table directly, add a parameter to all device-table accessing functions. This makes all places in the code that access the global device table grep-able, which is necessary to include the device-table code in the undo system. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16core: use C accessors in core/libdivecomputer.c instead of callbackGravatar Berthold Stoeger
Searching the proper device for the divecomputer was done via a callback. Very hard to follow code. Since we can now access "struct device" from C, obtain it directly via get_device_for_dc(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-05cleanup: remove libdc_serial field in device_data_tGravatar Berthold Stoeger
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>
2020-10-05cleanup: remove DC_FIELD_STRING conditional compilationGravatar Berthold Stoeger
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>
2020-10-05libdc/debug: provide better info regarding libdc interactionGravatar Dirk Hohndel
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>
2020-09-29Prefer "GPS1" for divecomputer download dive site resolutionGravatar Linus Torvalds
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>
2020-09-19core/bluetooth: only Linux / Windows are supported by libdc rfcommGravatar Dirk Hohndel
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-19core/bluetooth: switch to use libdivecomputer rfcomm supportGravatar Linus Torvalds
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-08-21Update to current libdivecomputerGravatar Linus Torvalds
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-06-13download: don't warn on unknown gasmixesGravatar Berthold Stoeger
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>
2020-05-01cleanup: move declaration of utc_mk* functions to new subsurface-time.h headerGravatar Berthold Stoeger
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>
2020-05-01cleanup: move dive_table from dive.h to divelist.hGravatar Berthold Stoeger
This allows us to decouple dive.h and divelist.h, a small step in include disentangling. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01core: always keep an empty cylinder at the end of the cylinder arrayGravatar Berthold Stoeger
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>
2020-03-16android/usb: pass in the UsbDevice when downloadingGravatar Dirk Hohndel
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>
2020-03-10Add timestamps to libdivecomputer.logGravatar Christof Arnosti
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>
2020-03-09Android: don't list devices with unsupported transportGravatar Dirk Hohndel
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>
2020-03-07usb-serial-for-android: ImplementationGravatar Christof Arnosti
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>
2020-01-10code cleanup: introduce empty_cylinder constantGravatar Dirk Hohndel
This deals with the issue of initializing structs in C++. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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>