


#include "BLV_485_Dev_PWMFun.h"
#include "string.h"
#include "SPI_SRAM.h"
#include "usart.h"
#include "check_fun.h"
#include "DBG.h"
#include "rw_logging.h"
#include "SRAM_Variable_Address.h"

#include "includes.h"

/*PWM调光驱动代码*/
#define PWM_OUT_CH_MAX  0x04   //PWM调光有4路

#define REPEATSENDTIMEMAX         0x03  //重发次数上限
#define PWMUPLIGHT              100    //最高亮80
#define PWMDOWNLIGHT            0    //最低亮20

#define PWMGRADUALTIME         30   //30  即300ms
#define PWMSnMax               15     //最大Sn号
#define DEVPWMTYPE               24           //PWM类型

/*整体调光宏定义开始*/
#define GLOBAL_STEP_VALUE   0x14   //步进20
#define GLOBAL_MAX_VALUE    0x64   //最大亮度
#define GLOBAL_MIN_VALUE    0x14   //最小亮度

/*整体调光宏定义结束*/

/*本地函数调用开始*/
uint8_t BLW_PWMCycleCtrl(uint32_t dev_addr); 
uint8_t BLW_Rs485_PWM_Check(uint32_t dev_addr,uint32_t data_addr,uint16_t len);
void BLW_Rs485_PWM_4LOOP_Ctrl(Device_Public_Information_G *BUS_Public, RS485_LED_INFO* Rs485PWMInfo);
//void BLW_PWM_Group_Ctrl(uint32_t CfgDevAddIn, uint16_t DevInputAddr,uint32_t devaddr, uint32_t CtrlFlag, uint8_t CtrlNum,uint16_t *start);
//uint16_t BLW_PWM_Group_Read(uint32_t devaddr, uint8_t SceneType, uint32_t ReadFlag, uint8_t ReadNum,uint16_t *start);
void BLW_Rs485_PWM_4LOOP_Read(Device_Public_Information_G *BUS_Public, RS485_LED_INFO* Rs485PWMInfo);
void BLW_Rs485_PWM_4LOOP_Way_Ctrl(Device_Public_Information_G *BUS_Public, RS485_LED_INFO* Rs485PWMInfo);
void BLW_PWM110_GlobalValue_Set(Device_Public_Information_G *BUS_Public, RS485_LED_INFO* Rs485LEDInfo);

/*本地函数调用结束*/

/*******************************************************************************
* Function Name  : BLW_RS485_PWM_Data_Init 
* Description    : 添加设备到链表 - 轮询设备
* Input          : 
	type	: 添加的设备类型
	addr	: 添加的设备地址
	polling_cf		：设备的轮询数据发送回调函数
	processing_cf	：设备的数据处理回调函数
* Return         : None
*******************************************************************************/
void BLW_RS485_PWM_Data_Init(Device_Public_Information_G *BUS_Public, RS485_LED_INFO *Rs485PWM, uint16_t LoopNum)
{

	BUS_Public->polling_cf = (uint32_t)&BLW_PWMCycleCtrl;
	BUS_Public->processing_cf = (uint32_t)&BLW_Rs485_PWM_Check;
	
	/*初始化LED调光初始值*/
	if(LoopNum >= PWM_OUT_CH_MAX)   //输出回路超过范围
	{
		Rs485PWM->LEDLoopValidNum = PWM_OUT_CH_MAX;
	}
	else if(0x00 == LoopNum)
	{
		Rs485PWM->LEDLoopValidNum = 0x01;
	}
	else              //未超过范围
	{
		Rs485PWM->LEDLoopValidNum = LoopNum;
	}
	Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"添加PWM设备, 回路数:%d", Rs485PWM->LEDLoopValidNum);

}



/*******************************************************************************
* Function Name  : BLW_PWMCycleCtrl 
* Description    : BLWPWM调光轮询兼控制发送函数
*******************************************************************************/
uint8_t BLW_PWMCycleCtrl(uint32_t dev_addr) 
{
//	uint16_t temp = 0;
//	uint8_t crc_val = 0;
	uint8_t i;     //用于遍历所有回路
	uint8_t Ret = RS485OCCUPYNOTIME;
	Device_Public_Information_G BUS_Public;
	RS485_LED_INFO Rs485PWMInfo;
	uint8_t KeepFlag = 0x00;

	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),dev_addr);	//拷贝所有共有数据
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485PWMInfo,sizeof(RS485_LED_INFO),dev_addr+Dev_Privately);
	
	for(i = 0; i < Rs485PWMInfo.LEDLoopValidNum; i++)
	{
		if(Rs485PWMInfo.DevSendBuf_last[i] != Rs485PWMInfo.DevSendBuf[i])
		{
			Rs485PWMInfo.LEDCtrlFlag = 0x01;
			Rs485PWMInfo.LEDCtrlCnt = REPEATSENDTIMEMAX;
//			Rs485PWMInfo.PWMUpFlag = 0x01;
			Rs485PWMInfo.DevReadBuf[i] = 0x01;         //状态变化置一
			memcpy(Rs485PWMInfo.DevSendBuf_last, Rs485PWMInfo.DevSendBuf, Rs485PWMInfo.LEDLoopValidNum);   //同步这组数据

			break;
		}
	}
	
	for(i = 0; i < Rs485PWMInfo.LEDLoopValidNum; i++)
	{
		if(Rs485PWMInfo.DevCtrlWayBuf_last[i] != Rs485PWMInfo.DevCtrlWayBuf[i])  //Rs485PWMInfo.DevCtrlWayBuf_last[i] 
		{
			Rs485PWMInfo.DevCtrlWayBuf_last[i] = Rs485PWMInfo.DevCtrlWayBuf[i];//方式控制，只能一路一路控制		
			Rs485PWMInfo.LEDWayCtrlFlag |= (0x01<<i);   //相应的方式控制标志置一
			Rs485PWMInfo.LEDWayCtrlCnt = REPEATSENDTIMEMAX;
//			Rs485PWMInfo.DevCtrlWayBuf[i] = 0x00;
//			Rs485PWMInfo.WayCtrli = i;
//			memcpy(Rs485PWMInfo.DevCtrlWayBuf_last, Rs485PWMInfo.DevCtrlWayBuf, Rs485PWMInfo.PWMLoopValidNum);   //同步这组数据
//			break;
		} 
	}
	
	if(Rs485PWMInfo.Dim_Global_Value != DevActionGlobal.DimGlobalValue)     //2025-07-15,全局亮度比较
	{
		Rs485PWMInfo.Dim_Global_Value = DevActionGlobal.DimGlobalValue;
	}
	
	if(Rs485PWMInfo.Dim_Global_Value_Last != Rs485PWMInfo.Dim_Global_Value)     //全局亮度
	{
		Rs485PWMInfo.Dim_Global_Value_Last = Rs485PWMInfo.Dim_Global_Value;
		Rs485PWMInfo.Dim_GV_Flag |= (0x01<<7);
	}
	
	
	if((Rs485PWMInfo.LEDUpLightLimitLast != Rs485PWMInfo.LEDUpLightLimit) || (Rs485PWMInfo.LEDDownLightLimitLast != Rs485PWMInfo.LEDDownLightLimit))         //可调上限
	{	
		Rs485PWMInfo.LEDUpLightLimitLast = Rs485PWMInfo.LEDUpLightLimit;
		Rs485PWMInfo.Dim_GV_Flag |= (0x01<<6);
		
		Rs485PWMInfo.LEDDownLightLimitLast = Rs485PWMInfo.LEDDownLightLimit;
		Rs485PWMInfo.Dim_GV_Flag |= (0x01<<5);
	}
	
//	if(Rs485PWMInfo.LEDDownLightLimitLast != Rs485PWMInfo.LEDDownLightLimit)    //可调下限
//	{
//		Rs485PWMInfo.LEDDownLightLimitLast = Rs485PWMInfo.LEDDownLightLimit;
//		Rs485PWMInfo.Dim_GV_Flag |= (0x01<<5);
//	}
	

	
	if(0x00 != Rs485PWMInfo.Dim_GV_Flag)                    //2024-1-30
	{
		BLW_PWM110_GlobalValue_Set(&BUS_Public, &Rs485PWMInfo);      //全局亮度设置
		Ret = RS485OCCUPYTIME;
	}
	else if(0x01 == Rs485PWMInfo.LEDCtrlFlag)
	{
		if(0x00 != Rs485PWMInfo.LEDCtrlCnt)
		{
			Rs485PWMInfo.LEDCtrlCnt--; 
		}
		else
		{
			Rs485PWMInfo.LEDCtrlFlag = 0x00;
		}
		BLW_Rs485_PWM_4LOOP_Ctrl(&BUS_Public, &Rs485PWMInfo);           //4路控制，状态控制
		Ret = RS485OCCUPYTIME;
	}
	else if(0x00 != Rs485PWMInfo.LEDWayCtrlFlag)
	{
		if(0x00 != Rs485PWMInfo.LEDWayCtrlCnt)
		{
			Rs485PWMInfo.LEDWayCtrlCnt--; 
		}
		else
		{
			Rs485PWMInfo.LEDWayCtrlFlag = 0x00;
		}
		if(0x00 != Rs485PWMInfo.LEDWayCtrlFlag)
		{
			BLW_Rs485_PWM_4LOOP_Way_Ctrl(&BUS_Public, &Rs485PWMInfo);
			Ret = RS485OCCUPYTIME;	
		}	
		else
		{
			KeepFlag = 0x01;      //为0保存
		}			
	}	
	else if(0x01 == Rs485PWMInfo.LEDLightnessReadFlag)
	{
		if(0x00 != Rs485PWMInfo.LEDLightnessReadCnt)
		{
			Rs485PWMInfo.LEDLightnessReadCnt--; 
		}
		else
		{
			Rs485PWMInfo.LEDLightnessReadFlag = 0x00;
		}
		BLW_Rs485_PWM_4LOOP_Read(&BUS_Public, &Rs485PWMInfo);           //4路调光亮度读取
		Ret = RS485OCCUPYTIME;
	}
	
	if(RS485OCCUPYTIME == Ret)
	{
		KeepFlag = 0x01;
		if(Rs485PWMInfo.DevSendCnt > REPEATSENDTIMEMAX)
		{
			if(Rs485PWMInfo.DevOffline != DEV_IS_OFFLINE)
			{	
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"DEV_PWMTYPE LogInfo_Device_Offline...........");
				LOG_Device_Online_Record(BUS_Public.type, BUS_Public.addr, LogInfo_Device_Offline);	//记录设备离线
			}
			Rs485PWMInfo.DevOffline = DEV_IS_OFFLINE;   //离线
			if(Rs485PWMInfo.DevOffline != Rs485PWMInfo.DevOfflineLast)	//当前在线状态不等于上一次在线状态
			{
				Rs485PWMInfo.DevOfflineLast = Rs485PWMInfo.DevOffline;	//更新上一次在线状态
				Write_Device_Fault_State(BUS_Public.type,BUS_Public.addr,In_ErrFun_LineState,DEV_IS_OFFLINE);	//保存设备在线状态到SRAM
			}
			if(0x00 != Rs485PWMInfo.Dim_GV_Flag)
			{
				Rs485PWMInfo.Dim_GV_Flag = 0x00;
			}
		}
		else
		{
			Rs485PWMInfo.DevSendCnt++;   //
		}
		Rs485PWMInfo.inquire_tick = SysTick_1ms;
		
		/*通讯统计记录*/
		BLV_Communication_Record(&Rs485PWMInfo.comm_record,0x01,0x00);
		

		//Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"PWM crc_val:%02X\r\n",crc_val);
	}
	
	if(0x01 == KeepFlag)
	{
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&Rs485PWMInfo, sizeof(RS485_LED_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),dev_addr);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&Rs485PWMInfo,sizeof(RS485_LED_INFO),dev_addr+Dev_Privately);
	}

	return Ret;
}

#define RECDATALENMAX   24   //接收数据最大长度

#define IsMyData     0x00
#define IsNotMyData  0x01
/*******************************************************************************
* Function Name  : BLW_Rs485_PWM_Check 
* Description    : BLWPWM调光接收数据处理函数
* Input          : 
	dev_addr	: 设备信息地址
	data_addr	: 数据地址
	len			：数据长度
* Return         : 
	0x00：处理成功
	0x01：处理失败
*******************************************************************************/
uint8_t BLW_Rs485_PWM_Check(uint32_t dev_addr,uint32_t data_addr,uint16_t len)
{
	uint8_t rev = IsNotMyData;
//	uint8_t temp;  //保存命令类型和数据长度
	RS485_LED_INFO Rs485PWM;
	uint8_t data[RECDATALENMAX];
	Device_Public_Information_G BUS_Public;
	
//	uint8_t PWM_addr = SRAM_Read_Byte(dev_addr+Dev_Addr);
//	uint8_t crc_val = SRAM_Read_Word(data_addr+5);        //保存校验
	
	if(len > RECDATALENMAX)
	{
//		Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"PWM接收数据长度超出范围!!\r\n");
		return rev;     //长度
	}
	
	SRAM_DMA_Read_Buff(data,len,data_addr);   //拷贝485数据
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),dev_addr);				
		
	
	if(data[0] != BUS_Public.addr)	   //地址不对
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PWM设备地址不对!!");
		return rev;				//校验文件头
	}

	
	if(data[5] == CheckSum_Overlook_Check(data, len, 5))   //校验通过
	{
		SRAM_DMA_Read_Buff((uint8_t *)&Rs485PWM,sizeof(RS485_LED_INFO),dev_addr+Dev_Privately);
//		temp = SRAM_Read_Byte(data_addr + 6);
		
		switch(data[6])  
		{
			case 0x31:
			case 0x34:
			case 0x30:
			case 0x35:
				if(Rs485PWM.DevOffline == DEV_IS_OFFLINE)
				{
					Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"DEV_PWMTYPE LogInfo_Device_Online...........");
					LOG_Device_Online_Record(BUS_Public.type, BUS_Public.addr,LogInfo_Device_Online);	//记录设备在线
				}
				
				BLV_Communication_Record(&Rs485PWM.comm_record,0x02,0x01);		//记录通讯成功
				rev = IsMyData;
				Rs485PWM.DevSendCnt = 0x00;
				Rs485PWM.DevOffline = DEV_IS_ONLINE;    //设备在线
				if(Rs485PWM.DevOffline != Rs485PWM.DevOfflineLast)	//当前在线状态不等于上一次在线状态
				{
					Rs485PWM.DevOfflineLast = Rs485PWM.DevOffline;	//更新上一次在线状态
					Write_Device_Fault_State(BUS_Public.type,BUS_Public.addr,In_ErrFun_LineState,DEV_IS_ONLINE);	//保存设备在线状态到SRAM
				}
				break;			
		}
		switch(data[6])
		{
			case 0x31:
				Rs485PWM.LEDCtrlFlag = 0x00;
				/*日志记录*/
				LOG_Device_COMM_Control_Reply_Record(BUS_Public.port,BUS_Public.baud,data,len);
					
				break;
			case 0x34:
				Rs485PWM.LEDWayCtrlFlag = 0x00;
				/*日志记录*/
				LOG_Device_COMM_Control_Reply_Record(BUS_Public.port,BUS_Public.baud,data,len);
								
				break;
			case 0x30:
				memcpy(Rs485PWM.LEDLightRelease, &data[12], Rs485PWM.LEDLoopValidNum);//松开保存亮度
				memcpy(Rs485PWM.DevSendBuf, &data[12], Rs485PWM.LEDLoopValidNum);
//			BLW_Rs485_PWM_4LOOP_Lightness_Get(data, CfgDevAdd);
				Rs485PWM.LEDLightnessReadFlag = 0x00;					
				break;
			case 0x35:
				Rs485PWM.Dim_GV_Flag = 0x00;
				break;
		}
		

		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&Rs485PWM, sizeof(RS485_LED_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),dev_addr);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&Rs485PWM,sizeof(RS485_LED_INFO),dev_addr+Dev_Privately);
		
		
	}
//	else {
////		Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"SRAM_CRC16 Fail ,crc_val:%02X SRAM_CRC16:%02X!!\r\n",crc_val,SRAM_CRC16(data_addr,len - 2));
//		
//	}
	
	return rev;
}




#define PWMCTRLSENDLEN    18
/**
	* @name BLW 4路 集中调光控制函数
	* @para
	*   dev_addr     设备起始地址   
	* @return         无
  * @attention      发送循环里调用，变量已经被判断
	*/
void BLW_Rs485_PWM_4LOOP_Ctrl(Device_Public_Information_G *BUS_Public, RS485_LED_INFO* Rs485PWMInfo)
{
//  RS485_LED_INFOP Rs485PWMInfo;       //调光局部变量
//	uint8_t i;
//	uint8_t port = SRAM_Read_Byte(dev_addr+Dev_port);      //通讯端口
//	uint8_t DevAddr = SRAM_Read_Byte(dev_addr+Dev_Addr);   //设备地址
	                  //己方地址 发送类型 设备类型      收方地址 LEN             校验和   CMD  开4通道 渐变0.1s 保存   CH8    CH7    CH6    CH5    CH4    CH3    CH2    CH1 
	uint8_t SendBuf[18] = {0x00,   0x00,  DEVPWMTYPE,    0x01,   PWMCTRLSENDLEN,  0x18,  0x21,  0x0f,   0x64,   0x00,  0x00,  0x00,  0x00,  0x00,  0x50,  0x50,  0x50,  0x50};
			
	
	SendBuf[1] |= BLV_SN_Get(&Rs485PWMInfo->LEDSn, 0, PWMSnMax);

		
	SendBuf[3] = BUS_Public->addr;   //
//	SendBuf[8] = PWMGRADUALTIME;       //调光渐变时间
	SendBuf[8] = Rs485PWMInfo->PWM_Set_Time;       //调光渐变时间
	Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PWM调光渐变时间:%d\r\n",Rs485PWMInfo->PWM_Set_Time);	
//	for(i = 0; i < Rs485PWMInfo->PWMLoopValidNum; i++)
//	{
//		SendBuf[16-i] = Rs485PWMInfo->DevSendBuf[i];
//	}
	memcpy(&SendBuf[14], &Rs485PWMInfo->DevSendBuf[0], Rs485PWMInfo->LEDLoopValidNum);  //指示灯控制
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf, PWMCTRLSENDLEN, 5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,PWMCTRLSENDLEN);
		
	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,PWMCTRLSENDLEN);
	
//	RS485_Port_SendFun(CfgDevAdd, SendBuf, PWMCTRLSENDLEN, BLWPWMCTRLTIMEOUT);  		
	
}



#define PWMWAYCTRLLEN   11
/*向上循环调光*/
/**
	* @name BLW 4路 向上循环调光
	* @para
	*   CfgDevAdd     设备节点   
  *   PWMLoop       回路地址   0~3 
	* @return         无
  * @attention      发送循环里调用，变量已经被判断
	*/
void BLW_Rs485_PWM_4LOOP_Way_Ctrl(Device_Public_Information_G *BUS_Public, RS485_LED_INFO* Rs485PWMInfo)
{

	                               //己方地址  发送类型 设备类型，    收方地址 LEN           校验和   CMD  开4通道 模式  方向  步进
	uint8_t SendBuf[PWMWAYCTRLLEN] = {0x00,   0x00,  DEVPWMTYPE,     0x01,   PWMWAYCTRLLEN,  0xBD,  0x24,  0x00,  0x01, 0x02, 0x01};
	uint8_t i;
	
	
	SendBuf[1] |= BLV_SN_Get(&Rs485PWMInfo->LEDSn, 0, PWMSnMax);

	SendBuf[3] = BUS_Public->addr;
	

	for(i = 0; i < Rs485PWMInfo->LEDLoopValidNum; i++)
	{
		if((Rs485PWMInfo->LEDWayCtrlFlag>>i)&0x01)
		{
			SendBuf[7] |= 0x01<<(3-i);   //通道MASK
			switch(Rs485PWMInfo->DevCtrlWayBuf[i])
			{
				case CFG_Dev_CtrlWay_Is_Dim_CycleUp:  //向上循环
					SendBuf[8] = 0x01;									//填入控制方式
					SendBuf[9] = 0x00;      
					break;
				case CFG_Dev_CtrlWay_Is_Dim_CycleDown:
					SendBuf[8] = 0x01;  
					SendBuf[9] = 0x01;
					break;
				case CFG_Dev_CtrlWay_Is_Dim_Up:      //向上调光
					SendBuf[8] = 0x00;
					SendBuf[9] = 0x00;     		
					break;
				case CFG_Dev_CtrlWay_Is_Dim_Down:	   //向下调光
					SendBuf[8] = 0x00;
					SendBuf[9] = 0x01;     		
					break;
				case CFG_Dev_CtrlWay_Is_Dim_Stop:    //停止调光
					SendBuf[8] = 0x02;
					break;
				default:   //其他情况直接返回
					return ;
			}
			SendBuf[10] = Rs485PWMInfo->DevCtrlWayContect[i];   //填入控制
		}
	}
	
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf, PWMWAYCTRLLEN, 5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,PWMWAYCTRLLEN);
		
	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,PWMWAYCTRLLEN);
	
}


#define  PWMREADLEN     7

/**
	* @name BLW 4路 集中调光亮度读取函数
	* @para
	*   CfgDevAdd     设备节点   
	* @return         无
  * @attention      发送循环里调用，变量已经被判断
	*/
void BLW_Rs485_PWM_4LOOP_Read(Device_Public_Information_G *BUS_Public, RS485_LED_INFO* Rs485PWMInfo)
{

									         	//己方地址 发送类型 设备类型      收方地址 LEN         校验和   CMD
	uint8_t SendBuf[PWMREADLEN] = {0x00,   0x00,  DEVPWMTYPE,    0x01,   PWMREADLEN,  0xD8,   0x20};
//	RS485_LED_INFOP Rs485PWMInfo;       //调光局部变量
//	Rs485PWMInfo = CfgDevAdd->DevDataStruct;

	
	SendBuf[1] |= BLV_SN_Get(&Rs485PWMInfo->LEDSn, 0, PWMSnMax);

	
	SendBuf[3] = BUS_Public->addr;  

	SendBuf[5] = CheckSum_Overlook_Check(SendBuf, PWMREADLEN, 5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,PWMREADLEN);
		
	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,PWMREADLEN);
	
//	SendBuf[5] = BLW_SOR_Negate(SendBuf, PWMREADLEN, 5);	
//	RS485_Port_SendFun(CfgDevAdd, SendBuf, PWMREADLEN, 100);  		
	
}

//全局亮度设置
void BLW_PWM110_GlobalValue_Set(Device_Public_Information_G *BUS_Public, RS485_LED_INFO* Rs485LEDInfo)
{
	uint8_t lens = 0x0C;
	uint8_t SendBuf[lens];
	memset(SendBuf,0,sizeof(SendBuf));
	
	SendBuf[0] = 0x00;                                               //已方地址	
	SendBuf[1] = BLV_SN_Get(&Rs485LEDInfo->LEDSn, 0, PWMSnMax);      //帧
	SendBuf[2] = DEVPWMTYPE;                                         //类型
	SendBuf[3] = BUS_Public->addr;     
	SendBuf[4] = lens;                                               //长度
	SendBuf[6] = 0x25;                                               //Cmd
	
	SendBuf[7] = Rs485LEDInfo->Dim_GV_Flag;
	SendBuf[8] = Rs485LEDInfo->Dim_Global_Value;                     //全局亮度
	SendBuf[9] = Rs485LEDInfo->LEDUpLightLimit;                      //可调上限
	SendBuf[10] = Rs485LEDInfo->LEDDownLightLimit;                   //可调下限
	SendBuf[11] = 0x01;                                              //掉电保存
	
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf, lens, 5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,lens);

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

}


