/**
  ******************************************************************************
  * @file    BLV_Nor_Dev_CurtainFun.c
  * @author  BLW RCU  development Team
  * @version V1.0.0
  * @date    2021年11月01日
  * @brief   窗帘初始化   设备窗帘控制
  * @attention 设备窗帘
  *		输入检测：  有
  *     输入类型：  有
			开\关\停 	
  *     执行函数：  有		
  *     执行方式：开\关\停  延时1S开\延时1S关\延时停止
	2022-06-16 曹聪 
		新增执行方式：延时1S开\延时1S关\延时停止
			该延时只是驱动层的控制延时，与逻辑层的控制延时无关
	2023-09-07 YHF
		由开切换至关或者由关切换至开时延时1S，其余情况不延时
  ******************************************************************************
  */
  
#include "includes.h"

#include "BLV_Nor_Dev_CurtainFun.h"
#include "BLV_Nor_DevFun.h"

#define CFG_NodeCurtain_OPEN   	 0x01            //配置控制设备窗帘开
#define CFG_NodeCurtain_CLOSE    0x02            //配置控制设备窗帘关
#define CFG_NodeCurtain_STOP   	 0x06            //配置控制设备窗帘停止
#define CFG_NodeCurtain_Change   0x04            //输入类型为变化    主要用于配置以窗帘为输入，扩展属性为对应窗帘开和关
#define CFG_NodeCurtain_TOGGLE   0x13            //配置控制设备开关互切

#define CFG_NodeCurtain_DelayOpen	0x15		//配置控制延时1S窗帘开
#define CFG_NodeCurtain_DelayClose	0x16		//配置控制延时1S窗帘关
#define CFG_NodeCurtain_DelayStop	0x17		//配置控制延时控制关闭

#define Device_Delay_Control_Enable	0x01		//2022-07-19	开启窗帘控制默认延时1S开关控制

/*本地函数申明开始*/
void Dev_Curtain_Dis(uint32_t DevAddr);

uint16_t Curtain_Loop_State(uint32_t devaddr, uint16_t DevOutputLoop);
void BLW_Curtain_Control_State(uint32_t CfgDevAddIn, uint16_t DevInputAddr, uint32_t devaddr,uint16_t DevOutputLoop,uint16_t start);
uint8_t Dev_Curtain_InType_Get(uint32_t DevAddr, uint16_t DevInputLoop, uint16_t DevInputType);
/*本地函数申明结束*/

/*窗帘新增到普通设备链表*/
void BLV_Nor_Dev_Curtain_Init(uint8_t devaddr)
{
	Device_Public_Information_G BUS_Public;
	NOR_CURTAIN_INFO DevCurtainInfo;       //窗帘局部变量
	
	memset(&BUS_Public,0,sizeof(Device_Public_Information_G));
	memset(&DevCurtainInfo,0,sizeof(NOR_CURTAIN_INFO));
	
	BUS_Public.addr = devaddr;			//设备地址
	BUS_Public.type = Dev_NodeCurtain;		//设备类型
	BUS_Public.port = NULL;			//设备发送端口
	BUS_Public.baud = 0000;			//设备发送波特率
//	BUS_Public.retry_num = 0x03;		//设备数据重发次数
//	BUS_Public.wait_time = 0x0064;		//设备数据发送等待回复时间
//	BUS_Public.polling_cf = (uint32_t)&BLW_Touch_SwitchCycleDis;
//	BUS_Public.processing_cf = (uint32_t)&BLW_Rs485_Touch_Swi_Check;
	
	BUS_Public.DevFunInfo.Dev_Data_Process = Dev_Curtain_Dis;                 //
	BUS_Public.DevFunInfo.Dev_Input_Type_Get = Dev_Curtain_InType_Get;        //
	BUS_Public.DevFunInfo.Dev_Output_Ctrl = BLW_Curtain_Control_State;        //
	BUS_Public.DevFunInfo.Dev_Output_Loop_State_Get = Curtain_Loop_State;     //
	
	
	
	Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"增加一个窗帘，窗帘私有数据长度:%d",sizeof(NOR_CURTAIN_INFO));
//	switch(BUS_Public.addr)
//	{
//		case 0x00:memcpy(&DevCurtainInfo.DevNameStruct, "窗帘", strlen("窗帘"));break;
//		case 0x01:memcpy(&DevCurtainInfo.DevNameStruct, "窗纱", strlen("窗纱"));break;
//		case 0x02:memcpy(&DevCurtainInfo.DevNameStruct, "窗帘", strlen("窗帘"));break;
//		case 0x03:memcpy(&DevCurtainInfo.DevNameStruct, "窗纱", strlen("窗纱"));break;
//		case 0x04:memcpy(&DevCurtainInfo.DevNameStruct, "窗帘", strlen("窗帘"));break;
//		case 0x05:memcpy(&DevCurtainInfo.DevNameStruct, "窗纱", strlen("窗纱"));break;
//		case 0x06:memcpy(&DevCurtainInfo.DevNameStruct, "窗帘", strlen("窗帘"));break;
//		case 0x07:memcpy(&DevCurtainInfo.DevNameStruct, "窗纱", strlen("窗纱"));break;
//		case 0x08:memcpy(&DevCurtainInfo.DevNameStruct, "窗帘", strlen("窗帘"));break;
//		
//	}
//	{
//		uint8_t SerData[200];
//		if(sizeof(NOR_CURTAIN_INFO) <= 200)
//		{
//			memcpy(SerData, &DevCurtainInfo, sizeof(NOR_CURTAIN_INFO));
//		
//			for(uint16_t j = 0; j < sizeof(NOR_CURTAIN_INFO); j++)
//			{
//				 
//				printf("%02X ", SerData[j]);
//			}
//			printf("\n\r");
//		}
//	}
	Add_Nor_Device_To_List2(&BUS_Public,(uint8_t *)&DevCurtainInfo,sizeof(NOR_CURTAIN_INFO));
}


/*窗帘新增到普通设备链表*/
void BLV_Nor_Dev_Curtain_Logic_Init(LOGICFILE_DEVICE_INFO *dev_info,uint8_t *data,uint16_t data_len)
{
	Device_Public_Information_G BUS_Public;
	NOR_CURTAIN_INFO DevCurtainInfo;       //窗帘局部变量
	
	memset(&BUS_Public,0,sizeof(Device_Public_Information_G));
	memset(&DevCurtainInfo,0,sizeof(NOR_CURTAIN_INFO));
	
	BUS_Public.addr = dev_info->addr;			//设备地址
	BUS_Public.type = dev_info->type;		//设备类型
	BUS_Public.port = NULL;			//设备发送端口
	BUS_Public.baud = 0000;			//设备发送波特率
//	BUS_Public.retry_num = 0x03;		//设备数据重发次数
//	BUS_Public.wait_time = 0x0064;		//设备数据发送等待回复时间
//	BUS_Public.polling_cf = (uint32_t)&BLW_Touch_SwitchCycleDis;
//	BUS_Public.processing_cf = (uint32_t)&BLW_Rs485_Touch_Swi_Check;
	
	BUS_Public.DevFunInfo.Dev_Data_Process = Dev_Curtain_Dis;                 //
	BUS_Public.DevFunInfo.Dev_Input_Type_Get = Dev_Curtain_InType_Get;        //
	BUS_Public.DevFunInfo.Dev_Output_Ctrl = BLW_Curtain_Control_State;        //
	BUS_Public.DevFunInfo.Dev_Output_Loop_State_Get = Curtain_Loop_State;     //
	
	
	
	Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"增加一个窗帘,私有数据长度:%d",sizeof(NOR_CURTAIN_INFO));
//	switch(BUS_Public.addr)
//	{
//		case 0x00:memcpy(&DevCurtainInfo.DevNameStruct, "窗帘", strlen("窗帘"));break;
//		case 0x01:memcpy(&DevCurtainInfo.DevNameStruct, "窗纱", strlen("窗纱"));break;
//		case 0x02:memcpy(&DevCurtainInfo.DevNameStruct, "窗帘", strlen("窗帘"));break;
//		case 0x03:memcpy(&DevCurtainInfo.DevNameStruct, "窗纱", strlen("窗纱"));break;
//		case 0x04:memcpy(&DevCurtainInfo.DevNameStruct, "窗帘", strlen("窗帘"));break;
//		case 0x05:memcpy(&DevCurtainInfo.DevNameStruct, "窗纱", strlen("窗纱"));break;
//		case 0x06:memcpy(&DevCurtainInfo.DevNameStruct, "窗帘", strlen("窗帘"));break;
//		case 0x07:memcpy(&DevCurtainInfo.DevNameStruct, "窗纱", strlen("窗纱"));break;
//		case 0x08:memcpy(&DevCurtainInfo.DevNameStruct, "窗帘", strlen("窗帘"));break;
//		
//	}
//	{
//		uint8_t SerData[200];
//		if(sizeof(NOR_CURTAIN_INFO) <= 200)
//		{
//			memcpy(SerData, &DevCurtainInfo, sizeof(NOR_CURTAIN_INFO));
//		
//			for(uint16_t j = 0; j < sizeof(NOR_CURTAIN_INFO); j++)
//			{
//				 
//				printf("%02X ", SerData[j]);
//			}
//			printf("\n\r");
//		}
//	}
	Add_Nor_Device_To_List2(&BUS_Public,(uint8_t *)&DevCurtainInfo,sizeof(NOR_CURTAIN_INFO));
}



/**
  * @name  指定窗帘回路状态得到
  * @param  
  *    devaddr             当前设备的地址
  *    DevOutputLoop       需要查找的窗帘回路 从0开始
  * @retval 
  *    ret                 回路状态返回    1 开   2关
  * @brief

  */
uint16_t Curtain_Loop_State(uint32_t devaddr, uint16_t DevOutputLoop)
{	
	NOR_CURTAIN_INFO DevCurtainInfo;       //窗帘局部变量

	if(devaddr == 0x00)
		return 0x00;
	
	SRAM_DMA_Read_Buff((uint8_t *)&DevCurtainInfo,sizeof(NOR_CURTAIN_INFO),devaddr+Dev_Privately);	

	if(DevCurtainInfo.DevCurtainDelayState != 0x00)
	{
//		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"当前窗帘处于延时控制 %d\r\n",DevCurtainInfo.DevCurtainDelayState);
//		return DevCurtainInfo.DevCurtainDelayState;
		if(DevCurtainInfo.DevCurtainDelayState==0x15)            //2022-08-04     为解决开和关延时没有反馈灯
		{
			return 0x01;
		}
		else if(DevCurtainInfo.DevCurtainDelayState==0x16)
		{
			return 0x02;
		}
	}
//	Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"当前窗帘处于 %d\r\n",DevCurtainInfo.DevCurtainState);
	return DevCurtainInfo.DevCurtainState;
}


uint16_t Curtain_Loop_Save_State(uint32_t devaddr, uint16_t DevOutputLoop)
{	
	NOR_CURTAIN_INFO DevCurtainInfo;       //窗帘局部变量
	uint16_t state = 0x00;

	if(devaddr == 0x00)
		return 0x00;
	
	SRAM_DMA_Read_Buff((uint8_t *)&DevCurtainInfo,sizeof(NOR_CURTAIN_INFO),devaddr+Dev_Privately);

	if(DevCurtainInfo.DevCurtainState != CFG_NodeCurtain_STOP)
	{
		state = DevCurtainInfo.DevCurtainState;
	}
	else if(DevCurtainInfo.DevCurtainState == CFG_NodeCurtain_STOP)
	{
		state = DevCurtainInfo.DevCurtainStateNext;
	}

	return state;
}



/*******************************************************************************
* Function Name  : BLW_Curtain_Control_State 
* Description    : BLW窗帘状态控制函数
* Input          : 
	devaddr	: 设备信息地址
  loop    ：回路      回路都是从0
	start   ：状态    0x01开  0x02关
* Return  : 无
* attention : temp1非0才会进行保存
*******************************************************************************/
void BLW_Curtain_Control_State(uint32_t CfgDevAddIn, uint16_t DevInputAddr, uint32_t devaddr,uint16_t DevOutputLoop,uint16_t start)
{
	uint8_t temp1 = 0,temp_start = 0;//temp_content = 0;
	Device_Public_Information_G BUS_Public;   //共用
	NOR_CURTAIN_INFO DevCurtainInfo;       //窗帘局部变量
	
	if(devaddr == 0x00)	return;
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),devaddr);	//拷贝所有共有数据	
	SRAM_DMA_Read_Buff((uint8_t *)&DevCurtainInfo,sizeof(NOR_CURTAIN_INFO),devaddr+Dev_Privately);
	Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"CURTAIN%d loop:%d,start:%04X 当前State:%d,之前状态:%d",BUS_Public.addr,DevOutputLoop,start,DevCurtainInfo.DevCurtainState,DevCurtainInfo.DevCurtainStateNext);
	
	switch(DevCurtainInfo.DevCurtainState)
	{
		case CFG_NodeCurtain_OPEN:    //当前为开
		case CFG_NodeCurtain_CLOSE:    //当前为关
			DevCurtainInfo.DevCurtainStateNext = DevCurtainInfo.DevCurtainState;
			break;
	}
	
	temp_start = start&0xFF;
//	temp_content = (start >> 8) & 0xFF;
	
	switch(temp_start)
	{
		case CFG_NodeCurtain_OPEN:
		case CFG_NodeCurtain_CLOSE:
		case CFG_NodeCurtain_STOP:
			#if Device_Delay_Control_Enable
			{
				if(temp_start != DevCurtainInfo.DevCurtainState)
				{
					DevCurtainInfo.DevCurtainState = temp_start;
					DevCurtainInfo.DevCurtainDelayLastState = temp_start;
					switch(temp_start)
					{
						case CFG_NodeCurtain_OPEN:
							Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"*延时1S控制窗帘开");
							DevCurtainInfo.DevCurtainState = CFG_NodeCurtain_STOP;
							DevCurtainInfo.DevCurtainDelayLastState = CFG_NodeCurtain_DelayOpen;
							DevCurtainInfo.DevCurtainDelayState = CFG_NodeCurtain_DelayOpen;
							if((DevCurtainInfo.DevCurtainStateLast==CFG_NodeCurtain_STOP)\
								&&((SysTick_1ms - DevCurtainInfo.DevCurtainDelayTick)>1000))
							{
								DevCurtainInfo.DevCurtainDelayTime = 0;			
							}
							else
							{
								DevCurtainInfo.DevCurtainDelayTime = 1000;			
							}
							DevCurtainInfo.DevCurtainDelayTick = SysTick_1ms;
							DevCurtainInfo.DevCurtainDelayFlag = 0x00;
							break;
						case CFG_NodeCurtain_CLOSE:
							Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"*延时1S控制窗帘关");
							DevCurtainInfo.DevCurtainState = CFG_NodeCurtain_STOP;
							DevCurtainInfo.DevCurtainDelayLastState = CFG_NodeCurtain_DelayClose;
							DevCurtainInfo.DevCurtainDelayState = CFG_NodeCurtain_DelayClose;
							if((DevCurtainInfo.DevCurtainStateLast==CFG_NodeCurtain_STOP)\
								&&((SysTick_1ms - DevCurtainInfo.DevCurtainDelayTick)>1000))
							{
								DevCurtainInfo.DevCurtainDelayTime = 0;			
							}
							else
							{
								DevCurtainInfo.DevCurtainDelayTime = 1000;			
							}
							DevCurtainInfo.DevCurtainDelayTick = SysTick_1ms;
							DevCurtainInfo.DevCurtainDelayFlag = 0x00;
							break;
					}
					temp1++;
				}
				if((temp_start == CFG_NodeCurtain_STOP) && (DevCurtainInfo.DevCurtainDelayState != 0x00) && (DevCurtainInfo.DevCurtainDelayLastState != CFG_NodeCurtain_DelayClose) && (DevCurtainInfo.DevCurtainDelayLastState != CFG_NodeCurtain_DelayOpen))	//如果当前控制关，需要把延时控制状态也清除
				{
					temp1++;
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"窗帘关,清除延时控制状态 - %d",DevCurtainInfo.DevCurtainDelayLastState);
					DevCurtainInfo.DevCurtainDelayState = 0x00;
					DevCurtainInfo.DevCurtainDelayFlag = 0x00;
				}
			}
			#else
			{
				if(start != DevCurtainInfo.DevCurtainState)
				{
					DevCurtainInfo.DevCurtainState = start;     //状态变了 ，就保存
					temp1++;
				}
			}
			#endif
			break;
		case CFG_NodeCurtain_Change:   //窗帘取反
			temp1++;
			switch(DevCurtainInfo.DevCurtainState)
			{
				case CFG_NodeCurtain_STOP:      //唯有停止
					switch(DevCurtainInfo.DevCurtainStateNext)
					{
						case CFG_NodeCurtain_OPEN:   //之前保存的开
							Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"之前保存的窗帘开");
							DevCurtainInfo.DevCurtainState = CFG_NodeCurtain_CLOSE;
							break;
						case CFG_NodeCurtain_CLOSE:   //之前保存的关
							Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"之前保存的窗帘关");
							DevCurtainInfo.DevCurtainState = CFG_NodeCurtain_OPEN;
							break;
						default:  //之前没有保存状态
							DevCurtainInfo.DevCurtainState = CFG_NodeCurtain_OPEN;   //默认为开
							break;
					}
					break;
			}
			DevCurtainInfo.DevCurtainDelayLastState = CFG_NodeCurtain_Change;
			break;
//		case CFG_NodeCurtain_DelayOpen:		//因为项目临时增加的解决方式 - 延时1S控制窗帘开
//			temp1++;
//			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"延时1S控制窗帘开\r\n");
//			DevCurtainInfo.DevCurtainState = CFG_NodeCurtain_STOP;
//			DevCurtainInfo.DevCurtainDelayLastState = CFG_NodeCurtain_DelayOpen;
//			DevCurtainInfo.DevCurtainDelayState = CFG_NodeCurtain_DelayOpen;
//			DevCurtainInfo.DevCurtainDelayTime = 1000;			//单位：100ms
//			DevCurtainInfo.DevCurtainDelayTick = SysTick_1ms;
//			DevCurtainInfo.DevCurtainDelayFlag = 0x00;
//			break;
//		case CFG_NodeCurtain_DelayClose:
//			temp1++;
//			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"延时1S控制窗帘关\r\n");
//			DevCurtainInfo.DevCurtainDelayLastState = CFG_NodeCurtain_DelayClose;
//			DevCurtainInfo.DevCurtainState = CFG_NodeCurtain_STOP;
//			DevCurtainInfo.DevCurtainDelayState = CFG_NodeCurtain_DelayClose;
//			DevCurtainInfo.DevCurtainDelayTime = 1000;
//			DevCurtainInfo.DevCurtainDelayTick = SysTick_1ms;
//			DevCurtainInfo.DevCurtainDelayFlag = 0x00;
//			break;	
//		case CFG_NodeCurtain_DelayStop:
//			temp1++;
//			DevCurtainInfo.DevCurtainDelayLastState = CFG_NodeCurtain_DelayStop;
//			DevCurtainInfo.DevCurtainState = CFG_NodeCurtain_STOP;
//			DevCurtainInfo.DevCurtainDelayState = 0x00;
//			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"延时控制停止");
//			break;
		default:    //	其他情况直接返回
			return ;
	}
	
	if(temp1 != 0x00)
	{
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&DevCurtainInfo, sizeof(NOR_CURTAIN_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),devaddr);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&DevCurtainInfo,sizeof(NOR_CURTAIN_INFO),devaddr+Dev_Privately);
		
	}	
}


/**
*@name 窗帘输入检测函数
*@para
*  DevAddr      设备地址
*  DevInputLoop 回路输入地址  范围0~CurtainLoopValidNum  
*  DevInputType 输入类型
*/

uint8_t Dev_Curtain_InType_Get(uint32_t DevAddr, uint16_t DevInputLoop, uint16_t DevInputType)
{
	Device_Public_Information_G BUS_Public;   //共用	
	NOR_CURTAIN_INFO DevCurtainInfo;       //窗帘局部变量
	uint8_t Ret = CtrlInvalid;         //控制无效
	
	if(DevAddr == 0x00)	return Ret;
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),DevAddr);	//拷贝所有共有数据	
	SRAM_DMA_Read_Buff((uint8_t *)&DevCurtainInfo,sizeof(NOR_CURTAIN_INFO),DevAddr+Dev_Privately);	/*拷贝设备私有信息*/
	
	switch(DevInputType)
	{
		case CFG_NodeCurtain_OPEN:
		case CFG_NodeCurtain_CLOSE:
		case CFG_NodeCurtain_STOP:
			if(DevInputType == DevCurtainInfo.DevCurtainAction)
			{
				DevCurtainInfo.DevCurtainAction = NULL;
				Ret = CtrlValid;
			}
			
			if(DevInputType == CFG_NodeCurtain_STOP)       //2023-09-07
			{
				DevCurtainInfo.DevCurtainDelayTick = SysTick_1ms;
			}
			break;
	}
	

	
	if(CtrlValid == Ret)
	{
		Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"窗帘动作清空");

		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&DevCurtainInfo, sizeof(NOR_CURTAIN_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),DevAddr);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&DevCurtainInfo,sizeof(NOR_CURTAIN_INFO),DevAddr+Dev_Privately);
		
	}
	
	return Ret;
	
}

/**
*@name 窗帘扫描函数
*@para
*  DevAddr      设备地址
*@brief 拿到窗帘的状态，并转换为动作
*/

void Dev_Curtain_Dis(uint32_t DevAddr)
{
	Device_Public_Information_G BUS_Public;   //共用	
	NOR_CURTAIN_INFO DevCurtainInfo;       //窗帘局部变量
	uint8_t KeepFlag = 0x00;
	
	if(NULL == DevAddr)
	{
		return ;
	}
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),DevAddr);	//拷贝所有共有数据	
	SRAM_DMA_Read_Buff((uint8_t *)&DevCurtainInfo,sizeof(NOR_CURTAIN_INFO),DevAddr+Dev_Privately); 
	
	if((DevCurtainInfo.DevCurtainDelayState != 0x00) && (DevCurtainInfo.DevCurtainDelayFlag == 0x00))
	{
		if(SysTick_1ms - DevCurtainInfo.DevCurtainDelayTick > DevCurtainInfo.DevCurtainDelayTime)
		{
			DevCurtainInfo.DevCurtainDelayTick = SysTick_1ms;
			
			DevCurtainInfo.DevCurtainDelayFlag = 0x01;
			
			Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"延时控制窗帘");
			
			switch(DevCurtainInfo.DevCurtainDelayState)
			{
				case CFG_NodeCurtain_DelayOpen:
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"控制窗帘开");
					DevCurtainInfo.DevCurtainState = CFG_NodeCurtain_OPEN;
					break;
				case CFG_NodeCurtain_DelayClose:
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"控制窗帘关");
					DevCurtainInfo.DevCurtainState = CFG_NodeCurtain_CLOSE;
					break;
			}
			
			KeepFlag = 0x01;
		}
	}
	
	if(DevCurtainInfo.DevCurtainStateLast != DevCurtainInfo.DevCurtainState)
	{
		DevCurtainInfo.DevCurtainStateLast = DevCurtainInfo.DevCurtainState;   //有变化
		DevCurtainInfo.DevCurtainAction = DevCurtainInfo.DevCurtainState;   //产生动作
		
		if((DevCurtainInfo.DevCurtainDelayState != 0x00) && (DevCurtainInfo.DevCurtainDelayFlag == 0x01) && (DevCurtainInfo.DevCurtainState == CFG_NodeCurtain_STOP))
		{
			Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"延时控制窗帘状态控制结束!");
			DevCurtainInfo.DevCurtainDelayState = 0x00;
			DevCurtainInfo.DevCurtainDelayFlag = 0x00;
		}
		
		Udp_Addtion_Roomstate(Dev_NodeCurtain,BUS_Public.addr, 0x00, DevCurtainInfo.DevCurtainState);	     //上报窗帘信息

		KeepFlag = 0x01;
	}
	
	
	if(0x01 == KeepFlag)
	{
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&DevCurtainInfo, sizeof(NOR_CURTAIN_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),DevAddr);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&DevCurtainInfo,sizeof(NOR_CURTAIN_INFO),DevAddr+Dev_Privately);
					
		
	}
	
	
}















