comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 247:ce869aad7440

BUGFIX Count gas switch delay down during ascent (bug bb26) + Detect gas switch during ascent in the range [stop, stop-3m[ + Fix recording switch stops at zero meter.
author JeanDo
date Tue, 29 Mar 2011 16:17:12 +0200
parents f44274d8440a
children f0cba9cff25c
comparison
equal deleted inserted replaced
246:90af80e57b49 247:ce869aad7440
890 // 890 //
891 // Output: sim_gas_depth_used 891 // Output: sim_gas_depth_used
892 // 892 //
893 static void gas_switch_find_current(void) 893 static void gas_switch_find_current(void)
894 { 894 {
895 if( sim_gas_last_used == 0 ) 895 overlay unsigned char j;
896 { 896 overlay unsigned char N2 = (unsigned char)(N2_ratio * 100 + 0.5);
897 overlay unsigned char j; 897 overlay unsigned char He = (unsigned char)(He_ratio * 100 + 0.5);
898 overlay unsigned char N2 = (unsigned char)(N2_ratio * 100 + 0.5); 898
899 overlay unsigned char He = (unsigned char)(He_ratio * 100 + 0.5); 899 for(j=0; j<5; ++j)
900 for(j=0; j<5; ++j) 900 {
901 { 901 // Make sure to detect if we are already breathing some gas in
902 // Make sure to detect if we are already breathing some gas in 902 // the current list (happends when first gas do have a depth).
903 // the current list (happends when first gas do have a depth). 903 if( N2 == char_I_deco_N2_ratio[j]
904 if( N2 == char_I_deco_N2_ratio[j] 904 && He == char_I_deco_He_ratio[j]
905 && He == char_I_deco_He_ratio[j] ) 905 )
906 {
907 temp_depth_limit = sim_gas_last_depth = char_I_deco_gas_change[j];
908 sim_gas_last_used = j+1;
909 break;
910 }
911 }
912
913 // If there is no gas-switch-delay running ?
914 if( sim_gas_delay <= sim_dive_mins)
915 {
916 // Compute current depth:
917 overlay unsigned char depth = (unsigned char)((pres_respiration - pres_surface) / 0.09985);
918 assert( depth < 130 );
919
920 // And if I'm above the last decostop (with the 3m margin) ?
921 if( (sim_gas_last_depth-3) > depth )
922 {
923 for(j=0; j<5; ++j)
906 { 924 {
907 sim_gas_last_depth = char_I_deco_gas_change[j]; 925 // And If I am in the range of a valide stop ?
908 sim_gas_last_used = j+1; 926 // (again, with the same 3m margin)
909 break; 927 if( char_I_deco_gas_change[j]
928 && depth <= char_I_deco_gas_change[j]
929 && depth >= (char_I_deco_gas_change[j] - 3)
930 )
931 {
932 // Then start gas-switch timer there,
933 sim_gas_delay = sim_dive_mins
934 + read_custom_function(55);
935
936 // And make sure decostop will be recorded at the right depth.
937 temp_depth_limit = char_I_deco_gas_change[j];
938 break;
939 }
910 } 940 }
911 } 941 }
942 else
943 // Make clear there is no deay anymore.
944 sim_gas_delay = 0;
912 } 945 }
913 } 946 }
914 947
915 ////////////////////////////////////////////////////////////////////////////// 948 //////////////////////////////////////////////////////////////////////////////
916 // Find deepest available gas. 949 // Find deepest available gas.
946 // Gas deeper than the current/previous one ? Skip ! 979 // Gas deeper than the current/previous one ? Skip !
947 if( sim_gas_last_depth && deco_gas_change[j] >= sim_gas_last_depth ) 980 if( sim_gas_last_depth && deco_gas_change[j] >= sim_gas_last_depth )
948 continue; 981 continue;
949 982
950 // First, or deeper ? 983 // First, or deeper ?
951 if( (switch_last == 0) || (switch_deco < deco_gas_change[j]) ) 984 if( switch_deco < deco_gas_change[j] )
952 { 985 {
953 switch_deco = deco_gas_change[j]; 986 switch_deco = deco_gas_change[j];
954 switch_last = j+1; 987 switch_last = j+1;
955 } 988 }
956 } 989 }
1167 char_O_deco_status = 2; // calc ascent next time. 1200 char_O_deco_status = 2; // calc ascent next time.
1168 break; 1201 break;
1169 1202
1170 case 2: //---- Simulate ascent to first stop ----------------------------- 1203 case 2: //---- Simulate ascent to first stop -----------------------------
1171 // Check proposed gas at begin of ascent simulation 1204 // Check proposed gas at begin of ascent simulation
1172 gas_switch_find_current(); 1205 sim_dive_mins = int_I_divemins; // Init current time.
1173 gas_switch_set(); 1206
1174 1207 gas_switch_find_current(); // Lookup for current gas & time.
1175 sim_dive_mins = int_I_divemins; // and time. 1208 gas_switch_set(); // setup calc_ratio's
1176 backup_gas_used = sim_gas_last_used; // And save for later simu steps. 1209
1177 backup_gas_depth = sim_gas_last_depth;// And save for later simu steps. 1210 backup_gas_used = sim_gas_last_used; // And save for later simu steps.
1211 backup_gas_depth = sim_gas_last_depth; // And save for later simu steps.
1178 backup_gas_delay = sim_gas_delay; 1212 backup_gas_delay = sim_gas_delay;
1179 1213
1180 sim_ascent_to_first_stop(); 1214 sim_ascent_to_first_stop();
1181 1215
1182 char_O_deco_status = 1; // Calc stops next time (deco or gas switch). 1216 char_O_deco_status = 1; // Calc stops next time (deco or gas switch).
1189 // next ascent simulation is done from the current depth: 1223 // next ascent simulation is done from the current depth:
1190 if( char_O_deco_status == 0 ) 1224 if( char_O_deco_status == 0 )
1191 { 1225 {
1192 sim_gas_last_used = backup_gas_used; 1226 sim_gas_last_used = backup_gas_used;
1193 sim_gas_last_depth = backup_gas_depth; 1227 sim_gas_last_depth = backup_gas_depth;
1194 sim_gas_delay = backup_gas_delay; 1228 sim_gas_delay = backup_gas_delay;
1195 } 1229 }
1196 break; 1230 break;
1197 } 1231 }
1198 1232
1199 check_post_dbg(); 1233 check_post_dbg();
1719 // internal_deco_time [] : time (in minutes) of each stops. 1753 // internal_deco_time [] : time (in minutes) of each stops.
1720 // 1754 //
1721 static void update_deco_table() 1755 static void update_deco_table()
1722 { 1756 {
1723 overlay unsigned char x; 1757 overlay unsigned char x;
1724 assert( temp_depth_limit < 128 ); // Can't be negativ (overflown). 1758 assert( temp_depth_limit < 128 ); // Can't be negativ (overflown).
1759 assert( temp_depth_limit > 0 ); // No stop at surface...
1725 1760
1726 for(x=0; x<32; ++x) 1761 for(x=0; x<32; ++x)
1727 { 1762 {
1728 // Make sure deco-stops are recorded in order: 1763 // Make sure deco-stops are recorded in order:
1729 assert( !internal_deco_depth[x] || temp_depth_limit <= internal_deco_depth[x] ); 1764 assert( !internal_deco_depth[x] || temp_depth_limit <= internal_deco_depth[x] );