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