i reading about MAVlink and i try to read packages from pixhawk fly controller. I thought of another way to make the call and i want to know from this discussions readers if its ok and what are you think
On my reader .. i read the two first byte from the pixhawk.
The second byte need to be the PAYLOAD length --> so new i know that i need to read the 4 bytes of the header + PAYLOAD length bytes + 2 chcksub bytes.
So after reading the PAYLOAD length i define a byte array -> size is
( PAYLOAD.length + 4 + 2 ) and read from the serial to this buffer.
Is it ok to do it ?
The MAVLink protocol has HEADER + PAYLOAD + SIGNATURE format.
MAVLink v1.0
v1.0 is the standard protocol as specified by QGroundControl. It has the format:
The first byte is always the protocol start-of-frame: 0xFE
The second byte is always the payload length.
Hence your receive buffer size should be (PAYLOAD length) + 8.
The method you described will generally work for most packets received from the pixhawk. However, pixhawk (ArduPilot) makes use of an extended MAVLink protocol which has been coined "v2.0" which adds additional header and signature bytes.
MAVLink v2.0
v2.0 is the extended protocol which applies to a select few messages such as "STATUSTEXT". It has the format:
The first byte has the start-of-frame: 0xFD
The second byte is again the payload length.
Hence, your buffer size should be (PAYLOAD length) + 25.
If you want to process MAVLink message data from the pixhawk, or from the generated .tlog file you should set your input message buffer size based on the start of frame and payload length bytes, the first two bytes of any MAVLink message.