I have debugged most of the communication between STM32 and the aircraft using the C language library. Including reading status information, reading and writing parameters, and downloading tasks.
However, the upload task section still failed to debug.
The problem is:
mavlink_msg_mission_count_pack(0xa8, 0XBE, &msg,1, 0,4, MAV_MISSION_TYPE_MISSION, 0);
l = mavlink_msg_to_send_buffer(sendda,&msg);
HAL_UART_Transmit(&huart2, sendda, l, 100);
After sending the Mission-COUNT packet, the aircraft does not return a Mission-QUEST-INT response.
I sent the Mission-COUNT packet in the order of the pictures, and then checked every 250MS to see if there was any data in the Mission-QUEST-INT, but it never had any data. Is there an error in the parameters in my mavlink_masg_comssion_comnt_cack package?
Compared to uploading tasks, downloading tasks are easier to debug and pass. Here is the program for downloading tasks.
if(0)//下载任务序列
{
neicun[0] = 0;//清除标志位
cpuzhizhen[0] = 0;
mavlink_msg_mission_request_list_pack(0xa8, 0XBE, &msg,1, 0, 0);//获取任务航点数
l = mavlink_msg_to_send_buffer(sendda,&msg);
HAL_UART_Transmit(&huart2, sendda, l, 100);
for(int i = 0; i < 5; i++)
{
cpuzhizhen[0] = 1;
delayms(250);
if(neicun[0] == 1)//如果收到响应
{
cpuzhizhen[0] = 2;
neicun[0] = 0;
//cpuzhizhen[3] = neicun[1];
for(int i2 = 0; i2 < neicun[1] ; i2++)//进入读任务序列
{
//cpuzhizhen[0] = 3;
neicun[2] = 0;
neicun[100] = i2;
mavlink_msg_mission_request_int_pack(0xa8, 0XBE, &msg,1, 0, i2,MAV_MISSION_TYPE_MISSION);
l = mavlink_msg_to_send_buffer(sendda,&msg);
HAL_UART_Transmit(&huart2, sendda, l, 100);
for(int i3 = 0; i3 < 5; i3++)
{
//cpuzhizhen[0] = 4;
delayms(250);
if(neicun[2] == 1)//如果收到响应
{
cpuzhizhen[1] = neicun[101];
cpuzhizhen[2] = neicun[102];
//cpuzhizhen[3] = neicun[103];
cpuzhizhen[0] = 5;
neicun[2]= 0;
break;
}
}
if(neicun[2] == 1)
{
cpuzhizhen[0] = 6;
break;
}
}
mavlink_msg_mission_ack_pack(0xa8, 0XBE, &msg, 1, 0, 0, MAV_MISSION_TYPE_MISSION, 0);
l = mavlink_msg_to_send_buffer(sendda,&msg);
HAL_UART_Transmit(&huart2, sendda, l, 100);
}
}
}
case MAVLINK_MSG_ID_MISSION_COUNT://任务数量
{
neicun[1] = mavlink_msg_mission_count_get_count(&msgin);
//cpuzhizhen[1] = neicun[1];
neicun[0] = 1;//响应标志位
//cpuzhizhen[2] ++;
break;
}
case MAVLINK_MSG_ID_MISSION_CURRENT://任务数量
{
//cpuzhizhen[1] = mavlink_msg_mission_current_get_total(&msgin);//
//cpuzhizhen[2] ++;
break;
}
case MAVLINK_MSG_ID_MISSION_REQUEST_INT://飞机请求任务
{
neicun[10] = 1;
neicun[12] = mavlink_msg_mission_request_int_get_seq(&msgin);
//cpuzhizhen[1] = mavlink_msg_mission_request_int_get_mission_type(&msgin);
//cpuzhizhen[2] ++;
//neicun[0] = 1;
break;
}
case MAVLINK_MSG_ID_MISSION_ITEM_INT://飞机请求任务
{
neicun[101 + neicun[ 100 ]] = mavlink_msg_mission_item_int_get_z(&msgin);
//cpuzhizhen[1] = mavlink_msg_mission_item_int_get_seq(&msgin);
neicun[2] = 1;
//cpuzhizhen[2]++;
break;
}
case MAVLINK_MSG_ID_MISSION_ACK://飞机接收任务结束的指令ACK
{
//neicun[2] = 2;
//cpuzhizhen[1] = mavlink_msg_mission_item_int_get_seq(&msgin);
//cpuzhizhen[2]++;
break;
}