aboutsummaryrefslogtreecommitdiffstats
path: root/core
AgeCommit message (Collapse)Author
2019-08-10Core: unconditionally include stdio.h in libdivecomputer.hGravatar Berthold Stoeger
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>
2019-08-08iOS: address build errorGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-08-08Planner: pass dive to enough_gas()Gravatar Berthold Stoeger
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>
2019-08-08Planner: pass dive / cylinder pair to track_ascent_gas()Gravatar Berthold Stoeger
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>
2019-08-08Planner: pass dive to analyze_gaslist()Gravatar Berthold Stoeger
Use the actual planned dive, not the displayed dive in analyze_gaslist(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08Planner: fix comment for create_dive_from_plan()Gravatar Berthold Stoeger
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>
2019-08-08Core: pass dive, cylinder-id to fill_default_cylinderGravatar Berthold Stoeger
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>
2019-08-08Planner: use planner's dive in interpolate_transition()Gravatar Berthold Stoeger
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>
2019-08-08Parser: remove global stateGravatar Berthold Stoeger
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>
2019-08-08Cleanup: remove unused function printdecotableGravatar Berthold Stoeger
It is unclear where this function has ever been used. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08Cleanup: make local functions in planner.c of static linkageGravatar Berthold Stoeger
A number of functions were not used outside of planner.c. Make them static. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08Cleanup: move planner/deco related declarations planner/deco.hGravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-08Cleanup: move file-related function declarations to file.hGravatar Berthold Stoeger
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>
2019-08-08Cleanup: move error reporting function declarations to errorhelper.hGravatar Berthold Stoeger
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>
2019-08-08Cleanup: replace macro by inline function in gas-model.cGravatar Berthold Stoeger
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>
2019-08-08Indicate negative cylider pressureGravatar Robert C. Helling
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>
2019-08-08Limit gas compressibility argument range to halfway sane valuesGravatar Linus Torvalds
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>
2019-08-04Cleanup: use clear_git_id() instead of setting saved_git_idGravatar Berthold Stoeger
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>
2019-08-04Coding style: add spaces in load-git.cGravatar Berthold Stoeger
Add spaces before and after multiplication and addition operators. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-04Git: Make parser reentrantGravatar Berthold Stoeger
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>
2019-08-04Cleanup: make functions in core/load-git.c localGravatar Berthold Stoeger
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>
2019-07-27Core: split copy_cylinders() in two functionsGravatar Berthold Stoeger
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>
2019-07-19Bluetooth: autodetect Shearwater NERD modelsGravatar Dirk Hohndel
This should allow it to work with Subsurface-mobile as well. Fixes #2187 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-07-19Cleanup: remove bogus mark_divelist_changed() callsGravatar Berthold Stoeger
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>
2019-07-18Cleanup: remove unused weightsystem_none() functionGravatar Berthold Stoeger
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>
2019-07-18Core: dynamically resize weight tableGravatar Berthold Stoeger
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>
2019-07-18Core: Implement same_weightsystem() function to compare weightsGravatar Berthold Stoeger
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>
2019-07-18Cleanup: declare functions in profile.h as externGravatar Berthold Stoeger
We seem to do this in other C-headers, so for consistency also do it here. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18Cleanup: make the plot-pressure type an enumGravatar Berthold Stoeger
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>
2019-07-18Cleanup: introduce function to set pressure valuesGravatar Berthold Stoeger
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>
2019-07-18Cleanup: update comment in core/gaspressures.cGravatar Berthold Stoeger
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>
2019-07-18Cleanup: replace pressure reading macros by inline functionsGravatar Berthold Stoeger
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>
2019-07-18Cleanup: turn GET_PRESSURE macro into inline functionGravatar Berthold Stoeger
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>
2019-07-18Cleanup: remove non-existing pressures in debug_print_pressures()Gravatar Berthold Stoeger
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>
2019-07-18Cleanup: remove unused macro SAC_WINDOWGravatar Berthold Stoeger
Last user was removed in ae1e9b11a537eb0ba9b649cb876dae4cc4628045 Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18Cleanup: remove includes from qthelper.hGravatar Berthold Stoeger
To reduce interdependencies, remove the dive.h and divelist.h includes in qthelper.h Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18Cleanup: move deco function declarations to deco.hGravatar Berthold Stoeger
Another tiny step in making dive.h smaller: move function declarations to deco.h if these functions are defined in deco.c and don't directly concern dives. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18Cleanup: fix include weirdness concerning string_to_*() functionsGravatar Berthold Stoeger
The string_to_*() functions were declared in dive.h and qthelper.h. Moreover in one file they were declared with C in the other with C++ linkage. This only works because qthelper.h includes dive.h first. Fix this anomaly by declaring the functions only in qthelper.h, but moving them from the C++ to the C part. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18Cleanup: move cylinderuse_from_text() to equipment.cGravatar Berthold Stoeger
Since this function doesn't act on a dive and is only related to cylinders, move it to equipment.c and equipment.h. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-15Bluetooth: recognize Ratio iX3m GPS dive computersGravatar Dirk Hohndel
We cannot tell them apart by Bluetooth name, so pick one of the names. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-07-14Fix up XML saving of remaining bottom time dataGravatar Linus Torvalds
While testing the cylinder type saving fix, I noticed that the RBT saving was broken. Instead of saving RBT whenever it changed, we'd save it when it was non-zero. Which doesn't match the git save format, and also doesn't match what we do when loading an xml file (where we default to the previous RBT value, and a sample RBT will modify it). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-07-14Fix cylinder gas type saving when we have bogus gas use dataGravatar Linus Torvalds
Steve Williams reported a crash when saving a previously loaded dive as xml, and gave a gdb backtrace. It turns out that if we can't parse the cylinder use type (OC, diluent, oxygen, unused) we initialize the cylinder use to an invalid type, and then when we save it, we mess up. Fix it up by doing proper limit checking before accessing the "cylinderuse_text[]" array when saving. Reported-by: Steve <stevewilliams@internode.on.net> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-07-11Thumbnailer: improve error messageGravatar Berthold Stoeger
In the error messages shown when failing to start ffmpeg, instruct the user to set the correct executable in the preferences. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-10Git: handle excess of cylinders or weightsystems gracefullyGravatar Berthold Stoeger
Currently, the git parser happily trashes memory if a git repository contains too many weightsystems or cylinders. This should only happen in testing, but nevertheless try to handle it gracefully and ignore excess cylinders / weightsystems. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-06Cleanup: call calculate_max_limits_new() in create_plot_info_new()Gravatar Berthold Stoeger
All callers of create_plot_info_new() called calculate_max_limits_new() a line before. Thus, simply call the latter in the former. This allows us to automatically free the plot data in create_plot_info_new(). The old code overwrote the corresponding field with NULL. As a side-effect, this removes a bogus static variable. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-06Cleanup: fix memory management of the plot dataGravatar Berthold Stoeger
There was a global variable last_pi_entry_new, which stored the recently allocated plot data. This was freed when new plot data was generated. A very scary proposition: You can never have two plot datas at the same time! But exactly that happens when you export for example subtitles. The only reason why this didn't lead to very crazy behavior is that at least on my Linux machine, the calloc() call would just return the previously freed memory. Fix this mess by removing the global variable and freeing the data in the callers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-06Cleanup: remove unused get_screen_dpi() functionGravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-06Cleanup: remove unused declarations from display.hGravatar Berthold Stoeger
A number of declarations were not used anywhere. Remove them. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-28Planner: Wait minimum switch time when bailing out to OCGravatar Robert C. Helling
Bailing out does not happen instantly. Rather wait for the minimum stop switch duration before ascending. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-06-28Cleanup: remove includes from extern "C" blockGravatar Berthold Stoeger
In "core/save-html.h", the "core/dive.h" header was included in the extern "C" block. This is invalid, because "core/dive.h" included from C++ code contains Qt macros that expand to C++ templates. These in turn must not have extern "C" linkage, since a plain C-linker cannot handle such things. The only reason this worked is that in all cases "core/save-html.h" was included after "core/dive.h". The include of the latter in the former had therefore not effect. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>