0

I am using the PX4Flow Optical Flow Control Module with a Raspberry Pi, I receive Mavlink Messages through UART and need to decode them. Does anyone know where I can find the Code to do that? I'm writing in C.

I've searched Google for hours and though there are threads about this topic, none of these seem to have the information I need or point to a direction where to find them.

Thanks for your help.

user3030653
  • 41
  • 2
  • 9

1 Answers1

1

The official mavlink project includes encoding/decoding code in C (and Python): https://github.com/mavlink/mavlink

There's an example of using the mavlink C code at http://qgroundcontrol.org/dev/mavlink_linux_integration_tutorial:

memset(buf, 0, BUFFER_LENGTH);
recsize = recvfrom(sock,
                   (void *)buf, BUFFER_LENGTH,
                   0,
                   (struct sockaddr *)&gcAddr, &fromlen);
if (recsize > 0) {
    // Something received - print out all bytes and parse packet
    mavlink_message_t msg;
    mavlink_status_t status;

    printf("Bytes Received: %d\nDatagram: ", (int)recsize);
    for (i = 0; i < recsize; ++i)
      {
        temp = buf[i];
        printf("%02x ", (unsigned char)temp);
        if (mavlink_parse_char(MAVLINK_COMM_0, buf[i], &msg, &status))
          {
            // Packet received
            printf("\nReceived packet: SYS: %d, COMP: %d, LEN: %d, MSG ID: %d\n",
                   msg.sysid, msg.compid, msg.len, msg.msgid);
          }
      }
}
John Wiseman
  • 3,081
  • 1
  • 22
  • 31