Mercurial > public > ostc4
comparison Small_CPU/Src/uartProtocol_Co2.c @ 976:0b81ac558e89 Evo_2_23
Devbugfix UART buffer cleaning:
In the previous version a buffer cleaning function was used which resets the ringbuffer read index. As result the processing of data was stopped until the DMA write comes to the index 0. When reaching it the complete buffer was proceeded including possibly invalid data.
The usage of the cleanbuffer function was replaced by the flush buffer function (meaning the data is discarded but the data index is maintained). There was already a function for this. Because the function was 99% the same as the read function, it was integrated into the ReadData function. Calling the function with parameter flush = 1 will result in a buffer flush.
The workaround of the previous revision was updated to only be applied in case a DiveO2 sensor is operated in stand alone mode.
author | Ideenmodellierer |
---|---|
date | Wed, 29 Jan 2025 17:21:20 +0100 (7 weeks ago) |
parents | effadaa3a1f7 |
children |
comparison
equal
deleted
inserted
replaced
975:142f3d0363b3 | 976:0b81ac558e89 |
---|---|
81 | 81 |
82 if(localComState == UART_CO2_INIT) | 82 if(localComState == UART_CO2_INIT) |
83 { | 83 { |
84 CO2Connected = 0; | 84 CO2Connected = 0; |
85 externalInterface_SetCO2Scale(0.0); | 85 externalInterface_SetCO2Scale(0.0); |
86 UART_clearRxBuffer(&Uart1Ctrl); | 86 UART_ReadData(SENSOR_CO2, 1); /* flush buffer */ |
87 UART_StartDMA_Receiption(&Uart1Ctrl); | 87 UART_StartDMA_Receiption(&Uart1Ctrl); |
88 localComState = UART_CO2_SETUP; | 88 localComState = UART_CO2_SETUP; |
89 } | 89 } |
90 if(localComState == UART_CO2_SETUP) | 90 if(localComState == UART_CO2_SETUP) |
91 { | 91 { |
108 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 */ | 108 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 */ |
109 { | 109 { |
110 //if(cmdLength == 0) /* poll data */ | 110 //if(cmdLength == 0) /* poll data */ |
111 if(localComState == UART_CO2_IDLE) | 111 if(localComState == UART_CO2_IDLE) |
112 { | 112 { |
113 uartCo2_SendCmd(CO2CMD_GETDATA, cmdString, &cmdLength); | 113 if(externalInterface_GetCO2Scale() == 0.0) |
114 localComState = UART_CO2_OPERATING; | 114 { |
115 uartCo2_SendCmd(CO2CMD_GETSCALE, cmdString, &cmdLength); | |
116 localComState = UART_CO2_SETUP; | |
117 } | |
118 else | |
119 { | |
120 uartCo2_SendCmd(CO2CMD_GETDATA, cmdString, &cmdLength); | |
121 localComState = UART_CO2_OPERATING; | |
122 } | |
115 } | 123 } |
116 else /* resend last command */ | 124 else /* resend last command */ |
117 { | 125 { |
118 UART_SendCmdString(cmdString); | 126 UART_SendCmdString(cmdString); |
119 cmdLength = 0; | 127 cmdLength = 0; |
205 case '.': externalInterface_SetCO2Scale(dataValue); | 213 case '.': externalInterface_SetCO2Scale(dataValue); |
206 break; | 214 break; |
207 default: rxState = CO2RX_Ready; | 215 default: rxState = CO2RX_Ready; |
208 break; | 216 break; |
209 } | 217 } |
218 rxState = CO2RX_Ready; | |
210 } | 219 } |
211 if(rxState != CO2RX_Data0) /* reset state machine because message in wrong format */ | 220 if(rxState != CO2RX_Data0) /* reset state machine because message in wrong format */ |
212 { | 221 { |
213 rxState = CO2RX_Ready; | 222 rxState = CO2RX_Ready; |
214 } | 223 } |