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