how to interpret the serial data

The code I gave you is just an incomplete example - you need to fill in the blanks, or you could rewrite as, say, a simple state machine.
You original question wasn't specific.