Commit graph

2535 commits

Author SHA1 Message Date
Berthold Stoeger
efab955d85 cleanup: make feet_to_mm signed
Depths are pretty much universally stored using signed integers
(e.g. depth_t is signed int). For consistency, make feet_to_mm()
likewise return a signed value.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-01-02 13:51:07 -08:00
Berthold Stoeger
4f1034b605 cleanup: make a variable signed
The prev_time variable was defined as unsigned and mixed
with signed variables. gcc rightfully complains with -Wextra.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-01-02 13:51:07 -08:00
Berthold Stoeger
c43311614e cleanup: remove obsolete includes in core/device.cpp
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-01-02 13:51:07 -08:00
Berthold Stoeger
72ad4cedf5 cleanup: replace strcmp by std::string methods
Since these are std::strings anyway, there seems to be no point
in using the C-lib functions. YMMV, but to me that code is
distinctly more easy to parse.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-01-02 13:51:07 -08:00
Berthold Stoeger
66896ad7d7 cleaup: remove device::operator==()
The last user was removed when including devices in the undo
system.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-01-02 13:51:07 -08:00
Berthold Stoeger
c893d19ea4 cleanup: pass all parameters to weightsystem_t
With -Wextra, gcc/g++ complains that compound initialization
of weightsystem_t misses the auto_filled parameter. Add it.
For C++ code we might think about writing a constructor. However,
we use two versions: with and without copied string.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-01-02 13:51:07 -08:00
Berthold Stoeger
d89ef3d906 cleanup: fix narrowing type conversion warning
In pscr_o2() the result of a double calculation was implicitly
converted to int, which resulted in a gcc warning.

Part of the expression was explicitly converted to int, but then
subtracted from a double.

Instead, do all the calculations in double and cast the final
expression to int. This is probably the prudent thing to do.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-01-02 13:51:07 -08:00
Berthold Stoeger
2645fa1495 profile: remove fast argument of create_plot_info_new()
This prevented calculation of the pressure data when dragging
planner handles. However, this lead to weird artifacts.

As an alternative, if this turns out to be too slow, we might
disable the plotting of the pressure curves instead.

That said, even on my super-slow fanless laptop, this performs
reasonably.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
725fda3cd1 profile: don't add excessive depth
The old get_maxdepth() function in profile.c was accounting for
two things:
- the partial pressure graphs
- rounding to sane value

Both are now taken care of by the profile itself. This leads to
excessive max-depths. Remove the code from profile.c.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
789eb2c620 profile: clear plot_info structure when freeing data
free_plot_info_data() frees the sample and pressure arrays
and accordingly sets the corresponding pointers to NULL.

However, it doesn't clear the element-count and thus leaves
the structure in an inconsistent state.

Clear the whole structure with memset(). I am not a fan of
doing so, but there are existing memset() calls in the
same source file, so let's keep it like that for consistency.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
01af4bcd00 profile: remove min/max entries from plot_data
These were the minimum and maximum of a 9-min window.
The profile now uses an adaptive peak-search, so this is not
used anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
0e9eee0a7f core: return floating point from to_PSI() functions
Dive data are stored internally using integral types using
appropriately fine units (mm, mbar, mkelvin, etc.). These
are converted with functions defined in units.h for display
(m, bar, C, etc.). Usually floating points are returned by
these functions, to retain the necessary precision. There
is one exception: the to_PSI() and mbar_to_PSI() functions.

For consistency, make these functions likewise return floats.
This will be needed for the rework of the profile-axes.
The plan is to use the conversion functions to make the
axes aware of the displayed values. This in turn will be
necessary to place the ticks at sensible distances. However,
the conversions need to be precise, which is not the
case for the current to_PSI() functions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
9e831c5001 core: remove DPR from IconMetrics class
There is no user of this left, because the device-pixel-ratio
is now passed directly to the profile.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
f7565c4a0f core: clear image before rendering SVGs
In renderSVGIconWidth() the image was not cleared, leading
to garbage backgrounds. This should have affected the video
icons. Apparently, nobody is using them..?

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
f82ae2be7f profile: cache pixmaps for dive event items
For better scalability, we might replace the dive event icons
by SVGs. Since rendering SVGs is potentially very slow, cache
the pixmaps when the scene is generated.

Note: this does not yet do any SVG rendering, only the caching
of pixmaps.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
24cf6709e3 profile: simplify get_maxtime()
This function has accumulated quite some cruft. It seems to add
additional space to make place for certain chart features
(e.g. the average depth text item).

However, it makes no sense to solve this here, as only the
profile knows how much place is needed to display these
features.

Therefore, basically revert this to the original version,
which simply returns the maximum time for long dives
and a threshhold for short dives that depends on the
zoomed_plot setting.

The result looks more reasonable to me, as there is no
(varying!) empty space to the right of the profile.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
d1b8f1ca3d formatting: move get_trip_title to string-format.h and split it
To enable grouping by trip in the statistics module, split
the get_trip_title() function in a version that appends
a "(n dive(s)" string an one that doesn't. The statistics
module doesn't want that added string, since it displays
the number of dives in a different way.

Also, move the functions to string-format.h, where these
are collected. And rename them to camelCase. Yes, it's
ugly, but consistent with most other C++ code in the code
base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 10:36:13 -08:00
Berthold Stoeger
afa989e32c cleanup: replace std::size() replacement by real deal
At other places, we already used std::size().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 10:36:13 -08:00
Dirk Hohndel
61e8ceef05 core: avoid resource leak
That code was obviously wrong from the start.

Fixes CID 373921

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-12-17 09:23:34 -08:00
Dirk Hohndel
cffcce77bb core: avoid uninitialized data
In an abundance of caution, make sure all fields are initialized.

Fixes CID 350734

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-12-17 09:23:10 -08:00
Berthold Stoeger
1af67512a1 cylinders: add cylinder before hidden cylinders
When adding a cylinder, it was added at the end of the list.
This would make hidden cylinders visible as the new rule is
to only hide unused cylinders at the end of the list.

Therefore, add the cylinder after the last used cylinder,
i.e. before the first hidden cylinder.

This means that the position where the cylinder is added has
to be hidden in the undo command.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-13 11:54:24 -08:00
Robert C. Helling
9fd531dcc5 Round gas depth properly
The D in MOD, EAD, END, and EADD stands for "depth" and
as such these should be mm in int rather than double.

The intermediate fn2 and fhe2, however, as intermediate
value should not be rounded to an integer.

The upshot of this is a litle more numerical stability.
It should lead to more stable values in TestProfile
when run on architectures with different floating
point precision.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2021-12-06 22:29:04 +01:00
Robert C. Helling
07745893e5 Don't attempt to compute SAC for CCR dives
CCRs are different. It does not make sense to compute
a depth dependent SAC. You could compute the rate of O2
consumption but even that is likely wrong (as O2 in the
diluent would enter that as well), so simply don't attempt
it.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2021-11-24 11:03:51 -08:00
Dirk Hohndel
cfd6a1634f cleanup: fix SkipEmptyParts warning for mobile
And while doing that, have all the cases where we already include
qthelper.h simply use a define in that header file - but keep the two
other instances of the define where the C++ source don't need qthelper.h
otherwise.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-11-24 10:53:26 -08:00
Dirk Hohndel
31e688ec00 core: load and save fingerprint to cloud storage
Very similar structure to the XML format. Raw data is again saved as a
hex string (which implicitly provides us with its length). The rest of
components are in a more human readable format.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-11-12 12:45:22 -08:00
Dirk Hohndel
2b1db9da82 core: load and save fingerprints to XML
We always use the global fingerprint table - maybe this should just not
be a parameter of the accessor functions?

The syntax is very simple - the raw data is encoded as a hex string, the
rest of the components are hex numbers.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-11-12 12:45:22 -08:00
Dirk Hohndel
33527cb9e5 core: add more C interfaces for fingerprint table
These are used to read/write fingerprint records as git or XML data from
C code.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-11-12 12:45:22 -08:00
Dirk Hohndel
02c770d997 core: use fingerprint table and on disk fingerprints
In order to not break existing behavior, we still store fingerprints on disk, but
we first check the data in the in-memory table, and we remember the fingerprint data
in the fingerprint table as well (which is then saved as part of the dive log data).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-11-12 12:45:22 -08:00
Dirk Hohndel
fa250906c9 core: add structures for handling fingerprints
This just adds the basic structures and the accessor functions needed to
manage a table of fingerprint data. The table is indexed by the hash of
the model name and binary serial number as created by libdivcecomputer.
This way the data is accessible when libdivecomputer fist accesses a
dive computer (which is the point in time when we need to use the
fingerprint.

The table also contains the corresponding device id and dive id so we
can verify that the current dive table still contains that dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-11-05 10:36:56 -07:00
Dirk Hohndel
95192bdf83 core: move has_dive helper function
This way it can be used by other code that needs this capability.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-10-30 20:22:52 -07:00
Dirk Hohndel
838151835b dc-download: use short date string
In both places in the UI where we show the date of a dive during
download we are actually pressed for space. So let's use the short
version of the date string to save some space.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-10-29 15:14:59 -07:00
Dirk Hohndel
44691dae10 dc-download: fingerprint details are debug info
In the normal use of the app this information is simply too verbose.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-10-29 15:14:59 -07:00
Dirk Hohndel
10e6519ad5 dc-download: give progress update for long downloads
Most divecomputers download data dive by dive - so we get reasonably
frequent updates during the download (as new dives are found and posted
in the progress text area). But some (like the G2) download all of the
new dives at once and only then start parsing them. As a result the
download can look like it is hung.

As a compromise this shows updates on the data received in 10kB
increments. Which for most cases should never be shown and therefore not
make the user experience any worse - but for cases like the G2 will make
a huge difference.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-10-29 15:14:59 -07:00
Dirk Hohndel
8e4b2d9b82 cleanup: replace QRegExp with QRegularExpression
Qt 6 will drop support for QRegExp.
Use QRegularExpression instead.

Much of this is a simple replacement of one class with the other, but
there are some changes to the way matches are tracked and captures are
created. Also, the exactMatch now needs to be implemented via anchors in
the regular expression itself.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-10-27 12:35:09 -07:00
Dirk Hohndel
4d0c863d61 cleanup: replace QRegExp with QRegularExpression
Qt 6 will drop support for QRegExp.
Use QRegularExpression instead.

This is a straight forward replacement without any other code changes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-10-27 12:33:20 -07:00
Berthold Stoeger
540e4437d5 cleanup: fix conversion warning
Fix a pair of warnings, which annoyed me for a long time:
For some reasons prefs.bottompo2 is an integer (mbar)
whereas prefs.modpO2 is a float (bar). This results
in mixed integer/floating point arithmetics when
conditionally using either of them. And ultimately
a warning, when storing a mbar value as an integer.
Fix this by an explicit cast to int after converting
modpO2 to mbar.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-10-16 15:32:56 -07:00
Robert C. Helling
41258647d2 Don't access gasmix.o2.fraction
Air is a special gas that does not contain oxygen according
to gasmix.o2.fraction. If you want to use the fo2, you
need to use get_o2() to treat this special case correctly.

This fixes a bug when setting the MND of a gas containing
21% oxygen when o2 is considered not narcotic.

Reported-by: Christoph Gruen <gruen.christoph@gmail.com>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2021-10-01 08:50:36 -07:00
Berthold Stoeger
a481cdc13d core: don't write pressure samples with "no sensor"
This has led to broken XML files, don't do it.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-09-22 09:11:00 -07:00
Berthold Stoeger
d9c77a27da core: properly clear pressure data of invalid sensors
When we found an invalid sensor (referring to a non
existing cylinder) in fixup_dive() the sensor-id was
set to NO_SENSOR.

This led to invalid XML files, because the code decides
to switch into legacy mode. However, there are two
pressure readings, which is invalid in legacy mode.

Therefore, also clear the pressure data.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-09-22 09:11:00 -07:00
Dirk Hohndel
8525b2e274 core: remove superfluous arguments
Fixes CID 373231

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-09-20 14:49:57 -07:00
Linus Torvalds
85392343fa Re-do the libdivecomputer fingerprint save/load code
This tries to make our fingerprinting code work better, by avoiding
using the "deviceid" field that has always been unreliable because we've
calculated it multiple different ways, and even for the same version of
subsurface, it ends up changing in the middle (ie we calculate one value
initially, then re-calculate it when we have a proper serial number
string).

So instead, the fingerprinting code will look up and save the
fingerprint file using purely "stable" information that is available
early during the download:

 - the device model name (which is a string with vendor and product name
   separated by a space)

 - the DC_EVENT_DEVINFO 32-bit 'serial' number (which is not necessarily
   a real serial number at all, but hopefully at least a unique number
   for the particular product)

but because the model name is not necessarily a good filename (think
slashes and other possibly invalid characters), we hash that model name
and use the resulting hex number in the fingerprint file name.

This way the fingerprint file is unambiguous at load and save time, and
depends purely on libdivecomputer data.

But because we also need to verify that we have the actual _dive_
associated with that fingerprint, we also need to save the final
deviceid and diveid when saving the fingerprint file, so that when we
load it again we can look up the dive and verify that we have it before
we use the fingerprint data.

To do that, the fingerprint file itself contains not just the
fingerprint data from libdivecomputer, but the last 8 bytes of the file
are the (subsurface) deviceid and the diveid of the dive that is
associated with the fingerprint.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-09-19 16:51:46 -07:00
Dirk Hohndel
2a0d14b100 core: remove location service preferences
Including the related tests.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-09-13 11:21:34 -07:00
Dirk Hohndel
6f813b9f8e mobile: remove GpsLocation
Only used in context of acquiring GPS locations with the mobile app, which
we no longer do.

Keep the DiveAndLocation structure around as that's needed by the
ApplyGpsFixes command.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-09-13 11:21:34 -07:00
Dirk Hohndel
bea552bf0d mobile: remove GpsListModel
This is only needed to show the list of GPS fixes obtained with
the now removed location service.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-09-13 11:21:34 -07:00
Josh Torres
7e6d9935f1 core: fix off-by-one causing incorrect profile display
In commit 4724c88 get_plot_details_new was updated to pass an index
instead of the entry into plot_string. This means we are passing "i" to
plot_string after the final increment of the for loop, instead of
getting the entry[i] within the loop before the final increment. This
means if we are mousing over the far right of the graph, where the time
based break is not hit, we will end up passing an index equal to nr-2
instead of nr-3, which is intended to shave off the final two rows
containing data not useful to the display.

There are a handful of ways to fix this. This commit intends to be
consistent with stylistic choices made elsewhere in the project.

Signed-off-by: Josh Torres <torres.josh.j@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-09-06 13:00:37 -07:00
Berthold Stoeger
28fe6a7b38 core: add a function to test for sensors of a given cylinder
We want to prevent the user from accidentally deleting a
cylinder with sensor readings. Therefore, we need such a
function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-09-03 13:35:28 -07:00
Berthold Stoeger
5eda1c0e39 parser: XML_PARSE_RECOVER to xmlReadMemory()
Due to changes in the handling of sensor-ids, invalid XMLs were
generated. In particular, these contained duplicate attributes
in the sample tags.

Even though these files shouldn't exist, let's try to parse
them anyway. Some data will be lost, but that's better than
not opening the file.

libxml2 can be told to try to recover from such petty(?) errors
by passing the XML_PARSE_RECOVER flag.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-09-03 09:30:34 -07:00
Robert C. Helling
c634a07e38 Planner: Correctly compute CNS and OTU for bailout segments
For dives with mixed divemode, one needs to check sample.setpoint
to figure out if the segment is an OC segment and the po2 needs
to be computed from the gasmix and ambient pressure.

This fixes #3310

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2021-08-19 10:58:08 -07:00
Dirk Hohndel
e7a5ec46f5 undo/device: adjust device management infrastructure
We no longer need the remove infrastructure, and the edit nickname function
becomes much more intuitive to use by passing in the dive computer for
which we want to create a nickname instead of the internal index into
the array of devices.

This also removes / simplifies the device list update signals in the
DiveListNotifier.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-08-18 13:22:02 -07:00
Dirk Hohndel
fbe17e620e core: add get_or_add helper for dc table
This makes it much easier to manipulate dc nickname entries. In order
for that to work we can't simply remove entries with empty nickname (but
that isn't needed, anyway, as the code that saves XML or git already
handles that case correctly).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-08-18 13:22:02 -07:00