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