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