aboutsummaryrefslogtreecommitdiffstats
path: root/core/profile.c
AgeCommit message (Collapse)Author
2021-01-20cleanup: constify create_plot_info_new()Gravatar Berthold Stoeger
This only read accesses the dive and constructs a plot-info structure. Make the dive parameter const. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-11undo: set dive mode to CCR in undo command, not profile codeGravatar Berthold Stoeger
When setting a CCR setpoint, the profile code(!) would turn the dive into a CCR dive. Not only should the display layer not alter dives, this also means that the action is not undoable. Move that to the appropriate undo command, where it makes more sense, but obviously also makes things more complicated. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10mobile: enable deco information calculation on mobileGravatar Dirk Hohndel
This simply allows us to calculate the information, it doesn't do anything to actually display it, yet. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-01-10profile: pass dive to RulerItemGravatar Berthold Stoeger
Instead of accessing the global displayed_dive variable in RulerItem, pass the dive. This is a step in making the profile reentrant. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: pass dive to ToolTipItem::refresh()Gravatar Berthold Stoeger
Don't access the global displayed_dive variable in a step to make the profile reentrant. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: move adding of ceiling-violation-eventGravatar Berthold Stoeger
The profile item that shows the ceilings adds a warning event if the ceiling is violated. This is very unfortunate. Improve this situation by adding the event up to the function that calculates the ceiling. This is still not how it should be - the display layer should not modify the dive that it displays. To make this clear, add a comment that details that this is a contract between planner and display layer: The planner uses a dive that can be trampled upon by the profile. Still, this should be solved differently. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10profile: use a parameter to determine planner stateGravatar Berthold Stoeger
The in_planner() function is incompatible with a reentrant profile, since it accesses a global variable. In create_plot_info_new() it is essentially redundant, because there is a planner_ds (ds = deco_state) parameter that is used only when in the planner. Therefore use that as the in_planner indicator: when non-null, the profile is showing a planned dive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-10cleanup: make calculate_deco_information() of static linkageGravatar Berthold Stoeger
This function was not used outside of profile.c Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: move interpolate inline function to its own header fileGravatar Berthold Stoeger
This is not really related to struct dive, so let's move it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: split out divecomputer functions from dive.cGravatar Berthold Stoeger
Since dive.c is so huge, split out divecomputer-related functions into divecomputer.[c|h], sample.[c|h] and extradata.[c|h]. This does not give huge compile time improvements, since struct dive contains a struct divecomputer and therefore dive.h has to include divecomputer.h. However, it make things distinctly more clear. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: break out event-related code into event.[c|h]Gravatar Berthold Stoeger
In an effort to reduce the size of dive.h and dive.c, break out the event related functions. Moreover event-names were handled by the profile-code, collect that also in the new source files. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01cleanup: make analyze_plot_info local to profile.cGravatar Berthold Stoeger
No external caller of this function exists. Moreover, turn the return type to void, as it only returned the passed-in plot_info and no caller used that. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01cleanup: const-ify a few functions in planner.cGravatar Berthold Stoeger
It make debugging much easier if the function signature tells you that a parameter is not altered. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01profile: for maxtime calculation include the sample after the last eventGravatar Berthold Stoeger
When plotting profiles with surface segments, there were strange artifacts. As we found out with Robert, these were due to the fact that the calculated maxtime was set to the last event which is just one second inside the surface segment. This terribly confused the profile code. For example, it didn't properly allocate samples for the surface segment. Thus, when calculating maxtime, consider the last sample beyond the last event. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-20profile: avoid invalid accesses in setup_gas_sensor_pressureGravatar Berthold Stoeger
Since we removed MAX_CYLINDERS, we have the possibility of dives with no cylinders. In such a case, setup_gas_sensor_pressure() would do invalid read- and write-accesses. Therefore, return early in such a case. Reported-by: Chirana Gheorghita Eugeniu Theodor <office@adaptcom.ro> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-18debug output: ensure our debug output is captured on AndroidGravatar Dirk Hohndel
I would have bet money that Android used to send stderr to the logcat log, but apparently it doesn't (anymore?). So in order to be able to have a chance to debug weird cloud storage issues on Android, let's do some wholesale replacement of fprintf(stderr,...) with our own version of the INFO macro that we long ago borrowed from libdivecomputer (and rename it to ensure we don't have a conflict there). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-18profile: avoid double-free when reusing plot_infoGravatar Berthold Stoeger
free_plot_info_data() freed the pressure-data, but didn't set the value to NULL. Thus, when the plot_info was reused, a double-free() could ensue. Crash condition: export the profiles of multiple dives with pressure data. Reported-by: Willem Ferguson <willemferguson@zoology.up.ac.za> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: remove commented-out evn_foreach() functionGravatar Berthold Stoeger
Apparently this was used to hide events in pre-Qt times. However, that has already been reimplemented in different ways. Let's remove that commented-out code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-11Grammar: replaces 'indexes' by 'indices'Gravatar Robert C. Helling
Grammar-nazi ran git grep -l 'indexes' | xargs sed -i '' -e 's/indexes/indices/g' to prevent future wincing when reading the source code. Unfortunatly, Qt itself is infected as in QModelIndexList QItemSelection::indexes() const Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-11-28Add current GF to infoboxGravatar Robert C. Helling
As per request from users on scubaforum.com, this adds the current gradient factor to the deco information of the infobox. Up to now, this information was only graphically represented in the pressure bar graph and the heatmap. This gives a numerical value. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-11-16Don't access uninitialized deco_structureGravatar Robert C. Helling
Coverty found that in the export functions, we initialize the planner deco state with NULL and then possibly later access its content. This makes sure, we don't do that. Let's see if this makes Coverty happy or I missed somehting else. Fixes CID 350736 Fixes CID 350735 Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-11-12Profile: fix pressure scaleGravatar Berthold Stoeger
The determination of minimum pressure in calculate_max_limits_new() in profile.c was wrong for a long time. Since the loop went over all cylinders (even unused ones), the minimum pressure was always zero. Since we loop only over used cylinders, the minimum pressure was initialized to the lowest starting pressure of any cylinder. If there were no events with pressure change, the minimum pressure stayed unchanged, resulting in a funky scaling. Instead, let's initialize the minimum pressure to the lowest ending pressure. Reported-by: Willem Ferguson <willemferguson@zoology.up.ac.za> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Cylinders: access cylinders with get_cylinder()Gravatar Berthold Stoeger
Instead of accessing the cylinder table directly, use the get_cylinder() function. This gives less unwieldy expressions. But more importantly, the function does bound checking. This is crucial for now as the code hasn't be properly audited since the change to arbitrarily sized cylinder tables. Accesses of invalid cylinder indexes may lead to silent data-corruption that is sometimes not even noticed by valgrind. Returning NULL instead of an invalid pointer will make debugging much easier. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Core: remove MAX_CYLINDERS restrictionGravatar Berthold Stoeger
Instead of using fixed size arrays, use a new cylinder_table structure. The code copies the weightsystem code, but is significantly more complex because cylinders are such an integral part of the core. Two functions to access the cylinders were added: get_cylinder() and get_or_create_cylinder() The former does a simple array access and supposes that the cylinder exists. The latter is used by the parser(s) and if a cylinder with the given id does not exist, cylinders up to that id are generated. One point will make C programmers cringe: the cylinder structure is passed by value. This is due to the way the table-macros work. A refactoring of the table macros is planned. It has to be noted that the size of a cylinder_t is 64 bytes, i.e. 8 long words on a 64-bit architecture, so passing on the stack is probably not even significantly slower than passing as reference. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Profile: dynamically allocate gases arrayGravatar Berthold Stoeger
To calculate sac rates, an array of used gases for every point on the profile was used. This was implemented using unsigned int bitfields. While nobody sane will ever use 32 or even 64 cylinders, for consistency with the rest of the code, also change this to use dynamically allocated arrays. But allocate only once per shown profile, not once per sample. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Profile: dynamically allocate plot pressure dataGravatar Berthold Stoeger
All accesses to the pressure data were converted to use functions. Therefore it is now rather trivial to dynamically allocate the pressure array and just change the functions. The only thing to take care of is the idiosyncratic memory management. Make sure to free and copy the buffer in the appropriate places. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Profile: turn INSERT_ENTRY macro into helper functionGravatar Berthold Stoeger
The only apparent reason that this was a macro is that it automatically increased the "index" and "entry" counts. But incrementing these explicitly seems reasonable. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Profile: pass index instead of pointer to set_plot_pressure_dataGravatar Berthold Stoeger
Another plot-pressure-related function whose argument is converted to an index. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Profile: switch pressure-accessing functions to indexesGravatar Berthold Stoeger
Continue with replacing pointers to struct plot_data entries by indexes. Thus the pressure data can be kept in its own array and can by dynamically sized. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Profile: change get_plot_pressure to take index instead of pointerGravatar Berthold Stoeger
The goal here is to make it possible to detach the pressure related data from the plot_info structure. Thus, the pressure related data can be allocated independently depending on the number of cylinders per dive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Cylinders: dynamically allocate cylinder arraysGravatar Berthold Stoeger
Dynamically allocate cylinder arrays in C code. This is a tiny step in removing the MAX_CYLINDERS limitation. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-08-28Profile: properly initialize plot_info structuresGravatar Berthold Stoeger
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>
2019-08-10Android: fix potential crashGravatar Dirk Hohndel
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>
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: 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-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-06-19Cleanup: remove unused parameter used from find_best_gasmix_match()Gravatar Berthold Stoeger
The last direct user of the used parameter was removed in 16276faa45279817e363367550a6a37c179251f7, the last actual user in e2bbd0ceecff7193bb272430fbebfc4b02dd67c3. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19Cleanup: Make gaspressures.h a regular include fileGravatar Berthold Stoeger
gaspressure.h had definitions of non-exported structs, but did not declare the only function exported by gaspressure.c. Therefore, move the struct definitions into gaspressure.c and the declarations of the populate_pressure_information() function from profile.c to gaspressures.h. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-07Correct typo in Information boxGravatar willemferguson
Correct type in SCR delta pO2 display in Information box Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2019-06-03Add delta-pO2 disply in Information BoxGravatar willemferguson
Add display of the difference between pO2 in rebreather loop and the equivalent OC pO2: this is the oxygen drop over the mouthpiece for SCR dives. Obviously this is only displayed for SCR dives. Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2019-05-12Cleanup: remove UTF8 macrosGravatar Berthold Stoeger
At some places we use UTF8 string literals. Therefore, we effectively only support UTF8 build systems. We might just as well remove all the other UTF_* macros and use direct string literals. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Coding style: remove Java-style function definitionGravatar Berthold Stoeger
Remove a few cases of void fun() { ... } While touching these functions, fix a few other whitespace coding style violations. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-03-29Show a bit of surface degassing in the plannerGravatar Robert C. Helling
to display the deco parameters at the surface, in particular tissue saturation and heat map. Suggeted-by: Matthias Heinrichs <info@heinrichsweikamp.com> Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-03-19Misc: replace some FIXME commentsGravatar Dirk Hohndel
All these aren't actually things that need fixing, they are observations about the code. Given that LGTM.com reports FIXME comments as Alerts, let's change the ones that aren't about things that need fixing to something more harmless. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-03-18Core: let TTS calculation use correct ascent velocitiesGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-02-05Add button to toggle deco info in info boxGravatar Robert C. Helling
The info box can get longish. Offer the user to turn off display of deco information (surface GF and individual ceilings). Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-02-05Include surface GF in infoboxGravatar Robert C. Helling
The most recent firmware of Shearwater computers shows this. This is a measure of absolute amout of tissue loadings in an easy to digest unit. Therefore it is useful to have. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-10-11Undo: select dives after add, remove, merge, split dive commandsGravatar Berthold Stoeger
Select the proper dives after the add, remove, split and merge dives commands on undo *and* redo. Generally, select the added dives. For undo of add, remember the pre-addition selection. For redo of remove, select the closest dive to the first removed dive. The biggest part of the commit is the signal-interface between the dive commands and the dive-list model and dive-list view. This is done in two steps: 1) To the DiveTripModel in batches of trips. The dive trip model transforms the dives into indices. 2) To the DiveListView. The DiveListView has to translate the DiveTripModel indexes to actual indexes via its QSortFilterProxy- model. For code-reuse, derive all divelist-changing commands from a new base-class, which has a flag that describes whether the divelist changed. The helper functions which add and remove dives are made members of the base class and set the flag is a selected dive is added or removed. To properly detect when the current dive was deleted it became necessary to turn the current dive from an index to a pointer, because indices are not stable. Unfortunately, in some cases an index was expected and these places now have to transform the dive into an index. These should be converted in due course. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>