Mercurial > public > ostc4
comparison Common/Src/decom.c @ 696:cc542448fb28
Merge
author | heinrichsweikamp |
---|---|
date | Fri, 19 Aug 2022 11:30:24 +0200 |
parents | 9bc817e9e221 |
children | 012f94ec2fe0 |
comparison
equal
deleted
inserted
replaced
661:87bee7cc77b3 | 696:cc542448fb28 |
---|---|
215 { | 215 { |
216 float fraction_all_inertgases; | 216 float fraction_all_inertgases; |
217 float ppo2_fraction_setpoint; | 217 float ppo2_fraction_setpoint; |
218 float diluent_divisor; | 218 float diluent_divisor; |
219 | 219 |
220 | |
221 *fraction_nitrogen = ((float)pGas->nitrogen_percentage) / 100.0f; | 220 *fraction_nitrogen = ((float)pGas->nitrogen_percentage) / 100.0f; |
222 *fraction_helium = ((float)pGas->helium_percentage) / 100.0f; | 221 *fraction_helium = ((float)pGas->helium_percentage) / 100.0f; |
223 | 222 |
224 if(!pGas->setPoint_cbar) | 223 if(pGas->AppliedDiveMode == DIVEMODE_CCR) |
225 return; | 224 { |
226 | 225 // continue with CCR |
227 // continue with CCR | 226 fraction_all_inertgases = *fraction_nitrogen + *fraction_helium; |
228 fraction_all_inertgases = *fraction_nitrogen + *fraction_helium; | 227 |
229 | 228 ppo2_fraction_setpoint = (float)pGas->setPoint_cbar/ (100 * ambient_pressure_bar); |
230 ppo2_fraction_setpoint = (float)pGas->setPoint_cbar/ (100 * ambient_pressure_bar); | 229 |
231 | 230 diluent_divisor = (1.0f - ppo2_fraction_setpoint) / fraction_all_inertgases; |
232 diluent_divisor = (1.0f - ppo2_fraction_setpoint) / fraction_all_inertgases; | 231 if(diluent_divisor < 0) |
233 if(diluent_divisor < 0) | 232 diluent_divisor = 0; |
234 diluent_divisor = 0; | 233 |
235 | 234 *fraction_nitrogen *= diluent_divisor; |
236 *fraction_nitrogen *= diluent_divisor; | 235 *fraction_helium *= diluent_divisor; |
237 *fraction_helium *= diluent_divisor; | 236 } |
237 if(pGas->AppliedDiveMode == DIVEMODE_PSCR) | |
238 { | |
239 fraction_all_inertgases = *fraction_nitrogen + *fraction_helium; | |
240 ppo2_fraction_setpoint = decom_calc_SimppO2(ambient_pressure_bar, pGas) / ambient_pressure_bar; | |
241 diluent_divisor = (1.0f - ppo2_fraction_setpoint) / fraction_all_inertgases; | |
242 if(diluent_divisor < 0) | |
243 diluent_divisor = 0; | |
244 | |
245 *fraction_nitrogen *= diluent_divisor; | |
246 *fraction_helium *= diluent_divisor; | |
247 } | |
238 } | 248 } |
239 | 249 |
240 | 250 |
241 void decom_tissues_exposure(int period_in_seconds, SLifeData * pLifeData) | 251 void decom_tissues_exposure(int period_in_seconds, SLifeData * pLifeData) |
242 { | 252 { |
616 pInput->decogaslist[count].nitrogen_percentage = 100; | 626 pInput->decogaslist[count].nitrogen_percentage = 100; |
617 pInput->decogaslist[count].nitrogen_percentage -= pInput->gas[i].oxygen_percentage; | 627 pInput->decogaslist[count].nitrogen_percentage -= pInput->gas[i].oxygen_percentage; |
618 pInput->decogaslist[count].nitrogen_percentage -= pInput->gas[i].helium_percentage; | 628 pInput->decogaslist[count].nitrogen_percentage -= pInput->gas[i].helium_percentage; |
619 pInput->decogaslist[count].helium_percentage = pInput->gas[i].helium_percentage; | 629 pInput->decogaslist[count].helium_percentage = pInput->gas[i].helium_percentage; |
620 pInput->decogaslist[count].GasIdInSettings = i; | 630 pInput->decogaslist[count].GasIdInSettings = i; |
621 | 631 pInput->decogaslist[count].AppliedDiveMode = DIVEMODE_OC; |
622 } | 632 } |
623 } | 633 } |
624 } | 634 } |
625 else | 635 else |
626 { | 636 { |
627 //divmode CCR | 637 //divmode CCR or PSCR |
628 for(i=6; i <= 10; i++) | 638 for(i=6; i <= 10; i++) |
629 { | 639 { |
630 if(pInput->gas[i].note.ub.active && pInput->gas[i].depth_meter | 640 if((pInput->gas[i].note.ub.active) && (pInput->gas[i].depth_meter) |
631 && (pLifeData->actualGas.GasIdInSettings != i) | 641 && (pLifeData->actualGas.GasIdInSettings != i) |
632 &&(pInput->gas[i].depth_meter < pLifeData->depth_meter ) ) | 642 && (pInput->gas[i].depth_meter < pLifeData->depth_meter )) |
633 { | 643 { |
634 count = 1; | 644 count = 1; |
635 for(j=6;j<= 10;j++) | 645 for(j=6;j<= 10;j++) |
636 { | 646 { |
637 // if(pInput->gas[j].note.ub.active && pInput->gas[j].depth_meter > 0 &&pInput->gas[j].depth_meter > pInput->gas[i].depth_meter) | 647 // if(pInput->gas[j].note.ub.active && pInput->gas[j].depth_meter > 0 &&pInput->gas[j].depth_meter > pInput->gas[i].depth_meter) |
638 if( (pInput->gas[j].note.ub.active && pInput->gas[j].depth_meter > 0) | 648 if(((pInput->gas[j].note.ub.active) && (pInput->gas[j].depth_meter > 0)) |
639 && (pLifeData->actualGas.GasIdInSettings != j) // new hw 160905 | 649 && (pLifeData->actualGas.GasIdInSettings != j) // new hw 160905 |
640 && (pInput->gas[j].depth_meter > pInput->gas[i].depth_meter)) | 650 && (pInput->gas[j].depth_meter > pInput->gas[i].depth_meter)) |
641 count++; | 651 count++; |
642 } | 652 } |
643 pInput->decogaslist[count].change_during_ascent_depth_meter_otherwise_zero = pInput->gas[i].depth_meter; | 653 pInput->decogaslist[count].change_during_ascent_depth_meter_otherwise_zero = pInput->gas[i].depth_meter; |
644 pInput->decogaslist[count].nitrogen_percentage = 100; | 654 pInput->decogaslist[count].nitrogen_percentage = 100; |
645 pInput->decogaslist[count].nitrogen_percentage -= pInput->gas[i].oxygen_percentage; | 655 if(pInput->diveMode == DIVEMODE_PSCR) |
656 { | |
657 pInput->decogaslist[count].AppliedDiveMode = DIVEMODE_PSCR; | |
658 pInput->decogaslist[count].setPoint_cbar = decom_calc_SimppO2_O2based((float)(pInput->gas[i].depth_meter / 10.0 + 1.0), pInput->gas[i].oxygen_percentage, pInput->decogaslist[count].pscr_factor ) * 100; | |
659 pInput->decogaslist[count].nitrogen_percentage -= pInput->gas[i].oxygen_percentage; | |
660 } | |
661 else | |
662 { | |
663 pInput->decogaslist[count].nitrogen_percentage -= pInput->gas[i].oxygen_percentage; | |
664 pInput->decogaslist[count].AppliedDiveMode = DIVEMODE_CCR; | |
665 pInput->decogaslist[count].setPoint_cbar = pInput->decogaslist[0].setPoint_cbar; /* assume that current setpoint is kept till end of the dive */ | |
666 } | |
646 pInput->decogaslist[count].nitrogen_percentage -= pInput->gas[i].helium_percentage; | 667 pInput->decogaslist[count].nitrogen_percentage -= pInput->gas[i].helium_percentage; |
647 pInput->decogaslist[count].helium_percentage = pInput->gas[i].helium_percentage; | 668 pInput->decogaslist[count].helium_percentage = pInput->gas[i].helium_percentage; |
648 pInput->decogaslist[count].GasIdInSettings = i; | 669 pInput->decogaslist[count].GasIdInSettings = i; |
649 | |
650 } | 670 } |
651 } | 671 } |
652 /* Include Setpoint Changes */ | |
653 for(j=0; j <= count; j++) | |
654 { | |
655 uint8_t depth = 0; | |
656 uint8_t changedepth = 0; | |
657 char newSetpoint; | |
658 if(j == 0) | |
659 { | |
660 depth = pLifeData->depth_meter; | |
661 } | |
662 else | |
663 { | |
664 //no setpointchange ? | |
665 pInput->decogaslist[j].setPoint_cbar = pInput->decogaslist[j - 1].setPoint_cbar; | |
666 depth = pInput->decogaslist[j].change_during_ascent_depth_meter_otherwise_zero + 0.1f; | |
667 } | |
668 /* Setpoint change at the same depth as gas changes */ | |
669 if(nextSetpointChange(pInput,depth + 1, &changedepth,&newSetpoint) && changedepth == depth) | |
670 { | |
671 pInput->decogaslist[j].setPoint_cbar = newSetpoint; | |
672 } | |
673 /* Setpoint changes inbetween gas changes */ | |
674 while(nextSetpointChange(pInput, depth, &changedepth,&newSetpoint) | |
675 && ( | |
676 ( (j < count) && (changedepth > pInput->decogaslist[j + 1].change_during_ascent_depth_meter_otherwise_zero)) | |
677 || ((j == count) && (changedepth > 0)) | |
678 )) | |
679 { | |
680 //Include new entry with setpoint change in decogaslist | |
681 for(int k = count; k > j; k--) | |
682 { | |
683 pInput->decogaslist[k+1] = pInput->decogaslist[k]; | |
684 } | |
685 pInput->decogaslist[j + 1] = pInput->decogaslist[j]; | |
686 pInput->decogaslist[j + 1].setPoint_cbar = newSetpoint; | |
687 j++; | |
688 count++; | |
689 depth = changedepth; | |
690 } | |
691 | |
692 } | |
693 | |
694 } | 672 } |
695 } | 673 } |
696 void test_decom_CreateGasChangeList(void) | 674 void test_decom_CreateGasChangeList(void) |
697 { | 675 { |
698 SDiveSettings diveSetting; | 676 SDiveSettings diveSetting; |
1020 } | 998 } |
1021 | 999 |
1022 | 1000 |
1023 float decom_calc_ppO2(const float ambiant_pressure_bar, const SGas* pGas) | 1001 float decom_calc_ppO2(const float ambiant_pressure_bar, const SGas* pGas) |
1024 { | 1002 { |
1025 float percent_N2 = 0; | 1003 float percent_N2 = 0; |
1026 float percent_He = 0; | 1004 float percent_He = 0; |
1027 float percent_O2 = 0; | 1005 float percent_O2 = 0; |
1028 decom_get_inert_gases(ambiant_pressure_bar, pGas, &percent_N2, &percent_He); | 1006 |
1029 percent_O2 = 1 - percent_N2 - percent_He; | 1007 decom_get_inert_gases(ambiant_pressure_bar, pGas, &percent_N2, &percent_He); |
1030 | 1008 percent_O2 = 1 - percent_N2 - percent_He; |
1031 return (ambiant_pressure_bar - WATER_VAPOUR_PRESSURE) * percent_O2; | 1009 |
1032 } | 1010 return (ambiant_pressure_bar - WATER_VAPOUR_PRESSURE) * percent_O2; |
1033 | 1011 } |
1012 | |
1013 | |
1014 float decom_calc_SimppO2(float ambiant_pressure_bar, const SGas* pGas) | |
1015 { | |
1016 float o2Ratio = 0.0; | |
1017 float inertGasRatio = 0.0; | |
1018 float simulatedPSCRppo2 = 0.0; | |
1019 | |
1020 o2Ratio = (100.0 - pGas->nitrogen_percentage - pGas->helium_percentage) / 100.0; | |
1021 inertGasRatio = 1.0 - o2Ratio; | |
1022 simulatedPSCRppo2 = (ambiant_pressure_bar - WATER_VAPOUR_PRESSURE) * o2Ratio; | |
1023 simulatedPSCRppo2 -= (inertGasRatio * pGas->pscr_factor); | |
1024 if(simulatedPSCRppo2 < 0.0) | |
1025 { | |
1026 simulatedPSCRppo2 = 0.0; | |
1027 } | |
1028 return simulatedPSCRppo2; | |
1029 } | |
1030 | |
1031 float decom_calc_SimppO2_O2based(float ambiant_pressure_bar, uint8_t O2PerCent, float factor) | |
1032 { | |
1033 float o2Ratio = 0.0; | |
1034 float inertGasRatio = 0.0; | |
1035 float simulatedPSCRppo2 = 0.0; | |
1036 | |
1037 o2Ratio = O2PerCent / 100.0; | |
1038 inertGasRatio = 1.0 - o2Ratio; | |
1039 simulatedPSCRppo2 = (ambiant_pressure_bar - WATER_VAPOUR_PRESSURE) * o2Ratio; | |
1040 simulatedPSCRppo2 -= (inertGasRatio * factor); | |
1041 if(simulatedPSCRppo2 < 0.0) | |
1042 { | |
1043 simulatedPSCRppo2 = 0.0; | |
1044 } | |
1045 return simulatedPSCRppo2; | |
1046 } | |
1034 | 1047 |
1035 uint8_t decom_get_actual_deco_stop(SDiveState* pDiveState) | 1048 uint8_t decom_get_actual_deco_stop(SDiveState* pDiveState) |
1036 { | 1049 { |
1037 SDecoinfo* pDecoinfo; | 1050 SDecoinfo* pDecoinfo; |
1038 uint8_t depthNext, depthLast, depthSecond, depthInc; | 1051 uint8_t depthNext, depthLast, depthSecond, depthInc; |