aboutsummaryrefslogtreecommitdiffstats
path: root/dive.c
AgeCommit message (Collapse)Author
2015-06-24Rewrite GPS fix matching code for imports from our webserviceGravatar Dirk Hohndel
The longer I stared at the existing code the less it made sense. So instead I rewrote it in a way that seems logical to me. And added a boatload of debugging output (which needs to be removed, of course). I tested this against more than a hundred dives and it seemed to always pick the right fix. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-21Comparing the address of a member to 0 is pointlessGravatar Dirk Hohndel
Or... this code doesn't do what you think it does. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-21Prevent possible null pointer dereferenceGravatar Dirk Hohndel
Neither of these functions should ever be called with dc == NULL. But it's easy to prevent the potential crash. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-17Make sure cylinder related data is filled when dives are readGravatar Dirk Hohndel
This is re-run every time we update the dive list model for the UI, but we should run it a first time right after loading the dives so that this data is correct even without the UI running - this way the data in headless standalone applications like the HTML exporter is correct as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-17Store the user's unit preferences in git storageGravatar Dirk Hohndel
Save and load a usually unused copy of the preferences with the units that were active the last time the dive list was saved to git storage (this isn't used in XML files); storing the unit preferences in the data file is usually pointless (that's a setting of the software, not a property of the data), but it's a great hint of what the user might expect to see when creating a backend service that visualizes the dive list without Subsurface running - so this is basically a functionality for the core library that Subsurface itself doesn't use but that another consumer of the library (like an HTML exporter) will need. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-05-02Tag list handling: add two new helpersGravatar Dirk Hohndel
taglist_added() simply figures out the tags that are in the new list but not in the original list. taglist_dump() makes debugging things easier. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-24Allow images to be added via the webGravatar Robert C. Helling
This adds a new divelist context menu entry which asks for a URL. The file is retrieved and if it is an image it is added to the cache and the url is associated to dives as with local files. NB this currently only works with URLs pointing directly to images. But it should not be too hard to add the possibility to add a direction via an html file and its image tags. To test: open dives/test43.xml and delete the image and then add the URL http://euve10195.vserver.de/~robert/wreck.jpg Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-24Don't load images too oftenGravatar Robert C. Helling
Factor out image load to find timestamp from loop over dives. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-24Cleaning up variable names in image loadingGravatar Robert C. Helling
Use more explicit variabel names and make the get timestamp function actually return the timestamp rather than getting a pointer argument Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-23When deleting a cylinder, adapt gas changesGravatar Dirk Hohndel
When we delete a cylinder the gas changes in that dive may have to be adjusted. We didn't do this at all in the past. With this commit we should be doing this right for a single dive that is being edited. This does NOT handle multiple dives being edited at the same time (or more specifically - if you have multiple dives selected and delete a cylinder, the dives that had the same set of cylinders (other than the displayed dive) will get that particular cylinder deleted, but won't have their gas change events (and sensor data in the samples) adapted. Possibly we should simply prohibit deleting cylinders when more than one dive are selected. See #834 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-02Only do safety stop of dive has at least max depth of 10mGravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-03-16When loading an image with geodata create a divesite when the dive has none.Gravatar Robert C. Helling
Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-03-16Fixed dive_set_geodata_from_picture segfault.Gravatar Jan Darowski
Segfault did appear when picture had some gps coordinates but there was no dive site assigned to the dive. Signed-off-by: Jan Darowski <jan.darowski@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-03-15Refactored image timestamp checking.Gravatar Jan Darowski
Seperated getting image timestamp from picture_load_exif_data() and ShiftImageTimesDialog::syncCameraClicked() into picture_get_timestamp() and seperated checking timestamp from dive_create_picture() to dive_check_picture_time(). Signed-off-by: Jan Darowski <jan.darowski@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-03-10Import Datatrak/WLog filesGravatar Salvador Cuñat
Sequentially parses a file, expected to be a Datatrak/WLog divelog, and converts the dive info into Subsurface's dive structure. As my first DC, back in 90s, was an Aladin Air X, the obvious choice of log software was DTrak (Win version). After using it for some time we moved to WLog (shareware software more user friendly than Dtrak, printing capable, and still better, it runs under wine, which, as linux user, was definitive for me). Then, some years later, my last Aladin died and I moved to an OSTC, forcing me to look for a software that support this DC. I found JDivelog which was capable of import Dtrak logs and used it for some time until discovered Subsurface existence and devoted to it. The fact was that importing Dtrak dives in JDivelog and then re-importing them in Subsurface caused a significant data loss (mainly in the profile events and alarms) and weird location of some other info in the dive notes (mostly tag items in the original Dtrak software). This situation can't actually be solved with tools like divelogs.de which causes similar if no greater data loss. Although this won't be a core feature for Subsurface, I expect it can be useful for some other divers as has been for me. Comments and issues: Datatrak/Wlog files include a lot of diving data which are not directly supported in Subsurface, in these cases we choose mostly to use "tags". The lack of some important info in Datatrak archives (e.g. tank's initial pressure) forces us to do some arbitrary assumptions (e.g. initial pressure = 200 bar). There might be archives coming directly from old DOS days, as first versions of Datatrak run on that OS; they were coded CP437 or CP850, while dive logs coming from Win versions seems to be coded CP1252. Finally, Wlog seems to use a mixed confusing style. Program directly converts some of the old encoded chars to iso8859 but is expected there be some issues with non alphabetic chars, e.g. "ª". There are two text fields: "Other activities" and "Dive notes", both limited to 256 char size. We have merged them in Subsurface's "Dive Notes" although the first one could be "tagged", but we're unsure that the user had filled it in a tag friendly way. WLog adds some information to the dive and lets the user to write more than 256 chars notes. This is achieved, while keeping compatibility with DTrak divelogs, by adding a complementary file named equally as the .log file and with .add extension where all this info is stored. We have, still, not worked with this complementary files. This work is based on the paper referenced in butracker #194 which has some errors (e.g. beginning of log and beginning of dive are changed) and a lot of bytes of unknown meaning. Example.log shows, at least, one more byte than those referred in the paper for the O2 Aladin computer, this could be a byte referred to the use of SCR but the lack of an OC dive with O2 computer makes impossible for us to compare. The only way we have figured out to distinguish a priori between SCR and non SCR dives with O2 computers is that the dives are tagged with a "rebreather" tag. Obviously this is not a very trusty way of doing things. In SCR dives, the O2% in mix means, probably, the maximum O2% in the circuit, not the O2% of the EAN mix in the tanks, which would be unknown in this case. The list of DCs related in bug #194 paper seems incomplete, we have added one or two from WLog and discarded those which are known to exist but whose model is unknown, grouping them under the imaginative name of "unknown". The list can easily be increased in the future if we ever know the models identifiers. BTW, in Example.log, 0x00 identifier is used for some DC dives and from my own divelogs is inferred that 0x00 is used for manually entered dives, this could easily be an error in Example.log coming from a preproduction DC model. Example.log which is shipped in datatrak package is included in dives directory for testing pourposes. [Dirk Hohndel: some small cleanups, merged with latest master, support divesites, remove the pointless memset() before free() calls add to cmake build] Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-27Add hashes to imagesGravatar Robert C. Helling
Upon successfull reading an image file, this computes a SHA1 hash of the image and saves it with the picture tag in the log file. When a file is not successfully loaded (for example because the log was created on a different computer) we look up the hash in a dictionary that maps hashes to local file names. That dictionary (actually two for both directions), is loaded on startup and saved upon destruction of the main window. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-13Allow editing of dive sitesGravatar Dirk Hohndel
And hook things up when double clicking the globe. The user experience isn't consistent with what we do on the main tab (i.e., no coloring of fields that are changed), but it seems to work. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-12Switch from locations to dive sites in dive.cGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-10These pO2 samples exist in both the Predator and the PetrelGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-10Be a bit more careful when deleting pO2 valuesGravatar Robert C. Helling
This patch adds tests if the computer is actually a Predator and if the value is close to what we would have computed anyway. [Dirk Hohndel: minor change to use same_string() ] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-10Only update tags in the selected dives if they were changedGravatar Dirk Hohndel
If current_dive and displayed_dive still have the same tags then we shouldn't touch the tags of other selected dives. Fixes #826 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-07Deal with setpoints in samples when switching a dive from CCR to OCGravatar Dirk Hohndel
For some dive computers (at least the Shearwater Predator, I haven't checked if there are others), libdivecomputer used to return setpoint values in each sample even if the dive computer was in OC mode. Those setpoint values are redundant and confuse our algorithm that tries to detect if a dive is OC or CCR. So when manually switching from CCR to OC we make sure that there are no setpoint values in the samples. This is a destructive change - if the user switches to OC by mistake and accepts that change, even when switching back to CCR the setpoint changes during the dive are lost. I rewrote the code dealing with the events as it was rather confused. Looping over the events that way didn't make any sense since get_next_event() is guaranteed to give you the first (if any) event of the requested name. See #826 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-02Do not reorder pictures when savingGravatar Miika Turkia
When one has 2 pictures with the same timestamp, these pictures are reordered on saving (requires something changed on the specific dive for the save to actually trigger). This patch keeps the picture order intact in the XML log. Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-30Merge pictures when downloading additional DCGravatar Miika Turkia
Fixes #822 Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-28Don't let the oxygen partial pressure drop below 0.Gravatar Robert C. Helling
No oxygen at all is not quite enough for the average diver but this prevents inifintie loops/extremely long deco when subsurface is used in pscr mode with unrealistic values for pscr preferences. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-20Don't divide 0/0 when using a PSCR with 100% oxygenGravatar Robert C. Helling
Reported-by: Anton "glance" Lundin <glance@acc.umu.se> Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-20Use SAC from preferences for PSCR oxygen dropGravatar Robert C. Helling
The ratio between SAC and oxygen metabolism rate can be assumed constant but not the metabolism rate. So we better base our calculation on the ratio that uses the SAC from the preferences as that pairs well with the O2 consumption from the preferences. Hence we ran remove the sac parameter from fill_pressures(). Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-10Refactor dctype -> divemodeGravatar Robert C. Helling
... and repair a failed rebase (sorry). Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-10Add setpoint events according to divetypeGravatar Robert C. Helling
When changing to a CCR dive, add a setpoint change to the default setpoint at the beginning of the dive. Otherwise add an explicit setpoint change to 0 . Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-10Maintab combobox to set dive typeGravatar Robert C. Helling
still needs some work Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-10Prepare for PSCR calculationsGravatar Robert C. Helling
Calculations for passive semi-closed rebreathers are pretty much like OC except the pO2 is lower bey a certain (SAC dependent) factor. This patch introduces the corresponding calculations in case dctype == PSCR which is so far never set and there is currently no UI for these calculations. As pO2 is SAC dependent it takes a certain attempt at getting it and drops to defaults from the prefs otherwise. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-03Extend SAMPLE_EVENT_GASCHANGE2 to have cylinder index in 'flags' fieldGravatar Linus Torvalds
A value of zero (which is the normal legacy one) remains "unknown", but the divecomputer backend can now give both gasmix and cylinder number this way. Currently only the EON Steel backend does that, but it should be easy enough to extend others too. Also, fix the user-visible cylinder numbering in the cylinder change tooltip to use a human-friendlier one-based numbering (ie first cylinder is "cyl 1", not "cyl 0") Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-02Partial revert of commit 6cf3787a0ed1Gravatar Dirk Hohndel
Commit 6cf3787a0ed1 ("Remove code that zeroes out duplicate oxygen sensor and temperature values") incorrectly removes the code that zeroes out the temperatures. Reported-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-12-30Prevent holes in cylinder list when copying used onesGravatar Robert C. Helling
This ensures that the list of configured cylinders is consecutive. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-12-21Revert "Free tag lists propperly"Gravatar Dirk Hohndel
No, this causes double free problems. And they show up in the weirdest ways, e.g. when just closing your data file. Or when making changes and re-saving a modified dive. Fixes #794 This reverts commit 0bdd8f41e0b217c6f0a3723dd756e96c93b3f5c6. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-12-18Free any previous userid before setting newGravatar Anton Lundin
When we load multiple files, we call set_userid multiple times. Then we need to free the old user id before we set a new. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-12-18Free tag lists propperlyGravatar Anton Lundin
The previous taglist_free didn't free the divetag, it only freed the tag. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-12-12Prevent 0/0 in partial pressure calculationGravatar Robert C. Helling
If for some reason the diluent is pure oxygen, there is a zero divided by zero error in the partial pressure calculation. This patch prevents it. Fixes #774 Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-12-12Don't rely on malloc to return NULL for zero sizeGravatar Anton Lundin
We rely on samples being NULL if a dc have no samples. Its completely legal for malloc to return a valid pointer to nowhere for zero sized malloc, which you can't follow and read what its pointing at. Its only viable to call free() on. In other code, if samples is a valid pointer, we dereference it and look at the first sample. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-12-12Initialize alloc_samples in copy_samplesGravatar Anton Lundin
We rely on alloc_samples in prepare_sample. If alloc_samples weren't initialized prepare_sample would wreak havoc on the samples list. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-22Check error code of get_cylider_idx_by_use()Gravatar Robert C. Helling
If not cylinder with type DILUENT or OXYGEN is defined, this function returns -1 which should not be used as an index to an array. This patch adds code to check for this return value and exit gracefully. On line I marked with a comment. Someone more knowledgeable of that part of code than me should double check that return is here what we want. [Dirk Hohndel: fixed small oversight...] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-21Update fixup_pressure to calculate CCR oxygen cylinderpressuresGravatar Willem Ferguson
Fixup_pressure() needs to calculate the cylinder pressures at the start and at the end of the dive, also for CCR oxygen cylinders. Since, in the case of CCR, the default cylinder is the diluent, this is not automatically done for oxygen. This code provides for fixup_pressure() to be able to do the calculations for oxygen as well. Another change to fixup_dive() invokes fixup_pressure() to calculate the values for the oxygen cylinder. Signed-off-by: willem ferguson <willemferguson@zoology.up.ac.za> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-20Prevent garbage from being saved in the userid fieldGravatar Dirk Hohndel
It seems that in some scenarios we end up with a string that isn't NUL terminated and that results in garbage being stored as userid. This patch is a little brute force but it fixes the problem even if a previous version os Subsurface ended up adding other text to the end of the userid. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-17Allow translation of the cylinder use strings for the UIGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-17Add helper function to translate cylinder use text to matching idxGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-17For CCR dives, the diluent cylinder is the current cylinderGravatar Robert C. Helling
Change the meaning that _the_ cylinder (as we treat it in OC dives) is the diluent cylinder (rather than the O2 cylinder). This eliminates special cases. Now, for CCR, we have to handle the O2 cylinder in addition (rather than the diluent in addition). Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-17Continue cleanup of string copying in equipmentGravatar Dirk Hohndel
Slowly trying to track down all spots where we copy string pointers instead of string data. And making sure that we free those pointers before overwriting them. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-17Fix per_cylinder_mean_depth calculation for CCRGravatar Dirk Hohndel
This patch is bigger than necessary because I also renamed the get_cylinder_use() function to the much more accurate get_cylinder_idx_by_use(). If we have no gas changes (except for a possible explicit first gas), (which in the CCR case also means no bailout), this code will give you correct per cylinder depth and duration for oxygen and diluent and therefore create more reasonable gas consumption data for CCR dives. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-16Load and save the dc type for CCR divesGravatar Dirk Hohndel
Oddly we already had code to load this from XML, but nothing else. This makes the load from XML work like the rest of our code and adds the save to XML plus the load and save for the git format. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-16Save CCR cylinder use in XML and gitGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>