aboutsummaryrefslogtreecommitdiffstats
path: root/libdivecomputer.c
AgeCommit message (Collapse)Author
2014-03-15Don't check for tank size information only on first tankGravatar Dirk Hohndel
commit d681bdcb6308 ("Only use default cylinder for first one") has a stupid bug in that it only calls get_tanksize for the first tank. That's of course completely bogus. Thanks to Linus for catching this. Reported-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-15Only use default cylinder for first oneGravatar Dirk Hohndel
When downloading from a divecomputer it makes little sense to assume that all tanks are the default cylinder. There's a good case to be made for having a default first cylinder (you always dive with your own cylinder, or you are always on a dive boat with AL80 tanks), but in multi-cylinder situations this is much more likely to cause unintended harm; for example for those dive computers that always report their maximum number of cylinders, even if some of them aren't used. Here setting a default cylinder turns those entries from obviously empty into something that appears to have meaning (i.e., cylinder type is filled in) even though this was just a default added by Subsurface. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-08Avoid calling free on uninitialized dive variableGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-06Fix memory leak when parsing a dive failsGravatar Dirk Hohndel
We had all these repetitive calls to dc_parser_destroy but didn't free the already allocated dive. 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-03Remove pointless assignmentsGravatar Dirk Hohndel
tissue_tolerance wasn't used after it was assigned. type was overwritten after it was assigned. serial was overwritten after the last /= 100. event is assigned in the for loop. clear isn't used after the assignment 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-26set the download progress bar to zero after a downloadGravatar Danilo Cesar Lemes de Paula
Before that, the behaviour was that in case of an error or a re-download, the progress bar would appear for a few milliseconds with the old value. Signed-off-by: Danilo Cesar Lemes de Paula <danilo.eu@gmail.com> 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-02-12Fix default value for missing surface pressure from divecomputerGravatar Linus Torvalds
We should *not* default to the incorrect "1 bar". Instead, we should leave the resuling pressure at 0 mbar, which leaves visual entries empty and uses the default surface pressure for calculations. Reported-by: Pedro Neves <nevesdiver@gmail.com> Cc: Patrick Valsecchi <patrick@thus.ch> Cc: Dirk Hohndel <dirk@hohndel.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-10Add support for heartrate and bearing information in samplesGravatar Linus Torvalds
libdivecomputer already supports this, but we didn't save it. Tested-by: Oscar Isoz <jan.oscar.isoz@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-27Fix the semantics of the dive_cbGravatar Dirk Hohndel
Libdivecomputer wants us to return true if it should continue to loop over the dives and false if we want to stop. Don't pass errors back. 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-08Write the event data to the libdivecomputer log.Gravatar Jef Driesen
For some devices, the event data contains important data that is required for parsing the dives, but which is not present in the full memory dump. Signed-off-by: Jef Driesen <jefdriesen@telenet.be> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-08libdivecomputer.c: Try not to pass NULL to fopen()Gravatar Lubomir I. Ivanov
C99 7.1.4, says nothing about passing NULL to fopen(), which means that it isn't portable and there are no guaranties that the return will be a NULL pointer or that that a library implementation will not assert or SYSSEGV in the middle of the fopen() branch. libdivecomputer.c's 'dumpfile_name' and 'logfile_name' could cause problems in that regard. A possible fix for #411 Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-24Enable libdivecomputer log or dump from the UIGravatar Dirk Hohndel
Pick filenames for these functions as they are selected. Use the windows-safe fopen function. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-24Support downloading memory dumps.Gravatar Jef Driesen
Signed-off-by: Jef Driesen <jefdriesen@telenet.be> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-24Enable diagnostic logging from libdivecomputer.Gravatar Jef Driesen
Signed-off-by: Jef Driesen <jefdriesen@telenet.be> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-24Remove an unnecessary function call.Gravatar Jef Driesen
Signed-off-by: Jef Driesen <jefdriesen@telenet.be> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-11Add some sanity checksGravatar Anton Lundin
If first sample is not a DC_SAMPLE_TIME, we would have bin dereferencing a null pointer. This might actually never happen, unless we talk to a really weird dc, but this makes the static analyzer happier. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-29Add comment for "below floor" eventGravatar Dirk Hohndel
This one is a tough one for translators. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-27Remove some constants and use helpers insteadGravatar Anton Lundin
We have allot of helpers, use them instead of local variants. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-23Use a default tank when populating tank data after downloadGravatar Dirk Hohndel
This is super-simplistic and also is kinda wrong. It forces all tanks that haven't been specified by the DC (so far only Atomics Aquatics Cobalt and UEMIS Zurich (which doesn't even use libdivecomputer) to be AL80. Just as we used AL80 as default for manually adding tanks. Obviously this needs to become an option where the user can pick. See #145 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-08Fixed conversion error when downloading salinity from DCGravatar Patrick Valsecchi
libdivecomputer doesn't give the salinity in kg/l, but in g/l and subsurface works with g/10l. So the salinity was too big by a factor of 1000. Signed-off-by: Patrick Valsecchi <patrick@thus.ch> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06Delete code and files that are no longer usedGravatar Dirk Hohndel
Most of this is Gtk related, some of it is helpers that we don't need anymore. I love the diffstat. 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-03Importing salinity and atmospheric pressure from DC.Gravatar Patrick Valsecchi
One cannot expect #ifdef to work with enum values. So the code for getting the salinity was basically never compiled in. And it was putting it in the wrong location anyway (in the dive struct instead of the divecomputer struct where it is expected). I took the opportunity to add the reading of the atmospheric pressure as well. Signed-off-by: Patrick Valsecchi <patrick@thus.ch> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-09-19Identify below floor event type properly.Gravatar Michael Andreen
This event is on when accumulating deco time. Once you reach the floor deco time will start decreasing and the event will stop. Going below the floor again will re-activate the event. Also identify event type 13 in DM4 imports as airtime. Signed-off-by: Michael Andreen <harv@ruin.nu> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-08-07ifdef out includes when we build without gtkGravatar Anton Lundin
Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-18Converting the device_info list into a Qt data structureGravatar Dirk Hohndel
This data structure was quite fragile and made 'undo' when editing rather hard to implement. So instead I decided to turn this into a QMultiMap which seemed like the ideal data structure for it. This map holds all the dive computer related data indexed by the model. As QMultiMap it allows multiple entries per key (model string) and disambiguates between them with the deviceId. This commit turned out much larger than I wanted. But I didn't manage to find a clean way to break it up and make the pieces make sense. So this brings back the Ok / Cancel button for the dive computer edit dialog. And it makes those two buttons actually do the right thing (which is what started this whole process). For this to work we simply copy the map to a working copy and do all edits on that one - and then copy that over the 'real' map when we accept the changes. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-20Added code to cancel the thread.Gravatar Tomaz Canabrava
I think it's self explanatory - When user clicks on 'Cancel', the interface will wait for the trhead to quit then will close itself. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-05-20Skeleton code for a non-blocking UI thread for downloading dives from the DCGravatar Tomaz Canabrava
This is the skeleton code for a non-blocking ui-thread It already creates the first-thread ( 'do not block the ui' ) and the second thread ('download from the dive computer') We can in the future merge both in the same place - I didn't want to do that now because the download function is written in the libdivecomputer.c code, and I cant just transform that to a QThread and use signals, so I used two threads for that. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-05-03Remove the majority of the Gtk related codeGravatar Dirk Hohndel
- rip all Gtk code from qt-gui.cpp - don't compile Gtk specific files - don't link against Gtk libraries - don't compile modules we don't use at all (yet) - use #if USE_GTK_UI on the remaining files to disable Gtk related parts - disable the non-functional Cochran support while I'm at it 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-07Don't re-use the dive computer model string for all downloaded divesGravatar Linus Torvalds
When we download dives with libdivecomputer, we create this strdup'ed name of the model information, but we then re-use that (single) strdup allocation for every dive we download. This works fine *until* you start freeing those dives (possibly directly after the download because they are redundant), at which point things go to hell in a handbasket, since there is just the one allocation for all the different dives. Fix by just doing another strdup() at the point where we assign the model information to the dive computer. Reported-by: Marc Merlin <marc@merlins.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-03Correctly reset stop depth if we receive NDL sample from libdivecomputerGravatar Dirk Hohndel
The existing code forgot to reset the stopdepth to 0 which resulted in a bogus safety stop being displayed on some divecomputers after the diver finished their deco obligation. Reported-by: Jan.Schubert <Jan.Schubert@GMX.li> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-29Add missing strings for translationsGravatar Dirk Hohndel
Mostly in new code, but some of them are strings in older code that have been missed in the past. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24Centralization for Kelvin and Standardization to milliKelvinGravatar Jan Schubert
This centralizes all occurrences of Kelvin to dive.h and standardizes all usages to milliKelvin. [Dirk Hohndel: renamed the constant plus minor white space cleanup] Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-23Move more dive computer filled data to the divecomputer structureGravatar Linus Torvalds
This moves the fields 'duration', 'surfacetime', 'maxdepth', 'meandepth', 'airtemp', 'watertemp', 'salinity' and 'surface_pressure' to the per-divecomputer data structure. They are filled in by the dive computer, and normally not edited. NOTE! All actual *use* of this data was then changed from dive->field to dive->dc.field programmatically with a shell-script and sed, and the result then edited for details. So while the XML save and restore code has been updated, all the displaying etc will currently always just show the first dive computer entry. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-22libdivecomputer: add air temperature fixups for SuuntoGravatar Linus Torvalds
libdivecomputer doesn't actually seem to support air temperature reporting at all, but at least for Suunto dive computers the air temperature is recorded as the temperature for the first sample. So since we already have vendor-specific libdivecomputer hacks, let's just add that one as a rule. It may be that other divecomputers do this too, so this adds it as a generic concept - it's just that right now the flag for "air temperature in first sample" is only set for Suunto dive computers. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-22Fix suunto serial number confusion in libdivecomputerGravatar Linus Torvalds
libdivecomputer has started giving the Suunto serial numbers in a different format, which means that we have the same device with two different serial numbers, and then we need two different ways of turning the numerical entity into a string. Look at the number pattern to see figure out which version of the format it is that libdivecomputer is reporting, and turn it back into the original format so that we can reliably give the right string for it. This also mean sthat the device ID stays the same regardless of libdivecomputer version. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-14Centralising and redefining values as integersGravatar Jan Schubert
This patch centralizes the definition for surface pressure, oxygen in air, (re)defines all such values as plain integers and adapts calculations. It eliminates 11 (!) occurrences of definitions for surface pressure and also a few for oxygen in air. It also rewrites the calculation for EAD, END and EADD using the new definitons, harmonizing it for OC and CC and fixes a bug for EADD OC calculation. And finally it removes the unneeded variable entry_ead in gtk-gui.c. Jan Signed-off-by: Jan Schubert <Jan.Schubert@GMX.li> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-09Assemble the actual Suunto serial numberGravatar Linus Torvalds
It turns out that the serial number returned by libdivecomputer isn't really the serial number as interpreted by the vendor. Those tend to be strings, but libdivecomputer gives us a 32bit number. Some experimenting showed that for the Suunto devies tested the serial number is encoded in that 32bit number: It so happens that the Suunto serial number strings are strings that have all numbers, but they aren't *one* number. They are four bytes representing two numbers each, and the "23500027" string is actually the four bytes 23 50 00 27 (0x17 0x32 0x00 0x1b). And libdivecomputer has incorrectly parsed those four bytes as one number, not as the encoded serial number string it is. So the value 389152795 is actually hex 0x1732001b, which is 0x17 0x32 0x00 0x1b, which is - 23 50 00 27. This should be done by libdivecomputer, but hey, in the meantime this at least shows the concept. And helps test the XML save/restore code. It depends on the two patches that create the whole "device.c" infrastructure, of course. With this, my dive file ends up having the settings section look like this: <divecomputerid model='Suunto Vyper Air' deviceid='d4629110' serial='01201094' firmware='1.1.22'/> <divecomputerid model='Suunto HelO2' deviceid='995dd566' serial='23500027' firmware='1.0.4'/> where the format of the firmware version is something I guessed at, but it was the obvious choice (again, it's byte-based, I'm ignoring the high byte that is zero for both of my Suuntos). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-30First step in cleaning up cylinder pressure sensor logicGravatar Linus Torvalds
This clarifies/changes the meaning of our "cylinderindex" entry in our samples. It has been rather confused, because different dive computers have done things differently, and the naming really hasn't helped. There are two totally different - and independent - cylinder "indexes": - the pressure sensor index, which indicates which cylinder the sensor data is from. - the "active cylinder" index, which indicates which cylinder we actually breathe from. These two values really are totally independent, and have nothing what-so-ever to do with each other. The sensor index may well be fixed: many dive computers only support a single pressure sensor (whether wireless or wired), and the sensor index is thus always zero. Other dive computers may support multiple pressure sensors, and the gas switch event may - or may not - indicate that the sensor changed too. A dive computer might give the sensor data for *all* cylinders it can read, regardless of which one is the one we're actively breathing. In fact, some dive computers might give sensor data for not just *your* cylinder, but your buddies. This patch renames "cylinderindex" in the samples as "sensor", making it quite clear that it's about which sensor index the pressure data in the sample is about. The way we figure out which is the currently active gas is with an explicit has change event. If a computer (like the Uemis Zurich) joins the two concepts together, then a sensor change should also create a gas switch event. This patch also changes the Uemis importer to do that. Finally, it should be noted that the plot info works totally separately from the sample data, and is about what we actually *display*, not about the sample pressures etc. In the plot info, the "cylinderindex" does in fact mean the currently active cylinder, and while it is initially set to match the sensor information from the samples, we then walk the gas change events and fix it up - and if the active cylinder differs from the sensor cylinder, we clear the sensor data. [Dirk Hohndel: this conflicted with some of my recent changes - I think I merged things correctly...] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-30Update deco handlingGravatar Dirk Hohndel
This commit makes deco handling in Subsurface more compatible with the way libdivecomputer creates the data. Previously we assumed that having a stopdepth or stoptime and no ndl meant that we were in deco. But libdivecomputer supports many dive computers that provide the deco state of the diver but with no information about the next stop or the time needed there. In order to be able to model this in Subsurface this adds an in_deco flag to the samples. This is only stored to the XML file when it changes so it doesn't add much overhead but will allow us to display some deco information on dive computers like the Atomic Aquatics Cobalt or many of the Suuntos (among others). The commit also removes the old event based deco code that was commented out already. And fixes the code so that the deco / ndl information is stored for the very last sample as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-30Add time stamp to the debugging printout of vendor specific samplesGravatar Dirk Hohndel
They are useful for debugging things in libdivecomputer and this way it's easier to match the data to specific points in the dive profile. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28When libdivecomputer reports a DECOSTOP or DEEPSTOP, set ndl to 0Gravatar Dirk Hohndel
Without this deco could be mistaken as safety stop (in the case where between two samples we go from a positive ndl to suddenly having a stop - so we never reach ndl of 0) Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-28Don't match existing dives by date if the dive computers are known to be ↵Gravatar Linus Torvalds
different When downloading from a dive computer, we fall back on matching the exact date of the dive if we can't tell whether we already have that exact dive computer data some other way. However, if you have multiple dive computers and they are sufficiently well synchronized, they might actually have the exact same date, despite the fact that we do want to download both dive computers. We do check the dive start to the exact second, so this sounds unlikely, but with dive computers rounding time to the next minute etc, it's not as unlikely as you'd think. Dirk hit it. So when we match against date, do check that the dive computer might actually be one we've already downloaded from. If we have full model information, we can dismiss the "match date" logic. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>