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