

/**
  ******************************************************************************
  * @file    BLV_Nor_Dev_HVoutFun.c
  * @author  BLW RCU  development Team
  * @version V1.0.0
  * @date    2021年11月01日
  * @brief   继电器初始化   设备继电器控制
	* @attention 设备继电器
	*									输入检测：  无
	*                 输入类型：  无	
	*                 执行函数：  有		
	*            			执行方式：
	*															开 
	*															关
	* @log   2022年3月27日 生成继电器总表  所有关于继电器的设备全纳为继电器总表
	* @log   202205171611     SongHan    增加继电器驱动开启关闭标志         
  ******************************************************************************
  */
  
  
#include "includes.h"

#include "BLV_Nor_Dev_HVoutFun.h"
#include "BLV_Nor_DevFun.h"

/*继电器头文件开始*/
#include "BLV_485_Dev_A9IO_SwiFun.h"
#include "BLV_485_Dev_C5RELAYFun.h"
#include "BLV_485_Dev_SwiRELAYFun.h"

/*继电器头文件结束*/


/*函数指针宏定义*/
typedef void (*DevFunP)(Device_Public_Information_G *BUS_Public, NOR_HVOUT_INFO *DevHVoutInfo);	//传递共用数据指针 私有数据指针

/*设备驱动宏定义开始*/
#define RS485_DEV_PRO_FUN_01    DevExistJudgge(RS485_HVout_C5RELAY_Flag, BLW_RS485_C5RELAY_Data_Init)  //((DevFunP)NULL)  // C5和C12自带继电器
#define RS485_DEV_PRO_FUN_02    DevExistJudgge(RS485_HVout_A9RELAY_Flag, BLW_RS485_A9RELAY_Data_Init) //((DevFunP)NULL)    //A9IO继电器
#define RS485_DEV_PRO_FUN_03    DevExistJudgge(RS485_HVout_SwiRELAY_Flag, BLW_RS485_SwiRELAY_Data_Init)  //((DevFunP)NULL)  //强电开关继电器          
#define RS485_DEV_PRO_FUN_04    ((DevFunP)NULL)    //          
#define RS485_DEV_PRO_FUN_05    ((DevFunP)NULL)    //
#define RS485_DEV_PRO_FUN_06    ((DevFunP)NULL) 

/*设备驱动宏定义结束*/

//void Dev_HVout_Dis(uint32_t DevAddr);
void BLW_HVout_Control_State(uint32_t CfgDevAddIn, uint16_t DevInputAddr,uint32_t devaddr,uint16_t DevOutputLoop,uint16_t start);
uint16_t HVout_Loop_State(uint32_t devaddr, uint16_t DevOutputLoop);
uint16_t BLW_HVout_Group_Read(uint32_t devaddr, uint8_t SceneType, uint32_t ReadFlag, uint8_t ReadNum,uint16_t *start);
void BLW_HVout_Group_Ctrl(uint32_t CfgDevAddIn, uint16_t DevInputAddr,uint32_t devaddr, uint32_t CtrlFlag, uint8_t CtrlNum,uint16_t *start);

/*继电器新增到普通设备链表*/
void BLV_Nor_Dev_HVout_Init(uint16_t DataLen, uint8_t *Data)
{
	Device_Public_Information_G BUS_Public;
	NOR_HVOUT_INFO DevHVoutInfo;       //继电器局部变量
	
	memset(&BUS_Public,0,sizeof(Device_Public_Information_G));
	memset(&DevHVoutInfo,0,sizeof(NOR_HVOUT_INFO));             //继电器结构体清空
	
	BUS_Public.addr = Data[1];			//设备地址
	BUS_Public.type = Data[0];		//设备类型
	BUS_Public.baud = Data[3] + (Data[4]<<8) + (Data[5]<<16) + (Data[6]<<24);		    //设备发送波特率9600
	BUS_Public.Protocol = Data[7];

	if(ENUM_RS485_DEV_PRO_01 == Data[7])
	{
		
		BUS_Public.retry_num = C5IO_REPEATSENDTIMEMAX;		//设备数据重发次数
		BUS_Public.wait_time = C5IO_SEND_WAIT_TIME;	//设备数据发送等待回复时间 - 100ms		
	}
	else
	{
		BUS_Public.retry_num = 0x03;	//设备数据重发次数
		BUS_Public.wait_time = 0x0064;	//设备数据发送等待回复时间 - 100ms
	}
//	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_HVout_Dis;                 //
	BUS_Public.DevFunInfo.Dev_Output_Ctrl = BLW_HVout_Control_State;        //
	BUS_Public.DevFunInfo.Dev_Output_Loop_State_Get = HVout_Loop_State;     //	
	BUS_Public.DevFunInfo.Dev_Output_Group_Ctrl = BLW_HVout_Group_Ctrl; //
	BUS_Public.DevFunInfo.Dev_Output_Loop_Group_State_Get_ptr = BLW_HVout_Group_Read; //
	
	if(Data[10] > C1_HVOUTNUMMAX)
	{
		DevHVoutInfo.HVoutLoopValidNum = C1_HVOUTNUMMAX;
	}
	else
	{
		DevHVoutInfo.HVoutLoopValidNum = Data[10];
	}

	switch(BUS_Public.Protocol)
	{
		case	 ENUM_RS485_DEV_PRO_01: if(NULL!=RS485_DEV_PRO_FUN_01) RS485_DEV_PRO_FUN_01(&BUS_Public, &DevHVoutInfo);break; //        
		case	 ENUM_RS485_DEV_PRO_02: if(NULL!=RS485_DEV_PRO_FUN_02) RS485_DEV_PRO_FUN_02(&BUS_Public, &DevHVoutInfo);break; //          
		case	 ENUM_RS485_DEV_PRO_03: if(NULL!=RS485_DEV_PRO_FUN_03) RS485_DEV_PRO_FUN_03(&BUS_Public, &DevHVoutInfo);break;                                 //3
		case	 ENUM_RS485_DEV_PRO_04: if(NULL!=RS485_DEV_PRO_FUN_04) RS485_DEV_PRO_FUN_04(&BUS_Public, &DevHVoutInfo);break;
		case	 ENUM_RS485_DEV_PRO_05: if(NULL!=RS485_DEV_PRO_FUN_05) RS485_DEV_PRO_FUN_05(&BUS_Public, &DevHVoutInfo);break;
		case	 ENUM_RS485_DEV_PRO_06: if(NULL!=RS485_DEV_PRO_FUN_06) RS485_DEV_PRO_FUN_06(&BUS_Public, &DevHVoutInfo);break;
		
	}

	switch(Data[2])
	{
		case Active_Port:   //主动端口 
			BUS_Public.port = Active_Port;		//设备发送端口	
			Add_ACT_Device_To_List2(&BUS_Public,(uint8_t *)&DevHVoutInfo,sizeof(NOR_HVOUT_INFO));
			Act485_Info.device_num += 1;
			break;  
		case Polling_Port:   //轮询端口
			BUS_Public.port = Polling_Port;		//设备发送端口
			Add_POLL_Device_To_List2(&BUS_Public,(uint8_t *)&DevHVoutInfo,sizeof(NOR_HVOUT_INFO));   //将填充后的数据添加到链表
			Poll485_Info.device_num += 1;	
			break;
		case Bus_port:    //总线端口
			BUS_Public.port = Bus_port;		//设备发送端口	
			Add_BUS_Device_To_List2(&BUS_Public,(uint8_t *)&DevHVoutInfo,sizeof(NOR_HVOUT_INFO));
			BUS485_Info.device_num += 1;
			break;
//		case NULL:   //普通总线
//			DevHVoutInfo.DevC5IOAddr = Find_AllDevice_List_Information(DEV_C5IO_Type, 0x00);
//			BUS_Public.port = NULL;			//设备发送端口
//			Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"增加一组强电继电器，强电继电器私有数据长度:%d,当前继电器读取函数地址：%04X",sizeof(NOR_HVOUT_INFO), BUS_Public.DevFunInfo.Dev_Output_Loop_State_Get);		
//			Add_Nor_Device_To_List2(&BUS_Public,(uint8_t *)&DevHVoutInfo,sizeof(NOR_HVOUT_INFO));
//			NorDevInfoGlobal.NorDeviceNum += 1;
//			break;
	}	
}

/*******************************************************************************
* Function Name  : BLV_Nor_Dev_HVout_For_Logic_Init 
* Description    : 继电器初始化信息来自逻辑文件
*******************************************************************************/
void BLV_Nor_Dev_HVout_For_Logic_Init(LOGICFILE_DEVICE_INFO *dev_info,uint8_t *data,uint16_t data_len)
{
	Device_Public_Information_G BUS_Public;
	NOR_HVOUT_INFO DevHVoutInfo;       //继电器局部变量

	memset(&BUS_Public,0,sizeof(Device_Public_Information_G));
	memset(&DevHVoutInfo,0,sizeof(NOR_HVOUT_INFO));             //继电器结构体清空
	
	BUS_Public.addr = dev_info->addr;			//设备地址
	BUS_Public.type = dev_info->type;			//设备类型
	BUS_Public.baud = dev_info->baud;		    //设备发送波特率9600
	BUS_Public.Protocol = dev_info->version;

	if(ENUM_RS485_DEV_PRO_01 == dev_info->version)
	{
		
		BUS_Public.retry_num = C5IO_REPEATSENDTIMEMAX;		//设备数据重发次数
		BUS_Public.wait_time = C5IO_SEND_WAIT_TIME;	//设备数据发送等待回复时间 - 100ms		
	}
	else
	{
		BUS_Public.retry_num = 0x03;	//设备数据重发次数
		BUS_Public.wait_time = 0x0064;	//设备数据发送等待回复时间 - 100ms
	}

	BUS_Public.DevFunInfo.Dev_Output_Ctrl = BLW_HVout_Control_State;        //
	BUS_Public.DevFunInfo.Dev_Output_Loop_State_Get = HVout_Loop_State;     //	
	BUS_Public.DevFunInfo.Dev_Output_Group_Ctrl = BLW_HVout_Group_Ctrl; //
	BUS_Public.DevFunInfo.Dev_Output_Loop_Group_State_Get_ptr = BLW_HVout_Group_Read; //
	
	if(dev_info->output_num > C1_HVOUTNUMMAX)
	{
		DevHVoutInfo.HVoutLoopValidNum = C1_HVOUTNUMMAX;
	}
	else if(0x00 == dev_info->output_num)
	{
		DevHVoutInfo.HVoutLoopValidNum = 0x01;    //回路为0，就默认一个回路
	}
	else
	{
		DevHVoutInfo.HVoutLoopValidNum = dev_info->output_num;
	}
//	for(i = 0; i < DevHVoutInfo.HVoutLoopValidNum; i++)
//	{
//		if(0x00 == BUS_Public.addr)   //0地址继电器
//		{
//			switch(i)   
//			{
//				case 0x00:memcpy(&DevHVoutInfo.DevNameStruct[0], "继电器01", strlen("继电器01"));   break;
//				case 0x01:memcpy(&DevHVoutInfo.DevNameStruct[1], "继电器02", strlen("继电器02"));   break;
//				case 0x02:memcpy(&DevHVoutInfo.DevNameStruct[2], "继电器03", strlen("继电器03"));   break;
//				case 0x03:memcpy(&DevHVoutInfo.DevNameStruct[3], "继电器04", strlen("继电器04"));   break;
//				case 0x04:memcpy(&DevHVoutInfo.DevNameStruct[4], "继电器05", strlen("继电器05"));   break;
//				case 0x05:memcpy(&DevHVoutInfo.DevNameStruct[5], "继电器06", strlen("继电器06"));   break;
//				case 0x06:memcpy(&DevHVoutInfo.DevNameStruct[6], "继电器07", strlen("继电器07"));   break;
//				case 0x07:memcpy(&DevHVoutInfo.DevNameStruct[7], "继电器08", strlen("继电器08"));   break;
//				case 0x08:memcpy(&DevHVoutInfo.DevNameStruct[8], "继电器09", strlen("继电器09"));   break;
//			}
//		}
//	}
	switch(BUS_Public.Protocol)
	{
		case	 ENUM_RS485_DEV_PRO_01: if(NULL!=RS485_DEV_PRO_FUN_01) RS485_DEV_PRO_FUN_01(&BUS_Public, &DevHVoutInfo);break; //        
		case	 ENUM_RS485_DEV_PRO_02: if(NULL!=RS485_DEV_PRO_FUN_02) RS485_DEV_PRO_FUN_02(&BUS_Public, &DevHVoutInfo);break; //          
		case	 ENUM_RS485_DEV_PRO_03: if(NULL!=RS485_DEV_PRO_FUN_03) RS485_DEV_PRO_FUN_03(&BUS_Public, &DevHVoutInfo);break;                                 //3
		case	 ENUM_RS485_DEV_PRO_04: if(NULL!=RS485_DEV_PRO_FUN_04) RS485_DEV_PRO_FUN_04(&BUS_Public, &DevHVoutInfo);break;
		case	 ENUM_RS485_DEV_PRO_05: if(NULL!=RS485_DEV_PRO_FUN_05) RS485_DEV_PRO_FUN_05(&BUS_Public, &DevHVoutInfo);break;
		case	 ENUM_RS485_DEV_PRO_06: if(NULL!=RS485_DEV_PRO_FUN_06) RS485_DEV_PRO_FUN_06(&BUS_Public, &DevHVoutInfo);break;
		
	}

	switch(dev_info->port)
	{
		case Active_Port:   //主动端口 
			BUS_Public.port = Active_Port;		//设备发送端口	
			Add_ACT_Device_To_List2(&BUS_Public,(uint8_t *)&DevHVoutInfo,sizeof(NOR_HVOUT_INFO));
			Act485_Info.device_num += 1;
			break;  
		case Polling_Port:   //轮询端口
			BUS_Public.port = Polling_Port;		//设备发送端口
			Add_POLL_Device_To_List2(&BUS_Public,(uint8_t *)&DevHVoutInfo,sizeof(NOR_HVOUT_INFO));   //将填充后的数据添加到链表
			Poll485_Info.device_num += 1;	
			break;
		case Bus_port:    //总线端口
			BUS_Public.port = Bus_port;		//设备发送端口	
			Add_BUS_Device_To_List2(&BUS_Public,(uint8_t *)&DevHVoutInfo,sizeof(NOR_HVOUT_INFO));
			BUS485_Info.device_num += 1;
			break;

	}	
}


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

  */
uint16_t HVout_Loop_State(uint32_t devaddr, uint16_t DevOutputLoop)
{	
	NOR_HVOUT_INFO DevHVoutInfo;       //继电器局部变量

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

	if(DevOutputLoop >= DevHVoutInfo.HVoutLoopValidNum)
	{
		return 0x00;
	}
	
	if(DevHVoutInfo.DevHVoutState[DevOutputLoop] == 0x01)   //
	{
		return 0x01;
	}
	else
	{
		return 0x02;
	}
	
}

/*******************************************************************************
* Function Name  : BLW_HVout_Control_State 
* Description    : BLW继电器状态控制函数
* Input          : 
	devaddr	: 设备信息地址
  loop    ：回路      回路都是从0
	start   ：状态    0x01开  0x02关
* Return  : 无
* attention : temp1非0才会进行保存
*******************************************************************************/
void BLW_HVout_Control_State(uint32_t CfgDevAddIn, uint16_t DevInputAddr, uint32_t devaddr,uint16_t DevOutputLoop,uint16_t start)
{
	uint8_t temp1 = 0;
	uint1_t state;    //0关  1开
	Device_Public_Information_G BUS_Public;   //共用
	NOR_HVOUT_INFO DevHVoutInfo;       //继电器局部变量
	

	if(devaddr == 0x00)	return;
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),devaddr);	//拷贝所有共有数据	
	SRAM_DMA_Read_Buff((uint8_t *)&DevHVoutInfo,sizeof(NOR_HVOUT_INFO),devaddr+Dev_Privately);
	

	switch(start)
	{
		case 0x01:state = OPEN;break;
		case 0x02:state = CLOSE;break;
		default:return;
	}

	if(DevOutputLoop >= DevHVoutInfo.HVoutLoopValidNum)
	{
		return ;
	}	
	

	if( DevHVoutInfo.DevHVoutState[DevOutputLoop] != state )
	{
		switch(state)
		{
			case 0x00:  //指定位清0
				DevHVoutInfo.DevHVoutState[DevOutputLoop] = 0x00;
				break;
			case 0x01:   //指定位置一
				DevHVoutInfo.DevHVoutState[DevOutputLoop] = 0x01;
				break;
		}
		Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"HVOUT loop:%d,start:%d",DevOutputLoop,start);
		temp1++;
	}
	else if(0x01 == DevHVoutInfo.HVSwitchFlag)  //反馈灯没有变化  但是是强电开关
	{
		temp1 = 0x01;
		DevHVoutInfo.HVSwitchCtrlFlag = 0x01;   //仍然置一
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"HVDevSendBuf loop:%d,start:%d",DevOutputLoop,start);
	}	
	
	if(temp1 != 0x00)
	{
		if(Active_Port  == BUS_Public.port)
		{
			BLV_Active_Set_List_Addr(devaddr);  //唯有主动才会优先处理
		}
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&DevHVoutInfo, sizeof(NOR_HVOUT_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),devaddr);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&DevHVoutInfo,sizeof(NOR_HVOUT_INFO),devaddr+Dev_Privately);
				
	}	
}

/*******************************************************************************
* Function Name  : BLW_HVout_Group_Ctrl 
* Description    : BLW继电器群控
* Input          : 
	devaddr	: 设备信息地址
  CtrlFlag：控制标志  不能超过32路
	CtrlNum : 控制的设备个数   以最后一个为准
	start   ：状态    0x01开  0x02关
* Return  : 无
* attention : temp1非0才会进行保存
*******************************************************************************/
void BLW_HVout_Group_Ctrl(uint32_t CfgDevAddIn, uint16_t DevInputAddr,uint32_t devaddr, uint32_t CtrlFlag, uint8_t CtrlNum,uint16_t *start)
{
	uint8_t temp1 = 0;
//	uint1_t state;    //0关  1开
	uint8_t i;
	Device_Public_Information_G BUS_Public;   //共用	
	NOR_HVOUT_INFO DevHVoutInfo;       //继电器局部变量

	if(devaddr == 0x00)	return;
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),devaddr);	//拷贝所有共有数据	
	SRAM_DMA_Read_Buff((uint8_t *)&DevHVoutInfo,sizeof(NOR_HVOUT_INFO),devaddr+Dev_Privately);
	
	if(CtrlNum >= DevHVoutInfo.HVoutLoopValidNum)
	{
		CtrlNum = DevHVoutInfo.HVoutLoopValidNum;
	}
	for(i = 0; i < CtrlNum; i++)
	{
		if(CtrlFlag&(0x0001<<i))   //非0为控制
		{
			switch(start[i])
			{
				case 0x01:   //控制开
					if(DevHVoutInfo.DevHVoutState[i] != 0x01)  //不为1
					{
						temp1++;
						DevHVoutInfo.DevHVoutState[i] = 0x01;
					}
					break; 
				case 0x02:   //控制关
					if(DevHVoutInfo.DevHVoutState[i] != 0x00)  //不为0
					{
						temp1++;
						DevHVoutInfo.DevHVoutState[i] = 0x00;
					}
					break;
			}
		}
	}
	if((0x00 == temp1) && (0x01 == DevHVoutInfo.HVSwitchFlag))  //反馈灯没有变化  但是是强电开关
	{
		if(0x00 == DevHVoutInfo.HVSwitchCtrlFlag)   //为0就重新保存为1
		{
			temp1 = 0x01;
			DevHVoutInfo.HVSwitchCtrlFlag = 0x01;   //仍然置一
		}
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"HVDevSendBuf loopCtrl");
	}		
	
	if(temp1 != 0x00)
	{
		if(Active_Port == BUS_Public.port)
		{
			BLV_Active_Set_List_Addr(devaddr);
		}
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&DevHVoutInfo, sizeof(NOR_HVOUT_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),devaddr);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&DevHVoutInfo,sizeof(NOR_HVOUT_INFO),devaddr+Dev_Privately);
					
	}	
}

/*******************************************************************************
* Function Name  : BLW_HVout_Group_Ctrl 
* Description    : BLW继电器群控
* Input          : 
	devaddr	: 设备信息地址
  CtrlFlag：控制标志  不能超过32路
	CtrlNum : 控制的设备个数   以最后一个为准
	start   ：状态    0x01开  0x02关
* Return  : 所有状态满足 返回开 有一个不满足 返回关
* attention : temp1非0才会进行保存
*******************************************************************************/
uint16_t BLW_HVout_Group_Read(uint32_t devaddr, uint8_t SceneType, uint32_t ReadFlag, uint8_t ReadNum,uint16_t *start)
{
	uint8_t i;
	uint8_t Ret = 0x00;
	NOR_HVOUT_INFO DevHVoutInfo;       //继电器局部变量
	
	if(devaddr == 0x00)	return 0x00;
	
	
//	Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"继电器状态群控读取开始，回路标志:%08X ", ReadFlag);
	SRAM_DMA_Read_Buff((uint8_t *)&DevHVoutInfo,sizeof(NOR_HVOUT_INFO),devaddr+Dev_Privately);
	
	if(ReadNum >= DevHVoutInfo.HVoutLoopValidNum)
	{
		ReadNum = DevHVoutInfo.HVoutLoopValidNum;
	}
	switch(SceneType)
	{
		case 0x01:
			for(i = 0; i < ReadNum; i++)
			{
				if(ReadFlag&(0x0001<<i))   //非0为读取判断
				{
					switch(start[i])
					{
						case 0x01:   //状态开
		//					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"继电器状态群控读取开始，当前回路配置:%04X ", start[i]);

							if( DevHVoutInfo.DevHVoutState[i] != 0x01 )  //不为1
							{
								Ret = DEV_STATE_CLOSE;
							}
							break; 
						case 0x02:   //状态关
		//					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"继电器状态群控读取开始，当前回路配置:%04X ", start[i]);
							if(DevHVoutInfo.DevHVoutState[i] != 0x00 )  //不为0
							{
								Ret = DEV_STATE_CLOSE;
							}
							break;
					}
				}
			}			
			break;
		case 0x02:
			for(i = 0; i < ReadNum; i++)
			{
				if(ReadFlag&(0x0001<<i))   //非0为读取判断
				{
					if(0x01 == start[i])//状态开
					{
						if( DevHVoutInfo.DevHVoutState[i] != 0x01 )  //不为1
						{
//							Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"特殊场景继电器状态群控读取开始，当前回路：%d状态:%04X ", i, start[i]);
							Ret = DEV_STATE_OPEN;
							break; 
						}
						
					}
				}
			}			
			break;
	}

	if(0x00 == Ret)   //
	{
		switch(SceneType)
		{
			case 0x01:
				Ret = DEV_STATE_OPEN;
			  break;
			case 0x02:
				Ret = DEV_STATE_CLOSE;
				break;
		}
	}
	return Ret;
}



/*获取继电器的在线状态*/
uint8_t Get_BLV485_Expand_Online_Status(uint32_t devaddr)
{
	NOR_HVOUT_INFO DevHVoutInfo;       //继电器局部变量
	
	SRAM_DMA_Read_Buff((uint8_t *)&DevHVoutInfo,sizeof(NOR_HVOUT_INFO),devaddr+Dev_Privately);
	
	if(DevHVoutInfo.DevOffline == DEV_IS_ONLINE)
	{
		return 0x01;
	}
	return 0x02;
}







