/**
  ******************************************************************************
  * @file    BLV_485_Dev_FreshAirFun.c
  * @author  BLW RCU  development Team	林开锐
  * @version V1.0.0
  * @date    2023年2月24日
  * @brief   新风驱动总表
  ******************************************************************************
  */

#include "includes.h"
#include "BLV_485_Dev_FreshAirFun.h"
/*外设头文件开始*/
#include "BLV_485_Dev_BLWFreshAirFun.h"
#include "BLV_485_Dev_CLEDFreshAirFun.h"
/*外设头文件结束*/

/*设备驱动宏定义开始*/
#define RS485_DEV_PRO_FUN_01	DevExistJudgge(RS485_BLW_FreshAir_Flag, BLW_RS485_FreshAir_Init)	    //宝来威新风
#define RS485_DEV_PRO_FUN_02	DevExistJudgge(RS485_CLED_FreshAir_Flag, BLW_RS485_CLEDFreshAir_Init)	//CLED新风
//#define RS485_DEV_PRO_FUN_03	((DevFunP)NULL)
//#define RS485_DEV_PRO_FUN_03	((DevFunP)NULL)
//#define RS485_DEV_PRO_FUN_04	((DevFunP)NULL)            
/*设备驱动宏定义结束*/

#define FRESHAIR_MAXRET							0x03	//新风最大重发次数

/*函数声明开始*/
uint8_t FreshAir_Input_Check(uint32_t CfgDevAddIn,uint16_t DevInputLoop,uint16_t DevInputType);	//新风设备输入检测
void Set_FreshAir_Func(uint32_t DevAddrIn,uint16_t DevInputLoop,uint32_t DevAddrOut,uint16_t DevOutputLoop,uint16_t DevOutputType);	//设置新风设备功能
void CLED_FreshAir_Func(uint32_t DevAddrIn,uint16_t DevInputLoop,uint32_t DevAddrOut,uint16_t DevOutputLoop,uint16_t DevOutputType);
uint8_t CLED_FreshAir_Input_Check(uint32_t CfgDevAddIn,uint16_t DevInputLoop,uint16_t DevInputType);
/*函数声明结束*/

/*******************************************************************************
  * @brief      初始化新风设备数据
  * @param  
  *		len		初始化的数据长度
  *		data	初始化数据的首地址
  * @retval     None
  * @attention	None
*******************************************************************************/
void BLW_RS485_FreshAirFun_Init(uint16_t len, uint8_t *data)
{
	Device_Public_Information_G BUS_Public;	//新风设备共有属性
	RS485_FreshAir_INFO FreshAir_Info;	//新风设备私有属性

	memset(&BUS_Public, 0, sizeof(Device_Public_Information_G));	//共有属性清0
	memset(&FreshAir_Info, 0, sizeof(RS485_FreshAir_INFO));	//私有属性清0
	
	BUS_Public.addr = data[1];	//设备485地址
	BUS_Public.type = data[0];	//设备类型
	BUS_Public.baud = data[3] + (data[4]<<8) + (data[5]<<16) + (data[6]<<24);	//设备发送波特率
	BUS_Public.retry_num = 0x03;	//设备数据重发次数
	BUS_Public.wait_time = 0x0064;	//设备数据发送等待回复时间 - 100ms
	
	if(data[7]==ENUM_RS485_DEV_PRO_01)
	{
		BUS_Public.DevFunInfo.Dev_Input_Type_Get = FreshAir_Input_Check;	//新风设备输入检测
		BUS_Public.DevFunInfo.Dev_Output_Ctrl = Set_FreshAir_Func;	//设置新风设备功能
	}
	else if(data[7]==ENUM_RS485_DEV_PRO_02)
	{
		BUS_Public.DevFunInfo.Dev_Input_Type_Get = CLED_FreshAir_Input_Check;	//新风设备输入检测
		BUS_Public.DevFunInfo.Dev_Output_Ctrl = CLED_FreshAir_Func;	//CLED新风设备功能
	}
	
	FreshAir_Info.DevOffline = FreshAir_Info.DevOfflineLast = DEV_IS_LINEUNINIT;	//设备在线状态初始化
	switch(data[7])	//协议判断
	{
		case ENUM_RS485_DEV_PRO_01: if(NULL!=RS485_DEV_PRO_FUN_01) RS485_DEV_PRO_FUN_01(&BUS_Public, &FreshAir_Info);break;
		case ENUM_RS485_DEV_PRO_02: if(NULL!=RS485_DEV_PRO_FUN_02) RS485_DEV_PRO_FUN_02(&BUS_Public, &FreshAir_Info);break;
//		case ENUM_RS485_DEV_PRO_03: if(NULL!=RS485_DEV_PRO_FUN_03) RS485_DEV_PRO_FUN_03(&BUS_Public, &FreshAir_Info);break;
//		case ENUM_RS485_DEV_PRO_04: if(NULL!=RS485_DEV_PRO_FUN_04) RS485_DEV_PRO_FUN_04(&BUS_Public, &FreshAir_Info);break;
	}
	switch(data[2])	//端口判断
	{
		case Active_Port:	//主动端口
			BUS_Public.port = Active_Port;	//设备发送端口
			Add_ACT_Device_To_List2(&BUS_Public,(uint8_t *)&FreshAir_Info,sizeof(RS485_FreshAir_INFO));	//将填充后的数据添加到链表
			Act485_Info.baud = BUS_Public.baud;	//波特率赋值
			Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"主动总线波特率赋值:%d", Act485_Info.baud);
			Act485_Info.device_num += 1;
			break;
		case Polling_Port:	//轮询端口
			BUS_Public.port = Polling_Port;	//设备发送端口
			Add_POLL_Device_To_List2(&BUS_Public,(uint8_t *)&FreshAir_Info,sizeof(RS485_FreshAir_INFO));	//将填充后的数据添加到链表
			Poll485_Info.baud = BUS_Public.baud;	//波特率赋值
			Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"轮询总线波特率赋值:%d", Poll485_Info.baud);
			Poll485_Info.device_num += 1;
			break;
		case Bus_port:	//总线端口
			break;
	}
}

/*******************************************************************************
  * @brief      配置文件初始化新风设备数据
  * @param  
  *		dev_info	逻辑文件设备存在信息
  *		data		初始化数据的首地址
  *		data_len	初始化数据长度
  * @retval     None
  * @attention	None
*******************************************************************************/
void BLW_RS485_FreshAirFun_Logic_Init(LOGICFILE_DEVICE_INFO *dev_info,uint8_t *data,uint16_t data_len)
{
	Device_Public_Information_G BUS_Public;	//新风设备共有属性
	RS485_FreshAir_INFO FreshAir_Info;	//新风设备私有属性

	memset(&BUS_Public, 0, sizeof(Device_Public_Information_G));	//共有属性清0
	memset(&FreshAir_Info, 0, sizeof(RS485_FreshAir_INFO));	//私有属性清0
	
	BUS_Public.addr = dev_info->addr;	//设备485地址
	BUS_Public.type = dev_info->type;	//设备类型
	BUS_Public.baud = dev_info->baud;	//设备发送波特率
	BUS_Public.retry_num = 0x03;	//设备数据重发次数
	BUS_Public.wait_time = 0x0064;	//设备数据发送等待回复时间 - 100ms
	BUS_Public.Protocol = dev_info->version;	//保存协议
	
	if(data[7]==ENUM_RS485_DEV_PRO_01)
	{
		BUS_Public.DevFunInfo.Dev_Input_Type_Get = FreshAir_Input_Check;	//新风设备输入检测
		BUS_Public.DevFunInfo.Dev_Output_Ctrl = Set_FreshAir_Func;	//设置新风设备功能
	}
	else if(data[7]==ENUM_RS485_DEV_PRO_02)
	{
		BUS_Public.DevFunInfo.Dev_Input_Type_Get = CLED_FreshAir_Input_Check;	//新风设备输入检测
		BUS_Public.DevFunInfo.Dev_Output_Ctrl = CLED_FreshAir_Func;	//CLED新风设备功能
	}
	
	FreshAir_Info.DevOffline = FreshAir_Info.DevOfflineLast = DEV_IS_LINEUNINIT;	//设备在线状态初始化
	switch(BUS_Public.Protocol)	//协议判断
	{
		case ENUM_RS485_DEV_PRO_01: if(NULL!=RS485_DEV_PRO_FUN_01) RS485_DEV_PRO_FUN_01(&BUS_Public, &FreshAir_Info);break;
		case ENUM_RS485_DEV_PRO_02: if(NULL!=RS485_DEV_PRO_FUN_02) RS485_DEV_PRO_FUN_02(&BUS_Public, &FreshAir_Info);break;
//		case ENUM_RS485_DEV_PRO_03: if(NULL!=RS485_DEV_PRO_FUN_03) RS485_DEV_PRO_FUN_03(&BUS_Public, &FreshAir_Info);break;
//		case ENUM_RS485_DEV_PRO_04: if(NULL!=RS485_DEV_PRO_FUN_04) RS485_DEV_PRO_FUN_04(&BUS_Public, &FreshAir_Info);break;
	}
	switch(dev_info->port)	//端口判断
	{
		case Active_Port:	//主动端口
			BUS_Public.port = Active_Port;		//设备发送端口
			Add_ACT_Device_To_List2(&BUS_Public,(uint8_t *)&FreshAir_Info,sizeof(RS485_FreshAir_INFO));
			Act485_Info.device_num += 1;
			break;
		case Polling_Port:	//轮询端口
			BUS_Public.port = Polling_Port;		//设备发送端口
			Add_POLL_Device_To_List2(&BUS_Public,(uint8_t *)&FreshAir_Info,sizeof(RS485_FreshAir_INFO));   //将填充后的数据添加到链表
			Poll485_Info.device_num += 1;
			break;
		case Bus_port:	//总线端口
			break;
	}
}

/*******************************************************************************
  * @brief      新风设备输入检测
  * @param  
  *		CfgDevAddIn		输入触发节点
  *		DevInputLoop	设备输入回路
  *		DevInputType	输入类型
  * @retval
		CtrlInvalid - 控制无效
		CtrlValid - 控制有效
  * @attention	None
*******************************************************************************/
uint8_t FreshAir_Input_Check(uint32_t CfgDevAddIn,uint16_t DevInputLoop,uint16_t DevInputType)
{
	uint8_t rec = CtrlInvalid;	//返回值（默认不是宝来威新风数据）
//	static uint8_t on_off_last = 0, wind_velocity_last = 0;	//上一次开关机、风速状态
	uint8_t keep_flag = 0x00;
	
	
	if(CfgDevAddIn == NULL) return rec;
	FreshAir_Content_Struct FreshAir_Input;	//新风输入控制条件
	
	Device_Public_Information_G BUS_Public;	//新风设备共有属性
	RS485_FreshAir_INFO FreshAir_Info;	//新风设备私有属性
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), CfgDevAddIn);	//读取共有属性
	SRAM_DMA_Read_Buff((uint8_t *)&FreshAir_Info,sizeof(RS485_FreshAir_INFO), CfgDevAddIn+Dev_Privately);	//读取私有属性
	
	FreshAir_Input.on_off = DevInputType & 0x01;	//取输入控制开关机
	FreshAir_Input.wind_velocity = (DevInputType >> 8) & 0x0F;	//取输入控制风速
	if(FreshAir_Info.new_state.on_off != FreshAir_Info.last_state.on_off || FreshAir_Info.new_state.wind_velocity != FreshAir_Info.last_state.wind_velocity)	//当前状态发生变化
	{
		if(FreshAir_Input.on_off == FRESHAIR_ON)	//输入控制开关机为开机
		{
			if(FreshAir_Info.new_state.on_off == FRESHAIR_ON)	//并且当前开关机状态为开机
			{
				if(FreshAir_Input.wind_velocity == FreshAir_Info.new_state.wind_velocity)	//对应风速相同
				{
					FreshAir_Info.last_state.on_off = FreshAir_Info.new_state.on_off;	//更新开关机状态
					FreshAir_Info.last_state.wind_velocity = FreshAir_Info.new_state.wind_velocity;	//更新风速状态
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"新风当前状态发生变化，执行当前 %d 风速对应动作",FreshAir_Input.wind_velocity);
					rec = CtrlValid;
					keep_flag = 0x01;
				}
			}
		}
		if(FreshAir_Input.on_off == FRESHAIR_OFF)	//输入控制开关机为关机
		{
			if(FreshAir_Info.new_state.on_off == FRESHAIR_OFF)	//并且当前开关机状态为关机
			{
				if(FreshAir_Input.wind_velocity == 0x00)	//对应风速为0
				{
					FreshAir_Info.last_state.on_off = FreshAir_Info.new_state.on_off;	//更新开关机状态
					FreshAir_Info.last_state.wind_velocity = FreshAir_Info.new_state.wind_velocity;	//更新风速状态
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"新风当前状态发生变化，执行当前 %d 风速对应动作",FreshAir_Input.wind_velocity);
					rec = CtrlValid;
					keep_flag = 0x01;
				}
			}
		}
	}
	
	
	if(keep_flag == 0x01)
	{
		BUS_Public.check = 0x00;	//校验和先置0
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&FreshAir_Info, sizeof(RS485_FreshAir_INFO));	//两个数组和校验取反
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), CfgDevAddIn);	//保存新风设备共有属性
		SRAM_DMA_Write_Buff((uint8_t *)&FreshAir_Info,sizeof(RS485_FreshAir_INFO), CfgDevAddIn + Dev_Privately);	//保存新风设备私有属性
	}
	
	
	
	return rec;
}

/*******************************************************************************
  * @brief      设置新风设备功能
  * @param  
  *		DevAddrIn		设备地址输入
  *		DevInputLoop	输入地址
  *		DevAddrOut		共有数据地址
  *		DevOutputLoop	输出回路数
  *		DevOutputType	输出类型
  * @retval     None
  * @attention	None
*******************************************************************************/
void Set_FreshAir_Func(uint32_t DevAddrIn,uint16_t DevInputLoop,uint32_t DevAddrOut,uint16_t DevOutputLoop,uint16_t DevOutputType)
{
	uint8_t function, content;	//功能，内容
	uint8_t save_flag = 0;	//保存标志
	Device_Public_Information_G BUS_Public;	//新风设备共有属性
	RS485_FreshAir_INFO FreshAir_Info;	//新风设备私有属性
	
	if(DevAddrOut == NULL)
	{
		return ;
	}
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), DevAddrOut);	//读取共有属性
	SRAM_DMA_Read_Buff((uint8_t *)&FreshAir_Info,sizeof(RS485_FreshAir_INFO), DevAddrOut+Dev_Privately);	//读取私有属性
	function = DevOutputType & 0x00FF;	//取低8位
	content = (DevOutputType >> 8) & 0x00FF;	//取高8位
	switch(function)	//判断命令
	{
		case FRESHAIR_ON_OFF_FUNCTION:	//开关机功能
			switch(content)	//判断内容
			{
				case FRESHAIR_ON:	//开机
				case FRESHAIR_OFF:	//关机
					FreshAir_Info.ctrl_content.on_off = content;
					FreshAir_Info.ctrl_flag.on_off = 0x01;	//控制开关机置1
					FreshAir_Info.ctrl_cnt.on_off = FRESHAIR_MAXRET;	//控制新风开关机发送次数
					save_flag = 1;	//保存标志置1
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"执行新风开关机控制，地址:%d 回路%d 状态:%d",BUS_Public.addr,DevOutputLoop,FreshAir_Info.ctrl_content.on_off);
					break;
			}
			break;
		case FRESHAIR_WIND_VELOCITY_FUNCTION:	//设置风速功能
			switch(content)	//判断内容
			{
				case WIND_VELOCITY_HIGH:	//风速高速
				case WIND_VELOCITY_MID:	//风速中速
				case WIND_VELOCITY_LOW:	//风速低速
					if(FreshAir_Info.new_state.on_off == FRESHAIR_ON)	//只有在开机状态下才能设置风速
					{
						FreshAir_Info.ctrl_content.wind_velocity = content;
						FreshAir_Info.ctrl_flag.wind_velocity = 0x01;	//控制风速置1
						FreshAir_Info.ctrl_cnt.wind_velocity = FRESHAIR_MAXRET;	//控制新风风速发送次数
						save_flag = 1;	//保存标志置1
						Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"执行新风风速控制，地址:%d 回路%d 状态:%d",BUS_Public.addr,DevOutputLoop,FreshAir_Info.ctrl_content.wind_velocity);
					}
					break;
			}
			break;
//		case FRESHAIR_READ_REGISTER_FUNCTION:	//读寄存器命令
//			switch(content)
//			{
//				case REGISTER0:	//寄存器0
//				case REGISTER1:	//寄存器1
//				case REGISTER2:	//寄存器2
//				case REGISTER3:	//寄存器3
//				case REGISTER4:	//寄存器4
//				case REGISTER5:	//寄存器5
//				case REGISTER6:	//寄存器6
//				case REGISTER7:	//寄存器7
//				case REGISTER8:	//寄存器8
//				case REGISTER9:	//寄存器9
//				case REGISTER10://寄存器10
//					break;
//			}
//			break;
//		case FRESHAIR_WRITE_REGISTER_FUNCTION:	//写寄存器命令
//			switch(content)
//			{
//				case REGISTER0:	//寄存器0
//				case REGISTER1:	//寄存器1
//				case REGISTER2:	//寄存器2
//				case REGISTER3:	//寄存器3
//				case REGISTER4:	//寄存器4
//				case REGISTER5:	//寄存器5
//				case REGISTER6:	//寄存器6
//				case REGISTER7:	//寄存器7
//				case REGISTER8:	//寄存器8
//				case REGISTER9:	//寄存器9
//				case REGISTER10://寄存器10
//					break;
//			}
//			break;
	}
	if(save_flag == 0x01)
	{
		BUS_Public.check = 0x00;	//校验和先置0
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&FreshAir_Info, 
							sizeof(RS485_FreshAir_INFO));	//两个数组和校验取反
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), DevAddrOut);	//保存新风设备共有属性
		SRAM_DMA_Write_Buff((uint8_t *)&FreshAir_Info,sizeof(RS485_FreshAir_INFO), DevAddrOut + Dev_Privately);	//保存新风设备私有属性
	}
}



/*******************************************************************************
  * @brief  CLED设置新风设备功能
  * @param  
  *		DevAddrIn		设备地址输入
  *		DevInputLoop	输入地址
  *		DevAddrOut		共有数据地址
  *		DevOutputLoop	输出回路数
  *		DevOutputType	输出类型
  * @retval     None
  * @attention	None
*******************************************************************************/
void CLED_FreshAir_Func(uint32_t DevAddrIn,uint16_t DevInputLoop,uint32_t DevAddrOut,uint16_t DevOutputLoop,uint16_t DevOutputType)
{
	uint8_t onoff, wind;	//功能，内容
	uint8_t save_flag = 0;	//保存标志
	Device_Public_Information_G BUS_Public;	//新风设备共有属性
	RS485_FreshAir_INFO FreshAir_Info;	//新风设备私有属性
	
	if(DevAddrOut == NULL)
	{
		return ;
	}
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), DevAddrOut);	//读取共有属性
	SRAM_DMA_Read_Buff((uint8_t *)&FreshAir_Info,sizeof(RS485_FreshAir_INFO), DevAddrOut+Dev_Privately);	//读取私有属性
	onoff = DevOutputType & 0x00FF;	//取低8位
	wind = (DevOutputType >> 8) & 0x00FF;	//取高8位
	
	switch(onoff)
	{
		case 0x00:
		case 0x01:
			FreshAir_Info.ctrl_content.on_off = onoff;
			FreshAir_Info.ctrl_flag.on_off = 0x01;	//控制开关机置1
			FreshAir_Info.ctrl_cnt.on_off = FRESHAIR_MAXRET;	//控制新风开关机发送次数
			save_flag = 1;	//保存标志置1
			break;
	}
	
	switch(wind)
	{
		case 0x00:
		case 0x01:
		case 0x02:
		case 0x03:
			FreshAir_Info.ctrl_content.wind_velocity = wind;
			FreshAir_Info.ctrl_flag.wind_velocity = 0x01;	//控制风速置1
			FreshAir_Info.ctrl_cnt.wind_velocity = FRESHAIR_MAXRET;	//控制新风风速发送次数
			save_flag = 1;	//保存标志置1
			break;
	}
	
	Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"执行CLED新风控制，地址:%d 回路%d 开关机:%d 风速:%d",\
	BUS_Public.addr,DevOutputLoop,FreshAir_Info.ctrl_content.on_off,FreshAir_Info.ctrl_content.wind_velocity);
	
	if(save_flag == 0x01)
	{
		BUS_Public.check = 0x00;	//校验和先置0
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&FreshAir_Info, sizeof(RS485_FreshAir_INFO));	//两个数组和校验取反
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), DevAddrOut);	//保存新风设备共有属性
		SRAM_DMA_Write_Buff((uint8_t *)&FreshAir_Info,sizeof(RS485_FreshAir_INFO), DevAddrOut + Dev_Privately);	//保存新风设备私有属性
		
//		Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"CLED新风保存，地址:%d 回路%d 开关机:%d 风速:%d",\
		BUS_Public.addr,DevOutputLoop,FreshAir_Info.ctrl_content.on_off,FreshAir_Info.ctrl_content.wind_velocity);
	}
}



/*******************************************************************************
  * @brief      CLED新风设备输入检测
  * @param  
  *		CfgDevAddIn		输入触发节点
  *		DevInputLoop	设备输入回路
  *		DevInputType	输入类型
  * @retval
		CtrlInvalid - 控制无效
		CtrlValid - 控制有效
  * @attention	None
*******************************************************************************/
uint8_t CLED_FreshAir_Input_Check(uint32_t CfgDevAddIn,uint16_t DevInputLoop,uint16_t DevInputType)
{
	uint8_t rec = CtrlInvalid;	//返回值（默认不是宝来威新风数据）
//	static uint8_t on_off_last = 0, wind_velocity_last = 0;	//上一次开关机、风速状态
	
	uint8_t keep_flag = 0x00;
	
	if(CfgDevAddIn == NULL) return rec;
	FreshAir_Content_Struct FreshAir_Input;	//新风输入控制条件
	
	Device_Public_Information_G BUS_Public;	//新风设备共有属性
	RS485_FreshAir_INFO FreshAir_Info;	//新风设备私有属性
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), CfgDevAddIn);	//读取共有属性
	SRAM_DMA_Read_Buff((uint8_t *)&FreshAir_Info,sizeof(RS485_FreshAir_INFO), CfgDevAddIn+Dev_Privately);	//读取私有属性
	
	FreshAir_Input.on_off = DevInputType & 0xFF;	//取输入控制开关机
	FreshAir_Input.wind_velocity = (DevInputType >> 8) & 0xFF;	//取输入控制风速
	
	
	if(FreshAir_Info.new_state.on_off != FreshAir_Info.last_state.on_off || FreshAir_Info.new_state.wind_velocity != FreshAir_Info.last_state.wind_velocity)	//当前状态发生变化
	{
		if(FreshAir_Input.on_off == FRESHAIR_ON)	//输入控制开关机为开机
		{
			if(FreshAir_Info.new_state.on_off == FRESHAIR_ON)	//并且当前开关机状态为开机
			{
				if(FreshAir_Input.wind_velocity == FreshAir_Info.new_state.wind_velocity)	//对应风速相同
				{
					FreshAir_Info.last_state.on_off = FreshAir_Info.new_state.on_off;	//更新开关机状态
					FreshAir_Info.last_state.wind_velocity = FreshAir_Info.new_state.wind_velocity;	//更新风速状态
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"CLED新风当前状态发生变化，执行当前 %d 风速对应动作",FreshAir_Input.wind_velocity);
					rec = CtrlValid;
					keep_flag = 0x01;
				}
			}
		}
		if(FreshAir_Input.on_off == FRESHAIR_OFF)	//输入控制开关机为关机
		{
			if(FreshAir_Info.new_state.on_off == FRESHAIR_OFF)	//并且当前开关机状态为关机
			{
				if(FreshAir_Input.wind_velocity == 0x00)	//对应风速为0
				{
					FreshAir_Info.last_state.on_off = FreshAir_Info.new_state.on_off;	//更新开关机状态
					FreshAir_Info.last_state.wind_velocity = FreshAir_Info.new_state.wind_velocity;	//更新风速状态
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"CLED新风当前状态发生变化，执行当前 %d 风速对应动作",FreshAir_Input.wind_velocity);
					rec = CtrlValid;
					keep_flag = 0x01;
				}
			}
		}
	}
	
	
	if(keep_flag == 0x01)
	{
		BUS_Public.check = 0x00;	//校验和先置0
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&FreshAir_Info, sizeof(RS485_FreshAir_INFO));	//两个数组和校验取反
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), CfgDevAddIn);	//保存新风设备共有属性
		SRAM_DMA_Write_Buff((uint8_t *)&FreshAir_Info,sizeof(RS485_FreshAir_INFO), CfgDevAddIn + Dev_Privately);	//保存新风设备私有属性
	}
	
	
	return rec;
}


