comparison Discovery/Src/tComm.c @ 886:d398ecc7d103 Evo_2_23

Improve communication stability: In case e.g. the bluetooth module has just been started some 'noice' characters may be in the receive buffer causing an error in the modul responds function. In case the legth of the response is unexpected then the buffer will be evaluated till it is empty or an matching answer is found.
author Ideenmodellierer
date Sun, 01 Sep 2024 21:38:06 +0200
parents fe955104901c
children 1b05a84f6d0f
comparison
equal deleted inserted replaced
885:8d3f3a635397 886:d398ecc7d103
2036 2036
2037 if(indexRef != sizeAnswer) /* unexpected answer => there might be characters left in RX que => read and check all rx bytes */ 2037 if(indexRef != sizeAnswer) /* unexpected answer => there might be characters left in RX que => read and check all rx bytes */
2038 { 2038 {
2039 do 2039 do
2040 { 2040 {
2041 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxBuffer[indexBuf], 1, 10); 2041 answer = HAL_ERROR;
2042 if (indexBuf < UART_CMD_BUF_SIZE) 2042 if (indexBuf < UART_CMD_BUF_SIZE)
2043 { 2043 {
2044 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxBuffer[indexBuf], 1, 10);
2045
2044 if(answerOkay[indexRef] == aRxBuffer[indexBuf]) 2046 if(answerOkay[indexRef] == aRxBuffer[indexBuf])
2045 { 2047 {
2046 indexRef++; 2048 indexRef++;
2047 } 2049 }
2048 else 2050 else
2052 indexRef = 0; 2054 indexRef = 0;
2053 } 2055 }
2054 } 2056 }
2055 indexBuf++; 2057 indexBuf++;
2056 } 2058 }
2057 }while(answer == HAL_OK); 2059 }while((answer == HAL_OK) && (indexRef != sizeAnswer));
2058 if(indexRef != sizeAnswer) 2060 if(indexRef != sizeAnswer)
2059 { 2061 {
2060 result = HAL_ERROR; 2062 result = HAL_ERROR;
2061 } 2063 }
2062 } 2064 }