comparison Common/Inc/data_central.h @ 38:5f11787b4f42

include in ostc4 repository
author heinrichsweikamp
date Sat, 28 Apr 2018 11:52:34 +0200
parents
children cc9c18075e00
comparison
equal deleted inserted replaced
37:ccc45c0e1ea2 38:5f11787b4f42
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;
89 float output_relative_gradient;
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 int32_t stopwatch_start_at_this_dive_time_seconds;
160 } SHelper;
161
162 /* struct SLifeData
163 * contains data all actual data (pressure, stuturation, etc. as received from second ship
164 * and has actualGas to be send to Small CPU (second chip)
165 * contains data calculated from actual data after receiption from Small CPU
166 */
167 typedef struct
168 {
169 /* from Small CPU */
170 int32_t dive_time_seconds;
171 int32_t dive_time_seconds_without_surface_time;
172 uint32_t surface_time_seconds;
173 float pressure_ambient_bar;
174 float pressure_surface_bar;
175 float tissue_nitrogen_bar[16];
176 float tissue_helium_bar[16];
177 float cns;
178 float otu;
179 uint16_t desaturation_time_minutes;
180 uint16_t no_fly_time_minutes;
181 float temperature_celsius;
182 float compass_heading;
183 float compass_roll;
184 float compass_pitch;
185 int16_t compass_DX_f;
186 int16_t compass_DY_f;
187 int16_t compass_DZ_f;
188 uint16_t counterSecondsShallowDepth;
189 float ascent_rate_meter_per_min;
190 uint32_t timeBinaryFormat;
191 uint32_t dateBinaryFormat;
192 float battery_voltage;
193 float battery_charge;
194 uint16_t ambient_light_level;
195 SDataWireless wireless_data[4];
196 uint8_t buttonPICdata[4];
197
198 /* by create DiveSettings() and by setActualGas()
199 * is send to Small CPU2 for nitrogen calculation
200 * includes setpoint information
201 */
202 SGas actualGas;
203 uint8_t lastDiluent_GasIdInSettings;
204 uint8_t gas_temp2;
205
206 /* calculated by DataEX_copy_to_LifeData()
207 bottle_bar array size is made like this to have multiples of 32bit
208 */
209 float ppO2;
210 float depth_meter;
211 float max_depth_meter;
212 float average_depth_meter;
213 float apnea_total_max_depth_meter;
214 float apnea_last_max_depth_meter;
215 int32_t apnea_last_dive_time_seconds;
216 int32_t stopwatch_seconds;
217 uint16_t bottle_bar[2 * NUM_GASES +1];
218 uint16_t bottle_bar_age_MilliSeconds[2 * NUM_GASES + 1];
219 uint16_t apnea_total_counter;
220
221 uint8_t scooterSpeed;
222 uint8_t scooterType;
223 uint16_t scooterWattstunden;
224 uint16_t scooterDrehzahl;
225 uint8_t scooterRestkapazitaet;
226 uint8_t scooterAmpere;
227 uint16_t scooterTemperature;
228 uint16_t scooterAgeInMilliSeconds;
229 float scooterSpannung;
230 uint8_t scooterRestkapazitaetWhBased;
231 uint8_t scooterRestkapazitaetVoltageBased;
232
233 /* control of DataEX_copy_to_LifeData()
234 */
235 uint8_t boolResetAverageDepth;
236 uint8_t boolResetStopwatch;
237 uint8_t bool_temp1;
238 uint8_t bool_temp2;
239
240 /* from local sensor or direct HUD communication */
241 //pp O2 Sensor
242 float ppO2Sensor_bar[3];
243 float sensorVoltage_mV[3];
244 float HUD_battery_voltage_V;
245
246 /* used by DataEX_copy_to_LifeData()
247 */
248 SHelper internal;
249 } SLifeData;
250
251
252 typedef struct
253 {
254 uint16_t tissue_nitrogen_desaturation_time_minutes[16];
255 uint16_t tissue_helium_desaturation_time_minutes[16];
256 } SLifeData2;
257
258
259 typedef struct
260 {
261 //warnings
262 int8_t decoMissed;
263 int8_t aGf;
264 int8_t ascentRateHigh;
265 int8_t ppO2Low;
266 int8_t ppO2High;
267 int8_t cnsHigh;
268 int8_t slowWarning;
269 int8_t lowBattery;
270 int8_t numWarnings;
271 int8_t sensorLinkLost;
272 int8_t sensorOutOfBounds[3];
273 int8_t betterGas;
274 int8_t fallback;
275 int8_t betterSetpoint;
276 } SWarnings;
277
278
279 typedef struct
280 {
281 //Events logbook only
282 int16_t manualMarker;
283 int16_t gasChange;
284 int16_t info_GasChange;
285 int16_t setpointChange;
286 int16_t info_SetpointChange;
287 int16_t manuelGasSet;
288 int16_t info_manuelGasSetHe;
289 int16_t info_manuelGasSetO2;
290 int16_t bailout;
291 int16_t info_bailoutHe;
292 int16_t info_bailoutO2;
293 } SEvents;
294
295
296
297 //struct SDiveSettings
298 //contains settings necessary for deco calculation
299 typedef struct
300 {
301 float last_stop_depth_bar;
302 float input_next_stop_increment_depth_bar;
303 float input_second_to_last_stop_depth_bar;
304 float ascentRate_meterperminute;
305 uint8_t diveMode; /* OC, CC, .. */
306 uint8_t CCR_Mode;
307 uint8_t future_TTS_minutes;
308
309 /* If beginning of dive is CCR than ccrOption is set true
310 * true allows returning from bailout (OC) back to CCR
311 * true activates CC gas and setpoint pages in dive menu
312 */
313 uint8_t ccrOption;
314 uint8_t fallbackOption;
315 uint8_t ppo2sensors_deactivated;
316
317 split2x4_Type deco_type; /* GF or VPM for standard and alternative seperate */
318
319 /* VPM conservatism, do not change during dive!!!
320 * do not change in between dives otherwise repetitve dive is not possible
321 */
322 uint8_t vpm_conservatism;
323
324 /* B�hlmann GF
325 * and a variable that is used by Buehlmann during the dive
326 * to remember the position of GF low during ascend
327 */
328 uint8_t gf_high;
329 uint8_t gf_low;
330
331 /* copy of the Settings GasList and SetpintList
332 * that can be modified during the dive
333 * especially gases can be actived and deactivated
334 * gas[0] and setpoint[0] are the special ones configurable during the dive
335 */
336 SGasLine gas[1 + (2*NUM_GASES)];
337 SSetpointLine setpoint[1 + NUM_GASES];
338
339 /* List of GasChanges in the actual order
340 * this is necessary for VPM and Buehlmann and will be created on start of each calculation
341 */
342 SGas decogaslist[BUEHLMANN_STRUCT_MAX_GASES]; // unused filled with 0xFF
343
344 /*
345 */
346 float internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero;
347 uint16_t compassHeading;
348 } SDiveSettings;
349
350 enum CHARGE_STATUS{
351 CHARGER_off = 0,
352 CHARGER_running,
353 CHARGER_complete,
354 CHARGER_lostConnection
355 };
356
357 typedef struct
358 {
359 SDiveSettings diveSettings;
360 SLifeData lifeData;
361 SVpm vpm;
362 SEvents events;
363 SWarnings warnings;
364 SDecoinfo decolistVPM;
365 SDecoinfo decolistFutureVPM;
366 SDecoinfo decolistBuehlmann; //
367 SDecoinfo decolistFutureBuehlmann;
368 uint8_t mode; /* hw for sleep, surface, dive, .. */
369 uint8_t chargeStatus;
370 uint8_t data_old__lost_connection_to_slave;
371
372 uint32_t pressure_uTick_new;
373 uint32_t compass_uTick_new;
374
375 uint32_t pressure_uTick_old;
376 uint32_t compass_uTick_old;
377
378 uint32_t pressure_uTick_local_new;
379 uint32_t compass_uTick_local_new;
380
381 uint8_t cnsHigh_at_the_end_of_dive;
382 uint8_t decoMissed_at_the_end_of_dive;
383
384 uint8_t sensorErrorsRTE;
385
386 uint8_t lastKnownBatteryPercentage;
387 } SDiveState;
388
389
390 typedef struct{
391 uint8_t bit0:1;
392 uint8_t bit1:1;
393 uint8_t bit2:1;
394 uint8_t bit3:1;
395 uint8_t bit4:1;
396 uint8_t bit5:1;
397 uint8_t bit6:1;
398 uint8_t bit7:1;
399 } ubit8_t;
400
401 typedef union{
402 ubit8_t ub;
403 uint8_t uw;
404 } bit8_Type;
405
406 //extern SDiveState stateReal; only via const SDiveState stateRealGetPointer(void);
407 extern SDiveState stateSim;
408 extern SDiveState stateDeco;
409 extern uint8_t decoLock;
410 extern const SDiveState * stateUsed;
411 extern SLifeData2 secondaryInformation;
412
413
414 enum DECO_LOCK{
415 DECO_CALC_running,
416 DECO_CALC_ready,
417 DECO_CALC_FINSHED_Buehlmann,
418 DECO_CALC_FINSHED_vpm,
419 DECO_CALC_FINSHED_FutureBuehlmann,
420 DECO_CALC_FINSHED_Futurevpm,
421 DECO_CALC_init_as_is_start_of_dive,
422 DECO_CALC_undefined
423 };
424
425 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow);
426
427 void set_stateUsedToSim(void);
428 void set_stateUsedToReal(void);
429
430 _Bool is_stateUsedSetToSim(void);
431
432 const SDiveState * stateRealGetPointer(void);
433 const SDiveState * stateSimGetPointer(void);
434 SDiveState * stateRealGetPointerWrite(void);
435 SDiveState * stateSimGetPointerWrite(void);
436 const SDevice * stateDeviceGetPointer(void);
437 SDevice * stateDeviceGetPointerWrite(void);
438 const SVpmRepetitiveData * stateVpmRepetitiveDataGetPointer(void);
439 SVpmRepetitiveData * stateVpmRepetitiveDataGetPointerWrite(void);
440
441 void UpdateLifeDataTest(SDiveState * diveState);
442
443 void setSimulationValues(int _ascent_rate_meter_per_min, int _descent_rate_meter_per_min, int _max_depth, int _bottom_time );
444
445 void createDiveSettings(void);
446 void copyDiveSettingsToSim(void);
447 void copyVpmRepetetiveDataToSim(void);
448 //void fallbackToFixedSetpoints(SLifeData *lifeData);
449 void setActualGasFirst(SLifeData *lifeData);
450 void setActualGasAir(SLifeData *lifeData);
451 void setActualGas(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar);
452 void setActualGas_ExtraGas(SLifeData *lifeData, uint8_t oxygen, uint8_t helium, uint8_t setpoint_cbar);
453 void setActualGas_DM(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar);
454 void setWeekday(RTC_DateTypeDef *sDate);
455 void setDate(RTC_DateTypeDef Sdate);
456 void setTime(RTC_TimeTypeDef Stime);
457 void setBatteryPercentage(uint8_t newChargePercentage);
458 void setButtonResponsiveness(uint8_t *ButtonSensitivyList);
459 void calibrateCompass(void);
460 void clearDeco(void);
461 void translateDate(uint32_t datetmpreg, RTC_DateTypeDef *sDate);
462 void translateTime(uint32_t tmpreg, RTC_TimeTypeDef *sTime);
463 void updateSetpointStateUsed(void);
464
465 uint8_t calc_MOD(uint8_t gasId);
466 uint8_t calc_MinOD(uint8_t gasId);
467 //float calc_ppO2(float input_ambient_pressure_bar, SGas* pGas);
468 int current_second(void);
469 _Bool vpm_crush(SDiveState* pDiveState);
470 _Bool deco_zone_reached(void);
471 void resetEvents(void);
472
473 uint32_t crc32c_checksum(uint8_t* message, uint16_t length, uint8_t* message2, uint16_t length2);
474 uint32_t CRC_CalcBlockCRC(uint32_t *buffer, uint32_t words);
475 uint32_t CRC_CalcBlockCRC_moreThan768000(uint32_t *buffer1, uint32_t *buffer2, uint32_t words);
476
477 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData);
478
479 uint8_t stateUsed_scooterRemainingBattCapacity(void);
480
481 #endif // DATA_CENTRAL_H