#include "BLV_485_Dev_XiaoBaoFun.h"

#include "includes.h"

#include <string.h>
#include "BLV_485_Protocol.h"
#include "SPI_SRAM.h"
#include "usart.h"
#include "CH57x_common.h"
#include "check_fun.h"
#include "rw_logging.h"
#include "SRAM_Variable_Address.h"
#include "DBG.h"
/*小宝驱动代码*/

#define XIAOBAO_REPEATSENDTIMEMAX			0x01  	//本设备重发次数上限

/*******************************************************************************
* Fail Description	: 485设备 - 小宝驱动文件
* 
*******************************************************************************/
uint32_t Add_BlwMap_To_List(Struct_CFG_BLW_Map_Add *BlwMapAdd);
void  BLWMap_Dev_Ctrl(uint8_t *buf);

void BLV_485_Dev_XiaoBao_Init(uint8_t devaddr)
{
	Device_Public_Information_G BUS_Public;
	RS485_XIAOBAO_INFO Rs485_xiaobao_Info;       //小宝局部变量
	
	memset(&BUS_Public,0,sizeof(Device_Public_Information_G));
	memset(&Rs485_xiaobao_Info,0,sizeof(RS485_XIAOBAO_INFO));
	
	BUS_Public.addr = devaddr;			//设备地址
	BUS_Public.type = DEV_XiaoBao_Type;		//设备类型
	BUS_Public.port = Active_Port;			//设备发送端口
	BUS_Public.baud = 9600;			//设备发送波特率
	BUS_Public.retry_num = XIAOBAO_REPEATSENDTIMEMAX;		//设备数据重发次数
	BUS_Public.wait_time = 0x0064;		//设备数据发送等待回复时间
	BUS_Public.polling_cf = (uint32_t)&BLV_Rs485_Dev_XiaoBao_CycleDis;
	BUS_Public.processing_cf = (uint32_t)&BLV_Rs485_Dev_XiaoBao_Check;
	Rs485_xiaobao_Info.DevAddr = devaddr;
	Rs485_xiaobao_Info.DevOffline = Rs485_xiaobao_Info.DevOfflineLast = DEV_IS_LINEUNINIT;   //在线状态初始化
//	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][1] = 0x00;
//	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][2] = Rs485_xiaobao_Info.DevConfigSN++;
//	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][3] = 0x15;
//	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][4] = Rs485_xiaobao_Info.DevAddr;  //语音模块地址
//	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5] = 0x07;  											//长度
//	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][7] = 0x20;  											//命令
//	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][0] = Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5];    //包长度
//	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][6] = CheckSum_Overlook_Check(&Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][1], \
//	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][0], 5);   //和校验取反
//	
//	Rs485_xiaobao_Info.Write_Id++;
//	if(Rs485_xiaobao_Info.Write_Id >= XiaoBao_BUFF_NUM)
//	{
//		Rs485_xiaobao_Info.Write_Id = 0;
//	}
	
	Add_ACT_Device_To_List2(&BUS_Public, (uint8_t *)&Rs485_xiaobao_Info, sizeof(RS485_XIAOBAO_INFO));
}

void BLV_485_Dev_XiaoBao_Logic_Init(LOGICFILE_DEVICE_INFO *dev_info,uint8_t *data,uint16_t data_len)
{
	Device_Public_Information_G BUS_Public;
	RS485_XIAOBAO_INFO Rs485_xiaobao_Info;       //小宝局部变量
	
	memset(&BUS_Public,0,sizeof(Device_Public_Information_G));
	memset(&Rs485_xiaobao_Info,0,sizeof(RS485_XIAOBAO_INFO));
	
	BUS_Public.addr = dev_info->addr;			//设备地址
	BUS_Public.type = dev_info->type;		//设备类型
	BUS_Public.port = Active_Port;			//设备发送端口
	BUS_Public.baud = dev_info->baud;		    //设备发送波特率9600
	BUS_Public.Protocol = dev_info->version;
	BUS_Public.retry_num = XIAOBAO_REPEATSENDTIMEMAX;		//设备数据重发次数
	BUS_Public.wait_time = 0x00C8;		//设备数据发送等待回复时间     2024-12-31  由100ms改成200ms   100ms时小宝设备有时解析失败
	BUS_Public.polling_cf = (uint32_t)&BLV_Rs485_Dev_XiaoBao_CycleDis;
	BUS_Public.processing_cf = (uint32_t)&BLV_Rs485_Dev_XiaoBao_Check;
	Rs485_xiaobao_Info.DevAddr = dev_info->addr;
	Rs485_xiaobao_Info.DevOffline = Rs485_xiaobao_Info.DevOfflineLast = DEV_IS_LINEUNINIT;   //在线状态初始化
//	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][1] = 0x00;
//	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][2] = Rs485_xiaobao_Info.DevConfigSN++;
//	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][3] = 0x15;
//	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][4] = Rs485_xiaobao_Info.DevAddr;  //语音模块地址
//	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5] = 0x07;  											//长度
//	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][7] = 0x20;  											//命令
//	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][0] = Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5];    //包长度
//	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][6] = CheckSum_Overlook_Check(&Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][1], \
//	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][0], 5);   //和校验取反
//	
//	Rs485_xiaobao_Info.Write_Id++;
//	if(Rs485_xiaobao_Info.Write_Id >= XiaoBao_BUFF_NUM)
//	{
//		Rs485_xiaobao_Info.Write_Id = 0;
//	}
	
	Add_ACT_Device_To_List2(&BUS_Public, (uint8_t *)&Rs485_xiaobao_Info, sizeof(RS485_XIAOBAO_INFO));
}
/*******************************************************************************
* Function Name  : BLV_Rs485_Dev_XiaoBao_CycleDis 
* Description    : 小宝485数据发送处理函数，包括重发

* Return         : 
	0x01：有数据需要发送
	0x00：没有数据需要发送
*******************************************************************************/
uint8_t BLV_Rs485_Dev_XiaoBao_CycleDis(uint32_t DevAdd)  
{
	Device_Public_Information_G BUS_Public;
	RS485_XIAOBAO_INFO Rs485_xiaobao_Info;       //小宝局部变量

	uint8_t temp;
	uint8_t Ret = RS485OCCUPYNOTIME;
	
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),DevAdd);		
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485_xiaobao_Info, sizeof(RS485_XIAOBAO_INFO), DevAdd+Dev_Privately);/*拷贝设备私有信息*/
	
	/*判断设备是否有数据需要发送*/
	
	if(Rs485_xiaobao_Info.DevCtrlFlag != 0x01 && Rs485_xiaobao_Info.Read_Id != Rs485_xiaobao_Info.Write_Id)
	{
		Rs485_xiaobao_Info.DevCtrlFlag = 0x01;
		Rs485_xiaobao_Info.DevSendCnt = 0;        //重发计数清零
	}
	
	if(0x01 == Rs485_xiaobao_Info.DevCtrlFlag)
	{
		if(Rs485_xiaobao_Info.DevSendCnt > XIAOBAO_REPEATSENDTIMEMAX)
		{
			if(Rs485_xiaobao_Info.DevOffline != DEV_IS_OFFLINE)
			{
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"Rs485_xiaobao DEV_IS_OFFLINE");
				LOG_Device_Online_Record(DEV_XiaoBao_Type,BUS_Public.addr,LogInfo_Device_Offline);	//记录设备离线
			}
			Rs485_xiaobao_Info.DevOffline = DEV_IS_OFFLINE;		//判为离线
			Rs485_xiaobao_Info.DevCtrlFlag = 0;
			if(Rs485_xiaobao_Info.DevOffline != Rs485_xiaobao_Info.DevOfflineLast)	//当前在线状态不等于上一次在线状态
			{
				Rs485_xiaobao_Info.DevOfflineLast = Rs485_xiaobao_Info.DevOffline;	//更新上一次在线状态
				Write_Device_Fault_State(BUS_Public.type,BUS_Public.addr,In_ErrFun_LineState,DEV_IS_OFFLINE);	//保存设备在线状态到SRAM
			}
			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"XiaoBao resend fail\n");
			
			Rs485_xiaobao_Info.Read_Id++;
			if(Rs485_xiaobao_Info.Read_Id >= XiaoBao_BUFF_NUM)
			{
				Rs485_xiaobao_Info.Read_Id = 0;
			}
		}
		else 
		{
			Rs485_xiaobao_Info.DevSendCnt++;   				//发送次数累计
			temp = SRAM_Read_Byte(DevAdd+Dev_port);
			MCU485_SendString(temp, &Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Read_Id][1], Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Read_Id][0]);   //发送
			
			/*日志记录*/
			LOG_Device_COMM_Send_Control_Record2(temp,DevAdd+Dev_baud,&Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Read_Id][1], Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Read_Id][0]);
			
			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"XiaoBao send data:");
			for(uint8_t i=0; i< Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Read_Id][0]; i++)
			{
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," %02X\n", Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Read_Id][1+i]);
			}
			
			if(Rs485_xiaobao_Info.Dev_Addr_CtrlFlag == 1)   //设置地址不会回复
			{
				Rs485_xiaobao_Info.Dev_Addr_CtrlFlag = 0;   //设置地址标记清零
				Rs485_xiaobao_Info.DevCtrlFlag = 0;
				Rs485_xiaobao_Info.DevSendCnt = 0;        //重发计数清零
				
				Rs485_xiaobao_Info.Read_Id++;
				if(Rs485_xiaobao_Info.Read_Id >= XiaoBao_BUFF_NUM)
				{
					Rs485_xiaobao_Info.Read_Id = 0;
				}
			}
			
			/*通讯统计*/
			BLV_Communication_Record(&Rs485_xiaobao_Info.comm_record,0x01,0x00);
		}
		
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&Rs485_xiaobao_Info, sizeof(RS485_XIAOBAO_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),DevAdd);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&Rs485_xiaobao_Info,sizeof(RS485_XIAOBAO_INFO),DevAdd+Dev_Privately);
				
	}
	
	return Ret;
}


/*******************************************************************************
* Function Name  : BLV_Rs485_Dev_XiaoBao_Check 
* Description    : BLW触摸开关485接收处理函数

* Return         : 
	0x01：数据处理失败
	0x00：数据处理成功
*******************************************************************************/
uint8_t BLV_Rs485_Dev_XiaoBao_Check(uint32_t DevAdd ,uint32_t Data_addr, uint16_t DataLen) 
{
	uint8_t temp = 0;
	uint8_t ret = 0x01;
	uint8_t receive[XiaoBao_BUFF_Size]	= {0};
	
	Device_Public_Information_G BUS_Public;
	RS485_XIAOBAO_INFO Rs485_xiaobao_Info;       //小宝局部变量
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),DevAdd);		
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485_xiaobao_Info,sizeof(RS485_XIAOBAO_INFO),DevAdd+Dev_Privately);/*拷贝设备私有信息*/
	
	if(DataLen > XiaoBao_BUFF_Size || DataLen < 5)  return 0x01;    //小宝回复最低5个字节
	SRAM_DMA_Read_Buff(receive, DataLen, Data_addr);
	
	Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"XiaoBao receive data:");
	for(uint8_t i=0; i< DataLen; i++)
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit," %02X\n", receive[i]);
	}
	
	if(receive[DataLen-1] == 0xFF && receive[DataLen-2] == (uint8_t)(~CheckSum(&receive[1], DataLen-3)))   //尾、及和校验正确
	{
		if(receive[0] == 0xFC && receive[2] == 0x41)    //模块对于播放反馈音控制命令的回复
		{
			temp++;
			if(Rs485_xiaobao_Info.DevOffline == DEV_IS_OFFLINE)
			{
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"Rs485_xiaobao DEV_IS_ONLINE");
				LOG_Device_Online_Record(DEV_XiaoBao_Type,BUS_Public.addr,LogInfo_Device_Online);	//记录设备离线
			}
			Rs485_xiaobao_Info.DevCtrlFlag = 0x00;
			Rs485_xiaobao_Info.DevSendCnt = 0;        //重发计数清零
			Rs485_xiaobao_Info.DevOffline = DEV_IS_ONLINE;
			if(Rs485_xiaobao_Info.DevOffline != Rs485_xiaobao_Info.DevOfflineLast)	//当前在线状态不等于上一次在线状态
			{
				Rs485_xiaobao_Info.DevOfflineLast = Rs485_xiaobao_Info.DevOffline;	//更新上一次在线状态
				Write_Device_Fault_State(BUS_Public.type,BUS_Public.addr,In_ErrFun_LineState,DEV_IS_ONLINE);	//保存设备在线状态到SRAM
			}
			BLV_Communication_Record(&Rs485_xiaobao_Info.comm_record,0x02,0x01);		//记录通讯成功
			
			Rs485_xiaobao_Info.Read_Id++;
			if(Rs485_xiaobao_Info.Read_Id >= XiaoBao_BUFF_NUM)
			{
				Rs485_xiaobao_Info.Read_Id = 0;
			}
			
			/*日志记录*/
			LOG_Device_COMM_Control_Reply_Record(BUS_Public.port, BUS_Public.baud,receive,DataLen);
		}
		else if(receive[2] == 0x35)    //语音模块发的控制命令功能码
		{
			temp++;
			if(Rs485_xiaobao_Info.DevOffline == DEV_IS_OFFLINE)
			{
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"Rs485_xiaobao DEV_IS_ONLINE");
				LOG_Device_Online_Record(DEV_XiaoBao_Type,BUS_Public.addr,LogInfo_Device_Online);	//记录设备离线
			}
			Rs485_xiaobao_Info.DevCtrlFlag = 0x00;
			Rs485_xiaobao_Info.DevSendCnt = 0;        //重发计数清零
			Rs485_xiaobao_Info.DevOffline = DEV_IS_ONLINE;
			if(Rs485_xiaobao_Info.DevOffline != Rs485_xiaobao_Info.DevOfflineLast)	//当前在线状态不等于上一次在线状态
			{
				Rs485_xiaobao_Info.DevOfflineLast = Rs485_xiaobao_Info.DevOffline;	//更新上一次在线状态
				Write_Device_Fault_State(BUS_Public.type,BUS_Public.addr,In_ErrFun_LineState,DEV_IS_ONLINE);	//保存设备在线状态到SRAM
			}
			BLV_Communication_Record(&Rs485_xiaobao_Info.comm_record,0x02,0x01);		//记录通讯成功
			
			BlwMap_AllDev_Ctrl(&receive[3]);
			memset(Rs485_xiaobao_Info.Ctrl_Buf, 0, XiaoBao_BUFF_Size);
			memcpy(Rs485_xiaobao_Info.Ctrl_Buf, &receive[3], DataLen-5);  //将数据拷贝到控制BUFF
			
			/*日志记录*/
			LOG_Device_COMM_Control_Reply_Record(BUS_Public.port, BUS_Public.baud,receive,DataLen);
		}
		
		ret = 0x00;
	}
	else if(receive[2] == 0x15 && receive[5] == CheckSum_Overlook_Check(receive, DataLen, 5))  //模块对于配置命令的回复
	{
		temp++;
		if(Rs485_xiaobao_Info.DevOffline == DEV_IS_OFFLINE)
		{
			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"Rs485_xiaobao DEV_IS_ONLINE");
			LOG_Device_Online_Record(DEV_XiaoBao_Type,BUS_Public.addr,LogInfo_Device_Online);	//记录设备在线
		}
		Rs485_xiaobao_Info.DevCtrlFlag = 0x00;
		Rs485_xiaobao_Info.DevSendCnt = 0;        //重发计数清零
		Rs485_xiaobao_Info.DevOffline = DEV_IS_ONLINE;
		if(Rs485_xiaobao_Info.DevOffline != Rs485_xiaobao_Info.DevOfflineLast)	//当前在线状态不等于上一次在线状态
		{
			Rs485_xiaobao_Info.DevOfflineLast = Rs485_xiaobao_Info.DevOffline;	//更新上一次在线状态
			Write_Device_Fault_State(BUS_Public.type,BUS_Public.addr,In_ErrFun_LineState,DEV_IS_ONLINE);	//保存设备在线状态到SRAM
		}
		BLV_Communication_Record(&Rs485_xiaobao_Info.comm_record,0x02,0x01);		//记录通讯成功
		
		Rs485_xiaobao_Info.Read_Id++;
		if(Rs485_xiaobao_Info.Read_Id >= XiaoBao_BUFF_NUM)
		{
			Rs485_xiaobao_Info.Read_Id = 0;
		}
		
		if(receive[6] == 0x30 && receive[4] == 0x0C)   //查询命令回复
		{
			temp++;
			Rs485_xiaobao_Info.mode = receive[8];   //识别模式
			Rs485_xiaobao_Info.vol = receive[9];   	//音量
			Rs485_xiaobao_Info.tone = receive[10];   //反馈音状态
			Rs485_xiaobao_Info.version = receive[11];   //词条版本
			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"xiaobao mode:%d, vol:%d, tone:%d, version:%d\r\n", receive[8], receive[9], receive[10], receive[11]);
		}
		else if(receive[6] == 0x42)    //查询地址
		{
			Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"xiaobao addr：%d", receive[7]);
		}
		
		/*日志记录*/
		LOG_Device_COMM_Control_Reply_Record(BUS_Public.port, BUS_Public.baud,receive,DataLen);
		ret = 0x00;
	}
//	else
//	{
//		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"xiaobao check fail!\r\n");
//	}
	
	if(temp)
	{
		
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&Rs485_xiaobao_Info, sizeof(RS485_XIAOBAO_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),DevAdd);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&Rs485_xiaobao_Info,sizeof(RS485_XIAOBAO_INFO),DevAdd+Dev_Privately);
				
	}
	
	return ret;
}

/*******************************************************************************
* Function Name  : BLV_Rs485_Dev_XiaoBao_Control_Pair_Feedback_Tone 
* Description    : 小宝 控制播放配对反馈音
* Input          : 
	dev_addr	:设备地址
	start		:控制反馈音状态 0x00:进入配对 0x01:配对成功 0x02:配对失败
*******************************************************************************/
void BLV_Rs485_Dev_XiaoBao_Control_Pair_Feedback_Tone(uint32_t dev_addr, uint8_t start)
{
	if(dev_addr == 0x00) return;
	Device_Public_Information_G BUS_Public;
	RS485_XIAOBAO_INFO Rs485_xiaobao_Info;
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),dev_addr);		
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485_xiaobao_Info,sizeof(RS485_XIAOBAO_INFO),dev_addr+Dev_Privately);
	
	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][0] = 10;
	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][1] = 0xF7;
	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][2] = 0x00;
	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][3] = 0x31;
	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][4] = 0x01;
	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5] = 0x1F;
	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][6] = 0x01;
	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][7] = 0x03;
	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][8] = start;
	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][9] = ~CheckSum(&Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][2], 7);   //和校验
	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][10] = 0xFF;
	
	Rs485_xiaobao_Info.Write_Id++;
	if(Rs485_xiaobao_Info.Write_Id >= XiaoBao_BUFF_NUM)
	{
		Rs485_xiaobao_Info.Write_Id = 0;
	}
	
	BUS_Public.check = 0x00;
	BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&Rs485_xiaobao_Info, sizeof(RS485_XIAOBAO_INFO));
	SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),dev_addr);/*将数据保存*/
	SRAM_DMA_Write_Buff((uint8_t *)&Rs485_xiaobao_Info,sizeof(RS485_XIAOBAO_INFO),dev_addr+Dev_Privately);
					
	
}

/*******************************************************************************
* Function Name  : BLV_Rs485_Dev_XiaoBao_Control_Config 
* Description    : 小宝 设置配置参数
* Input          : 
	dev_addr	:设备地址
	cmd		    :命令
	start     :附加参数
*******************************************************************************/
void BLV_Rs485_Dev_XiaoBao_Control_Config(uint32_t dev_addr, XIAOBAO_CONFIG_CMD_E cmd, uint8_t start)
{
	if(dev_addr == 0x00) return;
	Device_Public_Information_G BUS_Public;
	RS485_XIAOBAO_INFO Rs485_xiaobao_Info;
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),dev_addr);		
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485_xiaobao_Info,sizeof(RS485_XIAOBAO_INFO),dev_addr+Dev_Privately);
	
	switch(cmd)
	{
		case CMD_PLAY_WELCOME:       //播放欢迎词
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][4] = Rs485_xiaobao_Info.DevAddr;  //语音模块地址
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5] = 0x0B;  											//长度
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][7] = 0x22;  											//命令
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][8] = 0x05;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][9] = 0x00;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][10] = 0x00;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][11] = 0x00;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][0] = Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5];
		break;
		case CMD_PLAY_DOORBELL:       //播放门铃
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][4] = Rs485_xiaobao_Info.DevAddr;  //语音模块地址
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5] = 0x0B;  											//长度
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][7] = 0x22;  											//命令
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][8] = 0x04;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][9] = 0x00;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][10] = 0x00;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][11] = 0x00;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][0] = Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5];
		break;
		case CMD_DISTINGUISH_OFF:     //关闭语音识别
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][4] = Rs485_xiaobao_Info.DevAddr;  //语音模块地址
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5] = 0x0B;  											//长度
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][7] = 0x22;  											//命令
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][8] = 0x01;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][9] = 0x01;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][10] = 0x00;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][11] = 0x00;  											//参数
			
		break;
		case CMD_DISTINGUISH_ON:     //开启语音识别
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][4] = Rs485_xiaobao_Info.DevAddr;  //语音模块地址
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5] = 0x0B;  											//长度
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][7] = 0x22;  											//命令
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][8] = 0x01;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][9] = 0x00;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][10] = 0x00;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][11] = 0x00;  											//参数
			
		break;
		case CMD_VOLUME_UP:          //音量加
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][4] = Rs485_xiaobao_Info.DevAddr;  //语音模块地址
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5] = 0x0B;  											//长度
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][7] = 0x23;  											//命令
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][8] = 0x01;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][9] = 0x02;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][10] = 0x00;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][11] = 0x02;  											//参数
			
		break;
		case CMD_VOLUME_DOWN:         //音量减
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][4] = Rs485_xiaobao_Info.DevAddr;  //语音模块地址
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5] = 0x0B;  											//长度
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][7] = 0x23;  											//命令
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][8] = 0x01;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][9] = 0x02;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][10] = 0x00;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][11] = 0x01;  											//参数
			
		break;
		case CMD_SET_VOLUME:         //设置音量
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][4] = Rs485_xiaobao_Info.DevAddr;  //语音模块地址
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5] = 0x0B;  											//长度
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][7] = 0x23;  											//命令
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][8] = 0x01;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][9] = 0x01;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][10] = start;  											//设置音量值
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][11] = 0x00;  											//参数
			
		break;
		case CMD_QUERY_CONFIG:       //查询配置参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][4] = Rs485_xiaobao_Info.DevAddr;  //语音模块地址
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5] = 0x07;  											//长度
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][7] = 0x20;  											//命令
			
		break;
		case CMD_SET_ADDR:          //设置地址
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][4] = 0xFF;  											//广播地址
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5] = 0x08;  											//长度
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][7] = 0x41;  											//命令
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][8] = start;  											//设置的地址
			
			Rs485_xiaobao_Info.Dev_Addr_CtrlFlag = 1;                //设置地址控制标记，这条数据没有回复
		break;
		case CMD_READ_ADDR:         //读取地址
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][4] = 0xFF;  											//广播地址
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5] = 0x07;  											//长度
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][7] = 0x42;  											//命令
			
		break;
		
		case CMD_TONE_OFF:          //关闭提示音（反馈音）
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][4] = Rs485_xiaobao_Info.DevAddr;  //语音模块地址
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5] = 0x0B;  											//长度
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][7] = 0x22;  											//命令
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][8] = 0x01;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][9] = 0x08;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][10] = 0x00;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][11] = 0x00;  											//参数
			
		break;
		case CMD_TONE_ON:          //开启提示音（反馈音）
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][4] = Rs485_xiaobao_Info.DevAddr;  //语音模块地址
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5] = 0x0B;  											//长度
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][7] = 0x22;  											//命令
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][8] = 0x01;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][9] = 0x07;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][10] = 0x00;  											//参数
			Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][11] = 0x00;  											//参数
			
		break;
		default: return;
	}
	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][0] = Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][5];    //包长
	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][1] = 0x00;
	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][2] = Rs485_xiaobao_Info.DevConfigSN++;
	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][3] = 0x15;
	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][6] = CheckSum_Overlook_Check(&Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][1], \
	Rs485_xiaobao_Info.DevSendBuf[Rs485_xiaobao_Info.Write_Id][0], 5);   //和校验取反
	
	Rs485_xiaobao_Info.Write_Id++;
	if(Rs485_xiaobao_Info.Write_Id >= XiaoBao_BUFF_NUM)
	{
		Rs485_xiaobao_Info.Write_Id = 0;
	}
	
	BUS_Public.check = 0x00;
	BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&Rs485_xiaobao_Info, sizeof(RS485_XIAOBAO_INFO));
	SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),dev_addr);/*将数据保存*/
	SRAM_DMA_Write_Buff((uint8_t *)&Rs485_xiaobao_Info,sizeof(RS485_XIAOBAO_INFO),dev_addr+Dev_Privately);
	
}
/*******************************************************************************
*@name  Voice_Map_Dev_Add
*@para 
*  DevBuf  映射表数组
*@brief  填满映射表
*******************************************************************************/
void Voice_Map_Dev_Add(uint8_t *DevBuf)
{
	Struct_CFG_BLW_Map_Add BlwMapAdd;
	memset((uint8_t *)&BlwMapAdd, 0x00, sizeof(BlwMapStructLen));    
	
	memcpy((uint8_t *)&BlwMapAdd.BlwMapCore, DevBuf, BlwMapStructCoreLen);   //拷贝核心信息
	//其他参数信息得到
	switch(BlwMapAdd.BlwMapCore.DevType)
	{
		case 0x00:   //场景
			BlwMapAdd.CfgActionAdd = DevAction_No_Get(BlwMapAdd.BlwMapCore.DevLoopAddr);//根据场景号找到相应动作的地址
			break;
		default:     //其他设备
			BlwMapAdd.CfgDevAdd = Find_AllDevice_List_Information(BlwMapAdd.BlwMapCore.DevType, BlwMapAdd.BlwMapCore.DevAddr);
			break;
	}
	Add_BlwMap_To_List(&BlwMapAdd);//添加到映射表链表	
}


/*******************************************************************************
*@name  BlwMap_Dev_Add
*@para 
*  DevBuf  映射表数组
*  DevNum 设备数量
*@brief  填满映射表
*******************************************************************************/
void BlwMap_Dev_Add(uint8_t *DevBuf, uint8_t DevNum)
{
	uint16_t i;  //遍历
	
	Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"准备添加设备到映射表设备数量: %d", DevNum);		//	

	for(i = 0; i < DevNum; i++)
	{
		{
			Struct_CFG_BLW_Map_Add BlwMapAdd;
			memset((uint8_t *)&BlwMapAdd, 0x00, sizeof(BlwMapStructLen));    
			
			memcpy((uint8_t *)&BlwMapAdd.BlwMapCore, &DevBuf[i*BlwMapStructCoreLen], BlwMapStructCoreLen);   //拷贝核心信息
			//其他参数信息得到
			switch(BlwMapAdd.BlwMapCore.DevType)
			{
				case 0x00:   //场景
					BlwMapAdd.CfgActionAdd = DevAction_No_Get(BlwMapAdd.BlwMapCore.DevLoopAddr);//根据场景号找到相应动作的地址
					break;
				default:     //其他设备
					BlwMapAdd.CfgDevAdd = Find_AllDevice_List_Information(BlwMapAdd.BlwMapCore.DevType, BlwMapAdd.BlwMapCore.DevAddr);
					break;
			}
			Add_BlwMap_To_List(&BlwMapAdd);//添加到映射表链表
			
		}
	}
}	

/**
*@name 将宝来威映射表添加到链表
*@para  
*  BlwMapAdd  宝来威映射表节点
*@brief 将需要延时的节点添加到链表，如果是新节点，就返回新的地址，如果是旧节点，就返回旧地址
*/
uint32_t Add_BlwMap_To_List(Struct_CFG_BLW_Map_Add *BlwMapAdd)
{
	uint32_t list_addr;// = SRAM_DevDly_List_Start_Addr + DevActionGlobal.DevDlyNum*DevDlyStructLen;//找到当前位置 //获取设备信息保存地址
//	Struct_Dev_Dly_Core DevDlyCore;    //延时设备局部变量
	
	if(DevActionGlobal.BlwMapDevNum >= BlwMapDevNumMax)      //延时设备总数超过范围就返回
	{ 
		Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"超过映射表设备数量上限: %d", BlwMapDevNumMax);		//	
		return NULL;  //添加失败
	}
	
	list_addr = SRAM_BlwMap_List_Start_Addr + DevActionGlobal.BlwMapDevNum*BlwMapStructLen;   //拿到新地址
	//新增延时设备
	SRAM_DMA_Write_Buff((uint8_t *)BlwMapAdd, sizeof(Struct_CFG_BLW_Map_Add), list_addr);      //接着写入数据
	DevActionGlobal.BlwMapDevNum++;    //延时节点计数增加

	Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"映射表设备添加成功当前映射表节点地址:%08X 当前映射表设备计数:%d ",list_addr ,DevActionGlobal.BlwMapDevNum);		//	
	
	return list_addr;   //返回有效的地址
	/*遍历当前所有的延时设备，存在过的，就不添加，不存在的就往后添加*/
	
}

/**
*@name 映射表设备控制
*@para  
*  DevCtrl  控制数组
*@brief 
*   个数 类型 地址  执行方式  执行内容
*     01   01   00      01       00 
*/
void BlwMap_AllDev_Ctrl(uint8_t *DevCtrl)
{
	uint16_t i;
	
	Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"准备执行映射表设备控制，控制数量: %d 控制类型:%d", DevCtrl[0], DevCtrl[1]);		//	
	
	for(i = 0; i < DevCtrl[0]; i++)
	{
		BLWMap_Dev_Ctrl(&DevCtrl[1+i*0x04]);
	}
		
}

/**
  * @name  			BLW映射表设备节点获取
  * @param  
  *    buf      一共传6个字节过来
  * @retval     设备节点
  * @attention   
  */
void  BLWMap_Dev_Ctrl(uint8_t *buf)
{
	uint16_t i;
	uint32_t ListAddr;    
	Struct_CFG_BLW_Map_Add BlwMapAdd;
	uint8_t Data[6];    //6个字节设备控制
	
	Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"准备遍历映射表，设备总数:%d", DevActionGlobal.BlwMapDevNum);		//	
	
	for(i = 0; i < DevActionGlobal.BlwMapDevNum; i++)
	{
		ListAddr = SRAM_BlwMap_List_Start_Addr+i*BlwMapStructLen;
		SRAM_DMA_Read_Buff((uint8_t *)&BlwMapAdd, sizeof(Struct_CFG_BLW_Map_Add), ListAddr);      //接着读出数据
		
		if((buf[0] == BlwMapAdd.BlwMapCore.ServerDevType) && (buf[1] == BlwMapAdd.BlwMapCore.ServerDevAddr))
		{
			Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"找到映射表设备，设备类型:%d，设备地址:%d", BlwMapAdd.BlwMapCore.ServerDevType, BlwMapAdd.BlwMapCore.ServerDevAddr);		//	
			
			memcpy(Data, (uint8_t *)&BlwMapAdd.BlwMapCore.DevType, 0x04); //拷贝四个字节绝对回路
			Data[4] = buf[2];  //拿到控制方式
			Data[5] = buf[3]; 
			switch(BlwMapAdd.BlwMapCore.ServerDevType)
			{
				case Dev_Host_HVout:
					switch(BlwMapAdd.BlwMapCore.DevType)
					{
						case DEV_RS485_PWM:     //PWM调光
						case DEV_RS485_STRIP:   //灯带
							if(0x01 == Data[4])
							{
								Data[5] = 80;   //默认亮度为80
							}								
							break;
					}
					break;
//				case Dev_Host_Invalid:
//					if(XIAOBAO_SCENE_SLEEP == BlwMapAdd.BlwMapCore.ServerDevAddr)  //睡眠
//					{
//						Data[4] = 0x02;   //场景关闭
//					}
//					break;
				case DEV_RS485_STRIP:        //2023-09-05
					if((BlwMapAdd.BlwMapCore.DevType == Dev_Host_HVout) || (BlwMapAdd.BlwMapCore.DevType == Dev_Host_Invalid))
					{
						Data[0] = BlwMapAdd.BlwMapCore.DevType;
						Data[1] = BlwMapAdd.BlwMapCore.DevAddr;
						Data[2] = BlwMapAdd.BlwMapCore.DevLoopAddr&0xff;
						Data[3] = BlwMapAdd.BlwMapCore.DevLoopAddr>>8;
						Data[5] = 0x00;
					}
					break;
				case DEV_RS485_MUSIC:
					if(BlwMapAdd.BlwMapCore.DevType == DEV_RS485_MUSIC)  //主机自带音乐
					{
						if((buf[2] == 0x01) && (buf[3] == 0x01))         //播放
						{
							Data[0] = BlwMapAdd.BlwMapCore.DevType;
							Data[1] = BlwMapAdd.BlwMapCore.DevAddr;
							Data[2] = BlwMapAdd.BlwMapCore.DevLoopAddr&0xff;
							Data[3] = BlwMapAdd.BlwMapCore.DevLoopAddr>>8;
							Data[4] = 0x10;
							Data[5] = 0x00;
						}
						else if((buf[2] == 0x01) && (buf[3] == 0x02))   //暂停
						{
							Data[0] = BlwMapAdd.BlwMapCore.DevType;
							Data[1] = BlwMapAdd.BlwMapCore.DevAddr;
							Data[2] = BlwMapAdd.BlwMapCore.DevLoopAddr&0xff;
							Data[3] = BlwMapAdd.BlwMapCore.DevLoopAddr>>8;
							Data[4] = 0x20;
							Data[5] = 0x00;
						}
						else if((buf[2] == 0x01) && (buf[3] == 0x03))   //上一曲
						{
							Data[0] = BlwMapAdd.BlwMapCore.DevType;
							Data[1] = BlwMapAdd.BlwMapCore.DevAddr;
							Data[2] = BlwMapAdd.BlwMapCore.DevLoopAddr&0xff;
							Data[3] = BlwMapAdd.BlwMapCore.DevLoopAddr>>8;
							Data[4] = 0x30;
							Data[5] = 0x00;
						}
						else if((buf[2] == 0x01) && (buf[3] == 0x04))   //下一曲
						{
							Data[0] = BlwMapAdd.BlwMapCore.DevType;
							Data[1] = BlwMapAdd.BlwMapCore.DevAddr;
							Data[2] = BlwMapAdd.BlwMapCore.DevLoopAddr&0xff;
							Data[3] = BlwMapAdd.BlwMapCore.DevLoopAddr>>8;
							Data[4] = 0x40;
							Data[5] = 0x00;
						}
						else if((buf[2] == 0x01) && (buf[3] == 0x05))   //音量调大  +1
						{
							Data[0] = BlwMapAdd.BlwMapCore.DevType;
							Data[1] = BlwMapAdd.BlwMapCore.DevAddr;
							Data[2] = 0x00;
							Data[3] = 0x00;
							Data[4] = 0x50;
							Data[5] = 0x01;
						}
						else if((buf[2] == 0x01) && (buf[3] == 0x06))   //音量调小  -1
						{
							Data[0] = BlwMapAdd.BlwMapCore.DevType;
							Data[1] = BlwMapAdd.BlwMapCore.DevAddr;
							Data[2] = 0x00;
							Data[3] = 0x00;
							Data[4] = 0x60;
							Data[5] = 0x01;
						}
						else if((buf[2] == 0x01) && (buf[3] == 0xA0))   //音量最大 10
						{
							Data[0] = BlwMapAdd.BlwMapCore.DevType;
							Data[1] = BlwMapAdd.BlwMapCore.DevAddr;
							Data[2] = 0x00;
							Data[3] = 0x00;
							Data[4] = 0x70;
							Data[5] = 0x0A;
						}
						else if((buf[2] == 0x01) && (buf[3] == 0x10))   //音量最小  1
						{
							Data[0] = BlwMapAdd.BlwMapCore.DevType;
							Data[1] = BlwMapAdd.BlwMapCore.DevAddr;
							Data[2] = 0x00;
							Data[3] = 0x00;
							Data[4] = 0x70;
							Data[5] = 0x01;
						}
					}
					break;
			}
			
			Dbg_Print_Buff(DBG_BIT_LOGIC_STATUS_bit,"小宝控制动作数据:", Data,0x06);		//	
			
			DevActionCtrl(Data, 0x06);
			break;
		}
	}
	
}

