comparison Small_CPU/Src/uartProtocol_Co2.c @ 842:c3dd461ca3f9 Evo_2_23

Migrated Sentinel protocol to new UART structure: The Sentinel protocol had not been migrated to the new UART structure which was introduced with the introduction of the UART MUX. The Sentinel is now supported by autodetection again (development version only)
author Ideenmodellierer
date Mon, 15 Jan 2024 21:44:18 +0100
parents 9602a7338f28
children
comparison
equal deleted inserted replaced
841:70092f552f5a 842:c3dd461ca3f9
25 #include "externalInterface.h" 25 #include "externalInterface.h"
26 26
27 27
28 #ifdef ENABLE_CO2_SUPPORT 28 #ifdef ENABLE_CO2_SUPPORT
29 static uint8_t CO2Connected = 0; /* Binary indicator if a sensor is connected or not */ 29 static uint8_t CO2Connected = 0; /* Binary indicator if a sensor is connected or not */
30 static receiveState_t rxState = RX_Ready; 30 static receiveStateCO2_t rxState = CO2RX_Ready;
31 31
32 32
33 33
34 float LED_Level = 0.0; /* Normalized LED value which may be used as indication for the health status of the sensor */ 34 float LED_Level = 0.0; /* Normalized LED value which may be used as indication for the health status of the sensor */
35 float LED_ZeroOffset = 0.0; 35 float LED_ZeroOffset = 0.0;
135 static uint8_t dataType = 0; 135 static uint8_t dataType = 0;
136 static uint32_t dataValue = 0; 136 static uint32_t dataValue = 0;
137 uint8_t activeSensor = externalInterface_GetActiveUartSensor(); 137 uint8_t activeSensor = externalInterface_GetActiveUartSensor();
138 uartCO2Status_t localComState = externalInterface_GetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET); 138 uartCO2Status_t localComState = externalInterface_GetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET);
139 139
140 if(rxState == RX_Ready) /* identify data content */ 140 if(rxState == CO2RX_Ready) /* identify data content */
141 { 141 {
142 switch(data) 142 switch(data)
143 { 143 {
144 case 'G': 144 case 'G':
145 case 'l': 145 case 'l':
146 case 'D': 146 case 'D':
147 case 'Z': 147 case 'Z':
148 case '.': dataType = data; 148 case '.': dataType = data;
149 rxState = RX_Data0; 149 rxState = CO2RX_Data0;
150 dataValue = 0; 150 dataValue = 0;
151 break; 151 break;
152 case '?': localComState = UART_CO2_ERROR; 152 case '?': localComState = UART_CO2_ERROR;
153 break; 153 break;
154 default: /* unknown or corrupted => ignore */ 154 default: /* unknown or corrupted => ignore */
155 break; 155 break;
156 } 156 }
157 } 157 }
158 else if((data >= '0') && (data <= '9')) 158 else if((data >= '0') && (data <= '9'))
159 { 159 {
160 if((rxState >= RX_Data0) && (rxState <= RX_Data4)) 160 if((rxState >= CO2RX_Data0) && (rxState <= CO2RX_Data4))
161 { 161 {
162 dataValue = dataValue * 10 + (data - '0'); 162 dataValue = dataValue * 10 + (data - '0');
163 rxState++; 163 rxState++;
164 if(rxState == RX_Data5) 164 if(rxState == CO2RX_Data5)
165 { 165 {
166 rxState = RX_DataComplete; 166 rxState = CO2RX_DataComplete;
167 } 167 }
168 } 168 }
169 else /* protocol error data has max 5 digits */ 169 else /* protocol error data has max 5 digits */
170 { 170 {
171 if(rxState != RX_DataComplete) /* commands will not answer with number values */ 171 if(rxState != CO2RX_DataComplete) /* commands will not answer with number values */
172 { 172 {
173 rxState = RX_Ready; 173 rxState = CO2RX_Ready;
174 } 174 }
175 } 175 }
176 } 176 }
177 if((data == ' ') || (data == '\n')) /* Abort data detection */ 177 if((data == ' ') || (data == '\n')) /* Abort data detection */
178 { 178 {
179 if(rxState == RX_DataComplete) 179 if(rxState == CO2RX_DataComplete)
180 { 180 {
181 CO2Connected = 1; 181 CO2Connected = 1;
182 if(localComState == UART_CO2_SETUP) 182 if(localComState == UART_CO2_SETUP)
183 { 183 {
184 if(dataType == '.') 184 if(dataType == '.')
202 break; 202 break;
203 case 'Z': externalInterface_SetCO2Value(dataValue); 203 case 'Z': externalInterface_SetCO2Value(dataValue);
204 break; 204 break;
205 case '.': externalInterface_SetCO2Scale(dataValue); 205 case '.': externalInterface_SetCO2Scale(dataValue);
206 break; 206 break;
207 default: rxState = RX_Ready; 207 default: rxState = CO2RX_Ready;
208 break; 208 break;
209 } 209 }
210 } 210 }
211 if(rxState != RX_Data0) /* reset state machine because message in wrong format */ 211 if(rxState != CO2RX_Data0) /* reset state machine because message in wrong format */
212 { 212 {
213 rxState = RX_Ready; 213 rxState = CO2RX_Ready;
214 } 214 }
215 } 215 }
216 externalInterface_SetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET,localComState); 216 externalInterface_SetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET,localComState);
217 } 217 }
218 218