I use something like the following to call oneLineReceived
when a line from Serial is complete.
void handleSerial() {
static uint8_t bIndex;
static uint8_t buffer[maxMsgLen + 1];
bool lineReady = false;
if (Serial.available()) {
uint8_t inChar = Serial.read();
if (inChar != cbLF) {
if (inChar == cbCR) {
lineReady = true;
} else {
buffer[bIndex++] = inChar;
lineReady = (bIndex == maxMsgLen);
}
if (lineReady) {
buffer[bIndex] = 0;
oneLineReceived((const char*)buffer);
bIndex = 0;
}
}
}
}