#ifndef	__SOFT_UART_H
#define __SOFT_UART_H

#include "stm32f1xx_hal.h"
#include "soft_can.h"
#include "stdio.h"
#include "rkfifo.h"
#define UPDATE_FLAG   ((uint32_t)0x0801E000)

#define USART_2 	2
#define USART_3 	3

#define UART_FCU    1
#define UART_RADAR  2
#define UART_MCCOM  3

#define MAX_UART_BUF 256

#define GROUP_ID_FCU 0
#define GROUP_ID_PMU_UPDATE 204
#define GROUP_ID_F_UPDATE 51
#define GROUP_ID_B_UPDATE 52
#define GROUP_ID_T_UPDATE 56

#define GROUP_ID_WEIGHT_UPDATE  222

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

	uint8_t uart2_recv_buf[150];
	uint8_t uart3_recv_buf[128];
	uint8_t uart_dma_recv_counts;
	//uint8_t radar_update_buf[MAX_UART_BUF];
	uint32_t update_time;

	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;
}Uart;
#pragma pack()
extern Uart uart_info; 

#pragma pack(1)
typedef struct 
{
	uint8_t head;  //0xFE
	uint8_t len;
	uint8_t seq;
	uint8_t system_id; //0
	uint8_t group_id; 
	uint8_t msg_id;
	uint8_t head_bytes; //6
	uint8_t check_bytes;//2
	uint16_t crc;
	uint8_t payload[MAX_UART_BUF];
}Vk_protocol;
#pragma pack()
extern Vk_protocol fcu_protocol;
extern Vk_protocol radar_protocol;
extern rkfifo_t recv_rkfifo;
extern rkfifo_t send_uart_rkfifo;

extern uint8_t Update_buf[150];
extern bool radar_update_flag; // main函数中 是否进入升级标志

extern  uint32_t uart2_send_delay_time;
extern  uint32_t uart3_send_delay_time;

void uart_send_msg(void);
void UART_Init(void);
void uart2_send_msg(uint8_t *data,uint8_t size);
void uart3_send_msg(uint8_t *data,uint8_t size);
void check_uart_data(rkfifo_t *fifo);
bool uart_send_is_ok(uint8_t uart_num);
void send_uartfifo_msg(void);

#endif  
