aboutsummaryrefslogtreecommitdiffstats
path: root/core/dive.h
AgeCommit message (Collapse)Author
2018-01-08Make a few functions of static linkageGravatar Berthold Stoeger
Make functions in core/file.c, core/parse.c and core/import-csv.c that were not used outside their translation unit of static linkage. parse_date is moved from core/file.c to core/import-csv.c, since it is used only there. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-06Trivial: remove redundant declarations of downloadTableGravatar Berthold Stoeger
downloadTable was declared twice in "dive.h". Remove one occurence. Moreover, "uemis-downloader.c" also declared downloadTable. This can likewise be removed, because "uemis-downloader.c" indirectly includes "dive.h". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-04Turn autogroup from short into boolGravatar Berthold Stoeger
All users of autogroup are clearly expecting a boolean value, so let the type reflect this. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-28cleanup: correct signature and declare externGravatar Jan Mulder
clear_vpmb_state() was declared with incorrect signature, and all functios in this change are extern, so declare them as such. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-13Enable removal of pictures from different dives at the same momentGravatar Stefan Fuchs
Suggested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-12-11Remove second parameter (bool force) in set_filename()Gravatar Berthold Stoeger
The last force=false case was removed in commit 96d1cc570e31396039e4970d2bf75d5f00f1e550. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-27Add debug function dump_cylindersGravatar Stefan Fuchs
This function can be used to dump print all cylinder data. Signed-off-by: Stefan Fuchs <sfuchs@gmx.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-25Cleanup: remove unused extern declarationGravatar Berthold Stoeger
Removes the extern declaration of edit_dive, which wasn't defined anywhere. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-20Make handling of booleans consistent on the C++-side of preferencesGravatar Berthold Stoeger
In general, the C++-side of the preferences code consistently uses the bool data type for boolean settings. There are five exceptions, which use short instead: showPo2 showPn2 showPhe saveUserIdLocal displayInvalidDives This patch attempts to make the code more consistent by turning these into bools as well. Tests showed that writing as short and reading as bool is handled gracefully by the Qt variant code. Therefore, an upgrade should not cause user-visible changes to their settings. As a bonus, two extern declarations of the set_save_userid_local() function, which is not defined anywhere, were removed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-18Prevent annoying signed/unsigned comparison warningGravatar Berthold Stoeger
Commit d6c013f303 introduced a cast to avoid a signed/unsigned comparison warning for all translation units that included core/dive.h. Commit 1f8506ce64 then changed the definition of duration_t from unsigned to signed, inverting the effect of d6c013f303. Thus, revert d6c013f303 to allow compilation with -Wall without flooding. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-17Properly declare 'has_gaschange_event()' functionGravatar Linus Torvalds
It's already used in core/gaspressures.c where it was declared privately, and we'll have a new user in the profile code, so just declare it in a proper header file like it should have been. 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-09CNS can be higher than 255%Gravatar Jan Mulder
I'm sure this bug has heen here forever, but the CNS clock is not very relevant for most divers, and even some technical divers do not care about this value. However, doing long decompression dives, the value can easily grow over 100%, and a lot further. For example, the OSTC computers use 2 bytes to store the CNS value in the profile data, and I have multiple dives in my logbook going way over 255%. This all said. Just store the CNS value in an unsigned 16 bit. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
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-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-03win32: optimize the console and logging logicGravatar Lubomir I. Ivanov
Currently one has to explicitly use --win32console and/or --win32log to enable a dedicated console (a console window that opens next to the Subsurface window) or to enable file logging on Win32. This patch makes the following changes: - removes the --win32* command line arguments - removes the dedicated console window support - if the app starts from a shortcut and not from a console, always redirect stderr and stdout to _err & _out log files - if the app starts from a console redirect stderr and stdout to that console Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-10-30Add new helfer for strcasestrGravatar Dirk Hohndel
That's not a standard functions, so let's just build it. This is not the most efficient way to write it, but it will do. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-26Set error callback helperGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-19dive.h: add handling of NULL in get_dive_dc()Gravatar Lubomir I. Ivanov
This line: dc = &dive->dc can SIGSEGV for a NULL 'dive' pointer. return NULL if 'dive' is NULL. Also handle NULL 'dc' in get_gasmix() and set 'ev' to NULL. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-10-19Use displayed_dc instead of current_dcGravatar Robert C. Helling
current_dc is a macro that determines the dive computer based on the current dive number. When the planner is started from an emtpy dive list, the dive number ends up being -1 and that doesn't produce a valid dive computer. Use the divecomputer of the displayed_dive instead. This is done via a macro that can also be used in two other places. Without this patch, the planner crashed when called on an empty dive list. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-10-18init_deco correctly identify previous dives and report overlapping divesGravatar Stefan Fuchs
When changing the date/time of a dive in the planner the dive may end up in a totaly new position in respect to date/time of other dives in dive list table. It can be moved to the past or the future before or after other existing dives. It also could overlap with an existing dive. This change enables identification of a new "virtual" dive list position and based on this starts looking for previous dives. Then it (as before the change) does init the deco calculation with any applicable previous dive and surface interval. If some of these applicable dives overlap it returns a neg. surface time which is then used in the planner notes to prohibit display of results. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-16In dive.c make cylinder_renumber an external function...Gravatar Stefan Fuchs
instead of dc_cylinder_renumber() because it is the one which is really useful elsewhere. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-16Used gas in dive planner points: Support for multiple cyl with same gasGravatar Stefan Fuchs
In the planner if one adds two or more cylinders with the same gasmix (e.g. back gas and bottom stage 18/45) the drop down and data in the used gas column of the planner points table will be filled with a more verbose string mentioning also the cyl number and the cyl type description. Makes it easier in such a case to select the right cylinder. Introduces also a helper function which tells you if there is another cylinder with the same gasmix as the provided cylinder. This also has an option if it should consider unused cylinders or not. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-10-04Don't add separate country field, use taxonomyGravatar Dirk Hohndel
The more I looked at the code that added the country to the dive site, the more it seemed redundant given what we have with the taxonomy. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-02[Divesite] request dive countryGravatar Tomaz Canabrava
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
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-20Remove option to apply GFlow at maxdepthGravatar Robert C. Helling
This option should have never been there. This is not how gradient factors are supposed to work. It would only trick users to use the wrong value.. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-08-29Compute variations of plansGravatar Robert C. Helling
Print out partial derivatives of stop times with respect to variation of depth and duratin of last manual segment. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-08-29Store a table of deco stops in plannerGravatar Robert C. Helling
... in addition to struct diveplan which combines all kinds of information Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-08-29Make plan take dive and decotimestep as argumentsGravatar Robert C. Helling
...rather than use a global variable and a macro. This should be a no-op in preparation to allow planning several versions of a dive. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-08-26Hide signed/unsigned comparison warningGravatar Dirk Hohndel
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-28Add "get_gasmix()" helper function to iterate over gas changesGravatar Linus Torvalds
We have a few places that used to get the gasmix by looking at the sensor index in the plot data, which really doesn't work any more. To make it easier for those users to convert to the new world order, this adds a "get_gasmix()" function. The gasmix function takes as its argument the dive, the dive computer, and the time. In addition, for good performance (to avoid looping over the event list over and over and over again) it maintains a pointer to the next gas switch event, and the previous gas. Those need to be initialized to NULL by the caller, so the standard use-case pattern basically looks like this: struct gasmix *gasmix = NULL; struct event *ev = NULL; loop over samples or plot events in increasing time order: { ... gasmix = get_gasmix(dive, dc, time, &ev, gasmix); ... } and then you can see what the currently breathing gas is at that time. If for some reason you need to walk backwards in time, you can just pass in a NULL gasmix again, which will reset the event iterator (at the cost of now having to walk all the events again). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-25Make sample pressure helper functions available to everybodyGravatar Linus Torvalds
We had a "add_sample_pressure()" helper functions that was local to just the libdivecomputer downloading code, but it really is applicable to pretty much any code that adds cylinder pressure data to a sample. Also add another helper: "legacy_format_o2pressures()" which checks the sample data to see if we can use the legacy format, and returns the o2 pressure sensor to use for that legacy format. Because both the XML and the git save format will need a way to save the compatible old-style information, when possible, but save an extended format for when we have data from multiple concurrent sensors. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-25Try to sanely download multiple concurrent cylinder pressuresGravatar Linus Torvalds
This tries to sanely handle the case of a dive computer reporting multiple cylinder pressures concurrently. NOTE! There are various "interesting" situations that this whole issue brings up: - some dive computers may report more cylinder pressures than we have slots for. Currently we will drop such pressures on the floor if they come for the same sample, but if they end up being spread across multiple samples we will end up re-using the slots with different sensor indexes. That kind of slot re-use may or may not end up confusing other subsurface logic - for example, make things believe there was a cylidner change event. - some dive computers might send only one sample at a time, but switch *which* sample they send on a gas switch event. If they also report the correct sensor number, we'll now start reporting that pressure in the second slot. This should all be fine, and is the RightThing(tm) to do, but is different from what we used to do when we only ever used a single slot. - When people actually use multiple sensors, our old save format will start to need fixing. Right now our save format comes from the CCR model where the second sensor was always the Oxygen sensor. We save that pressure fine (except we save it as "o2pressure" - just an odd historical naming artifact), but we do *not* save the actual sensor index, because in our traditional format that was always implicit in the data ("it's the oxygen cylinder"). so while this code hopefully makes our libdivecomputer download do the right thing, there *will* be further fallout from having multiple cylinder pressure sensors. We're not done yet. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21Start cleaning up sensor indexing for multiple sensorsGravatar Linus Torvalds
This is a very timid start at making us actually use multiple sensors without the magical special case for just CCR oxygen tracking. It mainly does: - turn the "sample->sensor" index into an array of two indexes, to match the pressures themselves. - get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index}, since a CCR dive should now simply set the sample->sensor[] indices correctly instead. - in a couple of places, start actually looping over the sensors rather than special-case the O2 case (although often the small "loops" are just unrolled, since it's just two cases. but in many cases we still end up only covering the zero sensor case, because the CCR O2 sensor code coverage was fairly limited. It's entirely possible (even likely) that this migth break some existing case: it tries to be a fairly direct ("stupid") translation of the old code, but unlike the preparatory patch this does actually does change some semantics. For example, right now the git loader code assumes that if the git save data contains a o2pressure entry, it just hardcodes the O2 sensor index to 1. In fact, one issue is going to simply be that our file formats do not have that multiple sensor format, but instead had very clearly encoded things as being the CCR O2 pressure sensor. But this is hopefully close to usable, and I will need feedback (and maybe test cases) from people who have existing CCR dives with pressure data. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-20Unify sample pressure and o2pressure as pressure[2] arrayGravatar Linus Torvalds
We currently carry two pressures around for all the samples and plot info, but the second pressure is reserved for CCR dives as the O2 cylinder pressure. That's kind of annoying when we *could* use it for regular sidemount dives as the secondary pressure. So start prepping for that instead: don't make it "pressure" and "o2pressure", make it just be an array of two pressure values. NOTE! This is purely mindless prepwork. It literally just does a search-and-replace, keeping the exact same semantics, so "pressure[1]" is still just O2 pressure. But at some future date, we can now start using it for a second sensor value for sidemount instead. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-15tankinfomodel.cpp: clamp row index to [0 - MAX_TANK_INFO]Gravatar Lubomir I. Ivanov
MAX_TANK_INFO is a new macro in dive.h to define the maximum number of tank_info_t objects. TankInfoModel's data() and setData() now check for valid row indexes before accessing the tank_info[] array directly. Without this patch TankInfoMode::data() can cause a SIGSEGV. Reported-by: Pedro Neves <nevesdiver@gmail.com> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-27Separate the download thread from the widget logicGravatar Tomaz Canabrava
This is important to not duplicate code for the Qml view. Now the DownloadFromDiveComputer widget is mostly free from important code (that has been upgraded to the core folder), and I can start coding the QML interface. There are still a few functions on the desktop widget that will die so I can call them via the QML code later. I also touched the location of a few globals (please, let's stop using those) - because it was declared on the desktop code and being used in the core. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-26Compute and display gas densityGravatar Robert C. Helling
This appears to be critical for work of breathing so it might be worthwhile to compute. So far only in infobox. For background, see https://www.youtube.com/watch?v=QBajM3xmOtc Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-05-26Adopt planner state caching to new structGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-05-26Assemble global state of planner in a structGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-05-07Refactor Seabear importGravatar Miika Turkia
Moving the GUI independent Seabear import functionality to Subsurface core. This will allow Robert to call it directly from download from DC. Tested with H3 against released and daily versions of Subsurface. The result differs somewhat, but it is actually fixing 2 bugs: - Temperature was mis-interpreted previously - Sample interval for a dive with 1 second interval was parsed incorrectly Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-04-29Add SPDX header to remaining core filesGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-19Tests for minimum gasGravatar Stefan Fuchs
Add automatic tests in TestPlan for minimum gas: - Copy minimum gas result (pressure) to diveplan. - Add cylinder size and working pressure for bottom gas to every dive in TestPlan Hint: Unrealistic cylinder sizes (100l, 200l) have to be used for the very long and deep dives in TestPlan - Add minimum gas check for every dive - Add two additional test dives in TestPlan which produce sane minimum gas results with 24l tank Hint: Deco check for these new dives is commented out at the moment Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-03-11Merge branch 'master' of https://github.com/dje29/subsurfaceGravatar Dirk Hohndel
2017-03-11Change type of divedatepoint.depth to depth_tGravatar Robert C. Helling
... for consistency, while we are at it. There are still some internal depth variables which are ints somebody might take a go at those. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-03-11Make depth conversion work for negative depthsGravatar Robert C. Helling
This is needed in the altitude pressure conversion as there negative altitudes are possible (for diving in the netherlands or the Dead Sea). Signed-off-by: Robert C. Helling <helling@atdotde.de>
2017-03-09Fix potential double/float to int rounding errorsGravatar Jeremie Guichard
Not using lrint(f) when converting double/float to int creates rounding errors. This error was detected by TestParse::testParseDM4 failure on Windows. It was creating rounding inconsistencies on Linux too, see change in TestDiveDM4.xml. Enable -Wfloat-conversion for gcc version greater than 4.9.0 Signed-off-by: Jeremie Guichard <djebrest@gmail.com>