Mercurial > public > ostc4
annotate Common/Inc/data_central.h @ 308:1203255481e4 cleanup-4
cleanup: introduce function setAvgDepth
The simulator and the realtime code shared a literally identical piece
of code to compute a running depth average. This is simply poor coding
style, so factor this out and create a function to do this work.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Fri, 24 May 2019 09:02:46 +0200 |
parents | b6436edfb2c0 |
children | b0045281cb2d |
rev | line source |
---|---|
38 | 1 /////////////////////////////////////////////////////////////////////////////// |
2 /// -*- coding: UTF-8 -*- | |
3 /// | |
4 /// \file Common/Inc/data_central.h | |
5 /// \brief Common Dadatypes Declarations | |
6 /// \author Heinrichs Weikamp | |
7 /// \date 2018 | |
8 /// | |
9 /// $Id$ | |
10 /////////////////////////////////////////////////////////////////////////////// | |
11 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh | |
12 /// | |
13 /// This program is free software: you can redistribute it and/or modify | |
14 /// it under the terms of the GNU General Public License as published by | |
15 /// the Free Software Foundation, either version 3 of the License, or | |
16 /// (at your option) any later version. | |
17 /// | |
18 /// This program is distributed in the hope that it will be useful, | |
19 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 /// GNU General Public License for more details. | |
22 /// | |
23 /// You should have received a copy of the GNU General Public License | |
24 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
25 ////////////////////////////////////////////////////////////////////////////// | |
26 | |
27 #ifndef DATA_CENTRAL_H | |
28 #define DATA_CENTRAL_H | |
29 | |
30 #include <stdint.h> | |
31 | |
32 #include "settings.h" | |
33 #include "stm32f4xx_hal.h" | |
34 | |
35 #define BUEHLMANN_STRUCT_MAX_GASES 11 | |
36 #define BUEHLMANN_STRUCT_MAX_ASCENDRATES 3 | |
37 #define DECOINFO_STRUCT_MAX_STOPS 50 | |
38 | |
39 #define false 0 | |
40 #define true 1 | |
41 | |
42 /* Helper structs ------------------------------------------------------------*/ | |
43 | |
44 //struct SGas | |
45 //contains gasinfos of single gas for deco calculation | |
46 typedef struct | |
47 { | |
48 uint8_t nitrogen_percentage; | |
49 uint8_t helium_percentage; | |
50 uint8_t setPoint_cbar; | |
51 uint8_t change_during_ascent_depth_meter_otherwise_zero; | |
52 uint8_t GasIdInSettings; | |
53 uint8_t temp1_for16bitalign; | |
54 } SGas; | |
55 | |
56 typedef struct | |
57 { | |
58 float use_from_depth_bar; | |
59 float rate_bar_per_minute; | |
60 } SAscentrate; | |
61 | |
62 | |
63 typedef struct{ | |
64 uint32_t date_rtc_dr; | |
65 uint32_t time_rtc_tr; | |
66 int32_t value_int32; | |
67 } SDeviceLine; | |
68 | |
69 | |
70 typedef struct | |
71 { | |
72 uint16_t ageInMilliSeconds; | |
73 uint8_t numberOfBytes; | |
74 uint8_t status; | |
75 uint8_t data[12]; | |
76 } SDataWireless; | |
77 | |
78 /* Main structs -------------------------------------------------------------*/ | |
79 | |
80 | |
81 //struct SDecoinfo | |
82 //contains result of deco calculation | |
83 typedef struct | |
84 { | |
85 unsigned short output_stop_length_seconds[DECOINFO_STRUCT_MAX_STOPS]; | |
86 int output_time_to_surface_seconds; | |
87 int output_ndl_seconds; | |
88 float output_ceiling_meter; | |
247
3949781096d4
feature: Relative GF to Saturation renames
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
89 float super_saturation; |
38 | 90 uint32_t tickstamp; |
91 } SDecoinfo; | |
92 | |
93 | |
94 typedef struct | |
95 { | |
96 //crushing pressure | |
97 //in/out | |
98 float max_crushing_pressure_he[16]; | |
99 float max_crushing_pressure_n2[16]; | |
100 // | |
101 float run_time_start_of_deco_zone_save; | |
102 float depth_start_of_deco_zone_save; | |
103 float max_first_stop_depth_save; | |
104 short decomode_vpm_plus_conservatism_last_dive; | |
105 _Bool deco_zone_reached; | |
106 //State variables for repetetive dives | |
107 _Bool repetitive_variables_not_valid; | |
108 float adjusted_crushing_pressure_he[16]; | |
109 float adjusted_crushing_pressure_n2[16]; | |
110 float adjusted_critical_radius_he[16]; | |
111 float adjusted_critical_radius_n2[16]; | |
112 float initial_allowable_gradient_he[16]; | |
113 float initial_allowable_gradient_n2[16]; | |
114 float max_actual_gradient[16]; | |
115 } SVpm; | |
116 | |
117 typedef struct | |
118 { | |
119 _Bool repetitive_variables_not_valid; | |
120 _Bool is_data_from_RTE_CPU; | |
121 _Bool spare2; | |
122 _Bool spare3; | |
123 float adjusted_crushing_pressure_he[16]; | |
124 float adjusted_crushing_pressure_n2[16]; | |
125 float adjusted_critical_radius_he[16]; | |
126 float adjusted_critical_radius_n2[16]; | |
127 float initial_allowable_gradient_he[16]; | |
128 float initial_allowable_gradient_n2[16]; | |
129 float max_actual_gradient[16]; | |
130 } SVpmRepetitiveData; | |
131 | |
132 //struct SDevice | |
133 //contains information about usage | |
134 typedef struct | |
135 { | |
136 SDeviceLine batteryChargeCycles; | |
137 SDeviceLine batteryChargeCompleteCycles; | |
138 SDeviceLine temperatureMinimum; | |
139 SDeviceLine temperatureMaximum; | |
140 SDeviceLine depthMaximum; | |
141 SDeviceLine diveCycles; | |
142 SDeviceLine voltageMinimum; | |
143 SDeviceLine hoursOfOperation; | |
144 SDeviceLine diveAccident; | |
145 } SDevice; | |
146 | |
147 /* | |
148 typedef struct | |
149 { | |
150 SDevice device; | |
151 SVpmRepetitiveData vpm; | |
152 } SDeviceState; | |
153 */ | |
154 | |
155 typedef struct | |
156 { | |
157 uint32_t average_depth_meter_Count; | |
158 uint32_t average_depth_last_update_dive_time_seconds_without_surface_time; | |
159 } SHelper; | |
160 | |
161 /* struct SLifeData | |
162 * contains data all actual data (pressure, stuturation, etc. as received from second ship | |
163 * and has actualGas to be send to Small CPU (second chip) | |
164 * contains data calculated from actual data after receiption from Small CPU | |
165 */ | |
166 typedef struct | |
167 { | |
168 /* from Small CPU */ | |
169 int32_t dive_time_seconds; | |
170 int32_t dive_time_seconds_without_surface_time; | |
171 uint32_t surface_time_seconds; | |
172 float pressure_ambient_bar; | |
173 float pressure_surface_bar; | |
174 float tissue_nitrogen_bar[16]; | |
175 float tissue_helium_bar[16]; | |
176 float cns; | |
177 float otu; | |
178 uint16_t desaturation_time_minutes; | |
179 uint16_t no_fly_time_minutes; | |
180 float temperature_celsius; | |
181 float compass_heading; | |
182 float compass_roll; | |
183 float compass_pitch; | |
184 int16_t compass_DX_f; | |
185 int16_t compass_DY_f; | |
186 int16_t compass_DZ_f; | |
187 uint16_t counterSecondsShallowDepth; | |
188 float ascent_rate_meter_per_min; | |
189 uint32_t timeBinaryFormat; | |
190 uint32_t dateBinaryFormat; | |
191 float battery_voltage; | |
192 float battery_charge; | |
193 uint16_t ambient_light_level; | |
194 SDataWireless wireless_data[4]; | |
195 uint8_t buttonPICdata[4]; | |
196 | |
197 /* by create DiveSettings() and by setActualGas() | |
198 * is send to Small CPU2 for nitrogen calculation | |
199 * includes setpoint information | |
200 */ | |
201 SGas actualGas; | |
202 uint8_t lastDiluent_GasIdInSettings; | |
203 uint8_t gas_temp2; | |
204 | |
205 /* calculated by DataEX_copy_to_LifeData() | |
206 bottle_bar array size is made like this to have multiples of 32bit | |
207 */ | |
208 float ppO2; | |
209 float depth_meter; | |
210 float max_depth_meter; | |
211 float average_depth_meter; | |
212 float apnea_total_max_depth_meter; | |
213 float apnea_last_max_depth_meter; | |
214 int32_t apnea_last_dive_time_seconds; | |
215 uint16_t bottle_bar[2 * NUM_GASES +1]; | |
216 uint16_t bottle_bar_age_MilliSeconds[2 * NUM_GASES + 1]; | |
217 uint16_t apnea_total_counter; | |
218 | |
219 /* control of DataEX_copy_to_LifeData() | |
220 */ | |
221 uint8_t boolResetAverageDepth; | |
222 uint8_t bool_temp1; | |
223 uint8_t bool_temp2; | |
224 | |
225 /* from local sensor or direct HUD communication */ | |
226 //pp O2 Sensor | |
227 float ppO2Sensor_bar[3]; | |
228 float sensorVoltage_mV[3]; | |
229 float HUD_battery_voltage_V; | |
230 | |
231 /* used by DataEX_copy_to_LifeData() | |
232 */ | |
233 SHelper internal; | |
234 } SLifeData; | |
235 | |
236 | |
237 typedef struct | |
238 { | |
239 uint16_t tissue_nitrogen_desaturation_time_minutes[16]; | |
240 uint16_t tissue_helium_desaturation_time_minutes[16]; | |
241 } SLifeData2; | |
242 | |
243 | |
244 typedef struct | |
245 { | |
246 //warnings | |
247 int8_t decoMissed; | |
248 int8_t aGf; | |
249 int8_t ascentRateHigh; | |
250 int8_t ppO2Low; | |
251 int8_t ppO2High; | |
252 int8_t cnsHigh; | |
253 int8_t slowWarning; | |
254 int8_t lowBattery; | |
255 int8_t numWarnings; | |
256 int8_t sensorLinkLost; | |
257 int8_t sensorOutOfBounds[3]; | |
258 int8_t betterGas; | |
259 int8_t fallback; | |
260 int8_t betterSetpoint; | |
261 } SWarnings; | |
262 | |
263 | |
264 typedef struct | |
265 { | |
266 //Events logbook only | |
267 int16_t manualMarker; | |
268 int16_t gasChange; | |
269 int16_t info_GasChange; | |
270 int16_t setpointChange; | |
271 int16_t info_SetpointChange; | |
281 | 272 int16_t manualGasSet; |
273 int16_t info_manualGasSetHe; | |
274 int16_t info_manualGasSetO2; | |
38 | 275 int16_t bailout; |
276 int16_t info_bailoutHe; | |
277 int16_t info_bailoutO2; | |
278 } SEvents; | |
279 | |
280 | |
281 | |
282 //struct SDiveSettings | |
283 //contains settings necessary for deco calculation | |
284 typedef struct | |
285 { | |
286 float last_stop_depth_bar; | |
287 float input_next_stop_increment_depth_bar; | |
288 float input_second_to_last_stop_depth_bar; | |
289 float ascentRate_meterperminute; | |
290 uint8_t diveMode; /* OC, CC, .. */ | |
291 uint8_t CCR_Mode; | |
292 uint8_t future_TTS_minutes; | |
293 | |
294 /* If beginning of dive is CCR than ccrOption is set true | |
295 * true allows returning from bailout (OC) back to CCR | |
296 * true activates CC gas and setpoint pages in dive menu | |
297 */ | |
298 uint8_t ccrOption; | |
299 uint8_t fallbackOption; | |
300 uint8_t ppo2sensors_deactivated; | |
301 | |
302 split2x4_Type deco_type; /* GF or VPM for standard and alternative seperate */ | |
303 | |
304 /* VPM conservatism, do not change during dive!!! | |
305 * do not change in between dives otherwise repetitve dive is not possible | |
306 */ | |
307 uint8_t vpm_conservatism; | |
308 | |
309 /* B�hlmann GF | |
310 * and a variable that is used by Buehlmann during the dive | |
311 * to remember the position of GF low during ascend | |
312 */ | |
313 uint8_t gf_high; | |
314 uint8_t gf_low; | |
315 | |
316 /* copy of the Settings GasList and SetpintList | |
317 * that can be modified during the dive | |
318 * especially gases can be actived and deactivated | |
319 * gas[0] and setpoint[0] are the special ones configurable during the dive | |
320 */ | |
321 SGasLine gas[1 + (2*NUM_GASES)]; | |
322 SSetpointLine setpoint[1 + NUM_GASES]; | |
323 | |
324 /* List of GasChanges in the actual order | |
325 * this is necessary for VPM and Buehlmann and will be created on start of each calculation | |
326 */ | |
327 SGas decogaslist[BUEHLMANN_STRUCT_MAX_GASES]; // unused filled with 0xFF | |
328 | |
329 /* | |
330 */ | |
331 float internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero; | |
332 uint16_t compassHeading; | |
333 } SDiveSettings; | |
334 | |
335 enum CHARGE_STATUS{ | |
336 CHARGER_off = 0, | |
337 CHARGER_running, | |
338 CHARGER_complete, | |
339 CHARGER_lostConnection | |
340 }; | |
341 | |
342 typedef struct | |
343 { | |
344 SDiveSettings diveSettings; | |
345 SLifeData lifeData; | |
346 SVpm vpm; | |
347 SEvents events; | |
348 SWarnings warnings; | |
349 SDecoinfo decolistVPM; | |
350 SDecoinfo decolistFutureVPM; | |
351 SDecoinfo decolistBuehlmann; // | |
352 SDecoinfo decolistFutureBuehlmann; | |
353 uint8_t mode; /* hw for sleep, surface, dive, .. */ | |
354 uint8_t chargeStatus; | |
355 uint8_t data_old__lost_connection_to_slave; | |
356 | |
357 uint32_t pressure_uTick_new; | |
358 uint32_t compass_uTick_new; | |
359 | |
360 uint32_t pressure_uTick_old; | |
361 uint32_t compass_uTick_old; | |
362 | |
363 uint32_t pressure_uTick_local_new; | |
364 uint32_t compass_uTick_local_new; | |
365 | |
366 uint8_t cnsHigh_at_the_end_of_dive; | |
367 uint8_t decoMissed_at_the_end_of_dive; | |
368 | |
369 uint8_t sensorErrorsRTE; | |
370 | |
371 uint8_t lastKnownBatteryPercentage; | |
372 } SDiveState; | |
373 | |
374 | |
375 typedef struct{ | |
376 uint8_t bit0:1; | |
377 uint8_t bit1:1; | |
378 uint8_t bit2:1; | |
379 uint8_t bit3:1; | |
380 uint8_t bit4:1; | |
381 uint8_t bit5:1; | |
382 uint8_t bit6:1; | |
383 uint8_t bit7:1; | |
384 } ubit8_t; | |
385 | |
386 typedef union{ | |
387 ubit8_t ub; | |
388 uint8_t uw; | |
389 } bit8_Type; | |
390 | |
391 extern SDiveState stateSim; | |
392 extern SDiveState stateDeco; | |
393 extern uint8_t decoLock; | |
271
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
394 extern const SDiveState *stateUsed; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
395 extern SDiveState *stateUsedWrite; |
38 | 396 |
397 enum DECO_LOCK{ | |
398 DECO_CALC_running, | |
399 DECO_CALC_ready, | |
400 DECO_CALC_FINSHED_Buehlmann, | |
401 DECO_CALC_FINSHED_vpm, | |
402 DECO_CALC_FINSHED_FutureBuehlmann, | |
403 DECO_CALC_FINSHED_Futurevpm, | |
404 DECO_CALC_init_as_is_start_of_dive, | |
405 DECO_CALC_undefined | |
406 }; | |
407 | |
408 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow); | |
409 | |
410 void set_stateUsedToSim(void); | |
411 void set_stateUsedToReal(void); | |
412 | |
413 _Bool is_stateUsedSetToSim(void); | |
414 | |
415 const SDiveState * stateRealGetPointer(void); | |
416 const SDiveState * stateSimGetPointer(void); | |
417 SDiveState * stateRealGetPointerWrite(void); | |
418 SDiveState * stateSimGetPointerWrite(void); | |
419 const SDevice * stateDeviceGetPointer(void); | |
420 SDevice * stateDeviceGetPointerWrite(void); | |
421 const SVpmRepetitiveData * stateVpmRepetitiveDataGetPointer(void); | |
422 SVpmRepetitiveData * stateVpmRepetitiveDataGetPointerWrite(void); | |
423 | |
424 void UpdateLifeDataTest(SDiveState * diveState); | |
425 | |
426 void setSimulationValues(int _ascent_rate_meter_per_min, int _descent_rate_meter_per_min, int _max_depth, int _bottom_time ); | |
427 | |
428 void createDiveSettings(void); | |
429 void copyDiveSettingsToSim(void); | |
430 void copyVpmRepetetiveDataToSim(void); | |
431 //void fallbackToFixedSetpoints(SLifeData *lifeData); | |
432 void setActualGasFirst(SLifeData *lifeData); | |
433 void setActualGasAir(SLifeData *lifeData); | |
434 void setActualGas(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar); | |
435 void setActualGas_ExtraGas(SLifeData *lifeData, uint8_t oxygen, uint8_t helium, uint8_t setpoint_cbar); | |
436 void setActualGas_DM(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar); | |
437 void setWeekday(RTC_DateTypeDef *sDate); | |
438 void setDate(RTC_DateTypeDef Sdate); | |
439 void setTime(RTC_TimeTypeDef Stime); | |
440 void setBatteryPercentage(uint8_t newChargePercentage); | |
441 void setButtonResponsiveness(uint8_t *ButtonSensitivyList); | |
442 void calibrateCompass(void); | |
443 void clearDeco(void); | |
444 void translateDate(uint32_t datetmpreg, RTC_DateTypeDef *sDate); | |
445 void translateTime(uint32_t tmpreg, RTC_TimeTypeDef *sTime); | |
446 void updateSetpointStateUsed(void); | |
447 | |
448 uint8_t calc_MOD(uint8_t gasId); | |
449 uint8_t calc_MinOD(uint8_t gasId); | |
450 //float calc_ppO2(float input_ambient_pressure_bar, SGas* pGas); | |
451 int current_second(void); | |
452 _Bool vpm_crush(SDiveState* pDiveState); | |
453 _Bool deco_zone_reached(void); | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
454 void resetEvents(const SDiveState *pStateUsed); |
38 | 455 |
456 uint32_t crc32c_checksum(uint8_t* message, uint16_t length, uint8_t* message2, uint16_t length2); | |
457 uint32_t CRC_CalcBlockCRC(uint32_t *buffer, uint32_t words); | |
458 uint32_t CRC_CalcBlockCRC_moreThan768000(uint32_t *buffer1, uint32_t *buffer2, uint32_t words); | |
459 | |
460 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData); | |
461 | |
462 #endif // DATA_CENTRAL_H |