Mercurial > public > ostc4
comparison Discovery/Src/simulation.c @ 367:e309f78f89a5 MotionDetection
Merge default
author | Ideenmodellierer |
---|---|
date | Sat, 20 Jul 2019 21:42:45 +0200 |
parents | 1203255481e4 |
children | f1257a32f2d4 |
comparison
equal
deleted
inserted
replaced
366:3c7030d6d67a | 367:e309f78f89a5 |
---|---|
35 #include "simulation.h" | 35 #include "simulation.h" |
36 | 36 |
37 #include "decom.h" | 37 #include "decom.h" |
38 #include "calc_crush.h" | 38 #include "calc_crush.h" |
39 #include "data_exchange.h" | 39 #include "data_exchange.h" |
40 #include "data_exchange_main.h" | |
40 #include "timer.h" | 41 #include "timer.h" |
41 #include "check_warning.h" | 42 #include "check_warning.h" |
42 #include "vpm.h" | 43 #include "vpm.h" |
43 #include "buehlmann.h" | 44 #include "buehlmann.h" |
44 #include "logbook_miniLive.h" | 45 #include "logbook_miniLive.h" |
49 | 50 |
50 static const float sim_descent_rate_meter_per_min = 20; | 51 static const float sim_descent_rate_meter_per_min = 20; |
51 | 52 |
52 | 53 |
53 //Private functions | 54 //Private functions |
54 static float sim_get_ambiant_pressure(SDiveState * pDiveState); | 55 static float sim_get_ambient_pressure(SDiveState * pDiveState); |
55 static void sim_reduce_deco_time_one_second(SDiveState* pDiveState); | 56 static void sim_reduce_deco_time_one_second(SDiveState* pDiveState); |
56 static void simulation_set_aim_depth(int depth_meter); | 57 static void simulation_set_aim_depth(int depth_meter); |
57 | 58 |
58 /** | 59 /** |
59 ****************************************************************************** | 60 ****************************************************************************** |
155 pDiveState->lifeData.sensorVoltage_mV[0] = stateRealGetPointer()->lifeData.sensorVoltage_mV[0]; | 156 pDiveState->lifeData.sensorVoltage_mV[0] = stateRealGetPointer()->lifeData.sensorVoltage_mV[0]; |
156 pDiveState->lifeData.sensorVoltage_mV[1] = stateRealGetPointer()->lifeData.sensorVoltage_mV[1]; | 157 pDiveState->lifeData.sensorVoltage_mV[1] = stateRealGetPointer()->lifeData.sensorVoltage_mV[1]; |
157 pDiveState->lifeData.sensorVoltage_mV[2] = stateRealGetPointer()->lifeData.sensorVoltage_mV[2]; | 158 pDiveState->lifeData.sensorVoltage_mV[2] = stateRealGetPointer()->lifeData.sensorVoltage_mV[2]; |
158 | 159 |
159 pDiveState->lifeData.dive_time_seconds += 1; | 160 pDiveState->lifeData.dive_time_seconds += 1; |
160 pDiveState->lifeData.pressure_ambient_bar = sim_get_ambiant_pressure(pDiveState); | 161 pDiveState->lifeData.pressure_ambient_bar = sim_get_ambient_pressure(pDiveState); |
161 | |
162 if(!is_ambient_pressure_close_to_surface(&pDiveState->lifeData) && !(stateSimGetPointer()->lifeData.counterSecondsShallowDepth) ) | |
163 { | |
164 pDiveState->lifeData.dive_time_seconds_without_surface_time += 1; | |
165 } | |
166 | 162 |
167 if(is_ambient_pressure_close_to_surface(&pDiveState->lifeData)) // new hw 170214 | 163 if(is_ambient_pressure_close_to_surface(&pDiveState->lifeData)) // new hw 170214 |
168 { | 164 { |
169 if(!(stateSimGetPointer()->lifeData.counterSecondsShallowDepth)) | 165 if(!(stateSimGetPointer()->lifeData.counterSecondsShallowDepth)) |
170 { | 166 { |
183 else | 179 else |
184 { | 180 { |
185 pDiveState->lifeData.counterSecondsShallowDepth = 0; | 181 pDiveState->lifeData.counterSecondsShallowDepth = 0; |
186 } | 182 } |
187 | 183 |
184 if(!is_ambient_pressure_close_to_surface(&pDiveState->lifeData) && !(stateSimGetPointer()->lifeData.counterSecondsShallowDepth) ) | |
185 { | |
186 pDiveState->lifeData.dive_time_seconds_without_surface_time += 1; | |
187 } | |
188 | |
188 pDiveState->lifeData.depth_meter = (pDiveState->lifeData.pressure_ambient_bar - pDiveState->lifeData.pressure_surface_bar) * 10.0f; | 189 pDiveState->lifeData.depth_meter = (pDiveState->lifeData.pressure_ambient_bar - pDiveState->lifeData.pressure_surface_bar) * 10.0f; |
189 if(pDiveState->lifeData.max_depth_meter < pDiveState->lifeData.depth_meter) | 190 if(pDiveState->lifeData.max_depth_meter < pDiveState->lifeData.depth_meter) |
190 pDiveState->lifeData.max_depth_meter = pDiveState->lifeData.depth_meter; | 191 pDiveState->lifeData.max_depth_meter = pDiveState->lifeData.depth_meter; |
191 | 192 |
192 /* apnoe specials | 193 /* apnoe specials |
199 if(pDiveState->lifeData.counterSecondsShallowDepth) | 200 if(pDiveState->lifeData.counterSecondsShallowDepth) |
200 { | 201 { |
201 pDiveState->lifeData.dive_time_seconds = 0; | 202 pDiveState->lifeData.dive_time_seconds = 0; |
202 pDiveState->lifeData.max_depth_meter = 0; | 203 pDiveState->lifeData.max_depth_meter = 0; |
203 pDiveState->lifeData.boolResetAverageDepth = 1; | 204 pDiveState->lifeData.boolResetAverageDepth = 1; |
204 pDiveState->lifeData.boolResetStopwatch = 1; | 205 } |
205 } | 206 } |
206 } | 207 |
207 | 208 setAvgDepth(pDiveState); |
208 /* average depth | |
209 */ | |
210 float *AvgDepthValue = &pDiveState->lifeData.average_depth_meter; | |
211 float DepthNow = pDiveState->lifeData.depth_meter; | |
212 uint32_t *AvgDepthCount = &pDiveState->lifeData.internal.average_depth_meter_Count; | |
213 uint32_t *AvgDepthTimer = &pDiveState->lifeData.internal.average_depth_last_update_dive_time_seconds_without_surface_time; | |
214 uint32_t AvgSecondsSinceLast; | |
215 uint32_t DiveTime = pDiveState->lifeData.dive_time_seconds_without_surface_time; | |
216 | |
217 if(pDiveState->lifeData.boolResetAverageDepth) | |
218 { | |
219 *AvgDepthValue = DepthNow; | |
220 *AvgDepthCount = 1; | |
221 *AvgDepthTimer = DiveTime; | |
222 pDiveState->lifeData.boolResetAverageDepth = 0; | |
223 } | |
224 else if (DiveTime > *AvgDepthTimer) | |
225 { | |
226 AvgSecondsSinceLast = DiveTime - *AvgDepthTimer; | |
227 for(int i=0;i<AvgSecondsSinceLast;i++) | |
228 { | |
229 *AvgDepthValue = (*AvgDepthValue * *AvgDepthCount + DepthNow) / (*AvgDepthCount + 1); | |
230 *AvgDepthCount += 1; | |
231 } | |
232 *AvgDepthTimer = DiveTime; | |
233 } | |
234 if(*AvgDepthCount == 0) | |
235 *AvgDepthValue = 0; | |
236 | 209 |
237 /* Exposure Tissues | 210 /* Exposure Tissues |
238 */ | 211 */ |
239 decom_tissues_exposure(1, &pDiveState->lifeData); | 212 decom_tissues_exposure(1, &pDiveState->lifeData); |
240 decom_oxygen_calculate_cns_exposure(1, &pDiveState->lifeData.actualGas, pDiveState->lifeData.pressure_ambient_bar, &pDiveState->lifeData.cns); | 213 decom_oxygen_calculate_cns_exposure(1, &pDiveState->lifeData.actualGas, pDiveState->lifeData.pressure_ambient_bar, &pDiveState->lifeData.cns); |
301 sim_aim_depth_meter = depth_meter; | 274 sim_aim_depth_meter = depth_meter; |
302 } | 275 } |
303 | 276 |
304 /** | 277 /** |
305 ****************************************************************************** | 278 ****************************************************************************** |
306 * @brief simulates ambiant pressure depending on aim depth | 279 * @brief simulates ambient pressure depending on aim depth |
307 ****************************************************************************** | 280 ****************************************************************************** |
308 * @note if aim_depth != actual depth, the depth change within one second | 281 * @note if aim_depth != actual depth, the depth change within one second |
309 * (depending on descent or ascent) rate is calculated | 282 * (depending on descent or ascent) rate is calculated |
310 * @param SDiveState* pDiveState: | 283 * @param SDiveState* pDiveState: |
311 * @return float : new ambiant pressure | 284 * @return float : new ambient pressure |
312 */ | 285 */ |
313 static float sim_get_ambiant_pressure(SDiveState * pDiveState) | 286 static float sim_get_ambient_pressure(SDiveState * pDiveState) |
314 { | 287 { |
315 //Calc next depth | 288 //Calc next depth |
316 uint8_t actual_deco_stop = decom_get_actual_deco_stop(pDiveState); | 289 uint8_t actual_deco_stop = decom_get_actual_deco_stop(pDiveState); |
317 float depth_meter = pDiveState->lifeData.depth_meter; | 290 float depth_meter = pDiveState->lifeData.depth_meter; |
318 float surface_pressure_bar = pDiveState->lifeData.pressure_surface_bar; | 291 float surface_pressure_bar = pDiveState->lifeData.pressure_surface_bar; |
349 ****************************************************************************** | 322 ****************************************************************************** |
350 * @note called during fast simulation | 323 * @note called during fast simulation |
351 * @param SDiveState* pDiveState: | 324 * @param SDiveState* pDiveState: |
352 * @return void | 325 * @return void |
353 */ | 326 */ |
354 void sim_reduce_deco_time_one_second(SDiveState* pDiveState) | 327 static void sim_reduce_deco_time_one_second(SDiveState* pDiveState) |
355 { | 328 { |
356 SDecoinfo* pDecoinfo; | 329 SDecoinfo* pDecoinfo; |
357 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE) | 330 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE) |
358 pDecoinfo = &pDiveState->decolistBuehlmann; | 331 pDecoinfo = &pDiveState->decolistBuehlmann; |
359 else | 332 else |