Alright . Ill try actually am not good at explaining .
Ill share my code and explain you through it . So excuse me if i say something wrong.
First you start by initializing and creating objects of the these specific classes .
Other things you need are system id =1(for vehicle ) component id=1 (for flight controller) target system id = 255( for mission planner) target component id =1 ( for mission planner )
#include "c_library_v2-master/ardupilotmega/mavlink.h"
mavlink_status_t status;
mavlink_message_t msg;
uint8_t sysid = 1, compid = 1, targetsys_id = 255, targetcomp_id = 1, count = 0;
//initialize serial
//I am using serial to connect to mission planner and serial1 to debug and read
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial1.begin(115200);
}
void loop() {
if (Serial.available() > 0)
{
while (Serial.available() > 0)
{
uint8_t byte = Serial.read();
if (mavlink_parse_char(chan, byte, &msg, &status))
{
Serial1.print("Received message with ID ");
Serial1.print(msg.msgid);
Serial1.print(" Serquence :");
Serial1.print(msg.seq);
Serial1.print(" from Component:");
Serial1.print(msg.compid);
Serial1.print(" of system:");
Serial1.println(msg.sysid);
... DECODE THE MESSAGE PAYLOAD HERE ...
Serial1.println(mavlink_get_msg_entry(&msg));
}
}
}
}
This will give you the message id that mp is request .
So once you get the message id you can further decode it by using a switch statement
switch (msg.msgid)
{
case MAVLINK_MSG_ID_REQUEST_DATA_STREAM :
{
req_message_rate = mavlink_msg_request_data_stream_get_req_message_rate(&msg);
target_system = mavlink_msg_request_data_stream_get_target_system(&msg);
target_component = mavlink_msg_request_data_stream_get_target_component(&msg);
req_stream_id = mavlink_msg_request_data_stream_get_req_stream_id(&msg);
start_stop = mavlink_msg_request_data_stream_get_start_stop(&msg);
Serial1.print("RDS ");
Serial1.print(req_message_rate);
Serial1.print(" ");
Serial1.print(target_system);
Serial1.print(" ");
Serial1.print(target_component);
Serial1.print(" ");
Serial1.print(req_stream_id);
Serial1.print(" ");
Serial1.println(start_stop);
}
}
This is and example to decode the elements of MSGid request_data_stream
Similiarly you can decode other messages once you get their msg id