annotate Discovery/Src/data_central.c @ 250:822416168585 bm-2

Buelmann: new implementation for ceiling Since my first functional fix in the ceiling computation in commit ceecabfddb57, I noticed that the computation used a linear search, that became rather computational expensive after that commit. The simple question is: why not a binary search? So, this commit implements the binary search. But there is a long story attached to this. Comparing ceiling results from hwOS and this OSTC4 code were very different. Basically, the original OSTC4 algorithm computed the ceiling using the same GFlow to GFhigh slope, in such a way, that the ceiling was in sync with the presented deco stops, where the hwOS code presents a GFhigh based ceiling. This said, it is more logical when the OSTC4 and hwOS code give similar results. This new recursive algorithm gives very similar results for the ceiling compared to hwOS. To be complete here, the Buelmann ceiling is the depth to which you can ascend, so that the leading tissue reaches GFhigh. This also explains why the deepest deco stop is normally deeper than the ceiling (unless one dives with GF like 80/80). The code implemented here is rather straightforward recursion. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Thu, 11 Apr 2019 17:48:48 +0200
parents 2bb1db22b5f5
children 2e58a4094770
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 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @copyright heinrichs weikamp
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @file data_central.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 10-November-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @version V1.0.2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * @since 10-Nov-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * @brief All the data EXCEPT
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * - settings (settings.c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 * feste Werte, die nur an der Oberfl�che ge�ndert werden
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 * - dataIn and dataOut (data_exchange.h and data_exchange_main.c)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 * Austausch mit Small CPU
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 * @bug
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 * @warning
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 ##### SDiveState Real and Sim #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 [..] SDiveSettings
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 copy of parts of Settings that are necessary during the dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 and could be modified during the dive without post dive changes.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 [..] SLifeData
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 written in DataEX_copy_to_LifeData();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 block 1 "lifedata" set by SmallCPU in stateReal
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 block 2 "actualGas" set by main CPU from user input and send to Small CPU
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 block 3 "calculated data" set by main CPU based on "lifedata"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 [..] SVpm
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 [..] SEvents
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 [..] SDecoinfo
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 [..] mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 set by SmallCPU in stateReal, can be surface, dive, ...
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 [..] data_old__lost_connection_to_slave
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 set by DataEX_copy_to_LifeData();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 ##### SDiveState Deco #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 [..] kjbkldafj�lasdfjasdf
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 ##### decoLock #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 [..] The handler that synchronizes the data between IRQ copy and main deco loop
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 * <h2><center>&copy; COPYRIGHT(c) 2015 heinrichs weikamp</center></h2>
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 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 #include <string.h>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 #include "data_central.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 #include "calc_crush.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 #include "decom.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 #include "settings.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 #include "data_exchange_main.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 #include "ostc.h" // for button adjust on hw testboard 1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 #include "tCCR.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 #include "crcmodel.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 149
diff changeset
74 static SDiveState stateReal = { 0 };
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 SDiveState stateSim = { 0 };
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 SDiveState stateDeco = { 0 };
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 SDevice stateDevice =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 /* max is 0x7FFFFFFF, min is 0x80000000 but also defined in stdint.h :-) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 /* count, use 0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 .batteryChargeCompleteCycles.value_int32 = 0,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 .batteryChargeCycles.value_int32 = 0,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 .diveCycles.value_int32 = 0,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 .hoursOfOperation.value_int32 = 0,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 /* max values, use min. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 .temperatureMaximum.value_int32 = INT32_MIN,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 .depthMaximum.value_int32 = INT32_MIN,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 /* min values, use max. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 .temperatureMinimum.value_int32 = INT32_MAX,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 .voltageMinimum.value_int32 = INT32_MAX,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 };
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 SVpmRepetitiveData stateVPM =
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 .repetitive_variables_not_valid = 1,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 .is_data_from_RTE_CPU = 0,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 };
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 const SDiveState * stateUsed = &stateReal;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 void set_stateUsedToReal(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 stateUsed = &stateReal;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 void set_stateUsedToSim(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 stateUsed = &stateSim;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 _Bool is_stateUsedSetToSim(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 {
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 149
diff changeset
118 return stateUsed == &stateSim;
38
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 const SDiveState * stateRealGetPointer(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 return &stateReal;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 SDiveState * stateRealGetPointerWrite(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 return &stateReal;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 const SDiveState * stateSimGetPointer(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 return &stateSim;
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 SDiveState * stateSimGetPointerWrite(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 return &stateSim;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 const SDevice * stateDeviceGetPointer(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 return &stateDevice;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 SDevice * stateDeviceGetPointerWrite(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 return &stateDevice;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 const SVpmRepetitiveData * stateVpmRepetitiveDataGetPointer(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 return &stateVPM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 SVpmRepetitiveData * stateVpmRepetitiveDataGetPointerWrite(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 return &stateVPM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 if(ticksstart <= ticksnow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 return ticksnow - ticksstart;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 return 0xFFFFFFFF - ticksstart + ticksnow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 uint8_t decoLock = DECO_CALC_undefined;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 int ascent_rate_meter_per_min = 12;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 int descent_rate_meter_per_min = 20;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 int max_depth = 70;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 int bottom_time = 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 _Bool vpm_crush(SDiveState* pDiveState);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 void setSimulationValues(int _ascent_rate_meter_per_min, int _descent_rate_meter_per_min, int _max_depth, int _bottom_time )
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 ascent_rate_meter_per_min = _ascent_rate_meter_per_min;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 descent_rate_meter_per_min = _descent_rate_meter_per_min;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 max_depth = _max_depth;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 bottom_time = _bottom_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 int current_second(void) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 return HAL_GetTick() / 1000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 // printf("milliseconds: %lld\n", milliseconds);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 //return milliseconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 #define OXY_ONE_SIXTIETH_PART 0.0166667f
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 /*void oxygen_calculate_cns(float* oxygen_cns, float pressure_oxygen_real)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 int cns_no_range = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 _Bool not_found = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 //for the cns calculation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 const float cns_ppo2_ranges[60][2] = { {0.50, 0.00}, {0.60, 0.14}, {0.64, 0.15}, {0.66, 0.16}, {0.68, 0.17}, {0.70, 0.18},
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 {0.74, 0.19}, {0.76, 0.20}, {0.78, 0.21}, {0.80, 0.22}, {0.82, 0.23}, {0.84, 0.24},
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 {0.86, 0.25}, {0.88, 0.26}, {0.90, 0.28}, {0.92, 0.29}, {0.94, 0.30}, {0.96, 0.31},
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 {0.98, 0.32}, {1.00, 0.33}, {1.02, 0.35}, {1.04, 0.36}, {1.06, 0.38}, {1.08, 0.40},
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 {1.10, 0.42}, {1.12, 0.43}, {1.14, 0.43}, {1.16, 0.44}, {1.18, 0.46}, {1.20, 0.47},
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 {1.22, 0.48}, {1.24, 0.51}, {1.26, 0.52}, {1.28, 0.54}, {1.30, 0.56}, {1.32, 0.57},
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 {1.34, 0.60}, {1.36, 0.62}, {1.38, 0.63}, {1.40, 0.65}, {1.42, 0.68}, {1.44, 0.71},
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 {1.46, 0.74}, {1.48, 0.78}, {1.50, 0.83}, {1.52, 0.93}, {1.54, 1.04}, {1.56, 1.19},
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 {1.58, 1.47}, {1.60, 2.22}, {1.62, 5.00}, {1.65, 6.25}, {1.67, 7.69}, {1.70, 10.0},
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 {1.72,12.50}, {1.74,20.00}, {1.77,25.00}, {1.79,31.25}, {1.80,50.00}, {1.82,100.0}};
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 //find the correct cns range for the corresponding ppo2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 cns_no_range = 58;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 while (cns_no_range && not_found)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 if (pressure_oxygen_real > cns_ppo2_ranges[cns_no_range][0])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 cns_no_range++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 not_found = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 cns_no_range--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 //calculate cns for the actual ppo2 for 1 second
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 *oxygen_cns += OXY_ONE_SIXTIETH_PART * cns_ppo2_ranges[cns_no_range][1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 }*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 uint8_t calc_MOD(uint8_t gasId)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 int16_t oxygen, maxppO2, result;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 SSettings *pSettings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 pSettings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 oxygen = (int16_t)(pSettings->gas[gasId].oxygen_percentage);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 if(pSettings->gas[gasId].note.ub.deco > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 maxppO2 =(int16_t)(pSettings->ppO2_max_deco);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 maxppO2 =(int16_t)(pSettings->ppO2_max_std);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 result = 10 * maxppO2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 result /= oxygen;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 result -= 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 if(result < 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 if(result > 255)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 return 255;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 return result;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 uint8_t calc_MinOD(uint8_t gasId)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 int16_t oxygen, minppO2, result;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 SSettings *pSettings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 pSettings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 oxygen = (int16_t)(pSettings->gas[gasId].oxygen_percentage);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 minppO2 =(int16_t)(pSettings->ppO2_min);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 result = 10 * minppO2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 result += 9;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 result /= oxygen;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 result -= 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 if(result < 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 if(result > 255)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 return 255;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 return result;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 float calc_ppO2(float input_ambient_pressure_bar, SGas* pGas)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 float percent_N2 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 float percent_He = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 float percent_O2 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 decom_get_inert_gases(input_ambient_pressure_bar, pGas, &percent_N2, &percent_He);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 percent_O2 = 1 - percent_N2 - percent_He;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 return (input_ambient_pressure_bar - WATER_VAPOUR_PRESSURE) * percent_O2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 }*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 float get_ambiant_pressure_simulation(long dive_time_seconds, float surface_pressure_bar )
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 static
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 long descent_time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 float depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 descent_time = 60 * max_depth / descent_rate_meter_per_min;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 if(dive_time_seconds <= descent_time)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 depth_meter = ((float)(dive_time_seconds * descent_rate_meter_per_min)) / 60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 return surface_pressure_bar + depth_meter / 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 //else if(dive_time_seconds <= (descent_time + bottom_time * 60))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 return surface_pressure_bar + max_depth / 10;
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 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 void UpdateLifeDataTest(SDiveState * pDiveState)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 static int last_second = -1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 int now = current_second();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 if(last_second == now)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 last_second = now;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 pDiveState->lifeData.dive_time_seconds += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 pDiveState->lifeData.pressure_ambient_bar = get_ambiant_pressure_simulation(pDiveState->lifeData.dive_time_seconds,pDiveState->lifeData.pressure_surface_bar);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 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
330 if(pDiveState->lifeData.max_depth_meter < pDiveState->lifeData.depth_meter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 pDiveState->lifeData.max_depth_meter = pDiveState->lifeData.depth_meter;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 decom_tissues_exposure(1, &pDiveState->lifeData);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 pDiveState->lifeData.ppO2 = decom_calc_ppO2( pDiveState->lifeData.pressure_ambient_bar, &pDiveState->lifeData.actualGas);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 decom_oxygen_calculate_cns(& pDiveState->lifeData.cns, pDiveState->lifeData.ppO2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 vpm_crush(pDiveState);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 _Bool vpm_crush(SDiveState* pDiveState)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 int i = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 static float starting_ambient_pressure = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 static float ending_ambient_pressure = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 static float time_calc_begin = -1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 static float initial_helium_pressure[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 static float initial_nitrogen_pressure[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 ending_ambient_pressure = pDiveState->lifeData.pressure_ambient_bar * 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 if((pDiveState->lifeData.dive_time_seconds <= 4) || (starting_ambient_pressure >= ending_ambient_pressure))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 time_calc_begin = pDiveState->lifeData.dive_time_seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 starting_ambient_pressure = pDiveState->lifeData.pressure_ambient_bar * 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 for( i = 0; i < 16; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 initial_helium_pressure[i] = pDiveState->lifeData.tissue_helium_bar[i] * 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 initial_nitrogen_pressure[i] = pDiveState->lifeData.tissue_nitrogen_bar[i] * 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 return false;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 if(pDiveState->lifeData.dive_time_seconds - time_calc_begin >= 4)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 if(ending_ambient_pressure > starting_ambient_pressure + 0.5f)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 float rate = (ending_ambient_pressure - starting_ambient_pressure) * 60 / 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 calc_crushing_pressure(&pDiveState->lifeData, &pDiveState->vpm, initial_helium_pressure, initial_nitrogen_pressure, starting_ambient_pressure, rate);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 time_calc_begin = pDiveState->lifeData.dive_time_seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 starting_ambient_pressure = pDiveState->lifeData.pressure_ambient_bar * 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 for( i = 0; i < 16; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 initial_helium_pressure[i] = pDiveState->lifeData.tissue_helium_bar[i] * 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 initial_nitrogen_pressure[i] = pDiveState->lifeData.tissue_nitrogen_bar[i] * 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 return true;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 return false;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 };
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 void createDiveSettings(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 SSettings* pSettings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 setActualGasFirst(&stateReal.lifeData);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 stateReal.diveSettings.compassHeading = pSettings->compassBearing;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 stateReal.diveSettings.ascentRate_meterperminute = 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 stateReal.diveSettings.diveMode = pSettings->dive_mode;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 stateReal.diveSettings.CCR_Mode = pSettings->CCR_Mode;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 if(stateReal.diveSettings.diveMode == DIVEMODE_CCR)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 stateReal.diveSettings.ccrOption = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 stateReal.diveSettings.ccrOption = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 memcpy(stateReal.diveSettings.gas, pSettings->gas,sizeof(pSettings->gas));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 memcpy(stateReal.diveSettings.setpoint, pSettings->setpoint,sizeof(pSettings->setpoint));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 stateReal.diveSettings.gf_high = pSettings->GF_high;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 stateReal.diveSettings.gf_low = pSettings->GF_low;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 stateReal.diveSettings.input_next_stop_increment_depth_bar = ((float)pSettings->stop_increment_depth_meter) / 10.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 stateReal.diveSettings.last_stop_depth_bar = ((float)pSettings->last_stop_depth_meter) / 10.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 stateReal.diveSettings.vpm_conservatism = pSettings->VPM_conservatism.ub.standard;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 stateReal.diveSettings.deco_type.uw = pSettings->deco_type.uw;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 stateReal.diveSettings.fallbackOption = pSettings->fallbackToFixedSetpoint;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 stateReal.diveSettings.ppo2sensors_deactivated = pSettings->ppo2sensors_deactivated;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 stateReal.diveSettings.future_TTS_minutes = pSettings->future_TTS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 decom_CreateGasChangeList(&stateReal.diveSettings, &stateReal.lifeData); // decogaslist
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 stateReal.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
413
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 /* for safety */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 stateReal.diveSettings.input_second_to_last_stop_depth_bar = stateReal.diveSettings.last_stop_depth_bar + stateReal.diveSettings.input_next_stop_increment_depth_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 /* and the proper calc */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 for(int i = 1; i <10; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 if(stateReal.diveSettings.input_next_stop_increment_depth_bar * i > stateReal.diveSettings.last_stop_depth_bar)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 stateReal.diveSettings.input_second_to_last_stop_depth_bar = stateReal.diveSettings.input_next_stop_increment_depth_bar * i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 break;
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 void copyDiveSettingsToSim(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 memcpy(&stateSim, &stateReal, sizeof(stateReal));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 void copyVpmRepetetiveDataToSim(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 SDiveState * pSimData = stateSimGetPointerWrite();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 const SVpmRepetitiveData * pVpmData = stateVpmRepetitiveDataGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 if(pVpmData->is_data_from_RTE_CPU)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 for(int i=0; i<16;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 pSimData->vpm.adjusted_critical_radius_he[i] = pVpmData->adjusted_critical_radius_he[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 pSimData->vpm.adjusted_critical_radius_n2[i] = pVpmData->adjusted_critical_radius_n2[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 pSimData->vpm.adjusted_crushing_pressure_he[i] = pVpmData->adjusted_crushing_pressure_he[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 pSimData->vpm.adjusted_crushing_pressure_n2[i] = pVpmData->adjusted_crushing_pressure_n2[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 pSimData->vpm.initial_allowable_gradient_he[i] = pVpmData->initial_allowable_gradient_he[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 pSimData->vpm.initial_allowable_gradient_n2[i] = pVpmData->initial_allowable_gradient_n2[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 pSimData->vpm.max_actual_gradient[i] = pVpmData->max_actual_gradient[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 pSimData->vpm.repetitive_variables_not_valid = pVpmData->repetitive_variables_not_valid;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 void updateSetpointStateUsed(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 SLifeData *pLifeDataWrite;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 if(is_stateUsedSetToSim())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 pLifeDataWrite = &stateSimGetPointerWrite()->lifeData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 pLifeDataWrite = &stateRealGetPointerWrite()->lifeData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 if(stateUsed->diveSettings.diveMode != DIVEMODE_CCR)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 pLifeDataWrite->actualGas.setPoint_cbar = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 pLifeDataWrite->ppO2 = decom_calc_ppO2(stateUsed->lifeData.pressure_ambient_bar, &stateUsed->lifeData.actualGas);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 if(stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 pLifeDataWrite->actualGas.setPoint_cbar = get_ppO2SensorWeightedResult_cbar();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 if((stateUsed->lifeData.pressure_ambient_bar * 100) < stateUsed->lifeData.actualGas.setPoint_cbar)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 pLifeDataWrite->ppO2 = stateUsed->lifeData.pressure_ambient_bar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 pLifeDataWrite->ppO2 = ((float)stateUsed->lifeData.actualGas.setPoint_cbar) / 100;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 void fallbackToFixedSetpoints(SLifeData *lifeData)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 {
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 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 void setActualGasFirst(SLifeData *lifeData)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 SSettings* pSettings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 uint8_t start = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 uint8_t gasId = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 uint8_t setpoint_cbar = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 if(pSettings->dive_mode == DIVEMODE_CCR)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 setpoint_cbar = pSettings->setpoint[1].setpoint_cbar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504 start = NUM_OFFSET_DILUENT+1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 setpoint_cbar = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 start = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 gasId = start;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 for(int i=start;i<=NUM_GASES+start;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 if(pSettings->gas[i].note.ub.first)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 gasId = i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 break;
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 setActualGas(lifeData, gasId, setpoint_cbar);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 void setActualGasAir(SLifeData *lifeData)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 uint8_t nitrogen;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 nitrogen = 79;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 lifeData->actualGas.GasIdInSettings = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529 lifeData->actualGas.nitrogen_percentage = nitrogen;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530 lifeData->actualGas.helium_percentage =0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 lifeData->actualGas.setPoint_cbar = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 void setActualGas(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538 SSettings* pSettings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 uint8_t nitrogen;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541 nitrogen = 100;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 nitrogen -= pSettings->gas[gasId].oxygen_percentage;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 nitrogen -= pSettings->gas[gasId].helium_percentage;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 lifeData->actualGas.GasIdInSettings = gasId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 lifeData->actualGas.nitrogen_percentage = nitrogen;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 lifeData->actualGas.helium_percentage = pSettings->gas[gasId].helium_percentage;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548 lifeData->actualGas.setPoint_cbar = setpoint_cbar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551 if((pSettings->dive_mode == DIVEMODE_CCR) && (gasId > NUM_OFFSET_DILUENT))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552 lifeData->lastDiluent_GasIdInSettings = gasId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556 void setActualGas_DM(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558 //Real dive => Set events for logbook
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559 if(stateUsed == stateRealGetPointer())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 SDiveState * pStateUsed;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562 pStateUsed = stateRealGetPointerWrite();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 if(stateUsed->diveSettings.ccrOption && gasId < 6)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 if(lifeData->actualGas.GasIdInSettings != gasId)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 SSettings* pSettings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 pStateUsed->events.bailout = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570 pStateUsed->events.info_bailoutO2 = pSettings->gas[gasId].oxygen_percentage;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571 pStateUsed->events.info_bailoutHe = pSettings->gas[gasId].helium_percentage;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576 if(lifeData->actualGas.GasIdInSettings != gasId)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 pStateUsed->events.gasChange = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579 pStateUsed->events.info_GasChange = gasId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581 if( lifeData->actualGas.setPoint_cbar != setpoint_cbar)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 // setPoint_cbar = 255 -> change to sensor mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584 pStateUsed->events.setpointChange = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 pStateUsed->events.info_SetpointChange = setpoint_cbar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 setActualGas(lifeData, gasId, setpoint_cbar);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592 void setActualGas_ExtraGas(SLifeData *lifeData, uint8_t oxygen, uint8_t helium, uint8_t setpoint_cbar)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 uint8_t nitrogen;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596 nitrogen = 100;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597 nitrogen -= oxygen;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598 nitrogen -= helium;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600 //Real dive => Set events for logbook
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601 if(stateUsed == stateRealGetPointer())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603 SDiveState * pStateUsed;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604 pStateUsed = stateRealGetPointerWrite();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 if((lifeData->actualGas.nitrogen_percentage != nitrogen) || (lifeData->actualGas.helium_percentage != helium))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 pStateUsed->events.manuelGasSet = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608 pStateUsed->events.info_manuelGasSetHe = helium;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609 pStateUsed->events.info_manuelGasSetO2 = oxygen;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611 if( lifeData->actualGas.setPoint_cbar != setpoint_cbar)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613 pStateUsed->events.setpointChange = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614 pStateUsed->events.info_SetpointChange = setpoint_cbar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617 lifeData->actualGas.GasIdInSettings = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 lifeData->actualGas.nitrogen_percentage = nitrogen;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619 lifeData->actualGas.helium_percentage = helium;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 lifeData->actualGas.setPoint_cbar = setpoint_cbar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625 void setButtonResponsiveness(uint8_t *ButtonSensitivyList)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627 SDataReceiveFromMaster *pDataOut = dataOutGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 for(int i=0; i<4; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631 pDataOut->data.buttonResponsiveness[i] = settingsHelperButtonSens_translate_percentage_to_hwOS_values(ButtonSensitivyList[i]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633 pDataOut->setButtonSensitivityNow = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 void setDate(RTC_DateTypeDef Sdate)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639 SDataReceiveFromMaster *pDataOut = dataOutGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641 pDataOut->data.newDate = Sdate;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 pDataOut->setDateNow = 1;
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 void setTime(RTC_TimeTypeDef Stime)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648 SDataReceiveFromMaster *pDataOut = dataOutGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650 pDataOut->data.newTime = Stime;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 pDataOut->setTimeNow = 1;
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655 void setBatteryPercentage(uint8_t newChargePercentage)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 SDataReceiveFromMaster *pDataOut = dataOutGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659 pDataOut->data.newBatteryGaugePercentageFloat = settingsGetPointer()->lastKnownBatteryPercentage;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 pDataOut->setBatteryGaugeNow = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 void calibrateCompass(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666 SDataReceiveFromMaster *pDataOut = dataOutGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667 pDataOut->calibrateCompassNow = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 void clearDeco(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673 SDataReceiveFromMaster *pDataOut = dataOutGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 pDataOut->clearDecoNow = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 stateRealGetPointerWrite()->cnsHigh_at_the_end_of_dive = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 stateRealGetPointerWrite()->decoMissed_at_the_end_of_dive = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 int32_t helper_days_from_civil(int32_t y, uint32_t m, uint32_t d)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 y += 2000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 y -= m <= 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 int32_t era = (y >= 0 ? y : y-399) / 400;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 uint32_t yoe = (uint32_t)(y - era * 400); // [0, 399]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 uint32_t doy = (153*(m + (m > 2 ? -3 : 9)) + 2)/5 + d-1; // [0, 365]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 uint32_t doe = yoe * 365 + yoe/4 - yoe/100 + doy; // [0, 146096]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 return era * 146097 + (int32_t)(doe) - 719468;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693 uint8_t helper_weekday_from_days(int32_t z)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 return (uint8_t)(z >= -4 ? (z+4) % 7 : (z+5) % 7 + 6);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 void setWeekday(RTC_DateTypeDef *sDate)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 uint8_t day;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702 // [0, 6] -> [Sun, Sat]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 day = helper_weekday_from_days(helper_days_from_civil(sDate->Year, sDate->Month, sDate->Date));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 // [1, 7] -> [Mon, Sun]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705 if(day == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 day = 7;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 sDate->WeekDay = day;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711 void translateDate(uint32_t datetmpreg, RTC_DateTypeDef *sDate)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 datetmpreg = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715 /* Fill the structure fields with the read parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716 sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 sDate->Date = (uint8_t)(datetmpreg & (RTC_DR_DT | RTC_DR_DU));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719 sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> 13);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 /* Convert the date structure parameters to Binary format */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724 sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727 void translateTime(uint32_t tmpreg, RTC_TimeTypeDef *sTime)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 tmpreg = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 /* Fill the structure fields with the read parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732 sTime->Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> 16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 sTime->Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >>8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734 sTime->Seconds = (uint8_t)(tmpreg & (RTC_TR_ST | RTC_TR_SU));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735 sTime->TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> 16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737 /* Convert the time structure parameters to Binary format */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738 sTime->Hours = (uint8_t)RTC_Bcd2ToByte(sTime->Hours);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740 sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 sTime->SubSeconds = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746 void initDiveState(SDiveSettings * pDiveSettings, SVpm * pVpm)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 SSettings* pSettings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749 for(int i = 0; i< NUM_GASES; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 pDiveSettings->gas[i] = pSettings->gas[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 pDiveSettings->gas[NUM_OFFSET_DILUENT + i] = pSettings->gas[NUM_OFFSET_DILUENT + i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 pDiveSettings->setpoint[i] = pSettings->setpoint[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 pDiveSettings->diveMode = pSettings->dive_mode;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757 pDiveSettings->gf_high = pSettings->GF_high;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 pDiveSettings->gf_low = pSettings->GF_low;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 pDiveSettings->last_stop_depth_bar = ((float)pSettings->last_stop_depth_meter) / 10.0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 pDiveSettings->ascentRate_meterperminute = 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 pDiveSettings->vpm_conservatism = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 pDiveSettings->input_next_stop_increment_depth_bar = ((float)pSettings->stop_increment_depth_meter) / 10.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765 vpm_init(pVpm, pDiveSettings->vpm_conservatism, 0, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 _Bool deco_zone_reached(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770 if(stateUsed->diveSettings.deco_type.ub.standard == GF_MODE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771 return stateUsed->lifeData.pressure_ambient_bar <= stateUsed->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 return stateUsed->vpm.deco_zone_reached;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 void resetEvents(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779 {
149
e1d66bc78f9a Eliminate warnings
Ideenmodellierer
parents: 138
diff changeset
780 SDiveState * pStateUsed;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781 if(stateUsed == stateRealGetPointer())
149
e1d66bc78f9a Eliminate warnings
Ideenmodellierer
parents: 138
diff changeset
782 {
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783 pStateUsed = stateRealGetPointerWrite();
149
e1d66bc78f9a Eliminate warnings
Ideenmodellierer
parents: 138
diff changeset
784 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 else
149
e1d66bc78f9a Eliminate warnings
Ideenmodellierer
parents: 138
diff changeset
786 {
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787 pStateUsed = stateSimGetPointerWrite();
149
e1d66bc78f9a Eliminate warnings
Ideenmodellierer
parents: 138
diff changeset
788 }
e1d66bc78f9a Eliminate warnings
Ideenmodellierer
parents: 138
diff changeset
789 memset(&pStateUsed->events,0, sizeof(SEvents));
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793 /* This is derived from crc32b but does table lookup. First the table
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 itself is calculated, if it has not yet been set up.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 Not counting the table setup (which would probably be a separate
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796 function), when compiled to Cyclops with GCC, this function executes in
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797 7 + 13n instructions, where n is the number of bytes in the input
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 message. It should be doable in 4 + 9n instructions. In any case, two
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799 of the 13 or 9 instrucions are load byte.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800 This is Figure 14-7 in the text. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802 /* http://www.hackersdelight.org/ i guess ;-) *hw */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 uint32_t crc32c_checksum(uint8_t* message, uint16_t length, uint8_t* message2, uint16_t length2) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805 int i, j;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806 uint32_t byte, crc, mask;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 static unsigned int table[256] = {0};
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809 /* Set up the table, if necessary. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810 if (table[1] == 0) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 for (byte = 0; byte <= 255; byte++) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812 crc = byte;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 for (j = 7; j >= 0; j--) { // Do eight times.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 mask = -(crc & 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815 crc = (crc >> 1) ^ (0xEDB88320 & mask);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817 table[byte] = crc;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821 /* Through with table setup, now calculate the CRC. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822 i = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823 crc = 0xFFFFFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 while (length--) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825 byte = message[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826 crc = (crc >> 8) ^ table[(crc ^ byte) & 0xFF];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 i = i + 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829 if(length2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831 i = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 while (length2--) {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 byte = message2[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 crc = (crc >> 8) ^ table[(crc ^ byte) & 0xFF];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835 i = i + 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 return ~crc;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842 uint32_t CRC_CalcBlockCRC_moreThan768000(uint32_t *buffer1, uint32_t *buffer2, uint32_t words)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844 cm_t crc_model;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845 uint32_t word_to_do;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 uint8_t byte_to_do;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847 int i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 // Values for the STM32F generator.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851 crc_model.cm_width = 32; // 32-bit CRC
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 crc_model.cm_poly = 0x04C11DB7; // CRC-32 polynomial
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853 crc_model.cm_init = 0xFFFFFFFF; // CRC initialized to 1's
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854 crc_model.cm_refin = FALSE; // CRC calculated MSB first
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855 crc_model.cm_refot = FALSE; // Final result is not bit-reversed
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 crc_model.cm_xorot = 0x00000000; // Final result XOR'ed with this
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 cm_ini(&crc_model);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860 while (words--)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862 // The STM32F10x hardware does 32-bit words at a time!!!
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863 if(words > (768000/4))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864 word_to_do = *buffer2++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866 word_to_do = *buffer1++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
868 // Do all bytes in the 32-bit word.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870 for (i = 0; i < sizeof(word_to_do); i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
871 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
872 // We calculate a *byte* at a time. If the CRC is MSB first we
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
873 // do the next MS byte and vica-versa.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
875 if (crc_model.cm_refin == FALSE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
876 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
877 // MSB first. Do the next MS byte.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
878
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
879 byte_to_do = (uint8_t) ((word_to_do & 0xFF000000) >> 24);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
880 word_to_do <<= 8;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
881 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
882 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
883 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
884 // LSB first. Do the next LS byte.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
885
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
886 byte_to_do = (uint8_t) (word_to_do & 0x000000FF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887 word_to_do >>= 8;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890 cm_nxt(&crc_model, byte_to_do);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894 // Return the final result.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896 return (cm_crc(&crc_model));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
897 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
898
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
899
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
900 uint32_t CRC_CalcBlockCRC(uint32_t *buffer, uint32_t words)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
901 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
902 cm_t crc_model;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
903 uint32_t word_to_do;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
904 uint8_t byte_to_do;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
905 int i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
906
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
907 // Values for the STM32F generator.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909 crc_model.cm_width = 32; // 32-bit CRC
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910 crc_model.cm_poly = 0x04C11DB7; // CRC-32 polynomial
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911 crc_model.cm_init = 0xFFFFFFFF; // CRC initialized to 1's
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
912 crc_model.cm_refin = FALSE; // CRC calculated MSB first
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913 crc_model.cm_refot = FALSE; // Final result is not bit-reversed
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914 crc_model.cm_xorot = 0x00000000; // Final result XOR'ed with this
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
915
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
916 cm_ini(&crc_model);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
917
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918 while (words--)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920 // The STM32F10x hardware does 32-bit words at a time!!!
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922 word_to_do = *buffer++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924 // Do all bytes in the 32-bit word.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
925
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
926 for (i = 0; i < sizeof(word_to_do); i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
927 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
928 // We calculate a *byte* at a time. If the CRC is MSB first we
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
929 // do the next MS byte and vica-versa.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
930
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
931 if (crc_model.cm_refin == FALSE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
932 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
933 // MSB first. Do the next MS byte.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
934
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
935 byte_to_do = (uint8_t) ((word_to_do & 0xFF000000) >> 24);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
936 word_to_do <<= 8;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
937 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
938 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
939 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
940 // LSB first. Do the next LS byte.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
941
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
942 byte_to_do = (uint8_t) (word_to_do & 0x000000FF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
943 word_to_do >>= 8;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
944 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
945
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
946 cm_nxt(&crc_model, byte_to_do);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
947 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
948 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
949
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
950 // Return the final result.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
951
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
952 return (cm_crc(&crc_model));
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
956 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
957 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
958 if(lifeData->pressure_ambient_bar < (lifeData->pressure_surface_bar + 0.04f))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
959 return true;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
960 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
961 return false;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
962 }