/**
  ******************************************************************************
  * @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_FloorHeatFun.h"
/*外设头文件开始*/
#include "BLV_485_Dev_BLWFloorHeatFun.h"
#include "BLV_485_Dev_CLEDFloorHeatFun.h"
/*外设头文件结束*/

/*设备驱动宏定义开始*/
#define RS485_DEV_PRO_FUN_01	DevExistJudgge(RS485_BLW_FloorHeat_Flag, BLW_RS485_FloorHeat_Init)	//宝来威地暖
#define RS485_DEV_PRO_FUN_02	DevExistJudgge(RS485_CLED_FloorHeat_Flag, CLED_RS485_FloorHeat_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 FloorHeat_Input_Check(uint32_t CfgDevAddIn,uint16_t DevInputLoop,uint16_t DevInputType);	//地暖设备输入检测
void Set_FloorHeat_Func(uint32_t DevAddrIn,uint16_t DevInputLoop,uint32_t DevAddrOut,uint16_t DevOutputLoop,uint16_t DevOutputType);	//设置地暖设备功能

uint8_t CLED_FloorHeat_Input_Check(uint32_t CfgDevAddIn,uint16_t DevInputLoop,uint16_t DevInputType);
void CLED_Set_FloorHeat_Func(uint32_t DevAddrIn,uint16_t DevInputLoop,uint32_t DevAddrOut,uint16_t DevOutputLoop,uint16_t DevOutputType);
/*函数声明结束*/

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

	memset(&BUS_Public, 0, sizeof(Device_Public_Information_G));	//共有属性清0
	memset(&FloorHeat_Info, 0, sizeof(RS485_FloorHeat_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 = 0x00C8;	//设备数据发送等待回复时间 - 200ms
	
	if(data[7]==ENUM_RS485_DEV_PRO_01)
	{
		BUS_Public.DevFunInfo.Dev_Input_Type_Get = FloorHeat_Input_Check;	//地暖设备输入检测
		BUS_Public.DevFunInfo.Dev_Output_Ctrl = Set_FloorHeat_Func;	        //地暖设备输出控制
	}
	else if(data[7]==ENUM_RS485_DEV_PRO_02)
	{
		BUS_Public.DevFunInfo.Dev_Input_Type_Get = CLED_FloorHeat_Input_Check;	//地暖设备输入检测
		BUS_Public.DevFunInfo.Dev_Output_Ctrl = CLED_Set_FloorHeat_Func;	        //地暖设备输出控制
	}
	
	FloorHeat_Info.DevOffline = FloorHeat_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, &FloorHeat_Info);break;
		case ENUM_RS485_DEV_PRO_02: if(NULL!=RS485_DEV_PRO_FUN_02) RS485_DEV_PRO_FUN_02(&BUS_Public, &FloorHeat_Info);break;
//		case ENUM_RS485_DEV_PRO_03: if(NULL!=RS485_DEV_PRO_FUN_03) RS485_DEV_PRO_FUN_03(&BUS_Public, &FloorHeat_Info);break;
//		case ENUM_RS485_DEV_PRO_04: if(NULL!=RS485_DEV_PRO_FUN_04) RS485_DEV_PRO_FUN_04(&BUS_Public, &FloorHeat_Info);break;
	}
	switch(data[2])	//端口判断
	{
		case Active_Port:	//主动端口
			BUS_Public.port = Active_Port;	//设备发送端口
			Add_ACT_Device_To_List2(&BUS_Public,(uint8_t *)&FloorHeat_Info,sizeof(RS485_FloorHeat_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 *)&FloorHeat_Info,sizeof(RS485_FloorHeat_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  
  *		len		初始化的数据长度
  *		data	初始化数据的首地址
  * @retval     None
  * @attention	None
*******************************************************************************/
void BLW_RS485_FloorHeatFun_Logic_Init(LOGICFILE_DEVICE_INFO *dev_info,uint8_t *data,uint16_t data_len)
{
	Device_Public_Information_G BUS_Public;	//地暖设备共有属性
	RS485_FloorHeat_INFO FloorHeat_Info;	//地暖设备私有属性

	memset(&BUS_Public, 0, sizeof(Device_Public_Information_G));	//共有属性清0
	memset(&FloorHeat_Info, 0, sizeof(RS485_FloorHeat_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 = FloorHeat_Input_Check;	//地暖设备输入检测
		BUS_Public.DevFunInfo.Dev_Output_Ctrl = Set_FloorHeat_Func;	        //地暖设备输出控制
	}
	else if(data[7]==ENUM_RS485_DEV_PRO_02)
	{
		BUS_Public.DevFunInfo.Dev_Input_Type_Get = CLED_FloorHeat_Input_Check;	//地暖设备输入检测
		BUS_Public.DevFunInfo.Dev_Output_Ctrl = CLED_Set_FloorHeat_Func;	        //地暖设备输出控制
	}
	
	FloorHeat_Info.DevOfflineLast = DEV_IS_ONLINE;	//设备在线状态初始化
	FloorHeat_Info.DevOffline = FloorHeat_Info.DevOfflineLast;
	switch(BUS_Public.Protocol)	//协议判断
	{
		case ENUM_RS485_DEV_PRO_01: if(NULL!=RS485_DEV_PRO_FUN_01) RS485_DEV_PRO_FUN_01(&BUS_Public, &FloorHeat_Info);break;
		case ENUM_RS485_DEV_PRO_02: if(NULL!=RS485_DEV_PRO_FUN_02) RS485_DEV_PRO_FUN_02(&BUS_Public, &FloorHeat_Info);break;
//		case ENUM_RS485_DEV_PRO_03: if(NULL!=RS485_DEV_PRO_FUN_03) RS485_DEV_PRO_FUN_03(&BUS_Public, &FloorHeat_Info);break;
//		case ENUM_RS485_DEV_PRO_04: if(NULL!=RS485_DEV_PRO_FUN_04) RS485_DEV_PRO_FUN_04(&BUS_Public, &FloorHeat_Info);break;
	}
	switch(dev_info->port)	//端口判断
	{
		case Active_Port:	//主动端口
			BUS_Public.port = Active_Port;		//设备发送端口
			Add_ACT_Device_To_List2(&BUS_Public,(uint8_t *)&FloorHeat_Info,sizeof(RS485_FloorHeat_INFO));
			Act485_Info.device_num += 1;
			break;
		case Polling_Port:	//轮询端口
			BUS_Public.port = Polling_Port;		//设备发送端口
			Add_POLL_Device_To_List2(&BUS_Public,(uint8_t *)&FloorHeat_Info,sizeof(RS485_FloorHeat_INFO));   //将填充后的数据添加到链表
			Poll485_Info.device_num += 1;
			break;
		case Bus_port:	//总线端口
			break;
	}
}

/*******************************************************************************
  * @brief      地暖设备输入检测
  * @param  
  *		CfgDevAddIn		输入触发节点
  *		DevInputLoop	设备输入回路
  *		DevInputType	输入类型
  * @retval
		CtrlInvalid - 控制无效
		CtrlValid - 控制有效
  * @attention	None
*******************************************************************************/
uint8_t FloorHeat_Input_Check(uint32_t CfgDevAddIn,uint16_t DevInputLoop,uint16_t DevInputType)
{
	uint8_t rec = CtrlInvalid;	//返回值（默认不是宝来威新风数据）
//	static uint8_t on_off_last = 0, valve_last = 0;	//上一次开关机、阀状态
	
	uint8_t keep_flag = 0x00;
	
	if(CfgDevAddIn == NULL) return rec;
	FloorHeat_Content_Struct FloorHeat_Input;	//地暖输入控制条件
	
	
	RS485_FloorHeat_INFO FloorHeat_Info;	//地暖设备私有属性
	Device_Public_Information_G BUS_Public;
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),CfgDevAddIn);	
	SRAM_DMA_Read_Buff((uint8_t *)&FloorHeat_Info,sizeof(RS485_FloorHeat_INFO), CfgDevAddIn+Dev_Privately);	//读取私有属性
	
	
	FloorHeat_Input.valve = (DevInputType >> 8) & 0x0F;	//取输入阀门状态
	if(FloorHeat_Info.new_state.on_off != FloorHeat_Info.last_state.on_off || FloorHeat_Info.new_state.valve != FloorHeat_Info.last_state.valve)	//当前状态发生变化
	{
		if(FloorHeat_Input.valve == FLOORHEAT_VALVE_ON)	//输入控制阀为开
		{
			if(FloorHeat_Info.new_state.on_off == FLOORHEAT_ON)	//当前开关机状态为开机
			{
				if(FloorHeat_Info.new_state.valve == FLOORHEAT_VALVE_ON)	//当前阀开
				{
					FloorHeat_Info.last_state.on_off = FloorHeat_Info.new_state.on_off;	//更新开关机状态
					FloorHeat_Info.last_state.valve = FloorHeat_Info.new_state.valve;	//更新阀状态
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"地暖 %d 当前状态发生变化，执行当前 %d 阀门对应动作",BUS_Public.addr,FloorHeat_Input.valve);
					rec = CtrlValid;
					keep_flag = 0x01;
				}
			}
		}
		if(FloorHeat_Input.valve == FLOORHEAT_VALVE_OFF)	//输入控制阀为关
		{
			if(FloorHeat_Info.new_state.on_off == FLOORHEAT_ON)	//当前开关机状态为开机
			{
				if(FloorHeat_Info.new_state.valve == FLOORHEAT_VALVE_OFF)	//当前阀关
				{
					FloorHeat_Info.last_state.on_off = FloorHeat_Info.new_state.on_off;	//更新开关机状态
					FloorHeat_Info.last_state.valve = FloorHeat_Info.new_state.valve;	//更新阀状态
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"地暖 %d 当前状态发生变化，执行当前 %d 阀门对应动作",BUS_Public.addr,FloorHeat_Input.valve);
					rec = CtrlValid;
					keep_flag = 0x01;
				}
			}
			if(FloorHeat_Info.new_state.on_off == FLOORHEAT_OFF)	//当前开关机状态为关机
			{
				FloorHeat_Info.last_state.on_off = FloorHeat_Info.new_state.on_off;	//更新开关机状态
				FloorHeat_Info.last_state.valve = FloorHeat_Info.new_state.valve;	//更新阀状态
				Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"地暖 %d 当前状态发生变化，执行当前 %d 阀门对应动作",BUS_Public.addr,FloorHeat_Input.valve);
				rec = CtrlValid;
				keep_flag = 0x01;
			}
		}
	}
	
	if(keep_flag == 0x01)
	{
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&FloorHeat_Info, sizeof(RS485_FloorHeat_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),CfgDevAddIn);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&FloorHeat_Info,sizeof(RS485_FloorHeat_INFO),CfgDevAddIn+Dev_Privately);
	}
	
	return rec;
}

/*******************************************************************************
  * @brief      设置地暖设备功能
  * @param  
  *		DevAddrIn		设备地址输入
  *		DevInputLoop	输入地址
  *		DevAddrOut		共有数据地址
  *		DevOutputLoop	输出回路数
  *		DevOutputType	输出类型
  * @retval     None
  * @attention	None
*******************************************************************************/
void Set_FloorHeat_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_FloorHeat_INFO FloorHeat_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 *)&FloorHeat_Info,sizeof(RS485_FloorHeat_INFO), DevAddrOut+Dev_Privately);	//读取私有属性
	function = DevOutputType & 0x00FF;	//取低8位
	content = (DevOutputType >> 8) & 0x00FF;	//取高8位
	switch(function)	//判断命令
	{
		case FLOORHEAT_ON_OFF_FUNCTION:	//开关机功能
			switch(content)	//判断内容
			{
				case FLOORHEAT_ON:	//开机
				case FLOORHEAT_OFF:	//关机
					FloorHeat_Info.ctrl_content.on_off = content;
					FloorHeat_Info.ctrl_flag.on_off = 0x01;	//控制开关机置1
					FloorHeat_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,FloorHeat_Info.ctrl_content.on_off);
					break;
			}
			break;
		case FLOORHEAT_SET_OC_FUNCTION:	//设置温度功能
			if((FloorHeat_Info.new_state.on_off == FRESHAIR_ON) && ((content >= 16) && (content <= 32)))	//温度内容只能在开机并且温度设置16~32度范围
			{
				FloorHeat_Info.ctrl_content.set_oc = content;
				FloorHeat_Info.ctrl_flag.set_oc = 0x01;	//控制设置温度置1
				FloorHeat_Info.ctrl_cnt.set_oc = FRESHAIR_MAXRET;	//控制设置温度发送次数
				save_flag = 1;	//保存标志置1
				Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"执行地暖温度控制，地址:%d 回路%d 状态:%d",BUS_Public.addr,DevOutputLoop,FloorHeat_Info.ctrl_content.set_oc);
			}
			break;
//		case FLOORHEAT_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 FLOORHEAT_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 *)&FloorHeat_Info, 
							sizeof(RS485_FloorHeat_INFO));	//两个数组和校验取反
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), DevAddrOut);	//保存地暖设备共有属性
		SRAM_DMA_Write_Buff((uint8_t *)&FloorHeat_Info,sizeof(RS485_FloorHeat_INFO), DevAddrOut + Dev_Privately);	//保存地暖设备私有属性
	}
}



/*******************************************************************************
  * @brief      地暖设备输入检测
  * @param  
  *		CfgDevAddIn		输入触发节点
  *		DevInputLoop	设备输入回路
  *		DevInputType	输入类型
  * @retval
		CtrlInvalid - 控制无效
		CtrlValid - 控制有效
  * @attention	None
*******************************************************************************/
uint8_t CLED_FloorHeat_Input_Check(uint32_t CfgDevAddIn,uint16_t DevInputLoop,uint16_t DevInputType)
{
	uint8_t rec = CtrlInvalid;	//返回值（默认不是宝来威新风数据）
//	static uint8_t on_off_last = 0, valve_last = 0;	//上一次开关机、阀状态
	
	uint8_t keep_flag = 0x00;
	
	if(CfgDevAddIn == NULL) return rec;
	FloorHeat_Content_Struct FloorHeat_Input;	//地暖输入控制条件
	
	Device_Public_Information_G BUS_Public;	//地暖设备共有属性
	RS485_FloorHeat_INFO FloorHeat_Info;	//地暖设备私有属性
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),CfgDevAddIn);	
	SRAM_DMA_Read_Buff((uint8_t *)&FloorHeat_Info,sizeof(RS485_FloorHeat_INFO), CfgDevAddIn+Dev_Privately);	//读取私有属性
	FloorHeat_Input.valve = (DevInputType >> 8) & 0x0F;	//取输入阀门状态
	
	if(FloorHeat_Info.new_state.on_off != FloorHeat_Info.last_state.on_off || FloorHeat_Info.new_state.valve != FloorHeat_Info.last_state.valve)	//当前状态发生变化
	{
		if(FloorHeat_Input.valve == FLOORHEAT_VALVE_ON)	//输入控制阀为开
		{
			if(FloorHeat_Info.new_state.on_off == FLOORHEAT_ON)	//当前开关机状态为开机
			{
				if(FloorHeat_Info.new_state.valve == FLOORHEAT_VALVE_ON)	//当前阀开
				{
					FloorHeat_Info.last_state.on_off = FloorHeat_Info.new_state.on_off;	//更新开关机状态
					FloorHeat_Info.last_state.valve = FloorHeat_Info.new_state.valve;	//更新阀状态
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"CLED地暖当前状态发生变化，执行当前 %d 阀门对应动作",FloorHeat_Input.valve);
					rec = CtrlValid;
					keep_flag = 0x01;
				}
			}
		}
		if(FloorHeat_Input.valve == FLOORHEAT_VALVE_OFF)	//输入控制阀为关
		{
			if(FloorHeat_Info.new_state.on_off == FLOORHEAT_ON)	//当前开关机状态为开机
			{
				if(FloorHeat_Info.new_state.valve == FLOORHEAT_VALVE_OFF)	//当前阀关
				{
					FloorHeat_Info.last_state.on_off = FloorHeat_Info.new_state.on_off;	//更新开关机状态
					FloorHeat_Info.last_state.valve = FloorHeat_Info.new_state.valve;	//更新阀状态
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"CLED地暖当前状态发生变化，执行当前 %d 阀门对应动作",FloorHeat_Input.valve);
					rec = CtrlValid;
					keep_flag = 0x01;
				}
			}
			if(FloorHeat_Info.new_state.on_off == FLOORHEAT_OFF)	//当前开关机状态为关机
			{
				FloorHeat_Info.last_state.on_off = FloorHeat_Info.new_state.on_off;	//更新开关机状态
				FloorHeat_Info.last_state.valve = FloorHeat_Info.new_state.valve;	//更新阀状态
				Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"CLED地暖当前状态发生变化，执行当前 %d 阀门对应动作",FloorHeat_Input.valve);
				rec = CtrlValid;
				keep_flag = 0x01;
			}
		}
	}
	
	if(keep_flag == 0x01)
	{
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&FloorHeat_Info, sizeof(RS485_FloorHeat_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),CfgDevAddIn);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&FloorHeat_Info,sizeof(RS485_FloorHeat_INFO),CfgDevAddIn+Dev_Privately);
	}
	
	return rec;
}

/*******************************************************************************
  * @brief      设置地暖设备功能
  * @param  
  *		DevAddrIn		设备地址输入
  *		DevInputLoop	输入地址
  *		DevAddrOut		共有数据地址
  *		DevOutputLoop	输出回路数
  *		DevOutputType	输出类型
  * @retval     None
  * @attention	None
*******************************************************************************/
void CLED_Set_FloorHeat_Func(uint32_t DevAddrIn,uint16_t DevInputLoop,uint32_t DevAddrOut,uint16_t DevOutputLoop,uint16_t DevOutputType)
{
	uint8_t onoff, settemp;	//功能，内容
	uint8_t save_flag = 0;	//保存标志
	Device_Public_Information_G BUS_Public;	//地暖设备共有属性
	RS485_FloorHeat_INFO FloorHeat_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 *)&FloorHeat_Info,sizeof(RS485_FloorHeat_INFO), DevAddrOut+Dev_Privately);	//读取私有属性
	
	onoff = DevOutputType & 0x00FF;	//取低8位
	settemp = (DevOutputType >> 8) & 0x00FF;	//取高8位
	
	
	switch(onoff)
	{
		case FLOORHEAT_ON:	//开机
		case FLOORHEAT_OFF:	//关机
			FloorHeat_Info.ctrl_content.on_off = onoff;
		    FloorHeat_Info.ctrl_flag.on_off = 0x01;	//控制开关机置1
			FloorHeat_Info.ctrl_cnt.on_off = FRESHAIR_MAXRET;	//控制新风开关机发送次数
			save_flag = 1;	//保存标志置1
			break;
		default:
			break;
	}
	
	if(settemp)
	{
		if(((settemp >= 16) && (settemp <= 32)))	//温度内容只能在开机并且温度设置16~32度范围
		{
			FloorHeat_Info.ctrl_content.set_oc = settemp;
			FloorHeat_Info.ctrl_flag.set_oc = 0x01;	//控制设置温度置1
			FloorHeat_Info.ctrl_cnt.set_oc = FRESHAIR_MAXRET;	//控制设置温度发送次数
			save_flag = 1;	//保存标志置1
		}
	}
	
	Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"执行CLED地暖控制，地址:%d 回路%d 开关机:%d 温度:%d",\
	BUS_Public.addr,DevOutputLoop,FloorHeat_Info.ctrl_content.on_off,FloorHeat_Info.ctrl_content.set_oc);
	
	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 *)&FloorHeat_Info, 
							sizeof(RS485_FloorHeat_INFO));	//两个数组和校验取反
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), DevAddrOut);	//保存地暖设备共有属性
		SRAM_DMA_Write_Buff((uint8_t *)&FloorHeat_Info,sizeof(RS485_FloorHeat_INFO), DevAddrOut + Dev_Privately);	//保存地暖设备私有属性
	}
}

