Mercurial > public > ostc4
annotate Discovery/Src/simulation.c @ 1006:75f958ca5d0e GasConsumption
Minor modification activ gas indicator:
On the main screen the active gas is visualized by a number and a box around it.The box as well as the number started at coordinate 0 resultiong of a very close drawing of box and number. To improve this a small gap is added between box and number and the box itself was enlarged. With the OSTC5 a problem with the pixel sync was solfed which caused the first column to not be drawn.
author | Ideenmodellierer |
---|---|
date | Sat, 03 May 2025 17:52:05 +0200 (4 months ago) |
parents | 5a690195b6b7 |
children | 8c0134a287da |
rev | line source |
---|---|
38 | 1 /////////////////////////////////////////////////////////////////////////////// |
2 /// -*- coding: UTF-8 -*- | |
3 /// | |
4 /// \file Discovery/Src/simulation.c | |
5 /// \brief Contains dive simulation functionality | |
6 /// \author Heinrichs Weikamp gmbh | |
7 /// \date 13-Oct-2014 | |
8 /// | |
9 /// \details | |
10 /// The simulation uses "extern SDiveState stateSim" defined in dataCentral.h" | |
11 /// | |
12 /// simulation_start(void) sets stateUsed to stateSim and initializes simulation | |
13 /// simulation_UpdateLifeData should be called at least once per second | |
14 /// simulation_end() sets stateUsed back to stateReal | |
15 /// | |
16 /// $Id$ | |
17 /////////////////////////////////////////////////////////////////////////////// | |
18 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh | |
19 /// | |
20 /// This program is free software: you can redistribute it and/or modify | |
21 /// it under the terms of the GNU General Public License as published by | |
22 /// the Free Software Foundation, either version 3 of the License, or | |
23 /// (at your option) any later version. | |
24 /// | |
25 /// This program is distributed in the hope that it will be useful, | |
26 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
27 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28 /// GNU General Public License for more details. | |
29 /// | |
30 /// You should have received a copy of the GNU General Public License | |
31 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
32 ////////////////////////////////////////////////////////////////////////////// | |
33 | |
34 #include <string.h> | |
35 #include "simulation.h" | |
36 | |
37 #include "decom.h" | |
38 #include "calc_crush.h" | |
39 #include "data_exchange.h" | |
308
1203255481e4
cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents:
307
diff
changeset
|
40 #include "data_exchange_main.h" |
38 | 41 #include "timer.h" |
42 #include "check_warning.h" | |
43 #include "vpm.h" | |
44 #include "buehlmann.h" | |
45 #include "logbook_miniLive.h" | |
46 | |
450 | 47 #include "configuration.h" |
48 | |
38 | 49 //Private state variables |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
176
diff
changeset
|
50 static float sim_aim_depth_meter; |
760
21949c88da90
Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents:
748
diff
changeset
|
51 static float sim_aim_time_minutes; |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
176
diff
changeset
|
52 static _Bool sim_heed_decostops = 1; |
38 | 53 |
897 | 54 static float sim_descent_rate_meter_per_min = 20; |
55 | |
56 static uint16_t* pReplayData; /* pointer to source dive data */ | |
57 static uint8_t simReplayActive = 0; | |
38 | 58 |
924
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
59 static uint16_t simScrubberTimeoutCount = 0; |
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
60 |
38 | 61 |
62 //Private functions | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
233
diff
changeset
|
63 static float sim_get_ambient_pressure(SDiveState * pDiveState); |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
176
diff
changeset
|
64 static void sim_reduce_deco_time_one_second(SDiveState* pDiveState); |
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
176
diff
changeset
|
65 static void simulation_set_aim_depth(int depth_meter); |
38 | 66 |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
67 #define NUM_OF_SENSORS (3u) |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
68 #define SIM_PPO2_STEP (1.1f) |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
69 static float simSensmVOffset[NUM_OF_SENSORS]; |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
70 |
38 | 71 /** |
72 ****************************************************************************** | |
73 * @brief sets heed_decostops_while_ascending | |
74 ****************************************************************************** | |
75 * @param heed_decostops_while_ascending : true -> deco_stops are considered while ascending | |
76 * @return void | |
77 */ | |
78 void simulation_set_heed_decostops(_Bool heed_decostops_while_ascending) | |
79 { | |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
80 sim_heed_decostops = heed_decostops_while_ascending; |
38 | 81 } |
82 | |
83 /** | |
84 ****************************************************************************** | |
85 * @brief start of simulation | |
86 ****************************************************************************** | |
87 * @return void | |
88 */ | |
760
21949c88da90
Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents:
748
diff
changeset
|
89 void simulation_start(int aim_depth, uint16_t aim_time_minutes) |
38 | 90 { |
897 | 91 uint16_t replayDataLength = 0; |
92 uint8_t* pReplayMarker; | |
93 uint16_t max_depth = 10; | |
94 uint16_t diveMinutes = 0; | |
95 | |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
96 copyDiveSettingsToSim(); |
38 | 97 copyVpmRepetetiveDataToSim(); |
901 | 98 |
38 | 99 //vpm_init(&stateSimGetPointerWrite()->vpm, stateSimGetPointerWrite()->diveSettings.vpm_conservatism, 0, 0); |
100 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = 0; | |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
101 stateSimGetPointerWrite()->mode = MODE_DIVE; |
38 | 102 if(aim_depth <= 0) |
103 aim_depth = 20; | |
897 | 104 sim_descent_rate_meter_per_min = 20; |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
105 simulation_set_aim_depth(aim_depth); |
760
21949c88da90
Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents:
748
diff
changeset
|
106 sim_aim_time_minutes = aim_time_minutes; |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
107 timer_init(); |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
108 set_stateUsedToSim(); |
38 | 109 stateSim.lifeData.boolResetAverageDepth = 1; |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
110 decoLock = DECO_CALC_init_as_is_start_of_dive; |
38 | 111 |
112 stateSim.lifeData.apnea_total_max_depth_meter = 0; | |
924
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
113 |
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
114 memcpy(stateSim.scrubberDataDive, settingsGetPointer()->scrubberData, sizeof(stateSim.scrubberDataDive)); |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
115 memset(simSensmVOffset,0,sizeof(simSensmVOffset)); |
897 | 116 if(getReplayOffset() != 0xFFFF) |
117 { | |
118 simReplayActive = 1; | |
119 getReplayInfo(&pReplayData, &pReplayMarker, &replayDataLength, &max_depth, &diveMinutes); | |
120 } | |
38 | 121 } |
122 | |
123 /** | |
124 ****************************************************************************** | |
125 * @brief end of simulation | |
126 ****************************************************************************** | |
127 * | |
128 * @return void | |
129 */ | |
130 void simulation_exit(void) | |
131 { | |
132 timer_Stopwatch_Stop(); | |
805
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
790
diff
changeset
|
133 |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
790
diff
changeset
|
134 disableTimer(); |
dd7ce655db26
Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents:
790
diff
changeset
|
135 |
38 | 136 set_stateUsedToReal(); |
137 } | |
138 | |
139 /** | |
140 ****************************************************************************** | |
141 * @brief simulates change of Lifedata (saturation, depth change, etc.) within one second | |
142 ****************************************************************************** | |
143 * | |
144 * @param checkOncePerSecond : true -> simulation in real time (function is evaluated only once per second) | |
145 * and copy of parts of LifeData from SmallCPU with each call from HAL_TIM_PeriodElapsedCallback() | |
146 * : false -> fast simulation (many simulation cycles per second are possible) | |
147 * @return void | |
148 */ | |
149 void simulation_UpdateLifeData( _Bool checkOncePerSecond) | |
150 { | |
151 SDiveState * pDiveState = &stateSim; | |
813 | 152 const SDiveState * pRealState = stateRealGetPointer(); |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
153 SSettings *pSettings; |
998 | 154 uint8_t timerId = 0; |
38 | 155 |
156 static int last_second = -1; | |
157 static _Bool two_second = 0; | |
158 static float lastPressure_bar = 0; | |
159 | |
924
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
160 pSettings = settingsGetPointer(); |
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
161 |
897 | 162 if ((sim_aim_time_minutes && sim_aim_time_minutes * 60 <= pDiveState->lifeData.dive_time_seconds) |
163 && (!simReplayActive)) | |
164 { | |
760
21949c88da90
Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents:
748
diff
changeset
|
165 simulation_set_aim_depth(0); |
21949c88da90
Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents:
748
diff
changeset
|
166 } |
21949c88da90
Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents:
748
diff
changeset
|
167 |
699 | 168 float localCalibCoeff[3] = { 0.0, 0.0, 0.0 }; |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
169 uint8_t index, index2; |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
170 |
38 | 171 if(checkOncePerSecond) |
172 { | |
901 | 173 int now = current_second(); |
174 if( last_second == now) | |
175 return; | |
176 last_second = now; | |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
177 |
901 | 178 if(!two_second) |
179 two_second = 1; | |
180 else | |
181 { | |
182 two_second = 0; | |
183 } | |
924
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
184 |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
185 for(index = 0; index < 3; index++) |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
186 { |
977 | 187 if(pDiveState->lifeData.extIf_sensor_map[index] == SENSOR_DIGO2M) |
188 { | |
189 localCalibCoeff[index] = 0.01; | |
190 } | |
191 else | |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
192 { |
977 | 193 localCalibCoeff[index] = pSettings->ppo2sensors_calibCoeff[index]; |
194 if(localCalibCoeff[index] < 0.01) | |
195 { | |
196 for(index2 = 0; index2 < 3; index2++) /* no valid coeff => check other entries */ | |
197 { | |
198 if(pSettings->ppo2sensors_calibCoeff[index2] > 0.01) | |
199 { | |
200 localCalibCoeff[index] = pSettings->ppo2sensors_calibCoeff[index2]; | |
201 break; | |
202 } | |
203 if(index2 == 3) /* no coeff at all => use default */ | |
204 { | |
205 localCalibCoeff[index] = 0.02; | |
206 } | |
207 } | |
208 } | |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
209 } |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
210 } |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
211 |
813 | 212 pDiveState->lifeData.temperature_celsius = pRealState->lifeData.temperature_celsius; |
213 pDiveState->lifeData.battery_charge = pRealState->lifeData.battery_charge; | |
214 pDiveState->lifeData.compass_heading = pRealState->lifeData.compass_heading; | |
215 pDiveState->lifeData.compass_roll = pRealState->lifeData.compass_roll; | |
216 pDiveState->lifeData.compass_pitch = pRealState->lifeData.compass_pitch; | |
217 | |
218 for(index = 0; index < 3; index++) | |
219 { | |
220 memcpy(&pDiveState->lifeData.extIf_sensor_data[index], &pRealState->lifeData.extIf_sensor_data[index], 32); | |
221 } | |
548
e7e44986684a
Update roll and pitch value in simulation mode:
Ideenmodellierer
parents:
450
diff
changeset
|
222 |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
308
diff
changeset
|
223 #ifdef ENABLE_BOTTLE_SENSOR |
813 | 224 pDiveState->lifeData.bottle_bar[pDiveState->lifeData.actualGas.GasIdInSettings] = pRealState->lifeData.bottle_bar[pRealState->lifeData.actualGas.GasIdInSettings]; |
225 pDiveState->lifeData.bottle_bar_age_MilliSeconds[pDiveState->lifeData.actualGas.GasIdInSettings] = pRealState->lifeData.bottle_bar_age_MilliSeconds[pRealState->lifeData.actualGas.GasIdInSettings]; | |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
308
diff
changeset
|
226 #endif |
38 | 227 } |
228 else if(pDiveState->lifeData.depth_meter <= (float)(decom_get_actual_deco_stop(pDiveState) + 0.001)) | |
901 | 229 { |
230 if(decoLock == DECO_CALC_FINSHED_vpm) | |
231 { | |
232 sim_reduce_deco_time_one_second(&stateDeco); | |
233 } | |
234 else | |
235 { | |
236 sim_reduce_deco_time_one_second(pDiveState); | |
237 } | |
238 } | |
897 | 239 |
38 | 240 pDiveState->lifeData.dive_time_seconds += 1; |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
233
diff
changeset
|
241 pDiveState->lifeData.pressure_ambient_bar = sim_get_ambient_pressure(pDiveState); |
953 | 242 if(pDiveState->lifeData.depth_meter < 1.5) |
897 | 243 { |
244 lastPressure_bar = 0; | |
245 pDiveState->lifeData.ascent_rate_meter_per_min = 0; | |
246 } | |
924
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
247 |
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
248 if((pSettings->scrubTimerMode != SCRUB_TIMER_OFF) && (isLoopMode(pSettings->dive_mode)) && (pDiveState->mode == MODE_DIVE) && isLoopMode(pDiveState->diveSettings.diveMode)) |
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
249 { |
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
250 simScrubberTimeoutCount++; |
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
251 if(simScrubberTimeoutCount >= 60) /* resolution is minutes */ |
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
252 { |
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
253 simScrubberTimeoutCount = 0; |
998 | 254 for(timerId = 0; timerId < 2; timerId++) |
924
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
255 { |
998 | 256 if(pSettings->scubberActiveId & (1 << timerId)) |
257 { | |
258 if(pDiveState->scrubberDataDive[timerId].TimerCur > MIN_SCRUBBER_TIME) | |
259 { | |
260 pDiveState->scrubberDataDive[timerId].TimerCur--; | |
261 } | |
262 translateDate(stateUsed->lifeData.dateBinaryFormat, &pDiveState->scrubberDataDive[timerId].lastDive); | |
263 } | |
924
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
264 } |
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
265 } |
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
266 } |
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
267 |
4d98fb2a178e
Bugfix real scrubber time decreased in sim mode:
Ideenmodellierer
parents:
910
diff
changeset
|
268 |
897 | 269 if(lastPressure_bar > 0) |
270 { | |
271 //1 second * 60 == 1 minute, bar * 10 = meter | |
272 pDiveState->lifeData.ascent_rate_meter_per_min = (lastPressure_bar - pDiveState->lifeData.pressure_ambient_bar) * 600.0; | |
273 } | |
274 lastPressure_bar = pDiveState->lifeData.pressure_ambient_bar; | |
38 | 275 |
813 | 276 pDiveState->lifeData.sensorVoltage_mV[0] = pRealState->lifeData.sensorVoltage_mV[0] + simSensmVOffset[0]; |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
277 if(pDiveState->lifeData.sensorVoltage_mV[0] < 0.0) { pDiveState->lifeData.sensorVoltage_mV[0] = 0.0; } |
813 | 278 pDiveState->lifeData.sensorVoltage_mV[1] = pRealState->lifeData.sensorVoltage_mV[1] + simSensmVOffset[1]; |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
279 if(pDiveState->lifeData.sensorVoltage_mV[1] < 0.0) { pDiveState->lifeData.sensorVoltage_mV[1] = 0.0; } |
813 | 280 pDiveState->lifeData.sensorVoltage_mV[2] = pRealState->lifeData.sensorVoltage_mV[2] + simSensmVOffset[2]; |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
281 if(pDiveState->lifeData.sensorVoltage_mV[2] < 0.0) { pDiveState->lifeData.sensorVoltage_mV[2] = 0.0; } |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
282 |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
283 pDiveState->lifeData.ppO2Sensor_bar[0] = pDiveState->lifeData.sensorVoltage_mV[0] * localCalibCoeff[0] * pDiveState->lifeData.pressure_ambient_bar; |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
284 pDiveState->lifeData.ppO2Sensor_bar[1] = pDiveState->lifeData.sensorVoltage_mV[1] * localCalibCoeff[1] * pDiveState->lifeData.pressure_ambient_bar; |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
285 pDiveState->lifeData.ppO2Sensor_bar[2] = pDiveState->lifeData.sensorVoltage_mV[2] * localCalibCoeff[2] * pDiveState->lifeData.pressure_ambient_bar; |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
286 |
813 | 287 pDiveState->lifeData.CO2_data.CO2_ppm = pRealState->lifeData.CO2_data.CO2_ppm; |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
288 |
38 | 289 if(is_ambient_pressure_close_to_surface(&pDiveState->lifeData)) // new hw 170214 |
290 { | |
291 if(!(stateSimGetPointer()->lifeData.counterSecondsShallowDepth)) | |
292 { | |
293 if(pDiveState->diveSettings.diveMode != DIVEMODE_Apnea) | |
294 pDiveState->lifeData.counterSecondsShallowDepth = settingsGetPointer()->timeoutDiveReachedZeroDepth - 15; | |
295 else | |
296 { | |
297 pDiveState->lifeData.apnea_last_dive_time_seconds = pDiveState->lifeData.dive_time_seconds; | |
298 if(pDiveState->lifeData.apnea_last_dive_time_seconds > pDiveState->lifeData.dive_time_seconds_without_surface_time) | |
299 pDiveState->lifeData.apnea_last_dive_time_seconds = pDiveState->lifeData.dive_time_seconds_without_surface_time; | |
300 pDiveState->lifeData.apnea_last_max_depth_meter = pDiveState->lifeData.max_depth_meter; | |
301 pDiveState->lifeData.counterSecondsShallowDepth = 1; | |
302 } | |
303 } | |
304 } | |
305 else | |
306 { | |
307 pDiveState->lifeData.counterSecondsShallowDepth = 0; | |
308 } | |
309 | |
304
43b44f8d4fb0
bugfix, simulator: fix the 1 sec difference between stopwatch and divetime
Jan Mulder <jlmulder@xs4all.nl>
parents:
300
diff
changeset
|
310 if(!is_ambient_pressure_close_to_surface(&pDiveState->lifeData) && !(stateSimGetPointer()->lifeData.counterSecondsShallowDepth) ) |
43b44f8d4fb0
bugfix, simulator: fix the 1 sec difference between stopwatch and divetime
Jan Mulder <jlmulder@xs4all.nl>
parents:
300
diff
changeset
|
311 { |
43b44f8d4fb0
bugfix, simulator: fix the 1 sec difference between stopwatch and divetime
Jan Mulder <jlmulder@xs4all.nl>
parents:
300
diff
changeset
|
312 pDiveState->lifeData.dive_time_seconds_without_surface_time += 1; |
43b44f8d4fb0
bugfix, simulator: fix the 1 sec difference between stopwatch and divetime
Jan Mulder <jlmulder@xs4all.nl>
parents:
300
diff
changeset
|
313 } |
43b44f8d4fb0
bugfix, simulator: fix the 1 sec difference between stopwatch and divetime
Jan Mulder <jlmulder@xs4all.nl>
parents:
300
diff
changeset
|
314 |
38 | 315 pDiveState->lifeData.depth_meter = (pDiveState->lifeData.pressure_ambient_bar - pDiveState->lifeData.pressure_surface_bar) * 10.0f; |
316 if(pDiveState->lifeData.max_depth_meter < pDiveState->lifeData.depth_meter) | |
317 pDiveState->lifeData.max_depth_meter = pDiveState->lifeData.depth_meter; | |
318 | |
319 /* apnoe specials | |
320 */ | |
321 if(pDiveState->diveSettings.diveMode == DIVEMODE_Apnea) | |
322 { | |
323 if(pDiveState->lifeData.max_depth_meter > pDiveState->lifeData.apnea_total_max_depth_meter) | |
324 pDiveState->lifeData.apnea_total_max_depth_meter = pDiveState->lifeData.max_depth_meter; | |
325 | |
326 if(pDiveState->lifeData.counterSecondsShallowDepth) | |
327 { | |
328 pDiveState->lifeData.dive_time_seconds = 0; | |
329 pDiveState->lifeData.max_depth_meter = 0; | |
330 pDiveState->lifeData.boolResetAverageDepth = 1; | |
331 } | |
332 } | |
333 | |
308
1203255481e4
cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents:
307
diff
changeset
|
334 setAvgDepth(pDiveState); |
38 | 335 |
336 /* Exposure Tissues | |
337 */ | |
338 decom_tissues_exposure(1, &pDiveState->lifeData); | |
339 decom_oxygen_calculate_cns_exposure(1, &pDiveState->lifeData.actualGas, pDiveState->lifeData.pressure_ambient_bar, &pDiveState->lifeData.cns); | |
233
9f0efc4df01e
cleanup, bugfix: do not exit simulator on 5h dive time
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
340 |
38 | 341 if(stateSimGetPointer()->lifeData.counterSecondsShallowDepth) |
342 { | |
343 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth += 1; | |
344 if(stateSimGetPointer()->lifeData.counterSecondsShallowDepth >= settingsGetPointer()->timeoutDiveReachedZeroDepth) | |
345 simulation_exit(); | |
346 } | |
347 vpm_crush(pDiveState); | |
348 } | |
349 | |
350 /** | |
351 ****************************************************************************** | |
352 * @brief adds extra time for fast simulation | |
353 ****************************************************************************** | |
354 *@param minutes | |
355 * @return float : new pressure | |
356 */ | |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
176
diff
changeset
|
357 static void simulation_add_time(int minutes) |
38 | 358 { |
359 for(int i = 0; i < 60 * minutes; i++) | |
360 { | |
361 simulation_UpdateLifeData(0); | |
362 updateMiniLiveLogbook(0); | |
363 timer_UpdateSecond(0); | |
364 } | |
365 } | |
366 | |
367 /** | |
368 ****************************************************************************** | |
369 * @brief get aim_depth | |
370 ****************************************************************************** | |
371 * @return sim_aim_depth_meter; | |
372 */ | |
373 | |
374 uint16_t simulation_get_aim_depth(void) | |
375 { | |
376 return (uint16_t)sim_aim_depth_meter; | |
377 } | |
378 | |
379 /** | |
380 ****************************************************************************** | |
381 * @brief get heed decostops | |
382 ****************************************************************************** | |
383 * @return true if ascend follows decostops; | |
384 */ | |
385 | |
386 _Bool simulation_get_heed_decostops(void) | |
387 { | |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
176
diff
changeset
|
388 return sim_heed_decostops; |
38 | 389 } |
390 | |
391 /** | |
392 ****************************************************************************** | |
393 * @brief sets aim_depth | |
394 ****************************************************************************** | |
395 *@param depth_meter | |
396 * @return float : new pressure | |
397 */ | |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
176
diff
changeset
|
398 static void simulation_set_aim_depth(int depth_meter) |
38 | 399 { |
400 sim_aim_depth_meter = depth_meter; | |
401 } | |
402 | |
403 /** | |
404 ****************************************************************************** | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
233
diff
changeset
|
405 * @brief simulates ambient pressure depending on aim depth |
38 | 406 ****************************************************************************** |
407 * @note if aim_depth != actual depth, the depth change within one second | |
408 * (depending on descent or ascent) rate is calculated | |
409 * @param SDiveState* pDiveState: | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
233
diff
changeset
|
410 * @return float : new ambient pressure |
38 | 411 */ |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
233
diff
changeset
|
412 static float sim_get_ambient_pressure(SDiveState * pDiveState) |
38 | 413 { |
414 //Calc next depth | |
415 uint8_t actual_deco_stop = decom_get_actual_deco_stop(pDiveState); | |
416 float depth_meter = pDiveState->lifeData.depth_meter; | |
417 float surface_pressure_bar = pDiveState->lifeData.pressure_surface_bar; | |
897 | 418 static uint8_t sampleToggle = 0; |
910
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
419 static float sim_ascent_rate_meter_per_min_local = 0; |
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
420 uint8_t sampleTime = getReplayDataResolution(); |
897 | 421 |
910
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
422 if(simReplayActive) /* precondition: function is called once per second, sample rate is a multiple of second */ |
897 | 423 { |
424 if(sampleToggle == 0) | |
425 { | |
910
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
426 sampleToggle = sampleTime - 1; |
897 | 427 sim_aim_depth_meter = (float)(*pReplayData++/100.0); |
910
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
428 if(sim_aim_depth_meter > depth_meter) |
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
429 { |
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
430 sim_descent_rate_meter_per_min = (sim_aim_depth_meter - depth_meter) * (60 / sampleTime); |
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
431 } |
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
432 else |
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
433 { |
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
434 sim_ascent_rate_meter_per_min_local = (depth_meter - sim_aim_depth_meter) * (60 / sampleTime); |
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
435 } |
897 | 436 } |
437 else | |
438 { | |
910
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
439 sampleToggle--; |
897 | 440 } |
441 } | |
910
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
442 else |
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
443 { |
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
444 sim_ascent_rate_meter_per_min_local = pDiveState->diveSettings.ascentRate_meterperminute; |
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
445 } |
897 | 446 |
38 | 447 if(depth_meter < sim_aim_depth_meter) |
448 { | |
449 depth_meter = depth_meter + sim_descent_rate_meter_per_min / 60; | |
450 if(depth_meter > sim_aim_depth_meter) | |
451 depth_meter = sim_aim_depth_meter; | |
452 } | |
453 else if(depth_meter > sim_aim_depth_meter) | |
454 { | |
455 | |
910
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
456 depth_meter -= sim_ascent_rate_meter_per_min_local / 60; |
38 | 457 if(depth_meter < sim_aim_depth_meter) |
458 depth_meter = sim_aim_depth_meter; | |
459 | |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
176
diff
changeset
|
460 if(sim_heed_decostops && depth_meter < actual_deco_stop) |
38 | 461 { |
910
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
462 if(actual_deco_stop < (depth_meter + sim_ascent_rate_meter_per_min_local / 60)) |
38 | 463 depth_meter = actual_deco_stop; |
464 else | |
910
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
465 depth_meter += sim_ascent_rate_meter_per_min_local / 60; |
38 | 466 } |
467 | |
468 } | |
469 | |
470 return surface_pressure_bar + depth_meter / 10; | |
471 } | |
472 | |
473 | |
474 /** | |
475 ****************************************************************************** | |
476 * @brief Reduces deco time of deepest stop by one second | |
477 ****************************************************************************** | |
478 * @note called during fast simulation | |
479 * @param SDiveState* pDiveState: | |
480 * @return void | |
481 */ | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
233
diff
changeset
|
482 static void sim_reduce_deco_time_one_second(SDiveState* pDiveState) |
38 | 483 { |
484 SDecoinfo* pDecoinfo; | |
901 | 485 int8_t index = 0; |
486 | |
487 | |
38 | 488 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE) |
489 pDecoinfo = &pDiveState->decolistBuehlmann; | |
490 else | |
491 pDecoinfo = &pDiveState->decolistVPM; | |
492 | |
493 //Reduce deco time of deepest stop by one second | |
901 | 494 for(index = DECOINFO_STRUCT_MAX_STOPS -1 ;index >= 0; index--) |
38 | 495 { |
901 | 496 if(pDecoinfo->output_stop_length_seconds[index] > 0) |
38 | 497 { |
901 | 498 pDecoinfo->output_stop_length_seconds[index]--; |
38 | 499 break; |
500 } | |
501 } | |
901 | 502 /* update TTS */ |
503 if(pDecoinfo->output_time_to_surface_seconds) | |
504 { | |
505 pDecoinfo->output_time_to_surface_seconds--; | |
506 } | |
38 | 507 } |
508 | |
983 | 509 SDecoinfo* simulation_decoplaner(uint16_t depth_meter, uint16_t intervall_time_minutes, uint16_t dive_time_minutes, SgasChangeList *pGasChangeList) |
38 | 510 { |
983 | 511 uint8_t GasChangeIndex = 0; |
678
05cdd367dbd0
Bugfix: deco planner did not initialize properly
Jan Mulder <jan@jlmulder.nl>
parents:
629
diff
changeset
|
512 |
983 | 513 for (GasChangeIndex = 0; GasChangeIndex < GAS_CHANGE_LIST_ITEMS; GasChangeIndex++) |
514 { | |
515 pGasChangeList[GasChangeIndex].depth = 0; | |
516 pGasChangeList[GasChangeIndex].gasId = 0; | |
517 } | |
38 | 518 SDiveState * pDiveState = &stateSim; |
519 copyDiveSettingsToSim(); | |
888
07af9efd7c13
Dev bugfix: Consider decogas in planner independen from calculation setting:
Ideenmodellierer
parents:
830
diff
changeset
|
520 |
38 | 521 vpm_init(&pDiveState->vpm, pDiveState->diveSettings.vpm_conservatism, 0, 0); |
522 //buehlmann_init(); | |
523 //timer_init(); | |
524 memset(&pDiveState->events,0, sizeof(SEvents)); | |
525 pDiveState->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = 0; | |
526 //Calc desaturation during intervall (with Air) | |
527 setActualGasAir(&pDiveState->lifeData); | |
528 if(intervall_time_minutes > 0) | |
529 { | |
530 decom_tissues_exposure(intervall_time_minutes * 60, &pDiveState->lifeData); | |
531 decom_oxygen_calculate_cns_degrade(&pDiveState->lifeData.cns, intervall_time_minutes * 60); | |
532 } | |
533 | |
534 //Switch to first Gas | |
535 setActualGasFirst(&pDiveState->lifeData); | |
536 | |
983 | 537 GasChangeIndex = 0; |
538 | |
539 if(pGasChangeList) | |
38 | 540 { |
983 | 541 pGasChangeList[GasChangeIndex].depth = 0; |
542 pGasChangeList[GasChangeIndex].gasId = pDiveState->lifeData.actualGas.GasIdInSettings; | |
543 GasChangeIndex++; | |
38 | 544 } |
545 | |
546 //Going down / descent | |
547 simulation_set_aim_depth(depth_meter); | |
790
3b5f9557c053
Fix bug introduced in 04b98a2, causing the deco planner to not show deco stops.
heinrichsweikamp
parents:
760
diff
changeset
|
548 sim_aim_time_minutes = 0; |
38 | 549 for(int i = 0; i < 60 * dive_time_minutes; i++) |
550 { | |
551 simulation_UpdateLifeData(0); | |
552 check_warning2(pDiveState); | |
553 if(pDiveState->warnings.betterGas) | |
554 { | |
555 setActualGas(&pDiveState->lifeData,actualBetterGasId(),pDiveState->lifeData.actualGas.setPoint_cbar); | |
983 | 556 if(pGasChangeList && (pDiveState->diveSettings.diveMode == DIVEMODE_OC)) |
38 | 557 { |
983 | 558 pGasChangeList[GasChangeIndex].depth = pDiveState->lifeData.depth_meter; |
559 pGasChangeList[GasChangeIndex].gasId = actualBetterGasId(); | |
560 GasChangeIndex++; | |
38 | 561 } |
562 } | |
563 } | |
564 | |
565 decom_CreateGasChangeList(&pDiveState->diveSettings, &pDiveState->lifeData); // was there before and needed for buehlmann_calc_deco and vpm_calc | |
566 | |
983 | 567 if(pGasChangeList && (pDiveState->diveSettings.diveMode == DIVEMODE_OC)) |
38 | 568 { |
569 // change direction from better gas to deco gas | |
983 | 570 pGasChangeList[GasChangeIndex].depth = 255; |
571 pGasChangeList[GasChangeIndex].gasId = 255; | |
572 GasChangeIndex++; | |
38 | 573 |
574 // ascend (deco) gases | |
575 for(int i=1; i<=5;i++) | |
576 { | |
983 | 577 if((pDiveState->diveSettings.decogaslist[i].change_during_ascent_depth_meter_otherwise_zero != 0) |
578 && (pDiveState->diveSettings.gas[pDiveState->diveSettings.decogaslist[i].GasIdInSettings].note.ub.deco)) | |
579 { | |
580 pGasChangeList[GasChangeIndex].depth = pDiveState->diveSettings.decogaslist[i].change_during_ascent_depth_meter_otherwise_zero; | |
581 pGasChangeList[GasChangeIndex].gasId = pDiveState->diveSettings.decogaslist[i].GasIdInSettings; | |
582 GasChangeIndex++; | |
583 } | |
38 | 584 } |
585 } | |
586 | |
587 // deco and ascend calc | |
588 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE) | |
589 { | |
590 /* this does modify the cns now 11.06.2015 */ | |
591 buehlmann_calc_deco(&pDiveState->lifeData,&pDiveState->diveSettings,&pDiveState->decolistBuehlmann); | |
592 pDiveState->lifeData.cns += buehlmann_get_gCNS(); | |
593 return &pDiveState->decolistBuehlmann; | |
594 } | |
595 else | |
596 { | |
597 /* this does modify the cns now 11.06.2015 */ | |
598 vpm_calc(&pDiveState->lifeData,&pDiveState->diveSettings,&pDiveState->vpm,&pDiveState->decolistVPM, DECOSTOPS); | |
599 pDiveState->lifeData.cns += vpm_get_CNS(); | |
910
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
600 |
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
601 while(decoLock == DECO_CALC_FINSHED_vpm) |
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
602 { |
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
603 HAL_Delay(2); /* The deco data is copied during the timer ISR => wait till this has happened */ |
7bd347bdaa81
Devbugfix Sample time resolution for longer dives:
Ideenmodellierer
parents:
907
diff
changeset
|
604 } |
38 | 605 return &pDiveState->decolistVPM; |
606 } | |
607 } | |
608 | |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
176
diff
changeset
|
609 static float sGChelper_bar(uint16_t depth_meter) |
38 | 610 { |
611 SDiveState * pDiveState = &stateSim; | |
612 float ambient, surface, density, meter; | |
613 | |
614 surface = pDiveState->lifeData.pressure_surface_bar; | |
615 | |
616 if(!depth_meter) | |
617 return surface; | |
618 | |
619 density = ((float)( 100 + settingsGetPointer()->salinity)) / 100.0f; | |
620 meter = depth_meter * (0.09807f * density); | |
621 ambient = (meter + surface); | |
622 | |
623 return ambient; | |
624 } | |
625 | |
983 | 626 void getNextDecoDepthAndTime(uint8_t* pDepth, uint16_t* pTime, uint8_t currentDepth, SDecoinfo *decoInfoInput) |
38 | 627 { |
983 | 628 uint8_t depthLast, depthSecond, depthInc; |
629 uint8_t decoIndex = 0; | |
630 | |
631 depthLast = (uint8_t)(stateUsed->diveSettings.last_stop_depth_bar * 10); | |
632 depthSecond = (uint8_t)(stateUsed->diveSettings.input_second_to_last_stop_depth_bar * 10); | |
633 depthInc = (uint8_t)(stateUsed->diveSettings.input_next_stop_increment_depth_bar * 10); | |
634 | |
635 if(currentDepth > depthLast) | |
636 { | |
637 for(decoIndex = DECOINFO_STRUCT_MAX_STOPS-1; decoIndex > 0; decoIndex--) | |
638 { | |
639 if(decoInfoInput->output_stop_length_seconds[decoIndex]) | |
640 { | |
641 *pDepth = depthSecond + ( decoIndex - 1 ) * depthInc; | |
642 if(*pDepth < currentDepth) | |
643 { | |
644 break; | |
645 } | |
646 } | |
647 } | |
648 | |
649 if(decoIndex == 0) | |
650 { | |
651 *pDepth = depthLast; | |
652 } | |
653 *pTime = decoInfoInput->output_stop_length_seconds[decoIndex]; | |
654 } | |
655 else | |
656 { | |
657 *pDepth = 0; | |
658 *pTime = 0; | |
659 } | |
660 } | |
661 | |
662 void simulation_evaluate_profil(uint16_t *outputConsumptionList, | |
663 SSimDataSummary *outputSummary, | |
664 uint16_t depth_meter, uint16_t dive_time_minutes,uint8_t gasConsumTravelInput, uint8_t gasConsumDecoInput, | |
665 SDecoinfo *decoInfoInput, | |
666 const SgasChangeList *pGasChangeList) | |
667 { | |
668 uint16_t nextDecoTime = 0; | |
669 uint8_t nextDecoDepth = 0; | |
670 | |
671 uint8_t currentConsumGasId = 0; | |
38 | 672 uint8_t nextGasChangeMeter = 0; |
983 | 673 uint8_t nextGasChangeGasId = 0; |
674 uint8_t ChangeListIndex = 0; | |
675 uint8_t firstDecoGasIndex = 0; | |
676 float outputConsumptionTempFloat[6]; | |
38 | 677 |
983 | 678 float sim_descent_rate_meter_per_sec_local = 10.0; |
679 float sim_ascent_rate_meter_per_sec_local = 10.0; | |
680 | |
681 float currentDepth_m = 0.0; | |
682 uint16_t currentTime_sec = 0; | |
683 float currentGasConsumption = 0.0; | |
38 | 684 |
685 SDiveState * pDiveState = &stateSim; | |
686 | |
983 | 687 for(ChangeListIndex = 0; ChangeListIndex < 6; ChangeListIndex++) |
688 { | |
689 outputConsumptionTempFloat[ChangeListIndex] = 0.0; | |
690 } | |
38 | 691 |
692 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE) | |
693 { | |
983 | 694 sim_descent_rate_meter_per_sec_local = sim_descent_rate_meter_per_min / 60.0; |
695 sim_ascent_rate_meter_per_sec_local = pDiveState->diveSettings.ascentRate_meterperminute / 60.0; | |
38 | 696 } |
697 else | |
698 { | |
983 | 699 sim_descent_rate_meter_per_sec_local = sim_descent_rate_meter_per_min / 60.0; |
700 sim_ascent_rate_meter_per_sec_local = 10.0 / 60.0; // fix in vpm_calc_deco(); | |
701 } | |
702 | |
703 outputSummary->descentRateMeterPerMinute = sim_descent_rate_meter_per_sec_local * 60; | |
704 outputSummary->ascentRateMeterPerMinute = sim_ascent_rate_meter_per_sec_local * 60; | |
705 outputSummary->timeToBottom = 0; | |
706 outputSummary->timeToFirstStop = 0; | |
707 outputSummary->depthMeterFirstStop = 0; | |
708 outputSummary->timeAtBottom = 0; | |
709 outputSummary->timeToSurface = 0; | |
710 | |
711 currentConsumGasId = pGasChangeList[0].gasId; | |
712 | |
713 /* ascent + at depth loop at the moment work gas does not support change depth => no need to check */ | |
714 while(currentTime_sec < dive_time_minutes * 60) | |
715 { | |
716 if(currentDepth_m < depth_meter) | |
717 { | |
718 currentDepth_m += sim_descent_rate_meter_per_sec_local; | |
719 currentGasConsumption = ((float)gasConsumTravelInput) * sGChelper_bar(currentDepth_m ) / 60.0; | |
720 } | |
721 else | |
722 { | |
723 if(outputSummary->timeToBottom == 0) | |
724 { | |
725 currentDepth_m = depth_meter; | |
726 outputSummary->timeToBottom = currentTime_sec / 60; | |
727 outputSummary->ppO2AtBottom = (sGChelper_bar(depth_meter) - WATER_VAPOUR_PRESSURE) * pDiveState->diveSettings.gas[currentConsumGasId].oxygen_percentage / 100.0f; | |
728 } | |
729 } | |
730 currentTime_sec++; | |
731 outputConsumptionTempFloat[currentConsumGasId] += currentGasConsumption; | |
38 | 732 } |
733 | |
983 | 734 outputSummary->timeAtBottom = (currentTime_sec / 60); /* - outputSummary->timeToBottom; */ |
38 | 735 |
983 | 736 /* move forward to deco gas section (behind 255 entry) */ |
737 for(ChangeListIndex = 0; ChangeListIndex < GAS_CHANGE_LIST_ITEMS; ChangeListIndex++) | |
38 | 738 { |
983 | 739 if(pGasChangeList[ChangeListIndex].depth == 255) |
740 { | |
741 ChangeListIndex++; | |
742 firstDecoGasIndex = ChangeListIndex; | |
743 nextGasChangeMeter = pGasChangeList[firstDecoGasIndex].depth; | |
744 nextGasChangeGasId = pGasChangeList[firstDecoGasIndex].gasId; | |
745 } | |
746 if((firstDecoGasIndex != 0) && (pGasChangeList[ChangeListIndex].depth > nextGasChangeMeter) /* find deepest gas switch */ | |
747 && (pGasChangeList[ChangeListIndex].depth < currentDepth_m)) | |
748 { | |
749 nextGasChangeMeter = pGasChangeList[ChangeListIndex].depth; | |
750 nextGasChangeGasId = pGasChangeList[ChangeListIndex].gasId; | |
751 } | |
38 | 752 } |
753 | |
983 | 754 /* do ascent with stops */ |
755 getNextDecoDepthAndTime(&nextDecoDepth, &nextDecoTime, currentDepth_m, decoInfoInput); | |
756 while(currentDepth_m > 0) | |
38 | 757 { |
983 | 758 if(currentDepth_m > nextDecoDepth) |
759 { | |
760 currentDepth_m -= sim_ascent_rate_meter_per_sec_local; | |
761 currentGasConsumption = ((float)gasConsumDecoInput) * sGChelper_bar(currentDepth_m ) / 60.0; | |
762 } | |
763 else | |
764 { | |
765 if(outputSummary->timeToFirstStop == 0) | |
766 { | |
767 currentDepth_m = nextDecoDepth; | |
768 outputSummary->timeToFirstStop = currentTime_sec / 60; | |
769 outputSummary->depthMeterFirstStop = nextDecoDepth; | |
770 } | |
771 if(nextDecoTime) | |
772 { | |
773 nextDecoTime--; | |
774 } | |
775 else | |
776 { | |
777 getNextDecoDepthAndTime(&nextDecoDepth, &nextDecoTime, currentDepth_m, decoInfoInput); | |
778 } | |
779 } | |
780 if(currentDepth_m <= nextGasChangeMeter) /* switch gas ? */ | |
781 { | |
782 nextGasChangeMeter = 0; | |
783 currentConsumGasId = nextGasChangeGasId; | |
784 for(ChangeListIndex = firstDecoGasIndex; ChangeListIndex < GAS_CHANGE_LIST_ITEMS; ChangeListIndex++) | |
785 { | |
786 if((pGasChangeList[ChangeListIndex].depth > nextGasChangeMeter) /* find deepest gas switch */ | |
787 && (pGasChangeList[ChangeListIndex].depth < currentDepth_m)) | |
788 { | |
789 nextGasChangeMeter = pGasChangeList[ChangeListIndex].depth; | |
790 nextGasChangeGasId = pGasChangeList[ChangeListIndex].gasId; | |
791 } | |
792 } | |
793 } | |
794 currentTime_sec++; | |
795 outputConsumptionTempFloat[currentConsumGasId] += currentGasConsumption; | |
38 | 796 } |
797 | |
901 | 798 if(decoInfoInput->output_time_to_surface_seconds) |
38 | 799 { |
901 | 800 outputSummary->timeToSurface = outputSummary->timeAtBottom + (decoInfoInput->output_time_to_surface_seconds / 60); |
38 | 801 } |
901 | 802 else |
803 { | |
983 | 804 outputSummary->timeToSurface = currentTime_sec / 60; |
805 } | |
806 | |
807 for(ChangeListIndex = 0; ChangeListIndex < 6; ChangeListIndex++) | |
808 { | |
809 outputConsumptionList[ChangeListIndex] = (uint16_t)outputConsumptionTempFloat[ChangeListIndex]; | |
901 | 810 } |
38 | 811 } |
812 | |
813 | |
814 /** | |
815 ****************************************************************************** | |
816 * @brief Simulator control during simulated dive | |
817 ****************************************************************************** | |
818 * @note called by user via tHomeDiveMenuControl() | |
819 * @param void | |
820 * @return void | |
821 */ | |
822 | |
823 | |
824 void Sim_Descend (void) | |
825 { | |
826 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = 0; | |
827 if(simulation_get_aim_depth() < 200) | |
828 simulation_set_aim_depth(simulation_get_aim_depth() + 1); | |
829 } | |
830 | |
831 | |
832 void Sim_Ascend (void) | |
833 { | |
834 if(simulation_get_aim_depth() > 0) | |
835 simulation_set_aim_depth(simulation_get_aim_depth() - 1); | |
836 } | |
837 | |
838 | |
839 void Sim_Divetime (void) | |
840 { | |
841 simulation_add_time(5); | |
842 } | |
843 | |
844 | |
845 void Sim_Quit (void) | |
846 { | |
847 if(stateSimGetPointer()->lifeData.counterSecondsShallowDepth) | |
848 { | |
849 simulation_exit(); | |
850 return; | |
851 } | |
852 | |
853 if(simulation_get_aim_depth() > 0) | |
854 { | |
855 simulation_set_aim_depth(0); | |
856 } | |
857 else | |
858 { | |
859 stateSimGetPointerWrite()->lifeData.depth_meter = 0; | |
860 if(stateSimGetPointer()->diveSettings.diveMode == DIVEMODE_Apnea) | |
861 { | |
862 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = 1; | |
863 } | |
864 else | |
865 { | |
866 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = settingsGetPointer()->timeoutDiveReachedZeroDepth - 15; | |
867 } | |
868 } | |
869 } | |
760
21949c88da90
Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents:
748
diff
changeset
|
870 |
629
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
871 void Sim_IncreasePPO(uint8_t sensorIdx) |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
872 { |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
873 if((sensorIdx < NUM_OF_SENSORS) && (simSensmVOffset[sensorIdx] + SIM_PPO2_STEP < 100.0) && ((stateUsed->diveSettings.ppo2sensors_deactivated & (1 << sensorIdx)) == 0)) |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
874 { |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
875 simSensmVOffset[sensorIdx] += SIM_PPO2_STEP; |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
876 } |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
877 } |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
878 void Sim_DecreasePPO(uint8_t sensorIdx) |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
879 { |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
880 if((sensorIdx < NUM_OF_SENSORS) && (simSensmVOffset[sensorIdx] - SIM_PPO2_STEP >= -100.0)) |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
881 { |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
882 simSensmVOffset[sensorIdx] -= SIM_PPO2_STEP; |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
883 } |
55a9aa740f13
Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents:
548
diff
changeset
|
884 } |