diff Small_CPU/Src/uartProtocol_Co2.c @ 809:9602a7338f28

DevBugfix CO2 sensor in streaming mode: In standalone mode (no multiplexer) the CO2 sensor is working in streaming mode => it could happen that the OSTC received data before the scaling factor was requested. As result the CO2 values were calculated with a zero value. This problem has been fixed. In addition some code cleanup has been done. Unifying usage of changeBaudrate function instead of old baud selection based on protocol request of Discovery firmware.
author Ideenmodellierer
date Sun, 27 Aug 2023 20:51:13 +0200
parents e9eba334b942
children c3dd461ca3f9
line wrap: on
line diff
--- a/Small_CPU/Src/uartProtocol_Co2.c	Sat Aug 26 13:38:13 2023 +0200
+++ b/Small_CPU/Src/uartProtocol_Co2.c	Sun Aug 27 20:51:13 2023 +0200
@@ -39,6 +39,8 @@
 
 void uartCo2_SendCmd(uint8_t CO2Cmd, uint8_t *cmdString, uint8_t *cmdLength)
 {
+	*cmdLength = 0;
+
 	switch (CO2Cmd)
 	{
 		case CO2CMD_MODE_POLL:		*cmdLength = snprintf((char*)cmdString, 10, "K 2\r\n");
@@ -80,6 +82,7 @@
 
 	if(localComState == UART_CO2_INIT)
 	{
+		CO2Connected = 0;
 		externalInterface_SetCO2Scale(0.0);
 		UART_StartDMA_Receiption();
 		localComState = UART_CO2_SETUP;
@@ -100,6 +103,7 @@
 		if(localComState == UART_CO2_CALIBRATE)
 		{
 			uartCo2_SendCmd(CO2CMD_CALIBRATE, cmdString, &cmdLength);
+			localComState = UART_CO2_IDLE;
 		}
 		else if(pmap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX)		/* sensor is working in polling mode if mux is connected to avoid interference with other sensors */
 		{
@@ -118,6 +122,7 @@
 		else
 		{
 			localComState = UART_CO2_OPERATING;					/* sensor in streaming mode if not connected to mux => operating */
+			UART_StartDMA_Receiption();
 		}
 	}
 	lastComState = localComState;
@@ -159,19 +164,32 @@
 			if(rxState == RX_Data5)
 			{
 				rxState = RX_DataComplete;
-				CO2Connected = 1;
 			}
 		}
 		else	/* protocol error data has max 5 digits */
 		{
-			rxState = RX_Ready;
+			if(rxState != RX_DataComplete)	/* commands will not answer with number values */
+			{
+				rxState = RX_Ready;
+			}
 		}
 	}
 	if((data == ' ') || (data == '\n'))	/* Abort data detection */
 	{
 		if(rxState == RX_DataComplete)
 		{
-			localComState = UART_CO2_IDLE;
+			CO2Connected = 1;
+			if(localComState == UART_CO2_SETUP)
+			{
+				if(dataType == '.')
+				{
+					localComState = UART_CO2_IDLE;
+				}
+			}
+			else
+			{
+				localComState = UART_CO2_IDLE;
+			}
 			if(externalInterface_GetCO2State() == 0)
 			{
 				externalInterface_SetCO2State(EXT_INTERFACE_33V_ON);