
/**
  ******************************************************************************
  * @file    BLV_485_Dev_A9LDFun.c
  * @author  BLW RCU  development Team
  * @version SongHan
  * @date    2021年12月08日
  * @brief  
	*    A9LD调光扩展模块 每个模块有四路
	* @log  202205261640 SongHan  增加调光回路限制
  ******************************************************************************
  */



#include "BLV_485_Dev_A9LDFun.h"



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



/*A9LD调光驱动代码*/

#define A9LD_OUT_CH_MAX  0x04   //A9LD调光有4路
#define REPEATSENDTIMEMAX         0x03  //重发次数上限
#define A9LDUPLIGHT              100    //最高亮80
#define A9LDDOWNLIGHT            0    //最低亮20

#define A9LDGRADUALTIME         30   //30  即300ms

#define A9LDSnMin               0      //最小Sn号
#define A9LDSnMax               15     //最大Sn号

#define DEVA9LDTYPE               03           //A9LD类型  

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

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

/*本地函数调用开始*/
uint8_t BLW_A9LDCycleCtrl(uint32_t dev_addr);           //发送
uint8_t BLW_Rs485_A9LD_Check(uint32_t dev_addr,uint32_t data_addr,uint16_t len);  //接收
void BLW_Rs485_A9LD_Ctrl(Device_Public_Information_G *BUS_Public, RS485_LED_INFO* Rs485A9LDInfo);      //状态控制
void BLW_Rs485_A9LD_Way_Ctrl(Device_Public_Information_G *BUS_Public, RS485_LED_INFO* Rs485LEDInfo);  //方式控制
void BLW_Rs485_A9LD_Read(Device_Public_Information_G *BUS_Public, RS485_LED_INFO* Rs485LEDInfo);   //读取当前亮度
void BLW_A9LD_GlobalValue_Set(Device_Public_Information_G *BUS_Public, RS485_LED_INFO* Rs485LEDInfo);  //全局亮度设置


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

/*******************************************************************************
* Function Name  : BLW_RS485_A9LD_Data_Init 
* Description    : 添加设备到链表 - 轮询设备
* Input          : 
	type	: 添加的设备类型
	addr	: 添加的设备地址
	polling_cf		：设备的轮询数据发送回调函数
	processing_cf	：设备的数据处理回调函数
* Return         : None
*******************************************************************************/
void BLW_RS485_A9LD_Data_Init(Device_Public_Information_G *BUS_Public, RS485_LED_INFO *Rs485LED, uint16_t LoopNum)
{
	BUS_Public->polling_cf = (uint32_t)&BLW_A9LDCycleCtrl;
	BUS_Public->processing_cf = (uint32_t)&BLW_Rs485_A9LD_Check;
	
	/*初始化LED调光初始值*/
	if(LoopNum >= A9LD_OUT_CH_MAX)   //输出回路超过范围
	{
		Rs485LED->LEDLoopValidNum = A9LD_OUT_CH_MAX;
	}
	else if(0x00 == LoopNum)
	{
		Rs485LED->LEDLoopValidNum = 0x01;
	}
	else              //未超过范围
	{
		Rs485LED->LEDLoopValidNum = LoopNum;
	}
	
	Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"添加A9LD设备，回路:%d", Rs485LED->LEDLoopValidNum);

//	Add_POLL_Device_To_List2(BUS_Public,(uint8_t *)Rs485LED,sizeof(RS485_LED_INFO));
}



/*******************************************************************************
* Function Name  : BLW_LEDCycleCtrl 
* Description    : BLWLED调光轮询兼控制发送函数
*******************************************************************************/
uint8_t BLW_A9LDCycleCtrl(uint32_t dev_addr) 
{
	uint8_t i;     //用于遍历所有回路
	uint8_t Ret = RS485OCCUPYNOTIME;
	Device_Public_Information_G BUS_Public;
	RS485_LED_INFO Rs485LEDInfo;
	uint8_t KeepFlag = 0x00;
	uint32_t temp_val = 0;
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),dev_addr);	//拷贝所有共有数据
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485LEDInfo,sizeof(RS485_LED_INFO),dev_addr+Dev_Privately);
	
	for(i = 0; i < Rs485LEDInfo.LEDLoopValidNum; i++)
	{
		if(Rs485LEDInfo.DevSendBuf_last[i] != Rs485LEDInfo.DevSendBuf[i])
		{
			Rs485LEDInfo.LEDCtrlFlag = 0x01;
			Rs485LEDInfo.LEDCtrlCnt = REPEATSENDTIMEMAX;
			Rs485LEDInfo.DevReadBuf[i] = 0x01;         //状态变化置一
			memcpy(Rs485LEDInfo.DevSendBuf_last, Rs485LEDInfo.DevSendBuf, Rs485LEDInfo.LEDLoopValidNum);   //同步这组数据
			memcpy(Rs485LEDInfo.DevSendBufNext, Rs485LEDInfo.DevSendBuf, Rs485LEDInfo.LEDLoopValidNum);   //同步这组数据

			break;
		} 
	}
	
	for(i = 0; i < Rs485LEDInfo.LEDLoopValidNum; i++)
	{
		if(Rs485LEDInfo.DevCtrlWayBuf_last[i] != Rs485LEDInfo.DevCtrlWayBuf[i])  // 0x00
		{
			Rs485LEDInfo.LEDWayCtrlFlag |=(0x01<<i);   //相应的方式控制标志置一
//			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"调光控制方式置位:%d\r\n",Rs485LEDInfo.LEDWayCtrlFlag);  //
			
			Rs485LEDInfo.LEDWayCtrlCnt = REPEATSENDTIMEMAX;
			Rs485LEDInfo.DevCtrlWayBuf_last[i] = Rs485LEDInfo.DevCtrlWayBuf[i];
		} 
	}

    if(Rs485LEDInfo.Dim_Global_Value != DevActionGlobal.DimGlobalValue)     //2025-07-15,YYW,全局亮度比较
    {
        Rs485LEDInfo.Dim_Global_Value = DevActionGlobal.DimGlobalValue;
		Rs485LEDInfo.Dim_Global_Value_Last = Rs485LEDInfo.Dim_Global_Value;
		
        Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"A9LDFun 全局亮度改变: %d",Rs485LEDInfo.Dim_Global_Value); 
		
		/*A9LD 设定全局亮度有问题，不设置全局亮度 直接设置回路亮度*/
		for(i = 0; i < Rs485LEDInfo.LEDLoopValidNum; i++)
		{
			//根据全局亮度设置每个回路亮度
			Rs485LEDInfo.LEDCtrlFlag = 0x01;
			Rs485LEDInfo.LEDCtrlCnt = REPEATSENDTIMEMAX;
			Rs485LEDInfo.DevReadBuf[i] = 0x01;         //状态变化置一
			
			temp_val = Rs485LEDInfo.DevSendBuf[i];
			Rs485LEDInfo.DevSendBufNext[i] = (temp_val * DevActionGlobal.DimGlobalValue) / 100;
			//Rs485LEDInfo.DevSendBuf_last[i] = Rs485LEDInfo.DevSendBuf[i];
			
			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"A9LDFun-CH%d亮度:%d - %d",i,Rs485LEDInfo.DevSendBufNext[i],Rs485LEDInfo.DevSendBuf[i]); 
			
		}
		
    }
	
	if(Rs485LEDInfo.Dim_Global_Value_Last != Rs485LEDInfo.Dim_Global_Value)     //全局亮度
	{
		Rs485LEDInfo.Dim_Global_Value_Last = Rs485LEDInfo.Dim_Global_Value;
		Rs485LEDInfo.Dim_GV_Flag |= (0x01<<7);
	}
	
	
	if((Rs485LEDInfo.LEDUpLightLimitLast != Rs485LEDInfo.LEDUpLightLimit) || (Rs485LEDInfo.LEDDownLightLimitLast != Rs485LEDInfo.LEDDownLightLimit))         //可调上限
	{	
		Rs485LEDInfo.LEDUpLightLimitLast = Rs485LEDInfo.LEDUpLightLimit;
		Rs485LEDInfo.Dim_GV_Flag |= (0x01<<6);
		
		Rs485LEDInfo.LEDDownLightLimitLast = Rs485LEDInfo.LEDDownLightLimit;
		Rs485LEDInfo.Dim_GV_Flag |= (0x01<<5);
	}
	
//	if(Rs485LEDInfo.LEDDownLightLimitLast != Rs485LEDInfo.LEDDownLightLimit)    //可调下限
//	{
//		Rs485LEDInfo.LEDDownLightLimitLast = Rs485LEDInfo.LEDDownLightLimit;
//		Rs485LEDInfo.Dim_GV_Flag |= (0x01<<5);
//	}
	

	
	if(0x00 != Rs485LEDInfo.Dim_GV_Flag)                    //2024-1-30
	{
		BLW_A9LD_GlobalValue_Set(&BUS_Public, &Rs485LEDInfo);      //全局亮度设置
		Ret = RS485OCCUPYTIME;
	}
	else if(0x01 == Rs485LEDInfo.LEDCtrlFlag)
	{
		if(0x00 != Rs485LEDInfo.LEDCtrlCnt)
		{
			Rs485LEDInfo.LEDCtrlCnt--; 
		}
		else
		{
			Rs485LEDInfo.LEDCtrlFlag = 0x00;
		}
		BLW_Rs485_A9LD_Ctrl(&BUS_Public, &Rs485LEDInfo);           //状态控制
		Ret = RS485OCCUPYTIME;
	}
	else if(0x00 != Rs485LEDInfo.LEDWayCtrlFlag)
	{		

		if(0x00 != Rs485LEDInfo.LEDWayCtrlCnt)
		{
			Rs485LEDInfo.LEDWayCtrlCnt--; 
		}
		else
		{
			Rs485LEDInfo.LEDWayCtrlFlag = 0x00;
		}

		if(0x00 != Rs485LEDInfo.LEDWayCtrlFlag)
		{
			BLW_Rs485_A9LD_Way_Ctrl(&BUS_Public, &Rs485LEDInfo);	 //方式控制
			Ret = RS485OCCUPYTIME;  //非0发送  
		}		
		else
		{
			KeepFlag = 0x01;  //为0保存
		}
		
	}	
	else if(Rs485LEDInfo.LEDLightnessReadFlag)//  
	{

		if(0x00 != Rs485LEDInfo.LEDLightnessReadCnt)
		{
			Rs485LEDInfo.LEDLightnessReadCnt--; 
		}
		else
		{
			Rs485LEDInfo.LEDLightnessReadFlag = 0x00;
		}
		BLW_Rs485_A9LD_Read(&BUS_Public, &Rs485LEDInfo);           //读取
		Ret = RS485OCCUPYTIME;
	}
	
	if(RS485OCCUPYTIME == Ret)
	{
		KeepFlag = 0x01;
		if(Rs485LEDInfo.DevSendCnt > REPEATSENDTIMEMAX)
		{
			if(Rs485LEDInfo.DevOffline != DEV_IS_OFFLINE)
			{
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"Rs485A9LED DEV_IS_OFFLINE");
				LOG_Device_Online_Record(DEV_LEDTYPE,BUS_Public.addr,LogInfo_Device_Offline);	//记录设备离线
			}
			Rs485LEDInfo.DevOffline = DEV_IS_OFFLINE;   //离线
			if(Rs485LEDInfo.DevOffline != Rs485LEDInfo.DevOfflineLast)	//当前在线状态不等于上一次在线状态
			{
				Rs485LEDInfo.DevOfflineLast = Rs485LEDInfo.DevOffline;	//更新上一次在线状态
				Write_Device_Fault_State(BUS_Public.type,BUS_Public.addr,In_ErrFun_LineState,DEV_IS_OFFLINE);	//保存设备在线状态到SRAM
			}
			if(0x00 != Rs485LEDInfo.Dim_GV_Flag)
			{
				Rs485LEDInfo.Dim_GV_Flag = 0x00;
			}
		}
		else
		{
			Rs485LEDInfo.DevSendCnt++;   //
		}
		Rs485LEDInfo.inquire_tick = SysTick_1ms;
		
		/*通讯统计*/
		BLV_Communication_Record(&Rs485LEDInfo.comm_record,0x01,0x00);
	}
	
	if(0x01 == KeepFlag)
	{
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&Rs485LEDInfo, 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 *)&Rs485LEDInfo,sizeof(RS485_LED_INFO),dev_addr+Dev_Privately);
		
	}

	return Ret;
}

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

#define IsMyData     0x00
#define IsNotMyData  0x01
/*******************************************************************************
* Function Name  : BLW_Rs485_LED_Check 
* Description    : BLWLED调光接收数据处理函数
* Input          : 
	dev_addr	: 设备信息地址
	data_addr	: 数据地址
	len			：数据长度
* Return         : 
	0x00：处理成功
	0x01：处理失败
*******************************************************************************/
uint8_t BLW_Rs485_A9LD_Check(uint32_t dev_addr,uint32_t data_addr,uint16_t len)
{
	uint8_t rev = IsNotMyData;
//	uint16_t temp;  //保存命令类型和数据长度
	
	Device_Public_Information_G BUS_Public;
	RS485_LED_INFO Rs485LED;
	uint8_t data[RECDATALENMAX];
	
//	uint8_t LED_addr = SRAM_Read_Byte(dev_addr+Dev_Addr);  //485地址
//	uint8_t crc_val = SRAM_Read_Word(data_addr+5);        //保存校验
	if(len > RECDATALENMAX)
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"接收数据长度超出范围!!");
		return rev;     //长度
	}
	
	if(len < 6) 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) || (DEVA9LDTYPE != (data[2]))
		|| (len != (data[4]))
	   )	   //地址不对
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"A9LD设备地址不对或者类型不对或者长度不对!!");
		return rev;				//校验文件头
	}

	
	if(data[5] == CheckSum_Overlook_Check(data, len, 5))   //校验通过
	{
		SRAM_DMA_Read_Buff((uint8_t *)&Rs485LED,sizeof(RS485_LED_INFO),dev_addr+Dev_Privately);
//		temp = SRAM_Read_Byte(data_addr + 6);
		
		switch(data[6])  
		{
			case 0x31:      //控制回复
			case 0x32:		//方式回复
			case 0x30:		//读取回复
			case 0x33:      //全局亮度设置回复
				rev = IsMyData;
			
				if(Rs485LED.DevOffline != DEV_IS_ONLINE)
				{
					Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"Rs485LED DEV_IS_ONLINE");
					LOG_Device_Online_Record(DEV_LEDTYPE,BUS_Public.addr,LogInfo_Device_Online);	//记录设备在线
				}
				Rs485LED.DevSendCnt = 0x00;
				Rs485LED.DevOffline = DEV_IS_ONLINE;    //设备在线
				if(Rs485LED.DevOffline != Rs485LED.DevOfflineLast)	//当前在线状态不等于上一次在线状态
				{
					Rs485LED.DevOfflineLast = Rs485LED.DevOffline;	//更新上一次在线状态
					Write_Device_Fault_State(BUS_Public.type,BUS_Public.addr,In_ErrFun_LineState,DEV_IS_ONLINE);	//保存设备在线状态到SRAM
				}
				BLV_Communication_Record(&Rs485LED.comm_record,0x02,0x01);		//记录通讯成功
				break;			
		}
		switch(data[6])
		{
			case 0x31:
				Rs485LED.LEDCtrlFlag = 0x00;
				/*日志记录*/
				LOG_Device_COMM_Control_Reply_Record(BUS_Public.port,BUS_Public.baud,data,len);
				break;
			case 0x32:
				Rs485LED.LEDWayCtrlFlag = 0x00;
				/*日志记录*/
				LOG_Device_COMM_Control_Reply_Record(BUS_Public.port,BUS_Public.baud,data,len);
				break;
			case 0x30:
//			BLW_Rs485_A9LD_Lightness_Get(data, CfgDevAdd);
				/*检测到状态改变，才保存*/
				Rs485LED.LEDLightnessReadFlag = 0x00;	

				Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"A9LD Now Buff:",data,len);			
				break;
			case 0x33:
				Rs485LED.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 *)&Rs485LED, 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 *)&Rs485LED,sizeof(RS485_LED_INFO),dev_addr+Dev_Privately);
			
	}
	
	return rev;
}




#define A9LDCTRLSENDLEN    14
/**
	* @name BLW 4路 集中调光控制函数
	* @para
	*   dev_addr     设备起始地址   
	* @return         无
  * @attention      发送循环里调用，变量已经被判断
	*/
void BLW_Rs485_A9LD_Ctrl(Device_Public_Information_G *BUS_Public, RS485_LED_INFO* Rs485LEDInfo)
{
	uint8_t i;
	                     //己方地址 发送类型 设备类型      收方地址     LEN              校验和   CMD  开4通道 渐变0.1s 保存   CH4    CH3    CH2    CH1 
	uint8_t SendBuf[18] = {0x00,   0x00,  DEVA9LDTYPE,    0x01,   A9LDCTRLSENDLEN,  0x18,  0x21,  0x0f,   0x64,   0x00,  0x50,  0x50,  0x50,  0x50};
		
	
	SendBuf[1] |= BLV_SN_Get(&Rs485LEDInfo->LEDSn, 0, A9LDSnMax);

		
	SendBuf[3] = BUS_Public->addr;   //
	SendBuf[8] = Rs485LEDInfo->A9LD_Set_Time;       //调光渐变时间
//	SendBuf[8] = led_setime.A9LD_LED_SetTime;
	Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"A9LD Dim_Time:%d \r\n",Rs485LEDInfo->A9LD_Set_Time);
	
	for(i = 0; i < Rs485LEDInfo->LEDLoopValidNum; i++)
	{
		SendBuf[13-i] = Rs485LEDInfo->DevSendBufNext[i];				//2025-08-22 修改解决全局调光问题
	}
//	memcpy(&SendBuf[14], &Rs485LEDInfo->DevSendBuf[0], Rs485LEDInfo->LEDLoopValidNum);  //指示灯控制
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf, A9LDCTRLSENDLEN, 5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,A9LDCTRLSENDLEN);

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


#define A9LDWAYCTRLLEN   11
/*向上循环调光*/
/**
	* @name BLW 4路 向上循环调光
	* @para
	*   CfgDevAdd     设备节点   
  *   PBLEDLoop       回路地址   0~3 
	* @return         无
  * @attention      发送循环里调用，变量已经被判断
  *己方地址 发送类型 设备类型 收方地址  整包长度 校验和 命令字  mask
  *  00        09        03      01        0B       51     22    0F    01    00    64
	*/
void BLW_Rs485_A9LD_Way_Ctrl(Device_Public_Information_G *BUS_Public, RS485_LED_INFO* Rs485LEDInfo)
{
	
	uint8_t i;
	                                     //己方地址  发送类型 设备类型，    收方地址 LEN           校验和   CMD  开4通道 模式  方向  步进
	uint8_t   SendBuf[A9LDWAYCTRLLEN];// = {0x00,   0x00,  DEVA9LDTYPE,     0x01,   A9LDWAYCTRLLEN,  0xBD,  0x24,  0x00,  0x01, 0x02, 0x01};
	

	SendBuf[0] = 0x00;                                                   //已方地址
	SendBuf[1] = BLV_SN_Get(&Rs485LEDInfo->LEDSn, 0, A9LDSnMax);   //帧
  SendBuf[2] = DEVA9LDTYPE;       //类型
	SendBuf[3] = BUS_Public->addr;
	SendBuf[4] = A9LDWAYCTRLLEN;    //长度
	SendBuf[6] = 0x22;                 //命令，方式调光命令
	SendBuf[7] = Rs485LEDInfo->LEDWayCtrlFlag;   //通道MASK Bit0~Bit3分别对应回路1到回路4

	for(i = 0; i < Rs485LEDInfo->LEDLoopValidNum; i++)
	{
		if((Rs485LEDInfo->LEDWayCtrlFlag>>i)&0x01)
		{
			switch(Rs485LEDInfo->DevCtrlWayBuf_last[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;
					SendBuf[9] = 0x00;                 //无意义
					break;
			}
			break;   //只调用一次
		}
	}
  SendBuf[10] = Rs485LEDInfo->DevCtrlWayContect[i];   //填入控制
	
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf, A9LDWAYCTRLLEN, 5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,A9LDWAYCTRLLEN);
	
	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(BUS_Public->port,BUS_Public->baud,SendBuf,A9LDCTRLSENDLEN);
}

#define  A9LDREADLEN     7
/**
	* @name BLW 4路 集中调光亮度读取函数
	* @para
	*   CfgDevAdd     设备节点   
	* @return         无
  * @attention      发送循环里调用，变量已经被判断
	*/
void BLW_Rs485_A9LD_Read(Device_Public_Information_G *BUS_Public, RS485_LED_INFO* Rs485LEDInfo)
{
									         	      //己方地址 发送类型 设备类型      收方地址 LEN         校验和   CMD
	uint8_t SendBuf[A9LDREADLEN]; // = {0x00,   0x00,  DEVA9LDTYPE,    0x01,   A9LDREADLEN,  0xD8,   0x20};

	SendBuf[0] = 0x00;                                                   //已方地址	
	SendBuf[1] = BLV_SN_Get(&Rs485LEDInfo->LEDSn, 0, A9LDSnMax);   //帧
  SendBuf[2] = DEVA9LDTYPE;       //类型
	SendBuf[3] = BUS_Public->addr;
	SendBuf[4] = A9LDREADLEN;    //长度
	SendBuf[6] = 0x20;
	
	SendBuf[5] = CheckSum_Overlook_Check(SendBuf, A9LDREADLEN, 5);	
		
	MCU485_SendString(BUS_Public->port,SendBuf,A9LDREADLEN);	
}
//全局亮度设置
void BLW_A9LD_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, A9LDSnMax);     //帧
	SendBuf[2] = DEVA9LDTYPE;                                        //类型
	SendBuf[3] = BUS_Public->addr;                                   //Addr
	SendBuf[4] = lens;                                               //长度
	SendBuf[6] = 0x23;                                               //Cmd
	
	SendBuf[7] = Rs485LEDInfo->Dim_GV_Flag;
	SendBuf[8] = 100;                     //全局亮度
	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);	

}
