aboutsummaryrefslogtreecommitdiffstats
path: root/core/profile.c
AgeCommit message (Collapse)Author
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-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-14Implement bailout outside of the dive plannerGravatar Willem Ferguson
This is the second step for implementing bailout. The indirect calls to fill_pressures through add_segment() (in deco.c) are addressed. Bailout is now fully implemented in the dive log but not in the dive planner. 1) The parameters to add_segment() are changed to take a divemode as the second last parameter, and not a *dive. 2) Call to add_segment() in profile.c and in divelist.c are adapted. In divelist.c some calls to add_segment were left using dc-> divemode instead of possible bailout. This appears tp be the most appropriate route. 3) The functions get_divemode_from_time() and get_next_divemodechange() in dive.c have had some small changes. 4) The calls to get_segment(0 in planner.c were changed to reflect the new parameter list, but not updated to reflect bailout. This is the next step. 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-05-14Core: introduce new subsurface-string headerGravatar Dirk Hohndel
First small step to shrinking dive.h. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-04-28Plot OC-pO2 graph for SCR divesGravatar Willem Ferguson
This commit allows plotting the OC-equivalent pO2 graph for PSCR dives. This happens in both the cases where there is no external O2-monitoring AND when there is external pO2 monitoring. The calculations are only done for PSCR dives and is achieved as follows: 1) Within plot-info create a pressure-t called OC_pO2 in profile.h and populate this variable with the open-circuit pO2 values in profile.c. 2) Create a new partialPressureGasItem ocpo2GasItem in profilewidget2.h and, in profilewidget2.cpp, initialise it to read the plot-info OC_pO2 values and enable its display by using the setVisible method. The diveplotdatamodel was also touched in order to achieve this. 3) Create a pref button that controls the display of OC-pO2 for SCR dives 4) Change the colour of the OC-pO2 grpah to orange 5) Change the connection of the crr_OC_pO2 signal to be appropriate 6) rename the OC_pO2 attribute to scr_OC-pO2 Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-04-11Look for actual isobaric counter diffusionGravatar Robert C. Helling
Identify segements that fullfill the folllowing criteria for the leading compartment: He is off-gasing while N2 is on-gasing Overall there is on-gasing Add a line to the info box for those segments Signed-off-by: Robert C. Helling <helling@atdotde.de>
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-19Profile heartrate: Nicer min/max values and tic distanceGravatar Stefan Fuchs
Correct a bug in finding the minimum heartrate. Use the minimum and maximum heartrate value to set min/max and tic distance for the heartrate axis in the profile. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-03-13Treat a PSCR dive with sensors more like a CCR diveGravatar Anton Lundin
PSCR dives with o2 sensors are more like CCR dives. The math is exactly the same, its just a different diluent and a different po2. Signed-off-by: Anton Lundin <glance@acc.umu.se>
2018-03-06Cosmetic modifications in profile delta sample stringGravatar Stefan Fuchs
Consistently do not use a space between value and unit. Consistently do not use a space between "name:" and value. Add "/min" for SAC rate. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-03-05Localization: implement *_loc() functions in profile.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-17Coding-style: remove superfluous parenthesesGravatar Berthold Stoeger
Mostly replace "return (expression);" by "return expression;" and one case of "function((parameter))" by "function(parameter)". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-12dump_tissues: fix missing 'struct deco_state' argumentGravatar Lubomir I. Ivanov
With DECO_CALC_DEBUG != 0, divelist.c and profile.c have calls to dump_tissues() without passing a 'struct deco_state' argument. Fixes #1105 Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-12-21Handle plot_info->nr <= 0 gracefullyGravatar Berthold Stoeger
plot_info->nr should always be > 0. If this is not the case, write a message to stderr instead of crashing in add_plot_pressure(). This silences an use-of-uninitialized-variable warning. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-21Fix use of uninitialized variable in core/profile.cGravatar Berthold Stoeger
last_ceiling was used before initialization in the first iteration of the loop in calculate_deco_information(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-29Fix signed/unsigned issueGravatar Dirk Hohndel
Also deal with an unused argument in the case of a Subsurface-mobile build. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-11-25Hand planner variables to profileGravatar Robert C. Helling
Pass the planner state struct to the profile computation so it can use deco_time and first ceiling to display VPM-B ceiling. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-11-25Localize global planner stateGravatar Robert C. Helling
For UI responsiveness, we need to be able to run the planner in the background. This needs the planner state to be localized (and we need to pass a pointer around). In order to not let too many lines overrun (and to save typing in the future) I have renamed instances of struct deco_state to ds. Yes this should have gone to a separate commit but I accidentally commit --amend'ed it. Computing of planner variations is temporarily disabled. Unlock the planner when returning early So we don't deadlock in add dive and recreational mode (which use the planner without actually planning). Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-11-25Run variations calculation in backgroundGravatar Robert C. Helling
but there are still side effects and thus it crashes. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-11-25Add logic parentheses to make compiler happyGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-11-17Don't show cylinder pressures for other dive computersGravatar Linus Torvalds
Stefan Fuchs points out that sometimes you get cylinder duplication when you merge dives, particularly with a planned dive. For example, if we had different manual pressures in the two different dives, the cylinders will be kept separate. But that also means that we don't want to plot the pressures from those other cylinders that came from another dive and are now associated with another dive computer. Change the "seen" logic for the cylinder to ignore cylinders that are only mentioned by other dive computers than the active one. Reported-by: Stefan Fuchs <sfuchs@gmx.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-11-17Clean up confusing code in setup_gas_sensor_pressure()Gravatar Linus Torvalds
The "prev" cylinder can never be negative since commit 56c206d19fba ("For more manual gas pressure details"), so remove stale code that checks for a case that cannot happen any more. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-11-13Display values in info box only if value is interestingGravatar Stefan Fuchs
Type duration_t changed from uint to int. Default value of '-1' introduced for some of the values in struct sample: NDL used -1 as default. Bearing uses -1 as default (no bearing set). Display pXX, EAD, END, density, MOD only if values are larger than 0. In profile don't display data from two first and two last plot_data entries in info box. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-08VPMB: time_clear_ceiling is only valid after time_deep_ceilingGravatar Rick Walsh
Some messed up logic was producing negative deco_time values for some no-deco dives. The CVA wouldn't converge and unrealistic VPMB ceilings were displayed in the profile. This fixes it. See #762 Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-11-08VPMB profile: remember deco_time when restoring deco_stateGravatar Rick Walsh
Otherwise the CVA won't iterate properly. Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-11-08VPMB: final_tts may be calculated before final sampleGravatar Rick Walsh
We calculate tts every 30s, not every sample. Consider that when determining the time that the ceiling would have cleared if it's after the surfacing time. Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-11-08VPMB profile: use deco_time rather bottom_time from plannerGravatar Rick Walsh
This makes the calculations in profile.c a little simpler, especially now we adopt consistent final ascent rate to determine deco_time since d15779a27 Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-11-08VPMB in profile: deepest ceiling occurs just after bottom timeGravatar Rick Walsh
This lets us calculate deco_time for real dives closer to the planner value. Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-11-08VPMB: calculate deco_time assuming final ascent always takes the same timeGravatar Rick Walsh
If we consider the actual time to ascend from the final stop when calculating deco_time, then slowing the final ascent can lead to the final stop being extended, which is completely nonsensical. For consistency with the original VPMB implementation, we can't ignore the final ascent time completely, but if we assume it is always the same (take default ascent rate of 9m/min) then slower the final ascent won't lead to a longer final stop. Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-11-08VPM-B: move bottom_time into deco_stateGravatar Rick Walsh
Removing ext variable from profile.c should facilitate future performance gains Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-11-06Fix typo which prevented correct translation of word "Density"Gravatar Stefan Fuchs
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-30VPM-B ceiling: calculate deco_time similar to planned VPM-B divesGravatar Rick Walsh
When planning a VPM-B dive, the "deco time" ends at surfacing, which is after ascending after a full-minute deco stop is complete, after ceiling clears. We should take this into account when calculating the ceiling outside of the planner. Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-10-30VPM-B ceiling outside of planner: over-estimate deco_time on first iterationGravatar Rick Walsh
This means the iterations converge from an over-estimate, consistent with planning VPM-B dives Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-10-30VPMB profile: use bottom_time to calculate deco_time in plannerGravatar Rick Walsh
This corrects the issue where the displayed ceiling in the profile was "broken" by the planner, especially for shorter and shallower dives. Also fixes issue outside of planner where the deepest VPM-B ceiling was shown too early, messing up the deco_time calculation. VPM-B plans respond to change in O2% in gas as expected (in my testing) Fixes: #630 Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-10-08VPM-B profile: calculate parameters when in planner modeGravatar Rick Walsh
Calculating parameters when in the planner mode is necessary to display the correct ceiling. Fixes #601 Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-10-04When finding deepest ceiling, do not round to multiples of 3mGravatar Robert C. Helling
Fixes #630 Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-10-01VPM-B profile: initialize first_ceiling_pressureGravatar Rick Walsh
If we don't set first_ceiling_pressure at start of dive, a shallow ceiling can be shown when it shouldn't be. Fixes #584 Signed-off-by: Rick Walsh <rickmwalsh@gmail.com> Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-10-01More VPMB state in special structureGravatar Robert C. Helling
... and reset deco information in profile ceiling computation. The planner test then needs to know about the struct holding the deco state. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-09-15Properly clear sensor pressure data for synthetic plotinfo entriesGravatar Linus Torvalds
We only cleared the first sensor data when we created new synthetic plot info entries, because we only used to have one (well, we had the o2 data, but apparently nobody ever noticed that it didn't get properly interpolated, probably because people who have CCR dives with o2 pressures are few, and the pressure drops are gradual anyway). Clear all the pressure data, so that the interpolation code doesn't think we have some existing real sensor data for the plot info entries in between proper sample entries. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-09-13Make the info window show all the pressures we haveGravatar Linus Torvalds
We used to only show the first pressure we had, from back when we only supported a single sensor. Reported-by: Stefan Fuchs <sfuchs@gmx.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-08-26Remove some unused variablesGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-30For more manual gas pressure detailsGravatar Linus Torvalds
So the manual gas pressure case keeps showing issues, and in many ways it really is a fairly complex thing, since it needs interpolation of the intermediate pressures - possibly over several gas changes. So you might have beginning and ending pressures for one cylinder, but then use another cylinder in between. We've historically got all the code to do this, but the big rewrite for multiple cylinder pressures didn't get all the details right, and so here's a few more fixes for the case that was shown by a dive by Robert Helling. Hopefully we're approaching the old code situation, except now with concurrent gas pressure handling support. Reported-by: Robert Helling <helling@atdotde.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-30Fix another cylinder pressure plotting special caseGravatar Linus Torvalds
The core to plot manually entered pressures without any sample data did the obvious thing: it ended the pressures at the end of the dive as indicated by the last sample. However, that obvious thing didn't actually work, because sometimes the last sample is long long after the dive has actually ended, and we have no plot_info data for that. This depends on the dive computer used: most dive computers will not report samples after the end (even if they may internally remember them in case the diver just came up to the surface temporarily), but some definitely do. The OSTC3 is a prime example of that. Anyway, the code was fragile and wrong - even if passed a time past the end of the plot_info data, "add_plot_pressure()" should just have associated that with the last entry instead. Which also allows us to simplify the whole endtime logic entirely, and just use INT_MAX for it. Gaetan Bisson's test-case also showed another oddity: we would plot the gas pressure even for cylinders that had no has use (ie beginning and ending pressures were the same). That's kind of pointless in so many ways. So limit the manual pressure population to cylinders that actually have seen use. Reported-by: Gaetan Bisson <bisson@archlinux.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-28Fix manual pressures for cylinders with no gas switchesGravatar Linus Torvalds
"If it hasn't been tested, it doesn't work". All my testing of the multiple sensor pressures have been with some reasonably "interesting" dives: they actually *have* sensor pressures. But that test coverage means that I missed the truly trivial case of just having manual pressures for a single cylinder. Because there's only a single cylinder, it doesn't have any cylinder changes, and because there were no cylinder changes, it never filled in the use range for that cylinder. So then it never showed the pressure profile at all. Duh. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-28Calculate momentary SAC rates with the right gasesGravatar Linus Torvalds
The momentary SAC rate got broken by the multiple ressure handling too, and always used just the first cylinder. This uses the new "get_gasmix()" helper to see what you're breathing, and will do the SAC rate over all the cylinders that contain that gas. So it should now DTRT even for sidemount diving (assuming you had the same gas in the sidemount cylinders). NOTE! We could just do the SAC rate over *all* the gases you have pressures for, and maybe that's the right thing to do. The ones you are not breating from shouldn't have their pressure change. But maybe some people add their drysuit argon gas to the gas list? So this may need more work, but it's a step in the right direction. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-28Use the right gasmix for deco calculationsGravatar Linus Torvalds
In commit e1b880f4 "Profile support for multiple concurrent pressure sensors" I had mindlessly hacked away at some of the sensor lookups from the plot entries to make it all build, and forgotten about my butchery. Thankfully Jan and Davide noticed in their multi-cylinder deco dives that the deco calculations were no longer correct. This uses the newly introduced "get_gasmix()" helper to look up the currently breathing gasmix, and fixes the deco calculations. Reported-and-tested-by: Jan Mulder <jlmulder@xs4all.nl> Reported-by: Davide DB <dbdavide@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-27Profile support for multiple concurrent pressure sensorsGravatar Linus Torvalds
This finally handles multiple cylinder pressures, both overlapping and consecutive, and it seems to work on the nasty cases I've thrown at it. Want to just track five different cylinders all at once, without any pesky gas switch events? Sure, you can do that. It will show five different gas pressures for your five cylinders, and they will go down as you breathe down the cylinders. I obviously don't have any real data for that case, but I do have a test file with five actual cylinders that all have samples over the whole course of the dive. The end result looks messy as hell, but what did you expect? HOWEVER. The only way to do this sanely was - actually make the "struct plot_info" have all the cylinder pressures (so no "sensor index and pressure" - every cylinder has a pressure for every plot info entry) This obviously makes the plot_info much bigger. We used to have MAX_CYLINDERS be a fairly generous 8, which seems sane. The planning code made that 8 be 20. That seems questionable. But whatever. The good news is that the plot-info should hopefully get freed, and only be allocated one dive at a time, so the fact that it is big and nasty shouldn't be a scaling issue, though. - the "populate_pressure_information()" function had to be rewritten quite a bit. The good news is that it's actually simpler now, although I would not go so far as to really call it simple. It's still complicated and suble, but now it explicitly just does one cylinder at a time. It *used* to have this insanely complicated "keep track of the pressure ranges for every cylinder at once". I just couldn't stand that model and keep my sanity, so it now just tracks one cylinder at a time, and doesn't have an array of live data, instead the caller will just call it for each cylinder. - get rid of some of our hackier stuff, like the code that populates the plot_info data code with the currently selected cylinder number, and clears out any other pressures. That obviously does *not* work when you may not have a single primary cylinder any more. Now, the above sounds like all good things. Yeah, it mostly is. BUT. There's a few big downsides from the above: - there's no sane way to do this as a series of small changes. The change to make the plot_info take an array of cylinder pressures rather than the sensor+pressure model really isn't amenable to "fix up one use at a time". When you switch over to the new data structure model, you have to switch over to the new way of populating the pressure ranges. The two just go hand in hand. - Some of our code *depended* on the "sensor+pressure" model. I fixed all the ones I could sanely fix. There was one particular case that I just couldn't sanely fix, and I didn't care enough about it to do something insane. So the only _known_ breakage is the "TankItem" profile widget. That's the bar at the bottom of the profile that shows which cylinder is in use right now. You'd think that would be trivial to fix up, and yes it would be - I could just use the regular model of firstcyl = explicit_first_cylinder(dive, dc) .. then iterate over the gas change events to see the others .. but the problem with the "TankItem" widget is that it does its own model, and it has thrown away the dive and the dive computer information. It just doesn't even know. It only knows what cylinders there are, and the plot_info. And it just used to look at the sensor number in the plot_info, and be done with that. That number no longer exists. - I have tested it, and I think the code is better, but hey, it's a fairly large patch to some of the more complex code in our code base. That "interpolate missing pressure fields" code really isn't pretty. It may be prettier, but.. Anyway, without further ado, here's the patch. No sign-off yet, because I do think people should look and comment. But I think the patch is fine, and I'll fix anythign that anybody can find, *except* for that TankItem thing that I will refuse to touch. That class is ugly. It needs to have access to the actual dive. Note how it actually does remove more lines than it adds, and that's despite added comments etc. The code really is simpler, but there may be cases in there that need more work. Known missing pieces that don't currently take advantage of concurrent cylinder pressure data: - the momentary SAC rate coloring for dives will need more work - dive merging (but we expect to generally normally not merge dive computers, which is the main source of sensor data) - actually taking advantage of different sensor data from different dive computers But most of all: Testing. Lots and lots of testing to find all the corner cases. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>