I'll add some more comments to the function which might help clarify things.
void recvWithStartEndMarkers() {
//
// This functions reads from the Serial port, looking for a string of characters enclosed in '<' and '>'
// markers (up to numChars-1 long), and saves it to the global char array receivedChars.
//
static boolean recvInProgress = false; // flag to tell us if we are in the string we want
static byte ndx = 0; // index into the destination array
char startMarker = '<';
char endMarker = '>';
char rc; // latest received character
while (Serial.available() > 0 && newData == false) { // if we're starting a new string
rc = Serial.read(); // read the next character
if (recvInProgress == true) { // if we're already in a marked sequence
if (rc != endMarker) { // but not got to the end of it yet
receivedChars[ndx] = rc; // store the character
ndx++; // increment the index ready for the next
if (ndx >= numChars) { // if the output array is full
ndx = numChars - 1; // fudge it
} // (this is not very good code, but I haven't
} // time to rewrite it)
else { // we're done for this time
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) { // we weren't already in a marked string, so is the start of one?
recvInProgress = true; // yes, so flag it so that we know
}
}
}
I hope this helps. Using the Serial.readBytesUntil(character, buffer, length) function might have made the code a bit simpler.