comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 532:f5a06b9e2fef

cleanup debug stuff
author heinrichsweikamp
date Sat, 17 Dec 2011 10:28:29 +0100
parents 31db81de1d4f
children ba1fb2e23f46
comparison
equal deleted inserted replaced
531:d0f719aa5166 532:f5a06b9e2fef
6 // 6 //
7 // ************************************************************** 7 // **************************************************************
8 8
9 ////////////////////////////////////////////////////////////////////////////// 9 //////////////////////////////////////////////////////////////////////////////
10 // OSTC - diving computer code 10 // OSTC - diving computer code
11 // Copyright (C) 2008 HeinrichsWeikamp GbR 11 // Copyright (C) 2011 HeinrichsWeikamp GbR
12 // 12 //
13 // This program is free software: you can redistribute it and/or modify 13 // This program is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by 14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or 15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version. 16 // (at your option) any later version.
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 "Future TTS" function (CF58). 79 // 2011/05/02: [jDG] Added "Future TTS" function (CF58).
80 // 2011/05/17: [jDG] Various cleanups. 80 // 2011/05/17: [jDG] Various cleanups.
81 // 2011/08/08: [jDG] Computes CNS during deco planning ascent. 81 // 2011/08/08: [jDG] Computes CNS during deco planning ascent.
82 // 2011/11/24: [jDG] Slightly faster and better NDL computation. 82 // 2011/11/24: [jDG] Slightly faster and better NDL computation.
83 // 2011/12/17: [mH] Remove of the useless debug stuff
83 // 84 //
84 // TODO: 85 // TODO:
85 // + Allow to abort MD2 calculation (have to restart next time). 86 // + Allow to abort MD2 calculation (have to restart next time).
86 // 87 //
87 // Literature: 88 // Literature:
234 //---- Bank 9 parameters ----------------------------------------------------- 235 //---- Bank 9 parameters -----------------------------------------------------
235 #pragma udata bank9=0x900 236 #pragma udata bank9=0x900
236 237
237 static char md_state[48]; // DONT MOVE !! // has to be at the beginning of bank 9 for the asm code!!! 238 static char md_state[48]; // DONT MOVE !! // has to be at the beginning of bank 9 for the asm code!!!
238 239
239 // internal, dbg:
240 static unsigned char DBG_char_I_deco_model; // new in v.108.
241 static unsigned char DBG_char_I_depth_last_deco; // new in v.108
242 static unsigned char DBG_deco_gas_change; // new in v.108
243 static unsigned char DBG_deco_N2_ratio; // new in v.108
244 static unsigned char DBG_deco_He_ratio; // new in v.108
245 static float DBG_pres_surface; // new in v.108
246 static float DBG_GF_low; // new in v.108
247 static float DBG_GF_high; // new in v.108
248 static float DBG_const_ppO2; // new in v.108
249 static float DBG_float_saturation_multiplier; // new in v.108
250 static float DBG_float_desaturation_multiplier; // new in v.108
251 static float DBG_float_deco_distance; // new in v.108
252 static float DBG_N2_ratio; // new in v.108
253 static float DBG_He_ratio; // new in v.108
254
255 ////////////////////////////////////////////////////////////////////////////// 240 //////////////////////////////////////////////////////////////////////////////
256 ////////////////////////////////////////////////////////////////////////////// 241 //////////////////////////////////////////////////////////////////////////////
257 ///////////////////////////// THE LOOKUP TABLES ////////////////////////////// 242 ///////////////////////////// THE LOOKUP TABLES //////////////////////////////
258 ////////////////////////////////////////////////////////////////////////////// 243 //////////////////////////////////////////////////////////////////////////////
259 ////////////////////////////////////////////////////////////////////////////// 244 //////////////////////////////////////////////////////////////////////////////
296 // moved from 0x0D000 to 0x0C000 in v.108 281 // moved from 0x0D000 to 0x0C000 in v.108
297 282
298 #pragma code p2_deco = 0x0C000 283 #pragma code p2_deco = 0x0C000
299 284
300 ////////////////////////////////////////////////////////////////////////////// 285 //////////////////////////////////////////////////////////////////////////////
301 // DBS - debug on start of dive
302 //
303 static void create_dbs_set_dbg_and_ndl20mtr(void)
304 {
305 overlay char i; // Local loop index.
306
307 //---- Reset DEBUG bit fields --------------------------------------------
308 int_O_DBS_bitfield = 0;
309 int_O_DBS2_bitfield = 0;
310 if(int_O_DBG_pre_bitfield & DBG_RUN)
311 int_O_DBG_pre_bitfield = DBG_RESTART;
312 else
313 int_O_DBG_pre_bitfield = DBG_RUN;
314 int_O_DBG_post_bitfield = 0;
315
316 //---- Set 20meters ND limit ---------------------------------------------
317 char_O_NDL_at_20mtr = 255;
318
319 //---- Copy all dive parameters ------------------------------------------
320 DBG_N2_ratio = N2_ratio;
321 DBG_He_ratio = He_ratio;
322 DBG_char_I_deco_model = char_I_deco_model;
323 DBG_char_I_depth_last_deco = char_I_depth_last_deco;
324 DBG_pres_surface = pres_surface;
325 DBG_GF_low = GF_low;
326 DBG_GF_high = GF_high;
327 DBG_const_ppO2 = const_ppO2;
328 DBG_deco_N2_ratio = char_I_deco_N2_ratio[0];
329 DBG_deco_He_ratio = char_I_deco_He_ratio[0];
330 DBG_deco_gas_change = deco_gas_change[0];
331 DBG_float_saturation_multiplier = float_saturation_multiplier;
332 DBG_float_desaturation_multiplier = float_desaturation_multiplier;
333 DBG_float_deco_distance = float_deco_distance;
334
335 //---- Setup some error (?) conditions -----------------------------------
336 if(char_I_deco_model)
337 int_O_DBS_bitfield |= DBS_mode;
338 if(const_ppO2)
339 int_O_DBS_bitfield |= DBS_ppO2;
340 for(i = 0; i < NUM_COMP; i++)
341 if(pres_tissue_He[i])
342 int_O_DBS_bitfield |= DBS_HE_sat;
343 if(float_saturation_multiplier < 0.99)
344 int_O_DBS_bitfield |= DBS_SAT2l;
345 if(float_saturation_multiplier > 1.3)
346 int_O_DBS_bitfield |= DBS_SAT2h;
347 if(GF_low < 0.19)
348 int_O_DBS_bitfield |= DBS_GFLOW2l;
349 if(GF_low > 1.01)
350 int_O_DBS_bitfield |= DBS_GFLOW2h;
351 if(GF_high < 0.6)
352 int_O_DBS_bitfield |= DBS_GFHGH2l;
353 if(GF_high > 1.01)
354 int_O_DBS_bitfield |= DBS_GFHGH2h;
355 if((N2_ratio + He_ratio) > 0.95)
356 int_O_DBS_bitfield |= DBS_GASO22l;
357 if((N2_ratio + He_ratio) < 0.05)
358 int_O_DBS_bitfield |= DBS_GASO22h;
359 if(float_deco_distance > 0.25)
360 int_O_DBS_bitfield |= DBS_DIST2h;
361 if(char_I_depth_last_deco > 8)
362 int_O_DBS_bitfield |= DBS_LAST2h;
363 if(DBG_deco_gas_change && ((char_I_deco_N2_ratio[0] + char_I_deco_He_ratio[0]) > 95))
364 int_O_DBS_bitfield |= DBS_DECOO2l;
365 if(DBG_deco_gas_change && ((char_I_deco_N2_ratio[0] + char_I_deco_He_ratio[0]) < 5))
366 int_O_DBS_bitfield |= DBS_DECOO2h;
367 if(pres_respiration > 3.0)
368 int_O_DBS2_bitfield |= DBS2_PRES2h;
369 if(pres_surface - pres_respiration > 0.2)
370 int_O_DBS2_bitfield |= DBS2_PRES2l;
371 if(pres_surface < 0.75)
372 int_O_DBS2_bitfield |= DBS2_SURF2l;
373 if(pres_surface > 1.11)
374 int_O_DBS2_bitfield |= DBS2_SURF2h;
375 if(float_desaturation_multiplier < 0.70)
376 int_O_DBS2_bitfield |= DBS2_DESAT2l;
377 if(float_desaturation_multiplier > 1.01)
378 int_O_DBS2_bitfield |= DBS2_DESAT2h;
379 if(GF_low > GF_high)
380 int_O_DBS2_bitfield |= DBS2_GFDneg;
381 }
382
383 //////////////////////////////////////////////////////////////////////////////
384 // DBG - set DBG to end_of_dive
385 //
386 static void set_dbg_end_of_dive(void)
387 {
388 int_O_DBG_pre_bitfield &= (~DBG_RUN);
389 int_O_DBG_post_bitfield &= (~DBG_RUN);
390 }
391
392 //////////////////////////////////////////////////////////////////////////////
393 // DBG - NDL at first 20 m. hit
394 //
395 static void check_ndl(void)
396 {
397 if( char_O_NDL_at_20mtr == 255 // Still in NDL mode ?
398 && int_I_pres_respiration > 3000 // And we hit the 20m limit ?
399 )
400 {
401 char_O_NDL_at_20mtr = char_O_nullzeit; // change to max bottom time.
402 if( char_O_NDL_at_20mtr == 255) // and avoid confusion.
403 char_O_NDL_at_20mtr = 254;
404 }
405 }
406
407 //////////////////////////////////////////////////////////////////////////////
408 // DBG - multi main during dive
409 //
410 static void check_dbg(PARAMETER char is_post_check)
411 {
412 overlay unsigned short temp_DBS = 0;
413 overlay unsigned char i; // Local loop index.
414
415 if( (DBG_N2_ratio != N2_ratio) || (DBG_He_ratio != He_ratio) )
416 temp_DBS |= DBG_c_gas;
417 if(DBG_const_ppO2 != const_ppO2)
418 temp_DBS |= DBG_c_ppO2;
419 if( DBG_float_saturation_multiplier != float_saturation_multiplier
420 || DBG_float_desaturation_multiplier != float_desaturation_multiplier
421 )
422 temp_DBS |= DBG_CdeSAT;
423 if(DBG_char_I_deco_model != char_I_deco_model)
424 temp_DBS |= DBG_C_MODE;
425 if(DBG_pres_surface != pres_surface)
426 temp_DBS |= DBG_C_SURF;
427
428 if( !DBS_HE_sat && !He_ratio)
429 for(i = 0; i < NUM_COMP; i++)
430 if(pres_tissue_He[i])
431 temp_DBS |= DBG_HEwoHE;
432
433 if( DBG_deco_gas_change != deco_gas_change[0]
434 || DBG_deco_N2_ratio != char_I_deco_N2_ratio[0]
435 || DBG_deco_He_ratio != char_I_deco_He_ratio[0] )
436 temp_DBS |= DBG_C_DGAS;
437
438 if(DBG_float_deco_distance != float_deco_distance)
439 temp_DBS |= DBG_C_DIST;
440 if(DBG_char_I_depth_last_deco != char_I_depth_last_deco)
441 temp_DBS |= DBG_C_LAST;
442 if( DBG_GF_low != GF_low
443 || DBG_GF_high != GF_high )
444 temp_DBS |= DBG_C_GF;
445 if(pres_respiration > 13.0)
446 temp_DBS |= DBG_PHIGH;
447 if(pres_surface - pres_respiration > 0.2)
448 temp_DBS |= DBG_PLOW;
449 if(is_post_check)
450 int_O_DBG_post_bitfield |= temp_DBS;
451 else
452 int_O_DBG_pre_bitfield |= temp_DBS;
453 }
454
455 //////////////////////////////////////////////////////////////////////////////
456 // DBG - prior to calc. of dive
457 //
458 static void check_pre_dbg(void)
459 {
460 check_dbg(0);
461 }
462
463 //////////////////////////////////////////////////////////////////////////////
464 // DBG - after decocalc of dive
465 //
466 static void check_post_dbg(void)
467 {
468 check_dbg(1);
469 }
470
471 //////////////////////////////////////////////////////////////////////////////
472 ////////////////////////////////////////////////////////////////////////////// 286 //////////////////////////////////////////////////////////////////////////////
473 /////////////////////// U T I L I T I E S ///////////////////////////////// 287 /////////////////////// U T I L I T I E S /////////////////////////////////
474 ////////////////////////////////////////////////////////////////////////////// 288 //////////////////////////////////////////////////////////////////////////////
475 ////////////////////////////////////////////////////////////////////////////// 289 //////////////////////////////////////////////////////////////////////////////
476 290
583 var_N2_a = *ptr++; 397 var_N2_a = *ptr++;
584 var_N2_b = *ptr++; 398 var_N2_b = *ptr++;
585 var_He_a = *ptr++; 399 var_He_a = *ptr++;
586 var_He_b = *ptr++; 400 var_He_b = *ptr++;
587 } 401 }
588
589 // Check reading consistency:
590 if( (var_N2_a < 0.231)
591 || (var_N2_a > 1.27)
592 || (var_N2_b < 0.504)
593 || (var_N2_b > 0.966)
594 || (var_He_a < 0.510)
595 || (var_He_a > 1.75)
596 || (var_He_b < 0.423)
597 || (var_He_b > 0.927)
598 )
599 int_O_DBG_pre_bitfield |= DBG_ZH16ERR;
600 } 402 }
601 403
602 ////////////////////////////////////////////////////////////////////////////// 404 //////////////////////////////////////////////////////////////////////////////
603 // read buhlmann tables for compatriment ci 405 // read buhlmann tables for compatriment ci
604 // If period == 0 : 2sec interval 406 // If period == 0 : 2sec interval
626 { 428 {
627 overlay rom const float* ptr = &e2secs[2*ci]; 429 overlay rom const float* ptr = &e2secs[2*ci];
628 var_N2_e = *ptr++; 430 var_N2_e = *ptr++;
629 var_He_e = *ptr++; 431 var_He_e = *ptr++;
630 } 432 }
631
632 // Check reading consistency:
633 if( (var_N2_e < 0.0000363)
634 || (var_N2_e > 0.00577)
635 || (var_He_e < 0.0000961)
636 || (var_He_e > 0.150)
637 )
638 int_O_DBG_pre_bitfield |= DBG_ZH16ERR;
639
640 break; 433 break;
641 434
642 case 1: //---- 1 min ----------------------------------------------------- 435 case 1: //---- 1 min -----------------------------------------------------
643 { 436 {
644 overlay rom const float* ptr = &e1min[2*ci]; 437 overlay rom const float* ptr = &e1min[2*ci];
645 var_N2_e = *ptr++; 438 var_N2_e = *ptr++;
646 var_He_e = *ptr++; 439 var_He_e = *ptr++;
647 } 440 }
648
649 // Check reading consistency:
650 if( (var_N2_e < 1.09E-3)
651 || (var_N2_e > 0.1592)
652 || (var_He_e < 0.00288)
653 || (var_He_e > 0.3682)
654 )
655 int_O_DBG_pre_bitfield |= DBG_ZH16ERR;
656
657 break; 441 break;
658 442
659 case 2: //---- 10 min ---------------------------------------------------- 443 case 2: //---- 10 min ----------------------------------------------------
660 { 444 {
661 overlay rom const float* ptr = &e10min[2*ci]; 445 overlay rom const float* ptr = &e10min[2*ci];
662 var_N2_e = *ptr++; 446 var_N2_e = *ptr++;
663 var_He_e = *ptr++; 447 var_He_e = *ptr++;
664 } 448 }
665
666 // Check reading consistency:
667 if( (var_N2_e < 0.01085)
668 || (var_N2_e > 0.82323)
669 || (var_He_e < 0.02846)
670 || (var_He_e > 0.98986)
671 )
672 int_O_DBG_pre_bitfield |= DBG_ZH16ERR;
673
674 break; 449 break;
675 450
676 default: 451 default:
677 assert(0); // Never go there... 452 assert(0); // Never go there...
678 } 453 }
1010 { 785 {
1011 RESET_C_STACK 786 RESET_C_STACK
1012 calc_dive_interval(); 787 calc_dive_interval();
1013 } 788 }
1014 789
1015 //////////////////////////////////////////////////////////////////////////////
1016
1017 void deco_debug(void)
1018 {
1019 RESET_C_STACK
1020 }
1021
1022 790
1023 ////////////////////////////////////////////////////////////////////////////// 791 //////////////////////////////////////////////////////////////////////////////
1024 // Find current gas in the list (if any). 792 // Find current gas in the list (if any).
1025 // 793 //
1026 // Input: char_I_current_gas = 1..6 794 // Input: char_I_current_gas = 1..6
1200 // 968 //
1201 static void clear_tissue(void) 969 static void clear_tissue(void)
1202 { 970 {
1203 overlay float p; 971 overlay float p;
1204 flag_in_divemode = 0; 972 flag_in_divemode = 0;
1205 int_O_DBS_bitfield = 0;
1206 int_O_DBS2_bitfield = 0;
1207 int_O_DBG_pre_bitfield = 0;
1208 int_O_DBG_post_bitfield = 0;
1209 char_O_NDL_at_20mtr = 255;
1210 973
1211 // Kludge: the 0.0002 of 0.7902 are missing with standard air. 974 // Kludge: the 0.0002 of 0.7902 are missing with standard air.
1212 N2_ratio = 0.7902; 975 N2_ratio = 0.7902;
1213 pres_respiration = int_I_pres_respiration * 0.001; 976 pres_respiration = int_I_pres_respiration * 0.001;
1214 977
1258 static unsigned char backup_gas_used = 0; 1021 static unsigned char backup_gas_used = 0;
1259 static unsigned char backup_gas_depth = 0; 1022 static unsigned char backup_gas_depth = 0;
1260 static unsigned char backup_gas_delay = 0; 1023 static unsigned char backup_gas_delay = 0;
1261 1024
1262 calc_hauptroutine_data_input(); 1025 calc_hauptroutine_data_input();
1263
1264 if(!flag_in_divemode)
1265 {
1266 flag_in_divemode = 1;
1267 create_dbs_set_dbg_and_ndl20mtr();
1268 }
1269 else
1270 check_pre_dbg();
1271 1026
1272 calc_hauptroutine_update_tissues(); 1027 calc_hauptroutine_update_tissues();
1273 calc_gradient_factor(); 1028 calc_gradient_factor();
1274 1029
1275 // toggle between calculation for nullzeit (bottom time), 1030 // toggle between calculation for nullzeit (bottom time),
1301 default: 1056 default:
1302 gas_switch_find_current(); // Lookup for current gas & time. 1057 gas_switch_find_current(); // Lookup for current gas & time.
1303 gas_switch_set(); // setup calc_ratio's 1058 gas_switch_set(); // setup calc_ratio's
1304 1059
1305 calc_nullzeit(); 1060 calc_nullzeit();
1306 check_ndl(); 1061 /* if( char_O_nullzeit > 0 ) // Some NDL time left ?
1307 if( char_O_nullzeit > 0 ) // Some NDL time left ?
1308 char_O_deco_status = 0; // YES: recalc ndl next time. 1062 char_O_deco_status = 0; // YES: recalc ndl next time.
1309 else 1063 else
1310 char_O_deco_status = 2; // NO: calc ascent next time. 1064 char_O_deco_status = 2; // NO: calc ascent next time.
1065 */
1066 char_O_deco_status = 2; // calc ascent next time.
1311 break; 1067 break;
1312 1068
1313 case 2: //---- Simulate ascent to first stop ----------------------------- 1069 case 2: //---- Simulate ascent to first stop -----------------------------
1314 case 6: // @+5min variation 1070 case 6: // @+5min variation
1315 // Check proposed gas at begin of ascent simulation 1071 // Check proposed gas at begin of ascent simulation
1316 sim_dive_mins = int_I_divemins; // Init current time. 1072 sim_dive_mins = int_I_divemins; // Init current time.
1073
1074 gas_switch_find_current(); // Lookup for current gas & time.
1075 gas_switch_set(); // setup calc_ratio's
1317 1076
1318 backup_gas_used = sim_gas_last_used; // And save for later simu steps. 1077 backup_gas_used = sim_gas_last_used; // And save for later simu steps.
1319 backup_gas_depth = sim_gas_last_depth; // And save for later simu steps. 1078 backup_gas_depth = sim_gas_last_depth; // And save for later simu steps.
1320 backup_gas_delay = sim_gas_delay; 1079 backup_gas_delay = sim_gas_delay;
1321 1080
1338 sim_gas_delay = backup_gas_delay; 1097 sim_gas_delay = backup_gas_delay;
1339 } 1098 }
1340 break; 1099 break;
1341 } 1100 }
1342 1101
1343 check_post_dbg();
1344 } 1102 }
1345 1103
1346 ////////////////////////////////////////////////////////////////////////////// 1104 //////////////////////////////////////////////////////////////////////////////
1347 // calc_hauptroutine_data_input 1105 // calc_hauptroutine_data_input
1348 // 1106 //
2169 { 1927 {
2170 assert( 800 < int_I_pres_surface && int_I_pres_surface < 1100 ); 1928 assert( 800 < int_I_pres_surface && int_I_pres_surface < 1100 );
2171 assert( 800 < int_I_pres_respiration && int_I_pres_respiration < 1100 ); 1929 assert( 800 < int_I_pres_respiration && int_I_pres_respiration < 1100 );
2172 assert( 100 <= char_I_saturation_multiplier && char_I_saturation_multiplier < 200 ); 1930 assert( 100 <= char_I_saturation_multiplier && char_I_saturation_multiplier < 200 );
2173 assert( 0 < char_I_desaturation_multiplier && char_I_desaturation_multiplier <= 100 ); 1931 assert( 0 < char_I_desaturation_multiplier && char_I_desaturation_multiplier <= 100 );
2174
2175 if(flag_in_divemode)
2176 {
2177 flag_in_divemode = 0;
2178 set_dbg_end_of_dive();
2179 }
2180 1932
2181 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann 1933 N2_ratio = 0.7902; // FIXED, sum lt. buehlmann
2182 pres_respiration = pres_surface = int_I_pres_surface * 0.001; 1934 pres_respiration = pres_surface = int_I_pres_surface * 0.001;
2183 ppN2 = N2_ratio * (pres_respiration - ppWater); 1935 ppN2 = N2_ratio * (pres_respiration - ppWater);
2184 ppHe = 0.0; 1936 ppHe = 0.0;