I think the problem is that you leave 'ended' set to true when you process your first input. Then the second time through if there is not a full message in the buffer it gets processed anyway because 'ended' is true.
Add these lines:
started = true;
ended = false; ////////// Add this
index = 0;
if (ended)
{
ended = false; ///////// Add this
Alternatively you can use a single state variable:
enum {WAITING_FOR_START, STARTED} state = WAITING_FOR_START;
switch (state)
{
case WAITING_FOR_START:
if (inChar == '<')
{
state = STARTED;
index = 0;
}
break
case STARTED:
if (inChar == '>')
{
inData[index] = '\0'; // Terminate the string
process();
state = WAITING_FOR_START;
}
else
inData[index++] = inChar;
break;
}
Note that this code doesn't put the '<' and '>' in the buffer so they don't need to be removed in process().