annotate src/p2_deco.c @ 531:e6d730e771e6

2.21 start
author heinrichsweikamp
date Fri, 18 Aug 2017 15:19:35 +0200
parents 015b7fdd90a7
children a5d2e6083b1d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 // **************************************************************
heinrichsweikamp
parents:
diff changeset
2 // p2_deco.c
heinrichsweikamp
parents:
diff changeset
3 //
heinrichsweikamp
parents:
diff changeset
4 // Created on: 12.05.2009
heinrichsweikamp
parents:
diff changeset
5 // Author: chsw
heinrichsweikamp
parents:
diff changeset
6 //
heinrichsweikamp
parents:
diff changeset
7 // **************************************************************
heinrichsweikamp
parents:
diff changeset
8
heinrichsweikamp
parents:
diff changeset
9 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
10 // OSTC - diving computer code
heinrichsweikamp
parents:
diff changeset
11 // Copyright (C) 2011 HeinrichsWeikamp GbR
heinrichsweikamp
parents:
diff changeset
12 //
heinrichsweikamp
parents:
diff changeset
13 // This program is free software: you can redistribute it and/or modify
heinrichsweikamp
parents:
diff changeset
14 // it under the terms of the GNU General Public License as published by
heinrichsweikamp
parents:
diff changeset
15 // the Free Software Foundation, either version 3 of the License, or
heinrichsweikamp
parents:
diff changeset
16 // (at your option) any later version.
heinrichsweikamp
parents:
diff changeset
17 //
heinrichsweikamp
parents:
diff changeset
18 // This program is distributed in the hope that it will be useful,
heinrichsweikamp
parents:
diff changeset
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
heinrichsweikamp
parents:
diff changeset
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
heinrichsweikamp
parents:
diff changeset
21 // GNU General Public License for more details.
heinrichsweikamp
parents:
diff changeset
22 //
heinrichsweikamp
parents:
diff changeset
23 // You should have received a copy of the GNU General Public License
heinrichsweikamp
parents:
diff changeset
24 // along with this program. If not, see <http://www.gnu.org/licenses/>.
heinrichsweikamp
parents:
diff changeset
25 //
heinrichsweikamp
parents:
diff changeset
26 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
27
heinrichsweikamp
parents:
diff changeset
28 // *****************************
heinrichsweikamp
parents:
diff changeset
29 // ** I N T R O D U C T I O N **
heinrichsweikamp
parents:
diff changeset
30 // *****************************
heinrichsweikamp
parents:
diff changeset
31 //
heinrichsweikamp
parents:
diff changeset
32 // OSTC
heinrichsweikamp
parents:
diff changeset
33 //
heinrichsweikamp
parents:
diff changeset
34 // code:
heinrichsweikamp
parents:
diff changeset
35 // p2_deco_main_c_v101.c
heinrichsweikamp
parents:
diff changeset
36 // part2 of the OSTC code
heinrichsweikamp
parents:
diff changeset
37 // code with constant O2 partial pressure routines
heinrichsweikamp
parents:
diff changeset
38 // under construction !!
heinrichsweikamp
parents:
diff changeset
39 //
heinrichsweikamp
parents:
diff changeset
40 // summary:
heinrichsweikamp
parents:
diff changeset
41 // decompression routines
heinrichsweikamp
parents:
diff changeset
42 // for the OSTC experimental project
heinrichsweikamp
parents:
diff changeset
43 // written by Christian Weikamp
heinrichsweikamp
parents:
diff changeset
44 // last revision __________
heinrichsweikamp
parents:
diff changeset
45 // comments added _________
heinrichsweikamp
parents:
diff changeset
46 //
heinrichsweikamp
parents:
diff changeset
47 // additional files:
heinrichsweikamp
parents:
diff changeset
48 // p2_tables_v100.romdata (other files)
heinrichsweikamp
parents:
diff changeset
49 // 18f4685_ostc_v100.lkr (linker script)
heinrichsweikamp
parents:
diff changeset
50 //
heinrichsweikamp
parents:
diff changeset
51 // history:
heinrichsweikamp
parents:
diff changeset
52 // 01/03/08 v100: first release candidate
heinrichsweikamp
parents:
diff changeset
53 // 03/13/08 v101: start of programming ppO2 code
heinrichsweikamp
parents:
diff changeset
54 // 03/13/25 v101a: backup of interrim version with ppO2 calculation
heinrichsweikamp
parents:
diff changeset
55 // 03/13/25 v101: open circuit gas change during deco
heinrichsweikamp
parents:
diff changeset
56 // 03/13/25 v101: CNS_fraction calculation
heinrichsweikamp
parents:
diff changeset
57 // 03/13/26 v101: optimization of tissue calc routines
heinrichsweikamp
parents:
diff changeset
58 // 07/xx/08 v102a: debug of bottom time routine
heinrichsweikamp
parents:
diff changeset
59 // 09/xx/08 v102d: Gradient Factor Model implemenation
heinrichsweikamp
parents:
diff changeset
60 // 10/10/08 v104: renamed to build v103 for v118 stable
heinrichsweikamp
parents:
diff changeset
61 // 10/14/08 v104: integration of char_I_depth_last_deco for Gradient Model
heinrichsweikamp
parents:
diff changeset
62 // 03/31/09 v107: integration of FONT Incon24
heinrichsweikamp
parents:
diff changeset
63 // 05/23/10 v109: 5 gas changes & 1 min timer
heinrichsweikamp
parents:
diff changeset
64 // 07/13/10 v110: cns vault added
heinrichsweikamp
parents:
diff changeset
65 // 12/25/10 v110: split in three files (deco.c, main.c, definitions.h)
heinrichsweikamp
parents:
diff changeset
66 // 2011/01/20: [jDG] Create a common file included in ASM and C code.
heinrichsweikamp
parents:
diff changeset
67 // 2011/01/24: [jDG] Make ascenttime an short. No more overflow!
heinrichsweikamp
parents:
diff changeset
68 // 2011/01/25: [jDG] Fusion deco array for both models.
heinrichsweikamp
parents:
diff changeset
69 // 2011/01/25: [jDG] Use CF(54) to reverse deco order.
heinrichsweikamp
parents:
diff changeset
70 // 2011/02/11: [jDG] Reworked gradient-factor implementation.
heinrichsweikamp
parents:
diff changeset
71 // 2011/02/15: [jDG] Fixed inconsistencies introduced by gas switch delays.
heinrichsweikamp
parents:
diff changeset
72 // 2011/03/21: [jDG] Added gas consumption (CF56 & CF57) evaluation for OCR mode.
heinrichsweikamp
parents:
diff changeset
73 // 2011/04/15: [jDG] Store low_depth in 32bits (w/o rounding), for a better stability.
heinrichsweikamp
parents:
diff changeset
74 // 2011/04/25: [jDG] Added 1mn mode for CNS calculation, to allow it for decoplanning.
heinrichsweikamp
parents:
diff changeset
75 // 2011/04/27: [jDG] Fixed char_O_gradient_factor calculation when model uses gradient-factor.
heinrichsweikamp
parents:
diff changeset
76 // 2011/05/02: [jDG] Added "Future TTS" function (CF58).
heinrichsweikamp
parents:
diff changeset
77 // 2011/05/17: [jDG] Various cleanups.
heinrichsweikamp
parents:
diff changeset
78 // 2011/08/08: [jDG] Computes CNS during deco planning ascent.
heinrichsweikamp
parents:
diff changeset
79 // 2011/11/24: [jDG] Slightly faster and better NDL computation.
heinrichsweikamp
parents:
diff changeset
80 // 2011/12/17: [mH] Remove of the useless debug stuff
heinrichsweikamp
parents:
diff changeset
81 // 2012/02/24: [jDG] Remove missed stop bug.
heinrichsweikamp
parents:
diff changeset
82 // 2012/02/25: [jDG] Looking for a more stable LOW grad factor reference.
heinrichsweikamp
parents:
diff changeset
83 // 2012/09/10: [mH] Fill char_O_deco_time_for_log for logbook write
heinrichsweikamp
parents:
diff changeset
84 // 2012/10/05: [jDG] Better deco_gas_volumes accuracy (average depth, switch between stop).
heinrichsweikamp
parents:
diff changeset
85 // 2013/03/05: [jDG] Should vault low_depth too.
heinrichsweikamp
parents:
diff changeset
86 // 2013/03/05: [jDG] Wrobell remark: ascent_to_first_stop works better with finer steps (2sec).
33
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
87 // 2013/05/08: [jDG] A. Salm remark: NOAA tables for CNS are in ATA, not bar.
115
72259a79eac2 FIX: Gas volume computation when using several travel mix.
heinrichsweikamp
parents: 114
diff changeset
88 // 2013/12/21: [jDG] Fix CNS calculation in decoplan w/o marked gas switch
72259a79eac2 FIX: Gas volume computation when using several travel mix.
heinrichsweikamp
parents: 114
diff changeset
89 // 2014/06/16: [jDG] Fix Helium diluant. Fix volumes with many travel mix.
324
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
90 // 2014/06/29: [mH] Compute int_O_ceiling
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
91 // 2015/06/12: [jDG] Fix NDL prediction while desaturating with the Buhlmann model.
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
92 // 2017/08/04: [mH] Switch to absolute GF everywhere and apply safety margin parameters to both models (GF and non-GF), fixes from Ralph Lembcke
0
heinrichsweikamp
parents:
diff changeset
93 //
heinrichsweikamp
parents:
diff changeset
94 // TODO:
heinrichsweikamp
parents:
diff changeset
95 //
heinrichsweikamp
parents:
diff changeset
96 // Literature:
313
0ce5fa241b8e FIX minor comment about deco offset unit...
jDG
parents: 298
diff changeset
97 // Buhlmann, Albert: Tauchmedizin; 4. Auflage [2002];
0
heinrichsweikamp
parents:
diff changeset
98 // Schr"oder, Kai & Reith, Steffen; 2000; S"attigungsvorg"ange beim Tauchen, das Modell ZH-L16, Funktionsweise von Tauchcomputern; http://www.achim-und-kai.de/kai/tausim/saett_faq
heinrichsweikamp
parents:
diff changeset
99 // Morrison, Stuart; 2000; DIY DECOMPRESSION; http://www.lizardland.co.uk/DIYDeco.html
heinrichsweikamp
parents:
diff changeset
100 // Balthasar, Steffen; Dekompressionstheorie I: Neo Haldane Modelle; http://www.txfreak.de/dekompressionstheorie_1.pdf
heinrichsweikamp
parents:
diff changeset
101 // Baker, Erik C.; Clearing Up The Confusion About "Deep Stops"
heinrichsweikamp
parents:
diff changeset
102 // Baker, Erik C.; Understanding M-values; http://www.txfreak.de/understanding_m-values.pdf
heinrichsweikamp
parents:
diff changeset
103 //
heinrichsweikamp
parents:
diff changeset
104 //
heinrichsweikamp
parents:
diff changeset
105
heinrichsweikamp
parents:
diff changeset
106 // *********************
heinrichsweikamp
parents:
diff changeset
107 // ** I N C L U D E S **
heinrichsweikamp
parents:
diff changeset
108 // *********************
heinrichsweikamp
parents:
diff changeset
109 #include <math.h>
heinrichsweikamp
parents:
diff changeset
110
heinrichsweikamp
parents:
diff changeset
111 // ***********************************************
heinrichsweikamp
parents:
diff changeset
112 // ** V A R I A B L E S D E F I N I T I O N S **
heinrichsweikamp
parents:
diff changeset
113 // ***********************************************
heinrichsweikamp
parents:
diff changeset
114
heinrichsweikamp
parents:
diff changeset
115 #include "p2_definitions.h"
heinrichsweikamp
parents:
diff changeset
116 #define TEST_MAIN
heinrichsweikamp
parents:
diff changeset
117 #include "shared_definitions.h"
heinrichsweikamp
parents:
diff changeset
118
519
heinrichsweikamp
parents: 379
diff changeset
119 // Water vapour partial pressure in the lungs
0
heinrichsweikamp
parents:
diff changeset
120 #define ppWater 0.0627
heinrichsweikamp
parents:
diff changeset
121 #define METER_TO_BAR 0.09985
heinrichsweikamp
parents:
diff changeset
122 #define BAR_TO_METER 10.0150 // (1.0/METER_TO_BAR)
heinrichsweikamp
parents:
diff changeset
123
heinrichsweikamp
parents:
diff changeset
124 // Surface security factor
heinrichsweikamp
parents:
diff changeset
125 #define SURFACE_DESAT_FACTOR 0.7042
heinrichsweikamp
parents:
diff changeset
126
heinrichsweikamp
parents:
diff changeset
127 // *************************
heinrichsweikamp
parents:
diff changeset
128 // ** P R O T O T Y P E S **
heinrichsweikamp
parents:
diff changeset
129 // *************************
heinrichsweikamp
parents:
diff changeset
130
heinrichsweikamp
parents:
diff changeset
131 static void calc_hauptroutine(void);
heinrichsweikamp
parents:
diff changeset
132 static void calc_nullzeit(void);
heinrichsweikamp
parents:
diff changeset
133
heinrichsweikamp
parents:
diff changeset
134 static void calc_tissue(PARAMETER unsigned char period);
heinrichsweikamp
parents:
diff changeset
135 static void calc_limit(void);
heinrichsweikamp
parents:
diff changeset
136
heinrichsweikamp
parents:
diff changeset
137 static void clear_tissue(void);
heinrichsweikamp
parents:
diff changeset
138 static void calc_ascenttime(void);
heinrichsweikamp
parents:
diff changeset
139 static void update_startvalues(void);
heinrichsweikamp
parents:
diff changeset
140 static void clear_deco_table(void);
heinrichsweikamp
parents:
diff changeset
141 static unsigned char update_deco_table(void);
heinrichsweikamp
parents:
diff changeset
142
heinrichsweikamp
parents:
diff changeset
143 static void sim_tissue(PARAMETER unsigned char period);
heinrichsweikamp
parents:
diff changeset
144 static void sim_limit(PARAMETER float GF_current);
heinrichsweikamp
parents:
diff changeset
145 static void sim_extra_time(void);
heinrichsweikamp
parents:
diff changeset
146 static void calc_dive_interval(void);
heinrichsweikamp
parents:
diff changeset
147
heinrichsweikamp
parents:
diff changeset
148 static void calc_gradient_factor(void);
heinrichsweikamp
parents:
diff changeset
149 static void calc_wo_deco_step_1_min(void);
heinrichsweikamp
parents:
diff changeset
150
heinrichsweikamp
parents:
diff changeset
151 static void calc_hauptroutine_data_input(void);
heinrichsweikamp
parents:
diff changeset
152 static void calc_hauptroutine_update_tissues(void);
heinrichsweikamp
parents:
diff changeset
153 static void calc_hauptroutine_calc_deco(void);
heinrichsweikamp
parents:
diff changeset
154 static void sim_ascent_to_first_stop(void);
heinrichsweikamp
parents:
diff changeset
155
heinrichsweikamp
parents:
diff changeset
156 static unsigned char gas_switch_deepest(void);
heinrichsweikamp
parents:
diff changeset
157 static void gas_switch_set(void);
heinrichsweikamp
parents:
diff changeset
158
heinrichsweikamp
parents:
diff changeset
159 static unsigned char calc_nextdecodepth(void);
heinrichsweikamp
parents:
diff changeset
160
heinrichsweikamp
parents:
diff changeset
161 //---- Bank 5 parameters -----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
162 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
163 # pragma udata bank5=0x500
heinrichsweikamp
parents:
diff changeset
164 #endif
heinrichsweikamp
parents:
diff changeset
165
heinrichsweikamp
parents:
diff changeset
166 static float GF_low;
heinrichsweikamp
parents:
diff changeset
167 static float GF_high;
heinrichsweikamp
parents:
diff changeset
168 static float GF_delta;
heinrichsweikamp
parents:
diff changeset
169 static float locked_GF_step; // GF_delta / low_depth
heinrichsweikamp
parents:
diff changeset
170
heinrichsweikamp
parents:
diff changeset
171 static unsigned char temp_depth_limit;
342
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
172 float low_depth; // Depth of deepest stop
0
heinrichsweikamp
parents:
diff changeset
173
heinrichsweikamp
parents:
diff changeset
174 // Simulation context: used to predict ascent.
heinrichsweikamp
parents:
diff changeset
175 static unsigned char sim_lead_tissue_no; // Leading compatiment number.
heinrichsweikamp
parents:
diff changeset
176 static float sim_lead_tissue_limit; // Buhlmann tolerated pressure.
heinrichsweikamp
parents:
diff changeset
177
heinrichsweikamp
parents:
diff changeset
178 // Real context: what we are doing now.
heinrichsweikamp
parents:
diff changeset
179 static float calc_lead_tissue_limit; //
heinrichsweikamp
parents:
diff changeset
180
heinrichsweikamp
parents:
diff changeset
181 static unsigned char internal_deco_time[NUM_STOPS];
heinrichsweikamp
parents:
diff changeset
182 static unsigned char internal_deco_depth[NUM_STOPS];
heinrichsweikamp
parents:
diff changeset
183
heinrichsweikamp
parents:
diff changeset
184 static float cns_vault;
heinrichsweikamp
parents:
diff changeset
185 static float low_depth_vault;
heinrichsweikamp
parents:
diff changeset
186 static float pres_tissue_N2_vault[NUM_COMP];
heinrichsweikamp
parents:
diff changeset
187 static float pres_tissue_He_vault[NUM_COMP];
heinrichsweikamp
parents:
diff changeset
188
heinrichsweikamp
parents:
diff changeset
189 //---- Bank 6 parameters -----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
190 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
191 # pragma udata bank6=0x600
heinrichsweikamp
parents:
diff changeset
192 #endif
heinrichsweikamp
parents:
diff changeset
193
heinrichsweikamp
parents:
diff changeset
194 static unsigned char ci;
324
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
195 static float pres_respiration;
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
196 static float pres_surface;
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
197 static float temp_deco;
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
198 static float ppN2;
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
199 static float ppHe;
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
200 static float temp_tissue;
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
201 static float N2_ratio; // Breathed gas nitrogen ratio.
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
202 static float He_ratio; // Breathed gas helium ratio.
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
203 static float var_N2_a; // Buhlmann a, for current N2 tissue.
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
204 static float var_N2_b; // Buhlmann b, for current N2 tissue.
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
205 static float var_He_a; // Buhlmann a, for current He tissue.
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
206 static float var_He_b; // Buhlmann b, for current He tissue.
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
207 static float var_N2_e; // Exposition, for current N2 tissue.
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
208 static float var_He_e; // Exposition, for current He tissue.
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
209 static float var_N2_ht; // Half-time for current N2 tissue.
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
210 static float var_He_ht; // Half-time for current N2 tissue.
0
heinrichsweikamp
parents:
diff changeset
211
heinrichsweikamp
parents:
diff changeset
212 static float pres_diluent; // new in v.101
heinrichsweikamp
parents:
diff changeset
213 static float const_ppO2; // new in v.101
heinrichsweikamp
parents:
diff changeset
214
heinrichsweikamp
parents:
diff changeset
215 static unsigned char sim_gas_last_depth; // Depth of last used gas, to detected a gas switch.
heinrichsweikamp
parents:
diff changeset
216 static unsigned char sim_gas_last_used; // Number of last used gas, to detected a gas switch.
heinrichsweikamp
parents:
diff changeset
217 static unsigned short sim_dive_mins; // Simulated dive time.
324
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
218 static float calc_N2_ratio; // Simulated (switched) nitrogen ratio.
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
219 static float calc_He_ratio; // Simulated (switched) helium ratio.
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
220 static float CNS_fraction; // new in v.101
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
221 static float float_saturation_multiplier; // new in v.101
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
222 static float float_desaturation_multiplier; // new in v.101
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
223 static float float_deco_distance; // new in v.101
0
heinrichsweikamp
parents:
diff changeset
224
heinrichsweikamp
parents:
diff changeset
225 static unsigned char deco_gas_change[NUM_GAS]; // new in v.109
111
c61b7a4e317c Bugfix: CNS in planner
heinrichsweikamp
parents: 34
diff changeset
226 static unsigned char internal_deco_gas [NUM_STOPS];
0
heinrichsweikamp
parents:
diff changeset
227
heinrichsweikamp
parents:
diff changeset
228 //---- Bank 7 parameters -----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
229 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
230 # pragma udata bank7=0x700
heinrichsweikamp
parents:
diff changeset
231 #endif
133
939f1e83c4c2 BUGFIX: Surface interval was not displayed correctly in some cases
heinrichsweikamp
parents: 126
diff changeset
232 // Keep order of 0x700 variables
0
heinrichsweikamp
parents:
diff changeset
233 float pres_tissue_N2[NUM_COMP];
heinrichsweikamp
parents:
diff changeset
234 float pres_tissue_He[NUM_COMP];
heinrichsweikamp
parents:
diff changeset
235 float sim_pres_tissue_N2[NUM_COMP]; // 16 floats = 64 bytes.
heinrichsweikamp
parents:
diff changeset
236 float sim_pres_tissue_He[NUM_COMP]; // 16 floats = 64 bytes.
heinrichsweikamp
parents:
diff changeset
237
heinrichsweikamp
parents:
diff changeset
238 //---- Bank 8 parameters -----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
239 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
240 # pragma udata overlay bank8=0x800
heinrichsweikamp
parents:
diff changeset
241 static char md_pi_subst[256];
heinrichsweikamp
parents:
diff changeset
242 # define C_STACK md_pi_subst // Overlay C-code data stack here, too.
heinrichsweikamp
parents:
diff changeset
243 #endif
heinrichsweikamp
parents:
diff changeset
244
heinrichsweikamp
parents:
diff changeset
245 // Back to bank6 for further tmp data
heinrichsweikamp
parents:
diff changeset
246 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
247 # pragma udata bank6
heinrichsweikamp
parents:
diff changeset
248 #endif
heinrichsweikamp
parents:
diff changeset
249
heinrichsweikamp
parents:
diff changeset
250 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
251 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
252 ///////////////////////////// THE LOOKUP TABLES //////////////////////////////
heinrichsweikamp
parents:
diff changeset
253 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
254 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
255 //
heinrichsweikamp
parents:
diff changeset
256 // End of PROM code is 17F00, So push tables on PROM top...
heinrichsweikamp
parents:
diff changeset
257 //
heinrichsweikamp
parents:
diff changeset
258 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
259 # pragma romdata buhlmann_tables = 0x1DD00 // Needs to be in UPPER bank.
heinrichsweikamp
parents:
diff changeset
260 #endif
heinrichsweikamp
parents:
diff changeset
261
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
262 rom const float buhlmann_ab[4*16] = {
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
263 // Data ZH-L16C, from Bühlmann Tauchmedizin 2002, option 1a (4mn)
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
264 // a for N2 b for N2 a of He b for He
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
265 1.2599, 0.5050, 1.7424, 0.4245,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
266 1.0000, 0.6514, 1.3830, 0.5747,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
267 0.8618, 0.7222, 1.1919, 0.6527,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
268 0.7562, 0.7825, 1.0458, 0.7223,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
269 0.6200, 0.8126, 0.9220, 0.7582,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
270 0.5043, 0.8434, 0.8205, 0.7957,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
271 0.4410, 0.8693, 0.7305, 0.8279,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
272 0.4000, 0.8910, 0.6502, 0.8553,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
273 0.3750, 0.9092, 0.5950, 0.8757,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
274 0.3500, 0.9222, 0.5545, 0.8903,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
275 0.3295, 0.9319, 0.5333, 0.8997,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
276 0.3065, 0.9403, 0.5189, 0.9073,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
277 0.2835, 0.9477, 0.5181, 0.9122,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
278 0.2610, 0.9544, 0.5176, 0.9171,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
279 0.2480, 0.9602, 0.5172, 0.9217,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
280 0.2327, 0.9653, 0.5119, 0.9267
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
281 };
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
282
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
283 rom const float buhlmann_ht[2*16] = {
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
284 // Compartiment half-life, in minute
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
285 //-- N2 ---- He ---------------------------------------------------------------------
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
286 4.0, 1.51,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
287 8.0, 3.02,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
288 12.5, 4.72,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
289 18.5, 6.99,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
290 27.0, 10.21,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
291 38.3, 14.48,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
292 54.3, 20.53,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
293 77.0, 29.11,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
294 109.0, 41.20,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
295 146.0, 55.19,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
296 187.0, 70.69,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
297 239.0, 90.34,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
298 305.0, 115.29,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
299 390.0, 147.42,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
300 498.0, 188.24,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
301 635.0, 240.03
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
302 };
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
303
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
304 rom const float e2secs[2*16] = {
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
305 // result of 1 - 2^(-1/(30sec*HT))
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
306 //---- N2 ------------- He ------------
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
307 5.75958E-03, 1.51848E-02,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
308 2.88395E-03, 7.62144E-03,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
309 1.84669E-03, 4.88315E-03,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
310 1.24813E-03, 3.29997E-03,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
311 8.55371E-04, 2.26041E-03,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
312 6.03079E-04, 1.59437E-03,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
313 4.25414E-04, 1.12479E-03,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
314 3.00019E-04, 7.93395E-04,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
315 2.11949E-04, 5.60641E-04,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
316 1.58240E-04, 4.18555E-04,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
317 1.23548E-04, 3.26795E-04,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
318 9.66686E-05, 2.55722E-04,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
319 7.57509E-05, 2.00387E-04,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
320 5.92416E-05, 1.56716E-04,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
321 4.63943E-05, 1.22734E-04,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
322 3.63850E-05, 9.62538E-05
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
323 //-------------------------------------
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
324 };
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
325
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
326 rom const float e1min[2*16] = {
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
327 // Integration constant for 1 minute,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
328 // Ie. 1- 2^(-1/HT)
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
329 //----- N2 --------- e 1min He --------
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
330 1.59104E-01, 3.68109E-01,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
331 8.29960E-02, 2.05084E-01,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
332 5.39424E-02, 1.36579E-01,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
333 3.67742E-02, 9.44046E-02,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
334 2.53454E-02, 6.56359E-02,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
335 1.79351E-02, 4.67416E-02,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
336 1.26840E-02, 3.31991E-02,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
337 8.96152E-03, 2.35301E-02,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
338 6.33897E-03, 1.66832E-02,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
339 4.73633E-03, 1.24808E-02,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
340 3.69981E-03, 9.75753E-03,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
341 2.89600E-03, 7.64329E-03,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
342 2.27003E-03, 5.99417E-03,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
343 1.77572E-03, 4.69082E-03,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
344 1.39089E-03, 3.67548E-03,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
345 1.09097E-03, 2.88359E-03
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
346 //-------------------------------------
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
347 };
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
348
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
349 rom const float e10min[2*16] = {
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
350 // The 10 min Value in float notation:
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
351 // result of 1 - 2^(-10/ht)
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
352 //---- N2 -------------- He -----------
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
353 8.23223E-01, 9.89851E-01,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
354 5.79552E-01, 8.99258E-01,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
355 4.25651E-01, 7.69737E-01,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
356 3.12487E-01, 6.29027E-01,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
357 2.26416E-01, 4.92821E-01,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
358 1.65547E-01, 3.80407E-01,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
359 1.19840E-01, 2.86538E-01,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
360 8.60863E-02, 2.11886E-01,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
361 6.16117E-02, 1.54849E-01,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
362 4.63665E-02, 1.18026E-01,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
363 3.63881E-02, 9.34005E-02,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
364 2.85855E-02, 7.38569E-02,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
365 2.24698E-02, 5.83504E-02,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
366 1.76160E-02, 4.59303E-02,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
367 1.38222E-02, 3.61528E-02,
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
368 1.08563E-02, 2.84646E-02
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
369 //-------------------------------------
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
370 };
0
heinrichsweikamp
parents:
diff changeset
371
heinrichsweikamp
parents:
diff changeset
372 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
373 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
374 ////////////////////////////// THE SUBROUTINES ///////////////////////////////
heinrichsweikamp
parents:
diff changeset
375 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
376 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
377 //
heinrichsweikamp
parents:
diff changeset
378 // all new in v.102
heinrichsweikamp
parents:
diff changeset
379 // moved from 0x0D000 to 0x0C000 in v.108
heinrichsweikamp
parents:
diff changeset
380 #ifndef UNIX
heinrichsweikamp
parents:
diff changeset
381 # pragma code p2_deco = 0x0C000
heinrichsweikamp
parents:
diff changeset
382 #endif
heinrichsweikamp
parents:
diff changeset
383
heinrichsweikamp
parents:
diff changeset
384 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
385 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
386 /////////////////////// U T I L I T I E S /////////////////////////////////
heinrichsweikamp
parents:
diff changeset
387 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
388 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
389
heinrichsweikamp
parents:
diff changeset
390 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
391 // Bump to blue-screen when an assert is wrong
heinrichsweikamp
parents:
diff changeset
392 #ifdef __DEBUG
heinrichsweikamp
parents:
diff changeset
393 void assert_failed(PARAMETER short int line)
heinrichsweikamp
parents:
diff changeset
394 {
heinrichsweikamp
parents:
diff changeset
395 }
heinrichsweikamp
parents:
diff changeset
396 #endif
heinrichsweikamp
parents:
diff changeset
397
heinrichsweikamp
parents:
diff changeset
398 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
399 // When calling C code from ASM context, the data stack pointer and
heinrichsweikamp
parents:
diff changeset
400 // frames should be reset. Bank8 is used by stack
heinrichsweikamp
parents:
diff changeset
401
heinrichsweikamp
parents:
diff changeset
402 #ifdef CROSS_COMPILE
heinrichsweikamp
parents:
diff changeset
403 # define RESET_C_STACK
heinrichsweikamp
parents:
diff changeset
404 #else
heinrichsweikamp
parents:
diff changeset
405 # ifdef __DEBUG
heinrichsweikamp
parents:
diff changeset
406 # define RESET_C_STACK fillDataStack();
heinrichsweikamp
parents:
diff changeset
407 void fillDataStack(void)
heinrichsweikamp
parents:
diff changeset
408 {
heinrichsweikamp
parents:
diff changeset
409 _asm
heinrichsweikamp
parents:
diff changeset
410 LFSR 1,C_STACK
heinrichsweikamp
parents:
diff changeset
411 MOVLW 0xCC
heinrichsweikamp
parents:
diff changeset
412 loop: MOVWF POSTINC1,0
heinrichsweikamp
parents:
diff changeset
413 TSTFSZ FSR1L,0
heinrichsweikamp
parents:
diff changeset
414 BRA loop
heinrichsweikamp
parents:
diff changeset
415
heinrichsweikamp
parents:
diff changeset
416 LFSR 1,C_STACK
heinrichsweikamp
parents:
diff changeset
417 LFSR 2,C_STACK
heinrichsweikamp
parents:
diff changeset
418 _endasm
heinrichsweikamp
parents:
diff changeset
419 }
heinrichsweikamp
parents:
diff changeset
420 # else
heinrichsweikamp
parents:
diff changeset
421 # define RESET_C_STACK \
heinrichsweikamp
parents:
diff changeset
422 _asm \
heinrichsweikamp
parents:
diff changeset
423 LFSR 1, C_STACK \
heinrichsweikamp
parents:
diff changeset
424 LFSR 2, C_STACK \
heinrichsweikamp
parents:
diff changeset
425 _endasm
heinrichsweikamp
parents:
diff changeset
426 # endif
heinrichsweikamp
parents:
diff changeset
427 #endif
heinrichsweikamp
parents:
diff changeset
428
heinrichsweikamp
parents:
diff changeset
429 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
430 // Fast subroutine to read timer 5.
313
0ce5fa241b8e FIX minor comment about deco offset unit...
jDG
parents: 298
diff changeset
431 // Note: result is in 1/32 of msecs (30,51757813 us/bit to be precise)
0
heinrichsweikamp
parents:
diff changeset
432 static unsigned short tmr5(void)
heinrichsweikamp
parents:
diff changeset
433 {
heinrichsweikamp
parents:
diff changeset
434 #ifndef CROSS_COMPILE
heinrichsweikamp
parents:
diff changeset
435 _asm
heinrichsweikamp
parents:
diff changeset
436 movff 0xf7c,PRODL // TMR5L
heinrichsweikamp
parents:
diff changeset
437 movff 0xf7d,PRODH // TMR5H
heinrichsweikamp
parents:
diff changeset
438 _endasm // result in PRODH:PRODL.
heinrichsweikamp
parents:
diff changeset
439 #else
heinrichsweikamp
parents:
diff changeset
440 return 0;
heinrichsweikamp
parents:
diff changeset
441 #endif
heinrichsweikamp
parents:
diff changeset
442 }
heinrichsweikamp
parents:
diff changeset
443
heinrichsweikamp
parents:
diff changeset
444
heinrichsweikamp
parents:
diff changeset
445 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
446 // read buhlmann tables A and B for compatriment ci
heinrichsweikamp
parents:
diff changeset
447 //
heinrichsweikamp
parents:
diff changeset
448 static void read_buhlmann_coefficients(void)
heinrichsweikamp
parents:
diff changeset
449 {
heinrichsweikamp
parents:
diff changeset
450 #ifndef CROSS_COMPILE
heinrichsweikamp
parents:
diff changeset
451 // Note: we don't use far rom pointer, because the
heinrichsweikamp
parents:
diff changeset
452 // 24 bits is too complex, hence we have to set
heinrichsweikamp
parents:
diff changeset
453 // the UPPER page ourself...
heinrichsweikamp
parents:
diff changeset
454 // --> Set zero if tables are moved to lower pages !
heinrichsweikamp
parents:
diff changeset
455 _asm
heinrichsweikamp
parents:
diff changeset
456 movlw 1
heinrichsweikamp
parents:
diff changeset
457 movwf TBLPTRU,0
heinrichsweikamp
parents:
diff changeset
458 _endasm
heinrichsweikamp
parents:
diff changeset
459 #endif
heinrichsweikamp
parents:
diff changeset
460
heinrichsweikamp
parents:
diff changeset
461 assert( ci < NUM_COMP );
heinrichsweikamp
parents:
diff changeset
462
heinrichsweikamp
parents:
diff changeset
463 // Use an interleaved array (AoS) to access coefficients with a
heinrichsweikamp
parents:
diff changeset
464 // single addressing.
heinrichsweikamp
parents:
diff changeset
465 {
heinrichsweikamp
parents:
diff changeset
466 overlay rom const float* ptr = &buhlmann_ab[4*ci];
heinrichsweikamp
parents:
diff changeset
467 var_N2_a = *ptr++;
heinrichsweikamp
parents:
diff changeset
468 var_N2_b = *ptr++;
heinrichsweikamp
parents:
diff changeset
469 var_He_a = *ptr++;
heinrichsweikamp
parents:
diff changeset
470 var_He_b = *ptr++;
heinrichsweikamp
parents:
diff changeset
471 }
heinrichsweikamp
parents:
diff changeset
472 }
heinrichsweikamp
parents:
diff changeset
473
heinrichsweikamp
parents:
diff changeset
474 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
475 // read buhlmann tables for compatriment ci
heinrichsweikamp
parents:
diff changeset
476 // If period == 0 : 2sec interval
heinrichsweikamp
parents:
diff changeset
477 // 1 : 1 min interval
heinrichsweikamp
parents:
diff changeset
478 // 2 : 10 min interval.
heinrichsweikamp
parents:
diff changeset
479 static void read_buhlmann_times(PARAMETER char period)
heinrichsweikamp
parents:
diff changeset
480 {
heinrichsweikamp
parents:
diff changeset
481 #ifndef CROSS_COMPILE
heinrichsweikamp
parents:
diff changeset
482 // Note: we don't use far rom pointer, because the
heinrichsweikamp
parents:
diff changeset
483 // 24 bits is to complex, hence we have to set
heinrichsweikamp
parents:
diff changeset
484 // the UPPER page ourself...
heinrichsweikamp
parents:
diff changeset
485 // --> Set zero if tables are moved to lower pages !
heinrichsweikamp
parents:
diff changeset
486 _asm
heinrichsweikamp
parents:
diff changeset
487 movlw 1
heinrichsweikamp
parents:
diff changeset
488 movwf TBLPTRU,0
heinrichsweikamp
parents:
diff changeset
489 _endasm
heinrichsweikamp
parents:
diff changeset
490 #endif
heinrichsweikamp
parents:
diff changeset
491
heinrichsweikamp
parents:
diff changeset
492 assert( ci < NUM_COMP );
heinrichsweikamp
parents:
diff changeset
493
heinrichsweikamp
parents:
diff changeset
494 // Integration intervals.
heinrichsweikamp
parents:
diff changeset
495 switch(period)
heinrichsweikamp
parents:
diff changeset
496 {
heinrichsweikamp
parents:
diff changeset
497 case 0: //---- 2 sec -----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
498 {
heinrichsweikamp
parents:
diff changeset
499 overlay rom const float* ptr = &e2secs[2*ci];
heinrichsweikamp
parents:
diff changeset
500 var_N2_e = *ptr++;
heinrichsweikamp
parents:
diff changeset
501 var_He_e = *ptr++;
heinrichsweikamp
parents:
diff changeset
502 }
heinrichsweikamp
parents:
diff changeset
503 break;
heinrichsweikamp
parents:
diff changeset
504
heinrichsweikamp
parents:
diff changeset
505 case 1: //---- 1 min -----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
506 {
heinrichsweikamp
parents:
diff changeset
507 overlay rom const float* ptr = &e1min[2*ci];
heinrichsweikamp
parents:
diff changeset
508 var_N2_e = *ptr++;
heinrichsweikamp
parents:
diff changeset
509 var_He_e = *ptr++;
heinrichsweikamp
parents:
diff changeset
510 }
heinrichsweikamp
parents:
diff changeset
511 break;
heinrichsweikamp
parents:
diff changeset
512
heinrichsweikamp
parents:
diff changeset
513 case 2: //---- 10 min ----------------------------------------------------
heinrichsweikamp
parents:
diff changeset
514 {
heinrichsweikamp
parents:
diff changeset
515 overlay rom const float* ptr = &e10min[2*ci];
heinrichsweikamp
parents:
diff changeset
516 var_N2_e = *ptr++;
heinrichsweikamp
parents:
diff changeset
517 var_He_e = *ptr++;
heinrichsweikamp
parents:
diff changeset
518 }
heinrichsweikamp
parents:
diff changeset
519 break;
heinrichsweikamp
parents:
diff changeset
520
heinrichsweikamp
parents:
diff changeset
521 default:
heinrichsweikamp
parents:
diff changeset
522 assert(0); // Never go there...
heinrichsweikamp
parents:
diff changeset
523 }
heinrichsweikamp
parents:
diff changeset
524 }
heinrichsweikamp
parents:
diff changeset
525
heinrichsweikamp
parents:
diff changeset
526 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
527 // read buhlmann tables for compatriment ci
heinrichsweikamp
parents:
diff changeset
528 //
heinrichsweikamp
parents:
diff changeset
529 static void read_buhlmann_ht(void)
heinrichsweikamp
parents:
diff changeset
530 {
heinrichsweikamp
parents:
diff changeset
531
heinrichsweikamp
parents:
diff changeset
532 #ifndef CROSS_COMPILE
heinrichsweikamp
parents:
diff changeset
533 // Note: we don't use far rom pointer, because the
heinrichsweikamp
parents:
diff changeset
534 // 24 bits is to complex, hence we have to set
heinrichsweikamp
parents:
diff changeset
535 // the UPPER page ourself...
heinrichsweikamp
parents:
diff changeset
536 // --> Set zero if tables are moved to lower pages !
heinrichsweikamp
parents:
diff changeset
537 _asm
heinrichsweikamp
parents:
diff changeset
538 movlw 1
heinrichsweikamp
parents:
diff changeset
539 movwf TBLPTRU,0
heinrichsweikamp
parents:
diff changeset
540 _endasm
heinrichsweikamp
parents:
diff changeset
541 #endif
heinrichsweikamp
parents:
diff changeset
542
heinrichsweikamp
parents:
diff changeset
543 assert( ci < NUM_COMP );
heinrichsweikamp
parents:
diff changeset
544 {
heinrichsweikamp
parents:
diff changeset
545 overlay rom const float* ptr = &buhlmann_ht[2*ci];
heinrichsweikamp
parents:
diff changeset
546 var_N2_ht = *ptr++;
heinrichsweikamp
parents:
diff changeset
547 var_He_ht = *ptr++;
heinrichsweikamp
parents:
diff changeset
548 }
heinrichsweikamp
parents:
diff changeset
549
heinrichsweikamp
parents:
diff changeset
550 assert( 4.0 <= var_N2_ht && var_N2_ht <= 635.0 );
heinrichsweikamp
parents:
diff changeset
551 assert( 1.5099 <= var_He_ht && var_He_ht <= 240.03 );
heinrichsweikamp
parents:
diff changeset
552 }
heinrichsweikamp
parents:
diff changeset
553
heinrichsweikamp
parents:
diff changeset
554 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
555 // calc_nextdecodepth
heinrichsweikamp
parents:
diff changeset
556 //
heinrichsweikamp
parents:
diff changeset
557 // new in v.102
heinrichsweikamp
parents:
diff changeset
558 //
heinrichsweikamp
parents:
diff changeset
559 // INPUT, changing during dive:
heinrichsweikamp
parents:
diff changeset
560 // temp_deco
heinrichsweikamp
parents:
diff changeset
561 // low_depth
heinrichsweikamp
parents:
diff changeset
562 //
heinrichsweikamp
parents:
diff changeset
563 // INPUT, fixed during dive:
heinrichsweikamp
parents:
diff changeset
564 // pres_surface
heinrichsweikamp
parents:
diff changeset
565 // GF_delta
heinrichsweikamp
parents:
diff changeset
566 // GF_high
heinrichsweikamp
parents:
diff changeset
567 // GF_low
heinrichsweikamp
parents:
diff changeset
568 // char_I_depth_last_deco
heinrichsweikamp
parents:
diff changeset
569 // float_deco_distance
heinrichsweikamp
parents:
diff changeset
570 //
heinrichsweikamp
parents:
diff changeset
571 // RETURN TRUE iff a stop is needed.
heinrichsweikamp
parents:
diff changeset
572 //
heinrichsweikamp
parents:
diff changeset
573 // OUTPUT
heinrichsweikamp
parents:
diff changeset
574 // locked_GF_step
heinrichsweikamp
parents:
diff changeset
575 // temp_depth_limt
heinrichsweikamp
parents:
diff changeset
576 // low_depth
heinrichsweikamp
parents:
diff changeset
577 //
heinrichsweikamp
parents:
diff changeset
578 static unsigned char calc_nextdecodepth(void)
heinrichsweikamp
parents:
diff changeset
579 {
heinrichsweikamp
parents:
diff changeset
580 //--- Max ascent speed ---------------------------------------------------
heinrichsweikamp
parents:
diff changeset
581 // Recompute leading gas limit, at current depth:
heinrichsweikamp
parents:
diff changeset
582 overlay float depth = (temp_deco - pres_surface) * BAR_TO_METER;
heinrichsweikamp
parents:
diff changeset
583
heinrichsweikamp
parents:
diff changeset
584 // At most, ascent 1 minute, at 10m/min == 10.0 m.
heinrichsweikamp
parents:
diff changeset
585 overlay float min_depth = (depth > 10.0) ? (depth - 10.0) : 0.0;
heinrichsweikamp
parents:
diff changeset
586
heinrichsweikamp
parents:
diff changeset
587 // Do we need to stop at current depth ?
heinrichsweikamp
parents:
diff changeset
588 overlay unsigned char need_stop = 0;
heinrichsweikamp
parents:
diff changeset
589
heinrichsweikamp
parents:
diff changeset
590 assert( depth >= -0.2 ); // Allow for 200mbar of weather change.
heinrichsweikamp
parents:
diff changeset
591
heinrichsweikamp
parents:
diff changeset
592 //---- ZH-L16 + GRADIENT FACTOR model ------------------------------------
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
593 if( char_I_deco_model != 0 )
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
594 {
0
heinrichsweikamp
parents:
diff changeset
595 overlay unsigned char first_stop = 0;
heinrichsweikamp
parents:
diff changeset
596 overlay float p;
heinrichsweikamp
parents:
diff changeset
597
heinrichsweikamp
parents:
diff changeset
598 sim_limit( GF_low );
heinrichsweikamp
parents:
diff changeset
599 p = sim_lead_tissue_limit - pres_surface;
heinrichsweikamp
parents:
diff changeset
600 if( p <= 0.0f )
heinrichsweikamp
parents:
diff changeset
601 goto no_deco_stop; // We can surface directly...
heinrichsweikamp
parents:
diff changeset
602
heinrichsweikamp
parents:
diff changeset
603 p *= BAR_TO_METER;
342
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
604
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
605 // Store the deepest point needing a deco stop as the LOW reference for GF.
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
606 // NOTE: following stops will be validated using this LOW-HIGH gf scale,
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
607 // so if we want to keep coherency, we should not validate this stop
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
608 // yet, but apply the search to it, as for all the following stops afterward.
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
609 if( p > low_depth )
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
610 {
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
611 low_depth = p;
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
612 locked_GF_step = GF_delta / low_depth;
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
613 }
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
614
0
heinrichsweikamp
parents:
diff changeset
615 if( p < min_depth )
heinrichsweikamp
parents:
diff changeset
616 goto no_deco_stop; // First stop is higher than 1' ascent.
heinrichsweikamp
parents:
diff changeset
617
342
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
618 // Round to multiple of 3m.
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
619 first_stop = 3 * (short)(0.9995f + p*0.333333f);
0
heinrichsweikamp
parents:
diff changeset
620 assert( first_stop < 128 );
heinrichsweikamp
parents:
diff changeset
621
heinrichsweikamp
parents:
diff changeset
622 // Apply correction for the shallowest stop.
heinrichsweikamp
parents:
diff changeset
623 if( first_stop == 3 ) // new in v104
heinrichsweikamp
parents:
diff changeset
624 first_stop = char_I_depth_last_deco; // Use last 3m..6m instead.
heinrichsweikamp
parents:
diff changeset
625
heinrichsweikamp
parents:
diff changeset
626 // We have a stop candidate.
heinrichsweikamp
parents:
diff changeset
627 // But maybe ascending to the next stop will diminish the constraint,
heinrichsweikamp
parents:
diff changeset
628 // because the GF might decrease more than the preassure gradient...
heinrichsweikamp
parents:
diff changeset
629 while(first_stop > 0)
heinrichsweikamp
parents:
diff changeset
630 {
heinrichsweikamp
parents:
diff changeset
631 overlay unsigned char next_stop; // Next depth (0..90m)
heinrichsweikamp
parents:
diff changeset
632
heinrichsweikamp
parents:
diff changeset
633 // Check max speed, or reaching surface.
heinrichsweikamp
parents:
diff changeset
634 if( first_stop <= min_depth )
heinrichsweikamp
parents:
diff changeset
635 goto no_deco_stop;
heinrichsweikamp
parents:
diff changeset
636
heinrichsweikamp
parents:
diff changeset
637 if( first_stop <= char_I_depth_last_deco ) // new in v104
heinrichsweikamp
parents:
diff changeset
638 next_stop = 0;
heinrichsweikamp
parents:
diff changeset
639 else if( first_stop == 6 )
heinrichsweikamp
parents:
diff changeset
640 next_stop = char_I_depth_last_deco;
heinrichsweikamp
parents:
diff changeset
641 else
heinrichsweikamp
parents:
diff changeset
642 next_stop = first_stop - 3; // Index of next (upper) stop.
heinrichsweikamp
parents:
diff changeset
643
heinrichsweikamp
parents:
diff changeset
644 // Total preassure at the new stop candidate:
342
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
645 p = next_stop * METER_TO_BAR
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
646 + pres_surface;
0
heinrichsweikamp
parents:
diff changeset
647
342
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
648 // Recompute limit for this new stop:
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
649 if( !low_depth || next_stop > low_depth )
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
650 sim_limit( GF_low );
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
651 else
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
652 sim_limit( GF_high - next_stop * locked_GF_step );
0
heinrichsweikamp
parents:
diff changeset
653
342
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
654 // Check upper limit (lowest ambiant pressure tolerated):
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
655 if( sim_lead_tissue_limit >= p )
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
656 goto deco_stop_found; // Ascent to next_stop forbiden.
0
heinrichsweikamp
parents:
diff changeset
657
heinrichsweikamp
parents:
diff changeset
658 // Else, validate that stop and loop...
heinrichsweikamp
parents:
diff changeset
659 first_stop = next_stop;
heinrichsweikamp
parents:
diff changeset
660 }
heinrichsweikamp
parents:
diff changeset
661
heinrichsweikamp
parents:
diff changeset
662 no_deco_stop:
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
663 temp_depth_limit = min_depth;
0
heinrichsweikamp
parents:
diff changeset
664 goto done;
heinrichsweikamp
parents:
diff changeset
665
342
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
666 deco_stop_found:
0
heinrichsweikamp
parents:
diff changeset
667 // next stop is the last validated depth found, aka first_stop
heinrichsweikamp
parents:
diff changeset
668 need_stop = 1; // Hit.
heinrichsweikamp
parents:
diff changeset
669 temp_depth_limit = first_stop; // Stop depth, in meter.
heinrichsweikamp
parents:
diff changeset
670
heinrichsweikamp
parents:
diff changeset
671 done:
heinrichsweikamp
parents:
diff changeset
672 ;
heinrichsweikamp
parents:
diff changeset
673 }
heinrichsweikamp
parents:
diff changeset
674 else //---- ZH-L16 model -------------------------------------------------
heinrichsweikamp
parents:
diff changeset
675 {
heinrichsweikamp
parents:
diff changeset
676 overlay float pres_gradient;
heinrichsweikamp
parents:
diff changeset
677
heinrichsweikamp
parents:
diff changeset
678 // Original model
heinrichsweikamp
parents:
diff changeset
679 // optimized in v.101
heinrichsweikamp
parents:
diff changeset
680 // char_I_depth_last_deco included in v.101
heinrichsweikamp
parents:
diff changeset
681
heinrichsweikamp
parents:
diff changeset
682 // Compute sim_lead_tissue_limit too, but just once.
heinrichsweikamp
parents:
diff changeset
683 sim_limit(1.0);
heinrichsweikamp
parents:
diff changeset
684
heinrichsweikamp
parents:
diff changeset
685 pres_gradient = sim_lead_tissue_limit - pres_surface;
heinrichsweikamp
parents:
diff changeset
686 if (pres_gradient >= 0)
heinrichsweikamp
parents:
diff changeset
687 {
379
heinrichsweikamp
parents: 351
diff changeset
688 pres_gradient *= BAR_TO_METER/3; // bar --> stop number;
0
heinrichsweikamp
parents:
diff changeset
689 temp_depth_limit = 3 * (short) (pres_gradient + 0.99); // --> metre : depth for deco
heinrichsweikamp
parents:
diff changeset
690 need_stop = 1; // Hit.
heinrichsweikamp
parents:
diff changeset
691
heinrichsweikamp
parents:
diff changeset
692 // Implement last stop at 4m/5m/6m...
heinrichsweikamp
parents:
diff changeset
693 if( temp_depth_limit == 3 )
heinrichsweikamp
parents:
diff changeset
694 temp_depth_limit = char_I_depth_last_deco;
heinrichsweikamp
parents:
diff changeset
695 }
heinrichsweikamp
parents:
diff changeset
696 else
heinrichsweikamp
parents:
diff changeset
697 temp_depth_limit = 0;
heinrichsweikamp
parents:
diff changeset
698 }
heinrichsweikamp
parents:
diff changeset
699
heinrichsweikamp
parents:
diff changeset
700 //---- Check gas change --------------------------------------------------
heinrichsweikamp
parents:
diff changeset
701 need_stop |= gas_switch_deepest(); // Update temp_depth_limit if there is a change,
heinrichsweikamp
parents:
diff changeset
702
heinrichsweikamp
parents:
diff changeset
703 return need_stop;
heinrichsweikamp
parents:
diff changeset
704 }
heinrichsweikamp
parents:
diff changeset
705
heinrichsweikamp
parents:
diff changeset
706 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
707 // copy_deco_table
heinrichsweikamp
parents:
diff changeset
708 //
heinrichsweikamp
parents:
diff changeset
709 // Buffer the stops, once computed, so we can continue to display them
heinrichsweikamp
parents:
diff changeset
710 // while computing the next set.
heinrichsweikamp
parents:
diff changeset
711 //
heinrichsweikamp
parents:
diff changeset
712 static void copy_deco_table(void)
heinrichsweikamp
parents:
diff changeset
713 {
heinrichsweikamp
parents:
diff changeset
714 // Copy depth of the first (deepest) stop, because when reversing
heinrichsweikamp
parents:
diff changeset
715 // order, it will be hard to find...
111
c61b7a4e317c Bugfix: CNS in planner
heinrichsweikamp
parents: 34
diff changeset
716 char_O_first_deco_depth = internal_deco_depth[0];
0
heinrichsweikamp
parents:
diff changeset
717 char_O_first_deco_time = internal_deco_time [0];
heinrichsweikamp
parents:
diff changeset
718
heinrichsweikamp
parents:
diff changeset
719 {
heinrichsweikamp
parents:
diff changeset
720 overlay unsigned char x, y;
heinrichsweikamp
parents:
diff changeset
721
heinrichsweikamp
parents:
diff changeset
722 for(x=0; x<NUM_STOPS; x++)
heinrichsweikamp
parents:
diff changeset
723 {
heinrichsweikamp
parents:
diff changeset
724 char_O_deco_depth[x] = internal_deco_depth[x];
heinrichsweikamp
parents:
diff changeset
725 char_O_deco_time [x] = internal_deco_time [x];
111
c61b7a4e317c Bugfix: CNS in planner
heinrichsweikamp
parents: 34
diff changeset
726 char_O_deco_gas [x] = internal_deco_gas [x];
0
heinrichsweikamp
parents:
diff changeset
727 }
heinrichsweikamp
parents:
diff changeset
728
heinrichsweikamp
parents:
diff changeset
729 //Now fill the char_O_deco_time_for_log array
heinrichsweikamp
parents:
diff changeset
730 //---- First: search the first non-null depth
heinrichsweikamp
parents:
diff changeset
731 for(x=(NUM_STOPS-1); x != 0; --x)
heinrichsweikamp
parents:
diff changeset
732 if( internal_deco_depth[x] != 0 ) break;
heinrichsweikamp
parents:
diff changeset
733
heinrichsweikamp
parents:
diff changeset
734 //---- Second: copy to output table (in reverse order)
heinrichsweikamp
parents:
diff changeset
735 for(y=0; y<NUM_STOPS; y++, --x)
heinrichsweikamp
parents:
diff changeset
736 {
heinrichsweikamp
parents:
diff changeset
737 char_O_deco_time_for_log[y] = internal_deco_time [x];
heinrichsweikamp
parents:
diff changeset
738
heinrichsweikamp
parents:
diff changeset
739 // Stop only once the last transfer is done.
heinrichsweikamp
parents:
diff changeset
740 if( x == 0 ) break;
heinrichsweikamp
parents:
diff changeset
741 }
heinrichsweikamp
parents:
diff changeset
742
heinrichsweikamp
parents:
diff changeset
743 //---- Third: fill table end with null
heinrichsweikamp
parents:
diff changeset
744 for(y++; y<NUM_STOPS; y++)
heinrichsweikamp
parents:
diff changeset
745 {
heinrichsweikamp
parents:
diff changeset
746 char_O_deco_time_for_log [y] = 0;
heinrichsweikamp
parents:
diff changeset
747 }
heinrichsweikamp
parents:
diff changeset
748 }
heinrichsweikamp
parents:
diff changeset
749 }
heinrichsweikamp
parents:
diff changeset
750
heinrichsweikamp
parents:
diff changeset
751 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
752 // temp_tissue_safety //
heinrichsweikamp
parents:
diff changeset
753 //
heinrichsweikamp
parents:
diff changeset
754 // outsourced in v.102
heinrichsweikamp
parents:
diff changeset
755 //
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
756 // Apply safety factors for both ZH-L16 models.
0
heinrichsweikamp
parents:
diff changeset
757 //
heinrichsweikamp
parents:
diff changeset
758 static void temp_tissue_safety(void)
heinrichsweikamp
parents:
diff changeset
759 {
heinrichsweikamp
parents:
diff changeset
760 assert( 0.0 < float_desaturation_multiplier && float_desaturation_multiplier <= 1.0 );
heinrichsweikamp
parents:
diff changeset
761 assert( 1.0 <= float_saturation_multiplier && float_saturation_multiplier <= 2.0 );
heinrichsweikamp
parents:
diff changeset
762
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
763 if( temp_tissue < 0.0 )
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
764 temp_tissue *= float_desaturation_multiplier;
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
765 else
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
766 temp_tissue *= float_saturation_multiplier;
0
heinrichsweikamp
parents:
diff changeset
767 }
heinrichsweikamp
parents:
diff changeset
768
heinrichsweikamp
parents:
diff changeset
769 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
770 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
771 // ** THE JUMP-IN CODE **
heinrichsweikamp
parents:
diff changeset
772 // ** for the asm code **
heinrichsweikamp
parents:
diff changeset
773 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
774 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
775
heinrichsweikamp
parents:
diff changeset
776 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
777 // Called every 2 seconds during diving.
heinrichsweikamp
parents:
diff changeset
778 // update tissues every time.
heinrichsweikamp
parents:
diff changeset
779 //
heinrichsweikamp
parents:
diff changeset
780 // Every 6 seconds (or slower when TTS > 16):
heinrichsweikamp
parents:
diff changeset
781 // - update deco table (char_O_deco_time/depth) with new values.
heinrichsweikamp
parents:
diff changeset
782 // - update ascent time,
heinrichsweikamp
parents:
diff changeset
783 // - set status to zero (so we can check there is new results).
heinrichsweikamp
parents:
diff changeset
784 //
heinrichsweikamp
parents:
diff changeset
785 void deco_calc_hauptroutine(void)
heinrichsweikamp
parents:
diff changeset
786 {
heinrichsweikamp
parents:
diff changeset
787 RESET_C_STACK
heinrichsweikamp
parents:
diff changeset
788 calc_hauptroutine();
heinrichsweikamp
parents:
diff changeset
789 int_O_desaturation_time = 65535;
heinrichsweikamp
parents:
diff changeset
790 }
heinrichsweikamp
parents:
diff changeset
791
heinrichsweikamp
parents:
diff changeset
792 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
793 // Reset decompression model:
heinrichsweikamp
parents:
diff changeset
794 // + Set all tissues to equilibrium with Air at ambient pressure.
heinrichsweikamp
parents:
diff changeset
795 // + Reset last stop to 0m
heinrichsweikamp
parents:
diff changeset
796 // + Reset all model output.
heinrichsweikamp
parents:
diff changeset
797 void deco_clear_tissue(void)
heinrichsweikamp
parents:
diff changeset
798 {
heinrichsweikamp
parents:
diff changeset
799 RESET_C_STACK
heinrichsweikamp
parents:
diff changeset
800 clear_tissue();
heinrichsweikamp
parents:
diff changeset
801 }
heinrichsweikamp
parents:
diff changeset
802
heinrichsweikamp
parents:
diff changeset
803 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
804 // Called every 1 min during decoplanning.
heinrichsweikamp
parents:
diff changeset
805 // Update tissues for 1 min.
heinrichsweikamp
parents:
diff changeset
806 //
heinrichsweikamp
parents:
diff changeset
807 void deco_calc_tissue(void)
heinrichsweikamp
parents:
diff changeset
808 {
heinrichsweikamp
parents:
diff changeset
809 RESET_C_STACK
heinrichsweikamp
parents:
diff changeset
810 calc_hauptroutine_update_tissues();
heinrichsweikamp
parents:
diff changeset
811 }
heinrichsweikamp
parents:
diff changeset
812
heinrichsweikamp
parents:
diff changeset
813 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
814
heinrichsweikamp
parents:
diff changeset
815 void deco_calc_wo_deco_step_1_min(void)
heinrichsweikamp
parents:
diff changeset
816 {
heinrichsweikamp
parents:
diff changeset
817 RESET_C_STACK
heinrichsweikamp
parents:
diff changeset
818 calc_wo_deco_step_1_min();
heinrichsweikamp
parents:
diff changeset
819 deco_calc_desaturation_time();
heinrichsweikamp
parents:
diff changeset
820 }
heinrichsweikamp
parents:
diff changeset
821
heinrichsweikamp
parents:
diff changeset
822 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
823
heinrichsweikamp
parents:
diff changeset
824 void deco_calc_dive_interval(void)
heinrichsweikamp
parents:
diff changeset
825 {
heinrichsweikamp
parents:
diff changeset
826 RESET_C_STACK
heinrichsweikamp
parents:
diff changeset
827 calc_dive_interval();
heinrichsweikamp
parents:
diff changeset
828 }
heinrichsweikamp
parents:
diff changeset
829
heinrichsweikamp
parents:
diff changeset
830 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
831 // Find current gas in the list (if any).
heinrichsweikamp
parents:
diff changeset
832 //
heinrichsweikamp
parents:
diff changeset
833 // Input: char_I_current_gas = 1..6
heinrichsweikamp
parents:
diff changeset
834 //
heinrichsweikamp
parents:
diff changeset
835 // Output: sim_gas_last_depth = 0..5, temp_depth_limit.
heinrichsweikamp
parents:
diff changeset
836 //
heinrichsweikamp
parents:
diff changeset
837 static void gas_switch_find_current(void)
heinrichsweikamp
parents:
diff changeset
838 {
323
19f7dc2b12d6 FIX minor assert: separate diluant list means current gas can go up to 10.
jDG
parents: 322
diff changeset
839 assert( 0 < char_I_current_gas && char_I_current_gas <= (2*NUM_GAS) );
0
heinrichsweikamp
parents:
diff changeset
840
heinrichsweikamp
parents:
diff changeset
841 if( char_I_current_gas <= NUM_GAS ) // Gas1..Gas5
heinrichsweikamp
parents:
diff changeset
842 {
heinrichsweikamp
parents:
diff changeset
843 sim_gas_last_used = char_I_current_gas;
heinrichsweikamp
parents:
diff changeset
844
heinrichsweikamp
parents:
diff changeset
845 // Note: if current is first gas, we must find it, but not set
heinrichsweikamp
parents:
diff changeset
846 // last depth change to surface.
heinrichsweikamp
parents:
diff changeset
847 if( char_I_deco_gas_change[sim_gas_last_used-1] )
heinrichsweikamp
parents:
diff changeset
848 sim_gas_last_depth = char_I_deco_gas_change[sim_gas_last_used-1];
heinrichsweikamp
parents:
diff changeset
849 }
heinrichsweikamp
parents:
diff changeset
850 else
heinrichsweikamp
parents:
diff changeset
851 sim_gas_last_used = 0; // Gas 6 = manual set
heinrichsweikamp
parents:
diff changeset
852 }
heinrichsweikamp
parents:
diff changeset
853
heinrichsweikamp
parents:
diff changeset
854 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
855 // Find deepest available gas.
heinrichsweikamp
parents:
diff changeset
856 //
heinrichsweikamp
parents:
diff changeset
857 // Input: temp_depth_limit,
heinrichsweikamp
parents:
diff changeset
858 // deco_gas_change[]
heinrichsweikamp
parents:
diff changeset
859 // sim_gas_depth_used, sim_dive_mins.
heinrichsweikamp
parents:
diff changeset
860 //
heinrichsweikamp
parents:
diff changeset
861 // RETURNS TRUE if a stop is needed for gas switch.
heinrichsweikamp
parents:
diff changeset
862 //
heinrichsweikamp
parents:
diff changeset
863 // Output: temp_depth_limit, sim_gas_depth_used IFF the is a switch.
heinrichsweikamp
parents:
diff changeset
864 //
heinrichsweikamp
parents:
diff changeset
865 // NOTE: might be called from bottom (when sim_gas_delay and sim_gas_depth_used
heinrichsweikamp
parents:
diff changeset
866 // are null), or during the ascent to make sure we are not passing a
heinrichsweikamp
parents:
diff changeset
867 // stop (in which case both can be already set).
heinrichsweikamp
parents:
diff changeset
868 //
heinrichsweikamp
parents:
diff changeset
869 static unsigned char gas_switch_deepest(void)
heinrichsweikamp
parents:
diff changeset
870 {
heinrichsweikamp
parents:
diff changeset
871 overlay unsigned char switch_deco = 0, switch_last = 0;
heinrichsweikamp
parents:
diff changeset
872
heinrichsweikamp
parents:
diff changeset
873 if (char_I_const_ppO2 == 0)
heinrichsweikamp
parents:
diff changeset
874 {
heinrichsweikamp
parents:
diff changeset
875 overlay unsigned char j;
heinrichsweikamp
parents:
diff changeset
876
heinrichsweikamp
parents:
diff changeset
877 // Loop over all enabled gas, to find the deepest one,
heinrichsweikamp
parents:
diff changeset
878 // above last used gas, but below temp_depth_limit.
heinrichsweikamp
parents:
diff changeset
879 for(j=0; j<NUM_GAS; ++j)
heinrichsweikamp
parents:
diff changeset
880 {
heinrichsweikamp
parents:
diff changeset
881 // Gas not (yet) allowed ? Skip !
heinrichsweikamp
parents:
diff changeset
882 if( temp_depth_limit > deco_gas_change[j] )
heinrichsweikamp
parents:
diff changeset
883 continue;
heinrichsweikamp
parents:
diff changeset
884
heinrichsweikamp
parents:
diff changeset
885 // Gas deeper (or equal) than the current one ? Skip !
heinrichsweikamp
parents:
diff changeset
886 if( sim_gas_last_depth && deco_gas_change[j] >= sim_gas_last_depth )
heinrichsweikamp
parents:
diff changeset
887 continue;
heinrichsweikamp
parents:
diff changeset
888
heinrichsweikamp
parents:
diff changeset
889 // First, or deeper ?
heinrichsweikamp
parents:
diff changeset
890 if( switch_deco < deco_gas_change[j] )
heinrichsweikamp
parents:
diff changeset
891 {
heinrichsweikamp
parents:
diff changeset
892 switch_deco = deco_gas_change[j];
heinrichsweikamp
parents:
diff changeset
893 switch_last = j+1; // 1..5
heinrichsweikamp
parents:
diff changeset
894 }
heinrichsweikamp
parents:
diff changeset
895 }
heinrichsweikamp
parents:
diff changeset
896 }
heinrichsweikamp
parents:
diff changeset
897
heinrichsweikamp
parents:
diff changeset
898 // If there is a better gas available
heinrichsweikamp
parents:
diff changeset
899 if( switch_deco )
heinrichsweikamp
parents:
diff changeset
900 {
heinrichsweikamp
parents:
diff changeset
901 assert( !sim_gas_last_depth || sim_gas_last_depth > switch_deco );
heinrichsweikamp
parents:
diff changeset
902
heinrichsweikamp
parents:
diff changeset
903 sim_gas_last_depth = switch_deco;
heinrichsweikamp
parents:
diff changeset
904 sim_gas_last_used = switch_last;
heinrichsweikamp
parents:
diff changeset
905 }
heinrichsweikamp
parents:
diff changeset
906 return 0;
heinrichsweikamp
parents:
diff changeset
907 }
heinrichsweikamp
parents:
diff changeset
908
heinrichsweikamp
parents:
diff changeset
909 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
910 // Calculate gas switches
heinrichsweikamp
parents:
diff changeset
911 //
heinrichsweikamp
parents:
diff changeset
912 //
heinrichsweikamp
parents:
diff changeset
913 // Input: N2_ratio, He_ratio.
heinrichsweikamp
parents:
diff changeset
914 // sim_gas_last_used
heinrichsweikamp
parents:
diff changeset
915 //
heinrichsweikamp
parents:
diff changeset
916 // Output: calc_N2_ratio, calc_He_ratio
heinrichsweikamp
parents:
diff changeset
917 //
heinrichsweikamp
parents:
diff changeset
918 static void gas_switch_set(void)
heinrichsweikamp
parents:
diff changeset
919 {
heinrichsweikamp
parents:
diff changeset
920 assert( sim_gas_last_used <= NUM_GAS );
heinrichsweikamp
parents:
diff changeset
921
heinrichsweikamp
parents:
diff changeset
922 if( sim_gas_last_used == 0 ) // Gas6 = manualy set gas.
heinrichsweikamp
parents:
diff changeset
923 {
heinrichsweikamp
parents:
diff changeset
924 calc_N2_ratio = N2_ratio;
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
925 calc_He_ratio = He_ratio;
0
heinrichsweikamp
parents:
diff changeset
926 }
heinrichsweikamp
parents:
diff changeset
927 else
heinrichsweikamp
parents:
diff changeset
928 {
heinrichsweikamp
parents:
diff changeset
929 calc_N2_ratio = char_I_deco_N2_ratio[sim_gas_last_used-1] * 0.01;
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
930 calc_He_ratio = char_I_deco_He_ratio[sim_gas_last_used-1] * 0.01;
0
heinrichsweikamp
parents:
diff changeset
931 }
heinrichsweikamp
parents:
diff changeset
932
heinrichsweikamp
parents:
diff changeset
933 assert( 0.0 <= calc_N2_ratio && calc_N2_ratio <= 0.95 );
114
109df032cc54 minor fix: assert should pass for pure helium diluant
heinrichsweikamp
parents: 111
diff changeset
934 assert( 0.0 <= calc_He_ratio && calc_He_ratio <= 1.00 );
0
heinrichsweikamp
parents:
diff changeset
935 assert( (calc_N2_ratio + calc_He_ratio) <= 1.00 );
heinrichsweikamp
parents:
diff changeset
936 }
heinrichsweikamp
parents:
diff changeset
937
heinrichsweikamp
parents:
diff changeset
938 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
939 //
heinrichsweikamp
parents:
diff changeset
940 // Input: calc_N2_ratio, calc_He_ratio : simulated gas mix.
heinrichsweikamp
parents:
diff changeset
941 // temp_deco : simulated respiration pressure
heinrichsweikamp
parents:
diff changeset
942 // float_deco_distance : security factor.
heinrichsweikamp
parents:
diff changeset
943 // Water-vapor pressure inside limbs (ppWater).
heinrichsweikamp
parents:
diff changeset
944 //
heinrichsweikamp
parents:
diff changeset
945 // Output: ppN2, ppHe.
heinrichsweikamp
parents:
diff changeset
946 //
heinrichsweikamp
parents:
diff changeset
947 static void sim_alveolar_presures(void)
heinrichsweikamp
parents:
diff changeset
948 {
heinrichsweikamp
parents:
diff changeset
949 overlay float deco_diluent = temp_deco; // new in v.101
heinrichsweikamp
parents:
diff changeset
950
heinrichsweikamp
parents:
diff changeset
951 // Take deco offset into account, but not at surface.
heinrichsweikamp
parents:
diff changeset
952 // Note: this should be done on ambiant pressure, hence before
heinrichsweikamp
parents:
diff changeset
953 // computing the diluant partial pressure...
heinrichsweikamp
parents:
diff changeset
954 if( deco_diluent > pres_surface )
heinrichsweikamp
parents:
diff changeset
955 deco_diluent += float_deco_distance;
heinrichsweikamp
parents:
diff changeset
956
heinrichsweikamp
parents:
diff changeset
957 //---- CCR mode : deco gas switch ? --------------------------------------
heinrichsweikamp
parents:
diff changeset
958 if( char_I_const_ppO2 != 0 )
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
959 {
0
heinrichsweikamp
parents:
diff changeset
960 // In CCR mode, use calc_XX_ratio instead of XX_ratio.
heinrichsweikamp
parents:
diff changeset
961 // Note: PPO2 and ratios are known outside the lumbs, so there is no
heinrichsweikamp
parents:
diff changeset
962 // ppWater in the equations below:
heinrichsweikamp
parents:
diff changeset
963 deco_diluent -= const_ppO2;
527
015b7fdd90a7 BUGFIX: O2 as diluent in CCR caused wrong calculations (Deco, EAD, END) in less then 6m depth
heinrichsweikamp
parents: 522
diff changeset
964 deco_diluent /= calc_N2_ratio + calc_He_ratio;// potential DIV/0 issue when O2 is used as diluent!
015b7fdd90a7 BUGFIX: O2 as diluent in CCR caused wrong calculations (Deco, EAD, END) in less then 6m depth
heinrichsweikamp
parents: 522
diff changeset
965
015b7fdd90a7 BUGFIX: O2 as diluent in CCR caused wrong calculations (Deco, EAD, END) in less then 6m depth
heinrichsweikamp
parents: 522
diff changeset
966 if(calc_N2_ratio==0&calc_He_ratio==0) deco_diluent = 0.0; // workaround for potential DIV/0 issue
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
967 }
0
heinrichsweikamp
parents:
diff changeset
968
heinrichsweikamp
parents:
diff changeset
969 if( deco_diluent > ppWater )
heinrichsweikamp
parents:
diff changeset
970 {
heinrichsweikamp
parents:
diff changeset
971 ppN2 = calc_N2_ratio * (deco_diluent - ppWater);
heinrichsweikamp
parents:
diff changeset
972 ppHe = calc_He_ratio * (deco_diluent - ppWater);
heinrichsweikamp
parents:
diff changeset
973 }
heinrichsweikamp
parents:
diff changeset
974 else
heinrichsweikamp
parents:
diff changeset
975 {
heinrichsweikamp
parents:
diff changeset
976 ppN2 = 0.0;
heinrichsweikamp
parents:
diff changeset
977 ppHe = 0.0;
heinrichsweikamp
parents:
diff changeset
978 }
heinrichsweikamp
parents:
diff changeset
979 assert( 0.0 <= ppN2 && ppN2 < 14.0 );
heinrichsweikamp
parents:
diff changeset
980 assert( 0.0 <= ppHe && ppHe < 14.0 );
heinrichsweikamp
parents:
diff changeset
981 }
heinrichsweikamp
parents:
diff changeset
982
heinrichsweikamp
parents:
diff changeset
983 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
984 // clear_tissue
heinrichsweikamp
parents:
diff changeset
985 //
heinrichsweikamp
parents:
diff changeset
986 // optimized in v.101 (var_N2_a)
heinrichsweikamp
parents:
diff changeset
987 //
heinrichsweikamp
parents:
diff changeset
988 // preload tissues with standard pressure for the given ambient pressure.
heinrichsweikamp
parents:
diff changeset
989 // Note: fixed N2_ratio for standard air.
heinrichsweikamp
parents:
diff changeset
990 //
heinrichsweikamp
parents:
diff changeset
991 static void clear_tissue(void)
heinrichsweikamp
parents:
diff changeset
992 {
heinrichsweikamp
parents:
diff changeset
993 overlay float p;
heinrichsweikamp
parents:
diff changeset
994
heinrichsweikamp
parents:
diff changeset
995 // Kludge: the 0.0002 of 0.7902 are missing with standard air.
heinrichsweikamp
parents:
diff changeset
996 N2_ratio = 0.7902;
heinrichsweikamp
parents:
diff changeset
997 pres_respiration = int_I_pres_respiration * 0.001;
heinrichsweikamp
parents:
diff changeset
998
heinrichsweikamp
parents:
diff changeset
999 p = N2_ratio * (pres_respiration - ppWater);
heinrichsweikamp
parents:
diff changeset
1000 for(ci=0; ci<NUM_COMP; ci++)
heinrichsweikamp
parents:
diff changeset
1001 {
313
0ce5fa241b8e FIX minor comment about deco offset unit...
jDG
parents: 298
diff changeset
1002 // cycle through the 16 Buhlmann N2 tissues
0
heinrichsweikamp
parents:
diff changeset
1003 pres_tissue_N2[ci] = p;
heinrichsweikamp
parents:
diff changeset
1004
313
0ce5fa241b8e FIX minor comment about deco offset unit...
jDG
parents: 298
diff changeset
1005 // cycle through the 16 Buhlmann tissues for Helium
0
heinrichsweikamp
parents:
diff changeset
1006 pres_tissue_He[ci] = 0.0;
heinrichsweikamp
parents:
diff changeset
1007 }
heinrichsweikamp
parents:
diff changeset
1008
heinrichsweikamp
parents:
diff changeset
1009 clear_deco_table();
heinrichsweikamp
parents:
diff changeset
1010 char_O_deco_status = 0;
heinrichsweikamp
parents:
diff changeset
1011 char_O_nullzeit = 0;
heinrichsweikamp
parents:
diff changeset
1012 int_O_ascenttime = 0;
heinrichsweikamp
parents:
diff changeset
1013 char_O_gradient_factor = 0;
heinrichsweikamp
parents:
diff changeset
1014
heinrichsweikamp
parents:
diff changeset
1015 calc_lead_tissue_limit = 0.0;
heinrichsweikamp
parents:
diff changeset
1016 char_O_gtissue_no = 0;
heinrichsweikamp
parents:
diff changeset
1017 }
heinrichsweikamp
parents:
diff changeset
1018
heinrichsweikamp
parents:
diff changeset
1019 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1020 // calc_hauptroutine
heinrichsweikamp
parents:
diff changeset
1021 //
heinrichsweikamp
parents:
diff changeset
1022 // this is the major code in dive mode calculates:
heinrichsweikamp
parents:
diff changeset
1023 // the tissues,
heinrichsweikamp
parents:
diff changeset
1024 // the bottom time,
heinrichsweikamp
parents:
diff changeset
1025 // and simulates the ascend with all deco stops.
heinrichsweikamp
parents:
diff changeset
1026 //
heinrichsweikamp
parents:
diff changeset
1027 // The deco_state sequence is :
heinrichsweikamp
parents:
diff changeset
1028 // 3 (at surface)
heinrichsweikamp
parents:
diff changeset
1029 // +---> 0 : calc nullzeit
heinrichsweikamp
parents:
diff changeset
1030 // | 2 : simulate ascent to first stop (at 10m/min, less that 16x 1min simu)
heinrichsweikamp
parents:
diff changeset
1031 // | +-> 1 : simulate up to 16min of stops.
heinrichsweikamp
parents:
diff changeset
1032 // | +------< not finished
heinrichsweikamp
parents:
diff changeset
1033 // +--------< finish
heinrichsweikamp
parents:
diff changeset
1034 //
heinrichsweikamp
parents:
diff changeset
1035 // Added steps 6,5 for @+5 calculation:
heinrichsweikamp
parents:
diff changeset
1036 // 6 = ascent to first stop (same as 2), except continue to 7
heinrichsweikamp
parents:
diff changeset
1037 // 7 = same as 1, except loop to 7.
heinrichsweikamp
parents:
diff changeset
1038 //
heinrichsweikamp
parents:
diff changeset
1039 static void calc_hauptroutine(void)
heinrichsweikamp
parents:
diff changeset
1040 {
342
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
1041 static unsigned char backup_gas_used = 0;
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
1042 static unsigned char backup_gas_depth = 0;
0
heinrichsweikamp
parents:
diff changeset
1043
heinrichsweikamp
parents:
diff changeset
1044 calc_hauptroutine_data_input();
heinrichsweikamp
parents:
diff changeset
1045
heinrichsweikamp
parents:
diff changeset
1046 calc_hauptroutine_update_tissues();
heinrichsweikamp
parents:
diff changeset
1047 calc_gradient_factor();
heinrichsweikamp
parents:
diff changeset
1048
heinrichsweikamp
parents:
diff changeset
1049 // toggle between calculation for nullzeit (bottom time),
heinrichsweikamp
parents:
diff changeset
1050 // deco stops
heinrichsweikamp
parents:
diff changeset
1051 // and more deco stops (continue)
heinrichsweikamp
parents:
diff changeset
1052 switch( char_O_deco_status )
heinrichsweikamp
parents:
diff changeset
1053 {
heinrichsweikamp
parents:
diff changeset
1054 case 3: //---- At surface: start a new dive ------------------------------
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1055 clear_deco_table();
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1056 copy_deco_table();
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1057 int_O_ascenttime = 0; // Reset DTR.
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1058 int_O_extra_ascenttime = 0;
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1059 char_O_nullzeit = 0; // Reset bottom time.
0
heinrichsweikamp
parents:
diff changeset
1060 char_O_deco_status = 0; // Calc bottom-time/nullzeit next iteration.
heinrichsweikamp
parents:
diff changeset
1061
heinrichsweikamp
parents:
diff changeset
1062 // Values that should be reset just once for the full real dive.
heinrichsweikamp
parents:
diff changeset
1063 // This is used to record the lowest stop for the whole dive,
heinrichsweikamp
parents:
diff changeset
1064 // Including ACCROSS all simulated ascent.
342
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
1065 low_depth = 0.0;
0
heinrichsweikamp
parents:
diff changeset
1066 locked_GF_step = 0.0;
heinrichsweikamp
parents:
diff changeset
1067
heinrichsweikamp
parents:
diff changeset
1068 // Reset gas switch history.
heinrichsweikamp
parents:
diff changeset
1069 backup_gas_used = sim_gas_last_used = 0;
heinrichsweikamp
parents:
diff changeset
1070 backup_gas_depth = sim_gas_last_depth = 0;
heinrichsweikamp
parents:
diff changeset
1071 sim_dive_mins = 0;
heinrichsweikamp
parents:
diff changeset
1072 break;
heinrichsweikamp
parents:
diff changeset
1073
heinrichsweikamp
parents:
diff changeset
1074 case 0: //---- bottom time -----------------------------------------------
heinrichsweikamp
parents:
diff changeset
1075 default:
heinrichsweikamp
parents:
diff changeset
1076 gas_switch_find_current(); // Lookup for current gas & time.
heinrichsweikamp
parents:
diff changeset
1077 gas_switch_set(); // setup calc_ratio's
heinrichsweikamp
parents:
diff changeset
1078
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1079 calc_nullzeit();
0
heinrichsweikamp
parents:
diff changeset
1080 if( char_O_nullzeit > 0 ) // Some NDL time left ?
heinrichsweikamp
parents:
diff changeset
1081 {
heinrichsweikamp
parents:
diff changeset
1082 char_O_deco_status = 0; // YES: recalc ndl next time.
heinrichsweikamp
parents:
diff changeset
1083 clear_deco_table(); // Also clear stops !
heinrichsweikamp
parents:
diff changeset
1084 copy_deco_table();
heinrichsweikamp
parents:
diff changeset
1085 char_O_deco_last_stop = 0; // And last stop (OSTC menu anim)
heinrichsweikamp
parents:
diff changeset
1086 }
heinrichsweikamp
parents:
diff changeset
1087 else
heinrichsweikamp
parents:
diff changeset
1088 char_O_deco_status = 2; // NO: calc ascent next time.
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1089 break;
0
heinrichsweikamp
parents:
diff changeset
1090
heinrichsweikamp
parents:
diff changeset
1091 case 2: //---- Simulate ascent to first stop -----------------------------
heinrichsweikamp
parents:
diff changeset
1092 case 6: // @+5min variation
heinrichsweikamp
parents:
diff changeset
1093 // Check proposed gas at begin of ascent simulation
heinrichsweikamp
parents:
diff changeset
1094 sim_dive_mins = int_I_divemins; // Init current time.
heinrichsweikamp
parents:
diff changeset
1095
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1096 gas_switch_find_current(); // Lookup for current gas & time.
0
heinrichsweikamp
parents:
diff changeset
1097 gas_switch_set(); // setup calc_ratio's
heinrichsweikamp
parents:
diff changeset
1098
heinrichsweikamp
parents:
diff changeset
1099 backup_gas_used = sim_gas_last_used; // And save for later simu steps.
heinrichsweikamp
parents:
diff changeset
1100 backup_gas_depth = sim_gas_last_depth; // And save for later simu steps.
heinrichsweikamp
parents:
diff changeset
1101
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1102 sim_ascent_to_first_stop();
0
heinrichsweikamp
parents:
diff changeset
1103
heinrichsweikamp
parents:
diff changeset
1104 // Calc stops next time (deco or gas switch).
heinrichsweikamp
parents:
diff changeset
1105 char_O_deco_status = 1 | ( char_O_deco_status & 4 );
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1106 break;
0
heinrichsweikamp
parents:
diff changeset
1107
heinrichsweikamp
parents:
diff changeset
1108 case 1: //---- Simulate stops --------------------------------------------
heinrichsweikamp
parents:
diff changeset
1109 case 5: // @+5 variation.
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1110 calc_hauptroutine_calc_deco();
0
heinrichsweikamp
parents:
diff changeset
1111
heinrichsweikamp
parents:
diff changeset
1112 // If simulation is finished, restore the GF low reference, so that
heinrichsweikamp
parents:
diff changeset
1113 // next ascent simulation is done from the current depth:
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1114 if( (char_O_deco_status & 3) == 0 )
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1115 {
0
heinrichsweikamp
parents:
diff changeset
1116 sim_gas_last_used = backup_gas_used;
heinrichsweikamp
parents:
diff changeset
1117 sim_gas_last_depth = backup_gas_depth;
heinrichsweikamp
parents:
diff changeset
1118 }
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1119 break;
0
heinrichsweikamp
parents:
diff changeset
1120 }
heinrichsweikamp
parents:
diff changeset
1121 }
heinrichsweikamp
parents:
diff changeset
1122
heinrichsweikamp
parents:
diff changeset
1123 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1124 // calc_hauptroutine_data_input
heinrichsweikamp
parents:
diff changeset
1125 //
heinrichsweikamp
parents:
diff changeset
1126 // Reset all C-code dive parameters from their ASM-code values.
heinrichsweikamp
parents:
diff changeset
1127 // Detect gas change condition.
heinrichsweikamp
parents:
diff changeset
1128 //
heinrichsweikamp
parents:
diff changeset
1129 void calc_hauptroutine_data_input(void)
heinrichsweikamp
parents:
diff changeset
1130 {
heinrichsweikamp
parents:
diff changeset
1131 overlay short int_temp;
heinrichsweikamp
parents:
diff changeset
1132 overlay unsigned char g;
heinrichsweikamp
parents:
diff changeset
1133
heinrichsweikamp
parents:
diff changeset
1134 pres_respiration = int_I_pres_respiration * 0.001;
heinrichsweikamp
parents:
diff changeset
1135 pres_surface = int_I_pres_surface * 0.001;
heinrichsweikamp
parents:
diff changeset
1136 N2_ratio = char_I_N2_ratio * 0.01;
heinrichsweikamp
parents:
diff changeset
1137 He_ratio = char_I_He_ratio * 0.01;
379
heinrichsweikamp
parents: 351
diff changeset
1138 float_deco_distance = char_I_deco_distance * 0.01; // Get offset in mbar
0
heinrichsweikamp
parents:
diff changeset
1139
heinrichsweikamp
parents:
diff changeset
1140 // ____________________________________________________
heinrichsweikamp
parents:
diff changeset
1141 //
heinrichsweikamp
parents:
diff changeset
1142 // _____________ G A S _ C H A N G E S ________________
heinrichsweikamp
parents:
diff changeset
1143 // ____________________________________________________
heinrichsweikamp
parents:
diff changeset
1144
heinrichsweikamp
parents:
diff changeset
1145 // Keep a margin of 150mbar = 1.50m
heinrichsweikamp
parents:
diff changeset
1146 int_temp = (int_I_pres_respiration - int_I_pres_surface)
heinrichsweikamp
parents:
diff changeset
1147 + MBAR_REACH_GASCHANGE_AUTO_CHANGE_OFF;
heinrichsweikamp
parents:
diff changeset
1148
heinrichsweikamp
parents:
diff changeset
1149 // Gas are selectable if we did not pass the change depth by more than 1.50m:
heinrichsweikamp
parents:
diff changeset
1150 for(g=0; g < NUM_GAS; ++g)
heinrichsweikamp
parents:
diff changeset
1151 {
heinrichsweikamp
parents:
diff changeset
1152 deco_gas_change[g] = 0;
heinrichsweikamp
parents:
diff changeset
1153 if(char_I_deco_gas_change[g])
heinrichsweikamp
parents:
diff changeset
1154 if( int_temp > 100 *(short)char_I_deco_gas_change[g] )
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1155 deco_gas_change[g] = char_I_deco_gas_change[g];
0
heinrichsweikamp
parents:
diff changeset
1156 }
heinrichsweikamp
parents:
diff changeset
1157
heinrichsweikamp
parents:
diff changeset
1158 const_ppO2 = char_I_const_ppO2 * 0.01;
heinrichsweikamp
parents:
diff changeset
1159 float_desaturation_multiplier = char_I_desaturation_multiplier * 0.01;
heinrichsweikamp
parents:
diff changeset
1160 float_saturation_multiplier = char_I_saturation_multiplier * 0.01;
heinrichsweikamp
parents:
diff changeset
1161 GF_low = char_I_GF_Low_percentage * 0.01;
heinrichsweikamp
parents:
diff changeset
1162 GF_high = char_I_GF_High_percentage * 0.01;
heinrichsweikamp
parents:
diff changeset
1163 GF_delta = GF_high - GF_low;
heinrichsweikamp
parents:
diff changeset
1164 }
heinrichsweikamp
parents:
diff changeset
1165
heinrichsweikamp
parents:
diff changeset
1166 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1167 //
heinrichsweikamp
parents:
diff changeset
1168 //
heinrichsweikamp
parents:
diff changeset
1169 void calc_hauptroutine_update_tissues(void)
heinrichsweikamp
parents:
diff changeset
1170 {
heinrichsweikamp
parents:
diff changeset
1171 assert( 0.00 <= N2_ratio && N2_ratio <= 1.00 );
heinrichsweikamp
parents:
diff changeset
1172 assert( 0.00 <= He_ratio && He_ratio <= 1.00 );
114
109df032cc54 minor fix: assert should pass for pure helium diluant
heinrichsweikamp
parents: 111
diff changeset
1173 assert( (N2_ratio + He_ratio) <= 1.00 );
0
heinrichsweikamp
parents:
diff changeset
1174 assert( 0.800 < pres_respiration && pres_respiration < 14.0 );
heinrichsweikamp
parents:
diff changeset
1175
heinrichsweikamp
parents:
diff changeset
1176 pres_diluent = pres_respiration;
heinrichsweikamp
parents:
diff changeset
1177 if( char_I_const_ppO2 != 0 )
heinrichsweikamp
parents:
diff changeset
1178 {
heinrichsweikamp
parents:
diff changeset
1179 overlay float flush_ppO2 = pres_respiration * (1.0 - N2_ratio - He_ratio);
heinrichsweikamp
parents:
diff changeset
1180
heinrichsweikamp
parents:
diff changeset
1181 pres_diluent -= const_ppO2;
527
015b7fdd90a7 BUGFIX: O2 as diluent in CCR caused wrong calculations (Deco, EAD, END) in less then 6m depth
heinrichsweikamp
parents: 522
diff changeset
1182 pres_diluent /= N2_ratio + He_ratio; // potential DIV/0 issue when O2 is used as diluent!
0
heinrichsweikamp
parents:
diff changeset
1183 if( pres_diluent < 0.0 )
heinrichsweikamp
parents:
diff changeset
1184 pres_diluent = 0.0;
527
015b7fdd90a7 BUGFIX: O2 as diluent in CCR caused wrong calculations (Deco, EAD, END) in less then 6m depth
heinrichsweikamp
parents: 522
diff changeset
1185 if(N2_ratio==0&He_ratio==0) pres_diluent = 0.0; // workaround for potential DIV/0 issue
0
heinrichsweikamp
parents:
diff changeset
1186
heinrichsweikamp
parents:
diff changeset
1187 char_O_diluent = (unsigned char)(pres_diluent/pres_respiration*100.0 + 0.5);
heinrichsweikamp
parents:
diff changeset
1188
heinrichsweikamp
parents:
diff changeset
1189 if( flush_ppO2 > 2.545) flush_ppO2 = 2.55;
heinrichsweikamp
parents:
diff changeset
1190 if( flush_ppO2 < 0.0 ) flush_ppO2 = 0.0;
heinrichsweikamp
parents:
diff changeset
1191 char_O_flush_ppO2 = (unsigned char)(flush_ppO2*100.0 + 0.5);
heinrichsweikamp
parents:
diff changeset
1192 }
heinrichsweikamp
parents:
diff changeset
1193
heinrichsweikamp
parents:
diff changeset
1194 if( pres_diluent > ppWater )
heinrichsweikamp
parents:
diff changeset
1195 {
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1196 overlay float EAD, END;
0
heinrichsweikamp
parents:
diff changeset
1197
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1198 ppN2 = N2_ratio * (pres_diluent - ppWater);
0
heinrichsweikamp
parents:
diff changeset
1199 ppHe = He_ratio * (pres_diluent - ppWater);
heinrichsweikamp
parents:
diff changeset
1200
heinrichsweikamp
parents:
diff changeset
1201 // EAD : Equivalent Air Dive. Equivalent depth for the same N2 level
heinrichsweikamp
parents:
diff changeset
1202 // with plain air.
heinrichsweikamp
parents:
diff changeset
1203 // ppN2 = 79% * (P_EAD - ppWater)
heinrichsweikamp
parents:
diff changeset
1204 // EAD = (P_EAD - Psurface) * 10
heinrichsweikamp
parents:
diff changeset
1205 // ie: EAD = (ppN2 / 0.7902 + ppWater -Psurface) * 10
heinrichsweikamp
parents:
diff changeset
1206 EAD = (ppN2 / 0.7902 + ppWater - pres_surface) * BAR_TO_METER;
heinrichsweikamp
parents:
diff changeset
1207 if( EAD < 0.0 || EAD > 245.5 ) EAD = 0.0;
heinrichsweikamp
parents:
diff changeset
1208 char_O_EAD = (unsigned char)(EAD + 0.5);
heinrichsweikamp
parents:
diff changeset
1209
heinrichsweikamp
parents:
diff changeset
1210 // END : Equivalent Narcotic Dive.
heinrichsweikamp
parents:
diff changeset
1211 // Here we count O2 as narcotic too. Hence everything but helium (has a narcosis factor of
heinrichsweikamp
parents:
diff changeset
1212 // 0.23 btw). Hence the formula becomes:
heinrichsweikamp
parents:
diff changeset
1213 // END * BarPerMeter * (1.0 - 0.0) - ppWater + Psurface == Pambient - ppHe - ppWater
heinrichsweikamp
parents:
diff changeset
1214 // ie: END = (Pambient - ppHe - Psurface) * BAR_TO_METER
heinrichsweikamp
parents:
diff changeset
1215 //
heinrichsweikamp
parents:
diff changeset
1216 // Source cited:
heinrichsweikamp
parents:
diff changeset
1217 // The Physiology and Medicine of Diving by Peter Bennett and David Elliott,
heinrichsweikamp
parents:
diff changeset
1218 // 4th edition, 1993, W.B.Saunders Company Ltd, London.
heinrichsweikamp
parents:
diff changeset
1219 END = (pres_respiration - ppHe - pres_surface) * BAR_TO_METER;
heinrichsweikamp
parents:
diff changeset
1220 if( END < 0.0 || END > 245.5 ) END = 0.0;
heinrichsweikamp
parents:
diff changeset
1221 char_O_END = (unsigned char)(END + 0.5);
heinrichsweikamp
parents:
diff changeset
1222 }
heinrichsweikamp
parents:
diff changeset
1223 else // new in v.101
heinrichsweikamp
parents:
diff changeset
1224 {
heinrichsweikamp
parents:
diff changeset
1225 ppN2 = 0.0;
heinrichsweikamp
parents:
diff changeset
1226 ppHe = 0.0;
heinrichsweikamp
parents:
diff changeset
1227 char_O_EAD = char_O_END = 0;
heinrichsweikamp
parents:
diff changeset
1228 }
heinrichsweikamp
parents:
diff changeset
1229
heinrichsweikamp
parents:
diff changeset
1230 if(!char_I_step_is_1min)
heinrichsweikamp
parents:
diff changeset
1231 calc_tissue(0);
heinrichsweikamp
parents:
diff changeset
1232 else
heinrichsweikamp
parents:
diff changeset
1233 calc_tissue(1);
heinrichsweikamp
parents:
diff changeset
1234
heinrichsweikamp
parents:
diff changeset
1235 // Calc limit for surface, ie. GF_high.
heinrichsweikamp
parents:
diff changeset
1236 calc_limit();
heinrichsweikamp
parents:
diff changeset
1237
126
9e856337b225 fix depth<0m display, ceiling
heinrichsweikamp
parents: 123
diff changeset
1238 // Fill int_O_ceiling if ceiling is below the surface
9e856337b225 fix depth<0m display, ceiling
heinrichsweikamp
parents: 123
diff changeset
1239 if ((calc_lead_tissue_limit-pres_surface)>0)
9e856337b225 fix depth<0m display, ceiling
heinrichsweikamp
parents: 123
diff changeset
1240 int_O_ceiling = (short)((calc_lead_tissue_limit-pres_surface)*1000);
9e856337b225 fix depth<0m display, ceiling
heinrichsweikamp
parents: 123
diff changeset
1241 else
9e856337b225 fix depth<0m display, ceiling
heinrichsweikamp
parents: 123
diff changeset
1242 int_O_ceiling = 0;
9e856337b225 fix depth<0m display, ceiling
heinrichsweikamp
parents: 123
diff changeset
1243
0
heinrichsweikamp
parents:
diff changeset
1244 int_O_gtissue_press = (short)((pres_tissue_N2[char_O_gtissue_no] + pres_tissue_He[char_O_gtissue_no]) * 1000);
heinrichsweikamp
parents:
diff changeset
1245 }
heinrichsweikamp
parents:
diff changeset
1246
heinrichsweikamp
parents:
diff changeset
1247
heinrichsweikamp
parents:
diff changeset
1248 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1249 // Compute stops.
heinrichsweikamp
parents:
diff changeset
1250 //
heinrichsweikamp
parents:
diff changeset
1251 // Note: because this can be very long, break on 16 iterations, and set state
heinrichsweikamp
parents:
diff changeset
1252 // to 0 when finished, or to 1 when needing to continue.
heinrichsweikamp
parents:
diff changeset
1253 // Note: because each iteration might be very long too (~ 66 ms in 1.84beta),
heinrichsweikamp
parents:
diff changeset
1254 // break the loop when total time > 512msec.
heinrichsweikamp
parents:
diff changeset
1255 //
heinrichsweikamp
parents:
diff changeset
1256 void calc_hauptroutine_calc_deco(void)
heinrichsweikamp
parents:
diff changeset
1257 {
heinrichsweikamp
parents:
diff changeset
1258 overlay unsigned char loop;
heinrichsweikamp
parents:
diff changeset
1259
34
d7e6dfd5b498 small cleanup
heinrichsweikamp
parents: 33
diff changeset
1260 for(loop = 0; loop < 16; ++loop)
0
heinrichsweikamp
parents:
diff changeset
1261 {
heinrichsweikamp
parents:
diff changeset
1262 // Limit loops to 512ms, using timer 5:
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1263 if( tmr5() & (512*32) )
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1264 break;
34
d7e6dfd5b498 small cleanup
heinrichsweikamp
parents: 33
diff changeset
1265
0
heinrichsweikamp
parents:
diff changeset
1266 if( calc_nextdecodepth() )
heinrichsweikamp
parents:
diff changeset
1267 {
heinrichsweikamp
parents:
diff changeset
1268 if( temp_depth_limit == 0 )
heinrichsweikamp
parents:
diff changeset
1269 goto Surface;
heinrichsweikamp
parents:
diff changeset
1270
heinrichsweikamp
parents:
diff changeset
1271 //---- We hit a stop at temp_depth_limit ---------------------
heinrichsweikamp
parents:
diff changeset
1272 temp_deco = temp_depth_limit * METER_TO_BAR // Convert to relative bar,
342
7812ec7ef694 Fix low_depth shall be stored as a float (no rounding).
jDG
parents: 324
diff changeset
1273 + pres_surface; // To absolute.
0
heinrichsweikamp
parents:
diff changeset
1274 if( !update_deco_table() ) // Adds a one minute stops.
heinrichsweikamp
parents:
diff changeset
1275 goto Surface; // Deco table full: abort...
heinrichsweikamp
parents:
diff changeset
1276 }
heinrichsweikamp
parents:
diff changeset
1277 else
heinrichsweikamp
parents:
diff changeset
1278 {
heinrichsweikamp
parents:
diff changeset
1279 //---- No stop -----------------------------------------------
heinrichsweikamp
parents:
diff changeset
1280 temp_deco -= (10*METER_TO_BAR); // Ascend 10m, no wait.
heinrichsweikamp
parents:
diff changeset
1281
heinrichsweikamp
parents:
diff changeset
1282 //---- Finish computations once surface is reached -----------
heinrichsweikamp
parents:
diff changeset
1283 if( temp_deco <= pres_surface )
heinrichsweikamp
parents:
diff changeset
1284 {
heinrichsweikamp
parents:
diff changeset
1285 Surface:
heinrichsweikamp
parents:
diff changeset
1286 if( char_O_deco_status == 1 ) // Don't in @+5min variant.
heinrichsweikamp
parents:
diff changeset
1287 copy_deco_table();
heinrichsweikamp
parents:
diff changeset
1288
heinrichsweikamp
parents:
diff changeset
1289 calc_ascenttime();
heinrichsweikamp
parents:
diff changeset
1290 char_O_deco_status = 0; // calc nullzeit next time.
heinrichsweikamp
parents:
diff changeset
1291 char_O_deco_last_stop = 0; // Surface reached (to animate menu)
351
de8c45fb2ab9 BUGFIX gas volume: do not forget deco gas with switch >= dive's bottom depth.
jdg@air
parents: 348
diff changeset
1292 return;
0
heinrichsweikamp
parents:
diff changeset
1293 }
heinrichsweikamp
parents:
diff changeset
1294 }
heinrichsweikamp
parents:
diff changeset
1295 //---- Then update tissue --------------------------------------------
heinrichsweikamp
parents:
diff changeset
1296 sim_dive_mins++; // Advance simulated time by 1 minute.
heinrichsweikamp
parents:
diff changeset
1297 gas_switch_set(); // Apply any simulated gas change, once validated.
heinrichsweikamp
parents:
diff changeset
1298 sim_alveolar_presures(); // Updates ppN2 and ppHe.
heinrichsweikamp
parents:
diff changeset
1299 sim_tissue(1); // Simulate compartiments for 1 minute.
heinrichsweikamp
parents:
diff changeset
1300 }
heinrichsweikamp
parents:
diff changeset
1301
heinrichsweikamp
parents:
diff changeset
1302 // Surface not reached, need more stops... for menu animation.
heinrichsweikamp
parents:
diff changeset
1303 char_O_deco_last_stop = temp_depth_limit; // Reached depth.
heinrichsweikamp
parents:
diff changeset
1304 }
heinrichsweikamp
parents:
diff changeset
1305
heinrichsweikamp
parents:
diff changeset
1306
heinrichsweikamp
parents:
diff changeset
1307 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1308 // Simulation ascention to first deco stop.
heinrichsweikamp
parents:
diff changeset
1309 //
heinrichsweikamp
parents:
diff changeset
1310 // Note: because we ascent with a constant speed (10m/mn, ie. 1bar/mn),
heinrichsweikamp
parents:
diff changeset
1311 // there is no need to break on more that 16 iterations
heinrichsweikamp
parents:
diff changeset
1312 // (or we are already in deep shit).
heinrichsweikamp
parents:
diff changeset
1313 //
heinrichsweikamp
parents:
diff changeset
1314 // Input: pres_respiration
heinrichsweikamp
parents:
diff changeset
1315 // Output: temp_deco
heinrichsweikamp
parents:
diff changeset
1316 //
heinrichsweikamp
parents:
diff changeset
1317 // if char_O_deco_status indicate @+5 variant, add extra time at current depth,
heinrichsweikamp
parents:
diff changeset
1318 // before ascent.
heinrichsweikamp
parents:
diff changeset
1319 void sim_ascent_to_first_stop(void)
heinrichsweikamp
parents:
diff changeset
1320 {
heinrichsweikamp
parents:
diff changeset
1321 overlay unsigned char fast = 1; // 1min or 2sec steps.
heinrichsweikamp
parents:
diff changeset
1322
heinrichsweikamp
parents:
diff changeset
1323 update_startvalues();
heinrichsweikamp
parents:
diff changeset
1324 clear_deco_table();
heinrichsweikamp
parents:
diff changeset
1325
heinrichsweikamp
parents:
diff changeset
1326 temp_deco = pres_respiration; // Starts from current real depth.
heinrichsweikamp
parents:
diff changeset
1327
heinrichsweikamp
parents:
diff changeset
1328 // Are we doing the special @+5min variation ?
heinrichsweikamp
parents:
diff changeset
1329 if(char_O_deco_status & 4)
heinrichsweikamp
parents:
diff changeset
1330 sim_extra_time();
heinrichsweikamp
parents:
diff changeset
1331
heinrichsweikamp
parents:
diff changeset
1332 //---- Loop until first stop, gas switch, or surface is reached ----------
heinrichsweikamp
parents:
diff changeset
1333 for(;;)
heinrichsweikamp
parents:
diff changeset
1334 {
heinrichsweikamp
parents:
diff changeset
1335 overlay float old_deco = temp_deco; // Pamb backup (bars)
heinrichsweikamp
parents:
diff changeset
1336
heinrichsweikamp
parents:
diff changeset
1337 // Try ascending 1 full minute (fast) or 2sec (!fast):
heinrichsweikamp
parents:
diff changeset
1338 if( fast )
heinrichsweikamp
parents:
diff changeset
1339 temp_deco -= 10*METER_TO_BAR; // 1 min, at 10m/min. ~ 1bar.
heinrichsweikamp
parents:
diff changeset
1340 else
heinrichsweikamp
parents:
diff changeset
1341 temp_deco -= (10.0/30.0)*METER_TO_BAR; // 2sec at 10m/min.
heinrichsweikamp
parents:
diff changeset
1342
heinrichsweikamp
parents:
diff changeset
1343 if( temp_deco < pres_surface ) // But don't go over surface.
heinrichsweikamp
parents:
diff changeset
1344 temp_deco = pres_surface;
heinrichsweikamp
parents:
diff changeset
1345
heinrichsweikamp
parents:
diff changeset
1346 // Recompute sim_lead_tissue_limit at GF_low (deepest stop), because
heinrichsweikamp
parents:
diff changeset
1347 // one minute passed.
heinrichsweikamp
parents:
diff changeset
1348 sim_limit(GF_low);
heinrichsweikamp
parents:
diff changeset
1349
heinrichsweikamp
parents:
diff changeset
1350 // Did we reach deepest remaining stop ?
heinrichsweikamp
parents:
diff changeset
1351 if( temp_deco < sim_lead_tissue_limit )
heinrichsweikamp
parents:
diff changeset
1352 {
heinrichsweikamp
parents:
diff changeset
1353 temp_deco = old_deco; // Restore last correct depth,
heinrichsweikamp
parents:
diff changeset
1354
heinrichsweikamp
parents:
diff changeset
1355 if( fast )
heinrichsweikamp
parents:
diff changeset
1356 {
heinrichsweikamp
parents:
diff changeset
1357 fast = 0; // Retry with 2sec steps.
heinrichsweikamp
parents:
diff changeset
1358 continue;
heinrichsweikamp
parents:
diff changeset
1359 }
heinrichsweikamp
parents:
diff changeset
1360 else
heinrichsweikamp
parents:
diff changeset
1361 break; // Done...
heinrichsweikamp
parents:
diff changeset
1362 }
heinrichsweikamp
parents:
diff changeset
1363
heinrichsweikamp
parents:
diff changeset
1364 // Did we reach surface ?
heinrichsweikamp
parents:
diff changeset
1365 // NOTE: we should round BEFORE checking surface is reached.
heinrichsweikamp
parents:
diff changeset
1366 temp_depth_limit = (unsigned char)(0.5 + (temp_deco - pres_surface) * BAR_TO_METER);
heinrichsweikamp
parents:
diff changeset
1367 if( temp_depth_limit == 0 )
heinrichsweikamp
parents:
diff changeset
1368 {
heinrichsweikamp
parents:
diff changeset
1369 temp_deco = pres_surface; // Yes: finished !
heinrichsweikamp
parents:
diff changeset
1370 break;
heinrichsweikamp
parents:
diff changeset
1371 }
heinrichsweikamp
parents:
diff changeset
1372
heinrichsweikamp
parents:
diff changeset
1373 // Check for gas change below new depth ?
heinrichsweikamp
parents:
diff changeset
1374 if( gas_switch_deepest() )
heinrichsweikamp
parents:
diff changeset
1375 {
heinrichsweikamp
parents:
diff changeset
1376 assert( temp_depth_limit > 0);
heinrichsweikamp
parents:
diff changeset
1377
heinrichsweikamp
parents:
diff changeset
1378 temp_deco = temp_depth_limit * METER_TO_BAR + pres_surface;
heinrichsweikamp
parents:
diff changeset
1379 break;
heinrichsweikamp
parents:
diff changeset
1380 }
heinrichsweikamp
parents:
diff changeset
1381
heinrichsweikamp
parents:
diff changeset
1382 if( fast )
heinrichsweikamp
parents:
diff changeset
1383 sim_dive_mins++; // Advance simulated time by 1 minute.
heinrichsweikamp
parents:
diff changeset
1384 sim_alveolar_presures(); // temp_deco --> ppN2/ppHe
heinrichsweikamp
parents:
diff changeset
1385 sim_tissue(fast); // and update tissues for 1 min.
heinrichsweikamp
parents:
diff changeset
1386 }
heinrichsweikamp
parents:
diff changeset
1387 }
heinrichsweikamp
parents:
diff changeset
1388
heinrichsweikamp
parents:
diff changeset
1389 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1390 // Simulation extra time at the current depth.
heinrichsweikamp
parents:
diff changeset
1391 //
heinrichsweikamp
parents:
diff changeset
1392 // This routine is used for @+5min feature.
heinrichsweikamp
parents:
diff changeset
1393 void sim_extra_time(void)
heinrichsweikamp
parents:
diff changeset
1394 {
heinrichsweikamp
parents:
diff changeset
1395 overlay unsigned char extra = char_I_extra_time;
heinrichsweikamp
parents:
diff changeset
1396 do {
heinrichsweikamp
parents:
diff changeset
1397 sim_dive_mins++; // Advance simulated time by 1 minute.
heinrichsweikamp
parents:
diff changeset
1398 sim_tissue(1); // and update tissues for 1 min.
heinrichsweikamp
parents:
diff changeset
1399 } while( --extra != 0 );
heinrichsweikamp
parents:
diff changeset
1400 }
heinrichsweikamp
parents:
diff changeset
1401
heinrichsweikamp
parents:
diff changeset
1402 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1403 // calc_tissue
heinrichsweikamp
parents:
diff changeset
1404 //
heinrichsweikamp
parents:
diff changeset
1405 // optimized in v.101
heinrichsweikamp
parents:
diff changeset
1406 //
heinrichsweikamp
parents:
diff changeset
1407 static void calc_tissue(PARAMETER unsigned char period)
heinrichsweikamp
parents:
diff changeset
1408 {
heinrichsweikamp
parents:
diff changeset
1409 assert( 0.00 <= ppN2 && ppN2 < 11.2 ); // 80% N2 at 130m
heinrichsweikamp
parents:
diff changeset
1410 assert( 0.00 <= ppHe && ppHe < 12.6 ); // 90% He at 130m
heinrichsweikamp
parents:
diff changeset
1411
heinrichsweikamp
parents:
diff changeset
1412 for (ci=0;ci<NUM_COMP;ci++)
heinrichsweikamp
parents:
diff changeset
1413 {
heinrichsweikamp
parents:
diff changeset
1414 read_buhlmann_times(period); // 2 sec or 1 min period.
heinrichsweikamp
parents:
diff changeset
1415
heinrichsweikamp
parents:
diff changeset
1416 // N2
heinrichsweikamp
parents:
diff changeset
1417 temp_tissue = (ppN2 - pres_tissue_N2[ci]) * var_N2_e;
heinrichsweikamp
parents:
diff changeset
1418 temp_tissue_safety();
heinrichsweikamp
parents:
diff changeset
1419 pres_tissue_N2[ci] += temp_tissue;
heinrichsweikamp
parents:
diff changeset
1420
heinrichsweikamp
parents:
diff changeset
1421 // He
heinrichsweikamp
parents:
diff changeset
1422 temp_tissue = (ppHe - pres_tissue_He[ci]) * var_He_e;
heinrichsweikamp
parents:
diff changeset
1423 temp_tissue_safety();
heinrichsweikamp
parents:
diff changeset
1424 pres_tissue_He[ci] += temp_tissue;
heinrichsweikamp
parents:
diff changeset
1425 }
heinrichsweikamp
parents:
diff changeset
1426 }
heinrichsweikamp
parents:
diff changeset
1427
heinrichsweikamp
parents:
diff changeset
1428 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1429 // calc_limit
heinrichsweikamp
parents:
diff changeset
1430 //
heinrichsweikamp
parents:
diff changeset
1431 // New in v.111 : separated from calc_tissue(), and depends on GF value.
heinrichsweikamp
parents:
diff changeset
1432 //
heinrichsweikamp
parents:
diff changeset
1433 static void calc_limit(void)
heinrichsweikamp
parents:
diff changeset
1434 {
heinrichsweikamp
parents:
diff changeset
1435 char_O_gtissue_no = 255;
heinrichsweikamp
parents:
diff changeset
1436 calc_lead_tissue_limit = 0.0;
heinrichsweikamp
parents:
diff changeset
1437
heinrichsweikamp
parents:
diff changeset
1438 for(ci=0; ci<NUM_COMP;ci++)
heinrichsweikamp
parents:
diff changeset
1439 {
heinrichsweikamp
parents:
diff changeset
1440 overlay float N2 = pres_tissue_N2[ci];
heinrichsweikamp
parents:
diff changeset
1441 overlay float He = pres_tissue_He[ci];
heinrichsweikamp
parents:
diff changeset
1442 overlay float p = N2 + He;
heinrichsweikamp
parents:
diff changeset
1443
heinrichsweikamp
parents:
diff changeset
1444 read_buhlmann_coefficients();
heinrichsweikamp
parents:
diff changeset
1445 var_N2_a = (var_N2_a * N2 + var_He_a * He) / p;
heinrichsweikamp
parents:
diff changeset
1446 var_N2_b = (var_N2_b * N2 + var_He_b * He) / p;
heinrichsweikamp
parents:
diff changeset
1447
heinrichsweikamp
parents:
diff changeset
1448 // Apply the Eric Baker's varying gradient factor correction.
heinrichsweikamp
parents:
diff changeset
1449 // Note: the correction factor depends both on GF and b,
heinrichsweikamp
parents:
diff changeset
1450 // Actual values are in the 1.5 .. 1.0 range (for a GF=30%),
heinrichsweikamp
parents:
diff changeset
1451 // so that can change who is the leading gas...
heinrichsweikamp
parents:
diff changeset
1452 // Note: Also depends of the GF. So the calcul is different for
heinrichsweikamp
parents:
diff changeset
1453 // GF_low, current GF, or GF_high...
heinrichsweikamp
parents:
diff changeset
1454 // *BUT* calc_tissue() is used to compute bottom time,
heinrichsweikamp
parents:
diff changeset
1455 // hence what would happend at surface,
heinrichsweikamp
parents:
diff changeset
1456 // hence at GF_high.
heinrichsweikamp
parents:
diff changeset
1457 if( char_I_deco_model != 0 )
heinrichsweikamp
parents:
diff changeset
1458 p = ( p - var_N2_a * GF_high) * var_N2_b
heinrichsweikamp
parents:
diff changeset
1459 / (GF_high + var_N2_b * (1.0 - GF_high));
heinrichsweikamp
parents:
diff changeset
1460 else
heinrichsweikamp
parents:
diff changeset
1461 p = (p - var_N2_a) * var_N2_b;
heinrichsweikamp
parents:
diff changeset
1462 if( p < 0.0 ) p = 0.0;
heinrichsweikamp
parents:
diff changeset
1463
heinrichsweikamp
parents:
diff changeset
1464 if( p > calc_lead_tissue_limit )
heinrichsweikamp
parents:
diff changeset
1465 {
heinrichsweikamp
parents:
diff changeset
1466 char_O_gtissue_no = ci;
heinrichsweikamp
parents:
diff changeset
1467 calc_lead_tissue_limit = p;
heinrichsweikamp
parents:
diff changeset
1468 }
heinrichsweikamp
parents:
diff changeset
1469 }
heinrichsweikamp
parents:
diff changeset
1470
heinrichsweikamp
parents:
diff changeset
1471 assert( char_O_gtissue_no < NUM_COMP );
heinrichsweikamp
parents:
diff changeset
1472 assert( 0.0 <= calc_lead_tissue_limit && calc_lead_tissue_limit <= 14.0);
heinrichsweikamp
parents:
diff changeset
1473 }
heinrichsweikamp
parents:
diff changeset
1474
heinrichsweikamp
parents:
diff changeset
1475 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1476 // calc_nullzeit
heinrichsweikamp
parents:
diff changeset
1477 //
heinrichsweikamp
parents:
diff changeset
1478 // calculates the remaining bottom time
heinrichsweikamp
parents:
diff changeset
1479 //
heinrichsweikamp
parents:
diff changeset
1480 // NOTE: Erik Baker's closed formula works for Nitroxes. Trimix adds a second
heinrichsweikamp
parents:
diff changeset
1481 // exponential term to the M-value equation, making it impossible to
heinrichsweikamp
parents:
diff changeset
1482 // invert... So we have to make a fast-simu until we find a better way.
heinrichsweikamp
parents:
diff changeset
1483 //
heinrichsweikamp
parents:
diff changeset
1484 // Input: pres_respiration
heinrichsweikamp
parents:
diff changeset
1485 // Output: char_O_nullzeit
heinrichsweikamp
parents:
diff changeset
1486 //
heinrichsweikamp
parents:
diff changeset
1487 static void calc_nullzeit(void)
heinrichsweikamp
parents:
diff changeset
1488 {
heinrichsweikamp
parents:
diff changeset
1489 //---- Compute ppN2 and ppHe ---------------------------------------------
heinrichsweikamp
parents:
diff changeset
1490 temp_deco = pres_respiration;
heinrichsweikamp
parents:
diff changeset
1491 sim_alveolar_presures();
heinrichsweikamp
parents:
diff changeset
1492
heinrichsweikamp
parents:
diff changeset
1493 char_O_nullzeit = 240;
heinrichsweikamp
parents:
diff changeset
1494 for(ci=0; ci<NUM_COMP; ci++)
heinrichsweikamp
parents:
diff changeset
1495 {
heinrichsweikamp
parents:
diff changeset
1496 //---- Read A/B values and loading factor for N2 and He --------------
heinrichsweikamp
parents:
diff changeset
1497 overlay float tN2 = pres_tissue_N2[ci];
heinrichsweikamp
parents:
diff changeset
1498 overlay float tHe = pres_tissue_He[ci];
heinrichsweikamp
parents:
diff changeset
1499 overlay float t = tN2 + tHe;
heinrichsweikamp
parents:
diff changeset
1500 overlay unsigned char ndl;
heinrichsweikamp
parents:
diff changeset
1501 overlay unsigned char period = 10;
heinrichsweikamp
parents:
diff changeset
1502
heinrichsweikamp
parents:
diff changeset
1503 read_buhlmann_coefficients();
heinrichsweikamp
parents:
diff changeset
1504 read_buhlmann_times(2); // Starts with a 10min period.
heinrichsweikamp
parents:
diff changeset
1505
heinrichsweikamp
parents:
diff changeset
1506 //---- Simulate for that tissue --------------------------------------
heinrichsweikamp
parents:
diff changeset
1507 // NOTE: No need to simulate for longuer than the already found NDL.
heinrichsweikamp
parents:
diff changeset
1508 for(ndl=0; ndl<char_O_nullzeit;)
heinrichsweikamp
parents:
diff changeset
1509 {
heinrichsweikamp
parents:
diff changeset
1510 //---- Compute updated mix M-value at surface
heinrichsweikamp
parents:
diff changeset
1511 overlay float a = (var_N2_a * tN2 + var_He_a * tHe) / t;
heinrichsweikamp
parents:
diff changeset
1512 overlay float b = (var_N2_b * tN2 + var_He_b * tHe) / t;
heinrichsweikamp
parents:
diff changeset
1513 overlay float M0 = (a + pres_surface/b);
heinrichsweikamp
parents:
diff changeset
1514
heinrichsweikamp
parents:
diff changeset
1515 //---- Add 10min/1min to N2/He tissues
heinrichsweikamp
parents:
diff changeset
1516 overlay float dTN2 = (ppN2 - tN2) * var_N2_e;
heinrichsweikamp
parents:
diff changeset
1517 overlay float dTHe = (ppHe - tHe) * var_He_e;
heinrichsweikamp
parents:
diff changeset
1518
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
1519 //---- Apply security margin for both models
324
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
1520 // NDL can be computed while ascending... SO we have
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
1521 // to check wether we are saturating or desaturating.
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
1522 if( dTN2 > 0.0 ) dTN2 *= float_saturation_multiplier;
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
1523 else dTN2 *= float_desaturation_multiplier;
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
1524
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
1525 if( dTHe > 0.0 ) dTHe *= float_saturation_multiplier;
0e9dcdcf03c1 FIX NDL prediction error with Buhlmann model: might be desaturating too fast.
jdg@air
parents: 323
diff changeset
1526 else dTHe *= float_saturation_multiplier;
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
1527
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
1528 if (char_I_deco_model != 0 )
0
heinrichsweikamp
parents:
diff changeset
1529 M0 = GF_high * (M0 - pres_surface) + pres_surface;
heinrichsweikamp
parents:
diff changeset
1530
heinrichsweikamp
parents:
diff changeset
1531 //---- Simulate off-gasing while going to surface
heinrichsweikamp
parents:
diff changeset
1532 // TODO !
heinrichsweikamp
parents:
diff changeset
1533 // dTN2 -= exp( ... ascent time ... ppN2...)
heinrichsweikamp
parents:
diff changeset
1534 // dTHe -= exp( ... ascent time ... ppHe...)
heinrichsweikamp
parents:
diff changeset
1535
heinrichsweikamp
parents:
diff changeset
1536 //---- Ok now, and still ok to surface after 1 or 10 minutes ?
heinrichsweikamp
parents:
diff changeset
1537 if( (t <= M0) && (t + dTN2 + dTHe <= M0) )
heinrichsweikamp
parents:
diff changeset
1538 {
heinrichsweikamp
parents:
diff changeset
1539 tN2 += dTN2; // YES: apply gas loadings,
heinrichsweikamp
parents:
diff changeset
1540 tHe += dTHe;
heinrichsweikamp
parents:
diff changeset
1541 t = tN2 + tHe;
heinrichsweikamp
parents:
diff changeset
1542 ndl += period; // increment NDL,
heinrichsweikamp
parents:
diff changeset
1543 continue; // and loop.
heinrichsweikamp
parents:
diff changeset
1544 }
heinrichsweikamp
parents:
diff changeset
1545
heinrichsweikamp
parents:
diff changeset
1546 //---- Should we retry with smaller steps ?
heinrichsweikamp
parents:
diff changeset
1547 if( period == 10 )
heinrichsweikamp
parents:
diff changeset
1548 {
heinrichsweikamp
parents:
diff changeset
1549 read_buhlmann_times(1); // 1min coefs.
heinrichsweikamp
parents:
diff changeset
1550 period = 1;
heinrichsweikamp
parents:
diff changeset
1551 continue;
heinrichsweikamp
parents:
diff changeset
1552 }
heinrichsweikamp
parents:
diff changeset
1553
heinrichsweikamp
parents:
diff changeset
1554 //---- ELSE make a linear approx for the last minute
heinrichsweikamp
parents:
diff changeset
1555 // Usefull to have a meaningfull rounding of NDL.
heinrichsweikamp
parents:
diff changeset
1556 // But ONLY it positive (negativ casted to unsigned is bad).
heinrichsweikamp
parents:
diff changeset
1557 if( M0 > t )
heinrichsweikamp
parents:
diff changeset
1558 ndl += (unsigned char)(0.5f + (M0-t)/(dTN2+dTHe));
heinrichsweikamp
parents:
diff changeset
1559 break;
heinrichsweikamp
parents:
diff changeset
1560 }
heinrichsweikamp
parents:
diff changeset
1561
heinrichsweikamp
parents:
diff changeset
1562 // Keep the shortest NDL found
heinrichsweikamp
parents:
diff changeset
1563 if( ndl < char_O_nullzeit )
heinrichsweikamp
parents:
diff changeset
1564 char_O_nullzeit = ndl;
heinrichsweikamp
parents:
diff changeset
1565 }
heinrichsweikamp
parents:
diff changeset
1566 }
heinrichsweikamp
parents:
diff changeset
1567
heinrichsweikamp
parents:
diff changeset
1568 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1569 // calc_ascenttime
heinrichsweikamp
parents:
diff changeset
1570 //
heinrichsweikamp
parents:
diff changeset
1571 // Summup ascent from bottom to surface, at 1 bar/min, 1min for last 3 meters,
heinrichsweikamp
parents:
diff changeset
1572 // and all stops.
heinrichsweikamp
parents:
diff changeset
1573 //
heinrichsweikamp
parents:
diff changeset
1574 // Result in int_O_ascenttime, or int_O_extra_ascenttime if in @+5min variant.
heinrichsweikamp
parents:
diff changeset
1575 static void calc_ascenttime(void)
heinrichsweikamp
parents:
diff changeset
1576 {
heinrichsweikamp
parents:
diff changeset
1577 overlay unsigned char x;
heinrichsweikamp
parents:
diff changeset
1578 overlay unsigned short sum;
heinrichsweikamp
parents:
diff changeset
1579
heinrichsweikamp
parents:
diff changeset
1580 // + 0.7 to count 1 minute ascent time from 3 metre to surface
heinrichsweikamp
parents:
diff changeset
1581 overlay float ascent = pres_respiration - pres_surface + 0.7;
heinrichsweikamp
parents:
diff changeset
1582 if (ascent < 0.0)
heinrichsweikamp
parents:
diff changeset
1583 ascent = 0.0;
heinrichsweikamp
parents:
diff changeset
1584 sum = (unsigned short)(ascent + 0.99);
heinrichsweikamp
parents:
diff changeset
1585
heinrichsweikamp
parents:
diff changeset
1586 for(x=0; x<NUM_STOPS && internal_deco_depth[x]; x++)
heinrichsweikamp
parents:
diff changeset
1587 sum += (unsigned short)internal_deco_time[x];
heinrichsweikamp
parents:
diff changeset
1588
heinrichsweikamp
parents:
diff changeset
1589 if( char_O_deco_status == 1 )
heinrichsweikamp
parents:
diff changeset
1590 int_O_ascenttime = sum;
heinrichsweikamp
parents:
diff changeset
1591 else
heinrichsweikamp
parents:
diff changeset
1592 int_O_extra_ascenttime = sum;
heinrichsweikamp
parents:
diff changeset
1593
heinrichsweikamp
parents:
diff changeset
1594 }
heinrichsweikamp
parents:
diff changeset
1595
heinrichsweikamp
parents:
diff changeset
1596 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1597 // update_startvalues
heinrichsweikamp
parents:
diff changeset
1598 //
heinrichsweikamp
parents:
diff changeset
1599 // updated in v.102
heinrichsweikamp
parents:
diff changeset
1600 //
heinrichsweikamp
parents:
diff changeset
1601 void update_startvalues(void)
heinrichsweikamp
parents:
diff changeset
1602 {
heinrichsweikamp
parents:
diff changeset
1603 overlay unsigned char x;
heinrichsweikamp
parents:
diff changeset
1604
heinrichsweikamp
parents:
diff changeset
1605 // Start ascent simulation with current tissue partial pressures.
heinrichsweikamp
parents:
diff changeset
1606 for(x=0; x<NUM_COMP; x++)
heinrichsweikamp
parents:
diff changeset
1607 {
heinrichsweikamp
parents:
diff changeset
1608 sim_pres_tissue_N2[x] = pres_tissue_N2[x];
heinrichsweikamp
parents:
diff changeset
1609 sim_pres_tissue_He[x] = pres_tissue_He[x];
heinrichsweikamp
parents:
diff changeset
1610 }
heinrichsweikamp
parents:
diff changeset
1611
heinrichsweikamp
parents:
diff changeset
1612 // No leading tissue (yet) for this ascent simulation.
heinrichsweikamp
parents:
diff changeset
1613 sim_lead_tissue_limit = 0.0;
heinrichsweikamp
parents:
diff changeset
1614 sim_lead_tissue_no = 255;
heinrichsweikamp
parents:
diff changeset
1615 }
heinrichsweikamp
parents:
diff changeset
1616
heinrichsweikamp
parents:
diff changeset
1617 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1618 // sim_tissue
heinrichsweikamp
parents:
diff changeset
1619 //
heinrichsweikamp
parents:
diff changeset
1620 // optimized in v.101
heinrichsweikamp
parents:
diff changeset
1621 //
heinrichsweikamp
parents:
diff changeset
1622 // Function very simular to calc_tissue, but:
heinrichsweikamp
parents:
diff changeset
1623 // + Use a 1min or 10min period.
heinrichsweikamp
parents:
diff changeset
1624 // + Do it on sim_pres_tissue, instead of pres_tissue.
heinrichsweikamp
parents:
diff changeset
1625 static void sim_tissue(PARAMETER unsigned char period)
heinrichsweikamp
parents:
diff changeset
1626 {
heinrichsweikamp
parents:
diff changeset
1627 assert( 0.00 <= ppN2 && ppN2 < 11.2 ); // 80% N2 at 130m
heinrichsweikamp
parents:
diff changeset
1628 assert( 0.00 <= ppHe && ppHe < 12.6 ); // 90% He at 130m
heinrichsweikamp
parents:
diff changeset
1629
heinrichsweikamp
parents:
diff changeset
1630 for(ci=0; ci<NUM_COMP; ci++)
heinrichsweikamp
parents:
diff changeset
1631 {
heinrichsweikamp
parents:
diff changeset
1632 read_buhlmann_times(period); // 1 or 10 minute(s) interval
heinrichsweikamp
parents:
diff changeset
1633
heinrichsweikamp
parents:
diff changeset
1634 // N2
heinrichsweikamp
parents:
diff changeset
1635 temp_tissue = (ppN2 - sim_pres_tissue_N2[ci]) * var_N2_e;
heinrichsweikamp
parents:
diff changeset
1636 temp_tissue_safety();
heinrichsweikamp
parents:
diff changeset
1637 sim_pres_tissue_N2[ci] += temp_tissue;
heinrichsweikamp
parents:
diff changeset
1638
heinrichsweikamp
parents:
diff changeset
1639 // He
heinrichsweikamp
parents:
diff changeset
1640 temp_tissue = (ppHe - sim_pres_tissue_He[ci]) * var_He_e;
heinrichsweikamp
parents:
diff changeset
1641 temp_tissue_safety();
heinrichsweikamp
parents:
diff changeset
1642 sim_pres_tissue_He[ci] += temp_tissue;
heinrichsweikamp
parents:
diff changeset
1643 }
heinrichsweikamp
parents:
diff changeset
1644 }
heinrichsweikamp
parents:
diff changeset
1645
heinrichsweikamp
parents:
diff changeset
1646 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1647 // sim_limit()
heinrichsweikamp
parents:
diff changeset
1648 //
heinrichsweikamp
parents:
diff changeset
1649 // New in v.111
heinrichsweikamp
parents:
diff changeset
1650 //
heinrichsweikamp
parents:
diff changeset
1651 // Function separated from sim_tissue() to allow recomputing limit on
heinrichsweikamp
parents:
diff changeset
1652 // different depth, because it depends on current gradient factor.
heinrichsweikamp
parents:
diff changeset
1653 //
heinrichsweikamp
parents:
diff changeset
1654 static void sim_limit(PARAMETER float GF_current)
heinrichsweikamp
parents:
diff changeset
1655 {
heinrichsweikamp
parents:
diff changeset
1656 assert( 0.0 < GF_current && GF_current <= 1.0f);
heinrichsweikamp
parents:
diff changeset
1657
heinrichsweikamp
parents:
diff changeset
1658 sim_lead_tissue_limit = 0.0;
heinrichsweikamp
parents:
diff changeset
1659 sim_lead_tissue_no = 0; // If no one is critic, keep first tissue.
heinrichsweikamp
parents:
diff changeset
1660
heinrichsweikamp
parents:
diff changeset
1661 for(ci=0; ci<NUM_COMP; ci++)
heinrichsweikamp
parents:
diff changeset
1662 {
heinrichsweikamp
parents:
diff changeset
1663 overlay float N2 = sim_pres_tissue_N2[ci];
heinrichsweikamp
parents:
diff changeset
1664 overlay float He = sim_pres_tissue_He[ci];
heinrichsweikamp
parents:
diff changeset
1665 overlay float p = N2 + He;
heinrichsweikamp
parents:
diff changeset
1666
heinrichsweikamp
parents:
diff changeset
1667 read_buhlmann_coefficients();
heinrichsweikamp
parents:
diff changeset
1668 var_N2_a = (var_N2_a * N2 + var_He_a * He) / p;
heinrichsweikamp
parents:
diff changeset
1669 var_N2_b = (var_N2_b * N2 + var_He_b * He) / p;
heinrichsweikamp
parents:
diff changeset
1670
heinrichsweikamp
parents:
diff changeset
1671 // Apply the Eric Baker's varying gradient factor correction.
heinrichsweikamp
parents:
diff changeset
1672 // Note: the correction factor depends both on GF and b,
heinrichsweikamp
parents:
diff changeset
1673 // Actual values are in the 1.5 .. 1.0 range (for a GF=30%),
heinrichsweikamp
parents:
diff changeset
1674 // so that can change who is the leading gas...
heinrichsweikamp
parents:
diff changeset
1675 // Note: Also depends of the GF_current...
heinrichsweikamp
parents:
diff changeset
1676 if( char_I_deco_model != 0 )
heinrichsweikamp
parents:
diff changeset
1677 p = ( p - var_N2_a * GF_current)
heinrichsweikamp
parents:
diff changeset
1678 / (GF_current / var_N2_b + 1.0 - GF_current);
heinrichsweikamp
parents:
diff changeset
1679 else
heinrichsweikamp
parents:
diff changeset
1680 p = (p - var_N2_a) * var_N2_b;
heinrichsweikamp
parents:
diff changeset
1681
heinrichsweikamp
parents:
diff changeset
1682 if( p > sim_lead_tissue_limit )
heinrichsweikamp
parents:
diff changeset
1683 {
heinrichsweikamp
parents:
diff changeset
1684 sim_lead_tissue_no = ci;
heinrichsweikamp
parents:
diff changeset
1685 sim_lead_tissue_limit = p;
heinrichsweikamp
parents:
diff changeset
1686 }
heinrichsweikamp
parents:
diff changeset
1687 } // for ci
heinrichsweikamp
parents:
diff changeset
1688
heinrichsweikamp
parents:
diff changeset
1689 assert( sim_lead_tissue_no < NUM_COMP );
heinrichsweikamp
parents:
diff changeset
1690 assert( 0.0 <= sim_lead_tissue_limit && sim_lead_tissue_limit <= 14.0 );
heinrichsweikamp
parents:
diff changeset
1691 }
heinrichsweikamp
parents:
diff changeset
1692
heinrichsweikamp
parents:
diff changeset
1693 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1694 // clear_deco_table
heinrichsweikamp
parents:
diff changeset
1695 //
heinrichsweikamp
parents:
diff changeset
1696 // unchanged in v.101
heinrichsweikamp
parents:
diff changeset
1697 //
heinrichsweikamp
parents:
diff changeset
1698 static void clear_deco_table(void)
heinrichsweikamp
parents:
diff changeset
1699 {
heinrichsweikamp
parents:
diff changeset
1700 overlay unsigned char x;
heinrichsweikamp
parents:
diff changeset
1701
heinrichsweikamp
parents:
diff changeset
1702 for(x=0; x<NUM_STOPS; ++x)
heinrichsweikamp
parents:
diff changeset
1703 {
heinrichsweikamp
parents:
diff changeset
1704 internal_deco_time [x] = 0;
heinrichsweikamp
parents:
diff changeset
1705 internal_deco_depth[x] = 0;
heinrichsweikamp
parents:
diff changeset
1706 }
heinrichsweikamp
parents:
diff changeset
1707 }
heinrichsweikamp
parents:
diff changeset
1708
heinrichsweikamp
parents:
diff changeset
1709 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1710 // update_deco_table
heinrichsweikamp
parents:
diff changeset
1711 //
heinrichsweikamp
parents:
diff changeset
1712 // Add 1 min to current stop.
heinrichsweikamp
parents:
diff changeset
1713 //
heinrichsweikamp
parents:
diff changeset
1714 // Inputs:
heinrichsweikamp
parents:
diff changeset
1715 // temp_depth_limit = stop's depth, in meters.
heinrichsweikamp
parents:
diff changeset
1716 // In/Out:
heinrichsweikamp
parents:
diff changeset
1717 // internal_deco_depth[] : depth (in metres) of each stops.
heinrichsweikamp
parents:
diff changeset
1718 // internal_deco_time [] : time (in minutes) of each stops.
heinrichsweikamp
parents:
diff changeset
1719 //
heinrichsweikamp
parents:
diff changeset
1720 static unsigned char update_deco_table()
heinrichsweikamp
parents:
diff changeset
1721 {
heinrichsweikamp
parents:
diff changeset
1722 overlay unsigned char x;
heinrichsweikamp
parents:
diff changeset
1723 assert( temp_depth_limit < 128 ); // Can't be negativ (overflown).
heinrichsweikamp
parents:
diff changeset
1724 assert( temp_depth_limit > 0 ); // No stop at surface...
heinrichsweikamp
parents:
diff changeset
1725
heinrichsweikamp
parents:
diff changeset
1726 for(x=0; x<NUM_STOPS; ++x)
heinrichsweikamp
parents:
diff changeset
1727 {
heinrichsweikamp
parents:
diff changeset
1728 // Make sure deco-stops are recorded in order:
111
c61b7a4e317c Bugfix: CNS in planner
heinrichsweikamp
parents: 34
diff changeset
1729 assert( !internal_deco_depth[x] || temp_depth_limit <= internal_deco_depth[x] );
0
heinrichsweikamp
parents:
diff changeset
1730
111
c61b7a4e317c Bugfix: CNS in planner
heinrichsweikamp
parents: 34
diff changeset
1731 if( internal_deco_depth[x]== temp_depth_limit )
0
heinrichsweikamp
parents:
diff changeset
1732 {
heinrichsweikamp
parents:
diff changeset
1733 // Do not overflow (max 255')
heinrichsweikamp
parents:
diff changeset
1734 if( internal_deco_time[x] < 255 )
heinrichsweikamp
parents:
diff changeset
1735 {
heinrichsweikamp
parents:
diff changeset
1736 internal_deco_time[x]++;
heinrichsweikamp
parents:
diff changeset
1737 return 1;
heinrichsweikamp
parents:
diff changeset
1738 }
heinrichsweikamp
parents:
diff changeset
1739 // But store extra in the next stop...
heinrichsweikamp
parents:
diff changeset
1740 }
heinrichsweikamp
parents:
diff changeset
1741
heinrichsweikamp
parents:
diff changeset
1742 if( internal_deco_depth[x] == 0 )
heinrichsweikamp
parents:
diff changeset
1743 {
heinrichsweikamp
parents:
diff changeset
1744 internal_deco_depth[x] = temp_depth_limit;
heinrichsweikamp
parents:
diff changeset
1745
heinrichsweikamp
parents:
diff changeset
1746 internal_deco_time[x] = 1;
111
c61b7a4e317c Bugfix: CNS in planner
heinrichsweikamp
parents: 34
diff changeset
1747 internal_deco_gas[x] = sim_gas_last_used;
0
heinrichsweikamp
parents:
diff changeset
1748 return 1;
heinrichsweikamp
parents:
diff changeset
1749 }
heinrichsweikamp
parents:
diff changeset
1750 }
heinrichsweikamp
parents:
diff changeset
1751
heinrichsweikamp
parents:
diff changeset
1752 // Can't store stops at more than 96m.
heinrichsweikamp
parents:
diff changeset
1753 // Or stops at less that 3m too.
heinrichsweikamp
parents:
diff changeset
1754 // Just do nothing with that...
heinrichsweikamp
parents:
diff changeset
1755 return 0;
heinrichsweikamp
parents:
diff changeset
1756 }
heinrichsweikamp
parents:
diff changeset
1757
heinrichsweikamp
parents:
diff changeset
1758 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1759 // calc_gradient_factor
heinrichsweikamp
parents:
diff changeset
1760 //
heinrichsweikamp
parents:
diff changeset
1761 // optimized in v.101 (var_N2_a)
heinrichsweikamp
parents:
diff changeset
1762 // new code in v.102
heinrichsweikamp
parents:
diff changeset
1763 //
heinrichsweikamp
parents:
diff changeset
1764 static void calc_gradient_factor(void)
heinrichsweikamp
parents:
diff changeset
1765 {
heinrichsweikamp
parents:
diff changeset
1766 overlay float gf;
heinrichsweikamp
parents:
diff changeset
1767 overlay float N2 = pres_tissue_N2[char_O_gtissue_no];
heinrichsweikamp
parents:
diff changeset
1768 overlay float He = pres_tissue_He[char_O_gtissue_no];
heinrichsweikamp
parents:
diff changeset
1769
heinrichsweikamp
parents:
diff changeset
1770 assert( char_O_gtissue_no < NUM_COMP );
heinrichsweikamp
parents:
diff changeset
1771 assert( 0.800 <= pres_respiration && pres_respiration < 14.0 );
heinrichsweikamp
parents:
diff changeset
1772
heinrichsweikamp
parents:
diff changeset
1773 // tissue > respiration (currently off-gasing)
heinrichsweikamp
parents:
diff changeset
1774 // GF = 0% when respiration == tissue, ie. bubbles are at equilibrium.
heinrichsweikamp
parents:
diff changeset
1775 // GF = 100% when respiration == limit.
heinrichsweikamp
parents:
diff changeset
1776 temp_tissue = N2 + He;
heinrichsweikamp
parents:
diff changeset
1777 if( temp_tissue <= pres_respiration )
heinrichsweikamp
parents:
diff changeset
1778 gf = 0.0;
heinrichsweikamp
parents:
diff changeset
1779 else
heinrichsweikamp
parents:
diff changeset
1780 {
heinrichsweikamp
parents:
diff changeset
1781 overlay float limit = calc_lead_tissue_limit;
heinrichsweikamp
parents:
diff changeset
1782 // NOTE: in GF model, calc_lead_tissue_limit include already the
heinrichsweikamp
parents:
diff changeset
1783 // correction due to gradient factor. To compute the actual
heinrichsweikamp
parents:
diff changeset
1784 // current GF, we need to (re-)compute the raw ambiant-pressure
313
0ce5fa241b8e FIX minor comment about deco offset unit...
jDG
parents: 298
diff changeset
1785 // limit from the Buhlmann model.
0
heinrichsweikamp
parents:
diff changeset
1786 if( char_I_deco_model != 0 )
heinrichsweikamp
parents:
diff changeset
1787 {
heinrichsweikamp
parents:
diff changeset
1788 ci = char_O_gtissue_no;
heinrichsweikamp
parents:
diff changeset
1789 read_buhlmann_coefficients();
heinrichsweikamp
parents:
diff changeset
1790 var_N2_a = (var_N2_a * N2 + var_He_a * He) / temp_tissue;
heinrichsweikamp
parents:
diff changeset
1791 var_N2_b = (var_N2_b * N2 + var_He_b * He) / temp_tissue;
heinrichsweikamp
parents:
diff changeset
1792 limit = (temp_tissue - var_N2_a) * var_N2_b;
heinrichsweikamp
parents:
diff changeset
1793 }
heinrichsweikamp
parents:
diff changeset
1794
heinrichsweikamp
parents:
diff changeset
1795 gf = (temp_tissue - pres_respiration)
heinrichsweikamp
parents:
diff changeset
1796 / (temp_tissue - limit)
heinrichsweikamp
parents:
diff changeset
1797 * 100.0;
heinrichsweikamp
parents:
diff changeset
1798 if( gf > 254.5 ) gf = 255.0;
heinrichsweikamp
parents:
diff changeset
1799 if( gf < 0.0 ) gf = 0.0;
heinrichsweikamp
parents:
diff changeset
1800 }
heinrichsweikamp
parents:
diff changeset
1801 char_O_gradient_factor = (unsigned char)(gf+0.5f);
heinrichsweikamp
parents:
diff changeset
1802
heinrichsweikamp
parents:
diff changeset
1803 }
heinrichsweikamp
parents:
diff changeset
1804
heinrichsweikamp
parents:
diff changeset
1805 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1806 // deco_calc_desaturation_time
heinrichsweikamp
parents:
diff changeset
1807 //
heinrichsweikamp
parents:
diff changeset
1808 // FIXED N2_ratio
heinrichsweikamp
parents:
diff changeset
1809 // unchanged in v.101
heinrichsweikamp
parents:
diff changeset
1810 // Inputs: int_I_pres_surface, ppWater, char_I_desaturation_multiplier
heinrichsweikamp
parents:
diff changeset
1811 // Outputs: int_O_desaturation_time, char_O_tissue_saturation[0..31]
heinrichsweikamp
parents:
diff changeset
1812 //
heinrichsweikamp
parents:
diff changeset
1813 void deco_calc_desaturation_time(void)
heinrichsweikamp
parents:
diff changeset
1814 {
heinrichsweikamp
parents:
diff changeset
1815 RESET_C_STACK
heinrichsweikamp
parents:
diff changeset
1816
heinrichsweikamp
parents:
diff changeset
1817 assert( 800 < int_I_pres_surface && int_I_pres_surface < 1100 );
heinrichsweikamp
parents:
diff changeset
1818 assert( 0 < char_I_desaturation_multiplier && char_I_desaturation_multiplier <= 100 );
heinrichsweikamp
parents:
diff changeset
1819
313
0ce5fa241b8e FIX minor comment about deco offset unit...
jDG
parents: 298
diff changeset
1820 N2_ratio = 0.7902; // FIXED sum as stated in buhlmann
0
heinrichsweikamp
parents:
diff changeset
1821 pres_surface = int_I_pres_surface * 0.001;
heinrichsweikamp
parents:
diff changeset
1822 ppN2 = N2_ratio * (pres_surface - ppWater);
heinrichsweikamp
parents:
diff changeset
1823 int_O_desaturation_time = 0;
heinrichsweikamp
parents:
diff changeset
1824 float_desaturation_multiplier = char_I_desaturation_multiplier * (0.01 * SURFACE_DESAT_FACTOR);
heinrichsweikamp
parents:
diff changeset
1825
heinrichsweikamp
parents:
diff changeset
1826 for(ci=0; ci<NUM_COMP; ci++)
heinrichsweikamp
parents:
diff changeset
1827 {
heinrichsweikamp
parents:
diff changeset
1828 overlay unsigned short desat_time; // For a particular compartiment, in min.
heinrichsweikamp
parents:
diff changeset
1829 overlay float temp1;
heinrichsweikamp
parents:
diff changeset
1830 overlay float temp2;
heinrichsweikamp
parents:
diff changeset
1831 overlay float temp3;
heinrichsweikamp
parents:
diff changeset
1832 overlay float temp4;
heinrichsweikamp
parents:
diff changeset
1833
heinrichsweikamp
parents:
diff changeset
1834 read_buhlmann_ht();
heinrichsweikamp
parents:
diff changeset
1835
heinrichsweikamp
parents:
diff changeset
1836 // saturation_time (for flight) and N2_saturation in multiples of halftime
heinrichsweikamp
parents:
diff changeset
1837 // version v.100: 1.1 = 10 percent distance to totally clean (totally clean is not possible, would take infinite time )
heinrichsweikamp
parents:
diff changeset
1838 // new in version v.101: 1.07 = 7 percent distance to totally clean (totally clean is not possible, would take infinite time )
heinrichsweikamp
parents:
diff changeset
1839 // changes in v.101: 1.05 = 5 percent dist to totally clean is new desaturation point for display and NoFly calculations
heinrichsweikamp
parents:
diff changeset
1840 // N2
heinrichsweikamp
parents:
diff changeset
1841 temp1 = 1.05 * ppN2 - pres_tissue_N2[ci];
heinrichsweikamp
parents:
diff changeset
1842 temp2 = ppN2 - pres_tissue_N2[ci];
heinrichsweikamp
parents:
diff changeset
1843 if (temp2 >= 0.0)
heinrichsweikamp
parents:
diff changeset
1844 temp1 = 0.0;
heinrichsweikamp
parents:
diff changeset
1845 else
heinrichsweikamp
parents:
diff changeset
1846 temp1 = temp1 / temp2;
heinrichsweikamp
parents:
diff changeset
1847
heinrichsweikamp
parents:
diff changeset
1848 if( 0.0 < temp1 && temp1 < 1.0 )
heinrichsweikamp
parents:
diff changeset
1849 {
heinrichsweikamp
parents:
diff changeset
1850 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested.
heinrichsweikamp
parents:
diff changeset
1851 // minus because log is negative.
heinrichsweikamp
parents:
diff changeset
1852 temp1 = log(1.0 - temp1) / -0.6931; // temp1 is the multiples of half times necessary.
heinrichsweikamp
parents:
diff changeset
1853 temp2 = var_N2_ht * temp1 / float_desaturation_multiplier; // time necessary (in minutes ) for complete desaturation (see comment about 5 percent)
heinrichsweikamp
parents:
diff changeset
1854 }
heinrichsweikamp
parents:
diff changeset
1855 else
heinrichsweikamp
parents:
diff changeset
1856 {
heinrichsweikamp
parents:
diff changeset
1857 temp1 = 0.0;
heinrichsweikamp
parents:
diff changeset
1858 temp2 = 0.0;
heinrichsweikamp
parents:
diff changeset
1859 }
heinrichsweikamp
parents:
diff changeset
1860
heinrichsweikamp
parents:
diff changeset
1861 // He
heinrichsweikamp
parents:
diff changeset
1862 temp3 = 0.1 - pres_tissue_He[ci];
heinrichsweikamp
parents:
diff changeset
1863 if (temp3 >= 0.0)
heinrichsweikamp
parents:
diff changeset
1864 temp3 = 0.0;
heinrichsweikamp
parents:
diff changeset
1865 else
heinrichsweikamp
parents:
diff changeset
1866 temp3 = - temp3 / pres_tissue_He[ci];
heinrichsweikamp
parents:
diff changeset
1867
heinrichsweikamp
parents:
diff changeset
1868 if( 0.0 < temp3 && temp3 < 1.0 )
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1869 {
0
heinrichsweikamp
parents:
diff changeset
1870 temp3 = log(1.0 - temp3) / -0.6931; // temp1 is the multiples of half times necessary.
heinrichsweikamp
parents:
diff changeset
1871 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested.
heinrichsweikamp
parents:
diff changeset
1872 // minus because log is negative
heinrichsweikamp
parents:
diff changeset
1873 temp4 = var_He_ht * temp3 / float_desaturation_multiplier; // time necessary (in minutes ) for "complete" desaturation, new in v.101 float_desaturation_multiplier
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1874 }
0
heinrichsweikamp
parents:
diff changeset
1875 else
287
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1876 {
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1877 temp3 = 0.0;
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1878 temp4 = 0.0;
f342853afcd9 FIX gas_volumes: shall take stops in forward order.
jdg@air
parents: 284
diff changeset
1879 }
0
heinrichsweikamp
parents:
diff changeset
1880
heinrichsweikamp
parents:
diff changeset
1881 // saturation_time (for flight)
heinrichsweikamp
parents:
diff changeset
1882 if (temp4 > temp2)
heinrichsweikamp
parents:
diff changeset
1883 desat_time = (unsigned short)temp4;
heinrichsweikamp
parents:
diff changeset
1884 else
heinrichsweikamp
parents:
diff changeset
1885 desat_time = (unsigned short)temp2;
heinrichsweikamp
parents:
diff changeset
1886
heinrichsweikamp
parents:
diff changeset
1887 if(desat_time > int_O_desaturation_time)
heinrichsweikamp
parents:
diff changeset
1888 int_O_desaturation_time = desat_time;
heinrichsweikamp
parents:
diff changeset
1889
heinrichsweikamp
parents:
diff changeset
1890 // N2 saturation in multiples of halftime for display purposes
heinrichsweikamp
parents:
diff changeset
1891 temp2 = temp1 * 20.0; // 0 = 1/8, 120 = 0, 249 = 8
heinrichsweikamp
parents:
diff changeset
1892 temp2 = temp2 + 80.0; // set center
heinrichsweikamp
parents:
diff changeset
1893 if (temp2 < 0.0)
heinrichsweikamp
parents:
diff changeset
1894 temp2 = 0.0;
heinrichsweikamp
parents:
diff changeset
1895 if (temp2 > 255.0)
heinrichsweikamp
parents:
diff changeset
1896 temp2 = 255.0;
heinrichsweikamp
parents:
diff changeset
1897 char_O_tissue_N2_saturation[ci] = (char)temp2;
heinrichsweikamp
parents:
diff changeset
1898
heinrichsweikamp
parents:
diff changeset
1899 // He saturation in multiples of halftime for display purposes
heinrichsweikamp
parents:
diff changeset
1900 temp4 = temp3 * 20.0; // 0 = 1/8, 120 = 0, 249 = 8
heinrichsweikamp
parents:
diff changeset
1901 temp4 = temp4 + 80.0; // set center
heinrichsweikamp
parents:
diff changeset
1902 if (temp4 < 0.0)
heinrichsweikamp
parents:
diff changeset
1903 temp4 = 0.0;
heinrichsweikamp
parents:
diff changeset
1904 if (temp4 > 255.0)
heinrichsweikamp
parents:
diff changeset
1905 temp4 = 255.0;
heinrichsweikamp
parents:
diff changeset
1906 char_O_tissue_He_saturation[ci] = (char)temp4;
heinrichsweikamp
parents:
diff changeset
1907 } // for
heinrichsweikamp
parents:
diff changeset
1908 }
heinrichsweikamp
parents:
diff changeset
1909
heinrichsweikamp
parents:
diff changeset
1910 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1911 // calc_wo_deco_step_1_min
heinrichsweikamp
parents:
diff changeset
1912 //
heinrichsweikamp
parents:
diff changeset
1913 // FIXED N2 Ratio
heinrichsweikamp
parents:
diff changeset
1914 // optimized in v.101 (...saturation_multiplier)
heinrichsweikamp
parents:
diff changeset
1915 // desaturation slowed down to 70,42%
heinrichsweikamp
parents:
diff changeset
1916 //
heinrichsweikamp
parents:
diff changeset
1917 static void calc_wo_deco_step_1_min(void)
heinrichsweikamp
parents:
diff changeset
1918 {
heinrichsweikamp
parents:
diff changeset
1919 assert( 800 < int_I_pres_surface && int_I_pres_surface < 1100 );
heinrichsweikamp
parents:
diff changeset
1920 assert( 800 < int_I_pres_respiration && int_I_pres_respiration < 1100 );
heinrichsweikamp
parents:
diff changeset
1921 assert( 100 <= char_I_saturation_multiplier && char_I_saturation_multiplier < 200 );
heinrichsweikamp
parents:
diff changeset
1922 assert( 0 < char_I_desaturation_multiplier && char_I_desaturation_multiplier <= 100 );
heinrichsweikamp
parents:
diff changeset
1923
heinrichsweikamp
parents:
diff changeset
1924 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann
heinrichsweikamp
parents:
diff changeset
1925 pres_respiration = pres_surface = int_I_pres_surface * 0.001;
heinrichsweikamp
parents:
diff changeset
1926 ppN2 = N2_ratio * (pres_respiration - ppWater);
heinrichsweikamp
parents:
diff changeset
1927 ppHe = 0.0;
heinrichsweikamp
parents:
diff changeset
1928 float_desaturation_multiplier = char_I_desaturation_multiplier * (0.01 * SURFACE_DESAT_FACTOR);
heinrichsweikamp
parents:
diff changeset
1929 float_saturation_multiplier = char_I_saturation_multiplier * 0.01;
heinrichsweikamp
parents:
diff changeset
1930
heinrichsweikamp
parents:
diff changeset
1931 calc_tissue(1); // update the pressure in the tissues N2/He in accordance with the new ambient pressure
heinrichsweikamp
parents:
diff changeset
1932
heinrichsweikamp
parents:
diff changeset
1933 clear_deco_table();
heinrichsweikamp
parents:
diff changeset
1934 char_O_deco_status = 3; // surface new in v.102 : stays in surface state.
heinrichsweikamp
parents:
diff changeset
1935 char_O_nullzeit = 0;
heinrichsweikamp
parents:
diff changeset
1936 int_O_ascenttime = 0;
heinrichsweikamp
parents:
diff changeset
1937 int_O_extra_ascenttime = 0;
heinrichsweikamp
parents:
diff changeset
1938 calc_gradient_factor();
heinrichsweikamp
parents:
diff changeset
1939 }
heinrichsweikamp
parents:
diff changeset
1940
heinrichsweikamp
parents:
diff changeset
1941 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1942 // calc_dive_interval
heinrichsweikamp
parents:
diff changeset
1943 //
heinrichsweikamp
parents:
diff changeset
1944 // Prepare tissue for delay before the next dive simulation.
heinrichsweikamp
parents:
diff changeset
1945 //
heinrichsweikamp
parents:
diff changeset
1946 // Inputs: char_I_dive_interval == delay before dive (in 10' steps).
heinrichsweikamp
parents:
diff changeset
1947 // Outputs: pres_tissue_N2/He[], CNS_fraction
heinrichsweikamp
parents:
diff changeset
1948 //
heinrichsweikamp
parents:
diff changeset
1949 // Should be protected by deco_push_tissues_to_vault(),
heinrichsweikamp
parents:
diff changeset
1950 // deco_pull_tissues_from_vault()
heinrichsweikamp
parents:
diff changeset
1951 //
heinrichsweikamp
parents:
diff changeset
1952 // desaturation slowed down to 70,42%.
heinrichsweikamp
parents:
diff changeset
1953 //
heinrichsweikamp
parents:
diff changeset
1954 static void calc_dive_interval(void)
heinrichsweikamp
parents:
diff changeset
1955 {
heinrichsweikamp
parents:
diff changeset
1956 overlay unsigned char t;
521
06e9370c6d75 CHANGE: Apply safety margin parameters to both models (GF and non-GF)
heinrichsweikamp
parents: 519
diff changeset
1957
0
heinrichsweikamp
parents:
diff changeset
1958 //---- Initialize simulation parameters ----------------------------------
heinrichsweikamp
parents:
diff changeset
1959 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann
heinrichsweikamp
parents:
diff changeset
1960 pres_respiration = pres_surface = int_I_pres_surface * 0.001;
heinrichsweikamp
parents:
diff changeset
1961 ppN2 = N2_ratio * (pres_respiration - ppWater);
heinrichsweikamp
parents:
diff changeset
1962 ppHe = 0.0;
heinrichsweikamp
parents:
diff changeset
1963 float_desaturation_multiplier = char_I_desaturation_multiplier * (0.01 * SURFACE_DESAT_FACTOR);
heinrichsweikamp
parents:
diff changeset
1964 float_saturation_multiplier = char_I_saturation_multiplier * 0.01;
heinrichsweikamp
parents:
diff changeset
1965
heinrichsweikamp
parents:
diff changeset
1966 //---- Perform simulation ------------------------------------------------
heinrichsweikamp
parents:
diff changeset
1967 for(t=0; t<char_I_dive_interval; ++t)
heinrichsweikamp
parents:
diff changeset
1968 {
heinrichsweikamp
parents:
diff changeset
1969 calc_tissue(2); // period = 10min.
heinrichsweikamp
parents:
diff changeset
1970 CNS_fraction = 0.92587471 * CNS_fraction; // Half-time = 90min: (1/2)^(1/9)
heinrichsweikamp
parents:
diff changeset
1971 }
322
fe06f1d1a285 FIX 16bits CNS feedback: assert CNS up to 999%
jDG
parents: 313
diff changeset
1972 assert( 0.0 <= CNS_fraction && CNS_fraction <= 9.99 ); // 999 %
fe06f1d1a285 FIX 16bits CNS feedback: assert CNS up to 999%
jDG
parents: 313
diff changeset
1973 int_O_CNS_fraction = (unsigned short)(CNS_fraction * 100.0 + 0.5);
0
heinrichsweikamp
parents:
diff changeset
1974
heinrichsweikamp
parents:
diff changeset
1975 }
heinrichsweikamp
parents:
diff changeset
1976
heinrichsweikamp
parents:
diff changeset
1977 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1978 // deco_clear_CNS_fraction
heinrichsweikamp
parents:
diff changeset
1979 //
heinrichsweikamp
parents:
diff changeset
1980 // new in v.101
heinrichsweikamp
parents:
diff changeset
1981 //
heinrichsweikamp
parents:
diff changeset
1982 void deco_clear_CNS_fraction(void)
heinrichsweikamp
parents:
diff changeset
1983 {
heinrichsweikamp
parents:
diff changeset
1984 RESET_C_STACK
heinrichsweikamp
parents:
diff changeset
1985
heinrichsweikamp
parents:
diff changeset
1986 CNS_fraction = 0.0;
heinrichsweikamp
parents:
diff changeset
1987 int_O_CNS_fraction = 0;
heinrichsweikamp
parents:
diff changeset
1988 }
heinrichsweikamp
parents:
diff changeset
1989
heinrichsweikamp
parents:
diff changeset
1990 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
1991 // deco_calc_CNS_fraction
heinrichsweikamp
parents:
diff changeset
1992 //
heinrichsweikamp
parents:
diff changeset
1993 // Input: char_I_actual_ppO2 : Current condition (in decibars).
heinrichsweikamp
parents:
diff changeset
1994 // char_I_step_is_1min : use 1min or 10min steps instead of 2sec.
heinrichsweikamp
parents:
diff changeset
1995 // CNS_fraction : velue before period.
heinrichsweikamp
parents:
diff changeset
1996 // Output: CNS_fraction, int_O_CNS_fraction
heinrichsweikamp
parents:
diff changeset
1997 //
heinrichsweikamp
parents:
diff changeset
1998 void deco_calc_CNS_fraction(void)
heinrichsweikamp
parents:
diff changeset
1999 {
heinrichsweikamp
parents:
diff changeset
2000 overlay float time_factor = 1.0f;
heinrichsweikamp
parents:
diff changeset
2001 RESET_C_STACK
heinrichsweikamp
parents:
diff changeset
2002
322
fe06f1d1a285 FIX 16bits CNS feedback: assert CNS up to 999%
jDG
parents: 313
diff changeset
2003 assert( 0.0 <= CNS_fraction && CNS_fraction <= 9.99 );
0
heinrichsweikamp
parents:
diff changeset
2004 assert( char_I_actual_ppO2 > 15 );
heinrichsweikamp
parents:
diff changeset
2005
heinrichsweikamp
parents:
diff changeset
2006 if( char_I_step_is_1min == 1 )
heinrichsweikamp
parents:
diff changeset
2007 time_factor = 30.0f;
heinrichsweikamp
parents:
diff changeset
2008 else if( char_I_step_is_1min == 2 )
heinrichsweikamp
parents:
diff changeset
2009 time_factor = 300.0f;
33
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2010 //------------------------------------------------------------------------
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2011 // Don't increase CNS below 0.5 bar, but keep it steady.
0
heinrichsweikamp
parents:
diff changeset
2012 if (char_I_actual_ppO2 < 50)
heinrichsweikamp
parents:
diff changeset
2013 ; // no changes
33
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2014 //------------------------------------------------------------------------
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2015 // Below (and including) 1.60 bar
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2016 else if (char_I_actual_ppO2 < 61)
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2017 CNS_fraction += time_factor/(-533.07 * char_I_actual_ppO2 + 54000.0);
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2018 else if (char_I_actual_ppO2 < 71)
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2019 CNS_fraction += time_factor/(-444.22 * char_I_actual_ppO2 + 48600.0);
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2020 else if (char_I_actual_ppO2 < 81)
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2021 CNS_fraction += time_factor/(-355.38 * char_I_actual_ppO2 + 42300.0);
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2022 else if (char_I_actual_ppO2 < 91)
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2023 CNS_fraction += time_factor/(-266.53 * char_I_actual_ppO2 + 35100.0);
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2024 else if (char_I_actual_ppO2 < 111)
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2025 CNS_fraction += time_factor/(-177.69 * char_I_actual_ppO2 + 27000.0);
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2026 else if (char_I_actual_ppO2 < 152)
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2027 CNS_fraction += time_factor/( -88.84 * char_I_actual_ppO2 + 17100.0);
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2028 else if (char_I_actual_ppO2 < 167)
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2029 CNS_fraction += time_factor/(-222.11 * char_I_actual_ppO2 + 37350.0);
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2030 //------------------------------------------------------------------------
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2031 // Arieli et all.(2002): Modeling pulmonary and CNS O2 toxicity:
322
fe06f1d1a285 FIX 16bits CNS feedback: assert CNS up to 999%
jDG
parents: 313
diff changeset
2032 // J Appl Physiol 92: 248--256, 2002, doi:10.1152/japplphysiol.00434.2001
33
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2033 // Formula (A1) based on value for 1.55 and c=20
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2034 // example calculation: Sqrt((1.7/1.55)^20)*0.000404
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2035 else if (char_I_actual_ppO2 < 172)
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2036 CNS_fraction += time_factor*0.00102;
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2037 else if (char_I_actual_ppO2 < 177)
0
heinrichsweikamp
parents:
diff changeset
2038 CNS_fraction += time_factor*0.00136;
33
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2039 else if (char_I_actual_ppO2 < 182)
0
heinrichsweikamp
parents:
diff changeset
2040 CNS_fraction += time_factor*0.00180;
33
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2041 else if (char_I_actual_ppO2 < 187)
0
heinrichsweikamp
parents:
diff changeset
2042 CNS_fraction += time_factor*0.00237;
33
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2043 else if (char_I_actual_ppO2 < 192)
0
heinrichsweikamp
parents:
diff changeset
2044 CNS_fraction += time_factor*0.00310;
33
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2045 else if (char_I_actual_ppO2 < 198)
0
heinrichsweikamp
parents:
diff changeset
2046 CNS_fraction += time_factor*0.00401;
33
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2047 else if (char_I_actual_ppO2 < 203)
0
heinrichsweikamp
parents:
diff changeset
2048 CNS_fraction += time_factor*0.00517;
33
5d4a4fb0e8a6 Bugfix: NOAA tables for CNS are in ATA, not bar
heinrichsweikamp
parents: 0
diff changeset
2049 else if (char_I_actual_ppO2 < 233)
0
heinrichsweikamp
parents:
diff changeset
2050 CNS_fraction += time_factor*0.0209;
heinrichsweikamp
parents:
diff changeset
2051 else
heinrichsweikamp
parents:
diff changeset
2052 CNS_fraction += time_factor*0.0482; // value for 2.5
heinrichsweikamp
parents:
diff changeset
2053
322
fe06f1d1a285 FIX 16bits CNS feedback: assert CNS up to 999%
jDG
parents: 313
diff changeset
2054 if( CNS_fraction > 9.99) // Limit display to 999%
0
heinrichsweikamp
parents:
diff changeset
2055 CNS_fraction = 9.99;
heinrichsweikamp
parents:
diff changeset
2056 if( CNS_fraction < 0.0 )
heinrichsweikamp
parents:
diff changeset
2057 CNS_fraction = 0.0;
heinrichsweikamp
parents:
diff changeset
2058
322
fe06f1d1a285 FIX 16bits CNS feedback: assert CNS up to 999%
jDG
parents: 313
diff changeset
2059 int_O_CNS_fraction = (unsigned short)(100.0 * CNS_fraction + 0.5);
0
heinrichsweikamp
parents:
diff changeset
2060 }
heinrichsweikamp
parents:
diff changeset
2061
heinrichsweikamp
parents:
diff changeset
2062 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
2063 // deco_calc_CNS_planning
heinrichsweikamp
parents:
diff changeset
2064 //
heinrichsweikamp
parents:
diff changeset
2065 // Compute CNS during predicted ascent.
heinrichsweikamp
parents:
diff changeset
2066 //
heinrichsweikamp
parents:
diff changeset
2067 // Note: Needs a call to deco_push_tissues_to_vault(),
heinrichsweikamp
parents:
diff changeset
2068 // deco_pull_tissues_from_vault() to avoid trashing everything...
heinrichsweikamp
parents:
diff changeset
2069 //
heinrichsweikamp
parents:
diff changeset
2070 // Input: CNS_fraction, char_O_deco_time[], char_O_deco_depth[]
heinrichsweikamp
parents:
diff changeset
2071 // Output: CNS_fraction, int_O_CNS_fraction
heinrichsweikamp
parents:
diff changeset
2072 //
heinrichsweikamp
parents:
diff changeset
2073 void deco_calc_CNS_planning(void)
heinrichsweikamp
parents:
diff changeset
2074 {
heinrichsweikamp
parents:
diff changeset
2075 overlay unsigned char backup_gas_last_depth;
heinrichsweikamp
parents:
diff changeset
2076 overlay unsigned char backup_gas_last_used;
heinrichsweikamp
parents:
diff changeset
2077 overlay unsigned short backup_dive_mins;
heinrichsweikamp
parents:
diff changeset
2078 overlay unsigned char backup_actual_ppO2;
heinrichsweikamp
parents:
diff changeset
2079
heinrichsweikamp
parents:
diff changeset
2080 RESET_C_STACK
heinrichsweikamp
parents:
diff changeset
2081
heinrichsweikamp
parents:
diff changeset
2082 // Backup state machine
heinrichsweikamp
parents:
diff changeset
2083 backup_gas_last_depth = sim_gas_last_depth;
heinrichsweikamp
parents:
diff changeset
2084 backup_gas_last_used = sim_gas_last_used;
heinrichsweikamp
parents:
diff changeset
2085 backup_dive_mins = sim_dive_mins;
heinrichsweikamp
parents:
diff changeset
2086 backup_actual_ppO2 = char_I_actual_ppO2;
heinrichsweikamp
parents:
diff changeset
2087
heinrichsweikamp
parents:
diff changeset
2088 // Uses 1min CNS period:
heinrichsweikamp
parents:
diff changeset
2089 char_I_step_is_1min = 1;
heinrichsweikamp
parents:
diff changeset
2090
heinrichsweikamp
parents:
diff changeset
2091 //---- Retrieve bottom Gas used, and set variables.
heinrichsweikamp
parents:
diff changeset
2092 sim_gas_last_used = char_I_first_gas;
heinrichsweikamp
parents:
diff changeset
2093 sim_gas_last_depth = 0; // Surface gas marker.
heinrichsweikamp
parents:
diff changeset
2094 gas_switch_set(); // Sets initial calc_N2/He_ratio
heinrichsweikamp
parents:
diff changeset
2095
heinrichsweikamp
parents:
diff changeset
2096 //---- CCR mode : do the full TTS at once --------------------------------
heinrichsweikamp
parents:
diff changeset
2097 if( char_I_const_ppO2 != 0 )
heinrichsweikamp
parents:
diff changeset
2098 {
heinrichsweikamp
parents:
diff changeset
2099 overlay unsigned short t; // Needs 16bits here !
heinrichsweikamp
parents:
diff changeset
2100 char_I_actual_ppO2 = char_I_const_ppO2;
heinrichsweikamp
parents:
diff changeset
2101 for(t=0; t<int_O_ascenttime; ++t)
heinrichsweikamp
parents:
diff changeset
2102 deco_calc_CNS_fraction();
heinrichsweikamp
parents:
diff changeset
2103 }
heinrichsweikamp
parents:
diff changeset
2104 else //---- OC mode : have to follow all gas switches... -----------------
heinrichsweikamp
parents:
diff changeset
2105 {
heinrichsweikamp
parents:
diff changeset
2106 overlay unsigned char i = 0; // Decostop loop counter
heinrichsweikamp
parents:
diff changeset
2107 overlay float actual_ppO2;
heinrichsweikamp
parents:
diff changeset
2108 overlay unsigned char time, t;
heinrichsweikamp
parents:
diff changeset
2109
heinrichsweikamp
parents:
diff changeset
2110 //---- Ascent to surface delay
heinrichsweikamp
parents:
diff changeset
2111 // NOTE: count as if time is spent with bottom pressure,
heinrichsweikamp
parents:
diff changeset
2112 // AND the bottom gas
heinrichsweikamp
parents:
diff changeset
2113 actual_ppO2 = (pres_surface + char_I_bottom_depth * METER_TO_BAR)
heinrichsweikamp
parents:
diff changeset
2114 * (1.0 - calc_N2_ratio - calc_He_ratio);
heinrichsweikamp
parents:
diff changeset
2115 if( actual_ppO2 < 0.0 ) actual_ppO2 = 0.0;
heinrichsweikamp
parents:
diff changeset
2116 if( actual_ppO2 > 2.50 ) actual_ppO2 = 2.55;
heinrichsweikamp
parents:
diff changeset
2117 char_I_actual_ppO2 = (unsigned char)(100.0 * actual_ppO2 + 0.5);
heinrichsweikamp
parents:
diff changeset
2118
heinrichsweikamp
parents:
diff changeset
2119 // Ascent time (rounded up):
heinrichsweikamp
parents:
diff changeset
2120 time = (unsigned char)(0.1 * char_I_bottom_depth + 0.5);
heinrichsweikamp
parents:
diff changeset
2121
heinrichsweikamp
parents:
diff changeset
2122 for(t=0; t<time; ++t)
heinrichsweikamp
parents:
diff changeset
2123 {
heinrichsweikamp
parents:
diff changeset
2124 deco_calc_CNS_fraction();
heinrichsweikamp
parents:
diff changeset
2125 sim_dive_mins++;
heinrichsweikamp
parents:
diff changeset
2126 }
heinrichsweikamp
parents:
diff changeset
2127
heinrichsweikamp
parents:
diff changeset
2128 //---- Do all further stops ------------------------------------------
heinrichsweikamp
parents:
diff changeset
2129 for(i=0; i<NUM_STOPS; ++i)
heinrichsweikamp
parents:
diff changeset
2130 {
111
c61b7a4e317c Bugfix: CNS in planner
heinrichsweikamp
parents: 34
diff changeset
2131 overlay unsigned char stop_gas;
0
heinrichsweikamp
parents:
diff changeset
2132
210
7dbc1d780ca5 do not clear char_O_deco_gas in copy_deco_table
heinrichsweikamp
parents: 135
diff changeset
2133 //---- Get next stop ---------------------------------------------
0
heinrichsweikamp
parents:
diff changeset
2134 {
heinrichsweikamp
parents:
diff changeset
2135 time = char_O_deco_time[(NUM_STOPS-1)-i];
heinrichsweikamp
parents:
diff changeset
2136 temp_depth_limit = char_O_deco_depth[(NUM_STOPS-1)-i];
111
c61b7a4e317c Bugfix: CNS in planner
heinrichsweikamp
parents: 34
diff changeset
2137 stop_gas = char_O_deco_gas[(NUM_STOPS-1)-i];
0
heinrichsweikamp
parents:
diff changeset
2138 }
heinrichsweikamp
parents:
diff changeset
2139 if( time == 0 ) continue;
heinrichsweikamp
parents:
diff changeset
2140
heinrichsweikamp
parents:
diff changeset
2141 //---- Gas Switch ? ----------------------------------------------
111
c61b7a4e317c Bugfix: CNS in planner
heinrichsweikamp
parents: 34
diff changeset
2142 if( stop_gas != sim_gas_last_used )
0
heinrichsweikamp
parents:
diff changeset
2143 {
111
c61b7a4e317c Bugfix: CNS in planner
heinrichsweikamp
parents: 34
diff changeset
2144 sim_gas_last_depth = deco_gas_change[stop_gas-1];
c61b7a4e317c Bugfix: CNS in planner
heinrichsweikamp
parents: 34
diff changeset
2145 sim_gas_last_used = stop_gas;
0
heinrichsweikamp
parents:
diff changeset
2146 gas_switch_set();
heinrichsweikamp
parents:
diff changeset
2147 }
heinrichsweikamp
parents:
diff changeset
2148
heinrichsweikamp
parents:
diff changeset
2149 //---- Convert Depth and N2_ratio to ppO2 ------------------------
heinrichsweikamp
parents:
diff changeset
2150 actual_ppO2 = (pres_surface + temp_depth_limit * METER_TO_BAR)
heinrichsweikamp
parents:
diff changeset
2151 * (1.0 - calc_N2_ratio - calc_He_ratio);
heinrichsweikamp
parents:
diff changeset
2152 if( actual_ppO2 < 0.0 ) actual_ppO2 = 0.0;
heinrichsweikamp
parents:
diff changeset
2153 if( actual_ppO2 > 2.50 ) actual_ppO2 = 2.55;
heinrichsweikamp
parents:
diff changeset
2154 char_I_actual_ppO2 = (unsigned char)(100.0 * actual_ppO2 + 0.5);
heinrichsweikamp
parents:
diff changeset
2155
heinrichsweikamp
parents:
diff changeset
2156 //---- Apply the stop
heinrichsweikamp
parents:
diff changeset
2157 for(t=0; t<time; ++t)
heinrichsweikamp
parents:
diff changeset
2158 {
heinrichsweikamp
parents:
diff changeset
2159 deco_calc_CNS_fraction();
heinrichsweikamp
parents:
diff changeset
2160 sim_dive_mins++;
heinrichsweikamp
parents:
diff changeset
2161 }
heinrichsweikamp
parents:
diff changeset
2162 }
heinrichsweikamp
parents:
diff changeset
2163 }
heinrichsweikamp
parents:
diff changeset
2164
heinrichsweikamp
parents:
diff changeset
2165 //---- Back to normal mode... --------------------------------------------
heinrichsweikamp
parents:
diff changeset
2166 char_I_step_is_1min = 0;
heinrichsweikamp
parents:
diff changeset
2167 sim_gas_last_depth = backup_gas_last_depth;
heinrichsweikamp
parents:
diff changeset
2168 sim_gas_last_used = backup_gas_last_used;
heinrichsweikamp
parents:
diff changeset
2169 sim_dive_mins = backup_dive_mins;
heinrichsweikamp
parents:
diff changeset
2170 char_I_actual_ppO2 = backup_actual_ppO2;
heinrichsweikamp
parents:
diff changeset
2171 }
heinrichsweikamp
parents:
diff changeset
2172
heinrichsweikamp
parents:
diff changeset
2173 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
2174 // deco_calc_CNS_decrease_15min
heinrichsweikamp
parents:
diff changeset
2175 //
heinrichsweikamp
parents:
diff changeset
2176 // new in v.101
heinrichsweikamp
parents:
diff changeset
2177 //
heinrichsweikamp
parents:
diff changeset
2178 // calculates the half time of 90 minutes in 6 steps of 15 min
heinrichsweikamp
parents:
diff changeset
2179 // (Used in sleepmode, for low battery mode).
heinrichsweikamp
parents:
diff changeset
2180 //
heinrichsweikamp
parents:
diff changeset
2181 // Output: int_O_CNS_fraction
heinrichsweikamp
parents:
diff changeset
2182 // Uses and Updates: CNS_fraction
heinrichsweikamp
parents:
diff changeset
2183 //
heinrichsweikamp
parents:
diff changeset
2184 void deco_calc_CNS_decrease_15min(void)
heinrichsweikamp
parents:
diff changeset
2185 {
heinrichsweikamp
parents:
diff changeset
2186 RESET_C_STACK
322
fe06f1d1a285 FIX 16bits CNS feedback: assert CNS up to 999%
jDG
parents: 313
diff changeset
2187 assert( 0.0 <= CNS_fraction && CNS_fraction <= 9.99 );
0
heinrichsweikamp
parents:
diff changeset
2188
heinrichsweikamp
parents:
diff changeset
2189 CNS_fraction = 0.890899 * CNS_fraction;
322
fe06f1d1a285 FIX 16bits CNS feedback: assert CNS up to 999%
jDG
parents: 313
diff changeset
2190 int_O_CNS_fraction = (unsigned short)(CNS_fraction * 100.0 + 0.5);
0
heinrichsweikamp
parents:
diff changeset
2191 }
heinrichsweikamp
parents:
diff changeset
2192
heinrichsweikamp
parents:
diff changeset
2193 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
2194 // deco_calc_percentage
heinrichsweikamp
parents:
diff changeset
2195 //
heinrichsweikamp
parents:
diff changeset
2196 // new in v.101
heinrichsweikamp
parents:
diff changeset
2197 //
heinrichsweikamp
parents:
diff changeset
2198 // calculates int_I_temp * char_I_temp / 100
heinrichsweikamp
parents:
diff changeset
2199 // output is int_I_temp
heinrichsweikamp
parents:
diff changeset
2200 //
heinrichsweikamp
parents:
diff changeset
2201 // Used to compute NoFly remaining time.
heinrichsweikamp
parents:
diff changeset
2202 //
heinrichsweikamp
parents:
diff changeset
2203 void deco_calc_percentage(void)
heinrichsweikamp
parents:
diff changeset
2204 {
heinrichsweikamp
parents:
diff changeset
2205 RESET_C_STACK
heinrichsweikamp
parents:
diff changeset
2206
heinrichsweikamp
parents:
diff changeset
2207 assert( 60 <= char_I_temp && char_I_temp <= 100 );
heinrichsweikamp
parents:
diff changeset
2208 assert( int_I_temp < 5760 ); // Less than 4 days = 96h...
heinrichsweikamp
parents:
diff changeset
2209
heinrichsweikamp
parents:
diff changeset
2210 int_I_temp = (unsigned short)(((float)int_I_temp * (float)char_I_temp) * 0.01 );
heinrichsweikamp
parents:
diff changeset
2211
heinrichsweikamp
parents:
diff changeset
2212 assert( int_I_temp < 5760 ); // Less than 96h too...
heinrichsweikamp
parents:
diff changeset
2213 }
heinrichsweikamp
parents:
diff changeset
2214
heinrichsweikamp
parents:
diff changeset
2215 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
2216 // deco_gas_volumes
heinrichsweikamp
parents:
diff changeset
2217 //
heinrichsweikamp
parents:
diff changeset
2218 // new in v.111
heinrichsweikamp
parents:
diff changeset
2219 //
heinrichsweikamp
parents:
diff changeset
2220 // calculates volumes for each gas.
heinrichsweikamp
parents:
diff changeset
2221 //
heinrichsweikamp
parents:
diff changeset
2222 // Input: char_I_bottom_depth, char_I_bottom_time for planned dive.
heinrichsweikamp
parents:
diff changeset
2223 // Gas list.
heinrichsweikamp
parents:
diff changeset
2224 // char_I_first_gas is the bottom gas.
heinrichsweikamp
parents:
diff changeset
2225 // decoplan (char_O_deco_depth, char_O_deco_time).
298
2fe34fc0e2ae new submenu for gas consumption, show actual mix instead of GAS1-GAS5 in deco planner
heinrichsweikamp
parents: 289
diff changeset
2226 // char_I_bottom_usage is bottom liters/minutes (5 .. 50) or bar/min.
2fe34fc0e2ae new submenu for gas consumption, show actual mix instead of GAS1-GAS5 in deco planner
heinrichsweikamp
parents: 289
diff changeset
2227 // char_I_deco_usage is deco liters/minutes (5 .. 50) or bar/min.
0
heinrichsweikamp
parents:
diff changeset
2228 // Output: int_O_gas_volumes[0..4] in litters * 0.1
heinrichsweikamp
parents:
diff changeset
2229 //
heinrichsweikamp
parents:
diff changeset
2230 void deco_gas_volumes(void)
heinrichsweikamp
parents:
diff changeset
2231 {
heinrichsweikamp
parents:
diff changeset
2232 overlay float volumes[NUM_GAS];
heinrichsweikamp
parents:
diff changeset
2233 overlay float bottom_usage, deco_usage;
135
heinrichsweikamp
parents: 133
diff changeset
2234 overlay unsigned char i;
0
heinrichsweikamp
parents:
diff changeset
2235 overlay unsigned char gas, depth;
348
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2236 overlay unsigned char lastGasStop;
0
heinrichsweikamp
parents:
diff changeset
2237 RESET_C_STACK
heinrichsweikamp
parents:
diff changeset
2238
289
30edd177016a [mq]: 2015-05-29_02-40-44_r288+.diff
jdg@air
parents: 288
diff changeset
2239 //---- initialize --------------------------------------------------------
0
heinrichsweikamp
parents:
diff changeset
2240 for(i=0; i<NUM_GAS; ++i) // Nothing yet...
heinrichsweikamp
parents:
diff changeset
2241 volumes[i] = 0.0;
heinrichsweikamp
parents:
diff changeset
2242
298
2fe34fc0e2ae new submenu for gas consumption, show actual mix instead of GAS1-GAS5 in deco planner
heinrichsweikamp
parents: 289
diff changeset
2243 bottom_usage = char_I_bottom_usage; // In liter/minutes.
2fe34fc0e2ae new submenu for gas consumption, show actual mix instead of GAS1-GAS5 in deco planner
heinrichsweikamp
parents: 289
diff changeset
2244 deco_usage = char_I_deco_usage; // In liter/minutes.
289
30edd177016a [mq]: 2015-05-29_02-40-44_r288+.diff
jdg@air
parents: 288
diff changeset
2245
30edd177016a [mq]: 2015-05-29_02-40-44_r288+.diff
jdg@air
parents: 288
diff changeset
2246 // Early return if not defined:
30edd177016a [mq]: 2015-05-29_02-40-44_r288+.diff
jdg@air
parents: 288
diff changeset
2247 if( deco_usage <= 0.0 || bottom_usage <= 0.0 )
30edd177016a [mq]: 2015-05-29_02-40-44_r288+.diff
jdg@air
parents: 288
diff changeset
2248 goto done;
30edd177016a [mq]: 2015-05-29_02-40-44_r288+.diff
jdg@air
parents: 288
diff changeset
2249
30edd177016a [mq]: 2015-05-29_02-40-44_r288+.diff
jdg@air
parents: 288
diff changeset
2250 //---- Bottom usage -----------------------------------------------------
0
heinrichsweikamp
parents:
diff changeset
2251 assert(1 <= char_I_first_gas && char_I_first_gas <= NUM_GAS);
heinrichsweikamp
parents:
diff changeset
2252 gas = char_I_first_gas - 1;
heinrichsweikamp
parents:
diff changeset
2253
289
30edd177016a [mq]: 2015-05-29_02-40-44_r288+.diff
jdg@air
parents: 288
diff changeset
2254 if( char_I_const_ppO2 == 0 )
0
heinrichsweikamp
parents:
diff changeset
2255 volumes[gas]
heinrichsweikamp
parents:
diff changeset
2256 = (char_I_bottom_depth*0.1 + 1.0) // Use Psurface = 1.0 bar.
heinrichsweikamp
parents:
diff changeset
2257 * char_I_bottom_time // in minutes.
heinrichsweikamp
parents:
diff changeset
2258 * bottom_usage; // In liter/minutes.
heinrichsweikamp
parents:
diff changeset
2259
heinrichsweikamp
parents:
diff changeset
2260 //---- Ascent usage ------------------------------------------------------
351
de8c45fb2ab9 BUGFIX gas volume: do not forget deco gas with switch >= dive's bottom depth.
jdg@air
parents: 348
diff changeset
2261 depth = char_I_bottom_depth;
de8c45fb2ab9 BUGFIX gas volume: do not forget deco gas with switch >= dive's bottom depth.
jdg@air
parents: 348
diff changeset
2262 lastGasStop = 255; // Allow deco gas at or below bottom depth
0
heinrichsweikamp
parents:
diff changeset
2263
heinrichsweikamp
parents:
diff changeset
2264 for(i=0; i<NUM_STOPS; ++i)
heinrichsweikamp
parents:
diff changeset
2265 {
348
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2266 overlay unsigned char newDepth, time;
0
heinrichsweikamp
parents:
diff changeset
2267
348
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2268 time = char_O_deco_time [i];
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2269 if( time == 0 ) break; // End of table: done.
0
heinrichsweikamp
parents:
diff changeset
2270
288
08986d479b94 FIX gas_volume shall read gas switches from char_O_deco_gas
jdg@air
parents: 287
diff changeset
2271 newDepth = char_O_deco_depth[i];
348
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2272 assert(0 < newDepth && newDepth <= depth);
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2273
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2274 //---- Any gas switch before this stop -------------------------------
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2275 for(;;)
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2276 {
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2277 overlay unsigned char newGas = 0;
351
de8c45fb2ab9 BUGFIX gas volume: do not forget deco gas with switch >= dive's bottom depth.
jdg@air
parents: 348
diff changeset
2278 overlay unsigned char newStop = 0; // Mark as NO CHANGE yet
348
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2279 overlay unsigned char j;
288
08986d479b94 FIX gas_volume shall read gas switches from char_O_deco_gas
jdg@air
parents: 287
diff changeset
2280
348
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2281 for(j=0; j<NUM_GAS; ++j)
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2282 {
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2283 // Skip gas without changing depth:
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2284 if( ! char_I_deco_gas_change[j] )
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2285 continue;
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2286 // Select gas changed between [newDepth .. lastGasStop[
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2287 // Note that <= means changing gas at BEGINNING of this stop.
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2288 // Note that < means we cant use the same gas twice
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2289 if( newDepth <= char_I_deco_gas_change[j]
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2290 && char_I_deco_gas_change[j] < lastGasStop )
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2291 {
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2292 // Keep the DEEPEST gas in that range:
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2293 if( char_I_deco_gas_change[j] >= newStop )
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2294 {
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2295 newGas = j;
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2296 newStop = char_I_deco_gas_change[j];
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2297 }
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2298 }
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2299 }
0
heinrichsweikamp
parents:
diff changeset
2300
348
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2301 // Did we find something ?
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2302 if( !newStop )
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2303 break;
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2304
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2305 //---- usage BEFORE gas switch (if any), at 10m/min :
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2306 if( depth > newStop )
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2307 // Plus usage during ascent to the next stop, at 10m/min.
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2308 volumes[gas] += ((depth+newStop)*0.05 + 1.0) // average depth --> bar.
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2309 * (depth-newStop)*0.1 // metre --> min
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2310 * deco_usage;
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2311
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2312 //---- Do gas switch:
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2313 gas = newGas;
0
heinrichsweikamp
parents:
diff changeset
2314
348
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2315 lastGasStop = newStop; // Mark last used gas
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2316 if( newStop < depth ) // ascent to gas switch,
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2317 depth = newStop;
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2318 }
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2319
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2320 // Are we back to gas from the deco list (just in case):
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2321 assert(gas == char_O_deco_gas[i]-1);
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2322
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2323 //---- usage AFTER gas switch (if any), at 10m/min :
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2324 if( depth > newDepth )
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2325 volumes[gas] += ((depth+newDepth)*0.05 + 1.0) // average depth --> bar.
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2326 * (depth-newDepth)*0.1 // metre --> min
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2327 * deco_usage;
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2328
fca4f9de5f4a [FIX] GasVolume: missing gas changes w/o stops.
jDG
parents: 342
diff changeset
2329 //---- Do stop:
0
heinrichsweikamp
parents:
diff changeset
2330 depth = newDepth;
heinrichsweikamp
parents:
diff changeset
2331
289
30edd177016a [mq]: 2015-05-29_02-40-44_r288+.diff
jdg@air
parents: 288
diff changeset
2332 //---- Usage at stop:
30edd177016a [mq]: 2015-05-29_02-40-44_r288+.diff
jdg@air
parents: 288
diff changeset
2333 volumes[gas] += (depth*0.1 + 1.0) // depth --> bar.
30edd177016a [mq]: 2015-05-29_02-40-44_r288+.diff
jdg@air
parents: 288
diff changeset
2334 * time // in minutes.
30edd177016a [mq]: 2015-05-29_02-40-44_r288+.diff
jdg@air
parents: 288
diff changeset
2335 * deco_usage; // in xxx / min @ 1bar.
0
heinrichsweikamp
parents:
diff changeset
2336 }
heinrichsweikamp
parents:
diff changeset
2337
heinrichsweikamp
parents:
diff changeset
2338 // From last stop to surface
289
30edd177016a [mq]: 2015-05-29_02-40-44_r288+.diff
jdg@air
parents: 288
diff changeset
2339 volumes[gas] += (depth*0.05 + 1.0) // avg depth --> bar.
30edd177016a [mq]: 2015-05-29_02-40-44_r288+.diff
jdg@air
parents: 288
diff changeset
2340 * depth * 0.1 // time to surface, in minutes.
30edd177016a [mq]: 2015-05-29_02-40-44_r288+.diff
jdg@air
parents: 288
diff changeset
2341 * deco_usage; // in xxx / min @ 1bar.
0
heinrichsweikamp
parents:
diff changeset
2342
heinrichsweikamp
parents:
diff changeset
2343 //---- convert results for the ASM interface -----------------------------
289
30edd177016a [mq]: 2015-05-29_02-40-44_r288+.diff
jdg@air
parents: 288
diff changeset
2344 done:
0
heinrichsweikamp
parents:
diff changeset
2345 for(i=0; i<NUM_GAS; ++i)
heinrichsweikamp
parents:
diff changeset
2346 if( volumes[i] > 65534.0 )
heinrichsweikamp
parents:
diff changeset
2347 int_O_gas_volumes[i] = 65535;
heinrichsweikamp
parents:
diff changeset
2348 else
heinrichsweikamp
parents:
diff changeset
2349 int_O_gas_volumes[i] = (unsigned short)(volumes[i] + 0.5);
heinrichsweikamp
parents:
diff changeset
2350 }
heinrichsweikamp
parents:
diff changeset
2351
heinrichsweikamp
parents:
diff changeset
2352 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
2353
heinrichsweikamp
parents:
diff changeset
2354 void deco_push_tissues_to_vault(void)
heinrichsweikamp
parents:
diff changeset
2355 {
heinrichsweikamp
parents:
diff changeset
2356 overlay unsigned char x;
heinrichsweikamp
parents:
diff changeset
2357 RESET_C_STACK
heinrichsweikamp
parents:
diff changeset
2358
heinrichsweikamp
parents:
diff changeset
2359 cns_vault = CNS_fraction;
heinrichsweikamp
parents:
diff changeset
2360 low_depth_vault = low_depth;
heinrichsweikamp
parents:
diff changeset
2361
heinrichsweikamp
parents:
diff changeset
2362 for (x=0;x<NUM_COMP;x++)
heinrichsweikamp
parents:
diff changeset
2363 {
heinrichsweikamp
parents:
diff changeset
2364 pres_tissue_N2_vault[x] = pres_tissue_N2[x];
heinrichsweikamp
parents:
diff changeset
2365 pres_tissue_He_vault[x] = pres_tissue_He[x];
heinrichsweikamp
parents:
diff changeset
2366 }
heinrichsweikamp
parents:
diff changeset
2367 }
heinrichsweikamp
parents:
diff changeset
2368
heinrichsweikamp
parents:
diff changeset
2369 void deco_pull_tissues_from_vault(void)
heinrichsweikamp
parents:
diff changeset
2370 {
heinrichsweikamp
parents:
diff changeset
2371 overlay unsigned char x;
heinrichsweikamp
parents:
diff changeset
2372 RESET_C_STACK
heinrichsweikamp
parents:
diff changeset
2373
heinrichsweikamp
parents:
diff changeset
2374 for (x=0; x<NUM_COMP; x++)
heinrichsweikamp
parents:
diff changeset
2375 {
heinrichsweikamp
parents:
diff changeset
2376 pres_tissue_N2[x] = pres_tissue_N2_vault[x];
heinrichsweikamp
parents:
diff changeset
2377 pres_tissue_He[x] = pres_tissue_He_vault[x];
heinrichsweikamp
parents:
diff changeset
2378 }
heinrichsweikamp
parents:
diff changeset
2379
heinrichsweikamp
parents:
diff changeset
2380 // Restore both CNS variable, too.
heinrichsweikamp
parents:
diff changeset
2381 CNS_fraction = cns_vault;
322
fe06f1d1a285 FIX 16bits CNS feedback: assert CNS up to 999%
jDG
parents: 313
diff changeset
2382 int_O_CNS_fraction = (unsigned short)(CNS_fraction * 100.0 + 0.5);
0
heinrichsweikamp
parents:
diff changeset
2383
heinrichsweikamp
parents:
diff changeset
2384 // GF history too:
heinrichsweikamp
parents:
diff changeset
2385 low_depth = low_depth_vault;
heinrichsweikamp
parents:
diff changeset
2386 locked_GF_step = GF_delta / low_depth;
heinrichsweikamp
parents:
diff changeset
2387 }
heinrichsweikamp
parents:
diff changeset
2388
heinrichsweikamp
parents:
diff changeset
2389 //////////////////////////////////////////////////////////////////////////////
heinrichsweikamp
parents:
diff changeset
2390 //
heinrichsweikamp
parents:
diff changeset
2391 #ifndef CROSS_COMPILE
heinrichsweikamp
parents:
diff changeset
2392 void main() {}
heinrichsweikamp
parents:
diff changeset
2393 #endif