#ifndef _SOFT_P_2_C_H
#define _SOFT_P_2_C_H
#include "stm32f1xx_hal.h"
#include "soft_can.h"
#include "stdio.h"
#include "common.h"

typedef enum
{
	RX_HEAD = 0,
	RX_PAYLOAD_LEN,
	RX_SEQ,
	RX_SYSID,
	RX_GROUPID,
	RX_MSGID,
	RX_PAYLOAD,
	RX_CHECK_LOW,
	RX_CHECK_HIGH
} Msg_Rx_Stage;

extern Msg_Rx_Stage recv_step;
extern int time_heart[3];
extern int time_count[3];
enum vklink_msgid
{
	_MSGID_VOL = 1,		   // 电压
	_MSGID_RADAR = 2,	   // 雷达
	_MSGID_FLOW = 3,	   // 流量计
	_MSGID_BMS = 4,		   // 电池
	_MSGID_PWM = 5,		   // p1 p2 a1 a2通道
	_MSGID_LED = 6,		   // 外部LED灯
	_MSGID_ATTITUDE = 8,   // 飞机姿态信息
	_MSGID_TIME = 9,	   // UTC时间信息
	_MSG_ENGIN = 10,	   // 发动机
	_MSGID_EFT_CON = 11,   // EFT输出CAN控制
	_MSGID_DEV_INFO = 12,  // 设备信息
	_MSGID_REQ = 20,	   // 请求信息
	_MSGID_ACK = 21,	   // 主控应答
	_MSGID_SET = 22,	   // 设置信息
	_MSGID_SHA1 = 25,	   // 智能电池SHA1验证
	_MSGID_DEV_LIST = 26,  // 设备SN,软硬件管理
	_MSGID_HEART = 27,     // 心跳检测
	_MSGID_360RADAR = 30,     //360雷达
	_MSGID_DMRADAR = 31,     //电目雷达测试
	_MSGID_F4DRADAR = 32,     //电目4d雷达测试
	_MSGID_UPDATA = 200,   // 升级信息
	_MSGID_CANDEBUG = 213, // CAN调试
};

enum vklink_MSGID_REQ
{
	MSGID_REQ_VERSION = 7, // 版本信息
};

enum vklink_MSGID_ACK
{
	MSGID_ACK_HEART = 1,    
	MSGID_ACK_VERSION = 7, // 版本信息
	MSGID_ACK_DEV = 26,	   // 版本信息
};

enum vklink_MSGID_SET
{
	MSGID_SET_F_RADAR = 1,		  // 设置前雷达
	MSGID_SET_B_RADAR = 2,		  // 设置后雷达
	MSGID_SET_T_RADAR = 6,		  // 设置防地雷达
	MSGID_SET_TR_BLIND = 7,       //设置雷达盲区
    MSGID_SET_BR_POWER = 8,       //设置雷达能量
	MSGID_SET_R_FUNC = 9,         //设置电目雷达功能
	MSGID_SET_RAW_SWITCH = 15,    //设置DM雷达原始数据开关
	MSGID_SET_GEELY = 10,		  // 设置轩浮发动机
	MSGID_SET_VOL = 20,			  // 设置电压
	MSGID_SET_MIMO_FLOW = 21,	  // 设置恩曌流量计系数
	MSGID_SET_FLOW_BACKGROUND = 22,//清除流量背景
	MSGID_SET_WEIGHT_K = 23,	  // 设置重量传感器K
	MSGID_SET_SEED_OUT_TYPE = 24, // 设置播撒输出类型pwm can
	MSGID_SET_SEED_CAL_TYPE = 25, // 设置播撒校准类型
	MSGID_SET_WEIGHT_MODE = 26,	  // 设置重量传感器工作模式
	MSGID_SET_MAX_RATE = 27,	  // 设置播撒最大下药率
	MSGID_SET_PMU_SERIAL = 28,    // 设置pmu序列号
	MSGID_SET_RADAR_FB = 29,      // 设置当前雷达前后/恢复出厂 恩曌雷达有效
	MSGID_SET_LACKLOSS_CAL = 30,  // 断料记校准
	MSGID_SET_PUMP_ID = 32,       // 设置CAN水泵ID
	MSGID_SET_PNCANID   = 55,	  // 设置EFT水泵电调CAN ID
	MSGID_SET_RESIWIRE_BLOWN = 60,// 熔断电阻丝
	MSGID_SET_FRADAR_SN = 98,     // 设置雷达SN号
	MSGID_SET_BRADAR_SN = 99,     // 设置雷达SN号
	MSGID_SET_TRADAR_SN = 100,    // 设置雷达SN号
};

enum vklink_PMU_SEND
{
	PMU_SEND_YAOCE = 1,		// 遥测信息
	PMU_SEND_REQINFO = 2,	// 请求信息
	PMU_SEND_ACK = 3,		// 主控应答信息
	PMU_SEND_VERSION = 4,	// 版本信息
	PMU_SEND_SHA1 = 5,		// 版本信息
	PMU_SEND_DEV_INFO = 6, // 设备信息
};


typedef enum
{
	DEV_SEED = 1,
	DEV_WEIGHT,
	DEV_PUMP,
	DEV_NOZZLE,
	DEV_ARM,
	DEV_FLOW,
	DEV_CHECKLOW,
	DEV_RADAR,
	DEV_BMS,
	DEV_ENGINE,
	DEV_CURRENT,
	DEV_L_PUMP1,
	DEV_L_PUMP2,
	DEV_PART_RADAR,
	DEV_PART_FRADAR,
	DEV_PART_BRADAR,
	DEV_QQ_BMS,
	DEV_TEMPSENSOR
} Dev_Type_NUM;

enum LOCK_STATUS
{
	STA_LOCK = 0,
	STA_UNLOCK = 1,
};

#define JET_UAV_TYPE 13
#define VK_ALL_IN_ONE  18
#define AG_EFTZ 	 15   //EFTZ30/50机型

// 吉利发动机设置信息
#define SET_START_OR_STOP 1
#define SET_PROTECT_TIME 2
#define SET_LOCK_TIME 3
#define SET_LOWVOL_PROTECT 4

typedef struct
{
	short radar_buf[5];
	uint16_t voltage;
	uint16_t temperature;
	uint32_t flow_32_buf[2];
	uint16_t flow_16_buf[4];
} pmu_data;
extern pmu_data pmu;



#pragma pack(1)
typedef struct
{
	short pump1;
	short pump2;
	short nozz1_fm;
	short nozz2_zp;
	short nozz3;
	short nozz4;
	uint16_t aux_light;
	short aux_steer;
}_pmu_pin;
#pragma pack()
extern _pmu_pin pmu_pin;

#pragma pack(1)
typedef struct
{
	short yaw;		   // 航向角
	short roll_angle;  // 0.01
	short pitch_angle; // 0.01
	short alt;
	short E_vel;	   // 东西速度
	short N_vel;	   // 南北速度
	short alt_vel;	   // 垂直速度
	short lock_status; // 0 上锁 1解锁
	short UAV_type;
	short thr_pwm;
	short Candebug_flag; // can调试 0开 1关
	int pos_x1;           //经度
	int pos_y1;			 //纬度
	float QuaterQ0;
	float QuaterQ1;
	float QuaterQ2;
	float QuaterQ3;
	float pos_x;
	float pos_y;
	float pos_z;
	float pos_flag;
} plane_para;
#pragma pack()
extern plane_para planep;


extern uint8_t msg_buf[256];

typedef struct soft_p_2_c
{
	uint8_t num;
	uint16_t content1;
	uint16_t content2;
	uint16_t content3;
} Set_info;
extern Set_info msgidset;

#pragma pack(1)
typedef struct
{
	bool version_info;

	bool key_info_checking; // 给fcu发送信息
	bool key_to_bms;
	uint8_t mos_status;
	uint8_t Dev_type;
	uint8_t Id;
	uint8_t Id_content;
	unsigned char key_data[20];

} Start_info;
extern Start_info start_msg;
#pragma pack(0)

extern char request_id;
extern short request_1_content;
extern int request_2_content;

extern char ack_id;
extern short ack_content;
extern short ack_content1;
extern short ack_content2;
extern uint8_t pmu_send;

extern char radar_version[3][10];
extern bool recv_fmu_data;

extern comp_status flow_linkflag_status;
extern uint32_t utc_time;

void pmu_to_con_voltage_data(void);
void pmu_to_con_radar_data(void);
void pmu_to_con_barttery_data(void);
void pmu_to_fcu(void);
void uart_recv_con_msg(void);
void Update_ack_func(uint8_t group_id, uint8_t msg_id, uint8_t *ackbuf);
void pmu_to_con_version_data(void);
void pmu_to_con_request_data(void);
void pmu_to_con_ack_data(void);
void pmu_start_info(void);
void pmu_set_ack(uint8_t id, short content1, short content2, short content3);
void pmu_to_con_engine_data(void);
void pmu_to_fcu_version_data(void);
void pmu_to_fcu_key_data(void);
short get_radar_info(uint8_t Radar_Type,uint8_t Info_Type);
#endif
