comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 755:6724df41d4f1

CHANGE: Remove CF55 from decolist TODO: show gas change stops different from decostops
author heinrichsweikamp
date Tue, 22 Oct 2013 10:16:54 +0200
parents 7e7e98247a8a
children 50ed645c251d
comparison
equal deleted inserted replaced
754:780f182ae2b8 755:6724df41d4f1
86 // 2012/09/10: [mH] Fill char_O_deco_time_for_log for logbook write 86 // 2012/09/10: [mH] Fill char_O_deco_time_for_log for logbook write
87 // 2012/10/05: [jDG] Better deco_gas_volumes accuracy (average depth, switch between stop). 87 // 2012/10/05: [jDG] Better deco_gas_volumes accuracy (average depth, switch between stop).
88 // 2013/03/05: [jDG] Should vault low_depth too. 88 // 2013/03/05: [jDG] Should vault low_depth too.
89 // 2013/03/05: [jDG] Wrobell remark: ascent_to_first_stop works better with finer steps (2sec). 89 // 2013/03/05: [jDG] Wrobell remark: ascent_to_first_stop works better with finer steps (2sec).
90 // 2013/05/08: [jDG] A. Salm remark: NOAA tables for CNS are in ATA, not bar. 90 // 2013/05/08: [jDG] A. Salm remark: NOAA tables for CNS are in ATA, not bar.
91 // 2013/10/22: [mH] Remove CF55 stuff
91 // 92 //
92 // TODO: 93 // TODO:
93 // + Allow to abort MD2 calculation (have to restart next time). 94 // + Allow to abort MD2 calculation (have to restart next time).
94 // 95 //
95 // Literature: 96 // Literature:
211 static float pres_diluent; // new in v.101 212 static float pres_diluent; // new in v.101
212 static float const_ppO2; // new in v.101 213 static float const_ppO2; // new in v.101
213 214
214 static unsigned char sim_gas_last_depth; // Depth of last used gas, to detected a gas switch. 215 static unsigned char sim_gas_last_depth; // Depth of last used gas, to detected a gas switch.
215 static unsigned char sim_gas_last_used; // Number of last used gas, to detected a gas switch. 216 static unsigned char sim_gas_last_used; // Number of last used gas, to detected a gas switch.
216 static unsigned short sim_gas_delay; // Time of gas-switch-stop ends [min on dive].
217 static unsigned short sim_dive_mins; // Simulated dive time. 217 static unsigned short sim_dive_mins; // Simulated dive time.
218 static float calc_N2_ratio; // Simulated (switched) nitrogen ratio. 218 static float calc_N2_ratio; // Simulated (switched) nitrogen ratio.
219 static float calc_He_ratio; // Simulated (switched) helium ratio. 219 static float calc_He_ratio; // Simulated (switched) helium ratio.
220 static float CNS_fraction; // new in v.101 220 static float CNS_fraction; // new in v.101
221 static float float_saturation_multiplier; // new in v.101 221 static float float_saturation_multiplier; // new in v.101
882 } 882 }
883 883
884 // If there is a better gas available 884 // If there is a better gas available
885 if( switch_deco ) 885 if( switch_deco )
886 { 886 {
887 unsigned char delay;
888 delay = read_custom_function(55);
889
890 assert( !sim_gas_last_depth || sim_gas_last_depth > switch_deco ); 887 assert( !sim_gas_last_depth || sim_gas_last_depth > switch_deco );
891
892 // Should restart gas-switch delay only when gas do changes...
893 assert( sim_gas_delay <= sim_dive_mins );
894 888
895 sim_gas_last_depth = switch_deco; 889 sim_gas_last_depth = switch_deco;
896 sim_gas_last_used = switch_last; 890 sim_gas_last_used = switch_last;
897 sim_gas_delay = delay 891 return 0;
898 + sim_dive_mins; 892 }
899
900 if( delay )
901 {
902 temp_depth_limit = switch_deco;
903 return 1;
904 }
905 else
906 return 0;
907 }
908
909 sim_gas_delay = 0;
910 return 0; 893 return 0;
911 } 894 }
912 895
913 ////////////////////////////////////////////////////////////////////////////// 896 //////////////////////////////////////////////////////////////////////////////
914 // Calculate gas switches 897 // Calculate gas switches
1044 // 1027 //
1045 static void calc_hauptroutine(void) 1028 static void calc_hauptroutine(void)
1046 { 1029 {
1047 static unsigned char backup_gas_used = 0; 1030 static unsigned char backup_gas_used = 0;
1048 static unsigned char backup_gas_depth = 0; 1031 static unsigned char backup_gas_depth = 0;
1049 static unsigned char backup_gas_delay = 0;
1050 1032
1051 calc_hauptroutine_data_input(); 1033 calc_hauptroutine_data_input();
1052 1034
1053 calc_hauptroutine_update_tissues(); 1035 calc_hauptroutine_update_tissues();
1054 calc_gradient_factor(); 1036 calc_gradient_factor();
1073 locked_GF_step = 0.0; 1055 locked_GF_step = 0.0;
1074 1056
1075 // Reset gas switch history. 1057 // Reset gas switch history.
1076 backup_gas_used = sim_gas_last_used = 0; 1058 backup_gas_used = sim_gas_last_used = 0;
1077 backup_gas_depth = sim_gas_last_depth = 0; 1059 backup_gas_depth = sim_gas_last_depth = 0;
1078 backup_gas_delay = sim_gas_delay = 0;
1079 sim_dive_mins = 0; 1060 sim_dive_mins = 0;
1080 break; 1061 break;
1081 1062
1082 case 0: //---- bottom time ----------------------------------------------- 1063 case 0: //---- bottom time -----------------------------------------------
1083 default: 1064 default:
1104 gas_switch_find_current(); // Lookup for current gas & time. 1085 gas_switch_find_current(); // Lookup for current gas & time.
1105 gas_switch_set(); // setup calc_ratio's 1086 gas_switch_set(); // setup calc_ratio's
1106 1087
1107 backup_gas_used = sim_gas_last_used; // And save for later simu steps. 1088 backup_gas_used = sim_gas_last_used; // And save for later simu steps.
1108 backup_gas_depth = sim_gas_last_depth; // And save for later simu steps. 1089 backup_gas_depth = sim_gas_last_depth; // And save for later simu steps.
1109 backup_gas_delay = sim_gas_delay;
1110 1090
1111 sim_ascent_to_first_stop(); 1091 sim_ascent_to_first_stop();
1112 1092
1113 // Calc stops next time (deco or gas switch). 1093 // Calc stops next time (deco or gas switch).
1114 char_O_deco_status = 1 | ( char_O_deco_status & 4 ); 1094 char_O_deco_status = 1 | ( char_O_deco_status & 4 );
1122 // next ascent simulation is done from the current depth: 1102 // next ascent simulation is done from the current depth:
1123 if( (char_O_deco_status & 3) == 0 ) 1103 if( (char_O_deco_status & 3) == 0 )
1124 { 1104 {
1125 sim_gas_last_used = backup_gas_used; 1105 sim_gas_last_used = backup_gas_used;
1126 sim_gas_last_depth = backup_gas_depth; 1106 sim_gas_last_depth = backup_gas_depth;
1127 sim_gas_delay = backup_gas_delay;
1128 } 1107 }
1129 break; 1108 break;
1130 } 1109 }
1131 1110
1132 } 1111 }
1268 { 1247 {
1269 // Limit loops to 512ms, using the RTC timer 3: 1248 // Limit loops to 512ms, using the RTC timer 3:
1270 if( tmr3() & (512*32) ) 1249 if( tmr3() & (512*32) )
1271 break; 1250 break;
1272 1251
1273 // Do not ascent while doing a gas switch ? 1252 if( calc_nextdecodepth() )
1274 if( sim_gas_delay <= sim_dive_mins )
1275 {
1276 if( calc_nextdecodepth() )
1277 { 1253 {
1278 if( temp_depth_limit == 0 ) 1254 if( temp_depth_limit == 0 )
1279 goto Surface; 1255 goto Surface;
1280 1256
1281 //---- We hit a stop at temp_depth_limit --------------------- 1257 //---- We hit a stop at temp_depth_limit ---------------------
1282 temp_deco = temp_depth_limit * METER_TO_BAR // Convert to relative bar, 1258 temp_deco = temp_depth_limit * METER_TO_BAR // Convert to relative bar,
1283 + pres_surface; // To absolute. 1259 + pres_surface; // To absolute.
1284 if( !update_deco_table() ) // Adds a one minute stops. 1260 if( !update_deco_table() ) // Adds a one minute stops.
1285 goto Surface; // Deco table full: abort... 1261 goto Surface; // Deco table full: abort...
1286 } 1262 }
1287 else 1263 else
1288 { 1264 {
1297 copy_deco_table(); 1273 copy_deco_table();
1298 1274
1299 calc_ascenttime(); 1275 calc_ascenttime();
1300 char_O_deco_status = 0; // calc nullzeit next time. 1276 char_O_deco_status = 0; // calc nullzeit next time.
1301 char_O_deco_last_stop = 0; // Surface reached (to animate menu) 1277 char_O_deco_last_stop = 0; // Surface reached (to animate menu)
1302 return; 1278 return;
1303 } 1279 }
1304 } 1280 }
1305 }
1306 else
1307 {
1308 // Note: if loop==0, temp_depth_limit might not be already set here.
1309 temp_depth_limit = (int)(0.5 + (temp_deco - pres_surface) * BAR_TO_METER);
1310 if( !update_deco_table() ) // Just pass one minute.
1311 goto Surface; // Deco table full: abort...
1312 }
1313
1314 //---- Then update tissue -------------------------------------------- 1281 //---- Then update tissue --------------------------------------------
1315 sim_dive_mins++; // Advance simulated time by 1 minute. 1282 sim_dive_mins++; // Advance simulated time by 1 minute.
1316 gas_switch_set(); // Apply any simulated gas change, once validated. 1283 gas_switch_set(); // Apply any simulated gas change, once validated.
1317 sim_alveolar_presures(); // Updates ppN2 and ppHe. 1284 sim_alveolar_presures(); // Updates ppN2 and ppHe.
1318 sim_tissue(1); // Simulate compartiments for 1 minute. 1285 sim_tissue(1); // Simulate compartiments for 1 minute.
1344 temp_deco = pres_respiration; // Starts from current real depth. 1311 temp_deco = pres_respiration; // Starts from current real depth.
1345 1312
1346 // Are we doing the special @+5min variation ? 1313 // Are we doing the special @+5min variation ?
1347 if(char_O_deco_status & 4) 1314 if(char_O_deco_status & 4)
1348 sim_extra_time(); 1315 sim_extra_time();
1349
1350 // Do we have a gas switch going on ?
1351 if( sim_gas_delay > sim_dive_mins )
1352 return;
1353 1316
1354 //---- Loop until first stop, gas switch, or surface is reached ---------- 1317 //---- Loop until first stop, gas switch, or surface is reached ----------
1355 for(;;) 1318 for(;;)
1356 { 1319 {
1357 overlay float old_deco = temp_deco; // Pamb backup (bars) 1320 overlay float old_deco = temp_deco; // Pamb backup (bars)
1758 } 1721 }
1759 1722
1760 if( internal_deco_depth[x] == 0 ) 1723 if( internal_deco_depth[x] == 0 )
1761 { 1724 {
1762 internal_deco_depth[x] = temp_depth_limit; 1725 internal_deco_depth[x] = temp_depth_limit;
1763 if( sim_gas_delay >= sim_dive_mins )
1764 internal_deco_depth[x] |= 0x80;
1765 1726
1766 internal_deco_time[x] = 1; 1727 internal_deco_time[x] = 1;
1767 return 1; 1728 return 1;
1768 } 1729 }
1769 } 1730 }
2227 RESET_C_STACK 2188 RESET_C_STACK
2228 2189
2229 // Backup state machine 2190 // Backup state machine
2230 backup_gas_last_depth = sim_gas_last_depth; 2191 backup_gas_last_depth = sim_gas_last_depth;
2231 backup_gas_last_used = sim_gas_last_used; 2192 backup_gas_last_used = sim_gas_last_used;
2232 backup_gas_delay = sim_gas_delay;
2233 backup_dive_mins = sim_dive_mins; 2193 backup_dive_mins = sim_dive_mins;
2234 backup_actual_ppO2 = char_I_actual_ppO2; 2194 backup_actual_ppO2 = char_I_actual_ppO2;
2235 2195
2236 // Uses 1min CNS period: 2196 // Uses 1min CNS period:
2237 char_I_step_is_1min = 1; 2197 char_I_step_is_1min = 1;
2320 2280
2321 //---- Back to normal mode... -------------------------------------------- 2281 //---- Back to normal mode... --------------------------------------------
2322 char_I_step_is_1min = 0; 2282 char_I_step_is_1min = 0;
2323 sim_gas_last_depth = backup_gas_last_depth; 2283 sim_gas_last_depth = backup_gas_last_depth;
2324 sim_gas_last_used = backup_gas_last_used; 2284 sim_gas_last_used = backup_gas_last_used;
2325 sim_gas_delay = backup_gas_delay;
2326 sim_dive_mins = backup_dive_mins; 2285 sim_dive_mins = backup_dive_mins;
2327 char_I_actual_ppO2 = backup_actual_ppO2; 2286 char_I_actual_ppO2 = backup_actual_ppO2;
2328 } 2287 }
2329 2288
2330 ////////////////////////////////////////////////////////////////////////////// 2289 //////////////////////////////////////////////////////////////////////////////