comparison Discovery/Src/simulation.c @ 813:1e688b630a6e

Used real sensor state in simulation: In previous version the status information of the digital O2 sensors were not forwarded to the simulator. As result the simulator did not show the failure reaction in case of error injection using the RTE. In the new version the status information provided by RTE is used within the simulator.
author Ideenmodellierer
date Sun, 03 Sep 2023 17:53:07 +0200
parents dd7ce655db26
children b7d93ff6b3b2
comparison
equal deleted inserted replaced
812:6670eb11a842 813:1e688b630a6e
128 * @return void 128 * @return void
129 */ 129 */
130 void simulation_UpdateLifeData( _Bool checkOncePerSecond) 130 void simulation_UpdateLifeData( _Bool checkOncePerSecond)
131 { 131 {
132 SDiveState * pDiveState = &stateSim; 132 SDiveState * pDiveState = &stateSim;
133 const SDiveState * pRealState = stateRealGetPointer();
133 SSettings *pSettings; 134 SSettings *pSettings;
134 135
135 static int last_second = -1; 136 static int last_second = -1;
136 static _Bool two_second = 0; 137 static _Bool two_second = 0;
137 static float lastPressure_bar = 0; 138 static float lastPressure_bar = 0;
165 } 166 }
166 } 167 }
167 } 168 }
168 } 169 }
169 170
170 pDiveState->lifeData.temperature_celsius = stateRealGetPointer()->lifeData.temperature_celsius; 171 pDiveState->lifeData.temperature_celsius = pRealState->lifeData.temperature_celsius;
171 pDiveState->lifeData.battery_charge = stateRealGetPointer()->lifeData.battery_charge; 172 pDiveState->lifeData.battery_charge = pRealState->lifeData.battery_charge;
172 pDiveState->lifeData.compass_heading = stateRealGetPointer()->lifeData.compass_heading; 173 pDiveState->lifeData.compass_heading = pRealState->lifeData.compass_heading;
173 pDiveState->lifeData.compass_roll = stateRealGetPointer()->lifeData.compass_roll; 174 pDiveState->lifeData.compass_roll = pRealState->lifeData.compass_roll;
174 pDiveState->lifeData.compass_pitch = stateRealGetPointer()->lifeData.compass_pitch; 175 pDiveState->lifeData.compass_pitch = pRealState->lifeData.compass_pitch;
176
177 for(index = 0; index < 3; index++)
178 {
179 memcpy(&pDiveState->lifeData.extIf_sensor_data[index], &pRealState->lifeData.extIf_sensor_data[index], 32);
180 }
175 181
176 #ifdef ENABLE_BOTTLE_SENSOR 182 #ifdef ENABLE_BOTTLE_SENSOR
177 pDiveState->lifeData.bottle_bar[pDiveState->lifeData.actualGas.GasIdInSettings] = stateRealGetPointer()->lifeData.bottle_bar[stateRealGetPointer()->lifeData.actualGas.GasIdInSettings]; 183 pDiveState->lifeData.bottle_bar[pDiveState->lifeData.actualGas.GasIdInSettings] = pRealState->lifeData.bottle_bar[pRealState->lifeData.actualGas.GasIdInSettings];
178 pDiveState->lifeData.bottle_bar_age_MilliSeconds[pDiveState->lifeData.actualGas.GasIdInSettings] = stateRealGetPointer()->lifeData.bottle_bar_age_MilliSeconds[stateRealGetPointer()->lifeData.actualGas.GasIdInSettings]; 184 pDiveState->lifeData.bottle_bar_age_MilliSeconds[pDiveState->lifeData.actualGas.GasIdInSettings] = pRealState->lifeData.bottle_bar_age_MilliSeconds[pRealState->lifeData.actualGas.GasIdInSettings];
179 #endif 185 #endif
180 int now = current_second(); 186 int now = current_second();
181 if( last_second == now) 187 if( last_second == now)
182 return; 188 return;
183 last_second = now; 189 last_second = now;
199 sim_reduce_deco_time_one_second(pDiveState); 205 sim_reduce_deco_time_one_second(pDiveState);
200 206
201 pDiveState->lifeData.dive_time_seconds += 1; 207 pDiveState->lifeData.dive_time_seconds += 1;
202 pDiveState->lifeData.pressure_ambient_bar = sim_get_ambient_pressure(pDiveState); 208 pDiveState->lifeData.pressure_ambient_bar = sim_get_ambient_pressure(pDiveState);
203 209
204 pDiveState->lifeData.sensorVoltage_mV[0] = stateRealGetPointer()->lifeData.sensorVoltage_mV[0] + simSensmVOffset[0]; 210 pDiveState->lifeData.sensorVoltage_mV[0] = pRealState->lifeData.sensorVoltage_mV[0] + simSensmVOffset[0];
205 if(pDiveState->lifeData.sensorVoltage_mV[0] < 0.0) { pDiveState->lifeData.sensorVoltage_mV[0] = 0.0; } 211 if(pDiveState->lifeData.sensorVoltage_mV[0] < 0.0) { pDiveState->lifeData.sensorVoltage_mV[0] = 0.0; }
206 pDiveState->lifeData.sensorVoltage_mV[1] = stateRealGetPointer()->lifeData.sensorVoltage_mV[1] + simSensmVOffset[1]; 212 pDiveState->lifeData.sensorVoltage_mV[1] = pRealState->lifeData.sensorVoltage_mV[1] + simSensmVOffset[1];
207 if(pDiveState->lifeData.sensorVoltage_mV[1] < 0.0) { pDiveState->lifeData.sensorVoltage_mV[1] = 0.0; } 213 if(pDiveState->lifeData.sensorVoltage_mV[1] < 0.0) { pDiveState->lifeData.sensorVoltage_mV[1] = 0.0; }
208 pDiveState->lifeData.sensorVoltage_mV[2] = stateRealGetPointer()->lifeData.sensorVoltage_mV[2] + simSensmVOffset[2]; 214 pDiveState->lifeData.sensorVoltage_mV[2] = pRealState->lifeData.sensorVoltage_mV[2] + simSensmVOffset[2];
209 if(pDiveState->lifeData.sensorVoltage_mV[2] < 0.0) { pDiveState->lifeData.sensorVoltage_mV[2] = 0.0; } 215 if(pDiveState->lifeData.sensorVoltage_mV[2] < 0.0) { pDiveState->lifeData.sensorVoltage_mV[2] = 0.0; }
210 216
211 pDiveState->lifeData.ppO2Sensor_bar[0] = pDiveState->lifeData.sensorVoltage_mV[0] * localCalibCoeff[0] * pDiveState->lifeData.pressure_ambient_bar; 217 pDiveState->lifeData.ppO2Sensor_bar[0] = pDiveState->lifeData.sensorVoltage_mV[0] * localCalibCoeff[0] * pDiveState->lifeData.pressure_ambient_bar;
212 pDiveState->lifeData.ppO2Sensor_bar[1] = pDiveState->lifeData.sensorVoltage_mV[1] * localCalibCoeff[1] * pDiveState->lifeData.pressure_ambient_bar; 218 pDiveState->lifeData.ppO2Sensor_bar[1] = pDiveState->lifeData.sensorVoltage_mV[1] * localCalibCoeff[1] * pDiveState->lifeData.pressure_ambient_bar;
213 pDiveState->lifeData.ppO2Sensor_bar[2] = pDiveState->lifeData.sensorVoltage_mV[2] * localCalibCoeff[2] * pDiveState->lifeData.pressure_ambient_bar; 219 pDiveState->lifeData.ppO2Sensor_bar[2] = pDiveState->lifeData.sensorVoltage_mV[2] * localCalibCoeff[2] * pDiveState->lifeData.pressure_ambient_bar;
214 220
215 pDiveState->lifeData.CO2_data.CO2_ppm = stateRealGetPointer()->lifeData.CO2_data.CO2_ppm; 221 pDiveState->lifeData.CO2_data.CO2_ppm = pRealState->lifeData.CO2_data.CO2_ppm;
216 222
217 if(is_ambient_pressure_close_to_surface(&pDiveState->lifeData)) // new hw 170214 223 if(is_ambient_pressure_close_to_surface(&pDiveState->lifeData)) // new hw 170214
218 { 224 {
219 if(!(stateSimGetPointer()->lifeData.counterSecondsShallowDepth)) 225 if(!(stateSimGetPointer()->lifeData.counterSecondsShallowDepth))
220 { 226 {