#ifndef _SOFT_UPDATE_H
#define _SOFT_UPDATE_H 
#include "common.h"

//莫之比雷达设置灵敏度及反馈
#define CAN_UAVRH_SENSI_SA      (0x7F6)
//莫之比雷达读取灵敏度及反馈
#define CAN_UAVRH_SENSI_RA      (0x7F8)

enum vk_update_device
{
    // Update_buf 元素地址
    HEAD = 0,
    LEN = 1,
    TOTAL_PACK_NUM = 2,
    DEVICE = 4,
    UPDATE_STEP = 5,
    PACK_NUM = 6,
    PAYLOAD = 8,

    //更新步骤
    UPDATE_START = 200,
    UPDATE_ING = 201,
    UPDATE_END = 202,

    //设备ID
    UPDATE_OBS_F = 0x11,
    UPDATE_OBS_B = 0x12,
    UPDATE_TERAIN = 0x56,
    UPDATE_OBS360 = 0x78,
    UPDATE_SEED = 0xDA,
    UPDATE_FLOW = 0xDB,
    UPDATE_BMS = 0XDC,
    UPDATE_DISTOR = 0XDD,
    UPDATE_WEIGHT = 0xDE,
};

typedef struct 
{
    bool update_flag;
    uint8_t step;
    uint8_t node_id;
    uint32_t adr_offset;

    uint8_t frame_pci;
    uint8_t frame_len;

    uint8_t pack_content;
}ez_update;
extern ez_update EZup_par;

enum EZ_UPDATE
{
    STEP_DEFAULT = 0,
    STEP_FIND_NODE = 1, //发送125次寻找设备节点ID
    STEP_JUMP_BOOT = 2, //跳转boot
    STEP_EASER_FLASH = 3,//擦除FLASH
    STEP_SET_OFFSET_ADR = 4,//设置偏移地址
    STEP_SEND_DATE = 5, //发送升级数据
    STEP_ENDING = 6, //升级结束
    STEP_WAIT = 7,//等待

    PACK_HEAD = 10, //包头
    PACK_CONT = 11, //内容
    PACK_TAIL = 12, //包尾
    PACK_CRC = 13, //校验
    PACK_WAIT = 14, //等待雷达写flash
};

#pragma pack(1)
typedef struct 
{
   bool U7E1;
   bool U7E3;
   bool U7E6;
   bool buf_flag;
   bool update_flag;  //与AG不兼容 一个判断标志
   uint8_t update_buf[8];
}Radar;
#pragma pack()
extern Radar Rupdate;

extern bool uavrhup_getr1_ack;

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

   uint8_t buf[150];

	bool vk_dev_update_flag;
	uint16_t vk_dev_pack_num;
	uint32_t bin_size;

	bool step_200_flag;
	bool step_201_flag;
	bool step_202_flag;
}Update;
#pragma pack()
extern Update update_info; 


#pragma pack(1)
typedef struct 
{
    bool update_flag;
    uint32_t bin_size;
    uint32_t bin_crc;
    uint8_t step;
    uint8_t dev_id;

    uint8_t buf[256];
    bool send_pack_complete;
    uint32_t pack_num;
    uint8_t end_frame_flag;
    uint16_t totol_packNum;
    uint8_t pack_crc;

    bool step_200_flag;
	bool step_201_flag;
	bool step_202_flag;
}_eft_update;
extern _eft_update eft_update;
#pragma pack()

enum EFT_UPDATE
{
    STEP_START = 1,
    STEP_UPDATING = 2,
    STEP_END = 3,
    STEP_WAIT_ACK,
};

extern bool radar_update_flag;
extern uint32_t update_count;
void can_recv_mocib_updata_read_set_hookfunction(uint32_t cellCanID, uint8_t data[]);
void Update_Dev_Bootversion_Function(uint8_t data[]);
void mimo_obs_update_func(void);
void EZ_Radar_UpdateCanRecvHookFunction(uint32_t CanID, uint8_t data[], uint8_t len);
void Can_obstacle_update();
void eft_dev_update_func(void);
void eft_dev_update_wait_ereseflash(uint8_t data[]);
void Vk_Update_Device_Protocol(void);
#endif