annotate Discovery/Src/simulation.c @ 907:46a21ff3f5ab Evo_2_23

Adaptation custom view deco plan for VPM: The VPM deco plan now shows the start of deco zone as well as the state of the deco table state. In case the table defined when reaching the deco zone is updated then the header line will change to yellow to indicate this. In case a deco stop is missed the head line will change to red.
author ideenmodellierer
date Sun, 13 Oct 2024 18:13:35 +0200
parents e4e9acfde839
children 7bd347bdaa81
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"
308
1203255481e4 cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents: 307
diff changeset
40 #include "data_exchange_main.h"
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 #include "timer.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 #include "check_warning.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 #include "vpm.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 #include "buehlmann.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 #include "logbook_miniLive.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46
450
b2f8a39c11ea Added new compile switches for variants:
ideenmodellierer
parents: 446
diff changeset
47 #include "configuration.h"
b2f8a39c11ea Added new compile switches for variants:
ideenmodellierer
parents: 446
diff changeset
48
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 //Private state variables
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 176
diff changeset
50 static float sim_aim_depth_meter;
760
21949c88da90 Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents: 748
diff changeset
51 static float sim_aim_time_minutes;
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 176
diff changeset
52 static _Bool sim_heed_decostops = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
54 static float sim_descent_rate_meter_per_min = 20;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
55
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
56 static uint16_t* pReplayData; /* pointer to source dive data */
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
57 static uint8_t simReplayActive = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 //Private functions
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 233
diff changeset
61 static float sim_get_ambient_pressure(SDiveState * pDiveState);
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 176
diff changeset
62 static void sim_reduce_deco_time_one_second(SDiveState* pDiveState);
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 176
diff changeset
63 static void simulation_set_aim_depth(int depth_meter);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
65 #define NUM_OF_SENSORS (3u)
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
66 #define SIM_PPO2_STEP (1.1f)
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
67 static float simSensmVOffset[NUM_OF_SENSORS];
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
68
38
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 sets heed_decostops_while_ascending
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 * @param heed_decostops_while_ascending : true -> deco_stops are considered while ascending
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 void simulation_set_heed_decostops(_Bool heed_decostops_while_ascending)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 {
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
78 sim_heed_decostops = heed_decostops_while_ascending;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 * @brief start of simulation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 */
760
21949c88da90 Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents: 748
diff changeset
87 void simulation_start(int aim_depth, uint16_t aim_time_minutes)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 {
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
89 uint16_t replayDataLength = 0;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
90 uint8_t* pReplayMarker;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
91 uint16_t max_depth = 10;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
92 uint16_t diveMinutes = 0;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
93
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
94 copyDiveSettingsToSim();
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 copyVpmRepetetiveDataToSim();
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
96
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 //vpm_init(&stateSimGetPointerWrite()->vpm, stateSimGetPointerWrite()->diveSettings.vpm_conservatism, 0, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = 0;
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
99 stateSimGetPointerWrite()->mode = MODE_DIVE;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 if(aim_depth <= 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 aim_depth = 20;
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
102 sim_descent_rate_meter_per_min = 20;
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
103 simulation_set_aim_depth(aim_depth);
760
21949c88da90 Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents: 748
diff changeset
104 sim_aim_time_minutes = aim_time_minutes;
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
105 timer_init();
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
106 set_stateUsedToSim();
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 stateSim.lifeData.boolResetAverageDepth = 1;
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
108 decoLock = DECO_CALC_init_as_is_start_of_dive;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 stateSim.lifeData.apnea_total_max_depth_meter = 0;
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
111 memset(simSensmVOffset,0,sizeof(simSensmVOffset));
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
112 if(getReplayOffset() != 0xFFFF)
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
113 {
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
114 simReplayActive = 1;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
115 getReplayInfo(&pReplayData, &pReplayMarker, &replayDataLength, &max_depth, &diveMinutes);
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
116 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 * @brief end of simulation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 void simulation_exit(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 timer_Stopwatch_Stop();
805
dd7ce655db26 Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents: 790
diff changeset
129
dd7ce655db26 Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents: 790
diff changeset
130 disableTimer();
dd7ce655db26 Adds a simple countdown timer, available as a custom view in surface and dive mode.
heinrichsweikamp
parents: 790
diff changeset
131
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 set_stateUsedToReal();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 * @brief simulates change of Lifedata (saturation, depth change, etc.) within one second
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 * @param checkOncePerSecond : true -> simulation in real time (function is evaluated only once per second)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 * and copy of parts of LifeData from SmallCPU with each call from HAL_TIM_PeriodElapsedCallback()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 * : false -> fast simulation (many simulation cycles per second are possible)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 void simulation_UpdateLifeData( _Bool checkOncePerSecond)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 SDiveState * pDiveState = &stateSim;
813
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
148 const SDiveState * pRealState = stateRealGetPointer();
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
149 SSettings *pSettings;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 static int last_second = -1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 static _Bool two_second = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 static float lastPressure_bar = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
155 if ((sim_aim_time_minutes && sim_aim_time_minutes * 60 <= pDiveState->lifeData.dive_time_seconds)
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
156 && (!simReplayActive))
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
157 {
760
21949c88da90 Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents: 748
diff changeset
158 simulation_set_aim_depth(0);
21949c88da90 Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents: 748
diff changeset
159 }
21949c88da90 Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents: 748
diff changeset
160
699
01f40cb1057e Cleanup warnings:
Ideenmodellierer
parents: 678
diff changeset
161 float localCalibCoeff[3] = { 0.0, 0.0, 0.0 };
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
162 uint8_t index, index2;
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
163
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 if(checkOncePerSecond)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 {
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
166 int now = current_second();
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
167 if( last_second == now)
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
168 return;
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
169 last_second = now;
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
170
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
171 if(!two_second)
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
172 two_second = 1;
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
173 else
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
174 {
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
175 two_second = 0;
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
176 }
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
177 pSettings = settingsGetPointer();
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
178 for(index = 0; index < 3; index++)
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
179 {
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
180 localCalibCoeff[index] = pSettings->ppo2sensors_calibCoeff[index];
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
181 if(localCalibCoeff[index] < 0.01)
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
182 {
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
183 for(index2 = 0; index2 < 3; index2++) /* no valid coeff => check other entries */
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
184 {
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
185 if(pSettings->ppo2sensors_calibCoeff[index2] > 0.01)
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
186 {
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
187 localCalibCoeff[index] = pSettings->ppo2sensors_calibCoeff[index2];
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
188 break;
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
189 }
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
190 if(index2 == 3) /* no coeff at all => use default */
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
191 {
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
192 localCalibCoeff[index] = 0.02;
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
193 }
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
194 }
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
195 }
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
196 }
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
197
813
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
198 pDiveState->lifeData.temperature_celsius = pRealState->lifeData.temperature_celsius;
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
199 pDiveState->lifeData.battery_charge = pRealState->lifeData.battery_charge;
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
200 pDiveState->lifeData.compass_heading = pRealState->lifeData.compass_heading;
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
201 pDiveState->lifeData.compass_roll = pRealState->lifeData.compass_roll;
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
202 pDiveState->lifeData.compass_pitch = pRealState->lifeData.compass_pitch;
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
203
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
204 for(index = 0; index < 3; index++)
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
205 {
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
206 memcpy(&pDiveState->lifeData.extIf_sensor_data[index], &pRealState->lifeData.extIf_sensor_data[index], 32);
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
207 }
548
e7e44986684a Update roll and pitch value in simulation mode:
Ideenmodellierer
parents: 450
diff changeset
208
446
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 308
diff changeset
209 #ifdef ENABLE_BOTTLE_SENSOR
813
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
210 pDiveState->lifeData.bottle_bar[pDiveState->lifeData.actualGas.GasIdInSettings] = pRealState->lifeData.bottle_bar[pRealState->lifeData.actualGas.GasIdInSettings];
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
211 pDiveState->lifeData.bottle_bar_age_MilliSeconds[pDiveState->lifeData.actualGas.GasIdInSettings] = pRealState->lifeData.bottle_bar_age_MilliSeconds[pRealState->lifeData.actualGas.GasIdInSettings];
446
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 308
diff changeset
212 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 else if(pDiveState->lifeData.depth_meter <= (float)(decom_get_actual_deco_stop(pDiveState) + 0.001))
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
215 {
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
216 if(decoLock == DECO_CALC_FINSHED_vpm)
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
217 {
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
218 sim_reduce_deco_time_one_second(&stateDeco);
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
219 }
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
220 else
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
221 {
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
222 sim_reduce_deco_time_one_second(pDiveState);
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
223 }
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
224 }
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
225
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 pDiveState->lifeData.dive_time_seconds += 1;
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 233
diff changeset
227 pDiveState->lifeData.pressure_ambient_bar = sim_get_ambient_pressure(pDiveState);
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
228 if(pDiveState->lifeData.pressure_ambient_bar < 1.5)
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
229 {
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
230 lastPressure_bar = 0;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
231 pDiveState->lifeData.ascent_rate_meter_per_min = 0;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
232 }
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
233 if(lastPressure_bar > 0)
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
234 {
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
235 //1 second * 60 == 1 minute, bar * 10 = meter
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
236 pDiveState->lifeData.ascent_rate_meter_per_min = (lastPressure_bar - pDiveState->lifeData.pressure_ambient_bar) * 600.0;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
237 }
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
238 lastPressure_bar = pDiveState->lifeData.pressure_ambient_bar;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239
813
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
240 pDiveState->lifeData.sensorVoltage_mV[0] = pRealState->lifeData.sensorVoltage_mV[0] + simSensmVOffset[0];
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
241 if(pDiveState->lifeData.sensorVoltage_mV[0] < 0.0) { pDiveState->lifeData.sensorVoltage_mV[0] = 0.0; }
813
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
242 pDiveState->lifeData.sensorVoltage_mV[1] = pRealState->lifeData.sensorVoltage_mV[1] + simSensmVOffset[1];
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
243 if(pDiveState->lifeData.sensorVoltage_mV[1] < 0.0) { pDiveState->lifeData.sensorVoltage_mV[1] = 0.0; }
813
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
244 pDiveState->lifeData.sensorVoltage_mV[2] = pRealState->lifeData.sensorVoltage_mV[2] + simSensmVOffset[2];
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
245 if(pDiveState->lifeData.sensorVoltage_mV[2] < 0.0) { pDiveState->lifeData.sensorVoltage_mV[2] = 0.0; }
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
246
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
247 pDiveState->lifeData.ppO2Sensor_bar[0] = pDiveState->lifeData.sensorVoltage_mV[0] * localCalibCoeff[0] * pDiveState->lifeData.pressure_ambient_bar;
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
248 pDiveState->lifeData.ppO2Sensor_bar[1] = pDiveState->lifeData.sensorVoltage_mV[1] * localCalibCoeff[1] * pDiveState->lifeData.pressure_ambient_bar;
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
249 pDiveState->lifeData.ppO2Sensor_bar[2] = pDiveState->lifeData.sensorVoltage_mV[2] * localCalibCoeff[2] * pDiveState->lifeData.pressure_ambient_bar;
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
250
813
1e688b630a6e Used real sensor state in simulation:
Ideenmodellierer
parents: 805
diff changeset
251 pDiveState->lifeData.CO2_data.CO2_ppm = pRealState->lifeData.CO2_data.CO2_ppm;
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
252
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 if(is_ambient_pressure_close_to_surface(&pDiveState->lifeData)) // new hw 170214
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 if(!(stateSimGetPointer()->lifeData.counterSecondsShallowDepth))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 if(pDiveState->diveSettings.diveMode != DIVEMODE_Apnea)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 pDiveState->lifeData.counterSecondsShallowDepth = settingsGetPointer()->timeoutDiveReachedZeroDepth - 15;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 pDiveState->lifeData.apnea_last_dive_time_seconds = pDiveState->lifeData.dive_time_seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 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
263 pDiveState->lifeData.apnea_last_dive_time_seconds = pDiveState->lifeData.dive_time_seconds_without_surface_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 pDiveState->lifeData.apnea_last_max_depth_meter = pDiveState->lifeData.max_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 pDiveState->lifeData.counterSecondsShallowDepth = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 pDiveState->lifeData.counterSecondsShallowDepth = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273
304
43b44f8d4fb0 bugfix, simulator: fix the 1 sec difference between stopwatch and divetime
Jan Mulder <jlmulder@xs4all.nl>
parents: 300
diff changeset
274 if(!is_ambient_pressure_close_to_surface(&pDiveState->lifeData) && !(stateSimGetPointer()->lifeData.counterSecondsShallowDepth) )
43b44f8d4fb0 bugfix, simulator: fix the 1 sec difference between stopwatch and divetime
Jan Mulder <jlmulder@xs4all.nl>
parents: 300
diff changeset
275 {
43b44f8d4fb0 bugfix, simulator: fix the 1 sec difference between stopwatch and divetime
Jan Mulder <jlmulder@xs4all.nl>
parents: 300
diff changeset
276 pDiveState->lifeData.dive_time_seconds_without_surface_time += 1;
43b44f8d4fb0 bugfix, simulator: fix the 1 sec difference between stopwatch and divetime
Jan Mulder <jlmulder@xs4all.nl>
parents: 300
diff changeset
277 }
43b44f8d4fb0 bugfix, simulator: fix the 1 sec difference between stopwatch and divetime
Jan Mulder <jlmulder@xs4all.nl>
parents: 300
diff changeset
278
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 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
280 if(pDiveState->lifeData.max_depth_meter < pDiveState->lifeData.depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 pDiveState->lifeData.max_depth_meter = pDiveState->lifeData.depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 /* apnoe specials
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 if(pDiveState->diveSettings.diveMode == DIVEMODE_Apnea)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 if(pDiveState->lifeData.max_depth_meter > pDiveState->lifeData.apnea_total_max_depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 pDiveState->lifeData.apnea_total_max_depth_meter = pDiveState->lifeData.max_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 if(pDiveState->lifeData.counterSecondsShallowDepth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 pDiveState->lifeData.dive_time_seconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 pDiveState->lifeData.max_depth_meter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 pDiveState->lifeData.boolResetAverageDepth = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297
308
1203255481e4 cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents: 307
diff changeset
298 setAvgDepth(pDiveState);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 /* Exposure Tissues
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 decom_tissues_exposure(1, &pDiveState->lifeData);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 decom_oxygen_calculate_cns_exposure(1, &pDiveState->lifeData.actualGas, pDiveState->lifeData.pressure_ambient_bar, &pDiveState->lifeData.cns);
233
9f0efc4df01e cleanup, bugfix: do not exit simulator on 5h dive time
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
304
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 if(stateSimGetPointer()->lifeData.counterSecondsShallowDepth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 if(stateSimGetPointer()->lifeData.counterSecondsShallowDepth >= settingsGetPointer()->timeoutDiveReachedZeroDepth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 simulation_exit();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 vpm_crush(pDiveState);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 * @brief adds extra time for fast simulation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 *@param minutes
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 * @return float : new pressure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 */
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 176
diff changeset
321 static void simulation_add_time(int minutes)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 for(int i = 0; i < 60 * minutes; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 simulation_UpdateLifeData(0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 updateMiniLiveLogbook(0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 timer_UpdateSecond(0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 * @brief get aim_depth
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 * @return sim_aim_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 uint16_t simulation_get_aim_depth(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 return (uint16_t)sim_aim_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 * @brief get heed decostops
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 * @return true if ascend follows decostops;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 _Bool simulation_get_heed_decostops(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 {
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 176
diff changeset
352 return sim_heed_decostops;
38
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 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 * @brief sets aim_depth
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 *@param depth_meter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 * @return float : new pressure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 */
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 176
diff changeset
362 static void simulation_set_aim_depth(int depth_meter)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 sim_aim_depth_meter = depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 ******************************************************************************
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 233
diff changeset
369 * @brief simulates ambient pressure depending on aim depth
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 * @note if aim_depth != actual depth, the depth change within one second
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 * (depending on descent or ascent) rate is calculated
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 * @param SDiveState* pDiveState:
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 233
diff changeset
374 * @return float : new ambient pressure
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 */
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 233
diff changeset
376 static float sim_get_ambient_pressure(SDiveState * pDiveState)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 //Calc next depth
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 uint8_t actual_deco_stop = decom_get_actual_deco_stop(pDiveState);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 float depth_meter = pDiveState->lifeData.depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 float surface_pressure_bar = pDiveState->lifeData.pressure_surface_bar;
897
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
382 static uint8_t sampleToggle = 0;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
383
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
384 if(simReplayActive) /* precondition: function is called once per second, sample rate is 2 seconds */
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
385 {
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
386 if(sampleToggle == 0)
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
387 {
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
388 sampleToggle = 1;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
389 sim_aim_depth_meter = (float)(*pReplayData++/100.0);
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
390 sim_descent_rate_meter_per_min = (sim_aim_depth_meter - depth_meter) * 30;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
391 }
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
392 else
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
393 {
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
394 sampleToggle = 0;
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
395 }
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
396 }
65772ddee88c Use dive profile as source for simulator:
ideenmodellierer
parents: 888
diff changeset
397
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 if(depth_meter < sim_aim_depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 depth_meter = depth_meter + sim_descent_rate_meter_per_min / 60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 if(depth_meter > sim_aim_depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 depth_meter = sim_aim_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 else if(depth_meter > sim_aim_depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 depth_meter -= pDiveState->diveSettings.ascentRate_meterperminute / 60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 if(depth_meter < sim_aim_depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 depth_meter = sim_aim_depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 176
diff changeset
411 if(sim_heed_decostops && depth_meter < actual_deco_stop)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 if(actual_deco_stop < (depth_meter + pDiveState->diveSettings.ascentRate_meterperminute / 60))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 depth_meter = actual_deco_stop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 depth_meter += pDiveState->diveSettings.ascentRate_meterperminute / 60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 return surface_pressure_bar + depth_meter / 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 }
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 * @brief Reduces deco time of deepest stop by one second
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 * @note called during fast simulation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 * @param SDiveState* pDiveState:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 */
300
5ca177d2df5d cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents: 233
diff changeset
433 static void sim_reduce_deco_time_one_second(SDiveState* pDiveState)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 SDecoinfo* pDecoinfo;
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
436 int8_t index = 0;
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
437
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
438
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 pDecoinfo = &pDiveState->decolistBuehlmann;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 pDecoinfo = &pDiveState->decolistVPM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 //Reduce deco time of deepest stop by one second
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
445 for(index = DECOINFO_STRUCT_MAX_STOPS -1 ;index >= 0; index--)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 {
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
447 if(pDecoinfo->output_stop_length_seconds[index] > 0)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 {
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
449 pDecoinfo->output_stop_length_seconds[index]--;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 }
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
453 /* update TTS */
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
454 if(pDecoinfo->output_time_to_surface_seconds)
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
455 {
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
456 pDecoinfo->output_time_to_surface_seconds--;
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
457 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 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
461 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462 uint8_t ptrGasChangeList = 0; // new hw 160704
888
07af9efd7c13 Dev bugfix: Consider decogas in planner independen from calculation setting:
Ideenmodellierer
parents: 830
diff changeset
463 uint8_t index = 0;
678
05cdd367dbd0 Bugfix: deco planner did not initialize properly
Jan Mulder <jan@jlmulder.nl>
parents: 629
diff changeset
464 for (int i = 0; i < 40; i++)
05cdd367dbd0 Bugfix: deco planner did not initialize properly
Jan Mulder <jan@jlmulder.nl>
parents: 629
diff changeset
465 gasChangeListDepthGas20x2[i] = 0;
05cdd367dbd0 Bugfix: deco planner did not initialize properly
Jan Mulder <jan@jlmulder.nl>
parents: 629
diff changeset
466
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 SDiveState * pDiveState = &stateSim;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 copyDiveSettingsToSim();
888
07af9efd7c13 Dev bugfix: Consider decogas in planner independen from calculation setting:
Ideenmodellierer
parents: 830
diff changeset
469
07af9efd7c13 Dev bugfix: Consider decogas in planner independen from calculation setting:
Ideenmodellierer
parents: 830
diff changeset
470 /* activate deco calculation for all deco gases */
07af9efd7c13 Dev bugfix: Consider decogas in planner independen from calculation setting:
Ideenmodellierer
parents: 830
diff changeset
471 for(index = 0; index < 1 + (2*NUM_GASES); index++)
07af9efd7c13 Dev bugfix: Consider decogas in planner independen from calculation setting:
Ideenmodellierer
parents: 830
diff changeset
472 {
07af9efd7c13 Dev bugfix: Consider decogas in planner independen from calculation setting:
Ideenmodellierer
parents: 830
diff changeset
473 if(pDiveState->diveSettings.gas[index].note.ub.deco)
07af9efd7c13 Dev bugfix: Consider decogas in planner independen from calculation setting:
Ideenmodellierer
parents: 830
diff changeset
474 {
07af9efd7c13 Dev bugfix: Consider decogas in planner independen from calculation setting:
Ideenmodellierer
parents: 830
diff changeset
475 pDiveState->diveSettings.gas[index].note.ub.decocalc = 1;
07af9efd7c13 Dev bugfix: Consider decogas in planner independen from calculation setting:
Ideenmodellierer
parents: 830
diff changeset
476 }
07af9efd7c13 Dev bugfix: Consider decogas in planner independen from calculation setting:
Ideenmodellierer
parents: 830
diff changeset
477 }
07af9efd7c13 Dev bugfix: Consider decogas in planner independen from calculation setting:
Ideenmodellierer
parents: 830
diff changeset
478
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 vpm_init(&pDiveState->vpm, pDiveState->diveSettings.vpm_conservatism, 0, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 //buehlmann_init();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 //timer_init();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 memset(&pDiveState->events,0, sizeof(SEvents));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 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
484 //Calc desaturation during intervall (with Air)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 setActualGasAir(&pDiveState->lifeData);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 if(intervall_time_minutes > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 decom_tissues_exposure(intervall_time_minutes * 60, &pDiveState->lifeData);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 decom_oxygen_calculate_cns_degrade(&pDiveState->lifeData.cns, intervall_time_minutes * 60);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 //Switch to first Gas
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493 setActualGasFirst(&pDiveState->lifeData);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 // new hw 160704
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 if(gasChangeListDepthGas20x2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 gasChangeListDepthGas20x2[ptrGasChangeList++] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 gasChangeListDepthGas20x2[ptrGasChangeList++] = pDiveState->lifeData.actualGas.GasIdInSettings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500 gasChangeListDepthGas20x2[0] =0; // depth zero
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 //Going down / descent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504 simulation_set_aim_depth(depth_meter);
790
3b5f9557c053 Fix bug introduced in 04b98a2, causing the deco planner to not show deco stops.
heinrichsweikamp
parents: 760
diff changeset
505 sim_aim_time_minutes = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 for(int i = 0; i < 60 * dive_time_minutes; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 simulation_UpdateLifeData(0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 check_warning2(pDiveState);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510 if(pDiveState->warnings.betterGas)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 setActualGas(&pDiveState->lifeData,actualBetterGasId(),pDiveState->lifeData.actualGas.setPoint_cbar);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 if(gasChangeListDepthGas20x2 && (pDiveState->diveSettings.diveMode == DIVEMODE_OC))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 gasChangeListDepthGas20x2[ptrGasChangeList++] = pDiveState->lifeData.depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 gasChangeListDepthGas20x2[ptrGasChangeList++] = actualBetterGasId();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 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
522
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523 // new hw 160704
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 if(gasChangeListDepthGas20x2 && (pDiveState->diveSettings.diveMode == DIVEMODE_OC))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 // change direction from better gas to deco gas
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 gasChangeListDepthGas20x2[ptrGasChangeList++] = 255;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 gasChangeListDepthGas20x2[ptrGasChangeList++] = 255;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530 // ascend (deco) gases
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 for(int i=1; i<=5;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 {
830
b7d93ff6b3b2 Added selection if an active gas shall be used for deco calculation or not:
Ideenmodellierer
parents: 813
diff changeset
533 if((pDiveState->diveSettings.decogaslist[i].change_during_ascent_depth_meter_otherwise_zero == 0)
b7d93ff6b3b2 Added selection if an active gas shall be used for deco calculation or not:
Ideenmodellierer
parents: 813
diff changeset
534 || (pDiveState->diveSettings.gas[pDiveState->diveSettings.decogaslist[i].GasIdInSettings].note.ub.decocalc == 0))
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 gasChangeListDepthGas20x2[ptrGasChangeList++] = pDiveState->diveSettings.decogaslist[i].change_during_ascent_depth_meter_otherwise_zero;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 gasChangeListDepthGas20x2[ptrGasChangeList++] = pDiveState->diveSettings.decogaslist[i].GasIdInSettings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 gasChangeListDepthGas20x2[0] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 // deco and ascend calc
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 /* this does modify the cns now 11.06.2015 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 buehlmann_calc_deco(&pDiveState->lifeData,&pDiveState->diveSettings,&pDiveState->decolistBuehlmann);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 pDiveState->lifeData.cns += buehlmann_get_gCNS();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548 return &pDiveState->decolistBuehlmann;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552 /* this does modify the cns now 11.06.2015 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553 vpm_calc(&pDiveState->lifeData,&pDiveState->diveSettings,&pDiveState->vpm,&pDiveState->decolistVPM, DECOSTOPS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 pDiveState->lifeData.cns += vpm_get_CNS();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555 return &pDiveState->decolistVPM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 176
diff changeset
559 static float sGChelper_bar(uint16_t depth_meter)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 SDiveState * pDiveState = &stateSim;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562 float ambient, surface, density, meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 surface = pDiveState->lifeData.pressure_surface_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 if(!depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 return surface;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 density = ((float)( 100 + settingsGetPointer()->salinity)) / 100.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570 meter = depth_meter * (0.09807f * density);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571 ambient = (meter + surface);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 return ambient;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579 * @brief simulation_helper_change_points
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581 * @param
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584 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
585 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586 uint8_t ptrDecoInfo = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 uint16_t actualDepthPoint = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 uint16_t nextDepthPoint = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 uint8_t actualConsumGasId = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 uint8_t nextGasChangeMeter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 uint8_t ptrChangeList = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 float timeThis = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 float timeSummary = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595 float sim_descent_rate_meter_per_min_local = 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596 float sim_ascent_rate_meter_per_min_local = 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598 SDiveState * pDiveState = &stateSim;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600 uint8_t depthDecoNext, depthLast, depthSecond, depthInc;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604 sim_descent_rate_meter_per_min_local = sim_descent_rate_meter_per_min; // const float
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 sim_ascent_rate_meter_per_min_local = pDiveState->diveSettings.ascentRate_meterperminute;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609 sim_descent_rate_meter_per_min_local = sim_descent_rate_meter_per_min; // const float
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610 sim_ascent_rate_meter_per_min_local = 10;// fix in vpm_calc_deco();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613 outputSummary->descentRateMeterPerMinute = sim_descent_rate_meter_per_min_local;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614 outputSummary->ascentRateMeterPerMinute = sim_ascent_rate_meter_per_min_local;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 // bottom gas ppO2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617 if(gasChangeListDepthGas20x2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619 nextGasChangeMeter = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 actualConsumGasId = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621 nextGasChangeMeter = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623 while(actualDepthPoint < depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625 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
626 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627 nextDepthPoint = nextGasChangeMeter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631 nextDepthPoint = depth_meter;
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 if(actualConsumGasId > 5) // safety first
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635 actualConsumGasId = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 actualDepthPoint = nextDepthPoint;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639 if(actualDepthPoint != depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641 actualConsumGasId = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 nextGasChangeMeter = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648 actualConsumGasId = pDiveState->lifeData.actualGas.GasIdInSettings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649 nextGasChangeMeter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 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
652
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654 // going down
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655 actualDepthPoint = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656 nextDepthPoint = depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658 timeThis = ((float)(nextDepthPoint - actualDepthPoint)) / sim_descent_rate_meter_per_min_local;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659 timeSummary += timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 outputSummary->timeToBottom = (uint16_t)timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 // bottom time
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663 timeThis = ((float)dive_time_minutes) - timeSummary;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 timeSummary += timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 outputSummary->timeAtBottom = (uint16_t)timeSummary;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 // ascend to first deco stop
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 actualDepthPoint = depth_meter; // that is where we are
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670 timeThis = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 if(!decoInfoInput->output_stop_length_seconds[0]) // NDL dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 depthLast = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 ptrDecoInfo = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 depthDecoNext = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680 // prepare deco stop list
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 depthLast = (uint8_t)(stateUsed->diveSettings.last_stop_depth_bar * 10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 depthSecond = (uint8_t)(stateUsed->diveSettings.input_second_to_last_stop_depth_bar * 10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 depthInc = (uint8_t)(stateUsed->diveSettings.input_next_stop_increment_depth_bar * 10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 for(ptrDecoInfo=DECOINFO_STRUCT_MAX_STOPS-1; ptrDecoInfo>0; ptrDecoInfo--)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 if(decoInfoInput->output_stop_length_seconds[ptrDecoInfo]) break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 if(ptrDecoInfo == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 depthDecoNext = depthLast;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693 depthDecoNext = depthSecond + (( ptrDecoInfo - 1 )* depthInc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696 nextDepthPoint = depthDecoNext;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 if(actualDepthPoint > nextDepthPoint)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 // flip signs! It's going up
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 timeThis = ((float)(actualDepthPoint - nextDepthPoint)) / sim_ascent_rate_meter_per_min_local;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 actualDepthPoint = nextDepthPoint; // that is where we are
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 timeSummary += timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 outputSummary->timeToFirstStop = (uint16_t)timeSummary;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705 outputSummary->depthMeterFirstStop = actualDepthPoint;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
707 if(decoInfoInput->output_time_to_surface_seconds)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708 {
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
709 outputSummary->timeToSurface = outputSummary->timeAtBottom + (decoInfoInput->output_time_to_surface_seconds / 60);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 }
901
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
711 else
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
712 {
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
713 outputSummary->timeToSurface = outputSummary->timeToFirstStop;
e4e9acfde839 Bugfix simulator/planer:
Ideenmodellierer
parents: 897
diff changeset
714 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720 * @brief simulation_gas_consumption
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 * @note called by openEdit_PlanResult() in tMenuEditPlanner.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 * @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
724 * @param outputConsumptionList list from 1 to 5 for gas 1 to 5
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 * @param depth_meter for descend
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 * @param dive_time_minutes for descend and bottom time
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727 * @param the calculated deco list
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 * @param gasConsumTravelInput: how many l/min for all but deco stops
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 * @param gasConsumDecoInput: how many l/min for deco stops only
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 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
734 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735 uint8_t ptrDecoInfo = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736 uint8_t ptrChangeList = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737 uint8_t actualConsumGasId = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738 uint8_t nextGasChangeMeter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 uint16_t actualDepthPoint = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740 uint16_t nextDepthPoint = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 uint16_t inBetweenDepthPoint = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 float timeThis = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743 float consumThis = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 float timeSummary = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 float outputConsumptionTempFloat[6];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746 float sim_descent_rate_meter_per_min_local = 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747 float sim_ascent_rate_meter_per_min_local = 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749 SDiveState * pDiveState = &stateSim;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750
51
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
751 uint8_t depthDecoNext = 0;
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
752 uint8_t depthLast = 0;
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
753 uint8_t depthSecond = 0;
8f8ea3a32e82 Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents: 38
diff changeset
754 uint8_t depthInc = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 for(int i = 1; i < 6; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757 outputConsumptionTempFloat[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 if(gasChangeListDepthGas20x2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 nextGasChangeMeter = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762 actualConsumGasId = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 nextGasChangeMeter = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 actualConsumGasId = pDiveState->lifeData.actualGas.GasIdInSettings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 nextGasChangeMeter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 sim_descent_rate_meter_per_min_local = sim_descent_rate_meter_per_min; // const float
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774 sim_ascent_rate_meter_per_min_local = pDiveState->diveSettings.ascentRate_meterperminute;
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 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 sim_descent_rate_meter_per_min_local = sim_descent_rate_meter_per_min; // const float
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779 sim_ascent_rate_meter_per_min_local = 10;// fix in vpm_calc_deco();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782 // while((nextGasChangeMeter < depth_meter) && (actualDepthPoint < depth_meter))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783 while(actualDepthPoint < depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 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
786 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787 nextDepthPoint = nextGasChangeMeter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791 nextDepthPoint = depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 if(actualConsumGasId > 5) // safety first
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 actualConsumGasId = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797 timeThis = ((float)(nextDepthPoint - actualDepthPoint)) / sim_descent_rate_meter_per_min_local;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 if(actualDepthPoint) // not if on surface
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800 consumThis = ((float)gasConsumTravelInput) * sGChelper_bar(actualDepthPoint) * timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802 consumThis += ((float)gasConsumTravelInput) * sGChelper_bar(nextDepthPoint -actualDepthPoint) * timeThis / 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803 outputConsumptionTempFloat[actualConsumGasId] += consumThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 timeSummary += timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806 actualDepthPoint = nextDepthPoint;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808 if(actualDepthPoint != depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810 actualConsumGasId = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 nextGasChangeMeter = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815 // bottom Time
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 timeThis = ((float)dive_time_minutes) - timeSummary;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 if(timeThis > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820 consumThis = ((float)gasConsumTravelInput) * sGChelper_bar(depth_meter) * timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821 outputConsumptionTempFloat[actualConsumGasId] += consumThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 // ascend with deco stops prepare
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825 if(gasChangeListDepthGas20x2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 ptrChangeList++;// gasChangeListDepthGas20x2[ptrChangeList++]; // should be the 255
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828 nextGasChangeMeter = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 nextGasChangeMeter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836 if(!decoInfoInput->output_stop_length_seconds[0]) // NDL dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 depthLast = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 ptrDecoInfo = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 // prepare deco stop list
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844 depthLast = (uint8_t)(stateUsed->diveSettings.last_stop_depth_bar * 10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845 depthSecond = (uint8_t)(stateUsed->diveSettings.input_second_to_last_stop_depth_bar * 10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 depthInc = (uint8_t)(stateUsed->diveSettings.input_next_stop_increment_depth_bar * 10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 for(ptrDecoInfo=DECOINFO_STRUCT_MAX_STOPS-1; ptrDecoInfo>0; ptrDecoInfo--)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 if(decoInfoInput->output_stop_length_seconds[ptrDecoInfo]) break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 actualDepthPoint = depth_meter; // that is where we are
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854 // ascend with deco stops
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855 while(actualDepthPoint)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857 if(ptrDecoInfo == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859 depthDecoNext = depthLast;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862 depthDecoNext = depthSecond + (( ptrDecoInfo - 1 )* depthInc);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864 if(nextGasChangeMeter && (nextGasChangeMeter > depthDecoNext))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866 nextDepthPoint = nextGasChangeMeter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
868 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870 nextDepthPoint = depthDecoNext;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
871 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
872
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
873 if(actualConsumGasId > 5) // safety first
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874 actualConsumGasId = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
875
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
876 if(actualDepthPoint > nextDepthPoint)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
877 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
878 // flip signs! It's going up
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
879 timeThis = ((float)(actualDepthPoint - nextDepthPoint)) / sim_ascent_rate_meter_per_min_local;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
880 inBetweenDepthPoint = nextDepthPoint + ((actualDepthPoint - nextDepthPoint)/2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
881 consumThis = ((float)gasConsumDecoInput) * sGChelper_bar(inBetweenDepthPoint) * timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
882 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
883 if(nextDepthPoint)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
884 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
885 consumThis = ((float)gasConsumDecoInput) * sGChelper_bar(nextDepthPoint) * timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
886 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889 consumThis = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891 consumThis += ((float)gasConsumDecoInput) * sGChelper_bar(actualDepthPoint - nextDepthPoint) * timeThis / 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893 outputConsumptionTempFloat[actualConsumGasId] += consumThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896 if(nextGasChangeMeter && (nextDepthPoint == nextGasChangeMeter))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
897 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
898 actualConsumGasId = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
899 nextGasChangeMeter = gasChangeListDepthGas20x2[ptrChangeList++];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
900 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
901
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
902 if(actualConsumGasId > 5) // safety first
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
903 actualConsumGasId = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
904
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
905 if(nextDepthPoint && (nextDepthPoint == depthDecoNext))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
906 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
907 if(decoInfoInput->output_stop_length_seconds[ptrDecoInfo])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909 timeThis = ((float)(decoInfoInput->output_stop_length_seconds[ptrDecoInfo])) / 60.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910 consumThis = ((float)gasConsumDecoInput) * sGChelper_bar(nextDepthPoint) * timeThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911 outputConsumptionTempFloat[actualConsumGasId] += consumThis;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
912 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913 if(ptrDecoInfo != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
915 ptrDecoInfo--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
916 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
917 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919 depthLast = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922 actualDepthPoint = nextDepthPoint;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
925 // copy and return
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
926 for(int i = 1; i < 6; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
927 outputConsumptionList[i] = (uint16_t)(outputConsumptionTempFloat[i]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
928 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
929
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
930 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
931 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
932 * @brief Simulator control during simulated dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
933 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
934 * @note called by user via tHomeDiveMenuControl()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
935 * @param void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
936 * @return void
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
937 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
938
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
939
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
940 void Sim_Descend (void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
941 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
942 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
943 if(simulation_get_aim_depth() < 200)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
944 simulation_set_aim_depth(simulation_get_aim_depth() + 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
945 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
946
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
947
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
948 void Sim_Ascend (void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
949 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
950 if(simulation_get_aim_depth() > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
951 simulation_set_aim_depth(simulation_get_aim_depth() - 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
952 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
953
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
954
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
955 void Sim_Divetime (void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
956 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
957 simulation_add_time(5);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
958 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
959
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
960
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
961 void Sim_Quit (void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
962 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
963 if(stateSimGetPointer()->lifeData.counterSecondsShallowDepth)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
964 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
965 simulation_exit();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
966 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
967 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
968
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
969 if(simulation_get_aim_depth() > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
970 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
971 simulation_set_aim_depth(0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
972 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
973 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
974 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
975 stateSimGetPointerWrite()->lifeData.depth_meter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
976 if(stateSimGetPointer()->diveSettings.diveMode == DIVEMODE_Apnea)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
977 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
978 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
979 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
980 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
981 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
982 stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = settingsGetPointer()->timeoutDiveReachedZeroDepth - 15;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
983 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
984 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
985 }
760
21949c88da90 Quit simualted dives after the dive time set in the SIM tab.
heinrichsweikamp
parents: 748
diff changeset
986
629
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
987 void Sim_IncreasePPO(uint8_t sensorIdx)
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
988 {
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
989 if((sensorIdx < NUM_OF_SENSORS) && (simSensmVOffset[sensorIdx] + SIM_PPO2_STEP < 100.0) && ((stateUsed->diveSettings.ppo2sensors_deactivated & (1 << sensorIdx)) == 0))
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
990 {
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
991 simSensmVOffset[sensorIdx] += SIM_PPO2_STEP;
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
992 }
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
993 }
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
994 void Sim_DecreasePPO(uint8_t sensorIdx)
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
995 {
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
996 if((sensorIdx < NUM_OF_SENSORS) && (simSensmVOffset[sensorIdx] - SIM_PPO2_STEP >= -100.0))
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
997 {
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
998 simSensmVOffset[sensorIdx] -= SIM_PPO2_STEP;
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
999 }
55a9aa740f13 Added functionality to add ppo2 mV offset:
Ideenmodellierer
parents: 548
diff changeset
1000 }