Commit graph

2638 commits

Author SHA1 Message Date
Berthold Stoeger
9c253ee6c5 core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.

Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).

The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.

To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.

The whole commit is large, but was mostly an automatic
conversion.

One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-04-14 21:20:23 +02:00
Dirk Hohndel
ad8aa988f0 Merge branch 'add_ostc4_force_firmware_update' of https://github.com/mikeller/subsurface
together with the libdc change this should now work

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2023-03-29 10:36:29 -07:00
rafsalvioni
2f4b415e91 Saves default sea water salinity in log
Some DCs only report water type, without salinity level. Subsurface
fixes most of these cases using default levels, but when the type of water
is Sea/Salt, this fix was not saved.

This causes a bit confusion, mainly if the user defines own salinity level.

Signed-off-by: Rafael M. Salvioni <rafael.salvioni@gmail.com>
2023-03-28 20:51:36 -07:00
Berthold Stoeger
31cf991afe cleanup: remove pointless idle comment in string-format.cpp
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-03-28 20:39:02 -07:00
Berthold Stoeger
264adacba1 cleanup: move formatting of gas type to string-format.cpp
Since the only caller was C++ code, this can be done in
C++ code, which removes memory-management headaches.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-03-28 20:39:02 -07:00
Michael Keller
324fbfa685 Desktop: Add option to force overwrite firmware for OSTC4.
In order to support development of the open source firmware of the
OSTC4.
Requires changes in libdivecomputer.

Signed-off-by: Michael Keller <github@ike.ch>
2023-03-18 00:11:08 +13:00
Michael Keller
b9b47092c1 Desktop: Fix bug in diveplan for CCR dives with multiple segments.
Fixes a bug reported in
https://groups.google.com/g/subsurface-divelog/c/8N3cTz2Zv5E:
When planning a CCR dive with multiple segments, the textual dive plan
was showing a non-existent gas change with bogus data.  The first part
of the fix is uncluttering of the message printed: Since this change is
_after_ the current diveplanpoint the data needs to come from `nextdp`
and not `dp`.  The second part is that the message is not printed any
more if the current and the following segments have been manually added:
According to comments in the code the change should only be printed on
the segment _before_ the change if this segment is an ascent segment
that is followed by a manually entered segment.

Signed-off-by: Michael Keller <github@ike.ch>
2023-03-01 15:35:55 +01:00
Robert C. Helling
c47e28fa29 Dive mode for surface intervals
Divers breath air in open circuit mode during surface intervals,
not with their CCR.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2023-03-01 15:33:22 +01:00
Michael Keller
cb5bc68c59 Desktop: Fix the number of progress steps in the OSTC4 download steps.
Changed the maximum number of steps for the progress bar to match the
number of steps that exist.

Signed-off-by: Michael Keller <github@ike.ch>
2023-02-26 21:31:27 +01:00
Berthold Stoeger
4128fec1ea profile: register event names on creation of events
The event names were registered in add_event(). However,
the undo system did not use that function, but add_event_to_dc(),
which takes an already allocated event.

That gave the following unfortunate situation:

Load a log without setpoint changes.
Add a setpoint change.
The setpoint change event type now was not registered and
therefore couldn't be hidden.

Admittedly, a subtle bug, but still a bug. Fix by registering
event names on event creation.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-02-17 06:46:46 -08:00
Berthold Stoeger
0d3c9954f4 profile: redo eventname handling
The eventname handling code was splattered all over the place.
Collect it in a single source file and use C++ idioms to avoid
nasty memory management. Provide a C-only interface, however.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-02-17 06:46:46 -08:00
Michael Keller
ab7b9329c0 Standardised how divedatapoints are created.
Changed the way dive data points for OC cylinders to be added to the
dive plan are created in `createTemporaryPlan()` in
`diveplannermodel.cpp`. This now uses `plan_add_segment()` like all
other places where dive data points are added, in particular the planner
tests.
This also allowed for `create_dp()` to be made static.

Signed-off-by: Michael Keller <github@ike.ch>
2023-02-17 10:53:04 +01:00
Michael Keller
ec0c6833a0 Fix invalid bailout gas choice when planning a CCR dive.
Fixes a bug reported in
https://groups.google.com/g/subsurface-divelog/c/8N3cTz2Zv5E:
When planning a CCR dive with OC bailout, the diluent gas may be chosen
as the first OC bailout gas, despite being set up with a use type of
'diluent', and likely not being available for open circuit breathing.
`best_first_ascend_cylinder` is now initialised to an invalid value
(instead of the first cylinder, which may or may not be a diluent
 cylinder), and its subsequent use is guarded by a validity check.

Signed-off-by: Michael Keller <github@ike.ch>
2023-02-17 10:49:24 +01:00
Michael Keller
b4af03751d Improve accuracy of the 'unlikely dive gas' warning.
Change the values supplied in the warning to be fractions. This is what
is actually reported by libdivecomputer. The currently used thousandths
are hard to interpret for users, as they are only used internally in
Subsurface.

Signed-off-by: Michael Keller <github@ike.ch>
2023-02-09 05:18:56 -08:00
Michael Keller
40fc037aa4 Fix handling of gas type for CCR dives.
Fix bug introduced in #3576: On CCR dives cylinders listed as open
circuit bailout by the dive computer need to be set to `OC_GAS`.

Signed-off-by: Michael Keller <github@ike.ch>
2023-02-09 10:51:39 +01:00
Berthold Stoeger
7b44689c8e parser: fix char-not-found checks in import-csv.c
These were two weird and clearly wrong constructs of the
type "if (iter && iter + 1)", where iter is a pointer. This
is always true at best and undefined at worst. Another
instance was removed in 096de0efd0.

The original code probably wanted to check whether the
found character was the last character in the string.
But that likewise seems to make no particular sense in
this context. Therefore, just remove the second part of
the boolean expression.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-02-07 23:43:04 +01:00
Kim Delmar
3c771e2ee2 html export: fix diveguide display
Signed-off-by: Kim Delmar <62100831+KimDelmar@users.noreply.github.com>
2023-02-05 14:32:09 +01:00
Michael Keller
321c8d92dc Improvement: Show gases as diluent by default for CCR dives.
Instead of adding all gases read from a dive computer as part of a dive
log as 'OC-gas', add gases as 'diluent' if the dive has a dive mode of
'CCR'. This creates consistency with the ppO2 for CCR dives being
tracked as sensor readings or a fixed setpoint, and not as the ppO2 of
the current gas ad depth.
A follow up question from this is whether gas use in the cylinders list
on the Equipment tab should be user editable. This seems to be
inconsistent at the moment, with gas constituent percentages downloaded
from the dive computer being editable, but gas use not.

Signed-off-by: Michael Keller <github@ike.ch>
2023-02-01 21:26:48 +01:00
Michael Keller
ada32f999e Cleanup: Remove 'data' field from 'DeviceDetails'.
`device_data_t data` in DeviceDetails has never been populated since it was first
added, and consequently is not used. This is confusing, especially as certain
fields inside `device_data_t` have been added directly to `DeviceDetails` in the meantime (e.g. `firmwareVersion`).

Separated from #3568 as per
https://github.com/subsurface/subsurface/pull/3568#pullrequestreview-1274995287.

Signed-off-by: Michael Keller <github@ike.ch>
2023-01-31 10:54:39 +01:00
Berthold Stoeger
d7ca0c7253 planner: avoid out-of-bounds access
When exiting the loop, stopidx is 0, which means that if there
are no stoplevels, stoplevels[stopidx + 1] generates an
out-of-bounds access. Instead, suppose a stop at 3m or 10ft.

Suggested-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2023-01-19 14:26:00 +01:00
Berthold Stoeger
5525344594 git: don't access global dive site table
When loading a git repository, dive sites where loaded into the
global dive site table, not the local table. Apparently, nobody
ever tried to import a git repository into an existing divelog
(as opposed to opening it in the application). Because that would
have probably given funky results.

Remove this access of a global variable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-15 14:15:11 -08:00
Robert C. Helling
741099bdbb Show correct gas density in CCR mode
When collecting the data for the infobox, we have
already computed the current partial pressures of the
breathing gas taking into accoutn the divemode. Use
those rather than fractions (which for CCR mode are
those of diluent) to compute the gas density.

Reported-by: Pietro Tranquillini <p.tranquillini@gmail.com>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2022-11-08 10:43:47 -08:00
Berthold Stoeger
4bbe5646a5 cleanup: remove unused declarations in planner.h
Most of these declared non existing functions or pointers.
One [get_gas_idx()] was only used in one source file and
doesn't have to be globally accessible

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-01 12:12:19 +01:00
Berthold Stoeger
691d9e86de cleanup: implement index_of() and index_of_if() generics
Search the index of an item in a container. Compare by
equality or a lambda. The lack of these have annoyed me for a
long time. Return the index of the first found element or
-1 if no element found.

Currently, only supports random-access operators. Might be
trivially changed for forward iterators.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-10-31 19:35:15 +01:00
Berthold Stoeger
df5bf728f9 cleanup: remove thumbnail conversion function
The chances that their are still users of the old thumbnail
format (i.e. all thumbnails saved in the hash file) are basically
0. If there are they will just get their thumbnails rebuilt
when opening the individual dives.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-10-30 22:06:17 +01:00
Berthold Stoeger
727d519046 cleanup: use singleton pattern for getPrintingTemplatePath*()
Function-local statics are initialized on first invocation.
No point in extra logic.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-10-30 21:57:44 +01:00
Berthold Stoeger
f407f5269a cleanup: use std::size() instead of arithmetics
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-10-30 21:57:44 +01:00
Berthold Stoeger
e2338fe7e9 core: use range-based for loops in filterconstraints
This source file was looping over descriptors in a classical
"for (int i = 0; i < size; ++i)" loop.

However, the index is not really used, except for fetching the
actual elements.

Replace by range-based for loops. This prevents the potential
error of using the wrong size.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-10-30 21:57:44 +01:00
Berthold Stoeger
cea171ffd4 core: implement an enumerating iterator
In the printing-template code, we loop through a vector and
then determine the index of the current element by searching
the vector. This irks me.

Since looping over a collection with an index is a rather
common theme, implement an enumerating iterator that can
be used as in:
	for (auto [idx, item]: enumerated_range(v)) {
		...
	}

For now, use it for the above vexing case. Convert other
iterations of this theme later.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-10-30 21:57:39 +01:00
Berthold Stoeger
94641c510f core: create range.h header for range manupulation functions
The moveInVector() function was defined in qthelper.h, even
though it has nothing to do with Qt. Therefore, move it into
its own header.

Morover, since it is a very low-level function, use snake_case.
And rename it to move_in_range(), because it does not only
work on vectors, but any range with random-access iterators.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-10-30 21:16:00 +01:00
Berthold Stoeger
261f07dfa4 core: add make_manually_added_dc() function
For reasons of symmetry (there is a is_manually_added_dc()
function), create a make_manually_added_dc() function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-10-21 16:51:57 -07:00
Berthold Stoeger
f687e51d4b core: don't consider dives with many samples as manually added
This causes UI confusion. Notably we go into edit mode and
reduce the number of samples, leading to loss of information.

If someone really manually adds a dive with more than 50
samples, they should still be able to explicitly open the
dive in the planner.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-10-21 16:51:57 -07:00
Linus Torvalds
02f158b0c2 Fix the dc sensor index fixup
fixup_dc_sample_sensors() would make sure that any pressure sensor
indexes were in range of the cylinders by just clearing the pressure
data if the sensor index was larger than the number of cylinders in the
dive.

That certainly makes the sensor index data consistent, but at the cost
of just dropping the sensor data entirely.

Dirk had some cases of odd sensor data (probably because of an older
version of subsurface, but possibly due to removing cylinders manually
or because of oddities with the downloader for the Atomic Aquatics
Cobalt dive computer he used), and when re-saving the dive, the pressure
data would magically just get removed due to this.

So rewrite the sensor data fixup to strive very hard to avoid throwing
pressure sensor data away.  The simplest way to do that is to just add
the required number of cylinders, and then people can fix up their dives
manually by remapping the sensor data.

This whole "we clear the pressure data" was at least partly hidden by
two things:

 (1) in the git save format, we don't rewrite dives unless you've
     changed the dive some way, so old dives stay around with old data
     in the save until explicitly changed.

 (2) if you had multiple dive computers, and one dive computer does not
     have any pressure data but another one does, our profile will use
     that "other" dive computer pressure data (because often times you
     might have only one dive computer that is air integrated, but you
     still want to see the tank pressure when you look at other dive
     computers - or you have one dive computer give pressure data for
     your deco bottle, and another for your travel gas etc).

So those two facts hid the reality that we had actually cleared the tank
sensor data for Dirk's dive with the Atomic Aquatics dive computer,
because we'd still see pressure data in the profile, and the git data
would still be the old one.

Until Dirk renumbered his dives, and the data was rewritten.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-09-20 09:49:57 -07:00
Linus Torvalds
aa50be9cd5 Use the right type for sanitize_sensor_id()
It returned a 'uint8_t', which clashes pretty badly with NO_SENSOR being
-1, and turned it into 255.  That then ended up historically working,
because before commit 0c84f369c3 ("core: use int16_t for sensor-id")
we actually did that everywhere:

 #define NO_SENSOR ((uint8_t)-1)
 ...
    uint8_t sensor[MAX_SENSORS];

but that was changed to

 #define NO_SENSOR -1
 ...
    int16_t sensor[MAX_SENSORS];

and this helper type became wrong.

Just make it return 'int', avoiding any type narrowing issues.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-09-20 09:41:35 -07:00
Linus Torvalds
3446dd5125 fix up sample sensor indexes before fixing up cylinder pressures
The cylinder pressure fixup depends on the sample sensors indexes having
been fixed.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-09-12 16:58:59 -04:00
Berthold Stoeger
0d92ef2835 cleanup: remove unused variable
A QVariant was initialized but never used.

While doing so, remove construct/assign pairs of a number of
QStrings. Directly construct the QStrings with the desired
values.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-09-03 13:49:02 -07:00
Berthold Stoeger
4a7ee872f3 cleanup: move minute formating to format-string.cpp
The get_minutes() function formats a time as m:ss
and returns a static C-string. Since all callers are
C++ anyway and transform directly into QString, let us
move this to the other string formatting function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-09-03 13:49:02 -07:00
Linus Torvalds
34e169aace clean up logging, and add error reports to it too
The SSRF_INFO() macro is widely used, and there's a lot of confusion
about whether the newline at the end should be done by the SSRF_INFO or
be in the format string passed to it.  End result: we end up doing both,
and there are empty lines in the output as a result.

Clean this up by just using our existing 'strip_mb()' to strip any
whitespace at the end of the generated string, and then adding one final
newline when logging it.

Also, make sure to log our 'report_error()' messages, which apparently
only used to be showin in the red error bar on the display.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2022-08-31 13:58:34 -07:00
Berthold Stoeger
6d77d814a8 parser: allow import of dive sites without UUID
Fixes #3493.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-08-31 13:56:04 -07:00
Berthold Stoeger
aa4b48f440 core: move floating point functions to own header file
This were in subsurface-string.h for unknown reasons.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-08-30 22:34:38 +02:00
Berthold Stoeger
61701509b0 core: replace IS_FP_SAME macro by inline function
No reason to keep this as a macro - a function is easier to
read, type safe and easier to debug. Moreover, give it the
more appropriate name "nearly_equal()". After all, it precisely
does NOT check floating points for equality.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-08-30 22:34:38 +02:00
Berthold Stoeger
5db4a95a26 core: don't use relative precision when comparing to 0
The FP_IS_SAME macro uses a relative precision to compare
floating points. This fails when comparing to 0. Therefore,
use an absolute precision in this case. Implement as an
inline function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-08-30 22:34:38 +02:00
Dirk Hohndel
0a4689c2e6 Ratio BLE detection fix
For Ratio dive computers we can't tell by the Bluetooth name which model it is.
There are BT only models and BLE only models. The failure case here was a user
on iOS (BLE only) with a BLE only dive computer which we didn't recognize
because previously we returned a BT only device (which isn't supported on an
iPhone), and the lookup won't return a valid descriptor if the transport needed
isn't available.

These days BLE is far more common, so return a BLE enabled name by default, but
try a BT only name just in case.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2022-08-30 07:20:33 -07:00
Berthold Stoeger
f3221c6965 cleanup: remove unused function set_dive_nr_for_current_dive()
Last caller was removed in a6fa6cdb41.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-08-28 13:34:13 -07:00
Berthold Stoeger
acd385048a Prefer real data over planned
When a dive has both real dive computers as well as at
least a planned version (which is just another dive
computer with a special name), only use the data from
real dive computers for aggregate values like maxdepth,
dive time, average depth etc in order not to have
imagined data on the dive list, statistics etc.

Macro-magic-provided-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2022-08-25 13:38:12 -07:00
Berthold Stoeger
1c00f9f233 core: use free_dive() to free dive
One would think that calling free() on a dive structure, as the code
did in some places, would lead to a memory leak.

(Insert rant about C memory management.)

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-08-22 09:34:25 -07:00
Berthold Stoeger
252761498a liquivision: use uint32_t for event time
This is stored as uint32_t, so no reason to use the larger time_t.
It appears to be, after all, relative to the dive start.

Coverity was complaining about the down-conversion later in the code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-08-22 09:34:25 -07:00
Michael Werle
881a9cac4e cleanup: fix compiler warnings in recently edited files.
Replace NULL -> nullptr
Remove spurious semicolon

Signed-off-by: Michael WERLE <micha@michaelwerle.com>
2022-08-21 18:53:35 -07:00
Michael Werle
efb1832db8 Map Short Names - add preference setting
Adds a preference setting in the "Default" settings tab to toggle whether
to display shortened names in the Map.

TODO: instead of using the generic "settingsChanged" signal, it would be much
more efficient to only update items based on the actual setting which was
changed.

Signed-off-by: Michael WERLE <micha@michaelwerle.com>
2022-08-21 18:53:35 -07:00
Berthold Stoeger
c897edc13e parser: fix DLF import
In bc3b56a969, the import of the dive mode was simplified,
by replacing an if-else-if chain by bit manipulations.
However, the bitmask was wrong: 0b00111000 is 0x38 not 0x30,
which means that "odd" dive modes were not recognized as such.

Bug found by coverity.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-08-20 14:31:39 +02:00