Mercurial > public > ostc4
comparison Common/Src/decom.c @ 662:1b995079c045 Betatest
PSCR Mode
author | heinrichs weikamp |
---|---|
date | Tue, 14 Dec 2021 15:36:10 +0100 |
parents | 239aa58b533d |
children | 9bc817e9e221 |
comparison
equal
deleted
inserted
replaced
661:87bee7cc77b3 | 662:1b995079c045 |
---|---|
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 ) ) |
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 } | |
646 pInput->decogaslist[count].nitrogen_percentage -= pInput->gas[i].helium_percentage; | 665 pInput->decogaslist[count].nitrogen_percentage -= pInput->gas[i].helium_percentage; |
647 pInput->decogaslist[count].helium_percentage = pInput->gas[i].helium_percentage; | 666 pInput->decogaslist[count].helium_percentage = pInput->gas[i].helium_percentage; |
648 pInput->decogaslist[count].GasIdInSettings = i; | 667 pInput->decogaslist[count].GasIdInSettings = i; |
649 | 668 |
650 } | 669 } |
651 } | 670 } |
652 /* Include Setpoint Changes */ | 671 if(pInput->diveMode == DIVEMODE_CCR) |
653 for(j=0; j <= count; j++) | 672 { |
654 { | 673 /* Include Setpoint Changes */ |
655 uint8_t depth = 0; | 674 for(j=0; j <= count; j++) |
656 uint8_t changedepth = 0; | |
657 char newSetpoint; | |
658 if(j == 0) | |
659 { | 675 { |
660 depth = pLifeData->depth_meter; | 676 uint8_t depth = 0; |
677 uint8_t changedepth = 0; | |
678 char newSetpoint; | |
679 | |
680 pInput->decogaslist[j].AppliedDiveMode = DIVEMODE_CCR; | |
681 if(j == 0) | |
682 { | |
683 depth = pLifeData->depth_meter; | |
684 } | |
685 else | |
686 { | |
687 //no setpointchange ? | |
688 pInput->decogaslist[j].setPoint_cbar = pInput->decogaslist[j - 1].setPoint_cbar; | |
689 depth = pInput->decogaslist[j].change_during_ascent_depth_meter_otherwise_zero + 0.1f; | |
690 } | |
691 /* Setpoint change at the same depth as gas changes */ | |
692 if(nextSetpointChange(pInput,depth + 1, &changedepth,&newSetpoint) && changedepth == depth) | |
693 { | |
694 pInput->decogaslist[j].setPoint_cbar = newSetpoint; | |
695 } | |
696 /* Setpoint changes inbetween gas changes */ | |
697 while(nextSetpointChange(pInput, depth, &changedepth,&newSetpoint) | |
698 && ( | |
699 ( (j < count) && (changedepth > pInput->decogaslist[j + 1].change_during_ascent_depth_meter_otherwise_zero)) | |
700 || ((j == count) && (changedepth > 0)) | |
701 )) | |
702 { | |
703 //Include new entry with setpoint change in decogaslist | |
704 for(int k = count; k > j; k--) | |
705 { | |
706 pInput->decogaslist[k+1] = pInput->decogaslist[k]; | |
707 } | |
708 pInput->decogaslist[j + 1] = pInput->decogaslist[j]; | |
709 pInput->decogaslist[j + 1].setPoint_cbar = newSetpoint; | |
710 j++; | |
711 count++; | |
712 depth = changedepth; | |
713 } | |
714 | |
661 } | 715 } |
662 else | 716 |
663 { | 717 } |
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 } | 718 } |
695 } | 719 } |
696 void test_decom_CreateGasChangeList(void) | 720 void test_decom_CreateGasChangeList(void) |
697 { | 721 { |
698 SDiveSettings diveSetting; | 722 SDiveSettings diveSetting; |
1020 } | 1044 } |
1021 | 1045 |
1022 | 1046 |
1023 float decom_calc_ppO2(const float ambiant_pressure_bar, const SGas* pGas) | 1047 float decom_calc_ppO2(const float ambiant_pressure_bar, const SGas* pGas) |
1024 { | 1048 { |
1025 float percent_N2 = 0; | 1049 float percent_N2 = 0; |
1026 float percent_He = 0; | 1050 float percent_He = 0; |
1027 float percent_O2 = 0; | 1051 float percent_O2 = 0; |
1028 decom_get_inert_gases(ambiant_pressure_bar, pGas, &percent_N2, &percent_He); | 1052 |
1029 percent_O2 = 1 - percent_N2 - percent_He; | 1053 decom_get_inert_gases(ambiant_pressure_bar, pGas, &percent_N2, &percent_He); |
1030 | 1054 percent_O2 = 1 - percent_N2 - percent_He; |
1031 return (ambiant_pressure_bar - WATER_VAPOUR_PRESSURE) * percent_O2; | 1055 |
1032 } | 1056 return (ambiant_pressure_bar - WATER_VAPOUR_PRESSURE) * percent_O2; |
1033 | 1057 } |
1058 | |
1059 | |
1060 float decom_calc_SimppO2(float ambiant_pressure_bar, const SGas* pGas) | |
1061 { | |
1062 float o2Ratio = 0.0; | |
1063 float inertGasRatio = 0.0; | |
1064 float simulatedPSCRppo2 = 0.0; | |
1065 | |
1066 o2Ratio = (100.0 - pGas->nitrogen_percentage - pGas->helium_percentage) / 100.0; | |
1067 inertGasRatio = 1.0 - o2Ratio; | |
1068 simulatedPSCRppo2 = (ambiant_pressure_bar - WATER_VAPOUR_PRESSURE) * o2Ratio; | |
1069 simulatedPSCRppo2 -= (inertGasRatio * pGas->pscr_factor); | |
1070 if(simulatedPSCRppo2 < 0.0) | |
1071 { | |
1072 simulatedPSCRppo2 = 0.0; | |
1073 } | |
1074 return simulatedPSCRppo2; | |
1075 } | |
1076 | |
1077 float decom_calc_SimppO2_O2based(float ambiant_pressure_bar, uint8_t O2PerCent, float factor) | |
1078 { | |
1079 float o2Ratio = 0.0; | |
1080 float inertGasRatio = 0.0; | |
1081 float simulatedPSCRppo2 = 0.0; | |
1082 | |
1083 o2Ratio = O2PerCent / 100.0; | |
1084 inertGasRatio = 1.0 - o2Ratio; | |
1085 simulatedPSCRppo2 = (ambiant_pressure_bar - WATER_VAPOUR_PRESSURE) * o2Ratio; | |
1086 simulatedPSCRppo2 -= (inertGasRatio * factor); | |
1087 if(simulatedPSCRppo2 < 0.0) | |
1088 { | |
1089 simulatedPSCRppo2 = 0.0; | |
1090 } | |
1091 return simulatedPSCRppo2; | |
1092 } | |
1034 | 1093 |
1035 uint8_t decom_get_actual_deco_stop(SDiveState* pDiveState) | 1094 uint8_t decom_get_actual_deco_stop(SDiveState* pDiveState) |
1036 { | 1095 { |
1037 SDecoinfo* pDecoinfo; | 1096 SDecoinfo* pDecoinfo; |
1038 uint8_t depthNext, depthLast, depthSecond, depthInc; | 1097 uint8_t depthNext, depthLast, depthSecond, depthInc; |