Mercurial > public > ostc4
annotate Common/Inc/data_central.h @ 714:045ff7800501
Added customizable data area for specific sensor data:
In future smart sensors will be connected via UART interface. These sensor provide additional data like diagnostics or id numbers which may vary from sensor to sensor. That's why a byte array has been added which stores up to 32 bytes. The layout of this array may be specific to sensor needs. As first example temperature and id number of the DiveO2 sensor are provided.
author | Ideenmodellierer |
---|---|
date | Sun, 20 Nov 2022 20:42:08 +0100 |
parents | c00a80f26641 |
children | 5143e927219f |
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; |
714
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
672
diff
changeset
|
200 uint8_t extIf_sensor_Id; |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
672
diff
changeset
|
201 uint8_t UINT64ALIGNMENT; /* If your program crash check if you changed something in the life data structure ! The external sensor may contain a 64 bit ID */ |
045ff7800501
Added customizable data area for specific sensor data:
Ideenmodellierer
parents:
672
diff
changeset
|
202 uint8_t extIf_sensor_data[32]; |
662 | 203 |
38 | 204 |
205 /* by create DiveSettings() and by setActualGas() | |
206 * is send to Small CPU2 for nitrogen calculation | |
207 * includes setpoint information | |
208 */ | |
209 SGas actualGas; | |
210 uint8_t lastDiluent_GasIdInSettings; | |
211 uint8_t gas_temp2; | |
212 | |
213 /* calculated by DataEX_copy_to_LifeData() | |
214 bottle_bar array size is made like this to have multiples of 32bit | |
215 */ | |
216 float ppO2; | |
217 float depth_meter; | |
218 float max_depth_meter; | |
219 float average_depth_meter; | |
220 float apnea_total_max_depth_meter; | |
221 float apnea_last_max_depth_meter; | |
222 int32_t apnea_last_dive_time_seconds; | |
223 uint16_t bottle_bar[2 * NUM_GASES +1]; | |
224 uint16_t bottle_bar_age_MilliSeconds[2 * NUM_GASES + 1]; | |
225 uint16_t apnea_total_counter; | |
226 | |
227 /* control of DataEX_copy_to_LifeData() | |
228 */ | |
229 uint8_t boolResetAverageDepth; | |
230 uint8_t bool_temp1; | |
231 uint8_t bool_temp2; | |
232 | |
233 /* from local sensor or direct HUD communication */ | |
234 //pp O2 Sensor | |
235 float ppO2Sensor_bar[3]; | |
236 float sensorVoltage_mV[3]; | |
237 float HUD_battery_voltage_V; | |
662 | 238 |
239 /* for PSCR Mode */ | |
240 float ppo2Simulated_bar; | |
38 | 241 } SLifeData; |
242 | |
243 | |
244 typedef struct | |
245 { | |
246 uint16_t tissue_nitrogen_desaturation_time_minutes[16]; | |
247 uint16_t tissue_helium_desaturation_time_minutes[16]; | |
248 } SLifeData2; | |
249 | |
250 | |
251 typedef struct | |
252 { | |
253 //warnings | |
254 int8_t decoMissed; | |
255 int8_t aGf; | |
256 int8_t ascentRateHigh; | |
257 int8_t ppO2Low; | |
258 int8_t ppO2High; | |
259 int8_t cnsHigh; | |
260 int8_t slowWarning; | |
261 int8_t lowBattery; | |
262 int8_t numWarnings; | |
263 int8_t sensorLinkLost; | |
264 int8_t sensorOutOfBounds[3]; | |
265 int8_t betterGas; | |
266 int8_t fallback; | |
267 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
|
268 #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
|
269 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
|
270 #endif |
38 | 271 } SWarnings; |
272 | |
273 | |
274 typedef struct | |
275 { | |
276 //Events logbook only | |
277 int16_t manualMarker; | |
278 int16_t gasChange; | |
279 int16_t info_GasChange; | |
280 int16_t setpointChange; | |
281 int16_t info_SetpointChange; | |
281 | 282 int16_t manualGasSet; |
283 int16_t info_manualGasSetHe; | |
284 int16_t info_manualGasSetO2; | |
38 | 285 int16_t bailout; |
286 int16_t info_bailoutHe; | |
287 int16_t info_bailoutO2; | |
288 } SEvents; | |
289 | |
290 | |
291 | |
292 //struct SDiveSettings | |
293 //contains settings necessary for deco calculation | |
294 typedef struct | |
295 { | |
296 float last_stop_depth_bar; | |
297 float input_next_stop_increment_depth_bar; | |
298 float input_second_to_last_stop_depth_bar; | |
299 float ascentRate_meterperminute; | |
300 uint8_t diveMode; /* OC, CC, .. */ | |
301 uint8_t CCR_Mode; | |
302 uint8_t future_TTS_minutes; | |
303 | |
304 /* If beginning of dive is CCR than ccrOption is set true | |
305 * true allows returning from bailout (OC) back to CCR | |
306 * true activates CC gas and setpoint pages in dive menu | |
307 */ | |
308 uint8_t ccrOption; | |
309 uint8_t fallbackOption; | |
310 uint8_t ppo2sensors_deactivated; | |
311 | |
312 split2x4_Type deco_type; /* GF or VPM for standard and alternative seperate */ | |
313 | |
314 /* VPM conservatism, do not change during dive!!! | |
315 * do not change in between dives otherwise repetitve dive is not possible | |
316 */ | |
317 uint8_t vpm_conservatism; | |
318 | |
319 /* B�hlmann GF | |
320 * and a variable that is used by Buehlmann during the dive | |
321 * to remember the position of GF low during ascend | |
322 */ | |
323 uint8_t gf_high; | |
324 uint8_t gf_low; | |
325 | |
326 /* copy of the Settings GasList and SetpintList | |
327 * that can be modified during the dive | |
328 * especially gases can be actived and deactivated | |
329 * gas[0] and setpoint[0] are the special ones configurable during the dive | |
330 */ | |
331 SGasLine gas[1 + (2*NUM_GASES)]; | |
332 SSetpointLine setpoint[1 + NUM_GASES]; | |
333 | |
334 /* List of GasChanges in the actual order | |
335 * this is necessary for VPM and Buehlmann and will be created on start of each calculation | |
336 */ | |
337 SGas decogaslist[BUEHLMANN_STRUCT_MAX_GASES]; // unused filled with 0xFF | |
338 | |
339 /* | |
340 */ | |
341 float internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero; | |
342 uint16_t compassHeading; | |
662 | 343 |
344 uint8_t pscr_o2_drop; | |
345 uint8_t pscr_lung_ratio; | |
38 | 346 } SDiveSettings; |
347 | |
348 enum CHARGE_STATUS{ | |
349 CHARGER_off = 0, | |
350 CHARGER_running, | |
351 CHARGER_complete, | |
352 CHARGER_lostConnection | |
353 }; | |
354 | |
355 typedef struct | |
356 { | |
357 SDiveSettings diveSettings; | |
358 SLifeData lifeData; | |
359 SVpm vpm; | |
360 SEvents events; | |
361 SWarnings warnings; | |
362 SDecoinfo decolistVPM; | |
363 SDecoinfo decolistFutureVPM; | |
364 SDecoinfo decolistBuehlmann; // | |
365 SDecoinfo decolistFutureBuehlmann; | |
366 uint8_t mode; /* hw for sleep, surface, dive, .. */ | |
367 uint8_t chargeStatus; | |
368 uint8_t data_old__lost_connection_to_slave; | |
369 | |
370 uint32_t pressure_uTick_new; | |
371 uint32_t compass_uTick_new; | |
372 | |
373 uint32_t pressure_uTick_old; | |
374 uint32_t compass_uTick_old; | |
375 | |
376 uint32_t pressure_uTick_local_new; | |
377 uint32_t compass_uTick_local_new; | |
378 | |
379 uint8_t cnsHigh_at_the_end_of_dive; | |
380 uint8_t decoMissed_at_the_end_of_dive; | |
381 | |
382 uint8_t sensorErrorsRTE; | |
383 | |
384 uint8_t lastKnownBatteryPercentage; | |
385 } SDiveState; | |
386 | |
387 | |
388 typedef struct{ | |
389 uint8_t bit0:1; | |
390 uint8_t bit1:1; | |
391 uint8_t bit2:1; | |
392 uint8_t bit3:1; | |
393 uint8_t bit4:1; | |
394 uint8_t bit5:1; | |
395 uint8_t bit6:1; | |
396 uint8_t bit7:1; | |
397 } ubit8_t; | |
398 | |
399 typedef union{ | |
400 ubit8_t ub; | |
401 uint8_t uw; | |
402 } bit8_Type; | |
403 | |
404 extern SDiveState stateSim; | |
405 extern SDiveState stateDeco; | |
406 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
|
407 extern const SDiveState *stateUsed; |
1303747b5ba2
cleanup: also write gas and setpoint changes in simulator mode
Jan Mulder <jlmulder@xs4all.nl>
parents:
270
diff
changeset
|
408 extern SDiveState *stateUsedWrite; |
38 | 409 |
410 enum DECO_LOCK{ | |
411 DECO_CALC_running, | |
412 DECO_CALC_ready, | |
413 DECO_CALC_FINSHED_Buehlmann, | |
414 DECO_CALC_FINSHED_vpm, | |
415 DECO_CALC_FINSHED_FutureBuehlmann, | |
416 DECO_CALC_FINSHED_Futurevpm, | |
417 DECO_CALC_init_as_is_start_of_dive, | |
418 DECO_CALC_undefined | |
419 }; | |
420 | |
421 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow); | |
422 | |
423 void set_stateUsedToSim(void); | |
424 void set_stateUsedToReal(void); | |
425 | |
426 _Bool is_stateUsedSetToSim(void); | |
427 | |
428 const SDiveState * stateRealGetPointer(void); | |
429 const SDiveState * stateSimGetPointer(void); | |
430 SDiveState * stateRealGetPointerWrite(void); | |
431 SDiveState * stateSimGetPointerWrite(void); | |
432 const SDevice * stateDeviceGetPointer(void); | |
433 SDevice * stateDeviceGetPointerWrite(void); | |
434 const SVpmRepetitiveData * stateVpmRepetitiveDataGetPointer(void); | |
435 SVpmRepetitiveData * stateVpmRepetitiveDataGetPointerWrite(void); | |
436 | |
437 void UpdateLifeDataTest(SDiveState * diveState); | |
438 | |
439 void setSimulationValues(int _ascent_rate_meter_per_min, int _descent_rate_meter_per_min, int _max_depth, int _bottom_time ); | |
440 | |
441 void createDiveSettings(void); | |
442 void copyDiveSettingsToSim(void); | |
443 void copyVpmRepetetiveDataToSim(void); | |
444 //void fallbackToFixedSetpoints(SLifeData *lifeData); | |
445 void setActualGasFirst(SLifeData *lifeData); | |
446 void setActualGasAir(SLifeData *lifeData); | |
447 void setActualGas(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar); | |
448 void setActualGas_ExtraGas(SLifeData *lifeData, uint8_t oxygen, uint8_t helium, uint8_t setpoint_cbar); | |
449 void setActualGas_DM(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar); | |
450 void setWeekday(RTC_DateTypeDef *sDate); | |
451 void setDate(RTC_DateTypeDef Sdate); | |
452 void setTime(RTC_TimeTypeDef Stime); | |
453 void setBatteryPercentage(uint8_t newChargePercentage); | |
454 void setButtonResponsiveness(uint8_t *ButtonSensitivyList); | |
455 void calibrateCompass(void); | |
539
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
478
diff
changeset
|
456 void compass_Inertia(float newHeading); |
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
478
diff
changeset
|
457 float compass_getCompensated(); |
38 | 458 void clearDeco(void); |
459 void translateDate(uint32_t datetmpreg, RTC_DateTypeDef *sDate); | |
460 void translateTime(uint32_t tmpreg, RTC_TimeTypeDef *sTime); | |
461 void updateSetpointStateUsed(void); | |
462 | |
463 uint8_t calc_MOD(uint8_t gasId); | |
464 uint8_t calc_MinOD(uint8_t gasId); | |
465 //float calc_ppO2(float input_ambient_pressure_bar, SGas* pGas); | |
466 int current_second(void); | |
467 _Bool vpm_crush(SDiveState* pDiveState); | |
468 _Bool deco_zone_reached(void); | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
247
diff
changeset
|
469 void resetEvents(const SDiveState *pStateUsed); |
38 | 470 |
471 uint32_t crc32c_checksum(uint8_t* message, uint16_t length, uint8_t* message2, uint16_t length2); | |
472 uint32_t CRC_CalcBlockCRC(uint32_t *buffer, uint32_t words); | |
473 uint32_t CRC_CalcBlockCRC_moreThan768000(uint32_t *buffer1, uint32_t *buffer2, uint32_t words); | |
474 | |
475 _Bool is_ambient_pressure_close_to_surface(SLifeData *lifeData); | |
476 | |
662 | 477 uint8_t isLoopMode(uint8_t Mode); |
478 | |
38 | 479 #endif // DATA_CENTRAL_H |