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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
`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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>