comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 222:638f8e17bd51

Prototyping deco_gas_volumes() to compute gas consumption per tank with decoplanning.
author JeanDo
date Tue, 01 Mar 2011 14:41:10 +0100
parents f4b79292e31f
children 49c90c5d9603
comparison
equal deleted inserted replaced
221:448478ceccea 222:638f8e17bd51
1262 deco_gas_change3 = 0; 1262 deco_gas_change3 = 0;
1263 deco_gas_change4 = 0; 1263 deco_gas_change4 = 0;
1264 deco_gas_change5 = 0; 1264 deco_gas_change5 = 0;
1265 1265
1266 // Gas are selectable if we did not pass the change depth by more than 1.50m: 1266 // Gas are selectable if we did not pass the change depth by more than 1.50m:
1267 if(char_I_deco_gas_change1) 1267 if(char_I_deco_gas_change[0])
1268 { 1268 {
1269 if( int_temp > 100 *(short)char_I_deco_gas_change1 ) 1269 if( int_temp > 100 *(short)char_I_deco_gas_change[0] )
1270 deco_gas_change1 = char_I_deco_gas_change1; 1270 deco_gas_change1 = char_I_deco_gas_change[0];
1271 } 1271 }
1272 if(char_I_deco_gas_change2) 1272 if(char_I_deco_gas_change[1])
1273 { 1273 {
1274 if( int_temp > 100 *(short)char_I_deco_gas_change2 ) 1274 if( int_temp > 100 *(short)char_I_deco_gas_change[1] )
1275 deco_gas_change2 = char_I_deco_gas_change2; 1275 deco_gas_change2 = char_I_deco_gas_change[1];
1276 } 1276 }
1277 if(char_I_deco_gas_change3) 1277 if(char_I_deco_gas_change[2])
1278 { 1278 {
1279 if( int_temp > 100 *(short)char_I_deco_gas_change3 ) 1279 if( int_temp > 100 *(short)char_I_deco_gas_change[2] )
1280 deco_gas_change3 = char_I_deco_gas_change3; 1280 deco_gas_change3 = char_I_deco_gas_change[2];
1281 } 1281 }
1282 if(char_I_deco_gas_change4) 1282 if(char_I_deco_gas_change[3])
1283 { 1283 {
1284 if( int_temp > 100 *(short)char_I_deco_gas_change4 ) 1284 if( int_temp > 100 *(short)char_I_deco_gas_change[3] )
1285 deco_gas_change4 = char_I_deco_gas_change4; 1285 deco_gas_change4 = char_I_deco_gas_change[3];
1286 } 1286 }
1287 if(char_I_deco_gas_change5) 1287 if(char_I_deco_gas_change[4])
1288 { 1288 {
1289 if( int_temp > 100 *(short)char_I_deco_gas_change5 ) 1289 if( int_temp > 100 *(short)char_I_deco_gas_change[4] )
1290 deco_gas_change5 = char_I_deco_gas_change5; 1290 deco_gas_change5 = char_I_deco_gas_change[4];
1291 } 1291 }
1292 1292
1293 const_ppO2 = char_I_const_ppO2 * 0.01; 1293 const_ppO2 = char_I_const_ppO2 * 0.01;
1294 deco_ppO2_change = char_I_deco_ppO2_change / 99.95 1294 deco_ppO2_change = char_I_deco_ppO2_change / 99.95
1295 + pres_surface 1295 + pres_surface
2163 // 2163 //
2164 // calculates int_I_temp * char_I_temp / 100 2164 // calculates int_I_temp * char_I_temp / 100
2165 // output is int_I_temp 2165 // output is int_I_temp
2166 // 2166 //
2167 // Used to compute NoFly remaining time. 2167 // Used to compute NoFly remaining time.
2168 2168 //
2169 void deco_calc_percentage(void) 2169 void deco_calc_percentage(void)
2170 { 2170 {
2171 RESET_C_STACK 2171 RESET_C_STACK
2172 int_I_temp = (unsigned short)(((float)int_I_temp * (float)char_I_temp) / 100.0); 2172
2173 int_I_temp = (unsigned short)(((float)int_I_temp * (float)char_I_temp) * 0.01 );
2174 }
2175
2176
2177 //////////////////////////////////////////////////////////////////////////////
2178 // deco_gas_volumes
2179 //
2180 // new in v.111
2181 //
2182 // calculates volumes for each gas.
2183 //
2184 // Input: char_I_bottom_depth, char_I_bottom_time for planned dive.
2185 /// Gas list. First gas is the bottom gas.
2186 // decoplan (char_O_deco_depth, char_O_deco_time).
2187 // CF#56 == bottom deci-liters/minutes (0.5 .. 50.0)
2188 // CF#57 == deco deci-liters/minutes (0.5 .. 50.0).
2189 // Output: char_O_gas_volumes[0..4] in litters x 100.
2190 //
2191 void deco_gas_volumes(void)
2192 {
2193 overlay float volumes[5];
2194 overlay float ascent_usage;
2195 overlay unsigned char i, j;
2196 RESET_C_STACK
2197
2198 //---- initialize with bottom consumption --------------------------------
2199 volumes[0] = (char_I_bottom_depth*0.1 + 1.0) // Use Psurface = 1.0 bar.
2200 * char_I_bottom_time // in minutes.
2201 * read_custom_function(56) // In deci-liter/minutes.
2202 * 0.1; // deci-liters --> liters.
2203
2204 for(i=1; i<5; ++i) // Nothing yet...
2205 volumes[i] = 0.0;
2206
2207 //---- Ascent usage ------------------------------------------------------
2208
2209 ascent_usage = read_custom_function(57) * 0.1; // In liter/minutes.
2210
2211 // Usage to the first stop:
2212 // - computed at mean depth (triangular integration),
2213 // - with an ascent speed of 10m/min.
2214 // - with ascent liter / minutes.
2215 // - still using bottom gas:
2216 volumes[0] += (0.05 * (char_I_bottom_depth + char_O_first_deco_depth) + 1.0)
2217 * (char_I_bottom_depth - char_O_first_deco_depth) * 0.1
2218 * ascent_usage;
2219
2220 for(i=0; i<32 && char_O_deco_depth[i] > 0; ++i)
2221 {
2222 // Gas switch depth ?
2223 for(j=4; j>0; --j)
2224 {
2225 if( char_O_deco_depth[i] <= char_I_deco_gas_change[j] )
2226 break;
2227 }
2228
2229 // usage during stop:
2230 volumes[j] += (char_O_deco_depth[i]*0.1 + 1.0)// Use Psurface = 1.0 bar.
2231 * char_O_deco_time[i] // in minutes.
2232 * ascent_usage
2233 // Plus usage during ascent to the next stop, at 10m/min.
2234 + (0.05*(char_O_deco_depth[i] + char_O_deco_depth[i+1]) + 1.0)
2235 * (char_O_deco_depth[i] - char_O_deco_depth[i+1]) * 0.1
2236 * ascent_usage;
2237 }
2238
2239 //---- convert results for the ASM interface -----------------------------
2240 for(i=0; i<5; ++i)
2241 if( volumes[i] > 25499.0 )
2242 char_O_gas_volumes[i] = 255;
2243 else
2244 char_O_gas_volumes[i] = (unsigned char)((volumes[i] + 99.0)*0.01);
2173 } 2245 }
2174 2246
2175 ////////////////////////////////////////////////////////////////////////////// 2247 //////////////////////////////////////////////////////////////////////////////
2176 2248
2177 void deco_push_tissues_to_vault(void) 2249 void deco_push_tissues_to_vault(void)