I am attempting to read data over serial from a Pixhawk flight controller which communicates via the Mavlink protocol. It sends 17 bytes, the first three being 0xFE, 0x09 followed by a counter that increments every message. I have confirmed this with GtkTerm.
However when I run the following code, 0x09 (the second byte) is always skipped so only 16 bytes of each 17 byte message is received.
Any ideas? Thanks, James.
LibSerial::SerialStream pixhawkSerial;
pixhawkSerial.Open("/dev/ttyACM0");
pixhawkSerial.SetBaudRate( LibSerial::SerialStreamBuf::BAUD_57600 ) ;
pixhawkSerial.SetCharSize( LibSerial::SerialStreamBuf::CHAR_SIZE_8 );
pixhawkSerial.SetNumOfStopBits(1);
pixhawkSerial.SetParity( LibSerial::SerialStreamBuf::PARITY_NONE ) ;
pixhawkSerial.SetFlowControl( LibSerial::SerialStreamBuf::FLOW_CONTROL_NONE );
char next_byte [100];
int i = 0;
while (i<100){
if( pixhawkSerial.rdbuf()->in_avail() > 0 ){
pixhawkSerial >> next_byte[i];
i++;
}
else cout << "No data" << endl;
}