comparison Discovery/Src/simulation.c @ 629:55a9aa740f13

Added functionality to add ppo2 mV offset: For test purpose (in case no HW simulator is available) modification using the simulator are useful for testing of ppo2 error handling => Interface added
author Ideenmodellierer
date Tue, 23 Feb 2021 21:53:24 +0100
parents e7e44986684a
children 05cdd367dbd0
comparison
equal deleted inserted replaced
628:db2bcd2f6778 629:55a9aa740f13
56 //Private functions 56 //Private functions
57 static float sim_get_ambient_pressure(SDiveState * pDiveState); 57 static float sim_get_ambient_pressure(SDiveState * pDiveState);
58 static void sim_reduce_deco_time_one_second(SDiveState* pDiveState); 58 static void sim_reduce_deco_time_one_second(SDiveState* pDiveState);
59 static void simulation_set_aim_depth(int depth_meter); 59 static void simulation_set_aim_depth(int depth_meter);
60 60
61 #define NUM_OF_SENSORS (3u)
62 #define SIM_PPO2_STEP (1.1f)
63 static float simSensmVOffset[NUM_OF_SENSORS];
64
61 /** 65 /**
62 ****************************************************************************** 66 ******************************************************************************
63 * @brief sets heed_decostops_while_ascending 67 * @brief sets heed_decostops_while_ascending
64 ****************************************************************************** 68 ******************************************************************************
65 * @param heed_decostops_while_ascending : true -> deco_stops are considered while ascending 69 * @param heed_decostops_while_ascending : true -> deco_stops are considered while ascending
66 * @return void 70 * @return void
67 */ 71 */
68 void simulation_set_heed_decostops(_Bool heed_decostops_while_ascending) 72 void simulation_set_heed_decostops(_Bool heed_decostops_while_ascending)
69 { 73 {
70 sim_heed_decostops = heed_decostops_while_ascending; 74 sim_heed_decostops = heed_decostops_while_ascending;
71 } 75 }
72 76
73 /** 77 /**
74 ****************************************************************************** 78 ******************************************************************************
75 * @brief start of simulation 79 * @brief start of simulation
76 ****************************************************************************** 80 ******************************************************************************
77 * @return void 81 * @return void
78 */ 82 */
79 void simulation_start(int aim_depth) 83 void simulation_start(int aim_depth)
80 { 84 {
81 copyDiveSettingsToSim(); 85 copyDiveSettingsToSim();
82 copyVpmRepetetiveDataToSim(); 86 copyVpmRepetetiveDataToSim();
83 //vpm_init(&stateSimGetPointerWrite()->vpm, stateSimGetPointerWrite()->diveSettings.vpm_conservatism, 0, 0); 87 //vpm_init(&stateSimGetPointerWrite()->vpm, stateSimGetPointerWrite()->diveSettings.vpm_conservatism, 0, 0);
84 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = 0; 88 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = 0;
85 stateSimGetPointerWrite()->mode = MODE_DIVE; 89 stateSimGetPointerWrite()->mode = MODE_DIVE;
86 if(aim_depth <= 0) 90 if(aim_depth <= 0)
87 aim_depth = 20; 91 aim_depth = 20;
88 simulation_set_aim_depth(aim_depth); 92 simulation_set_aim_depth(aim_depth);
89 timer_init(); 93 timer_init();
90 set_stateUsedToSim(); 94 set_stateUsedToSim();
91 stateSim.lifeData.boolResetAverageDepth = 1; 95 stateSim.lifeData.boolResetAverageDepth = 1;
92 decoLock = DECO_CALC_init_as_is_start_of_dive; 96 decoLock = DECO_CALC_init_as_is_start_of_dive;
93 97
94 stateSim.lifeData.apnea_total_max_depth_meter = 0; 98 stateSim.lifeData.apnea_total_max_depth_meter = 0;
99 memset(simSensmVOffset,0,sizeof(simSensmVOffset));
95 } 100 }
96 101
97 /** 102 /**
98 ****************************************************************************** 103 ******************************************************************************
99 * @brief end of simulation 104 * @brief end of simulation
118 * @return void 123 * @return void
119 */ 124 */
120 void simulation_UpdateLifeData( _Bool checkOncePerSecond) 125 void simulation_UpdateLifeData( _Bool checkOncePerSecond)
121 { 126 {
122 SDiveState * pDiveState = &stateSim; 127 SDiveState * pDiveState = &stateSim;
128 SSettings *pSettings;
123 129
124 static int last_second = -1; 130 static int last_second = -1;
125 static _Bool two_second = 0; 131 static _Bool two_second = 0;
126 static float lastPressure_bar = 0; 132 static float lastPressure_bar = 0;
127 133
134 float localCalibCoeff[3];
135 uint8_t index, index2;
136
128 if(checkOncePerSecond) 137 if(checkOncePerSecond)
129 { 138 {
139
140 pSettings = settingsGetPointer();
141 for(index = 0; index < 3; index++)
142 {
143 localCalibCoeff[index] = pSettings->ppo2sensors_calibCoeff[index];
144 if(localCalibCoeff[index] < 0.01)
145 {
146 for(index2 = 0; index2 < 3; index2++) /* no valid coeff => check other entries */
147 {
148 if(pSettings->ppo2sensors_calibCoeff[index2] > 0.01)
149 {
150 localCalibCoeff[index] = pSettings->ppo2sensors_calibCoeff[index2];
151 break;
152 }
153 if(index2 == 3) /* no coeff at all => use default */
154 {
155 localCalibCoeff[index] = 0.02;
156 }
157 }
158 }
159 }
160
130 pDiveState->lifeData.temperature_celsius = stateRealGetPointer()->lifeData.temperature_celsius; 161 pDiveState->lifeData.temperature_celsius = stateRealGetPointer()->lifeData.temperature_celsius;
131 pDiveState->lifeData.battery_charge = stateRealGetPointer()->lifeData.battery_charge; 162 pDiveState->lifeData.battery_charge = stateRealGetPointer()->lifeData.battery_charge;
132 pDiveState->lifeData.compass_heading = stateRealGetPointer()->lifeData.compass_heading; 163 pDiveState->lifeData.compass_heading = stateRealGetPointer()->lifeData.compass_heading;
133 pDiveState->lifeData.compass_roll = stateRealGetPointer()->lifeData.compass_roll; 164 pDiveState->lifeData.compass_roll = stateRealGetPointer()->lifeData.compass_roll;
134 pDiveState->lifeData.compass_pitch = stateRealGetPointer()->lifeData.compass_pitch; 165 pDiveState->lifeData.compass_pitch = stateRealGetPointer()->lifeData.compass_pitch;
156 } 187 }
157 } 188 }
158 else if(pDiveState->lifeData.depth_meter <= (float)(decom_get_actual_deco_stop(pDiveState) + 0.001)) 189 else if(pDiveState->lifeData.depth_meter <= (float)(decom_get_actual_deco_stop(pDiveState) + 0.001))
159 sim_reduce_deco_time_one_second(pDiveState); 190 sim_reduce_deco_time_one_second(pDiveState);
160 191
161 pDiveState->lifeData.ppO2Sensor_bar[0] = stateRealGetPointer()->lifeData.ppO2Sensor_bar[0];
162 pDiveState->lifeData.ppO2Sensor_bar[1] = stateRealGetPointer()->lifeData.ppO2Sensor_bar[1];
163 pDiveState->lifeData.ppO2Sensor_bar[2] = stateRealGetPointer()->lifeData.ppO2Sensor_bar[2];
164 pDiveState->lifeData.sensorVoltage_mV[0] = stateRealGetPointer()->lifeData.sensorVoltage_mV[0];
165 pDiveState->lifeData.sensorVoltage_mV[1] = stateRealGetPointer()->lifeData.sensorVoltage_mV[1];
166 pDiveState->lifeData.sensorVoltage_mV[2] = stateRealGetPointer()->lifeData.sensorVoltage_mV[2];
167
168 pDiveState->lifeData.dive_time_seconds += 1; 192 pDiveState->lifeData.dive_time_seconds += 1;
169 pDiveState->lifeData.pressure_ambient_bar = sim_get_ambient_pressure(pDiveState); 193 pDiveState->lifeData.pressure_ambient_bar = sim_get_ambient_pressure(pDiveState);
194
195 pDiveState->lifeData.sensorVoltage_mV[0] = stateRealGetPointer()->lifeData.sensorVoltage_mV[0] + simSensmVOffset[0];
196 if(pDiveState->lifeData.sensorVoltage_mV[0] < 0.0) { pDiveState->lifeData.sensorVoltage_mV[0] = 0.0; }
197 pDiveState->lifeData.sensorVoltage_mV[1] = stateRealGetPointer()->lifeData.sensorVoltage_mV[1] + simSensmVOffset[1];
198 if(pDiveState->lifeData.sensorVoltage_mV[1] < 0.0) { pDiveState->lifeData.sensorVoltage_mV[1] = 0.0; }
199 pDiveState->lifeData.sensorVoltage_mV[2] = stateRealGetPointer()->lifeData.sensorVoltage_mV[2] + simSensmVOffset[2];
200 if(pDiveState->lifeData.sensorVoltage_mV[2] < 0.0) { pDiveState->lifeData.sensorVoltage_mV[2] = 0.0; }
201
202 pDiveState->lifeData.ppO2Sensor_bar[0] = pDiveState->lifeData.sensorVoltage_mV[0] * localCalibCoeff[0] * pDiveState->lifeData.pressure_ambient_bar;
203 pDiveState->lifeData.ppO2Sensor_bar[1] = pDiveState->lifeData.sensorVoltage_mV[1] * localCalibCoeff[1] * pDiveState->lifeData.pressure_ambient_bar;
204 pDiveState->lifeData.ppO2Sensor_bar[2] = pDiveState->lifeData.sensorVoltage_mV[2] * localCalibCoeff[2] * pDiveState->lifeData.pressure_ambient_bar;
205
170 206
171 if(is_ambient_pressure_close_to_surface(&pDiveState->lifeData)) // new hw 170214 207 if(is_ambient_pressure_close_to_surface(&pDiveState->lifeData)) // new hw 170214
172 { 208 {
173 if(!(stateSimGetPointer()->lifeData.counterSecondsShallowDepth)) 209 if(!(stateSimGetPointer()->lifeData.counterSecondsShallowDepth))
174 { 210 {
870 { 906 {
871 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = settingsGetPointer()->timeoutDiveReachedZeroDepth - 15; 907 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = settingsGetPointer()->timeoutDiveReachedZeroDepth - 15;
872 } 908 }
873 } 909 }
874 } 910 }
911 void Sim_IncreasePPO(uint8_t sensorIdx)
912 {
913 if((sensorIdx < NUM_OF_SENSORS) && (simSensmVOffset[sensorIdx] + SIM_PPO2_STEP < 100.0) && ((stateUsed->diveSettings.ppo2sensors_deactivated & (1 << sensorIdx)) == 0))
914 {
915 simSensmVOffset[sensorIdx] += SIM_PPO2_STEP;
916 }
917 }
918 void Sim_DecreasePPO(uint8_t sensorIdx)
919 {
920 if((sensorIdx < NUM_OF_SENSORS) && (simSensmVOffset[sensorIdx] - SIM_PPO2_STEP >= -100.0))
921 {
922 simSensmVOffset[sensorIdx] -= SIM_PPO2_STEP;
923 }
924 }