aboutsummaryrefslogtreecommitdiffstats
path: root/core/plannernotes.c
AgeCommit message (Collapse)Author
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-03Planner: Don't accumulate rounding errors in stop durationsGravatar Robert C. Helling
When displaying segment or stop times in the planner notes, we always round to the next full minute. This can mean for example that we round down more often than rounding up with the result that the sum of the segment times does not match the total runtime and can for example lead to stops that are shown with 0min duration. With this patch, we increase the reference time of the last display only by the duration time actually shown. This way, the rounding errors don't accumulate but having rounded down previously makes rounding up the next time more propable. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-10-27Don't expose 'detach_buffer()' to membuffer usersGravatar Linus Torvalds
The native buffer of a membuffer is not NUL-terminated, so when you want to detach it and use it as a C string, you had to first do 'mb_cstring()' that adds the proper termination/ This was all documented in the header files, and all but two users did it correctly. But there were those two users, and the exported interface was unnecessarily hard to use. We do want the "just detach the raw buffer" internally in the membuffer code, but let's not make the exported interface be that hard to use. So this switches the exported interface to be 'detach_cstring()', which does that 'mb_cstring()' for you, and avoids the possibility that you'd use a non-terminated memory buffer as a C string. The old 'detach_buffer()' is now purely the internal membuffer implementation, and not used by others. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-09-11Cleanup and correct plannernotes htmlGravatar Anton Lundin
This balances the tags to a equal amount of start and end tags in the planner notes html. This also breaks it up with new-lines, so its a bit easier on the eyes, and gives a validator the chance to point out on which line a error is. Signed-off-by: Anton Lundin <glance@acc.umu.se>
2019-09-11Add debug capability to planner notesGravatar Anton Lundin
The output it spits out can be copy-pasted into a html validator like: https://validator.w3.org/nu/#textarea Signed-off-by: Anton Lundin <glance@acc.umu.se>
2019-09-11Show correct notes entry when switching on stopsGravatar Robert C. Helling
When gas switching only on stops is selected, the notes showed an extra line at the not realized stop depth. This eliminates it. It also makes sure there are no 0 second spurious entries. And gas switching takes more than zero time (otherwise we would have to print a line of zero duration for at the gas switch depth). Reported-by: tormento <turment@gmail.com> Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-09-10Plan: introduce function that returns disclaimerGravatar Berthold Stoeger
The setting of the disclaimer variable was removed inadvertently some time ago, which removed the disclaimer from the printed plan. Instead, introduce a function that returns the disclaimer with the current deco mode. Use that function to generate the dive notes and for printing. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-10Planner: remove planner disclaimer from old notesGravatar Berthold Stoeger
There used to be code to remove the old planner notes when replanning a dive. It used a global variable and seemed rather brittle. Moreover, the place that set the global variable was inadvertently removed. Therefore has been effectively dead code. Reimplement the functionality, but be more robust by considering that the deco-type may have changed: Split the translated disclaimer string in two parts, before and after the "%s" place-holder. Search for these two parts. Remove the disclaimer and everything after the disclaimer. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-29Update deco disclaimerGravatar Robert C. Helling
Our disclaimer is no longer "new". It is still true that people should not blindly follow it. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-05-17Implement height-to-pressure functions in plannerGravatar willemferguson
The units.h file has two functions to convert atm pressure to mbar and also to convert mbar to atm pressure. Implement these two functions in the planner. Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2019-04-16Don't show surface gas in gas use listGravatar Robert C. Helling
Skip gas use calculation for the gas that was used in the surface segment added by the planner in the end. Reported-by: philippe@philmassart.net Signed-off-by: Robert C. Helling <helling@atdotde.de>
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>
2018-09-12Planner: fix display of "overlapping dives" messageGravatar Berthold Stoeger
1) Add a missing <div> 2) More importantly: recognize html content via <div>-tags instead of <table>-tags. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-10Profile: fix SAC calculation for air divesGravatar Berthold Stoeger
Commit f5b11daffd6f240268ce78d72c64be43670988ea changed gasmix arguments and return values to be passed by value instead of using pointers. Notably, get_gasmix() is fed a default-value and returns a new value. In the old code, NULL was passed in in a first loop iteration and non-NULL was always returned in the first iteration. Thus, an equality comparison of passed-in an returned gasmix would always fail in the first loop iteration. The new code passed in air as default. Now if air was also returned, then the matching gases were not calculated in calculate_sac(). To revert to the old behavior, pass in an invalid gasmix. Moreover, give names to the invalid and air gasmixes. Reported-by: tormento <turment@gmail.com> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23Cleanup: const-ify functions taking pointers to eventsGravatar Berthold Stoeger
This is another entry in the series to make more things "const-clean" with the ultimate goal of merge_dive() take const pointers. This concerns functions taking pointers to events and the fallout from making these const. The somewhat debatable part of this commit might be that get_next_event() is split in a two distinct (const and non-const) versions with different names, since C doesn't allow overloading. The linker should recognize that these functions are identical and remove one of them. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23Cleanup: pass gasmix by valueGravatar Berthold Stoeger
In a previous commit, the get_gasmix_* functions were changed to return by value. For consistency, also pass gasmix by value. Note that on common 64-bit platforms struct gasmix is the size of a pointer [2 * 32 bit vs. 64 bit] and therefore uses the same space on the stack. On 32-bit platforms, the stack use is probably doubled, but in return a dereference is avoided. Supporting arbitrary gas-mixes (H2, Ar, ...) will be such an invasive change that going back to pointers is probably the least of our worries. This commit is a step in const-ifying input parameters (passing by value is the ultimate way of signaling that the input parameter will not be changed [unless there are references to said parameter]). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-13In planner notes don't show dive mode for first data pointGravatar Stefan Fuchs
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-07-13Add three missing translations for divemode_text_ui in plannernotes.cGravatar Stefan Fuchs
Added three missing translations which were forgotten here: fcf6b819d9cf337714fb542497cffc6effafe2ca Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-06-24Make planner notes divemode aware...Gravatar Robert C. Helling
... and fix a problem with setpoint changes shown in the wrong line Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-05-18Plannernotes: '\0'-terminate ICD-bufferGravatar Berthold Stoeger
When creating the ICD-notes the membuffer was not '\0'-terminated, leading to output of stale data. Reported-by: Willem Ferguson <willemferguson@zoology.up.ac.za> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-14Rename enum dive_comp_type to divemode_tGravatar Robert C. Helling
...as the usuage is not anymore about a computer but a momentary dive mode. Rename the end indicator as well. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-05-14Implement get_divemode() to find the divemode at a particular timeGravatar Willem Ferguson
Replaced a rather cumbersome function that that did the above. Upon the suggestion of Robert Helling who proposed a much shorter way, this new function replaced the previous ones. This necessitated changes to divelist.c, profile.c and plannernotes.c, as well as dive.c/h. Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-05-14Simplify the bailout detection functions.Gravatar Willem Ferguson
Function peek_next_divemodechange() is redundant if get_next_divemodechange() has one additional parameter. Calls to get_next_divemodechange() were updated in divelist.c, plannernotes.c and profile.c. Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-05-14Incorporate bailout events in CCR & PSCR gas calculations.Gravatar Willem Ferguson
This is a first step to interpret bailout events. 1) The event structures have a new attribute: divemode. Currently interpreted dive modes are OC, CCR, PSCR. 2) When doing fill_pressures(), the calculation is aware of divemode. When divemode is OC (==bailout), then the appropriate calculations of gas pressures are done. 3) Two new functions get_next_divemodechange() and get_divemode_at_time() are created to find divemode changes in the events linked list and to determine the dive mode at any point during the dive. 4) fill_pressures gets a small amendment to facilitate the correct calculations, depending on divemode. The cases where fill_pressures() is used *outside the planner* are changed. The result is that, for dives with bailout, the correct gas pressures are shown on the dive profile. The deco for bailout dives is not yet correct. This is the next step. Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-04-11Cleanup: Fix memory leak in plannernotes.cGravatar Berthold Stoeger
dive->notes was overwritten without free()ing the old buffer. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-11Cleanup: fix "unsave" snprintf()s in plannernotes.cGravatar Berthold Stoeger
The planner notes were constructed using a sequence of len += snprintf(buf, buflen - len, ...); calls. This will fail once len > buflen, because the second parameter of snprintf is unsigned. Note that snprintf returns the number of bytes that would have been written if it weren't truncated. Fix this by using membuffer with put_format()/put_string() and asprintf_loc(). Fixes #1155. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-11Cleanup: unconstify results of two functionsGravatar Berthold Stoeger
get_dive_date_c_string() and get_current_date() return copied strings. Make this explicit by returning non-const pointers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-11Cleanup: make local functions in core/plannernotes.c of static linkageGravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-09Cleanup: Move *_loc formatting functions into new format.cpp fileGravatar Berthold Stoeger
qthelper.cpp is already quite voluminous. Move the recently introduced localized versions of (v)snprintf() and put_format() into their own translation unit. Moreover, adopt C-style semantics for asprintf_loc(). This function will be used to remove fixed-size buffers in core/plannernotes.c. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05Localization: implement *_loc() functions in plannernotes.cGravatar Berthold Stoeger
Replace snprintf() and put_format() by snprintf_loc() and put_format_loc(), respectively to localize formatting of integers and floats. Acked-by: Stefan Fuchs <sfuchs@gmx.de> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-26Cleanup: Unify qthelper.h and qthelperfromc.hGravatar Berthold Stoeger
Since all qt-helpers are defined in qthelper.cpp, there seems to be no reason to have two include files. By unifying the two files, duplication and inconsistencies are removed. The C++-only part is simply compiled away with #ifdefs. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-25Correctly suppress display of ICD table if prefs.show_icd is falseGravatar Stefan Fuchs
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-22Exit add_plan_to_notes() in plannernotes.c always via label finishedGravatar Stefan Fuchs
Replace an early "return" in add_plan_to_notes() with a "goto finished;" This was the initial idea of doing it plus it fixes a potential memory leak (missing free for icdbuffer). Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-20Indicate direction of transition in verbatim planGravatar Robert C. Helling
Replace "Transition to" by "Ascent to" or "Descend to" Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-02-02Print icd data only when it is really neededGravatar Willem Ferguson
Reduce the impact and visibility of icd calculations by writing the data to the planner output only in cases where gas switches involve: 1) ascent 2) helium is used as part of breathing gas 3) gas switch results in an increase in partial pressure of nitrogen. Coding change: 1) The code for writing the header of the icd table as well as the inclusion of the data in the planner output is made conditional on the above three requirements. This involves moving the code that writes the table header into the function that writes an icd data item to buffer. 2) Manipulation of a boolean variable that controls writing of the table header to buffer and that also determines whether any icd results should be inluded in the planner results. 3) Reorganise comments so that there are not multiple tabs between the code and the start of a comment. Correct type and insert braces where important Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-24Planner: print icd information at 0.1 resolutionGravatar Willem Ferguson
The gas fractions (in %) are now printed at a resolution of 0.1% and not at 0.01% as previously. The string in the info box that provides icd data is reformatted so that the info-box is as narrow as possible. Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-21Planner notes min gas: Remove incorrect line wrap inside printf stringGravatar Stefan Fuchs
With old code the tabs at the start of the second line were incorrectly added to the string. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-01-21Planner notes ICD: Format HTML with DIV, do table title differentlyGravatar Stefan Fuchs
In the planner notes format the HTML for different sections with div tags. Put the table title for the ICD table outside the table because then the alignment looks a little bit nicer. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-01-21Planner notes ICD: Coding style change onlyGravatar Stefan Fuchs
Avoid the need for a char array for the "old_gas_name" by passing two pointers to the gasmixes to the add_icd_entry function and calling helper function gasname() there twice. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-01-21Planner notes ICD: Print correct runtime for gaschangeGravatar Stefan Fuchs
If a gaschange happens at the beginning of a segment, currently the wrong runtime (end of segment time) is printed in the ICD table. This is corrected here. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-01-20Move function isobaric_counterdiffusion()Gravatar Willem Ferguson
Move the above function from plannernotes.c to dive.c so that it is available to be called from the dive log part of the software, and not only from the planner. The following was done: 1) Edit the comment above the code to make it more accurate 2) Move the structure icd_data to dive.h 3) Create an external reference in dive.h for the above function 4) Copy the body of isobaric_counterdiffusion() to dive.c Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-19Implement ICD calculations in planner outputGravatar Willem Ferguson
This patch implements the calculation and printing of icd parameters in the dive planner output. It does: 1) icd parameters are calculated following the rule-of-fifths for OC trimix dives. For each gas change on the ascent that involves helium, the change in gas composition as well as the change in partial pressures are shown. If rule-of-fifths is exceeded, a warning message is prinetd. 2) An independent function is provided that in principle enables calculation of icd paramaters outside of the context of the dive planner. Further updates to icd calculations These changes respond to #1047. Code style conventions have been improved. The ICD table is now also printed when the planner is set to verbatim mode. The code that created the html icd results has been moved to a function. This does not make the code more efficient (many parameters passed) but it makes the code more clean. Free a new dynamic variable (old_gas_name) Stylistic changes to new code in plannernotes.c Changes in comments to explain some of the changes I made. Preparation of comments and functioning of isobaric_counterdiffusion() and its dependent data structure for possible transfer to dive.c and dive.h after finalisation and merging of the present PR. Smaller stylistic changes to conform to our coding rules. The several comments and suggestions during github review (@atdotde, @leolit123, @sfuchs79) are incorporated. Fixed up mis-aligned comments and text descriptions by replacing tab characters with space characters, thereby hard-forcing alignment of indented lines of text. Remove parameter *dive from function isobaric_counterdiffusion(). Improve a few constructs to conform to our style rules. Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-11Fix indentations for plannernotes.cGravatar Willem Ferguson
The last 2 commits have now been squashed. S Fuchs's comment on line 315 has been fixed Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2017-12-28Planner notes: don't omit deco stops with rapid ascent ratesGravatar Rick Walsh
This fixes a bug where if the user entered very high ascent (or less commonly descent) rates such that the time to ascend (or descend) from one level to the next was less than 10s, that leg would be skipped in the dive plan notes. Reported-by: Alexander Maier <maieralex@me.com> Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-12-26Cleanup: avoid memory leakGravatar Dirk Hohndel
Coverity CID 208308 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-17Unify float calulations: use doubleGravatar Berthold Stoeger
Internal floating point (FP) calculations should be performed using double unless there is a very good reason. This avoids headaches with conversions. Indeed, the vast majority of FP calculations were already done using double. This patch adapts most remaining calculations. Not converted where things that were based on binary representations and variables which weren't used anyway. An analysis of all instances follows: core/plannernotes.c, l.404: This was a comparison between two floats. On the left side, first an integer was cast to float then multiplied with and integer and divided by a constant double. The right hand side was an integer cast to a float. Simply divide by 1000.0 first to convert to double and continue with calculations. On the right hand side, remove the cast, because the integer will be implicitely cast to double for comparison. This conversion actually emits less instructions, because no conversion to double and back is performed. core/planner.c, l.613: Same analysis as previous case. subsurface-desktop-main.cpp, l.155: A local variable representing the version OpenGL version. Turn this into integer logic. Not only does this avoid dreaded FP rounding issues, it also works correctly for minor version > 10 (not that such a thing is to be expected anytime soon). abstractpreferenceswidget.[h/cpp]: A widget where the position is described as a float. Turn into double. desktop-widgets/divelogexportdialog.cpp, l.313: total_weight is described as float. Use double arithmetics instead. This instance fixes a truncation warning emitted by gcc.
2017-12-01Document background computation of variationsGravatar Robert C. Helling
Update changelog, update user manual, clarify meaning in dive notes. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-12-01Disable plan variation in recreational modeGravatar Rick Walsh
Calculating variations when in recreational mode doesn't make sense, and can prevent variations from being calculated when switching back to Buhlmann or VPM-B modes. Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-12-01Round up diveplan duration the same way values in diveplan are roundedGravatar Stefan Fuchs
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>