Serial Port - Buffering questions - "sliding" / ring buffer performance

Your ring is implemented poorly. It seems a little like "schlemeil the painter". You are copying the entire string many times over.

Think of waiting by the mail slot at home and someone sends you a letter once per week. You are loking for "expected_string". If the first letter that comes through the slot is not an "e" then throw it away. Don't store it for later.

If you are waiting for several different messages then there may be several valid first letters. Then you might need to store only the matching letters. Usually you don't even do that because you always start the machine-to-machine messages with a single start char such as $ or <