comparison src/p2_deco.c @ 289:30edd177016a

[mq]: 2015-05-29_02-40-44_r288+.diff
author jdg@air
date Fri, 29 May 2015 02:46:44 +0200
parents 08986d479b94
children 2fe34fc0e2ae
comparison
equal deleted inserted replaced
288:08986d479b94 289:30edd177016a
2138 int_I_temp = (unsigned short)(((float)int_I_temp * (float)char_I_temp) * 0.01 ); 2138 int_I_temp = (unsigned short)(((float)int_I_temp * (float)char_I_temp) * 0.01 );
2139 2139
2140 assert( int_I_temp < 5760 ); // Less than 96h too... 2140 assert( int_I_temp < 5760 ); // Less than 96h too...
2141 } 2141 }
2142 2142
2143
2144 ////////////////////////////////////////////////////////////////////////////// 2143 //////////////////////////////////////////////////////////////////////////////
2145 // deco_gas_volumes 2144 // deco_gas_volumes
2146 // 2145 //
2147 // new in v.111 2146 // new in v.111
2148 // 2147 //
2155 // CF#54 == TRUE if shallowest stop first. 2154 // CF#54 == TRUE if shallowest stop first.
2156 // CF#56 == bottom liters/minutes (5 .. 50) or bar/min. 2155 // CF#56 == bottom liters/minutes (5 .. 50) or bar/min.
2157 // CF#57 == deco liters/minutes (5 .. 50) or bar/min. 2156 // CF#57 == deco liters/minutes (5 .. 50) or bar/min.
2158 // Output: int_O_gas_volumes[0..4] in litters * 0.1 2157 // Output: int_O_gas_volumes[0..4] in litters * 0.1
2159 // 2158 //
2160
2161
2162 void deco_gas_volumes(void) 2159 void deco_gas_volumes(void)
2163 { 2160 {
2164 overlay float volumes[NUM_GAS]; 2161 overlay float volumes[NUM_GAS];
2165 overlay float bottom_usage, deco_usage; 2162 overlay float bottom_usage, deco_usage;
2166 overlay unsigned char i; 2163 overlay unsigned char i;
2167 overlay unsigned char gas, depth; 2164 overlay unsigned char gas, depth;
2168 RESET_C_STACK 2165 RESET_C_STACK
2169 2166
2170 //---- initialize with bottom consumption -------------------------------- 2167 //---- initialize --------------------------------------------------------
2171 for(i=0; i<NUM_GAS; ++i) // Nothing yet... 2168 for(i=0; i<NUM_GAS; ++i) // Nothing yet...
2172 volumes[i] = 0.0; 2169 volumes[i] = 0.0;
2173 2170
2171 // TODO: get conso from settings:
2172 bottom_usage = 20; // In liter/minutes.
2173 deco_usage = 20; // In liter/minutes.
2174
2175 // Early return if not defined:
2176 if( deco_usage <= 0.0 || bottom_usage <= 0.0 )
2177 goto done;
2178
2179 //---- Bottom usage -----------------------------------------------------
2174 assert(1 <= char_I_first_gas && char_I_first_gas <= NUM_GAS); 2180 assert(1 <= char_I_first_gas && char_I_first_gas <= NUM_GAS);
2175 gas = char_I_first_gas - 1; 2181 gas = char_I_first_gas - 1;
2176 2182
2177 bottom_usage = 20; // In liter/minutes. 2183 if( char_I_const_ppO2 == 0 )
2178 if( char_I_const_ppO2 == 0 && bottom_usage > 0.0 )
2179 volumes[gas] 2184 volumes[gas]
2180 = (char_I_bottom_depth*0.1 + 1.0) // Use Psurface = 1.0 bar. 2185 = (char_I_bottom_depth*0.1 + 1.0) // Use Psurface = 1.0 bar.
2181 * char_I_bottom_time // in minutes. 2186 * char_I_bottom_time // in minutes.
2182 * bottom_usage; // In liter/minutes. 2187 * bottom_usage; // In liter/minutes.
2183 2188
2184 //---- Ascent usage ------------------------------------------------------ 2189 //---- Ascent usage ------------------------------------------------------
2185 deco_usage = 20; // In liter/minutes.
2186
2187 depth = char_I_bottom_depth; 2190 depth = char_I_bottom_depth;
2188 2191
2189 for(i=0; i<NUM_STOPS; ++i) 2192 for(i=0; i<NUM_STOPS; ++i)
2190 { 2193 {
2191 overlay unsigned char newDepth, time, newGas; 2194 overlay unsigned char newDepth, time, newGas;
2197 newGas = char_O_deco_gas [i]-1; 2200 newGas = char_O_deco_gas [i]-1;
2198 2201
2199 assert(0 < newDepth && newDepth <= depth); 2202 assert(0 < newDepth && newDepth <= depth);
2200 assert(0 <= newGas && newGas < NUM_GAS); 2203 assert(0 <= newGas && newGas < NUM_GAS);
2201 2204
2202 //---- usage BEFORE gas switch (if any), at 10m/min ------------------ 2205 //---- usage BEFORE gas switch (if any), at 10m/min:
2203 volumes[gas] += ((depth+newDepth)*0.05 + 1.0) // average depth --> bar. 2206 volumes[gas] += ((depth+newDepth)*0.05 + 1.0) // average depth --> bar.
2204 * (depth-newDepth)*0.1 // metre --> min 2207 * (depth-newDepth)*0.1 // metre --> min
2205 * deco_usage; 2208 * deco_usage;
2206 2209
2207 //---- Do gas switch, at new depth 2210 //---- Do gas switch, at new depth:
2208 gas = newGas; 2211 gas = newGas;
2209 depth = newDepth; 2212 depth = newDepth;
2210 2213
2211 // Usage at stop: 2214 //---- Usage at stop:
2212 if( deco_usage > 0.0 ) 2215 volumes[gas] += (depth*0.1 + 1.0) // depth --> bar.
2213 volumes[gas] += (depth*0.1 + 1.0) // depth --> bar. 2216 * time // in minutes.
2214 * time // in minutes. 2217 * deco_usage; // in xxx / min @ 1bar.
2215 * deco_usage; // in xxx / min @ 1bar.
2216 else
2217 volumes[gas] = 65535.0;
2218 } 2218 }
2219 2219
2220 // From last stop to surface 2220 // From last stop to surface
2221 if( deco_usage > 0.0 ) 2221 volumes[gas] += (depth*0.05 + 1.0) // avg depth --> bar.
2222 volumes[gas] += (depth*0.05 + 1.0) // avg depth --> bar. 2222 * depth * 0.1 // time to surface, in minutes.
2223 * depth * 0.1 // time to surface, in minutes. 2223 * deco_usage; // in xxx / min @ 1bar.
2224 * deco_usage; // in xxx / min @ 1bar.
2225 2224
2226 //---- convert results for the ASM interface ----------------------------- 2225 //---- convert results for the ASM interface -----------------------------
2226 done:
2227 for(i=0; i<NUM_GAS; ++i) 2227 for(i=0; i<NUM_GAS; ++i)
2228 if( volumes[i] > 65534.0 ) 2228 if( volumes[i] > 65534.0 )
2229 int_O_gas_volumes[i] = 65535; 2229 int_O_gas_volumes[i] = 65535;
2230 else 2230 else
2231 int_O_gas_volumes[i] = (unsigned short)(volumes[i] + 0.5); 2231 int_O_gas_volumes[i] = (unsigned short)(volumes[i] + 0.5);
2232 } 2232 }
2233 2233
2234 ////////////////////////////////////////////////////////////////////////////// 2234 //////////////////////////////////////////////////////////////////////////////
2235 2235
2236
2237
2238 void deco_push_tissues_to_vault(void) 2236 void deco_push_tissues_to_vault(void)
2239 { 2237 {
2240 overlay unsigned char x; 2238 overlay unsigned char x;
2241 RESET_C_STACK 2239 RESET_C_STACK
2242 2240