annotate Discovery/Src/buehlmann.c @ 232:f0069f002c55 div-fixes-4-1

Bugfix: make date/time setting work over reboots Setting the time/date over the UART interface or by the menu, seems to work, but a reboot of the RTE brings back strange, seemingly random, time. The reason for this is rather simple. In the settings, a time is stored, based on some flawed logic, and that time was restored on reboot. There is no reason to store any time, when the moment of restoring it is unrelated in time. So, the fix is simple: do not set time (in the RTC) based on some time from the past. The whole idea of a RTC is that it does preserve the time for you, as long its powered. Any attempt to do things better using stored time data is futile (and nonsense). And while working on his, also kick out some useless code from the RTE. There is no reason to initialize the time on the RTC to some random time/date in the past. A zero data/time is as good and any random date. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Wed, 03 Apr 2019 21:11:56 +0200
parents ceecabfddb57
children ff0d23625cd5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
1 /* getrennte Gase f�r die verschiedenen Modi
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
2 um Gaswechsel Eintr�ge zu vereinfachen
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 das heisst:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 oc == bailout in cc mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 /* Konvention:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 float extExample_variable_can_be_used_with_extern;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 #include <string.h>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 //#include "arm_math.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 #include <math.h>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 #include <stdbool.h>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 #include "buehlmann.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 #include "decom.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 extern const float buehlmann_N2_a[];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 extern const float buehlmann_N2_b[];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 extern const float buehlmann_He_a[];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 extern const float buehlmann_He_b[];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 typedef struct
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 float *pointer_array_tissue_nitrogen_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 float *pointer_array_tissue_helium_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 char gf_value;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 float output_ceiling_ambient_bar_or_input;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 _Bool output_ceiling_tolerated_if_ceiling_used_as_input;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 } tissue_test_tolerance_struct;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 typedef struct
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 float depth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 int id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 } SStop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 #define DECO_STOPS_MAX_TTS_CALCULATON_IN_SECONDS 59940 // 999 minuten; before: 18000 // 5(h) * 60(min) * 60 sec = 18000 sec
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 #define DECO_STOPS_MAX_TTS_FOR_EVERY_SECOND_CALC_IN_SECONDS 7200
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 #define NINETY_NINE_MINUTES_IN_SECONDS 59940
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 # define PRESSURE_TEN_METER 1.0f
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 # define PRESSURE_THREE_METER 0.333334f
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 # define PRESSURE_150_CM 0.15f
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 # define PRESSURE_HALF_METER 0.05f
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 # define PRESSURE_150_CM_MBAR 150
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 # define PRESSURE_TWO_M_MBAR 200
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 # define PRESSURE_FIVE_M_MBAR 500
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 # define PRESSURE_TEN_M_MBAR 1000
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 # define PRESSURE_120_METER 12.0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 _____________________________________________________________
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 void buehlmann_backup_and_restore(_Bool backup_restore_otherwise);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 float tissue_tolerance(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 void ambient_bar_to_deco_stop_depth_bar(float ceiling);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 int ascend_with_all_gaschanges(float pressure_decrease);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 float next_stop_depth_input_is_actual_stop_id(int actual_id);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 float get_gf_at_pressure(float pressure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 void buehlmann_calc_ndl(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 _Bool dive1_check_deco(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 uint8_t buehlmann_tissue_test_tolerance(float depth_in_bar_absolute);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 _____________________________________________________________
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 SDecoinfo gDecotable;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 float gSurface_pressure_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 float gPressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 int gGas_id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 float gTTS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 float gTissue_nitrogen_bar[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 float gTissue_helium_bar[16];
130
b7689d9e888a Minor changes to improved code quality and to eliminate warnings
Ideenmodellierer
parents: 51
diff changeset
83 float gGF_value;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 float gCNS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 //float gMax_ceiling_bar = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 int gNDL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 //SLifeData *pLifeData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 SDiveSettings *pBuDiveSettings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 SDecoinfo* pDecolistBuehlmann;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 //signed char gGaschange_decreasing_depth_gas_id[BUEHLMANN_STRUCT_MAX_GASES];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 float gGF_low_depth_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 SStop gStop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 void buehlmann_init(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 //gMax_ceiling_bar = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 void buehlmann_backup_and_restore(_Bool backup_restore_otherwise)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 static float pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 static float gas_id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 static float tts;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 static float tissue_nitrogen_bar[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 static float tissue_helium_bar[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 static float gf_value;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 static int ndl;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 static float cns;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 if(backup_restore_otherwise)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 pressure = gPressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 gas_id = gGas_id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 tts = gTTS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 gf_value = gGF_value;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 ndl = gNDL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 cns = gCNS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 memcpy(tissue_nitrogen_bar, gTissue_nitrogen_bar, (4*16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 memcpy(tissue_helium_bar, gTissue_helium_bar, (4*16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 gPressure = pressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 gGas_id = gas_id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 gTTS = tts;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 gGF_value = gf_value;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 gNDL = ndl;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 gCNS = cns;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 memcpy(gTissue_nitrogen_bar, tissue_nitrogen_bar, (4*16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 memcpy(gTissue_helium_bar, tissue_helium_bar, (4*16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 /*void buehlmann__test__saturate_tissues(SBuehlmann *pInput, int seconds)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 pBuehlmann = pInput;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 pInput->dive_time_seconds += seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 // internal copying
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 gSurface_pressure_bar = pBuehlmann->pressure_surface_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 gPressure = pBuehlmann->pressure_ambient_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 gGas_id = pBuehlmann->actual_gas_id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 memcpy(gTissue_nitrogen_bar, pBuehlmann->tissue_nitrogen_bar, (4*16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 memcpy(gTissue_helium_bar, pBuehlmann->tissue_helium_bar, (4*16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 tissues_exposure_at_gPressure_seconds(seconds);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 memcpy(pBuehlmann->tissue_nitrogen_bar, gTissue_nitrogen_bar, (4*16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 memcpy(pBuehlmann->tissue_helium_bar, gTissue_helium_bar, (4*16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 }*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 float buehlmann_get_gCNS(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 return gCNS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 void buehlmann_calc_deco(SLifeData* pLifeData, SDiveSettings * pDiveSettings, SDecoinfo * pDecoInfo)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 float ceiling;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 int ascend_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 int tts_seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 float pressure_delta;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 float next_depth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 _Bool deco_reached = false;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 // tissue_test_tolerance_struct tolerance_data;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 unsigned short *stoplist;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 int i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 // decom_CreateGasChangeList(pDiveSettings, pLifeData);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 gCNS = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 pDecoInfo->output_time_to_surface_seconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 pDecoInfo->output_ndl_seconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 for(int i=0;i<DECOINFO_STRUCT_MAX_STOPS;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 pDecoInfo->output_stop_length_seconds[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 /* make input available global*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 pBuDiveSettings = pDiveSettings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 pDecolistBuehlmann = pDecoInfo;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 /* internal copying */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 gSurface_pressure_bar = pLifeData->pressure_surface_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 gPressure = pLifeData->pressure_ambient_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 gGas_id = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 memcpy(gTissue_nitrogen_bar, pLifeData->tissue_nitrogen_bar, (4*16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 memcpy(gTissue_helium_bar, pLifeData->tissue_helium_bar, (4*16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 gGF_value = ((float)pBuDiveSettings->gf_low) / 100.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 //
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 memcpy(&gDecotable, pDecolistBuehlmann, sizeof(SDecoinfo));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 stoplist = gDecotable.output_stop_length_seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 if(pLifeData->dive_time_seconds < 60)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 /* coupling */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 /* functions */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 // clean stop list
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 for(i = 0; i < DECOINFO_STRUCT_MAX_STOPS; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 stoplist[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 gTTS = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 gNDL = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 if(pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero >= (gPressure - PRESSURE_150_CM))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 deco_reached = true;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 //ascend_with_all_gaschanges(gPressure - gSurface_pressure_bar);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 gGF_value = ((float)pBuDiveSettings->gf_high) / 100.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 //iling = tissue_tolerance();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 // includes backup for gGF_value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 // NDL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 buehlmann_backup_and_restore(true); // includes backup for gGF_value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 if(!dive1_check_deco() )
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 buehlmann_backup_and_restore(false);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 // no deco
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 pDecolistBuehlmann->output_time_to_surface_seconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 for(i = 0; i < DECOINFO_STRUCT_MAX_STOPS; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 pDecolistBuehlmann->output_stop_length_seconds[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 // calc NDL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 buehlmann_calc_ndl();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 pDecolistBuehlmann->output_ndl_seconds = gNDL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 buehlmann_backup_and_restore(false);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 pDecolistBuehlmann->output_ndl_seconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 gGF_value = get_gf_at_pressure(gPressure);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 //current ceiling at actual position
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 ceiling = tissue_tolerance();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 //if(ceiling < pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 //ambient_bar_to_deco_stop_depth_bar(pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 //else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 ambient_bar_to_deco_stop_depth_bar(ceiling);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 // set the base for all upcoming parameters
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 ceiling = gStop.depth + gSurface_pressure_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 tts_seconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 // modify parameters if there is ascend or parameter fine adjustment
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 if(ceiling < (gPressure - PRESSURE_150_CM)) // more than 1.5 meter below ceiling
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 // ascend within 10 mtr to GF_low // speed 12 mtr/min -> 50 sec / 10 mtr; 15 sec / 3 mtr.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 if(ceiling < (gPressure - PRESSURE_TEN_METER) )
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 { do {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 ascend_time = ascend_with_all_gaschanges(PRESSURE_TEN_METER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 tts_seconds += ascend_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 ceiling = tissue_tolerance();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 if(tts_seconds > DECO_STOPS_MAX_TTS_CALCULATON_IN_SECONDS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 /* pInput == pBuehlmann */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 pDecolistBuehlmann->output_time_to_surface_seconds = NINETY_NINE_MINUTES_IN_SECONDS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 return;// NINETY_NINE_MINUTES_IN_SECONDS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 } while ((ascend_time > 0 ) && ((gPressure - PRESSURE_TEN_METER ) > gSurface_pressure_bar) && (ceiling < (gPressure - PRESSURE_TEN_METER)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 do {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 buehlmann_backup_and_restore(true);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 ascend_time = ascend_with_all_gaschanges(PRESSURE_THREE_METER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 tts_seconds += ascend_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 ceiling = tissue_tolerance();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 if(tts_seconds > DECO_STOPS_MAX_TTS_CALCULATON_IN_SECONDS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 /* pInput == pBuehlmann */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 pDecolistBuehlmann->output_time_to_surface_seconds = NINETY_NINE_MINUTES_IN_SECONDS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 return;// NINETY_NINE_MINUTES_IN_SECONDS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 ambient_bar_to_deco_stop_depth_bar(ceiling);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 } while ((ascend_time > 0 ) && ((gStop.depth + gSurface_pressure_bar) < gPressure));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 if(gStop.depth + gSurface_pressure_bar > gPressure)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 gPressure += PRESSURE_THREE_METER;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 buehlmann_backup_and_restore(false);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 tts_seconds -= ascend_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 // calculate first stop based on tissue saturation within 10 meters of stop
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 //ambient_bar_to_deco_stop_depth_bar(ceiling);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 // initial values, upper code might not be executed (is within 150 cm)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 if(ceiling > gSurface_pressure_bar)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 ceiling = gStop.depth + gSurface_pressure_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 // ascend the last meters to first stop (especially consider any gas changes around)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 pressure_delta = gPressure - ceiling;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 ascend_time = (int)ceil(pressure_delta * 50.0f);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 tts_seconds += ascend_with_all_gaschanges(pressure_delta);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 // NDL check
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 if(ceiling <= gSurface_pressure_bar)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 /* pInput == pBuehlmann same pointer*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 // NDL with GF_low
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 pDecolistBuehlmann->output_time_to_surface_seconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 if(ceiling >pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = ceiling;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 // calc gf loop
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 if(deco_reached)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 gGF_low_depth_bar = pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero - gSurface_pressure_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 gGF_low_depth_bar = ceiling - gSurface_pressure_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 while(gStop.depth > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 do
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 next_depth = next_stop_depth_input_is_actual_stop_id(gStop.id);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 gGF_value = get_gf_at_pressure(next_depth + gSurface_pressure_bar);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 buehlmann_backup_and_restore(true);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 ascend_time = ascend_with_all_gaschanges(gStop.depth - next_depth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 ceiling = tissue_tolerance();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 /* pre check actual limit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 if(gDecotable.output_stop_length_seconds[gStop.id] >= 999*60)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 tts_seconds -= 999*60 - gDecotable.output_stop_length_seconds[gStop.id];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 gDecotable.output_stop_length_seconds[gStop.id] = 999*60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 /* more deco on the actual depth */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 if(ceiling > next_depth + gSurface_pressure_bar)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 next_depth = -1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 buehlmann_backup_and_restore(false);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 decom_tissues_exposure2(10, &pBuDiveSettings->decogaslist[gGas_id], gPressure,gTissue_nitrogen_bar,gTissue_helium_bar); // some seconds at least at each stop
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 decom_oxygen_calculate_cns_exposure(10, &pBuDiveSettings->decogaslist[gGas_id], gPressure, &gCNS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 gDecotable.output_stop_length_seconds[gStop.id] += 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 tts_seconds += 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 } while(next_depth == -1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 tts_seconds += ascend_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 gStop.depth = next_depth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 for(i = gGas_id + 1; i < BUEHLMANN_STRUCT_MAX_GASES; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 if(pBuDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 float pressureChange = ((float)pBuDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero) / 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 if(gStop.depth <= pressureChange + 0.00001f)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 gGas_id = i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 gStop.id--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 gDecotable.output_time_to_surface_seconds = tts_seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 memcpy(pDecolistBuehlmann, &gDecotable, sizeof(SDecoinfo));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 float tissue_tolerance(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 float tissue_inertgas_saturation;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 float inertgas_a;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 float inertgas_b;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 float ceiling;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 float global_ceiling;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 int ci;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 global_ceiling = -1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 for (ci = 0; ci < 16; ci++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 if(gTissue_helium_bar[ci] == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 //
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 inertgas_a = buehlmann_N2_a[ci];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 inertgas_b = buehlmann_N2_b[ci];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci] + gTissue_helium_bar[ci];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 //
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 inertgas_a = ( ( buehlmann_N2_a[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_a[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 inertgas_b = ( ( buehlmann_N2_b[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_b[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 //
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 ceiling = (inertgas_b * ( tissue_inertgas_saturation - gGF_value * inertgas_a ) ) / (gGF_value - (inertgas_b * gGF_value) + inertgas_b);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 if(ceiling > global_ceiling)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 global_ceiling = ceiling;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 return global_ceiling;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 // hw 161121 for relative gradient
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 float tissue_tolerance_without_gf_correction(float *tissue_inertgas_saturation_output)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 float tissue_inertgas_saturation;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 float inertgas_a;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 float inertgas_b;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 float ceiling;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 float global_ceiling;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 int ci;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 global_ceiling = -1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 for (ci = 0; ci < 16; ci++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 if(gTissue_helium_bar[ci] == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 //
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 inertgas_a = buehlmann_N2_a[ci];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 inertgas_b = buehlmann_N2_b[ci];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci] + gTissue_helium_bar[ci];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 //
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 inertgas_a = ( ( buehlmann_N2_a[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_a[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 inertgas_b = ( ( buehlmann_N2_b[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_b[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 //
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 ceiling = inertgas_b * ( tissue_inertgas_saturation - inertgas_a );
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 if(ceiling > global_ceiling)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 global_ceiling = ceiling;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 if(tissue_inertgas_saturation_output)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 *tissue_inertgas_saturation_output = tissue_inertgas_saturation;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 return global_ceiling;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 uint8_t buehlmann_tissue_test_tolerance(float depth_in_bar_absolute)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 float tissue_inertgas_saturation;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 float inertgas_a;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 float inertgas_b;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 float inertgas_tolerance;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 float gf_minus_1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 gf_minus_1 = gGF_value - 1.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462 for (int ci = 0; ci < 16; ci++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 if(gTissue_helium_bar[ci] == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 //
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 inertgas_a = buehlmann_N2_a[ci];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 inertgas_b = buehlmann_N2_b[ci];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 tissue_inertgas_saturation = gTissue_nitrogen_bar[ci] + gTissue_helium_bar[ci];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 //
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 inertgas_a = ( ( buehlmann_N2_a[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_a[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 inertgas_b = ( ( buehlmann_N2_b[ci] * gTissue_nitrogen_bar[ci]) + ( buehlmann_He_b[ci] * gTissue_helium_bar[ci]) ) / tissue_inertgas_saturation;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 //
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 inertgas_tolerance = ( (gGF_value / inertgas_b - gf_minus_1) * depth_in_bar_absolute ) + ( gGF_value * inertgas_a );
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 //
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 if(inertgas_tolerance < tissue_inertgas_saturation)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 void ambient_bar_to_deco_stop_depth_bar(float ceiling)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 int i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 ceiling -= gSurface_pressure_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 if(ceiling <= 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 gStop.depth = pBuDiveSettings->last_stop_depth_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 gStop.id = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502 //for(int i = 1; i < 10; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504 if((ceiling - pBuDiveSettings->last_stop_depth_bar) <= 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 gStop.depth = pBuDiveSettings->last_stop_depth_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 gStop.id = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 gStop.depth = pBuDiveSettings->input_second_to_last_stop_depth_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 gStop.id = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 ceiling -= pBuDiveSettings->input_second_to_last_stop_depth_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 if(ceiling <= 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 for(i = 1; i < (DECOINFO_STRUCT_MAX_STOPS - 2); i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 ceiling -= pBuDiveSettings->input_next_stop_increment_depth_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 if(ceiling <= 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 gStop.depth += i * pBuDiveSettings->input_next_stop_increment_depth_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 gStop.id += i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529 float next_stop_depth_input_is_actual_stop_id(int actual_id)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 if(actual_id == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534 if(actual_id == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 return pBuDiveSettings->last_stop_depth_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 actual_id -= 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538 return pBuDiveSettings->input_second_to_last_stop_depth_bar + (actual_id * pBuDiveSettings->input_next_stop_increment_depth_bar);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541 int ascend_with_all_gaschanges(float pressure_decrease)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 float pressureTop, pressureTop_tmp, pressureBottom, pressureChange, ascendrate_in_seconds_for_one_bar, pressure_difference;
51
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
544 int time_for_ascend = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 int seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 int i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548 ascendrate_in_seconds_for_one_bar = 60 * 10 / pBuDiveSettings->ascentRate_meterperminute;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550 if(fabsf(gPressure - gSurface_pressure_bar) < PRESSURE_HALF_METER)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552 gPressure = gSurface_pressure_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556 pressureTop = gPressure - pressure_decrease;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 if( gSurface_pressure_bar > pressureTop)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558 pressureTop = gSurface_pressure_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559 pressureBottom = gPressure;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 seconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 do{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562 pressureTop_tmp = pressureTop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 for(i = gGas_id + 1; i < BUEHLMANN_STRUCT_MAX_GASES; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 if(pBuDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 pressureChange = gSurface_pressure_bar + ((float)pBuDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero) / 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 if(pressureBottom <= pressureChange)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570 gGas_id = i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 for(i = gGas_id + 1; i < BUEHLMANN_STRUCT_MAX_GASES; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 if(pBuDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 pressureChange = gSurface_pressure_bar + ((float)pBuDiveSettings->decogaslist[i].change_during_ascent_depth_meter_otherwise_zero)/ 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 if((pressureChange < pressureBottom) && (pressureChange > pressureTop))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 pressureTop_tmp = pressureChange;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 pressure_difference = pressureBottom - pressureTop_tmp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 if(pressure_difference > 0.0001f)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 time_for_ascend = (int)ceilf(pressure_difference * ascendrate_in_seconds_for_one_bar);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592 decom_tissues_exposure_stage_schreiner(time_for_ascend, &pBuDiveSettings->decogaslist[gGas_id],
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 pressureBottom, pressureTop_tmp, gTissue_nitrogen_bar, gTissue_helium_bar);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 decom_oxygen_calculate_cns_stage_SchreinerStyle(time_for_ascend,&pBuDiveSettings->decogaslist[gGas_id],
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595 pressureBottom, pressureTop_tmp, &gCNS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597 pressureBottom = pressureTop_tmp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598 seconds += time_for_ascend;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599 }while(pressureTop_tmp > pressureTop);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600 gPressure = pressureTop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601 return seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 float get_gf_at_pressure(float pressure)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 float gfSteigung = 0.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609 if(gGF_low_depth_bar < 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610 gGF_low_depth_bar = PRESSURE_THREE_METER; // just to prevent erratic behaviour if variable is not set
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612 gfSteigung = ((float)(pBuDiveSettings->gf_high - pBuDiveSettings->gf_low))/ gGF_low_depth_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615 if((pressure - gSurface_pressure_bar) <= PRESSURE_HALF_METER)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 return ((float)pBuDiveSettings->gf_high) / 100.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 if(pressure >= gSurface_pressure_bar + gGF_low_depth_bar)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619 return ((float)pBuDiveSettings->gf_low) / 100.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621 return (pBuDiveSettings->gf_high - gfSteigung * (pressure - gSurface_pressure_bar) )/ 100.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625 void buehlmann_calc_ndl(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627 float local_tissue_nitrogen_bar[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628 float local_tissue_helium_bar[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 int i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631 gNDL = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632 //Check ndl always use gHigh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633 gGF_value = ((float)pBuDiveSettings->gf_high) / 100.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634 //10 minutes steps
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635 while(gNDL < (300 * 60))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 memcpy(local_tissue_nitrogen_bar, gTissue_nitrogen_bar, (4*16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638 memcpy(local_tissue_helium_bar, gTissue_helium_bar, (4*16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639 //
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 gNDL += 600;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641 decom_tissues_exposure2(600, &pBuDiveSettings->decogaslist[gGas_id], gPressure,gTissue_nitrogen_bar,gTissue_helium_bar);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 decom_oxygen_calculate_cns_exposure(600,&pBuDiveSettings->decogaslist[gGas_id],gPressure,&gCNS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 //tissues_exposure_at_gPressure_seconds(600);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644 buehlmann_backup_and_restore(true);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 if(dive1_check_deco() == true)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647 buehlmann_backup_and_restore(false);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650 buehlmann_backup_and_restore(false);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653 if(gNDL < (300 * 60))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654 gNDL -= 600;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656 if(gNDL > (150 * 60))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659 // refine
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 memcpy(gTissue_nitrogen_bar, local_tissue_nitrogen_bar, (4*16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661 memcpy(gTissue_helium_bar, local_tissue_helium_bar, (4*16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663 //One minutes step
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 for(i = 0; i < 20; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666 gNDL += 60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667 //tissues_exposure_at_gPressure_seconds(60);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 decom_tissues_exposure2(60, &pBuDiveSettings->decogaslist[gGas_id], gPressure,gTissue_nitrogen_bar,gTissue_helium_bar);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 decom_oxygen_calculate_cns_exposure(60,&pBuDiveSettings->decogaslist[gGas_id],gPressure,&gCNS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670 buehlmann_backup_and_restore(true);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 if(dive1_check_deco() == true)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673 buehlmann_backup_and_restore(false);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 //gNDL -= 60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 // dive1_check_deco
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 /// @brief for NDL calculations
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 /// 160614 using ceilingOther and not ceiling
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 _Bool dive1_check_deco(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 // gGF_value is set in call routine;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 // internes Backup!
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 // calc like in deco
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 float ceiling;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692 float ceilingOther; // new hw 160614
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 ceiling = tissue_tolerance();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 ambient_bar_to_deco_stop_depth_bar(ceiling); // this will set gStop.depth :-) (and gStop.id)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 // set the base for all upcoming parameters
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 ceilingOther = gStop.depth + gSurface_pressure_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 // modify parameters if there is ascend or parameter fine adjustment
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 if(ceilingOther < (gPressure - PRESSURE_150_CM)) // more than 1.5 meter below ceiling
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 // ascend within 10 mtr to GF_low // speed 12 mtr/min -> 50 sec / 10 mtr; 15 sec / 3 mtr.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 while(((gPressure - PRESSURE_TEN_METER ) > gSurface_pressure_bar) && (ceiling < (gPressure - PRESSURE_TEN_METER)))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 ascend_with_all_gaschanges(PRESSURE_TEN_METER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 ceiling = tissue_tolerance();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 while(((gPressure - PRESSURE_THREE_METER )> gSurface_pressure_bar) && (ceiling < gPressure))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711 ascend_with_all_gaschanges(PRESSURE_THREE_METER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 ceiling = tissue_tolerance();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715 if(ceiling <= gSurface_pressure_bar)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716 return false;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 return true;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 void buehlmann_ceiling_calculator(SLifeData* pLifeData, SDiveSettings * pDiveSettings, SDecoinfo * pDecoInfo)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724 float gf_low;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 float gf_high;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 float gf_delta;
224
ceecabfddb57 Bugfix, deco: fix 2 (small) problems with calculated ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents: 130
diff changeset
727 float dv_gf_low_stop_meter;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 _Bool test_result;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 float next_gf_value;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730 float next_pressure_absolute;
224
ceecabfddb57 Bugfix, deco: fix 2 (small) problems with calculated ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents: 130
diff changeset
731 float depth_in_meter;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 gf_low = pDiveSettings->gf_low;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734 gf_high = pDiveSettings->gf_high;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736 dv_gf_low_stop_meter = (int)((pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero - pLifeData->pressure_surface_bar) * 10);
224
ceecabfddb57 Bugfix, deco: fix 2 (small) problems with calculated ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents: 130
diff changeset
737
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738 if(dv_gf_low_stop_meter < 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740 next_gf_value = gf_high; // fix hw 161024
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 gf_delta = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 next_gf_value = gf_high;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746 gf_delta = gf_high - gf_low;
224
ceecabfddb57 Bugfix, deco: fix 2 (small) problems with calculated ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents: 130
diff changeset
747 gf_delta /= (dv_gf_low_stop_meter * 10); // gf_delta is delta for 10 cm !!
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 }
224
ceecabfddb57 Bugfix, deco: fix 2 (small) problems with calculated ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents: 130
diff changeset
749
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 depth_in_meter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 next_pressure_absolute = pLifeData->pressure_surface_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 memcpy(gTissue_nitrogen_bar, pLifeData->tissue_nitrogen_bar, (4*16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 memcpy(gTissue_helium_bar, pLifeData->tissue_helium_bar, (4*16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 gGF_value = next_gf_value / 100.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 //
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757 test_result = buehlmann_tissue_test_tolerance(next_pressure_absolute);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 //
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 while(!test_result && depth_in_meter < 200)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 {
224
ceecabfddb57 Bugfix, deco: fix 2 (small) problems with calculated ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents: 130
diff changeset
761 depth_in_meter += 0.1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762 next_gf_value = fmaxf(gf_low, next_gf_value - gf_delta);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 gGF_value = next_gf_value / 100.0f;
224
ceecabfddb57 Bugfix, deco: fix 2 (small) problems with calculated ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents: 130
diff changeset
764 next_pressure_absolute += 0.01f; // 0.1 meter down
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765 test_result = buehlmann_tissue_test_tolerance(next_pressure_absolute);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766 }
224
ceecabfddb57 Bugfix, deco: fix 2 (small) problems with calculated ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents: 130
diff changeset
767
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 if(test_result)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770 pDecoInfo->output_ceiling_meter = depth_in_meter;
224
ceecabfddb57 Bugfix, deco: fix 2 (small) problems with calculated ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents: 130
diff changeset
771
ceecabfddb57 Bugfix, deco: fix 2 (small) problems with calculated ceiling
Jan Mulder <jlmulder@xs4all.nl>
parents: 130
diff changeset
772 if(depth_in_meter >= 0)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774 for(int i = 0; i < 10; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776 next_gf_value += gf_delta/10.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777 gGF_value = next_gf_value / 100.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 next_pressure_absolute -= 0.01f; // 0.1 meter up
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779 if(!buehlmann_tissue_test_tolerance(next_pressure_absolute))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781 pDecoInfo->output_ceiling_meter -= ((float)i)/10.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 pDecoInfo->output_ceiling_meter = 999;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 void buehlmann_relative_gradient_calculator(SLifeData* pLifeData, SDiveSettings * pDiveSettings, SDecoinfo * pDecoInfo)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796 float gf_low;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797 float gf_high;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 float gf_delta;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799 int dv_gf_low_stop_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801 float rgf; // relative gradient factor by hwOS p2_deco.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802 float temp_tissue;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803 float limit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 float pres_respiration;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805 float gf;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 gf_low = pDiveSettings->gf_low;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808 gf_high = pDiveSettings->gf_high;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810 dv_gf_low_stop_meter = (int)((pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero - pLifeData->pressure_surface_bar) * 10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812 if(dv_gf_low_stop_meter < 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 gf_delta = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 gf_delta = gf_high - gf_low;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 gf_delta /= dv_gf_low_stop_meter; // gf_delta is delta for each meter now!!
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823 limit = tissue_tolerance_without_gf_correction(&temp_tissue);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 pres_respiration = pLifeData->pressure_ambient_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826 if( temp_tissue <= pres_respiration )
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828 gf = 0.0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 gf = (temp_tissue - pres_respiration)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 / (temp_tissue - limit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 * 100.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 if(dv_gf_low_stop_meter < 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 rgf = gf_high;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 float temp1 = dv_gf_low_stop_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844 float temp2 = pLifeData->depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 if (temp2 <= 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847 rgf = gf_high;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 else if (temp2 >= temp1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 rgf = gf_low;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851 rgf = gf_low + (temp1 - temp2)*gf_delta;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854 rgf = gf / rgf;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 // avoid discussions about values > 100 below next deco stop
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857 if((rgf > 1.0f) && (pLifeData->depth_meter >= pDecoInfo->output_ceiling_meter))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 rgf = 1.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860 pDecoInfo->output_relative_gradient = rgf;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861 }