Mercurial > public > ostc4
annotate Discovery/Src/data_exchange_main.c @ 199:ac58a9fb92ac div-fixes-cleaup-2
Bugfix: fix initial CNS data in the logbook header
Apparently, there has been confusion in the past about the data format of the
CNS data in the logbook. This seems to be partially fixed back in 2015, but
this fix forgot that the initial CNS data is also in the logbook header.
So, now, the logbook header also stores the initial CNS data in a correct way,
which fixes the problem of strange CNS values at the very start of repetitive
dives, that get reset in the dive profile after the first CNS sample data comes
along.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Fri, 22 Mar 2019 08:36:39 +0100 |
parents | 878dc9e0dbc5 |
children | 9fc06e1e0f66 |
rev | line source |
---|---|
38 | 1 /** |
2 ****************************************************************************** | |
3 * @file data_exchange_main.c | |
4 * @author heinrichs weikamp gmbh | |
5 * @date 13-Oct-2014 | |
6 * @version V0.0.3 | |
7 * @since 17-Feb-2016 | |
8 | |
9 * @brief Communication with the second CPU == RTE system | |
10 * | |
11 @verbatim | |
12 ============================================================================== | |
13 ##### Version Changes ##### | |
14 ============================================================================== | |
15 160217 V0.0.3 pStateUsed->decolistXXXXX.tickstamp = HAL_GetTick(); added | |
16 150627 V0.0.2 | |
17 | |
18 ============================================================================== | |
19 ##### How to use ##### | |
20 ============================================================================== | |
21 | |
22 ============================================================================== | |
23 ##### Button, Set Time, Clear Deco etc Request ##### | |
24 ============================================================================== | |
25 was updated (151207) for buttons and clear deco at the moment only | |
26 using requestNecessary and checking in DataEX_copy_to_LifeData() | |
27 Hence if there is no confirm from the smallCPU on the data after the request | |
28 the request will be send again. | |
29 | |
30 ============================================================================== | |
31 ##### Device Data ##### | |
32 ============================================================================== | |
33 | |
34 main CPU always sends the device data info that it has at the moment | |
35 | |
36 on start it is INT32_MIN, INT32_MAX and 0 | |
37 as initialized in data_central.c variable declaration | |
38 | |
39 second small CPU gets request to send its device data | |
40 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
41 on reception the data is merged with the data in externLogbookFlash, |
38 | 42 stored on the externLogbookFlash and from now on send to small CPU |
43 | |
44 ============================================================================== | |
45 ##### Magnet Reset ##### | |
46 ============================================================================== | |
47 | |
48 @endverbatim | |
49 ****************************************************************************** | |
50 * @attention | |
51 * | |
52 * <h2><center>© COPYRIGHT(c) 2014 heinrichs weikamp</center></h2> | |
53 * | |
54 ****************************************************************************** | |
55 */ | |
56 | |
57 /* Includes ------------------------------------------------------------------*/ | |
133
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
58 #include <stdlib.h> |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
59 #include <string.h> // for memcpy |
38 | 60 #include "stm32f4xx_hal.h" |
61 #include "stdio.h" | |
62 #include "ostc.h" | |
63 #include "settings.h" | |
64 #include "data_central.h" | |
65 #include "data_exchange_main.h" | |
66 #include "base.h" | |
67 #include "decom.h" | |
68 #include "calc_crush.h" /* for vpm_init */ | |
69 #include "simulation.h" | |
70 #include "tCCR.h" | |
71 #include "timer.h" | |
72 #include "buehlmann.h" | |
73 #include "externLogbookFlash.h" | |
74 | |
75 | |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
76 /* Exported variables --------------------------------------------------------*/ |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
77 static uint8_t wasPowerOn = 0; |
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
78 static confirmbit8_Type requestNecessary = { .uw = 0 }; |
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
79 static uint8_t wasUpdateNotPowerOn = 0; |
38 | 80 |
81 /* Private variables with external access ------------------------------------*/ | |
82 | |
83 /* Private variables ---------------------------------------------------------*/ | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
84 static uint8_t told_reset_logik_alles_ok = 0; |
38 | 85 |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
86 static SDataReceiveFromMaster dataOut; |
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
87 static SDataExchangeSlaveToMaster dataIn; |
38 | 88 |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
89 static uint8_t data_old__lost_connection_to_slave_counter_temp = 0; |
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
90 static uint8_t data_old__lost_connection_to_slave_counter_retry = 0; |
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
91 static uint32_t data_old__lost_connection_to_slave_counter_total = 0; |
38 | 92 |
93 /* Private types -------------------------------------------------------------*/ | |
94 | |
95 /* Private function prototypes -----------------------------------------------*/ | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
96 static uint8_t DataEX_check_header_and_footer_ok(void); |
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
97 static uint8_t DataEX_check_header_and_footer_shifted(void); |
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
98 static uint8_t DataEX_check_header_and_footer_devicedata(void); |
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
99 static void DataEX_check_DeviceData(void); |
38 | 100 |
101 /* Exported functions --------------------------------------------------------*/ | |
102 | |
103 uint8_t DataEX_was_power_on(void) | |
104 { | |
105 return wasPowerOn; | |
106 } | |
107 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
108 static uint8_t count_DataEX_Error_Handler = 0; |
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
109 static uint8_t last_error_DataEX_Error_Handler = 0; |
38 | 110 |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
111 static void DataEX_Error_Handler(uint8_t answer) |
38 | 112 { |
113 count_DataEX_Error_Handler++; | |
114 last_error_DataEX_Error_Handler = answer; | |
133
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
115 |
156
1fbdb45db701
Removed special indicator for DMA transfer error
Ideenmodellierer
parents:
154
diff
changeset
|
116 /* A wrong footer indicates a communication interrupt. State machine is waiting for new data which is not received because no new transmission is triggered */ |
133
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
117 /* ==> Abort data exchange to enable a new RX / TX cycle */ |
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
118 if(answer == HAL_BUSY) |
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
119 { |
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
120 HAL_SPI_Abort_IT(&cpu2DmaSpi); |
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
121 } |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
122 |
38 | 123 return; |
124 } | |
125 | |
126 | |
127 uint32_t DataEX_lost_connection_count(void) | |
128 { | |
129 return data_old__lost_connection_to_slave_counter_total; | |
130 } | |
131 | |
132 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
133 SDataReceiveFromMaster *dataOutGetPointer(void) |
38 | 134 { |
135 return &dataOut; | |
136 } | |
137 | |
138 void DataEX_init(void) | |
139 { | |
140 SDiveState * pStateReal = stateRealGetPointerWrite(); | |
99 | 141 pStateReal->data_old__lost_connection_to_slave = 0; //initial value |
38 | 142 data_old__lost_connection_to_slave_counter_temp = 0; |
143 data_old__lost_connection_to_slave_counter_total = 0; | |
144 | |
145 memset((void *)&dataOut, 0, sizeof(SDataReceiveFromMaster)); | |
146 | |
147 dataOut.header.checkCode[0] = 0xBB; | |
148 dataOut.header.checkCode[1] = 0x01; | |
149 dataOut.header.checkCode[2] = 0x01; | |
150 dataOut.header.checkCode[3] = 0xBB; | |
151 | |
152 dataOut.footer.checkCode[0] = 0xF4; | |
153 dataOut.footer.checkCode[1] = 0xF3; | |
154 dataOut.footer.checkCode[2] = 0xF2; | |
155 dataOut.footer.checkCode[3] = 0xF1; | |
156 } | |
157 | |
158 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
159 static void DataEx_call_helper_requests(void) |
38 | 160 { |
161 static uint8_t setDateWasSend = 0; | |
162 static uint8_t setTimeWasSend = 0; | |
163 static uint8_t calibrateCompassWasSend = 0; | |
164 static uint8_t setButtonSensitivityWasSend = 0; | |
165 static uint8_t clearDecoWasSend = 0; | |
166 static uint8_t getDeviceDataWasSend = 0; | |
167 static uint8_t setAccidentFlagWasSend = 0; | |
168 static uint8_t setEndDiveWasSend = 0; | |
169 | |
170 if(getDeviceDataWasSend) | |
171 { | |
172 dataOut.getDeviceDataNow = 0; | |
173 requestNecessary.ub.devicedata = 1; | |
174 } | |
175 getDeviceDataWasSend = 0; | |
176 if(dataOut.getDeviceDataNow) | |
177 { | |
178 getDeviceDataWasSend = 1; | |
179 } | |
180 | |
181 if(setEndDiveWasSend) | |
182 { | |
183 dataOut.setEndDive = 0; | |
184 //requestNecessary.ub.XXX = 1; not implemented and no space here | |
185 } | |
186 setEndDiveWasSend = 0; | |
187 if(dataOut.setEndDive) | |
188 { | |
189 setEndDiveWasSend = 1; | |
190 } | |
191 | |
192 if(setAccidentFlagWasSend) | |
193 { | |
194 dataOut.setAccidentFlag = 0; | |
195 requestNecessary.ub.accident = 1; | |
196 } | |
197 setAccidentFlagWasSend = 0; | |
198 if(dataOut.setAccidentFlag) | |
199 { | |
200 setAccidentFlagWasSend = 1; | |
201 } | |
202 | |
203 if(setDateWasSend) | |
204 { | |
205 dataOut.setDateNow = 0; | |
206 requestNecessary.ub.date = 1; | |
207 } | |
208 setDateWasSend = 0; | |
209 if(dataOut.setDateNow) | |
210 { | |
211 setDateWasSend = 1; | |
212 } | |
213 | |
214 if(setTimeWasSend) | |
215 { | |
216 dataOut.setTimeNow = 0; | |
217 requestNecessary.ub.time = 1; | |
218 } | |
219 setTimeWasSend = 0; | |
220 if(dataOut.setTimeNow) | |
221 { | |
222 setTimeWasSend = 1; | |
223 } | |
224 | |
225 if(calibrateCompassWasSend) | |
226 { | |
227 dataOut.calibrateCompassNow = 0; | |
228 requestNecessary.ub.compass = 1; | |
229 } | |
230 calibrateCompassWasSend = 0; | |
231 if(dataOut.calibrateCompassNow) | |
232 { | |
233 calibrateCompassWasSend = 1; | |
234 } | |
235 | |
236 if(clearDecoWasSend) | |
237 { | |
238 dataOut.clearDecoNow = 0; | |
239 requestNecessary.ub.clearDeco = 1; | |
240 } | |
241 if(dataOut.clearDecoNow) | |
242 { | |
243 clearDecoWasSend = 1; | |
244 } | |
245 | |
246 if(setButtonSensitivityWasSend) | |
247 { | |
248 dataOut.setButtonSensitivityNow = 0; | |
249 requestNecessary.ub.button = 1; | |
250 } | |
251 setButtonSensitivityWasSend = 0; | |
252 if(dataOut.setButtonSensitivityNow) | |
253 { | |
254 setButtonSensitivityWasSend = 1; | |
255 } | |
256 } | |
257 | |
258 | |
259 uint8_t DataEX_call(void) | |
260 { | |
261 uint8_t SPI_DMA_answer = 0; | |
141 | 262 |
87 | 263 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET); |
141 | 264 |
38 | 265 if(data_old__lost_connection_to_slave_counter_temp >= 3) |
266 { | |
267 data_old__lost_connection_to_slave_counter_temp = 0; | |
141 | 268 if((DataEX_check_header_and_footer_shifted()) && (data_old__lost_connection_to_slave_counter_retry == 0)) |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
269 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
270 HAL_SPI_Abort_IT(&cpu2DmaSpi); |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
271 } |
141 | 272 /* reset of own DMA does not work ==> request reset of slave dma */ |
149 | 273 if((DataEX_check_header_and_footer_shifted()) && (data_old__lost_connection_to_slave_counter_retry == 2)) |
141 | 274 { |
275 dataOut.header.checkCode[SPI_HEADER_INDEX_SLAVE] = 0xA5; | |
276 } | |
38 | 277 data_old__lost_connection_to_slave_counter_retry++; |
278 } | |
149 | 279 #if USE_OLD_SYNC_METHOD |
280 /* one cycle with NotChipSelect true to clear slave spi buffer */ | |
281 else | |
282 { | |
283 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET); | |
284 } | |
285 #endif | |
38 | 286 |
287 DataEx_call_helper_requests(); | |
288 | |
289 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_RESET); /* only for testing with Oscilloscope */ | |
290 | |
133
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
291 |
89 | 292 SPI_DMA_answer = HAL_SPI_TransmitReceive_DMA(&cpu2DmaSpi, (uint8_t *)&dataOut, (uint8_t *)&dataIn, EXCHANGE_BUFFERSIZE); |
38 | 293 if(SPI_DMA_answer != HAL_OK) |
149 | 294 { |
133
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
295 DataEX_Error_Handler(SPI_DMA_answer); |
149 | 296 } |
104 | 297 // HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); |
38 | 298 //HAL_Delay(3); |
299 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_SET); /* only for testing with Oscilloscope */ | |
300 | |
301 return 1; | |
302 } | |
303 | |
82 | 304 |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
305 static uint32_t SPI_CALLBACKS; |
82 | 306 uint32_t get_num_SPI_CALLBACKS(void){ |
307 return SPI_CALLBACKS; | |
308 } | |
309 | |
310 SDataExchangeSlaveToMaster* get_dataInPointer(void){ | |
311 return &dataIn; | |
312 } | |
313 | |
314 | |
315 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) | |
316 { | |
317 if(hspi == &cpu2DmaSpi) | |
318 { | |
154 | 319 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); |
82 | 320 SPI_CALLBACKS+=1; |
321 } | |
322 } | |
323 | |
324 | |
38 | 325 void DateEx_copy_to_dataOut(void) |
326 { | |
327 const SDiveState * pStateReal = stateRealGetPointer(); | |
328 SSettings *settings = settingsGetPointer(); | |
329 | |
330 if(get_globalState() == StStop) | |
331 dataOut.mode = MODE_SHUTDOWN; | |
332 else | |
333 dataOut.mode = 0; | |
334 | |
335 dataOut.diveModeInfo = pStateReal->diveSettings.diveMode; // hw 170215 | |
336 | |
337 memcpy(&dataOut.data.DeviceData, stateDeviceGetPointer(), sizeof(SDevice)); | |
338 | |
339 dataOut.data.VPMconservatism = pStateReal->diveSettings.vpm_conservatism; | |
340 dataOut.data.actualGas = pStateReal->lifeData.actualGas; | |
341 dataOut.data.ambient_pressure_mbar_ceiling = (pStateReal->decolistBuehlmann.output_ceiling_meter * 100) + (pStateReal->lifeData.pressure_surface_bar * 1000); | |
342 dataOut.data.divetimeToCreateLogbook = settings->divetimeToCreateLogbook; | |
343 dataOut.data.timeoutDiveReachedZeroDepth = settings->timeoutDiveReachedZeroDepth; | |
344 | |
345 dataOut.data.offsetPressureSensor_mbar = settings->offsetPressure_mbar; | |
346 dataOut.data.offsetTemperatureSensor_centiDegree = settings->offsetTemperature_centigrad; | |
347 | |
348 if((hardwareDataGetPointer()->primarySerial <= 32) || (((hardwareDataGetPointer()->primarySerial == 72) && (hardwareDataGetPointer()->secondarySerial == 15)))) | |
349 { | |
350 dataOut.revisionHardware = 0x00; | |
351 dataOut.revisionCRCx0x7A = 0x7A; | |
352 } | |
353 else | |
354 if(hardwareDataGetPointer()->primarySerial < 0xFFFF) | |
355 { | |
356 dataOut.revisionHardware = hardwareDataGetPointer()->revision8bit; | |
357 dataOut.revisionCRCx0x7A = hardwareDataGetPointer()->revision8bit ^ 0x7A; | |
358 } | |
359 else | |
360 { | |
361 dataOut.revisionHardware = 0xFF; | |
362 dataOut.revisionCRCx0x7A = 0xFF; | |
363 } | |
364 | |
365 if(DataEX_check_header_and_footer_ok() && !told_reset_logik_alles_ok) | |
366 { | |
367 MX_tell_reset_logik_alles_ok(); | |
368 told_reset_logik_alles_ok = 1; | |
369 } | |
370 | |
371 if(DataEX_check_header_and_footer_ok() && (dataIn.power_on_reset == 1)) | |
372 { | |
373 if(!wasUpdateNotPowerOn) | |
374 wasPowerOn = 1; | |
375 | |
376 RTC_DateTypeDef Sdate; | |
377 RTC_TimeTypeDef Stime; | |
378 | |
379 translateDate(settings->backup_localtime_rtc_dr, &Sdate); | |
380 translateTime(settings->backup_localtime_rtc_tr, &Stime); | |
381 | |
382 dataOut.data.newTime = Stime; | |
383 dataOut.setTimeNow = 1; | |
384 dataOut.data.newDate = Sdate; | |
385 dataOut.setDateNow = 1; | |
386 | |
387 settingsHelperButtonSens_keepPercentageValues(settingsGetPointerStandard()->ButtonResponsiveness[3], settings->ButtonResponsiveness); | |
388 setButtonResponsiveness(settings->ButtonResponsiveness); | |
389 | |
390 // hw 160720 new lastKnownBatteryPercentage | |
391 if(!wasUpdateNotPowerOn) | |
392 { | |
393 // dataOut.data.newBatteryGaugePercentageFloat = settingsGetPointer()->lastKnownBatteryPercentage; | |
394 dataOut.data.newBatteryGaugePercentageFloat = 0; | |
395 dataOut.setBatteryGaugeNow = 1; | |
396 } | |
397 } | |
398 } | |
399 | |
400 | |
401 void DataEX_copy_to_deco(void) | |
402 { | |
403 SDiveState * pStateUsed; | |
404 if(decoLock == DECO_CALC_running) | |
405 return; | |
406 if(stateUsed == stateRealGetPointer()) | |
407 pStateUsed = stateRealGetPointerWrite(); | |
90 | 408 else{ |
38 | 409 pStateUsed = stateSimGetPointerWrite(); |
90 | 410 } |
38 | 411 |
412 if(decoLock == DECO_CALC_init_as_is_start_of_dive) | |
413 { | |
414 vpm_init(&pStateUsed->vpm, pStateUsed->diveSettings.vpm_conservatism, 0, 0); | |
415 buehlmann_init(); | |
416 timer_init(); | |
417 resetEvents(); | |
418 pStateUsed->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = 0; | |
419 /* | |
420 * ToDo by Peter | |
421 * copy VPM stuff etc. pp. | |
422 * was void initDiveState(SDiveSettings * pDiveSettings, SVpm * pVpm); | |
423 */ | |
424 } | |
425 | |
426 if(decoLock == DECO_CALC_FINSHED_Buehlmann) | |
427 { | |
428 | |
429 } | |
430 switch(decoLock) | |
431 { | |
432 | |
433 //Deco_calculation finished | |
434 case DECO_CALC_FINSHED_vpm: | |
435 memcpy(&pStateUsed->decolistVPM,&stateDeco.decolistVPM,sizeof(SDecoinfo)); | |
436 pStateUsed->decolistVPM.tickstamp = HAL_GetTick(); | |
437 pStateUsed->vpm.deco_zone_reached = stateDeco.vpm.deco_zone_reached; | |
438 for(int i = 0; i< 16; i++) | |
439 { | |
440 pStateUsed->vpm.adjusted_critical_radius_he[i] = stateDeco.vpm.adjusted_critical_radius_he[i]; | |
441 pStateUsed->vpm.adjusted_critical_radius_n2[i] = stateDeco.vpm.adjusted_critical_radius_n2[i]; | |
442 pStateUsed->vpm.adjusted_crushing_pressure_he[i] = stateDeco.vpm.adjusted_crushing_pressure_he[i]; | |
443 pStateUsed->vpm.adjusted_crushing_pressure_n2[i] = stateDeco.vpm.adjusted_crushing_pressure_n2[i]; | |
444 pStateUsed->vpm.initial_allowable_gradient_he[i] = stateDeco.vpm.initial_allowable_gradient_he[i]; | |
445 pStateUsed->vpm.initial_allowable_gradient_n2[i] = stateDeco.vpm.initial_allowable_gradient_n2[i]; | |
446 pStateUsed->vpm.max_actual_gradient[i] = stateDeco.vpm.max_actual_gradient[i]; | |
447 } | |
448 break; | |
449 case DECO_CALC_FINSHED_Buehlmann: | |
450 memcpy(&pStateUsed->decolistBuehlmann,&stateDeco.decolistBuehlmann,sizeof(SDecoinfo)); | |
451 pStateUsed->decolistBuehlmann.tickstamp = HAL_GetTick(); | |
452 //Copy Data to be stored if regular Buehlmann, not FutureBuehlmann | |
453 pStateUsed->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = stateDeco.diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero; | |
454 break; | |
455 case DECO_CALC_FINSHED_FutureBuehlmann: | |
456 memcpy(&pStateUsed->decolistFutureBuehlmann,&stateDeco.decolistFutureBuehlmann,sizeof(SDecoinfo)); | |
457 pStateUsed->decolistFutureBuehlmann.tickstamp = HAL_GetTick(); | |
458 break; | |
459 case DECO_CALC_FINSHED_Futurevpm: | |
460 memcpy(&pStateUsed->decolistFutureVPM,&stateDeco.decolistFutureVPM,sizeof(SDecoinfo)); | |
461 pStateUsed->decolistFutureVPM.tickstamp = HAL_GetTick(); | |
462 break; | |
463 } | |
464 | |
465 //Copy Inputdata from stateReal to stateDeco | |
466 memcpy(&stateDeco.lifeData,&pStateUsed->lifeData,sizeof(SLifeData)); | |
467 memcpy(&stateDeco.diveSettings,&pStateUsed->diveSettings,sizeof(SDiveSettings)); | |
468 | |
469 stateDeco.vpm.deco_zone_reached = pStateUsed->vpm.deco_zone_reached; | |
470 // memcpy(&stateDeco.vpm,&pStateUsed->vpm,sizeof(SVpm)); | |
471 for(int i = 0; i< 16; i++) | |
472 { | |
473 stateDeco.vpm.max_crushing_pressure_he[i] = pStateUsed->vpm.max_crushing_pressure_he[i]; | |
474 stateDeco.vpm.max_crushing_pressure_n2[i] = pStateUsed->vpm.max_crushing_pressure_n2[i]; | |
475 stateDeco.vpm.adjusted_critical_radius_he[i] = pStateUsed->vpm.adjusted_critical_radius_he[i]; | |
476 stateDeco.vpm.adjusted_critical_radius_n2[i] = pStateUsed->vpm.adjusted_critical_radius_n2[i]; | |
477 } | |
478 decoLock = DECO_CALC_ready; | |
479 } | |
480 | |
481 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
482 static void DataEX_helper_copy_deviceData(SDeviceLine *lineWrite, const SDeviceLine *lineRead) |
38 | 483 { |
484 lineWrite->date_rtc_dr = lineRead->date_rtc_dr; | |
485 lineWrite->time_rtc_tr = lineRead->time_rtc_tr; | |
486 lineWrite->value_int32 = lineRead->value_int32; | |
487 } | |
488 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
489 static void DataEX_helper_SetTime(RTC_TimeTypeDef inStimestructure, uint32_t *outTimetmpreg) |
38 | 490 { |
491 inStimestructure.TimeFormat = RTC_HOURFORMAT_24; | |
492 | |
493 *outTimetmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(inStimestructure.Hours) << 16U) | \ | |
494 ((uint32_t)RTC_ByteToBcd2(inStimestructure.Minutes) << 8U) | \ | |
495 ((uint32_t)RTC_ByteToBcd2(inStimestructure.Seconds)) | \ | |
496 (((uint32_t)inStimestructure.TimeFormat) << 16U)); | |
497 } | |
498 | |
499 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
500 static void DataEX_helper_SetDate(RTC_DateTypeDef inSdatestructure, uint32_t *outDatetmpreg) |
38 | 501 { |
502 *outDatetmpreg = (((uint32_t)RTC_ByteToBcd2(inSdatestructure.Year) << 16U) | \ | |
503 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Month) << 8U) | \ | |
504 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Date)) | \ | |
505 ((uint32_t)inSdatestructure.WeekDay << 13U)); | |
506 } | |
507 | |
508 | |
509 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
510 static void DataEX_helper_set_Unknown_Date_deviceData(SDeviceLine *lineWrite) |
38 | 511 { |
512 RTC_DateTypeDef sdatestructure; | |
513 RTC_TimeTypeDef stimestructure; | |
514 | |
515 stimestructure.Hours = 1; | |
516 stimestructure.Minutes = 0; | |
517 stimestructure.Seconds = 0; | |
518 | |
519 sdatestructure.Date = 1; | |
520 sdatestructure.Month = 1; | |
521 sdatestructure.Year = 16; | |
522 setWeekday(&sdatestructure); | |
523 | |
524 DataEX_helper_SetTime(stimestructure, &lineWrite->time_rtc_tr); | |
525 DataEX_helper_SetDate(sdatestructure, &lineWrite->date_rtc_dr); | |
526 } | |
527 | |
528 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
529 static uint8_t DataEX_helper_Check_And_Correct_Date_deviceData(SDeviceLine *lineWrite) |
38 | 530 { |
531 RTC_DateTypeDef sdatestructure; | |
532 RTC_TimeTypeDef stimestructure; | |
533 | |
534 // from lineWrite to structure | |
535 translateDate(lineWrite->date_rtc_dr, &sdatestructure); | |
536 translateTime(lineWrite->time_rtc_tr, &stimestructure); | |
537 | |
538 if( (sdatestructure.Year >= 15) | |
539 && (sdatestructure.Year <= 30) | |
540 && (sdatestructure.Month <= 12)) | |
541 return 0; | |
542 | |
543 | |
544 DataEX_helper_set_Unknown_Date_deviceData(lineWrite); | |
545 return 1; | |
546 } | |
547 | |
548 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
549 static uint8_t DataEX_helper_Check_And_Correct_Value_deviceData(SDeviceLine *lineWrite, int32_t from, int32_t to) |
38 | 550 { |
551 if(lineWrite->value_int32 >= from && lineWrite->value_int32 <= to) | |
552 return 0; | |
553 | |
554 if(lineWrite->value_int32 < from) | |
555 lineWrite->value_int32 = from; | |
556 else | |
557 lineWrite->value_int32 = to; | |
558 | |
559 DataEX_helper_set_Unknown_Date_deviceData(lineWrite); | |
560 return 0; | |
561 } | |
562 | |
563 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
564 static void DataEX_check_DeviceData(void) |
38 | 565 { |
566 SDevice *DeviceData = stateDeviceGetPointerWrite(); | |
567 | |
568 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->batteryChargeCompleteCycles); | |
569 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->batteryChargeCycles); | |
570 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->depthMaximum); | |
571 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->diveCycles); | |
572 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->hoursOfOperation); | |
573 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->temperatureMaximum); | |
574 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->temperatureMinimum); | |
575 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->voltageMinimum); | |
576 | |
577 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->batteryChargeCompleteCycles, 0, 10000); | |
578 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->batteryChargeCycles, 0, 20000); | |
579 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->depthMaximum, 0, (500*100)+1000); | |
580 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->diveCycles, 0, 20000); | |
581 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->hoursOfOperation, 0, 1000000); | |
582 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMaximum, -30*100, 150*100); | |
583 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMinimum, -30*100, 150*100); | |
584 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->voltageMinimum, -1*1000, 6*1000); | |
585 } | |
586 | |
587 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
588 static void DataEX_merge_DeviceData_and_store(void) |
38 | 589 { |
590 uint16_t dataLengthRead; | |
591 SDevice DeviceDataFlash; | |
592 SDevice *DeviceData = stateDeviceGetPointerWrite(); | |
593 | |
594 dataLengthRead = ext_flash_read_devicedata((uint8_t *)&DeviceDataFlash,sizeof(SDevice)); | |
595 | |
596 if(dataLengthRead == 0) | |
597 { | |
598 ext_flash_write_devicedata(); | |
599 return; | |
600 } | |
601 | |
602 /* max values */ | |
603 if(DeviceData->batteryChargeCompleteCycles.value_int32 < DeviceDataFlash.batteryChargeCompleteCycles.value_int32) | |
604 { | |
605 DataEX_helper_copy_deviceData(&DeviceData->batteryChargeCompleteCycles, &DeviceDataFlash.batteryChargeCompleteCycles); | |
606 } | |
607 if(DeviceData->batteryChargeCycles.value_int32 < DeviceDataFlash.batteryChargeCycles.value_int32) | |
608 { | |
609 DataEX_helper_copy_deviceData(&DeviceData->batteryChargeCycles, &DeviceDataFlash.batteryChargeCycles); | |
610 } | |
611 if(DeviceData->temperatureMaximum.value_int32 < DeviceDataFlash.temperatureMaximum.value_int32) | |
612 { | |
613 DataEX_helper_copy_deviceData(&DeviceData->temperatureMaximum, &DeviceDataFlash.temperatureMaximum); | |
614 } | |
615 if(DeviceData->depthMaximum.value_int32 < DeviceDataFlash.depthMaximum.value_int32) | |
616 { | |
617 DataEX_helper_copy_deviceData(&DeviceData->depthMaximum, &DeviceDataFlash.depthMaximum); | |
618 } | |
619 if(DeviceData->diveCycles.value_int32 < DeviceDataFlash.diveCycles.value_int32) | |
620 { | |
621 DataEX_helper_copy_deviceData(&DeviceData->diveCycles, &DeviceDataFlash.diveCycles); | |
622 } | |
623 | |
624 /* min values */ | |
625 if(DeviceData->temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32) | |
626 { | |
627 DataEX_helper_copy_deviceData(&DeviceData->temperatureMinimum, &DeviceDataFlash.temperatureMinimum); | |
628 } | |
629 // Voltage minimum, keep limit to 2.0 Volt; hw 09.09.2015 | |
630 if(DeviceData->voltageMinimum.value_int32 > DeviceDataFlash.voltageMinimum.value_int32) | |
631 { | |
632 if(DeviceDataFlash.voltageMinimum.value_int32 > 2000) // do not copy back 2000 and below | |
633 DataEX_helper_copy_deviceData(&DeviceData->voltageMinimum, &DeviceDataFlash.voltageMinimum); | |
634 } | |
635 if(DeviceData->voltageMinimum.value_int32 < 2000) | |
636 DeviceData->voltageMinimum.value_int32 = 2000; | |
637 | |
638 DataEX_check_DeviceData (); | |
639 ext_flash_write_devicedata(); | |
640 } | |
641 | |
642 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
643 static void DataEX_copy_to_DeviceData(void) |
38 | 644 { |
645 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn; | |
646 SDevice * pDeviceState = stateDeviceGetPointerWrite(); | |
647 | |
648 memcpy(pDeviceState, &dataInDevice->DeviceData[dataInDevice->boolDeviceData], sizeof(SDevice)); | |
649 } | |
650 | |
651 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
652 static void DataEX_copy_to_VpmRepetitiveData(void) |
38 | 653 { |
654 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn; | |
655 SVpmRepetitiveData * pVpmState = stateVpmRepetitiveDataGetPointerWrite(); | |
656 | |
657 if(dataInDevice->boolVpmRepetitiveDataValid) | |
658 { | |
659 memcpy(pVpmState, &dataInDevice->VpmRepetitiveData, sizeof(SVpmRepetitiveData)); | |
660 pVpmState->is_data_from_RTE_CPU = 1; | |
661 } | |
662 } | |
663 | |
664 | |
665 void DataEX_control_connection_while_asking_for_sleep(void) | |
666 { | |
667 if(!DataEX_check_header_and_footer_ok()) | |
668 { | |
669 if(DataEX_check_header_and_footer_devicedata()) | |
670 { | |
671 data_old__lost_connection_to_slave_counter_retry = 0; | |
672 data_old__lost_connection_to_slave_counter_temp = 0; | |
673 stateRealGetPointerWrite()->data_old__lost_connection_to_slave = 0; | |
674 } | |
675 else | |
676 { | |
677 stateRealGetPointerWrite()->data_old__lost_connection_to_slave = 1; | |
678 data_old__lost_connection_to_slave_counter_temp += 1; | |
679 data_old__lost_connection_to_slave_counter_total += 1; | |
680 } | |
681 } | |
682 } | |
683 | |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
684 #define AVERAGE_COUNT 4 |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
685 static float getSampleDepth(SDataExchangeSlaveToMaster *d, SDiveState *ds) |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
686 { |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
687 static uint8_t c = 0; |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
688 static float ambient[AVERAGE_COUNT] = {0}; |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
689 static float surface[AVERAGE_COUNT]= {0}; |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
690 static float depth[AVERAGE_COUNT]= {0}; |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
691 |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
692 ambient[c] = d->data[d->boolPressureData].pressure_mbar / 1000.0f; |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
693 surface[c] = d->data[d->boolPressureData].surface_mbar / 1000.0f; |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
694 float density = ((float)( 100 + settingsGetPointer()->salinity)) / 100.0f; |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
695 |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
696 ds->lifeData.pressure_ambient_bar = (ambient[0] + ambient[1] + ambient[2] + ambient[3])/4.0f; |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
697 ds->lifeData.pressure_surface_bar = (surface[0] + surface[1] + surface[2] + surface[3])/4.0f; |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
698 depth[c] = (ambient[c] - surface[c]) / (0.09807f * density); |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
699 |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
700 c++; |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
701 if (c == AVERAGE_COUNT) c = 0; |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
702 |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
703 return (depth[0] + depth[1] + depth[2] + depth[3])/4.0f; |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
704 } |
38 | 705 |
189
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
706 #define TEMP_AVERAGE_COUNT 3 |
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
707 static float getTemperature(SDataExchangeSlaveToMaster *d) |
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
708 { |
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
709 static uint8_t c = 0; |
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
710 static float temp[TEMP_AVERAGE_COUNT] = {0}; |
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
711 |
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
712 temp[c] = d->data[d->boolPressureData].temperature; |
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
713 |
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
714 c++; |
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
715 if (c == TEMP_AVERAGE_COUNT) c = 0; |
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
716 |
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
717 return (temp[0] + temp[1] + temp[2])/3.0f; |
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
718 } |
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
719 |
38 | 720 void DataEX_copy_to_LifeData(_Bool *modeChangeFlag) |
721 { | |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
722 SDiveState *pStateReal = stateRealGetPointerWrite(); |
38 | 723 static uint16_t getDeviceDataAfterStartOfMainCPU = 20; |
724 | |
725 /* internal sensor: HUD data | |
726 */ | |
727 for(int i=0;i<3;i++) | |
728 { | |
729 pStateReal->lifeData.ppO2Sensor_bar[i] = get_ppO2Sensor_bar(i); | |
730 pStateReal->lifeData.sensorVoltage_mV[i] = get_sensorVoltage_mV(i); | |
731 } | |
732 pStateReal->lifeData.HUD_battery_voltage_V = get_HUD_battery_voltage_V(); | |
733 | |
734 | |
735 // wireless - �ltere daten aufr�umen | |
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
736 for(int i=0;i<(2*NUM_GASES+1);i++) |
38 | 737 { |
738 if(pStateReal->lifeData.bottle_bar[i]) | |
739 { | |
740 if((pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] == 0) || (pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] > 60000)) | |
741 { | |
742 pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] = 0; | |
743 pStateReal->lifeData.bottle_bar[i] = 0; | |
744 } | |
745 else | |
746 pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] += 100; | |
747 } | |
748 } | |
749 | |
750 if(!DataEX_check_header_and_footer_ok()) | |
751 { | |
752 if(DataEX_check_header_and_footer_devicedata()) | |
753 { | |
754 DataEX_copy_to_DeviceData(); | |
755 DataEX_merge_DeviceData_and_store(); | |
756 DataEX_copy_to_VpmRepetitiveData(); | |
757 data_old__lost_connection_to_slave_counter_temp = 0; | |
758 data_old__lost_connection_to_slave_counter_retry = 0; | |
759 pStateReal->data_old__lost_connection_to_slave = 0; | |
760 } | |
761 else | |
762 { | |
763 pStateReal->data_old__lost_connection_to_slave = 1; | |
764 data_old__lost_connection_to_slave_counter_temp += 1; | |
765 data_old__lost_connection_to_slave_counter_total += 1; | |
766 } | |
767 return; | |
768 } | |
141 | 769 else /* RX data OK */ |
770 { | |
771 data_old__lost_connection_to_slave_counter_temp = 0; | |
772 data_old__lost_connection_to_slave_counter_retry = 0; | |
773 pStateReal->data_old__lost_connection_to_slave = 0; | |
774 } | |
38 | 775 |
141 | 776 /* update SPI communication tokens */ |
777 dataOut.header.checkCode[SPI_HEADER_INDEX_SLAVE] = dataIn.header.checkCode[SPI_HEADER_INDEX_SLAVE]; | |
778 dataOut.header.checkCode[SPI_HEADER_INDEX_MASTER] = (dataOut.header.checkCode[SPI_HEADER_INDEX_MASTER] + 1) & 0x7F; | |
779 | |
38 | 780 if(getDeviceDataAfterStartOfMainCPU) |
781 { | |
782 getDeviceDataAfterStartOfMainCPU--; | |
783 if(getDeviceDataAfterStartOfMainCPU == 0) | |
784 { | |
785 dataOut.getDeviceDataNow = 1; | |
141 | 786 getDeviceDataAfterStartOfMainCPU = 10*60*10; /* * 100ms = 60 second => update device data every 10 minutes */ |
38 | 787 } |
788 } | |
789 | |
790 /* new 151207 hw */ | |
791 if(requestNecessary.uw != 0) | |
792 { | |
793 if(((dataIn.confirmRequest.uw) & CRBUTTON) != 0) | |
794 { | |
795 requestNecessary.ub.button = 0; | |
796 } | |
797 | |
798 if(requestNecessary.ub.button == 1) | |
799 { | |
800 setButtonResponsiveness(settingsGetPointer()->ButtonResponsiveness); | |
801 } | |
802 } | |
803 requestNecessary.uw = 0; // clear all | |
804 | |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
805 float meter = 0; |
38 | 806 SSettings *pSettings; |
149 | 807 |
38 | 808 /* uint8_t IAmStolenPleaseKillMe; |
809 */ | |
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
810 pSettings = settingsGetPointer(); |
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
811 |
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
812 if(pSettings->IAmStolenPleaseKillMe > 3) |
38 | 813 { |
814 pSettings->salinity = 0; | |
815 dataIn.data[dataIn.boolPressureData].surface_mbar = 999; | |
816 dataIn.data[dataIn.boolPressureData].pressure_mbar = 98971; | |
817 dataIn.mode = MODE_DIVE; | |
818 } | |
819 | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
820 if(pStateReal->data_old__lost_connection_to_slave == 0) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
821 { |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
822 meter = getSampleDepth(&dataIn, pStateReal); |
38 | 823 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
824 pStateReal->pressure_uTick_old = pStateReal->pressure_uTick_new; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
825 pStateReal->pressure_uTick_new = dataIn.data[dataIn.boolPressureData].pressure_uTick; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
826 pStateReal->pressure_uTick_local_new = HAL_GetTick(); |
38 | 827 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
828 pStateReal->lifeData.dateBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_dr; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
829 pStateReal->lifeData.timeBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_tr; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
830 } |
38 | 831 dataOut.setAccidentFlag = 0; |
832 | |
141 | 833 if(pStateReal->data_old__lost_connection_to_slave == 0) |
38 | 834 { |
141 | 835 //Start of diveMode? |
836 if(pStateReal->mode != MODE_DIVE && dataIn.mode == MODE_DIVE) | |
837 { | |
838 if(modeChangeFlag) | |
839 { | |
840 *modeChangeFlag = 1; | |
841 } | |
842 if(stateUsed == stateSimGetPointer()) | |
38 | 843 { |
844 simulation_exit(); | |
845 } | |
141 | 846 // new 170508 |
38 | 847 settingsGetPointer()->bluetoothActive = 0; |
848 MX_Bluetooth_PowerOff(); | |
849 //Init dive Mode | |
141 | 850 decoLock = DECO_CALC_init_as_is_start_of_dive; |
851 pStateReal->lifeData.boolResetAverageDepth = 1; | |
852 pStateReal->lifeData.boolResetStopwatch = 1; | |
38 | 853 } |
141 | 854 |
197
c853f5d23bb7
cleanup: fix (harmless) use before assign
Jan Mulder <jlmulder@xs4all.nl>
parents:
189
diff
changeset
|
855 pStateReal->lifeData.cns = dataIn.data[dataIn.boolToxicData].cns; |
c853f5d23bb7
cleanup: fix (harmless) use before assign
Jan Mulder <jlmulder@xs4all.nl>
parents:
189
diff
changeset
|
856 pStateReal->lifeData.otu = dataIn.data[dataIn.boolToxicData].otu; |
c853f5d23bb7
cleanup: fix (harmless) use before assign
Jan Mulder <jlmulder@xs4all.nl>
parents:
189
diff
changeset
|
857 pStateReal->lifeData.no_fly_time_minutes = dataIn.data[dataIn.boolToxicData].no_fly_time_minutes; |
c853f5d23bb7
cleanup: fix (harmless) use before assign
Jan Mulder <jlmulder@xs4all.nl>
parents:
189
diff
changeset
|
858 pStateReal->lifeData.desaturation_time_minutes = dataIn.data[dataIn.boolToxicData].desaturation_time_minutes; |
c853f5d23bb7
cleanup: fix (harmless) use before assign
Jan Mulder <jlmulder@xs4all.nl>
parents:
189
diff
changeset
|
859 |
141 | 860 //End of diveMode? |
861 if(pStateReal->mode == MODE_DIVE && dataIn.mode != MODE_DIVE) | |
862 { | |
863 if(modeChangeFlag) | |
864 { | |
865 *modeChangeFlag = 1; | |
866 } | |
867 createDiveSettings(); | |
38 | 868 |
141 | 869 if(pStateReal->warnings.cnsHigh) |
870 { | |
871 if(pStateReal->lifeData.cns >= 130) | |
872 dataOut.setAccidentFlag += ACCIDENT_CNSLVL2; | |
873 else if(pStateReal->lifeData.cns >= 100) | |
874 dataOut.setAccidentFlag += ACCIDENT_CNS; | |
875 } | |
876 if(pStateReal->warnings.decoMissed) | |
877 dataOut.setAccidentFlag += ACCIDENT_DECOSTOP; | |
878 } | |
879 pStateReal->mode = dataIn.mode; | |
880 pStateReal->chargeStatus = dataIn.chargeStatus; | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
881 |
141 | 882 if(is_ambient_pressure_close_to_surface(&pStateReal->lifeData)) |
883 { | |
884 pStateReal->lifeData.depth_meter = 0; | |
885 } | |
886 else | |
887 { | |
888 pStateReal->lifeData.depth_meter = meter; | |
889 } | |
890 | |
189
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
891 pStateReal->lifeData.temperature_celsius = getTemperature(&dataIn); |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
892 pStateReal->lifeData.ascent_rate_meter_per_min = dataIn.data[dataIn.boolPressureData].ascent_rate_meter_per_min; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
893 if(pStateReal->mode != MODE_DIVE) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
894 pStateReal->lifeData.max_depth_meter = 0; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
895 else |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
896 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
897 if(meter > pStateReal->lifeData.max_depth_meter) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
898 pStateReal->lifeData.max_depth_meter = meter; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
899 } |
38 | 900 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
901 if(dataIn.accidentFlags & ACCIDENT_DECOSTOP) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
902 pStateReal->decoMissed_at_the_end_of_dive = 1; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
903 if(dataIn.accidentFlags & ACCIDENT_CNS) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
904 pStateReal->cnsHigh_at_the_end_of_dive = 1; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
905 |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
906 pStateReal->lifeData.dive_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].divetime_seconds; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
907 pStateReal->lifeData.dive_time_seconds_without_surface_time = (int32_t)dataIn.data[dataIn.boolTimeData].dive_time_seconds_without_surface_time; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
908 pStateReal->lifeData.counterSecondsShallowDepth = dataIn.data[dataIn.boolTimeData].counterSecondsShallowDepth; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
909 pStateReal->lifeData.surface_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].surfacetime_seconds; |
38 | 910 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
911 pStateReal->lifeData.compass_heading = dataIn.data[dataIn.boolCompassData].compass_heading; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
912 if(settingsGetPointer()->FlipDisplay) /* consider that diver is targeting into the opposite direction */ |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
913 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
914 pStateReal->lifeData.compass_heading -= 180.0; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
915 if (pStateReal->lifeData.compass_heading < 0) pStateReal->lifeData.compass_heading +=360.0; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
916 } |
109
65a6e352ce08
Consider computer heading in case of a flipped display
Ideenmodellierer
parents:
51
diff
changeset
|
917 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
918 pStateReal->lifeData.compass_roll = dataIn.data[dataIn.boolCompassData].compass_roll; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
919 pStateReal->lifeData.compass_pitch = dataIn.data[dataIn.boolCompassData].compass_pitch; |
38 | 920 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
921 pStateReal->lifeData.compass_DX_f = dataIn.data[dataIn.boolCompassData].compass_DX_f; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
922 pStateReal->lifeData.compass_DY_f = dataIn.data[dataIn.boolCompassData].compass_DY_f; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
923 pStateReal->lifeData.compass_DZ_f = dataIn.data[dataIn.boolCompassData].compass_DZ_f; |
38 | 924 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
925 pStateReal->compass_uTick_old = pStateReal->compass_uTick_new; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
926 pStateReal->compass_uTick_new = dataIn.data[dataIn.boolCompassData].compass_uTick; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
927 pStateReal->compass_uTick_local_new = HAL_GetTick(); |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
928 |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
929 memcpy(pStateReal->lifeData.tissue_nitrogen_bar, dataIn.data[dataIn.boolTisssueData].tissue_nitrogen_bar,sizeof(pStateReal->lifeData.tissue_nitrogen_bar)); |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
930 memcpy(pStateReal->lifeData.tissue_helium_bar, dataIn.data[dataIn.boolTisssueData].tissue_helium_bar,sizeof(pStateReal->lifeData.tissue_helium_bar)); |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
931 |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
932 if(pStateReal->mode == MODE_DIVE) |
38 | 933 { |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
934 for(int i= 0; i <16; i++) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
935 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
936 pStateReal->vpm.max_crushing_pressure_he[i] = dataIn.data[dataIn.boolCrushingData].max_crushing_pressure_he[i]; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
937 pStateReal->vpm.max_crushing_pressure_n2[i] = dataIn.data[dataIn.boolCrushingData].max_crushing_pressure_n2[i]; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
938 pStateReal->vpm.adjusted_critical_radius_he[i] = dataIn.data[dataIn.boolCrushingData].adjusted_critical_radius_he[i]; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
939 pStateReal->vpm.adjusted_critical_radius_n2[i] = dataIn.data[dataIn.boolCrushingData].adjusted_critical_radius_n2[i]; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
940 } |
38 | 941 } |
942 | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
943 /* battery and ambient light sensors |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
944 */ |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
945 pStateReal->lifeData.ambient_light_level = dataIn.data[dataIn.boolAmbientLightData].ambient_light_level; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
946 pStateReal->lifeData.battery_charge = dataIn.data[dataIn.boolBatteryData].battery_charge; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
947 pStateReal->lifeData.battery_voltage = dataIn.data[dataIn.boolBatteryData].battery_voltage; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
948 } |
38 | 949 |
950 /* apnea specials | |
951 */ | |
952 if(pStateReal->diveSettings.diveMode == DIVEMODE_Apnea) | |
953 { | |
954 if(pStateReal->mode != MODE_DIVE) | |
955 { | |
956 pStateReal->lifeData.apnea_total_max_depth_meter = 0; | |
957 pStateReal->lifeData.apnea_last_dive_time_seconds = 0; | |
958 pStateReal->lifeData.apnea_last_max_depth_meter = 0; | |
959 } | |
960 else | |
961 { | |
962 if(pStateReal->lifeData.max_depth_meter > pStateReal->lifeData.apnea_total_max_depth_meter) | |
963 pStateReal->lifeData.apnea_total_max_depth_meter = pStateReal->lifeData.max_depth_meter; | |
964 } | |
965 | |
966 if(pStateReal->lifeData.dive_time_seconds > 15) | |
967 { | |
968 pStateReal->lifeData.apnea_last_dive_time_seconds = pStateReal->lifeData.dive_time_seconds; | |
969 } | |
970 | |
971 if(pStateReal->lifeData.counterSecondsShallowDepth) | |
972 { | |
973 if(pStateReal->lifeData.max_depth_meter > 1.5f) | |
974 { | |
975 pStateReal->lifeData.apnea_last_max_depth_meter = pStateReal->lifeData.max_depth_meter; | |
976 } | |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
977 // reset max_depth_meter, average_depth_meter and internal values |
38 | 978 pStateReal->lifeData.max_depth_meter = 0; |
979 pStateReal->lifeData.boolResetAverageDepth = 1; | |
980 pStateReal->lifeData.boolResetStopwatch = 1; | |
981 } | |
982 } | |
983 | |
984 /* average depth | |
985 */ | |
986 float *AvgDepthValue = &pStateReal->lifeData.average_depth_meter; | |
987 float DepthNow = pStateReal->lifeData.depth_meter; | |
988 uint32_t *AvgDepthCount = &pStateReal->lifeData.internal.average_depth_meter_Count; | |
989 uint32_t *AvgDepthTimer = &pStateReal->lifeData.internal.average_depth_last_update_dive_time_seconds_without_surface_time; | |
990 uint32_t AvgSecondsSinceLast; | |
991 uint32_t DiveTime = pStateReal->lifeData.dive_time_seconds_without_surface_time; | |
992 | |
993 if(pStateReal->lifeData.boolResetAverageDepth) | |
994 { | |
995 *AvgDepthValue = DepthNow; | |
996 *AvgDepthCount = 1; | |
997 *AvgDepthTimer = DiveTime; | |
998 pStateReal->lifeData.boolResetAverageDepth = 0; | |
999 } | |
1000 else if (DiveTime > *AvgDepthTimer) | |
1001 { | |
1002 AvgSecondsSinceLast = DiveTime - *AvgDepthTimer; | |
1003 for(int i=0;i<AvgSecondsSinceLast;i++) | |
1004 { | |
1005 *AvgDepthValue = (*AvgDepthValue * *AvgDepthCount + DepthNow) / (*AvgDepthCount + 1); | |
1006 *AvgDepthCount += 1; | |
1007 } | |
1008 *AvgDepthTimer = DiveTime; | |
1009 } | |
1010 if(*AvgDepthCount == 0) | |
1011 *AvgDepthValue = 0; | |
1012 | |
1013 | |
1014 /* stop watch | |
1015 */ | |
1016 if(pStateReal->lifeData.boolResetStopwatch) | |
1017 { | |
1018 pStateReal->lifeData.internal.stopwatch_start_at_this_dive_time_seconds = pStateReal->lifeData.dive_time_seconds; | |
1019 pStateReal->lifeData.boolResetStopwatch = 0; | |
1020 } | |
1021 pStateReal->lifeData.stopwatch_seconds = pStateReal->lifeData.dive_time_seconds - pStateReal->lifeData.internal.stopwatch_start_at_this_dive_time_seconds; | |
1022 | |
1023 /* wireless data | |
1024 */ | |
1025 uint16_t wirelessData[4][3]; | |
1026 for(int i=0;i<4;i++) | |
1027 { | |
1028 pStateReal->lifeData.wireless_data[i].ageInMilliSeconds = dataIn.data[dataIn.boolWirelessData].wireless_data[i].ageInMilliSeconds; | |
1029 pStateReal->lifeData.wireless_data[i].status = dataIn.data[dataIn.boolWirelessData].wireless_data[i].status; | |
1030 pStateReal->lifeData.wireless_data[i].numberOfBytes = dataIn.data[dataIn.boolWirelessData].wireless_data[i].numberOfBytes; | |
1031 for(int j=0;j<12;j++) | |
1032 pStateReal->lifeData.wireless_data[i].data[j] = dataIn.data[dataIn.boolWirelessData].wireless_data[i].data[j]; | |
1033 } | |
1034 | |
1035 // neu 160412 | |
1036 for(int i=0;i<4;i++) | |
1037 { | |
1038 if(pStateReal->lifeData.wireless_data[i].numberOfBytes == 10) | |
1039 { | |
1040 wirelessData[i][0] = (pStateReal->lifeData.wireless_data[i].data[0] >> 4) & 0x7F; | |
1041 wirelessData[i][1] = 0; | |
1042 wirelessData[i][2] = pStateReal->lifeData.wireless_data[i].ageInMilliSeconds; | |
1043 } | |
1044 else | |
1045 { | |
1046 wirelessData[i][0] = 0; | |
1047 wirelessData[i][1] = 0; | |
1048 wirelessData[i][2] = 0; | |
1049 } | |
1050 } | |
1051 | |
1052 // aussortieren doppelte ids, j�ngster datensatz ist relevant | |
1053 for(int i=0;i<3;i++) | |
1054 { | |
1055 if(wirelessData[i][0]) | |
1056 { | |
1057 for(int j=i+1; j<4; j++) | |
1058 { | |
1059 if(wirelessData[i][0] == wirelessData[j][0]) | |
1060 { | |
1061 if(wirelessData[i][2] > wirelessData[j][2]) | |
1062 { | |
1063 wirelessData[i][0] = wirelessData[j][0]; | |
1064 wirelessData[i][1] = wirelessData[j][1]; | |
1065 wirelessData[i][2] = wirelessData[j][2]; | |
1066 } | |
1067 wirelessData[j][0] = 0; | |
1068 wirelessData[j][1] = 0; | |
1069 wirelessData[j][2] = 0; | |
1070 } | |
1071 } | |
1072 } | |
1073 } | |
1074 | |
1075 /* PIC data | |
1076 */ | |
1077 for(int i=0;i<4;i++) | |
1078 { | |
1079 pStateReal->lifeData.buttonPICdata[i] = dataIn.data[dataIn.boolPICdata].button_setting[i]; | |
1080 } | |
1081 | |
1082 /* sensorErrors | |
1083 */ | |
1084 pStateReal->sensorErrorsRTE = dataIn.sensorErrors; | |
1085 } | |
1086 | |
1087 | |
1088 uint8_t DataEX_check_RTE_version__needs_update(void) | |
1089 { | |
1090 if(data_old__lost_connection_to_slave_counter_retry > 10) | |
1091 return 1; | |
1092 else | |
1093 { | |
1094 if(stateRealGetPointer()->data_old__lost_connection_to_slave == 0) | |
1095 { | |
1096 setActualRTEversion(dataIn.RTE_VERSION_high, dataIn.RTE_VERSION_low); | |
1097 | |
1098 if(RTEminimum_required_high() < dataIn.RTE_VERSION_high) | |
1099 return 0; | |
1100 else | |
1101 if((RTEminimum_required_high() == dataIn.RTE_VERSION_high) && (RTEminimum_required_low() <= dataIn.RTE_VERSION_low)) | |
1102 return 0; | |
1103 else | |
1104 return 1; | |
1105 } | |
1106 else | |
1107 return 0; | |
1108 } | |
1109 } | |
1110 | |
1111 | |
1112 /* Private functions ---------------------------------------------------------*/ | |
1113 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
1114 /* Check if there is an empty frame provided by RTE (all 0) or even no data provided by RTE (all 0xFF) |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1115 * If that is not the case the DMA is somehow not in sync |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1116 */ |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
1117 static uint8_t DataEX_check_header_and_footer_shifted() |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1118 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1119 uint8_t ret = 1; |
141 | 1120 if((dataIn.footer.checkCode[0] == 0x00) |
1121 && (dataIn.footer.checkCode[1] == 0x00) | |
1122 && (dataIn.footer.checkCode[2] == 0x00) | |
1123 && (dataIn.footer.checkCode[3] == 0x00)) { ret = 0; } | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1124 |
141 | 1125 if((dataIn.footer.checkCode[0] == 0xff) |
1126 && (dataIn.footer.checkCode[1] == 0xff) | |
1127 && (dataIn.footer.checkCode[2] == 0xff) | |
1128 && (dataIn.footer.checkCode[3] == 0xff)) { ret = 0; } | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1129 |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1130 return ret; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1131 } |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1132 |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
1133 static uint8_t DataEX_check_header_and_footer_ok(void) |
38 | 1134 { |
1135 if(dataIn.header.checkCode[0] != 0xA1) | |
1136 return 0; | |
141 | 1137 #if USE_OLD_HEADER_FORMAT |
38 | 1138 if(dataIn.header.checkCode[1] != 0xA2) |
1139 return 0; | |
1140 if(dataIn.header.checkCode[2] != 0xA3) | |
1141 return 0; | |
141 | 1142 #endif |
38 | 1143 if(dataIn.header.checkCode[3] != 0xA4) |
1144 return 0; | |
1145 if(dataIn.footer.checkCode[0] != 0xE1) | |
1146 return 0; | |
1147 if(dataIn.footer.checkCode[1] != 0xE2) | |
1148 return 0; | |
1149 if(dataIn.footer.checkCode[2] != 0xE3) | |
1150 return 0; | |
1151 if(dataIn.footer.checkCode[3] != 0xE4) | |
1152 return 0; | |
1153 | |
1154 return 1; | |
1155 } | |
1156 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
1157 static uint8_t DataEX_check_header_and_footer_devicedata(void) |
38 | 1158 { |
1159 if(dataIn.header.checkCode[0] != 0xDF) | |
1160 return 0; | |
1161 if(dataIn.header.checkCode[1] != 0xDE) | |
1162 return 0; | |
1163 if(dataIn.header.checkCode[2] != 0xDD) | |
1164 return 0; | |
1165 if(dataIn.header.checkCode[3] != 0xDC) | |
1166 return 0; | |
1167 if(dataIn.footer.checkCode[0] != 0xE1) | |
1168 return 0; | |
1169 if(dataIn.footer.checkCode[1] != 0xE2) | |
1170 return 0; | |
1171 if(dataIn.footer.checkCode[2] != 0xE3) | |
1172 return 0; | |
1173 if(dataIn.footer.checkCode[3] != 0xE4) | |
1174 return 0; | |
1175 | |
1176 return 1; | |
1177 } |