

/**
  ******************************************************************************
  * @file    BLV_485_Dev_MusicFun.c
  * @author  BLW RCU  development Team
  * @version SongHan
  * @date    2021年12月08日
  * @brief  
	*    485背景音乐总表，所有的背景音乐驱动尽可能放在这张表里面
  ******************************************************************************
	2022.10.13			林开锐
		在BLV_485_Dev_MusicFun.c中，增加6号协议——华尔思音乐（轮询端口）
  ******************************************************************************
  */




#include "BLV_485_Dev_MusicFun.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"

/*背景音乐驱动头文件开始*/
#include "BLV_485_Dev_BLWMusicFun.h"
#include "BLV_485_Dev_HuaErSiFun.h"
/*背景音乐驱动头文件结束*/

/*Music背景音乐驱动代码*/

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

#define MusicSnMax               15     //最大Sn号


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

/*设备驱动宏定义开始*/
#define RS485_DEV_PRO_FUN_01    ((DevFunP)NULL)      //背景音乐
#define RS485_DEV_PRO_FUN_02    DevExistJudgge(RS485_MUSIC_BLW_Flag, BLW_RS485_BLWMusic_Data_Init) //((DevFunP)NULL)      //宝来威背景音乐 也可用于小宝音乐控制
#define RS485_DEV_PRO_FUN_03    ((DevFunP)NULL)      //背景音乐
#define RS485_DEV_PRO_FUN_04    ((DevFunP)NULL)      //背景音乐
#define RS485_DEV_PRO_FUN_05    ((DevFunP)NULL)      //背景音乐
/***2022.10.13林开锐修改开始***/
#define RS485_DEV_PRO_FUN_06    DevExistJudgge(RS485_MUSIC_HES_Flag, HuaErSi_RS485_Music_Data_Init)	//华尔思背景音乐
/***2022.10.13林开锐修改结束***/
/*设备驱动宏定义结束*/

/*本地函数调用开始*/
void BLW_Music_Control_State(uint32_t CfgDevAddIn, uint16_t DevInputAddr, uint32_t devaddr,uint16_t loop,uint16_t start);
uint16_t BLW_Music_Read_State(uint32_t devaddr,uint16_t loop);
uint8_t Get_BLV485_Music_Online_Status(uint32_t devaddr);
void Dev_Logic_Music_Ctrl(uint32_t DevAddrIn, uint16_t DevInputLoop, uint32_t DevAddrOut, uint16_t DevOutputLoop, uint16_t DevOutputType);

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

/*******************************************************************************
* @name  :  Music背景音乐驱动总表
* @para  : 
*   DataLen :数据长度
*   Data：   数据数组
* @attention   : 将背景音乐的所有设备参数传进来，
*
*******************************************************************************/
void BLW_RS485_Music_Data_Init(uint16_t DataLen, uint8_t *Data)
{
	Device_Public_Information_G BUS_Public;
	RS485_MUSIC_INFO Rs485Music;

	memset(&BUS_Public,0,sizeof(Device_Public_Information_G));
	memset(&Rs485Music,0,sizeof(RS485_MUSIC_INFO));
	
	BUS_Public.addr = Data[1];		//设备485地址
	BUS_Public.type = DEV_RS485_MUSIC;		//设备类型
	BUS_Public.baud = 9600;		//设备发送波特率
	BUS_Public.retry_num = 0x03;	//设备数据重发次数
	BUS_Public.wait_time = 0x0064;	//设备数据发送等待回复时间 - 100ms
	BUS_Public.DevFunInfo.Dev_Output_Ctrl = BLW_Music_Control_State;
	BUS_Public.DevFunInfo.Dev_Output_Loop_State_Get = BLW_Music_Read_State;   
	Rs485Music.DevOffline = Rs485Music.DevOfflineLast = DEV_IS_LINEUNINIT;   //在线状态初始化
	/*初始化Music背景音乐初始值*/
	if(Data[10] >= MUSICLOOPMAX)   //输出回路超过范围
	{
		Rs485Music.MusicLoopValidNum = MUSICLOOPMAX;
	}
	else              //未超过范围
	{
		Rs485Music.MusicLoopValidNum = Data[10];
	}
	switch(Data[7])
	{
		case	 ENUM_RS485_DEV_PRO_01: if(NULL!=RS485_DEV_PRO_FUN_01) RS485_DEV_PRO_FUN_01(&BUS_Public, &Rs485Music);break; //        
		case	 ENUM_RS485_DEV_PRO_02: if(NULL!=RS485_DEV_PRO_FUN_02) RS485_DEV_PRO_FUN_02(&BUS_Public, &Rs485Music);break; //          
		case	 ENUM_RS485_DEV_PRO_03: if(NULL!=RS485_DEV_PRO_FUN_03) RS485_DEV_PRO_FUN_03(&BUS_Public, &Rs485Music);break;                                 //3
		case	 ENUM_RS485_DEV_PRO_04: if(NULL!=RS485_DEV_PRO_FUN_04) RS485_DEV_PRO_FUN_04(&BUS_Public, &Rs485Music);break;
		/***2022.10.13林开锐修改开始***/
		case	 ENUM_RS485_DEV_PRO_06: if(NULL!=RS485_DEV_PRO_FUN_06) RS485_DEV_PRO_FUN_06(&BUS_Public, &Rs485Music);break;
		/***2022.10.13林开锐修改结束***/
	}
	
	switch(Data[2])
	{
		case Active_Port:   //主动端口
			BUS_Public.port = Active_Port;		//设备发送端口
			Add_ACT_Device_To_List2(&BUS_Public,(uint8_t *)&Rs485Music,sizeof(RS485_MUSIC_INFO));
			Act485_Info.device_num += 1;
			break;  
		case Polling_Port:   //轮询端口
			BUS_Public.port = Polling_Port;		//设备发送端口
			Add_POLL_Device_To_List2(&BUS_Public,(uint8_t *)&Rs485Music,sizeof(RS485_MUSIC_INFO));   //将填充后的数据添加到链表
			Poll485_Info.device_num += 1;	
			break;
		case Bus_port:    //总线端口
			break;
	}

}




/*******************************************************************************
* @name  :  Music背景音乐驱动总表
* @para  : 
*   DataLen :数据长度
*   Data：   数据数组
* @attention   : 将背景音乐的所有设备参数传进来，
*
*******************************************************************************/
void BLW_RS485_Music_Data_Logic_Init(LOGICFILE_DEVICE_INFO *dev_info,uint8_t *data,uint16_t data_len)
{
	Device_Public_Information_G BUS_Public;
	RS485_MUSIC_INFO Rs485Music;

	memset(&BUS_Public,0,sizeof(Device_Public_Information_G));
	memset(&Rs485Music,0,sizeof(RS485_MUSIC_INFO));
	
	BUS_Public.addr = dev_info->addr;		//设备485地址
	BUS_Public.type = dev_info->type;		//设备类型
	BUS_Public.baud = dev_info->baud;;		//设备发送波特率
	BUS_Public.retry_num = 0x03;	//设备数据重发次数
	BUS_Public.wait_time = 0x00C8;		//设备数据发送等待回复时间     2024-12-31  由100ms改成200ms   100ms时小宝设备有时解析失败
	BUS_Public.Protocol = dev_info->version;

#if LOGIC_FILE_EN
	BUS_Public.DevFunInfo.Dev_Output_Ctrl = Dev_Logic_Music_Ctrl;
	#else
	BUS_Public.DevFunInfo.Dev_Output_Ctrl = BLW_Music_Control_State;
#endif	
	BUS_Public.DevFunInfo.Dev_Output_Loop_State_Get = BLW_Music_Read_State;   
	Rs485Music.DevOfflineLast = DEV_IS_ONLINE;   //在线状态初始化
	Rs485Music.DevOffline = Rs485Music.DevOfflineLast;
	/*初始化Music背景音乐初始值*/
	if(dev_info->output_num >= MUSICLOOPMAX)   //输出回路超过范围
	{
		Rs485Music.MusicLoopValidNum = MUSICLOOPMAX;
	}
  else if(0x00 == dev_info->output_num)
	{
		Rs485Music.MusicLoopValidNum = 0x01;   //默认一个回路
	}
	else              //未超过范围
	{
		Rs485Music.MusicLoopValidNum = dev_info->output_num;
	}
	switch(BUS_Public.Protocol)		//协议版本
	{
		case	 ENUM_RS485_DEV_PRO_01: if(NULL!=RS485_DEV_PRO_FUN_01) RS485_DEV_PRO_FUN_01(&BUS_Public, &Rs485Music);break; //        
		case	 ENUM_RS485_DEV_PRO_02: if(NULL!=RS485_DEV_PRO_FUN_02) RS485_DEV_PRO_FUN_02(&BUS_Public, &Rs485Music);break; //          
		case	 ENUM_RS485_DEV_PRO_03: if(NULL!=RS485_DEV_PRO_FUN_03) RS485_DEV_PRO_FUN_03(&BUS_Public, &Rs485Music);break;                                 //3
		case	 ENUM_RS485_DEV_PRO_04: if(NULL!=RS485_DEV_PRO_FUN_04) RS485_DEV_PRO_FUN_04(&BUS_Public, &Rs485Music);break;
		/***2022.10.13林开锐修改开始***/
		case	 ENUM_RS485_DEV_PRO_06: if(NULL!=RS485_DEV_PRO_FUN_06) RS485_DEV_PRO_FUN_06(&BUS_Public, &Rs485Music);break;
		/***2022.10.13林开锐修改结束***/
	}
	
	switch(dev_info->port)
	{
		case Active_Port:   //主动端口
			BUS_Public.port = Active_Port;		//设备发送端口
			Add_ACT_Device_To_List2(&BUS_Public,(uint8_t *)&Rs485Music,sizeof(RS485_MUSIC_INFO));
			Act485_Info.device_num += 1;
			break;  
		case Polling_Port:   //轮询端口
			BUS_Public.port = Polling_Port;		//设备发送端口
			Add_POLL_Device_To_List2(&BUS_Public,(uint8_t *)&Rs485Music,sizeof(RS485_MUSIC_INFO));   //将填充后的数据添加到链表
			Poll485_Info.device_num += 1;	
			break;
		case Bus_port:    //总线端口
			break;
	}

}

/**
*@name 背景音乐控制函数
*@para
*  DevAddrIn            设备输入
*  DevInputLoop         输入回路
*  DevAddrOut           设备输出
*  DevOutputLoop        输出回路
*  DevOutputType        输出类型
*/
void Dev_Logic_Music_Ctrl(uint32_t DevAddrIn, uint16_t DevInputLoop, uint32_t DevAddrOut, uint16_t DevOutputLoop, uint16_t DevOutputType)
{
//	DEV_MUSIC_CTRLSTATE DevMusicCtrlState;    //背景音乐控制状态
	Device_Public_Information_G BUS_Public;	
	RS485_MUSIC_INFO Rs485Music;
//	uint8_t KeepFlag = 0x00;

	if(NULL == DevAddrOut)
	{
		return ;
	}
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),DevAddrOut);				
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485Music,sizeof(RS485_MUSIC_INFO),DevAddrOut+Dev_Privately);

	if(DevOutputLoop >= MUSICLOOPMAX)    //有效回路
	{
		return ;
	}

	BLV_Music_CtrlState_Get(&Rs485Music.DevMusicCtrlState[DevOutputLoop],DevOutputType);
	switch(Rs485Music.DevMusicCtrlState[DevOutputLoop].DevMusicCtrlWay.CtrlDirect)   //功能
	{
		case 0x00:  //功能
			switch(Rs485Music.DevMusicCtrlState[DevOutputLoop].DevMusicCtrlWay.CtrlDir)
			{
				case 0x01: //播放
				case 0x02: //暂停  
				case 0x03: //上一曲
				case 0x04: //下一曲
				case MUSIC_PLAY_SPE_1:	//指定播放第1首(华尔思)
				case MUSIC_PLAY_SPE_2:	//指定播放第2首(华尔思)
				case MUSIC_PLAY_SPE_3:	//指定播放第3首(华尔思)
				case MUSIC_PLAY_SPE_4:	//指定播放第4首(华尔思)
				case MUSIC_PLAY_SPE_5:	//指定播放第5首(华尔思)
				case MUSIC_PLAY_SPE_6:	//指定播放第6首(华尔思)
					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"执行背景音乐模式控制，地址:%d 回路%d 状态:%08X",BUS_Public.addr,DevOutputLoop, Rs485Music.DevMusicCtrlState[DevOutputLoop].DevMusicCtrlWay.CtrlDir);	
					Rs485Music.MusicStateCtrlFlag[DevOutputLoop].MusicModeCtrlVar = 0x01;    // MusicBackCtrlFlag[DevOutputLoop] = 0x01;            //背景音乐内容控制标志  
					Rs485Music.MusicStateCtrlCnt[DevOutputLoop].MusicModeCtrlVar = REPEATSENDTIMEMAX;
					break;
				case MUSIC_VOICE_STOP:	//音量停止（华尔思为指定音量设置）
					Rs485Music.MusicStateCtrlFlag[DevOutputLoop].MusicReadFlagVar = 0x01;    //所有通道共用一个标志       读取音量
					Rs485Music.MusicStateCtrlCnt[DevOutputLoop].MusicReadFlagVar =  REPEATSENDTIMEMAX;  // MusicVoiceReadCnt = MusicBackSendMax;
					break;
				
				case 0x05: //音量加     目前按照10级音量进行加减，每次加减一级
//					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"执行背景音乐控制，音量加");	
					if(BUS_Public.addr == 0x02)	//华尔思地址
					{
						Rs485Music.MusicStateCtrlFlag[DevOutputLoop].MusicVoiceCtrlVar = 0x01;	//背景音乐音量控制标志  
						Rs485Music.MusicStateCtrlCnt[DevOutputLoop].MusicVoiceCtrlVar = 0x00;	//发送次数0（只发1次）
					}
					else
					{
						if(Rs485Music.music_volume.now_volume[DevOutputLoop] < 30)     //宝来威 相对调节
						{
//							KeepFlag = 0x01;
							Rs485Music.MusicStateCtrlFlag[DevOutputLoop].MusicVoiceCtrlVar = 0x01;	//2023-04-14
							Rs485Music.MusicStateCtrlCnt[DevOutputLoop].MusicVoiceCtrlVar = 0x03;
							Rs485Music.music_volume.now_volume[DevOutputLoop]++;
						}
					}
					break;
				case 0x06: //音量减     目前按照10级音量进行加减，每次加减一级
//					Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"执行背景音乐控制，音量减");			
					if(BUS_Public.addr == 0x02)	//华尔思地址
					{
						Rs485Music.MusicStateCtrlFlag[DevOutputLoop].MusicVoiceCtrlVar = 0x01;	//背景音乐音量控制标志  
						Rs485Music.MusicStateCtrlCnt[DevOutputLoop].MusicVoiceCtrlVar = 0x00;	//发送次数0（只发1次）
					}
					else
					{
						if(Rs485Music.music_volume.now_volume[DevOutputLoop] > 0)     //宝来威 相对调节
						{
//							KeepFlag = 0x01;
							Rs485Music.MusicStateCtrlFlag[DevOutputLoop].MusicVoiceCtrlVar = 0x02;	//2023-04-14
							Rs485Music.MusicStateCtrlCnt[DevOutputLoop].MusicVoiceCtrlVar = 0x03;
							Rs485Music.music_volume.now_volume[DevOutputLoop]--;							
						}
					}
					break;
				case 0x07: //宝来威设定音乐音量
					if(Rs485Music.DevMusicCtrlState[DevOutputLoop].CtrlCont.CtrlVoice <= 15)  //内容
					{
//						KeepFlag = 0x01;
						Rs485Music.MusicStateCtrlFlag[DevOutputLoop].MusicVoiceCtrlVar = 0x03;	//2023-04-14
						Rs485Music.music_volume.now_volume[DevOutputLoop] = Rs485Music.DevMusicCtrlState[DevOutputLoop].CtrlCont.CtrlVoice*2;
						Rs485Music.MusicStateCtrlCnt[DevOutputLoop].MusicVoiceCtrlVar = 0x03;
					}
					break;
			}
			break;
		case 0x01:  //开机
		case 0x02:  //关机
			Rs485Music.huaersi_onoff[DevOutputLoop] = Rs485Music.DevMusicCtrlState[DevOutputLoop].DevMusicCtrlWay.CtrlDirect;
			break;
		case 0x05:	//华尔思打开左声道
		case 0x06:	//华尔思关闭左声道
		case 0x07:	//华尔思打开右声道
		case 0x08:	//华尔思关闭右声道
		case 0x09:	//华尔思打开左右声道
		case 0x0A:	//华尔思关闭左右声道
			Rs485Music.huaersi_track_control[DevOutputLoop] = 0x07;	//声道发送标志置1，声道发送次数为3
			break;
	}
	switch(Rs485Music.DevMusicCtrlState[DevOutputLoop].DevMusicCtrlWay.CtrlDir)
	{
		case MUSIC_PLAY:  //音乐播放
		case MUSIC_PRE:   //上一曲
		case MUSIC_NEX:   //下一曲
		case MUSIC_PLAY_SPE_1:        //指定播放第1首
		case MUSIC_PLAY_SPE_2:        //指定播放第2首
		case MUSIC_PLAY_SPE_3:        //指定播放第3首
		case MUSIC_PLAY_SPE_4:        //指定播放第4首
		case MUSIC_PLAY_SPE_5:        //指定播放第5首 
		case MUSIC_PLAY_SPE_6:        //指定播放第6首
			Rs485Music.BackMusicState[DevOutputLoop].CtrlCont.CtrlMode = MUSIC_PLAY;    //置播放    MusicBackPlayStopState[DevOutputLoop] 
			break;
		case MUSIC_STOP:
			Rs485Music.BackMusicState[DevOutputLoop].CtrlCont.CtrlMode = MUSIC_STOP;    //置停止    MusicBackPlayStopState[DevOutputLoop]
			break;
		default:
//			MusicState = CtrlMode;      //其他情况不改变状态 
			break;
	}
//	if(KeepFlag)
	{

		
//		Dbg_Print(DBG_BIT_LOGIC_STATUS_bit,"背景音乐音量调节:回路：%d音量：%d\r\n", DevOutputLoop, Rs485Music.BackMusicState[DevOutputLoop].CtrlCont.CtrlVoice);
		
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&Rs485Music, sizeof(RS485_MUSIC_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),DevAddrOut);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&Rs485Music,sizeof(RS485_MUSIC_INFO),DevAddrOut+Dev_Privately);
			
	}	
//	BUS_C5MUSIC_Set_LoopVolume_2(DevAddrOut, DevOutputLoop, C5Music_Info.BackMusicState[DevOutputLoop].CtrlCont.CtrlVoice*3);  //音量的值放大3倍传入
}


/*******************************************************************************
* Function Name  : BLW_Music_Control_State 
* Description    : BLWMusic背景音乐状态控制函数
* Input          : 
	devaddr	: 设备信息地址
  loop    ：回路
	start   ：状态
* Return  : 无
* attention : temp1非0才会进行保存
*******************************************************************************/
void BLW_Music_Control_State(uint32_t CfgDevAddIn, uint16_t DevInputAddr, uint32_t devaddr,uint16_t DevOutputLoop,uint16_t DevOutputType)
{
//	uint8_t temp1 = 0;
//	uint8_t CtrlMode;   //控制模式
//	uint8_t CtrlContect;
	Device_Public_Information_G BUS_Public;
	RS485_MUSIC_INFO Rs485Music;
//	DEV_MUSIC_CTRLSTATE DevMusicCtrlState;    //背景音乐控制状态
	
	if(devaddr == 0x00)	return;
	

	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),devaddr);				
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485Music,sizeof(RS485_MUSIC_INFO),devaddr+Dev_Privately);
	
	if(DevOutputLoop >= Rs485Music.MusicLoopValidNum)    //有效回路
	{
		return ;
	}
	BLV_Music_CtrlState_Get(&Rs485Music.DevMusicCtrlState[DevOutputLoop],DevOutputType);
	switch(Rs485Music.DevMusicCtrlState[DevOutputLoop].CtrlCont.CtrlMode)             //背景音乐模式控制
	{
		case MUSIC_PLAY:  //音乐播放
		case MUSIC_STOP:  //暂停
		case MUSIC_PRE:   //上一曲
		case MUSIC_NEX:   //下一曲
		case MUSIC_PLAY_SPE_1:        //指定播放第1首
		case MUSIC_PLAY_SPE_2:        //指定播放第2首
		case MUSIC_PLAY_SPE_3:        //指定播放第3首
		case MUSIC_PLAY_SPE_4:        //指定播放第4首
		case MUSIC_PLAY_SPE_5:        //指定播放第5首 
		case MUSIC_PLAY_SPE_6:        //指定播放第6首 

			Rs485Music.MusicStateCtrlFlag[DevOutputLoop].MusicModeCtrlVar = 0x01;    // MusicBackCtrlFlag[DevOutputLoop] = 0x01;            //背景音乐内容控制标志  
			Rs485Music.MusicStateCtrlCnt[DevOutputLoop].MusicModeCtrlVar = REPEATSENDTIMEMAX;
		
//			Rs485Music.MusicBackSendCnt[DevOutputLoop] = MusicBackSendMax;
			break;	
		case MUSIC_VOICE_STOP:         //音量停止（华尔思为指定音量设置）
			Rs485Music.MusicStateCtrlFlag[DevOutputLoop].MusicReadFlagVar = 0x01;    //所有通道共用一个标志       读取音量
			Rs485Music.MusicStateCtrlCnt[DevOutputLoop].MusicReadFlagVar =  REPEATSENDTIMEMAX;  // MusicVoiceReadCnt = MusicBackSendMax;
			break;
		case MUSIC_VOICE_UP:           //音量加
		case MUSIC_VOICE_DOWN:			   //音量减
		case MUSIC_VOICE_ALW_UP:       //音量一直加
		case MUSIC_VOICE_ALW_DOWN:     //音量一直减 
			if(BUS_Public.addr == 0x02)	//华尔思地址
			{
				Rs485Music.MusicStateCtrlFlag[DevOutputLoop].MusicVoiceCtrlVar = 0x01;	//背景音乐音量控制标志  
				Rs485Music.MusicStateCtrlCnt[DevOutputLoop].MusicVoiceCtrlVar = 0x00;	//发送次数0（只发1次）
			}
			else
			{
				Rs485Music.MusicStateCtrlFlag[DevOutputLoop].MusicVoiceCtrlVar = 0x01;  //  MusicBackVoiceCtrlFlag[DevOutputLoop] = 0x01;     //背景音乐音量控制标志  
				Rs485Music.MusicStateCtrlCnt[DevOutputLoop].MusicVoiceCtrlVar = REPEATSENDTIMEMAX;  // MusicBackVoiceSendCnt[DevOutputLoop] = MusicBackSendMax;				
			}
			break;
	}
	
	
	
	if((0x00 != Rs485Music.DevMusicCtrlState[DevOutputLoop].CtrlCont.CtrlVoice) && (Rs485Music.DevMusicCtrlState[DevOutputLoop].CtrlCont.CtrlVoice <= MUSICVOICELEVELMAX))   //音量不为0
	{
		Rs485Music.MusicStateCtrlFlag[DevOutputLoop].MusicVoiceCtrlVar = 0x01;  //背景音乐音量控制标志 
		Rs485Music.MusicStateCtrlCnt[DevOutputLoop].MusicVoiceCtrlVar = REPEATSENDTIMEMAX;  //音量控制计数
		Rs485Music.BackMusicState[DevOutputLoop].CtrlCont.CtrlVoice = Rs485Music.DevMusicCtrlState[DevOutputLoop].CtrlCont.CtrlVoice;  //音量有效
	}
	
	switch(Rs485Music.DevMusicCtrlState[DevOutputLoop].CtrlCont.CtrlMode)
	{
		case MUSIC_VOICE_UP:
			if(Rs485Music.BackMusicState[DevOutputLoop].CtrlCont.CtrlVoice < MUSICVOICELEVELMAX)
			{
				Rs485Music.BackMusicState[DevOutputLoop].CtrlCont.CtrlVoice++;   //无视设置音量大小，进行加减
			}
			break;
		case MUSIC_VOICE_DOWN:
			if(Rs485Music.BackMusicState[DevOutputLoop].CtrlCont.CtrlVoice > 1)     //本地只能降到1  
			{
				Rs485Music.BackMusicState[DevOutputLoop].CtrlCont.CtrlVoice--;
			}
			break;
	}
	
//	switch(Rs485Music.DevMusicCtrlState.CtrlCont.CtrlMode)   //模式           保存控制内容
//	{	
//		case MUSIC_VOICE_STOP:         //音量加减停止
//		case MUSIC_VOICE_UP:					//音量加
//		case MUSIC_VOICE_DOWN:				//音量减
//		case MUSIC_PLAY:         //音乐播放
//		case MUSIC_STOP:				//音乐暂停
//		case MUSIC_PRE:					//上一曲
//		case MUSIC_NEX:					//下一曲
//		case MUSIC_PLAY_SPE_1:        //指定播放第1首
//		case MUSIC_PLAY_SPE_2:        //指定播放第2首
//		case MUSIC_PLAY_SPE_3:        //指定播放第3首
//		case MUSIC_PLAY_SPE_4:        //指定播放第4首
//		case MUSIC_PLAY_SPE_5:        //指定播放第5首
//		case MUSIC_PLAY_SPE_6:       //指定播放第6首 
//			
//		case MUSIC_VOICE_ALW_UP:       //音量一直加
//		case MUSIC_VOICE_ALW_DOWN:    //音量一直减
//			Rs485Music.BackMusicState[DevOutputLoop].CtrlCont.CtrlMode = Rs485Music.DevMusicCtrlState.CtrlCont.CtrlMode; //执行内容赋值
//			break;                      //	

//	}
	
	
	switch(Rs485Music.DevMusicCtrlState[DevOutputLoop].CtrlCont.CtrlMode)       //音乐模式
	{
		case MUSIC_PLAY:  //音乐播放
		case MUSIC_PRE:   //上一曲
		case MUSIC_NEX:   //下一曲
		case MUSIC_PLAY_SPE_1:        //指定播放第1首
		case MUSIC_PLAY_SPE_2:        //指定播放第2首
		case MUSIC_PLAY_SPE_3:        //指定播放第3首
		case MUSIC_PLAY_SPE_4:        //指定播放第4首
		case MUSIC_PLAY_SPE_5:        //指定播放第5首 
		case MUSIC_PLAY_SPE_6:        //指定播放第6首 
			Rs485Music.BackMusicState[DevOutputLoop].CtrlCont.CtrlMode = MUSIC_PLAY;    //置播放    MusicBackPlayStopState[DevOutputLoop] 
			break;
		case MUSIC_STOP:
			Rs485Music.BackMusicState[DevOutputLoop].CtrlCont.CtrlMode = MUSIC_STOP;    //置停止    MusicBackPlayStopState[DevOutputLoop]
			break;
		default:
//			MusicState = CtrlMode;      //其他情况不改变状态 
			break;
	}
	switch(Rs485Music.DevMusicCtrlState[DevOutputLoop].DevMusicCtrlWay.CtrlDirect)
	{
		case 0x01:	//开机
		case 0x02:	//关机
			Rs485Music.huaersi_onoff[DevOutputLoop] = Rs485Music.DevMusicCtrlState[DevOutputLoop].DevMusicCtrlWay.CtrlDirect;
			break;
		case 0x05:	//华尔思打开左声道
		case 0x06:	//华尔思关闭左声道
		case 0x07:	//华尔思打开右声道
		case 0x08:	//华尔思关闭右声道
		case 0x09:	//华尔思打开左右声道
		case 0x0A:	//华尔思关闭左右声道
			Rs485Music.huaersi_track_control[DevOutputLoop] = 0x07;	//声道发送标志置1，声道发送次数为3
			break;
	}
//	Rs485Music.BackMusicState[DevOutputLoop] = (Rs485Music.MusicVoiceValue[DevOutputLoop]<<12)+(Rs485Music.MusicBackPlayStopState[DevOutputLoop]<<8)+(Rs485Music.MusicBackOnOff[DevOutputLoop]);//
		
	
	
//	if(temp1 != 0x00)
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"MusicCtrl loop:%d,start:%d",DevOutputLoop,DevOutputType);
	
		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&Rs485Music, sizeof(RS485_MUSIC_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),devaddr);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&Rs485Music,sizeof(RS485_MUSIC_INFO),devaddr+Dev_Privately);
		
	}
}
/*******************************************************************************
* Function Name  : BLW_Music_Read_State 
* Description    : BLWMusic背景音乐状态读取函数
* Input          : 
	devaddr	: 设备信息地址
  loop    ：回路
* Return  : 无
*******************************************************************************/
uint16_t BLW_Music_Read_State(uint32_t devaddr,uint16_t loop)
{
	if(devaddr == 0x00)	return 0x00;
	uint16_t temp_val = 0;
	
	RS485_MUSIC_INFO Rs485Music;
	
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485Music,sizeof(RS485_MUSIC_INFO),devaddr+Dev_Privately);	
	
	if(loop >= Rs485Music.MusicLoopValidNum)
	{
		return 0x00;    //超出范围 直接返回0
	}
	
	temp_val = Rs485Music.BackMusicState[loop].CtrlCont.CtrlVoice;
	temp_val <<= 8;
	temp_val |= Rs485Music.BackMusicState[loop].DevMusicCtrlWay.CtrlDir;
	temp_val <<= 4;
	temp_val |= Rs485Music.BackMusicState[loop].DevMusicCtrlWay.CtrlDirect;
	
	return temp_val;
		
}

/*获取Music背景音乐在线状态*/
uint8_t Get_BLV485_Music_Online_Status(uint32_t devaddr)
{
	RS485_MUSIC_INFO Rs485Music;
	
	SRAM_DMA_Read_Buff((uint8_t *)&Rs485Music,sizeof(RS485_MUSIC_INFO),devaddr+Dev_Privately);
	
	if(Rs485Music.DevOffline == DEV_IS_ONLINE)
	{
		return 0x01;
	}
	return 0x02;
}



