#pragma once

#ifndef MAVLINK_CONTROL_H
#define MAVLINK_CONTROL_H

//关闭针对mavlink的警告
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
#include <common/mavlink.h>
#pragma GCC diagnostic pop




struct Mavlink_Messages {

	int sysid;
	int compid;

	// Heartbeat
	mavlink_heartbeat_t heartbeat;

	// System Status
	mavlink_sys_status_t sys_status;

	// Battery Status
	mavlink_battery_status_t battery_status;

	// Radio Status
	mavlink_radio_status_t radio_status;

	// Local Position
	mavlink_local_position_ned_t local_position_ned;

	// Global Position
	mavlink_global_position_int_t global_position_int;

	// Local Position Target
	mavlink_position_target_local_ned_t position_target_local_ned;

	// Global Position Target
	mavlink_position_target_global_int_t position_target_global_int;

	// HiRes IMU
	mavlink_highres_imu_t highres_imu;

	// Attitude
	mavlink_attitude_t attitude;

	// System Parameters?

};

typedef struct {

    mavlink_status_t lastStatus;
    struct Mavlink_Messages current_messages;
    
    bool debug;

	int (*read)(void *data, uint32_t size, uint32_t wait_ms);
	int (*write)(const void *data, uint32_t size, uint32_t wait_ms);
}mavlink_device_t;
/**
 * @brief 初始化mavlink
 * 
 * @param mavlink_device 接口
 */
void mavlink_init(mavlink_device_t* mavlink_device);
/**
 * @brief MAVLINK消息解析
 * 
 * @param mavlink_device 接口
 * @param message 解析成功存放消息
 * @param cp 数据
 */
int mavlink_message(mavlink_device_t* mavlink_device, mavlink_message_t* message,uint8_t cp);
/**
 * @brief MAVLINK消息发送
 * 
 * @param mavlink_device 接口
 * @param message 需要发送的消息
 */
int write_message(mavlink_device_t* mavlink_device, const mavlink_message_t *message);
/**
 * @brief MAVLINK消息处理
 * 
 * @param mavlink_device 接口
 * @param message 需要处理的消息
 */
void mavlik_packet_processing(mavlink_device_t* mavlink_device, mavlink_message_t* message);
/**
 * @brief MAVLINK消息接收 （针对需要自己进行读操作）
 * 
 * @param mavlink_device 接口
 */
void mavlink_recv_loop(mavlink_device_t* mavlink_device);
/**
 * @brief MAVLINK消息接收（针对已获取到数据缓存）
 * 
 * @param mavlink_device 接口
 * @param data 数据
 * @param size 大小
 */
void mavlink_recv_buf(mavlink_device_t* mavlink_device, void *data, uint32_t size);

#endif