Mercurial > public > ostc4
annotate Discovery/Src/data_exchange_main.c @ 431:49c3c5f0d0cb
make a 1.5.3 for tests
author | heinrichsweikamp |
---|---|
date | Tue, 18 Feb 2020 09:58:52 +0100 |
parents | 3f7d80f37bfc |
children | 079f32a8e68c |
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 |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
93 static uint8_t DeviceDataUpdated = 0; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
94 |
38 | 95 /* Private types -------------------------------------------------------------*/ |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
96 #define UNKNOWN_TIME_HOURS 1 |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
97 #define UNKNOWN_TIME_MINUTES 0 |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
98 #define UNKNOWN_TIME_SECOND 0 |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
99 #define UNKNOWN_DATE_DAY 1 |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
100 #define UNKNOWN_DATE_MONTH 1 |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
101 #define UNKNOWN_DATE_YEAR 16 |
38 | 102 |
103 /* Private function prototypes -----------------------------------------------*/ | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
104 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
|
105 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
|
106 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
|
107 static void DataEX_check_DeviceData(void); |
38 | 108 |
109 /* Exported functions --------------------------------------------------------*/ | |
110 uint8_t DataEX_was_power_on(void) | |
111 { | |
112 return wasPowerOn; | |
113 } | |
114 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
115 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
|
116 static uint8_t last_error_DataEX_Error_Handler = 0; |
38 | 117 |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
118 static void DataEX_Error_Handler(uint8_t answer) |
38 | 119 { |
120 count_DataEX_Error_Handler++; | |
121 last_error_DataEX_Error_Handler = answer; | |
133
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
122 |
156
1fbdb45db701
Removed special indicator for DMA transfer error
Ideenmodellierer
parents:
154
diff
changeset
|
123 /* 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
|
124 /* ==> Abort data exchange to enable a new RX / TX cycle */ |
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
125 if(answer == HAL_BUSY) |
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
126 { |
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
127 HAL_SPI_Abort_IT(&cpu2DmaSpi); |
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
128 } |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
129 |
38 | 130 return; |
131 } | |
132 | |
133 | |
134 uint32_t DataEX_lost_connection_count(void) | |
135 { | |
136 return data_old__lost_connection_to_slave_counter_total; | |
137 } | |
138 | |
139 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
140 SDataReceiveFromMaster *dataOutGetPointer(void) |
38 | 141 { |
142 return &dataOut; | |
143 } | |
144 | |
145 void DataEX_init(void) | |
146 { | |
147 SDiveState * pStateReal = stateRealGetPointerWrite(); | |
99 | 148 pStateReal->data_old__lost_connection_to_slave = 0; //initial value |
38 | 149 data_old__lost_connection_to_slave_counter_temp = 0; |
150 data_old__lost_connection_to_slave_counter_total = 0; | |
407
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
151 DeviceDataUpdated = 0; |
38 | 152 |
153 memset((void *)&dataOut, 0, sizeof(SDataReceiveFromMaster)); | |
154 | |
155 dataOut.header.checkCode[0] = 0xBB; | |
208 | 156 dataOut.header.checkCode[1] = SPI_RX_STATE_OK; |
157 dataOut.header.checkCode[2] = SPI_RX_STATE_OK; | |
38 | 158 dataOut.header.checkCode[3] = 0xBB; |
159 | |
160 dataOut.footer.checkCode[0] = 0xF4; | |
161 dataOut.footer.checkCode[1] = 0xF3; | |
162 dataOut.footer.checkCode[2] = 0xF2; | |
163 dataOut.footer.checkCode[3] = 0xF1; | |
164 } | |
165 | |
166 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
167 static void DataEx_call_helper_requests(void) |
38 | 168 { |
169 static uint8_t setDateWasSend = 0; | |
170 static uint8_t setTimeWasSend = 0; | |
171 static uint8_t calibrateCompassWasSend = 0; | |
172 static uint8_t setButtonSensitivityWasSend = 0; | |
173 static uint8_t clearDecoWasSend = 0; | |
174 static uint8_t getDeviceDataWasSend = 0; | |
175 static uint8_t setAccidentFlagWasSend = 0; | |
176 static uint8_t setEndDiveWasSend = 0; | |
177 | |
178 if(getDeviceDataWasSend) | |
179 { | |
180 dataOut.getDeviceDataNow = 0; | |
181 requestNecessary.ub.devicedata = 1; | |
182 } | |
183 getDeviceDataWasSend = 0; | |
184 if(dataOut.getDeviceDataNow) | |
185 { | |
186 getDeviceDataWasSend = 1; | |
187 } | |
188 | |
189 if(setEndDiveWasSend) | |
190 { | |
191 dataOut.setEndDive = 0; | |
192 //requestNecessary.ub.XXX = 1; not implemented and no space here | |
193 } | |
194 setEndDiveWasSend = 0; | |
195 if(dataOut.setEndDive) | |
196 { | |
197 setEndDiveWasSend = 1; | |
198 } | |
199 | |
200 if(setAccidentFlagWasSend) | |
201 { | |
202 dataOut.setAccidentFlag = 0; | |
203 requestNecessary.ub.accident = 1; | |
204 } | |
205 setAccidentFlagWasSend = 0; | |
206 if(dataOut.setAccidentFlag) | |
207 { | |
208 setAccidentFlagWasSend = 1; | |
209 } | |
210 | |
211 if(setDateWasSend) | |
212 { | |
213 dataOut.setDateNow = 0; | |
214 requestNecessary.ub.date = 1; | |
215 } | |
216 setDateWasSend = 0; | |
217 if(dataOut.setDateNow) | |
218 { | |
219 setDateWasSend = 1; | |
220 } | |
221 | |
222 if(setTimeWasSend) | |
223 { | |
224 dataOut.setTimeNow = 0; | |
225 requestNecessary.ub.time = 1; | |
226 } | |
227 setTimeWasSend = 0; | |
228 if(dataOut.setTimeNow) | |
229 { | |
230 setTimeWasSend = 1; | |
231 } | |
232 | |
233 if(calibrateCompassWasSend) | |
234 { | |
235 dataOut.calibrateCompassNow = 0; | |
236 requestNecessary.ub.compass = 1; | |
237 } | |
238 calibrateCompassWasSend = 0; | |
239 if(dataOut.calibrateCompassNow) | |
240 { | |
241 calibrateCompassWasSend = 1; | |
242 } | |
243 | |
244 if(clearDecoWasSend) | |
245 { | |
246 dataOut.clearDecoNow = 0; | |
247 requestNecessary.ub.clearDeco = 1; | |
248 } | |
249 if(dataOut.clearDecoNow) | |
250 { | |
251 clearDecoWasSend = 1; | |
252 } | |
253 | |
254 if(setButtonSensitivityWasSend) | |
255 { | |
256 dataOut.setButtonSensitivityNow = 0; | |
257 requestNecessary.ub.button = 1; | |
258 } | |
259 setButtonSensitivityWasSend = 0; | |
260 if(dataOut.setButtonSensitivityNow) | |
261 { | |
262 setButtonSensitivityWasSend = 1; | |
263 } | |
264 } | |
265 | |
266 | |
267 uint8_t DataEX_call(void) | |
268 { | |
208 | 269 static uint32_t RTEOfflineCnt = 0; |
270 static uint8_t SusppressCom = 0; | |
271 | |
38 | 272 uint8_t SPI_DMA_answer = 0; |
141 | 273 |
208 | 274 if(SusppressCom) |
38 | 275 { |
208 | 276 SusppressCom--; |
38 | 277 } |
149 | 278 else |
279 { | |
208 | 280 if(data_old__lost_connection_to_slave_counter_temp >= 2) /* error reaction is triggered whenever communication could not be reestablishen within two cycles */ |
281 { | |
282 data_old__lost_connection_to_slave_counter_temp = 0; | |
283 if(DataEX_check_header_and_footer_shifted()) | |
284 { | |
285 if(RTEOfflineCnt > 1) /* RTE restarted communication after a longer silent time => restart error handling to recover */ | |
286 { | |
287 data_old__lost_connection_to_slave_counter_retry = 0; | |
288 RTEOfflineCnt = 0; | |
289 } | |
38 | 290 |
208 | 291 /* We received shifted data. Step one. Reset DMA to see if the problem is located at main */ |
292 if (data_old__lost_connection_to_slave_counter_retry == 0) | |
293 { | |
294 HAL_SPI_Abort_IT(&cpu2DmaSpi); | |
295 } | |
296 /* reset of own DMA does not work ==> request reset of slave dma by indicating shifted receiption */ | |
297 if (data_old__lost_connection_to_slave_counter_retry == 1) | |
298 { | |
299 dataOut.header.checkCode[SPI_HEADER_INDEX_RX_STATE] = SPI_RX_STATE_SHIFTED; | |
300 } | |
301 | |
302 /* stop communication with RTE to trigger RTE timeout reaction */ | |
303 if (data_old__lost_connection_to_slave_counter_retry == 2) | |
304 { | |
305 SusppressCom = 3; | |
306 } | |
38 | 307 |
208 | 308 data_old__lost_connection_to_slave_counter_retry++; |
309 } | |
310 else | |
311 { | |
312 RTEOfflineCnt++; /* based on footer status the RTE does not seem to provide data in time */ | |
313 dataOut.header.checkCode[SPI_HEADER_INDEX_RX_STATE] = SPI_RX_STATE_OFFLINE; | |
314 } | |
315 } | |
316 #if USE_OLD_SYNC_METHOD | |
317 /* one cycle with NotChipSelect true to clear slave spi buffer */ | |
318 else | |
319 { | |
320 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET); | |
321 } | |
322 #endif | |
133
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
323 |
208 | 324 DataEx_call_helper_requests(); |
325 | |
326 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_RESET); /* only for testing with Oscilloscope */ | |
327 | |
328 if(SusppressCom == 0) | |
329 { | |
330 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET); | |
331 | |
332 SPI_DMA_answer = HAL_SPI_TransmitReceive_DMA(&cpu2DmaSpi, (uint8_t *)&dataOut, (uint8_t *)&dataIn, EXCHANGE_BUFFERSIZE); | |
333 if(SPI_DMA_answer != HAL_OK) | |
334 { | |
335 DataEX_Error_Handler(SPI_DMA_answer); | |
336 } | |
337 } | |
338 } | |
104 | 339 // HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); |
38 | 340 //HAL_Delay(3); |
341 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_SET); /* only for testing with Oscilloscope */ | |
342 | |
343 return 1; | |
344 } | |
345 | |
82 | 346 |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
347 static uint32_t SPI_CALLBACKS; |
82 | 348 uint32_t get_num_SPI_CALLBACKS(void){ |
349 return SPI_CALLBACKS; | |
350 } | |
351 | |
352 SDataExchangeSlaveToMaster* get_dataInPointer(void){ | |
353 return &dataIn; | |
354 } | |
355 | |
356 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) | |
357 { | |
358 if(hspi == &cpu2DmaSpi) | |
359 { | |
154 | 360 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); |
82 | 361 SPI_CALLBACKS+=1; |
362 } | |
363 } | |
364 | |
365 | |
38 | 366 void DateEx_copy_to_dataOut(void) |
367 { | |
368 const SDiveState * pStateReal = stateRealGetPointer(); | |
369 SSettings *settings = settingsGetPointer(); | |
370 | |
371 if(get_globalState() == StStop) | |
372 dataOut.mode = MODE_SHUTDOWN; | |
373 else | |
374 dataOut.mode = 0; | |
375 | |
376 dataOut.diveModeInfo = pStateReal->diveSettings.diveMode; // hw 170215 | |
377 | |
378 memcpy(&dataOut.data.DeviceData, stateDeviceGetPointer(), sizeof(SDevice)); | |
379 | |
380 dataOut.data.VPMconservatism = pStateReal->diveSettings.vpm_conservatism; | |
381 dataOut.data.actualGas = pStateReal->lifeData.actualGas; | |
382 dataOut.data.ambient_pressure_mbar_ceiling = (pStateReal->decolistBuehlmann.output_ceiling_meter * 100) + (pStateReal->lifeData.pressure_surface_bar * 1000); | |
383 dataOut.data.divetimeToCreateLogbook = settings->divetimeToCreateLogbook; | |
384 dataOut.data.timeoutDiveReachedZeroDepth = settings->timeoutDiveReachedZeroDepth; | |
385 | |
386 dataOut.data.offsetPressureSensor_mbar = settings->offsetPressure_mbar; | |
387 dataOut.data.offsetTemperatureSensor_centiDegree = settings->offsetTemperature_centigrad; | |
388 | |
389 if((hardwareDataGetPointer()->primarySerial <= 32) || (((hardwareDataGetPointer()->primarySerial == 72) && (hardwareDataGetPointer()->secondarySerial == 15)))) | |
390 { | |
391 dataOut.revisionHardware = 0x00; | |
392 dataOut.revisionCRCx0x7A = 0x7A; | |
393 } | |
394 else | |
395 if(hardwareDataGetPointer()->primarySerial < 0xFFFF) | |
396 { | |
397 dataOut.revisionHardware = hardwareDataGetPointer()->revision8bit; | |
398 dataOut.revisionCRCx0x7A = hardwareDataGetPointer()->revision8bit ^ 0x7A; | |
399 } | |
400 else | |
401 { | |
402 dataOut.revisionHardware = 0xFF; | |
403 dataOut.revisionCRCx0x7A = 0xFF; | |
404 } | |
405 | |
406 if(DataEX_check_header_and_footer_ok() && !told_reset_logik_alles_ok) | |
407 { | |
408 MX_tell_reset_logik_alles_ok(); | |
409 told_reset_logik_alles_ok = 1; | |
410 } | |
411 | |
412 if(DataEX_check_header_and_footer_ok() && (dataIn.power_on_reset == 1)) | |
413 { | |
414 if(!wasUpdateNotPowerOn) | |
415 wasPowerOn = 1; | |
416 | |
417 settingsHelperButtonSens_keepPercentageValues(settingsGetPointerStandard()->ButtonResponsiveness[3], settings->ButtonResponsiveness); | |
418 setButtonResponsiveness(settings->ButtonResponsiveness); | |
419 | |
420 // hw 160720 new lastKnownBatteryPercentage | |
421 if(!wasUpdateNotPowerOn) | |
422 { | |
423 // dataOut.data.newBatteryGaugePercentageFloat = settingsGetPointer()->lastKnownBatteryPercentage; | |
424 dataOut.data.newBatteryGaugePercentageFloat = 0; | |
425 dataOut.setBatteryGaugeNow = 1; | |
426 } | |
427 } | |
428 } | |
429 | |
430 | |
431 void DataEX_copy_to_deco(void) | |
432 { | |
433 if(decoLock == DECO_CALC_running) | |
434 return; | |
435 | |
436 if(decoLock == DECO_CALC_init_as_is_start_of_dive) | |
437 { | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
438 vpm_init(&stateUsedWrite->vpm, stateUsedWrite->diveSettings.vpm_conservatism, 0, 0); |
38 | 439 buehlmann_init(); |
440 timer_init(); | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
441 resetEvents(stateUsedWrite); |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
442 stateUsedWrite->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = 0; |
38 | 443 } |
444 | |
445 if(decoLock == DECO_CALC_FINSHED_Buehlmann) | |
446 { | |
447 | |
448 } | |
449 switch(decoLock) | |
450 { | |
451 | |
452 //Deco_calculation finished | |
453 case DECO_CALC_FINSHED_vpm: | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
454 memcpy(&stateUsedWrite->decolistVPM,&stateDeco.decolistVPM,sizeof(SDecoinfo)); |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
455 stateUsedWrite->decolistVPM.tickstamp = HAL_GetTick(); |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
456 stateUsedWrite->vpm.deco_zone_reached = stateDeco.vpm.deco_zone_reached; |
38 | 457 for(int i = 0; i< 16; i++) |
458 { | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
459 stateUsedWrite->vpm.adjusted_critical_radius_he[i] = stateDeco.vpm.adjusted_critical_radius_he[i]; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
460 stateUsedWrite->vpm.adjusted_critical_radius_n2[i] = stateDeco.vpm.adjusted_critical_radius_n2[i]; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
461 stateUsedWrite->vpm.adjusted_crushing_pressure_he[i] = stateDeco.vpm.adjusted_crushing_pressure_he[i]; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
462 stateUsedWrite->vpm.adjusted_crushing_pressure_n2[i] = stateDeco.vpm.adjusted_crushing_pressure_n2[i]; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
463 stateUsedWrite->vpm.initial_allowable_gradient_he[i] = stateDeco.vpm.initial_allowable_gradient_he[i]; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
464 stateUsedWrite->vpm.initial_allowable_gradient_n2[i] = stateDeco.vpm.initial_allowable_gradient_n2[i]; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
465 stateUsedWrite->vpm.max_actual_gradient[i] = stateDeco.vpm.max_actual_gradient[i]; |
38 | 466 } |
467 break; | |
468 case DECO_CALC_FINSHED_Buehlmann: | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
469 memcpy(&stateUsedWrite->decolistBuehlmann,&stateDeco.decolistBuehlmann,sizeof(SDecoinfo)); |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
470 stateUsedWrite->decolistBuehlmann.tickstamp = HAL_GetTick(); |
38 | 471 //Copy Data to be stored if regular Buehlmann, not FutureBuehlmann |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
472 stateUsedWrite->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; |
38 | 473 break; |
474 case DECO_CALC_FINSHED_FutureBuehlmann: | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
475 memcpy(&stateUsedWrite->decolistFutureBuehlmann,&stateDeco.decolistFutureBuehlmann,sizeof(SDecoinfo)); |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
476 stateUsedWrite->decolistFutureBuehlmann.tickstamp = HAL_GetTick(); |
38 | 477 break; |
478 case DECO_CALC_FINSHED_Futurevpm: | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
479 memcpy(&stateUsedWrite->decolistFutureVPM,&stateDeco.decolistFutureVPM,sizeof(SDecoinfo)); |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
480 stateUsedWrite->decolistFutureVPM.tickstamp = HAL_GetTick(); |
38 | 481 break; |
482 } | |
483 | |
484 //Copy Inputdata from stateReal to stateDeco | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
485 memcpy(&stateDeco.lifeData,&stateUsedWrite->lifeData,sizeof(SLifeData)); |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
486 memcpy(&stateDeco.diveSettings,&stateUsedWrite->diveSettings,sizeof(SDiveSettings)); |
38 | 487 |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
488 stateDeco.vpm.deco_zone_reached = stateUsedWrite->vpm.deco_zone_reached; |
38 | 489 // memcpy(&stateDeco.vpm,&pStateUsed->vpm,sizeof(SVpm)); |
490 for(int i = 0; i< 16; i++) | |
491 { | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
492 stateDeco.vpm.max_crushing_pressure_he[i] = stateUsedWrite->vpm.max_crushing_pressure_he[i]; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
493 stateDeco.vpm.max_crushing_pressure_n2[i] = stateUsedWrite->vpm.max_crushing_pressure_n2[i]; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
494 stateDeco.vpm.adjusted_critical_radius_he[i] = stateUsedWrite->vpm.adjusted_critical_radius_he[i]; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
495 stateDeco.vpm.adjusted_critical_radius_n2[i] = stateUsedWrite->vpm.adjusted_critical_radius_n2[i]; |
38 | 496 } |
497 decoLock = DECO_CALC_ready; | |
498 } | |
499 | |
500 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
501 static void DataEX_helper_copy_deviceData(SDeviceLine *lineWrite, const SDeviceLine *lineRead) |
38 | 502 { |
503 lineWrite->date_rtc_dr = lineRead->date_rtc_dr; | |
504 lineWrite->time_rtc_tr = lineRead->time_rtc_tr; | |
505 lineWrite->value_int32 = lineRead->value_int32; | |
506 } | |
507 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
508 static void DataEX_helper_SetTime(RTC_TimeTypeDef inStimestructure, uint32_t *outTimetmpreg) |
38 | 509 { |
510 inStimestructure.TimeFormat = RTC_HOURFORMAT_24; | |
511 | |
512 *outTimetmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(inStimestructure.Hours) << 16U) | \ | |
513 ((uint32_t)RTC_ByteToBcd2(inStimestructure.Minutes) << 8U) | \ | |
514 ((uint32_t)RTC_ByteToBcd2(inStimestructure.Seconds)) | \ | |
515 (((uint32_t)inStimestructure.TimeFormat) << 16U)); | |
516 } | |
517 | |
518 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
519 static void DataEX_helper_SetDate(RTC_DateTypeDef inSdatestructure, uint32_t *outDatetmpreg) |
38 | 520 { |
521 *outDatetmpreg = (((uint32_t)RTC_ByteToBcd2(inSdatestructure.Year) << 16U) | \ | |
522 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Month) << 8U) | \ | |
523 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Date)) | \ | |
524 ((uint32_t)inSdatestructure.WeekDay << 13U)); | |
525 } | |
526 | |
527 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
528 static void DataEX_helper_set_Unknown_Date_deviceData(SDeviceLine *lineWrite) |
38 | 529 { |
530 RTC_DateTypeDef sdatestructure; | |
531 RTC_TimeTypeDef stimestructure; | |
532 | |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
533 stimestructure.Hours = UNKNOWN_TIME_HOURS; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
534 stimestructure.Minutes = UNKNOWN_TIME_MINUTES; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
535 stimestructure.Seconds = UNKNOWN_TIME_SECOND; |
38 | 536 |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
537 sdatestructure.Date = UNKNOWN_DATE_DAY; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
538 sdatestructure.Month = UNKNOWN_DATE_MONTH; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
539 sdatestructure.Year = UNKNOWN_DATE_YEAR; |
38 | 540 setWeekday(&sdatestructure); |
541 | |
542 DataEX_helper_SetTime(stimestructure, &lineWrite->time_rtc_tr); | |
543 DataEX_helper_SetDate(sdatestructure, &lineWrite->date_rtc_dr); | |
544 } | |
545 | |
546 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
547 static uint8_t DataEX_helper_Check_And_Correct_Date_deviceData(SDeviceLine *lineWrite) |
38 | 548 { |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
549 uint8_t retval = 0; |
38 | 550 RTC_DateTypeDef sdatestructure; |
551 RTC_TimeTypeDef stimestructure; | |
552 | |
553 // from lineWrite to structure | |
554 translateDate(lineWrite->date_rtc_dr, &sdatestructure); | |
555 translateTime(lineWrite->time_rtc_tr, &stimestructure); | |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
556 |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
557 /* Check if date is out of range */ |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
558 if(!( (sdatestructure.Year >= 15) |
38 | 559 && (sdatestructure.Year <= 30) |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
560 && (sdatestructure.Month <= 12))) |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
561 { |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
562 DataEX_helper_set_Unknown_Date_deviceData(lineWrite); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
563 retval = 1; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
564 } |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
565 return retval; |
38 | 566 } |
567 | |
568 | |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
569 static uint8_t DataEX_helper_Check_And_Correct_Value_deviceData(SDeviceLine *lineWrite, int32_t from, int32_t to, uint8_t defaulttofrom) |
38 | 570 { |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
571 uint8_t retval = 0; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
572 RTC_DateTypeDef sdatestructure; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
573 |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
574 /* Is value out of valid range? */ |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
575 if(!(lineWrite->value_int32 >= from && lineWrite->value_int32 <= to)) |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
576 { |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
577 if(defaulttofrom) |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
578 { |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
579 lineWrite->value_int32 = from; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
580 } |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
581 else |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
582 { |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
583 lineWrite->value_int32 = to; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
584 } |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
585 DataEX_helper_set_Unknown_Date_deviceData(lineWrite); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
586 } |
38 | 587 |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
588 /* This is just a repair function to restore metric if a corruption occurred in an older fw version */ |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
589 if(((lineWrite->value_int32 == to) && defaulttofrom ) |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
590 || ((lineWrite->value_int32 == from) && !defaulttofrom )) |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
591 { |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
592 translateDate(lineWrite->date_rtc_dr, &sdatestructure); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
593 if(sdatestructure.Year == UNKNOWN_DATE_YEAR) |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
594 { |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
595 if(defaulttofrom) |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
596 { |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
597 lineWrite->value_int32 = from; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
598 } |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
599 else |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
600 { |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
601 lineWrite->value_int32 = to; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
602 } |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
603 } |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
604 } |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
605 return retval; |
38 | 606 } |
607 | |
608 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
609 static void DataEX_check_DeviceData(void) |
38 | 610 { |
611 SDevice *DeviceData = stateDeviceGetPointerWrite(); | |
612 | |
613 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->batteryChargeCompleteCycles); | |
614 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->batteryChargeCycles); | |
615 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->depthMaximum); | |
616 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->diveCycles); | |
617 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->hoursOfOperation); | |
618 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->temperatureMaximum); | |
619 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->temperatureMinimum); | |
620 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->voltageMinimum); | |
621 | |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
622 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->batteryChargeCompleteCycles, 0, 10000,1); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
623 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->batteryChargeCycles, 0, 20000,1); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
624 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->depthMaximum, 0, (500*100)+1000,1); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
625 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->diveCycles, 0, 20000,1); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
626 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->hoursOfOperation, 0, 1000000,1); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
627 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMaximum, -30*100, 150*100,1); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
628 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMinimum, -30*100, 150*100,0); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
629 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->voltageMinimum, 2*1000, 6*1000,0); |
38 | 630 } |
631 | |
632 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
633 static void DataEX_merge_DeviceData_and_store(void) |
38 | 634 { |
635 uint16_t dataLengthRead; | |
636 SDevice DeviceDataFlash; | |
637 SDevice *DeviceData = stateDeviceGetPointerWrite(); | |
638 | |
639 dataLengthRead = ext_flash_read_devicedata((uint8_t *)&DeviceDataFlash,sizeof(SDevice)); | |
640 | |
641 if(dataLengthRead == 0) | |
642 { | |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
407
diff
changeset
|
643 ext_flash_write_devicedata(false); |
38 | 644 return; |
645 } | |
646 | |
647 /* max values */ | |
648 if(DeviceData->batteryChargeCompleteCycles.value_int32 < DeviceDataFlash.batteryChargeCompleteCycles.value_int32) | |
649 { | |
650 DataEX_helper_copy_deviceData(&DeviceData->batteryChargeCompleteCycles, &DeviceDataFlash.batteryChargeCompleteCycles); | |
651 } | |
652 if(DeviceData->batteryChargeCycles.value_int32 < DeviceDataFlash.batteryChargeCycles.value_int32) | |
653 { | |
654 DataEX_helper_copy_deviceData(&DeviceData->batteryChargeCycles, &DeviceDataFlash.batteryChargeCycles); | |
655 } | |
656 if(DeviceData->temperatureMaximum.value_int32 < DeviceDataFlash.temperatureMaximum.value_int32) | |
657 { | |
658 DataEX_helper_copy_deviceData(&DeviceData->temperatureMaximum, &DeviceDataFlash.temperatureMaximum); | |
659 } | |
660 if(DeviceData->depthMaximum.value_int32 < DeviceDataFlash.depthMaximum.value_int32) | |
661 { | |
662 DataEX_helper_copy_deviceData(&DeviceData->depthMaximum, &DeviceDataFlash.depthMaximum); | |
663 } | |
664 if(DeviceData->diveCycles.value_int32 < DeviceDataFlash.diveCycles.value_int32) | |
665 { | |
666 DataEX_helper_copy_deviceData(&DeviceData->diveCycles, &DeviceDataFlash.diveCycles); | |
667 } | |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
668 if(DeviceData->hoursOfOperation.value_int32 < DeviceDataFlash.hoursOfOperation.value_int32) |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
669 { |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
670 DataEX_helper_copy_deviceData(&DeviceData->hoursOfOperation, &DeviceDataFlash.hoursOfOperation); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
671 } |
38 | 672 |
407
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
673 |
38 | 674 /* min values */ |
675 if(DeviceData->temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32) | |
676 { | |
677 DataEX_helper_copy_deviceData(&DeviceData->temperatureMinimum, &DeviceDataFlash.temperatureMinimum); | |
678 } | |
679 if(DeviceData->voltageMinimum.value_int32 > DeviceDataFlash.voltageMinimum.value_int32) | |
680 { | |
681 DataEX_helper_copy_deviceData(&DeviceData->voltageMinimum, &DeviceDataFlash.voltageMinimum); | |
682 } | |
683 | |
684 DataEX_check_DeviceData (); | |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
407
diff
changeset
|
685 ext_flash_write_devicedata(false); |
38 | 686 } |
687 | |
688 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
689 static void DataEX_copy_to_DeviceData(void) |
38 | 690 { |
691 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn; | |
692 SDevice * pDeviceState = stateDeviceGetPointerWrite(); | |
693 | |
694 memcpy(pDeviceState, &dataInDevice->DeviceData[dataInDevice->boolDeviceData], sizeof(SDevice)); | |
407
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
695 DeviceDataUpdated = 1; /* indicate new data to be written to flash by background task (at last op hour count will be updated) */ |
38 | 696 } |
697 | |
698 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
699 static void DataEX_copy_to_VpmRepetitiveData(void) |
38 | 700 { |
701 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn; | |
702 SVpmRepetitiveData * pVpmState = stateVpmRepetitiveDataGetPointerWrite(); | |
703 | |
704 if(dataInDevice->boolVpmRepetitiveDataValid) | |
705 { | |
706 memcpy(pVpmState, &dataInDevice->VpmRepetitiveData, sizeof(SVpmRepetitiveData)); | |
707 pVpmState->is_data_from_RTE_CPU = 1; | |
708 } | |
709 } | |
710 | |
711 | |
712 void DataEX_control_connection_while_asking_for_sleep(void) | |
713 { | |
714 if(!DataEX_check_header_and_footer_ok()) | |
715 { | |
716 if(DataEX_check_header_and_footer_devicedata()) | |
717 { | |
718 data_old__lost_connection_to_slave_counter_retry = 0; | |
719 data_old__lost_connection_to_slave_counter_temp = 0; | |
720 stateRealGetPointerWrite()->data_old__lost_connection_to_slave = 0; | |
208 | 721 dataOut.header.checkCode[SPI_HEADER_INDEX_RX_STATE] = SPI_RX_STATE_OK; |
38 | 722 } |
723 else | |
724 { | |
725 stateRealGetPointerWrite()->data_old__lost_connection_to_slave = 1; | |
726 data_old__lost_connection_to_slave_counter_temp += 1; | |
727 data_old__lost_connection_to_slave_counter_total += 1; | |
728 } | |
729 } | |
730 } | |
731 | |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
732 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
|
733 { |
342
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
734 float ambient = 0; |
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
735 float surface = 0; |
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
736 float depth = 0; |
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
737 float density = 0; |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
738 |
342
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
739 ambient = d->data[d->boolPressureData].pressure_mbar / 1000.0f; |
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
740 surface = d->data[d->boolPressureData].surface_mbar / 1000.0f; |
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
741 density = ((float)( 100 + settingsGetPointer()->salinity)) / 100.0f; |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
742 |
342
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
743 ds->lifeData.pressure_ambient_bar = ambient; |
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
744 ds->lifeData.pressure_surface_bar = surface; |
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
745 depth = (ambient - surface) / (0.09807f * density); |
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
746 ds->lifeData.bool_temp1 = d->data[d->boolPressureData].SPARE1; |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
747 |
342
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
748 return depth; |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
749 } |
38 | 750 |
189
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
751 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
|
752 { |
342
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
753 float temp = 0; |
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
754 temp = d->data[d->boolPressureData].temperature; |
189
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
755 |
342
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
756 return temp; |
189
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
757 } |
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
758 |
38 | 759 void DataEX_copy_to_LifeData(_Bool *modeChangeFlag) |
760 { | |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
761 SDiveState *pStateReal = stateRealGetPointerWrite(); |
38 | 762 static uint16_t getDeviceDataAfterStartOfMainCPU = 20; |
763 | |
764 /* internal sensor: HUD data | |
765 */ | |
766 for(int i=0;i<3;i++) | |
767 { | |
768 pStateReal->lifeData.ppO2Sensor_bar[i] = get_ppO2Sensor_bar(i); | |
769 pStateReal->lifeData.sensorVoltage_mV[i] = get_sensorVoltage_mV(i); | |
770 } | |
771 pStateReal->lifeData.HUD_battery_voltage_V = get_HUD_battery_voltage_V(); | |
772 | |
773 | |
774 // wireless - �ltere daten aufr�umen | |
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
775 for(int i=0;i<(2*NUM_GASES+1);i++) |
38 | 776 { |
777 if(pStateReal->lifeData.bottle_bar[i]) | |
778 { | |
779 if((pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] == 0) || (pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] > 60000)) | |
780 { | |
781 pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] = 0; | |
782 pStateReal->lifeData.bottle_bar[i] = 0; | |
783 } | |
784 else | |
785 pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] += 100; | |
786 } | |
787 } | |
788 | |
789 if(!DataEX_check_header_and_footer_ok()) | |
790 { | |
791 if(DataEX_check_header_and_footer_devicedata()) | |
792 { | |
793 DataEX_copy_to_DeviceData(); | |
794 DataEX_copy_to_VpmRepetitiveData(); | |
795 data_old__lost_connection_to_slave_counter_temp = 0; | |
796 data_old__lost_connection_to_slave_counter_retry = 0; | |
275
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
797 /* Do not yet reset state. Wait till common data has been received in next cycle. Otherwise invalid data may be forwarded for processing */ |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
798 /* pStateReal->data_old__lost_connection_to_slave = 0; */ |
208 | 799 dataOut.header.checkCode[SPI_HEADER_INDEX_RX_STATE] = SPI_RX_STATE_OK; |
38 | 800 } |
801 else | |
802 { | |
803 pStateReal->data_old__lost_connection_to_slave = 1; | |
804 data_old__lost_connection_to_slave_counter_temp += 1; | |
805 data_old__lost_connection_to_slave_counter_total += 1; | |
806 } | |
807 return; | |
808 } | |
141 | 809 else /* RX data OK */ |
810 { | |
811 data_old__lost_connection_to_slave_counter_temp = 0; | |
812 data_old__lost_connection_to_slave_counter_retry = 0; | |
813 pStateReal->data_old__lost_connection_to_slave = 0; | |
208 | 814 dataOut.header.checkCode[SPI_HEADER_INDEX_RX_STATE] = SPI_RX_STATE_OK; |
141 | 815 } |
38 | 816 |
817 if(getDeviceDataAfterStartOfMainCPU) | |
818 { | |
819 getDeviceDataAfterStartOfMainCPU--; | |
820 if(getDeviceDataAfterStartOfMainCPU == 0) | |
821 { | |
822 dataOut.getDeviceDataNow = 1; | |
141 | 823 getDeviceDataAfterStartOfMainCPU = 10*60*10; /* * 100ms = 60 second => update device data every 10 minutes */ |
38 | 824 } |
825 } | |
826 | |
827 /* new 151207 hw */ | |
828 if(requestNecessary.uw != 0) | |
829 { | |
830 if(((dataIn.confirmRequest.uw) & CRBUTTON) != 0) | |
831 { | |
832 requestNecessary.ub.button = 0; | |
833 } | |
834 | |
835 if(requestNecessary.ub.button == 1) | |
836 { | |
837 setButtonResponsiveness(settingsGetPointer()->ButtonResponsiveness); | |
838 } | |
839 } | |
840 requestNecessary.uw = 0; // clear all | |
841 | |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
842 float meter = 0; |
38 | 843 SSettings *pSettings; |
149 | 844 |
38 | 845 /* uint8_t IAmStolenPleaseKillMe; |
846 */ | |
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
847 pSettings = settingsGetPointer(); |
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
848 |
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
849 if(pSettings->IAmStolenPleaseKillMe > 3) |
38 | 850 { |
851 pSettings->salinity = 0; | |
852 dataIn.data[dataIn.boolPressureData].surface_mbar = 999; | |
853 dataIn.data[dataIn.boolPressureData].pressure_mbar = 98971; | |
854 dataIn.mode = MODE_DIVE; | |
855 } | |
856 | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
857 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
|
858 { |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
859 meter = getSampleDepth(&dataIn, pStateReal); |
38 | 860 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
861 pStateReal->pressure_uTick_old = pStateReal->pressure_uTick_new; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
862 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
|
863 pStateReal->pressure_uTick_local_new = HAL_GetTick(); |
38 | 864 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
865 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
|
866 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
|
867 } |
38 | 868 dataOut.setAccidentFlag = 0; |
869 | |
141 | 870 if(pStateReal->data_old__lost_connection_to_slave == 0) |
38 | 871 { |
141 | 872 //Start of diveMode? |
873 if(pStateReal->mode != MODE_DIVE && dataIn.mode == MODE_DIVE) | |
874 { | |
875 if(modeChangeFlag) | |
876 { | |
877 *modeChangeFlag = 1; | |
878 } | |
879 if(stateUsed == stateSimGetPointer()) | |
38 | 880 { |
881 simulation_exit(); | |
882 } | |
141 | 883 // new 170508 |
38 | 884 settingsGetPointer()->bluetoothActive = 0; |
885 MX_Bluetooth_PowerOff(); | |
886 //Init dive Mode | |
141 | 887 decoLock = DECO_CALC_init_as_is_start_of_dive; |
888 pStateReal->lifeData.boolResetAverageDepth = 1; | |
38 | 889 } |
141 | 890 |
197
c853f5d23bb7
cleanup: fix (harmless) use before assign
Jan Mulder <jlmulder@xs4all.nl>
parents:
189
diff
changeset
|
891 pStateReal->lifeData.cns = dataIn.data[dataIn.boolToxicData].cns; |
c853f5d23bb7
cleanup: fix (harmless) use before assign
Jan Mulder <jlmulder@xs4all.nl>
parents:
189
diff
changeset
|
892 pStateReal->lifeData.otu = dataIn.data[dataIn.boolToxicData].otu; |
c853f5d23bb7
cleanup: fix (harmless) use before assign
Jan Mulder <jlmulder@xs4all.nl>
parents:
189
diff
changeset
|
893 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
|
894 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
|
895 |
141 | 896 //End of diveMode? |
897 if(pStateReal->mode == MODE_DIVE && dataIn.mode != MODE_DIVE) | |
898 { | |
899 if(modeChangeFlag) | |
900 { | |
901 *modeChangeFlag = 1; | |
902 } | |
903 createDiveSettings(); | |
38 | 904 |
141 | 905 if(pStateReal->warnings.cnsHigh) |
906 { | |
907 if(pStateReal->lifeData.cns >= 130) | |
908 dataOut.setAccidentFlag += ACCIDENT_CNSLVL2; | |
909 else if(pStateReal->lifeData.cns >= 100) | |
910 dataOut.setAccidentFlag += ACCIDENT_CNS; | |
911 } | |
912 if(pStateReal->warnings.decoMissed) | |
913 dataOut.setAccidentFlag += ACCIDENT_DECOSTOP; | |
914 } | |
915 pStateReal->mode = dataIn.mode; | |
916 pStateReal->chargeStatus = dataIn.chargeStatus; | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
917 |
306
2f43419102c8
bugfix, cleanup: do not clip depth to 0
Jan Mulder <jlmulder@xs4all.nl>
parents:
288
diff
changeset
|
918 pStateReal->lifeData.depth_meter = meter; |
141 | 919 |
189
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
920 pStateReal->lifeData.temperature_celsius = getTemperature(&dataIn); |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
921 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
|
922 if(pStateReal->mode != MODE_DIVE) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
923 pStateReal->lifeData.max_depth_meter = 0; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
924 else |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
925 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
926 if(meter > pStateReal->lifeData.max_depth_meter) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
927 pStateReal->lifeData.max_depth_meter = meter; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
928 } |
38 | 929 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
930 if(dataIn.accidentFlags & ACCIDENT_DECOSTOP) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
931 pStateReal->decoMissed_at_the_end_of_dive = 1; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
932 if(dataIn.accidentFlags & ACCIDENT_CNS) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
933 pStateReal->cnsHigh_at_the_end_of_dive = 1; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
934 |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
935 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
|
936 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
|
937 pStateReal->lifeData.counterSecondsShallowDepth = dataIn.data[dataIn.boolTimeData].counterSecondsShallowDepth; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
938 pStateReal->lifeData.surface_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].surfacetime_seconds; |
38 | 939 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
940 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
|
941 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
|
942 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
943 pStateReal->lifeData.compass_heading -= 180.0; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
944 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
|
945 } |
109
65a6e352ce08
Consider computer heading in case of a flipped display
Ideenmodellierer
parents:
51
diff
changeset
|
946 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
947 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
|
948 pStateReal->lifeData.compass_pitch = dataIn.data[dataIn.boolCompassData].compass_pitch; |
38 | 949 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
950 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
|
951 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
|
952 pStateReal->lifeData.compass_DZ_f = dataIn.data[dataIn.boolCompassData].compass_DZ_f; |
38 | 953 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
954 pStateReal->compass_uTick_old = pStateReal->compass_uTick_new; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
955 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
|
956 pStateReal->compass_uTick_local_new = HAL_GetTick(); |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
957 |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
958 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
|
959 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
|
960 |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
961 if(pStateReal->mode == MODE_DIVE) |
38 | 962 { |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
963 for(int i= 0; i <16; i++) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
964 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
965 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
|
966 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
|
967 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
|
968 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
|
969 } |
38 | 970 } |
971 | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
972 /* battery and ambient light sensors |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
973 */ |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
974 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
|
975 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
|
976 pStateReal->lifeData.battery_voltage = dataIn.data[dataIn.boolBatteryData].battery_voltage; |
275
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
977 |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
978 /* PIC data |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
979 */ |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
980 for(int i=0;i<4;i++) |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
981 { |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
982 pStateReal->lifeData.buttonPICdata[i] = dataIn.data[dataIn.boolPICdata].button_setting[i]; |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
983 } |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
984 |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
985 /* sensorErrors |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
986 */ |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
987 pStateReal->sensorErrorsRTE = dataIn.sensorErrors; |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
988 } |
38 | 989 |
990 /* apnea specials | |
991 */ | |
992 if(pStateReal->diveSettings.diveMode == DIVEMODE_Apnea) | |
993 { | |
994 if(pStateReal->mode != MODE_DIVE) | |
995 { | |
996 pStateReal->lifeData.apnea_total_max_depth_meter = 0; | |
997 pStateReal->lifeData.apnea_last_dive_time_seconds = 0; | |
998 pStateReal->lifeData.apnea_last_max_depth_meter = 0; | |
999 } | |
1000 else | |
1001 { | |
1002 if(pStateReal->lifeData.max_depth_meter > pStateReal->lifeData.apnea_total_max_depth_meter) | |
1003 pStateReal->lifeData.apnea_total_max_depth_meter = pStateReal->lifeData.max_depth_meter; | |
1004 } | |
1005 | |
1006 if(pStateReal->lifeData.dive_time_seconds > 15) | |
1007 { | |
1008 pStateReal->lifeData.apnea_last_dive_time_seconds = pStateReal->lifeData.dive_time_seconds; | |
1009 } | |
1010 | |
1011 if(pStateReal->lifeData.counterSecondsShallowDepth) | |
1012 { | |
1013 if(pStateReal->lifeData.max_depth_meter > 1.5f) | |
1014 { | |
1015 pStateReal->lifeData.apnea_last_max_depth_meter = pStateReal->lifeData.max_depth_meter; | |
1016 } | |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
1017 // reset max_depth_meter, average_depth_meter and internal values |
38 | 1018 pStateReal->lifeData.max_depth_meter = 0; |
1019 pStateReal->lifeData.boolResetAverageDepth = 1; | |
1020 } | |
1021 } | |
1022 | |
308
1203255481e4
cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents:
307
diff
changeset
|
1023 setAvgDepth(pStateReal); |
1203255481e4
cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents:
307
diff
changeset
|
1024 } |
1203255481e4
cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents:
307
diff
changeset
|
1025 |
1203255481e4
cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents:
307
diff
changeset
|
1026 void setAvgDepth(SDiveState *pStateReal) { |
1203255481e4
cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents:
307
diff
changeset
|
1027 |
38 | 1028 float *AvgDepthValue = &pStateReal->lifeData.average_depth_meter; |
1029 float DepthNow = pStateReal->lifeData.depth_meter; | |
309
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1030 static uint32_t AvgDepthCount = 0; |
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1031 static uint32_t AvgDepthTimer = 0; |
38 | 1032 uint32_t AvgSecondsSinceLast; |
1033 uint32_t DiveTime = pStateReal->lifeData.dive_time_seconds_without_surface_time; | |
308
1203255481e4
cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents:
307
diff
changeset
|
1034 |
38 | 1035 if(pStateReal->lifeData.boolResetAverageDepth) |
1036 { | |
1037 *AvgDepthValue = DepthNow; | |
309
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1038 AvgDepthCount = 0; |
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1039 AvgDepthTimer = DiveTime; |
38 | 1040 pStateReal->lifeData.boolResetAverageDepth = 0; |
1041 } | |
309
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1042 else if (DiveTime > AvgDepthTimer) |
38 | 1043 { |
309
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1044 AvgSecondsSinceLast = DiveTime - AvgDepthTimer; |
38 | 1045 for(int i=0;i<AvgSecondsSinceLast;i++) |
1046 { | |
309
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1047 *AvgDepthValue = (*AvgDepthValue * AvgDepthCount + DepthNow) / (AvgDepthCount + 1); |
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1048 AvgDepthCount += 1; |
38 | 1049 } |
309
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1050 AvgDepthTimer = DiveTime; |
38 | 1051 } |
309
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1052 if(AvgDepthCount == 0) |
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1053 *AvgDepthValue = DepthNow; |
38 | 1054 } |
1055 | |
1056 | |
1057 uint8_t DataEX_check_RTE_version__needs_update(void) | |
1058 { | |
1059 if(data_old__lost_connection_to_slave_counter_retry > 10) | |
1060 return 1; | |
1061 else | |
1062 { | |
1063 if(stateRealGetPointer()->data_old__lost_connection_to_slave == 0) | |
1064 { | |
1065 setActualRTEversion(dataIn.RTE_VERSION_high, dataIn.RTE_VERSION_low); | |
1066 | |
1067 if(RTEminimum_required_high() < dataIn.RTE_VERSION_high) | |
1068 return 0; | |
1069 else | |
1070 if((RTEminimum_required_high() == dataIn.RTE_VERSION_high) && (RTEminimum_required_low() <= dataIn.RTE_VERSION_low)) | |
1071 return 0; | |
1072 else | |
1073 return 1; | |
1074 } | |
1075 else | |
1076 return 0; | |
1077 } | |
1078 } | |
1079 | |
1080 | |
1081 /* Private functions ---------------------------------------------------------*/ | |
1082 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
1083 /* 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
|
1084 * 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
|
1085 */ |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
1086 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
|
1087 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1088 uint8_t ret = 1; |
141 | 1089 if((dataIn.footer.checkCode[0] == 0x00) |
1090 && (dataIn.footer.checkCode[1] == 0x00) | |
1091 && (dataIn.footer.checkCode[2] == 0x00) | |
1092 && (dataIn.footer.checkCode[3] == 0x00)) { ret = 0; } | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1093 |
141 | 1094 if((dataIn.footer.checkCode[0] == 0xff) |
1095 && (dataIn.footer.checkCode[1] == 0xff) | |
1096 && (dataIn.footer.checkCode[2] == 0xff) | |
1097 && (dataIn.footer.checkCode[3] == 0xff)) { ret = 0; } | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1098 |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1099 return ret; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1100 } |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1101 |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
1102 static uint8_t DataEX_check_header_and_footer_ok(void) |
38 | 1103 { |
1104 if(dataIn.header.checkCode[0] != 0xA1) | |
1105 return 0; | |
141 | 1106 #if USE_OLD_HEADER_FORMAT |
38 | 1107 if(dataIn.header.checkCode[1] != 0xA2) |
1108 return 0; | |
1109 if(dataIn.header.checkCode[2] != 0xA3) | |
1110 return 0; | |
141 | 1111 #endif |
38 | 1112 if(dataIn.header.checkCode[3] != 0xA4) |
1113 return 0; | |
1114 if(dataIn.footer.checkCode[0] != 0xE1) | |
1115 return 0; | |
1116 if(dataIn.footer.checkCode[1] != 0xE2) | |
1117 return 0; | |
1118 if(dataIn.footer.checkCode[2] != 0xE3) | |
1119 return 0; | |
1120 if(dataIn.footer.checkCode[3] != 0xE4) | |
1121 return 0; | |
1122 | |
1123 return 1; | |
1124 } | |
1125 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
1126 static uint8_t DataEX_check_header_and_footer_devicedata(void) |
38 | 1127 { |
1128 if(dataIn.header.checkCode[0] != 0xDF) | |
1129 return 0; | |
1130 if(dataIn.header.checkCode[1] != 0xDE) | |
1131 return 0; | |
1132 if(dataIn.header.checkCode[2] != 0xDD) | |
1133 return 0; | |
1134 if(dataIn.header.checkCode[3] != 0xDC) | |
1135 return 0; | |
1136 if(dataIn.footer.checkCode[0] != 0xE1) | |
1137 return 0; | |
1138 if(dataIn.footer.checkCode[1] != 0xE2) | |
1139 return 0; | |
1140 if(dataIn.footer.checkCode[2] != 0xE3) | |
1141 return 0; | |
1142 if(dataIn.footer.checkCode[3] != 0xE4) | |
1143 return 0; | |
1144 | |
1145 return 1; | |
1146 } | |
407
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1147 |
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1148 void DataEX_merge_devicedata(void) |
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1149 { |
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1150 if(DeviceDataUpdated) |
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1151 { |
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1152 DeviceDataUpdated = 0; |
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1153 DataEX_merge_DeviceData_and_store(); |
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1154 } |
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1155 } |
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1156 |