The create_plot_info_new() function releases old plot data. This
can only work if the plot_info structure was initialized previously.
The ProfileWidget2 did that by a memset, but other parts of the code
did not.
Therefore, introduce a init_plot_info() function and call that when
generating a plot_info struct. Constructors would make this so much
easier - but since this is called from C, we can't use them.
Fixes#2251
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
I got confirmation from Tiago Thedim Dias that my libdivecomputer patch
makes BLE downloading work from the i200c, and already pushed out the
libdivecomputer changes earlier. This updates the subproject in
subsurface to have those changes.
This also adds the bluetooth name patterns for the i300c and a few other
Aqualung dive computers we hadn't added yet. That should make them show
up in the bleutooth device list even without having to check the "Show
all bluetooth devices" check-box.
Tiago claims he didn't need that, and I wonder if we have some overly
permissive match somewhere, but it's the right thing to do regardless.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Instead of generating cylinder data in the form of
CylinderObjectHelper objects for every DiveObjectHelper,
generate it only if needed. DiveObjectHelper is used extensively
in the mobile interface, which doesn't use the cylinder data.
Let's not generate unnecessary CylinderObjectHelpers in this
case!
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
CylinderObjectHelper is used for structured formatting of cylinder
values in grantlee types. Instead of keeping a reference to a
cylinder, turn it into a value type containing the formatted strings.
This should be distinctly safer, as we don't risk having stale
references flying around. Moreover, we don't have to use pointers
but can use containers containing plain CylinderObjectHelper. Thus,
no explicit memory management is needed, making the code distinctly
easier to understand.
Sadly, currently grantlee does not support Q_GADGET based Q_PROPERTY.
Therefore a GRANTLEE_*_LOOKUP block has to be added. This can be
removed in due course, as a patch to remedy this issue is in current
grantlee master.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We used a table lookup for CNS equivalent times. Turns
out the log of this table falls pretty much on a straight
line for po2 <= 1.5bar. We now fit this tabel two two
lines, one for <= 1.5 bar and one above. This four
parameter fit has half the sum of errors squared
than the five parameter fit using a fourth order
polynomial.
Fitting the log has the advantage that this never
crosses 0, which would have the bad effect of
resulting in negative CNS values as we divide
by the table value.
We don't adopt a maximum pO2 cut-off for the CNS calculation
but rather live with the large values that the interpolation
formula produces when extrapolating.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
It turns out that the dive site saving was subtly but horribly buggy.
To save the value of the dive site, it did
show_utf8_blanked(b, t->value, " value='", "'/>\n", 1, anonymize);
which looks sane on the face of it, but the problem is that it puts the
final closing xml marker in the 'append this at the end' case.
That means that if the value is empty, the value won't be saved, but
neither will the closing tag. Resulting in an xml line that looks like
this:
<geo cat='3' origin='0' <geo cat='5' origin='0' value='Other name'/>
where the first geo tag was saved without the ending marker.
That then makes all the xml nesting entirely wrong, and the whole file
fails to save.
Now, the code around it does check that 't->value' is not NULL, but it
doesn't check for a value that is empty or all spaces (which also will
make 'show_utf8()' just skip it.
Fix it by saving the end marker separately:
show_utf8_blanked(b, t->value, " value='", "'", 1, anonymize);
put_format(b, "/>\n");
so that the xml is valid even if the goe marker value wasn'r.
Reported-by: Bob Barker <barkerb1965@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
It needs a newer version of libdivecomputer to actually download, but
early very experimental code exists in the Subsurface-NG branch.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
We don't support null-dives in DiveObjectHelper. Defaulting the
dive parameter to NULL seems to send the wrong message.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When removing the max-weightsystem restriction, the semantics of
the DiveObjectHelper::singleWeightSystem() function changed:
it now returned false for "no weightsystem". Change it back,
to 0 or 1 weightsystems, because the mobile frontend uses this
to check whether it can edit dive systems.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
I'm not sure about this one, as we test name at the start of the
function and event->name shouldn't be NULL, but hey, we have the safe
compare function, so let's use it.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Header files should compile regardless of order of inclusion.
Since libdivecomputer.h uses FILE unconditional include of
stdio.h is the correct thing to do.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Enough gas was checking the currently displayed dive instead of the
dive to be planned. Not good in a multi-threaded context. Pass the
actual dive instead.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Pass the dive to be planned to track_ascent_gas and don't use
the displayed_dive. For convenience, pass the cylinder-id, since
the function can now access the cylinder of the dive by itself.
This makes the callers less verbose.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The function comment talks about overwriting displayed_dive, when
in reality the function overwrites a passed in dive.
Also fix a debug-call which dumped the displayed_dive, not the
actual dive to stdout.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The fill_default_cylinder() function calculated the MOD based
on the currently displayed dive. This does not seem to make sense:
- When importing dives, why would we care about the altitude and
salinity of the currently displayed dive, possibly from a different
trip.
- The planner is supposed to be thread-safe and should not touch
global variables.
Of course this means that the importing-functions have to fill
out altitude and salinity before creating the default cylinder,
but this is their problem. For a freshly created dive they will
get the default values, which still seems less random than the
values from the displayed dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of passing the global displayed_dive to
calc_crushing_pressure(), use the dive the planner is working on.
A small step in making the planner thread-safe.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The parser had global state in the form of a linear regression
and the "plot_depth" variable. Collect that in the deco_state struct and
pass it down the call-chain. Move out the code to update the
regression data to not bother other callers of tissue_tolerance_calc().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
A number of architecture-dependent functions were declared in
dive.h. Move them to file.h so that not all file-manipulating
translation units have to include dive.h. This is a small step
in avoiding mass-recompilation on every change to dive.h
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Move the declarations of the "report_error()" and "set_error_cb()"
functions and the "verbose" variable to errorhelper.h.
Thus, error-reporting translation units don't have to import the
big dive.h header file.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Replace a macro calculating a degree-three polynomial by an
inline function.
Moreover, calculate the powers 1, 2 and 3 of the pressure inside
the function. The compiler will be smart enough to optimize this
to the same code. The only important thing is to write "x*x*x*coeff"
instead of "coeff*x*x*x". The compiler can't optimize the latter
because ... wonderful floating point semantics.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The planner can produce negative cylinder pressures when
more gas is used than available. Let's color the pressure
graph in a highly visible color to alert the user of the
fact that current gas planning is insufficient.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
The curve fitting for our gas compressibility was only done in the sane
range of 0-500 bar, which is what a scuba cylinder can reasonably be
expected to perhaps have.
But the planner ends up happily using negative cylinder pressures when
you run out of gas, and then the compressibility gives nonsensical
results.
That's clearly a planner bug, but the nonsensical gas compressibility
values made it harder to see what could be wrong.
So we just clamp the inpot range to the range we have verified against
experimental data. If you try to get compressibility for negative
pressures, you get the compressibility for an ideal and imaginary gas.
And if you try to get compressibility for pressures over 500 bar, we'll
just assume that it's 500 bar.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
For better encapsulation, use clear_git_id() in clear_dive_file_data()
instead of setting saved_git_id directly.
Thus, memory management of the saved_git_id value is encapsulated
and can be modified more easily.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The git parser was using a number of global static variables. Remove
them by introducing a parser state, which is passed down to the
call hierarchy.
Advantages:
1) Removes global variables and makes the parser (mostly) reentrant.
2) More flexible - e.g. when parsing samples, the parser can now
access the dive to check if the cylinder number is valid.
3) Less weak typing through "void *".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The function get_divemode() and git_tree_entry_blob() were not used
outside of load-git.c. Make them of static linkage.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
copy_cylinders() copied the cylinders of one dive onto another dive
and then reset to the original gas values. Presumably, when copy and
pasting cylinders from one dive to another, only the types should
be copied, not the gases.
Moreover, the function could either copy all or only the used cylinders.
Firstly, the code was bogus: when restoring the pressures the indices
were mixed up: the old indices were used. Thus, when there where
uncopied cylinders, not all pressure values were restored.
Secondly, it is not clear that all callers actually want to restore
the pressure data. It rather appears the two (out of three) callers
actually just want to copy the cylinders.
Therefore, split the function in
1) copy_cylinders(): copy the cylinders with pressure data
2) copy_cylinder_types(): copy only the cylinder information
Since there is only one caller of copy_cylinder_types(), the "used_only"
argument can be removed. Since all cylinders are copied there is
no point in storing the pressure data. Don't overwrite it in
the first place.
The resulting two functions should be distinctly easier to understand.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The parsers / downloaders parse into a separate table and do
not directly change the divelist. Therefore, they shouldn't
call mark_divelist_changed().
Likewise split_dive_at() doesn't modify the dive list and
therefore shouldn't call this function.
Calling the function has the unwanted side-effect that undoing
the change will not clear the *-symbol in the title of the
main window.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This function was used to count the number of weightsystems
used in a dive. Since the weightsysems are now collected
in a dynamic table it became unused. Remove.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Replace the fixed-size weightsystem table by a dynamically
relocated table. Reuse the table-macros used in other parts
of the code.
The table stores weightsystem entries, not pointers to
weightsystems. Thus, ownership of the description string is
taken when adding a weightsystem. An extra function adds
a cloned weightsystem at the end of the table.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This will be used later when joining and editing dives.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Sadly, this doesn't give any type safety. But at least it documents
the function arguments.
Make the last item in the enum as a number-of-pressure-entries
sentinel. Use that to size the pressure-values array.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of assigning the the lvalue of the SENSOR_PRESSURE
macro, introduce a general function to set pressure values.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The comment to populate_pressure_information() was mentioning
gas pressures that didn't exist. Remove these parts.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Replace the INTERPOLATED_PRESSURE and SENSOR_PRESSURE macros by
inline functions. Generate a common inline function that reads
a pressure value for a dynamic sensor.
Not all SENSOR_PRESSURE macros can be replaced, because the
macro is also used to set the value and C sadly doesn't know
the concept of "return reference from a function".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There is absolutely no reason to use a macro here.
The only argument that can be made is consistency with
the other pressure-macros, but those too are questionable.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
DILUENT_PRESSURE and INTERPOLATED_DILUENT_PRESSURE do not exist
anymore. No point in trying to output them.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>