Commit graph

277 commits

Author SHA1 Message Date
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
Dirk Hohndel
202c5cbfeb Save CCR cylinder use in XML and git
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-16 22:13:12 +00:00
Robert C. Helling
84dc8b8962 Some gas handling improvements
Add a time linear gas interpolation strategy. Some minor changes.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-16 20:50:16 +00:00
Dirk Hohndel
8d766e13e2 Make sure we always have copies of equipment descriptions
Having pointers copied around that might get freed elsewhere could be a
problem.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-14 13:45:54 -08:00
Dirk Hohndel
8086b39e11 Adjust the counter function for filter with "none of the above"
So this should count dives with neither buddy nor divemaster, without a
location, with no tags, etc.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-13 12:45:32 -08:00
Dirk Hohndel
dae76cdc2d Add a function to count dives with a specific suit
Checking against the location field probably wasn't the best way to do
this...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-13 12:35:12 -08:00
Dirk Hohndel
61dc19d2e0 Show the number of dives with given person / location in the filter panel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-12 16:02:37 -08:00
Dirk Hohndel
f9b9535c69 Add tag helper functions to allow us to count dives with a given tag
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-11 02:20:13 -08:00
Linus Torvalds
0a27978014 Use the new DC_FIELD_STRING callback if it exists
This recognizes recognize some strigns (serial number and firmware
version), and the ones that it doesn't recognize it adds as extra data
using Dirk's new interface.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-07 20:55:18 -08:00
Dirk Hohndel
9aefaa1ec8 Add helper function to add extra_data to dive computer
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-07 12:59:08 -08:00
Robert C. Helling
06ddfc0122 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.

As there is no UI at this point and I also don't have any dives, this has
not received much testing, yet, but it compiles. At least.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-04 07:13:04 -08:00
willem ferguson
40bdd607c0 Calculate nitrogen and helium gas pressures for CCR after import from CSV
Currently the gas pressures stored in structures of pressure are
calculated using the gasmix composition of the currently selected
cylinder. But with CCR dives the default cylinder is the oxygen
cylinder (here, index 0). However, the gas pressures need to
be calculated using gasmix data from cylinder 1 (the diluent
cylinder). This patch allows setting the appropriate cylinder
for calculating the values in the structures of pressure. It
also allows for correctly calculating gas pressures for any
open circuit cylinders (e.g. bailout) that a CCR diver may
use. This is performed as follows:

1) In dive.h create an enum variable {oxygen, diluent, bailout}

2) Within the definition of cylinder_t, add a member: cylinder_use_type
   This stores an enum variable, one of the above.

3) In file.c where the Poseidon CSV data are read in, assign
   the appropriate enum values to each of the cylinders.

4) Within the definition of structure dive, add two members:
   int oxygen_cylinder_index
   int diluent_cylinder_index
   This will keep the indices of the two main CCR cylinders.

5) In dive.c create a function get_cylinder_use(). This scans the
   cylinders for that dive, looking for a cylinder that has a
   particular cylinder_use_type and returns that cylinder index.

6) In dive.c create a function fixup_cylinder_use() that stores the
   indices of the oxygen and diluent cylinders in the variables
   dive->oxygen_cylinder_index and dive->diluent_cylinder_index,
   making use of the function in 4) above.

7) In profile.c, modify function calculate_gas_information_new()
   to use the above functions for CCR dives to find the oxygen and
   diluent cylinders and to calculate partail gas pressures based
   on the diluent cylinder gas mix.

This results in the correct calculation of gas partial pressures
in the case of CCR dives, displaying the correct partial pressure
graphs in the dive profile widget.

Signed-off-by: willem ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-03 14:13:55 -08:00
Dirk Hohndel
9eb55a0fc6 Prevent segfault for dive with gas change but no samples
Not quite sure where such a dive would come from, but anyway, just don't
dereference the pointer unless it's non-NULL.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-02 10:38:09 -08:00
willem ferguson
6cf3787a0e Remove code that zeroes out duplicate oxygen sensor and temperature values
Remove the code that changes all duplicate oxygen sensor, setpoint and
temperature values from a dive log to zero. One of the motivations is
that a zero setpoint value indicates an Open Circuit dive segment, not
Closed Circuit Rebreather. The code in dive.c is removed and the comments
for the corresponding restoration code that restores the last known values
into sensor or temperature with zero values is [fill_o2_values()
in profile.c] is changed to apply to the present situation.

Signed-off-by: willem ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-01 22:13:47 -07:00
willem ferguson
9e2ce3d99a Remove code causing problems with CCR dive log rendering.
Currently, if there is a po2 given in the dive log, the dive is assumed
to be CCR. When a CCR dive has a fo2 of 100%, then the po2 is set as
the same as ambient pressure. This destroys the CCR po2 graph in the dive
profile that derives from oxygen with a fo2 of 100% in one of the
cylinders but which, after adding the dilent gas, has a po2 far below
ambient pressure. The calculation for 100% oxygen only applies to deco
using 100% o2 and then the dive computer calculates the appropriate po2.
This patch removes the setting of po2 to ambient when fo2 is 100%,
1) to enable accurate graphing of po2 values for CCR dives using 100% o2
   in the first cylinder.
2) To use the po2 value reported by the DC in the first place.

Signed-off-by: willem ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-01 22:05:13 -07:00
Dirk Hohndel
e32ba4d6d8 Improve tank handling for Cobalt
This isn't Cobalt specific, this is specific to dive computers that
indicate the first tank that's in use with a gaschange event that
coincides with the first sample.

We need to make sure that we suppress showing that gas change event
(regardless which cylinder it goes to) and instead set the correct
cylinder index from the very start of the dive.

This works with the test data I have and doesn't seem to break thing with
any of the files that I tried... but I'm worried that this is not the
right way to do things.

Fixes #742

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-28 14:04:19 -07:00
Miika Turkia
8b6d49092b Do not zero setpoint value when duplicate
We cannot zero setpoint value upon import if the current and previous
values are zero. This is because on setpoint context a value of 0 means
open circuit.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-27 09:32:22 -07:00
Robert C. Helling
5f44fdd9cf Make planner work again for CCR dives
The latest CCR patches had rendered the planner not usable for CCR dives.
This patch corrects this (and reenables the CCR set point column for
segments). The problem was that a new member setpoint of struct divepoint
had been introduced, but there was already po2 which had the same meaning.
This patch merges the two and renames them setpoint to prevent future
confusion.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-19 07:07:07 -07:00
Robert C. Helling
34bb461c3d Reshuffle CCR voting logic and minor clean ups
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-14 20:33:46 +02:00
willem ferguson
c8eb2dccc5 CCR patch: Reorganise the oxygen partial pressure calculations
This patch responds to the side effects that the CCR code has had with
respect to ceilings in OC dives and dive plans. Dive ceilings are now
calculated correctly again.

The following were performed:
1) remove the oxygen sensor and setpoint fields from the gas_pressures
   structure.
2) Re-insert setpoint and oxygen sensor fields in the plot_data structure.
3) Remove the algorithm that reads the o2 sensor data and calculates the
   pressures.po2 value from function fill_pressures() in dive.c and save
   it as a separate function calc_ccr_po2() in profile.c.
4) Activate calc_ccr_po2 from function fill_pressures() in profile.c.
5) Move the relative position of the call to fill_pressures() within the
   function create_polt_info_new() in profile.c.

Signed-off-by: willem ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-13 23:15:41 +02:00
willem ferguson
bc9df4652f CCR patch: Calculate the correct partial gas pressures for CCR dives
This patch adds code to the function fillpressures() in dive.c to
allow calculating o2 pressures, based on the data from the po2
sensors in the system. The following changes were made:
1) add code to perform po2 calculations for CCR with 1, 2 or 3
   oxygen sesnors.
2) Add four fields to the gas_pressures structure in dive.h. This
   allows communication of data between the function that calls
   get_pressures() and the return of partail pressure values to the
   calling function.
3) Delete the fields for setpoint and gas partial pressures from
   the structure plot_info. All partial pressures (from instruments
   as well as calculated) now reside in the pressures structure
   that forms part of plot_info.
4) Perform changes in several parts of profile.c to make use of the
   pressures structure in plot_info.

[Dirk Hohndel: yet again massive whitespace cleanup]

Signed-off-by: willem ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-12 15:23:49 -04:00
Dirk Hohndel
613402f6c9 Correctly copy all information in an event
Instead of trying to use add_event() to reinsert events we simply copy the
memory and adjust the pointers.

Using add_event() lost the gas mix and gas index information on gaschange
events - and this prevent switches between cylinders with the same gasmix
to be rendered correctly.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-12 14:49:18 -04:00
willem ferguson
49c9ad199f CCR patch: Oxygen partial pressures
This patch does three things:
1) A new function fill_o2_values() is added to profile.c. This
   fills all oxygen sesnsor and setpoint values that have been
   zeroed before in order to save space in the dive log. This
   recreates the full set of sensor values obtained from the
   original CCR xml log file.
2) Function fill_o2_values() is activated in function create_
   plot_info_new() in profile.c
3) The calling parameters to function fill_pressures() in dive.c
   are changed. The last parameter is now a pointer to a structure
   of divecomputer. This will be needed in the last patch of the
   present series of three patches.

[Dirk Hohndel: minor whitespace cleanup]

Signed-off-by: willem ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-12 12:40:34 -04:00
Linus Torvalds
df4e26c875 Start sanitizing gaschange event information
Decode the gasmix data into a sane format when creating the event, and
add the (currently unused) ability to specify a gas change to a
particular cylinder rather than (or in addition to) the gasmix.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-12 07:45:37 -04:00
Dirk Hohndel
9882bf5ff8 Just use strdup
In commit 272f85bb24 ("Fix silly crash") I indeed fixed the crash, but I
also broke the code. Now a broken userid might end upsaved in the data
file. Oops.

This should be correct now.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-11 17:35:31 -04:00
Dirk Hohndel
43765d2897 Keeping up the fight for whitespace consistency
Sadly, some of the code being fixed is my own...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-11 07:26:26 -04:00
willem ferguson
46bb02e8fc CCR patch: Import and store oxygen sensor data
This patch allows the importing of oxygen sensor and setpoint data from
Poseidon CCR dive logs.
1) Change parse-xml.c to read up to three oxygen sensor values from xml.
   and to store the information in sample structures
2) Change parse-xml.c to read o2 setpoint values fro xml and to store
   it in sample structures
3) Change dive.c to delete all sensor and setpoint values where
   subsequent samples have sensor/setpoint values that are the same.
4) Change profile.c to store the sensor/setpoint values from the samples
   into plotinfo.
5) Change the sample Poseidon xml log in the dives directory to ensure
   the correct order and hierarchy of the dive and divecomputer nodes.

[Dirk Hohndel: minor cleanup, removed debug code, whitespace]

Signed-off-by: willem ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-11 07:12:04 -04:00
willem ferguson
c5490af192 CCR dives: Clear duplicate diluent gas pressure readings
This patch concludes the calculation of gas pressure readings for CCR
dives. Duplicate diluent gas pressures are removed from the dive structure
and set to zero, as is done for the other gases.

Signed-off-by: willem ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-10 02:34:02 -04:00
Dirk Hohndel
272f85bb24 Fix silly crash
Who the heck uses strcpy?

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-07 20:43:45 -04:00
Robert C. Helling
7cdf55ffcc Set O2 partial pressure for CCR dives correctly
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-09-19 21:39:11 -07:00
Robert C. Helling
d6abb739d9 Helper function for partial pressure calculation
This patch introduces a new structure holding partial pressures (doubles in bar) for
all three gases and a helper function to compute them from gasmix (which holds fractions)
and ambient pressure. Currentlty this works for OC and CCR, to be extended later to PSCR.

Currently the dive_comp_type argument is unused.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-09-18 06:20:25 -07:00
Dirk Hohndel
6ed189f32c Planner: bring sanity to the SAC rate handling
The old implementation was... let's call it creative.
This tries to actually get things right instead of using magic.
Don't pretend that double values are ints.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-08-19 11:36:54 -05:00
Dirk Hohndel
4a7432e3d5 Don't always clear the dive before selectively copying
This will be needed when pasting the data back into a (set of) dive(s).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-08-16 18:34:27 -06:00