aboutsummaryrefslogtreecommitdiffstats
path: root/dive.c
AgeCommit message (Collapse)Author
2014-03-06Initial implementation of git save formatGravatar Linus Torvalds
This saves the dive data into a git object repository instead of a single XML file. We create a git object tree with each dive as a separate file, hierarchically by trip and date. NOTE 1: This largely duplicates the XML saving code, because trying to share it seemed just too painful: the logic is very similar, but the details of the actual strings end up differing sufficiently that there are tons of trivial differences. The git save format is line-based with minimal quoting, while XML quotes everything with either "<..\>" or using single quotes around attributes. NOTE 2: You currently need a dummy "file" to save to, which points to the real save location: the git repository and branch to be used. We should make this a config thing, but for testing, do something like this: echo git /home/torvalds/scuba:linus > git-test to create that git information file, and when you use "Save To" and specify "git-test" as the file to save to, subsurface will use the new git save logic to save to the branch "linus" in the repository found at "/home/torvalds/scuba". NOTE 3: The git save format uses just the git object directory, it does *not* check out the result in any git working tree or index. So after you do a save, you can do git log -p linus to see what actually happened in that branch, but it will not affect any actual checked-out state in the repository. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-05Another small tweak to whitespace toolGravatar Dirk Hohndel
clang-format doesn't appear to reindent multi line #define statements correctly - so this hopefully will clean those up. The included whitespace corrections to the code should stay in place when using the updated tool. This includes cleaning up some multi-line comments that were messed up the last time around as well as a few other minor changes. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-03Whitespace cleanupGravatar Dirk Hohndel
Minor change to the perl postprocessing script and resulting changes to the affected source files. This deals with two issues: - "foreach"-like structures were not always treated correctly - some longer calculations that ended on "+ constant" were reformatted in a rather unatractive manner In one source file (divelist.c) I ended up adding braces to the sources... trying to cascade the indentation further down without having the block there seemed a lot more trouble than it's worth. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-28Fix negative value for depths in Information BoxGravatar Nicu Badescu
The get_depth_units function was expecting an unsigned int as a first parameter. When it received a negative integer, the function made a cast to an unsigned int, resulting in a very big number. Signed-off-by: Nicu Badescu <badescunicu@yahoo.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-27Massive automated whitespace cleanupGravatar Dirk Hohndel
I know everyone will hate it. Go ahead. Complain. Call me names. At least now things are consistent and reproducible. If you want changes, have your complaint come with a patch to scripts/whitespace.pl so that we can automate it. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-16Fix missed "+0.5" rounding - use rint() insteadGravatar Linus Torvalds
In commit 23baf20f569f (Use "rint()" instead of rounding manually with "+ 0.5") I had missed this one remaining place where we rounded things by adding "+0.5" and then truncated. Fix that up. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-12Use "rint()" instead of rounding manually with "+ 0.5"Gravatar Linus Torvalds
rint() is "round to nearest integer", and does a better job than +0.5 (followed by the implicit truncation inherent in integer casting). We already used 'rint()' for values that could be negative (where +0.5 is actively wrong), let's just make it consistent. Of course, as is usual for the messy C math functions, it depends on the current rounding mode. But the default round-to-nearest is what we want and use, and the functions that explicitly always round to nearest aren't standard enough to worry about. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16Convert the C code to using stdbool and true/falseGravatar Anton Lundin
Earlier we converted the C++ code to using true/false, and this converts the C code to using the same style. We already depended on stdbool.h in subsurfacestartup.[ch], and we build with -std=gnu99 so nobody could build subsurface without a c99 compiler. [Dirk Hohndel: small change suggested by Thiago Macieira: don't include stdbool.h for C++] Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-15Remove unused variableGravatar Anton Lundin
Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-11Don't show tanks that aren't used during a diveGravatar Dirk Hohndel
Some dive computers will always download all tanks that they store, not just the ones used in a dive. Most people only want to see the tanks that they actually used during the dive (and for the others there's an option to go back to the old behavior, just in case). All this is only in memory / during runtime. If the dive computer provided the extra data we will not throw it away. Fixes #373 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-11Properly handle user dive merge requestsGravatar Linus Torvalds
When the user asks to merge dives in the divelist, we would always use the "try tp find matching dive computers and merge at an offset" model. That is incorrect if the intent is to actually merge two *identical* dives (with different dive computers), as opposed to merging two short dives into one longer one with a surface interval. Normally this doesn't ever trigger (the "same dive" merging will have been done automatically after downloading from the dive computer), but if the dive computer times are off, and the user fixes them, and then asks to merge dives, we should use the non-offset dive merging logic. We already have that "likely_same_dive()" function that is used to determine when downloaded dives get merged, so just use it for the user merge case too. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-07Add a unique id to every diveGravatar Dirk Hohndel
This id is just held in memory. It's not supposed to be used for anything but having a unique handle that represents a dive. Whenever you need to remember a dive across an operation that might change the dive_table, this is what you should hold on to, not a dive number, a dive pointer, or anything like that. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-20Silence a few warningsGravatar Dirk Hohndel
None of these are actual bugs. But none of the fixes are harmful, either. And much as I hate adding the 'default' clauses, I'd rather not have the build output cluttered by invalid warnings. The exception is the fix in divelistview.cpp - while I don't think it is possible for this function to be called with no dive selected, initializing pd to NULL is cheap insurance in case that does happen for some weird reason. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-29Editing air or water temperature should modify dive computer, not diveGravatar Dirk Hohndel
The dive fields are summary fields, the actual data needs to be in the divecomputer specific fields. Fixes #307
2013-11-20Remove duplicate of add_gas_switch_event in dive.cGravatar Anton Lundin
Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-20Use get_cylinder_index in per_cylinder_mean_depthGravatar Anton Lundin
Use get_cylinder_index that handles SAMPLE_EVENT_GASCHANGE and SAMPLE_EVENT_GASCHANGE2. This also removes the need for a special case where get_gasidx returns -1, because get_cylinder_index always returns the "closest" gas that it finds. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-20Fix potential crash in the per tank sac calculationGravatar Dirk Hohndel
In an inconsistant XML file (like our own dives/test20.xml) it is possible that a gas change event refers to a non-existing gas. In that case get_gasidx returns -1 - which we shouldn't use as index into the arrays. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-19Collect per tank SAC rateGravatar Dirk Hohndel
This is a bit painful, but we basically walk the samples and pick the valid tank from the events. And then we do a simple discrete integration to figure out the mean depth per tank and duration per tank. And then we assemble all that into per tank statistics. Strangely the value calculated here seems slightly higher than one would expect from the overall SAC rate. This inconsistency should be investigated a bit further, but my guess it it's based on the assumption that the DC provided mean depth is possibly more accurate than what we can calculate from the profile. Fixes #284 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-19Only translate default tagsGravatar Maximilian Güntner
We translate only tags we know since possible translations of custom tags (provided by the user) may be out of context and therefore wrong. Signed-off-by: Maximilian Güntner <maximilian.guentner@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-18Shift times of selected divesGravatar Robert Helling
This patch adds the possibility to shift the times of all selected dives by a fixed amount to correct for time zone problems or mis-set dive computer clocks. Select the dives and right click in the dive list. [Dirk Hohndel: added .ui file to FORMS and fixed some whitespace damage] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-16Removed duplicated method.Gravatar Tomaz Canabrava
This patch removes a duplicated method: get_divenr and get_index_for_dive. The two are exactly the same ( if my c is not broken, but I may be broken since I'm working like crazy for almost 30h nonstop. ), so please take a good look before applying this one. [Dirk Hohndel: Tomaz took the slightly broken of the two implementations, so I switched that out for the correct one] Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-08Be consistent when passing around gas data in the plannerGravatar Dirk Hohndel
We need to make sure that the correct segment has the correct gas assigned to it - and that those gases are correctly tracked when editing a manually added dive as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-07Include the cylinder information in a dive added with "Add Dive"Gravatar Dirk Hohndel
We only copied the samples, but not the related cylinder data. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-02Fix warning about ambiguous if / else nestingGravatar Dirk Hohndel
Should have cleaned that up when committing the code. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-02Replaced the tag implementationGravatar Maximilian Güntner
The new implementation supports custom tags which are provided by the user as well as default tags which are provided by subsurface. Default tags can be translated and will be written to XML in their non-localized form. Signed-off-by: Maximilian Güntner <maximilian.guentner@gmail.com>
2013-10-11Fix dive planner sidebar depth unitsGravatar Linus Torvalds
The dive planner always showed the depth in our internal units, ie millimeter, in the sidebar that showed the plan points. That made little sense in metric mode, and none at all in imperial. The _graph_ showed things in meter and feet. So make the DivePlannerPointsModel always convert things to and from the user units. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-09Next step towards working translationsGravatar Dirk Hohndel
This may seem like a really odd change - but with this change the Qt tools can correctly parse the C files (and qt-gui.cpp) and get the context for the translatable strings right. It's not super-pretty (I'll admit that _("string literal") is much easier on the eye than translate("gettextFromC", "string literal") ) but I think this will be the price of success. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-07Remove info.c/info.hGravatar Dirk Hohndel
The one remaining helper function in there was moved to maintab.cpp (which was the one remaining user). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-07dive.c: fix compile error for missing INT_MAXGravatar Lubomir I. Ivanov
file requires <limits.h> to solve: error: INT_MAX undeclared gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06Trying to switch to Qt translationGravatar Dirk Hohndel
This compiles and looks about right, but it doesn't appear to work, yet. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06First steps towards removing glib dependenciesGravatar Dirk Hohndel
- remove the build flags and libraries from the Makefile / Configure.mk - remove the glib types (gboolean, gchar, gint64, gint) - comment out / hack around gettext - replace the glib file helper functions - replace g_ascii_strtod - replace g_build_filename - use environment variables instead of g_get_home_dir() & g_get_user_name() - comment out GPS string parsing (uses glib utf8 macros) This needs massive cleanup, but it's a snapshot of what I have right now, in case people want to look at it. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-04Added configuration options for vertical speed units.Gravatar Patrick Valsecchi
Some people (free divers) are loving ft/s or m/s units for vertical speeds. Now they can choose between /min or /s in the configuration (only Qt UI). Signed-off-by: Patrick Valsecchi <patrick@thus.ch> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-09-19Hook up adding a diveGravatar Dirk Hohndel
This gets things mostly right. It creates a dive and uses the planner widget to create samples which are copied into the dive. It fills in some reasonable defaults (DC model, timestamp), but doesn't allow editing the timestamp (or the temperatures and air pressure). On accept the planner gets reset and the dive appears correctly in the dive list. Cancel still needs to be handled. And I bet there are many subtle bugs lurking here and there. But it's a start. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-09-18Use the right event typeGravatar Anton Lundin
11 is SAMPLE_EVENT_GASCHANGE, and thats the one that doesn't contain any He-part. The type where He and O2 is packed togeather is 25, SAMPLE_EVENT_GASCHANGE2. Left to implement is to figure out the type of the event when we read the xml, so we can create the right type there. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-05Merge dive tags when merging divesGravatar Linus Torvalds
.. otherwise the dive tags generally end up cleared when you download a duplicate dive from another dive computer. This uses MERGE_NONZERO, which means that if one of the dives has tags set, we'll prefer those tags. If both dives have tags set, we take the tags from the first ("preferred") dive. We could do a "just or all the bits together" too. But this way we at least take a set of tags that are consistent (ie we don't get both "boat" and "shore" set unless one of the original dives already had that inconsistency) Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-22Get the math right for cylinder model setData functionGravatar Dirk Hohndel
This is a fun one. We only want to mark the divelist changed if the user actually changed something. So we try really hard to compare what was entered with what was there and only if it is different do we overwrite existing values and record this as a change to the divelist. An additional challenge here is the fact that the user needs to enter a working pressure before they can enter a size (when in cuft mode). That is not really intuitive. We work around this by assuming working pressure is 3000psi if a size is given in cuft - but then if the user changes the working pressure, that changes the volume. Now going back and changing the volume again does the trick. Or enter the working pressure FIRST and then the volume... This also changes the incorrect MAXPRESSURE to WORKINGPRESSURE and uses the text WorkPress in English (Gtk code used MaxPress which was simply wrong - this is just the design pressure or working pressure, not some hard maximum. In fact, people quite commonly "overfill" these tanks. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-02Added code to Select a dive, fixed minor annoyances.Gravatar Tomaz Canabrava
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-23Retain event sort order on restartGravatar Miika Turkia
The events that had same time stamp were reversed in order on every new load of the log file. This patch will keep the order static. (Changing order is annoying when using version control to store the logs.) Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-28Use the new get_o2()/get_he() helper functions more widelyGravatar Linus Torvalds
They do the "02=0 means air" thing autmatically, and make for less typing. So use them more widely in places that looked up the o2 and he permille values of a gasmix. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-28When merging dives, match up the cylinders to each other using gasmixGravatar Linus Torvalds
.. so that different computers that have different ordering of the same cylinders will see the end result the same way. This also fixes up the sample sensor index and generates special initial tank change events for the dive computers that had their cylinder indexes renamed on them. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-17Manually add gas changes to a diveGravatar Dirk Hohndel
Create a little widget that lists all the gases / tanks we know about and allow the user to pick one of them. Turns out that add_event only added events at the end of the list - but we treat that list as chronologically sorted. So I fixed that little mis-feature as well. This does raise the question whether we need the inverse operation (removing a gas change). And if there are other things that we should be able to manually edit, now that we have the infrastructure for this neat little context menu... See #60 -- this doesn't address all of the issues mentioned there, but at least deals with the 'headline' of the feature request... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-08Don't strdup(NULL)Gravatar Dirk Hohndel
merge_text() could call strdup(NULL) if one pointer was "" and the other NULL. This commit fixes that. Reported-by: fhuberts Analyzed-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-03-03Try to capture some more potential buffer overflows caused by localizationGravatar Dirk Hohndel
A couple of these could clearly cause a crash just like the one fixed by commit 00865f5a1e1a ("equipment.c: Fix potential buffer overflow in size_data_funct()"). One would append user input to fixed length buffer without checking. We were hardcoding the (correct) max path length in macos.c - replaced by the actual OS constant. But the vast majority are just extremely generous guesses how long localized strings could possibly be. Yes, this commit is likely leaning towards overkill. But we have now been bitten by buffer overflow crashes twice that were caused by localization, so I tried to go through all of the code and identify every possible buffer that could be affected by this. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-26Another update to DivingLog importGravatar Dirk Hohndel
This fixes two bugs: - we overwrote the max depth that we read from an XML file with 0 if there are no samples - we didn't parse the DepthAvg tag in the DivingLog XML Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-25Take incompressibility of gas into account at higher pressuresGravatar Linus Torvalds
This creates a helper function called "gas_volume()" that takes the cylinder and a particular pressure, and returns the estimated volume of the gas at surface pressure, including proper approximation of the incompressibility of gas. It very much is an approximation, but it's closer to reality than assuming a pure ideal gas. See for example compressibility at http://en.wikipedia.org/wiki/Compressibility_factor Suggested-by: Jukka Lind <jukka.lind@iki.fi> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-24Use the improved duration and average depth for everythingGravatar Linus Torvalds
The code was written to get the SAC rate correct, but we probably do want to have the duration and mean depth of the dive always be shown for the non-surface-time. So move the code from the sac-rate calculation to the generic dive fixup part. This makes the dive list and statistics all show the duration as the under-water duration, which is not necessarily the same as "difference between beginning and end of dive". Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-24Fix SAC calculations for dives without any samplesGravatar Linus Torvalds
We computed a made-up average depth based on the maximum depth, and used that. That's questionable even if we didn't have any explicit average depth to begin with, but it's particularly wrong if we did have an explicit average depth to use. Now, admittedly we have no way to actually create fake dives like this with a particular average depth, so this really doesn't make any difference in real life. But we should do this right. Also, make the XML be in the format that subsurface actually saves things in (mainly things like cylinder sizes having an extra decimal place, but also ordering of XML elements). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-24Fix up SAC calculations for ATM/bar confusionGravatar Linus Torvalds
We even documented that we did SAC in bar*l/min, but the "S" in SAC stands for "Surface". So we should normalize SAC rate to surface pressure, not one bar. It's a tiny 1% difference, and doesn't actually matter in practice, but it's noticeable when you want to explicitly test for SAC-rate by creating a test-dive that averages exactly 10m. Suddenly you don't get the round numbers you expect. [ Side note: 10m is not _exactly_ one extra atmosphere according to our calculations, but it's darn close in sea water: the standard salinity of 1.03 kg/l together with the standard acceleration of 9.81m/s^2 gives an additional pressure of 1.01 bar, which is within a fraction of a percent of one ATM. Of course, divers have likely chosen that value exactly for the math to come out that way, since the true average salinity of seawater is actually slightly lower ] So here's a few test-dives, along with the SAC rate fixup to make them look right. (There's also a one-liner to dive.c that makes the duration come out right if the last sample has a non-zero depth, and the previous sample did not: one of my original test-dives did the "average 10m depth" by starting at 0 and ending at 20m, and dive.c got a tiny bit confused about that ;) [ The rationale for me testing our SAC rate calculations in the first place was that on snorkkeli.net user "Poltsi" reported that our SAC rate calculations differ from the ones that Suunto DM4 reports. So I wanted to verify that we did things right. Note that Poltsi reported differences larger than the difference of BAR/ATM, so this is not the cause. I'll continue to look at this. ] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-17Fix ordering issue in fixupGravatar Linus Torvalds
We have this oddity in "fixup_dive()" that we fix up the dive water temperates and durations by looking over all the dive computer data. But we actually call that *before* we've fixed-up the dive computer data. So the water temperature is there in the samples, but hasn't made it to the generic dive computer water temperature yet, so then it doesn't make it into the dive structure either. Until the *second* time, when we have load the (partially fixed-up) data. Acked-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-16Skip mean depth comparison when no such data existGravatar Miika Turkia
Downloading dives from the dive computer attempts to merge same dives, e.g. when multiple dive computers are used. If the mean depth is zero when downloading from DC this comparison fails resulting in not merging the multiple dive computers used on one dive. This patch skips the mean depth comparison when this information is not available. Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>