/* * Read data from the serial device */ void ControlBoard::readPendingSerialData(void) { while (serialPort.bytesAvailable() > 0) { // FIXME: try to avoid unneccessary mallocing serialData.append(serialPort.readAll()); //qDebug() << "in" << __FUNCTION__ << ", data size: " << serialData.size(); } parseSerialData(); }
void loop() // run over and over again { Modes(); char c; if (Uart.available()) { c = Uart.read(); if(c == '<') // Start of packet { started = 1; ended = 0; } else if(c == '>') // End of packet { ended = 1; } else { buffer[serialIn] = c; serialIn++; buffer[serialIn] = '\0'; } } if(started && ended) // complete packet { if(buffer[0] == 'H' && buffer[1] == 'M' && buffer[2] == 'G') //header { Serial.println("RECEIVED HEADER"); parseSerialData(); // sorts data based on channel } serialIn = 0; buffer[serialIn] = '\0'; started = 0; ended = 0; } }