comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 766:3b1af9891019

BUGFIX: CNS calculation in decoplan should track gas (no marked changes anymore)
author JeanDo
date Sun, 22 Dec 2013 14:23:11 +0100
parents 50ed645c251d
children 6f54104ea0ee
comparison
equal deleted inserted replaced
765:aac1379d6983 766:3b1af9891019
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 // 2013/10/22: [mH] Remove CF55 stuff
92 // 2013/12/21: [jDG] Fix CNS calculation in decoplan w/o marked gas switch
92 // 93 //
93 // TODO: 94 // TODO:
94 // + Allow to abort MD2 calculation (have to restart next time). 95 // + Allow to abort MD2 calculation (have to restart next time).
95 // 96 //
96 // Literature: 97 // Literature:
667 // 668 //
668 static void copy_deco_table(void) 669 static void copy_deco_table(void)
669 { 670 {
670 // Copy depth of the first (deepest) stop, because when reversing 671 // Copy depth of the first (deepest) stop, because when reversing
671 // order, it will be hard to find... 672 // order, it will be hard to find...
672 char_O_first_deco_depth = internal_deco_depth[0] & 0x7F; 673 char_O_first_deco_depth = internal_deco_depth[0];
673 char_O_first_deco_time = internal_deco_time [0]; 674 char_O_first_deco_time = internal_deco_time [0];
674 675
675 if( read_custom_function(54) & 1 ) //---- Should we reverse table ? ------ 676 if( read_custom_function(54) & 1 ) //---- Should we reverse table ? ------
676 { 677 {
677 overlay unsigned char x, y; 678 overlay unsigned char x, y;
843 ////////////////////////////////////////////////////////////////////////////// 844 //////////////////////////////////////////////////////////////////////////////
844 // Find deepest available gas. 845 // Find deepest available gas.
845 // 846 //
846 // Input: temp_depth_limit, 847 // Input: temp_depth_limit,
847 // deco_gas_change[] 848 // deco_gas_change[]
848 // sim_gas_delay, sim_gas_depth_used, sim_dive_mins. 849 // sim_gas_depth_used, sim_dive_mins.
849 // 850 //
850 // RETURNS TRUE if a stop is needed for gas switch. 851 // RETURNS TRUE if a stop is needed for gas switch.
851 // 852 //
852 // Output: temp_depth_limit, sim_gas_delay, sim_gas_depth_used IFF the is a switch. 853 // Output: temp_depth_limit, sim_gas_depth_used IFF the is a switch.
853 // 854 //
854 // NOTE: might be called from bottom (when sim_gas_delay and sim_gas_depth_used 855 // NOTE: might be called from bottom (when sim_gas_depth_used
855 // are null), or during the ascent to make sure we are not passing a 856 // is null), or during the ascent to make sure we are not passing a
856 // stop (in which case both can be already set). 857 // stop (in which case both can be already set).
857 // 858 //
858 static unsigned char gas_switch_deepest(void) 859 static unsigned char gas_switch_deepest(void)
859 { 860 {
860 overlay unsigned char switch_deco = 0, switch_last = 0; 861 overlay unsigned char switch_deco = 0, switch_last = 0;
1708 assert( temp_depth_limit > 0 ); // No stop at surface... 1709 assert( temp_depth_limit > 0 ); // No stop at surface...
1709 1710
1710 for(x=0; x<NUM_STOPS; ++x) 1711 for(x=0; x<NUM_STOPS; ++x)
1711 { 1712 {
1712 // Make sure deco-stops are recorded in order: 1713 // Make sure deco-stops are recorded in order:
1713 assert( !internal_deco_depth[x] || temp_depth_limit <= (internal_deco_depth[x]& 0x7F) ); 1714 assert( !internal_deco_depth[x] || temp_depth_limit <= internal_deco_depth[x] );
1714 1715
1715 if( (internal_deco_depth[x] & 0x7F) == temp_depth_limit ) 1716 if( internal_deco_depth[x]== temp_depth_limit )
1716 { 1717 {
1717 // Do not overflow (max 255') 1718 // Do not overflow (max 255')
1718 if( internal_deco_time[x] < 255 ) 1719 if( internal_deco_time[x] < 255 )
1719 { 1720 {
1720 internal_deco_time[x]++; 1721 internal_deco_time[x]++;
2183 // 2184 //
2184 void deco_calc_CNS_planning(void) 2185 void deco_calc_CNS_planning(void)
2185 { 2186 {
2186 overlay unsigned char backup_gas_last_depth; 2187 overlay unsigned char backup_gas_last_depth;
2187 overlay unsigned char backup_gas_last_used; 2188 overlay unsigned char backup_gas_last_used;
2188 overlay unsigned short backup_gas_delay;
2189 overlay unsigned short backup_dive_mins; 2189 overlay unsigned short backup_dive_mins;
2190 overlay unsigned char backup_actual_ppO2; 2190 overlay unsigned char backup_actual_ppO2;
2191 2191
2192 RESET_C_STACK 2192 RESET_C_STACK
2193 2193
2239 } 2239 }
2240 2240
2241 //---- Do all further stops ------------------------------------------ 2241 //---- Do all further stops ------------------------------------------
2242 for(i=0; i<NUM_STOPS; ++i) 2242 for(i=0; i<NUM_STOPS; ++i)
2243 { 2243 {
2244 overlay unsigned char switch_gas; 2244 overlay unsigned char stop_gas;
2245 2245
2246 //---- Get next stop, possibly in reverse order ------------------ 2246 //---- Get next stop, possibly in reverse order ------------------
2247 if( deepest_first ) 2247 if( deepest_first )
2248 { 2248 {
2249 time = char_O_deco_time[i]; 2249 time = char_O_deco_time[i];
2250 temp_depth_limit = char_O_deco_depth[i]; 2250 temp_depth_limit = char_O_deco_depth[i];
2251 stop_gas = char_O_deco_gas[i];
2251 } 2252 }
2252 else 2253 else
2253 { 2254 {
2254 time = char_O_deco_time[(NUM_STOPS-1)-i]; 2255 time = char_O_deco_time[(NUM_STOPS-1)-i];
2255 temp_depth_limit = char_O_deco_depth[(NUM_STOPS-1)-i]; 2256 temp_depth_limit = char_O_deco_depth[(NUM_STOPS-1)-i];
2257 stop_gas = char_O_deco_gas[(NUM_STOPS-1)-i];
2256 } 2258 }
2257 if( time == 0 ) continue; 2259 if( time == 0 ) continue;
2258 2260
2259 //---- Gas Switch ? ---------------------------------------------- 2261 //---- Gas Switch ? ----------------------------------------------
2260 switch_gas = temp_depth_limit & 0x80; // Switch flag. 2262 if( stop_gas != sim_gas_last_used )
2261 temp_depth_limit &= 0x7F; // True stop depth.
2262
2263 if( switch_gas )
2264 { 2263 {
2265 gas_switch_deepest(); 2264 sim_gas_last_depth = deco_gas_change[stop_gas-1];
2265 sim_gas_last_used = stop_gas;
2266 gas_switch_set(); 2266 gas_switch_set();
2267 } 2267 }
2268 2268
2269 //---- Convert Depth and N2_ratio to ppO2 ------------------------ 2269 //---- Convert Depth and N2_ratio to ppO2 ------------------------
2270 actual_ppO2 = (pres_surface + temp_depth_limit * METER_TO_BAR) 2270 actual_ppO2 = (pres_surface + temp_depth_limit * METER_TO_BAR)
2385 if( deepest_first ) 2385 if( deepest_first )
2386 { 2386 {
2387 time = char_O_deco_time[i]; 2387 time = char_O_deco_time[i];
2388 if( time == 0 ) break; // End of table: done. 2388 if( time == 0 ) break; // End of table: done.
2389 2389
2390 newDepth = char_O_deco_depth[i] & 0x7F; 2390 newDepth = char_O_deco_depth[i];
2391 } 2391 }
2392 else 2392 else
2393 { 2393 {
2394 time = char_O_deco_time[31-i]; 2394 time = char_O_deco_time[31-i];
2395 if( time == 0 ) continue; // not yet: still search table. 2395 if( time == 0 ) continue; // not yet: still search table.
2396 2396
2397 newDepth = char_O_deco_depth[31-i] & 0x7F; 2397 newDepth = char_O_deco_depth[31-i];
2398 } 2398 }
2399 2399
2400 //---- Gas switch during this step ----------------------------------- 2400 //---- Gas switch during this step -----------------------------------
2401 { 2401 {
2402 overlay unsigned char newGas = 0; 2402 overlay unsigned char newGas = 0;