Commit graph

2740 commits

Author SHA1 Message Date
Berthold Stoeger
c05be40bfd core: convert load-git.c to C++
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
d803e42314 core: convert file.c to C++
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
a032d9c979 core: convert save-xml.c to C++
This includes using the C++ version of membuffer. There appears
to not have been a leak, because the buffer is freed in
flush_buffer(), but usage was somewhat inconsistent and hard to
follow.

Also, convert some string handling to std::string to avoid free()
madness.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
76c2069fa8 core: port subsurface-startup.c to C++
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
f1012283a0 core: turn a few string helpers into C++
get_changes_made(), subsurface_user_agent() and normalize_cloud_name()
are only called from C++.

Avoids having to manually free the returned value and is therefore
more robust against leaks.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
924b23ed56 core: convert git-access.c to C++
Had to make sha.h compatible with C++.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
b0438ad1dd core: use C++-style memory management for struct dir
The code is now much easier to check for memory leaks,
since there are no explicit free()s. Yes, memory is not
released immediately, but that should be of no concern.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
371b155922 core: convert core/save-git.c to C++
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
148775f418 core: convert sample.c to C++ and add default constructor
This changes default behavior when creating a sample struct
in C++ code: it is now initialized to default values. If this
ever turns out to be a performance problem, we can either add
additional constructors or use special functions that do
not initialize memory, such as make_unique_for_overwrite.

This removes non-standard (respectively >C++20) constructs,
namely designated initializers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
c27e093ebd core: replace dynamic arrays in dive.cpp by C++ constructs
Avoid error-prone malloc/free pairs. This uses somewhat
obscure constructs to stay as close as possible to the
original C code. Notably, it uses mostly unique_ptr<T[]>
which doesn't store the length of the array, because the
length is supposed to be known.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
52e6a098aa core: convert dive.c to C++
Long term project: convert core to C++ so that we can
use higer-level constructs, notably std::vector<>.

This does not change any code - only fixes compile issues.

Mostly casting of (void *) to the proper type. Also designated
initialization of the sample struct had to be rearranged.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
096e49e15b core: make translate() accessible from C++
In the core, we usually want C strings, not QStrings. Therefore,
make translated C strings directly available from C++.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-10 11:01:42 +13:00
Berthold Stoeger
9d2bd425e1 core: fix memory leak in tables code
The function clear_*_table frees all elements of the table.
However, persumably as a performance feature, it kept the
memory of the table itselt (i.e. it only reset the number of
elements but kept the capacity).

That is fine if the table is reused later. However, this
function was also used when freeing the table and this
would leak the table memory.

This commit frees the table memory. An alternative would
be to have separate clear_*_table and free_*_table functions.
But let's wait with that until we port the table code to C++.
Then this will be "automatically" fixed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-07 07:55:23 -05:00
Berthold Stoeger
805cd550f2 cleanup: fix memory leak
get_local_dir() returns the copy of a c-string. It therefore
has to be free()d.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-03 14:59:31 -08:00
Berthold Stoeger
a4091189b0 cleanup: use proper size when allocating string
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-02 19:21:59 +01:00
Berthold Stoeger
ef5859437a cleanup: remove ominous pointer calculation
Firstly, why calculate something when the next statement is a return
anyway.

Secondly, the calculation subtracts two completely unrelated pointers.

This must be some code reshuffling artifact.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-01 12:28:52 -08:00
Berthold Stoeger
cb3e21c443 cleanup: remove unused data and bogus UNUSED in libdivecomputer.c
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-03-01 07:57:34 -08:00
Michael Keller
3ccd7e4bc7 Import: Add Support for New Dive Computer Models Supported by Libdivecomputer.
Add support for the new dive computer models that have been added in the
latest version of libdivecomputer.

Signed-off-by: Michael Keller <mikeller@042.ch>
2024-02-28 15:38:48 +13:00
Michael Keller
f495c4f002 Import: Update libdivecomputer to the Latest Version.
Update `libdivecomputer` to the latest upstream version.

Signed-off-by: Michael Keller <mikeller@042.ch>
2024-02-28 15:38:48 +13:00
Berthold Stoeger
bf5510e5a6 cleanup: remove bogus forward declaration of inexistent structure
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-02-27 13:14:34 +01:00
Berthold Stoeger
fac006148f profile: make event hiding persistent across change of dive
Currently, the "hide event" status is lost when switching dives.
Save it in the event struct instead to make it persistent.

In the future we might save this information to the log file.
Then this should be integrated in the undo-system.

This commit also makes the "unhide events" menu entry more
fine grained: It now differentiates between individual
events and event types.

Note this adds an additional field to the event structure.
There is a "deleted" field that is used internally for
book-keeping, but probably should be removed. Not touching
this at the moment as long as this is C-only code. When/if
switching to C++ we can make the event linked list a table,
which will make this much simpler.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-02-23 09:46:16 -08:00
Berthold Stoeger
4422dbb52b events: make event severity explicit
Currently the event type code uses libdivecomputer's flags
to differentiate between events. Make this explicit and extract
the event severity.

The reason is that later we want to be more explicit about showing/
hiding events and thereto we must format the name of events.

Moreover, this encapsulates the complexities of extracting
the severity in the event code (that used to be in the profile
code).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-02-23 09:46:16 -08:00
Berthold Stoeger
6ad7e577f1 core: pass event to event_type functions
Instead of passing name / flag pairs to event_type functions,
pass a pointer to the event. This hides implementation details.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-02-23 09:46:16 -08:00
Berthold Stoeger
d3c9cb14bf core: rename eventname.* to eventtype.*
This structure is used to hide events of a certain type.
The type was inferred from its name, but now includes flags.
So event_type is more appropriate.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-02-23 09:46:16 -08:00
Michael Keller
1309064873 Profile: Reinstate Hiding of Events by Type across Dives.
Reinstate the hiding of events by event type across
all dives in the log. This was unintentionally removed in #3948.
Also change the event type to be specific to name and severity, and fix
bug causing 'Unhide all events' to not show when only individual events
were hidden.

This still leaves the inconsistency that hiding of similar events is
persisted across the switch between dives, but hiding of individual
events is lost when switching dives, which is mildly confusing.

Follow-up to #4092.

Signed-off-by: Michael Keller <github@ike.ch>
2024-02-12 12:27:59 +01:00
Berthold Stoeger
02055ba067 planner: fix crash when planning with surface interval
The planner uses a one-past-end pseudo cylinder for marking the
surface interval outside of water. This overflowed arrays in
setup_gas_sensor_pressure().

See #4086. Note: contains a second unrelated crash report.

As a band-aid allocate bigger arrays. But obviously, the proper
fix is to not generate invalid gas-change events.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-02-07 12:19:04 -08:00
Michael Keller
df1974a244 Mobile: Fix Configuration of Ceiling Display.
Fix the configuration of the deco ceilings in the mobile version:
- make the settings work;
- remove reading of the dive computer ceiling from git;
- hide the gradient factor in the profile when the calculated ceiling is
  not shown;
- when the calculated ceiling is disabled in the settings, disable
  editing of the gradient factor.

Signed-off-by: Michael Keller <github@ike.ch>
2024-02-06 11:58:49 +13:00
Richard Fuchs
caf2f8c102 core: return error from parsing failure
If the XML document could not be parsed then `root_element` will come
out as NULL. Check this before trying to dereference it.

Signed-off-by: Richard Fuchs <dfx@dfx.at>
2024-01-28 12:00:32 -08:00
Robert C. Helling
e794efaba6 Allow for more O2 sensors
The Divesoft Liberty has four O2 sensors. So far, we had a hard coded
limit of three sensors and crashed with a failed assert when we
encoutered more than three. This allows for up to
MAX_O2_SENSORS which is currently 6. The voting logic is adapted
accordingly: We sort the values and we keep deleting the values that
differ more than 20% by value from the closest. This follows what
Shearwater implements on their computers.

In some of the import/export functions the value is still hard
coded to 6 thanks to explicit field names.

Signed-off-by: Robert C. Helling <helling@lmu.de>
2024-01-23 19:24:53 +01:00
Berthold Stoeger
429230ced1 saving: fix resource leak found by coverity
fp_get_data() returns a copy of a string that must be freed.
Fix this in save-git.c. The analogous function in save-xml.c
has already been fixed. However, change the code to be more
idiomatic: since we own the pointer, make it "char *" instead
of "const char *". Then we don't have to cast on free().

Ultimately, we really should change string manipulation code
to C++.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-01-17 14:23:19 -08:00
Berthold Stoeger
91e4fb4769 cleanup: more Coverity silencing
Mostly irrelevant std::move() stuff of copy-on-write Qt objects,
a few real bugs, a timestamp_t downconversion and some codingsyle
adaptation.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-01-17 14:23:19 -08:00
Berthold Stoeger
13b894a756 gases: fill result of isobaric_counterdiffusion() on early return
If prefs.show_icd is false, this function does nothing, but
the output parameter is checked by the calling function
DiveEventItem::setupToolTipString().

Let's reset the strucvture to 0.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-01-16 14:22:16 -08:00
Berthold Stoeger
249b82f6dc pictures: make delta-time a 64-bit int
When adjusting picture times, the offset in seconds is stored in a
32-bit int. Make it a 64-bit int. Sounds crazy, because why would
you want to move the pictures by more than 70 years?

Well, suppose it is the year 2039, for some strange reason your
camera was set to unix epoch and you want to adjust the pictures
to current time.

Ok - that's a far-fetched scenario. The real reason is that this
hopefully silences a Coverity warning and avoids integer casting.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-01-15 15:11:36 -08:00
Berthold Stoeger
8a3a0edb83 cleanup: silence std::move()-related Coverity warnings
Unfortunately Coverity doesn't understand that most Qt data
structures are copy-on-write. It's a mis-feature of Qt, but
it is the way it is. Thus, passing by value is not an issue.

Out of ca. 25 warnings only two were legit. Let's silence
the others by either std::move()ing or passing by reference,
as would be idiomatic C++, which Qt is not.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-01-15 15:11:36 -08:00
Berthold Stoeger
798e426926 cleanup: fix enum in profile.c
There are two enums related to the type of dive.
There is the global

enum divemode_t {OC, CCR, PSCR, FREEDIVE, NUM_DIVEMODE,
                 UNDEF_COMP_TYPE};

and the anonymous

enum {AIR, NITROX, TRIMIX, FREEDIVING} dive_type;

in struct plot_info.

In profile.c FREEDIVE (of divemode_t) is assigned to dive_type.
This only works because by chance(?) FREEDIVE and FREEDIVING are
the fourth element of each enum.

Fix this. C truly is a bad language when it comes to types
(very weak) and namespaces (non existing).

Contains whitespace fix.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-01-13 09:14:32 -08:00
Dirk Hohndel
0a46068501 remove app uuid
This hasn't been used on the backend in a long time (and appears to get
stripped out on several platforms). No point in keeping it around.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2024-01-07 16:01:55 -08:00
Dirk Hohndel
ef35c3e8cb update copyright year and version details
While the update to the copyright year really isn't required, it just looks
better.

By using the canonical instead of the git version in user visible strings we
are creating more consistency in how we refer to the version.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2024-01-07 16:01:55 -08:00
Dirk Hohndel
62477d8c65 Complete redesign of Subsurface version numbers
- for now all versions start with v6.0
- CICD builds use the monolithic build number as patch level, e.g. v6.0.12345
- local builds use the following algorithm
  - find the newest commit with a CICD build number that is included in the
    working tree
  - count the number of commits in the working tree since that commit
  - if there are no commits since the last CICD build, the local build version
    will be v6.0.12345-local
  - if there are N commits since the last CICD build, it will be
    v6.0.12345-N-local
- test builds in the CICD that don't create artifacts simply use a dummy release
  in order to not incorrectly increment the build number and also not to waste
  time and resources by manually checking out the nightly-build repo for each of
  these builds.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2024-01-06 10:55:24 -08:00
Dirk Hohndel
58fb49f243 retire the mobile version
Both Subsurface and Subsurface-mobile will share the same version number moving
forward.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2024-01-06 10:55:24 -08:00
Michael Keller
de5311033c Planner: Increase CCR Setpoint Precision to 0.01.
Increase the precision of the setpoint that can be specified per planned
leg of the dive to 0.01 mbar.
Some rebreather models (APD Inspiration) support this precision for
setpoint setting.

Motivated-by: https://groups.google.com/g/subsurface-divelog/c/pD5gYlG5szI/m/G8_as4TyBwAJ
Signed-off-by: Michael Keller <github@ike.ch>
2024-01-02 10:28:30 -08:00
Dirk Hohndel
3e82973361 some explanations for the different servers
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2023-12-29 14:20:52 -08:00
Dirk Hohndel
f4cac010ae additional git error info
I ran into this a couple of times where the debug output didn't seem to
make any sense until I understood that libgit simply didn't give me
detailed error info.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2023-12-29 14:20:52 -08:00
Dirk Hohndel
7792e227da add two more cloud servers to the rotation
This is not a great way to load-balance, but it works and doesn't require
high end hardware on the backend.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2023-12-29 14:20:52 -08:00
Dirk Hohndel
8e212c0858 Fedora Rawhide builds fail without stdlib include
Implicit declarations of malloc, free, atoi, and others are considered an
error now.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2023-12-04 12:55:10 -08:00
Micha WERLE
c612641517 fix: actually default bottom gas to air
If there are no gas mixes returned by libdivecomputer, we need to default to air. The previous commit would have defaulted to pure oxygen.

Signed-off-by: Micha WERLE <micha@michaelwerle.com>
2023-11-21 22:30:45 +13:00
Micha WERLE
4842344bc1 feat: extend bottom gas instead of last mix
During code review, an argument was made to use the bottom gas mix as
the mix to fill additional tanks with instead of the last mix reported
by the dive computer.

This change implements `get_deeper_gasmix` which compares two gas mixes
and returns the one with the lower MOD. This comparison does not perform
actual MOD calculations but only performs a  relative oxygen and helium
content comparison.

Instead of saving the last gas mix and assigning it to additional tanks,
a `bottom_gas` mix is saved and assigned instead.

Signed-off-by: Micha WERLE <micha@michaelwerle.com>
2023-11-21 22:30:45 +13:00
Micha WERLE
d0b95f9401 refactor: revert questionable optimisation
Reverted "optimisation" based on code feedback.

Firstly, it's implementation-defined whether or not a stack frame is created for sub-scopes, secondly any optimisation is questionable regardless, and thirdly it was felt that it makes the code harder to understand.

Signed-off-by: Micha WERLE <micha@michaelwerle.com>
2023-11-21 22:30:45 +13:00
Micha WERLE
c7171179b3 Core: extend last gas mix instead of defaulting to air.
Instead of defaulting to air when we run out of gas mixes to assign to
cylinders, use the last gas mix provided by the dive computer.

If no gas mixes are provided at all, then default to air.

This prevents Subsurface from "inventing" gas mixes which are not
reported by the dive computer. It also works very nicely with a sidemount
configuration where the dive computer typically reports two cylinders but
only a single gas mix.

Signed-off-by: Micha WERLE <micha@michaelwerle.com>
2023-11-21 22:30:45 +13:00
Jef Driesen
1abf400c63 Return the actual libdivecomputer error code
The divecomputer_device_open() function tries all supported transports
one by one, and exits as soon as one is opened successfully. When the
end of the function is reached, the DC_STATUS_UNSUPPORTED error code is
returned.

The annoying side effect is that the actual error code returned by the
transport is ignored and changed into DC_STATUS_UNSUPPORTED. This is
very confusing while troubleshooting download problems.

Fixed by initializing the error code to DC_STATUS_UNSUPPORTED, in case
no transport is available for trying, and returning the last reported
error to caller.

Signed-off-by: Jef Driesen <jef@libdivecomputer.org>
2023-11-05 06:54:40 +13:00
Jef Driesen
2a3c0d981f Add BLE detection for the Aqualung i330R and Apeks DSX
Add the Aqualung i330R and Apeks DSX model numbers to the Pelagic
pattern table. These two models also use a new BLE service UUID.

Signed-off-by: Jef Driesen <jef@libdivecomputer.org>
2023-11-04 23:03:09 +13:00