comparison Discovery/Src/tCCR.c @ 446:f1257a32f2d4 minor_improvments

Introduced configuration header for variant managment: At the moment several defines are distributed across the code allowing special SW builds (e.g. logging simulated dives). To make these options more transparent and easier to configurate a separate header has been added. With this header an new option for an optical pressure sensor was introduced.
author ideenmodellierer
date Thu, 05 Mar 2020 22:31:50 +0100
parents 31e471d60797
children 91a939915bfa
comparison
equal deleted inserted replaced
445:ee1434824c3f 446:f1257a32f2d4
31 #include "tCCR.h" 31 #include "tCCR.h"
32 #include "ostc.h" 32 #include "ostc.h"
33 #include "data_central.h" 33 #include "data_central.h"
34 #include "data_exchange.h" 34 #include "data_exchange.h"
35 #include "check_warning.h" 35 #include "check_warning.h"
36 #include "configuration.h"
36 37
37 /* Private types -------------------------------------------------------------*/ 38 /* Private types -------------------------------------------------------------*/
38 typedef struct 39 typedef struct
39 { 40 {
40 uint8_t hud_firmwareVersion; 41 uint8_t hud_firmwareVersion;
348 } 349 }
349 350
350 351
351 void tCCR_control(void) 352 void tCCR_control(void)
352 { 353 {
354 uint16_t checksum = 0;
355 SDiveState *pLivedata = stateRealGetPointerWrite();
356
353 357
354 if((UartReadyHUD == RESET) && StartListeningToUART_HUD && (time_elapsed_ms(LastReceivedTick_HUD, HAL_GetTick()) > HUD_RX_START_DELAY_MS)) 358 if((UartReadyHUD == RESET) && StartListeningToUART_HUD && (time_elapsed_ms(LastReceivedTick_HUD, HAL_GetTick()) > HUD_RX_START_DELAY_MS))
355 { 359 {
356 StartListeningToUART_HUD = 0; 360 StartListeningToUART_HUD = 0;
357 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, HUD_RX_FRAME_LENGTH); 361 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, HUD_RX_FRAME_LENGTH);
360 if(UartReadyHUD == SET) 364 if(UartReadyHUD == SET)
361 { 365 {
362 UartReadyHUD = RESET; 366 UartReadyHUD = RESET;
363 StartListeningToUART_HUD = 1; 367 StartListeningToUART_HUD = 1;
364 368
365 memcpy(&receiveHUD[!boolHUDdata], receiveHUDraw, 11); 369 /* check if received package is valid */
366 receiveHUD[!boolHUDdata].battery_voltage_mV = receiveHUDraw[11] + (256 * receiveHUDraw[12]); 370 for(int i=0;i<13;i++)
367 receiveHUD[!boolHUDdata].checksum = receiveHUDraw[13] + (256 * receiveHUDraw[14]); 371 {
368 372 checksum += receiveHUDraw[i];
369 uint16_t checksum = 0; 373 }
370 374 receiveHUD[!boolHUDdata].checksum = receiveHUDraw[13] + (256 * receiveHUDraw[14]);
371 for(int i=0;i<13;i++) 375 if(checksum == receiveHUD[!boolHUDdata].checksum)
372 { 376 {
373 checksum += receiveHUDraw[i]; 377 #ifdef ENABLE_BOTTLE_SENSOR
374 } 378 if(receiveHUDraw[0] == 0xA5) /* code for pressure sensor */
375 if(checksum == receiveHUD[!boolHUDdata].checksum) 379 {
376 { 380 pLivedata->lifeData.bottle_bar[pLivedata->lifeData.actualGas.GasIdInSettings] = receiveHUDraw[10];
377 boolHUDdata = !boolHUDdata; 381 pLivedata->lifeData.bottle_bar_age_MilliSeconds[pLivedata->lifeData.actualGas.GasIdInSettings] = 0;
378 HUDTimeoutCount = 0; 382 }
379 data_old__lost_connection_to_HUD = 0; 383 else
380 } 384 #endif
381 else 385 /* handle O2 sensor data */
382 { 386 {
383 if(data_old__lost_connection_to_HUD) /* we lost connection, maybe due to RX shift => start single byte read to resynchronize */ 387 memcpy(&receiveHUD[!boolHUDdata], receiveHUDraw, 11);
384 { 388 receiveHUD[!boolHUDdata].battery_voltage_mV = receiveHUDraw[11] + (256 * receiveHUDraw[12]);
385 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, 1); 389 }
386 StartListeningToUART_HUD = 0; 390
387 } 391 boolHUDdata = !boolHUDdata;
388 } 392 HUDTimeoutCount = 0;
389 memset(receiveHUDraw,0,sizeof(receiveHUDraw)); 393 data_old__lost_connection_to_HUD = 0;
394 }
395 else
396 {
397 if(data_old__lost_connection_to_HUD) /* we lost connection, maybe due to RX shift => start single byte read to resynchronize */
398 {
399 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, 1);
400 StartListeningToUART_HUD = 0;
401 }
402 }
403 memset(receiveHUDraw,0,sizeof(receiveHUDraw));
390 } 404 }
391 } 405 }
392 406
393 #endif 407 #endif
394 /* Private functions ---------------------------------------------------------*/ 408 /* Private functions ---------------------------------------------------------*/