comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 312:b7e4e74c0e17 @5 variant

New @5 variant: compute TTS if staying some extra time (CF58) at current depth. * Added extra deco_status, and sim_extra_time() in p2_deco.c * Launched by setting char_O_deco_state to 6, result in int_O_extra_ascenttime * Added 8th divemode customview * Auto stole every other cycles * CF58 menu updated (EN,FR,DE,SP)
author JeanDo
date Tue, 03 May 2011 00:52:42 +0200
parents b20fc8c4ac92
children 1de9eee3837b
comparison
equal deleted inserted replaced
311:91371c7553f5 312:b7e4e74c0e17
74 // 2011/03/21: [jDG] Added gas consumption (CF56 & CF57) evaluation for OCR mode. 74 // 2011/03/21: [jDG] Added gas consumption (CF56 & CF57) evaluation for OCR mode.
75 // 2011/04/10: [jDG] Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco(). 75 // 2011/04/10: [jDG] Use timer TMR3 to limit loops in calc_hauptroutine_calc_deco().
76 // 2011/04/15: [jDG] Store low_depth in 32bits (w/o rounding), for a better stability. 76 // 2011/04/15: [jDG] Store low_depth in 32bits (w/o rounding), for a better stability.
77 // 2011/04/25: [jDG] Added 1mn mode for CNS calculation, to allow it for decoplanning. 77 // 2011/04/25: [jDG] Added 1mn mode for CNS calculation, to allow it for decoplanning.
78 // 2011/04/27: [jDG] Fixed char_O_gradient_factor calculation when model uses gradient-factor. 78 // 2011/04/27: [jDG] Fixed char_O_gradient_factor calculation when model uses gradient-factor.
79 // 2011/05/02: [jDG] Added @+5min variant.
79 // 80 //
80 // TODO: 81 // TODO:
81 // + Allow to abort MD2 calculation (have to restart next time). 82 // + Allow to abort MD2 calculation (have to restart next time).
82 // 83 //
83 // Literature: 84 // Literature:
124 125
125 static void backup_sim_pres_tissue(void); 126 static void backup_sim_pres_tissue(void);
126 static void restore_sim_pres_tissue(void); 127 static void restore_sim_pres_tissue(void);
127 static void sim_tissue(PARAMETER unsigned char period); 128 static void sim_tissue(PARAMETER unsigned char period);
128 static void sim_limit(PARAMETER float GF_current); 129 static void sim_limit(PARAMETER float GF_current);
130 static void sim_extra_time(void);
131
129 static void calc_gradient_factor(void); 132 static void calc_gradient_factor(void);
130 static void calc_wo_deco_step_1_min(void); 133 static void calc_wo_deco_step_1_min(void);
131 134
132 static void calc_hauptroutine_data_input(void); 135 static void calc_hauptroutine_data_input(void);
133 static void calc_hauptroutine_update_tissues(void); 136 static void calc_hauptroutine_update_tissues(void);
1222 // | 2 : simulate ascent to first stop (at 10m/min, less that 16x 1min simu) 1225 // | 2 : simulate ascent to first stop (at 10m/min, less that 16x 1min simu)
1223 // | +-> 1 : simulate up to 16min of stops. 1226 // | +-> 1 : simulate up to 16min of stops.
1224 // | +------< not finished 1227 // | +------< not finished
1225 // +--------< finish 1228 // +--------< finish
1226 // 1229 //
1230 // Added steps 6,5 for @+5 calculation:
1231 // 6 = ascent to first stop (same as 2), except continue to 7
1232 // 7 = same as 1, except loop to 7.
1233 //
1227 static void calc_hauptroutine(void) 1234 static void calc_hauptroutine(void)
1228 { 1235 {
1229 static unsigned char backup_gas_used = 0; 1236 static unsigned char backup_gas_used = 0;
1230 static unsigned char backup_gas_depth = 0; 1237 static unsigned char backup_gas_depth = 0;
1231 static unsigned char backup_gas_delay = 0; 1238 static unsigned char backup_gas_delay = 0;
1266 backup_gas_delay = sim_gas_delay = 0; 1273 backup_gas_delay = sim_gas_delay = 0;
1267 sim_dive_mins = 0; 1274 sim_dive_mins = 0;
1268 break; 1275 break;
1269 1276
1270 case 0: //---- bottom time ----------------------------------------------- 1277 case 0: //---- bottom time -----------------------------------------------
1278 default:
1271 calc_nullzeit(); 1279 calc_nullzeit();
1272 check_ndl(); 1280 check_ndl();
1273 char_O_deco_status = 2; // calc ascent next time. 1281 char_O_deco_status = 2; // calc ascent next time.
1274 break; 1282 break;
1275 1283
1276 case 2: //---- Simulate ascent to first stop ----------------------------- 1284 case 2: //---- Simulate ascent to first stop -----------------------------
1285 case 6: // @+5min variation
1277 // Check proposed gas at begin of ascent simulation 1286 // Check proposed gas at begin of ascent simulation
1278 sim_dive_mins = int_I_divemins; // Init current time. 1287 sim_dive_mins = int_I_divemins; // Init current time.
1279 1288
1280 gas_switch_find_current(); // Lookup for current gas & time. 1289 gas_switch_find_current(); // Lookup for current gas & time.
1281 gas_switch_set(); // setup calc_ratio's 1290 gas_switch_set(); // setup calc_ratio's
1284 backup_gas_depth = sim_gas_last_depth; // And save for later simu steps. 1293 backup_gas_depth = sim_gas_last_depth; // And save for later simu steps.
1285 backup_gas_delay = sim_gas_delay; 1294 backup_gas_delay = sim_gas_delay;
1286 1295
1287 sim_ascent_to_first_stop(); 1296 sim_ascent_to_first_stop();
1288 1297
1289 char_O_deco_status = 1; // Calc stops next time (deco or gas switch). 1298 // Calc stops next time (deco or gas switch).
1299 char_O_deco_status = 1 | ( char_O_deco_status & 4 );
1290 break; 1300 break;
1291 1301
1292 case 1: //---- Simulate stops -------------------------------------------- 1302 case 1: //---- Simulate stops --------------------------------------------
1303 case 5: // @+5 variation.
1293 calc_hauptroutine_calc_deco(); 1304 calc_hauptroutine_calc_deco();
1294 1305
1295 // If simulation is finished, restore the GF low reference, so that 1306 // If simulation is finished, restore the GF low reference, so that
1296 // next ascent simulation is done from the current depth: 1307 // next ascent simulation is done from the current depth:
1297 if( char_O_deco_status == 0 ) 1308 if( (char_O_deco_status & 3) == 0 )
1298 { 1309 {
1299 sim_gas_last_used = backup_gas_used; 1310 sim_gas_last_used = backup_gas_used;
1300 sim_gas_last_depth = backup_gas_depth; 1311 sim_gas_last_depth = backup_gas_depth;
1301 sim_gas_delay = backup_gas_delay; 1312 sim_gas_delay = backup_gas_delay;
1302 } 1313 }
1492 1503
1493 //---- Finish computations once surface is reached ----------- 1504 //---- Finish computations once surface is reached -----------
1494 if( temp_deco <= pres_surface ) 1505 if( temp_deco <= pres_surface )
1495 { 1506 {
1496 Surface: 1507 Surface:
1497 copy_deco_table(); 1508 if( char_O_deco_status == 1 ) // Don't in @+5min variant.
1498 calc_ascenttime(); 1509 copy_deco_table();
1499 char_O_deco_status = 0; // calc nullzeit next time. 1510
1511 calc_ascenttime();
1512 char_O_deco_status = 0; // calc nullzeit next time.
1500 char_O_deco_last_stop = 0; // Surface reached. 1513 char_O_deco_last_stop = 0; // Surface reached.
1501 return; 1514 return;
1502 } 1515 }
1503 } 1516 }
1504 } 1517 }
1511 sim_alveolar_presures(); // Updates ppN2 and ppHe. 1524 sim_alveolar_presures(); // Updates ppN2 and ppHe.
1512 sim_tissue(1); // Simulate compartiments for 1 minute. 1525 sim_tissue(1); // Simulate compartiments for 1 minute.
1513 } 1526 }
1514 1527
1515 // Surface not reached, need more stops... 1528 // Surface not reached, need more stops...
1516 char_O_deco_status = 1; // calc more stops next time.
1517 char_O_deco_last_stop = temp_depth_limit; // Reached depth. 1529 char_O_deco_last_stop = temp_depth_limit; // Reached depth.
1518 } 1530 }
1519 1531
1520 ////////////////////////////////////////////////////////////////////////////// 1532 //////////////////////////////////////////////////////////////////////////////
1521 // Simulation ascention to first deco stop. 1533 // Simulation ascention to first deco stop.
1522 // 1534 //
1523 // Note: because we ascent with a constant speed (10m/mn, ie. 1bar/mn), 1535 // Note: because we ascent with a constant speed (10m/mn, ie. 1bar/mn),
1524 // there is no need to break on more that 16 iterations 1536 // there is no need to break on more that 16 iterations
1525 // (or we are already in deep shit). 1537 // (or we are already in deep shit).
1526 // 1538 //
1539 // if char_O_deco_status indicate @+5 variant, add extra time at current depth,
1540 // before ascent.
1527 void sim_ascent_to_first_stop(void) 1541 void sim_ascent_to_first_stop(void)
1528 { 1542 {
1529 update_startvalues(); 1543 update_startvalues();
1530 clear_deco_table(); 1544 clear_deco_table();
1531 1545
1532 temp_deco = pres_respiration; // Starts from current real depth. 1546 temp_deco = pres_respiration; // Starts from current real depth.
1547
1548 // Are we doing the special @+5min variation ?
1549 if(char_O_deco_status & 4)
1550 sim_extra_time();
1533 1551
1534 // Do we have a gas switch going on ? 1552 // Do we have a gas switch going on ?
1535 if( sim_gas_delay > sim_dive_mins ) 1553 if( sim_gas_delay > sim_dive_mins )
1536 return; 1554 return;
1537 1555
1569 1587
1570 sim_dive_mins++; // Advance simulated time by 1 minute. 1588 sim_dive_mins++; // Advance simulated time by 1 minute.
1571 sim_alveolar_presures(); // temp_deco --> ppN2/ppHe 1589 sim_alveolar_presures(); // temp_deco --> ppN2/ppHe
1572 sim_tissue(1); // and update tissues for 1 min. 1590 sim_tissue(1); // and update tissues for 1 min.
1573 } 1591 }
1592 }
1593
1594 //////////////////////////////////////////////////////////////////////////////
1595 // Simulation extra time at the current depth.
1596 //
1597 // This routine is used for @+5min feature.
1598 void sim_extra_time(void)
1599 {
1600 overlay unsigned char extra = read_custom_function(58);
1601 do {
1602 sim_dive_mins++; // Advance simulated time by 1 minute.
1603 sim_tissue(1); // and update tissues for 1 min.
1604 } while( --extra != 0 );
1574 } 1605 }
1575 1606
1576 ////////////////////////////////////////////////////////////////////////////// 1607 //////////////////////////////////////////////////////////////////////////////
1577 // calc_tissue 1608 // calc_tissue
1578 // 1609 //
1711 } 1742 }
1712 1743
1713 ////////////////////////////////////////////////////////////////////////////// 1744 //////////////////////////////////////////////////////////////////////////////
1714 // calc_ascenttime 1745 // calc_ascenttime
1715 // 1746 //
1747 // Summup ascent from bottom to surface, at 1 bar/min, 1min for last 3 meters,
1748 // and all stops.
1749 //
1750 // Result in int_O_ascenttime, or int_O_extra_ascenttime if in @+5min variant.
1716 static void calc_ascenttime(void) 1751 static void calc_ascenttime(void)
1717 { 1752 {
1718 if (pres_respiration > pres_surface) 1753 if( pres_respiration > pres_surface )
1719 { 1754 {
1720 overlay unsigned char x; 1755 overlay unsigned char x;
1756 overlay unsigned short sum;
1721 1757
1722 // + 0.7 to count 1 minute ascent time from 3 metre to surface 1758 // + 0.7 to count 1 minute ascent time from 3 metre to surface
1723 overlay float ascent = pres_respiration - pres_surface + 0.7; 1759 overlay float ascent = pres_respiration - pres_surface + 0.7;
1724 if (ascent < 0.0) 1760 if (ascent < 0.0)
1725 ascent = 0.0; 1761 ascent = 0.0;
1726 int_O_ascenttime = (unsigned short)(ascent + 0.99); 1762 sum = (unsigned short)(ascent + 0.99);
1727 1763
1728 for(x=0; x<32 && internal_deco_depth[x]; x++) 1764 for(x=0; x<32 && internal_deco_depth[x]; x++)
1729 int_O_ascenttime += (unsigned short)internal_deco_time[x]; 1765 sum += (unsigned short)internal_deco_time[x];
1766
1767 if( char_O_deco_status == 1 )
1768 int_O_ascenttime = sum;
1769 else
1770 int_O_extra_ascenttime = sum;
1730 } 1771 }
1731 else 1772 else
1732 int_O_ascenttime = 0; 1773 int_O_ascenttime = 0;
1733 } 1774 }
1734 1775