Mercurial > public > mk2
annotate code_part1/OSTC_code_c_part2/p2_deco.c @ 491:560764da0629
BUGFIX Surface desat factor missing for Interval planning in GF mode.
author | JeanDo |
---|---|
date | Fri, 04 Nov 2011 16:24:12 +0100 |
parents | 68aa097f0062 |
children | 103051b4d9c1 |
rev | line source |
---|---|
116 | 1 // ************************************************************** |
2 // p2_deco.c | |
3 // | |
4 // Created on: 12.05.2009 | |
5 // Author: chsw | |
6 // | |
7 // ************************************************************** | |
8 | |
9 ////////////////////////////////////////////////////////////////////////////// | |
10 // OSTC - diving computer code | |
11 // Copyright (C) 2008 HeinrichsWeikamp GbR | |
12 // | |
13 // This program is free software: you can redistribute it and/or modify | |
14 // it under the terms of the GNU General Public License as published by | |
15 // the Free Software Foundation, either version 3 of the License, or | |
16 // (at your option) any later version. | |
17 // | |
18 // This program is distributed in the hope that it will be useful, | |
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 // GNU General Public License for more details. | |
22 // | |
23 // You should have received a copy of the GNU General Public License | |
24 // along with this program. If not, see <http://www.gnu.org/licenses/>. | |
25 // | |
26 ////////////////////////////////////////////////////////////////////////////// | |
27 | |
28 // ***************************** | |
29 // ** I N T R O D U C T I O N ** | |
30 // ***************************** | |
31 // | |
32 // OSTC | |
33 // | |
34 // code: | |
35 // p2_deco_main_c_v101.c | |
36 // part2 of the OSTC code | |
37 // code with constant O2 partial pressure routines | |
38 // under construction !! | |
39 // | |
40 // summary: | |
41 // decompression routines | |
42 // for the OSTC experimental project | |
43 // written by Christian Weikamp | |
44 // last revision __________ | |
45 // comments added _________ | |
46 // | |
47 // additional files: | |
48 // p2_tables_v100.romdata (other files) | |
49 // 18f4685_ostc_v100.lkr (linker script) | |
50 // | |
51 // history: | |
52 // 01/03/08 v100: first release candidate | |
53 // 03/13/08 v101: start of programming ppO2 code | |
54 // 03/13/25 v101a: backup of interrim version with ppO2 calculation | |
55 // 03/13/25 v101: open circuit gas change during deco | |
56 // 03/13/25 v101: CNS_fraction calculation | |
57 // 03/13/26 v101: optimization of tissue calc routines | |
58 // 07/xx/08 v102a: debug of bottom time routine | |
59 // 09/xx/08 v102d: Gradient Factor Model implemenation | |
60 // 10/10/08 v104: renamed to build v103 for v118 stable | |
171 | 61 // 10/14/08 v104: integration of char_I_depth_last_deco for Gradient Model |
116 | 62 // 03/31/09 v107: integration of FONT Incon24 |
63 // 05/23/10 v109: 5 gas changes & 1 min timer | |
64 // 07/13/10 v110: cns vault added | |
65 // 12/25/10 v110: split in three files (deco.c, main.c, definitions.h) | |
163 | 66 // 2011/01/20: [jDG] Create a common file included in ASM and C code. |
167 | 67 // 2011/01/23: [jDG] Added read_custom_function(). |
203 | 68 // 2011/01/24: [jDG] Make ascenttime an short. No more overflow! |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
69 // 2011/01/25: [jDG] Fusion deco array for both models. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
70 // 2011/01/25: [jDG] Use CF(54) to reverse deco order. |
193 | 71 // 2011/02/11: [jDG] Reworked gradient-factor implementation. |
197 | 72 // 2011/02/13: [jDG] CF55 for additional gas switch delay in decoplan. |
275
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
73 // 2011/02/15: [jDG] Fixed inconsistencies introduced by gas switch delays. |
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
74 // 2011/03/21: [jDG] Added gas consumption (CF56 & CF57) evaluation for OCR mode. |
293
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
75 // 2011/04/10: [jDG] Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco(). |
275
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
76 // 2011/04/15: [jDG] Store low_depth in 32bits (w/o rounding), for a better stability. |
293
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
77 // 2011/04/25: [jDG] Added 1mn mode for CNS calculation, to allow it for decoplanning. |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
78 // 2011/04/27: [jDG] Fixed char_O_gradient_factor calculation when model uses gradient-factor. |
334
4ccdc72ec0e5
BUGFIX minor error in gas-switch algo (spurious surface decostop rarely added).
JeanDo
parents:
326
diff
changeset
|
79 // 2011/05/02: [jDG] Added "Future TTS" function (CF58). |
338 | 80 // 2011/05/17: [jDG] Various cleanups. |
116 | 81 // |
167 | 82 // TODO: |
83 // + Allow to abort MD2 calculation (have to restart next time). | |
84 // | |
85 // Literature: | |
200 | 86 // Bühlmann, Albert: Tauchmedizin; 4. Auflage [2002]; |
116 | 87 // 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 |
88 // Morrison, Stuart; 2000; DIY DECOMPRESSION; http://www.lizardland.co.uk/DIYDeco.html | |
89 // Balthasar, Steffen; Dekompressionstheorie I: Neo Haldane Modelle; http://www.txfreak.de/dekompressionstheorie_1.pdf | |
90 // Baker, Erik C.; Clearing Up The Confusion About "Deep Stops" | |
91 // Baker, Erik C.; Understanding M-values; http://www.txfreak.de/understanding_m-values.pdf | |
167 | 92 // |
93 // | |
116 | 94 |
95 // ********************* | |
96 // ** I N C L U D E S ** | |
97 // ********************* | |
98 #include <math.h> | |
167 | 99 |
192 | 100 // *********************************************** |
101 // ** V A R I A B L E S D E F I N I T I O N S ** | |
102 // *********************************************** | |
103 | |
104 #include "p2_definitions.h" | |
275
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
105 #define TEST_MAIN |
192 | 106 #include "shared_definitions.h" |
107 | |
200 | 108 // Water vapour partial pressure in the lumb. |
317 | 109 #define ppWater 0.0627 |
110 #define METER_TO_BAR 0.09985 | |
111 #define BAR_TO_METER 10.0150 // (1.0/METER_TO_BAR) | |
200 | 112 |
491
560764da0629
BUGFIX Surface desat factor missing for Interval planning in GF mode.
JeanDo
parents:
490
diff
changeset
|
113 // Surface security factor |
560764da0629
BUGFIX Surface desat factor missing for Interval planning in GF mode.
JeanDo
parents:
490
diff
changeset
|
114 #define SURFACE_DESAT_FACTOR 0.7042 |
560764da0629
BUGFIX Surface desat factor missing for Interval planning in GF mode.
JeanDo
parents:
490
diff
changeset
|
115 |
167 | 116 // ************************* |
117 // ** P R O T O T Y P E S ** | |
118 // ************************* | |
119 | |
120 static void calc_hauptroutine(void); | |
121 static void calc_nullzeit(void); | |
122 | |
192 | 123 static void calc_tissue(PARAMETER unsigned char period); |
258 | 124 static void calc_limit(void); |
192 | 125 |
167 | 126 static void clear_tissue(void); |
127 static void calc_ascenttime(void); | |
128 static void update_startvalues(void); | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
129 static void clear_deco_table(void); |
471 | 130 static unsigned char update_deco_table(void); |
192 | 131 |
132 static void backup_sim_pres_tissue(void); | |
133 static void restore_sim_pres_tissue(void); | |
134 static void sim_tissue(PARAMETER unsigned char period); | |
135 static void sim_limit(PARAMETER float GF_current); | |
312
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
136 static void sim_extra_time(void); |
368 | 137 static void calc_dive_interval(void); |
312
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
138 |
167 | 139 static void calc_gradient_factor(void); |
140 static void calc_wo_deco_step_1_min(void); | |
141 | |
142 static void calc_hauptroutine_data_input(void); | |
143 static void calc_hauptroutine_update_tissues(void); | |
144 static void calc_hauptroutine_calc_deco(void); | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
145 static void sim_ascent_to_first_stop(void); |
167 | 146 |
241 | 147 static unsigned char gas_switch_deepest(void); |
148 static void gas_switch_set(void); | |
217 | 149 |
241 | 150 static unsigned char calc_nextdecodepth(void); |
116 | 151 |
200 | 152 //---- Bank 4 parameters ----------------------------------------------------- |
163 | 153 #pragma udata bank4=0x400 |
116 | 154 |
155 static float temp_limit; | |
156 static float GF_low; | |
157 static float GF_high; | |
158 static float GF_delta; | |
275
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
159 static float low_depth; // Depth of deepest stop |
192 | 160 static float locked_GF_step; // GF_delta / low_depth |
161 | |
162 static unsigned char temp_depth_limit; | |
171 | 163 |
192 | 164 // Simulation context: used to predict ascent. |
165 static unsigned char sim_lead_tissue_no; // Leading compatiment number. | |
166 static float sim_lead_tissue_limit; // Buhlmann tolerated pressure. | |
116 | 167 |
192 | 168 // Real context: what we are doing now. |
169 static float calc_lead_tissue_limit; // | |
116 | 170 |
338 | 171 static unsigned char internal_deco_time[NUM_STOPS]; |
172 static unsigned char internal_deco_depth[NUM_STOPS]; | |
116 | 173 |
174 static float cns_vault; | |
339 | 175 static float pres_tissue_N2_vault[NUM_COMP]; |
176 static float pres_tissue_He_vault[NUM_COMP]; | |
116 | 177 |
163 | 178 //---- Bank 5 parameters ----------------------------------------------------- |
179 #pragma udata bank5=0x500 | |
180 | |
167 | 181 static unsigned char ci; |
116 | 182 static float pres_respiration; |
183 static float pres_surface; | |
184 static float temp_deco; | |
236 | 185 static float ppN2; |
200 | 186 static float ppHe; |
116 | 187 static float temp_tissue; |
200 | 188 static float N2_ratio; // Breathed gas nitrogen ratio. |
189 static float He_ratio; // Breathed gas helium ratio. | |
190 static float var_N2_a; // Bühlmann a, for current N2 tissue. | |
191 static float var_N2_b; // Bühlmann b, for current N2 tissue. | |
192 static float var_He_a; // Bühlmann a, for current He tissue. | |
193 static float var_He_b; // Bühlmann b, for current He tissue. | |
194 static float var_N2_e; // Exposition, for current N2 tissue. | |
195 static float var_He_e; // Exposition, for current He tissue. | |
116 | 196 |
338 | 197 static float pres_diluent; // new in v.101 |
198 static float const_ppO2; // new in v.101 | |
116 | 199 |
241 | 200 static unsigned char sim_gas_last_depth; // Depth of last used gas, to detected a gas switch. |
201 static unsigned char sim_gas_last_used; // Number of last used gas, to detected a gas switch. | |
203 | 202 static unsigned short sim_gas_delay; // Time of gas-switch-stop ends [min on dive]. |
203 static unsigned short sim_dive_mins; // Simulated dive time. | |
200 | 204 static float calc_N2_ratio; // Simulated (switched) nitrogen ratio. |
205 static float calc_He_ratio; // Simulated (switched) helium ratio. | |
206 static float CNS_fraction; // new in v.101 | |
207 static float float_saturation_multiplier; // new in v.101 | |
208 static float float_desaturation_multiplier; // new in v.101 | |
338 | 209 static float float_deco_distance; // new in v.101 |
210 static char flag_in_divemode; // new in v.108 | |
167 | 211 |
338 | 212 static unsigned char deco_gas_change[NUM_GAS]; // new in v.109 |
167 | 213 |
163 | 214 //---- Bank 6 parameters ----------------------------------------------------- |
215 #pragma udata bank6=0x600 | |
116 | 216 |
339 | 217 float pres_tissue_N2[NUM_COMP]; |
218 float pres_tissue_He[NUM_COMP]; | |
116 | 219 |
163 | 220 //---- Bank 7 parameters ----------------------------------------------------- |
221 #pragma udata bank7=0x700 | |
222 | |
339 | 223 float sim_pres_tissue_N2[NUM_COMP]; // 32 floats = 128 bytes. |
224 float sim_pres_tissue_He[NUM_COMP]; // 32 floats = 128 bytes. | |
225 static float sim_pres_tissue_backup_N2[NUM_COMP]; | |
226 static float sim_pres_tissue_backup_He[NUM_COMP]; | |
116 | 227 |
163 | 228 //---- Bank 8 parameters ----------------------------------------------------- |
116 | 229 #pragma udata bank8=0x800 |
163 | 230 |
116 | 231 static char md_pi_subst[256]; |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
232 #define C_STACK md_pi_subst // Overlay C-code data stack here, too. |
116 | 233 |
163 | 234 //---- Bank 9 parameters ----------------------------------------------------- |
167 | 235 #pragma udata bank9=0x900 |
116 | 236 |
163 | 237 static char md_state[48]; // DONT MOVE !! // has to be at the beginning of bank 9 for the asm code!!! |
116 | 238 |
164 | 239 // internal, dbg: |
167 | 240 static unsigned char DBG_char_I_deco_model; // new in v.108. |
164 | 241 static unsigned char DBG_char_I_depth_last_deco; // new in v.108 |
212 | 242 static unsigned char DBG_deco_gas_change; // new in v.108 |
224 | 243 static unsigned char DBG_deco_N2_ratio; // new in v.108 |
244 static unsigned char DBG_deco_He_ratio; // new in v.108 | |
164 | 245 static float DBG_pres_surface; // new in v.108 |
246 static float DBG_GF_low; // new in v.108 | |
247 static float DBG_GF_high; // new in v.108 | |
248 static float DBG_const_ppO2; // new in v.108 | |
249 static float DBG_float_saturation_multiplier; // new in v.108 | |
250 static float DBG_float_desaturation_multiplier; // new in v.108 | |
251 static float DBG_float_deco_distance; // new in v.108 | |
252 static float DBG_N2_ratio; // new in v.108 | |
253 static float DBG_He_ratio; // new in v.108 | |
254 | |
167 | 255 ////////////////////////////////////////////////////////////////////////////// |
256 ////////////////////////////////////////////////////////////////////////////// | |
257 ///////////////////////////// THE LOOKUP TABLES ////////////////////////////// | |
258 ////////////////////////////////////////////////////////////////////////////// | |
259 ////////////////////////////////////////////////////////////////////////////// | |
260 // | |
261 // End of PROM code is 17F00, So push tables on PROM top... | |
262 // | |
263 #pragma romdata buhlmann_tables = 0x017B00 // Needs to be in UPPER bank. | |
264 #include "p2_tables.romdata" // new table for deco_main_v.101 (var_N2_a modified) | |
116 | 265 |
167 | 266 // Magic table to compute the MD2 HASH |
267 // | |
268 #pragma romdata hash_tables = 0x017E00 // Address fixed by ASM access... | |
203 | 269 rom const rom unsigned short md_pi[] = |
116 | 270 { |
271 0x292E, 0x43C9, 0xA2D8, 0x7C01, 0x3D36, 0x54A1, 0xECF0, 0x0613 | |
272 , 0x62A7, 0x05F3, 0xC0C7, 0x738C, 0x9893, 0x2BD9, 0xBC4C, 0x82CA | |
273 , 0x1E9B, 0x573C, 0xFDD4, 0xE016, 0x6742, 0x6F18, 0x8A17, 0xE512 | |
274 , 0xBE4E, 0xC4D6, 0xDA9E, 0xDE49, 0xA0FB, 0xF58E, 0xBB2F, 0xEE7A | |
275 , 0xA968, 0x7991, 0x15B2, 0x073F, 0x94C2, 0x1089, 0x0B22, 0x5F21 | |
276 , 0x807F, 0x5D9A, 0x5A90, 0x3227, 0x353E, 0xCCE7, 0xBFF7, 0x9703 | |
277 , 0xFF19, 0x30B3, 0x48A5, 0xB5D1, 0xD75E, 0x922A, 0xAC56, 0xAAC6 | |
278 , 0x4FB8, 0x38D2, 0x96A4, 0x7DB6, 0x76FC, 0x6BE2, 0x9C74, 0x04F1 | |
279 , 0x459D, 0x7059, 0x6471, 0x8720, 0x865B, 0xCF65, 0xE62D, 0xA802 | |
280 , 0x1B60, 0x25AD, 0xAEB0, 0xB9F6, 0x1C46, 0x6169, 0x3440, 0x7E0F | |
281 , 0x5547, 0xA323, 0xDD51, 0xAF3A, 0xC35C, 0xF9CE, 0xBAC5, 0xEA26 | |
282 , 0x2C53, 0x0D6E, 0x8528, 0x8409, 0xD3DF, 0xCDF4, 0x4181, 0x4D52 | |
283 , 0x6ADC, 0x37C8, 0x6CC1, 0xABFA, 0x24E1, 0x7B08, 0x0CBD, 0xB14A | |
284 , 0x7888, 0x958B, 0xE363, 0xE86D, 0xE9CB, 0xD5FE, 0x3B00, 0x1D39 | |
285 , 0xF2EF, 0xB70E, 0x6658, 0xD0E4, 0xA677, 0x72F8, 0xEB75, 0x4B0A | |
286 , 0x3144, 0x50B4, 0x8FED, 0x1F1A, 0xDB99, 0x8D33, 0x9F11, 0x8314 | |
287 }; | |
288 | |
167 | 289 ////////////////////////////////////////////////////////////////////////////// |
290 ////////////////////////////////////////////////////////////////////////////// | |
291 ////////////////////////////// THE SUBROUTINES /////////////////////////////// | |
292 ////////////////////////////////////////////////////////////////////////////// | |
293 ////////////////////////////////////////////////////////////////////////////// | |
294 // | |
116 | 295 // all new in v.102 |
296 // moved from 0x0D000 to 0x0C000 in v.108 | |
297 | |
298 #pragma code p2_deco = 0x0C000 | |
299 | |
167 | 300 ////////////////////////////////////////////////////////////////////////////// |
301 // DBS - debug on start of dive | |
302 // | |
303 static void create_dbs_set_dbg_and_ndl20mtr(void) | |
116 | 304 { |
167 | 305 overlay char i; // Local loop index. |
306 | |
307 //---- Reset DEBUG bit fields -------------------------------------------- | |
116 | 308 int_O_DBS_bitfield = 0; |
309 int_O_DBS2_bitfield = 0; | |
310 if(int_O_DBG_pre_bitfield & DBG_RUN) | |
311 int_O_DBG_pre_bitfield = DBG_RESTART; | |
312 else | |
313 int_O_DBG_pre_bitfield = DBG_RUN; | |
314 int_O_DBG_post_bitfield = 0; | |
167 | 315 |
316 //---- Set 20meters ND limit --------------------------------------------- | |
116 | 317 char_O_NDL_at_20mtr = 255; |
318 | |
167 | 319 //---- Copy all dive parameters ------------------------------------------ |
116 | 320 DBG_N2_ratio = N2_ratio; |
321 DBG_He_ratio = He_ratio; | |
322 DBG_char_I_deco_model = char_I_deco_model; | |
323 DBG_char_I_depth_last_deco = char_I_depth_last_deco; | |
324 DBG_pres_surface = pres_surface; | |
325 DBG_GF_low = GF_low; | |
326 DBG_GF_high = GF_high; | |
327 DBG_const_ppO2 = const_ppO2; | |
224 | 328 DBG_deco_N2_ratio = char_I_deco_N2_ratio[0]; |
329 DBG_deco_He_ratio = char_I_deco_He_ratio[0]; | |
225 | 330 DBG_deco_gas_change = deco_gas_change[0]; |
116 | 331 DBG_float_saturation_multiplier = float_saturation_multiplier; |
332 DBG_float_desaturation_multiplier = float_desaturation_multiplier; | |
333 DBG_float_deco_distance = float_deco_distance; | |
334 | |
167 | 335 //---- Setup some error (?) conditions ----------------------------------- |
116 | 336 if(char_I_deco_model) |
337 int_O_DBS_bitfield |= DBS_mode; | |
338 if(const_ppO2) | |
339 int_O_DBS_bitfield |= DBS_ppO2; | |
339 | 340 for(i = 0; i < NUM_COMP; i++) |
341 if(pres_tissue_He[i]) | |
116 | 342 int_O_DBS_bitfield |= DBS_HE_sat; |
343 if(float_saturation_multiplier < 0.99) | |
344 int_O_DBS_bitfield |= DBS_SAT2l; | |
345 if(float_saturation_multiplier > 1.3) | |
346 int_O_DBS_bitfield |= DBS_SAT2h; | |
347 if(GF_low < 0.19) | |
348 int_O_DBS_bitfield |= DBS_GFLOW2l; | |
349 if(GF_low > 1.01) | |
350 int_O_DBS_bitfield |= DBS_GFLOW2h; | |
351 if(GF_high < 0.6) | |
352 int_O_DBS_bitfield |= DBS_GFHGH2l; | |
353 if(GF_high > 1.01) | |
354 int_O_DBS_bitfield |= DBS_GFHGH2h; | |
355 if((N2_ratio + He_ratio) > 0.95) | |
356 int_O_DBS_bitfield |= DBS_GASO22l; | |
357 if((N2_ratio + He_ratio) < 0.05) | |
358 int_O_DBS_bitfield |= DBS_GASO22h; | |
359 if(float_deco_distance > 0.25) | |
360 int_O_DBS_bitfield |= DBS_DIST2h; | |
361 if(char_I_depth_last_deco > 8) | |
362 int_O_DBS_bitfield |= DBS_LAST2h; | |
224 | 363 if(DBG_deco_gas_change && ((char_I_deco_N2_ratio[0] + char_I_deco_He_ratio[0]) > 95)) |
116 | 364 int_O_DBS_bitfield |= DBS_DECOO2l; |
224 | 365 if(DBG_deco_gas_change && ((char_I_deco_N2_ratio[0] + char_I_deco_He_ratio[0]) < 5)) |
116 | 366 int_O_DBS_bitfield |= DBS_DECOO2h; |
367 if(pres_respiration > 3.0) | |
368 int_O_DBS2_bitfield |= DBS2_PRES2h; | |
369 if(pres_surface - pres_respiration > 0.2) | |
370 int_O_DBS2_bitfield |= DBS2_PRES2l; | |
371 if(pres_surface < 0.75) | |
372 int_O_DBS2_bitfield |= DBS2_SURF2l; | |
373 if(pres_surface > 1.11) | |
374 int_O_DBS2_bitfield |= DBS2_SURF2h; | |
375 if(float_desaturation_multiplier < 0.70) | |
376 int_O_DBS2_bitfield |= DBS2_DESAT2l; | |
377 if(float_desaturation_multiplier > 1.01) | |
378 int_O_DBS2_bitfield |= DBS2_DESAT2h; | |
379 if(GF_low > GF_high) | |
380 int_O_DBS2_bitfield |= DBS2_GFDneg; | |
381 } | |
382 | |
167 | 383 ////////////////////////////////////////////////////////////////////////////// |
384 // DBG - set DBG to end_of_dive | |
385 // | |
386 static void set_dbg_end_of_dive(void) | |
116 | 387 { |
388 int_O_DBG_pre_bitfield &= (~DBG_RUN); | |
389 int_O_DBG_post_bitfield &= (~DBG_RUN); | |
390 } | |
391 | |
167 | 392 ////////////////////////////////////////////////////////////////////////////// |
393 // DBG - NDL at first 20 m. hit | |
394 // | |
395 static void check_ndl(void) | |
116 | 396 { |
167 | 397 if( char_O_NDL_at_20mtr == 255 // Still in NDL mode ? |
398 && int_I_pres_respiration > 3000 // And we hit the 20m limit ? | |
399 ) | |
116 | 400 { |
167 | 401 char_O_NDL_at_20mtr = char_O_nullzeit; // change to max bottom time. |
402 if( char_O_NDL_at_20mtr == 255) // and avoid confusion. | |
184 | 403 char_O_NDL_at_20mtr = 254; |
116 | 404 } |
405 } | |
406 | |
167 | 407 ////////////////////////////////////////////////////////////////////////////// |
408 // DBG - multi main during dive | |
409 // | |
184 | 410 static void check_dbg(PARAMETER char is_post_check) |
116 | 411 { |
203 | 412 overlay unsigned short temp_DBS = 0; |
200 | 413 overlay unsigned char i; // Local loop index. |
167 | 414 |
116 | 415 if( (DBG_N2_ratio != N2_ratio) || (DBG_He_ratio != He_ratio) ) |
416 temp_DBS |= DBG_c_gas; | |
417 if(DBG_const_ppO2 != const_ppO2) | |
418 temp_DBS |= DBG_c_ppO2; | |
167 | 419 if( DBG_float_saturation_multiplier != float_saturation_multiplier |
420 || DBG_float_desaturation_multiplier != float_desaturation_multiplier | |
421 ) | |
116 | 422 temp_DBS |= DBG_CdeSAT; |
423 if(DBG_char_I_deco_model != char_I_deco_model) | |
424 temp_DBS |= DBG_C_MODE; | |
425 if(DBG_pres_surface != pres_surface) | |
426 temp_DBS |= DBG_C_SURF; | |
167 | 427 |
428 if( !DBS_HE_sat && !He_ratio) | |
339 | 429 for(i = 0; i < NUM_COMP; i++) |
430 if(pres_tissue_He[i]) | |
116 | 431 temp_DBS |= DBG_HEwoHE; |
167 | 432 |
225 | 433 if( DBG_deco_gas_change != deco_gas_change[0] |
224 | 434 || DBG_deco_N2_ratio != char_I_deco_N2_ratio[0] |
435 || DBG_deco_He_ratio != char_I_deco_He_ratio[0] ) | |
116 | 436 temp_DBS |= DBG_C_DGAS; |
167 | 437 |
116 | 438 if(DBG_float_deco_distance != float_deco_distance) |
439 temp_DBS |= DBG_C_DIST; | |
440 if(DBG_char_I_depth_last_deco != char_I_depth_last_deco) | |
441 temp_DBS |= DBG_C_LAST; | |
167 | 442 if( DBG_GF_low != GF_low |
443 || DBG_GF_high != GF_high ) | |
116 | 444 temp_DBS |= DBG_C_GF; |
445 if(pres_respiration > 13.0) | |
446 temp_DBS |= DBG_PHIGH; | |
447 if(pres_surface - pres_respiration > 0.2) | |
448 temp_DBS |= DBG_PLOW; | |
449 if(is_post_check) | |
450 int_O_DBG_post_bitfield |= temp_DBS; | |
451 else | |
452 int_O_DBG_pre_bitfield |= temp_DBS; | |
453 } | |
454 | |
167 | 455 ////////////////////////////////////////////////////////////////////////////// |
456 // DBG - prior to calc. of dive | |
457 // | |
458 static void check_pre_dbg(void) | |
116 | 459 { |
460 check_dbg(0); | |
461 } | |
462 | |
167 | 463 ////////////////////////////////////////////////////////////////////////////// |
464 // DBG - after decocalc of dive | |
465 // | |
466 static void check_post_dbg(void) | |
116 | 467 { |
468 check_dbg(1); | |
469 } | |
470 | |
165 | 471 ////////////////////////////////////////////////////////////////////////////// |
167 | 472 ////////////////////////////////////////////////////////////////////////////// |
473 /////////////////////// U T I L I T I E S ///////////////////////////////// | |
474 ////////////////////////////////////////////////////////////////////////////// | |
475 ////////////////////////////////////////////////////////////////////////////// | |
476 | |
235 | 477 ////////////////////////////////////////////////////////////////////////////// |
257
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
478 // Bump to blue-screen when an assert is wrong |
235 | 479 #ifdef __DEBUG |
480 void assert_failed(PARAMETER short int line) | |
481 { | |
482 extern void PLED_resetdebugger(void); | |
483 extern unsigned short temp10; | |
484 | |
257
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
485 temp10 = line; // Show source line number as stack depth. |
235 | 486 PLED_resetdebugger(); |
487 } | |
488 #endif | |
257
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
489 |
235 | 490 ////////////////////////////////////////////////////////////////////////////// |
491 // When calling C code from ASM context, the data stack pointer and | |
492 // frames should be reset. Bank8 is used by stack, when not doing hashing. | |
493 | |
494 #ifdef CROSS_COMPILE | |
495 # define RESET_C_STACK | |
496 #else | |
497 # ifdef __DEBUG | |
498 # define RESET_C_STACK fillDataStack(); | |
499 void fillDataStack(void) | |
500 { | |
501 _asm | |
502 LFSR 1,C_STACK | |
503 MOVLW 0xCC | |
504 loop: MOVWF POSTINC1,0 | |
505 TSTFSZ FSR1L,0 | |
506 BRA loop | |
507 | |
508 LFSR 1,C_STACK | |
509 LFSR 2,C_STACK | |
510 _endasm | |
511 } | |
512 # else | |
513 # define RESET_C_STACK \ | |
514 _asm \ | |
515 LFSR 1, C_STACK \ | |
516 LFSR 2, C_STACK \ | |
517 _endasm | |
518 # endif | |
519 #endif | |
520 | |
521 ////////////////////////////////////////////////////////////////////////////// | |
257
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
522 // Read CF values from the C code. |
235 | 523 |
488 | 524 #ifdef CROSS_COMPILE |
525 // Full description of the OSTC EEPROM map, including CF values. | |
526 # include "OSTC_eeprom.h" | |
527 #endif | |
528 | |
203 | 529 static short read_custom_function(PARAMETER unsigned char cf) |
167 | 530 { |
184 | 531 #ifdef CROSS_COMPILE |
488 | 532 return (cf & 32) ? eeprom.bank1_CF[cf-32].value |
533 : eeprom.bank0_CF[cf ].value; | |
184 | 534 #else |
167 | 535 extern unsigned char hi, lo; |
536 extern void getcustom15(); | |
537 _asm | |
538 movff cf,WREG | |
539 call getcustom15,0 | |
540 movff lo,PRODL | |
541 movff hi,PRODH | |
542 _endasm | |
184 | 543 #endif |
167 | 544 } |
545 | |
546 ////////////////////////////////////////////////////////////////////////////// | |
257
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
547 // Fast subroutine to read RTC timer 3. |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
548 // Note: result is in 1/32 of msecs. |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
549 static unsigned short tmr3(void) |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
550 { |
261 | 551 #ifndef CROSS_COMPILE |
257
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
552 _asm |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
553 movff 0xfb2,PRODL // TMR3L |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
554 movff 0xfb3,PRODH // TMR3H |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
555 _endasm // result in PRODH:PRODL. |
261 | 556 #else |
557 return 0; | |
558 #endif | |
257
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
559 } |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
560 |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
561 ////////////////////////////////////////////////////////////////////////////// |
258 | 562 // read buhlmann tables A and B for compatriment ci |
563 // | |
564 static void read_buhlmann_coefficients(void) | |
165 | 565 { |
338 | 566 |
184 | 567 #ifndef CROSS_COMPILE |
167 | 568 // Note: we don't use far rom pointer, because the |
338 | 569 // 24 bits is too complex, hence we have to set |
167 | 570 // the UPPER page ourself... |
571 // --> Set zero if tables are moved to lower pages ! | |
572 _asm | |
573 movlw 1 | |
574 movwf TBLPTRU,0 | |
575 _endasm | |
184 | 576 #endif |
258 | 577 |
338 | 578 assert( 0 <= ci && ci < NUM_COMP ); |
579 | |
580 // Use an interleaved array (AoS) to access coefficients with a | |
581 // single addressing. | |
582 { | |
583 overlay rom const float* ptr = &buhlmann_ab[4*ci]; | |
584 var_N2_a = *ptr++; | |
585 var_N2_b = *ptr++; | |
586 var_He_a = *ptr++; | |
587 var_He_b = *ptr++; | |
588 } | |
167 | 589 |
165 | 590 // Check reading consistency: |
591 if( (var_N2_a < 0.231) | |
592 || (var_N2_a > 1.27) | |
593 || (var_N2_b < 0.504) | |
594 || (var_N2_b > 0.966) | |
595 || (var_He_a < 0.510) | |
596 || (var_He_a > 1.75) | |
597 || (var_He_b < 0.423) | |
598 || (var_He_b > 0.927) | |
599 ) | |
258 | 600 int_O_DBG_pre_bitfield |= DBG_ZH16ERR; |
601 } | |
602 | |
603 ////////////////////////////////////////////////////////////////////////////// | |
604 // read buhlmann tables for compatriment ci | |
605 // If period == 0 : 2sec interval | |
606 // 1 : 1 min interval | |
607 // 2 : 10 min interval. | |
608 static void read_buhlmann_times(PARAMETER char period) | |
609 { | |
610 #ifndef CROSS_COMPILE | |
611 // Note: we don't use far rom pointer, because the | |
612 // 24 bits is to complex, hence we have to set | |
613 // the UPPER page ourself... | |
614 // --> Set zero if tables are moved to lower pages ! | |
615 _asm | |
616 movlw 1 | |
617 movwf TBLPTRU,0 | |
618 _endasm | |
619 #endif | |
338 | 620 |
621 assert( 0 <= ci && ci < NUM_COMP ); | |
258 | 622 |
165 | 623 // Integration intervals. |
167 | 624 switch(period) |
165 | 625 { |
626 case 0: //---- 2 sec ----------------------------------------------------- | |
338 | 627 { |
628 overlay rom const float* ptr = &e2secs[2*ci]; | |
629 var_N2_e = *ptr++; | |
630 var_He_e = *ptr++; | |
631 } | |
165 | 632 |
633 // Check reading consistency: | |
634 if( (var_N2_e < 0.0000363) | |
635 || (var_N2_e > 0.00577) | |
636 || (var_He_e < 0.0000961) | |
637 || (var_He_e > 0.150) | |
638 ) | |
639 int_O_DBG_pre_bitfield |= DBG_ZH16ERR; | |
640 | |
641 break; | |
642 | |
643 case 1: //---- 1 min ----------------------------------------------------- | |
338 | 644 { |
645 overlay rom const float* ptr = &e1min[2*ci]; | |
646 var_N2_e = *ptr++; | |
647 var_He_e = *ptr++; | |
648 } | |
165 | 649 |
650 // Check reading consistency: | |
651 if( (var_N2_e < 1.09E-3) | |
652 || (var_N2_e > 0.1592) | |
653 || (var_He_e < 0.00288) | |
654 || (var_He_e > 0.3682) | |
655 ) | |
656 int_O_DBG_pre_bitfield |= DBG_ZH16ERR; | |
657 | |
658 break; | |
659 | |
660 case 2: //---- 10 min ---------------------------------------------------- | |
338 | 661 { |
662 overlay rom const float* ptr = &e10min[2*ci]; | |
663 var_N2_e = *ptr++; | |
664 var_He_e = *ptr++; | |
665 } | |
165 | 666 |
667 // Check reading consistency: | |
668 if( (var_N2_e < 0.01085) | |
669 || (var_N2_e > 0.82323) | |
670 || (var_He_e < 0.02846) | |
671 || (var_He_e > 0.98986) | |
672 ) | |
673 int_O_DBG_pre_bitfield |= DBG_ZH16ERR; | |
674 | |
675 break; | |
197 | 676 |
677 default: | |
678 assert(0); // Never go there... | |
165 | 679 } |
680 } | |
681 | |
682 ////////////////////////////////////////////////////////////////////////////// | |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
339
diff
changeset
|
683 // calc_nextdecodepth |
165 | 684 // |
116 | 685 // new in v.102 |
165 | 686 // |
116 | 687 // INPUT, changing during dive: |
192 | 688 // low_depth |
167 | 689 // |
116 | 690 // INPUT, fixed during dive: |
167 | 691 // pres_surface |
692 // GF_delta | |
693 // GF_high | |
694 // GF_low | |
171 | 695 // char_I_depth_last_deco |
167 | 696 // float_deco_distance |
697 // | |
241 | 698 // RETURN TRUE iff a stop is needed. |
699 // | |
116 | 700 // OUTPUT |
171 | 701 // locked_GF_step |
167 | 702 // temp_depth_limt |
192 | 703 // low_depth |
167 | 704 // |
241 | 705 static unsigned char calc_nextdecodepth(void) |
167 | 706 { |
241 | 707 //--- Max ascent speed --------------------------------------------------- |
708 // Recompute leading gas limit, at current depth: | |
317 | 709 overlay float depth = (temp_deco - pres_surface) * BAR_TO_METER; |
241 | 710 |
711 // At most, ascent 1 minute, at 10m/min == 10.0 m. | |
302 | 712 overlay float min_depth = (depth > 10.0) ? (depth - 10.0) : 0.0; |
241 | 713 |
714 // Do we need to stop at current depth ? | |
715 overlay unsigned char need_stop = 0; | |
716 | |
717 assert( depth >= -0.2 ); // Allow for 200mbar of weather change. | |
718 | |
212 | 719 //---- ZH-L16 + GRADIENT FACTOR model ------------------------------------ |
116 | 720 if (char_I_deco_model == 1) |
721 { | |
241 | 722 if( depth >= low_depth ) |
192 | 723 sim_limit( GF_low ); |
724 else | |
725 sim_limit( GF_high - depth * locked_GF_step ); | |
726 | |
727 // Stops are needed ? | |
728 if( sim_lead_tissue_limit > pres_surface ) | |
729 { | |
275
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
730 // Compute tolerated depth, for the leading tissue [metre]: |
317 | 731 overlay float depth_tol = (sim_lead_tissue_limit - pres_surface) * BAR_TO_METER; |
275
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
732 |
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
733 // Deepest stop, in multiples of 3 metres. |
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
734 overlay unsigned char first_stop = 3 * (short)(0.99999 + depth_tol * 0.33333 ); |
192 | 735 assert( first_stop < 128 ); |
171 | 736 |
275
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
737 // Is it a new deepest needed stop ? If yes this is the reference for |
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
738 // the varying gradient factor. So reset that: |
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
739 if( depth_tol > min_depth && depth_tol > low_depth ) |
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
740 { |
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
741 // Store the deepest stop depth, as reference for GF_low. |
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
742 low_depth = depth_tol; |
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
743 locked_GF_step = GF_delta / low_depth; |
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
744 } |
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
745 |
264 | 746 #if defined(__DEBUG) || defined(CROSS_COMPILE) |
261 | 747 { |
748 // Extra testing code to make sure the first_stop formula | |
749 // and rounding provides correct depth: | |
317 | 750 overlay float pres_stop = first_stop * METER_TO_BAR |
261 | 751 + pres_surface; |
752 | |
753 // Keep GF_low until a first stop depth is found: | |
754 if( first_stop >= low_depth ) | |
755 sim_limit( GF_low ); | |
756 else | |
757 // current GF is GF_high - alpha (GF_high - GF_low) | |
758 // With alpha = currentDepth / maxDepth, hence in [0..1] | |
759 sim_limit( GF_high - first_stop * locked_GF_step ); | |
760 | |
302 | 761 // upper limit (lowest pressure tolerated), + 1mbar for rounding...: |
762 assert( sim_lead_tissue_limit < (pres_stop + 0.001) ); | |
261 | 763 } |
764 #endif | |
765 | |
212 | 766 // Apply correction for the shallowest stop. |
192 | 767 if( first_stop == 3 ) // new in v104 |
768 first_stop = char_I_depth_last_deco; // Use last 3m..6m instead. | |
171 | 769 |
275
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
770 // Because gradient factor at first_stop might be bigger than at |
261 | 771 // current depth, we might ascent a bit more. |
772 // Hence, check all stops until one is indeed higher than tolerated presure: | |
773 while(first_stop > 0) | |
192 | 774 { |
775 overlay unsigned char next_stop; // Next index (0..30) | |
776 overlay float pres_stop; // Next depth (0m..90m) | |
171 | 777 |
241 | 778 // Check max speed, or reaching surface. |
779 if( first_stop <= min_depth ) | |
780 break; | |
781 | |
782 // So, there is indeed a stop needed: | |
783 need_stop = 1; | |
784 | |
192 | 785 if( first_stop <= char_I_depth_last_deco ) // new in v104 |
786 next_stop = 0; | |
216 | 787 else if( first_stop == 6 ) |
788 next_stop = char_I_depth_last_deco; | |
192 | 789 else |
790 next_stop = first_stop - 3; // Index of next (upper) stop. | |
167 | 791 |
317 | 792 pres_stop = next_stop * METER_TO_BAR |
192 | 793 + pres_surface; |
794 | |
212 | 795 // Keep GF_low until a first stop depth is found: |
796 if( next_stop >= low_depth ) | |
797 sim_limit( GF_low ); | |
798 else | |
799 // current GF is GF_high - alpha (GF_high - GF_low) | |
800 // With alpha = currentDepth / maxDepth, hence in [0..1] | |
801 sim_limit( GF_high - next_stop * locked_GF_step ); | |
171 | 802 |
192 | 803 // upper limit (lowest pressure tolerated): |
804 if( sim_lead_tissue_limit >= pres_stop ) // check if ascent to next deco stop is ok | |
805 break; | |
806 | |
807 // Else, validate that stop and loop... | |
808 first_stop = next_stop; | |
212 | 809 } |
810 | |
811 // next stop is the last validated depth found, aka first_stop | |
275
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
812 temp_depth_limit = first_stop; // Stop depth, in metre. |
192 | 813 } |
171 | 814 else |
275
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
815 temp_depth_limit = 0; // stop depth, in metre. |
116 | 816 } |
167 | 817 else //---- ZH-L16 model ------------------------------------------------- |
116 | 818 { |
192 | 819 overlay float pres_gradient; |
820 | |
821 // Original model | |
116 | 822 // optimized in v.101 |
171 | 823 // char_I_depth_last_deco included in v.101 |
116 | 824 |
192 | 825 // Compute sim_lead_tissue_limit too, but just once. |
826 sim_limit(1.0); | |
827 | |
828 pres_gradient = sim_lead_tissue_limit - pres_surface; | |
167 | 829 if (pres_gradient >= 0) |
116 | 830 { |
317 | 831 pres_gradient *= BAR_TO_METER/3; // Bar --> stop number; |
275
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
832 temp_depth_limit = 3 * (short) (pres_gradient + 0.99); // --> metre : depth for deco |
241 | 833 need_stop = 1; // Hit. |
834 | |
835 // Implement last stop at 4m/5m/6m... | |
836 if( temp_depth_limit == 3 ) | |
837 temp_depth_limit = char_I_depth_last_deco; | |
171 | 838 } |
116 | 839 else |
241 | 840 temp_depth_limit = 0; |
171 | 841 } |
212 | 842 |
217 | 843 //---- Check gas change -------------------------------------------------- |
241 | 844 need_stop |= gas_switch_deepest(); // Update temp_depth_limit if there is a change, |
845 | |
846 return need_stop; | |
167 | 847 } |
116 | 848 |
167 | 849 ////////////////////////////////////////////////////////////////////////////// |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
850 // copy_deco_table |
167 | 851 // |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
852 // Buffer the stops, once computed, so we can continue to display them |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
853 // while computing the next set. |
167 | 854 // |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
855 static void copy_deco_table(void) |
116 | 856 { |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
857 // Copy depth of the first (deepest) stop, because when reversing |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
858 // order, it will be hard to find... |
279
8514588eb6a2
Mark gas-switch stops for decoplans, displayed in yellow.
JeanDo
parents:
278
diff
changeset
|
859 char_O_first_deco_depth = internal_deco_depth[0] & 0x7F; |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
860 char_O_first_deco_time = internal_deco_time [0]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
861 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
862 if( read_custom_function(54) & 1 ) //---- Should we reverse table ? ------ |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
863 { |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
864 overlay unsigned char x, y; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
865 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
866 //---- First: search the first non-null depth |
339 | 867 for(x=(NUM_STOPS-1); x != 0; --x) |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
868 if( internal_deco_depth[x] != 0 ) break; |
116 | 869 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
870 //---- Second: copy to output table (in reverse order) |
338 | 871 for(y=0; y<NUM_STOPS; y++, --x) |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
872 { |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
873 char_O_deco_depth[y] = internal_deco_depth[x]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
874 char_O_deco_time [y] = internal_deco_time [x]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
875 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
876 // Stop only once the last transfer is done. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
877 if( x == 0 ) break; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
878 } |
116 | 879 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
880 //---- Third: fill table end with null |
339 | 881 for(y++; y<NUM_STOPS; y++) |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
882 { |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
883 char_O_deco_time [y] = 0; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
884 char_O_deco_depth[y] = 0; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
885 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
886 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
887 else //---- Straight copy ------------------------------------------------ |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
888 { |
167 | 889 overlay unsigned char x; |
890 | |
339 | 891 for(x=0; x<NUM_STOPS; x++) |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
892 { |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
893 char_O_deco_depth[x] = internal_deco_depth[x]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
894 char_O_deco_time [x] = internal_deco_time [x]; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
895 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
896 } |
167 | 897 } |
116 | 898 |
167 | 899 ////////////////////////////////////////////////////////////////////////////// |
116 | 900 // temp_tissue_safety // |
167 | 901 // |
116 | 902 // outsourced in v.102 |
167 | 903 // |
904 // Apply safety factors for brand ZH-L16 model. | |
905 // | |
906 static void temp_tissue_safety(void) | |
116 | 907 { |
197 | 908 assert( 0.0 < float_desaturation_multiplier && float_desaturation_multiplier <= 1.0 ); |
909 assert( 1.0 <= float_saturation_multiplier && float_saturation_multiplier <= 2.0 ); | |
910 | |
167 | 911 if( char_I_deco_model == 0 ) |
116 | 912 { |
491
560764da0629
BUGFIX Surface desat factor missing for Interval planning in GF mode.
JeanDo
parents:
490
diff
changeset
|
913 if( temp_tissue < 0.0 ) |
126 | 914 temp_tissue *= float_desaturation_multiplier; |
116 | 915 else |
126 | 916 temp_tissue *= float_saturation_multiplier; |
116 | 917 } |
167 | 918 } |
116 | 919 |
167 | 920 ////////////////////////////////////////////////////////////////////////////// |
921 ////////////////////////////////////////////////////////////////////////////// | |
116 | 922 // ** THE JUMP-IN CODE ** |
923 // ** for the asm code ** | |
167 | 924 ////////////////////////////////////////////////////////////////////////////// |
925 ////////////////////////////////////////////////////////////////////////////// | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
926 |
167 | 927 ////////////////////////////////////////////////////////////////////////////// |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
928 // Called every 2 seconds during diving. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
929 // update tissues every time. |
184 | 930 // |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
931 // Every 6 seconds (or slower when TTS > 16): |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
932 // - update deco table (char_O_deco_time/depth) with new values. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
933 // - update ascent time, |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
934 // - set status to zero (so we can check there is new results). |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
935 // |
116 | 936 void deco_calc_hauptroutine(void) |
937 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
938 RESET_C_STACK |
116 | 939 calc_hauptroutine(); |
940 int_O_desaturation_time = 65535; | |
941 } | |
942 | |
167 | 943 ////////////////////////////////////////////////////////////////////////////// |
184 | 944 // Reset decompression model: |
945 // + Set all tissues to equilibrium with Air at ambient pressure. | |
946 // + Reset last stop to 0m | |
947 // + Reset all model output. | |
116 | 948 void deco_clear_tissue(void) |
949 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
950 RESET_C_STACK |
116 | 951 clear_tissue(); |
952 } | |
953 | |
167 | 954 ////////////////////////////////////////////////////////////////////////////// |
278 | 955 // Called every 1 min during decoplanning. |
956 // Update tissues for 1 min. | |
957 // | |
958 void deco_calc_tissue(void) | |
959 { | |
960 RESET_C_STACK | |
961 calc_hauptroutine_update_tissues(); | |
962 } | |
963 | |
964 ////////////////////////////////////////////////////////////////////////////// | |
167 | 965 |
116 | 966 void deco_calc_wo_deco_step_1_min(void) |
967 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
968 RESET_C_STACK |
116 | 969 calc_wo_deco_step_1_min(); |
970 deco_calc_desaturation_time(); | |
971 } | |
972 | |
167 | 973 ////////////////////////////////////////////////////////////////////////////// |
974 | |
368 | 975 void deco_calc_dive_interval(void) |
976 { | |
977 RESET_C_STACK | |
978 calc_dive_interval(); | |
979 } | |
980 | |
981 ////////////////////////////////////////////////////////////////////////////// | |
982 | |
116 | 983 void deco_debug(void) |
984 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
985 RESET_C_STACK |
116 | 986 } |
987 | |
241 | 988 |
989 ////////////////////////////////////////////////////////////////////////////// | |
990 // Find current gas in the list (if any). | |
991 // | |
353
b5b030c1ae7e
Avoid spurious switch-depth stops with 3 or more gas.
JeanDo
parents:
340
diff
changeset
|
992 // Input: char_I_current_gas. |
241 | 993 // |
353
b5b030c1ae7e
Avoid spurious switch-depth stops with 3 or more gas.
JeanDo
parents:
340
diff
changeset
|
994 // Output: sim_gas_last_depth, temp_depth_limit. |
241 | 995 // |
996 static void gas_switch_find_current(void) | |
997 { | |
353
b5b030c1ae7e
Avoid spurious switch-depth stops with 3 or more gas.
JeanDo
parents:
340
diff
changeset
|
998 assert( 0 <= char_I_current_gas && char_I_current_gas <= (NUM_GAS+1) ); |
247
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
999 |
388 | 1000 if( char_I_current_gas <= NUM_GAS ) // Gas1..Gas5 |
353
b5b030c1ae7e
Avoid spurious switch-depth stops with 3 or more gas.
JeanDo
parents:
340
diff
changeset
|
1001 { |
388 | 1002 sim_gas_last_used = char_I_current_gas; |
1003 | |
1004 // Note: if current is first gas, we must find it, but not set | |
1005 // last depth change to surface. | |
1006 if( char_I_deco_gas_change[sim_gas_last_used-1] ) | |
1007 sim_gas_last_depth = char_I_deco_gas_change[sim_gas_last_used-1]; | |
241 | 1008 } |
388 | 1009 else |
1010 sim_gas_last_used = 0; // Gas 6 = manual set | |
241 | 1011 } |
1012 | |
167 | 1013 ////////////////////////////////////////////////////////////////////////////// |
217 | 1014 // Find deepest available gas. |
201 | 1015 // |
241 | 1016 // Input: temp_depth_limit, |
1017 // deco_gas_change[] | |
1018 // sim_gas_delay, sim_gas_depth_used, sim_dive_mins. | |
212 | 1019 // |
241 | 1020 // RETURNS TRUE if a stop is needed for gas switch. |
1021 // | |
1022 // Output: temp_depth_limit, sim_gas_delay, sim_gas_depth_used IFF the is a switch. | |
212 | 1023 // |
241 | 1024 // NOTE: might be called from bottom (when sim_gas_delay and sim_gas_depth_used |
1025 // are null), or during the ascent to make sure we are not passing a | |
1026 // stop (in which case both can be already set). | |
1027 // | |
1028 static unsigned char gas_switch_deepest(void) | |
201 | 1029 { |
241 | 1030 overlay unsigned char switch_deco = 0, switch_last = 0; |
201 | 1031 |
1032 if (char_I_const_ppO2 == 0) | |
1033 { | |
225 | 1034 overlay unsigned char j; |
1035 | |
241 | 1036 // Loop over all enabled gas, to find the deepest one, |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
339
diff
changeset
|
1037 // above last used gas, but below temp_depth_limit. |
338 | 1038 for(j=0; j<NUM_GAS; ++j) |
225 | 1039 { |
241 | 1040 // Gas not (yet) allowed ? Skip ! |
1041 if( temp_depth_limit > deco_gas_change[j] ) | |
1042 continue; | |
1043 | |
353
b5b030c1ae7e
Avoid spurious switch-depth stops with 3 or more gas.
JeanDo
parents:
340
diff
changeset
|
1044 // Gas deeper (or equal) than the current one ? Skip ! |
241 | 1045 if( sim_gas_last_depth && deco_gas_change[j] >= sim_gas_last_depth ) |
1046 continue; | |
1047 | |
1048 // First, or deeper ? | |
247
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1049 if( switch_deco < deco_gas_change[j] ) |
241 | 1050 { |
1051 switch_deco = deco_gas_change[j]; | |
388 | 1052 switch_last = j+1; // 1..5 |
241 | 1053 } |
225 | 1054 } |
201 | 1055 } |
1056 | |
203 | 1057 // If there is a better gas available |
241 | 1058 if( switch_deco ) |
201 | 1059 { |
241 | 1060 assert( !sim_gas_last_depth || sim_gas_last_depth > switch_deco ); |
201 | 1061 |
241 | 1062 // Should restart gas-switch delay only when gas do changes... |
1063 assert( sim_gas_delay <= sim_dive_mins ); | |
217 | 1064 |
241 | 1065 sim_gas_last_depth = switch_deco; |
1066 sim_gas_last_used = switch_last; | |
1067 sim_gas_delay = read_custom_function(55); | |
217 | 1068 |
241 | 1069 // Apply depth correction ONLY if CF#55 is not null: |
1070 if( sim_gas_delay > 0 ) | |
225 | 1071 { |
241 | 1072 sim_gas_delay += sim_dive_mins; |
1073 temp_depth_limit = switch_deco; | |
1074 return 1; | |
225 | 1075 } |
241 | 1076 |
1077 return 0; | |
217 | 1078 } |
1079 | |
241 | 1080 sim_gas_delay = 0; |
1081 return 0; | |
217 | 1082 } |
1083 | |
1084 ////////////////////////////////////////////////////////////////////////////// | |
1085 // Calculate gas switches | |
1086 // | |
1087 // | |
1088 // Input: N2_ratio, He_ratio. | |
1089 // sim_gas_last_used | |
1090 // | |
1091 // Output: calc_N2_ratio, calc_He_ratio | |
1092 // | |
241 | 1093 static void gas_switch_set(void) |
217 | 1094 { |
338 | 1095 assert( 0 <= sim_gas_last_used && sim_gas_last_used <= NUM_GAS ); |
217 | 1096 |
388 | 1097 if( sim_gas_last_used == 0 ) // Gas6 = manualy set gas. |
224 | 1098 { |
1099 calc_N2_ratio = N2_ratio; | |
1100 calc_He_ratio = He_ratio; | |
1101 } | |
1102 else | |
1103 { | |
1104 calc_N2_ratio = char_I_deco_N2_ratio[sim_gas_last_used-1] * 0.01; | |
1105 calc_He_ratio = char_I_deco_He_ratio[sim_gas_last_used-1] * 0.01; | |
217 | 1106 } |
201 | 1107 |
1108 assert( 0.0 <= calc_N2_ratio && calc_N2_ratio <= 0.95 ); | |
1109 assert( 0.0 <= calc_He_ratio && calc_He_ratio <= 0.95 ); | |
1110 assert( (calc_N2_ratio + calc_He_ratio) <= 1.00 ); | |
1111 } | |
1112 | |
1113 ////////////////////////////////////////////////////////////////////////////// | |
1114 // | |
212 | 1115 // Input: calc_N2_ratio, calc_He_ratio : simulated gas mix. |
1116 // temp_deco : simulated respiration pressure + security offset (deco_distance) | |
276 | 1117 // float_deco_distance : security factor. |
310
b20fc8c4ac92
Fix EAD/END display (not mm, m with a trailling space)
JeanDo
parents:
307
diff
changeset
|
1118 // Water-vapor pressure inside limbs (ppWater). |
212 | 1119 // |
236 | 1120 // Output: ppN2, ppHe. |
212 | 1121 // |
1122 static void sim_alveolar_presures(void) | |
201 | 1123 { |
212 | 1124 overlay float deco_diluent = temp_deco; // new in v.101 |
1125 | |
276 | 1126 // Take deco offset into account, but not at surface. |
1127 // Note: this should be done on ambiant pressure, hence before | |
1128 // computing the diluant partial pressure... | |
1129 if( deco_diluent > pres_surface ) | |
1130 deco_diluent += float_deco_distance; | |
1131 | |
212 | 1132 //---- CCR mode : deco gas switch ? -------------------------------------- |
276 | 1133 if( char_I_const_ppO2 != 0 ) |
201 | 1134 { |
276 | 1135 // In CCR mode, use calc_XX_ratio instead of XX_ratio. |
1136 // Note: PPO2 and ratios are known outside the lumbs, so there is no | |
310
b20fc8c4ac92
Fix EAD/END display (not mm, m with a trailling space)
JeanDo
parents:
307
diff
changeset
|
1137 // ppWater in the equations below: |
321 | 1138 deco_diluent -= const_ppO2; |
276 | 1139 deco_diluent /= calc_N2_ratio + calc_He_ratio; |
212 | 1140 |
1141 if (deco_diluent > temp_deco) | |
1142 deco_diluent = temp_deco; | |
201 | 1143 } |
1144 | |
310
b20fc8c4ac92
Fix EAD/END display (not mm, m with a trailling space)
JeanDo
parents:
307
diff
changeset
|
1145 if( deco_diluent > ppWater ) |
201 | 1146 { |
310
b20fc8c4ac92
Fix EAD/END display (not mm, m with a trailling space)
JeanDo
parents:
307
diff
changeset
|
1147 ppN2 = calc_N2_ratio * (deco_diluent - ppWater); |
b20fc8c4ac92
Fix EAD/END display (not mm, m with a trailling space)
JeanDo
parents:
307
diff
changeset
|
1148 ppHe = calc_He_ratio * (deco_diluent - ppWater); |
201 | 1149 } |
1150 else | |
1151 { | |
236 | 1152 ppN2 = 0.0; |
201 | 1153 ppHe = 0.0; |
1154 } | |
236 | 1155 assert( 0.0 <= ppN2 && ppN2 < 14.0 ); |
201 | 1156 assert( 0.0 <= ppHe && ppHe < 14.0 ); |
1157 } | |
1158 | |
1159 ////////////////////////////////////////////////////////////////////////////// | |
167 | 1160 // clear_tissue |
1161 // | |
165 | 1162 // optimized in v.101 (var_N2_a) |
167 | 1163 // |
1164 // preload tissues with standard pressure for the given ambient pressure. | |
1165 // Note: fixed N2_ratio for standard air. | |
201 | 1166 // |
167 | 1167 static void clear_tissue(void) |
116 | 1168 { |
1169 flag_in_divemode = 0; | |
1170 int_O_DBS_bitfield = 0; | |
1171 int_O_DBS2_bitfield = 0; | |
1172 int_O_DBG_pre_bitfield = 0; | |
1173 int_O_DBG_post_bitfield = 0; | |
1174 char_O_NDL_at_20mtr = 255; | |
1175 | |
167 | 1176 // Kludge: the 0.0002 of 0.7902 are missing with standard air. |
1177 N2_ratio = 0.7902; | |
212 | 1178 pres_respiration = int_I_pres_respiration * 0.001; |
164 | 1179 |
338 | 1180 for(ci=0; ci<NUM_COMP; ci++) |
126 | 1181 { |
197 | 1182 // cycle through the 16 Bühlmann tissues |
310
b20fc8c4ac92
Fix EAD/END display (not mm, m with a trailling space)
JeanDo
parents:
307
diff
changeset
|
1183 overlay float p = N2_ratio * (pres_respiration - ppWater); |
339 | 1184 pres_tissue_N2[ci] = p; |
197 | 1185 |
1186 // cycle through the 16 Bühlmann tissues for Helium | |
339 | 1187 pres_tissue_He[ci] = 0.0; |
338 | 1188 } // for 0 to 15 |
116 | 1189 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1190 clear_deco_table(); |
126 | 1191 char_O_deco_status = 0; |
1192 char_O_nullzeit = 0; | |
168 | 1193 int_O_ascenttime = 0; |
126 | 1194 char_O_gradient_factor = 0; |
1195 char_O_relative_gradient_GF = 0; | |
197 | 1196 char_I_depth_last_deco = 0; // for compatibility with v.101pre_no_last_deco |
258 | 1197 |
1198 calc_lead_tissue_limit = 0.0; | |
1199 char_O_gtissue_no = 0; | |
167 | 1200 } |
116 | 1201 |
167 | 1202 ////////////////////////////////////////////////////////////////////////////// |
1203 // calc_hauptroutine | |
1204 // | |
1205 // this is the major code in dive mode calculates: | |
116 | 1206 // the tissues, |
167 | 1207 // the bottom time, |
1208 // and simulates the ascend with all deco stops. | |
171 | 1209 // |
1210 // The deco_state sequence is : | |
1211 // 3 (at surface) | |
1212 // +---> 0 : calc nullzeit | |
1213 // | 2 : simulate ascent to first stop (at 10m/min, less that 16x 1min simu) | |
1214 // | +-> 1 : simulate up to 16min of stops. | |
1215 // | +------< not finished | |
1216 // +--------< finish | |
1217 // | |
312
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1218 // Added steps 6,5 for @+5 calculation: |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1219 // 6 = ascent to first stop (same as 2), except continue to 7 |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1220 // 7 = same as 1, except loop to 7. |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1221 // |
167 | 1222 static void calc_hauptroutine(void) |
116 | 1223 { |
241 | 1224 static unsigned char backup_gas_used = 0; |
1225 static unsigned char backup_gas_depth = 0; | |
217 | 1226 static unsigned char backup_gas_delay = 0; |
186 | 1227 |
116 | 1228 calc_hauptroutine_data_input(); |
1229 | |
1230 if(!flag_in_divemode) | |
1231 { | |
1232 flag_in_divemode = 1; | |
1233 create_dbs_set_dbg_and_ndl20mtr(); | |
1234 } | |
1235 else | |
1236 check_pre_dbg(); | |
1237 | |
1238 calc_hauptroutine_update_tissues(); | |
1239 calc_gradient_factor(); | |
1240 | |
167 | 1241 // toggle between calculation for nullzeit (bottom time), |
1242 // deco stops | |
1243 // and more deco stops (continue) | |
1244 switch( char_O_deco_status ) | |
116 | 1245 { |
186 | 1246 case 3: //---- At surface: start a new dive ------------------------------ |
1247 clear_deco_table(); | |
1248 copy_deco_table(); | |
200 | 1249 int_O_ascenttime = 0; // Reset DTR. |
323 | 1250 int_O_extra_ascenttime = 0; |
200 | 1251 char_O_nullzeit = 0; // Reset bottom time. |
278 | 1252 char_O_deco_status = 0; // Calc bottom-time/nullzeit next iteration. |
201 | 1253 |
217 | 1254 // Values that should be reset just once for the full real dive. |
1255 // This is used to record the lowest stop for the whole dive, | |
1256 // Including ACCROSS all simulated ascent. | |
293
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1257 low_depth = 0.0; |
217 | 1258 |
1259 // Reset gas switch history. | |
241 | 1260 backup_gas_used = sim_gas_last_used = 0; |
1261 backup_gas_depth = sim_gas_last_depth = 0; | |
217 | 1262 backup_gas_delay = sim_gas_delay = 0; |
203 | 1263 sim_dive_mins = 0; |
1264 break; | |
186 | 1265 |
167 | 1266 case 0: //---- bottom time ----------------------------------------------- |
312
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1267 default: |
167 | 1268 calc_nullzeit(); |
1269 check_ndl(); | |
186 | 1270 char_O_deco_status = 2; // calc ascent next time. |
1271 break; | |
1272 | |
1273 case 2: //---- Simulate ascent to first stop ----------------------------- | |
312
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1274 case 6: // @+5min variation |
203 | 1275 // Check proposed gas at begin of ascent simulation |
247
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1276 sim_dive_mins = int_I_divemins; // Init current time. |
241 | 1277 |
247
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1278 gas_switch_find_current(); // Lookup for current gas & time. |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1279 gas_switch_set(); // setup calc_ratio's |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1280 |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1281 backup_gas_used = sim_gas_last_used; // And save for later simu steps. |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1282 backup_gas_depth = sim_gas_last_depth; // And save for later simu steps. |
203 | 1283 backup_gas_delay = sim_gas_delay; |
186 | 1284 |
1285 sim_ascent_to_first_stop(); | |
201 | 1286 |
312
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1287 // Calc stops next time (deco or gas switch). |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1288 char_O_deco_status = 1 | ( char_O_deco_status & 4 ); |
167 | 1289 break; |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1290 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1291 case 1: //---- Simulate stops -------------------------------------------- |
312
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1292 case 5: // @+5 variation. |
167 | 1293 calc_hauptroutine_calc_deco(); |
186 | 1294 |
1295 // If simulation is finished, restore the GF low reference, so that | |
1296 // next ascent simulation is done from the current depth: | |
312
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1297 if( (char_O_deco_status & 3) == 0 ) |
186 | 1298 { |
241 | 1299 sim_gas_last_used = backup_gas_used; |
1300 sim_gas_last_depth = backup_gas_depth; | |
247
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1301 sim_gas_delay = backup_gas_delay; |
186 | 1302 } |
167 | 1303 break; |
116 | 1304 } |
167 | 1305 |
116 | 1306 check_post_dbg(); |
1307 } | |
1308 | |
167 | 1309 ////////////////////////////////////////////////////////////////////////////// |
1310 // calc_hauptroutine_data_input | |
1311 // | |
1312 // Reset all C-code dive parameters from their ASM-code values. | |
1313 // Detect gas change condition. | |
1314 // | |
116 | 1315 void calc_hauptroutine_data_input(void) |
1316 { | |
203 | 1317 overlay short int_temp; |
126 | 1318 |
197 | 1319 pres_respiration = int_I_pres_respiration * 0.001; |
1320 pres_surface = int_I_pres_surface * 0.001; | |
1321 N2_ratio = char_I_N2_ratio * 0.01; | |
1322 He_ratio = char_I_He_ratio * 0.01; | |
1323 float_deco_distance = char_I_deco_distance * 0.01; // Get offset is in mbar. | |
116 | 1324 |
126 | 1325 // ____________________________________________________ |
1326 // | |
1327 // _____________ G A S _ C H A N G E S ________________ | |
1328 // ____________________________________________________ | |
1329 | |
212 | 1330 // Keep a margin of 150mbar = 1.50m |
1331 int_temp = (int_I_pres_respiration - int_I_pres_surface) | |
1332 + MBAR_REACH_GASCHANGE_AUTO_CHANGE_OFF; | |
126 | 1333 |
225 | 1334 deco_gas_change[0] = 0; |
1335 deco_gas_change[1] = 0; | |
1336 deco_gas_change[2] = 0; | |
1337 deco_gas_change[3] = 0; | |
1338 deco_gas_change[4] = 0; | |
116 | 1339 |
203 | 1340 // Gas are selectable if we did not pass the change depth by more than 1.50m: |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1341 if(char_I_deco_gas_change[0]) |
126 | 1342 { |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1343 if( int_temp > 100 *(short)char_I_deco_gas_change[0] ) |
225 | 1344 deco_gas_change[0] = char_I_deco_gas_change[0]; |
126 | 1345 } |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1346 if(char_I_deco_gas_change[1]) |
126 | 1347 { |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1348 if( int_temp > 100 *(short)char_I_deco_gas_change[1] ) |
225 | 1349 deco_gas_change[1] = char_I_deco_gas_change[1]; |
126 | 1350 } |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1351 if(char_I_deco_gas_change[2]) |
126 | 1352 { |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1353 if( int_temp > 100 *(short)char_I_deco_gas_change[2] ) |
225 | 1354 deco_gas_change[2] = char_I_deco_gas_change[2]; |
126 | 1355 } |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1356 if(char_I_deco_gas_change[3]) |
126 | 1357 { |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1358 if( int_temp > 100 *(short)char_I_deco_gas_change[3] ) |
225 | 1359 deco_gas_change[3] = char_I_deco_gas_change[3]; |
126 | 1360 } |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1361 if(char_I_deco_gas_change[4]) |
126 | 1362 { |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
1363 if( int_temp > 100 *(short)char_I_deco_gas_change[4] ) |
225 | 1364 deco_gas_change[4] = char_I_deco_gas_change[4]; |
126 | 1365 } |
116 | 1366 |
197 | 1367 const_ppO2 = char_I_const_ppO2 * 0.01; |
1368 float_desaturation_multiplier = char_I_desaturation_multiplier * 0.01; | |
1369 float_saturation_multiplier = char_I_saturation_multiplier * 0.01; | |
1370 GF_low = char_I_GF_Low_percentage * 0.01; | |
1371 GF_high = char_I_GF_High_percentage * 0.01; | |
126 | 1372 GF_delta = GF_high - GF_low; |
116 | 1373 } |
1374 | |
167 | 1375 ////////////////////////////////////////////////////////////////////////////// |
171 | 1376 // |
1377 // | |
116 | 1378 void calc_hauptroutine_update_tissues(void) |
1379 { | |
197 | 1380 assert( 0.00 <= N2_ratio && N2_ratio <= 1.00 ); |
1381 assert( 0.00 <= He_ratio && He_ratio <= 1.00 ); | |
1382 assert( (N2_ratio + He_ratio) <= 0.95 ); | |
237 | 1383 assert( 0.800 < pres_respiration && pres_respiration < 14.0 ); |
197 | 1384 |
276 | 1385 pres_diluent = pres_respiration; |
307 | 1386 if( char_I_const_ppO2 != 0 ) // new in v.101 |
186 | 1387 { |
322 | 1388 overlay float flush_ppO2 = pres_respiration * (1.0 - N2_ratio - He_ratio); |
1389 | |
276 | 1390 pres_diluent -= const_ppO2; // new in v.101 |
1391 pres_diluent /= N2_ratio + He_ratio; // new in v.101 | |
321 | 1392 if( pres_diluent < 0.0 ) |
1393 pres_diluent = 0.0; | |
276 | 1394 if( pres_diluent > pres_respiration ) // new in v.101 |
1395 pres_diluent = pres_respiration; // new in v.101 | |
307 | 1396 |
321 | 1397 char_O_diluent = (unsigned char)(pres_diluent/pres_respiration*100.0 + 0.5); |
322 | 1398 |
326 | 1399 if( flush_ppO2 > 2.545) flush_ppO2 = 2.55; |
322 | 1400 if( flush_ppO2 < 0.0 ) flush_ppO2 = 0.0; |
1401 char_O_flush_ppO2 = (unsigned char)(flush_ppO2*100.0 + 0.5); | |
186 | 1402 } |
307 | 1403 |
310
b20fc8c4ac92
Fix EAD/END display (not mm, m with a trailling space)
JeanDo
parents:
307
diff
changeset
|
1404 if( pres_diluent > ppWater ) // new in v.101 |
116 | 1405 { |
307 | 1406 overlay float EAD, END; |
1407 | |
310
b20fc8c4ac92
Fix EAD/END display (not mm, m with a trailling space)
JeanDo
parents:
307
diff
changeset
|
1408 ppN2 = N2_ratio * (pres_diluent - ppWater); // changed in v.101 |
b20fc8c4ac92
Fix EAD/END display (not mm, m with a trailling space)
JeanDo
parents:
307
diff
changeset
|
1409 ppHe = He_ratio * (pres_diluent - ppWater); // changed in v.101 |
307 | 1410 |
1411 // EAD : Equivalent Air Dive. Equivalent depth for the same N2 level | |
1412 // with plain air. | |
310
b20fc8c4ac92
Fix EAD/END display (not mm, m with a trailling space)
JeanDo
parents:
307
diff
changeset
|
1413 // ppN2 = 79% * (P_EAD - ppWater) |
307 | 1414 // EAD = (P_EAD - Psurface) * 10 |
310
b20fc8c4ac92
Fix EAD/END display (not mm, m with a trailling space)
JeanDo
parents:
307
diff
changeset
|
1415 // ie: EAD = (ppN2 / 0.7902 + ppWater -Psurface) * 10 |
317 | 1416 EAD = (ppN2 / 0.7902 + ppWater - pres_surface) * BAR_TO_METER; |
307 | 1417 if( EAD < 0.0 || EAD > 245.5 ) EAD = 0.0; |
317 | 1418 char_O_EAD = (unsigned char)(EAD + 0.5); |
307 | 1419 |
1420 // END : Equivalent Narcotic Dive. | |
1421 // Here we count O2 as narcotic too. Hence everything but helium (has a narcosis factor of | |
1422 // 0.23 btw). Hence the formula becomes: | |
310
b20fc8c4ac92
Fix EAD/END display (not mm, m with a trailling space)
JeanDo
parents:
307
diff
changeset
|
1423 // END * BarPerMeter * (1.0 - 0.0) - ppWater + Psurface == Pambient - ppHe - ppWater |
317 | 1424 // ie: END = (Pambient - ppHe - Psurface) * BAR_TO_METER |
307 | 1425 // |
1426 // Source cited: | |
1427 // The Physiology and Medicine of Diving by Peter Bennett and David Elliott, | |
1428 // 4th edition, 1993, W.B.Saunders Company Ltd, London. | |
317 | 1429 END = (pres_respiration - ppHe - pres_surface) * BAR_TO_METER; |
307 | 1430 if( END < 0.0 || END > 245.5 ) END = 0.0; |
317 | 1431 char_O_END = (unsigned char)(END + 0.5); |
116 | 1432 } |
167 | 1433 else // new in v.101 |
116 | 1434 { |
236 | 1435 ppN2 = 0.0; // new in v.101 |
200 | 1436 ppHe = 0.0; // new in v.101 |
307 | 1437 char_O_EAD = char_O_END = 0; |
116 | 1438 } |
1439 | |
1440 if(!char_I_step_is_1min) | |
192 | 1441 calc_tissue(0); |
116 | 1442 else |
192 | 1443 calc_tissue(1); |
186 | 1444 |
192 | 1445 // Calc limit for surface, ie. GF_high. |
258 | 1446 calc_limit(); |
186 | 1447 |
203 | 1448 int_O_gtissue_limit = (short)(calc_lead_tissue_limit * 1000); |
339 | 1449 int_O_gtissue_press = (short)((pres_tissue_N2[char_O_gtissue_no] + pres_tissue_He[char_O_gtissue_no]) * 1000); |
192 | 1450 |
1451 // if guiding tissue can not be exposed to surface pressure immediately | |
1452 if( calc_lead_tissue_limit > pres_surface && char_O_deco_status == 0) | |
116 | 1453 { |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1454 char_O_nullzeit = 0; // deco necessary |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1455 char_O_deco_status = 2; // calculate ascent on next iteration. |
116 | 1456 } |
171 | 1457 } |
1458 | |
116 | 1459 |
167 | 1460 ////////////////////////////////////////////////////////////////////////////// |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1461 // Compute stops. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1462 // |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1463 // Note: because this can be very long, break on 16 iterations, and set state |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1464 // to 0 when finished, or to 1 when needing to continue. |
334
4ccdc72ec0e5
BUGFIX minor error in gas-switch algo (spurious surface decostop rarely added).
JeanDo
parents:
326
diff
changeset
|
1465 // Note: because each iteration might be very long too (~ 66 ms in 1.84beta), |
257
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
1466 // break the loop when total time > 512msec. |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1467 // |
116 | 1468 void calc_hauptroutine_calc_deco(void) |
1469 { | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1470 overlay unsigned char loop; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1471 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1472 for(loop = 0; loop < 16; ++loop) |
116 | 1473 { |
257
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
1474 // Limit loops to 512ms, using the RTC timer 3: |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
1475 if( tmr3() & (512*32) ) |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
1476 break; |
f8f869bafd92
Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco()
JeanDo
parents:
252
diff
changeset
|
1477 |
241 | 1478 // Do not ascent while doing a gas switch ? |
203 | 1479 if( sim_gas_delay <= sim_dive_mins ) |
1480 { | |
241 | 1481 if( calc_nextdecodepth() ) |
1482 { | |
1483 if( temp_depth_limit == 0 ) | |
1484 goto Surface; | |
116 | 1485 |
241 | 1486 //---- We hit a stop at temp_depth_limit --------------------- |
317 | 1487 temp_deco = temp_depth_limit * METER_TO_BAR // Convert to relative bar, |
241 | 1488 + pres_surface; // To absolute. |
471 | 1489 if( !update_deco_table() ) // Adds a one minute stops. |
1490 goto Surface; // Deco table full: abort... | |
241 | 1491 } |
1492 else | |
1493 { | |
1494 //---- No stop ----------------------------------------------- | |
317 | 1495 temp_deco -= (10*METER_TO_BAR); // Ascend 10m, no wait. |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1496 |
241 | 1497 //---- Finish computations once surface is reached ----------- |
1498 if( temp_deco <= pres_surface ) | |
1499 { | |
1500 Surface: | |
471 | 1501 if( char_O_deco_status == 1 ) // Don't in @+5min variant. |
312
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1502 copy_deco_table(); |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1503 |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1504 calc_ascenttime(); |
471 | 1505 char_O_deco_status = 0; // calc nullzeit next time. |
1506 char_O_deco_last_stop = 0; // Surface reached (to animate menu) | |
241 | 1507 return; |
1508 } | |
1509 } | |
212 | 1510 } |
1511 else | |
334
4ccdc72ec0e5
BUGFIX minor error in gas-switch algo (spurious surface decostop rarely added).
JeanDo
parents:
326
diff
changeset
|
1512 { |
4ccdc72ec0e5
BUGFIX minor error in gas-switch algo (spurious surface decostop rarely added).
JeanDo
parents:
326
diff
changeset
|
1513 // Note: if loop==0, temp_depth_limit might not be already set here. |
4ccdc72ec0e5
BUGFIX minor error in gas-switch algo (spurious surface decostop rarely added).
JeanDo
parents:
326
diff
changeset
|
1514 temp_depth_limit = (int)(0.5 + (temp_deco - pres_surface) * BAR_TO_METER); |
471 | 1515 if( !update_deco_table() ) // Just pass one minute. |
1516 goto Surface; // Deco table full: abort... | |
334
4ccdc72ec0e5
BUGFIX minor error in gas-switch algo (spurious surface decostop rarely added).
JeanDo
parents:
326
diff
changeset
|
1517 } |
197 | 1518 |
241 | 1519 //---- Then update tissue -------------------------------------------- |
203 | 1520 sim_dive_mins++; // Advance simulated time by 1 minute. |
241 | 1521 gas_switch_set(); // Apply any simulated gas change, once validated. |
212 | 1522 sim_alveolar_presures(); // Updates ppN2 and ppHe. |
192 | 1523 sim_tissue(1); // Simulate compartiments for 1 minute. |
116 | 1524 } |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1525 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1526 // Surface not reached, need more stops... |
278 | 1527 char_O_deco_last_stop = temp_depth_limit; // Reached depth. |
116 | 1528 } |
1529 | |
167 | 1530 ////////////////////////////////////////////////////////////////////////////// |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1531 // Simulation ascention to first deco stop. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1532 // |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1533 // Note: because we ascent with a constant speed (10m/mn, ie. 1bar/mn), |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1534 // there is no need to break on more that 16 iterations |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1535 // (or we are already in deep shit). |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1536 // |
334
4ccdc72ec0e5
BUGFIX minor error in gas-switch algo (spurious surface decostop rarely added).
JeanDo
parents:
326
diff
changeset
|
1537 // Input: pres_respiration |
4ccdc72ec0e5
BUGFIX minor error in gas-switch algo (spurious surface decostop rarely added).
JeanDo
parents:
326
diff
changeset
|
1538 // Output: temp_deco |
4ccdc72ec0e5
BUGFIX minor error in gas-switch algo (spurious surface decostop rarely added).
JeanDo
parents:
326
diff
changeset
|
1539 // |
312
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1540 // if char_O_deco_status indicate @+5 variant, add extra time at current depth, |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1541 // before ascent. |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1542 void sim_ascent_to_first_stop(void) |
116 | 1543 { |
171 | 1544 update_startvalues(); |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1545 clear_deco_table(); |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1546 |
200 | 1547 temp_deco = pres_respiration; // Starts from current real depth. |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1548 |
312
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1549 // Are we doing the special @+5min variation ? |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1550 if(char_O_deco_status & 4) |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1551 sim_extra_time(); |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1552 |
212 | 1553 // Do we have a gas switch going on ? |
1554 if( sim_gas_delay > sim_dive_mins ) | |
1555 return; | |
1556 | |
241 | 1557 //---- Loop until first stop, gas switch, or surface is reached ---------- |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1558 for(;;) |
116 | 1559 { |
461 | 1560 overlay float old_deco = temp_deco; // Pamb backup (bars) |
460 | 1561 |
241 | 1562 // Try ascending 1 full minute. |
461 | 1563 temp_deco -= 10*METER_TO_BAR; // 1 min, at 10m/min. ~ 1bar. |
1564 if( temp_deco < pres_surface ) // But don't go over surface. | |
1565 temp_deco = pres_surface; | |
203 | 1566 |
461 | 1567 // Recompute sim_lead_tissue_limit at GF_low (deepest stop), because |
1568 // one minute passed. | |
212 | 1569 sim_limit(GF_low); |
1570 | |
1571 // Did we reach deepest remaining stop ? | |
241 | 1572 if( temp_deco < sim_lead_tissue_limit ) |
212 | 1573 { |
461 | 1574 temp_deco = old_deco; // Restore last correct depth, |
1575 break; // Do no spend a minute more. | |
212 | 1576 } |
1577 | |
203 | 1578 // Did we reach surface ? |
460 | 1579 // NOTE: we should round BEFORE checking surface is reached. |
461 | 1580 temp_depth_limit = (unsigned char)(0.5 + (temp_deco - pres_surface) * BAR_TO_METER); |
1581 if( temp_depth_limit == 0 ) | |
203 | 1582 { |
1583 temp_deco = pres_surface; // Yes: finished ! | |
1584 break; | |
1585 } | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1586 |
241 | 1587 // Check for gas change below new depth ? |
1588 if( gas_switch_deepest() ) | |
1589 { | |
334
4ccdc72ec0e5
BUGFIX minor error in gas-switch algo (spurious surface decostop rarely added).
JeanDo
parents:
326
diff
changeset
|
1590 assert( temp_depth_limit > 0); |
4ccdc72ec0e5
BUGFIX minor error in gas-switch algo (spurious surface decostop rarely added).
JeanDo
parents:
326
diff
changeset
|
1591 |
317 | 1592 temp_deco = temp_depth_limit * METER_TO_BAR + pres_surface; |
212 | 1593 break; |
241 | 1594 } |
171 | 1595 |
203 | 1596 sim_dive_mins++; // Advance simulated time by 1 minute. |
241 | 1597 sim_alveolar_presures(); // temp_deco --> ppN2/ppHe |
203 | 1598 sim_tissue(1); // and update tissues for 1 min. |
1599 } | |
167 | 1600 } |
116 | 1601 |
167 | 1602 ////////////////////////////////////////////////////////////////////////////// |
312
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1603 // Simulation extra time at the current depth. |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1604 // |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1605 // This routine is used for @+5min feature. |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1606 void sim_extra_time(void) |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1607 { |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1608 overlay unsigned char extra = read_custom_function(58); |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1609 do { |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1610 sim_dive_mins++; // Advance simulated time by 1 minute. |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1611 sim_tissue(1); // and update tissues for 1 min. |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1612 } while( --extra != 0 ); |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1613 } |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1614 |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1615 ////////////////////////////////////////////////////////////////////////////// |
167 | 1616 // calc_tissue |
1617 // | |
116 | 1618 // optimized in v.101 |
167 | 1619 // |
184 | 1620 static void calc_tissue(PARAMETER unsigned char period) |
116 | 1621 { |
251 | 1622 assert( 0.00 <= ppN2 && ppN2 < 11.2 ); // 80% N2 at 130m |
1623 assert( 0.00 <= ppHe && ppHe < 12.6 ); // 90% He at 130m | |
236 | 1624 |
338 | 1625 for (ci=0;ci<NUM_COMP;ci++) |
126 | 1626 { |
258 | 1627 read_buhlmann_times(period); // 2 sec or 1 min period. |
116 | 1628 |
126 | 1629 // N2 |
339 | 1630 temp_tissue = (ppN2 - pres_tissue_N2[ci]) * var_N2_e; |
126 | 1631 temp_tissue_safety(); |
339 | 1632 pres_tissue_N2[ci] += temp_tissue; |
165 | 1633 |
126 | 1634 // He |
339 | 1635 temp_tissue = (ppHe - pres_tissue_He[ci]) * var_He_e; |
126 | 1636 temp_tissue_safety(); |
339 | 1637 pres_tissue_He[ci] += temp_tissue; |
192 | 1638 } |
167 | 1639 } |
116 | 1640 |
167 | 1641 ////////////////////////////////////////////////////////////////////////////// |
192 | 1642 // calc_limit |
167 | 1643 // |
192 | 1644 // New in v.111 : separated from calc_tissue(), and depends on GF value. |
167 | 1645 // |
258 | 1646 static void calc_limit(void) |
167 | 1647 { |
192 | 1648 char_O_gtissue_no = 255; |
1649 calc_lead_tissue_limit = 0.0; | |
1650 | |
338 | 1651 for(ci=0; ci<NUM_COMP;ci++) |
192 | 1652 { |
339 | 1653 overlay float N2 = pres_tissue_N2[ci]; |
1654 overlay float He = pres_tissue_He[ci]; | |
293
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1655 overlay float p = N2 + He; |
192 | 1656 |
258 | 1657 read_buhlmann_coefficients(); |
293
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1658 var_N2_a = (var_N2_a * N2 + var_He_a * He) / p; |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1659 var_N2_b = (var_N2_b * N2 + var_He_b * He) / p; |
116 | 1660 |
192 | 1661 // Apply the Eric Baker's varying gradient factor correction. |
1662 // Note: the correction factor depends both on GF and b, | |
1663 // Actual values are in the 1.5 .. 1.0 range (for a GF=30%), | |
1664 // so that can change who is the leading gas... | |
1665 // Note: Also depends of the GF. So the calcul is different for | |
1666 // GF_low, current GF, or GF_high... | |
1667 // *BUT* calc_tissue() is used to compute bottom time, | |
1668 // hence what would happend at surface, | |
1669 // hence at GF_high. | |
1670 if( char_I_deco_model == 1 ) | |
258 | 1671 p = ( p - var_N2_a * GF_high) * var_N2_b |
1672 / (GF_high + var_N2_b * (1.0 - GF_high)); | |
192 | 1673 else |
1674 p = (p - var_N2_a) * var_N2_b; | |
258 | 1675 if( p < 0.0 ) p = 0.0; |
192 | 1676 |
1677 if( p > calc_lead_tissue_limit ) | |
1678 { | |
1679 char_O_gtissue_no = ci; | |
1680 calc_lead_tissue_limit = p; | |
1681 } | |
1682 } | |
197 | 1683 |
338 | 1684 assert( char_O_gtissue_no < NUM_COMP ); |
197 | 1685 assert( 0.0 <= calc_lead_tissue_limit && calc_lead_tissue_limit <= 14.0); |
167 | 1686 } |
1687 | |
1688 ////////////////////////////////////////////////////////////////////////////// | |
1689 // calc_nullzeit | |
1690 // | |
1691 // calculates the remaining bottom time | |
1692 // | |
1693 // unchanged in v.101 | |
1694 // | |
1695 static void calc_nullzeit(void) | |
1696 { | |
203 | 1697 overlay unsigned char loop; |
200 | 1698 update_startvalues(); |
167 | 1699 |
116 | 1700 char_O_nullzeit = 0; |
167 | 1701 for(loop = 1; loop <= 17; loop++) |
116 | 1702 { |
1703 backup_sim_pres_tissue(); | |
197 | 1704 sim_tissue(2); // 10 min. |
192 | 1705 sim_limit(GF_high); |
167 | 1706 |
192 | 1707 if( sim_lead_tissue_limit > pres_surface ) // changed in v.102 , if guiding tissue can not be exposed to surface pressure immediately |
185 | 1708 { |
1709 restore_sim_pres_tissue(); | |
1710 break; | |
1711 } | |
1712 // Validate once we know its good. | |
1713 char_O_nullzeit += 10; | |
167 | 1714 } |
1715 | |
116 | 1716 if (char_O_nullzeit < 60) |
1717 { | |
167 | 1718 for(loop=1; loop <= 10; loop++) |
116 | 1719 { |
197 | 1720 sim_tissue(1); // 1 min |
192 | 1721 sim_limit(GF_high); |
1722 | |
1723 if( sim_lead_tissue_limit > pres_surface) // changed in v.102 , if guiding tissue can not be exposed to surface pressure immediately | |
185 | 1724 break; |
1725 char_O_nullzeit++; | |
167 | 1726 } |
185 | 1727 } |
1728 } | |
116 | 1729 |
167 | 1730 ////////////////////////////////////////////////////////////////////////////// |
1731 // backup_sim_pres_tissue | |
1732 // | |
116 | 1733 void backup_sim_pres_tissue(void) |
1734 { | |
167 | 1735 overlay unsigned char x; |
1736 | |
339 | 1737 for(x=0; x<NUM_COMP; x++) |
1738 { | |
1739 sim_pres_tissue_backup_N2[x] = sim_pres_tissue_N2[x]; | |
1740 sim_pres_tissue_backup_He[x] = sim_pres_tissue_He[x]; | |
1741 } | |
167 | 1742 } |
116 | 1743 |
167 | 1744 ////////////////////////////////////////////////////////////////////////////// |
1745 // restore_sim_pres_tissue | |
1746 // | |
116 | 1747 void restore_sim_pres_tissue(void) |
1748 { | |
167 | 1749 overlay unsigned char x; |
1750 | |
339 | 1751 for(x=0; x<NUM_COMP; x++) |
1752 { | |
1753 sim_pres_tissue_N2[x] = sim_pres_tissue_backup_N2[x]; | |
1754 sim_pres_tissue_He[x] = sim_pres_tissue_backup_He[x]; | |
1755 } | |
167 | 1756 } |
116 | 1757 |
167 | 1758 ////////////////////////////////////////////////////////////////////////////// |
1759 // calc_ascenttime | |
1760 // | |
312
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1761 // Summup ascent from bottom to surface, at 1 bar/min, 1min for last 3 meters, |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1762 // and all stops. |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1763 // |
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1764 // Result in int_O_ascenttime, or int_O_extra_ascenttime if in @+5min variant. |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1765 static void calc_ascenttime(void) |
116 | 1766 { |
323 | 1767 overlay unsigned char x; |
1768 overlay unsigned short sum; | |
168 | 1769 |
323 | 1770 // + 0.7 to count 1 minute ascent time from 3 metre to surface |
1771 overlay float ascent = pres_respiration - pres_surface + 0.7; | |
1772 if (ascent < 0.0) | |
1773 ascent = 0.0; | |
1774 sum = (unsigned short)(ascent + 0.99); | |
312
b7e4e74c0e17
New @5 variant: compute TTS if staying some extra time (CF58) at current depth.
JeanDo
parents:
310
diff
changeset
|
1775 |
338 | 1776 for(x=0; x<NUM_STOPS && internal_deco_depth[x]; x++) |
323 | 1777 sum += (unsigned short)internal_deco_time[x]; |
1778 | |
1779 if( char_O_deco_status == 1 ) | |
1780 int_O_ascenttime = sum; | |
126 | 1781 else |
323 | 1782 int_O_extra_ascenttime = sum; |
167 | 1783 } |
116 | 1784 |
167 | 1785 ////////////////////////////////////////////////////////////////////////////// |
1786 // update_startvalues | |
1787 // | |
116 | 1788 // updated in v.102 |
167 | 1789 // |
116 | 1790 void update_startvalues(void) |
1791 { | |
167 | 1792 overlay unsigned char x; |
116 | 1793 |
201 | 1794 // Start ascent simulation with current tissue partial pressures. |
339 | 1795 for(x=0; x<NUM_COMP; x++) |
116 | 1796 { |
339 | 1797 sim_pres_tissue_N2[x] = pres_tissue_N2[x]; |
1798 sim_pres_tissue_He[x] = pres_tissue_He[x]; | |
116 | 1799 } |
197 | 1800 |
201 | 1801 // No leading tissue (yet) for this ascent simulation. |
197 | 1802 sim_lead_tissue_limit = 0.0; |
1803 sim_lead_tissue_no = 255; | |
167 | 1804 } |
116 | 1805 |
167 | 1806 ////////////////////////////////////////////////////////////////////////////// |
192 | 1807 // sim_tissue |
167 | 1808 // |
116 | 1809 // optimized in v.101 |
167 | 1810 // |
1811 // Function very simular to calc_tissue, but: | |
1812 // + Use a 1min or 10min period. | |
1813 // + Do it on sim_pres_tissue, instead of pres_tissue. | |
184 | 1814 static void sim_tissue(PARAMETER unsigned char period) |
116 | 1815 { |
251 | 1816 assert( 0.00 <= ppN2 && ppN2 < 11.2 ); // 80% N2 at 130m |
1817 assert( 0.00 <= ppHe && ppHe < 12.6 ); // 90% He at 130m | |
236 | 1818 |
338 | 1819 for(ci=0; ci<NUM_COMP; ci++) |
126 | 1820 { |
258 | 1821 read_buhlmann_times(period); // 1 or 10 minute(s) interval |
165 | 1822 |
126 | 1823 // N2 |
339 | 1824 temp_tissue = (ppN2 - sim_pres_tissue_N2[ci]) * var_N2_e; |
126 | 1825 temp_tissue_safety(); |
339 | 1826 sim_pres_tissue_N2[ci] += temp_tissue; |
126 | 1827 |
1828 // He | |
339 | 1829 temp_tissue = (ppHe - sim_pres_tissue_He[ci]) * var_He_e; |
126 | 1830 temp_tissue_safety(); |
339 | 1831 sim_pres_tissue_He[ci] += temp_tissue; |
192 | 1832 } |
167 | 1833 } |
116 | 1834 |
167 | 1835 ////////////////////////////////////////////////////////////////////////////// |
192 | 1836 // sim_limit() |
1837 // | |
1838 // New in v.111 | |
1839 // | |
1840 // Function separated from sim_tissue() to allow recomputing limit on | |
1841 // different depth, because it depends on current gradient factor. | |
167 | 1842 // |
192 | 1843 static void sim_limit(PARAMETER float GF_current) |
116 | 1844 { |
212 | 1845 assert( 0.0 < GF_current && GF_current <= 1.0f); |
1846 | |
192 | 1847 sim_lead_tissue_limit = 0.0; |
212 | 1848 sim_lead_tissue_no = 0; // If no one is critic, keep first tissue. |
192 | 1849 |
338 | 1850 for(ci=0; ci<NUM_COMP; ci++) |
192 | 1851 { |
339 | 1852 overlay float N2 = sim_pres_tissue_N2[ci]; |
1853 overlay float He = sim_pres_tissue_He[ci]; | |
241 | 1854 overlay float p = N2 + He; |
192 | 1855 |
258 | 1856 read_buhlmann_coefficients(); |
241 | 1857 var_N2_a = (var_N2_a * N2 + var_He_a * He) / p; |
1858 var_N2_b = (var_N2_b * N2 + var_He_b * He) / p; | |
192 | 1859 |
1860 // Apply the Eric Baker's varying gradient factor correction. | |
1861 // Note: the correction factor depends both on GF and b, | |
1862 // Actual values are in the 1.5 .. 1.0 range (for a GF=30%), | |
1863 // so that can change who is the leading gas... | |
1864 // Note: Also depends of the GF_current... | |
1865 if( char_I_deco_model == 1 ) | |
302 | 1866 p = ( p - var_N2_a * GF_current) |
1867 / (GF_current / var_N2_b + 1.0 - GF_current); | |
192 | 1868 else |
1869 p = (p - var_N2_a) * var_N2_b; | |
237 | 1870 if( p < 0.0 ) p = 0.0; |
192 | 1871 |
1872 if( p > sim_lead_tissue_limit ) | |
1873 { | |
1874 sim_lead_tissue_no = ci; | |
1875 sim_lead_tissue_limit = p; | |
1876 } | |
1877 } // for ci | |
197 | 1878 |
338 | 1879 assert( sim_lead_tissue_no < NUM_COMP ); |
237 | 1880 assert( 0.0 <= sim_lead_tissue_limit && sim_lead_tissue_limit <= 14.0 ); |
167 | 1881 } |
116 | 1882 |
167 | 1883 ////////////////////////////////////////////////////////////////////////////// |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1884 // clear_deco_table |
167 | 1885 // |
1886 // unchanged in v.101 | |
1887 // | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1888 static void clear_deco_table(void) |
116 | 1889 { |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1890 overlay unsigned char x; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1891 |
338 | 1892 for(x=0; x<NUM_STOPS; ++x) |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1893 { |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1894 internal_deco_time [x] = 0; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1895 internal_deco_depth[x] = 0; |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1896 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1897 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1898 |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1899 ////////////////////////////////////////////////////////////////////////////// |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1900 // update_deco_table |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1901 // |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1902 // Add 1 min to current stop. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1903 // |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1904 // Inputs: |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1905 // temp_depth_limit = stop's depth, in meters. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1906 // In/Out: |
275
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
1907 // internal_deco_depth[] : depth (in metres) of each stops. |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1908 // internal_deco_time [] : time (in minutes) of each stops. |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1909 // |
471 | 1910 static unsigned char update_deco_table() |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1911 { |
192 | 1912 overlay unsigned char x; |
247
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1913 assert( temp_depth_limit < 128 ); // Can't be negativ (overflown). |
ce869aad7440
BUGFIX Count gas switch delay down during ascent (bug bb26)
JeanDo
parents:
241
diff
changeset
|
1914 assert( temp_depth_limit > 0 ); // No stop at surface... |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1915 |
338 | 1916 for(x=0; x<NUM_STOPS; ++x) |
192 | 1917 { |
212 | 1918 // Make sure deco-stops are recorded in order: |
334
4ccdc72ec0e5
BUGFIX minor error in gas-switch algo (spurious surface decostop rarely added).
JeanDo
parents:
326
diff
changeset
|
1919 assert( !internal_deco_depth[x] || temp_depth_limit <= (internal_deco_depth[x]& 0x7F) ); |
212 | 1920 |
279
8514588eb6a2
Mark gas-switch stops for decoplans, displayed in yellow.
JeanDo
parents:
278
diff
changeset
|
1921 if( (internal_deco_depth[x] & 0x7F) == temp_depth_limit ) |
192 | 1922 { |
1923 // Do not overflow (max 255') | |
1924 if( internal_deco_time[x] < 255 ) | |
1925 { | |
1926 internal_deco_time[x]++; | |
471 | 1927 return 1; |
192 | 1928 } |
1929 // But store extra in the next stop... | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1930 } |
192 | 1931 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1932 if( internal_deco_depth[x] == 0 ) |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1933 { |
192 | 1934 internal_deco_depth[x] = temp_depth_limit; |
279
8514588eb6a2
Mark gas-switch stops for decoplans, displayed in yellow.
JeanDo
parents:
278
diff
changeset
|
1935 if( sim_gas_delay > sim_dive_mins ) |
8514588eb6a2
Mark gas-switch stops for decoplans, displayed in yellow.
JeanDo
parents:
278
diff
changeset
|
1936 internal_deco_depth[x] |= 0x80; |
8514588eb6a2
Mark gas-switch stops for decoplans, displayed in yellow.
JeanDo
parents:
278
diff
changeset
|
1937 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1938 internal_deco_time[x] = 1; |
471 | 1939 return 1; |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1940 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1941 } |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1942 |
192 | 1943 // Can't store stops at more than 96m. |
1944 // Or stops at less that 3m too. | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
1945 // Just do nothing with that... |
471 | 1946 return 0; |
167 | 1947 } |
116 | 1948 |
167 | 1949 ////////////////////////////////////////////////////////////////////////////// |
1950 // calc_gradient_factor | |
1951 // | |
165 | 1952 // optimized in v.101 (var_N2_a) |
116 | 1953 // new code in v.102 |
167 | 1954 // |
1955 static void calc_gradient_factor(void) | |
116 | 1956 { |
197 | 1957 overlay float gf; |
339 | 1958 overlay float N2 = pres_tissue_N2[char_O_gtissue_no]; |
1959 overlay float He = pres_tissue_He[char_O_gtissue_no]; | |
237 | 1960 |
338 | 1961 assert( char_O_gtissue_no < NUM_COMP ); |
237 | 1962 assert( 0.800 <= pres_respiration && pres_respiration < 14.0 ); |
197 | 1963 |
293
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1964 // tissue > respiration (currently off-gasing) |
302 | 1965 // GF = 0% when respiration == tissue, ie. bubbles are at equilibrium. |
1966 // GF = 100% when respiration == limit. | |
293
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1967 temp_tissue = N2 + He; |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1968 if( temp_tissue <= pres_respiration ) |
197 | 1969 gf = 0.0; |
1970 else | |
1971 { | |
293
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1972 overlay float limit = calc_lead_tissue_limit; |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1973 // NOTE: in GF model, calc_lead_tissue_limit include already the |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1974 // correction due to gradient factor. To compute the actual |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1975 // current GF, we need to (re-)compute the raw ambiant-pressure |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1976 // limit from the Bühlmann model. |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1977 if( char_I_deco_model == 1 ) |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1978 { |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1979 ci = char_O_gtissue_no; |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1980 read_buhlmann_coefficients(); |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1981 var_N2_a = (var_N2_a * N2 + var_He_a * He) / temp_tissue; |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1982 var_N2_b = (var_N2_b * N2 + var_He_b * He) / temp_tissue; |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1983 limit = (temp_tissue - var_N2_a) * var_N2_b; |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1984 } |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1985 |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1986 gf = (temp_tissue - pres_respiration) |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1987 / (temp_tissue - limit) |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1988 * 100.0; |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1989 if( gf > 254.5 ) gf = 255.0; |
197 | 1990 if( gf < 0.0 ) gf = 0.0; |
1991 } | |
293
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1992 char_O_gradient_factor = (unsigned char)(gf+0.5f); |
116 | 1993 |
1994 if (char_I_deco_model == 1) // calculate relative gradient factor | |
1995 { | |
197 | 1996 overlay float rgf; |
1997 | |
293
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
1998 if( low_depth < 1.5 ) |
197 | 1999 rgf = GF_high; |
2000 else | |
2001 { | |
317 | 2002 overlay float temp1 = low_depth * METER_TO_BAR; |
197 | 2003 overlay float temp2 = pres_respiration - pres_surface; |
186 | 2004 |
197 | 2005 if (temp2 <= 0) |
2006 rgf = GF_high; | |
2007 else if (temp2 >= temp1) | |
2008 rgf = GF_low; | |
2009 else | |
2010 rgf = GF_low + (temp1 - temp2)/temp1*GF_delta; | |
2011 } | |
186 | 2012 |
197 | 2013 rgf = gf / rgf; // gf is already in percent |
2014 if( rgf < 0.0 ) rgf = 0.0; | |
293
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
2015 if( rgf > 254.5 ) rgf = 255.0; |
e0083f259552
BUGFIX char_O_gradient_factor calculation in GF model.
JeanDo
parents:
292
diff
changeset
|
2016 char_O_relative_gradient_GF = (unsigned char)(rgf+0.5f); |
116 | 2017 } // calc relative gradient factor |
2018 else | |
2019 { | |
186 | 2020 char_O_relative_gradient_GF = char_O_gradient_factor; |
116 | 2021 } |
167 | 2022 } |
116 | 2023 |
167 | 2024 ////////////////////////////////////////////////////////////////////////////// |
2025 // deco_calc_desaturation_time | |
2026 // | |
116 | 2027 // FIXED N2_ratio |
2028 // unchanged in v.101 | |
310
b20fc8c4ac92
Fix EAD/END display (not mm, m with a trailling space)
JeanDo
parents:
307
diff
changeset
|
2029 // Inputs: int_I_pres_surface, ppWater, char_I_desaturation_multiplier |
233 | 2030 // Outputs: int_O_desaturation_time, char_O_tissue_saturation[0..31] |
167 | 2031 // |
116 | 2032 void deco_calc_desaturation_time(void) |
2033 { | |
338 | 2034 overlay rom const float *ptr; |
2035 | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2036 RESET_C_STACK |
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2037 |
233 | 2038 assert( 800 < int_I_pres_surface && int_I_pres_surface < 1100 ); |
2039 assert( 0 < char_I_desaturation_multiplier && char_I_desaturation_multiplier <= 100 ); | |
2040 | |
260
bde83cac971f
BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
JeanDo
parents:
258
diff
changeset
|
2041 #ifndef CROSS_COMPILE |
bde83cac971f
BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
JeanDo
parents:
258
diff
changeset
|
2042 // Note: we don't use far rom pointer, because the |
bde83cac971f
BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
JeanDo
parents:
258
diff
changeset
|
2043 // 24 bits is to complex, hence we have to set |
bde83cac971f
BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
JeanDo
parents:
258
diff
changeset
|
2044 // the UPPER page ourself... |
bde83cac971f
BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
JeanDo
parents:
258
diff
changeset
|
2045 // --> Set zero if tables are moved to lower pages ! |
bde83cac971f
BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
JeanDo
parents:
258
diff
changeset
|
2046 _asm |
bde83cac971f
BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
JeanDo
parents:
258
diff
changeset
|
2047 movlw 1 |
bde83cac971f
BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
JeanDo
parents:
258
diff
changeset
|
2048 movwf TBLPTRU,0 |
bde83cac971f
BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
JeanDo
parents:
258
diff
changeset
|
2049 _endasm |
bde83cac971f
BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
JeanDo
parents:
258
diff
changeset
|
2050 #endif |
bde83cac971f
BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
JeanDo
parents:
258
diff
changeset
|
2051 |
237 | 2052 N2_ratio = 0.7902; // FIXED sum as stated in bühlmann |
233 | 2053 pres_surface = int_I_pres_surface * 0.001; |
310
b20fc8c4ac92
Fix EAD/END display (not mm, m with a trailling space)
JeanDo
parents:
307
diff
changeset
|
2054 ppN2 = N2_ratio * (pres_surface - ppWater); |
126 | 2055 int_O_desaturation_time = 0; |
491
560764da0629
BUGFIX Surface desat factor missing for Interval planning in GF mode.
JeanDo
parents:
490
diff
changeset
|
2056 float_desaturation_multiplier = char_I_desaturation_multiplier * (0.01 * SURFACE_DESAT_FACTOR); |
233 | 2057 |
338 | 2058 ptr = &buhlmann_ht[0]; |
339 | 2059 for(ci=0; ci<NUM_COMP; ci++) |
126 | 2060 { |
338 | 2061 overlay float var_N2_halftime = *ptr++; |
2062 overlay float var_He_halftime = *ptr++; | |
251 | 2063 overlay unsigned short desat_time; // For a particular compartiment, in min. |
2064 overlay float temp1; | |
2065 overlay float temp2; | |
2066 overlay float temp3; | |
2067 overlay float temp4; | |
338 | 2068 |
2069 assert( 4.0 <= var_N2_halftime && var_N2_halftime <= 635.0 ); | |
2070 assert( 1.5099 <= var_He_halftime && var_He_halftime <= 240.03 ); | |
2071 | |
126 | 2072 // saturation_time (for flight) and N2_saturation in multiples of halftime |
2073 // version v.100: 1.1 = 10 percent distance to totally clean (totally clean is not possible, would take infinite time ) | |
2074 // new in version v.101: 1.07 = 7 percent distance to totally clean (totally clean is not possible, would take infinite time ) | |
260
bde83cac971f
BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
JeanDo
parents:
258
diff
changeset
|
2075 // changes in v.101: 1.05 = 5 percent dist to totally clean is new desaturation point for display and NoFly calculations |
126 | 2076 // N2 |
339 | 2077 temp1 = 1.05 * ppN2 - pres_tissue_N2[ci]; |
2078 temp2 = ppN2 - pres_tissue_N2[ci]; | |
126 | 2079 if (temp2 >= 0.0) |
2080 { | |
233 | 2081 temp1 = 0.0; |
2082 temp2 = 0.0; | |
126 | 2083 } |
2084 else | |
2085 temp1 = temp1 / temp2; | |
251 | 2086 if( 0.0 < temp1 && temp1 < 1.0 ) |
126 | 2087 { |
260
bde83cac971f
BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
JeanDo
parents:
258
diff
changeset
|
2088 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested. |
bde83cac971f
BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
JeanDo
parents:
258
diff
changeset
|
2089 // minus because log is negative. |
bde83cac971f
BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
JeanDo
parents:
258
diff
changeset
|
2090 temp1 = log(1.0 - temp1) / -0.6931; // temp1 is the multiples of half times necessary. |
bde83cac971f
BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
JeanDo
parents:
258
diff
changeset
|
2091 temp2 = var_N2_halftime * temp1 / float_desaturation_multiplier; // time necessary (in minutes ) for complete desaturation (see comment about 5 percent) , new in v.101: float_desaturation_multiplier |
bde83cac971f
BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
JeanDo
parents:
258
diff
changeset
|
2092 |
126 | 2093 } |
2094 else | |
2095 { | |
233 | 2096 temp1 = 0.0; |
2097 temp2 = 0.0; | |
126 | 2098 } |
116 | 2099 |
126 | 2100 // He |
339 | 2101 temp3 = 0.1 - pres_tissue_He[ci]; |
126 | 2102 if (temp3 >= 0.0) |
2103 { | |
233 | 2104 temp3 = 0.0; |
2105 temp4 = 0.0; | |
126 | 2106 } |
2107 else | |
339 | 2108 temp3 = - temp3 / pres_tissue_He[ci]; |
251 | 2109 if( 0.0 < temp3 && temp3 < 1.0 ) |
126 | 2110 { |
260
bde83cac971f
BUGFIX bb13 : deco_calc_desaturation_time() should reset TBLPTR Upper register.
JeanDo
parents:
258
diff
changeset
|
2111 temp3 = log(1.0 - temp3) / -0.6931; // temp1 is the multiples of half times necessary. |
126 | 2112 // 0.6931 is ln(2), because the math function log() calculates with a base of e not 2 as requested. |
2113 // minus because log is negative | |
165 | 2114 temp4 = var_He_halftime * temp3 / float_desaturation_multiplier; // time necessary (in minutes ) for "complete" desaturation, new in v.101 float_desaturation_multiplier |
126 | 2115 } |
2116 else | |
2117 { | |
233 | 2118 temp3 = 0.0; |
2119 temp4 = 0.0; | |
126 | 2120 } |
116 | 2121 |
126 | 2122 // saturation_time (for flight) |
2123 if (temp4 > temp2) | |
203 | 2124 desat_time = (unsigned short)temp4; |
126 | 2125 else |
203 | 2126 desat_time = (unsigned short)temp2; |
252 | 2127 |
251 | 2128 if(desat_time > int_O_desaturation_time) |
2129 int_O_desaturation_time = desat_time; | |
116 | 2130 |
126 | 2131 // N2 saturation in multiples of halftime for display purposes |
339 | 2132 temp2 = temp1 * 20.0; // 0 = 1/8, 120 = 0, 249 = 8 |
2133 temp2 = temp2 + 80.0; // set center | |
126 | 2134 if (temp2 < 0.0) |
2135 temp2 = 0.0; | |
2136 if (temp2 > 255.0) | |
2137 temp2 = 255.0; | |
339 | 2138 char_O_tissue_N2_saturation[ci] = (char)temp2; |
233 | 2139 |
126 | 2140 // He saturation in multiples of halftime for display purposes |
339 | 2141 temp4 = temp3 * 20.0; // 0 = 1/8, 120 = 0, 249 = 8 |
2142 temp4 = temp4 + 80.0; // set center | |
126 | 2143 if (temp4 < 0.0) |
2144 temp4 = 0.0; | |
2145 if (temp4 > 255.0) | |
2146 temp4 = 255.0; | |
339 | 2147 char_O_tissue_He_saturation[ci] = (char)temp4; |
126 | 2148 } // for |
167 | 2149 } |
116 | 2150 |
167 | 2151 ////////////////////////////////////////////////////////////////////////////// |
2152 // calc_wo_deco_step_1_min | |
2153 // | |
116 | 2154 // FIXED N2 Ratio |
2155 // optimized in v.101 (...saturation_multiplier) | |
2156 // desaturation slowed down to 70,42% | |
167 | 2157 // |
2158 static void calc_wo_deco_step_1_min(void) | |
116 | 2159 { |
251 | 2160 assert( 800 < int_I_pres_surface && int_I_pres_surface < 1100 ); |
2161 assert( 800 < int_I_pres_respiration && int_I_pres_respiration < 1100 ); | |
2162 assert( 100 <= char_I_saturation_multiplier && char_I_saturation_multiplier < 200 ); | |
2163 assert( 0 < char_I_desaturation_multiplier && char_I_desaturation_multiplier <= 100 ); | |
2164 | |
116 | 2165 if(flag_in_divemode) |
2166 { | |
2167 flag_in_divemode = 0; | |
2168 set_dbg_end_of_dive(); | |
2169 } | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2170 |
126 | 2171 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann |
368 | 2172 pres_respiration = pres_surface = int_I_pres_surface * 0.001; |
2173 ppN2 = N2_ratio * (pres_respiration - ppWater); | |
200 | 2174 ppHe = 0.0; |
491
560764da0629
BUGFIX Surface desat factor missing for Interval planning in GF mode.
JeanDo
parents:
490
diff
changeset
|
2175 float_desaturation_multiplier = char_I_desaturation_multiplier * (0.01 * SURFACE_DESAT_FACTOR); |
197 | 2176 float_saturation_multiplier = char_I_saturation_multiplier * 0.01; |
126 | 2177 |
339 | 2178 calc_tissue(1); // update the pressure in the tissues N2/He in accordance with the new ambient pressure |
167 | 2179 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
168
diff
changeset
|
2180 clear_deco_table(); |
200 | 2181 char_O_deco_status = 3; // surface new in v.102 : stays in surface state. |
126 | 2182 char_O_nullzeit = 0; |
168 | 2183 int_O_ascenttime = 0; |
323 | 2184 int_O_extra_ascenttime = 0; |
126 | 2185 calc_gradient_factor(); |
167 | 2186 } |
126 | 2187 |
167 | 2188 ////////////////////////////////////////////////////////////////////////////// |
368 | 2189 // calc_dive_interval |
2190 // | |
2191 // Prepare tissue for delay before the next dive simulation. | |
2192 // | |
2193 // Inputs: char_I_dive_interval == delay before dive (in 10' steps). | |
2194 // Outputs: pres_tissue_N2/He[], CNS_fraction | |
2195 // | |
2196 // Should be protected by deco_push_tissues_to_vault(), | |
2197 // deco_pull_tissues_from_vault() | |
2198 // | |
2199 // desaturation slowed down to 70,42%. | |
2200 // | |
2201 static void calc_dive_interval() | |
2202 { | |
2203 overlay unsigned char t; | |
491
560764da0629
BUGFIX Surface desat factor missing for Interval planning in GF mode.
JeanDo
parents:
490
diff
changeset
|
2204 overlay unsigned char backup_model; |
368 | 2205 |
2206 //---- Initialize simulation parameters ---------------------------------- | |
2207 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann | |
2208 pres_respiration = pres_surface = int_I_pres_surface * 0.001; | |
2209 ppN2 = N2_ratio * (pres_respiration - ppWater); | |
2210 ppHe = 0.0; | |
491
560764da0629
BUGFIX Surface desat factor missing for Interval planning in GF mode.
JeanDo
parents:
490
diff
changeset
|
2211 float_desaturation_multiplier = char_I_desaturation_multiplier * (0.01 * SURFACE_DESAT_FACTOR); |
368 | 2212 float_saturation_multiplier = char_I_saturation_multiplier * 0.01; |
2213 | |
491
560764da0629
BUGFIX Surface desat factor missing for Interval planning in GF mode.
JeanDo
parents:
490
diff
changeset
|
2214 // Make sure SURFACE_DESAT_FACTOR is applyed: |
560764da0629
BUGFIX Surface desat factor missing for Interval planning in GF mode.
JeanDo
parents:
490
diff
changeset
|
2215 backup_model = char_I_deco_model; |
560764da0629
BUGFIX Surface desat factor missing for Interval planning in GF mode.
JeanDo
parents:
490
diff
changeset
|
2216 char_I_deco_model = 0; |
560764da0629
BUGFIX Surface desat factor missing for Interval planning in GF mode.
JeanDo
parents:
490
diff
changeset
|
2217 |
368 | 2218 //---- Perform simulation ------------------------------------------------ |
491
560764da0629
BUGFIX Surface desat factor missing for Interval planning in GF mode.
JeanDo
parents:
490
diff
changeset
|
2219 |
368 | 2220 for(t=0; t<char_I_dive_interval; ++t) |
2221 { | |
2222 calc_tissue(2); // period = 10min. | |
2223 CNS_fraction = 0.92587471 * CNS_fraction; // Half-time = 90min: (1/2)^(1/9) | |
2224 } | |
2225 char_O_CNS_fraction = (char)(CNS_fraction * 100.0 + 0.5); | |
491
560764da0629
BUGFIX Surface desat factor missing for Interval planning in GF mode.
JeanDo
parents:
490
diff
changeset
|
2226 |
560764da0629
BUGFIX Surface desat factor missing for Interval planning in GF mode.
JeanDo
parents:
490
diff
changeset
|
2227 //---- Restore model ----------------------------------------------------- |
560764da0629
BUGFIX Surface desat factor missing for Interval planning in GF mode.
JeanDo
parents:
490
diff
changeset
|
2228 char_I_deco_model = backup_model; |
368 | 2229 } |
2230 | |
2231 ////////////////////////////////////////////////////////////////////////////// | |
167 | 2232 ////////////////////////////////////////////////////////////////////////////// |
2233 ////////////////////////////////// deco_hash ///////////////////////////////// | |
2234 ////////////////////////////////////////////////////////////////////////////// | |
2235 ////////////////////////////////////////////////////////////////////////////// | |
126 | 2236 |
184 | 2237 #ifndef CROSS_COMPILE |
116 | 2238 void deco_hash(void) |
2239 { | |
167 | 2240 overlay unsigned char md_i, md_j; // Loop index. |
2241 overlay unsigned char md_t; | |
2242 overlay unsigned char md_buffer[16]; | |
2243 overlay unsigned char md_temp; | |
203 | 2244 overlay unsigned short md_pointer; |
167 | 2245 |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2246 RESET_C_STACK |
126 | 2247 |
2248 // init | |
164 | 2249 for(md_i=0;md_i<16;md_i++) |
126 | 2250 { |
2251 md_state[md_i] = 0; | |
164 | 2252 char_O_hash[md_i] = 0; |
126 | 2253 } // for md_i 16 |
116 | 2254 |
126 | 2255 _asm |
167 | 2256 movlw 0x01 // md_pi address. |
2257 movwf TBLPTRU,0 | |
2258 movlw 0x7E | |
2259 movwf TBLPTRH,0 | |
2260 movlw 0x00 | |
2261 movwf TBLPTRL,0 | |
126 | 2262 _endasm; |
165 | 2263 md_i = 0; |
2264 do { | |
126 | 2265 _asm |
2266 TBLRDPOSTINC | |
2267 movff TABLAT,md_temp | |
2268 _endasm | |
165 | 2269 md_pi_subst[md_i++] = md_temp; |
2270 } while( md_i != 0 ); | |
2271 | |
126 | 2272 _asm |
167 | 2273 movlw 0x00 |
2274 movwf TBLPTRU,0 | |
2275 movlw 0x00 | |
2276 movwf TBLPTRH,0 | |
2277 movlw 0x00 | |
2278 movwf TBLPTRL,0 | |
126 | 2279 _endasm |
167 | 2280 |
126 | 2281 // cycle buffers |
2282 for (md_pointer=0x0000;md_pointer<0x17f3;md_pointer++) | |
2283 { | |
2284 md_t = 0; | |
2285 for (md_i=0;md_i<16;md_i++) | |
2286 { | |
2287 if(md_pointer == 9) | |
164 | 2288 md_temp = char_O_hash[md_i]; |
126 | 2289 else |
2290 { | |
2291 _asm | |
167 | 2292 TBLRDPOSTINC |
2293 movff TABLAT,md_temp | |
126 | 2294 _endasm |
2295 } // else | |
167 | 2296 |
2297 md_buffer[md_i] = md_temp; | |
186 | 2298 md_state[md_i+16] = md_temp; |
2299 md_state[md_i+32] = (unsigned char)(md_temp ^ md_state[md_i]); | |
126 | 2300 } // for md_i 16 |
2301 | |
2302 for (md_i=0;md_i<18;md_i++) | |
2303 { | |
2304 for (md_j=0;md_j<48;md_j++) | |
2305 { | |
167 | 2306 md_state[md_j] ^= md_pi_subst[md_t]; |
126 | 2307 md_t = md_state[md_j]; |
2308 } // for md_j 48 | |
2309 md_t = (unsigned char)(md_t+1); | |
2310 } // for md_i 18 | |
164 | 2311 md_t = char_O_hash[15]; |
126 | 2312 |
2313 for (md_i=0;md_i<16;md_i++) | |
2314 { | |
167 | 2315 char_O_hash[md_i] ^= md_pi_subst[(md_buffer[md_i] ^ md_t)]; |
164 | 2316 md_t = char_O_hash[md_i]; |
126 | 2317 } // for md_i 16 |
2318 } // for md_pointer | |
116 | 2319 } // void deco_hash(void) |
184 | 2320 #endif |
116 | 2321 |
167 | 2322 ////////////////////////////////////////////////////////////////////////////// |
2323 // deco_clear_CNS_fraction | |
2324 // | |
116 | 2325 // new in v.101 |
167 | 2326 // |
116 | 2327 void deco_clear_CNS_fraction(void) |
2328 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2329 RESET_C_STACK |
237 | 2330 |
126 | 2331 CNS_fraction = 0.0; |
2332 char_O_CNS_fraction = 0; | |
167 | 2333 } |
116 | 2334 |
167 | 2335 ////////////////////////////////////////////////////////////////////////////// |
2336 // deco_calc_CNS_fraction | |
2337 // | |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2338 // Input: char_I_actual_ppO2 : Current condition (in decibars). |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2339 // char_I_step_is_1min : use 1min or 10min steps instead of 2sec. |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2340 // CNS_fraction : velue before period. |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2341 // Output: CNS_fraction, char_O_CNS_fraction |
167 | 2342 // |
116 | 2343 void deco_calc_CNS_fraction(void) |
2344 { | |
292 | 2345 overlay float time_factor = 1.0f; |
126 | 2346 RESET_C_STACK |
167 | 2347 |
471 | 2348 assert( 0.0 <= CNS_fraction && CNS_fraction <= 2.56 ); |
237 | 2349 assert( char_I_actual_ppO2 > 15 ); |
2350 | |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2351 if( char_I_step_is_1min == 1 ) |
292 | 2352 time_factor = 30.0f; |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2353 else if( char_I_step_is_1min == 2 ) |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2354 time_factor = 300.0f; |
116 | 2355 |
126 | 2356 if (char_I_actual_ppO2 < 50) |
292 | 2357 ; // no changes |
126 | 2358 else if (char_I_actual_ppO2 < 60) |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2359 CNS_fraction += time_factor/(-540.0 * char_I_actual_ppO2 + 54000.0); |
126 | 2360 else if (char_I_actual_ppO2 < 70) |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2361 CNS_fraction += time_factor/(-450.0 * char_I_actual_ppO2 + 48600.0); |
126 | 2362 else if (char_I_actual_ppO2 < 80) |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2363 CNS_fraction += time_factor/(-360.0 * char_I_actual_ppO2 + 42300.0); |
126 | 2364 else if (char_I_actual_ppO2 < 90) |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2365 CNS_fraction += time_factor/(-270.0 * char_I_actual_ppO2 + 35100.0); |
126 | 2366 else if (char_I_actual_ppO2 < 110) |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2367 CNS_fraction += time_factor/(-180.0 * char_I_actual_ppO2 + 27000.0); |
126 | 2368 else if (char_I_actual_ppO2 < 150) |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2369 CNS_fraction += time_factor/( -90.0 * char_I_actual_ppO2 + 17100.0); |
126 | 2370 else if (char_I_actual_ppO2 < 160) |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2371 CNS_fraction += time_factor/(-225.0 * char_I_actual_ppO2 + 37350.0); |
126 | 2372 else if (char_I_actual_ppO2 < 165) |
292 | 2373 CNS_fraction += time_factor*0.000755; // Arieli et all.(2002): Modeling pulmonary and CNS O2 toxicity... Formula (A1) based on value for 1.55 and c=20 |
126 | 2374 else if (char_I_actual_ppO2 < 170) |
292 | 2375 CNS_fraction += time_factor*0.00102; // example calculation: Sqrt((1.7/1.55)^20)*0.000404 |
126 | 2376 else if (char_I_actual_ppO2 < 175) |
292 | 2377 CNS_fraction += time_factor*0.00136; |
126 | 2378 else if (char_I_actual_ppO2 < 180) |
292 | 2379 CNS_fraction += time_factor*0.00180; |
126 | 2380 else if (char_I_actual_ppO2 < 185) |
292 | 2381 CNS_fraction += time_factor*0.00237; |
126 | 2382 else if (char_I_actual_ppO2 < 190) |
292 | 2383 CNS_fraction += time_factor*0.00310; |
126 | 2384 else if (char_I_actual_ppO2 < 195) |
292 | 2385 CNS_fraction += time_factor*0.00401; |
126 | 2386 else if (char_I_actual_ppO2 < 200) |
292 | 2387 CNS_fraction += time_factor*0.00517; |
126 | 2388 else if (char_I_actual_ppO2 < 230) |
292 | 2389 CNS_fraction += time_factor*0.0209; |
126 | 2390 else |
292 | 2391 CNS_fraction += time_factor*0.0482; // value for 2.5 |
116 | 2392 |
126 | 2393 if (CNS_fraction > 2.5) |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2394 CNS_fraction = 2.55; |
126 | 2395 if (CNS_fraction < 0.0) |
2396 CNS_fraction = 0.0; | |
2397 | |
443
4c7f304de294
BUGFIX: infinite loop for Decoplaner's CNS in CCR mode.
JeanDo
parents:
441
diff
changeset
|
2398 char_O_CNS_fraction = (unsigned char)(100.0 * CNS_fraction + 0.5); |
167 | 2399 } |
116 | 2400 |
167 | 2401 ////////////////////////////////////////////////////////////////////////////// |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2402 // deco_calc_CNS_planning |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2403 // |
488 | 2404 // Compute CNS during predicetd ascent. |
2405 // | |
2406 // Note: Needs a call to deco_push_tissues_to_vault(), | |
2407 // deco_pull_tissues_from_vault() to avoid trashing everything... | |
2408 // | |
2409 // Input: CNS_fraction, char_O_deco_time[], char_O_deco_depth[] | |
2410 // Output: CNS_fraction, char_O_CNS_fraction | |
2411 // | |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2412 void deco_calc_CNS_planning(void) |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2413 { |
490
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2414 overlay unsigned char backup_gas_last_depth; |
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2415 overlay unsigned char backup_gas_last_used; |
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2416 overlay unsigned short backup_gas_delay; |
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2417 overlay unsigned short backup_dive_mins; |
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2418 overlay unsigned char backup_actual_ppO2; |
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2419 |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2420 RESET_C_STACK |
490
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2421 |
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2422 // Backup state machine |
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2423 backup_gas_last_depth = sim_gas_last_depth; |
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2424 backup_gas_last_used = sim_gas_last_used; |
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2425 backup_gas_delay = sim_gas_delay; |
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2426 backup_dive_mins = sim_dive_mins; |
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2427 backup_actual_ppO2 = char_I_actual_ppO2; |
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2428 |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2429 // Uses 1min CNS period: |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2430 char_I_step_is_1min = 1; |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2431 |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2432 //---- Retrieve bottom Gas used, and set variables. |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2433 sim_gas_last_used = char_I_first_gas; |
443
4c7f304de294
BUGFIX: infinite loop for Decoplaner's CNS in CCR mode.
JeanDo
parents:
441
diff
changeset
|
2434 sim_gas_last_depth = 0; // Surface gas marker. |
4c7f304de294
BUGFIX: infinite loop for Decoplaner's CNS in CCR mode.
JeanDo
parents:
441
diff
changeset
|
2435 gas_switch_set(); // Sets initial calc_N2/He_ratio |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2436 |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2437 //---- CCR mode : do the full TTS at once -------------------------------- |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2438 if( char_I_const_ppO2 != 0 ) |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2439 { |
443
4c7f304de294
BUGFIX: infinite loop for Decoplaner's CNS in CCR mode.
JeanDo
parents:
441
diff
changeset
|
2440 overlay unsigned short t; // Needs 16bits here ! |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2441 char_I_actual_ppO2 = char_I_const_ppO2; |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2442 for(t=0; t<int_O_ascenttime; ++t) |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2443 deco_calc_CNS_fraction(); |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2444 } |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2445 else //---- OC mode : have to follow all gas switches... ----------------- |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2446 { |
443
4c7f304de294
BUGFIX: infinite loop for Decoplaner's CNS in CCR mode.
JeanDo
parents:
441
diff
changeset
|
2447 overlay unsigned char i = 0; // Decostop loop counter |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2448 overlay float actual_ppO2; |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2449 overlay unsigned char time, t; |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2450 |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2451 //---- Ascent to surface delay |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2452 // NOTE: count as if time is spent with bottom pressure, |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2453 // AND the bottom gas |
488 | 2454 actual_ppO2 = (pres_surface + char_I_bottom_depth * METER_TO_BAR - ppWater) |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2455 * (1.0 - calc_N2_ratio - calc_He_ratio); |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2456 if( actual_ppO2 < 0.0 ) actual_ppO2 = 0.0; |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2457 if( actual_ppO2 > 2.50 ) actual_ppO2 = 2.55; |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2458 char_I_actual_ppO2 = (unsigned char)(100.0 * actual_ppO2 + 0.5); |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2459 |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2460 // Ascent time (rounded up): |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2461 time = (unsigned char)(0.1 * char_I_bottom_depth + 0.5); |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2462 |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2463 for(t=0; t<time; ++t) |
490
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2464 { |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2465 deco_calc_CNS_fraction(); |
490
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2466 sim_dive_mins++; |
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2467 } |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2468 |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2469 //---- Do all further stops |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2470 for(i=0; i<NUM_STOPS; ++i) |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2471 { |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2472 //---- Get next stop |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2473 time = char_O_deco_time[i]; |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2474 temp_depth_limit = char_O_deco_depth[i] & 0x7F; |
443
4c7f304de294
BUGFIX: infinite loop for Decoplaner's CNS in CCR mode.
JeanDo
parents:
441
diff
changeset
|
2475 if( time == 0 ) break; // End of table: done. |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2476 |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2477 //---- Gas Switch ? |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2478 if( char_O_deco_depth[i] & 0x80 ) |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2479 gas_switch_deepest(); |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2480 |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2481 //---- Convert Depth and N2_ratio to ppO2 |
488 | 2482 actual_ppO2 = (pres_surface + temp_depth_limit * METER_TO_BAR - ppWater) |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2483 * (1.0 - calc_N2_ratio - calc_He_ratio); |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2484 if( actual_ppO2 < 0.0 ) actual_ppO2 = 0.0; |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2485 if( actual_ppO2 > 2.50 ) actual_ppO2 = 2.55; |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2486 char_I_actual_ppO2 = (unsigned char)(100.0 * actual_ppO2 + 0.5); |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2487 |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2488 //---- Apply the stop |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2489 for(t=0; t<time; ++t) |
490
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2490 { |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2491 deco_calc_CNS_fraction(); |
490
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2492 sim_dive_mins++; |
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2493 } |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2494 } |
488 | 2495 } |
2496 | |
2497 // Back to normal mode... | |
2498 char_I_step_is_1min = 0; | |
490
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2499 sim_gas_last_depth = backup_gas_last_depth; |
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2500 sim_gas_last_used = backup_gas_last_used; |
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2501 sim_gas_delay = backup_gas_delay; |
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2502 sim_dive_mins = backup_dive_mins; |
68aa097f0062
BUGFIX (minor) deco_calc_CNS_planning should save ppO2 and gas switch history.
JeanDo
parents:
488
diff
changeset
|
2503 char_I_actual_ppO2 = backup_actual_ppO2; |
439
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2504 } |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2505 |
b9cf06de8aca
BUGFIX: Decoplanner accumulates CNS during ascent (bug #55)
JeanDo
parents:
388
diff
changeset
|
2506 ////////////////////////////////////////////////////////////////////////////// |
167 | 2507 // deco_calc_CNS_decrease_15min |
2508 // | |
116 | 2509 // new in v.101 |
167 | 2510 // |
116 | 2511 // calculates the half time of 90 minutes in 6 steps of 15 min |
200 | 2512 // (Used in sleepmode, for low battery mode). |
167 | 2513 // |
116 | 2514 // Output: char_O_CNS_fraction |
2515 // Uses and Updates: CNS_fraction | |
167 | 2516 // |
116 | 2517 void deco_calc_CNS_decrease_15min(void) |
2518 { | |
237 | 2519 RESET_C_STACK |
2520 assert( 0.0 <= CNS_fraction && CNS_fraction <= 2.5 ); | |
2521 | |
126 | 2522 CNS_fraction = 0.890899 * CNS_fraction; |
167 | 2523 char_O_CNS_fraction = (char)(CNS_fraction * 100.0 + 0.5); |
2524 } | |
116 | 2525 |
167 | 2526 ////////////////////////////////////////////////////////////////////////////// |
2527 // deco_calc_percentage | |
2528 // | |
116 | 2529 // new in v.101 |
167 | 2530 // |
116 | 2531 // calculates int_I_temp * char_I_temp / 100 |
2532 // output is int_I_temp | |
200 | 2533 // |
2534 // Used to compute NoFly remaining time. | |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2535 // |
116 | 2536 void deco_calc_percentage(void) |
2537 { | |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2538 RESET_C_STACK |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2539 |
237 | 2540 assert( 60 <= char_I_temp && char_I_temp <= 100 ); |
2541 assert( 0 <= int_I_temp && int_I_temp < 2880 ); // Less than 48h... | |
2542 | |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2543 int_I_temp = (unsigned short)(((float)int_I_temp * (float)char_I_temp) * 0.01 ); |
237 | 2544 |
302 | 2545 assert( int_I_temp < 2880 ); // Less than 48h... |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2546 } |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2547 |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2548 |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2549 ////////////////////////////////////////////////////////////////////////////// |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2550 // deco_gas_volumes |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2551 // |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2552 // new in v.111 |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2553 // |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2554 // calculates volumes for each gas. |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2555 // |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2556 // Input: char_I_bottom_depth, char_I_bottom_time for planned dive. |
240
d995e220ddac
BUGFIX Gas Usage when first gas is not #1 (bug BB22).
JeanDo
parents:
237
diff
changeset
|
2557 // Gas list. |
d995e220ddac
BUGFIX Gas Usage when first gas is not #1 (bug BB22).
JeanDo
parents:
237
diff
changeset
|
2558 // char_I_first_gas is the bottom gas. |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2559 // decoplan (char_O_deco_depth, char_O_deco_time). |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2560 // CF#54 == TRUE if shallowest stop first. |
478
fd8266b511cc
New SAC (CF56/CF57) in 5..50 l/min range (no more decimal).
JeanDo
parents:
471
diff
changeset
|
2561 // CF#56 == bottom liters/minutes (5 .. 50) or bar/min. |
fd8266b511cc
New SAC (CF56/CF57) in 5..50 l/min range (no more decimal).
JeanDo
parents:
471
diff
changeset
|
2562 // CF#57 == deco liters/minutes (5 .. 50) or bar/min. |
224 | 2563 // Output: int_O_gas_volumes[0..4] in litters * 0.1 |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2564 // |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2565 void deco_gas_volumes(void) |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2566 { |
338 | 2567 overlay float volumes[NUM_GAS]; |
478
fd8266b511cc
New SAC (CF56/CF57) in 5..50 l/min range (no more decimal).
JeanDo
parents:
471
diff
changeset
|
2568 overlay float bottom_usage, deco_usage; |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2569 overlay unsigned char i, deepest_first; |
241 | 2570 overlay unsigned char gas; |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2571 RESET_C_STACK |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2572 |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2573 //---- initialize with bottom consumption -------------------------------- |
338 | 2574 for(i=0; i<NUM_GAS; ++i) // Nothing yet... |
240
d995e220ddac
BUGFIX Gas Usage when first gas is not #1 (bug BB22).
JeanDo
parents:
237
diff
changeset
|
2575 volumes[i] = 0.0; |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2576 |
338 | 2577 assert(1 <= char_I_first_gas && char_I_first_gas <= NUM_GAS); |
241 | 2578 gas = char_I_first_gas - 1; |
2579 | |
478
fd8266b511cc
New SAC (CF56/CF57) in 5..50 l/min range (no more decimal).
JeanDo
parents:
471
diff
changeset
|
2580 bottom_usage = (float) read_custom_function(56); |
265 | 2581 if( bottom_usage > 0.0 ) |
2582 volumes[gas] | |
2583 = (char_I_bottom_depth*0.1 + 1.0) // Use Psurface = 1.0 bar. | |
2584 * char_I_bottom_time // in minutes. | |
2585 * bottom_usage; // In liter/minutes. | |
2586 else | |
2587 volumes[gas] = 65535.0; | |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2588 |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2589 //---- Ascent usage ------------------------------------------------------ |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2590 |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2591 deepest_first = read_custom_function(54) == 0; |
478
fd8266b511cc
New SAC (CF56/CF57) in 5..50 l/min range (no more decimal).
JeanDo
parents:
471
diff
changeset
|
2592 deco_usage = (float) read_custom_function(57); // In liter/minutes. |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2593 |
224 | 2594 // Usage up to the first stop: |
2595 // - computed at MAX depth (easier, safer), | |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2596 // - with an ascent speed of 10m/min. |
224 | 2597 // - with ascent litter / minutes. |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2598 // - still using bottom gas: |
478
fd8266b511cc
New SAC (CF56/CF57) in 5..50 l/min range (no more decimal).
JeanDo
parents:
471
diff
changeset
|
2599 if( deco_usage > 0.0 ) |
265 | 2600 volumes[gas] |
2601 += (char_I_bottom_depth*0.1 + 1.0) // Depth -> bar | |
2602 * (char_I_bottom_depth - char_O_first_deco_depth) * 0.1 // ascent time (min) | |
478
fd8266b511cc
New SAC (CF56/CF57) in 5..50 l/min range (no more decimal).
JeanDo
parents:
471
diff
changeset
|
2603 * deco_usage; // Consumption ( xxx / min @ 1 bar) |
265 | 2604 else |
2605 volumes[gas] = 65535.0; | |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2606 |
338 | 2607 for(i=0; i<NUM_STOPS; ++i) |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2608 { |
241 | 2609 overlay unsigned char j; |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2610 overlay unsigned char depth, time, ascent; |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2611 |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2612 // Manage stops in reverse order (CF#54) |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2613 if( deepest_first ) |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2614 { |
241 | 2615 time = char_O_deco_time[i]; |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2616 if( time == 0 ) break; // End of table: done. |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2617 |
288
9feb224f6871
Manage gas-switch marked stops in volume consumption.
JeanDo
parents:
279
diff
changeset
|
2618 ascent = depth = char_O_deco_depth[i] & 0x7F; |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2619 if( i < 31 ) |
288
9feb224f6871
Manage gas-switch marked stops in volume consumption.
JeanDo
parents:
279
diff
changeset
|
2620 ascent -= char_O_deco_depth[i+1] & 0x7F; |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2621 } |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2622 else |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2623 { |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2624 time = char_O_deco_time[31-i]; |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2625 if( time == 0 ) continue; // not yet: still searh table. |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2626 |
288
9feb224f6871
Manage gas-switch marked stops in volume consumption.
JeanDo
parents:
279
diff
changeset
|
2627 ascent = depth = char_O_deco_depth[31-i] & 0x7F; |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2628 if( i < 31 ) |
288
9feb224f6871
Manage gas-switch marked stops in volume consumption.
JeanDo
parents:
279
diff
changeset
|
2629 ascent -= char_O_deco_depth[30-i] & 0x7F; |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2630 } |
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2631 |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2632 // Gas switch depth ? |
338 | 2633 for(j=0; j<NUM_GAS; ++j) |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2634 { |
234
bb8940caebe1
BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
JeanDo
parents:
233
diff
changeset
|
2635 if( depth <= char_I_deco_gas_change[j] ) |
241 | 2636 if( !char_I_deco_gas_change[gas] || (char_I_deco_gas_change[gas] > char_I_deco_gas_change[j]) ) |
224 | 2637 gas = j; |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2638 } |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2639 |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2640 // usage during stop: |
224 | 2641 // Note: because first gas is not in there, increment gas+1 |
478
fd8266b511cc
New SAC (CF56/CF57) in 5..50 l/min range (no more decimal).
JeanDo
parents:
471
diff
changeset
|
2642 if( deco_usage > 0.0 ) |
265 | 2643 volumes[gas] += (depth*0.1 + 1.0) // depth --> bar. |
2644 * time // in minutes. | |
478
fd8266b511cc
New SAC (CF56/CF57) in 5..50 l/min range (no more decimal).
JeanDo
parents:
471
diff
changeset
|
2645 * deco_usage // in xxx / min @ 1bar. |
265 | 2646 // Plus usage during ascent to the next stop, at 10m/min. |
2647 + (depth*0.1 + 1.0) | |
275
4310ab395dbe
Keep low_depth in float 32bits (w/o rounding) for a better stability.
JeanDo
parents:
270
diff
changeset
|
2648 * ascent*0.1 // metre --> min |
478
fd8266b511cc
New SAC (CF56/CF57) in 5..50 l/min range (no more decimal).
JeanDo
parents:
471
diff
changeset
|
2649 * deco_usage; |
265 | 2650 else |
2651 volumes[gas] = 65535.0; | |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2652 } |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2653 |
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2654 //---- convert results for the ASM interface ----------------------------- |
338 | 2655 for(i=0; i<NUM_GAS; ++i) |
441
4826dd98514b
NEW: Decoplanner OC volumes in liters (or bars), up to 65000.
JeanDo
parents:
439
diff
changeset
|
2656 if( volumes[i] > 65534.0 ) |
224 | 2657 int_O_gas_volumes[i] = 65535; |
222
638f8e17bd51
Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
JeanDo
parents:
218
diff
changeset
|
2658 else |
441
4826dd98514b
NEW: Decoplanner OC volumes in liters (or bars), up to 65000.
JeanDo
parents:
439
diff
changeset
|
2659 int_O_gas_volumes[i] = (unsigned short)(volumes[i] + 0.5); |
116 | 2660 } |
2661 | |
167 | 2662 ////////////////////////////////////////////////////////////////////////////// |
2663 | |
116 | 2664 void deco_push_tissues_to_vault(void) |
2665 { | |
167 | 2666 overlay unsigned char x; |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2667 RESET_C_STACK |
167 | 2668 |
116 | 2669 cns_vault = CNS_fraction; |
339 | 2670 for (x=0;x<NUM_COMP;x++) |
2671 { | |
2672 pres_tissue_N2_vault[x] = pres_tissue_N2[x]; | |
2673 pres_tissue_He_vault[x] = pres_tissue_He[x]; | |
2674 } | |
116 | 2675 } |
167 | 2676 |
116 | 2677 void deco_pull_tissues_from_vault(void) |
2678 { | |
167 | 2679 overlay unsigned char x; |
122
3003a8040b78
FIX again reset C data stack and frame pointer when entering C code.
JeanDo
parents:
116
diff
changeset
|
2680 RESET_C_STACK |
167 | 2681 |
339 | 2682 for (x=0; x<NUM_COMP; x++) |
2683 { | |
2684 pres_tissue_N2[x] = pres_tissue_N2_vault[x]; | |
2685 pres_tissue_He[x] = pres_tissue_He_vault[x]; | |
2686 } | |
292 | 2687 |
2688 // Restore both CNS variable, too. | |
2689 CNS_fraction = cns_vault; | |
2690 char_O_CNS_fraction = (char)(CNS_fraction * 100.0 + 0.5); | |
116 | 2691 } |
2692 | |
167 | 2693 ////////////////////////////////////////////////////////////////////////////// |
2694 // | |
184 | 2695 #ifndef CROSS_COMPILE |
2696 void main() {} | |
2697 #endif |