diff Small_CPU/Src/uart.c @ 742:e23fe82cbf8c

Update Sentinel protocol: The Sentinel protocol is now supported by autodetection. Added Autodetection indicator: In the previous version no indicator showed that an auto detection is running. A new pseudo sensor type has been introduced which now causes the auto detection string to be displayed while the detection is running in the background.
author Ideenmodellierer
date Sun, 19 Feb 2023 21:43:24 +0100
parents 2a801cfe23ab
children df0d43da1614
line wrap: on
line diff
--- a/Small_CPU/Src/uart.c	Thu Feb 02 17:35:54 2023 +0100
+++ b/Small_CPU/Src/uart.c	Sun Feb 19 21:43:24 2023 +0100
@@ -39,6 +39,7 @@
 static uint8_t dmaActive;								/* Indicator if DMA reception needs to be started */
 static uint8_t digO2Connected = 0;						/* Binary indicator if a sensor is connected or not */
 static uint8_t CO2Connected = 0;						/* Binary indicator if a sensor is connected or not */
+static uint8_t SentinelConnected = 0;					/* Binary indicator if a sensor is connected or not */
 static uint8_t ppO2TargetChannel = 0;					/* The OSTC4 supports three slots for visualization of the ppo2. This one is reserved for the digital sensor */
 
 static SSensorDataDiveO2 sensorDataDiveO2;		/* intermediate storage for additional sensor data */
@@ -86,6 +87,7 @@
   dmaActive = 0;
   digO2Connected = 0;
   CO2Connected = 0;
+  SentinelConnected = 0;
   Comstatus_O2 = UART_O2_INIT;
 }
 
@@ -194,6 +196,13 @@
 	}
 }
 
+void UART_StartDMA_Receiption()
+{
+	if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE))
+	{
+		dmaActive = 1;
+	}
+}
 
 #ifdef ENABLE_CO2_SUPPORT
 void UART_HandleCO2Data(void)
@@ -265,7 +274,7 @@
 				rxState = RX_Ready;
 			}
 		}
-
+		rxBuffer[localRX] = 0;
 		localRX++;
 		rxReadIndex++;
 		if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
@@ -283,10 +292,7 @@
 
 	if((dmaActive == 0)	&& (externalInterface_isEnabledPower33()))	/* Should never happen in normal operation => restart in case of communication error */
 	{
-		if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE))
-		{
-			dmaActive = 1;
-		}
+		UART_StartDMA_Receiption();
 	}
 }
 #endif
@@ -303,9 +309,9 @@
 	static uint8_t lastAlive = 0;
 	static uint8_t curAlive = 0;
 	static uint8_t checksum = 0;
-	char checksum_str[]="00";
+	static char checksum_str[]="00";
 
-	while(localRX != rxWriteIndex)
+	while((rxBuffer[localRX]!=0))
 	{
 		lastReceiveTick = HAL_GetTick();
 
@@ -404,6 +410,7 @@
 										setExternalInterfaceChannel(0,(float)(dataValue[0] / 10.0));
 										setExternalInterfaceChannel(1,(float)(dataValue[1] / 10.0));
 										setExternalInterfaceChannel(2,(float)(dataValue[2] / 10.0));
+										SentinelConnected = 1;
 									}
 									rxState = RX_Ready;
 				break;
@@ -413,7 +420,6 @@
 				break;
 
 		}
-
 		localRX++;
 		rxReadIndex++;
 		if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
@@ -430,16 +436,14 @@
 			setExternalInterfaceChannel(0,0.0);
 			setExternalInterfaceChannel(1,0.0);
 			setExternalInterfaceChannel(2,0.0);
+			SentinelConnected = 0;
 		}
 		lastAlive = curAlive;
 	}
 
 	if((dmaActive == 0)	&& (externalInterface_isEnabledPower33()))	/* Should never happen in normal operation => restart in case of communication error */
 	{
-		if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE))
-		{
-			dmaActive = 1;
-		}
+		UART_StartDMA_Receiption();
 	}
 }
 #endif
@@ -482,10 +486,7 @@
 		cmdReadIndex = 0;
 		lastO2ReqTick = tick;
 
-		if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE))
-		{
-			dmaActive = 1;
-		}
+		UART_StartDMA_Receiption();
 	}
 	if(time_elapsed_ms(lastO2ReqTick,tick) > 1000)		/* repeat request once per second */
 	{
@@ -654,13 +655,9 @@
 		}
 		lastAlive = curAlive;
 	}
-
 	if((dmaActive == 0)	&& (externalInterface_isEnabledPower33()))	/* Should never happen in normal operation => restart in case of communication error */
 	{
-		if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE))
-		{
-			dmaActive = 1;
-		}
+		UART_StartDMA_Receiption();
 	}
 }
 
@@ -672,7 +669,10 @@
 {
 	return CO2Connected;
 }
-
+uint8_t UART_isSentinelConnected()
+{
+	return SentinelConnected;
+}
 
 void UART_setTargetChannel(uint8_t channel)
 {
@@ -694,10 +694,7 @@
     		if(externalInterface_isEnabledPower33())
     		{
     			memset((char*)&rxBuffer[rxWriteIndex],(int)0,CHUNK_SIZE);
-				if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE))
-				{
-					dmaActive = 1;
-				}
+				UART_StartDMA_Receiption();
     		}
     	}
     }