Mercurial > public > mk2
comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 471:5546da23afab
BUGFIX infinite loop when deco table full.
author | JeanDo |
---|---|
date | Sun, 25 Sep 2011 17:39:44 +0200 |
parents | 68d595db29a1 |
children | fd8266b511cc |
comparison
equal
deleted
inserted
replaced
462:32e1174fb89e | 471:5546da23afab |
---|---|
122 | 122 |
123 static void clear_tissue(void); | 123 static void clear_tissue(void); |
124 static void calc_ascenttime(void); | 124 static void calc_ascenttime(void); |
125 static void update_startvalues(void); | 125 static void update_startvalues(void); |
126 static void clear_deco_table(void); | 126 static void clear_deco_table(void); |
127 static void update_deco_table(void); | 127 static unsigned char update_deco_table(void); |
128 | 128 |
129 static void backup_sim_pres_tissue(void); | 129 static void backup_sim_pres_tissue(void); |
130 static void restore_sim_pres_tissue(void); | 130 static void restore_sim_pres_tissue(void); |
131 static void sim_tissue(PARAMETER unsigned char period); | 131 static void sim_tissue(PARAMETER unsigned char period); |
132 static void sim_limit(PARAMETER float GF_current); | 132 static void sim_limit(PARAMETER float GF_current); |
1476 goto Surface; | 1476 goto Surface; |
1477 | 1477 |
1478 //---- We hit a stop at temp_depth_limit --------------------- | 1478 //---- We hit a stop at temp_depth_limit --------------------- |
1479 temp_deco = temp_depth_limit * METER_TO_BAR // Convert to relative bar, | 1479 temp_deco = temp_depth_limit * METER_TO_BAR // Convert to relative bar, |
1480 + pres_surface; // To absolute. | 1480 + pres_surface; // To absolute. |
1481 update_deco_table(); // Adds a one minute stops. | 1481 if( !update_deco_table() ) // Adds a one minute stops. |
1482 goto Surface; // Deco table full: abort... | |
1482 } | 1483 } |
1483 else | 1484 else |
1484 { | 1485 { |
1485 //---- No stop ----------------------------------------------- | 1486 //---- No stop ----------------------------------------------- |
1486 temp_deco -= (10*METER_TO_BAR); // Ascend 10m, no wait. | 1487 temp_deco -= (10*METER_TO_BAR); // Ascend 10m, no wait. |
1487 | 1488 |
1488 //---- Finish computations once surface is reached ----------- | 1489 //---- Finish computations once surface is reached ----------- |
1489 if( temp_deco <= pres_surface ) | 1490 if( temp_deco <= pres_surface ) |
1490 { | 1491 { |
1491 Surface: | 1492 Surface: |
1492 if( char_O_deco_status == 1 ) // Don't in @+5min variant. | 1493 if( char_O_deco_status == 1 ) // Don't in @+5min variant. |
1493 copy_deco_table(); | 1494 copy_deco_table(); |
1494 | 1495 |
1495 calc_ascenttime(); | 1496 calc_ascenttime(); |
1496 char_O_deco_status = 0; // calc nullzeit next time. | 1497 char_O_deco_status = 0; // calc nullzeit next time. |
1497 char_O_deco_last_stop = 0; // Surface reached (to animate menu) | 1498 char_O_deco_last_stop = 0; // Surface reached (to animate menu) |
1498 return; | 1499 return; |
1499 } | 1500 } |
1500 } | 1501 } |
1501 } | 1502 } |
1502 else | 1503 else |
1503 { | 1504 { |
1504 // Note: if loop==0, temp_depth_limit might not be already set here. | 1505 // Note: if loop==0, temp_depth_limit might not be already set here. |
1505 temp_depth_limit = (int)(0.5 + (temp_deco - pres_surface) * BAR_TO_METER); | 1506 temp_depth_limit = (int)(0.5 + (temp_deco - pres_surface) * BAR_TO_METER); |
1506 update_deco_table(); // Just pass one minute. | 1507 if( !update_deco_table() ) // Just pass one minute. |
1508 goto Surface; // Deco table full: abort... | |
1507 } | 1509 } |
1508 | 1510 |
1509 //---- Then update tissue -------------------------------------------- | 1511 //---- Then update tissue -------------------------------------------- |
1510 sim_dive_mins++; // Advance simulated time by 1 minute. | 1512 sim_dive_mins++; // Advance simulated time by 1 minute. |
1511 gas_switch_set(); // Apply any simulated gas change, once validated. | 1513 gas_switch_set(); // Apply any simulated gas change, once validated. |
1895 // temp_depth_limit = stop's depth, in meters. | 1897 // temp_depth_limit = stop's depth, in meters. |
1896 // In/Out: | 1898 // In/Out: |
1897 // internal_deco_depth[] : depth (in metres) of each stops. | 1899 // internal_deco_depth[] : depth (in metres) of each stops. |
1898 // internal_deco_time [] : time (in minutes) of each stops. | 1900 // internal_deco_time [] : time (in minutes) of each stops. |
1899 // | 1901 // |
1900 static void update_deco_table() | 1902 static unsigned char update_deco_table() |
1901 { | 1903 { |
1902 overlay unsigned char x; | 1904 overlay unsigned char x; |
1903 assert( temp_depth_limit < 128 ); // Can't be negativ (overflown). | 1905 assert( temp_depth_limit < 128 ); // Can't be negativ (overflown). |
1904 assert( temp_depth_limit > 0 ); // No stop at surface... | 1906 assert( temp_depth_limit > 0 ); // No stop at surface... |
1905 | 1907 |
1912 { | 1914 { |
1913 // Do not overflow (max 255') | 1915 // Do not overflow (max 255') |
1914 if( internal_deco_time[x] < 255 ) | 1916 if( internal_deco_time[x] < 255 ) |
1915 { | 1917 { |
1916 internal_deco_time[x]++; | 1918 internal_deco_time[x]++; |
1917 return; | 1919 return 1; |
1918 } | 1920 } |
1919 // But store extra in the next stop... | 1921 // But store extra in the next stop... |
1920 } | 1922 } |
1921 | 1923 |
1922 if( internal_deco_depth[x] == 0 ) | 1924 if( internal_deco_depth[x] == 0 ) |
1924 internal_deco_depth[x] = temp_depth_limit; | 1926 internal_deco_depth[x] = temp_depth_limit; |
1925 if( sim_gas_delay > sim_dive_mins ) | 1927 if( sim_gas_delay > sim_dive_mins ) |
1926 internal_deco_depth[x] |= 0x80; | 1928 internal_deco_depth[x] |= 0x80; |
1927 | 1929 |
1928 internal_deco_time[x] = 1; | 1930 internal_deco_time[x] = 1; |
1929 return; | 1931 return 1; |
1930 } | 1932 } |
1931 } | 1933 } |
1932 | 1934 |
1933 // Can't store stops at more than 96m. | 1935 // Can't store stops at more than 96m. |
1934 // Or stops at less that 3m too. | 1936 // Or stops at less that 3m too. |
1935 // Just do nothing with that... | 1937 // Just do nothing with that... |
1938 return 0; | |
1936 } | 1939 } |
1937 | 1940 |
1938 ////////////////////////////////////////////////////////////////////////////// | 1941 ////////////////////////////////////////////////////////////////////////////// |
1939 // calc_gradient_factor | 1942 // calc_gradient_factor |
1940 // | 1943 // |
2323 void deco_calc_CNS_fraction(void) | 2326 void deco_calc_CNS_fraction(void) |
2324 { | 2327 { |
2325 overlay float time_factor = 1.0f; | 2328 overlay float time_factor = 1.0f; |
2326 RESET_C_STACK | 2329 RESET_C_STACK |
2327 | 2330 |
2328 assert( 0.0 <= CNS_fraction && CNS_fraction <= 2.5 ); | 2331 assert( 0.0 <= CNS_fraction && CNS_fraction <= 2.56 ); |
2329 assert( char_I_actual_ppO2 > 15 ); | 2332 assert( char_I_actual_ppO2 > 15 ); |
2330 | 2333 |
2331 if( char_I_step_is_1min == 1 ) | 2334 if( char_I_step_is_1min == 1 ) |
2332 time_factor = 30.0f; | 2335 time_factor = 30.0f; |
2333 else if( char_I_step_is_1min == 2 ) | 2336 else if( char_I_step_is_1min == 2 ) |