summaryrefslogtreecommitdiffstats
path: root/core
AgeCommit message (Collapse)Author
2020-09-03datatrak.c: Do not duplicate string as it's not being freedGravatar Salvador Cuñat
It is cloned later by add_cloned_cylinder(), anyway. Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2020-09-03datatrak.c: use two_bytes_to_int() to get little endian valuesGravatar Salvador Cuñat
And use memcmp() call to avoid conversion + comparison. Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2020-09-03datatrak.c - Do not return unsigned negative valuesGravatar Salvador Cuñat
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-03DataTrak import: Add support for WLog extensions.Gravatar Salvador Cuñat
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-02Planner: Properly initialize salinityGravatar Robert C. Helling
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-08-22core/BLE: delay characteristics discovery until service discovery completeGravatar Dirk Hohndel
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-22core/BLE: provide state and error updates during BLE discoveryGravatar Dirk Hohndel
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-22core/bluetooth: stop discovery once the dive computer has been foundGravatar Dirk Hohndel
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-22macOS/bluetooth: remove the forced rescanGravatar Dirk Hohndel
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-22core/BLE: correct the reference for the Shearwater characteristicGravatar Dirk Hohndel
They use that same UUID on the Peregrine as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-08-22core/BLE: detect Sherwater PeregrineGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-08-21cleanup: consistently use get_cylinder() accessorGravatar Berthold Stoeger
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-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-08-21cleanup: remove obsolete logic in getFormattedCylinder()Gravatar Berthold Stoeger
getFormattedCylinder() is a helper function to format a list of cylinders. It had that weird logic that it would skip cylinders without description unless it is the first, which would instead be written as "unkown". The reason was the old statically sized cylinder array, where it wasn't clear if a cylinder was actually in use. This became obsolete when switching to a variable size cylinder array. Firstly, all cylinders in the array were added by the user. Secondly, we now also support dives without cylinders, i.e. the first cylinder is not any different from the rest. Thus, remove the logic and format any cylinder without description as being of type "unknown". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-08-18core/bt-discovery: recognize BT names of four more dive computersGravatar Dirk Hohndel
This adds the Oceanic Veo 4.0 & Pro Plus 4, the Sherwood Wisdom 4 and the Tecdiving DiveComputer.eu to our list of known names. The Oceanic Pro Plus X detection is simply moved to have the other names in a more logical order. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-08-17core: fix dive renumbering logic on importGravatar Berthold Stoeger
0249e12 split up the dive import logic in multiple steps. Thereby, the one of the conditions for renumbering the imported dives (is the last old dive numbered) got messed up: The first number of the new dive was compared to the total number of old dives, which makes no sense. - Simply check for the number of the last existing dive (if any). - Don't remember the number of old dives - the original table is not modified anyway. Fixes #2731 Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-08-16core/localized-parsing: correctly handle group and decimal separatorGravatar Dirk Hohndel
We are usually showing pressures with localized group separator. And we made a total mess out of things when then re-parsing those values. This caused us to ignore start and end pressures in Subsurface-mobile when those were entered in psi and included a group separator: 2,900psi was turned into 2.900psi which we then rounded to 0 mbar. This fixes the problem by asking Qt to do the right thing instead of doing stupid separator magic. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-08-15Fix event merging when merging divesGravatar Linus Torvalds
The merge_events() function was subtly and not-so-subtly broken in a couple of ways: - in commit 8c2383b49 ("Undo: don't modify source-dives on merge"), we stopped walking the event list after we merged the first event from a dive when the other dive computer had run out of events. In particular, this meant that when merging consecutive dives, the second dive only had the first event copied over to the merged dive. This happened because the original code just moved the whole old list over when there was nothing left from the other dive, so the old code didn't need to iterate over the event list. The new code didn't realize that the pointer movement used to copy the whole rest of the list, and also stopped iterating. In all fairness, the new code did get the time offset right, which the old code didn't. So this was always buggy. - similarly, the "avoid redundant gas changes" case was not handled for the "we ran out of events for the other dive computer" case. This fixes both issues. Cc: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-07-27core: detect McLean Extreme dive computer as BLE deviceGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-07-14core/BLE: add detection of Scubapro Aladin A1Gravatar Dirk Hohndel
This was supported in libdivecomputer, but not recognized as dive computer by our core BLE code. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-07-11helper functions: remove timestamp argument from gettiemzoneoffset()Gravatar Dirk Hohndel
The last user of that argument has been removed. (a random whitespace fix snuck in with this) Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-07-11mobile/location-service: stop using broken adjustment functionGravatar Dirk Hohndel
gettimezoneoffset() returns incorrect values when called with a time_t. Since we only accept the value here if it is within 5 minutes of 'now', using the current timezone offset is a fair approximation. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-07-11mobile/location-service: fix timezone issue in GPS timestampsGravatar Dirk Hohndel
For some reason we suddenly started logging the GPS fixes in UTC instead of local time. Which caused the matching algorithm to fail (unless you happened to be diving in UTC). Unclear what broke this, but this seems like an easy enough fix, since the GPS fix being reported is by definition "right around now". So using gettimezoneoffset() with the current time seems "good enough". I don't know when gettimezoneoffset() with an argument got broken, TBH. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-07-11Make MND display depend on O2 narcotic preferenceGravatar Robert C. Helling
A while ago, we introduced a preference whether O2 should be considered narcotic. We used this when computing best mix or when entering the He content via MND. But we forgot to make the displayed MND depend on this preference. This patch add this. Fixes #2895 Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-07-02profile: fix displaying of profiles with multiple pressure sensorsGravatar Berthold Stoeger
When removing the MAX_CYLINDERS restriction, the layout of the pressure readings was changed from a (cylinder,sample) to a (sample,cylinder) scheme. I.e. previously there were one cylinder block for each sample, then one sample block for one cylinder. However, after populating the samples, the array size was reduced to the actual number of used samples. With the new layout this breaks indexing. Therefore, restore the old layout. Fixes #2887 Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-06-29Fix dive merging with multiple cylindersGravatar Linus Torvalds
We did something really horribly wrong when merging cylinders. It's been broken since commit 7c9f46a ("Core: remove MAX_CYLINDERS restriction"), and used some really strange logic. This rewrites the logic to be (I think) a bit more easy to understand. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-06-25Add support for the Oceans S1 and McLean ExtremeGravatar Linus Torvalds
This updates libdivecomputer to support the Oceans S1 and McLean Extreme divecomputers. It also adds the Oceans S1 to the list of dive computers we reconize by bluetooth name. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-18core: fix compile issue with older g++Gravatar Dirk Hohndel
Having the full list of all members in the exact order should be enough to get g++ to accept the named initializers. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-06-18core: fix libdivecomputer dc_custom callbacks structuresGravatar Linus Torvalds
The last time those changed, we forgot to update serial_ftdi. In that change set_latency had been removed from libdivecomputer and poll and ioctl had been added. This caused the callbacks to no longer be aligned correctly and the functions were called with the wrong arguments through the wrong function pointers, leading to crashes. Instead of the fragile assumptions about order and type of function pointers, use named initializers. And while we are at it, fix that for the bluetooth implementation as well. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-06-16cleanup: remove indirection when passing arguments to parser functionsGravatar Berthold Stoeger
For unknown reasons, the dive site and trip to be parsed into were passed as pointers to pointers. A simple pointer seems to be enough, since the object is not allocated by the function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-06-14git-storage: add global flag to indicate successful cloud syncGravatar Dirk Hohndel
This may seem like a bit heavy handed as it adds more global state, but given the number of ways in which attempts to sync with the cloud can fail it seems much more reliable to claim success in the spots where we actually know that we have successfully synced with the remote server. Transporting that information back through the various call chains turned out to be very disruptive and ugly, so I went with global state instead. Whenever we access cloud storage (or any git repo), we always first check if it actually is a git repo by calling is_git_repository() - so this is the perfect spot to initialize the variable to false. And there are only two spots where we either clone the remote repo (create_local_repo()) or update the remote with the (potentially merged) local changes (check_remote_status()). So those are the two places where we set the variable to true. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-06-14git storage: significantly expand logging to stderrGravatar Dirk Hohndel
In many cases we did not log the issues the code ran into to stderr which made remote debugging user problems much harder. This hopefully will help with that. Since I was looking at the code, I also made the existing messages more consistent. Signed-off-by: Dirk Hohndel <dirk@hohndel.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-29cleanup: make local functions of static linkageGravatar Berthold Stoeger
A few functions in save-html.c were local but not marked as static. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-26Print correct template name on CSV exportGravatar Miika Turkia
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-05-22cleanup: constify time_during_dive_with_offset() functionGravatar Berthold Stoeger
There is no reason to pass a non-const dive pointer as first argument. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22cleanup: remove unused function get_dive_n_near()Gravatar Berthold Stoeger
The last caller was removed in 7eb422d98837b3cfb289a66fa0f3a8f78f222001. Since this is the only caller of dive_within_time_range(), remove that function as well. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22cleanup: create common QDateTime -> timestamp conversion functionGravatar Berthold Stoeger
In analogy to the timestamp -> QDateTime conversion, create a common function. 1) For symmetry with the opposite conversion. 2) To remove numerous inconsistencies. 3) To remove use of the deprecated QDateTime::toTime_t() function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22cleanup: remove unused libc-structures from get_trip_date_string()Gravatar Berthold Stoeger
This must be an artifact from before using Qt's datetime functions. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22cleanup: move timestampToDateTime() to qthelper.cppGravatar Berthold Stoeger
Move this function from maintab.cpp to qthelper.cpp. Since the functionality was used in numerous places, use the helper function there as well. This removes a number of inconsistencies. For example, sometime setTimeSpec(Qt::UTC) was called, even though the QDateTime object was already created with that time spec. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-22Fix incorrect Farenheit to Kelvin formula.Gravatar Paul Buxton
Use defined function instead. Signed-off-by: Paul Buxton <paulbuxton.mail@googlemail.com>
2020-05-22cleanup: set long and short date formats in independent branchesGravatar Berthold Stoeger
The short and long date formats where initialized in a common if-branch. However, inside the if-branch the code rechecked which of the two should be initialized. This could make sense if there was some common code between the two, but there wasn't. Therefore, make this two independent branches to avoid one nesting-level. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-17BLE: trivial updates to the GATT services listsGravatar Linus Torvalds
Add a couple of known services (Scubapro G2 and Shearwater), and update the names of others that turn out to be used for multiple dive computers. Also add another Broadcom upgrade service UUID. While at it, sort the services numerically to make it easier to see that a UUID already exists, since these service numbers do get used across multiple different devices. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-17BLE: add list of known good/bad BLE GATT servicesGravatar Linus Torvalds
We've tried to do this "automagic" service discovery, and it mostly works, but then occasionally it doesn't. Making things worse, I think different platforms end up enumerating services differently, so our "pick the first service that looks like it might be a serial service" ends up working on some platforms, but not necessarily on others. Because "first" might be different. So start a list of known good/bad services - and fall back to the old logic when you can't decide reliably. This fills in juat a few cases that I can easily check myself, and the "details" field for them may be incomplete. For example, I know Nordic Semiconductor has their vendor-specific UUIDs, and they can be found in different devices, so calling them "Nordic UART" and "Nordic Flash" services makes sense. But the "Scubapro i770R" service? It might indeed be specific to the Scubapro i770R. Or it might be a general service UUID that Pelagic uses. Or it might be the service UUID of a particular chip, and found in dive computers from other designs too (and not necessarily in all i770R's either). So this is a preliminary first stab at this, and I'm sure we'll extend the list and possibly improve on the explanations. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-16filter: properly search for tagsGravatar Berthold Stoeger
The old code used get_taglist_string() and split the resulting string at commas to get the list of tags. This was wrong for two reasons: 1) It was buggy. Every tag but the first would start with a leading space and thus not be found. 2) It was inefficient. The tag list was concatenated, just to be split again. Turn the tag list directly into a QStringList and remove whitespace for good measure. Fixes #2842. Reported-by: Hartley Horwitz <hhrwtz@gmail.com> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-16filter: include tags in fulltext searchGravatar Berthold Stoeger
The tags have been forgotten when implementing the fulltext search. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-15core/bt: ensure that BT/BLE addresses with name sort firstGravatar Dirk Hohndel
We don't order the list of addresses alphabetically, but we want to ensure that devices that offer us a name are listed before those that don't. This should only be relevant if the user selects the option to show all BT/BLE devices, not just recognized dive computer, because if we recognize a computer we always have the product name prepended to the address. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-05-15core/bt: always add bt name for devicesGravatar Dirk Hohndel
If the user asks to have all BT/BLE devices shown, we should behave consistently to the case of a recognized dive computer and always show the device name. In almost all cases the BT/BLE address (and even worse on iOS/macOS the weird uuids) are completely meaningless. If there isn't a name, don't add a leading space in order to make it easy to detect if we have an address without a name (which almost certainly isn't a dive computer, so it should be towards the end of the list of addresses - which will be handled in a later commit). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-05-15core/bt: match DC descriptor in lower caseGravatar Dirk Hohndel
This fixes a rather subtle bug. In btdiscovery.cpp we are detecting dive computers based on their BT name and are setting up product+vendor as the key for that lookup. QMap always uses case sensitive comparisons and a tiny inconsistency snuck into our code. libdivecomputer names for the Aqualung dive computers i200C / i300C / i550C end in an upper case C (as matches the official branding), but in btdiscovery.cpp we have those names with lower case c. And therefore didn't recognize these dive computers. Obviously this is easy to fix by fixing those three strings, but I decided that it was silly to set ourselves up for similar oversights in the future. So instead I switched the matching of the descriptor to simply be allways all lower case. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-05-14Save SAC, OTU and CNS in the XML exportGravatar Linus Torvalds
We do _not_ read them back, since they are calculated values, although I guess we could aim to do that too at some point in case we have an import from somewhere else that has these values but not the profile (or gas use) to actually calculate them. Fix test-cases that are checked by TestParse (but nothing else) to match. Requested-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>