Hi, I'm using n ATMEga328P to send commands to a ESP8266 via USART. I wrote some code to send commands and receive responses using two FIFO circular buffers (one receive buffer and one transmit buffer), and USART interrupts take care of sending/receiving data.
(the usual stuff). The ESP module receives a command and responds either with a response and OK\r\n or with ERROR\r\n. I'm checking the RX buffer after every command to see what response i got. I implemented a find(const char*) function that looks for a specific string of characters in the receive buffer, consuming the characters as it goes through them and blocking until it finds the string.
Now, this leaves me with this problem: I want to check wheter I received OK or ERROR and THEN parse the response, but the find function consumes the characters in the buffers (it calls a function USART_receive() that gets the char from the queue).
In general, how can I handle serial communication with such a module? (It will come in handy with BLE or GPRS modules as well...) in a robust fashion?