/*
 * uart_rcv.h
 *
 *  Created on: 2022年4月20日
 *      Author: dell
 */

#ifndef UART_RCV_H_
#define UART_RCV_H_



#define DEBUG_BUF_SIZE (512)	// 调试串口缓冲区长度
#define FRAME_RCV_OVERTIME (10) // 帧接收超时时间，单位：ms
#define OVERTIME_SEC (10)		// 接收清除命令超时时间：10秒


#define BUF_SIZE (64)			// 调试串口缓冲区长度
#define FRAME_RCV_OVERTIME (10) // 帧接收超时时间，单位：ms
#define OVERTIME_SEC (10)
#define MINI7_HEADER_FALG 0x55AA
#define MINI7_TAIL_FALG 0x5A
#define MINI7_MASSAGE_SIZE 8
#define MINI7_MASSAGE_TYPE_MCUTOMCU 0x10

#define DEBUG_UART           UART0         //调试串口号
#define DEBUG_UART_RST       UART0_RST     //调试串口复位标志
#define DEBUG_UART_IRQ       UART02_IRQn   //中断向量

//#define hole1 	1
//#define hole2 	2
//#define hole3 	3
//#define hole4 	4
//#define hole5 	5
//#define hole6	6
//#define hole7 	7
//#define hole8 	8
//#define hole9 	9
//#define hole10 	10
//#define hole1 1

enum QR_CHECH_STATE
{
	QR_CHECH_STATE_FIRST = 0,
	QR_CHECH_STATE_TRYAGAIN = 1,
	QR_CHECH_STATE_WAITING= 3,
	QR_CHECH_STATE_SEND= 4,
};
enum QR_REC_STATE
{
	QR_REC_STATE_EMPTY = 0,
	QR_REC_STATE_HEADER ,
	QR_REC_STATE_SENDPRAM,
	QR_REC_STATE_SENDQR,
	QR_REC_STATE_END,
};

/* 串口命令码  */
enum
{
	UART0_PARAM_DOWNLOAD  = 0x01,           //参数下载
	UART0_HEAT_CTRL       = 0x02,           //加热控制
	UART0_lIGHTBAND_CTRL  = 0x03,           //灯带控制
	UART0_QRSCANNER_CTRL  = 0x04,           //二维码扫码模块控制
	UART0_FAN_CTRL        = 0x05,           //风扇控制
	UART0_CARD_STA        = 0x06,           //风扇控制
	UART0_CMD_REPLY       = 0x10,           //回复命令
};
/* 串口2命令码  */
enum
{
	UART2_CMD_RCV         = 0x00,           //命令回复

};
typedef struct
{
	uint8_t   heat_state;            		//串口控制加热状态
	uint8_t   temp_stable_sta;            	//加热稳定状态
	uint8_t   fan_state;   					//风扇状态
	uint8_t   card_state;   				//插卡状态
	float     SetTempVal;
	uint32_t  PresetTempTime;
	float     PresetTempVal;
	
	float    HoldTemp;       //稳定温度
	float	TempOffset;		//温度补偿
	uint32_t  PreHeatTime;					//上电预热时间,min
	float     ReadyTempVal;					//就绪温度55℃
	float     adJTarget;					//根据环境温度，修正目标温度
}heat_ctrl_struct;

extern heat_ctrl_struct g_heat_ctrl;




//灯带控制参数
struct light_band_para_t
{
	uint8_t		channel;
	uint8_t		mode;
	uint16_t	speed;
	uint32_t	color;
};

struct str_card_param_info m_str_card_param_info;

void UART02_IRQHandler(void);
extern void debug_receive_int_handle0(void);
extern void debug_receive_int_handle1(void);
extern void debug_receive_int_handle2(void);
void uart0_rcv_data_analysis(void);
void uart1_rcv_data_analysis(void);
void uart2_rcv_frame_analysis(void);
void debug_receive_start0(void);
void debug_receive_start2(void);
void heater_state_upload(uint32_t upenv);
void trigmode_select_sensor(void);
void data_out_original(void);
int parse_qrcode_info(struct str_card_param_info *info, char *qrcode_str);
void QRparam_upload(str_card_param_info_t *p_str_card_param_info);
int DecodeNew(struct CmdMessage *pMessage, uint8_t *pdata, const uint8_t *pInBuffer, uint32_t* pheader,uint32_t  ulast,uint32_t maxlen);
void sendQR_inf(void);

#endif /* UART_RCV_H_ */
