Commit graph

309 commits

Author SHA1 Message Date
Dirk Hohndel
35dc814105 Add simple test for the dive planner
This sets up a standard dive scenario (30 minutes at 260ft/79m, EAN36 and
Oxygen as deco gases, last stop at 20ft/6m) and calls the planner to set
up a dive plan given certain standard gases.

Instead of trying to verify the complete plans it checks that we switch to
the deco gases at the right depth and the complete duration of the dive
matches our expectation.

The test intentionally fails right now for imperial as we have the wrong
switch depth for Oxygen. See how useful tests are?

On the downside, the test does NOT produce the same plan as Subsurface
when I try to create a consistent setup for both - and I have not been
able to figure out why. There must be some other parameters that I'm not
setting, but I haven't identified them, yet. It's very small differences,
for example in the metric case the stops at 21m, 9m, and 6m are each one
minute shorter in the test than it what Subsurface calculates.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-05 09:42:38 -07:00
Dirk Hohndel
e5f4697f91 Rewrite GPS fix matching code for imports from our webservice
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-24 22:38:44 -07:00
Dirk Hohndel
895d6e0000 Comparing the address of a member to 0 is pointless
Or... this code doesn't do what you think it does.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-21 22:11:49 -07:00
Dirk Hohndel
18d52ec86e Prevent possible null pointer dereference
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-21 21:40:21 -07:00
Dirk Hohndel
b63b656c1f Make sure cylinder related data is filled when dives are read
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-17 17:58:31 -07:00
Dirk Hohndel
ff4b5478b5 Store the user's unit preferences in git storage
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-06-17 09:48:10 -07:00
Dirk Hohndel
51183f4ee7 Tag list handling: add two new helpers
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-05-02 12:16:03 -07:00
Robert C. Helling
757c4aab20 Allow images to be added via the web
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-24 09:36:21 -07:00
Robert C. Helling
98ae7b1f86 Don't load images too often
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-24 09:35:51 -07:00
Robert C. Helling
a0a3c6ec15 Cleaning up variable names in image loading
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-24 09:35:35 -07:00
Dirk Hohndel
415abeea66 When deleting a cylinder, adapt gas changes
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-23 15:27:21 -07:00
Robert C. Helling
61ff7c5f8b Only do safety stop of dive has at least max depth of 10m
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-02 09:46:10 -07:00
Robert C. Helling
e5e2be92bc When loading an image with geodata create a divesite when the dive has none.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-03-16 12:42:29 -07:00
Jan Darowski
d45c2da81d Fixed dive_set_geodata_from_picture segfault.
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-16 12:19:23 -07:00
Jan Darowski
7d37a3f5a6 Refactored image timestamp checking.
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-15 15:47:23 -07:00
Salvador Cuñat
44b55bd1a2 Import Datatrak/WLog files
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-03-10 10:03:08 -07:00
Robert C. Helling
b02bf002a6 Add hashes to images
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-27 06:29:44 +01:00
Dirk Hohndel
32ad046f56 Allow editing of dive sites
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-13 14:27:35 -08:00
Dirk Hohndel
99ba2f0687 Switch from locations to dive sites in dive.c
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-12 20:56:46 -08:00
Dirk Hohndel
6374d9cc03 These pO2 samples exist in both the Predator and the Petrel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-10 15:19:57 -08:00
Robert C. Helling
8fa205a59d Be a bit more careful when deleting pO2 values
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-10 14:56:33 -08:00
Dirk Hohndel
585d6a004b Only update tags in the selected dives if they were changed
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-10 06:31:37 -08:00
Dirk Hohndel
8f9a20a908 Deal with setpoints in samples when switching a dive from CCR to OC
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-07 08:39:14 -08:00
Miika Turkia
bbc3a0e55f Do not reorder pictures when saving
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-02-02 09:17:28 -08:00
Miika Turkia
129b54093b Merge pictures when downloading additional DC
Fixes #822

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-30 16:55:20 -08:00
Robert C. Helling
52b92ee03b Don't let the oxygen partial pressure drop below 0.
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-28 07:51:32 -08:00
Robert C. Helling
bbef887b79 Don't divide 0/0 when using a PSCR with 100% oxygen
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-20 17:22:08 +12:00
Robert C. Helling
837dcde0c1 Use SAC from preferences for PSCR oxygen drop
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-20 06:16:15 +12:00
Robert C. Helling
e219bc70f8 Refactor dctype -> divemode
... 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-10 17:27:25 -08:00
Robert C. Helling
0f7f2195d5 Add setpoint events according to divetype
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-10 17:27:24 -08:00
Robert C. Helling
a478eb5711 Maintab combobox to set dive type
still needs some work

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-10 17:27:24 -08:00
Robert C. Helling
93eb386ba9 Prepare for PSCR calculations
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-10 17:27:24 -08:00
Linus Torvalds
08d2ceb66b Extend SAMPLE_EVENT_GASCHANGE2 to have cylinder index in 'flags' field
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-03 21:36:51 -08:00
Dirk Hohndel
d1af75357d Partial revert of commit 6cf3787a0e
Commit 6cf3787a0e ("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>
2015-01-02 20:39:19 -08:00
Robert C. Helling
ac067fb424 Prevent holes in cylinder list when copying used ones
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-30 15:54:52 -08:00
Dirk Hohndel
1ba4137fec Revert "Free tag lists propperly"
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 0bdd8f41e0.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-12-21 11:11:00 -08:00
Anton Lundin
8d54c9640d Free any previous userid before setting new
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-18 08:34:00 -08:00
Anton Lundin
0bdd8f41e0 Free tag lists propperly
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-18 08:34:00 -08:00
Robert C. Helling
767fd39ca0 Prevent 0/0 in partial pressure calculation
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-12 07:07:49 -08:00
Anton Lundin
bf20c251ab Don't rely on malloc to return NULL for zero size
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-12 07:04:26 -08:00
Anton Lundin
46bd71a184 Initialize alloc_samples in copy_samples
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-12-12 07:01:16 -08:00
Robert C. Helling
13934b0f02 Check error code of get_cylider_idx_by_use()
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-22 16:22:57 -08:00
Willem Ferguson
e288751353 Update fixup_pressure to calculate CCR oxygen cylinderpressures
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-21 07:33:52 -08:00
Dirk Hohndel
2f7a7f3e6a Prevent garbage from being saved in the userid field
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-20 14:30:44 -08:00
Dirk Hohndel
8856417b2f Allow translation of the cylinder use strings for the UI
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-17 14:39:30 +00:00
Dirk Hohndel
74582de06c Add helper function to translate cylinder use text to matching idx
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-17 13:51:19 +00:00
Robert C. Helling
0d7c192e6e For CCR dives, the diluent cylinder is the current cylinder
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-17 11:45:06 +00:00
Dirk Hohndel
5ed4876ad2 Continue cleanup of string copying in equipment
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-17 11:30:49 +00:00
Dirk Hohndel
3e5cb7e2aa Fix per_cylinder_mean_depth calculation for CCR
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-17 00:09:59 +00:00
Dirk Hohndel
23304f69c0 Load and save the dc type for CCR dives
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-16 23:20:39 +00:00