comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 225:2dc4a7340510

BUGFIX Gas usage for unsorted gas list. + Fix detection of saturation (6553.5 l). + Better handling of unsorted gas list.
author JeanDo
date Thu, 03 Mar 2011 15:52:16 +0100
parents 49c90c5d9603
children 24cd6e256d61
comparison
equal deleted inserted replaced
224:49c90c5d9603 225:2dc4a7340510
192 static float float_saturation_multiplier; // new in v.101 192 static float float_saturation_multiplier; // new in v.101
193 static float float_desaturation_multiplier; // new in v.101 193 static float float_desaturation_multiplier; // new in v.101
194 static float float_deco_distance; // new in v.101 194 static float float_deco_distance; // new in v.101
195 static char flag_in_divemode; // new in v.108 195 static char flag_in_divemode; // new in v.108
196 196
197 static unsigned char deco_gas_change1; // new in v.101 197 static unsigned char deco_gas_change[5]; // new in v.109
198 static unsigned char deco_gas_change2; // new in v.109
199 static unsigned char deco_gas_change3; // new in v.109
200 static unsigned char deco_gas_change4; // new in v.109
201 static unsigned char deco_gas_change5; // new in v.109
202 198
203 //---- Bank 6 parameters ----------------------------------------------------- 199 //---- Bank 6 parameters -----------------------------------------------------
204 #pragma udata bank6=0x600 200 #pragma udata bank6=0x600
205 201
206 float pres_tissue[32]; 202 float pres_tissue[32];
317 DBG_const_ppO2 = const_ppO2; 313 DBG_const_ppO2 = const_ppO2;
318 DBG_deco_ppO2_change = deco_ppO2_change; 314 DBG_deco_ppO2_change = deco_ppO2_change;
319 DBG_deco_ppO2 = deco_ppO2; 315 DBG_deco_ppO2 = deco_ppO2;
320 DBG_deco_N2_ratio = char_I_deco_N2_ratio[0]; 316 DBG_deco_N2_ratio = char_I_deco_N2_ratio[0];
321 DBG_deco_He_ratio = char_I_deco_He_ratio[0]; 317 DBG_deco_He_ratio = char_I_deco_He_ratio[0];
322 DBG_deco_gas_change = deco_gas_change1; 318 DBG_deco_gas_change = deco_gas_change[0];
323 DBG_float_saturation_multiplier = float_saturation_multiplier; 319 DBG_float_saturation_multiplier = float_saturation_multiplier;
324 DBG_float_desaturation_multiplier = float_desaturation_multiplier; 320 DBG_float_desaturation_multiplier = float_desaturation_multiplier;
325 DBG_float_deco_distance = float_deco_distance; 321 DBG_float_deco_distance = float_deco_distance;
326 322
327 //---- Setup some error (?) conditions ----------------------------------- 323 //---- Setup some error (?) conditions -----------------------------------
425 temp_DBS |= DBG_HEwoHE; 421 temp_DBS |= DBG_HEwoHE;
426 422
427 if(DBG_deco_ppO2 != deco_ppO2) 423 if(DBG_deco_ppO2 != deco_ppO2)
428 temp_DBS |= DBG_C_DPPO2; 424 temp_DBS |= DBG_C_DPPO2;
429 425
430 if( DBG_deco_gas_change != deco_gas_change1 426 if( DBG_deco_gas_change != deco_gas_change[0]
431 || DBG_deco_N2_ratio != char_I_deco_N2_ratio[0] 427 || DBG_deco_N2_ratio != char_I_deco_N2_ratio[0]
432 || DBG_deco_He_ratio != char_I_deco_He_ratio[0] ) 428 || DBG_deco_He_ratio != char_I_deco_He_ratio[0] )
433 temp_DBS |= DBG_C_DGAS; 429 temp_DBS |= DBG_C_DGAS;
434 430
435 if(DBG_float_deco_distance != float_deco_distance) 431 if(DBG_float_deco_distance != float_deco_distance)
859 } 855 }
860 856
861 ////////////////////////////////////////////////////////////////////////////// 857 //////////////////////////////////////////////////////////////////////////////
862 // Find deepest available gas. 858 // Find deepest available gas.
863 // 859 //
864 // Input: deco_gas_change* 860 // Input: deco_gas_change[]
865 // sim_gas_delay, sim_gas_last_used, sim_dive_mins. 861 // sim_gas_delay, sim_gas_last_used, sim_dive_mins.
866 // 862 //
867 // Output: temp_depth_limit, sim_gas_delay, sim_gas_last_used IFF the is a switch. 863 // Output: temp_depth_limit, sim_gas_delay, sim_gas_last_used IFF the is a switch.
868 // 864 //
869 static void deepest_gas_switch(void) 865 static void deepest_gas_switch(void)
871 overlay unsigned char temp_gas_switch = 0; 867 overlay unsigned char temp_gas_switch = 0;
872 overlay unsigned char switch_deco = 0; 868 overlay unsigned char switch_deco = 0;
873 869
874 if (char_I_const_ppO2 == 0) 870 if (char_I_const_ppO2 == 0)
875 { 871 {
876 // Keep selecting the best gas during the ascent simulation. 872 overlay unsigned char j;
877 // Add a one meter margin in depth comparaison. 873
878 if( deco_gas_change1 && ((temp_depth_limit-1) <= deco_gas_change1)) 874 // Loop over all enabled gas, to find the deepest enabled one above us.
879 { 875 for(temp_gas_switch=j=0; j<5; ++j)
880 temp_gas_switch = 1; 876 {
881 switch_deco = deco_gas_change1; 877 if( temp_depth_limit <= deco_gas_change[j] )
882 } 878 if( (temp_gas_switch == 0) || (switch_deco < deco_gas_change[j]) )
883 else if(deco_gas_change2 && ((temp_depth_limit-1) <= deco_gas_change2)) 879 {
884 { 880 temp_gas_switch = j+1;
885 temp_gas_switch = 2; 881 switch_deco = deco_gas_change[j];
886 switch_deco = deco_gas_change2; 882 }
887 } 883 }
888 else if(deco_gas_change3 && ((temp_depth_limit-1) <= deco_gas_change3))
889 {
890 temp_gas_switch = 3;
891 switch_deco = deco_gas_change3;
892 }
893 else if(deco_gas_change4 && ((temp_depth_limit-1) <= deco_gas_change4))
894 {
895 temp_gas_switch = 4;
896 switch_deco = deco_gas_change4;
897 }
898 else if(deco_gas_change5 && ((temp_depth_limit-1) <= deco_gas_change5))
899 {
900 temp_gas_switch = 5;
901 switch_deco = deco_gas_change5;
902 }
903 } 884 }
904 885
905 // If there is a better gas available 886 // If there is a better gas available
906 if( temp_gas_switch ) 887 if( temp_gas_switch )
907 { 888 {
940 overlay unsigned char temp_gas_switch = 0; 921 overlay unsigned char temp_gas_switch = 0;
941 overlay unsigned char switch_deco = 0; 922 overlay unsigned char switch_deco = 0;
942 923
943 if (char_I_const_ppO2 == 0) 924 if (char_I_const_ppO2 == 0)
944 { 925 {
945 // Keep selecting the best gas during the ascent simulation. 926 overlay unsigned char j;
946 // Add a one meter margin in depth comparaison. 927
947 if( deco_gas_change5 && ((temp_depth_limit-1) <= deco_gas_change5)) 928 // Loop over all enabled gas, to find the shallowest enabled one above us.
948 { 929 for(temp_gas_switch=j=0; j<5; ++j)
949 temp_gas_switch = 5; 930 {
950 switch_deco = deco_gas_change5; 931 if( temp_depth_limit <= deco_gas_change[j] )
951 } 932 if( (temp_gas_switch == 0) || (switch_deco > deco_gas_change[j]) )
952 else if(deco_gas_change4 && ((temp_depth_limit-1) <= deco_gas_change4)) 933 {
953 { 934 temp_gas_switch = j+1;
954 temp_gas_switch = 4; 935 switch_deco = deco_gas_change[j];
955 switch_deco = deco_gas_change4; 936 }
956 } 937 }
957 else if(deco_gas_change3 && ((temp_depth_limit-1) <= deco_gas_change3))
958 {
959 temp_gas_switch = 3;
960 switch_deco = deco_gas_change3;
961 }
962 else if(deco_gas_change2 && ((temp_depth_limit-1) <= deco_gas_change2))
963 {
964 temp_gas_switch = 2;
965 switch_deco = deco_gas_change2;
966 }
967 else if(deco_gas_change1 && ((temp_depth_limit-1) <= deco_gas_change1))
968 {
969 temp_gas_switch = 1;
970 switch_deco = deco_gas_change1;
971 }
972 } 938 }
973 939
974 // If there is a better gas available 940 // If there is a better gas available
975 if( temp_gas_switch ) 941 if( temp_gas_switch )
976 { 942 {
1231 1197
1232 // Keep a margin of 150mbar = 1.50m 1198 // Keep a margin of 150mbar = 1.50m
1233 int_temp = (int_I_pres_respiration - int_I_pres_surface) 1199 int_temp = (int_I_pres_respiration - int_I_pres_surface)
1234 + MBAR_REACH_GASCHANGE_AUTO_CHANGE_OFF; 1200 + MBAR_REACH_GASCHANGE_AUTO_CHANGE_OFF;
1235 1201
1236 deco_gas_change1 = 0; 1202 deco_gas_change[0] = 0;
1237 deco_gas_change2 = 0; 1203 deco_gas_change[1] = 0;
1238 deco_gas_change3 = 0; 1204 deco_gas_change[2] = 0;
1239 deco_gas_change4 = 0; 1205 deco_gas_change[3] = 0;
1240 deco_gas_change5 = 0; 1206 deco_gas_change[4] = 0;
1241 1207
1242 // Gas are selectable if we did not pass the change depth by more than 1.50m: 1208 // Gas are selectable if we did not pass the change depth by more than 1.50m:
1243 if(char_I_deco_gas_change[0]) 1209 if(char_I_deco_gas_change[0])
1244 { 1210 {
1245 if( int_temp > 100 *(short)char_I_deco_gas_change[0] ) 1211 if( int_temp > 100 *(short)char_I_deco_gas_change[0] )
1246 deco_gas_change1 = char_I_deco_gas_change[0]; 1212 deco_gas_change[0] = char_I_deco_gas_change[0];
1247 } 1213 }
1248 if(char_I_deco_gas_change[1]) 1214 if(char_I_deco_gas_change[1])
1249 { 1215 {
1250 if( int_temp > 100 *(short)char_I_deco_gas_change[1] ) 1216 if( int_temp > 100 *(short)char_I_deco_gas_change[1] )
1251 deco_gas_change2 = char_I_deco_gas_change[1]; 1217 deco_gas_change[1] = char_I_deco_gas_change[1];
1252 } 1218 }
1253 if(char_I_deco_gas_change[2]) 1219 if(char_I_deco_gas_change[2])
1254 { 1220 {
1255 if( int_temp > 100 *(short)char_I_deco_gas_change[2] ) 1221 if( int_temp > 100 *(short)char_I_deco_gas_change[2] )
1256 deco_gas_change3 = char_I_deco_gas_change[2]; 1222 deco_gas_change[2] = char_I_deco_gas_change[2];
1257 } 1223 }
1258 if(char_I_deco_gas_change[3]) 1224 if(char_I_deco_gas_change[3])
1259 { 1225 {
1260 if( int_temp > 100 *(short)char_I_deco_gas_change[3] ) 1226 if( int_temp > 100 *(short)char_I_deco_gas_change[3] )
1261 deco_gas_change4 = char_I_deco_gas_change[3]; 1227 deco_gas_change[3] = char_I_deco_gas_change[3];
1262 } 1228 }
1263 if(char_I_deco_gas_change[4]) 1229 if(char_I_deco_gas_change[4])
1264 { 1230 {
1265 if( int_temp > 100 *(short)char_I_deco_gas_change[4] ) 1231 if( int_temp > 100 *(short)char_I_deco_gas_change[4] )
1266 deco_gas_change5 = char_I_deco_gas_change[4]; 1232 deco_gas_change[4] = char_I_deco_gas_change[4];
1267 } 1233 }
1268 1234
1269 const_ppO2 = char_I_const_ppO2 * 0.01; 1235 const_ppO2 = char_I_const_ppO2 * 0.01;
1270 deco_ppO2_change = char_I_deco_ppO2_change / 99.95 1236 deco_ppO2_change = char_I_deco_ppO2_change / 99.95
1271 + pres_surface 1237 + pres_surface
2195 2161
2196 for(i=0; i<32 && char_O_deco_depth[i] > 0; ++i) 2162 for(i=0; i<32 && char_O_deco_depth[i] > 0; ++i)
2197 { 2163 {
2198 overlay unsigned char j, gas; 2164 overlay unsigned char j, gas;
2199 // Gas switch depth ? 2165 // Gas switch depth ?
2200 for(gas=j=0; j<4; ++j) 2166 for(gas=j=0; j<5; ++j)
2201 { 2167 {
2202 if( char_O_deco_depth[i] <= char_I_deco_gas_change[j] ) 2168 if( char_O_deco_depth[i] <= char_I_deco_gas_change[j] )
2203 if( (gas == 0) || (char_I_deco_gas_change[gas] > char_I_deco_gas_change[j]) ) 2169 if( (gas == 0) || (char_I_deco_gas_change[gas] > char_I_deco_gas_change[j]) )
2204 gas = j; 2170 gas = j;
2205 } 2171 }
2206 2172
2207 // usage during stop: 2173 // usage during stop:
2208 // Note: because first gas is not in there, increment gas+1 2174 // Note: because first gas is not in there, increment gas+1
2209 volumes[gas+1] += (char_O_deco_depth[i]*0.1 + 1.0)// Use Psurface = 1.0 bar. 2175 volumes[gas] += (char_O_deco_depth[i]*0.1 + 1.0)// Use Psurface = 1.0 bar.
2210 * char_O_deco_time[i] // in minutes. 2176 * char_O_deco_time[i] // in minutes.
2211 * ascent_usage 2177 * ascent_usage
2212 // Plus usage during ascent to the next stop, at 10m/min. 2178 // Plus usage during ascent to the next stop, at 10m/min.
2213 + (char_O_deco_depth[i]*0.1 + 1.0) 2179 + (char_O_deco_depth[i]*0.1 + 1.0)
2214 * (char_O_deco_depth[i] - char_O_deco_depth[i+1]) * 0.1 2180 * (char_O_deco_depth[i] - char_O_deco_depth[i+1]) * 0.1
2215 * ascent_usage; 2181 * ascent_usage;
2216 } 2182 }
2217 2183
2218 //---- convert results for the ASM interface ----------------------------- 2184 //---- convert results for the ASM interface -----------------------------
2219 for(i=0; i<5; ++i) 2185 for(i=0; i<5; ++i)
2220 if( volumes[i] > 6553.4 ) 2186 if( volumes[i] > 6553.4 )