
/**
  ******************************************************************************
  * @file    BLV_485_Dev_TempFun.c
  * @author  BLW RCU  development Team
  * @version V1.0.0
  * @date    2022年03月18日
  * @brief   温控器驱动总表         
	* @log   202205171611     SongHan    增加温控器驱动开启关闭标志         
	* 
  ******************************************************************************
  */


#include "BLV_485_Dev_TempFun.h"
#include "string.h"
#include "SPI_SRAM.h"
#include "usart.h"
#include "check_fun.h"
#include "DBG.h"
#include "rw_logging.h"
#include "SRAM_Variable_Address.h"
#include "Log_api.h"
#include "BLV_NET_Function.h"
#include "rtc.h"
#include "includes.h"

/*外设头文件开始*/
#include "BLV_485_Dev_TempT1Fun.h"
#include "BLV_485_Dev_C7TFun.h"

/*外设头文件结束*/


/*T1温控器驱动代码*/

#define REPEATSENDTIMEMAX         0x03  //重发次数上限

#define Dev_Temp_RecvData_Len_Max	0x20	//温控器接收最大数据长度

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

/*设备驱动宏定义开始*/
#define RS485_DEV_PRO_FUN_01    DevExistJudgge(RS485_Temp_T1_Flag, BLWOut_RS485_TempT1_Data_Init) //((DevFunP)NULL)      //宝来威T1温控器
#define RS485_DEV_PRO_FUN_02    DevExistJudgge(RS485_Temp_C7T_Flag, BLV_RS485_C7T_Data_Init)  //((DevFunP)NULL)      //C7T温控器
#define RS485_DEV_PRO_FUN_03    DevExistJudgge(RS485_Temp_T1_Flag_Si, BLWOut_RS485_TempT1D_Data_Init)   //宝来威T1温控器    四管   2023-03-24
#define RS485_DEV_PRO_FUN_04    DevExistJudgge(RS485_Temp_T1_Active_Flag, BLWOut_RS485_TempT1_Activ_Init)   //宝来威T1温控器    四管  主动端口   2024-11-05
/*设备驱动宏定义结束*/

/*本地函数申明开始*/
uint8_t Dev_TEMPCTRL_InType_Get(uint32_t CfgDevAddIn, uint16_t DevInputLoop, uint16_t DevInputType);
void Dev_TEMPCTRL_Ctrl(uint32_t CfgDevAddIn, uint16_t DevInputAddr, uint32_t CfgDevAddOut, uint16_t DevOutputLoop, uint16_t DevOutputType);
void Temp_FanAuto_Set(RS485_TEMP_BASIC *Rs485TemRecBuf, RS485_TEMP_INFO *Rs485Tem);


/*本地函数申明结束*/

/*******************************************************************************
* Function Name  : BLW_RS485_TempFun_For_Logic_Init 
* Description    : 继电器初始化信息来自逻辑文件
*******************************************************************************/
void BLW_RS485_TempFun_For_Logic_Init(LOGICFILE_DEVICE_INFO *dev_info,uint8_t *data,uint16_t data_len)
{
	Device_Public_Information_G BUS_Public;
	RS485_TEMP_INFO Rs485TempT1;
	
	memset(&BUS_Public,0,sizeof(Device_Public_Information_G));
	memset(&Rs485TempT1,0,sizeof(RS485_TEMP_INFO));
	
	BUS_Public.addr = dev_info->addr;		//设备地址
	BUS_Public.type = dev_info->type;		//设备类型
	BUS_Public.port = dev_info->port;
	BUS_Public.baud = 9600;		//设备发送波特率
	BUS_Public.retry_num = 0x05;	//设备数据重发次数
	BUS_Public.wait_time = 0x0190;	//设备数据发送等待回复时间 - 200ms
	BUS_Public.Protocol = dev_info->version;
	
	
	BUS_Public.DevFunInfo.Dev_Input_Type_Get = Dev_TEMPCTRL_InType_Get;   
	BUS_Public.DevFunInfo.Dev_Output_Ctrl = Dev_TEMPCTRL_Ctrl;  
	BUS_Public.DevFunInfo.Dev_Output_Loop_State_Get = Get_BLV485_TEMP_Status;  
	Rs485TempT1.TemState.on_off = 1;
	Rs485TempT1.TemState.set_t = 25;
	Rs485TempT1.TemState.indoor_t = 26;
	Rs485TempT1.DevOfflineLast = DEV_IS_ONLINE;   //在线状态初始化
	Rs485TempT1.DevOffline = Rs485TempT1.DevOfflineLast;
	
//	switch(BUS_Public.addr)
//	{
//		case 0x00:memcpy(&Rs485TempT1.DevNameStruct, "空调00", strlen("空调00"));break;
//		case 0x01:memcpy(&Rs485TempT1.DevNameStruct, "空调01", strlen("空调01"));break;
//		case 0x02:memcpy(&Rs485TempT1.DevNameStruct, "空调02", strlen("空调02"));break;
//		case 0x03:memcpy(&Rs485TempT1.DevNameStruct, "空调03", strlen("空调03"));break;
//		case 0x04:memcpy(&Rs485TempT1.DevNameStruct, "空调04", strlen("空调04"));break;
//		case 0x05:memcpy(&Rs485TempT1.DevNameStruct, "空调05", strlen("空调05"));break;
//		case 0x06:memcpy(&Rs485TempT1.DevNameStruct, "空调06", strlen("空调06"));break;
//		case 0x07:memcpy(&Rs485TempT1.DevNameStruct, "空调07", strlen("空调07"));break;
//		case 0x08:memcpy(&Rs485TempT1.DevNameStruct, "空调08", strlen("空调08"));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, &Rs485TempT1);break; //        
		case	 ENUM_RS485_DEV_PRO_02: if(NULL!=RS485_DEV_PRO_FUN_02) RS485_DEV_PRO_FUN_02(&BUS_Public, &Rs485TempT1);break; //          
		case	 ENUM_RS485_DEV_PRO_03: if(NULL!=RS485_DEV_PRO_FUN_03) RS485_DEV_PRO_FUN_03(&BUS_Public, &Rs485TempT1);break;                                 //3
		case	 ENUM_RS485_DEV_PRO_04: if(NULL!=RS485_DEV_PRO_FUN_04) RS485_DEV_PRO_FUN_04(&BUS_Public, &Rs485TempT1);break;
	}
	
	Rs485TempT1.ValveNoExist = dev_info->priproperty[0];      //无阀标记
	
	////提示音使能标记
	if( (dev_info->priproperty[1] & 0x03) == 0x01 )
	{
		Rs485TempT1.fan_en_flag = 0x01;
	}else {
		Rs485TempT1.fan_en_flag = 0x00;
	}
	
	//开机提示音
	if( (dev_info->priproperty[1] & 0x0C) == 0x04 )
	{
		Rs485TempT1.switch_en_flag = 0x01;
	}else {
		Rs485TempT1.switch_en_flag = 0x00;
	}
	
	//是否含停止档位
	if(dev_info->priproperty[2] == 0x01){
		Rs485TempT1.FanStop_Flag = 0x00;		//自动风速不包含风速停
	}else{
		Rs485TempT1.FanStop_Flag = 0x01;		//自动风速包含风速停,兼容老版本配置
	}
	
	//判断提示音是否使能
	if( ((Rs485TempT1.fan_en_flag == 0x01) && (PlayList.EnFlag == 0x00)) || ((Rs485TempT1.switch_en_flag == 0x01) && (PlayList.EnFlag == 0x00)) )
	{
		PlayList.EnFlag = 0x01;
	}
	
	Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"ValveNoExist init: %02X, %02X - %02x - %02x",Rs485TempT1.ValveNoExist,Rs485TempT1.fan_en_flag,Rs485TempT1.switch_en_flag,Rs485TempT1.FanStop_Flag);
	
	switch(dev_info->port)
	{
		case Active_Port:	//主动端口
			BUS_Public.port = Active_Port;		//设备发送端口
			Add_ACT_Device_To_List2(&BUS_Public,(uint8_t *)&Rs485TempT1,sizeof(RS485_TEMP_INFO));
			Act485_Info.device_num += 1;
			break;  
		case Polling_Port:	//轮询端口
			BUS_Public.port = Polling_Port;		//设备发送端口
			Add_POLL_Device_To_List2(&BUS_Public,(uint8_t *)&Rs485TempT1,sizeof(RS485_TEMP_INFO));
			Poll485_Info.device_num += 1;	
			break;
		case Bus_port:		//总线端口
			break;
	}
}

/*空调状态同步
	将sync_temp 状态同步给 temp

*/
void Dev_Temp_State_Sync(TemState_Struct *temp,TemState_Struct *sync_temp)
{
	temp->on_off = sync_temp->on_off;
	temp->mode = sync_temp->mode;
	temp->fan = sync_temp->fan;
	temp->valve = sync_temp->valve;
	temp->set_t = sync_temp->set_t;
	temp->indoor_t = sync_temp->indoor_t;
	

}

uint16_t Dev_Temp_State_Data(TemState_Struct temp)
{
	uint16_t temp_data = 0;
	
	temp_data = temp.on_off & 0x01;
	temp_data <<= 2;
	temp_data |= temp.mode & 0x03;
	temp_data <<= 2;
	temp_data |= temp.fan & 0x03;
	temp_data <<= 1;
	temp_data |= temp.valve & 0x01;
	temp_data <<= 5;
	temp_data |= temp.set_t & 0x1F;
	temp_data <<= 5;
	temp_data |= temp.indoor_t & 0x1F;
	
	return temp_data;
}

/**
  * @name  				空调输入类型状态得到，以及设备状态得到
  * @param  
  *    CfgDevAddIn  输入触发节点
  *    DevInputLoop 设备输入回路 也是空调下标  范围1~3
  *    DevInputType 输入类型
  * @retval 				输入回路的输入类型
	*   0x01:继电器状态改变      0x00:继电器状态不变
	* @brief          指定输入回路，输入类型状态返回
  * @attention      空调控制的继电器状态改变时
  */
uint8_t Dev_TEMPCTRL_InType_Get(uint32_t CfgDevAddIn, uint16_t DevInputLoop, uint16_t DevInputType)
{
	Device_Public_Information_G BUS_Public;   //共用	
	RS485_TEMP_INFO Rs485Tem;                                  //温控器局部变量
	uint8_t Ret = CtrlInvalid;          

	uint8_t SingFlag;   //单一判断  1为单一  2为非单一
	uint8_t SingCnt = 0;
	uint8_t i;
	
	if((DevInputLoop > 0x00) || (NULL == CfgDevAddIn))   //只要回路超过
	{
		return 0;               //就返回
	}
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),CfgDevAddIn);	
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485Tem,sizeof(RS485_TEMP_INFO),CfgDevAddIn+Dev_Privately);

	Rs485Tem.TemCondCfg.IndoorFlag = DevInputType & 0x0001;
	Rs485Tem.TemCondCfg.SetTFlag = (DevInputType >> 1) & 0x0001;
	Rs485Tem.TemCondCfg.ValveFlag = (DevInputType >> 2) & 0x0001;
	Rs485Tem.TemCondCfg.FanFlag = (DevInputType >> 3) & 0x0001;
	Rs485Tem.TemCondCfg.ModeFlag = (DevInputType >> 4) & 0x0001;
	Rs485Tem.TemCondCfg.OnOffFlag = (DevInputType >> 5) & 0x0001;
	Rs485Tem.TemCondCfg.IndoorState = (DevInputType >> 6) & 0x0001;
	Rs485Tem.TemCondCfg.SetTState = (DevInputType >> 7) & 0x0001;
	Rs485Tem.TemCondCfg.HValveFlag = (DevInputType >> 8) & 0x0001;
	Rs485Tem.TemCondCfg.HValveState = (DevInputType >> 9) & 0x0001;
	Rs485Tem.TemCondCfg.ValveState = (DevInputType >> 10) & 0x0001;
	Rs485Tem.TemCondCfg.FanState = (DevInputType >> 11) & 0x0003;
	Rs485Tem.TemCondCfg.ModeState = (DevInputType >> 13) & 0x0003;
	Rs485Tem.TemCondCfg.OnOffState = (DevInputType >> 15) & 0x0001;
	
	for(i = 0; i < 9; i++)     //2023-03-24
	{
		if(i!=6&&i!=7)    //2023-03-24
		{ 
			if(DevInputType&(0x01<<i))
			{
				SingCnt++;
			}
		}
	}
	if(0x01 == SingCnt)SingFlag = 0x01;
	else SingFlag = 0x02;
		
//	Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"当前动作执行，单一或者非单一:%d", SingFlag);						

	switch(SingFlag)
	{
		case 0x01:  //单一判断 状态也要满足
			if(0x01 == Rs485Tem.TemCondCfg.OnOffFlag)
			{
				if(0x01 == Rs485Tem.TemCondRec.OnOffFlag)
				{
					if(Rs485Tem.TemCondCfg.OnOffState == Rs485Tem.TemCondRec.OnOffState)
					{
						Ret = CtrlValid;
						Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"单一判断温控开关机清动作");						
						Rs485Tem.TemCondRec.OnOffFlag = 0x00;
					}
				}
			}
			else if((0x01 == Rs485Tem.TemCondCfg.ModeFlag)&&(0x01 == Rs485Tem.TemCondRec.ModeFlag)&&(Rs485Tem.TemCondCfg.ModeState == Rs485Tem.TemCondRec.ModeState))
			{
				Ret = CtrlValid;		
				Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"单一判断温控模式清动作");								
				Rs485Tem.TemCondRec.ModeFlag = 0x00;
			}
			else if((0x01 == Rs485Tem.TemCondCfg.FanFlag)&&(0x01 == Rs485Tem.TemCondRec.FanFlag)&&(Rs485Tem.TemCondCfg.FanState == Rs485Tem.TemCondRec.FanState)&&(Rs485Tem.TemCondRec.OnOffState==0x01))    //2023-02-23    只有在开机的时候判断风速
			{
				Ret = CtrlValid;	
				Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"单一判断温控风速清动作");								
				Rs485Tem.TemCondRec.FanFlag = 0x00;
			}
			else if(Rs485Tem.ValveSameFlag == 0x01)       //2023-03-24   双管
			{
				if((0x01 == Rs485Tem.TemCondCfg.ValveFlag)&&(0x01 == Rs485Tem.TemCondRec.ValveFlag)&&(Rs485Tem.TemCondCfg.ValveState == Rs485Tem.TemCondRec.ValveState)&&(Rs485Tem.TemCondRec.OnOffState==0x01))
				{
					Ret = CtrlValid;
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"单一判断温控阀门清动作");
					Rs485Tem.TemCondRec.ValveFlag = 0x00;
				}
			}
			else if(Rs485Tem.ValveSameFlag == 0x02)       //2023-03-24   四管
			{   
				if((0x01 == Rs485Tem.TemCondCfg.ValveFlag)\
					&&(0x01 == Rs485Tem.TemCondRec.ValveFlag)&&(Rs485Tem.TemCondCfg.ValveState == Rs485Tem.TemCondRec.ValveState)&&(Rs485Tem.TemCondRec.OnOffState==0x01))
				{
					Ret = CtrlValid;
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"单一判断温控冷阀清动作");
					Rs485Tem.TemCondRec.ValveFlag = 0x00;
		
				}  
				else if((0x01 == Rs485Tem.TemCondCfg.HValveFlag)\
					&&(0x01 == Rs485Tem.TemCondRec.HValveFlag)&&(Rs485Tem.TemCondCfg.HValveState == Rs485Tem.TemCondRec.HValveState)&&(Rs485Tem.TemCondRec.OnOffState==0x01))
				{
					Ret = CtrlValid;
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"单一判断温控热阀清动作");
					Rs485Tem.TemCondRec.HValveFlag = 0x00;
				}
				
			}
			else if((0x01 == Rs485Tem.TemCondCfg.SetTFlag)&&(0x01 == Rs485Tem.TemCondRec.SetTFlag)&&(Rs485Tem.TemCondCfg.SetTState == Rs485Tem.TemCondRec.SetTState))
			{
				Ret = CtrlValid;		
				Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"单一判断温控设置温度清动作");								
				Rs485Tem.TemCondRec.SetTFlag = 0x00;
			}
			else if((0x01 == Rs485Tem.TemCondCfg.IndoorFlag)&&(0x01 == Rs485Tem.TemCondRec.IndoorFlag)&&(Rs485Tem.TemCondCfg.IndoorState == Rs485Tem.TemCondRec.IndoorState))
			{
				Ret = CtrlValid;	
				Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"单一判断温控室内温度清动作");								
				Rs485Tem.TemCondRec.IndoorFlag = 0x00;
			}
			break;	
		case 0x02:   //非单一判断  不用判断状态
			if((0x01 == Rs485Tem.TemCondCfg.OnOffFlag)&&(0x01 == Rs485Tem.TemCondRec.OnOffFlag))
			{
				Ret = CtrlValid;
				Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"非单一判断温控开关机清动作");						
				Rs485Tem.TemCondRec.OnOffFlag = 0x00;
			}
			if((0x01 == Rs485Tem.TemCondCfg.ModeFlag)&&(0x01 == Rs485Tem.TemCondRec.ModeFlag))
			{
				Ret = CtrlValid;		
				Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"非单一判断温控模式清动作");								
				Rs485Tem.TemCondRec.ModeFlag = 0x00;
			}
			if((0x01 == Rs485Tem.TemCondCfg.FanFlag)&&(0x01 == Rs485Tem.TemCondRec.FanFlag))
			{
				Ret = CtrlValid;	
				Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"非单一判断温控风速清动作");								
				Rs485Tem.TemCondRec.FanFlag = 0x00;
			}
			if((0x01 == Rs485Tem.TemCondCfg.ValveFlag)&&(0x01 == Rs485Tem.TemCondRec.ValveFlag))
			{
				Ret = CtrlValid;	
				Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"非单一判断温控阀门清动作");								
				Rs485Tem.TemCondRec.ValveFlag = 0x00;
			}
			if((0x01 == Rs485Tem.TemCondCfg.SetTFlag)&&(0x01 == Rs485Tem.TemCondRec.SetTFlag))
			{
				Ret = CtrlValid;		
				Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"非单一判断温控设置温度清动作");								
				Rs485Tem.TemCondRec.SetTFlag = 0x00;
			}
			if((0x01 == Rs485Tem.TemCondCfg.IndoorFlag)&&(0x01 == Rs485Tem.TemCondRec.IndoorFlag))
			{
				Ret = CtrlValid;	
				Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"非单一判断温控室内温度清动作");								
				Rs485Tem.TemCondRec.IndoorFlag = 0x00;
			}			
			break;
	}
	
	if(CtrlValid == Ret)
	{
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&Rs485Tem, sizeof(RS485_TEMP_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),CfgDevAddIn);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&Rs485Tem,sizeof(RS485_TEMP_INFO),CfgDevAddIn+Dev_Privately);
	}
	
	return Ret;
}




/**
  * @name 					   设备485空调节点485参数空调控制数组变量赋值     
  * @param  
  *		 CfgDevAddIn        该动作的触发节点
  *    CfgDevAddOut       被控制的设备节点
	*    DevOutputLoop  		空调数组下标，目前用不上
	*    DevOutputType      设备执行方式
  * @retval 							无
  * @attention  			 专门为 Rs485Tem->TemStateCtrl 进行赋值
  *
  * 11 11 11 11 1111 
  */
void Dev_TEMPCTRL_Ctrl(uint32_t CfgDevAddIn, uint16_t DevInputAddr, uint32_t CfgDevAddOut, uint16_t DevOutputLoop, uint16_t DevOutputType)
{
	uint8_t TempOnOff;       //开关机
	uint8_t TempMode;        //模式
	uint8_t TempFan;        //风速
//	uint8_t TempValve;      //阀门控制   阀门暂时不参与控制
	uint8_t TempSet;        //设置温度
	TemState_Struct Rs485TemLoc;     //温控器局部变量，用于保存比较
	uint8_t TemCtrlFlag = 0x00;   //控制输出温控器标志
	
	Device_Public_Information_G BUS_PublicOut;   //共用	
	RS485_TEMP_INFO Rs485Tem;      //温控器局部变量
	uint8_t KeepFlag = 0x00;       //保存标志
	uint8_t SingleCtrlFlag = 0x00;   //单控标志，为1即为单控，为0即为全控
	Device_Public_Information_G BUS_PublicIn;   //共用
	RS485_TEMP_INFO Rs485TemIn;      //温控器局部变量
	
	if((NULL == CfgDevAddOut)||(0x00 != DevOutputLoop))  //被控制节点为空，或者被控制的回路非0就返回
	{
		return ;
	}
	/*拷贝设备私有信息*/
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485Tem,sizeof(RS485_TEMP_INFO),CfgDevAddOut+Dev_Privately);
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_PublicIn,sizeof(Device_Public_Information_G),CfgDevAddIn);		
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485TemIn,sizeof(RS485_TEMP_INFO),CfgDevAddIn+Dev_Privately);
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_PublicOut,sizeof(Device_Public_Information_G),CfgDevAddOut);		
//	Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"温控器状态事先同步485地址:%d，控制状态:%4x，控制参数:%4x,在线状态:%d",BUS_PublicOut.addr, TEMSTATECONVER(Rs485Tem.TemStateCtrl), DevOutputType, Rs485Tem.DevOffline);			
	
	Dev_Temp_State_Sync(&Rs485TemLoc,&Rs485Tem.TemStateCtrl);
	
	if(DEV_IS_ONLINE == Rs485Tem.DevOffline)  //如果输出温控器在线，状态全同步
	{
		if(Dev_Temp_State_Data(Rs485TemLoc) != Dev_Temp_State_Data(Rs485Tem.TemState))
		{
			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"温控器状态事先全同步，状态:%4x", Dev_Temp_State_Data(Rs485Tem.TemState));			

			Dev_Temp_State_Sync(&Rs485TemLoc,&Rs485Tem.TemState);
			Dev_Temp_State_Sync(&Rs485Tem.TemStateCtrlLast,&Rs485TemLoc);

			KeepFlag = 0x01;
		}
	}
	
	if((NULL != CfgDevAddIn) && (BUS_PublicIn.type == BUS_PublicOut.type) && (BUS_PublicIn.addr != BUS_PublicOut.addr))   //如果触发节点类型跟自己的一样 别的温控器需要同步自己的
	{ 
		if(DEV_IS_ONLINE == Rs485TemIn.DevOffline)  //如果触发温控器在线，才能同步
		{		
			TemCtrlFlag = 0x01;
			if(Dev_Temp_State_Data(Rs485Tem.TemState) != Dev_Temp_State_Data(Rs485TemIn.TemState))   //只要状态不一致，就赋值控制状态
			{
				Dev_Temp_State_Sync(&Rs485TemLoc,&Rs485TemIn.TemState);				//状态不一致，置控制状态
			}
			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"温控器状态同步，状态:%4x - %4x", Dev_Temp_State_Data(Rs485Tem.TemState),Dev_Temp_State_Data(Rs485TemIn.TemState));	
		}
	}
	else              //或者普通设备控制温控器
	{
		TemCtrlFlag = 0x01;
		TempOnOff = (DevOutputType>>14)&0x0003;   //取最高两位   
		TempMode = (DevOutputType>>12)&0x0003;    //取两位
		TempFan = (DevOutputType>>10)&0x0003;     //取两位
//		TempValve = (DevOutputType>>8)&0x0003;    //取两位
		TempSet = (DevOutputType)&0x00ff;         //温度(0x00 == TempOnOff) || 
		
		if(((DevOutputType&0xC000)&&(0x00 == (DevOutputType&0x3CFF))) || 
			((DevOutputType&0x3000)&&(0x00 == (DevOutputType&0xCCFF))) ||
		  ((DevOutputType&0x0C00)&&(0x00 == (DevOutputType&0xF0FF))) ||
//		  ((DevOutputType&0x0300)&&(0x00 == (DevOutputType&0xFCFF))) ||
		  ((DevOutputType&0x00FF)&&(0x00 == (DevOutputType&0xFC00))))  //开关机不为0，其他为0；模式不为0，其他为0；风速不为0，其他为0；温度不为0，其他为0  阀门不算
		{
			SingleCtrlFlag = 0x01;   //为1，即为单控，其他为0，就不要赋值
		}
		
		if(0x00 == SingleCtrlFlag)
		{
			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"温控器全控 %d %d %d %d",TempOnOff,TempMode,TempFan,TempSet);
		}
		else
		{
			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"温控器单控 %d %d %d %d",TempOnOff,TempMode,TempFan,TempSet);			
		}
		
		if((0x00 == TempOnOff) && (0x00 == TempMode) && (0x00 == TempFan) && (0x00 == TempSet))    //还原
		{
			if(0x00 != Dev_Temp_State_Data(Rs485Tem.TemKeepState))  //里面有保存过状态
			{
				//将保存过的状态，对控制状态进行赋值
				Dev_Temp_State_Sync(&Rs485TemLoc,&Rs485Tem.TemKeepState);
			}	
		}
		else if(0x03 == TempOnOff)  //保存
		{
			Rs485Tem.TemKeepState = Rs485Tem.TemState;
		}
		else if((0x00 == TempOnOff) && (0x00 != TempMode) && (0x00 != TempFan) && (0x00 == TempSet))  //温控器高级设置    2024-03-12 
		{
			switch(TempMode)
			{
				case 0x01:      //插卡状态同步
					switch(TempFan)
					{
						case 0x01:
							Rs485Tem.CardEn = 0x01;
							break;
						case 0x02:
							Rs485Tem.CardEn = 0x00;
							break;
						default:
							break;
					}
//					if(Rs485Tem.CardEnLast != Rs485Tem.CardEn)
//					{
						Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"温控器插卡同步：%d",Rs485Tem.CardEn);
//						Rs485Tem.CardEnLast = Rs485Tem.CardEn;
						Rs485Tem.CardFlag = 0x01;
						Rs485Tem.CardCnt = 0x03;
//					}
					break;
				case 0x02:     //控制模式提示音
					switch(TempFan)
					{
						case 0x01:
							Rs485Tem.fan_en_flag = 0x01;
							break;
						case 0x02:
							Rs485Tem.fan_en_flag = 0x00;
							break;
						default:
							break;
					}
					
					break; 
				case 0x03:     //控制开关提示音
					switch(TempFan)
					{
						case 0x01:
							Rs485Tem.switch_en_flag = 0x01;
							break;
						case 0x02:
							Rs485Tem.switch_en_flag = 0x00;
							break;
						default:
							break;
					}
					break;
				default:
					break;
			}
			//判断提示音是否使能
			if( ((Rs485Tem.fan_en_flag == 0x01) && (PlayList.EnFlag == 0x00)) || ((Rs485Tem.switch_en_flag == 0x01) && (PlayList.EnFlag == 0x00)) )
			{
				PlayList.EnFlag = 0x01;
			}
			
			Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"Tone EnFlag Rev: %02X - %02X",Rs485Tem.switch_en_flag,Rs485Tem.fan_en_flag);
			
			KeepFlag = 0x01;
		}
		else       //其他情况，全部转换成 Rs485Tem->TemStateCtrl 的值
		{
			switch(TempOnOff)
			{
				case 0x01:Rs485TemLoc.on_off = TEMP_STATE_ON;Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"温控器开机");break;//开机				
				case 0x02: Rs485TemLoc.on_off = TEMP_STATE_OFF;Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"温控器关机");break; //关机
			}
			
			switch(TempMode)                         //模式
			{
				case 1:   //冷
				case 2:   //热
				case 3:   //送风
					Rs485TemLoc.mode = TempMode; 
					Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"温控器模式:%d", TempMode);
					break;
				case 0:   //不存在
					if((0x00 == SingleCtrlFlag) && ((0x01 == TempOnOff)||(0x02 == TempOnOff))) //全控  且开关机有效
					{
						uint32_t Season;
						
						SRAM_Read_Buff((uint8_t *)&Season,4,SRAM_Register_Start_ADDRESS + Register_SeasonStatus_OFFSET);
						Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"季节打印:%08X 当前月份:%x", Season, RTC_Raw_Data.month);
						
						switch((Season>>(HEX_Conversion_To_DEC(RTC_Raw_Data.month)-1)*2)&0x03)   //当前月份的季节  
						{
							case Season_Summer:
								Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"当前季节夏季");
								Rs485TemLoc.mode = TEMP_COLD;
								Rs485TemLoc.fan = TEMP_MID; 
								Rs485TemLoc.set_t = 24;
								break;      //夏天 
							case Season_Winter:
								Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"当前季节冬季");							
								Rs485TemLoc.mode = TEMP_HOT; 
								Rs485TemLoc.fan = TEMP_MID;
								Rs485TemLoc.set_t = 26;
								break;     //冬天
							case Season_Spring:
								Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"当前季节春季");
								Rs485TemLoc.mode = TEMP_WIND;
							  Rs485TemLoc.fan = TEMP_MID;
							  Rs485TemLoc.set_t = 25;
							  break;      //春天 
							case Season_Autumn:
								Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"当前季节秋季");
								Rs485TemLoc.mode = TEMP_WIND;
							  Rs485TemLoc.fan = TEMP_LOW;
							  Rs485TemLoc.set_t = 25;
								break;
						}						
//						Rs485Tem->TemStateCtrl.mode = TEMP_MODEAUTO;
					}
					break;
			}	

			switch(TempFan)
			{
				case TEMP_FANAUTO:  //风速自动
					if(0x00 == SingleCtrlFlag)   //全控
					{
						Rs485TemLoc.fan = TEMP_FANAUTO;
					}
					break;
				default:
					Rs485TemLoc.fan = TempFan;  //风速完全赋值
					break;
			}
			
			switch(TempSet)     //温度单控  或者风速增加减少  温度增加减少
			{
				case TEM_DecTem:	//减少温度
					if(Rs485TemLoc.set_t == 0)	//32°
					{
						Rs485TemLoc.set_t = 31;
					}else if(Rs485TemLoc.set_t > 16)
					{
						Rs485TemLoc.set_t = Rs485Tem.TemState.set_t - 1;
					}else{
						//Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"当前温度已达最小值");
					}
					
					break;  
				case TEM_AddTem:	//增加温度
					if(Rs485TemLoc.set_t == 0)	//32°
					{
						//Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"当前温度已达最大值");		
					}else if(Rs485TemLoc.set_t < 32)
					{
						Rs485TemLoc.set_t = Rs485Tem.TemState.set_t + 1;
						if(Rs485TemLoc.set_t >= 32)
						{
							Rs485TemLoc.set_t = 0x00;
						}
					}
					
					break;   
				case TEM_DecFan:   //减风速
					if(0x00 == SingleCtrlFlag) break;   //仅单控
					switch(Rs485Tem.TemState.fan)
					{
						case TEMP_HIGH:Rs485TemLoc.fan = TEMP_MID;break;			
						case TEMP_MID:Rs485TemLoc.fan = TEMP_LOW;break;
					}
					break;
				case TEM_AddFan:   //加风速
					if(0x00 == SingleCtrlFlag) break;   //仅单控
					switch(Rs485Tem.TemState.fan)
					{
						case TEMP_MID:Rs485TemLoc.fan = TEMP_HIGH;break;	
						case TEMP_LOW:Rs485TemLoc.fan = TEMP_MID;break;	  
					}
					break;
				case SET_TEMP_FANAUTO:  //设置风速自动
					if(0x00 == SingleCtrlFlag) break;   //仅单控
					Rs485TemLoc.fan = TEMP_FANAUTO;
					break;
				case SET_TEMP_MODEAUTO:  //设置模式自动(暂无)
					if(0x00 == SingleCtrlFlag) break;   //仅单控
					break;
				case SET_FANAUTO1:  //设置风速含停止档
					if(0x00 == SingleCtrlFlag) break;   //仅单控
					Rs485Tem.FanStop_Flag = 0x01;
					break;
				case SET_FANAUTO2:  //设置风速不含停止档
					if(0x00 == SingleCtrlFlag) break;   //仅单控
					Rs485Tem.FanStop_Flag = 0x00;
					break;
				case 0x20:   //唯有32度  才赋值为0
//					if(0x00 == SingleCtrlFlag)  //全控
					{
						Rs485TemLoc.set_t = 0x00;
					}
					break;
				case 0x00:   //不赋值 保持原有温度
					break;
				default:
					if(TempSet >= 16 && TempSet < 32){
						Rs485TemLoc.set_t = TempSet; //设置温度完全赋值 赋值 16~31
					}
					break;
			}
			
			/*判断是否是服务器控制状态*/
			if(Rs485Tem.TemStateNetFlag != 0x00)
			{
				if(Rs485Tem.TemStateNetState == DevOutputType)
				{
					Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"云端控制 1:%4x - %4x", Rs485Tem.TemStateNetState,DevOutputType);
					Rs485Tem.TemStateNetFlag = 0x02;
					Rs485Tem.TemStateNetCnt = 0x00;
				}else{
					Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"非云端控制 1:%4x - %4x", Rs485Tem.TemStateNetState,DevOutputType);
					Rs485Tem.TemStateNetFlag = 0x00;
					Rs485Tem.TemStateNetState = 0x00;
					Rs485Tem.TemStateNetCnt = 0x00;
				}
			}
			
//			switch(TempValve)
//			{
//				case 0x01: Rs485Tem->TemStateCtrl.valve = TEMP_VALVE_OPEN; break; //开
//				case 0x02: Rs485Tem->TemStateCtrl.valve = TEMP_VALVE_CLOSE;break; //关
//			}	
			
		}	
	}
//	Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"温控器被控制后，状态:%4x", TEMSTATECONVER(Rs485TemLoc));			
	
	if(0x01 == TemCtrlFlag)
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"温控器控制状态:%4x - %4x", Dev_Temp_State_Data(Rs485Tem.TemStateCtrl),Dev_Temp_State_Data(Rs485TemLoc));
		
		/*给碳达人判断使用 - 设置状态进行同步，当设置状态与温控器实际状态不符时，碳达人判定将不生效 */
		if(Rs485Tem.Carbon_Set_Temp != Rs485TemLoc.set_t){
			Rs485Tem.Carbon_Set_Temp = Rs485TemLoc.set_t;
			KeepFlag = 0x01;
		}
		
		if(Dev_Temp_State_Data(Rs485Tem.TemStateCtrl) != Dev_Temp_State_Data(Rs485TemLoc) )
		{
			KeepFlag = 0x01;
			
			Dev_Temp_State_Sync(&Rs485Tem.TemStateCtrl,&Rs485TemLoc);
			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"TemStateCtrl: %04X", Dev_Temp_State_Data(Rs485Tem.TemStateCtrl));
		}else {
			if(Rs485Tem.TemStateNetFlag != 0x00)
			{
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"云端控制 2:%4x 不控制", Rs485Tem.TemStateNetState,DevOutputType);
				Rs485Tem.TemStateNetFlag = 0x00;
				Rs485Tem.TemStateNetState = 0x00;
				Rs485Tem.TemStateNetCnt = 0x00;
				KeepFlag = 0x01;
			}
		}
	}

	
	if(0x01 == KeepFlag)
	{
		
		BUS_PublicOut.check = 0x00;
		BUS_PublicOut.check = DoubleData_CheckSum((uint8_t *)&BUS_PublicOut, sizeof(Device_Public_Information_G), (uint8_t *)&Rs485Tem, sizeof(RS485_TEMP_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_PublicOut, sizeof(Device_Public_Information_G),CfgDevAddOut);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&Rs485Tem,sizeof(RS485_TEMP_INFO),CfgDevAddOut+Dev_Privately);
				
	}
}


/*获取温控器在线状态*/
uint8_t Get_BLV485_TEMP_Online_Status(uint32_t devaddr)
{
	RS485_TEMP_INFO Rs485TempT1;
	
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485TempT1,sizeof(RS485_TEMP_INFO),devaddr+Dev_Privately);
	
	if(Rs485TempT1.DevOffline == DEV_IS_ONLINE)
	{
		return 0x01;
	}
	return 0x02;
}

uint16_t Get_BLV485_TEMP_Status(uint32_t devaddr,uint16_t loop)
{
	RS485_TEMP_INFO Rs485TempT1;
	
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485TempT1,sizeof(RS485_TEMP_INFO),devaddr+Dev_Privately);
	
	return Dev_Temp_State_Data(Rs485TempT1.TemState);
}


/**
* @Name  空调设备单控标志判断
* @Para
*   CfgDevAdd     空调设备节点
*   Rs485TemCtrl  空调控制函数
*   Rs485TemCycle 空调轮询函数
* @ret    Ret 0x01 占用时间片  0x00  不占用
*/
uint8_t TemSingleJudge(uint32_t CfgDevAdd, RS485_Tem_Ctrl_ptr Rs485TemCtrl, RS485_Tem_CycleCtrl_ptr Rs485TemCycle)
{
	uint8_t Ret = RS485OCCUPYNOTIME;
//	uint16_t DataLen;
//	uint8_t Crc;
	
	uint8_t keepflag = 0x00;
	
	Device_Public_Information_G BUS_Public;
	RS485_TEMP_INFO Rs485TempT1;
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),CfgDevAdd);				
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485TempT1,sizeof(RS485_TEMP_INFO),CfgDevAdd+Dev_Privately);/*拷贝设备私有信息*/
	
//	Rs485Tem = CfgDevAdd->DevDataStruct;   //已经判断非空

	if(Rs485TempT1.TemStateCtrlLast.on_off != Rs485TempT1.TemStateCtrl.on_off)  //开关机
	{
		Rs485TempT1.TemStateCtrlLast.on_off = Rs485TempT1.TemStateCtrl.on_off;
		Rs485TempT1.TemStateCtrlFlag.TemOnOffCtrlVar = 0x01;
		Rs485TempT1.TemStateCtrlCnt.TemOnOffCtrlVar = REPEATSENDTIMEMAX;
	}
	if(Rs485TempT1.TemStateCtrlLast.mode != Rs485TempT1.TemStateCtrl.mode)  //模式
	{
		Rs485TempT1.TemStateCtrlLast.mode = Rs485TempT1.TemStateCtrl.mode;
		Rs485TempT1.TemStateCtrlFlag.TemModeCtrlVar = 0x01;
		Rs485TempT1.TemStateCtrlCnt.TemModeCtrlVar = REPEATSENDTIMEMAX;
	}
	if(Rs485TempT1.TemStateCtrlLast.set_t != Rs485TempT1.TemStateCtrl.set_t)  //温度
	{
		Rs485TempT1.TemStateCtrlLast.set_t = Rs485TempT1.TemStateCtrl.set_t;
		Rs485TempT1.TemStateCtrlFlag.TemSetTCtrlVar = 0x01;
		Rs485TempT1.TemStateCtrlCnt.TemSetTCtrlVar = REPEATSENDTIMEMAX;		
	}		
	if(Rs485TempT1.TemStateCtrlLast.fan != Rs485TempT1.TemStateCtrl.fan)  //风速
	{
		Rs485TempT1.TemStateCtrlLast.fan = Rs485TempT1.TemStateCtrl.fan;
		Rs485TempT1.TemStateCtrlFlag.TemFanCtrlVar = 0x01;
		Rs485TempT1.TemStateCtrlCnt.TemFanCtrlVar = REPEATSENDTIMEMAX;		
	}
	
	if(Rs485TempT1.DevPort != Rs485TempT1.DevPort_Last)
	{
		Rs485TempT1.DevPort_Last = Rs485TempT1.DevPort;
		Rs485TempT1.DevPort_Flag = 0x01;
	}


	if(0x01 == Rs485TempT1.TemStateCtrlFlag.TemOnOffCtrlVar)  //开关机
	{
		if(0x00 != Rs485TempT1.TemStateCtrlCnt.TemOnOffCtrlVar)
		{
			Rs485TempT1.TemStateCtrlCnt.TemOnOffCtrlVar--; 
			
			Rs485TemCtrl(&BUS_Public,&Rs485TempT1, 0x00);   //开关机
			Ret = RS485OCCUPYTIME;   //发送控制
		}
		else
		{
			Rs485TempT1.TemStateCtrlFlag.TemOnOffCtrlVar = 0x00;
			keepflag = 0x01;
		}
		
	}
	else if(0x01 == Rs485TempT1.TemStateCtrlFlag.TemModeCtrlVar)  //模式
	{
		if(0x00 != Rs485TempT1.TemStateCtrlCnt.TemModeCtrlVar)
		{
			Rs485TempT1.TemStateCtrlCnt.TemModeCtrlVar--; 
			
			Rs485TemCtrl(&BUS_Public, &Rs485TempT1, 0x01);   //模式
			Ret = RS485OCCUPYTIME;   //发送控制
		}
		else
		{
			Rs485TempT1.TemStateCtrlFlag.TemModeCtrlVar = 0x00;
			keepflag = 0x01;
		}
		
	}
	else if(0x01 == Rs485TempT1.TemStateCtrlFlag.TemSetTCtrlVar)  //温度
	{
		if(0x00 != Rs485TempT1.TemStateCtrlCnt.TemSetTCtrlVar)
		{
			Rs485TempT1.TemStateCtrlCnt.TemSetTCtrlVar--; 
			
			Rs485TemCtrl(&BUS_Public, &Rs485TempT1, 0x02);   //设置温度
			Ret = RS485OCCUPYTIME;   //发送控制
		}
		else
		{
			Rs485TempT1.TemStateCtrlFlag.TemSetTCtrlVar = 0x00;
			keepflag = 0x01;
		}
		
	}
	else if(0x01 == Rs485TempT1.TemStateCtrlFlag.TemFanCtrlVar)  //风速
	{
		if(0x00 != Rs485TempT1.TemStateCtrlCnt.TemFanCtrlVar)
		{
			Rs485TempT1.TemStateCtrlCnt.TemFanCtrlVar--; 
			
			Rs485TemCtrl(&BUS_Public, &Rs485TempT1, 0x03);   //风速
			Ret = RS485OCCUPYTIME;   //发送控制		
		}
		else
		{
			Rs485TempT1.TemStateCtrlFlag.TemFanCtrlVar = 0x00;
			keepflag = 0x01;
		}
		
	}
	else if(Rs485TempT1.CardFlag == 0x01)
	{
		if(0x00 != Rs485TempT1.CardCnt)
		{
			BLWOut_tempT1CardCtrl(&BUS_Public, &Rs485TempT1);
			Rs485TempT1.CardCnt--; 
			Ret = RS485OCCUPYTIME;   //发送控制
		}
		else
		{
			Rs485TempT1.CardFlag = 0x00;
			Rs485TempT1.CardCnt = 0x03;
			keepflag = 0x01;
		}
	}
	else if(Rs485TempT1.DevPort_Flag == 0x01)
	{
		BLV_T1Temp_PortSet_Send(&BUS_Public,&Rs485TempT1);
		Ret = RS485OCCUPYTIME;
	}
	else
	{
		if(BUS_Public.port == Polling_Port)    //2024-11-05
		{
			if(NULL != Rs485TemCycle)
			{
				Rs485TemCycle(&BUS_Public); 
				Ret = RS485OCCUPYTIME;// 发送轮询
			}
		}
		
		/* 2026-02-28
			云端控制后，查3次状态该标志位还存在的话,清除状态
			无控制标志位的情况下，云端控制不为零，便清除标志位
		
			预防温控器离线后，标志位一直成立
		*/
		if(Rs485TempT1.TemStateNetFlag != 0x00)
		{
			Rs485TempT1.TemStateNetCnt++;
			if(Rs485TempT1.TemStateNetCnt >= REPEATSENDTIMEMAX)
			{
				Rs485TempT1.TemStateNetCnt = 0x00;
				Rs485TempT1.TemStateNetFlag = 0x00;
				Rs485TempT1.TemStateNetState = 0x00;
			}
		}
	}

	if((RS485OCCUPYTIME == Ret) || (keepflag == 0x01))
	{
		/*通讯统计*/
		BLV_Communication_Record(&Rs485TempT1.comm_record,0x01,0x00);
		Rs485TempT1.inquire_tick = SysTick_1ms;
		
		if(Rs485TempT1.DevSendCnt > REPEATSENDTIMEMAX)
		{
			if(Rs485TempT1.DevOffline != DEV_IS_OFFLINE)
			{
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"Rs485TempT1%d DEV_IS_OFFLINE",BUS_Public.addr);
				LOG_Device_Online_Record(DEV_RS485_TEMP,BUS_Public.addr,LogInfo_Device_Offline);	//记录设备离线SRAM_Read_Byte(CfgDevAdd+Dev_Addr)
			}
			Rs485TempT1.DevOffline = DEV_IS_OFFLINE;   //判为离线
			if(Rs485TempT1.DevOffline != Rs485TempT1.DevOfflineLast)	//当前在线状态不等于上一次在线状态
			{
				Rs485TempT1.DevOfflineLast = Rs485TempT1.DevOffline;	//更新上一次在线状态
				Write_Device_Fault_State(BUS_Public.type,BUS_Public.addr,In_ErrFun_LineState,DEV_IS_OFFLINE);	//保存设备在线状态到SRAM
			}
			Rs485TempT1.DevPort_Flag = 0x00;
		}
		else
		{
			Rs485TempT1.DevSendCnt++;   //发送次数累计
		}
		
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&Rs485TempT1, sizeof(RS485_TEMP_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),CfgDevAdd);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&Rs485TempT1,sizeof(RS485_TEMP_INFO),CfgDevAdd+Dev_Privately);
				
	}
	
	return Ret;
}




/**
* @Name  空调设备全控标志判断
* @Para
*   CfgDevAdd     空调设备节点
*   Rs485TemCtrl  空调控制函数
*   Rs485TemCycle 空调轮询函数
* @ret    Ret 0x01 占用时间片  0x00  不占用
*/
uint8_t TemGlobalJudge(uint32_t CfgDevAdd, RS485_Tem_Ctrl_ptr Rs485TemCtrl, RS485_Tem_CycleCtrl_ptr Rs485TemCycle)
{
	uint8_t Ret = RS485OCCUPYNOTIME,Keep_flag = 0;
	
	Device_Public_Information_G BUS_Public;
	RS485_TEMP_INFO Rs485Tem;
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),CfgDevAdd);				
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485Tem,sizeof(RS485_TEMP_INFO),CfgDevAdd+Dev_Privately);/*拷贝设备私有信息*/
			
	if(Dev_Temp_State_Data(Rs485Tem.TemStateCtrlLast) != Dev_Temp_State_Data(Rs485Tem.TemStateCtrl))  //控制状态改变了
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"%s",__func__);
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"Rs485Temp %d CtrlFlag Set %04x - ", BUS_Public.addr, Dev_Temp_State_Data(Rs485Tem.TemStateCtrl),Dev_Temp_State_Data(Rs485Tem.TemStateCtrlLast));  
		
		//C7T 只有一个发送标志位即可
		
		Rs485Tem.TemStateCtrlFlag.TemOnOffCtrlVar = 0x01;
		Rs485Tem.TemStateCtrlCnt.TemOnOffCtrlVar = REPEATSENDTIMEMAX;
		
		Dev_Temp_State_Sync(&Rs485Tem.TemStateCtrlLast,&Rs485Tem.TemStateCtrl);
		
		Keep_flag = 0x01;
	}
	
	
	if(0x01 == Rs485Tem.TemStateCtrlFlag.TemOnOffCtrlVar)
	{
		if(0x00 != Rs485Tem.TemStateCtrlCnt.TemOnOffCtrlVar)
		{
			Rs485Tem.TemStateCtrlCnt.TemOnOffCtrlVar--; 
		}
		else
		{
			Rs485Tem.TemStateCtrlCnt.TemOnOffCtrlVar = 0x00;
		}
		if(NULL != Rs485TemCtrl)
		{
			Rs485TemCtrl(&BUS_Public, &Rs485Tem, NULL);   //发送控制
			Ret = RS485OCCUPYTIME;
		}
		
		Keep_flag = 0x01;
	}
	else
	{
		if(NULL != Rs485TemCycle)
		{
			Rs485TemCycle(&BUS_Public);   
			Ret = RS485OCCUPYTIME;// 发送轮询
			
			Keep_flag = 0x01;
		}
	}
	
	
	if( Keep_flag == 0x01 )
	{
		/*通讯统计*/
		BLV_Communication_Record(&Rs485Tem.comm_record,0x01,0x00);
		Rs485Tem.inquire_tick = SysTick_1ms;
		
		if(Rs485Tem.DevSendCnt > REPEATSENDTIMEMAX)
		{
			if(Rs485Tem.DevOffline != DEV_IS_OFFLINE)
			{
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"Rs485TempT1 %d DEV_IS_OFFLINE", BUS_Public.addr);
				LOG_Device_Online_Record(DEV_RS485_TEMP,BUS_Public.addr,LogInfo_Device_Offline);	//记录设备离线SRAM_Read_Byte(CfgDevAdd+Dev_Addr)
			}			
			Rs485Tem.DevOffline = DEV_IS_OFFLINE;   //判为离线
			if(Rs485Tem.DevOffline != Rs485Tem.DevOfflineLast)	//当前在线状态不等于上一次在线状态
			{
				Rs485Tem.DevOfflineLast = Rs485Tem.DevOffline;	//更新上一次在线状态
				Write_Device_Fault_State(BUS_Public.type,BUS_Public.addr,In_ErrFun_LineState,DEV_IS_OFFLINE);	//保存设备在线状态到SRAM
			}
		}
		else
		{
			Rs485Tem.DevSendCnt++;   //发送次数累计
		}
		
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&Rs485Tem, sizeof(RS485_TEMP_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),CfgDevAdd);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&Rs485Tem,sizeof(RS485_TEMP_INFO),CfgDevAdd+Dev_Privately);
	}
	
	return Ret;
}


///**
//  * @name  				空调自动风速动作赋值
//  * @param  
//  *    Rs485Tem        485温控器
//  * @retval 			     无
//	* @brief            将自动风速的转换成低中高的动作
//  * @attention      
//  */
//void Temp_FanAuto_Set(RS485_TEMP_BASIC *Rs485TemRecBuf, RS485_TEMP_INFO *Rs485Tem)
//{
//	if((0x00 == Rs485TemRecBuf->TemState.indoor_t) || (0x00 == Rs485TemRecBuf->TemState.set_t)) //为0就不判断了
//	{
//		return;
//	}
//	if(0x00 == Rs485TemRecBuf->FanAutoRelay)
//	{
//		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 自动风速，风速为0");

//		if(TEMP_COLD == Rs485TemRecBuf->TemState.mode)               //制冷
//		{
//			if(Rs485TemRecBuf->TemState.indoor_t <= Rs485TemRecBuf->TemState.set_t-3)
//			{
//				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 停止风速动作置位");
//				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作
//				Rs485Tem->TemCondRec.FanState = 0x00;    //风速停止
//			}
//			else if(Rs485TemRecBuf->TemState.indoor_t == Rs485TemRecBuf->TemState.set_t - 1)     //=
//			{
//				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 低风速动作置位");
//				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作
//				Rs485Tem->TemCondRec.FanState = TEMP_LOW;   //低风速
//			}
//			else if(Rs485TemRecBuf->TemState.indoor_t == (Rs485TemRecBuf->TemState.set_t + 1))
//			{
//				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 中风速动作置位");	
//				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作
//				Rs485Tem->TemCondRec.FanState = TEMP_MID; //中风速
//			}
//			else if(Rs485TemRecBuf->TemState.indoor_t >= (Rs485TemRecBuf->TemState.set_t + 3))       //=
//			{
//				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 高风速动作置位");		
//				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作			
//				Rs485Tem->TemCondRec.FanState = TEMP_HIGH;  //高风速
//			}
//		}
//		else if(TEMP_HOT == Rs485TemRecBuf->TemState.mode)               //制热
//		{
//			if(Rs485TemRecBuf->TemState.set_t <= Rs485TemRecBuf->TemState.indoor_t-3)
//			{
//				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作		
//				Rs485Tem->TemCondRec.FanState = 0x00;    //风速停止
//			}					
//			else if(Rs485TemRecBuf->TemState.set_t == Rs485TemRecBuf->TemState.indoor_t - 1)
//			{
//				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作		
//				Rs485Tem->TemCondRec.FanState = TEMP_LOW;   //低风速
//			}
//			else if(Rs485TemRecBuf->TemState.set_t == (Rs485TemRecBuf->TemState.indoor_t + 1))
//			{
//				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作		
//				Rs485Tem->TemCondRec.FanState = TEMP_MID; //中风速
//			}
//			else if(Rs485TemRecBuf->TemState.set_t >= (Rs485TemRecBuf->TemState.indoor_t + 3))
//			{
//				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作		
//				Rs485Tem->TemCondRec.FanState = TEMP_HIGH;  //高风速
//			}					
//		}
////	else if(TEMP_WIND == Rs485Tem->TemState.mode)
////	{
////			Rs485Tem->TemCondRec.FanState = TEMP_LOW;   //低风速
////	}	
//	}
//	else if(0x00 != Rs485TemRecBuf->FanAutoRelay)  //非0 就按照自动风速运行
//	{
//		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 自动风速，风速非0");
//		
//		switch(Rs485TemRecBuf->FanAutoRelay)
//		{
//			case 0x00:   //风速停止
//				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 停止风速动作置位");
//				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作
//				Rs485Tem->TemCondRec.FanState = 0x00;    //风速停止
//				break;
//			case 0x01:   //低风速
//				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 低风速动作置位");
//				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作
//				Rs485Tem->TemCondRec.FanState = TEMP_LOW;   //低风速
//				break;
//			case 0x02:   //中风速
//				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 中风速动作置位");	
//				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作
//				Rs485Tem->TemCondRec.FanState = TEMP_MID; //中风速
//				break;
//			case 0x04:   //高风速
//				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 高风速动作置位");		
//				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作			
//				Rs485Tem->TemCondRec.FanState = TEMP_HIGH;  //高风速				
//				break;
//		}
//	}
//}

/*2023.03.20林开锐修改开始*/
/**
  * @name  				空调自动风速动作赋值
  * @param  
  *    Rs485Tem        485温控器
  * @retval 			     无
	* @brief            将自动风速的转换成低中高的动作
  * @attention      
  */
void Temp_FanAuto_Set(RS485_TEMP_BASIC *Rs485TemRecBuf, RS485_TEMP_INFO *Rs485Tem)
{
	static uint8_t last_auto_fan = TEMP_LOW;	//默认上电是低速
	uint8_t indoor_temp = 0, set_temp = 0;	//室内温度，设置温度转化
	
	if((Rs485TemRecBuf->TemState.indoor_t > 0 && Rs485TemRecBuf->TemState.indoor_t < 16) || 
		(Rs485TemRecBuf->TemState.set_t > 0 && Rs485TemRecBuf->TemState.set_t < 16))
	{
		//printf("温度范围不符合，不处理。室内温度：%d   设置温度：%d\r\n",Rs485TemRecBuf->TemState.indoor_t,Rs485TemRecBuf->TemState.set_t);
		return;
	}
	if(Rs485TemRecBuf->TemState.indoor_t == 0) indoor_temp = 32;
	else indoor_temp = Rs485TemRecBuf->TemState.indoor_t;
	if(Rs485TemRecBuf->TemState.set_t == 0) set_temp = 32;
	else set_temp = Rs485TemRecBuf->TemState.set_t;
	//printf("室内温度：%d   设置温度：%d\r\n",indoor_temp,set_temp);
//	if((0x00 == Rs485TemRecBuf->TemState.indoor_t) || (0x00 == Rs485TemRecBuf->TemState.set_t)) //为0就不判断了
//	{
//		return;
//	}
	if(0x00 == Rs485TemRecBuf->FanAutoRelay)
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 自动风速，风速为0");

		if(TEMP_COLD == Rs485TemRecBuf->TemState.mode)               //制冷
		{
			if(indoor_temp <= (set_temp - 3))
			{
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 停止风速动作置位");
				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作
				
				if( (Rs485Tem->FanStop_Flag == 0x01) || (Rs485Tem->ValveNoExist == 0x01) ){    //自动风有停止档或者无阀
					Rs485Tem->TemCondRec.FanState = 0x00;    //风速停止
				}else{
					Rs485Tem->TemCondRec.FanState = TEMP_LOW;   //低风速
				}
				
				last_auto_fan = Rs485Tem->TemCondRec.FanState;
				//printf("Rs485Tem->TemCondRec.FanState：%d   last_auto_fan：%d\r\n",Rs485Tem->TemCondRec.FanState,last_auto_fan);
			}
			else if(indoor_temp == (set_temp - 1))     //=
			{
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 低风速动作置位");
				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作
				Rs485Tem->TemCondRec.FanState = TEMP_LOW;   //低风速
				last_auto_fan = Rs485Tem->TemCondRec.FanState;
				//printf("Rs485Tem->TemCondRec.FanState：%d   last_auto_fan：%d\r\n",Rs485Tem->TemCondRec.FanState,last_auto_fan);
			}
			else if(indoor_temp == (set_temp + 1))
			{
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 中风速动作置位");	
				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作
				Rs485Tem->TemCondRec.FanState = TEMP_MID; //中风速
				last_auto_fan = Rs485Tem->TemCondRec.FanState;
				//printf("Rs485Tem->TemCondRec.FanState：%d   last_auto_fan：%d\r\n",Rs485Tem->TemCondRec.FanState,last_auto_fan);
			}
			else if(indoor_temp >= (set_temp + 3))       //=
			{
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 高风速动作置位");		
				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作			
				Rs485Tem->TemCondRec.FanState = TEMP_HIGH;  //高风速
				last_auto_fan = Rs485Tem->TemCondRec.FanState;
				//printf("Rs485Tem->TemCondRec.FanState：%d   last_auto_fan：%d\r\n",Rs485Tem->TemCondRec.FanState,last_auto_fan);
			}
			else if(indoor_temp == set_temp)
			{
				//printf("设置温度与室内温度相等，赋值为上一次风速\r\n");
				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作			
				Rs485Tem->TemCondRec.FanState = last_auto_fan;  //高风速
			}
		}
		else if(TEMP_HOT == Rs485TemRecBuf->TemState.mode)               //制热
		{
			if(set_temp <= (indoor_temp - 3))
			{
				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作		
				if( (Rs485Tem->FanStop_Flag == 0x01) || (Rs485Tem->ValveNoExist == 0x01) ){    //自动风有停止档或者无阀
					Rs485Tem->TemCondRec.FanState = 0x00;    //风速停止
				}else{
					Rs485Tem->TemCondRec.FanState = TEMP_LOW;   //低风速
				}
				last_auto_fan = Rs485Tem->TemCondRec.FanState;
				//printf("Rs485Tem->TemCondRec.FanState：%d   last_auto_fan：%d\r\n",Rs485Tem->TemCondRec.FanState,last_auto_fan);
			}					
			else if(set_temp == (indoor_temp - 1))
			{
				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作		
				Rs485Tem->TemCondRec.FanState = TEMP_LOW;   //低风速
				last_auto_fan = Rs485Tem->TemCondRec.FanState;
				//printf("Rs485Tem->TemCondRec.FanState：%d   last_auto_fan：%d\r\n",Rs485Tem->TemCondRec.FanState,last_auto_fan);
			}
			else if(set_temp == (indoor_temp + 1))
			{
				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作		
				Rs485Tem->TemCondRec.FanState = TEMP_MID; //中风速
				last_auto_fan = Rs485Tem->TemCondRec.FanState;
				//printf("Rs485Tem->TemCondRec.FanState：%d   last_auto_fan：%d\r\n",Rs485Tem->TemCondRec.FanState,last_auto_fan);
			}
			else if(set_temp >= (indoor_temp + 3))
			{
				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作
				Rs485Tem->TemCondRec.FanState = TEMP_HIGH;  //高风速
				last_auto_fan = Rs485Tem->TemCondRec.FanState;
				//printf("Rs485Tem->TemCondRec.FanState：%d   last_auto_fan：%d\r\n",Rs485Tem->TemCondRec.FanState,last_auto_fan);
			}
			else if(set_temp == indoor_temp)
			{
				//printf("设置温度与室内温度相等，赋值为上一次风速\r\n");
				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作			
				Rs485Tem->TemCondRec.FanState = last_auto_fan;  //高风速
			}
		}
//	else if(TEMP_WIND == Rs485Tem->TemState.mode)
//	{
//			Rs485Tem->TemCondRec.FanState = TEMP_LOW;   //低风速
//	}	
	}
	else if(0x00 != Rs485TemRecBuf->FanAutoRelay)  //非0 就按照自动风速运行
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 自动风速，风速非0");
		
		switch(Rs485TemRecBuf->FanAutoRelay)
		{
			case 0x00:   //风速停止
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 停止风速动作置位");
				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作
				Rs485Tem->TemCondRec.FanState = 0x00;    //风速停止
				break;
			case 0x01:   //低风速
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 低风速动作置位");
				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作
				Rs485Tem->TemCondRec.FanState = TEMP_LOW;   //低风速
				break;
			case 0x02:   //中风速
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 中风速动作置位");	
				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作
				Rs485Tem->TemCondRec.FanState = TEMP_MID; //中风速
				break;
			case 0x04:   //高风速
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," 高风速动作置位");		
				Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作			
				Rs485Tem->TemCondRec.FanState = TEMP_HIGH;  //高风速				
				break;
		}
	}
}
/*2023.03.20林开锐修改结束*/

/**
  * @name  				空调动作得到函数
  * @param  
  *    Rs485TemRecBuf  485接收到的温控器数据
  *    Rs485Tem        485温控器
  * @retval 			     无
	* @brief            温控器可以产生6个动作 每个动作可以独立配置 也可以一起配置
  * @attention      
  */
void Temp_Action_Set(RS485_TEMP_BASIC *Rs485TemRecBuf, RS485_TEMP_INFO *Rs485Tem)
{
	uint8_t addPrompt_flag = 0;
	
	if(Rs485Tem->TemState.on_off != Rs485TemRecBuf->TemState.on_off)
	{
		Rs485Tem->TemState.on_off = Rs485TemRecBuf->TemState.on_off;  //开关机同步
		Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"产生开关机动作，当前状态: %d",Rs485TemRecBuf->TemState.on_off);
		Rs485Tem->TemCondRec.OnOffFlag = 0x01;      //开机动作
		Rs485Tem->TemCondRec.OnOffState = Rs485TemRecBuf->TemState.on_off;
		
		if(TEMP_STATE_ON == Rs485TemRecBuf->TemState.on_off)
		{
			Rs485Tem->TemCondRec.FanFlag = 0x01;  //开机产生风速动作  
			Rs485Tem->TemCondRec.FanState = Rs485TemRecBuf->TemState.fan;
			
			if(Rs485Tem->ValveSameFlag == 0x01)       //2023-03-24   双管
			{
				Rs485Tem->TemCondRec.ValveFlag = 0x01;  //开机产生阀门动作
			}
			else if(Rs485Tem->ValveSameFlag == 0x02)  //2023-03-24   四管
			{
				if(Rs485TemRecBuf->TemState.mode==0x01)         //2023-03-24
				{
					Rs485Tem->TemCondRec.ValveFlag = 0x01;   //开机产生冷阀门动作
					Rs485Tem->TemCondRec.HValveFlag = 0x00;  
				}
				else if(Rs485TemRecBuf->TemState.mode==0x02)
				{
					Rs485Tem->TemCondRec.ValveFlag = 0x00;   //开机产生热阀门动作
					Rs485Tem->TemCondRec.HValveFlag = 0x01;  
				}
				else if(Rs485TemRecBuf->TemState.mode==0x03)  //2023-03-24
				{
					Rs485Tem->TemCondRec.ValveFlag = 0x01;   
					Rs485Tem->TemCondRec.HValveFlag = 0x01;  
				}
			}
			Rs485Tem->TemCondRec.ValveState = Rs485TemRecBuf->TemState.valve;
			if(TEMP_FANAUTO == Rs485TemRecBuf->TemState.fan)   //自动风速
			{
				Temp_FanAuto_Set(Rs485TemRecBuf, Rs485Tem);//转换成低中高停的动作
			}
			Rs485Tem->TemCondRec.ModeFlag = 0x01;   //开机产生模式动作
			Rs485Tem->TemCondRec.ModeState = Rs485TemRecBuf->TemState.mode;
			
			if(Rs485Tem->inif_flag != 0x00)
			{
				if( (Rs485Tem->TemStateNetFlag == 0x00) && (Rs485Tem->switch_en_flag == 0x01) )
				{
					AddPrompt_ToList(0x06);
					addPrompt_flag = 0x01;
				}else {
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"空调提示音 不响应 %02x-%02x",Rs485Tem->switch_en_flag,Rs485Tem->TemStateNetFlag);	
				}
			}
		}else {
			if(Rs485Tem->inif_flag != 0x00)
			{
				if( (Rs485Tem->TemStateNetFlag == 0x00) && (Rs485Tem->switch_en_flag == 0x01) )
				{
					AddPrompt_ToList(0x07);
					addPrompt_flag = 0x01;
				}else {
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"空调提示音 不响应 %02x-%02x",Rs485Tem->switch_en_flag,Rs485Tem->TemStateNetFlag);	
				}
			}
		}
	}
	if(Rs485Tem->TemState.mode != Rs485TemRecBuf->TemState.mode)
	{
		Rs485Tem->TemState.mode = Rs485TemRecBuf->TemState.mode;  //模式同步
		if(TEMP_STATE_ON == Rs485TemRecBuf->TemState.on_off)
		{
			Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"产生模式动作，当前状态: %d",Rs485TemRecBuf->TemState.mode);
			Rs485Tem->TemCondRec.ModeFlag = 0x01;      //模式动作
			Rs485Tem->TemCondRec.ModeState = Rs485TemRecBuf->TemState.mode;
			/*2023.03.20林开锐修改开始*/
			
			if(TEMP_FANAUTO == Rs485TemRecBuf->TemState.fan)   //自动风速
			{
//				printf("自动风转化为低中高速动作\r\n");
				
				Rs485Tem->TemCondRec.FanFlag = 0x01;  //开机产生风速动作  
				Rs485Tem->TemCondRec.FanState = Rs485TemRecBuf->TemState.fan;
				
				Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"模式切换，自动风转化为低中高速动作");
				Temp_FanAuto_Set(Rs485TemRecBuf, Rs485Tem);//转换成低中高停的动作
				
			}
			/*2023.03.20林开锐修改结束*/
			if(Rs485Tem->inif_flag != 0x00)			//2025-8-22
			{
				if( (Rs485Tem->TemStateNetFlag == 0x00) && (addPrompt_flag == 0x00) && (Rs485Tem->fan_en_flag == 0x01) )
				{
					if(Rs485TemRecBuf->TemState.mode == 0x01)       //制冷
					{
						Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"增加制冷提示音");	
					
						AddPrompt_ToList(0x00);
						addPrompt_flag = 0x01;
					}
					else if(Rs485TemRecBuf->TemState.mode == 0x02)  //制热
					{
						Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"增加制热提示音");	
						AddPrompt_ToList(0x01);
						addPrompt_flag = 0x01;
					}
					else if(Rs485TemRecBuf->TemState.mode == 0x03)  //送风
					{
						Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"增加送风提示音");	
						AddPrompt_ToList(0x02);
						addPrompt_flag = 0x01;
					}
				}else {
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"空调提示音 不响应 %02x-%02x",Rs485Tem->fan_en_flag,Rs485Tem->TemStateNetFlag);	
				}
			}else {
				Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"第一次 空调提示音 不响应");	
			}
			
		}
	}
	if(Rs485Tem->TemState.fan != Rs485TemRecBuf->TemState.fan)
	{
		Rs485Tem->TemState.fan = Rs485TemRecBuf->TemState.fan;  //风速同步
		if((TEMP_STATE_ON == Rs485TemRecBuf->TemState.on_off)&&(TEMP_FANAUTO != Rs485TemRecBuf->TemState.fan))
		{
			Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"产生风速动作，当前状态: %d",Rs485TemRecBuf->TemState.fan);
			Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作
			Rs485Tem->TemCondRec.FanState = Rs485TemRecBuf->TemState.fan;
			
			if(Rs485Tem->inif_flag != 0x00)
			{
				if( (Rs485Tem->TemStateNetFlag == 0x00) && (addPrompt_flag == 0x00) && (Rs485Tem->fan_en_flag == 0x01) )
				{
					if(Rs485TemRecBuf->TemState.fan == 0x01)       //低速
					{
						Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"增加低速提示音");	
						AddPrompt_ToList(0x03);
					}
					else if(Rs485TemRecBuf->TemState.fan == 0x02)  //中速
					{
						Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"增加中速提示音");	
						AddPrompt_ToList(0x04);
					}
					else if(Rs485TemRecBuf->TemState.fan == 0x03)  //高速
					{
						Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"增加高速提示音");	
						AddPrompt_ToList(0x05);
					}
				}else {
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"空调提示音 不响应 %02x-%02x",Rs485Tem->fan_en_flag,Rs485Tem->TemStateNetFlag);
				}
			}else {
				Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"第一次 空调提示音 不响应");	
			}
		}else if((TEMP_STATE_ON == Rs485TemRecBuf->TemState.on_off)&&(TEMP_FANAUTO == Rs485TemRecBuf->TemState.fan)){
			Temp_FanAuto_Set(Rs485TemRecBuf, Rs485Tem);//转换成低中高停的动作    2026-03-26
		}
	}
	if((Rs485Tem->FanAutoRelay != Rs485TemRecBuf->FanAutoRelay)||(Rs485Tem->TemState.set_t != Rs485TemRecBuf->TemState.set_t)
		||(Rs485Tem->TemState.indoor_t != Rs485TemRecBuf->TemState.indoor_t))  //自动风速变 或者设置温度，室内温度变
	{
		Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"自动风速变化或者设置室内温度变化 :%d,%d,%d,%d,%d,%d",
			Rs485Tem->FanAutoRelay,
			Rs485TemRecBuf->FanAutoRelay,
			Rs485Tem->TemState.set_t,
			Rs485TemRecBuf->TemState.set_t,
			Rs485Tem->TemState.indoor_t,
			Rs485TemRecBuf->TemState.indoor_t
			);		
		Rs485Tem->FanAutoRelay = Rs485TemRecBuf->FanAutoRelay;	
		if((TEMP_STATE_ON == Rs485TemRecBuf->TemState.on_off) && (TEMP_FANAUTO == Rs485TemRecBuf->TemState.fan))  //如果是自动风速 动作将会重新赋值
		{
			Temp_FanAuto_Set(Rs485TemRecBuf, Rs485Tem);//转换成低中高停的动作
		}
	}

	if(Rs485Tem->TemState.valve != Rs485TemRecBuf->TemState.valve)
	{
		Rs485Tem->TemState.valve = Rs485TemRecBuf->TemState.valve;  //阀门同步
		if(TEMP_STATE_ON == Rs485TemRecBuf->TemState.on_off)
		{		
			Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"产生阀门动作，当前状态: %d",Rs485TemRecBuf->TemState.valve);
			if(Rs485Tem->ValveSameFlag == 0x01)       //2023-03-24   双管
			{
				Rs485Tem->TemCondRec.ValveFlag = 0x01;      //阀门动作
				Rs485Tem->TemCondRec.ValveState = Rs485TemRecBuf->TemState.valve;
			}
			else if(Rs485Tem->ValveSameFlag == 0x02)  //2023-03-24   四管
			{
				if(Rs485TemRecBuf->TemState.mode==0x01)
				{
					Rs485Tem->TemCondRec.ValveFlag = 0x01;      //阀门动作
					Rs485Tem->TemCondRec.HValveFlag = 0x00;      //阀门动作
					Rs485Tem->TemCondRec.ValveState = Rs485TemRecBuf->TemState.valve;
				}
				else if(Rs485TemRecBuf->TemState.mode==0x02)
				{
					Rs485Tem->TemCondRec.ValveFlag = 0x00;      //阀门动作
					Rs485Tem->TemCondRec.HValveFlag = 0x01;      //阀门动作
					Rs485Tem->TemCondRec.HValveState = Rs485TemRecBuf->TemState.valve;
				}
				else if(Rs485TemRecBuf->TemState.mode==0x03)
				{
					Rs485Tem->TemCondRec.ValveFlag = 0x01;      //阀门动作
					Rs485Tem->TemCondRec.HValveFlag = 0x01;      //阀门动作
					Rs485Tem->TemCondRec.ValveState = Rs485TemRecBuf->TemState.valve;
					Rs485Tem->TemCondRec.HValveState = Rs485TemRecBuf->TemState.valve;
				}
			}
			
		}
	}
	
	//2024-06-27    无阀时绑定风速动作
	if(Rs485Tem->ValveNoExist == 0x01)               
	{
		if((Rs485Tem->TemCondRec.ValveFlag == 0x01) || (Rs485Tem->TemCondRec.HValveFlag == 0x01))
		{
			if(Rs485Tem->TemState.on_off == TEMP_STATE_ON)
			{
				if(Rs485Tem->TemState.valve == 0x01)
				{
					if(TEMP_FANAUTO != Rs485TemRecBuf->TemState.fan)
					{
						Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作
						Rs485Tem->TemCondRec.FanState = Rs485TemRecBuf->TemState.fan;
					}
					else
					{
						Temp_FanAuto_Set(Rs485TemRecBuf, Rs485Tem);//转换成低中高停的动作
					}
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"无阀，风速: %d",Rs485Tem->TemCondRec.FanState);
				}
				else
				{
					if(TEMP_FANAUTO != Rs485TemRecBuf->TemState.fan)
					{
						Rs485Tem->TemCondRec.FanFlag = 0x01;      //风速动作
						Rs485Tem->TemCondRec.FanState = 0x00;     //风速停止
						Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"无阀，风速停");
					}
					else
					{
						Temp_FanAuto_Set(Rs485TemRecBuf, Rs485Tem);//转换成低中高停的动作
					}
				}
			}
		}
	}
	//2024-06-27
	
	if(Rs485Tem->TemState.set_t != Rs485TemRecBuf->TemState.set_t)
	{
		Rs485Tem->TemState.set_t = Rs485TemRecBuf->TemState.set_t;  //设置温度同步
		if(TEMP_STATE_ON == Rs485TemRecBuf->TemState.on_off)
		{
			Rs485Tem->TemCondRec.SetTFlag = 0x01;      //设置温度动作
			
			if(Rs485Tem->TemState.set_t < Rs485TemRecBuf->TemState.set_t)
			{
				Rs485Tem->TemCondRec.SetTState = 0x00;  //温度升    由0x01改为0x00    2023-03-24
			}
			else
			{ 
				Rs485Tem->TemCondRec.SetTState = 0x01;  //温度降    由0x02改为0x01    2023-03-24
			}
			Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"产生设置温度动作，当前状态: %d",Rs485Tem->TemCondRec.SetTState);
			
		}
	}
	if(Rs485Tem->TemState.indoor_t != Rs485TemRecBuf->TemState.indoor_t)
	{
		Rs485Tem->TemState.indoor_t = Rs485TemRecBuf->TemState.indoor_t;  //室内温度同步
		Rs485Tem->TemCondRec.IndoorFlag = 0x01;      //室内温度动作
		if(TEMP_STATE_ON == Rs485TemRecBuf->TemState.on_off)
		{		
			if(Rs485Tem->TemState.indoor_t < Rs485TemRecBuf->TemState.indoor_t)
			{
				Rs485Tem->TemCondRec.IndoorState = 0x00;  //温度升     由0x01改为0x00    2023-03-24
			}
			else
			{
				Rs485Tem->TemCondRec.IndoorState = 0x01;  //温度降     由0x02改为0x01    2023-03-24
			}
		}
		Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"产生室内温度动作，当前状态: %d",Rs485Tem->TemCondRec.IndoorState);
	}
	
	
	if(Rs485Tem->inif_flag == 0x00)
	{
		Rs485Tem->inif_flag = 0x01;
	}
	
	/*2026-02-28 增加云端控制温控器不响应提示音*/
	if( Rs485Tem->TemStateNetFlag != 0x00 )
	{
		Rs485Tem->TemStateNetFlag = 0x00;
		Rs485Tem->TemStateNetState = 0x00;
		Rs485Tem->TemStateNetCnt = 0x00;
	}
	
#if Dev_Nor_Carbon_Flag
	//Dev_Temp_State_Sync(&Rs485Tem->TemStateCtrl,&Rs485Tem->TemState);		//2024-12-16  碳达人用
	Rs485Tem->Carbon_Set_Temp = Rs485Tem->TemState.set_t;
	
#endif
}


