#include "includes.h"

/*
文件描述：PC测试驱动文件 - 2021-07-13 暂时不弄了，先弄网络
	2021-11-09 PC测试 修改通过命令进入模块测试模式
功 能：PC测试功能支持，同时支持485设备升级
*/

PC_TEST_FLAG_G g_pc_test;			//pc测试标志位

#define PC_REPEATSENDTIMEMAX			0x04  	//本设备重发次数上限




/*******************************************************************************
* Function Name  : BLV_PC_DEVICE_TEST_Init 
* Description    : PC测试驱动初始化 - 该设备增加在设备列表的最后一个，归属于主动端口
*******************************************************************************/
void BLV_PC_DEVICE_TEST_Init(void)
{
	Device_Public_Information_G BUS_Public;
	PC_TEST_DEVICE_INFO PC_Test_Info;
	
	memset(&BUS_Public,0,sizeof(Device_Public_Information_G));
	memset(&PC_Test_Info,0,sizeof(PC_TEST_DEVICE_INFO));
	
	BUS_Public.addr = DEV_PCTEST_Addr;			//设备地址 - 默认地址
	BUS_Public.type = DEV_PCTEST_TYPE;			//设备类型
	BUS_Public.port = 0x02;						//设备发送端口
	BUS_Public.baud = 115200;					//设备发送波特率
	BUS_Public.retry_num = PC_REPEATSENDTIMEMAX;		//设备数据重发次数
	BUS_Public.wait_time = 0x01F4;		//设备数据发送等待回复时间 - 100ms
	BUS_Public.polling_cf = (uint32_t)&BLV_PC_DEVICE_TEST_Cycle_Call;
	BUS_Public.processing_cf = (uint32_t)&BLV_PC_DEVICE_TEST_Data_Processing;
	
	g_pc_test.link_port = 0xFF;		//默认采用 2022-05-29
	
	Add_ACT_Device_To_List2(&BUS_Public,(uint8_t *)&PC_Test_Info,sizeof(PC_TEST_DEVICE_INFO));
	
}

/*******************************************************************************
* Function Name  : BLV_BUS_C5MUSIC_Cycle_Call 
* Description    : PC回复发送函数函数
* Input          : 
	dev_addr	: 设备信息地址
* Return         :
	0x00：没问题
	0x01：错误 - 设备类型不对
*******************************************************************************/
uint8_t BLV_PC_DEVICE_TEST_Cycle_Call(uint32_t dev_addr)
{
	Device_Public_Information_G BUS_Public;
	PC_TEST_DEVICE_INFO PC_Test_Info;
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),dev_addr);		
	SRAM_DMA_Read_Buff((uint8_t *)&PC_Test_Info,sizeof(PC_TEST_DEVICE_INFO),dev_addr+Dev_Privately);
	
	if((PC_Test_Info.test_flag == 0x01) || (PC_Test_Info.test_flag == 0x02) || (PC_Test_Info.test_flag == 0x11) || (PC_Test_Info.test_flag == 0x12))		//输入测试结束判断
	{
		if(SysTick_1ms - PC_Test_Info.test_tick > PC_Test_Info.test_time)
		{
			PC_Test_Info.test_flag = 0x00;
			g_pc_test.test_flag = PC_Test_Info.test_flag;		//全局参数为0x00	
			
			Dbg_Println(DBG_OPT_DEVICE_STATUS,"PC Test - The Input Test END");
			
			BUS_Public.check = 0x00;
			BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&PC_Test_Info, sizeof(PC_TEST_DEVICE_INFO));
			SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),dev_addr);/*将数据保存*/
			SRAM_DMA_Write_Buff((uint8_t *)&PC_Test_Info,sizeof(PC_TEST_DEVICE_INFO),dev_addr+Dev_Privately);
					
		}
	}else if((PC_Test_Info.test_flag == 0x03) || (PC_Test_Info.test_flag == 0x13))		//进入巡回测试，关闭端口1任务，开始定时发送数据
	{	
		if(SysTick_1ms - g_pc_test.tour_tick > 60)
		{
			
			g_pc_test.tour_tick = SysTick_1ms;
			Dbg_Println(DBG_OPT_DEVICE_STATUS,"PC Test BLV_PC_TEST_TOUR_DATASEND：%d num:%d------",PC_Test_Info.test_flag,g_pc_test.tour_num);
			
			if(g_pc_test.tour_num >= 100)	
			{
				/*应答数据*/
				if(PC_Test_Info.test_flag == 0x13)				//网络回复结果
				{
					uint8_t ack_buff[3] = {0};
					ack_buff[0] = 0x13;
					ack_buff[1] = g_pc_test.tour_succ;
					
					Dbg_Println(DBG_OPT_DEVICE_STATUS,"网络回复巡回结果!IP:%d.%d.%d.%d Port:%ld\n",g_pc_test.pc_ip[0],g_pc_test.pc_ip[1],g_pc_test.pc_ip[2],g_pc_test.pc_ip[3],g_pc_test.pc_port);
					Udp_Internal_PC_Testing_Reported(ack_buff,0x02,g_pc_test.pc_ip,g_pc_test.pc_port);
					
				}else if(PC_Test_Info.test_flag == 0x03)		//串口回复结果
				{
					Dbg_Println(DBG_OPT_DEVICE_STATUS,"串口回复巡回结果!\r\n");
					BLV_PC_TEST_TOUR_ACKSend(g_pc_test.tour_succ);
				}
				
				
				PC_Test_Info.test_flag = 0;
				g_pc_test.test_flag = PC_Test_Info.test_flag;
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"PC Test TOUR DATAS END：%d num:%d SUCC:%d",PC_Test_Info.test_flag,g_pc_test.tour_num,g_pc_test.tour_succ);
				
				BUS_Public.check = 0x00;
				BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&PC_Test_Info, sizeof(PC_TEST_DEVICE_INFO));
				SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),dev_addr);/*将数据保存*/
				SRAM_DMA_Write_Buff((uint8_t *)&PC_Test_Info,sizeof(PC_TEST_DEVICE_INFO),dev_addr+Dev_Privately);
										
			}else {
				g_pc_test.tour_num++;
				BLV_PC_TEST_TOUR_DATASEND();		//发送巡回数据
				return RS485OCCUPYTIME;
			}
			
			
		}
	}
	
	return RS485OCCUPYNOTIME;
}


/*******************************************************************************
* Function Name  : BLV_PC_DEVICE_TEST_Data_Processing 
* Description    : PC数据处理函数
* Input          : 
	dev_addr	: 设备信息地址
	data_addr	: 数据地址
	len			：数据长度
* Return         : 
	0x00：处理成功
	0x01：处理失败
*******************************************************************************/
uint8_t BLV_PC_DEVICE_TEST_Data_Processing(uint32_t dev_addr,uint32_t data_addr,uint16_t len)
{
	uint16_t temp = 0;
	uint8_t temp1 = 0;
	Device_Public_Information_G BUS_Public;
	PC_TEST_DEVICE_INFO PC_Test_Info;
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),dev_addr);	
	SRAM_DMA_Read_Buff((uint8_t *)&PC_Test_Info,sizeof(PC_TEST_DEVICE_INFO),dev_addr+Dev_Privately);
	
	
	/*校验巡回数据*/
	if(BLV_PC_TEST_TOUR_DATACheck(data_addr,len) == 0x00)
	{
		Dbg_Println(DBG_OPT_DEVICE_STATUS,"BLV_PC_TEST_TOUR_DATASEND2------");
		BLV_PC_TEST_TOUR_DATASEND2();		//是巡回数据将数据返回
		
		return 0x00;
	}
	
	/*判断一下当前数据是哪个端口发送过来的*/
#if (USE_CORE_TYPE == 1)    //使用C1F核心板
	
	if((data_addr > SRAM_UART1_RecvBuffer_Start_Addr) && (data_addr < SRAM_UART1_RecvBuffer_End_Addr))
	{
		Dbg_Println(DBG_OPT_DEVICE_STATUS,"PC Test UART1------");
		g_pc_test.link_port = 0x01;
	}else if((data_addr > SRAM_UART2_RecvBuffer_Start_Addr) && (data_addr < SRAM_UART2_RecvBuffer_End_Addr))
	{
		Dbg_Println(DBG_OPT_DEVICE_STATUS,"PC Test UART2------");
		g_pc_test.link_port = 0x02;
	}
	
	/*升级回复*/
	if(Uart_Search_Cmd_from_SRAM(data_addr, len) == 0x00)
	{
		Dbg_Switch = 0x00;		//收到升级搜索命令，关闭调试信息
		char* cmd = "Search:1\r\n";
		char ack[35] = {0};
		sprintf(ack, "%s%s\r\n", cmd, APP_NAME);
		
		if(g_pc_test.link_port == 0x01)
		{
			UART1_SendString((uint8_t *)ack, strlen(ack));
		}
		else if(g_pc_test.link_port == 0x02)
		{
			MCU485_SendString_2((uint8_t *)ack, strlen(ack));
		}
	}
	else if(Uart_Jump_Cmd_from_SRAM(data_addr, len) == 0x00)
	{
		char* cmd = "Jump:1\r\n";
		char ack[30] = {0};
		sprintf(ack, "%s%s\r\n", cmd, APP_NAME);
		WDT_Feed();		//防止看门狗复位
		if(g_pc_test.link_port == 0x01)
		{
			UART1_SendString((uint8_t *)ack, strlen(ack));
			Uart1_Flush(100);
		}
		else if(g_pc_test.link_port == 0x02)
		{
			MCU485_SendString_2((uint8_t *)ack, strlen(ack));
		}
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"SYS_ResetExecute!");
		
		SRAM_Write_Word(APPFlag_UartUpgrade_Reset,SRAM_APPFlag_Reset_Source);
		WWDG_ResetCfg(DISABLE);
		DelayMs(100);
		
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"串口升级复位!");
		LOG_LogicInfo_DebugRecord("串口升级复位");
		
		SYS_ResetExecute();		//软件复位
	}
#elif (USE_CORE_TYPE == 2)   //使用C1核心板
	if((data_addr > SRAM_UART0_RecvBuffer_Start_Addr) && (data_addr < SRAM_UART0_RecvBuffer_End_Addr))
	{
		Dbg_Println(DBG_OPT_DEVICE_STATUS,"PC Test UART0------",data_addr,len);
		g_pc_test.link_port = 0x00;
	}else if((data_addr > SRAM_UART2_RecvBuffer_Start_Addr) && (data_addr < SRAM_UART2_RecvBuffer_End_Addr))
	{
		Dbg_Println(DBG_OPT_DEVICE_STATUS,"PC Test UART2------",data_addr,len);
		g_pc_test.link_port = 0x02;
	}
	
	/*升级回复*/
	if(Uart_Search_Cmd_from_SRAM(data_addr, len) == 0x00)
	{
		char* cmd = "Search:1\r\n";
		char ack[35] = {0};
		sprintf(ack, "%s%s\r\n", cmd, APP_NAME);
		
		if(g_pc_test.link_port == 0x00)
		{
			UART0_SendString((uint8_t *)ack, strlen(ack));
		}
		else if(g_pc_test.link_port == 0x02)
		{
			MCU485_SendString_2((uint8_t *)ack, strlen(ack));
		}
	}
	else if(Uart_Jump_Cmd_from_SRAM(data_addr, len) == 0x00)
	{
		char* cmd = "Jump:1\r\n";
		char ack[30] = {0};
		sprintf(ack, "%s%s\r\n", cmd, APP_NAME);
		WDT_Feed();		//防止看门狗复位
		if(g_pc_test.link_port == 0x00)
		{
			UART0_SendString((uint8_t *)ack, strlen(ack));
			Uart0_Flush(100);
		}
		else if(g_pc_test.link_port == 0x02)
		{
			MCU485_SendString_2((uint8_t *)ack, strlen(ack));
		}
		Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"SYS_ResetExecute!");
		
		SRAM_Write_Word(APPFlag_UartUpgrade_Reset,SRAM_APPFlag_Reset_Source);
		WWDG_ResetCfg(DISABLE);
		DelayMs(100);
		SYS_ResetExecute();		//软件复位
	}
#endif  //USE_CORE_TYPE == CORE_TYPE_C1F		
	
	
	temp = SRAM_Read_Byte(data_addr + PKT2_ADD_FM);
	if(temp != 0x00)	
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PC PKT_ADD_FM Fail!");
		return 0x01;						//发送地址不对
	}
//	temp = SRAM_Read_Byte(data_addr + PKT2_TYPE);
//	if(((temp & 0x0F) == PC_Test_Info.DevSendSN) || ((temp & 0x40) == 0x40))	//序列号不同，同时不是重发数据
//	{
//		Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"PC PKT_TYPE the same and Not resend!");
//		return 0x01;			//序号不对
//	}
	temp = SRAM_Read_Byte(data_addr + PKT2_DevType);
	if(temp != PCTESTTYPE)	
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PC PKT_DevType Fail!");
		return 0x01;					//设备类型不对
	}
	temp = SRAM_Read_Byte(data_addr + PKT2_ADD_TO);
	if(temp != 0x00)	
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PC PKT_ADD_TO Fail!");
		return 0x01;						//接收地址不对
	}
	temp = SRAM_Read_Byte(data_addr + PKT2_LEN);
	if(temp != len||(len>256)) //2022-12-13   增加长度是否大于512Byte判断 
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PC PKT_LEN Fail!");
		return 0x01;						//长度不对
	}
	
		/*测试数据校验*/    //2022-12-13   将和校验放在长度校验之后 
	if(Dev_CheckSum(data_addr,len) != 0x00) 
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PC Check Fail!");
		return 0x01;	//和校验
	}
	
	
	
	Dbg_Println(DBG_OPT_DEVICE_STATUS,"PC Test Data Addr:%08X Len:%d",data_addr,len);
	
	temp = SRAM_Read_Byte(data_addr + PKT2_TYPE);
	PC_Test_Info.DevSendSN = temp & 0x0F;
	g_pc_test.DevSendSN = PC_Test_Info.DevSendSN;
	/*接收数据*/
	temp = SRAM_Read_Byte(data_addr + PKT2_CMD);
	switch(temp)
	{
		case BLV_PC_TEST_SearchMCU_CMD:			//搜索主机
			
			break;
		case BLV_PC_TEST_SyncTime_CMD:			//同步主机时间
			
			SyncTime_DATA_Processing(data_addr,len);
			break;
		case BLV_PC_TEST_QueryTime_CMD:			//查询主机时间
			
			QueryTime_Relay_DATA_Packaging(data_addr,len);
			break;
		case BLV_PC_TEST_ConfigInfo_CMD:		//配置信息下发 - 下发设备存在信息
			
			break;
		case BLV_PC_TEST_ReadRegister_CMD:		//读取映射寄存器内容
			BLV_PC_ReadRegister_DataDeal(data_addr,len);
			break;
		case BLV_PC_TEST_WriteRegister_CMD:		//写映射寄存器内容 - 设置MAC地址项目编号、、
			BLV_PC_WriteRegister_DataDeal(data_addr,len);
			break;
		case BLV_PC_TEST_StartTesting_CMD:		//开启设备测试,发送测试数据
			/*发送测试数据 */
			temp1 = SRAM_Read_Byte(data_addr + PKT2_PARA);
			if(temp1 == 0x01)			//测试输入 - 同时检测时间
			{
				g_pc_test.test_flag = 0x01;
				
				g_pc_test.test_dev = SRAM_Read_Byte(data_addr + PKT2_PARA + 1);
				g_pc_test.test_addr = SRAM_Read_Byte(data_addr + PKT2_PARA + 2);
				PC_Test_Info.test_time = SRAM_Read_Byte(data_addr + PKT2_PARA + 3);		//测试时间，单位：分钟
				
				PC_Test_Info.test_flag = g_pc_test.test_flag;
				PC_Test_Info.test_tick = SysTick_1ms;
				PC_Test_Info.test_time *= 60000;
			}
			else if(temp1 == 0x02)		//测试输出
			{
				g_pc_test.test_flag = 0x02;		
				PC_Test_Info.test_flag = g_pc_test.test_flag;
				PC_Test_Info.test_tick = SysTick_1ms;
				PC_Test_Info.test_time = 120000;
			
				BLV_PC_Testing_DataDeal(data_addr,len);
			}else if(temp1 == 0x03)		//开启巡回测试 - 测试485端口
			{
				g_pc_test.test_flag = 0x03;
				PC_Test_Info.test_flag = g_pc_test.test_flag;
				g_pc_test.tour_num = 0;
				g_pc_test.tour_succ = 0;
			}
			break;
		case BLV_PC_TEST_SetBaud_CMD:			//设置PC端口波特率，进入配置模式
			
			break;
		case BLV_PC_SET_DEBUG_CMD:				//设置Debug调试输出信息
			/*
				参数1：控制参数  0：关 1：开
					bit0:	系统调试信息打印开关
					bit1:	网络调试信息打印开关
					bit2:	设备驱动层打印调试信息打印开关
					bit3:	逻辑调试信息打印开关
			*/
		{
			uint32_t temp_switch = 0x00FFFFFF;
			switch(len)
			{
				case 0x0C:
				{
					temp_switch = 0x00FFFFFF;
					Dbg_Switch &= temp_switch;
					temp_switch = SRAM_Read_Byte(data_addr + PKT2_PARA + 3);
					temp_switch <<= 24;
					Dbg_Switch |= temp_switch;
				}
				case 0x0B:
				{
					temp_switch = 0xFF00FFFF;
					Dbg_Switch &= temp_switch;
					temp_switch = SRAM_Read_Byte(data_addr + PKT2_PARA + 2);
					temp_switch <<= 16;
					Dbg_Switch |= temp_switch;
				}
				case 0x0A:
				{
					temp_switch = 0xFFFF00FF;
					Dbg_Switch &= temp_switch;
					temp_switch = SRAM_Read_Byte(data_addr + PKT2_PARA + 1);
					temp_switch <<= 8;
					Dbg_Switch |= temp_switch;
				}
				case 0x09:
				{
					temp_switch = 0xFFFFFF00;
					Dbg_Switch &= temp_switch;
					temp_switch = SRAM_Read_Byte(data_addr + PKT2_PARA );
					Dbg_Switch |= temp_switch;
				}
					break;
				
			}
		
			Dbg_Switch &= 0x00;
			Dbg_Switch |= SRAM_Read_Byte(data_addr + PKT2_PARA);
		
			printf("Dbg_Switch:%08X",Dbg_Switch);
		}
			break;
		case BLV_PC_TEST_GPIO_CMD:
			Dbg_Println(DBG_OPT_DEVICE_STATUS,"BLV_PC_TEST_GPIO_CMD");
			TEST_GPIO_Relay_Fail();
			break;
		case BLV_PC_SET_MCU_Revision_CMD:		//设置MCU型号以及中控型号
			BLV_PC_SET_MCU_Revision_Data_Reported(data_addr,len);
			break;
		case BLV_PC_READ_MCU_Revision_CMD:		//读取MCU型号以及中控型号
			BLV_PC_READ_MCU_Revision_Data_Reported(data_addr,len);
			break;
		case BLV_PC_SET_MQTT_CMD:      	//设置MQTT参数
			BLV_PC_SET_MQTT_Reported(data_addr,len);
			break;
		case BLV_PC_READ_MQTT_CMD:      //读取MQTT参数
			Dbg_Println(DBG_OPT_DEVICE_STATUS,"PC_READ_MQTT:%d", BLV_PC_READ_MQTT_Reported(data_addr,len));
			break;
		case BLV_PC_CORE_TEST_CMD:		//开启PC测试
			
			BLV_PC_CORE_TEST_Data_Reported();
		
			break;
		case BLV_PC_READ_RCU_Data_CMD:
			BLV_PC_READ_RCU_Data_Reported(data_addr,len);
			break;
        case BLV_PC_READ_Device_Data_CMD:
            //读取设备信息
            BLV_PC_READ_Device_Data_Reported(data_addr,len);
            break;
		case BLV_PC_READ_RCU_VERSION_CMD:
            //读取设备信息
            BLV_PC_READ_RCU_VERSION_Reported(data_addr,len);
            break;
		default: break;
	}
	
	BUS_Public.check = 0x00;
	BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&PC_Test_Info, sizeof(PC_TEST_DEVICE_INFO));
	SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),dev_addr);/*将数据保存*/
	SRAM_DMA_Write_Buff((uint8_t *)&PC_Test_Info,sizeof(PC_TEST_DEVICE_INFO),dev_addr+Dev_Privately);
						
	
	return 0;
}

uint8_t BLV_PC_TEST_SearchMCU_DataDeal(PC_TEST_DEVICE_INFO *Dev_Info,uint32_t data_addr,uint16_t len)
{
	uint8_t ack_buff[60];
	
	
	memset(ack_buff,0,60);
	
	ack_buff[PKT2_ADD_FM] = 0x00;						//己方（发送者）地址 - 默认：0x00
	ack_buff[PKT2_TYPE] = Dev_Info->DevSendSN;			//设备序列号
	ack_buff[PKT2_DevType] = PCTESTTYPE;				//设备类型
	ack_buff[PKT2_ADD_TO] = 0x00;						//对方地址 - 默认：0x00
	ack_buff[PKT2_LEN] = 54;							//数据长度
	ack_buff[PKT2_CHKSUM] = 0x00;						//校验值
	ack_buff[PKT2_CMD] = BLV_PC_TEST_SearchMCU_CMD;						//命令字
	
	ack_buff[PKT2_PARA] = 0x00;							//服务器IP地址 - 4Byte
	ack_buff[PKT2_PARA] = 0x00;							//子网掩码 - 4Byte
	ack_buff[PKT2_PARA] = 0x00;							//网关 - 4Byte
	ack_buff[PKT2_PARA] = 0x00;							//端口 - 2Byte
	ack_buff[PKT2_PARA] = 0x00;							//MAC地址 - 6Byte
	ack_buff[PKT2_PARA] = 0x00;							//版本号 - 20Byte
	ack_buff[PKT2_PARA] = 0x00;							//配置数据版本号 - 3Byte
	ack_buff[PKT2_PARA] = 0x00;							//项目编号 - 2Byte
	
	/*发送数据 len=9+45*/
	
	return 0;
}

/*******************************************************************************
* Function Name  : BLV_PC_ReadRegister_DataDeal
* Description    : 读取映射寄存器
* Input          : 
	data_addr	: 处理数据地址
	len			：处理数据长度
* Return         : 
*******************************************************************************/
uint8_t BLV_PC_ReadRegister_DataDeal(uint32_t data_addr,uint16_t len)
{
	uint8_t i = 0,temp = 0;
	uint32_t read_register = 0,temp_offset = 0,temp_data = 0;
	uint16_t temp_len = 0;
	uint8_t back_data[100];
	
	memset(back_data,0,100);
	
	temp = SRAM_Read_Byte(data_addr + PKT2_PARA);	//设置寄存器个数,最大10个
	if(temp > 10)	back_data[PKT2_PARA] = 10;	//读取寄存器个数,最大10个
	else back_data[PKT2_PARA] = temp;		
	/*读取寄存器内容*/
	for(i = 0;i<back_data[PKT2_PARA];i++)
	{
		back_data[PKT2_PARA+i*8+4] = SRAM_Read_Byte(data_addr + PKT2_PARA + i*4 + 4);
		back_data[PKT2_PARA+i*8+3] = SRAM_Read_Byte(data_addr + PKT2_PARA + i*4 + 3);
		back_data[PKT2_PARA+i*8+2] = SRAM_Read_Byte(data_addr + PKT2_PARA + i*4 + 2);
		back_data[PKT2_PARA+i*8+1] = SRAM_Read_Byte(data_addr + PKT2_PARA + i*4 + 1);
		
		temp_offset = back_data[PKT2_PARA+i*8+4];
		temp_offset <<= 8;
		temp_offset |= back_data[PKT2_PARA+i*8+3];
		temp_offset <<= 8;
		temp_offset |= back_data[PKT2_PARA+i*8+2];
		temp_offset <<= 8;
		temp_offset |= back_data[PKT2_PARA+i*8+1];
		
		
		
		temp_offset = SRAM_Read_DW(data_addr + PKT2_PARA + i*8 + 1);
		temp_data = SRAM_Read_DW(data_addr + PKT2_PARA + i*8 + 5);
		
		read_register = SRAM_Register_Start_ADDRESS + temp_offset;
		Dbg_Println(DBG_BIT_NET_STATUS_bit,"temp_offset:%08X data:%d",read_register,temp_data);
		
		if(read_register > SRAM_Register_End_ADDRESS)	
		{
			Dbg_Println(DBG_BIT_NET_STATUS_bit,"Not In The Right Range");
			continue;
		}
		temp_data = SRAM_Read_DW(read_register);					//读取寄存器内容
		
		back_data[PKT2_PARA+i*8+8] = ((temp_data >> 24) & 0xFF);		
		back_data[PKT2_PARA+i*8+7] = ((temp_data >> 16) & 0xFF);
		back_data[PKT2_PARA+i*8+6] = ((temp_data >> 8) & 0xFF);
		back_data[PKT2_PARA+i*8+5] = (temp_data & 0xFF);
	}
	
	temp_len = 0x09 + back_data[PKT2_PARA]*8;
	
	/*回复数据打包*/
	back_data[PKT2_ADD_FM] = 0x00;			//本机地址
	back_data[PKT2_TYPE] = g_pc_test.DevSendSN;
	back_data[PKT2_DevType] = PCTESTTYPE;						//设备类型
	back_data[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
	back_data[PKT2_LEN] = temp_len & 0xFF;						//本次发送数据长度
	back_data[PKT2_LEN_8] = (temp_len >> 8) & 0xFF;
	back_data[PKT2_CHKSUM] = 0x00;								//校验
	back_data[PKT2_CMD] = BLV_PC_TEST_ReadRegister_Relay;		//设置命令

	back_data[PKT2_CHKSUM] = CheckSum(back_data,temp_len);
	
	/*发送数据*/
	if(g_pc_test.link_port == 0x00)
	{
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
			MCU485_SendString_0(back_data,temp_len);			//串口0
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
			UART0_SendString(back_data,temp_len);				//串口0
		#endif
	}else if(g_pc_test.link_port == 0x01)
	{	
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
			UART1_SendString(back_data,temp_len);				//串口1
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
			MCU485_SendString_1(back_data,temp_len);			//串口1
		#endif	
	}else if(g_pc_test.link_port == 0x02)
	{
		MCU485_SendString_2(back_data,temp_len);			//串口2
	}else {
		return 0xF0;
	}
	
	return 0x00;
}

/*******************************************************************************
* Function Name  : BLV_PC_WriteRegister_DataDeal
* Description    : 写映射寄存器
* Input          : 
	data_addr	: 处理数据地址
	len			：处理数据长度
* Return         : 
*******************************************************************************/
uint8_t BLV_PC_WriteRegister_DataDeal(uint32_t data_addr,uint16_t len)
{
	uint8_t i = 0,temp = 0,temp_num = 0,temp1 = 0x01;
	uint32_t read_register = 0,temp_offset = 0,temp_data = 0;
	uint16_t temp_len = 0x09;
	uint8_t back_data[10];
	
	memset(back_data,0,10);

	/*设置寄存器内容*/
	temp = SRAM_Read_Byte(data_addr + PKT2_PARA);	//设置寄存器个数,最大10个
	
	if(temp > 10)	temp_num = 10;		//设置寄存器个数,最大10个
	else temp_num = temp;	
	
	for(i = 0;i<temp_num;i++)
	{
		temp_offset = SRAM_Read_DW(data_addr + PKT2_PARA + i*8 + 1);
		temp_data = SRAM_Read_DW(data_addr + PKT2_PARA + i*8 + 5);
		
		read_register = SRAM_Register_Start_ADDRESS + temp_offset;
		Dbg_Println(DBG_BIT_NET_STATUS_bit,"temp_offset:%08X data:%d",read_register,temp_data);
		
		if(read_register > SRAM_Register_End_ADDRESS)	
		{
			temp1 = 0x00;
			Dbg_Println(DBG_BIT_NET_STATUS_bit,"Not In The Right Range");
			continue;
		}
		
		SRAM_Write_DW(temp_data,read_register);
		if(temp_data != SRAM_Read_DW(read_register))	temp = 0x02;		//写入失败
	}
	
	Retain_Flash_Register_Data();		//将数据保存到Flash中
	
	SRAM_Read_Buff(back_data, 4, SRAM_Register_Start_ADDRESS + Register_NETMACKADDR_OFFSET);
	Dbg_Println(DBG_BIT_SYS_STATUS_bit,"MACAddr:%02X.%02X.%02X.%02X.%02X.%02X",back_data[0],back_data[1],back_data[2],back_data[3],back_data[4],back_data[5]);
	
	/*回复数据打包*/
	back_data[PKT2_ADD_FM] = 0x00;			//本机地址
	back_data[PKT2_TYPE] = g_pc_test.DevSendSN;
	back_data[PKT2_DevType] = PCTESTTYPE;						//设备类型
	back_data[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
	back_data[PKT2_LEN] = temp_len & 0xFF;						//本次发送数据长度
	back_data[PKT2_LEN_8] = (temp_len >> 8) & 0xFF;
	back_data[PKT2_CHKSUM] = 0x00;								//校验
	back_data[PKT2_CMD] = BLV_PC_TEST_WriteRegister_Relay;		//设置命令

	back_data[PKT2_PARA] = temp1;		//设置成功
	back_data[PKT2_CHKSUM] = CheckSum(back_data,temp_len);
	
	/*发送数据*/
	if(g_pc_test.link_port == 0x00)
	{
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
			MCU485_SendString_0(back_data,temp_len);			//串口0
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
			UART0_SendString(back_data,temp_len);				//串口0
		#endif
	}else if(g_pc_test.link_port == 0x01)
	{	
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
			UART1_SendString(back_data,temp_len);				//串口1
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
			MCU485_SendString_1(back_data,temp_len);			//串口1
		#endif	
	}else if(g_pc_test.link_port == 0x02)
	{
		MCU485_SendString_2(back_data,temp_len);			//串口2
	}else {
		return 0xF0;
	}
	
	return 0x00;
}


/*******************************************************************************
* Function Name  : BLV_PC_Testing_DataDeal
* Description    : 测试数据处理
* Input          : 
	data_addr	: 处理数据地址
	len			：处理数据长度
* Return         : 
*******************************************************************************/
uint8_t BLV_PC_Testing_DataDeal(uint32_t data_addr,uint16_t len)
{
	uint8_t control_dev = 0,control_addr = 0,control_cmd = 0,temp = 0,temp1 = 0,temp2 = 0;
	uint8_t control_num = 0;
	
	uint32_t device_listaddr = 0;
	uint16_t temp_len = 0x09;
	uint8_t back_data[15];
	
	memset(back_data,0,15);
	
	control_dev = SRAM_Read_Byte(data_addr + PKT2_PARA + 1);		//控制设备类型
	control_addr = SRAM_Read_Byte(data_addr + PKT2_PARA + 2);		//控制设备地址
	
    Dbg_Println(DBG_OPT_DEVICE_STATUS,"PC Test DevType:%08x",control_dev);
    Dbg_Println(DBG_OPT_DEVICE_STATUS,"PC Test DevAddr:%08x",control_addr);
	/*记录一下当前测试的设备类型及设备地址*/
	g_pc_test.test_dev = control_dev;
	g_pc_test.test_addr = control_addr;
	
	device_listaddr = Find_Device_List_Information(control_dev,control_addr);
	if((device_listaddr < SRAM_Device_List_Start_Addr) || (device_listaddr > SRAM_Device_List_End_Addr))	{
        Dbg_Println(DBG_OPT_DEVICE_STATUS,"PC Test Find Dev Error:%08x",control_dev);
        return 0xF0;
    }
	
	switch(control_dev)
	{
		case DEV_C5IO_Type:		//C5IO 数据处理
			control_cmd = SRAM_Read_Byte(data_addr + PKT2_PARA + 3);
			
			if(control_cmd == BLV_C5IO_Set_Relay_CMD)		//继电器控制
			{
				control_num = len - 12;
				if(control_num >= 6)	control_num = 6;	//目前最长6Byte的控制数据
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"PC Test C5IO_Control Len %d,Control_NUM:%d",len,control_num);
				
				for(uint8_t i = 0;i<control_num;i++)
				{
					temp = SRAM_Read_Byte(data_addr + PKT2_PARA + 4 + i);
					for(uint8_t j = 0;j<4;j++)
					{
						temp2 = i*4+j;					//控制回路
						temp1 = (temp >> j*2) & 0x03;	//控制状态
						if(temp1 != 0x00)	
						{
							Dbg_Println(DBG_OPT_DEVICE_STATUS,"PC Test C5IO_Control_RelayCH%d status:%d - %08X",temp2,temp1,device_listaddr);
							{
								UINT8 control[6];
								control[0] = Dev_Host_HVout;
								control[1] = 0x00;
								control[2] = temp2;  //回路
								control[3] = 0x00;
								control[4] = temp1;  //控制状态
								control[5] = 0x00;
								DevActionCtrl(control, 6);			//继电器
							}
							BUS_C5IO_Control_Relay(device_listaddr,temp2,temp1);
						}
					}
				}
			}else if(control_cmd == BLV_C5IO_Set_Do_CMD)	//DO控制
			{
				for(uint8_t i = 0;i<2;i++)
				{
					temp = SRAM_Read_Byte(data_addr + PKT2_PARA + 4 + i);
					for(uint8_t j = 0;j<4;j++)
					{
						temp2 = i*4+j;					//控制回路
						temp1 = (temp >> j*2) & 0x03;	//控制状态
						if(temp1 != 0x00)	
						{
							Dbg_Println(DBG_OPT_DEVICE_STATUS,"PC Test C5IO_Control_DoCH%d status:%d",temp2,temp1);
							BUS_C5IO_Control_Do(device_listaddr,temp2,temp1);
						}
					}
				}
			}
			return 0x00;
		case DEV_C5MUSIC_Type:
			control_cmd = SRAM_Read_Byte(data_addr + PKT2_PARA + 3);
			if(control_cmd == BLV_C5MUSIC_Specify_Play_CMD)
			{
				temp = SRAM_Read_Byte(data_addr + PKT2_PARA + 4);	//播放状态
				temp1 = SRAM_Read_Byte(data_addr + PKT2_PARA + 5);	//播放文件夹
				temp2 = SRAM_Read_Byte(data_addr + PKT2_PARA + 6);	//播放ID
				
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"PC Test C5Music_Control dir:%d id:%d status:%d",temp1,temp2,temp);
				BUS_C5MUSIC_Playback(device_listaddr,temp1,temp,temp2);
			}
			
			/*回复数据打包*/
			back_data[PKT2_ADD_FM] = 0x00;			//本机地址
			back_data[PKT2_TYPE] = g_pc_test.DevSendSN;
			back_data[PKT2_DevType] = PCTESTTYPE;						//设备类型
			back_data[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
			back_data[PKT2_LEN] = temp_len & 0xFF;						//本次发送数据长度
			back_data[PKT2_LEN_8] = (temp_len >> 8) & 0xFF;
			back_data[PKT2_CHKSUM] = 0x00;								//校验
			back_data[PKT2_CMD] = BLV_PC_TEST_StartTesting_Relay;		//设置命令

			back_data[PKT2_PARA] = 0x01;		//设置成功
			back_data[PKT2_CHKSUM] = CheckSum(back_data,temp_len);
			
//			/*发送数据*/
//			if(g_pc_test.link_port == 0x00)
//			{
//				UART0_SendString(back_data,temp_len);			//串口0
//			}else if(g_pc_test.link_port == 0x01)
//			{
//				MCU485_SendString_1(back_data,temp_len);			//串口1
//			}else if(g_pc_test.link_port == 0x02)
//			{
//				MCU485_SendString_2(back_data,temp_len);			//串口2
//			}else {
//				return 0xF0;
//			}
			/*发送数据*/
			if(g_pc_test.link_port == 0x00)
			{
				#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
					MCU485_SendString_0(back_data,temp_len);			//串口0
				#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
					UART0_SendString(back_data,temp_len);				//串口0
				#endif
			}else if(g_pc_test.link_port == 0x01)
			{	
				#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
					UART1_SendString(back_data,temp_len);				//串口1
				#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
					MCU485_SendString_1(back_data,temp_len);			//串口1
				#endif	
			}else if(g_pc_test.link_port == 0x02)
			{
				MCU485_SendString_2(back_data,temp_len);			//串口2
			}else {
				return 0xF0;
			}
			
			break;
//#if (USE_FLOOR_TYPE == 2)  //C12底板
			case DEV_RS485_PWM:
				control_cmd = SRAM_Read_Byte(data_addr + PKT2_PARA + 3);
				if(control_cmd == C12_SET_LIGHT_CMD)
				{
					temp = SRAM_Read_Byte(data_addr + PKT2_PARA + 4);	//设置回路
					temp1 = SRAM_Read_Byte(data_addr + PKT2_PARA + 5);	//亮度值
					temp2 = SRAM_Read_Byte(data_addr + PKT2_PARA + 6);	//渐变时间
					
					Dbg_Println(DBG_BIT_NET_STATUS_bit,"PC Test C12Dimming:%d light:%d fade:%d",temp1,temp2,temp);

					if(temp)
					{
						UINT8 control[6];
						control[0] = DEV_RS485_PWM;
						control[1] = 0x00;
						control[2] = temp-1;  //回路
						control[3] = 0x00;
						control[4] = 0x01;  //控制状态
						control[5] = temp1;  //亮度值
						DevActionCtrl(control, 6);			//继电器
					}
//					BUS_C12Dimming_Control_Light(device_listaddr, CHx, temp1, temp2, 0);
				}
			break;
//#endif

		default: 
        //其他控制命令
        {
            uint8_t control[8];
            
            
            SRAM_Read_Buff(control,6,data_addr + PKT2_PARA + 1);
            DevActionCtrl(control, 6);
            Dbg_Print_Buff(DBG_BIT_NET_STATUS_bit,"PC Test Control Data:",control,6);
            
            /*回复数据打包*/
			back_data[PKT2_ADD_FM] = 0x00;			//本机地址
			back_data[PKT2_TYPE] = g_pc_test.DevSendSN;
			back_data[PKT2_DevType] = PCTESTTYPE;						//设备类型
			back_data[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
			back_data[PKT2_LEN] = temp_len & 0xFF;						//本次发送数据长度
			back_data[PKT2_LEN_8] = (temp_len >> 8) & 0xFF;
			back_data[PKT2_CHKSUM] = 0x00;								//校验
			back_data[PKT2_CMD] = BLV_PC_TEST_StartTesting_Relay;		//设置命令

			back_data[PKT2_PARA] = 0x01;		//设置成功
			back_data[PKT2_CHKSUM] = CheckSum(back_data,temp_len);
			
			/*发送数据*/
			if(g_pc_test.link_port == 0x00)
			{
				#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
					MCU485_SendString_0(back_data,temp_len);			//串口0
				#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
					UART0_SendString(back_data,temp_len);				//串口0
				#endif
			}else if(g_pc_test.link_port == 0x01)
			{	
				#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
					UART1_SendString(back_data,temp_len);				//串口1
				#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
					MCU485_SendString_1(back_data,temp_len);			//串口1
				#endif	
			}else if(g_pc_test.link_port == 0x02)
			{
				MCU485_SendString_2(back_data,temp_len);			//串口2
			}else {
				return 0xF0;
			}
        }
        break;
	}
	
	
	
	return 0x00;
}



/*测试数据上报*/
uint8_t BLV_PC_Testing_Data_Reported(uint8_t type,uint8_t dev_type,uint8_t dev_addr,uint32_t data_addr,uint8_t data_len)
{
	uint8_t send_buff[50];
	memset(send_buff,0,50);
	
	Dbg_Println(DBG_OPT_DEVICE_STATUS,"%s",__func__);
	g_pc_test.DevSendSN++;
	
	send_buff[PKT2_ADD_FM] = 0x00;			//本机地址
	send_buff[PKT2_TYPE] = g_pc_test.DevSendSN;
	send_buff[PKT2_DevType] = PCTESTTYPE;						//设备类型
	send_buff[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
	send_buff[PKT2_LEN] = 0x08+data_len+3;						//本次发送数据长度
	send_buff[PKT2_CHKSUM] = 0x00;								//校验
	send_buff[PKT2_CMD] = BLV_PC_TEST_StartTesting_Relay;		//设置命令
	
	send_buff[PKT2_PARA] = type;		//输出上报
	send_buff[PKT2_PARA + 1] = dev_type;		//输入上报
	send_buff[PKT2_PARA + 2] = dev_addr;		//输入上报
	
	for(uint8_t i=0;i<data_len;i++)
	{
		send_buff[PKT2_PARA + 3 + i] = SRAM_Read_Byte(data_addr + i);
	}
	
	
	send_buff[PKT2_CHKSUM] = CheckSum(send_buff,send_buff[PKT2_LEN]);
	
	/*发送数据*/
	if(g_pc_test.link_port == 0x00)	
	{
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
			MCU485_SendString_0(send_buff,send_buff[PKT2_LEN]);			//串口0
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
			UART0_SendString(send_buff,send_buff[PKT2_LEN]);				//串口0
		#endif
	}else if(g_pc_test.link_port == 0x01)
	{	
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
			UART1_SendString(send_buff,send_buff[PKT2_LEN]);				//串口1
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
			MCU485_SendString_1(send_buff,send_buff[PKT2_LEN]);			//串口1
		#endif	
	}else if(g_pc_test.link_port == 0x02)
	{
		MCU485_SendString_2(send_buff,send_buff[PKT2_LEN]);			//串口2
	}else {
		return 0xF0;
	}
	
	return 0x00;
}

uint8_t BLV_PC_Testing_Data_Reported2(uint8_t type,uint8_t dev_type,uint8_t dev_addr,uint8_t *data_buff,uint8_t data_len)
{
	uint8_t send_buff[50];
	memset(send_buff,0,50);
	
	Dbg_Println(DBG_OPT_DEVICE_STATUS,"%s",__func__);
	g_pc_test.DevSendSN++;
	
	send_buff[PKT2_ADD_FM] = 0x00;			//本机地址
	send_buff[PKT2_TYPE] = g_pc_test.DevSendSN;
	send_buff[PKT2_DevType] = PCTESTTYPE;						//设备类型
	send_buff[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
	send_buff[PKT2_LEN] = 0x08+data_len+3;						//本次发送数据长度
	send_buff[PKT2_CHKSUM] = 0x00;								//校验
	send_buff[PKT2_CMD] = BLV_PC_TEST_StartTesting_Relay;		//设置命令
	
	send_buff[PKT2_PARA] = type;		//输出上报
	send_buff[PKT2_PARA + 1] = dev_type;		//输入上报
	send_buff[PKT2_PARA + 2] = dev_addr;		//输入上报
	
	for(uint8_t i=0;i<data_len;i++)
	{
		send_buff[PKT2_PARA + 3 + i] = data_buff[i];
	}
	
	
	send_buff[PKT2_CHKSUM] = CheckSum(send_buff,send_buff[PKT2_LEN]);
	
	/*发送数据*/
	if(g_pc_test.link_port == 0x00)	
	{
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
			MCU485_SendString_0(send_buff,send_buff[PKT2_LEN]);			//串口0
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
			UART0_SendString(send_buff,send_buff[PKT2_LEN]);				//串口0
		#endif
	}else if(g_pc_test.link_port == 0x01)
	{	
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
			UART1_SendString(send_buff,send_buff[PKT2_LEN]);				//串口1
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
			MCU485_SendString_1(send_buff,send_buff[PKT2_LEN]);			//串口1
		#endif	
	}else if(g_pc_test.link_port == 0x02)
	{
		MCU485_SendString_2(send_buff,send_buff[PKT2_LEN]);			//串口2
	}else {
		return 0xF0;
	}
	
	return 0x00;
}

/*发送巡回测试数据*/
uint8_t BLV_PC_TEST_TOUR_DATASEND(void)
{
	uint8_t send_buff[10];
	memset(send_buff,0,10);
	
	for(uint8_t i = 0;i<10;i++)
	{
		send_buff[i] = i;
	}
#if (USE_CORE_TYPE == 1)    //使用C1F核心板
	MCU485_SendString_0(send_buff,10);			//串口0
#elif (USE_CORE_TYPE == 2)   //使用C1核心板
	MCU485_SendString_1(send_buff,10);			//串口1
#endif  //USE_CORE_TYPE == CORE_TYPE_C1F			
	
	
	return 0;
}

uint8_t BLV_PC_TEST_TOUR_DATASEND2(void)
{
	uint8_t send_buff[10];
	memset(send_buff,0,10);
	
	for(uint8_t i = 0;i<10;i++)
	{
		send_buff[i] = i;
	}
	
	MCU485_SendString_2(send_buff,10);			//串口2
	
	return 0;
}

/*巡回数据校验*/
uint8_t BLV_PC_TEST_TOUR_DATACheck(uint32_t data_addr,uint16_t len)
{
	uint8_t temp = 0;
	uint8_t i=0;
	
	for(i=0;i<10;i++)
	{
		temp = SRAM_Read_Byte(data_addr + i);
		if(temp != i)	return 0xF0;
	}
	return 0x00;
}

/*巡回测试 - 回复数据*/
uint8_t BLV_PC_TEST_TOUR_ACKSend(uint8_t ack_data)
{
	uint8_t send_buff[10];
	memset(send_buff,0,10);
	
	Dbg_Println(DBG_OPT_DEVICE_STATUS,"%s",__func__);
	g_pc_test.DevSendSN++;
	
	send_buff[PKT2_ADD_FM] = 0x00;			//本机地址
	send_buff[PKT2_TYPE] = g_pc_test.DevSendSN;
	send_buff[PKT2_DevType] = PCTESTTYPE;						//设备类型
	send_buff[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
	send_buff[PKT2_LEN] = 0x0A;						//本次发送数据长度
	send_buff[PKT2_CHKSUM] = 0x00;								//校验
	send_buff[PKT2_CMD] = BLV_PC_TEST_StartTesting_Relay;		//设置命令
	
	send_buff[PKT2_PARA] = 0x03;			//巡回测试类型
	send_buff[PKT2_PARA+1] = ack_data;		//巡回测试结果
	
	send_buff[PKT2_CHKSUM] = CheckSum(send_buff,send_buff[PKT2_LEN]);

	/*发送数据*/
	if(g_pc_test.link_port == 0x00)
	{
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
			MCU485_SendString_0(send_buff,send_buff[PKT2_LEN]);			//串口0
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
			UART0_SendString(send_buff,send_buff[PKT2_LEN]);				//串口0
		#endif
	}else if(g_pc_test.link_port == 0x01)
	{	
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
			UART1_SendString(send_buff,send_buff[PKT2_LEN]);				//串口1
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
			MCU485_SendString_1(send_buff,send_buff[PKT2_LEN]);			//串口1
		#endif	
	}else if(g_pc_test.link_port == 0x02)
	{
		MCU485_SendString_2(send_buff,send_buff[PKT2_LEN]);			//串口2
	}else {
		return 0xF0;
	}
	
	return 0x00;
}

/*设置MCU版本号
	数据内容：MCU版本号 64Byte + 中控版本号 64Byte
*/
uint8_t BLV_PC_SET_MCU_Revision_Data_Reported(uint32_t data_addr,uint8_t data_len)
{
	uint8_t temp_data = 0;
	uint32_t write_addr = data_addr;
	uint8_t send_buff[100];
	memset(send_buff,0,100);
	
	if(data_len == PKT2_PARA + 129)
	{
		write_addr = data_addr+PKT2_PARA;
		temp_data = SRAM_Read_Byte(write_addr);		//需要设置参数
		
		/*数据处理*/
		if((temp_data & 0x01) != 0x00)
		{
			write_addr = data_addr+PKT2_PARA+1;
			SRAM_Read_Buff(send_buff,64,write_addr);
			Flash_Write(send_buff,64,FLASH_MCU_Model_Revision_ADDRESS);
		}

		if((temp_data & 0x02) != 0x00)
		{
			write_addr = data_addr+PKT2_PARA+65;
			SRAM_Read_Buff(send_buff,64,write_addr);
			Flash_Write(send_buff,64,FLASH_MCU_Control_Revision_ADDRESS);
		}
		
		temp_data = 0x01;
	}
	
	/*数据处理回复*/
	Dbg_Println(DBG_OPT_DEVICE_STATUS,"%s",__func__);
	g_pc_test.DevSendSN++;
	
	send_buff[PKT2_ADD_FM] = 0x00;			//本机地址
	send_buff[PKT2_TYPE] = g_pc_test.DevSendSN;
	send_buff[PKT2_DevType] = PCTESTTYPE;						//设备类型
	send_buff[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
	send_buff[PKT2_LEN] = 0x09;									//本次发送数据长度
	send_buff[PKT2_CHKSUM] = 0x00;								//校验
	send_buff[PKT2_CMD] = BLV_PC_SET_MCU_Revision_Relay;		//设置命令
	
	send_buff[PKT2_PARA] = temp_data;				//设置结果	
	
	send_buff[PKT2_CHKSUM] = CheckSum(send_buff,send_buff[PKT2_LEN]);

	/*发送数据*/
	if(g_pc_test.link_port == 0x00)
	{
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
			MCU485_SendString_0(send_buff,send_buff[PKT2_LEN]);			//串口0
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
			UART0_SendString(send_buff,send_buff[PKT2_LEN]);				//串口0
		#endif
	}else if(g_pc_test.link_port == 0x01)
	{	
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
			UART1_SendString(send_buff,send_buff[PKT2_LEN]);				//串口1
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
			MCU485_SendString_1(send_buff,send_buff[PKT2_LEN]);			//串口1
		#endif	
	}else if(g_pc_test.link_port == 0x02)
	{
		MCU485_SendString_2(send_buff,send_buff[PKT2_LEN]);			//串口2
	}else {
		return 0xF0;
	}
	
	return 0x00;
}

/*读取MCU版本号
	数据内容：MCU版本号 64Byte + 中控版本号 64Byte
*/
uint8_t BLV_PC_READ_MCU_Revision_Data_Reported(uint32_t data_addr,uint8_t data_len)
{
	uint8_t send_buff[150];
	memset(send_buff,0,150);
	
	/*数据处理*/

	Flash_Read(&send_buff[PKT2_PARA],64,FLASH_MCU_Model_Revision_ADDRESS);

	Flash_Read(&send_buff[PKT2_PARA+64],64,FLASH_MCU_Control_Revision_ADDRESS);
	
	/*数据处理回复*/
	Dbg_Println(DBG_OPT_DEVICE_STATUS,"%s",__func__);
	g_pc_test.DevSendSN++;
	
	send_buff[PKT2_ADD_FM] = 0x00;			//本机地址
	send_buff[PKT2_TYPE] = g_pc_test.DevSendSN;
	send_buff[PKT2_DevType] = PCTESTTYPE;						//设备类型
	send_buff[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
	send_buff[PKT2_LEN] = 0x88;									//本次发送数据长度
	send_buff[PKT2_CHKSUM] = 0x00;								//校验
	send_buff[PKT2_CMD] = BLV_PC_READ_MCU_Revision_Relay;		//设置命令
	
	send_buff[PKT2_CHKSUM] = CheckSum(send_buff,send_buff[PKT2_LEN]);

	/*发送数据*/
	if(g_pc_test.link_port == 0x00)
	{
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
			MCU485_SendString_0(send_buff,send_buff[PKT2_LEN]);			//串口0
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
			UART0_SendString(send_buff,send_buff[PKT2_LEN]);				//串口0
		#endif
	}else if(g_pc_test.link_port == 0x01)
	{	
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
			UART1_SendString(send_buff,send_buff[PKT2_LEN]);				//串口1
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
			MCU485_SendString_1(send_buff,send_buff[PKT2_LEN]);			//串口1
		#endif	
	}else if(g_pc_test.link_port == 0x02)
	{
		MCU485_SendString_2(send_buff,send_buff[PKT2_LEN]);			//串口2
	}else {
		return 0xF0;
	}
	
	return 0x00;
}

/*设置MQTT参数
*/
uint8_t BLV_PC_SET_MQTT_Reported(uint32_t data_addr,uint8_t data_len)
{
	uint8_t temp_data = 0, save_flg = 0, max = 0;
	
	uint8_t* receive = malloc(data_len);
	if(receive == NULL)   return 1;
	SRAM_Read_Buff(receive, data_len, data_addr);
	ALIYUN_INFO aLiYun_info;
	Flash_Read((uint8_t*)&aLiYun_info, sizeof(ALIYUN_INFO)-4, FLASH_MCU_MQTT_START_ADDRESS);
	aLiYun_info.mqtt_data.mqtt_basic_info = NULL;
	Dbg_Println(DBG_OPT_DEVICE_STATUS,"%s",__func__);
	
	for(uint8_t i =0, j = PKT2_PARA +1; i< receive[PKT2_PARA]; i++)   //参数个数控制循环
	{
		if((j + 1) > data_len-1)   //数据长度不对
		{
			temp_data = 2;
			break;
		}			
		switch(receive[j])
		{
			case PRODUCTKEY_CMD:       //0x01: productKey   //产品密钥
				max = sizeof(aLiYun_info.productKey);
				if(receive[j+1] > max)    receive[j+1] = max;
				if(strlen((char*)aLiYun_info.productKey) != receive[j+1] || memcmp(aLiYun_info.productKey, &receive[j+2], receive[j+1]) != 0)     //变化
				{
					memset(aLiYun_info.productKey, 0, max);
					memcpy(aLiYun_info.productKey, &receive[j+2], receive[j+1]);
					save_flg = 1;
				}
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"productKey:%s", (char*)aLiYun_info.productKey);
				
			break;
			case DEVICE_NAME_CMD:      // 0x02: deviceName   //设备名
				max = sizeof(aLiYun_info.deviceName);
				if(receive[j+1] > max)    receive[j+1] = max;
				if(strlen((char*)aLiYun_info.deviceName) != receive[j+1] || memcmp(aLiYun_info.deviceName, &receive[j+2], receive[j+1]) != 0)  //变化
				{
					memset(aLiYun_info.deviceName, 0, max);
					memcpy(aLiYun_info.deviceName, &receive[j+2], receive[j+1]);
					save_flg = 1;
				}
				
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"deviceName:%s", (char*)aLiYun_info.deviceName);
				
			break;
			case DEVICE_SECRET_CMD:      // 0x03: deviceSecret  //设备秘钥
				max = sizeof(aLiYun_info.deviceSecret);
				if(receive[j+1] > max)    receive[j+1] = max;
				if(strlen((char*)aLiYun_info.deviceSecret) != receive[j+1] || memcmp(aLiYun_info.deviceSecret, &receive[j+2], receive[j+1]) != 0)  //变化
				{
					memset(aLiYun_info.deviceSecret, 0, max);
					memcpy(aLiYun_info.deviceSecret, &receive[j+2], receive[j+1]);
					save_flg = 1;
				}
				
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"deviceSecret:%s", (char*)aLiYun_info.deviceSecret);
			
			break;
			case ALIYUN_PUBLISH_CMD:			//0x04: aLiYun_publish    //阿里云发布会话
				max = sizeof(aLiYun_info.publish);
				if(receive[j+1] > max-1)    receive[j+1] = max-1;
				if(strlen((char*)aLiYun_info.publish) != receive[j+1] || memcmp(aLiYun_info.publish, &receive[j+2], receive[j+1]) != 0)  //变化
				{
					memset(aLiYun_info.publish, 0, max);
					memcpy(aLiYun_info.publish, &receive[j+2], receive[j+1]);
					save_flg = 1;
				}
		
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"aLiYun publish:%s", (char*)aLiYun_info.publish);
	
			
			break;
			case ALIYUN_SUBLISH_CMD:			//0x05: aLiYun_sublish    //阿里云订阅会话
				max = sizeof(aLiYun_info.sublish);
				if(receive[j+1] > max-1)    receive[j+1] = max-1;
				if(strlen((char*)aLiYun_info.sublish) != receive[j+1] || memcmp(aLiYun_info.sublish, &receive[j+2], receive[j+1]) != 0)  //变化
				{
					memset(aLiYun_info.sublish, 0, max);
					memcpy(aLiYun_info.sublish, &receive[j+2], receive[j+1]);
					save_flg = 1;
				}
				
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"aLiYun sublish:%s", (char*)aLiYun_info.sublish);
			
			break;
			case KEEPALIVE_CMD:          // 0x06: keepAlive    //保持在线时间
			{
				uint16_t keepAlive = receive[j+2] | (receive[j+3]<<8);
				if(keepAlive != aLiYun_info.mqtt_data.keepAliveInterval)    //变化
				{
					aLiYun_info.mqtt_data.keepAliveInterval = keepAlive;
					save_flg = 1;
				}
				
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"keepAlive:%d", aLiYun_info.mqtt_data.keepAliveInterval);
			}
			break;
			case PUBLISH_CMD:            // 0x07: publish      //发布会话
				if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
				{
					aLiYun_info.mqtt_data.mqtt_basic_info = malloc(sizeof(MQTT_BASIC_INFO));
					if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
					{
						free(receive);
						return 1;
					}	
					int Addr_offest = sizeof(ALIYUN_INFO)-4;
					Flash_Read((uint8_t*)aLiYun_info.mqtt_data.mqtt_basic_info, sizeof(MQTT_BASIC_INFO), FLASH_MCU_MQTT_START_ADDRESS + Addr_offest);
				}
				max = sizeof(aLiYun_info.mqtt_data.mqtt_basic_info->mqtt_theme.publish);
				if(receive[j+1] > max-1)    receive[j+1] = max-1;
				if(strlen((char*)aLiYun_info.mqtt_data.mqtt_basic_info->mqtt_theme.publish) != receive[j+1] || 
					memcmp(aLiYun_info.mqtt_data.mqtt_basic_info->mqtt_theme.publish, &receive[j+2], receive[j+1]) != 0)  //变化
				{
					memset(aLiYun_info.mqtt_data.mqtt_basic_info->mqtt_theme.publish, 0, max);
					memcpy(aLiYun_info.mqtt_data.mqtt_basic_info->mqtt_theme.publish, &receive[j+2], receive[j+1]);
					save_flg = 1;
				}
		
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"publish:%s", (char*)aLiYun_info.mqtt_data.mqtt_basic_info->mqtt_theme.publish);
	
			
			break;
			case SUBLISH_CMD:            // 0x08: sublish      //订阅会话
				if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
				{
					aLiYun_info.mqtt_data.mqtt_basic_info = malloc(sizeof(MQTT_BASIC_INFO));
					if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
					{
						free(receive);
						return 1;
					}	
					int Addr_offest = sizeof(ALIYUN_INFO)-4;
					Flash_Read((uint8_t*)aLiYun_info.mqtt_data.mqtt_basic_info, sizeof(MQTT_BASIC_INFO), FLASH_MCU_MQTT_START_ADDRESS + Addr_offest);
				}
				max = sizeof(aLiYun_info.mqtt_data.mqtt_basic_info->mqtt_theme.sublish);
				if(receive[j+1] > max-1)    receive[j+1] = max-1;
				if(strlen((char*)aLiYun_info.mqtt_data.mqtt_basic_info->mqtt_theme.sublish) != receive[j+1] || 
					memcmp(aLiYun_info.mqtt_data.mqtt_basic_info->mqtt_theme.sublish, &receive[j+2], receive[j+1]) != 0)  //变化
				{
					memset(aLiYun_info.mqtt_data.mqtt_basic_info->mqtt_theme.sublish, 0, max);
					memcpy(aLiYun_info.mqtt_data.mqtt_basic_info->mqtt_theme.sublish, &receive[j+2], receive[j+1]);
					save_flg = 1;
				}
				
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"sublish:%s", (char*)aLiYun_info.mqtt_data.mqtt_basic_info->mqtt_theme.sublish);
			
			break;
			case DOMAINNAME_CMD:         // 0x09: domainName   //域名
				if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
				{
					aLiYun_info.mqtt_data.mqtt_basic_info = malloc(sizeof(MQTT_BASIC_INFO));
					if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
					{
						free(receive);
						return 1;
					}	
					int Addr_offest = sizeof(ALIYUN_INFO)-4;
					Flash_Read((uint8_t*)aLiYun_info.mqtt_data.mqtt_basic_info, sizeof(MQTT_BASIC_INFO), FLASH_MCU_MQTT_START_ADDRESS + Addr_offest);
				}
				max = sizeof(aLiYun_info.mqtt_data.mqtt_basic_info->domain_name);
				if(receive[j+1] > max-1)    receive[j+1] = max-1;
				if(strlen((char*)aLiYun_info.mqtt_data.mqtt_basic_info->domain_name) != receive[j+1] || 
					memcmp(aLiYun_info.mqtt_data.mqtt_basic_info->domain_name, &receive[j+2], receive[j+1]) != 0)  //变化
				{
					memset(aLiYun_info.mqtt_data.mqtt_basic_info->domain_name, 0, max);
					memcpy(aLiYun_info.mqtt_data.mqtt_basic_info->domain_name, &receive[j+2], receive[j+1]);
					save_flg = 1;
				}
			
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"domain_name:%s", (char*)aLiYun_info.mqtt_data.mqtt_basic_info->domain_name);
			
			break;
			case CLIENT_ID_CMD:          // 0x0A: clientId    //客户端ID
				
				if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
				{
					aLiYun_info.mqtt_data.mqtt_basic_info = malloc(sizeof(MQTT_BASIC_INFO));
					if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
					{
						free(receive);
						return 1;
					}	
					int Addr_offest = sizeof(ALIYUN_INFO)-4;
					Flash_Read((uint8_t*)aLiYun_info.mqtt_data.mqtt_basic_info, sizeof(MQTT_BASIC_INFO), FLASH_MCU_MQTT_START_ADDRESS + Addr_offest);
				}
				max = sizeof(aLiYun_info.mqtt_data.mqtt_basic_info->clientID);
				if(receive[j+1] > max-1)    receive[j+1] = max-1;
				if(strlen((char*)aLiYun_info.mqtt_data.mqtt_basic_info->clientID) != receive[j+1] || 
					memcmp(aLiYun_info.mqtt_data.mqtt_basic_info->clientID, &receive[j+2], receive[j+1]) != 0)  //变化
				{
					memset(aLiYun_info.mqtt_data.mqtt_basic_info->clientID, 0, max);
					memcpy(aLiYun_info.mqtt_data.mqtt_basic_info->clientID, &receive[j+2], receive[j+1]);
					save_flg = 1;
				}
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"clientId:%s", (char*)aLiYun_info.mqtt_data.mqtt_basic_info->clientID);
			
			break;
			case USERNAME_CMD:           // 0x0B: userName    //用户名
				
				if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
				{
					aLiYun_info.mqtt_data.mqtt_basic_info = malloc(sizeof(MQTT_BASIC_INFO));
					if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
					{
						free(receive);
						return 1;
					}	
					int Addr_offest = sizeof(ALIYUN_INFO)-4;
					Flash_Read((uint8_t*)aLiYun_info.mqtt_data.mqtt_basic_info, sizeof(MQTT_BASIC_INFO), FLASH_MCU_MQTT_START_ADDRESS + Addr_offest);
				}
				max = sizeof(aLiYun_info.mqtt_data.mqtt_basic_info->username);
				if(receive[j+1] > max-1)    receive[j+1] = max-1;
				if(strlen((char*)aLiYun_info.mqtt_data.mqtt_basic_info->username) != receive[j+1] || 
					memcmp(aLiYun_info.mqtt_data.mqtt_basic_info->username, &receive[j+2], receive[j+1]) != 0)  //变化
				{
					memset(aLiYun_info.mqtt_data.mqtt_basic_info->username, 0, max);
					memcpy(aLiYun_info.mqtt_data.mqtt_basic_info->username, &receive[j+2], receive[j+1]);
					save_flg = 1;
				}
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"username:%s", (char*)aLiYun_info.mqtt_data.mqtt_basic_info->username);
			
			break;
			case PASSWORD_CMD:           // 0x0C: password    //密码
				
				if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
				{
					aLiYun_info.mqtt_data.mqtt_basic_info = malloc(sizeof(MQTT_BASIC_INFO));
					if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
					{
						free(receive);
						return 1;
					}	
					int Addr_offest = sizeof(ALIYUN_INFO)-4;
					Flash_Read((uint8_t*)aLiYun_info.mqtt_data.mqtt_basic_info, sizeof(MQTT_BASIC_INFO), FLASH_MCU_MQTT_START_ADDRESS + Addr_offest);
				}
				max = sizeof(aLiYun_info.mqtt_data.mqtt_basic_info->password);
				if(receive[j+1] > max-1)    receive[j+1] = max-1;
				if(strlen((char*)aLiYun_info.mqtt_data.mqtt_basic_info->password) != receive[j+1] || 
					memcmp(aLiYun_info.mqtt_data.mqtt_basic_info->password, &receive[j+2], receive[j+1]) != 0)  //变化
				{
					memset(aLiYun_info.mqtt_data.mqtt_basic_info->password, 0, max);
					memcpy(aLiYun_info.mqtt_data.mqtt_basic_info->password, &receive[j+2], receive[j+1]);
					save_flg = 1;
				}
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"password:%s", (char*)aLiYun_info.mqtt_data.mqtt_basic_info->password);
			
			break;
			default: break;
		}
		j += receive[j+1] +2;
	}
	temp_data = 1;
	free(receive);
	
	if(save_flg)
	{
		Flash_Write((uint8_t*)&aLiYun_info, sizeof(ALIYUN_INFO)-4, FLASH_MCU_MQTT_START_ADDRESS);   //保存阿里云参数
		if(aLiYun_info.mqtt_data.mqtt_basic_info)
		{
			Flash_Write((uint8_t*)aLiYun_info.mqtt_data.mqtt_basic_info, sizeof(MQTT_BASIC_INFO), FLASH_MCU_MQTT_START_ADDRESS + sizeof(ALIYUN_INFO)-4);   //保存MQTT参数
		}
	}
	
	if(aLiYun_info.mqtt_data.mqtt_basic_info)
	{
		free(aLiYun_info.mqtt_data.mqtt_basic_info);
	}
	
	/*数据处理回复*/
	
	g_pc_test.DevSendSN++;
	
	uint8_t send_buff[20];
	memset(send_buff,0,20);
	
	send_buff[PKT2_ADD_FM] = 0x00;			//本机地址
	send_buff[PKT2_TYPE] = g_pc_test.DevSendSN;
	send_buff[PKT2_DevType] = PCTESTTYPE;						//设备类型
	send_buff[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
	send_buff[PKT2_LEN] = 0x09;									//本次发送数据长度
	send_buff[PKT2_CHKSUM] = 0x00;								//校验
	send_buff[PKT2_CMD] = BLV_PC_SET_MQTT_Relay;		//设置命令
	
	send_buff[PKT2_PARA] = temp_data;				//设置结果	
	
	send_buff[PKT2_CHKSUM] = CheckSum(send_buff,send_buff[PKT2_LEN]);

	/*发送数据*/
	if(g_pc_test.link_port == 0x00)
	{
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
			MCU485_SendString_0(send_buff,send_buff[PKT2_LEN]);			//串口0
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
			UART0_SendString(send_buff,send_buff[PKT2_LEN]);				//串口0
		#endif
	}else if(g_pc_test.link_port == 0x01)
	{	
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
			UART1_SendString(send_buff,send_buff[PKT2_LEN]);				//串口1
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
			MCU485_SendString_1(send_buff,send_buff[PKT2_LEN]);			//串口1
		#endif	
	}else if(g_pc_test.link_port == 0x02)
	{
		MCU485_SendString_2(send_buff,send_buff[PKT2_LEN]);			//串口2
	}else {
		return 0xF0;
	}
	
	return 0x00;
}


/*读取MQTT参数
*/
uint8_t BLV_PC_READ_MQTT_Reported(uint32_t data_addr,uint8_t data_len)
{
	uint16_t temp = 0;
	uint8_t* send_buff;
	uint8_t* receive = malloc(data_len);
	if(receive == NULL)   return 1;
	SRAM_Read_Buff(receive, data_len, data_addr);
	ALIYUN_INFO aLiYun_info;
	aLiYun_info.mqtt_data.mqtt_basic_info = NULL;

	Dbg_Println(DBG_OPT_DEVICE_STATUS,"%s",__func__);
	
	for(uint8_t i =0, j = PKT2_PARA +1; i< receive[PKT2_PARA]; i++, j++)   //参数个数控制循环
	{
		if(receive[j] > KEEPALIVE_CMD)
		{
			temp = 1;
			uint16_t len = sizeof(ALIYUN_INFO) + sizeof(MQTT_BASIC_INFO) -4 + 15;
			send_buff = malloc(len);
			if(send_buff == NULL)
			{
				free(receive);
				return 1;
			}
			Dbg_Println(DBG_OPT_DEVICE_STATUS,"send_buff:%p", send_buff);
			memset(send_buff, 0, len);
			break;
		}
	}
	if(temp == 0)
	{
		send_buff = malloc(sizeof(ALIYUN_INFO)+ 15);
		if(send_buff == NULL)
		{
			free(receive);
			return 1;
		}	
		Dbg_Println(DBG_OPT_DEVICE_STATUS,"send_buff:%p", send_buff);
		memset(send_buff, 0, sizeof(ALIYUN_INFO)+ 15);
	}
	Flash_Read((uint8_t*)&aLiYun_info, sizeof(ALIYUN_INFO)-4, FLASH_MCU_MQTT_START_ADDRESS);
	
	if(receive[PKT2_PARA] == 0 || receive[PKT2_PARA] > CMD_END - 1)     return 2;
	
	temp = PKT2_PARA +1;
	for(uint8_t i =0, j = temp; i< receive[PKT2_PARA]; i++, j++)   //参数个数控制循环
	{
		if(j > data_len-1)
		{
			break;
		}			
		switch(receive[j])
		{
			case PRODUCTKEY_CMD:       //0x01: productKey   //产品密钥
				
				send_buff[PKT2_PARA]++;		//参数个数
				send_buff[temp] = receive[j];		//参数类型
			  send_buff[temp+1] = strlen((char*)aLiYun_info.productKey);		//参数长度
				memcpy(&send_buff[temp+2], aLiYun_info.productKey, send_buff[temp+1]);
					
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"productKey:%s", (char*)aLiYun_info.productKey);
				
			break;
			case DEVICE_NAME_CMD:      // 0x02: deviceName   //设备名
				
				send_buff[PKT2_PARA]++;		//参数个数
				send_buff[temp] = receive[j];		//参数类型
			  send_buff[temp+1] = strlen((char*)aLiYun_info.deviceName);		//参数长度
				memcpy(&send_buff[temp+2], aLiYun_info.deviceName, send_buff[temp+1]);
				
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"deviceName:%s", (char*)aLiYun_info.deviceName);
				
			break;
			case DEVICE_SECRET_CMD:      // 0x03: deviceSecret  //设备秘钥
				
				send_buff[PKT2_PARA]++;		//参数个数
				send_buff[temp] = receive[j];		//参数类型
			  send_buff[temp+1] = strlen((char*)aLiYun_info.deviceSecret);		//参数长度
				memcpy(&send_buff[temp+2], aLiYun_info.deviceSecret, send_buff[temp+1]);
				
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"deviceSecret:%s", (char*)aLiYun_info.deviceSecret);
			
			break;
			case ALIYUN_PUBLISH_CMD:			//0x04: aLiYun_publish    //阿里云发布会话
				
				send_buff[PKT2_PARA]++;		//参数个数
				send_buff[temp] = receive[j];		//参数类型
			  send_buff[temp+1] = strlen((char*)aLiYun_info.publish);		//参数长度
				memcpy(&send_buff[temp+2], aLiYun_info.publish, send_buff[temp+1]);
		
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"publish:%s", (char*)aLiYun_info.publish);
	
			
			break;
			case ALIYUN_SUBLISH_CMD:			//0x05: aLiYun_sublish    //阿里云订阅会话
				
				send_buff[PKT2_PARA]++;		//参数个数
				send_buff[temp] = receive[j];		//参数类型
			  send_buff[temp+1] = strlen((char*)aLiYun_info.sublish);		//参数长度
				memcpy(&send_buff[temp+2], aLiYun_info.sublish, send_buff[temp+1]);
				
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"sublish:%s", (char*)aLiYun_info.sublish);
			
			break;
			case KEEPALIVE_CMD:          // 0x06: keepAlive    //保持在线时间
			{
				send_buff[PKT2_PARA]++;		//参数个数
				send_buff[temp] = receive[j];		//参数类型
				send_buff[temp+1] = 2;          //参数长度
				send_buff[temp+2] = aLiYun_info.mqtt_data.keepAliveInterval;
				send_buff[temp+3] = aLiYun_info.mqtt_data.keepAliveInterval>>8;
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"keepAlive:%d", aLiYun_info.mqtt_data.keepAliveInterval);
			}
			break;
			case PUBLISH_CMD:            // 0x07: publish      //发布会话
				if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
				{
					aLiYun_info.mqtt_data.mqtt_basic_info = malloc(sizeof(MQTT_BASIC_INFO));
					if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
					{
						free(receive);
						free(send_buff);
						return 1;
					}		
					Dbg_Println(DBG_OPT_DEVICE_STATUS,"mqtt_basic_info:%p", aLiYun_info.mqtt_data.mqtt_basic_info);
					int Addr_offest = sizeof(ALIYUN_INFO)-4;
					Flash_Read((uint8_t*)aLiYun_info.mqtt_data.mqtt_basic_info, sizeof(MQTT_BASIC_INFO), FLASH_MCU_MQTT_START_ADDRESS + Addr_offest);
				}
				send_buff[PKT2_PARA]++;		//参数个数
				send_buff[temp] = receive[j];		//参数类型
			  send_buff[temp+1] = strlen((char*)aLiYun_info.mqtt_data.mqtt_basic_info->mqtt_theme.publish);		//参数长度
				memcpy(&send_buff[temp+2], aLiYun_info.mqtt_data.mqtt_basic_info->mqtt_theme.publish, send_buff[temp+1]);
		
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"publish:%s", (char*)aLiYun_info.mqtt_data.mqtt_basic_info->mqtt_theme.publish);
	
			
			break;
			case SUBLISH_CMD:            // 0x08: sublish      //订阅会话
				
				if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
				{
					aLiYun_info.mqtt_data.mqtt_basic_info = malloc(sizeof(MQTT_BASIC_INFO));
					if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
					{
						free(receive);
						free(send_buff);
						return 1;
					}		
					Dbg_Println(DBG_OPT_DEVICE_STATUS,"mqtt_basic_info:%p", aLiYun_info.mqtt_data.mqtt_basic_info);
					int Addr_offest = sizeof(ALIYUN_INFO)-4;
					Flash_Read((uint8_t*)aLiYun_info.mqtt_data.mqtt_basic_info, sizeof(MQTT_BASIC_INFO), FLASH_MCU_MQTT_START_ADDRESS + Addr_offest);
				}
				send_buff[PKT2_PARA]++;		//参数个数
				send_buff[temp] = receive[j];		//参数类型
			  send_buff[temp+1] = strlen((char*)aLiYun_info.mqtt_data.mqtt_basic_info->mqtt_theme.sublish);		//参数长度
				memcpy(&send_buff[temp+2], aLiYun_info.mqtt_data.mqtt_basic_info->mqtt_theme.sublish, send_buff[temp+1]);
				
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"sublish:%s", (char*)aLiYun_info.mqtt_data.mqtt_basic_info->mqtt_theme.sublish);
			
			break;
			
			case DOMAINNAME_CMD:         // 0x09: domainName   //域名
				if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
				{
					aLiYun_info.mqtt_data.mqtt_basic_info = malloc(sizeof(MQTT_BASIC_INFO));
					if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
					{
						free(receive);
						free(send_buff);
						return 1;
					}		
					Dbg_Println(DBG_OPT_DEVICE_STATUS,"mqtt_basic_info:%p", aLiYun_info.mqtt_data.mqtt_basic_info);
					int Addr_offest = sizeof(ALIYUN_INFO)-4;
					Flash_Read((uint8_t*)aLiYun_info.mqtt_data.mqtt_basic_info, sizeof(MQTT_BASIC_INFO), FLASH_MCU_MQTT_START_ADDRESS + Addr_offest);
				}
				send_buff[PKT2_PARA]++;		//参数个数
				send_buff[temp] = receive[j];		//参数类型
			  send_buff[temp+1] = strlen((char*)aLiYun_info.mqtt_data.mqtt_basic_info->domain_name);		//参数长度
				memcpy(&send_buff[temp+2], aLiYun_info.mqtt_data.mqtt_basic_info->domain_name, send_buff[temp+1]);
			
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"domain_name:%s", (char*)aLiYun_info.mqtt_data.mqtt_basic_info->domain_name);
			
			break;
			case CLIENT_ID_CMD:          // 0x0A: clientId    //客户端ID
				
				if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
				{
					aLiYun_info.mqtt_data.mqtt_basic_info = malloc(sizeof(MQTT_BASIC_INFO));
					if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
					{
						free(receive);
						free(send_buff);
						return 1;
					}		
					Dbg_Println(DBG_OPT_DEVICE_STATUS,"mqtt_basic_info:%p", aLiYun_info.mqtt_data.mqtt_basic_info);
					int Addr_offest = sizeof(ALIYUN_INFO)-4;
					Flash_Read((uint8_t*)aLiYun_info.mqtt_data.mqtt_basic_info, sizeof(MQTT_BASIC_INFO), FLASH_MCU_MQTT_START_ADDRESS + Addr_offest);
				}
				send_buff[PKT2_PARA]++;		//参数个数
				send_buff[temp] = receive[j];		//参数类型
			  send_buff[temp+1] = strlen((char*)aLiYun_info.mqtt_data.mqtt_basic_info->clientID);		//参数长度
				memcpy(&send_buff[temp+2], aLiYun_info.mqtt_data.mqtt_basic_info->clientID, send_buff[temp+1]);
				
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"clientId:%s", (char*)aLiYun_info.mqtt_data.mqtt_basic_info->clientID);
			
			break;
			case USERNAME_CMD:           // 0x0B: userName    //用户名
				
				if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
				{
					aLiYun_info.mqtt_data.mqtt_basic_info = malloc(sizeof(MQTT_BASIC_INFO));
					if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
					{
						free(receive);
						free(send_buff);
						return 1;
					}		
					Dbg_Println(DBG_OPT_DEVICE_STATUS,"mqtt_basic_info:%p", aLiYun_info.mqtt_data.mqtt_basic_info);
					int Addr_offest = sizeof(ALIYUN_INFO)-4;
					Flash_Read((uint8_t*)aLiYun_info.mqtt_data.mqtt_basic_info, sizeof(MQTT_BASIC_INFO), FLASH_MCU_MQTT_START_ADDRESS + Addr_offest);
				}
				send_buff[PKT2_PARA]++;		//参数个数
				send_buff[temp] = receive[j];		//参数类型
			  send_buff[temp+1] = strlen((char*)aLiYun_info.mqtt_data.mqtt_basic_info->username);		//参数长度
				memcpy(&send_buff[temp+2], aLiYun_info.mqtt_data.mqtt_basic_info->username, send_buff[temp+1]);
				
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"username:%s", (char*)aLiYun_info.mqtt_data.mqtt_basic_info->username);
			
			break;
			case PASSWORD_CMD:           // 0x0C: password    //密码
				
				if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
				{
					aLiYun_info.mqtt_data.mqtt_basic_info = malloc(sizeof(MQTT_BASIC_INFO));
					if(aLiYun_info.mqtt_data.mqtt_basic_info == NULL)
					{
						free(receive);
						free(send_buff);
						return 1;
					}		
					Dbg_Println(DBG_OPT_DEVICE_STATUS,"mqtt_basic_info:%p", aLiYun_info.mqtt_data.mqtt_basic_info);
					int Addr_offest = sizeof(ALIYUN_INFO)-4;
					Flash_Read((uint8_t*)aLiYun_info.mqtt_data.mqtt_basic_info, sizeof(MQTT_BASIC_INFO), FLASH_MCU_MQTT_START_ADDRESS + Addr_offest);
				}
				send_buff[PKT2_PARA]++;		//参数个数
				send_buff[temp] = receive[j];		//参数类型
			  send_buff[temp+1] = strlen((char*)aLiYun_info.mqtt_data.mqtt_basic_info->password);		//参数长度
				memcpy(&send_buff[temp+2], aLiYun_info.mqtt_data.mqtt_basic_info->password, send_buff[temp+1]);
				
				Dbg_Println(DBG_OPT_DEVICE_STATUS,"password:%s", (char*)aLiYun_info.mqtt_data.mqtt_basic_info->password);
			
			break;
			default: break;
		}
		temp += send_buff[temp+1] +2;
	}

	free(receive);
	
	if(aLiYun_info.mqtt_data.mqtt_basic_info)
	{
		free(aLiYun_info.mqtt_data.mqtt_basic_info);
	}
	
	/*数据处理回复*/
	
	g_pc_test.DevSendSN++;
	
	send_buff[PKT2_ADD_FM] = 0x00;			//本机地址
	send_buff[PKT2_TYPE] = g_pc_test.DevSendSN;
	send_buff[PKT2_DevType] = PCTESTTYPE;						//设备类型
	send_buff[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
	send_buff[PKT2_LEN] = temp;									//本次发送数据长度
	send_buff[PKT2_LEN_8] = temp>>8;									//本次发送数据长度
	send_buff[PKT2_CHKSUM] = 0x00;								//校验
	send_buff[PKT2_CMD] = BLV_PC_READ_MQTT_Relay;		//设置命令
	
	send_buff[PKT2_CHKSUM] = CheckSum(send_buff, temp);

	/*发送数据*/
	if(g_pc_test.link_port == 0x00)
	{
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
			MCU485_SendString_0(send_buff,send_buff[PKT2_LEN]);			//串口0
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
			UART0_SendString(send_buff,send_buff[PKT2_LEN]);				//串口0
		#endif
	}else if(g_pc_test.link_port == 0x01)
	{	
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
			UART1_SendString(send_buff,send_buff[PKT2_LEN]);				//串口1
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
			MCU485_SendString_1(send_buff,send_buff[PKT2_LEN]);			//串口1
		#endif	
	}else if(g_pc_test.link_port == 0x02)
	{
		MCU485_SendString_2(send_buff,send_buff[PKT2_LEN]);			//串口2
	}else {
		free(send_buff);
		return 0xF0;
	}
	
	free(send_buff);
	return 0x00;
}

uint8_t BLV_PC_READ_RCU_Data_Reported(uint32_t data_addr,uint8_t data_len)
{
	uint8_t send_buff[530];
	uint16_t send_len = PKT2_PARA + 10;
	uint8_t read_flag = 0,result = 0;
	uint32_t read_addr = 0,read_len = 0;
	memset(send_buff,0,sizeof(send_buff));
	
	/*数据处理*/
	if(data_len > (PKT2_PARA + 9))	{
		return 0x01;
	}
	
	Dbg_Println(DBG_OPT_DEVICE_STATUS,"%s",__func__);
	
	read_flag = SRAM_Read_Byte(data_addr+PKT2_PARA);
	read_addr = SRAM_Read_DW(data_addr+PKT2_PARA+1);
	read_len = SRAM_Read_DW(data_addr+PKT2_PARA+5);
	
	Dbg_Println(DBG_BIT_Debug_STATUS_bit,"读取RCU:%08X,Len:%08X",read_addr,read_len);
	if(read_len >= 512)	read_len = 512;				//读取数据长度最长为512Byte
	
	switch(read_flag)
	{
		case 0x01:	//SRAM
			if(read_addr >= SRAM_ADDRESS_MAX) {
				Dbg_Println(DBG_BIT_Debug_STATUS_bit,"Addr Error");
				break;
			}
			SRAM_Read_Buff(&send_buff[PKT2_PARA+10],read_len,read_addr);
			send_len += read_len;
			result = 0x01;
			break;
		case 0x02:	//Flash
			if(read_addr >= Flash_ADDRESS_MAX) {
				Dbg_Println(DBG_BIT_Debug_STATUS_bit,"Addr Error");
				break;
			}
			Flash_Read(&send_buff[PKT2_PARA+10],read_len,read_addr);
			send_len += read_len;
			result = 0x01;
			break;
		default:
			
			break;
	}
	
	send_buff[PKT2_PARA] = result;
	SRAM_Read_Buff(&send_buff[PKT2_PARA+1],9,data_addr+PKT2_PARA);
	
	/*数据处理回复*/
	
	g_pc_test.DevSendSN++;
	
	send_buff[PKT2_ADD_FM] = 0x00;			//本机地址
	send_buff[PKT2_TYPE] = g_pc_test.DevSendSN;
	send_buff[PKT2_DevType] = PCTESTTYPE;						//设备类型
	send_buff[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
	send_buff[PKT2_LEN] = (send_len & 0xFF);									//本次发送数据长度
	send_buff[PKT2_LEN_8] = ((send_len >> 8) & 0xFF);
	send_buff[PKT2_CHKSUM] = 0x00;								//校验
	send_buff[PKT2_CMD] = BLV_PC_READ_MCU_Revision_Relay;		//设置命令
	
	send_buff[PKT2_CHKSUM] = CheckSum(send_buff,send_len);

	/*发送数据*/
	if(g_pc_test.link_port == 0x00)
	{
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
			MCU485_SendString_0(send_buff,send_buff[PKT2_LEN]);			//串口0
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
			UART0_SendString(send_buff,send_buff[PKT2_LEN]);				//串口0
		#endif
	}else if(g_pc_test.link_port == 0x01)
	{	
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
			UART1_SendString(send_buff,send_buff[PKT2_LEN]);				//串口1
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
			MCU485_SendString_1(send_buff,send_buff[PKT2_LEN]);			//串口1
		#endif	
	}else if(g_pc_test.link_port == 0x02)
	{
		MCU485_SendString_2(send_buff,send_buff[PKT2_LEN]);			//串口2
	}else {
		return 0xF0;
	}
	
	return 0x00;
}



uint8_t BLV_PC_READ_RCU_VERSION_Reported(uint32_t data_addr,uint8_t data_len)
{
	uint8_t send_buff[100];
	uint16_t send_len = 0x00;
	uint8_t read_flag;
	memset(send_buff,0,sizeof(send_buff));
	
	/*数据处理*/

	
	Dbg_Println(DBG_OPT_DEVICE_STATUS,"%s",__func__);
	
	read_flag = SRAM_Read_Byte(data_addr+PKT2_PARA);      //1:固件版本 2:launcher版本  3:配置版本
	
    //查找设备

	
	
	switch(read_flag){
		case 1:
			memcpy(&send_buff[PKT2_PARA+2],SoftwareVer,sizeof(SoftwareVer));
			break;
		case 2:
//			Dbg_Println(DBG_OPT_DEVICE_STATUS,":%08x,:%08x",(uint8_t *)&send_buff[PKT2_PARA+1],(uint32_t)Launcher_SoftwareVer_Addr);
//			MCU_Flash_Read((uint8_t *)&send_buff[PKT2_PARA+1],20,(uint32_t)Launcher_SoftwareVer_Addr);
//			memcpy(&send_buff[PKT2_PARA+1],Launcher_SoftwareVer_Char,20);
			SRAM_DMA_Read_Buff((uint8_t *)&send_buff[PKT2_PARA+2],20,SRAM_Launcher_SoftwareVer_Addr);
			break;
		case 3:
			if (Read_LogicFile_Information(0x08,(uint8_t *)&send_buff[PKT2_PARA+2]) != 0x00) return 0xF1; 
		
			send_buff[PKT2_PARA+9] = send_buff[PKT2_PARA+4]%10+(uint8_t)'0';
			send_buff[PKT2_PARA+8] = send_buff[PKT2_PARA+4]/10%10+(uint8_t)'0';
			send_buff[PKT2_PARA+6] = send_buff[PKT2_PARA+3]%10+(uint8_t)'0';
			send_buff[PKT2_PARA+5] = send_buff[PKT2_PARA+3]/10%10+(uint8_t)'0';
			send_buff[PKT2_PARA+3] = send_buff[PKT2_PARA+2]%10+(uint8_t)'0';
			send_buff[PKT2_PARA+2] = send_buff[PKT2_PARA+2]/10%10+(uint8_t)'0';
			send_buff[PKT2_PARA+4] = (uint8_t)'.';
			send_buff[PKT2_PARA+7] = (uint8_t)'.';
		
			break;
		case 4:
			if (Read_LogicFile_Information(0x02,(uint8_t *)&send_buff[PKT2_PARA+2]) != 0x00) return 0xF2; 
			send_buff[PKT2_PARA+12] = send_buff[PKT2_PARA+5]%10+(uint8_t)'0';
			send_buff[PKT2_PARA+11] = send_buff[PKT2_PARA+5]/10%10+(uint8_t)'0';
			send_buff[PKT2_PARA+9] = send_buff[PKT2_PARA+4]%10+(uint8_t)'0';
			send_buff[PKT2_PARA+8] = send_buff[PKT2_PARA+4]/10%10+(uint8_t)'0';
			send_buff[PKT2_PARA+6] = send_buff[PKT2_PARA+3]%10+(uint8_t)'0';
			send_buff[PKT2_PARA+5] = send_buff[PKT2_PARA+3]/10%10+(uint8_t)'0';
			send_buff[PKT2_PARA+3] = send_buff[PKT2_PARA+2]%10+(uint8_t)'0';
			send_buff[PKT2_PARA+2] = send_buff[PKT2_PARA+2]/10%10+(uint8_t)'0';
			send_buff[PKT2_PARA+4] = (uint8_t)'.';
			send_buff[PKT2_PARA+7] = (uint8_t)'.';
			send_buff[PKT2_PARA+10] = (uint8_t)'.';
		
			break;
		default:
			break;
	}
	
	send_buff[PKT2_PARA] = 0x01;
	send_buff[PKT2_PARA+1] = strlen((char *)&send_buff[PKT2_PARA+2]);
	
	send_len = PKT2_PARA + 0x02 + strlen((char *)&send_buff[PKT2_PARA+2]);
	
	/*数据处理回复*/
	
	g_pc_test.DevSendSN++;
	
	send_buff[PKT2_ADD_FM] = 0x00;			//本机地址
	send_buff[PKT2_TYPE] = g_pc_test.DevSendSN;
	send_buff[PKT2_DevType] = PCTESTTYPE;						//设备类型
	send_buff[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
	send_buff[PKT2_LEN] = (send_len & 0xFF);									//本次发送数据长度
	send_buff[PKT2_LEN_8] = ((send_len >> 8) & 0xFF);
	send_buff[PKT2_CHKSUM] = 0x00;								//校验
	send_buff[PKT2_CMD] = BLV_PC_READ_RCU_VERSION_Relay;		//设置命令
	
	send_buff[PKT2_CHKSUM] = CheckSum(send_buff,send_len);

	/*发送数据*/
	if(g_pc_test.link_port == 0x00)
	{
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
			MCU485_SendString_0(send_buff,send_buff[PKT2_LEN]);			//串口0
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
			UART0_SendString(send_buff,send_buff[PKT2_LEN]);				//串口0
		#endif
	}else if(g_pc_test.link_port == 0x01)
	{	
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
			UART1_SendString(send_buff,send_buff[PKT2_LEN]);				//串口1
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
			MCU485_SendString_1(send_buff,send_buff[PKT2_LEN]);			//串口1
		#endif	
	}else if(g_pc_test.link_port == 0x02)
	{
		MCU485_SendString_2(send_buff,send_buff[PKT2_LEN]);			//串口2
	}else {
		return 0xF0;
	}
	
	return 0x00;
}

uint8_t BLV_PC_READ_Device_Data_Reported(uint32_t data_addr,uint8_t data_len)
{
	uint8_t send_buff[100];
	uint16_t send_len = 0x00;
	uint8_t read_devaddr = 0,read_devtype = 0,read_devinfo = 0;
	uint32_t read_addr = 0;
	memset(send_buff,0,sizeof(send_buff));
	
	/*数据处理*/
	if(data_len < (PKT2_PARA + 3))	{
		return 0x01;
	}
	
	Dbg_Println(DBG_OPT_DEVICE_STATUS,"%s",__func__);
	
	read_devtype = SRAM_Read_Byte(data_addr+PKT2_PARA);     //设备类型
	read_devaddr = SRAM_Read_Byte(data_addr+PKT2_PARA+1);   //设备地址
	read_devinfo = SRAM_Read_Byte(data_addr+PKT2_PARA+2);   //读取信息内容
	
	Dbg_Println(DBG_BIT_Debug_STATUS_bit,"读取设备类型:%08X, 地址:%d 信息:%d",read_devtype,read_devaddr,read_devinfo);
	
    //查找设备
    read_addr = Find_Device_List_Information(read_devtype,read_devaddr);
    if(read_addr != 0x00){
        //目前该内容是针对BLV-C8 测试使用的
        send_buff[PKT2_PARA] = 0x01;
        
        switch(read_devtype){
            case Dev_Rs485_PB20:
				#if RS485_PB20Fun_Flag
                if(read_devinfo == 0x01){
                    //查询软件版本
                    send_buff[PKT2_PARA + 1] = Get_BLV_PB20_COMM_Version(read_addr);
                    Dbg_Println(DBG_BIT_Debug_STATUS_bit,"读取版本:%d",send_buff[PKT2_PARA + 1] );
                    send_len = PKT2_PARA + 0x02;
                }else if(read_devinfo == 0x02){
                    //查询PS 电压
                    uint16_t temp_val = 0x00;
                    temp_val = Get_BLV_PB20_PS_Voltage(read_addr);
                    Dbg_Println(DBG_BIT_Debug_STATUS_bit,"读取PS电压:%dmV",temp_val );
                    send_buff[PKT2_PARA + 1] = (temp_val >> 8) & 0xFF;
                    send_buff[PKT2_PARA + 2] = temp_val & 0xFF;
                    send_len = PKT2_PARA + 0x03;
                }else if(read_devinfo == 0x03){
                    //查询BUS 电压
                    uint16_t temp_val = 0x00;
                    temp_val = Get_BLV_PB20_BUS_Voltage(read_addr);
                    Dbg_Println(DBG_BIT_Debug_STATUS_bit,"读取BUS电压:%dmV",temp_val );
                    send_buff[PKT2_PARA + 1] = (temp_val >> 8) & 0xFF;
                    send_buff[PKT2_PARA + 2] = temp_val & 0xFF;
                    send_len = PKT2_PARA + 0x03;
                }else if(read_devinfo == 0x04){
                    //查询BUS 电流
                    uint16_t temp_val = 0x00;
                    temp_val = Get_BLV_PB20_BUS_Current(read_addr);
                    Dbg_Println(DBG_BIT_Debug_STATUS_bit,"读取BUS电流:%dmV",temp_val );
                    send_buff[PKT2_PARA + 1] = (temp_val >> 8) & 0xFF;
                    send_buff[PKT2_PARA + 2] = temp_val & 0xFF;
                    send_len = PKT2_PARA + 0x03;
                }
				#endif
                break;
            case DEV_C5IO_Type:
                if(read_devinfo == 0x01){
                    //查询软件版本
                    send_buff[PKT2_PARA + 1] = Get_Bus_CSIO_COMM_Version(read_addr);
                    Dbg_Println(DBG_BIT_Debug_STATUS_bit,"读取版本:%d",send_buff[PKT2_PARA + 1] );
                    send_len = PKT2_PARA + 0x02;
                }
                break;
            default:
                send_len = PKT2_PARA + 0x01;
                break;
        }
    }else{
        //设备不存在
        Dbg_Println(DBG_BIT_Debug_STATUS_bit,"读取设备失败");
        send_buff[PKT2_PARA] = 0x00;
        send_len = PKT2_PARA + 0x01;
    }
	
	
	/*数据处理回复*/
	
	g_pc_test.DevSendSN++;
	
	send_buff[PKT2_ADD_FM] = 0x00;			//本机地址
	send_buff[PKT2_TYPE] = g_pc_test.DevSendSN;
	send_buff[PKT2_DevType] = PCTESTTYPE;						//设备类型
	send_buff[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
	send_buff[PKT2_LEN] = (send_len & 0xFF);									//本次发送数据长度
	send_buff[PKT2_LEN_8] = ((send_len >> 8) & 0xFF);
	send_buff[PKT2_CHKSUM] = 0x00;								//校验
	send_buff[PKT2_CMD] = BLV_PC_READ_Device_Data_Relay;		//设置命令
	
	send_buff[PKT2_CHKSUM] = CheckSum(send_buff,send_len);

	/*发送数据*/
	if(g_pc_test.link_port == 0x00)
	{
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
			MCU485_SendString_0(send_buff,send_buff[PKT2_LEN]);			//串口0
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
			UART0_SendString(send_buff,send_buff[PKT2_LEN]);				//串口0
		#endif
	}else if(g_pc_test.link_port == 0x01)
	{	
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
			UART1_SendString(send_buff,send_buff[PKT2_LEN]);				//串口1
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
			MCU485_SendString_1(send_buff,send_buff[PKT2_LEN]);			//串口1
		#endif	
	}else if(g_pc_test.link_port == 0x02)
	{
		MCU485_SendString_2(send_buff,send_buff[PKT2_LEN]);			//串口2
	}else {
		return 0xF0;
	}
	
	return 0x00;
}

/*************************************BLV-CX 模块测试处理代码**********************************/
uint8_t BLV_PC_CORE_TEST_Data_Reported(void)
{

	BLV_CORE_TEST_Process();		//进入测试模式
	
	return 0x00;
}

uint8_t BLV_PC_CORE_TEST_Only_Relay(void)
{
	uint8_t send_buff[20];
	memset(send_buff,0,20);

	/*数据处理回复*/
	Dbg_Println(DBG_OPT_DEVICE_STATUS,"%s",__func__);
	g_pc_test.DevSendSN++;
	
	send_buff[PKT2_ADD_FM] = 0x00;			//本机地址
	send_buff[PKT2_TYPE] = g_pc_test.DevSendSN;
	send_buff[PKT2_DevType] = PCTESTTYPE;						//设备类型
	send_buff[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
	send_buff[PKT2_LEN] = 0x09;									//本次发送数据长度
	send_buff[PKT2_CHKSUM] = 0x00;								//校验
	send_buff[PKT2_CMD] = BLV_PC_CORE_TEST_Relay;		//设置命令
	
	send_buff[PKT2_PARA] = 0x01;						//设置结果	
	
	send_buff[PKT2_CHKSUM] = CheckSum(send_buff,send_buff[PKT2_LEN]);

	/*发送数据*/
	if(g_pc_test.link_port == 0x00)
	{
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
			MCU485_SendString_0(send_buff,send_buff[PKT2_LEN]);			//串口0
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
			UART0_SendString(send_buff,send_buff[PKT2_LEN]);				//串口0
		#endif
	}else if(g_pc_test.link_port == 0x01)
	{	
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
			UART1_SendString(send_buff,send_buff[PKT2_LEN]);				//串口1
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
			MCU485_SendString_1(send_buff,send_buff[PKT2_LEN]);			//串口1
		#endif	
	}else if(g_pc_test.link_port == 0x02)
	{
		MCU485_SendString_2(send_buff,send_buff[PKT2_LEN]);			//串口2
	}else {
		return 0xF0;
	}
	
	return 0x00;
}


void BLV_CORE_TEST_Process(void)
{
	uint8_t rev = 0;
	g_pc_test.core_tick = SysTick_1ms;
	
	Dbg_Println(DBG_BIT_SYS_STATUS_bit,"%s",__func__);
	while(1)
	{
		if(SysTick_1ms - g_pc_test.core_tick > 30000)		//长时间没有进行测试便自动退出
		{
			Dbg_Println(DBG_BIT_SYS_STATUS_bit,"BLY_C1_TEST END!!!");
			//长时间没有处理,直接看门狗复位，重新初始化
			break;
		}
		WDT_Feed();	
		
		RTC_TASK();
		
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板	
			UART1_RECEIVE();
			rev = BLV_C1F_TestData_Process();
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板	
			UART0_RECEIVE();
			rev = BLV_C1_TestData_Process();
		#endif
		
		if(rev == 0x01)	{
			Dbg_Println(DBG_BIT_SYS_STATUS_bit,"BLY_C1F_TEST 时间刷新....");
			g_pc_test.core_tick = SysTick_1ms;	//有处理数据，将时间刷新
		}
	}
	while(1);			//测试完成。不管测试结果如何，重新复位MCU

}

/*C1 DEBUG为串口0*/
uint8_t BLV_C1_TestData_Process(void)
{
	uint16_t data_len = 0;
	
	if(g_Uart[USART_0].RX_Buffer_WriteAddr != g_Uart[USART_0].RX_Buffer_ReadAddr)
	{
		data_len = SRAM_Read_Word(g_Uart[USART_0].RX_Buffer_ReadAddr);
		
		/*串口0数据处理*/
		Dbg_Println(DBG_BIT_SYS_STATUS_bit,"USART_0 Revice Len:%d",data_len);
		
		BLV_C1_TEST_DATA_Processing(g_Uart[USART_0].RX_Buffer_ReadAddr+2,data_len);		//数据处理
		
		g_Uart[USART_0].RX_Buffer_ReadAddr += SRAM_Uart_Buffer_Size;
		if(g_Uart[USART_0].RX_Buffer_ReadAddr > SRAM_UART0_RecvBuffer_End_Addr)	g_Uart[USART_0].RX_Buffer_ReadAddr = SRAM_UART0_RecvBuffer_Start_Addr;
		
		return 0x01;
	}
	return 0x00;
}

/*C1F DEBUG为串口1*/
uint8_t BLV_C1F_TestData_Process(void)
{
	uint16_t data_len = 0;
	
	if(g_Uart[USART_1].RX_Buffer_WriteAddr != g_Uart[USART_1].RX_Buffer_ReadAddr)
	{
		data_len = SRAM_Read_Word(g_Uart[USART_1].RX_Buffer_ReadAddr);
		
		/*串口1数据处理*/
		Dbg_Println(DBG_BIT_SYS_STATUS_bit,"USART_1 Revice Len:%d",data_len);
		
		BLV_C1_TEST_DATA_Processing(g_Uart[USART_1].RX_Buffer_ReadAddr+2,data_len);		//数据处理
		
		g_Uart[USART_1].RX_Buffer_ReadAddr += SRAM_Uart_Buffer_Size;
		if(g_Uart[USART_1].RX_Buffer_ReadAddr > SRAM_UART1_RecvBuffer_End_Addr)	g_Uart[USART_1].RX_Buffer_ReadAddr = SRAM_UART1_RecvBuffer_Start_Addr;
		
		return 0x01;
	}
	return 0x00;
}

uint8_t BLV_C1_TEST_DATA_Processing(uint32_t data_addr,uint16_t len)
{
	uint16_t temp = 0;
	uint8_t AckBUFF[50];

	memset(AckBUFF,0,sizeof(AckBUFF));

	if(Dev_CheckSum(data_addr,len) != 0x00) 
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PC Check Fail!");
		return 0x01;	//和校验
	}
	temp = SRAM_Read_Byte(data_addr + PKT2_ADD_FM);
	if(temp != 0x00)	
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PC PKT_ADD_FM Fail!");
		return 0x01;						//发送地址不对
	}
//	temp = SRAM_Read_Byte(data_addr + PKT2_TYPE);
//	if((temp & 0x0F) == g_pc_test.DevSendSN)	//序列号不同，同时不是重发数据
//	{
//		Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"PC PKT_TYPE the same and Not resend!");
//		return 0x01;			//序号不对
//	}
	temp = SRAM_Read_Byte(data_addr + PKT2_DevType);
	if(temp != PCTESTTYPE)	
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PC PKT_DevType Fail!");
		return 0x01;					//设备类型不对
	}
	temp = SRAM_Read_Byte(data_addr + PKT2_ADD_TO);
	if(temp != 0x00)	
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PC PKT_ADD_TO Fail!");
		return 0x01;						//接收地址不对
	}
	temp = SRAM_Read_Word(data_addr + PKT2_LEN);
	if(temp != len)		
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"PC PKT_LEN Fail!");
		return 0x01;						//长度不对
	}
	
	Dbg_Println(DBG_OPT_DEVICE_STATUS,"PC Test Data Addr:%08X Len:%d",data_addr,len);
	temp = SRAM_Read_Byte(data_addr + PKT2_TYPE);
	g_pc_test.DevSendSN = temp & 0x0F;
	g_pc_test.link_port = 0x01;
	
	/*接收数据*/
	temp = SRAM_Read_Byte(data_addr + PKT2_CMD);
	switch(temp)
	{
		case BLV_PC_TEST_SearchMCU_CMD:			//搜索主机
			
			break;
		case BLV_PC_TEST_SyncTime_CMD:			//同步主机时间
			SyncTime_DATA_Processing(data_addr,len);

			break;
		case BLV_PC_TEST_QueryTime_CMD:			//查询主机时间
			QueryTime_Relay_DATA_Packaging(data_addr,len);

			break;
		case BLV_PC_TEST_ConfigInfo_CMD:		//配置信息下发 - 下发设备存在信息
			
			break;
		case BLV_PC_TEST_ReadRegister_CMD:		//读取映射寄存器内容
			
			break;
		case BLV_PC_TEST_WriteRegister_CMD:		//写映射寄存器内容
			
			break;
		case BLV_PC_TEST_StartTesting_CMD:		//开启设备测试,发送测试数据

			break;
		case BLV_PC_TEST_SetBaud_CMD:			//设置PC端口波特率，进入配置模式
			
			break;
		case BLV_PC_SET_DEBUG_CMD:				//设置Debug调试输出信息
			/*
				参数1：控制参数  0：关 1：开
					bit0:	系统调试信息打印开关
					bit1:	网络调试信息打印开关
					bit2:	设备驱动层打印调试信息打印开关
					bit3:	逻辑调试信息打印开关
			*/
			Dbg_Switch &= 0x00;
			Dbg_Switch |= SRAM_Read_Byte(data_addr + PKT2_PARA);
			printf("Dbg_Switch:%08X",Dbg_Switch);
			break;
		case BLV_PC_TEST_GPIO_CMD:
			Dbg_Println(DBG_OPT_DEVICE_STATUS,"BLV_PC_TEST_GPIO_CMD");
			TEST_GPIO_DATA_Processing(data_addr,len);

			break;
		case BLV_PC_SET_MCU_Revision_CMD:		//设置MCU型号以及中控型号
			BLV_PC_SET_MCU_Revision_Data_Reported(data_addr,len);
			break;
		case BLV_PC_READ_MCU_Revision_CMD:		//读取MCU型号以及中控型号
			BLV_PC_READ_MCU_Revision_Data_Reported(data_addr,len);
			break;
		case BLV_PC_CORE_TEST_CMD:		//开启PC测试
			
			BLV_PC_CORE_TEST_Only_Relay();	//只回复应答数据
			break;
		case BLV_PC_READ_RCU_VERSION_CMD:
            //读取设备信息
            BLV_PC_READ_RCU_VERSION_Reported(data_addr,len);
            break;
		default:
			
			break;
	}

	return 0;
}

uint8_t SyncTime_DATA_Processing(uint32_t data_addr,uint16_t data_len)
{
//	uint32_t utc_tick = 0;
	uint16_t temp_len = 0x09;
	uint8_t temp = 0;
    uint32_t device_listaddr = 0;
	S_RTC set_time;
	uint8_t ack_buff[temp_len];
	memset(ack_buff,0,temp_len);
	
	set_time.year = SRAM_Read_Byte(data_addr + PKT2_PARA);

	set_time.month = SRAM_Read_Byte(data_addr + PKT2_PARA + 1);
	
	set_time.day = SRAM_Read_Byte(data_addr + PKT2_PARA + 2);
	
	set_time.hour = SRAM_Read_Byte(data_addr + PKT2_PARA + 3);

	set_time.minute = SRAM_Read_Byte(data_addr + PKT2_PARA + 4);
	
	set_time.second = SRAM_Read_Byte(data_addr + PKT2_PARA + 5);
	
	set_time.week = SRAM_Read_Byte(data_addr + PKT2_PARA + 6);
	
	
	temp = RTC_WriteDate(set_time);
    
    //找到CSIO 发送数据
    if(g_time_info.time_select == 0x02){
        device_listaddr = Find_Device_List_Information(DEV_C5IO_Type,0x00);
        if((device_listaddr >= SRAM_Device_List_Start_Addr) && (device_listaddr <= SRAM_Device_List_End_Addr))	{
            
            BUS_CSIO_Set_RTC_Time(device_listaddr);
        }
    }
    
	
//	/*UTC时间*/
//	utc_tick = RTC_Conversion_To_Unix(&set_time);
//	Unix_Conversion_To_RTC(&set_time,utc_tick);
	
	/*回复数据打包*/
	ack_buff[PKT2_ADD_FM] = 0x00;			//本机地址
	ack_buff[PKT2_TYPE] = g_pc_test.DevSendSN;
	ack_buff[PKT2_DevType] = PCTESTTYPE;						//设备类型
	ack_buff[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
	ack_buff[PKT2_LEN] = temp_len & 0xFF;						//本次发送数据长度
	ack_buff[PKT2_LEN_8] = (temp_len >> 8) & 0xFF;
	ack_buff[PKT2_CHKSUM] = 0x00;								//校验
	ack_buff[PKT2_CMD] = BLV_PC_TEST_QueryTime_Relay;		//设置命令
		
	ack_buff[PKT2_PARA] = temp;		//回复状态	0x01：执行成功 ，0x00：执行失败	

	ack_buff[PKT2_CHKSUM] = CheckSum(ack_buff,temp_len);
	
	/*发送数据*/
	
	if(g_pc_test.link_port == 0x00)
	{
		UART0_SendString(ack_buff,temp_len);			//串口0
	}else if(g_pc_test.link_port == 0x01)
	{
		MCU485_SendString_1(ack_buff,temp_len);			//串口1
	}else if(g_pc_test.link_port == 0x02)
	{
		MCU485_SendString_2(ack_buff,temp_len);			//串口2
	}else {
		return 0xF0;
	}
	
	/*发送数据*/
	if(g_pc_test.link_port == 0x00)
	{
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
			MCU485_SendString_0(ack_buff,temp_len);			//串口0
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
			UART0_SendString(ack_buff,temp_len);				//串口0
		#endif
	}else if(g_pc_test.link_port == 0x01)
	{	
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
			UART1_SendString(ack_buff,temp_len);				//串口1
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
			MCU485_SendString_1(ack_buff,temp_len);			//串口1
		#endif	
	}else if(g_pc_test.link_port == 0x02)
	{
		MCU485_SendString_2(ack_buff,temp_len);			//串口2
	}else {
		return 0xF0;
	}
	
	return 0x00;
}

/*同步时间回复数据打包函数*/
uint16_t QueryTime_Relay_DATA_Packaging(uint32_t data_addr,uint16_t data_len)
{
	uint16_t temp_len = 0x0F;
	uint8_t ack_buff[temp_len];
	memset(ack_buff,0,temp_len);
	
	ack_buff[PKT2_ADD_FM] = 0x00;			//本机地址
	ack_buff[PKT2_TYPE] = g_pc_test.DevSendSN;
	ack_buff[PKT2_DevType] = PCTESTTYPE;						//设备类型
	ack_buff[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
	ack_buff[PKT2_LEN] = temp_len & 0xFF;						//本次发送数据长度
	ack_buff[PKT2_LEN_8] = (temp_len >> 8) & 0xFF;
	ack_buff[PKT2_CHKSUM] = 0x00;								//校验
	ack_buff[PKT2_CMD] = BLV_PC_TEST_QueryTime_Relay;		//设置命令
		
	ack_buff[PKT2_PARA] = HEX_Conversion_To_DEC(RTC_Raw_Data.year);			
	ack_buff[PKT2_PARA+1] = HEX_Conversion_To_DEC(RTC_Raw_Data.month);		
	ack_buff[PKT2_PARA+2] = HEX_Conversion_To_DEC(RTC_Raw_Data.day);		
	ack_buff[PKT2_PARA+3] = HEX_Conversion_To_DEC(RTC_Raw_Data.hour);		
	ack_buff[PKT2_PARA+4] = HEX_Conversion_To_DEC(RTC_Raw_Data.minute);		
	ack_buff[PKT2_PARA+5] = HEX_Conversion_To_DEC(RTC_Raw_Data.second);		
	ack_buff[PKT2_PARA+6] = HEX_Conversion_To_DEC(RTC_Raw_Data.week);
	
	ack_buff[PKT2_CHKSUM] = CheckSum(ack_buff,temp_len);
	
	/*发送数据*/
	if(g_pc_test.link_port == 0x00)
	{
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
			MCU485_SendString_0(ack_buff,temp_len);			//串口0
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
			UART0_SendString(ack_buff,temp_len);				//串口0
		#endif
	}else if(g_pc_test.link_port == 0x01)
	{	
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
			UART1_SendString(ack_buff,temp_len);				//串口1
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
			MCU485_SendString_1(ack_buff,temp_len);			//串口1
		#endif	
	}else if(g_pc_test.link_port == 0x02)
	{
		MCU485_SendString_2(ack_buff,temp_len);			//串口2
	}else {
		return 0xF0;
	}
	return 0x00;
}

uint8_t TEST_GPIO_DATA_Processing(uint32_t data_addr,uint16_t data_len)
{
	uint16_t temp_len = 0x09;
	uint8_t temp = 0,temp1 = 0;
	uint8_t ack_buff[10];
	memset(ack_buff,0,10);

	temp = SRAM_Read_Byte(data_addr + PKT2_PARA);		//设置GPIO输出高电平 - 控制序号
	temp1 = SRAM_Read_Byte(data_addr + PKT2_PARA + 1);	//设置GPIO状态
	
	#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
		C1F_Test_Gpio_Control(temp,temp1);
	#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
			
		Test_Gpio_Control(temp,temp1);
	#endif
	
	
	/*回复数据打包*/
	ack_buff[PKT2_ADD_FM] = 0x00;			//本机地址
	ack_buff[PKT2_TYPE] = g_pc_test.DevSendSN;
	ack_buff[PKT2_DevType] = PCTESTTYPE;						//设备类型
	ack_buff[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
	ack_buff[PKT2_LEN] = temp_len & 0xFF;						//本次发送数据长度
	ack_buff[PKT2_LEN_8] = (temp_len >> 8) & 0xFF;
	ack_buff[PKT2_CHKSUM] = 0x00;								//校验
	ack_buff[PKT2_CMD] = BLV_PC_TEST_GPIO_Relay;		//设置命令
		
	ack_buff[PKT2_PARA] = 0x01;		//回复状态	0x01：执行成功 ，0x00：执行失败	

	ack_buff[PKT2_CHKSUM] = CheckSum(ack_buff,temp_len);
	
	/*发送数据*/
	if(g_pc_test.link_port == 0x00)
	{
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
			MCU485_SendString_0(ack_buff,temp_len);			//串口0
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
			UART0_SendString(ack_buff,temp_len);				//串口0
		#endif
	}else if(g_pc_test.link_port == 0x01)
	{	
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
			UART1_SendString(ack_buff,temp_len);				//串口1
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
			MCU485_SendString_1(ack_buff,temp_len);			//串口1
		#endif	
	}else if(g_pc_test.link_port == 0x02)
	{
		MCU485_SendString_2(ack_buff,temp_len);			//串口2
	}else {
		return 0xF0;
	}
	
	return 0x00;
}

uint8_t TEST_GPIO_Relay_Fail(void)
{
	uint16_t temp_len = 0x09;
	uint8_t ack_buff[10];
	memset(ack_buff,0,10);
	
	/*回复数据打包*/
	ack_buff[PKT2_ADD_FM] = 0x00;			//本机地址
	ack_buff[PKT2_TYPE] = g_pc_test.DevSendSN;
	ack_buff[PKT2_DevType] = PCTESTTYPE;						//设备类型
	ack_buff[PKT2_ADD_TO] = 0x00;								//设备地址 - C5 MUSIC固定设备地址为0x01
	ack_buff[PKT2_LEN] = temp_len & 0xFF;						//本次发送数据长度
	ack_buff[PKT2_LEN_8] = (temp_len >> 8) & 0xFF;
	ack_buff[PKT2_CHKSUM] = 0x00;								//校验
	ack_buff[PKT2_CMD] = BLV_PC_TEST_GPIO_Relay;		//设置命令
		
	ack_buff[PKT2_PARA] = 0x00;		//回复状态	0x01：执行成功 ，0x00：执行失败	

	ack_buff[PKT2_CHKSUM] = CheckSum(ack_buff,temp_len);
	
	/*发送数据*/
	if(g_pc_test.link_port == 0x00)
	{
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		
			MCU485_SendString_0(ack_buff,temp_len);			//串口0
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		-- DEBUG
			UART0_SendString(ack_buff,temp_len);				//串口0
		#endif
	}else if(g_pc_test.link_port == 0x01)
	{	
		#if (USE_CORE_TYPE == 1)    //使用C1F核心板		-- DEBUG
			UART1_SendString(ack_buff,temp_len);				//串口1
		#elif (USE_CORE_TYPE == 2)   //使用C1核心板		
			MCU485_SendString_1(ack_buff,temp_len);			//串口1
		#endif	
	}else if(g_pc_test.link_port == 0x02)
	{
		MCU485_SendString_2(ack_buff,temp_len);			//串口2
	}else {
		return 0xF0;
	}
	
	return 0x00;
}


/*初始化GPIO口 输出拉低*/
void Test_GPIO_Init(void)
{
}

uint8_t Test_Gpio_Control(uint8_t pin,uint8_t status)
{
	uint8_t rev = 0;
	switch(pin)
	{
		case 1:		//PA5
			GPIOA_ModeCfg(GPIO_Pin_5,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOA_SetBits(GPIO_Pin_5);
			}else {
				GPIOA_ResetBits(GPIO_Pin_5);
			}
			break;
		case 2:		//PA4
			GPIOA_ModeCfg(GPIO_Pin_4,GPIO_ModeOut_PP_20mA);
			
			if(status == 0x01)
			{
				GPIOA_SetBits(GPIO_Pin_4);
			}else {
				GPIOA_ResetBits(GPIO_Pin_4);
			}
			break;
		case 3:		//PA6
			GPIOA_ModeCfg(GPIO_Pin_6,GPIO_ModeOut_PP_20mA);
			
			if(status == 0x01)
			{
				GPIOA_SetBits(GPIO_Pin_6);
			}else {
				GPIOA_ResetBits(GPIO_Pin_6);
			}
			break;
		case 4:		//PA0
			GPIOA_ModeCfg(GPIO_Pin_0,GPIO_ModeOut_PP_20mA);
			
			if(status == 0x01)
			{
				GPIOA_SetBits(GPIO_Pin_0);
			}else {
				GPIOA_ResetBits(GPIO_Pin_0);
			}
			break;
		case 5:		//PA1
			GPIOA_ModeCfg(GPIO_Pin_1,GPIO_ModeOut_PP_20mA);
			
			if(status == 0x01)
			{
				GPIOA_SetBits(GPIO_Pin_1);
			}else {
				GPIOA_ResetBits(GPIO_Pin_1);
			}
			break;
		case 6:		//PA2
			GPIOA_ModeCfg(GPIO_Pin_2,GPIO_ModeOut_PP_20mA);
			
			if(status == 0x01)
			{
				GPIOA_SetBits(GPIO_Pin_2);
			}else {
				GPIOA_ResetBits(GPIO_Pin_2);
			}
			break;
		case 7:		//VCC
			
			break;
		case 8:		//PA11
			GPIOA_ModeCfg(GPIO_Pin_11,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOA_SetBits(GPIO_Pin_11);
			}else {
				GPIOA_ResetBits(GPIO_Pin_11);
			}
			
			break;
		case 9:		//VCC
			
			break;
		case 10:	//GND
			
			break;
		case 11:	//PB16
			GPIOB_ModeCfg(GPIO_Pin_16,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_16);
			}else {
				GPIOB_ResetBits(GPIO_Pin_16);
			}
			break;
		case 12:	//GND
			
			break;
		case 13:	//PB8
			GPIOB_ModeCfg(GPIO_Pin_8,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_8);
			}else {
				GPIOB_ResetBits(GPIO_Pin_8);
			}
			break;
		case 14:	//PB17
			GPIOB_ModeCfg(GPIO_Pin_17,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_17);
			}else {
				GPIOB_ResetBits(GPIO_Pin_17);
			}
			
			break;
		case 15:	//PA9
			GPIOA_ModeCfg(GPIO_Pin_9,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOA_SetBits(GPIO_Pin_9);
			}else {
				GPIOA_ResetBits(GPIO_Pin_9);
			}
			
			break;
		case 16:	//PB9
			GPIOB_ModeCfg(GPIO_Pin_9,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_9);
			}else {
				GPIOB_ResetBits(GPIO_Pin_9);
			}

			break;
		case 17:	//PA8
			GPIOA_ModeCfg(GPIO_Pin_8,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOA_SetBits(GPIO_Pin_8);
			}else {
				GPIOA_ResetBits(GPIO_Pin_8);
			}
			
			break;
		case 18:	//PA7
			GPIOA_ModeCfg(GPIO_Pin_7,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOA_SetBits(GPIO_Pin_7);
			}else {
				GPIOA_ResetBits(GPIO_Pin_7);
			}
			
			break;
		case 19:	//VBAT
			
			break;
		case 20:	//VBAT
			
			break;
		case 21:	//PB20
			GPIOB_ModeCfg(GPIO_Pin_20,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_20);
			}else {
				GPIOB_ResetBits(GPIO_Pin_20);
			}
			
			break;
		case 22:	//PB21
			GPIOB_ModeCfg(GPIO_Pin_21,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_21);
			}else {
				GPIOB_ResetBits(GPIO_Pin_21);
			}
			
			break;
		case 23:	//PB19
			GPIOB_ModeCfg(GPIO_Pin_19,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_19);
			}else {
				GPIOB_ResetBits(GPIO_Pin_19);
			}
			
			break;
		case 24:	//PB22
			GPIOB_ModeCfg(GPIO_Pin_22,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_22);
			}else {
				GPIOB_ResetBits(GPIO_Pin_22);
			}
			
			break;
		case 25:	//PB18
			GPIOB_ModeCfg(GPIO_Pin_18,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_18);
			}else {
				GPIOB_ResetBits(GPIO_Pin_18);
			}
			
			break;
		case 26:	//PB23
			GPIOB_ModeCfg(GPIO_Pin_23,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_23);
			}else {
				GPIOB_ResetBits(GPIO_Pin_23);
			}
			
			break;
		case 27:	//PB0
			GPIOB_ModeCfg(GPIO_Pin_0,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_0);
			}else {
				GPIOB_ResetBits(GPIO_Pin_0);
			}

			break;
		case 28:	//PB2
			GPIOB_ModeCfg(GPIO_Pin_2,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_2);
			}else {
				GPIOB_ResetBits(GPIO_Pin_2);
			}
			
			break;
		case 29:	//PB1
			GPIOB_ModeCfg(GPIO_Pin_1,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_1);
			}else {
				GPIOB_ResetBits(GPIO_Pin_1);
			}
			
			break;
		case 30:	//PB3
			GPIOB_ModeCfg(GPIO_Pin_3,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_3);
			}else {
				GPIOB_ResetBits(GPIO_Pin_3);
			}
			
			break;
		case 31:	//PB5
			GPIOB_ModeCfg(GPIO_Pin_5,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_5);
			}else {
				GPIOB_ResetBits(GPIO_Pin_5);
			}
			
			break;
		case 32:	//PB4
			GPIOB_ModeCfg(GPIO_Pin_4,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_4);
			}else {
				GPIOB_ResetBits(GPIO_Pin_4);
			}
			
			break;
		case 33:	//PB7
			GPIOB_ModeCfg(GPIO_Pin_7,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_7);
			}else {
				GPIOB_ResetBits(GPIO_Pin_7);
			}
			
			break;
		case 34:	//PB6
			GPIOB_ModeCfg(GPIO_Pin_6,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_6);
			}else {
				GPIOB_ResetBits(GPIO_Pin_6);
			}
			
			break;
		case 35:	//PB11
			GPIOB_ModeCfg(GPIO_Pin_11,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_11);
			}else {
				GPIOB_ResetBits(GPIO_Pin_11);
			}
			
			break;
		case 36:	//PB10
			GPIOB_ModeCfg(GPIO_Pin_10,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_10);
			}else {
				GPIOB_ResetBits(GPIO_Pin_10);
			}
			
			break;
		case 37:	//PB13
			GPIOB_ModeCfg(GPIO_Pin_13,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_13);
			}else {
				GPIOB_ResetBits(GPIO_Pin_13);
			}
			
			break;
		case 38:	//PB12
			GPIOB_ModeCfg(GPIO_Pin_12,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_12);
			}else {
				GPIOB_ResetBits(GPIO_Pin_12);
			}
			
			break;
		case 39:	//PB15
			GPIOB_ModeCfg(GPIO_Pin_15,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_15);
			}else {
				GPIOB_ResetBits(GPIO_Pin_15);
			}
			
			break;
		case 40:	//PB14
			GPIOB_ModeCfg(GPIO_Pin_14,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_14);
			}else {
				GPIOB_ResetBits(GPIO_Pin_14);
			}
			
			break;
		default:
			rev = 0xF0;
			break;
	}
	return rev;
}

/*C1F GPIO控制*/
uint8_t C1F_Test_Gpio_Control(uint8_t pin,uint8_t status)
{
	uint8_t rev = 0;
	switch(pin)
	{
		case 1:		//PA5
			GPIOA_ModeCfg(GPIO_Pin_5,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOA_SetBits(GPIO_Pin_5);
			}else {
				GPIOA_ResetBits(GPIO_Pin_5);
			}
			break;
		case 2:		//PA4
			GPIOA_ModeCfg(GPIO_Pin_4,GPIO_ModeOut_PP_20mA);
			
			if(status == 0x01)
			{
				GPIOA_SetBits(GPIO_Pin_4);
			}else {
				GPIOA_ResetBits(GPIO_Pin_4);
			}
			break;
		case 3:		//PB22
			GPIOB_ModeCfg(GPIO_Pin_22,GPIO_ModeOut_PP_20mA);
			
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_22);
			}else {
				GPIOB_ResetBits(GPIO_Pin_22);
			}
			break;
		case 4:		//PB11
			GPIOB_ModeCfg(GPIO_Pin_11,GPIO_ModeOut_PP_20mA);
			
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_11);
			}else {
				GPIOB_ResetBits(GPIO_Pin_11);
			}
			break;
		case 5:		//PA11
			GPIOA_ModeCfg(GPIO_Pin_11,GPIO_ModeOut_PP_20mA);
			
			if(status == 0x01)
			{
				GPIOA_SetBits(GPIO_Pin_11);
			}else {
				GPIOA_ResetBits(GPIO_Pin_11);
			}
			break;
		case 6:		//C1F没有
			break;
		case 7:		//VCC
			break;
		case 8:		//C1F没有
			break;
		case 9:		//VCC
			break;
		case 10:	//GND
			break;
		case 11:	//C1F没有
			break;
		case 12:	//GND
			break;
		case 13:	//C1F没有
			break;
		case 14:	//C1F没有
			break;
		case 15:	//PB7
			GPIOB_ModeCfg(GPIO_Pin_7,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_7);
			}else {
				GPIOB_ResetBits(GPIO_Pin_7);
			}
			
			break;
		case 16:	//C1F没有
			break;
		case 17:	//PB4
			GPIOB_ModeCfg(GPIO_Pin_4,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_4);
			}else {
				GPIOB_ResetBits(GPIO_Pin_4);
			}
			
			break;
		case 18:	//PA7
			GPIOA_ModeCfg(GPIO_Pin_7,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOA_SetBits(GPIO_Pin_7);
			}else {
				GPIOA_ResetBits(GPIO_Pin_7);
			}
			break;
		case 19:	//VBAT
			break;
		case 20:	//VBAT
			break;
		case 21:	//C1F没有
			break;
		case 22:	//PA10
			GPIOA_ModeCfg(GPIO_Pin_10,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOA_SetBits(GPIO_Pin_10);
			}else {
				GPIOA_ResetBits(GPIO_Pin_10);
			}
			break;
		case 23:	//C1F没有
			break;
		case 24:	//PB22
			GPIOB_ModeCfg(GPIO_Pin_22,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_22);
			}else {
				GPIOB_ResetBits(GPIO_Pin_22);
			}
			break;
		case 25:	//C1F没有
			break;
		case 26:	//C1F没有
			break;
		case 27:	//C1F没有
			break;
		case 28:	//C1F没有
			break;
		case 29:	//C1F没有
			break;
		case 30:	//C1F没有
			break;
		case 31:	//PB5
			GPIOB_ModeCfg(GPIO_Pin_5,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_5);
			}else {
				GPIOB_ResetBits(GPIO_Pin_5);
			}
			
			break;
		case 32:	//PA8
			GPIOA_ModeCfg(GPIO_Pin_8,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOA_SetBits(GPIO_Pin_8);
			}else {
				GPIOA_ResetBits(GPIO_Pin_8);
			}
			
			break;
		case 33:	//PA9
			GPIOA_ModeCfg(GPIO_Pin_9,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOA_SetBits(GPIO_Pin_9);
			}else {
				GPIOA_ResetBits(GPIO_Pin_9);
			}
			
			break;
		case 34:	//PB6
			GPIOB_ModeCfg(GPIO_Pin_6,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_6);
			}else {
				GPIOB_ResetBits(GPIO_Pin_6);
			}
			
			break;
		case 35:	//C1F没有
			break;
		case 36:	//C1F没有
			break;
		case 37:	//PB13
			GPIOB_ModeCfg(GPIO_Pin_13,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_13);
			}else {
				GPIOB_ResetBits(GPIO_Pin_13);
			}
			
			break;
		case 38:	//PB12
			GPIOB_ModeCfg(GPIO_Pin_12,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_12);
			}else {
				GPIOB_ResetBits(GPIO_Pin_12);
			}
			
			break;
		case 39:	//PB15
			GPIOB_ModeCfg(GPIO_Pin_15,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_15);
			}else {
				GPIOB_ResetBits(GPIO_Pin_15);
			}
			
			break;
		case 40:	//PB14
			GPIOB_ModeCfg(GPIO_Pin_14,GPIO_ModeOut_PP_20mA);
			if(status == 0x01)
			{
				GPIOB_SetBits(GPIO_Pin_14);
			}else {
				GPIOB_ResetBits(GPIO_Pin_14);
			}
			
			break;
		default:
			rev = 0xF0;
			break;
	}
	return rev;
}
