aboutsummaryrefslogtreecommitdiffstats
path: root/dive.c
AgeCommit message (Collapse)Author
2013-02-09Finish removing accesses to first divecomputer instead of diveGravatar Dirk Hohndel
This adds watertemp and airtemp to the dive, populates them in fixup and uses them elsewhere in the code. WARNING: as a sideeffect we now edit the airtemp in the dive, but we never display this in the DIve Info notebook (as that always displays the data from the specific selected divecomputer). This is likely to cause confusion. It's consistent behavior, but... odd. This brings back the desire to have a view of "best data available" for a dive, in addition to the "per divecomputer" view. This would also allow us to consolidate the different pressure graphs we may be getting from different divecomputers (consider the case where you dive with multiple air integrated computers that are connected to different tanks - now we could have one profile with all the correct tank pressure plots overlayed - and the best available (or edited) data in the corresponding Dive Info notebook. This commit also fixes a few remaining accesses to the first divecomputer that fell through the cracks earlier and does a couple of other related cleanups. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09Move duration to dive structure and replace accessor functionGravatar Dirk Hohndel
When starting on this quest to stop using the first divecomputer instead of data for the whole dive in commit eb73b5a528c8 ("Duration of a dive is the maximum duration from all divecomputers") I introduced an accessor function that calculates the dive duration on the fly as the maximum of the durations in the divecomputers. Since then Linus and I have added quite a few of the variables back to the dive data structure and it makes perfect sense to do the same thing for the duration as well and simply do the calculation once during fixup. This commit also replaces accesses to the first divecomputer in likely_same_dive to use the maxdepth and meandepth of the dive (those two slipped through the cracks in the previous commits, it seems). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09Add a meandepth to the dive structureGravatar Dirk Hohndel
This is currently only used in one place (in statistics.c), but it certainly is consistent with the other recent changes to avoid using only the first divecomputer when trying to make statements about a dive. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09Initialize variables in helper functionsGravatar Dirk Hohndel
In commit 904aa0be0d0e ("Do more dive fixup for each dive computer") two new helper functions were introduced that sadly both incremented variables without initializing them, first. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08Add maxdepth back to the dive structureGravatar Dirk Hohndel
Populate during dive fixup as the maximum depth shown by all the divecomputers. Use this value (instead of the one in the first divecomputer) in printing, statistics, etc. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08Improve calculation of maxtemp and mintemp of diveGravatar Dirk Hohndel
The existing code only populated the maxtemp based on the samples of a dive and then in statistics.c checked if there was no such temperature and replaced it with the water temperature of the first divecomputer. It makes much more sense to add the water temperature information in every divecomputer to the min / max calculation during the dive fixup phase. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08Walk over each divecomputer entry in fixup_dives()Gravatar Linus Torvalds
The fixup_dives() code used to only look at the first divecomputer, which meant that minimun temperatures etc for the dive would only ever come from the primary divecomputer. This splits up the code that walks over the divecomputer into a function of its own, and iterates over all computers in fixup_dive() calling into it. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08Do more dive fixup for each dive computerGravatar Linus Torvalds
In commit b6c9301e5847 ("Move more dive computer filled data to the divecomputer structure") we moved the fields that get filled in by the dive computers to be per-divecomputer data structures. This patch re-creates some of those fields back in the "struct dive", but now the fields are initialized to be a reasonable average from the dive computer data. We already did some of this for the temperature min/max fields for the statistics, so this just continues that trend. The goal is to make it easy to look at "dive values" without having to iterate over dive computers every time you do. Just do it once in "fixup_dive()" instead. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08Simplify/clarify the get_surface_pressure_in_mbar() functionGravatar Linus Torvalds
Instead of maintaining a rolling average and re-calculating it at each stage, just calculate the surface_pressure average the natural way: as the sum divided by the number of entries. This results in a single rounding, rather than doing rounding multiple times and possibly rounding wrong as a result. Not that we care all that deeply about the LSB of the mbar value, but the code is simpler and more obvious this way too. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-09Clean up the handling of surface pressureGravatar Dirk Hohndel
There are two ways to look at surface pressure. One is to say "what was the surface pressure during that dive?" - in that case we now return an average over the pressure reported by the different divecomputers (or the standard 1013mbar if none reported any). Or you want to do specific calculations for a specific divecomputer - in which case we access only the pressure reported by THAT divecomputer, if present (and fall back to the previous case, otherwise). We still have lots of places in Subsurface that only act on the first divecomputer. As a side effect of this change we now make this more obvious as we in those cases pass a pointer to the first divecomputer explicitly to the calculations. Either way, this commit should prevent us from ever mistakenly basing our calculations on a surface pressure of 0 (which is the initial bug in deco.c that triggered all this). Similar changes need to be made for other elements that we currently only use from the first divecomputer, i.e., salinity. Reported-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08Fix duration calculationGravatar Dirk Hohndel
Some days I'm just a f*cking moron. That code was so stupid that I'm lacking words. I replaced using the first divecomputer with using the last divecomputer. When what I wanted was to use the maximum duration. This looks better. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-08Duration of a dive is the maximum duration from all divecomputersGravatar Dirk Hohndel
So far we always used the duration of the first divecomputer. The same fix needs to be done for some of the other calculations that always use the first divecomputer. This commit also removes some obsolete code from the webservice merging. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-04Fix dive computer interleaving so it works againGravatar Linus Torvalds
Merging two different dives by interleaving dive computer data got broken by the multi-dive-computer code in commit b6c9301e5847 ("Move more dive computer filled data to the divecomputer structure") which added a lot more entries to the dive computer data structure, and then copied the resulting structure incorrectly. Make sure we don't copy the events and samples allocations when we copy all the other fields of the divecomputer. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-02-04Get rid of dive->{start,end}Gravatar Linus Torvalds
We had this special logic to not show the end of a dive when a dive computer shows a series of very shallow samples (basically snorkeling back to shore after the dive ended). However, that logic ended up being global per dive, which is very annoying when you have two or more dive computers, and it decides to cut off the second one because the first one surfaces. So get rid of this per-dive state, and just use the plot-info 'maxtime' field for this (we never used the 'start' case anyway). That way we will properly cut off boring surface entries only when they are past the end of the interesting entries of *all* dive computers, and we won't be cutting things short. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-31Better algorithm to merge gps locations & locations names from webserviceGravatar Dirk Hohndel
This no longer abuses the dive merging code (which would leave stray "dives" behind if a gps fix couldn't be merged with any of the dives) and instead parses the gps fixes into a second table and then walks that table and tries to find matching dives. The code tries to be reasonably smart about this. If we have auto-generated GPS fixes at regular intervals, we look for a fix that is during a dive (that's likely when the boat where the phone is staying dry is more or less above the diver having fun). And if we have named entries (so the user typed in a location name) we try to match them in order to the dives that happened "that day" (where "that day" is about 6h before and after the timestamp of the gps fix). This commit also renames dive_has_location() to dive_has_gps_location() as the difference between if(!dive->location) and if(dives_has_location) is a bit too subtle... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-30Massive cleanupGravatar Dirk Hohndel
Mostly coding style and whitespace changes plus making lots of functions static that have no need to be extern. This also helped find a bit of code that is actually no longer used. This should have absolutely no functional impact - all changes should be purely cosmetic. But it removes a bunch of lines of code and makes the rest easier to read. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24Use actual min and max temperatures in statistics.Gravatar Henrik Brautaset Aronsen
The statistics page only used each dive's "watertemp" attribute, regardless of actual higher/lower temperatures in the samples. By finding the actual max/min temperatures, the statistics page utilize more "real" data, and look better even on single dives. Signed-off-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-24Merge branch 'webservice-import'Gravatar Dirk Hohndel
Update maxdepth / duration that have moved into the divecomputer structure. 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-23Import and merge GPS data from the webserviceGravatar Dirk Hohndel
Dive locations marked (and named) via the companion app are downloaded from the webservice, parsed and merged with the existing dives. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-22Improve on the "prefer downloaded" dive computer modelGravatar Linus Torvalds
It used to be that when you checked the "Prefer downloaded" checkmark, we'd throw away *any* old dive computer data. That was good, because it allowed us to start from a clean slate when you had some old subsurface data with questionable dive computer data. However, it was a bit extreme, and it's really not what you want if you already have (good) dive computer data from other dive computers. So this modifies the logic a bit. Instead of throwing away all old dive computer data, the "Prefer downloaded" checkmark now means: - the newly downloaded data becomes the "primary" dive computer data (ie the first in the list) - if there was old dive computer data that *could* have been from this new dive computer (ie it didn't have model information, or it had a matching model but no device ID data), we throw that away - but any existing dive computer data from other dive computers is left. This seems to be much closer to what we really would want for a new "preferred" download. 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-10Split up preference data structure definition into 'pref.h'Gravatar Linus Torvalds
.. and rename the badly named 'output_units/input_units' variables. We used to have this confusing thing where we had two different units (input vs output) that *look* like they are mirror images, but in fact "output_units" was the user units, and "input_units" are the XML parsing units. So this renames them to be clearer. "output_units" is now just "units" (it's the units a user would ever see), and "input_units" is now "xml_parsing_units" and set by the XML file parsers to reflect the units of the parsed file. 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-30Allow overlapping (and disjoint) dive tripsGravatar Linus Torvalds
We used to have the rule that a dive trip has to have all dives in it in sequential order, even though our XML file really is much more flexible, and allows arbitrary nesting of dives within a dive trip. Put another way, the old model had fairly inflexible rules: - the dive array is sorted by time - a dive trip is always a contiguous slice of this sorted array which makes perfect sense when you think of the dive and trip list as a physical activity by one person, but leads to various very subtle issues in the general case when there are no guarantees that the user then uses subsurface that way. In particular, if you load the XML files of two divers that have overlapping dive trips, the end result is incredibly messy, and does not conform to the above model at all. There's two ways to enforce such conformance: - disallow that kind of behavior entirely. This is actually hard. Our XML files aren't date-based, they are based on XML nesting rules, and even a single XML file can have nesting that violates the date ordering. With multiple XML files, it's trivial to do in practice, and while we could just fail at loading, the failure would have to be a hard failure that leaves the user no way to use the data at all. - try to "fix it up" by sorting, splitting, and combining dive trips automatically. Dirk had a patch to do this, but it really does destroy the actual dive data: if you load both mine and Dirk's dive trips, you ended up with a result that followed the above two technical rules, but that didn't actually make any *sense*. So this patch doesn't try to enforce the rules, and instead just changes them to be more generic: - the dive array is still sorted by dive time - a dive trip is just an arbitrary collection of dives. The relaxed rules means that mixing dives and dive trips for two people is trivial, and we can easily handle any XML file. The dive trip is defined by the XML nesting level, and is totally independent of any date-based sorting. It does require a few things: - when we save our dive data, we have to do it hierarchically by dive trip, not just by walking the dive array linearly. - similarly, when we create the dive tree model, we can't just blindly walk the array of dives one by one, we have to look up the correct trip (parent) - when we try to merge two dives that are adjacent (by date sorting), we can't do it if they are in different trips. but apart from that, nothing else really changes. NOTE! Despite the new relaxed model, creating totally disjoing dive trips is not all that easy (nor is there any *reason* for it to be easty). Our GUI interfaces still are "add dive to trip above" etc, and the automatic adding of dives to dive trips is obviously still based on date. So this does not really change the expected normal usage, the relaxed data structure rules just mean that we don't need to worry about the odd cases as much, because we can just let them be. 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-28Added some extra space for the "or" word when merging two stringsGravatar Lubomir I. Ivanov
dive.c:merge_text(): When "or" is translated into other languages it may be longer than 2 letters, therefore there is a need for a slightly larger buffer to be reserved. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-27Clear redundant "description" when merging two cylinder typesGravatar Lubomir I. Ivanov
dive.c: merge_cyclinder_type() can cause a small memory leak if two cylinder types are about to be merged, but the redundant one has a "description" string allocated. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-27When a dive computer is deleted also clear its modelGravatar Lubomir I. Ivanov
dive.c: A dive computer may have its model allocated in memory. Let's clear that as well when calling free_dc(). Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-27Small changes in the memory management when dive-mergingGravatar Lubomir I. Ivanov
This patch makes a couple of modifications: 1) divelist.c:delete_single_dive() now tries to free all memory associated with a dive, such as the string values for divemaster, location, notes & etc. 2) dive.c:merge_text(), now always makes a copy in memory for the returned string - either combined or one of the two which are passed to the function. The reason for the above two changes is that when (say) importing the same data over and over, technically a merge will occur for the contained dives, but mapped pointers can go out of scope. main.c:report_dives() calls try_to_merge() and if succeeds the two dives that were merged are deleted from the table. when we delete a dive, we now make sure all string data is cleared with it, but also in the actual merge itself, which precedes, copies of the merged texts are made (with merge_text()), so that the new, resulted dive has his own text allocations. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-16Properly remove redundant dive computer informationGravatar Linus Torvalds
We had logic to remove duplicate dive computer information after merging dives, but it didn't actually work. Why? Because we had used the 'res' dive computer pointer to traverse the list of dive computers, so it no longer actually pointed to the first dive computer in the result list any more, and so the "remove redundant" code only removed redundant dive computers from a limited and incomplete list. Oops. Also, before checking the whole event and sample list, check if it's the exact same dive computer using our new "match_one_dc()" helper function, and don't even bother checking for sample details if it is. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-16Use dive computer model/ID when trying to merge divesGravatar Linus Torvalds
If we havd divecomputer model and dive ID information available, use that to match existing dives when trying to merge them. Otherwise fall back to the fuzzy time-based merging logic. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-11Correctly merge cns, ndl and deco informationGravatar Dirk Hohndel
I keep forgetting to do that. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-11Merge branch 'cns' into cns-mergeGravatar Dirk Hohndel
I foolishly changed visible_columns in both the (ill-named) cns branch and master... Signed-off-by: Dirk Hohndel <dirk@hohndel.org> Conflicts: divelist.c gtk-gui.c profile.c
2012-12-10Display maximum CNS in the divelistGravatar Dirk Hohndel
We either pick the CNS reported by the dive computer at the end of the dive, or the maximum of that and the CNS values in the samples, if any. As usual, this column in the dive list defaults to off and it is controlled by a setting in the tec page of the preferences. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-10Move global variables covered by Preferences into one structureGravatar Dirk Hohndel
Now we can simply remember the state of all the preferences at the beginning of preferences_dialog() and restore them if the user presses 'Cancel'. Fixes #21 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07Add CNS and pO2 tracking in the samplesGravatar Dirk Hohndel
This adds the new members to the sample structure and fills them from supported dive computers (Uemis SDA and OSTC / Shearwater Predator, assuming you have libdivecomputer 0.3). Save relvant values of this to the XML file and load it back. Handle the new fields when merging dives. At this stage we don't DO anything with this, all we do is extract them from the dive computer, save them to the XML file and load them back. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07Tune the dive joining surface event insert codeGravatar Linus Torvalds
From 178a3f0d6d5112f76943fec5f8c1c1f3b173a7f4 Mon Sep 17 00:00:00 2001 From: Linus Torvalds <torvalds@linux-foundation.org> Date: Fri, 7 Dec 2012 09:34:18 -0800 Subject: [PATCH 2/2] Tune the dive joining surface event insert code So this makes us do surface events only if the samples are more than one minute apart, and are shallow enough (randomly selected at 5m). We can add more heuristics. Maybe we should compare the 1-minute sample time limit of the previous sample to the time to the sample before that: if some computer (or manually entered dive) has a long time between *all* samples, we'd make the cut-off time longer. Baby steps. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-07When merging downloaded dives, strive to keep old dive in 'a'Gravatar Linus Torvalds
This doesn't really change the logic of the merging, but it does mean that the end result tends to be less unexpected: when downloading dives that end up being merged with pre-existing dives (because you have multiple dive computers, for example), the newly downloaded dive data will tend to be appended to the old dive data, rather than showing up first. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-06Fix SIGSEGV when joining dives without dive computer informationGravatar Linus Torvalds
Handle the case where we have no divecomputer information. Reported-by: Sergey Starosek <sergey.starosek@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-05Turn latitude and longitude into integer micro-degree valuesGravatar Linus Torvalds
This actually makes us internally use 'micro-degrees' for latitude and longitude, and we never turn them into floating point either at parse time or save time. That said, the Uemis downloader internally does still use atof() when converting things, which is likely a bug (locale issues and all that), but I'll ask Dirk to check it out. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-04Improve automatic dive merging logicGravatar Linus Torvalds
This tunes the heuristics for when to merge two dives together into a single dive. We used to just look at the date, and say "if they're within one minute of each other, try to merge". This looks at the actual dive data, and tries to see just how much sense it makes to merge the dive. It also checks if the dives to be merged use different dive computers, and if so relaxes the one minute to five, since most people aren't quite as OCD as I am, and don't tend to set their dive computers quite that exactly to the same time and date. I'm sure people can come up with other heuristics, but this should make that easier too. NOTE! If you have things like wrong timezones etc, and the divecomputer dates are thus off by hours rather than by a couple of minutes, this will still not merge them. For that kind of situation, we'd need some kind of manual merge option. Note that that is *not* the same as the current "merge two adjacent dives" together, which joins two separate dives into one *longer* dive with a surface interval in between. That kind of manual merge UI makes sense, but is independent of this partical change. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-26Fix dive trip selection for mergingGravatar Linus Torvalds
When picking the "better" trip, we stupidly looked not at the trip location, but at the _dive_ location. Which obviously didn't actually pick the "better" trip information at all, since it never actually looked at the trip itself. Oops. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-25Don't compile unused code to determine offset between samplesGravatar Dirk Hohndel
Commit bb6b6b49a6d4 "Start merging dives by keeping the dive computer data from both dives" created a compile time warning. This simply adds an #if / Yes, this might accelearate bit rod in the code, but I just dislike the warning message when compiling Subsurface. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-25Be much saner about merging dive computer dataGravatar Linus Torvalds
Now that we have dive computer device ID fields etc, we can do a much better job of merging the dive computer data. The rule is - if we actually merge two disjoint dives (ie extended surface interval causing the dive computer to think the dive ended and turning two of those dives into one), find the *matching* dive computer from the other dive to combine with. - if we are merging dives at the same time, discard old-style data with no dive computer info (ie act like a re-download) - if we have new-style dive computers with identifiers, take them all. which seems to work fairly well. There's more tweaking to be done, but I think this is getting to the point where it largely works. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-25Start merging dives by keeping the dive computer data from both divesGravatar Linus Torvalds
Also, note that we do *not* do the "find_sample_offset()" any more when we merge two dives that happen at the same time - since we just keep both sets of dive computer data around. But we keep the function to find the best offset around, because we may well want to use it later when *showing* the dive, and trying to match up the different sample data from the multiple dive computers associated with the dive. Because of that, this causes warnings about the now unused function. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-25Fix "prefer downloaded" dive sample merging caseGravatar Linus Torvalds
When we have a preferred dive computer that overrides old information when merging two dives, we just copy the dive computer data over. However, we need to clear the source of the dive computer data so that we then don't free the sample data when that old source of the newly merged dive gets free'd. This fixes a memory scribble (and likely SIGSEGV) for the "prefer downloaded" case. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-23Move events and samples into a 'struct divecomputer'Gravatar Linus Torvalds
For now we only have one fixed divecomputer associated with each dive, so this doesn't really change any current semantics. But it will make it easier for us to associate a dive with multiple dive computers. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-23Allocate dive samples separately from 'struct dive'Gravatar Linus Torvalds
We used to avoid some extra allocations by just allocating the dive samples as part of the 'struct dive' allocation itself, but that ends up complicating things, and will make it impossible to have multiple different sets of samples (for multiple dive computers). So stop doing it. Just allocate the dive samples array separately. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-11-21Fix "prefer download" behaviorGravatar Dirk Hohndel
When this was first implemented the assumption was that a downloaded dive that is to be merged with an existing dive would have the same time stamp. But as Linus pointed out even back then, this does fail if a dive has been merged with a download from a different dive computer before (think: download from computer a, then download same dive from b, then improve something in the parsing from computer a and try to redownload; the time stamp could have changed). This commit also fixes a silly omission in the merge_dives() function (which ended up ALWAYS prefering the downloaded dive) and finally implements the necessary changes to mark dives downloaded from a Uemis SDA as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>