annotate Discovery/Src/simulation.c @ 189:8b8074080d7b avg-temp

Bugfix: average temperature on arrival from RTE instead of display time This commit is heavily inspired by commits 05c770dc2911 and ecb71521d004. Reading the code, it was clear that a display time averaging process for measured temperature was implemented as was fixed for current depth display in the two mentioned commits. The bug for the late averaging of the temperature is, obviously, not as prominent as the current depth fault. The bug fixed here was nothing more than a visual glitch when first selecting the temperature display in the lower left corner (by default at the start of the dive, or by manually selecting it during the dive using the left button). So, to summarize. A small visual glitch fix, but more important, more consistent data handling and code. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Fri, 15 Mar 2019 15:04:57 +0100
parents 1719b9d1094b
children 2bb1db22b5f5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 ///////////////////////////////////////////////////////////////////////////////
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 /// -*- coding: UTF-8 -*-
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 /// \file Discovery/Src/simulation.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 /// \brief Contains dive simulation functionality
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 /// \author Heinrichs Weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 /// \date 13-Oct-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 /// \details
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 /// The simulation uses "extern SDiveState stateSim" defined in dataCentral.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 /// simulation_start(void) sets stateUsed to stateSim and initializes simulation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 /// simulation_UpdateLifeData should be called at least once per second
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 /// simulation_end() sets stateUsed back to stateReal
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 /// $Id$
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 ///////////////////////////////////////////////////////////////////////////////
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 /// This program is free software: you can redistribute it and/or modify
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 /// it under the terms of the GNU General Public License as published by
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 /// the Free Software Foundation, either version 3 of the License, or
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 /// (at your option) any later version.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 /// This program is distributed in the hope that it will be useful,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 /// but WITHOUT ANY WARRANTY; without even the implied warranty of
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 /// GNU General Public License for more details.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 /// You should have received a copy of the GNU General Public License
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 /// along with this program. If not, see <http://www.gnu.org/licenses/>.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 //////////////////////////////////////////////////////////////////////////////
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 #include <string.h>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 #include "simulation.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 #include "decom.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 #include "calc_crush.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 #include "data_exchange.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 #include "timer.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 #include "check_warning.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 #include "vpm.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 #include "buehlmann.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 #include "logbook_miniLive.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 //Private state variables
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 float sim_aim_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 _Bool sim_head_decostops = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 const float sim_descent_rate_meter_per_min = 20;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 //Private functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 float sim_get_ambiant_pressure(SDiveState * pDiveState);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 void sim_reduce_deco_time_one_second(SDiveState* pDiveState);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 * @brief sets heed_decostops_while_ascending
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 * @param heed_decostops_while_ascending : true -> deco_stops are considered while ascending
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 void simulation_set_heed_decostops(_Bool heed_decostops_while_ascending)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 sim_head_decostops = heed_decostops_while_ascending;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 * @brief start of simulation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 void simulation_start(int aim_depth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 copyDiveSettingsToSim();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 copyVpmRepetetiveDataToSim();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 //vpm_init(&stateSimGetPointerWrite()->vpm, stateSimGetPointerWrite()->diveSettings.vpm_conservatism, 0, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 stateSimGetPointerWrite()->mode = MODE_DIVE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 if(aim_depth <= 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 aim_depth = 20;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 simulation_set_aim_depth(aim_depth);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 timer_init();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 stateUsed = &stateSim;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 stateSim.lifeData.boolResetAverageDepth = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 decoLock = DECO_CALC_init_as_is_start_of_dive;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 stateSim.lifeData.apnea_total_max_depth_meter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 * @brief end of simulation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 void simulation_exit(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 timer_Stopwatch_Stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 set_stateUsedToReal();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 * @brief simulates change of Lifedata (saturation, depth change, etc.) within one second
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 * @param checkOncePerSecond : true -> simulation in real time (function is evaluated only once per second)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 * and copy of parts of LifeData from SmallCPU with each call from HAL_TIM_PeriodElapsedCallback()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 * : false -> fast simulation (many simulation cycles per second are possible)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 void simulation_UpdateLifeData( _Bool checkOncePerSecond)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 SDiveState * pDiveState = &stateSim;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 static int last_second = -1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 static _Bool two_second = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 static float lastPressure_bar = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 if(checkOncePerSecond)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 pDiveState->lifeData.temperature_celsius = stateRealGetPointer()->lifeData.temperature_celsius;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 pDiveState->lifeData.compass_heading = stateRealGetPointer()->lifeData.compass_heading;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 pDiveState->lifeData.battery_charge = stateRealGetPointer()->lifeData.battery_charge;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 int now = current_second();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 if( last_second == now)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 last_second = now;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 if(!two_second)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 two_second = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 two_second = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 if(lastPressure_bar >= 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 //2 seconds * 30 == 1 minute, bar * 10 = meter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 pDiveState->lifeData.ascent_rate_meter_per_min = (lastPressure_bar - pDiveState->lifeData.pressure_ambient_bar) * 30 * 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 lastPressure_bar = pDiveState->lifeData.pressure_ambient_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 else if(pDiveState->lifeData.depth_meter <= (float)(decom_get_actual_deco_stop(pDiveState) + 0.001))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 sim_reduce_deco_time_one_second(pDiveState);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 pDiveState->lifeData.ppO2Sensor_bar[0] = stateRealGetPointer()->lifeData.ppO2Sensor_bar[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 pDiveState->lifeData.ppO2Sensor_bar[1] = stateRealGetPointer()->lifeData.ppO2Sensor_bar[1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 pDiveState->lifeData.ppO2Sensor_bar[2] = stateRealGetPointer()->lifeData.ppO2Sensor_bar[2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 pDiveState->lifeData.sensorVoltage_mV[0] = stateRealGetPointer()->lifeData.sensorVoltage_mV[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 pDiveState->lifeData.sensorVoltage_mV[1] = stateRealGetPointer()->lifeData.sensorVoltage_mV[1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 pDiveState->lifeData.sensorVoltage_mV[2] = stateRealGetPointer()->lifeData.sensorVoltage_mV[2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 pDiveState->lifeData.dive_time_seconds += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 pDiveState->lifeData.pressure_ambient_bar = sim_get_ambiant_pressure(pDiveState);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 if(!is_ambient_pressure_close_to_surface(&pDiveState->lifeData) && !(stateSimGetPointer()->lifeData.counterSecondsShallowDepth) )
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 pDiveState->lifeData.dive_time_seconds_without_surface_time += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 if(is_ambient_pressure_close_to_surface(&pDiveState->lifeData)) // new hw 170214
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 if(!(stateSimGetPointer()->lifeData.counterSecondsShallowDepth))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 if(pDiveState->diveSettings.diveMode != DIVEMODE_Apnea)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 pDiveState->lifeData.counterSecondsShallowDepth = settingsGetPointer()->timeoutDiveReachedZeroDepth - 15;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 pDiveState->lifeData.apnea_last_dive_time_seconds = pDiveState->lifeData.dive_time_seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 if(pDiveState->lifeData.apnea_last_dive_time_seconds > pDiveState->lifeData.dive_time_seconds_without_surface_time)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 pDiveState->lifeData.apnea_last_dive_time_seconds = pDiveState->lifeData.dive_time_seconds_without_surface_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 pDiveState->lifeData.apnea_last_max_depth_meter = pDiveState->lifeData.max_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 pDiveState->lifeData.counterSecondsShallowDepth = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 pDiveState->lifeData.counterSecondsShallowDepth = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 pDiveState->lifeData.depth_meter = (pDiveState->lifeData.pressure_ambient_bar - pDiveState->lifeData.pressure_surface_bar) * 10.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 if(pDiveState->lifeData.max_depth_meter < pDiveState->lifeData.depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 pDiveState->lifeData.max_depth_meter = pDiveState->lifeData.depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 /* apnoe specials
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 if(pDiveState->diveSettings.diveMode == DIVEMODE_Apnea)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 if(pDiveState->lifeData.max_depth_meter > pDiveState->lifeData.apnea_total_max_depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 pDiveState->lifeData.apnea_total_max_depth_meter = pDiveState->lifeData.max_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 if(pDiveState->lifeData.counterSecondsShallowDepth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 pDiveState->lifeData.dive_time_seconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 pDiveState->lifeData.max_depth_meter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 pDiveState->lifeData.boolResetAverageDepth = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 pDiveState->lifeData.boolResetStopwatch = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 /* average depth
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 float *AvgDepthValue = &pDiveState->lifeData.average_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 float DepthNow = pDiveState->lifeData.depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 uint32_t *AvgDepthCount = &pDiveState->lifeData.internal.average_depth_meter_Count;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 uint32_t *AvgDepthTimer = &pDiveState->lifeData.internal.average_depth_last_update_dive_time_seconds_without_surface_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 uint32_t AvgSecondsSinceLast;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 uint32_t DiveTime = pDiveState->lifeData.dive_time_seconds_without_surface_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 if(pDiveState->lifeData.boolResetAverageDepth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 *AvgDepthValue = DepthNow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 *AvgDepthCount = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 *AvgDepthTimer = DiveTime;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 pDiveState->lifeData.boolResetAverageDepth = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 else if (DiveTime > *AvgDepthTimer)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 AvgSecondsSinceLast = DiveTime - *AvgDepthTimer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 for(int i=0;i<AvgSecondsSinceLast;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 *AvgDepthValue = (*AvgDepthValue * *AvgDepthCount + DepthNow) / (*AvgDepthCount + 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 *AvgDepthCount += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 *AvgDepthTimer = DiveTime;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 if(*AvgDepthCount == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 *AvgDepthValue = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 /* Exposure Tissues
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 decom_tissues_exposure(1, &pDiveState->lifeData);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 /* moved to updateSetpointStateUsed()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 pDiveState->lifeData.ppO2 = decom_calc_ppO2( pDiveState->lifeData.pressure_ambient_bar, &pDiveState->lifeData.actualGas);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 decom_oxygen_calculate_cns_exposure(1, &pDiveState->lifeData.actualGas, pDiveState->lifeData.pressure_ambient_bar, &pDiveState->lifeData.cns);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 //if((pDiveState->lifeData.depth_meter < 0.1f) || (pDiveState->lifeData.dive_time_seconds > 1*60*60))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 // if(pDiveState->lifeData.dive_time_seconds > 1*60*60)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 if(pDiveState->lifeData.dive_time_seconds > 5*60*60) // test Dirk Berben
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 simulation_exit();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 if(stateSimGetPointer()->lifeData.counterSecondsShallowDepth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 if(stateSimGetPointer()->lifeData.counterSecondsShallowDepth >= settingsGetPointer()->timeoutDiveReachedZeroDepth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 simulation_exit();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 vpm_crush(pDiveState);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 * @brief adds extra time for fast simulation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 *@param minutes
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 * @return float : new pressure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 void simulation_add_time(int minutes)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 for(int i = 0; i < 60 * minutes; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 simulation_UpdateLifeData(0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 updateMiniLiveLogbook(0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 timer_UpdateSecond(0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 * @brief get aim_depth
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 * @return sim_aim_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 uint16_t simulation_get_aim_depth(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 return (uint16_t)sim_aim_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 * @brief get heed decostops
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 * @return true if ascend follows decostops;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 _Bool simulation_get_heed_decostops(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 return sim_head_decostops;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 * @brief sets aim_depth
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 *@param depth_meter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 * @return float : new pressure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 void simulation_set_aim_depth(int depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 sim_aim_depth_meter = depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 * @brief simulates ambiant pressure depending on aim depth
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 * @note if aim_depth != actual depth, the depth change within one second
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 * (depending on descent or ascent) rate is calculated
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 * @param SDiveState* pDiveState:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 * @return float : new ambiant pressure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 float sim_get_ambiant_pressure(SDiveState * pDiveState)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 //Calc next depth
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 uint8_t actual_deco_stop = decom_get_actual_deco_stop(pDiveState);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 float depth_meter = pDiveState->lifeData.depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 float surface_pressure_bar = pDiveState->lifeData.pressure_surface_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 if(depth_meter < sim_aim_depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 depth_meter = depth_meter + sim_descent_rate_meter_per_min / 60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 if(depth_meter > sim_aim_depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 depth_meter = sim_aim_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 else if(depth_meter > sim_aim_depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 depth_meter -= pDiveState->diveSettings.ascentRate_meterperminute / 60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 if(depth_meter < sim_aim_depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 depth_meter = sim_aim_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 if(sim_head_decostops && depth_meter < actual_deco_stop)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 if(actual_deco_stop < (depth_meter + pDiveState->diveSettings.ascentRate_meterperminute / 60))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 depth_meter = actual_deco_stop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 depth_meter += pDiveState->diveSettings.ascentRate_meterperminute / 60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 return surface_pressure_bar + depth_meter / 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 * @brief Reduces deco time of deepest stop by one second
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 * @note called during fast simulation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 * @param SDiveState* pDiveState:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 void sim_reduce_deco_time_one_second(SDiveState* pDiveState)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 SDecoinfo* pDecoinfo;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 pDecoinfo = &pDiveState->decolistBuehlmann;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 pDecoinfo = &pDiveState->decolistVPM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 //Reduce deco time of deepest stop by one second
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 for(int i = DECOINFO_STRUCT_MAX_STOPS -1 ;i >= 0; i--)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 if(pDecoinfo->output_stop_length_seconds[i] > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 pDecoinfo->output_stop_length_seconds[i]--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 SDecoinfo* simulation_decoplaner(uint16_t depth_meter, uint16_t intervall_time_minutes, uint16_t dive_time_minutes, uint8_t *gasChangeListDepthGas20x2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 uint8_t ptrGasChangeList = 0; // new hw 160704
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 SDiveState * pDiveState = &stateSim;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 copyDiveSettingsToSim();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 vpm_init(&pDiveState->vpm, pDiveState->diveSettings.vpm_conservatism, 0, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 //buehlmann_init();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 //timer_init();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 memset(&pDiveState->events,0, sizeof(SEvents));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 pDiveState->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 //Calc desaturation during intervall (with Air)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 setActualGasAir(&pDiveState->lifeData);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 if(intervall_time_minutes > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 decom_tissues_exposure(intervall_time_minutes * 60, &pDiveState->lifeData);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 decom_oxygen_calculate_cns_degrade(&pDiveState->lifeData.cns, intervall_time_minutes * 60);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 //Switch to first Gas
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 setActualGasFirst(&pDiveState->lifeData);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 // new hw 160704
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 if(gasChangeListDepthGas20x2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 gasChangeListDepthGas20x2[ptrGasChangeList++] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 gasChangeListDepthGas20x2[ptrGasChangeList++] = pDiveState->lifeData.actualGas.GasIdInSettings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 gasChangeListDepthGas20x2[0] =0; // depth zero
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 //Going down / descent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 simulation_set_aim_depth(depth_meter);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 for(int i = 0; i < 60 * dive_time_minutes; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 simulation_UpdateLifeData(0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 check_warning2(pDiveState);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 if(pDiveState->warnings.betterGas)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 setActualGas(&pDiveState->lifeData,actualBetterGasId(),pDiveState->lifeData.actualGas.setPoint_cbar);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 if(gasChangeListDepthGas20x2 && (pDiveState->diveSettings.diveMode == DIVEMODE_OC))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 gasChangeListDepthGas20x2[ptrGasChangeList++] = pDiveState->lifeData.depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 gasChangeListDepthGas20x2[ptrGasChangeList++] = actualBetterGasId();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 decom_CreateGasChangeList(&pDiveState->diveSettings, &pDiveState->lifeData); // was there before and needed for buehlmann_calc_deco and vpm_calc
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 // new hw 160704
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 if(gasChangeListDepthGas20x2 && (pDiveState->diveSettings.diveMode == DIVEMODE_OC))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 // change direction from better gas to deco gas
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 gasChangeListDepthGas20x2[ptrGasChangeList++] = 255;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 gasChangeListDepthGas20x2[ptrGasChangeList++] = 255;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 // ascend (deco) gases
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 for(int i=1; i<=5;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 if(pDiveState->diveSettings.decogaslist[i].change_during_ascent_depth_meter_otherwise_zero == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 gasChangeListDepthGas20x2[ptrGasChangeList++] = pDiveState->diveSettings.decogaslist[i].change_during_ascent_depth_meter_otherwise_zero;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 gasChangeListDepthGas20x2[ptrGasChangeList++] = pDiveState->diveSettings.decogaslist[i].GasIdInSettings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 gasChangeListDepthGas20x2[0] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 // deco and ascend calc
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 /* this does modify the cns now 11.06.2015 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 buehlmann_calc_deco(&pDiveState->lifeData,&pDiveState->diveSettings,&pDiveState->decolistBuehlmann);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 pDiveState->lifeData.cns += buehlmann_get_gCNS();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 return &pDiveState->decolistBuehlmann;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 /* this does modify the cns now 11.06.2015 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 vpm_calc(&pDiveState->lifeData,&pDiveState->diveSettings,&pDiveState->vpm,&pDiveState->decolistVPM, DECOSTOPS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 pDiveState->lifeData.cns += vpm_get_CNS();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 return &pDiveState->decolistVPM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 float sGChelper_bar(uint16_t depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 SDiveState * pDiveState = &stateSim;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 float ambient, surface, density, meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 surface = pDiveState->lifeData.pressure_surface_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 if(!depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 return surface;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 density = ((float)( 100 + settingsGetPointer()->salinity)) / 100.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 meter = depth_meter * (0.09807f * density);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 ambient = (meter + surface);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 return ambient;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 * @brief simulation_helper_change_points
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 * @param
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 void simulation_helper_change_points(SSimDataSummary *outputSummary, uint16_t depth_meter, uint16_t dive_time_minutes, SDecoinfo *decoInfoInput, const uint8_t *gasChangeListDepthGas20x2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491 uint8_t ptrDecoInfo = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 uint16_t actualDepthPoint = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493 uint16_t nextDepthPoint = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 uint8_t actualConsumGasId = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 uint8_t nextGasChangeMeter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 uint8_t ptrChangeList = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 float timeThis = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 float timeSummary = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500 float sim_descent_rate_meter_per_min_local = 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 float sim_ascent_rate_meter_per_min_local = 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 SDiveState * pDiveState = &stateSim;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 uint8_t depthDecoNext, depthLast, depthSecond, depthInc;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 sim_descent_rate_meter_per_min_local = sim_descent_rate_meter_per_min; // const float
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510 sim_ascent_rate_meter_per_min_local = pDiveState->diveSettings.ascentRate_meterperminute;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 sim_descent_rate_meter_per_min_local = sim_descent_rate_meter_per_min; // const float
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 sim_ascent_rate_meter_per_min_local = 10;// fix in vpm_calc_deco();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 outputSummary->descentRateMeterPerMinute = sim_descent_rate_meter_per_min_local;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 outputSummary->ascentRateMeterPerMinute = sim_ascent_rate_meter_per_min_local;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 // bottom gas ppO2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 if(gasChangeListDepthGas20x2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 nextGasChangeMeter = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 actualConsumGasId = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 nextGasChangeMeter = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 while(actualDepthPoint < depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530 if(nextGasChangeMeter && (nextGasChangeMeter < depth_meter) && (gasChangeListDepthGas20x2[ptrChangeList] != 255)) // list has 255,255 for turn from travel to deco
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 nextDepthPoint = nextGasChangeMeter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 nextDepthPoint = depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 if(actualConsumGasId > 5) // safety first
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 actualConsumGasId = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 actualDepthPoint = nextDepthPoint;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544 if(actualDepthPoint != depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 actualConsumGasId = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 nextGasChangeMeter = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553 actualConsumGasId = pDiveState->lifeData.actualGas.GasIdInSettings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 nextGasChangeMeter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556 outputSummary->ppO2AtBottom = (sGChelper_bar(depth_meter) - WATER_VAPOUR_PRESSURE) * pDiveState->diveSettings.gas[actualConsumGasId].oxygen_percentage / 100.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559 // going down
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 actualDepthPoint = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 nextDepthPoint = depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 timeThis = ((float)(nextDepthPoint - actualDepthPoint)) / sim_descent_rate_meter_per_min_local;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 timeSummary += timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 outputSummary->timeToBottom = (uint16_t)timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 // bottom time
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 timeThis = ((float)dive_time_minutes) - timeSummary;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 timeSummary += timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570 outputSummary->timeAtBottom = (uint16_t)timeSummary;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 // ascend to first deco stop
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 actualDepthPoint = depth_meter; // that is where we are
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575 timeThis = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 if(!decoInfoInput->output_stop_length_seconds[0]) // NDL dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579 depthLast = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 ptrDecoInfo = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581 depthDecoNext = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 // prepare deco stop list
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586 depthLast = (uint8_t)(stateUsed->diveSettings.last_stop_depth_bar * 10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 depthSecond = (uint8_t)(stateUsed->diveSettings.input_second_to_last_stop_depth_bar * 10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 depthInc = (uint8_t)(stateUsed->diveSettings.input_next_stop_increment_depth_bar * 10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 for(ptrDecoInfo=DECOINFO_STRUCT_MAX_STOPS-1; ptrDecoInfo>0; ptrDecoInfo--)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 if(decoInfoInput->output_stop_length_seconds[ptrDecoInfo]) break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 if(ptrDecoInfo == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595 depthDecoNext = depthLast;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598 depthDecoNext = depthSecond + (( ptrDecoInfo - 1 )* depthInc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601 nextDepthPoint = depthDecoNext;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 if(actualDepthPoint > nextDepthPoint)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604 // flip signs! It's going up
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 timeThis = ((float)(actualDepthPoint - nextDepthPoint)) / sim_ascent_rate_meter_per_min_local;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606 actualDepthPoint = nextDepthPoint; // that is where we are
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608 timeSummary += timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609 outputSummary->timeToFirstStop = (uint16_t)timeSummary;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610 outputSummary->depthMeterFirstStop = actualDepthPoint;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612 //ascent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613 nextDepthPoint = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614 timeThis = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615 if(actualDepthPoint > nextDepthPoint) // only if deco
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617 // ascent time
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 timeThis = ((float)(actualDepthPoint - nextDepthPoint)) / sim_ascent_rate_meter_per_min_local;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 // deco stop time
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621 for(ptrDecoInfo=0;ptrDecoInfo < DECOINFO_STRUCT_MAX_STOPS; ptrDecoInfo++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623 timeThis += decoInfoInput->output_stop_length_seconds[ptrDecoInfo] / 60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624 if(!decoInfoInput->output_stop_length_seconds[ptrDecoInfo]) break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627 timeSummary += timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628 outputSummary->timeToSurface = (uint16_t)timeSummary;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635 * @brief simulation_gas_consumption
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 * @note called by openEdit_PlanResult() in tMenuEditPlanner.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638 * @note the ascend and descend time is taken from pDiveState->lifeData.ascent_rate_meter_per_min and const float sim_descent_rate_meter_per_min
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639 * @param outputConsumptionList list from 1 to 5 for gas 1 to 5
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 * @param depth_meter for descend
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641 * @param dive_time_minutes for descend and bottom time
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 * @param the calculated deco list
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 * @param gasConsumTravelInput: how many l/min for all but deco stops
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644 * @param gasConsumDecoInput: how many l/min for deco stops only
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648 void simulation_gas_consumption(uint16_t *outputConsumptionList, uint16_t depth_meter, uint16_t dive_time_minutes, SDecoinfo *decoInfoInput, uint8_t gasConsumTravelInput, uint8_t gasConsumDecoInput, const uint8_t *gasChangeListDepthGas20x2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650 uint8_t ptrDecoInfo = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 uint8_t ptrChangeList = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652 uint8_t actualConsumGasId = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653 uint8_t nextGasChangeMeter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654 uint16_t actualDepthPoint = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655 uint16_t nextDepthPoint = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656 uint16_t inBetweenDepthPoint = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 float timeThis = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658 float consumThis = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659 float timeSummary = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 float outputConsumptionTempFloat[6];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661 float sim_descent_rate_meter_per_min_local = 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 float sim_ascent_rate_meter_per_min_local = 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 SDiveState * pDiveState = &stateSim;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665
51
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
666 uint8_t depthDecoNext = 0;
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
667 uint8_t depthLast = 0;
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
668 uint8_t depthSecond = 0;
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
669 uint8_t depthInc = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 for(int i = 1; i < 6; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 outputConsumptionTempFloat[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 if(gasChangeListDepthGas20x2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 nextGasChangeMeter = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 actualConsumGasId = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 nextGasChangeMeter = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 actualConsumGasId = pDiveState->lifeData.actualGas.GasIdInSettings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 nextGasChangeMeter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 sim_descent_rate_meter_per_min_local = sim_descent_rate_meter_per_min; // const float
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 sim_ascent_rate_meter_per_min_local = pDiveState->diveSettings.ascentRate_meterperminute;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693 sim_descent_rate_meter_per_min_local = sim_descent_rate_meter_per_min; // const float
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 sim_ascent_rate_meter_per_min_local = 10;// fix in vpm_calc_deco();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 // while((nextGasChangeMeter < depth_meter) && (actualDepthPoint < depth_meter))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 while(actualDepthPoint < depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 if(nextGasChangeMeter && (nextGasChangeMeter < depth_meter) && (gasChangeListDepthGas20x2[ptrChangeList] != 255)) // list has 255,255 for turn from travel to deco
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702 nextDepthPoint = nextGasChangeMeter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 nextDepthPoint = depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 if(actualConsumGasId > 5) // safety first
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 actualConsumGasId = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 timeThis = ((float)(nextDepthPoint - actualDepthPoint)) / sim_descent_rate_meter_per_min_local;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 if(actualDepthPoint) // not if on surface
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715 consumThis = ((float)gasConsumTravelInput) * sGChelper_bar(actualDepthPoint) * timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 consumThis += ((float)gasConsumTravelInput) * sGChelper_bar(nextDepthPoint -actualDepthPoint) * timeThis / 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 outputConsumptionTempFloat[actualConsumGasId] += consumThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719 timeSummary += timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 actualDepthPoint = nextDepthPoint;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 if(actualDepthPoint != depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 actualConsumGasId = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 nextGasChangeMeter = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730 // bottom Time
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 timeThis = ((float)dive_time_minutes) - timeSummary;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 if(timeThis > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735 consumThis = ((float)gasConsumTravelInput) * sGChelper_bar(depth_meter) * timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736 outputConsumptionTempFloat[actualConsumGasId] += consumThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 // ascend with deco stops prepare
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740 if(gasChangeListDepthGas20x2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 ptrChangeList++;// gasChangeListDepthGas20x2[ptrChangeList++]; // should be the 255
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743 nextGasChangeMeter = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747 nextGasChangeMeter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 if(!decoInfoInput->output_stop_length_seconds[0]) // NDL dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 depthLast = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 ptrDecoInfo = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 // prepare deco stop list
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 depthLast = (uint8_t)(stateUsed->diveSettings.last_stop_depth_bar * 10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 depthSecond = (uint8_t)(stateUsed->diveSettings.input_second_to_last_stop_depth_bar * 10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 depthInc = (uint8_t)(stateUsed->diveSettings.input_next_stop_increment_depth_bar * 10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 for(ptrDecoInfo=DECOINFO_STRUCT_MAX_STOPS-1; ptrDecoInfo>0; ptrDecoInfo--)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764 if(decoInfoInput->output_stop_length_seconds[ptrDecoInfo]) break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 actualDepthPoint = depth_meter; // that is where we are
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769 // ascend with deco stops
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770 while(actualDepthPoint)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 if(ptrDecoInfo == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774 depthDecoNext = depthLast;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777 depthDecoNext = depthSecond + (( ptrDecoInfo - 1 )* depthInc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779 if(nextGasChangeMeter && (nextGasChangeMeter > depthDecoNext))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781 nextDepthPoint = nextGasChangeMeter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 nextDepthPoint = depthDecoNext;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 if(actualConsumGasId > 5) // safety first
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 actualConsumGasId = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791 if(actualDepthPoint > nextDepthPoint)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793 // flip signs! It's going up
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 timeThis = ((float)(actualDepthPoint - nextDepthPoint)) / sim_ascent_rate_meter_per_min_local;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 inBetweenDepthPoint = nextDepthPoint + ((actualDepthPoint - nextDepthPoint)/2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796 consumThis = ((float)gasConsumDecoInput) * sGChelper_bar(inBetweenDepthPoint) * timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 if(nextDepthPoint)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800 consumThis = ((float)gasConsumDecoInput) * sGChelper_bar(nextDepthPoint) * timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 consumThis = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806 consumThis += ((float)gasConsumDecoInput) * sGChelper_bar(actualDepthPoint - nextDepthPoint) * timeThis / 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808 outputConsumptionTempFloat[actualConsumGasId] += consumThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 if(nextGasChangeMeter && (nextDepthPoint == nextGasChangeMeter))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 actualConsumGasId = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 nextGasChangeMeter = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817 if(actualConsumGasId > 5) // safety first
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 actualConsumGasId = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820 if(nextDepthPoint && (nextDepthPoint == depthDecoNext))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822 if(decoInfoInput->output_stop_length_seconds[ptrDecoInfo])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 timeThis = ((float)(decoInfoInput->output_stop_length_seconds[ptrDecoInfo])) / 60.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825 consumThis = ((float)gasConsumDecoInput) * sGChelper_bar(nextDepthPoint) * timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826 outputConsumptionTempFloat[actualConsumGasId] += consumThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828 if(ptrDecoInfo != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 ptrDecoInfo--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 depthLast = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 actualDepthPoint = nextDepthPoint;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 // copy and return
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 for(int i = 1; i < 6; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842 outputConsumptionList[i] = (uint16_t)(outputConsumptionTempFloat[i]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847 * @brief Simulator control during simulated dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 * @note called by user via tHomeDiveMenuControl()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 * @param void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855 void Sim_Descend (void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 if(simulation_get_aim_depth() < 200)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859 simulation_set_aim_depth(simulation_get_aim_depth() + 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863 void Sim_Ascend (void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865 if(simulation_get_aim_depth() > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866 simulation_set_aim_depth(simulation_get_aim_depth() - 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
868
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870 void Sim_Divetime (void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
871 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
872 simulation_add_time(5);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
873 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
875
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
876 void Sim_Quit (void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
877 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
878 if(stateSimGetPointer()->lifeData.counterSecondsShallowDepth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
879 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
880 simulation_exit();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
881 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
882 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
883
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
884 if(simulation_get_aim_depth() > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
885 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
886 simulation_set_aim_depth(0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890 stateSimGetPointerWrite()->lifeData.depth_meter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891 if(stateSimGetPointer()->diveSettings.diveMode == DIVEMODE_Apnea)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
897 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = settingsGetPointer()->timeoutDiveReachedZeroDepth - 15;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
898 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
899 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
900 }