diff 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
line wrap: on
line diff
--- a/Discovery/Src/tCCR.c	Thu Mar 05 22:27:55 2020 +0100
+++ b/Discovery/Src/tCCR.c	Thu Mar 05 22:31:50 2020 +0100
@@ -33,6 +33,7 @@
 #include "data_central.h"
 #include "data_exchange.h"
 #include "check_warning.h"
+#include "configuration.h"
 
 /* Private types -------------------------------------------------------------*/
 typedef struct
@@ -350,6 +351,9 @@
 
 void tCCR_control(void)
 {
+	uint16_t checksum = 0;
+	SDiveState *pLivedata = stateRealGetPointerWrite();
+
 
 	if((UartReadyHUD == RESET) && StartListeningToUART_HUD && (time_elapsed_ms(LastReceivedTick_HUD, HAL_GetTick()) > HUD_RX_START_DELAY_MS))
 	{
@@ -362,31 +366,41 @@
             UartReadyHUD = RESET;
             StartListeningToUART_HUD = 1;
 
-            memcpy(&receiveHUD[!boolHUDdata], receiveHUDraw, 11);
-            receiveHUD[!boolHUDdata].battery_voltage_mV = receiveHUDraw[11] + (256 * receiveHUDraw[12]);
-            receiveHUD[!boolHUDdata].checksum = receiveHUDraw[13] + (256 * receiveHUDraw[14]);
-
-            uint16_t checksum = 0;
+    /* check if received package is valid */
+			for(int i=0;i<13;i++)
+			{
+				checksum += receiveHUDraw[i];
+			}
+			receiveHUD[!boolHUDdata].checksum = receiveHUDraw[13] + (256 * receiveHUDraw[14]);
+			if(checksum == receiveHUD[!boolHUDdata].checksum)
+			{
+#ifdef ENABLE_BOTTLE_SENSOR
+		        if(receiveHUDraw[0] == 0xA5)				/* code for pressure sensor */
+		        {
+		        	pLivedata->lifeData.bottle_bar[pLivedata->lifeData.actualGas.GasIdInSettings] = receiveHUDraw[10];
+		        	pLivedata->lifeData.bottle_bar_age_MilliSeconds[pLivedata->lifeData.actualGas.GasIdInSettings] = 0;
+		        }
+		        else
+#endif
+		        											/* handle O2 sensor data */
+		        {
+		        	memcpy(&receiveHUD[!boolHUDdata], receiveHUDraw, 11);
+					receiveHUD[!boolHUDdata].battery_voltage_mV = receiveHUDraw[11] + (256 * receiveHUDraw[12]);
+		        }
 
-            for(int i=0;i<13;i++)
-            {
-                checksum += receiveHUDraw[i];
-            }
-            if(checksum == receiveHUD[!boolHUDdata].checksum)
-            {
-                boolHUDdata = !boolHUDdata;
-                HUDTimeoutCount = 0;
-                data_old__lost_connection_to_HUD = 0;
-            }
-            else
-            {
-            	if(data_old__lost_connection_to_HUD)	/* we lost connection, maybe due to RX shift => start single byte read to resynchronize */
-            	{
-            		HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, 1);
-            		StartListeningToUART_HUD = 0;
-            	}
-            }
-            memset(receiveHUDraw,0,sizeof(receiveHUDraw));
+				boolHUDdata = !boolHUDdata;
+				HUDTimeoutCount = 0;
+				data_old__lost_connection_to_HUD = 0;
+			}
+			else
+			{
+				if(data_old__lost_connection_to_HUD)	/* we lost connection, maybe due to RX shift => start single byte read to resynchronize */
+				{
+					HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, 1);
+					StartListeningToUART_HUD = 0;
+				}
+			}
+			memset(receiveHUDraw,0,sizeof(receiveHUDraw));
     }
 }