/**
  ******************************************************************************
  * @file    BLV_Bus_Dev_PB20Fun.c
  * @author  BLW RCU  development Team
  * @version V1.0
  * @date    2023年10月18日
  * @brief  
  *          PB20驱动
  ******************************************************************************
  */

#include "includes.h"

#if RS485_PB20Fun_Flag

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


/*设备驱动宏定义开始*/
#define RS485_DEV_PRO_FUN_01    DevExistJudgge(RS485_PB20Fun_Flag, BLV_RS485_PB20_Init)
#define RS485_DEV_PRO_FUN_02    DevExistJudgge(NULL, ((DevFunP)NULL))  //((DevFunP)NULL)           
/*设备驱动宏定义结束*/

/*本地函数定义开始*/
void BLV_PB20_Control_State(uint32_t CfgDevAddIn, uint16_t DevInputAddr, uint32_t devaddr,uint16_t loop,uint16_t start);
uint16_t BLV_PB20_Read_State(uint32_t devaddr,uint16_t loop);
void BLV_RS485_PB20_Init(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO *Rs485PB20, uint16_t LoopNum);
void BLV_PB20_GLight_Ctrl_Send(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20);
uint8_t BLV_PB20_CycleCtrl(uint32_t dev_addr);
uint8_t BLV_PB20_Rccv_Check(uint32_t dev_addr,uint32_t data_addr,uint16_t len);

void PB20_Strip_LoopCtrl(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20,uint8_t LoopNum,uint8_t LightNum,uint8_t DevAddr);        //PB-LS LoopCtrl
void PB20_LED_LoopCtrl(Device_Public_Information_G *BUS_Public,RS485_PB20_INFO* Rs485PB20,uint8_t LoopNum,uint8_t LightNum,uint8_t DevAddr);           //PB-LD LoopCtrl
void PB20_Relay_LoopCtrl(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20,uint8_t LoopNum,uint8_t State,uint8_t DevAddr); //PB-Relay LoopCtrl
void PB20_Strip_AllClose(Device_Public_Information_G *BUS_Public,RS485_PB20_INFO* Rs485PB20);    //PB-LS-ALLCLOSE
void PB20_Relay_AllClose(Device_Public_Information_G *BUS_Public,RS485_PB20_INFO* Rs485PB20);    //PB-Relay-AllClose
/*本地函数定义结束*/



/*******************************************************************************
* @name  :  PB20设备初始化
* @para  : 
*   DataLen :数据长度
*   Data:    数据数组
* @attention :代码配置
*******************************************************************************/
void BLV_RS485_PB20_Data_Init(uint16_t DataLen, uint8_t *Data)
{
	Device_Public_Information_G BUS_Public;
	RS485_PB20_INFO Rs485PB20;
	
	memset(&BUS_Public,0,sizeof(Device_Public_Information_G));
	memset(&Rs485PB20,0,sizeof(RS485_PB20_INFO));
	
	BUS_Public.addr = Data[1];		                                            //设备485地址
	BUS_Public.type = Data[0];		                                            //设备类型
	BUS_Public.baud = Data[3] + (Data[4]<<8) + (Data[5]<<16) + (Data[6]<<24);   //设备发送波特率
	BUS_Public.retry_num = 0x03;	                                            //设备数据重发次数
	BUS_Public.wait_time = 0x0064;	                                            //设备数据发送等待回复时间 - 100ms
	BUS_Public.Protocol = Data[7];	                                            //设备协议
	
	BUS_Public.DevFunInfo.Dev_Output_Ctrl = BLV_PB20_Control_State;
	BUS_Public.DevFunInfo.Dev_Output_Loop_State_Get = BLV_PB20_Read_State;   
	
	Rs485PB20.DevOffline = Rs485PB20.DevOfflineLast = DEV_IS_LINEUNINIT;   //在线状态初始化
	Rs485PB20.LoopValidNum = Data[10] + (Data[11]<<8);
	Rs485PB20.Own_Ls_DimTime = 10;
	
	memset(Rs485PB20.LightBuf,0x80,sizeof(Rs485PB20.LightBuf));
	
	
	switch(Data[7])
	{
		case	 ENUM_RS485_DEV_PRO_01: if(NULL!=RS485_DEV_PRO_FUN_01) RS485_DEV_PRO_FUN_01(&BUS_Public, &Rs485PB20, Data[10]);break;   
		case	 ENUM_RS485_DEV_PRO_02: if(NULL!=RS485_DEV_PRO_FUN_02) RS485_DEV_PRO_FUN_02(&BUS_Public, &Rs485PB20, Data[10]);break;                
		default:
			break;
	}
	
	
	switch(Data[2])
	{
		case Active_Port:   //主动端口
			BUS_Public.port = Active_Port;		//设备发送端口
			Add_ACT_Device_To_List2(&BUS_Public,(uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO));
			Act485_Info.device_num += 1;
			break;  
		case Polling_Port:   //轮询端口
			BUS_Public.port = Polling_Port;		//设备发送端口
			Add_POLL_Device_To_List2(&BUS_Public,(uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO));   //将填充后的数据添加到链表
			Poll485_Info.device_num += 1;	
			break;
		case Bus_port:    //总线端口
			BUS_Public.port = Bus_port;		//设备发送端口		
			Add_BUS_Device_To_List2(&BUS_Public,(uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO));
			BUS485_Info.device_num += 1;
			break;
		default:
			break;
	}
	
}



/*******************************************************************************
* @name  :  PB20设备初始化
* @para  : 
*   dev_info :逻辑文件指针
*   data     :数据指针
*   data_len :数据长度
* @attention :逻辑配置
*******************************************************************************/
void BLV_RS485_PB20_For_Logic_Init(LOGICFILE_DEVICE_INFO *dev_info,uint8_t *data,uint16_t data_len)
{
	Device_Public_Information_G BUS_Public;
	RS485_PB20_INFO Rs485PB20;
	
	memset(&BUS_Public,0,sizeof(Device_Public_Information_G));
	memset(&Rs485PB20,0,sizeof(RS485_PB20_INFO));
	
	BUS_Public.addr = dev_info->addr;		  //设备485地址
	BUS_Public.type = dev_info->type;		  //设备类型
	BUS_Public.baud = dev_info->baud;;		  //设备发送波特率
	BUS_Public.retry_num = dev_info->retry;			  //设备数据重发次数
	BUS_Public.wait_time = 200;//dev_info->writ_time;			  //设备数据发送等待回复时间 - 100ms
	BUS_Public.Protocol = dev_info->version;  //协议号
	
	BUS_Public.DevFunInfo.Dev_Output_Ctrl = BLV_PB20_Control_State;
	BUS_Public.DevFunInfo.Dev_Output_Loop_State_Get = BLV_PB20_Read_State; 
	
//	Rs485PB20.Dim_Global_Value = 100;
//	DevActionGlobal.DimGlobalValue = Rs485PB20.Dim_Global_Value;
	DevActionGlobal.Dim_Upper_limit = 100;
	DevActionGlobal.Dim_Lower_limit = 0;
	
	
	Rs485PB20.DevOffline = Rs485PB20.DevOfflineLast = DEV_IS_LINEUNINIT;   //在线状态初始化
	Rs485PB20.LoopValidNum = dev_info->output_num;
	Rs485PB20.Own_Ls_DimTime = 10;
	memset(Rs485PB20.LightBuf,0x80,sizeof(Rs485PB20.LightBuf));
	
	switch(BUS_Public.Protocol)
	{
		case	 ENUM_RS485_DEV_PRO_01: if(NULL!=RS485_DEV_PRO_FUN_01) RS485_DEV_PRO_FUN_01(&BUS_Public, &Rs485PB20, dev_info->output_num);break;        
		case	 ENUM_RS485_DEV_PRO_02: if(NULL!=RS485_DEV_PRO_FUN_02) RS485_DEV_PRO_FUN_02(&BUS_Public, &Rs485PB20, dev_info->output_num);break;          
		default:			
			break;
	}
	
	
	switch(dev_info->port)
	{
		case Active_Port:   //主动端口
			BUS_Public.port = Active_Port;		//设备发送端口
			Add_ACT_Device_To_List2(&BUS_Public,(uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO));
			Act485_Info.device_num += 1;
			break;  
		case Polling_Port:   //轮询端口
			BUS_Public.port = Polling_Port;		//设备发送端口
			Add_POLL_Device_To_List2(&BUS_Public,(uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO));   //将填充后的数据添加到链表
			Poll485_Info.device_num += 1;	
			break;
		case Bus_port:    //总线端口
			BUS_Public.port = Bus_port;		//设备发送端口		
			Add_BUS_Device_To_List2(&BUS_Public,(uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO));
			BUS485_Info.device_num += 1;
			break;
		default:
			break;
	}

}



/*******************************************************************************
* Function Name  : BLV_PB20_Control_State 
* Description    : PB20控制函数
* Input          : 
	devaddr	: 设备信息地址
	loop    : 回路
	start   : 状态
* Return  : 无
* attention : temp1非0才会进行保存
*******************************************************************************/
void BLV_PB20_Control_State(uint32_t CfgDevAddIn, uint16_t DevInputAddr, uint32_t devaddr,uint16_t loop,uint16_t start)
{
	Device_Public_Information_G BUS_Public;
	RS485_PB20_INFO Rs485PB20;
	
	uint8_t CtrlMode;     //控制模式
	uint8_t CtrlContect;  //控制内容
	
	uint8_t temp1 = 0x00;
	
	if(devaddr == 0x00)	return;
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),devaddr);				
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO),devaddr+Dev_Privately);
	
	if(loop >= Rs485PB20.LoopValidNum)    //有效回路
	{
		return;
	}
	
	CtrlMode = start&0x00ff;    //控制模式
	CtrlContect = start>>8;     //控制内容
	
	Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20_Control mode:%d state:%d",CtrlMode,CtrlContect);
	
	switch(CtrlMode)
	{
		case PB20_OWN_LS_STATE_OPEN:                   //控制灯光状态开 - 同时控制亮度
			Rs485PB20.LightBuf[loop] |= (0x01 << 7);
            Rs485PB20.LightBuf[loop] &= 0x80;
            Rs485PB20.LightBuf[loop] |= (CtrlContect & 0x7f);
			temp1++;
			break;
		case PB20_OWN_LS_STATE_CLOSE:                  //控制灯光状态关 - 同时控制亮度
			Rs485PB20.LightBuf[loop] &= ~(0x01 << 7);
            Rs485PB20.LightBuf[loop] &= 0x80;
            Rs485PB20.LightBuf[loop] |= (CtrlContect & 0x7f);
			temp1++;
			break;
		case PB20_OWN_LS_LIGHT_Ctrl:                   //单独设定亮度
			Rs485PB20.LightBuf[loop] &= 0x80;
			Rs485PB20.LightBuf[loop] |= (CtrlContect & 0x7f);
			temp1++;
			break;
        case PB20_OWN_LS_SWITCH_Ctrl:                   //单独设定开关状态
            if(CtrlContect == 0x01){
                Rs485PB20.LightBuf[loop] |= (0x01 << 7);
            }else{
                Rs485PB20.LightBuf[loop] &= ~(0x01 << 7);
            }
			temp1++;
			break;
		case PB20_OWN_LS_Dim_Up:                       //向上调光（百分比控制）
			if((Rs485PB20.LightBuf[loop] & 0x7f) + (CtrlContect & 0x7f) <= 100)   
			{
				Rs485PB20.LightBuf[loop] += (CtrlContect & 0x7f);
			}
			else 
			{
				Rs485PB20.LightBuf[loop] &= 0x80;
				Rs485PB20.LightBuf[loop] |= 0x64;
			}
			temp1++;
			break;
		case PB20_OWN_LS_Dim_Down:                     //向下调光（百分比控制）
			if((Rs485PB20.LightBuf[loop] & 0x7f) > (CtrlContect & 0x7f))
			{
				Rs485PB20.LightBuf[loop] -= (CtrlContect & 0x7f);
			}
			else
			{
				Rs485PB20.LightBuf[loop] &= 0x80;
			}
			temp1++;
			break;
		case PB20_OWN_LS_Dim_Up_Limit:                 //唯有亮的灯 向上调光 至上限  -  百分比控制
			if((Rs485PB20.LightBuf[loop] & 0x7f) > 0)
			{
				if((Rs485PB20.LightBuf[loop] & 0x7f) + (CtrlContect & 0x7f) <= 100)   
				{
					Rs485PB20.LightBuf[loop] += (CtrlContect & 0x7f);
				}
				else 
				{
					Rs485PB20.LightBuf[loop] &= 0x80;
					Rs485PB20.LightBuf[loop] |= 0x64;
				}
			}
			temp1++;
			break;
		case PB20_OWN_LS_Dim_Down_Limit:               //唯有亮的灯 向下调光 至下限  -  百分比控制
			if((Rs485PB20.LightBuf[loop] & 0x7f) > 0)
			{
				if((Rs485PB20.LightBuf[loop] & 0x7f) > (CtrlContect & 0x7f))
				{
					Rs485PB20.LightBuf[loop] -= (CtrlContect & 0x7f);
				}
				else
				{
					Rs485PB20.LightBuf[loop] &= 0x80;
				}
			}
			break;
		case PB20_Device_CHECK_OPEN:                   //巡检开
			Rs485PB20.Check_Flag = DEV_CHECK_OPEN;
			Rs485PB20.Check_State = CLOSEALL;
			Rs485PB20.Check_Loop = 0x00;
			Rs485PB20.Close_State = 0x00;
			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"Rs485PB20.Check_Flag:%d",Rs485PB20.Check_Flag);
			temp1++;
			break;
		case PB20_Device_CHECK_CLOSE:                  //巡检关
			Rs485PB20.Check_Flag = DEV_CHECK_CLOSE;
			Rs485PB20.Check_State = CLOSEALL;
			Rs485PB20.Check_Loop = 0x00;
			Rs485PB20.Close_State = 0x00;
			temp1++;
			break;
		case PB20_OWN_LS_Ctrl_UpperLimit:      //向上调光至上限 - 单向向上自动渐变
		case PB20_OWN_LS_Ctrl_LowerLimit:      //向下调光至下限 - 单向向下自动渐变
		case PB20_OWN_LS_Cycle_Dim_Up:         //向上循环 - 双向自动渐变
		case PB20_OWN_LS_Cycle_Dim_Down:       //向下循环 - 双向自动渐变
		case PB20_OWN_LS_Cycle_Stop:           //停止调光
			Rs485PB20.CtrlMode[loop] = CtrlMode;
			Rs485PB20.Own_Ls_Cycle_Time[loop] = CtrlContect;
			
			if(Rs485PB20.CtrlMode_Last[loop] != Rs485PB20.CtrlMode[loop])
			{
				Rs485PB20.CtrlMode_Last[loop] = Rs485PB20.CtrlMode[loop];
				Rs485PB20.Own_Ls_Cycle_Flag |= (0x01<<loop);
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20_CycleCtrl,Ctrl Flag:%d",Rs485PB20.Own_Ls_Cycle_Flag);
			}
			temp1++;
			break;
		case PB20_OWN_LS_Cycle_Dim_Up_Limit:           //唯有亮的灯 向上循环 至上限
		case PB20_OWN_LS_Cycle_Dim_Down_Limit:         //唯有亮的灯 向下循环 至下限
			if((Rs485PB20.LightBuf[loop] & 0x7f) > 0)
			{
				Rs485PB20.CtrlMode[loop] = CtrlMode;
				Rs485PB20.Own_Ls_Cycle_Time[loop] = CtrlContect;
				
				if(Rs485PB20.CtrlMode_Last[loop] != Rs485PB20.CtrlMode[loop])
				{
					Rs485PB20.CtrlMode_Last[loop] = Rs485PB20.CtrlMode[loop];
					Rs485PB20.Own_Ls_Cycle_Flag |= (0x01<<loop);
					Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20_CycleCtrl,Ctrl Flag:%d",Rs485PB20.Own_Ls_Cycle_Flag);
				}
				temp1++;
			}
			break;
		case PB20_OWN_LS_DimTime_Set:          //渐变时间设置
			Rs485PB20.Own_Ls_DimTime = CtrlContect;
			temp1++;
			break;
		case PB20_Global_Light_Set:           //全局亮度设置
			Rs485PB20.Global_Light = CtrlContect;
			Rs485PB20.GLight_Flag |= (0x01<<7);
			DevActionGlobal.DimGlobalValue = Rs485PB20.Global_Light;      
			temp1++;
			break;
		case PB20_GlobalLight_UpperLimit:     //全局可调上限设置
//			Rs485PB20.GLight_UpperLimit = CtrlContect;
//			Rs485PB20.GLight_Flag |= (0x01<<6);
			DevActionGlobal.Dim_Upper_limit = CtrlContect;
			temp1++;
			break;
		case PB20_GlobalLight_LowerLimit:     //全局可调下限设置
//			Rs485PB20.GLight_LowerLimit = CtrlContect;
//			Rs485PB20.GLight_Flag |= (0x01<<5);
			DevActionGlobal.Dim_Lower_limit = CtrlContect;
		    temp1++;
			break;
		default:
			break;
	}
	
	
	if(temp1 != 0x00)
	{
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&Rs485PB20, sizeof(RS485_PB20_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),devaddr);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO),devaddr+Dev_Privately);
	}
}


/*******************************************************************************
* Function Name  : BLV_PB20_Group_Control_State 
* Description    : PB20群控函数
* Input          : 
	devaddr	: 设备信息地址
	loop    : 回路
	start   : 状态
* Return  : 无
* attention : temp1非0才会进行保存
*******************************************************************************/
void BLV_PB20_Group_Control_State(uint32_t CfgDevAddIn, uint16_t DevInputAddr,uint32_t devaddr, uint32_t CtrlFlag, uint8_t CtrlNum,uint16_t *start)
{
	Device_Public_Information_G BUS_Public;
	RS485_PB20_INFO Rs485PB20;
	
	uint8_t CtrlMode;     //控制模式
	uint8_t CtrlContect;  //控制内容
	
	uint8_t temp1 = 0x00;
	
	uint8_t i = 0x00;
	
	if(devaddr == 0x00)	return;
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),devaddr);				
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO),devaddr+Dev_Privately);
	
	if(CtrlNum >= Rs485PB20.LoopValidNum)    //有效回路
	{
		CtrlNum = Rs485PB20.LoopValidNum;
	}
	
	for(i = 0; i < CtrlNum; i++)
	{
		if(CtrlFlag&(0x0001<<i))   //非0为控制
		{
			CtrlMode = start[i] & 0x00ff;    //控制模式
			CtrlContect = start[i] >> 8;     //控制内容
	
			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20_Control Loop%d mode:%d state:%d",i,CtrlMode,CtrlContect);
	
			switch(CtrlMode)
			{
				case PB20_OWN_LS_STATE_OPEN:                   //控制灯光状态开 - 同时控制亮度
					Rs485PB20.LightBuf[i] |= (0x01 << 7);
					Rs485PB20.LightBuf[i] &= 0x80;
					Rs485PB20.LightBuf[i] |= (CtrlContect & 0x7f);
					temp1++;
					break;
				case PB20_OWN_LS_STATE_CLOSE:                  //控制灯光状态关 - 同时控制亮度
					Rs485PB20.LightBuf[i] &= ~(0x01 << 7);
					Rs485PB20.LightBuf[i] &= 0x80;
					Rs485PB20.LightBuf[i] |= (CtrlContect & 0x7f);
					temp1++;
					break;
				case PB20_OWN_LS_LIGHT_Ctrl:                   //单独设定亮度
					Rs485PB20.LightBuf[i] &= 0x80;
					Rs485PB20.LightBuf[i] |= (CtrlContect & 0x7f);
					temp1++;
					break;
				case PB20_OWN_LS_SWITCH_Ctrl:                   //单独设定开关状态
					if(CtrlContect == 0x01){
						Rs485PB20.LightBuf[i] |= (0x01 << 7);
					}else{
						Rs485PB20.LightBuf[i] &= ~(0x01 << 7);
					}
					temp1++;
					break;
				case PB20_OWN_LS_Dim_Up:                       //向上调光（百分比控制）
					if((Rs485PB20.LightBuf[i] & 0x7f) + (CtrlContect & 0x7f) <= 100)   
					{
						Rs485PB20.LightBuf[i] += (CtrlContect & 0x7f);
					}
					else 
					{
						Rs485PB20.LightBuf[i] &= 0x80;
						Rs485PB20.LightBuf[i] |= 0x64;
					}
					temp1++;
					break;
				case PB20_OWN_LS_Dim_Down:                     //向下调光（百分比控制）
					if((Rs485PB20.LightBuf[i] & 0x7f) > (CtrlContect & 0x7f))
					{
						Rs485PB20.LightBuf[i] -= (CtrlContect & 0x7f);
					}
					else
					{
						Rs485PB20.LightBuf[i] &= 0x80;
					}
					temp1++;
					break;
				case PB20_OWN_LS_Dim_Up_Limit:                 //唯有亮的灯 向上调光 至上限  -  百分比控制
					if((Rs485PB20.LightBuf[i] & 0x7f) > 0)
					{
						if((Rs485PB20.LightBuf[i] & 0x7f) + (CtrlContect & 0x7f) <= 100)   
						{
							Rs485PB20.LightBuf[i] += (CtrlContect & 0x7f);
						}
						else 
						{
							Rs485PB20.LightBuf[i] &= 0x80;
							Rs485PB20.LightBuf[i] |= 0x64;
						}
					}
					temp1++;
					break;
				case PB20_OWN_LS_Dim_Down_Limit:               //唯有亮的灯 向下调光 至下限  -  百分比控制
					if((Rs485PB20.LightBuf[i] & 0x7f) > 0)
					{
						if((Rs485PB20.LightBuf[i] & 0x7f) > (CtrlContect & 0x7f))
						{
							Rs485PB20.LightBuf[i] -= (CtrlContect & 0x7f);
						}
						else
						{
							Rs485PB20.LightBuf[i] &= 0x80;
						}
					}
					break;
				case PB20_Device_CHECK_OPEN:                   //巡检开
					Rs485PB20.Check_Flag = DEV_CHECK_OPEN;
					Rs485PB20.Check_State = CLOSEALL;
					Rs485PB20.Check_Loop = 0x00;
					Rs485PB20.Close_State = 0x00;
					Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"Rs485PB20.Check_Flag:%d",Rs485PB20.Check_Flag);
					temp1++;
					break;
				case PB20_Device_CHECK_CLOSE:                  //巡检关
					Rs485PB20.Check_Flag = DEV_CHECK_CLOSE;
					Rs485PB20.Check_State = CLOSEALL;
					Rs485PB20.Check_Loop = 0x00;
					Rs485PB20.Close_State = 0x00;
					temp1++;
					break;
				case PB20_OWN_LS_Ctrl_UpperLimit:      //向上调光至上限 - 单向向上自动渐变
				case PB20_OWN_LS_Ctrl_LowerLimit:      //向下调光至下限 - 单向向下自动渐变
				case PB20_OWN_LS_Cycle_Dim_Up:         //向上循环 - 双向自动渐变
				case PB20_OWN_LS_Cycle_Dim_Down:       //向下循环 - 双向自动渐变
				case PB20_OWN_LS_Cycle_Stop:           //停止调光
					Rs485PB20.CtrlMode[i] = CtrlMode;
					Rs485PB20.Own_Ls_Cycle_Time[i] = CtrlContect;
					
					if(Rs485PB20.CtrlMode_Last[i] != Rs485PB20.CtrlMode[i])
					{
						Rs485PB20.CtrlMode_Last[i] = Rs485PB20.CtrlMode[i];
						Rs485PB20.Own_Ls_Cycle_Flag |= (0x01<<i);
						Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20_CycleCtrl,Ctrl Flag:%d",Rs485PB20.Own_Ls_Cycle_Flag);
					}
					temp1++;
					break;
				case PB20_OWN_LS_Cycle_Dim_Up_Limit:           //唯有亮的灯 向上循环 至上限
				case PB20_OWN_LS_Cycle_Dim_Down_Limit:         //唯有亮的灯 向下循环 至下限
					if((Rs485PB20.LightBuf[i] & 0x7f) > 0)
					{
						Rs485PB20.CtrlMode[i] = CtrlMode;
						Rs485PB20.Own_Ls_Cycle_Time[i] = CtrlContect;
						
						if(Rs485PB20.CtrlMode_Last[i] != Rs485PB20.CtrlMode[i])
						{
							Rs485PB20.CtrlMode_Last[i] = Rs485PB20.CtrlMode[i];
							Rs485PB20.Own_Ls_Cycle_Flag |= (0x01<<i);
							Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20_CycleCtrl,Ctrl Flag:%d",Rs485PB20.Own_Ls_Cycle_Flag);
						}
						temp1++;
					}
					break;
				case PB20_OWN_LS_DimTime_Set:          //渐变时间设置
					Rs485PB20.Own_Ls_DimTime = CtrlContect;
					temp1++;
					break;
				case PB20_Global_Light_Set:           //全局亮度设置
					Rs485PB20.Global_Light = CtrlContect;
					Rs485PB20.GLight_Flag |= (0x01<<7);
					DevActionGlobal.DimGlobalValue = Rs485PB20.Global_Light;      
					temp1++;
					break;
				case PB20_GlobalLight_UpperLimit:     //全局可调上限设置
					Rs485PB20.GLight_UpperLimit = CtrlContect;
					Rs485PB20.GLight_Flag |= (0x01<<6);
					DevActionGlobal.Dim_Upper_limit = Rs485PB20.GLight_UpperLimit;
					temp1++;
					break;
				case PB20_GlobalLight_LowerLimit:     //全局可调下限设置
					Rs485PB20.GLight_LowerLimit = CtrlContect;
					Rs485PB20.GLight_Flag |= (0x01<<5);
					DevActionGlobal.Dim_Lower_limit = Rs485PB20.GLight_LowerLimit;
					temp1++;
					break;
				default:
					break;
			}
		}
	}
	
	
	if(temp1 != 0x00)
	{
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&Rs485PB20, sizeof(RS485_PB20_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),devaddr);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO),devaddr+Dev_Privately);
	}
}


/*******************************************************************************
* Function Name  : BLV_PB20_Read_State 
* Description    : PB20状态读取函数
* Input          : 
	devaddr	: 设备信息地址
	loop    :回路
* Return  : 无
*******************************************************************************/
uint16_t BLV_PB20_Read_State(uint32_t devaddr,uint16_t loop)
{
	if(devaddr == 0x00)
		return 0x00;
	
	RS485_PB20_INFO Rs485PB20;
	
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO),devaddr+Dev_Privately);	
	
	if(loop >= PB20_OWN_LS_BUFF_SIZE)
	{
		return 0x00;    //超出范围 直接返回0
	}
	
	
	return Rs485PB20.LightBuf[loop];
}



/*******************************************************************************
* Function Name  : BLV_RS485_PB20_Init 
* Description    : 添加设备到链表
* Input          : 
	type	     : 添加的设备类型
	addr	     : 添加的设备地址
	polling_cf	 :设备的轮询数据发送回调函数
    processing_cf:设备的数据处理回调函数
* Return         : None
*******************************************************************************/
void BLV_RS485_PB20_Init(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO *Rs485PB20, uint16_t LoopNum)
{
	BUS_Public->polling_cf = (uint32_t)&BLV_PB20_CycleCtrl;
	BUS_Public->processing_cf = (uint32_t)&BLV_PB20_Rccv_Check;
}

/*******************************************************************************
* Function Name  : BLV_PB20_OwnLs_OnOff_Ctrl_Send 
* Description    : PB20自带灯带开关控制发送函数
* Input          : 
	BUS_Public	 : 公有属性
	Rs485PB20	 : 私有属性
* Return         : None
*******************************************************************************/
void BLV_PB20_OwnLs_OnOff_Ctrl_Send(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20)
{
	uint8_t i;
	uint8_t lens = 0x0D;                                   
	uint8_t SendBuf[lens];
	memset(SendBuf,0,sizeof(SendBuf));
		
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = Dev_Rs485_PB20;   //设备类型
	
	SendBuf[3] = BUS_Public->addr;
	SendBuf[4] = lens;    //长度
	SendBuf[6] = PB20_CMD_OLS_ONOFF;    //CMD
	SendBuf[7] = Rs485PB20->Own_Ls_OnOff_Flag; 
	SendBuf[8] = 0xF0;    //掉电不保存

	for(i = 0; i < PB20_OWN_LS_BUFF_SIZE; i++)
	{
		SendBuf[i+9] = ((Rs485PB20->LightBuf[i] >> 7) & 0x01);
	}
	
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);

	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Strip OnOff Send Buff:",SendBuf,lens);
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);

	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);
}

/*******************************************************************************
* Function Name  : BLV_PB20_OwnLs_Light_Ctrl_Send 
* Description    : PB20自带灯带亮度控制发送函数
* Input          : 
	BUS_Public	 : 公有属性
	Rs485PB20	 : 私有属性
* Return         : None
*******************************************************************************/
void BLV_PB20_OwnLs_Light_Ctrl_Send(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20)
{
	uint8_t i;
	uint8_t lens = 0x11;                                   
	uint8_t SendBuf[lens];
	memset(SendBuf,0,sizeof(SendBuf));
		
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = Dev_Rs485_PB20;   //设备类型
	
	SendBuf[3] = BUS_Public->addr;
	SendBuf[4] = lens;    //长度
	SendBuf[6] = PB20_CMD_OLS_LCTRL;    //CMD
	SendBuf[7] = Rs485PB20->Own_Ls_Light_Flag; 
	SendBuf[8] = 0xF0;    //掉电不保存

	for(i = 0; i < PB20_OWN_LS_BUFF_SIZE; i++)
	{
		SendBuf[i+9] = (Rs485PB20->LightBuf[i] & 0x7f);
	}
	
	SendBuf[13] = Rs485PB20->Own_Ls_DimTime;      //调光渐变时间;
	SendBuf[14] = Rs485PB20->Own_Ls_DimTime;      //调光渐变时间;
	SendBuf[15] = Rs485PB20->Own_Ls_DimTime;      //调光渐变时间;
	SendBuf[16] = Rs485PB20->Own_Ls_DimTime;      //调光渐变时间;

	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);

	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Strip Light Send Buff:",SendBuf,lens);
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);

	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);
}





/*******************************************************************************
* Function Name  : BLV_PB20_OwnLs_Cycle_Ctrl_Send 
* Description    : PB20自带灯带循环控制发送函数
* Input          : 
	BUS_Public	 : 公有属性
	Rs485PB20	 : 私有属性
* Return         : None
*******************************************************************************/
void BLV_PB20_OwnLs_Cycle_Ctrl_Send(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20)
{
	uint8_t lens = 0x14;                                   
	uint8_t SendBuf[lens];
	memset(SendBuf,0,sizeof(SendBuf));
	
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = Dev_Rs485_PB20;   //设备类型
	
	SendBuf[3] = BUS_Public->addr;
	SendBuf[4] = lens;    //长度
	SendBuf[6] = PB20_CMD_OLS_CCTRL;    //CMD
	SendBuf[7] = Rs485PB20->Own_Ls_Cycle_Flag;
	
	for(uint8_t i = 0 ; i < 4; i++)
	{
		switch(Rs485PB20->CtrlMode[i])
		{
			case PB20_OWN_LS_Ctrl_UpperLimit:         //向上调光至上限
			case PB20_OWN_LS_Cycle_Dim_Up_Limit:      //唯有亮的灯 向上循环 至上限
				SendBuf[8+3*i] = 0x00;
				SendBuf[9+3*i] = 0x01;
				SendBuf[10+3*i] = Rs485PB20->Own_Ls_Cycle_Time[i];
				break;
			case PB20_OWN_LS_Ctrl_LowerLimit:        //向下调光至下限
			case PB20_OWN_LS_Cycle_Dim_Down_Limit:   //唯有亮的灯 向下循环 至下限
				SendBuf[8+3*i] = 0x00;
				SendBuf[9+3*i] = 0x00;
				SendBuf[10+3*i] = Rs485PB20->Own_Ls_Cycle_Time[i];
				break;
			case PB20_OWN_LS_Cycle_Dim_Up:        //向上循环
			case PB20_OWN_LS_Cycle_Dim_Down:      //向下循环
				SendBuf[8+3*i] = 0x01;
				SendBuf[9+3*i] = 0x02;
				SendBuf[10+3*i] = Rs485PB20->Own_Ls_Cycle_Time[i];
				break;
			case PB20_OWN_LS_Cycle_Stop:          //停止调光
				SendBuf[8+3*i] = 0x02;
				SendBuf[9+3*i] = 0x00;
				SendBuf[10+3*i] = 0x00;
			default:
				break;
		}
	}
	
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);

//	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Strip Cycyle Send Buff:",SendBuf,lens);
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);

	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);
	
}


/*******************************************************************************
* Function Name  : BLV_PB20_GLight_Ctrl_Send 
* Description    : PB20全局设置发送函数
* Input          : 
	BUS_Public	 : 公有属性
	Rs485PB20	 : 私有属性
* Return         : None
*******************************************************************************/
void BLV_PB20_GLight_Ctrl_Send(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20)
{
	uint8_t lens = 0x0D;                                   
	uint8_t SendBuf[lens];
	memset(SendBuf,0,sizeof(SendBuf));
	
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = Dev_Rs485_PB20;   //设备类型
	
	SendBuf[3] = BUS_Public->addr;
	SendBuf[4] = lens;    //长度
	SendBuf[6] = PB20_CMD_GL_CTRL;    //CMD
	SendBuf[7] = PB20_RETRY_TIME;
	SendBuf[8] = Rs485PB20->GLight_Flag;
	SendBuf[9] = 0xF0;
	SendBuf[10] = Rs485PB20->Global_Light;
	SendBuf[11] = Rs485PB20->GLight_UpperLimit;
	SendBuf[12] = Rs485PB20->GLight_LowerLimit;
	
	
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);

	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Glight Set Send Buff:",SendBuf,lens);
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);

	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);
	
}



/*******************************************************************************
* Function Name  : BLV_PB20_Inquire_Send 
* Description    : PB20状态查询
* Input          : 
	BUS_Public	 : 公有属性
	Rs485PB20	 : 私有属性
* Return         : None
*******************************************************************************/
void BLV_PB20_Inquire_Send(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20)
{
	uint8_t lens = 0x07;
	uint8_t SendBuf[lens];
	memset(SendBuf,0,sizeof(SendBuf));
	
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	

	SendBuf[2] = Dev_Rs485_PB20;   //设备类型
	
	SendBuf[3] = BUS_Public->addr;
	SendBuf[4] = lens;    //长度
	SendBuf[6] = PB20_CMD_INQUIRE;    //CMD
	
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);
	
//	Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"DevSendCnt:%d",Rs485PB20->DevSendCnt);
	
	if(Rs485PB20->Check_Flag == 0x01 || Rs485PB20->DevSendCnt != 0x00)
	{
		Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Inquire Send Buff:",SendBuf,lens);
	}
	

	/*日志记录*/
//	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);
	
}


/*******************************************************************************
* Function Name  : BLV_PB20_LED_Ctrl_Send 
* Description    : PB20LED灯光控制发送
* Input          : 
	BUS_Public	 : 公有属性
	Rs485PB20	 : 私有属性
* Return         : None
*******************************************************************************/
void BLV_PB20_LED_Ctrl_Send(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20,uint8_t ld_addr)
{
	uint8_t lens = 10;
	uint8_t SendBuf[50];
//	uint8_t devnum = 0;
	uint8_t loopnum = 0;
	memset(SendBuf,0,sizeof(SendBuf));
	
	uint32_t tempaddr = Find_AllDevice_List_Information(Dev_Rs485_PB20_LD,ld_addr);
	RS485_PB20_LED_INFO Rs485PB20LED;
	
	if(tempaddr == NULL) { return;}
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20LED,sizeof(RS485_PB20_LED_INFO),tempaddr+Dev_Privately);
	
	Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 LED ADDR:%08X Light_Flag:%02X",tempaddr,Rs485PB20LED.Light_Flag);
	
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = Dev_Rs485_PB20;   //设备类型
	SendBuf[3] = BUS_Public->addr;
	SendBuf[7] = PB20_RETRY_TIME;    //重发次数
	
	
	if(Rs485PB20LED.Light_Flag!=0x00)
	{
		SendBuf[6] = PB20_CMD_LD_LCTRL;    //CMD
		for(uint8_t i = 0; i < Rs485PB20LED.LoopValidNum; i++)
		{
			if((Rs485PB20LED.Light_Flag>>i)&0x01)
			{
				SendBuf[10+3*loopnum] = ld_addr*4 + i;
				SendBuf[11+3*loopnum] = Rs485PB20LED.LED_DimTime;
				SendBuf[12+3*loopnum] = Rs485PB20LED.LightBuf[i];
				loopnum++;
				lens += 3;
			}
		}
		SendBuf[8] = (lens-10)/3;    //回路数量
		SendBuf[9] = 0xF0;    //掉电不保存
	}
	else if(Rs485PB20LED.Cycle_Flag!=0x00)
	{
		SendBuf[6] = PB20_CMD_LD_CCTRL;    //CMD
		SendBuf[8] = 4;       //回路数量
		for(uint8_t i = 0; i < Rs485PB20LED.LoopValidNum; i++)
		{
			switch(Rs485PB20LED.CtrlMode[i])
			{
				case 0x05:             //向上调光至上限
					SendBuf[ 9+loopnum*4] = ld_addr*4 + i;
					SendBuf[10+loopnum*4] = 0x00;
					SendBuf[11+loopnum*4] = 0x01;
					SendBuf[12+loopnum*4] = Rs485PB20LED.CtrlTime[i];
					break;
				case 0x06:             //向下调光至下限
					SendBuf[ 9+loopnum*4] = ld_addr*4 + i;
					SendBuf[10+loopnum*4] = 0x00;
					SendBuf[11+loopnum*4] = 0x00;
					SendBuf[12+loopnum*4] = Rs485PB20LED.CtrlTime[i];
					break;
				case 0x07:             //循环调光
					SendBuf[ 9+loopnum*4] = ld_addr*4 + i;
					SendBuf[10+loopnum*4] = 0x01;
					SendBuf[11+loopnum*4] = 0x02;
					SendBuf[12+loopnum*4] = Rs485PB20LED.CtrlTime[i];
					break;
				case 0x08:             //停止调光
					SendBuf[ 9+loopnum*4] = ld_addr*4 + i;
					SendBuf[10+loopnum*4] = 0x02;
					SendBuf[11+loopnum*4] = 0x00;
					SendBuf[12+loopnum*4] = 0x00;
				default:
					break; 
			}
		
			loopnum++;
			lens += 4;
		}
	}
	
	
	
	SendBuf[4] = lens;    //长度
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);
	
//	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 LED Send Buff:",SendBuf,lens);

	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);
	
}


void BLV_PB20_LED_Loop_Ctrl(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20,uint8_t loop)
{
	uint8_t lens = 10;
	uint8_t SendBuf[22];
	memset(SendBuf,0,sizeof(SendBuf));
	
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = 0x30;   //设备类型
	
	SendBuf[3] = BUS_Public->addr;
	
	SendBuf[6] = 0x27;    //CMD
	SendBuf[7] = 0x00;    //重发次数
	//SendBuf[8] = PB20_LED_BUFF_SIZE;    //回路数量
	SendBuf[9] = 0xF0;    //掉电不保存
	
//	for(uint8_t i = 0; i < PB20_LED_BUFF_SIZE; i++)
//	{
//		SendBuf[10+3*i] = Rs485PB20->LEDNowAddr*4 + i;    
//		SendBuf[11+3*i] = 0x00;
//		if((loop-1)==i)
//		{
//			SendBuf[12+3*i] = 0x64;
//		}
//		else
//		{
//			SendBuf[12+3*i] = 0x00;
//		}
//		
//		lens += 3;
//		   
//	}
	
	SendBuf[4] = lens;    //长度
	
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);
	
	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 LED Loop Ctrl Send Buff:",SendBuf,lens);

	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);
	
}

/*******************************************************************************
* Function Name  : BLV_PB20_Strip_Ctrl_Send 
* Description    : PB20_Strip控制发送
* Input          : 
	BUS_Public	 : 公有属性
	Rs485PB20	 : 私有属性
* Return         : None
*******************************************************************************/
void BLV_PB20_Strip_Ctrl_Send(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20,uint8_t ld_addr)
{
	uint8_t lens = 10;
	uint8_t SendBuf[50];
	uint8_t loopnum = 0;
	memset(SendBuf,0,sizeof(SendBuf));
	
	uint32_t tempaddr = Find_AllDevice_List_Information(Dev_Rs485_PB20_LS,ld_addr);
	
	if(tempaddr == NULL) { return;}
	
	RS485_PB20_Strip_INFO Rs485PB20Strip;
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20Strip,sizeof(RS485_PB20_Strip_INFO),tempaddr+Dev_Privately);
	
	Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 %d Strip ADDR:%08X Light_Flag:%02X",ld_addr,tempaddr,Rs485PB20->Strip_LLCtrl_Flag[ld_addr]);
	
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = Dev_Rs485_PB20;   //设备类型
	SendBuf[3] = BUS_Public->addr;
	SendBuf[7] = PB20_RETRY_TIME;    //重发次数
	
	
	if(Rs485PB20->Strip_LLCtrl_Flag[ld_addr] != 0x00)
	{   //设置灯带亮度
		SendBuf[6] = PB20_CMD_LS_LCTRL;    //CMD
		for(uint8_t i = 0; i < Rs485PB20Strip.LoopValidNum; i++)
		{
			if((Rs485PB20->Strip_LLCtrl_Flag[ld_addr] >> i)&0x01)
			{
				SendBuf[10+3*loopnum] = ld_addr*4 + i;
				SendBuf[11+3*loopnum] = Rs485PB20Strip.Strip_DimTime;
				SendBuf[12+3*loopnum] = (Rs485PB20Strip.LightBuf[i] & 0x7F);
				loopnum++;
				lens += 3;
			}
		}
		SendBuf[8] = (lens-10)/3;    //回路数量
		SendBuf[9] = 0xF0;    //掉电不保存
	}else if(Rs485PB20->Strip_LSCtrl_Flag[ld_addr] != 0x00){
        //设置灯带 - 开关状态
        SendBuf[6] = PB20_CMD_LS_SCTRL;    //CMD
		for(uint8_t i = 0; i < Rs485PB20Strip.LoopValidNum; i++)
		{
			if((Rs485PB20->Strip_LSCtrl_Flag[ld_addr] >> i)&0x01)
			{
				SendBuf[10+2*loopnum] = ld_addr*4 + i;
                if((Rs485PB20Strip.LightBuf[i] & 0x80) != 0x00){
                    SendBuf[11+2*loopnum] = 0x01;
                }else{
                    SendBuf[11+2*loopnum] = 0x00;
                }
				loopnum++;
				lens += 2;
			}
		}
		SendBuf[8] = (lens-10)/2;    //回路数量
		SendBuf[9] = 0xF0;    //掉电不保存
    }
	else if(Rs485PB20->Strip_AGCtrl_Flag[ld_addr]!=0x00)
	{
		SendBuf[6] = PB20_CMD_LS_CCTRL;            //CMD
		SendBuf[8] = Rs485PB20Strip.LoopValidNum;       //回路数量
		lens = 9;
		for(uint8_t i = 0; i < Rs485PB20Strip.LoopValidNum; i++)
		{
			switch(Rs485PB20Strip.CtrlMode[i])
			{
				case PB20_Strip_Ctrl_UpperLimit:             //向上调光至上限
				case PB20_Strip_Cycle_Dim_Up_Limit:          //唯有亮的灯 向上循环 至上限
					SendBuf[ 9+loopnum*4] = ld_addr*4 + i;
					SendBuf[10+loopnum*4] = 0x00;
					SendBuf[11+loopnum*4] = 0x01;
					SendBuf[12+loopnum*4] = Rs485PB20Strip.CtrlTime[i];
					break;
				case PB20_Strip_Ctrl_LowerLimit:             //向下调光至下限
				case PB20_Strip_Cycle_Dim_Down_Limit:        //唯有亮的灯 向下循环 至下限
					SendBuf[ 9+loopnum*4] = ld_addr*4 + i;
					SendBuf[10+loopnum*4] = 0x00;
					SendBuf[11+loopnum*4] = 0x00;
					SendBuf[12+loopnum*4] = Rs485PB20Strip.CtrlTime[i];
					break;
				case PB20_Strip_Cycle_Dim_Up:                //向下循环
				case PB20_Strip_Cycle_Dim_Down:              //向上循环
					SendBuf[ 9+loopnum*4] = ld_addr*4 + i;
					SendBuf[10+loopnum*4] = 0x01;
					SendBuf[11+loopnum*4] = 0x02;
					SendBuf[12+loopnum*4] = Rs485PB20Strip.CtrlTime[i];
					break;
				case PB20_Strip_Cycle_Stop:                 //停止调光
					SendBuf[ 9+loopnum*4] = ld_addr*4 + i;
					SendBuf[10+loopnum*4] = 0x02;
					SendBuf[11+loopnum*4] = 0x00;
					SendBuf[12+loopnum*4] = 0x00;
				default:
					break; 
			}
		
			loopnum++;
			lens += 4;
		}
	}
	
	
	
	SendBuf[4] = lens;    //长度
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);
	
	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Strip Send Buff:",SendBuf,lens);

	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);

}


/*******************************************************************************
* Function Name  : BLV_PB20_Strip_Light_Loop_Ctrl_Send 
* Description    : PB20_Strip控制发送
* Input          : 
	BUS_Public	 : 公有属性
	Rs485PB20	 : 私有属性
* Return         : None
*******************************************************************************/
void BLV_PB20_Strip_Light_Loop_Ctrl_Send(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20)
{
	uint8_t lens = 10;
	uint8_t SendBuf[106];
	uint8_t loopnum = 0;
	memset(SendBuf,0,sizeof(SendBuf));
	
	uint32_t tempaddr = 0;
	RS485_PB20_Strip_INFO Rs485PB20Strip;
	
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = Dev_Rs485_PB20;   //设备类型
	SendBuf[3] = BUS_Public->addr;
	SendBuf[6] = PB20_CMD_LS_LCTRL;    //CMD
	SendBuf[7] = PB20_RETRY_TIME;    //重发次数
	
	for(uint8_t j = 0; j < Rs485PB20->StripDevNum; j++)
	{
		tempaddr = Find_AllDevice_List_Information(Dev_Rs485_PB20_LS,Rs485PB20->Strip_List[j].Addr);
		if(tempaddr != NULL)
		{
			SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20Strip,sizeof(RS485_PB20_Strip_INFO),tempaddr+Dev_Privately);
			
			if(Rs485PB20->Strip_LLCtrl_Flag[Rs485PB20->Strip_List[j].Addr] != 0x00)
			{   //设置灯带亮度
				for(uint8_t i = 0; i < Rs485PB20Strip.LoopValidNum; i++)
				{
					if((Rs485PB20->Strip_LLCtrl_Flag[Rs485PB20->Strip_List[j].Addr] >> i) & 0x01)
					{
						SendBuf[10+3*loopnum] = Rs485PB20->Strip_List[j].Addr*4 + i;
						SendBuf[11+3*loopnum] = Rs485PB20Strip.Strip_DimTime;
						SendBuf[12+3*loopnum] = (Rs485PB20Strip.LightBuf[i] & 0x7F);
						loopnum++;
						lens += 3;
					}
				}
				SendBuf[8] = (lens-10)/3;    //回路数量
				SendBuf[9] = 0xF0;    //掉电不保存
			}
		}
	}
	
	SendBuf[4] = lens;    //长度
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);
	
	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Strip Light_Loop Send Buff:",SendBuf,lens);

	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);

}

/*******************************************************************************
* Function Name  : BLV_PB20_Strip_Switch_Ctrl_Send 
* Description    : PB20_Strip开关状态发送
* Input          : 
	BUS_Public	 : 公有属性
	Rs485PB20	 : 私有属性
* Return         : None
*******************************************************************************/
void BLV_PB20_Strip_Switch_Loop_Ctrl_Send(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20)
{
	uint8_t lens = 10;
	uint8_t SendBuf[106];
	uint8_t loopnum = 0;
	memset(SendBuf,0,sizeof(SendBuf));
	
	uint32_t tempaddr = 0;
	RS485_PB20_Strip_INFO Rs485PB20Strip;
	
	
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = Dev_Rs485_PB20;      //设备类型
	SendBuf[3] = BUS_Public->addr;
	SendBuf[6] = PB20_CMD_LS_SCTRL;   //CMD
	SendBuf[7] = PB20_RETRY_TIME;     //重发次数
	
	
	for(uint8_t j = 0; j < Rs485PB20->StripDevNum; j++)
	{
		tempaddr = Find_AllDevice_List_Information(Dev_Rs485_PB20_LS,Rs485PB20->Strip_List[j].Addr);
		if(tempaddr != NULL)
		{
			SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20Strip,sizeof(RS485_PB20_Strip_INFO),tempaddr+Dev_Privately);
			
			if(Rs485PB20->Strip_LSCtrl_Flag[Rs485PB20->Strip_List[j].Addr] != 0x00)
			{
				//设置灯带 - 开关状态
				for(uint8_t i = 0; i < Rs485PB20Strip.LoopValidNum; i++)
				{
					if((Rs485PB20->Strip_LSCtrl_Flag[Rs485PB20->Strip_List[j].Addr] >> i)&0x01)
					{
						SendBuf[10+2*loopnum] = Rs485PB20->Strip_List[j].Addr*4 + i;
						if((Rs485PB20Strip.LightBuf[i] & 0x80) != 0x00){
							SendBuf[11+2*loopnum] = 0x01;
						}else{
							SendBuf[11+2*loopnum] = 0x00;
						}
						loopnum++;
						lens += 2;
					}
				}
				SendBuf[8] = (lens-10)/2;    //回路数量
				SendBuf[9] = 0xF0;    //掉电不保存
			}
		}
	}
	
	SendBuf[4] = lens;    //长度
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);
	
	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Strip Switch Send Buff:",SendBuf,lens);

	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);

}



/*******************************************************************************
* Function Name  : BLV_PB20_Strip_LLCtrl_Send 
* Description    : PB20_Strip亮度组控发送
* Input          : 
	BUS_Public	 : 公有属性
	Rs485PB20	 : 私有属性
* Return         : None
*******************************************************************************/
void BLV_PB20_Strip_LLCtrl_Send(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20)
{
	uint8_t lens = 83;
	uint8_t SendBuf[lens];
	memset(SendBuf,0,sizeof(SendBuf));
	
	uint32_t tempaddr = 0;
	RS485_PB20_Strip_INFO Rs485PB20Strip;
	
	
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = Dev_Rs485_PB20;   //设备类型
	SendBuf[3] = BUS_Public->addr;
	SendBuf[4] = lens;    //长度
	SendBuf[6] = PB20_CMD_LS_LLCTRL;    //CMD
	SendBuf[7] = PB20_RETRY_TIME;    //重发次数
	SendBuf[8] = 0;
	
	SendBuf[9] = (Rs485PB20->Strip_A00_07_LLCtrl & 0xff);
	SendBuf[10] = ((Rs485PB20->Strip_A00_07_LLCtrl >> 8) & 0xff);
	SendBuf[11] = ((Rs485PB20->Strip_A00_07_LLCtrl >> 16) & 0xff);
	SendBuf[12] = ((Rs485PB20->Strip_A00_07_LLCtrl >> 24) & 0xff);
	
	SendBuf[13] = (Rs485PB20->Strip_A08_15_LLCtrl & 0xff);
	SendBuf[14] = ((Rs485PB20->Strip_A08_15_LLCtrl >> 8) & 0xff);
	SendBuf[15] = ((Rs485PB20->Strip_A08_15_LLCtrl >> 16) & 0xff);
	SendBuf[16] = ((Rs485PB20->Strip_A08_15_LLCtrl >> 24) & 0xff);
	
	SendBuf[17] = 0xF0;
	
	for(uint8_t i = 0; i < Rs485PB20->StripDevNum; i++)
	{
		tempaddr = Find_AllDevice_List_Information(Dev_Rs485_PB20_LS,Rs485PB20->Strip_List[i].Addr);
		if(tempaddr != NULL)
		{
			SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20Strip,sizeof(RS485_PB20_Strip_INFO),tempaddr+Dev_Privately);
			SendBuf[18] = Rs485PB20Strip.Strip_DimTime;
			
			SendBuf[19 + (Rs485PB20->Strip_List[i].Addr * 4) + 0] = (Rs485PB20Strip.LightBuf[0] & 0x7f);
			SendBuf[19 + (Rs485PB20->Strip_List[i].Addr * 4) + 1] = (Rs485PB20Strip.LightBuf[1] & 0x7f);
			SendBuf[19 + (Rs485PB20->Strip_List[i].Addr * 4) + 2] = (Rs485PB20Strip.LightBuf[2] & 0x7f);
			SendBuf[19 + (Rs485PB20->Strip_List[i].Addr * 4) + 3] = (Rs485PB20Strip.LightBuf[3] & 0x7f);
			
			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 %d Strip ADDR:%08X loop1:%d loop2:%d loop3:%d loop4:%d",\
			Rs485PB20->Strip_List[i].Addr,tempaddr,(Rs485PB20Strip.LightBuf[0] & 0x7f),(Rs485PB20Strip.LightBuf[1] & 0x7f),(Rs485PB20Strip.LightBuf[2] & 0x7f),(Rs485PB20Strip.LightBuf[3] & 0x7f));
		}
	}
	

	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);
	
	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Strip LLCtrl Send Buff:",SendBuf,lens);

	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);

}



/*******************************************************************************
* Function Name  : BLV_PB20_Strip_LSCtrl_Send 
* Description    : PB20_Strip开关组控发送
* Input          : 
	BUS_Public	 : 公有属性
	Rs485PB20	 : 私有属性
* Return         : None
*******************************************************************************/
void BLV_PB20_Strip_LSCtrl_Send(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20)
{
	uint8_t lens = 82;
	uint8_t SendBuf[lens];
	memset(SendBuf,0,sizeof(SendBuf));
	
	uint32_t tempaddr = 0;
	RS485_PB20_Strip_INFO Rs485PB20Strip;
	
	
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = Dev_Rs485_PB20;   //设备类型
	SendBuf[3] = BUS_Public->addr;
	SendBuf[4] = lens;    //长度
	SendBuf[6] = PB20_CMD_LS_LSCTRL;    //CMD
	SendBuf[7] = PB20_RETRY_TIME;    //重发次数
	SendBuf[8] = 0;
	
	SendBuf[9] = (Rs485PB20->Strip_A00_07_LSCtrl & 0xff);
	SendBuf[10] = ((Rs485PB20->Strip_A00_07_LSCtrl >> 8) & 0xff);
	SendBuf[11] = ((Rs485PB20->Strip_A00_07_LSCtrl >> 16) & 0xff);
	SendBuf[12] = ((Rs485PB20->Strip_A00_07_LSCtrl >> 24) & 0xff);
	
	SendBuf[13] = (Rs485PB20->Strip_A08_15_LSCtrl & 0xff);
	SendBuf[14] = ((Rs485PB20->Strip_A08_15_LSCtrl >> 8) & 0xff);
	SendBuf[15] = ((Rs485PB20->Strip_A08_15_LSCtrl >> 16) & 0xff);
	SendBuf[16] = ((Rs485PB20->Strip_A08_15_LSCtrl >> 24) & 0xff);
	
	SendBuf[17] = 0xF0;
	
	for(uint8_t i = 0; i < Rs485PB20->StripDevNum; i++)
	{
		tempaddr = Find_AllDevice_List_Information(Dev_Rs485_PB20_LS,Rs485PB20->Strip_List[i].Addr);
		if(tempaddr != NULL)
		{
			SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20Strip,sizeof(RS485_PB20_Strip_INFO),tempaddr+Dev_Privately);
			
			for(uint8_t j = 0; j < 4; j++)
			{
				if(((Rs485PB20Strip.LightBuf[j] & 0x80) >> 7) == 0x01)
				{
					SendBuf[18 + (Rs485PB20->Strip_List[i].Addr * 4) + j] = 0x01;
				}
				else if(((Rs485PB20Strip.LightBuf[j] & 0x80) >> 7) == 0x00)
				{
					SendBuf[18 + (Rs485PB20->Strip_List[i].Addr * 4) + j] = 0x02;
				}
			}
			
			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 %d Strip ADDR:%08X loop1:%d loop2:%d loop3:%d loop4:%d",\
			Rs485PB20->Strip_List[i].Addr,tempaddr,((Rs485PB20Strip.LightBuf[0] & 0x80) >> 7),((Rs485PB20Strip.LightBuf[1] & 0x80) >> 7),\
			((Rs485PB20Strip.LightBuf[2] & 0x80) >> 7),((Rs485PB20Strip.LightBuf[3] & 0x80) >> 7));
		}
	}
	

	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);

	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Strip LSCtrl Send Buff:",SendBuf,lens);

	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);

}



/*******************************************************************************
* Function Name  : BLV_PB20_Strip_ICCtrl_Send 
* Description    : PB20_Strip   相对调节  单回路发送,YYW,2025-07-08
* Input          : 
	BUS_Public	 : 公有属性
	Rs485PB20	 : 私有属性
* Return         : None
*******************************************************************************/
void BLV_PB20_Strip_ICCtrl_Send(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20)
{
	uint8_t lens = 10;
    uint8_t loopnum = 0;
    uint8_t ctrlstate = 0x00;   //0x01,不管亮度全控，0x00,只控亮的灯
	uint8_t SendBuf[106];
	memset(SendBuf,0,sizeof(SendBuf));
	
	uint32_t tempaddr = 0;
	RS485_PB20_Strip_INFO Rs485PB20Strip;
	
	
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = Dev_Rs485_PB20;   //设备类型
	SendBuf[3] = BUS_Public->addr;

	SendBuf[6] = 0x48;    //CMD   ,2025-07-08-YYW 
	SendBuf[7] = PB20_RETRY_TIME;    //重发次数
	

	for(uint8_t i = 0; i < Rs485PB20->StripDevNum; i++)
	{
		tempaddr = Find_AllDevice_List_Information(Dev_Rs485_PB20_LS,Rs485PB20->Strip_List[i].Addr);
		if(tempaddr != NULL)
		{
			SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20Strip,sizeof(RS485_PB20_Strip_INFO),tempaddr+Dev_Privately);
           
			if(Rs485PB20->Strip_AGCtrl_Flag[Rs485PB20->Strip_List[i].Addr] != 0x00)
			{
				//设置灯带 - 开关状态//设置各回路渐变
				for(uint8_t j = 0; j < Rs485PB20Strip.LoopValidNum; j++)
				{
					if((Rs485PB20->Strip_AGCtrl_Flag[Rs485PB20->Strip_List[i].Addr] >> j)&0x01)
					{
						SendBuf[10+3*loopnum] = Rs485PB20->Strip_List[i].Addr*4 + j;
                        //SendBuf[11+3*loopnum] =  Rs485PB20Strip.CtrlMode[j];
                        SendBuf[12+3*loopnum] =  Rs485PB20Strip.CtrlTime[j];
                        
                        Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"333:mode:%d,j:%d",Rs485PB20Strip.CtrlMode[j],j);
                        switch(Rs485PB20Strip.CtrlMode[j])
                        {
                            case PB20_Strip_Dim_Up:                    //相对调节   向上
                                SendBuf[11+3*loopnum] = 0x01;
                                ctrlstate++;
                                break;
                            case PB20_Strip_Dim_Down:                  //相对调节   向下 
                                SendBuf[11+3*loopnum] = 0x00;
                                ctrlstate++;
                                break;
                            case PB20_Strip_Dim_Up_Limit:              //相对调节   唯有亮的  向上
                                SendBuf[11+3*loopnum] = 0x01;
                                break;
                            case PB20_Strip_Dim_Down_Limit:            //相对调节   唯有亮的  向下
                                SendBuf[11+3*loopnum] = 0x00;
                                break;
                            case PB20_Strip_Dim_Cir:                   //相对调节  -  反向
                                SendBuf[11+3*loopnum] = 0x02;
                                ctrlstate++;
                                break;
                            case PB20_Strip_Dim_OnCir:                 //相对调节  - 反向  亮的灯
                                SendBuf[11+3*loopnum] = 0x02;   
                                break; 
                            default:
                                break; 
                        }

                        
						loopnum++;
						lens += 3;
					}
				}
                
				SendBuf[8] = (lens-10)/3;    //回路数量
                      
			}            
            
		}
	}
    if(ctrlstate == 0x00){
        SendBuf[9] = 0x01;  //只调节亮度输出不为关的回路
    }else{
        SendBuf[9] = 0x00;
    }    
    
	
    SendBuf[4] = lens;    //长度
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);
	
    Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"3333:LoopValidNum:%d,len:%d",Rs485PB20Strip.LoopValidNum,lens);
	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Strip AGCtrl Send Buff:",SendBuf,lens);

	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);

}




/*******************************************************************************
* Function Name  : BLV_PB20_Strip_AGCtrl_Send 
* Description    : PB20_Strip渐变组控发送
* Input          : 
	BUS_Public	 : 公有属性
	Rs485PB20	 : 私有属性
* Return         : None
*******************************************************************************/
void BLV_PB20_Strip_AGCtrl_Send(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20)
{
	uint8_t lens = 20;
	uint8_t SendBuf[lens];
	memset(SendBuf,0,sizeof(SendBuf));
	
	uint32_t tempaddr = 0;
	RS485_PB20_Strip_INFO Rs485PB20Strip;
	
	
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = Dev_Rs485_PB20;   //设备类型
	SendBuf[3] = BUS_Public->addr;
	SendBuf[4] = lens;    //长度
	SendBuf[7] = PB20_RETRY_TIME;    //重发次数
	SendBuf[8] = 0;
	
	SendBuf[9] = (Rs485PB20->Strip_A00_07_AGCtrl & 0xff);
	SendBuf[10] = ((Rs485PB20->Strip_A00_07_AGCtrl >> 8) & 0xff);
	SendBuf[11] = ((Rs485PB20->Strip_A00_07_AGCtrl >> 16) & 0xff);
	SendBuf[12] = ((Rs485PB20->Strip_A00_07_AGCtrl >> 24) & 0xff);
	
	SendBuf[13] = (Rs485PB20->Strip_A08_15_AGCtrl & 0xff);
	SendBuf[14] = ((Rs485PB20->Strip_A08_15_AGCtrl >> 8) & 0xff);
	SendBuf[15] = ((Rs485PB20->Strip_A08_15_AGCtrl >> 16) & 0xff);
	SendBuf[16] = ((Rs485PB20->Strip_A08_15_AGCtrl >> 24) & 0xff);
	

	for(uint8_t i = 0; i < Rs485PB20->StripDevNum; i++)
	{
		tempaddr = Find_AllDevice_List_Information(Dev_Rs485_PB20_LS,Rs485PB20->Strip_List[i].Addr);
		if(tempaddr != NULL)
		{
			SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20Strip,sizeof(RS485_PB20_Strip_INFO),tempaddr+Dev_Privately);

			switch(Rs485PB20Strip.CtrlMode[0])
			{
				case PB20_Strip_Ctrl_UpperLimit:             //向上调光至上限
				case PB20_Strip_Cycle_Dim_Up_Limit:          //唯有亮的灯 向上循环 至上限
					SendBuf[6] = PB20_CMD_LS_AGCTRL;    //CMD
					SendBuf[17] = 0x00;
					SendBuf[18] = 0x01;
					SendBuf[19] = Rs485PB20Strip.CtrlTime[0];
					break;
				case PB20_Strip_Ctrl_LowerLimit:             //向下调光至下限
				case PB20_Strip_Cycle_Dim_Down_Limit:        //唯有亮的灯 向下循环 至下限
					SendBuf[6] = PB20_CMD_LS_AGCTRL;    //CMD
					SendBuf[17] = 0x00;
					SendBuf[18] = 0x00;
					SendBuf[19] = Rs485PB20Strip.CtrlTime[0];
					break;
				case PB20_Strip_Cycle_Dim_Up:                //向下循环
				case PB20_Strip_Cycle_Dim_Down:              //向上循环
					SendBuf[6] = PB20_CMD_LS_AGCTRL;    //CMD
					SendBuf[17] = 0x01;
					SendBuf[18] = 0x02;
					SendBuf[19] = Rs485PB20Strip.CtrlTime[0];
					break;
				case PB20_Strip_Cycle_Stop:                 //停止调光
					SendBuf[6] = PB20_CMD_LS_AGCTRL;    //CMD
					SendBuf[17] = 0x02;
					SendBuf[18] = 0x00;
					SendBuf[19] = 0x00;
				case PB20_Strip_Dim_Up:                    //相对调节   向上
					SendBuf[6] = PB20_CMD_LS_RELCTRL;    //CMD
					SendBuf[17] = 0x01;
					SendBuf[18] = Rs485PB20Strip.CtrlTime[0];   //相对调节值
					SendBuf[19] = 0x00;
					break;
				case PB20_Strip_Dim_Down:                  //相对调节   向下
					SendBuf[6] = PB20_CMD_LS_RELCTRL;    //CMD
					SendBuf[17] = 0x00;
					SendBuf[18] = Rs485PB20Strip.CtrlTime[0];   //相对调节值
					SendBuf[19] = 0x00;
					break;
				case PB20_Strip_Dim_Up_Limit:              //相对调节   唯有亮的  向上
					SendBuf[6] = PB20_CMD_LS_RELCTRL;    //CMD
					SendBuf[17] = 0x01;
					SendBuf[18] = Rs485PB20Strip.CtrlTime[0];   //相对调节值
					SendBuf[19] = 0x01;
					break;
				case PB20_Strip_Dim_Down_Limit:            //相对调节   唯有亮的  向下
					SendBuf[6] = PB20_CMD_LS_RELCTRL;    //CMD
					SendBuf[17] = 0x00;
					SendBuf[18] = Rs485PB20Strip.CtrlTime[0];   //相对调节值
					SendBuf[19] = 0x01;
					break;
				case PB20_Strip_Dim_Cir:                 //相对调节  -  反向
					SendBuf[6] = PB20_CMD_LS_RELCTRL;    //CMD
					SendBuf[17] = 0x02;
					SendBuf[18] = Rs485PB20Strip.CtrlTime[0];   //相对调节值
					SendBuf[19] = 0x00;
					break;
			    case PB20_Strip_Dim_OnCir:                 //相对调节  - 反向
					SendBuf[6] = PB20_CMD_LS_RELCTRL;    //CMD
					SendBuf[17] = 0x02;
					SendBuf[18] = Rs485PB20Strip.CtrlTime[0];   //相对调节值
					SendBuf[19] = 0x01;      //亮的灯
					break; 
				default:
					break; 
			}

			break;
		}
	}
	

	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);
	
    Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"2222222222:%d",Rs485PB20Strip.CtrlTime[0]);
	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Strip LSCtrl Send Buff:",SendBuf,lens);

	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);

}



/*******************************************************************************
* Function Name  : BLV_PB20_Relay_Ctrl_Send 
* Description    : PB20_Relay控制发送
* Input          : 
	BUS_Public	 : 公有属性
	Rs485PB20	 : 私有属性
* Return         : None
*******************************************************************************/
void BLV_PB20_Relay_Ctrl_Send(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20,uint8_t ld_addr)
{
	uint8_t lens = 10;
	uint8_t SendBuf[50];
	uint8_t loopnum = 0;
	memset(SendBuf,0,sizeof(SendBuf));
	
	uint32_t tempaddr = Find_AllDevice_List_Information(Dev_Rs485_PB20_Relay,ld_addr);
	RS485_PB20_Relay_INFO Rs485PB20Relay;
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20Relay,sizeof(RS485_PB20_Relay_INFO),tempaddr+Dev_Privately);
	
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = Dev_Rs485_PB20;   //设备类型
	SendBuf[3] = BUS_Public->addr;
	SendBuf[7] = PB20_RETRY_TIME;    //重发次数
	
	
	Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 Ctrl Flag:%02X ",Rs485PB20->Relay_LoopCtrl_Flag[ld_addr]);
	
	if(Rs485PB20->Relay_LoopCtrl_Flag[ld_addr] != 0x00)
	{
		SendBuf[6] = PB20_CMD_RELAY_CTRL;    //CMD
		for(uint8_t i = 0; i < Rs485PB20Relay.LoopValidNum; i++)
		{
			if((Rs485PB20->Relay_LoopCtrl_Flag[ld_addr] >> i)&0x01)
			{
				SendBuf[10+2*loopnum] = ld_addr*4 + i;
				SendBuf[11+2*loopnum] = Rs485PB20Relay.RelayState[i];
				loopnum++;
				lens += 2;
			}
		}
		SendBuf[8] = (lens-10)/2;    //回路数量
		SendBuf[9] = 0xF0;              //掉电不保存
	}

	SendBuf[4] = lens;    //长度
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);
	
	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Relay Send Buff:",SendBuf,lens);

	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);

}



/*******************************************************************************
* Function Name  : BLV_PB20_Relay_LoopCtrl_Send 
* Description    : PB20_Relay多地址控制发送
* Input          : 
	BUS_Public	 : 公有属性
	Rs485PB20	 : 私有属性
* Return         : None
*******************************************************************************/
void BLV_PB20_Relay_LoopCtrl_Send(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20)
{
	uint8_t lens = 10;
	uint8_t SendBuf[138];
	uint8_t loopnum = 0;
	memset(SendBuf,0,sizeof(SendBuf));
	
	uint32_t tempaddr = 0;
	
	RS485_PB20_Relay_INFO Rs485PB20Relay;
	
	
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = Dev_Rs485_PB20;   //设备类型
	SendBuf[3] = BUS_Public->addr;
	SendBuf[6] = PB20_CMD_RELAY_CTRL;    //CMD
	SendBuf[7] = PB20_RETRY_TIME;    //重发次数
	
	
	for(uint8_t j = 0; j < Rs485PB20->RelayDevNum; j++)
	{
		tempaddr = Find_AllDevice_List_Information(Dev_Rs485_PB20_Relay,Rs485PB20->Relay_List[j].Addr);
		if(tempaddr != NULL)
		{
			SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20Relay,sizeof(RS485_PB20_Relay_INFO),tempaddr+Dev_Privately);
			if(Rs485PB20->Relay_LoopCtrl_Flag[Rs485PB20->Relay_List[j].Addr] != 0x00)
			{
				for(uint8_t i = 0; i < Rs485PB20Relay.LoopValidNum; i++)
				{
					if((Rs485PB20->Relay_LoopCtrl_Flag[Rs485PB20->Relay_List[j].Addr] >> i)&0x01)
					{
						SendBuf[10+2*loopnum] = Rs485PB20->Relay_List[j].Addr*4 + i;
						SendBuf[11+2*loopnum] = Rs485PB20Relay.RelayState[i];
						loopnum++;
						lens += 2;
					}
				}
				SendBuf[8] = (lens-10)/2;    //回路数量
				SendBuf[9] = 0xF0;              //掉电不保存
			}
		}
	}
	
	
	SendBuf[4] = lens;    //长度
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);
	
	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Relay LoopCtrl Send Buff:",SendBuf,lens);

	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);
}


/*******************************************************************************
* Function Name  : BLV_PB20_CycleCtrl 
* Description    : PB20发送数据处理函数
* Input          : 
	dev_addr	 : 设备信息地址
* Return         : 
RS485OCCUPYTIME  :占用时间
RS485OCCUPYNOTIME:不占用时间
*******************************************************************************/
uint8_t BLV_PB20_CycleCtrl(uint32_t dev_addr) 
{
	uint8_t Ret = RS485OCCUPYNOTIME;
	uint8_t keepflag = 0x00;
	Device_Public_Information_G BUS_Public;
	RS485_PB20_INFO Rs485PB20;
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),dev_addr);	//拷贝所有共有数据
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO),dev_addr+Dev_Privately);
	
	for(uint8_t i = 0; i < PB20_OWN_LS_BUFF_SIZE; i++)
	{
		if((Rs485PB20.LightBuf_Last[i] & 0x7f) != (Rs485PB20.LightBuf[i] & 0x7f))      //亮度判断
		{
			Rs485PB20.LightBuf_Last[i] &= 0x80;
			Rs485PB20.LightBuf_Last[i] |= (Rs485PB20.LightBuf[i] & 0x7f);
            
			Rs485PB20.Own_Ls_Light_Flag |= (0x01<<i);
			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 Light Ctrl,Flag:%d",Rs485PB20.Own_Ls_Light_Flag);
			keepflag = 0x01;
		}
		
		if((Rs485PB20.LightBuf_Last[i] & 0x80) != (Rs485PB20.LightBuf[i] & 0x80))      //开关判断
		{
			Rs485PB20.LightBuf_Last[i] &= 0x7f;
			Rs485PB20.LightBuf_Last[i] |= (Rs485PB20.LightBuf[i] & 0x80);
            
			Rs485PB20.Own_Ls_OnOff_Flag |= (0x01<<i);
			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 OnOff Ctrl Flag:%d",Rs485PB20.Own_Ls_OnOff_Flag);
			keepflag = 0x01;
		}
        
        /*向服务器上报状态*/
        if( Rs485PB20.ReportLight[i] != Rs485PB20.LightBuf[i] ){
            uint16_t report_state = 0;
            
            Rs485PB20.ReportLight[i] = Rs485PB20.LightBuf[i];
            
            if((Rs485PB20.ReportLight[i] & 0x80) != 0x00){
                report_state = Rs485PB20.ReportLight[i] & 0x7F;
                report_state = (report_state << 8) | 0x0001;
                Udp_Addtion_Roomstate(Dev_Rs485_PB20,BUS_Public.addr,i+1,report_state);
            }else{
                report_state = Rs485PB20.ReportLight[i] & 0x7F;
                report_state = (report_state << 8) | 0x0002;
                Udp_Addtion_Roomstate(Dev_Rs485_PB20,BUS_Public.addr,i+1,report_state);
            }
			
			keepflag = 0x01;
        }
	}

    if(DevActionGlobal.DimGlobalValue != Rs485PB20.Global_Light)       //2025-07-15,YYW,全局亮度比较
    {
        Rs485PB20.Global_Light = DevActionGlobal.DimGlobalValue;
        Rs485PB20.GLight_Flag |= (0x01<<7);
        
        Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20Fun--全局亮度改变:",Rs485PB20.Global_Light); 
        
    }
	


	if((Rs485PB20.Check_Flag == DEV_CHECK_OPEN) && (DevActionGlobal.CheckMapDevNum != 0x00) && (Rs485PB20.PB20_Process_State == PB20_CMD_Relpy_OK))    //巡检开且有设备参与巡检
	{
  
		DEVCHECKMAP DevCheckMap;
		
		uint16_t vol = 0x00;   uint16_t ele = 0x00;   uint32_t power = 0x00;
		
		if(Rs485PB20.Check_Loop < DevActionGlobal.CheckMapDevNum)   
		{
			uint32_t list_addr = SRAM_CheckMap_List_Start_Addr + Rs485PB20.Check_Loop*sizeof(DEVCHECKMAP);   //拿到新地址
			SRAM_DMA_Read_Buff((uint8_t *)&DevCheckMap,sizeof(DEVCHECKMAP),list_addr);
			
			if(NULL != Find_AllDevice_List_Information(DevCheckMap.DevType, DevCheckMap.DevAddr))
			{
				switch(Rs485PB20.Check_State)
				{
					case CLOSEALL:
						Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"------Device Check State:CLOSEALL DevType:%d Addr:%d Loop:%d------",\
						DevCheckMap.DevType,DevCheckMap.DevAddr,DevCheckMap.DevLoop);
					
						if(Rs485PB20.Close_State < DevActionGlobal.CheckTypeNum)
						{
							switch(DevActionGlobal.CheckMapList[Rs485PB20.Close_State])     
							{
								case Dev_Rs485_PB20_Relay:
									PB20_Relay_AllClose(&BUS_Public,&Rs485PB20);
									Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
									Ret = RS485OCCUPYTIME;
									break;
								case Dev_Rs485_PB20_LS:
									PB20_Strip_AllClose(&BUS_Public,&Rs485PB20);
									Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
									Ret = RS485OCCUPYTIME;
									break;
							}
						}
						
						if(Rs485PB20.Close_State == DevActionGlobal.CheckTypeNum)
						{
							Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 Go To FIRSTINQUIRE");
							Rs485PB20.Check_State = FIRSTINQUIRE;
							Rs485PB20.Close_State = 0x00;
							keepflag = 0x01;
						}
						
						Rs485PB20.Wait_Tick = SysTick_1ms;
						break;
					case FIRSTINQUIRE:
						if(SysTick_1ms - Rs485PB20.Wait_Tick > 500)
						{
							Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"------Device Check State:FIRSTINQUIRE DevType:%d Addr:%d Loop:%d------",\
							DevCheckMap.DevType,DevCheckMap.DevAddr,DevCheckMap.DevLoop);
							
							BLV_PB20_Inquire_Send(&BUS_Public, &Rs485PB20);      //查询状态
							Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
							Ret = RS485OCCUPYTIME;
							
							Rs485PB20.Wait_Tick = SysTick_1ms;
						}
						break;
					case OPENONE:
						
						Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"------Device Check State:OPENONE DevType:%d Addr:%d Loop:%d------",\
						DevCheckMap.DevType,DevCheckMap.DevAddr,DevCheckMap.DevLoop);
						switch(DevCheckMap.DevType)
						{
							case Dev_Rs485_PB20_Relay:
								PB20_Relay_LoopCtrl(&BUS_Public,&Rs485PB20,(DevCheckMap.DevLoop-1),0x01,DevCheckMap.DevAddr);
								Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
								Ret = RS485OCCUPYTIME;
								break;
							case Dev_Rs485_PB20_LS:
								PB20_Strip_LoopCtrl(&BUS_Public,&Rs485PB20,(DevCheckMap.DevLoop-1),100,DevCheckMap.DevAddr);    //开一个回路	
								Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
								Ret = RS485OCCUPYTIME;
								break;
						}
						
						Rs485PB20.Wait_Tick = SysTick_1ms;

						break;
					case SECONDINQUIRE:
						if(SysTick_1ms - Rs485PB20.Wait_Tick > 500)               //查询新开一个回路的电压、电流、功率
						{
							Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"------Device Check State:SECONDINQUIRE DevType:%d Addr:%d Loop:%d------",\
							DevCheckMap.DevType,DevCheckMap.DevAddr,DevCheckMap.DevLoop);
							
							BLV_PB20_Inquire_Send(&BUS_Public, &Rs485PB20);      //查询状态
							Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
							Ret = RS485OCCUPYTIME;
							Rs485PB20.Wait_Tick = SysTick_1ms;
						}
						break;
					case CHECKONE:
						Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"------Device Check State:CHECKONE DevType:%d Addr:%d Loop:%d------",\
						DevCheckMap.DevType,DevCheckMap.DevAddr,DevCheckMap.DevLoop);
						
						Dbg_Println(DBG_BIT_SYS_STATUS_bit,"PB20 Vol Now:%d Last:%d    Ele Now:%d Last:%d  Power Now:%d Last:%d",\
						Rs485PB20.Bus_Vol,Rs485PB20.Bus_Vol_Last,Rs485PB20.Bus_Ele,Rs485PB20.Bus_Ele_Last,Rs485PB20.Bus_Power,Rs485PB20.Bus_Power_Last);
						
						if(Rs485PB20.Bus_Vol >= Rs485PB20.Bus_Vol_Last)
						{
							vol = Rs485PB20.Bus_Vol - Rs485PB20.Bus_Vol_Last;
						}
						else
						{
							vol = Rs485PB20.Bus_Vol_Last - Rs485PB20.Bus_Vol;
						}
						
						if(Rs485PB20.Bus_Ele >= Rs485PB20.Bus_Ele_Last)
						{
							ele = Rs485PB20.Bus_Ele - Rs485PB20.Bus_Ele_Last;
						}
						else
						{
							ele = Rs485PB20.Bus_Ele_Last - Rs485PB20.Bus_Ele;
						}
						
						if(Rs485PB20.Bus_Power >= Rs485PB20.Bus_Power_Last)
						{
							power = Rs485PB20.Bus_Power - Rs485PB20.Bus_Power_Last;
						}
						else
						{
							power = Rs485PB20.Bus_Power_Last - Rs485PB20.Bus_Power;
						}
						
						
						if((power < (DevCheckMap.LP_Limit*1000)) || (power > (DevCheckMap.UP_Limit*1000)))                    //Rs485PB20.Bus_Rate_Power[Rs485PB20.Check_Loop-1]
						{
							Dbg_Println(DBG_BIT_SYS_STATUS_bit,"Loop Unnormal!  PB20 Vol-Last:%d  Ele-Last:%d  Power-Last:%d",\
							vol,ele,power);
							Write_Device_Loop_Fault_State(DevCheckMap.DevType,DevCheckMap.DevAddr,In_ErrFun_LoopState,0x01,(DevCheckMap.DevLoop-1));	
						}
						else
						{
							Dbg_Println(DBG_BIT_SYS_STATUS_bit,"Loop Normal!  PB20 Vol-Last:%d  Ele-Last:%d  Power-Last:%d",\
							vol,ele,power);
						}
						
		
						if(Rs485PB20.Check_Loop == (DevActionGlobal.CheckMapDevNum - 1))
						{
							Rs485PB20.Check_State = CHECKEND;
							Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"Go To CHECKEND");
						}
						else
						{
							Rs485PB20.Check_State = FIRSTINQUIRE;
							Rs485PB20.Check_Loop++;
						}
						Rs485PB20.Wait_Tick = SysTick_1ms;
						
						
						keepflag = 0x01;
						
						break;
					case CHECKEND:
						Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"------Device Check State:CHECKEND------");
						if(Rs485PB20.Close_State < DevActionGlobal.CheckTypeNum)
						{
							switch(DevActionGlobal.CheckMapList[Rs485PB20.Close_State])     
							{
								case Dev_Rs485_PB20_Relay:
									PB20_Relay_AllClose(&BUS_Public,&Rs485PB20);
									Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
									Ret = RS485OCCUPYTIME;
									break;
								case Dev_Rs485_PB20_LS:
									PB20_Strip_AllClose(&BUS_Public,&Rs485PB20);
									Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
									Ret = RS485OCCUPYTIME;
									break;
							}
							Rs485PB20.Close_State++;
						}
						
						if(Rs485PB20.Close_State == DevActionGlobal.CheckTypeNum)
						{
							Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 CHECKEND!!!!");
							Rs485PB20.Check_Flag = 0x00;
							Rs485PB20.Check_Loop = 0x00;
							keepflag = 0x01;
						}
						
					
						break;
					default:
						break;
				}
			}
		}
		else
		{
			Rs485PB20.Check_Flag = 0x00;
			Rs485PB20.Check_Loop = 0x00;
			keepflag = 0x01;
		}

	}
	else if(Rs485PB20.Own_Ls_OnOff_Flag != 0x00)            //自带灯带开关控制标记
	{
		BLV_PB20_OwnLs_OnOff_Ctrl_Send(&BUS_Public, &Rs485PB20);
		Ret = RS485OCCUPYTIME;
		keepflag = 0x01;
	}
	else if(Rs485PB20.Own_Ls_Light_Flag != 0x00)            //自带灯带亮度控制标志
	{
		BLV_PB20_OwnLs_Light_Ctrl_Send(&BUS_Public, &Rs485PB20);    
		Ret = RS485OCCUPYTIME;
		keepflag = 0x01;
	}
	else if(Rs485PB20.Own_Ls_Cycle_Flag != 0x00)           //自带灯带循环控制标志
	{
		BLV_PB20_OwnLs_Cycle_Ctrl_Send(&BUS_Public, &Rs485PB20);
		Ret = RS485OCCUPYTIME;
		keepflag = 0x01;
	}
	else if(Rs485PB20.GLight_Flag != 0x00)                 //PB20全局亮度/可调上限/可调下限设置
	{
		BLV_PB20_GLight_Ctrl_Send(&BUS_Public, &Rs485PB20);
		Ret = RS485OCCUPYTIME;
		keepflag = 0x01;
	}
	#if RS485_PB20_LD_Flag
	else if((Rs485PB20.LED_Send_L_Flag!=0x00)||(Rs485PB20.LED_Send_H_Flag!=0x00))
	{
		Dbg_Println(DBG_BIT_SYS_STATUS_bit,"LED_Send_L_Flag:%04X  LED_Send_H_Flag:%04X",Rs485PB20.LED_Send_L_Flag,Rs485PB20.LED_Send_H_Flag);
		for(uint8_t i = 0; i < Rs485PB20.LEDDevNum; i++)
		{
			if(((Rs485PB20.LED_Send_L_Flag>>Rs485PB20.LED_List[i].Addr)&0x01)||
				((Rs485PB20.LED_Send_H_Flag>>Rs485PB20.LED_List[i].Addr)&0x01))
			{
				BLV_PB20_LED_Ctrl_Send(&BUS_Public, &Rs485PB20,Rs485PB20.LED_List[i].Addr);     //LED控制发送
				Ret = RS485OCCUPYTIME;
				break;
			}
		}
	}
	#endif
	
	
	
	#if RS485_PB20_LS_Flag
	else if(((Rs485PB20.Strip_A00_07_LSCtrl != 0x00) || (Rs485PB20.Strip_A08_15_LSCtrl != 0x00)) && (Rs485PB20.PB20_Process_State == PB20_CMD_Relpy_OK) )   //PB外挂灯带开关控制
	{
		if(Rs485PB20.Strip_LS_CtrlLoopNum < 14)
		{
			Rs485PB20.Strip_A00_07_LSCtrl_Send = Rs485PB20.Strip_A00_07_LSCtrl;      //按回路控制时保存已发送的控制标记      2024-11-12
			Rs485PB20.Strip_A08_15_LSCtrl_Send = Rs485PB20.Strip_A08_15_LSCtrl;      //按回路控制时保存已发送的控制标记      2024-11-12
			Rs485PB20.Strip_LS_CtrlLoopNum_Send = Rs485PB20.Strip_LS_CtrlLoopNum;    //按回路控制时保存已发送控制的回路数    2024-11-12
			
			BLV_PB20_Strip_Switch_Loop_Ctrl_Send(&BUS_Public, &Rs485PB20);  //单个回路
		}
		else
		{
			BLV_PB20_Strip_LSCtrl_Send(&BUS_Public, &Rs485PB20);            //组控
		}
		Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
		Ret = RS485OCCUPYTIME;
	}
	else if(((Rs485PB20.Strip_A00_07_LLCtrl != 0x00) || (Rs485PB20.Strip_A08_15_LLCtrl != 0x00)) && (Rs485PB20.PB20_Process_State == PB20_CMD_Relpy_OK) )        //PB外挂灯带亮度
	{
		if(Rs485PB20.Strip_LL_CtrlLoopNum < 14)
		{
			Rs485PB20.Strip_A00_07_LLCtrl_Send = Rs485PB20.Strip_A00_07_LLCtrl;         //按回路控制时保存已发送的控制标记      2024-11-12
			Rs485PB20.Strip_A08_15_LLCtrl_Send = Rs485PB20.Strip_A08_15_LLCtrl;         //按回路控制时保存已发送的控制标记      2024-11-12
			Rs485PB20.Strip_LL_CtrlLoopNum_Send = Rs485PB20.Strip_LL_CtrlLoopNum;       //按回路控制时保存已发送控制的回路数    2024-11-12
			
			BLV_PB20_Strip_Light_Loop_Ctrl_Send(&BUS_Public, &Rs485PB20);   //单个回路
		}
		else
		{
			BLV_PB20_Strip_LLCtrl_Send(&BUS_Public, &Rs485PB20);            //组控
		}
		Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
		Ret = RS485OCCUPYTIME;
	}
	else if(((Rs485PB20.Strip_A00_07_AGCtrl != 0x00) || (Rs485PB20.Strip_A08_15_AGCtrl != 0x00)) && (Rs485PB20.PB20_Process_State == PB20_CMD_Relpy_OK) )   //PB外挂灯带渐变组控
	{
//			if(Rs485PB20.Strip_AG_CtrlLoopNum < 32)
//			{
//				
//			}
//			else 
        
//        Dbg_Println(DBG_BIT_SYS_STATUS_bit,"YYW,Send-Strip_AG_Flag :%d",Rs485PB20.Strip_AG_Flag);
        
        if(Rs485PB20.Strip_AG_Flag == 0x00)
		{
			BLV_PB20_Strip_AGCtrl_Send(&BUS_Public, &Rs485PB20);            //组控
		}else{      //相对调节，2025-07-09,YYW
            Rs485PB20.Strip_AG_Flag = 0x00;
            BLV_PB20_Strip_ICCtrl_Send(&BUS_Public, &Rs485PB20);        //相对调节单回路控制，2025-07-09,YYW          
        }
        
		Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
		Ret = RS485OCCUPYTIME;
	}
	
	#endif
	#if RS485_PB20_Relay_Flag

	else if(((Rs485PB20.Relay_A00_07_LoopCtrl != 0x00) || (Rs485PB20.Relay_A08_15_LoopCtrl != 0x00)) && (Rs485PB20.PB20_Process_State == PB20_CMD_Relpy_OK))
	{
		Dbg_Println(DBG_BIT_SYS_STATUS_bit,"Relay_A00_07_LoopCtrl:%08X  Relay_A08_15_LoopCtrl:%08X",Rs485PB20.Relay_A00_07_LoopCtrl,Rs485PB20.Relay_A08_15_LoopCtrl);
		
		if(Rs485PB20.Relay_CtrlLoopNum < 32)
		{
			Rs485PB20.Relay_A00_07_LoopCtrl_Send = Rs485PB20.Relay_A00_07_LoopCtrl;       //2024-11-12
			Rs485PB20.Relay_A08_15_LoopCtrl_Send = Rs485PB20.Relay_A08_15_LoopCtrl;       //2024-11-12
			Rs485PB20.Relay_CtrlLoopNum_Send = Rs485PB20.Relay_CtrlLoopNum;               //2024-11-12
			
			BLV_PB20_Relay_LoopCtrl_Send(&BUS_Public, &Rs485PB20);  //单个回路
			
			Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
			Ret = RS485OCCUPYTIME;
		}
	}

	#endif
	else
	{
		/*2024-10-15 增加PB 总线，在一段时间内无通讯的情况下，下发心跳包(LS灯光开关控制命令)*/
		if(SysTick_1ms - Rs485PB20.PB_Idle_Tick >= 10000){
			Rs485PB20.PB_Idle_Tick = SysTick_1ms;
			
			Dbg_Println(DBG_BIT_SYS_STATUS_bit,"PB20 定期下发心跳包(LS灯光开关控制命令)");
			
			Rs485PB20.Strip_A00_07_LSCtrl = 0xFFFFFFFF;
			Rs485PB20.Strip_A08_15_LSCtrl = 0xFFFFFFFF;
			BLV_PB20_Strip_LSCtrl_Send(&BUS_Public, &Rs485PB20);            //组控
			Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
			Ret = RS485OCCUPYTIME;
		}else{
			BLV_PB20_Inquire_Send(&BUS_Public, &Rs485PB20);      //查询状态
			Ret = RS485OCCUPYTIME;
		}
	}
	
	
	if(Ret==RS485OCCUPYTIME)
	{
		keepflag = 0x01;
		if(Rs485PB20.DevSendCnt > PB20_RETAYTIME_MAX)
		{
			if(Rs485PB20.DevOffline != DEV_IS_OFFLINE)
			{
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 OFFLINE");  //  离线上报
				LOG_Device_Online_Record(Dev_Rs485_PB20,BUS_Public.addr,LogInfo_Device_Offline);	//记录设备离线
			}
			
			Rs485PB20.DevOffline = DEV_IS_OFFLINE;		//判为离线
			Rs485PB20.DevSendCnt = 0;
			if(Rs485PB20.DevOffline != Rs485PB20.DevOfflineLast)	//当前在线状态不等于上一次在线状态
			{
				Rs485PB20.DevOfflineLast = Rs485PB20.DevOffline;	//更新上一次在线状态
				Write_Device_Fault_State(BUS_Public.type,BUS_Public.addr,In_ErrFun_LineState,DEV_IS_OFFLINE);	//保存设备在线状态到SRAM
			}
			
			Rs485PB20.Own_Ls_Light_Flag = 0x00;
			Rs485PB20.Own_Ls_Cycle_Flag = 0x00;
			
		}else {
			Rs485PB20.DevSendCnt++;   				//发送次数累计
		}
	}

	if(keepflag == 0x01)
	{
		
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&Rs485PB20, sizeof(RS485_PB20_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),dev_addr);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO),dev_addr+Dev_Privately);
	}
	
	
	return Ret;
}


/*******************************************************************************
* Function Name  : BLV_PB20_Rccv_Check 
* Description    : PB20接收数据处理函数
* Input          : 
	dev_addr	 : 设备信息地址
	data_addr	 : 数据地址
	len			 : 数据长度
* Return         : 
	0x00：处理成功
	0x01：处理失败
*******************************************************************************/
uint8_t BLV_PB20_Rccv_Check(uint32_t dev_addr,uint32_t data_addr,uint16_t len)
{
	uint8_t rev = 0x01;
	Device_Public_Information_G BUS_Public;
	RS485_PB20_INFO Rs485PB20;
	uint8_t data[50];
	uint16_t vol = 0;
	uint16_t ele = 0;
	uint32_t power = 0;
	uint16_t ps_vol = 0;
    
	if(len > 50)
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 Recv Lens Err");
		return rev;     //长度
	}
	
	SRAM_DMA_Read_Buff(data,len,data_addr);   //拷贝482数据
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),dev_addr);				
	
	if((data[0] != BUS_Public.addr) || (0x30 != (data[2]))   ||(len != (data[4])))	   
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 Addr or Type or Lens Err!!");
		return rev;				//校验文件头
	}

	if(data[5] == CheckSum_Overlook_Check(data, len, 5))   //校验通过
	{
		
		SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO),dev_addr+Dev_Privately);

		switch(data[6])  
		{
			case PB20_CMD_INQUIRE:          //状态轮询命令         
			case PB20_CMD_OLS_LCTRL:        //PB20自带灯带亮度控制
			case PB20_CMD_OLS_CCTRL:        //PB20自带灯带循环控制
			case PB20_CMD_OLS_ONOFF:        //PB20自带灯带开关控制
			case PB20_CMD_GL_CTRL:          //PB20全局参数设置
			case PB20_CMD_LD_LCTRL:         //PB20-LD亮度控制
			case PB20_CMD_LD_CCTRL:         //PB20-LD循环控制	
			case PB20_CMD_LS_LCTRL:         //PB20-LS亮度控制
			case PB20_CMD_LS_CCTRL:         //PB20-LS循环控制
			case PB20_CMD_LS_LLCTRL:        //PB20-LS亮度组控
			case PB20_CMD_LS_AGCTRL:        //PB20-LS渐变组控
			case PB20_CMD_LS_LSCTRL:        //PB20-LS开关状态组控
			case PB20_CMD_LS_SCTRL:         //PB20-LS开关控制
			case PB20_CMD_RELAY_CTRL:       //PB20-Relay控制
			case PB20_CMD_LS_RELCTRL:       //PB20-LS-相对调节
            case PB20_CMD_LS_INRELCTRL:          //2025-07-09,YYW
				rev = 0x00;
			
				if(Rs485PB20.DevOffline != DEV_IS_ONLINE)
				{
					Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 DEV_IS_ONLINE");
					LOG_Device_Online_Record(Dev_Rs485_PB20,BUS_Public.addr,LogInfo_Device_Online);	//记录设备在线
				}
				Rs485PB20.DevSendCnt = 0x00;
				Rs485PB20.DevOffline = DEV_IS_ONLINE;    //设备在线
				if(Rs485PB20.DevOffline != Rs485PB20.DevOfflineLast)	//当前在线状态不等于上一次在线状态
				{
					Rs485PB20.DevOfflineLast = Rs485PB20.DevOffline;	//更新上一次在线状态
					Write_Device_Fault_State(BUS_Public.type,BUS_Public.addr,In_ErrFun_LineState,DEV_IS_ONLINE);	//保存设备在线状态到SRAM
				}
				BLV_Communication_Record(&Rs485PB20.comm_record,0x02,0x01);		//记录通讯成功
				break;			
		}
		switch(data[6])
		{
			case PB20_CMD_INQUIRE:
				
                ps_vol = (data[14]<<8) + data[15];
                Rs485PB20.PS_vol = ps_vol;
                
				vol = (data[25]<<8) + data[26];
				ele = (data[27]<<8) + data[28];
				power = (data[29]<<24) + (data[30]<<16) + (data[31]<<8) + data[32];
//				if(Rs485PB20.Bus_Vol != vol)
				{
					Rs485PB20.Bus_Vol_Last = Rs485PB20.Bus_Vol;
					Rs485PB20.Bus_Vol = vol;
				}
				
//				if(Rs485PB20.Bus_Ele != ele)
				{
					Rs485PB20.Bus_Ele_Last = Rs485PB20.Bus_Ele;
					Rs485PB20.Bus_Ele = ele;
				}
				
//				if(Rs485PB20.Bus_Power != power)
				{
					Rs485PB20.Bus_Power_Last = Rs485PB20.Bus_Power;
					Rs485PB20.Bus_Power = power;
				}
				
				Rs485PB20.soft_version = data[35];  //软件版本 - data[35];    硬件版本 - data[36];  
                
                if(data[37] == PB20_CMD_Relpy_OK){
					
					if(Rs485PB20.PB20_Process_State != PB20_CMD_Relpy_OK){
						Rs485PB20.PB_Idle_Tick = SysTick_1ms;
					}
					Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_OK;    	//PowerBus 总线当前通讯处于空闲状态
				}else{
					Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;    	//PowerBus 总线当前通讯处于繁忙状态
				}
                
//                Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 Version:%d - %d",Rs485PB20.soft_version,Rs485PB20.PB20_Process_State);
                
//				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 Bus Vol:%dmV  Ele:%dmA  Power:%dmW PS:%dmV",\
//					Rs485PB20.Bus_Vol,Rs485PB20.Bus_Ele,Rs485PB20.Bus_Power,Rs485PB20.PS_vol);

//				LOG_Device_COMM_Control_Reply_Record(BUS_Public.port,BUS_Public.baud,data,len);
				
				
				break;
			case PB20_CMD_OLS_ONOFF:
				Rs485PB20.Own_Ls_OnOff_Flag = 0x00;
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 Cmd 0x%02X Ack",data[6]);
                
				break;
			case PB20_CMD_OLS_LCTRL:
                
				Rs485PB20.Own_Ls_Light_Flag = 0x00;
				break;
			case PB20_CMD_OLS_CCTRL:
				Rs485PB20.Own_Ls_Cycle_Flag = 0x00;
				break;
			case PB20_CMD_GL_CTRL:
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 Cmd 0x%02X Ack",data[6]);
				Rs485PB20.GLight_Flag = 0x00;
				break;

			#if RS485_PB20_LS_Flag
			case PB20_CMD_LS_LLCTRL:    //LS亮度组控
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 Cmd 0x%02X Ack:%02X",data[6],data[7]);
                if(data[7] == 0x00){
                    //当前处理成功，清楚控制标志位
                    Rs485PB20.Strip_A00_07_LLCtrl = 0x00;
                    Rs485PB20.Strip_A08_15_LLCtrl = 0x00;
                    Rs485PB20.Strip_LL_CtrlLoopNum = 0x00;
					
					
					memset(Rs485PB20.Strip_LLCtrl_Flag,0,sizeof(Rs485PB20.Strip_LLCtrl_Flag));
                }else{
                    //当前处于繁忙状态
                    Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
                }
				break;
			case PB20_CMD_LS_LCTRL:     //LS亮度按回路控制    2024-11-12
                Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 Cmd 0x%02X Ack:%02X",data[6],data[7]);
                if(data[7] == 0x00){
                    //当前处理成功，清楚控制标志位
					
                    Rs485PB20.Strip_A00_07_LLCtrl &= ~Rs485PB20.Strip_A00_07_LLCtrl_Send;
                    Rs485PB20.Strip_A08_15_LLCtrl &= ~Rs485PB20.Strip_A08_15_LLCtrl_Send;
					
					if(Rs485PB20.Strip_LL_CtrlLoopNum >= Rs485PB20.Strip_LL_CtrlLoopNum_Send)
					{
						Rs485PB20.Strip_LL_CtrlLoopNum -= Rs485PB20.Strip_LL_CtrlLoopNum_Send;
					}
					else 
					{
						Rs485PB20.Strip_LL_CtrlLoopNum = 0x00;
					}
                    
					for(uint8_t i = 0; i < 8; i++)
					{
						Rs485PB20.Strip_LLCtrl_Flag[i] &= ~((Rs485PB20.Strip_A00_07_LLCtrl_Send >> (i * 4)) & 0x0f);
					}
					
					for(uint8_t i = 8; i < 16; i++)
					{
						Rs485PB20.Strip_LLCtrl_Flag[i] &= ~((Rs485PB20.Strip_A08_15_LLCtrl_Send >> ((i - 8) * 4)) & 0x0f);
					}
				
					Rs485PB20.Strip_A00_07_LLCtrl_Send = 0x00;
					Rs485PB20.Strip_A08_15_LLCtrl_Send = 0x00;
					Rs485PB20.Strip_LL_CtrlLoopNum_Send = 0x00;
                }else{
                    //当前处于繁忙状态
                    Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
                }
				break;
			case PB20_CMD_LS_AGCTRL:   //LS循环组控
			case PB20_CMD_LS_CCTRL:    //LS循环单回路控制
			case PB20_CMD_LS_RELCTRL:  //LS-相对调节
            case PB20_CMD_LS_INRELCTRL:  //单回路相对调节，2025-07-09，YYW
                Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 Cmd 0x%02X Ack:%02X",data[6],data[7]);
                if(data[7] == 0x00){
                    //当前处理成功，清楚控制标志位
                    Rs485PB20.Strip_A00_07_AGCtrl = 0x00;
                    Rs485PB20.Strip_A08_15_AGCtrl = 0x00;
                    Rs485PB20.Strip_AG_CtrlLoopNum = 0x00;
					memset(Rs485PB20.Strip_AGCtrl_Flag,0,sizeof(Rs485PB20.Strip_AGCtrl_Flag));
                }else{
                    //当前处于繁忙状态
                    Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
                }
				break;
			case PB20_CMD_LS_LSCTRL:    //LS开关组控
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 Cmd 0x%02X Ack:%02X",data[6],data[7]);
                if(data[7] == 0x00){
                    //当前处理成功，清楚控制标志位
                    Rs485PB20.Strip_A00_07_LSCtrl = 0x00;
                    Rs485PB20.Strip_A08_15_LSCtrl = 0x00;
                    Rs485PB20.Strip_LS_CtrlLoopNum = 0x00;
					memset(Rs485PB20.Strip_LSCtrl_Flag,0,sizeof(Rs485PB20.Strip_LSCtrl_Flag));
                }else if(data[7] == 0x01){
                    //当前处于繁忙状态
                    Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
                }
				break;
			case PB20_CMD_LS_SCTRL:     //LS开关按回路控制     2024-11-12
                Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 Cmd 0x%02X Ack:%02X",data[6],data[7]);
                if(data[7] == 0x00){
                    //当前处理成功，清楚控制标志位
                    Rs485PB20.Strip_A00_07_LSCtrl &= ~Rs485PB20.Strip_A00_07_LSCtrl_Send;
                    Rs485PB20.Strip_A08_15_LSCtrl &= ~Rs485PB20.Strip_A08_15_LSCtrl_Send;
					
					if(Rs485PB20.Strip_LS_CtrlLoopNum >= Rs485PB20.Strip_LS_CtrlLoopNum_Send)
					{
						Rs485PB20.Strip_LS_CtrlLoopNum -= Rs485PB20.Strip_LS_CtrlLoopNum_Send;
					}
					else 
					{
						Rs485PB20.Strip_LS_CtrlLoopNum = 0x00;
					}
                    
					for(uint8_t i = 0; i < 8; i++)
					{
						Rs485PB20.Strip_LSCtrl_Flag[i] &= ~((Rs485PB20.Strip_A00_07_LSCtrl_Send >> (i * 4)) & 0x0f);
					}
					
					for(uint8_t i = 8; i < 16; i++)
					{
						Rs485PB20.Strip_LSCtrl_Flag[i] &= ~((Rs485PB20.Strip_A08_15_LSCtrl_Send >> ((i - 8) * 4)) & 0x0f);
					}
				
					Rs485PB20.Strip_A00_07_LSCtrl_Send = 0x00;
					Rs485PB20.Strip_A08_15_LSCtrl_Send = 0x00;
					Rs485PB20.Strip_LS_CtrlLoopNum_Send = 0x00;
					
					
                }else if(data[7] == 0x01){
                    //当前处于繁忙状态
                    Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
                }
				break;
			#endif
			
			#if RS485_PB20_Relay_Flag
			case PB20_CMD_RELAY_CTRL:    //继电器控制
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 Cmd 0x%02X Ack",data[6]);
				if(data[7] == 0x00){
					//当前处理成功，清楚控制标志位
					Rs485PB20.Relay_A00_07_LoopCtrl &= ~Rs485PB20.Relay_A00_07_LoopCtrl_Send;
                    Rs485PB20.Relay_A08_15_LoopCtrl &= ~Rs485PB20.Relay_A08_15_LoopCtrl_Send;
					
					if(Rs485PB20.Relay_CtrlLoopNum >= Rs485PB20.Relay_CtrlLoopNum_Send)
					{
						Rs485PB20.Relay_CtrlLoopNum -= Rs485PB20.Relay_CtrlLoopNum_Send;
					}
					else 
					{
						Rs485PB20.Relay_CtrlLoopNum = 0x00;
					}
                    
					for(uint8_t i = 0; i < 8; i++)
					{
						Rs485PB20.Relay_LoopCtrl_Flag[i] &= ~((Rs485PB20.Relay_A00_07_LoopCtrl_Send >> (i * 4)) & 0x0f);
					}
					
					for(uint8_t i = 8; i < 16; i++)
					{
						Rs485PB20.Relay_LoopCtrl_Flag[i] &= ~((Rs485PB20.Relay_A08_15_LoopCtrl_Send >> ((i - 8) * 4)) & 0x0f);
					}
				
					Rs485PB20.Relay_A00_07_LoopCtrl_Send = 0x00;
					Rs485PB20.Relay_A08_15_LoopCtrl_Send = 0x00;
					Rs485PB20.Relay_CtrlLoopNum_Send = 0x00;
					
				}else if(data[7] == 0x01){
                    //当前处于繁忙状态
                    Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
                }
				break;
			#endif
				
			default:
				break;
		}
		
	
		switch(data[6])      //巡检状态机切换
		{
			case PB20_CMD_INQUIRE:
				if(Rs485PB20.Check_Flag == DEV_CHECK_OPEN)
				{
					Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 Cmd 0x%02X Ack:%d",data[6],data[37]);
					Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Require Recv Buff:",data,len);
					Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 Bus Vol:%dmV  Ele:%dmA  Power:%dmW",\
					Rs485PB20.Bus_Vol,Rs485PB20.Bus_Ele,Rs485PB20.Bus_Power);
					
					if(data[37] == 0x00)
					{
						Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_OK;    	//PowerBus 总线当前通讯处于空闲状态
						
						if(Rs485PB20.Check_State == FIRSTINQUIRE)
						{
							Rs485PB20.Check_State = OPENONE;
							Rs485PB20.Wait_Tick = SysTick_1ms;
						}
						else if(Rs485PB20.Check_State == SECONDINQUIRE)
						{
							Rs485PB20.Check_State = CHECKONE;
							Rs485PB20.Wait_Tick = SysTick_1ms;
						}
					}else{
						//当前处于繁忙状态
						Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
					}
				}
				break;
			case PB20_CMD_LS_LCTRL:
			case PB20_CMD_RELAY_CTRL:
				if(Rs485PB20.Check_Flag == DEV_CHECK_OPEN)
				{
					if(data[7] == 0x00)
					{
						if(Rs485PB20.Check_State == OPENONE)
						{
							Rs485PB20.Wait_Tick = SysTick_1ms;
							Rs485PB20.Check_State = SECONDINQUIRE;
						}
					}
					else if(data[7] == 0x01)
					{
						//当前处于繁忙状态
						Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
					}
					
				}
				break;
			case PB20_CMD_LS_LLCTRL:
			case PB20_CMD_RELAY_ADDRCTRL:
				if((Rs485PB20.Check_Flag == DEV_CHECK_OPEN) && (Rs485PB20.Check_State == CLOSEALL))
				{
					if(data[7] == 0x00)
					{
						Rs485PB20.Close_State++;
						Rs485PB20.Wait_Tick = SysTick_1ms;
					}
					else if(data[7] == 0x01)
					{
						//当前处于繁忙状态
						Rs485PB20.PB20_Process_State = PB20_CMD_Relpy_Busy;
					}
				}
				break;
			default:break;
		}
		
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&Rs485PB20, sizeof(RS485_PB20_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),dev_addr);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO),dev_addr+Dev_Privately);
			
	}
	else
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PB20 Recv CheckSum Err!!");
	}

	
	return rev;
}


/*******************************************************************************
*@name  Dev_Check_Map_Add
*@para 
*  DevBuf  映射表数组
*@brief  填满映射表
*******************************************************************************/
void Dev_Check_Map_Add(uint8_t *DevBuf)
{
	static uint8_t devtype_last = 0x00;
	DEVCHECKMAP DevCheckMapAdd;
	memset((uint8_t *)&DevCheckMapAdd, 0x00, sizeof(DEVCHECKMAP));    
	
	memcpy((uint8_t *)&DevCheckMapAdd, DevBuf, sizeof(DEVCHECKMAP));   //拷贝核心信息
	
	uint32_t list_addr;

	if(DevActionGlobal.CheckMapDevNum < CheckMapDevNumMax)      
	{ 
		list_addr = SRAM_CheckMap_List_Start_Addr + DevActionGlobal.CheckMapDevNum*sizeof(DEVCHECKMAP);   //拿到新地址

		SRAM_DMA_Write_Buff((uint8_t *)&DevCheckMapAdd, sizeof(DEVCHECKMAP), list_addr);      //接着写入数据
		DevActionGlobal.CheckMapDevNum++;

		if((devtype_last != DevCheckMapAdd.DevType) && (DevActionGlobal.CheckTypeNum < 4))
		{
			devtype_last = DevCheckMapAdd.DevType;
			DevActionGlobal.CheckMapList[DevActionGlobal.CheckTypeNum] = DevCheckMapAdd.DevType;
			DevActionGlobal.CheckTypeNum++;
			Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"新增巡检设备类型:%d, 巡检设备类型总数:%d", DevActionGlobal.CheckTypeNum);
		}

		Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"巡检表设备添加成功,当前节点地址:%08X 当前映射表设备计数:%d ",list_addr ,DevActionGlobal.BlwMapDevNum);		//	
	}
	else
	{
		Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"超过映射表设备数量上限: %d", CheckMapDevNumMax);
	}
}


void PB20_Strip_LoopCtrl(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20,uint8_t LoopNum,uint8_t LightNum,uint8_t DevAddr)
{
	uint8_t lens = 10;
	uint8_t SendBuf[30];
	uint8_t loopnum = 0;
	memset(SendBuf,0,sizeof(SendBuf));
	
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = 0x30;   //设备类型
	SendBuf[3] = BUS_Public->addr;
	SendBuf[7] = PB20_RETRY_TIME;    //重发次数
	
	SendBuf[6] = 0x45;    //CMD
//	for(uint8_t i = 0; i < LoopNum; i++)
	{
		SendBuf[10+3*loopnum] = DevAddr*4 + LoopNum;
		SendBuf[11+3*loopnum] = 0;
		SendBuf[12+3*loopnum] = LightNum;
		loopnum++;
		lens += 3;
	}
	SendBuf[8] = (lens-10)/3;    //回路数量
	SendBuf[9] = 0xF0;    //掉电不保存

	SendBuf[4] = lens;    //长度
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);
	
	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Strip LoopCtrl Buff:",SendBuf,lens);

	/*日志记录*/
//	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);

}





void PB20_Strip_AllClose(Device_Public_Information_G *BUS_Public,RS485_PB20_INFO* Rs485PB20)
{
	uint8_t lens = 83;
	uint8_t SendBuf[lens];
	memset(SendBuf,0,sizeof(SendBuf));
	
	
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = Dev_Rs485_PB20;     //设备类型
	SendBuf[3] = BUS_Public->addr;
	SendBuf[4] = lens;
	SendBuf[6] = PB20_CMD_LS_LLCTRL;
	SendBuf[7] = PB20_RETRY_TIME;    //重发次数
	SendBuf[8] = 10;
	
	SendBuf[9] = 0xFF;
	SendBuf[10] = 0xFF;
	SendBuf[11] = 0xFF;
	SendBuf[12] = 0xFF;
	
	SendBuf[13] = 0xFF;
	SendBuf[14] = 0xFF;
	SendBuf[15] = 0xFF;
	SendBuf[16] = 0xFF;
	
	SendBuf[17] = 0xF0;      //掉电不保存
	SendBuf[18] = 0x00;      //渐变时间
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);	

	MCU485_SendString(BUS_Public->port,SendBuf,lens);
	
	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Strip All Close Buff:",SendBuf,lens);

	/*日志记录*/
//	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);
}



/*******************************************************************************
* Function Name  : BLV_PB20_Relay_Loop_Ctrl_Send 
* Description    : PB20_Relay回路控制发送
* Input          : 
	BUS_Public	 : 公有属性
	Rs485PB20	 : 私有属性
* Return         : None
*******************************************************************************/
void PB20_Relay_LoopCtrl(Device_Public_Information_G *BUS_Public, RS485_PB20_INFO* Rs485PB20,uint8_t LoopNum,uint8_t State,uint8_t DevAddr)
{
	uint8_t lens = 10;
	uint8_t SendBuf[50];
	uint8_t loopnum = 0;
	memset(SendBuf,0,sizeof(SendBuf));
	
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = Dev_Rs485_PB20;   //设备类型
	SendBuf[3] = BUS_Public->addr;
	SendBuf[7] = PB20_RETRY_TIME;    //重发次数
	
	
//	if(Rs485PB20Relay.Ctrl_Flag!=0x00)
	{
		SendBuf[6] = PB20_CMD_RELAY_CTRL;    //CMD
//		for(uint8_t i = 0; i < Rs485PB20Relay.LoopValidNum; i++)
		{
//			if((Rs485PB20Relay.Ctrl_Flag>>i)&0x01)
			{
				SendBuf[10+2*loopnum] = DevAddr*4 + LoopNum;
				SendBuf[11+2*loopnum] = State;
				loopnum++;
				lens += 2;
			}
		}
		SendBuf[8] = (lens-10)/2;    //回路数量
		SendBuf[9] = 0xF0;              //掉电不保存
	}

	SendBuf[4] = lens;    //长度
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);
	
	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Relay Loop Send Buff:",SendBuf,lens);

	/*日志记录*/
//	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);

}



void PB20_Relay_AllClose(Device_Public_Information_G *BUS_Public,RS485_PB20_INFO* Rs485PB20)
{
	uint8_t SendBuf[50];
	memset(SendBuf,0,sizeof(SendBuf));
	
	uint8_t lens = 46;

	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = Dev_Rs485_PB20;     //设备类型
	SendBuf[3] = BUS_Public->addr;
	SendBuf[4] = lens;
	SendBuf[6] = PB20_CMD_RELAY_ADDRCTRL;
	SendBuf[7] = PB20_RETRY_TIME;    //重发次数
	SendBuf[8] = 10;
	SendBuf[9] = 0xFF;
	SendBuf[10] = 0xFF;
	SendBuf[11] = 0xFF;
	SendBuf[12] = 0xFF;
	SendBuf[13] = 0xF0;      //掉电不保存
	memset(&SendBuf[14],2,32);
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);	

	MCU485_SendString(BUS_Public->port,SendBuf,lens);
	
	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 Relay All Close Buff:",SendBuf,lens);

	/*日志记录*/
//	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);
}


void PB20_LED_LoopCtrl(Device_Public_Information_G *BUS_Public,RS485_PB20_INFO* Rs485PB20,uint8_t LoopNum,uint8_t LightNum,uint8_t DevAddr)
{
	uint8_t lens = 10;
	uint8_t SendBuf[50];
//	uint8_t devnum = 0;
	uint8_t loopnum = 0;
	memset(SendBuf,0,sizeof(SendBuf));
	
	SendBuf[0] = 0x00;   //本机地址
	
	if(Rs485PB20->DevSendCnt == 0x00)
	{
		Rs485PB20->DevSendSN++;
		if(Rs485PB20->DevSendSN > 0x0F)	Rs485PB20->DevSendSN = 0x00;
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		SendBuf[PKT_TYPE] |= (Rs485PB20->DevSendSN & 0x0F);
		SendBuf[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	SendBuf[2] = 0x30;   //设备类型
	SendBuf[3] = BUS_Public->addr;
	SendBuf[7] = PB20_RETRY_TIME;    //重发次数
	
	
	SendBuf[6] = 0x35;    //CMD
//	for(uint8_t i = 0; i < Rs485PB20LED.LoopValidNum; i++)
	{
		SendBuf[10+3*loopnum] = DevAddr*4 + LoopNum;
		SendBuf[11+3*loopnum] = 0;
		SendBuf[12+3*loopnum] = LightNum;
		loopnum++;
		lens += 3;
	}
	SendBuf[8] = (lens-10)/3;    //回路数量
	SendBuf[9] = 0xF0;    //掉电不保存

	SendBuf[4] = lens;    //长度
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf,lens,5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);
	
	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"PB20 LED LoopCtrl Buff:",SendBuf,lens);

	/*日志记录*/
//	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,lens);
}




/*******************************************************************************
* Function Name  : Get_BLV_PB20_COMM_Version 
* Description    : 获取PB20 软件版本
* Input          : 
	devaddr		:设备地址
* Return         : 软件版本号
*******************************************************************************/
uint8_t Get_BLV_PB20_COMM_Version(uint32_t devaddr)
{
	if(devaddr == 0x00) return 0xFF;
	uint8_t dev_ver = 0;
	
	RS485_PB20_INFO Rs485PB20;
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO),devaddr+Dev_Privately);
	
	dev_ver = Rs485PB20.soft_version;
	
	return dev_ver;
}

/*******************************************************************************
* Function Name  : Get_BLV_PB20_PS_Voltage 
* Description    : 获取PB 灯带输入电压
* Input          : 
	devaddr		:设备地址
* Return         : 软件版本号
*******************************************************************************/
uint16_t Get_BLV_PB20_PS_Voltage(uint32_t devaddr)
{
	if(devaddr == 0x00) return 0xFF;
	uint16_t dev_vol = 0;
	
	RS485_PB20_INFO Rs485PB20;
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO),devaddr+Dev_Privately);
	
	dev_vol = Rs485PB20.PS_vol;
	
	return dev_vol;
}

/*******************************************************************************
* Function Name  : Get_BLV_PB20_BUS_Voltage 
* Description    : 获取CSIO BUS总线输入电压
* Input          : 
	devaddr		:设备地址
* Return         : 软件版本号
*******************************************************************************/
uint16_t Get_BLV_PB20_BUS_Voltage(uint32_t devaddr)
{
	if(devaddr == 0x00) return 0xFF;
	uint16_t dev_vol = 0;
	
	RS485_PB20_INFO Rs485PB20;
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO),devaddr+Dev_Privately);
	
	dev_vol = Rs485PB20.Bus_Vol;
	
	return dev_vol;
}

/*******************************************************************************
* Function Name  : Get_BLV_PB20_BUS_Current 
* Description    : 获取CSIO BUS总线输出电流
* Input          : 
	devaddr		:设备地址
* Return         : 软件版本号
*******************************************************************************/
uint16_t Get_BLV_PB20_BUS_Current(uint32_t devaddr)
{
	if(devaddr == 0x00) return 0xFF;
	uint16_t dev_vol = 0;
	
	RS485_PB20_INFO Rs485PB20;
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485PB20,sizeof(RS485_PB20_INFO),devaddr+Dev_Privately);
	
	dev_vol = Rs485PB20.Bus_Ele;
	
	return dev_vol;
}

#endif

