
/**
  ******************************************************************************
  * @file    BLV_485_Dev_IN_CH6.c
  * @author  BLW RCU  development Team
  * @version 
  * @date    2022年04月20日
  * @brief  
	*    485 六路弱电输入
	*    输入：有
	*    输出：无
	* @log Songhan 202204201500   接收处理函数里，产生动作就置设备扫描下标
	* @log Songhan 202204212030   接收处理函数里，按照最快的速度返回
  ******************************************************************************
  */








#include "BLV_485_Dev_IN_CH6.h"
#include "string.h"
#include "DBG.h"
#include "SPI_SRAM.h"
#include "check_fun.h"
#include "usart.h"
#include "Log_api.h"
//#include "APP_SwitchCtrl.h"
#include "BLV_Nor_Dev_LVinputFun.h"
#include "APP_SwitchCtrl.h"


#define INCH6TYPE			0xF1	//设备类型只用于协议通讯上使用
#define DEV_IN_CH6_Type		0x02	//弱电输入 - 用于设备列表中的设备类型

#define INCH6_DI_CH_MAX		0x06
#define INCH6_RecvData_Len_Max	0x20	//目前接收数据最长21Byte	

#define INCH6_Control_Num	2
#define INCH6_Query_State_Flag		0x0001		//查询状态
#define INCH6_Set_DIState_Flag		0x0002		//设置DI状态

#define INCH6_Query_State_Cmd 		0x20
#define INCH6_Set_DIState_Cmd		0x25
#define INCH6_Query_Versions_Cmd	0x26		//查询版本号 - 暂时没用，但协议支持
#define INCH6_DIState_Report_Cmd	0x28

#define BLV_INCH6_Reply_CMD			0xA0		//回复命令
#define BLV_INCH6_Reply_Result				0x00		//查询结果
#define BLV_INCH6_Di_Result					0x05		//DI执行成功
#define BLV_INCH6_Error_Result				0xF0		//数据格式错误

#define INCH6_DI_Key_Type		0x01	//DI输入检测 - 按键类型
#define INCH6_DI_Pir_Type		0x02	//DI输入检测 - PIR类型
#define INCH6_DI_Dry_Type		0x03	//DI输入检测 - 干接点
#define INCH6_DI_Level_HIGH		0x20	//DI输入检测为高电平
#define INCH6_DI_Level_LOW		0x10	//DI输入检测为低电平

typedef enum{
	DI_CH1,
	DI_CH2,
	DI_CH3,
	DI_CH4,
	DI_CH5,
	DI_CH6,
	DI_CH_MAX,
}INCH6_DI_NUM_E;

#if RS485_Dev_IN_CH6

uint8_t BLV_485_DEV_IN_CH6_Cycle_Call(uint32_t dev_addr);
uint8_t BLV_485_DEV_IN_CH6_Data_Processing(uint32_t dev_addr,uint32_t data_addr,uint16_t len);
uint8_t Dev_IN_CH6_InType_Get(uint32_t DevAddr, uint16_t DevInputLoop, uint16_t DevInputType);

/*******************************************************************************
* Function Name  : BLV_485_DEV_IN_CH6_Data_Init 
* Description    : IN_CH6设备信息初始化函数
* Input			 :
	data：数据指针 - 设备类型 1Byte，设备地址 1Byte，端口号 1Byte，波特率 4Byte，协议类型 1Byte，设备输入 2Byte,设备输出 2Byte,
	data_len：数据长度
*******************************************************************************/
void BLV_485_DEV_IN_CH6_Data_Init(uint16_t data_len, uint8_t *data)
{
	NOR_LVINPUT_INFO DevLVinputInfo;       //弱电输入局部变量
	Device_Public_Information_G BUS_Public;
	
	memset(&BUS_Public,0,sizeof(Device_Public_Information_G));
	memset(&DevLVinputInfo,0,sizeof(NOR_LVINPUT_INFO));
	
	/*公共信息初始化*/
	BUS_Public.type = data[0];
	BUS_Public.addr = data[1];
	BUS_Public.baud = 9600;				//设备发送波特率
	BUS_Public.retry_num = 0x03;		//设备数据重发次数
	BUS_Public.wait_time = 0x64;		//设备数据发送等待回复时间 
	BUS_Public.polling_cf = (uint32_t)&BLV_485_DEV_IN_CH6_Cycle_Call;
	BUS_Public.processing_cf = (uint32_t)&BLV_485_DEV_IN_CH6_Data_Processing;
	BUS_Public.DevFunInfo.Dev_Input_Type_Get = Dev_IN_CH6_InType_Get;        //

	/*设备信息初始化*/
	DevLVinputInfo.DI_Type[DI_CH1] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;
	DevLVinputInfo.DI_Type[DI_CH2] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;			
	DevLVinputInfo.DI_Type[DI_CH3] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;			
	DevLVinputInfo.DI_Type[DI_CH4] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;			
	DevLVinputInfo.DI_Type[DI_CH5] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;			
	DevLVinputInfo.DI_Type[DI_CH6] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;		
	
	DevLVinputInfo.DI_Detection_Time[DI_CH1] = 0x02;	//设置消抖时间为20ms	
	DevLVinputInfo.DI_Detection_Time[DI_CH2] = 0x02;	//设置消抖时间为20ms
	DevLVinputInfo.DI_Detection_Time[DI_CH3] = 0x02;	//设置消抖时间为20ms
	DevLVinputInfo.DI_Detection_Time[DI_CH4] = 0x02;	//设置消抖时间为20ms
	DevLVinputInfo.DI_Detection_Time[DI_CH5] = 0x02;	//设置消抖时间为20ms
	DevLVinputInfo.DI_Detection_Time[DI_CH6] = 0x02;	//设置消抖时间为20ms

	DevLVinputInfo.DI_Report_En[DI_CH1] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH2] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH3] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH4] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH5] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH6] = 0x01;
	
	DevLVinputInfo.DI_set_flag = 0x3F;
	DevLVinputInfo.control_flag |= INCH6_Set_DIState_Flag;
	DevLVinputInfo.DevOffline = DevLVinputInfo.DevOfflineLast = DEV_IS_LINEUNINIT;   //在线状态初始化
	if(data[8] > LVINPUTNUMMAX)
	{
		 DevLVinputInfo.LVinputValidNum = LVINPUTNUMMAX;
	}
	else
	{
		DevLVinputInfo.LVinputValidNum = data[8];  //C1_LVINPUTNUMMAX;
	}
	
	BUS_Public.port = Active_Port;		//设备发送端口
	Add_ACT_Device_To_List2(&BUS_Public,(uint8_t *)&DevLVinputInfo,sizeof(NOR_LVINPUT_INFO));

//	Add_POLL_Device_To_List2(&BUS_Public,(uint8_t *)&DevLVinputInfo,sizeof(NOR_LVINPUT_INFO));

}

/*******************************************************************************
* Function Name  : BLV_485_DEV_IN_CH6_Data_Logic_Init 
* Description    : IN_CH6设备信息初始化函数
* Input			 :
	data：数据指针 - 设备类型 1Byte，设备地址 1Byte，端口号 1Byte，波特率 4Byte，协议类型 1Byte，设备输入 2Byte,设备输出 2Byte,
	data_len：数据长度
*******************************************************************************/
void BLV_485_DEV_IN_CH6_Data_Logic_Init(LOGICFILE_DEVICE_INFO *dev_info, uint8_t *data, uint16_t data_len)
{
	NOR_LVINPUT_INFO DevLVinputInfo;       //弱电输入局部变量
	Device_Public_Information_G BUS_Public;
	uint16_t temp_len = 0;
	uint8_t input_type = 0;
	uint8_t input_level = 0;
	uint8_t input_time = 0;
	uint8_t input_set_flag = 0;
	
	memset(&BUS_Public,0,sizeof(Device_Public_Information_G));
	memset(&DevLVinputInfo,0,sizeof(NOR_LVINPUT_INFO));
	
	/*公共信息初始化*/
	BUS_Public.type = dev_info->type;			//设备地址
	BUS_Public.addr = dev_info->addr;		//设备类型
	BUS_Public.baud = dev_info->baud;				//设备发送波特率
	BUS_Public.Protocol = dev_info->version;
	BUS_Public.retry_num = 0x03;		//设备数据重发次数
	BUS_Public.wait_time = 0x64;		//设备数据发送等待回复时间 
	BUS_Public.polling_cf = (uint32_t)&BLV_485_DEV_IN_CH6_Cycle_Call;
	BUS_Public.processing_cf = (uint32_t)&BLV_485_DEV_IN_CH6_Data_Processing;
	BUS_Public.DevFunInfo.Dev_Input_Type_Get = Dev_IN_CH6_InType_Get;        //

//	/*设备信息初始化*/
//	DevLVinputInfo.DI_Type[DI_CH1] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;
//	DevLVinputInfo.DI_Type[DI_CH2] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;			
//	DevLVinputInfo.DI_Type[DI_CH3] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;			
//	DevLVinputInfo.DI_Type[DI_CH4] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;			
//	DevLVinputInfo.DI_Type[DI_CH5] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;			
//	DevLVinputInfo.DI_Type[DI_CH6] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;		
//	
//	DevLVinputInfo.DI_Detection_Time[DI_CH1] = 0x02;	//设置消抖时间为20ms	
//	DevLVinputInfo.DI_Detection_Time[DI_CH2] = 0x02;	//设置消抖时间为20ms
//	DevLVinputInfo.DI_Detection_Time[DI_CH3] = 0x02;	//设置消抖时间为20ms
//	DevLVinputInfo.DI_Detection_Time[DI_CH4] = 0x02;	//设置消抖时间为20ms
//	DevLVinputInfo.DI_Detection_Time[DI_CH5] = 0x02;	//设置消抖时间为20ms
//	DevLVinputInfo.DI_Detection_Time[DI_CH6] = 0x02;	//设置消抖时间为20ms

//	DevLVinputInfo.DI_Report_En[DI_CH1] = 0x01;
//	DevLVinputInfo.DI_Report_En[DI_CH2] = 0x01;
//	DevLVinputInfo.DI_Report_En[DI_CH3] = 0x01;
//	DevLVinputInfo.DI_Report_En[DI_CH4] = 0x01;
//	DevLVinputInfo.DI_Report_En[DI_CH5] = 0x01;
//	DevLVinputInfo.DI_Report_En[DI_CH6] = 0x01;
//	
//	DevLVinputInfo.DI_set_flag = 0x3F;
//	DevLVinputInfo.control_flag |= INCH6_Set_DIState_Flag;
//	
	if(dev_info->input_num > LVINPUTNUMMAX)
	{
		DevLVinputInfo.LVinputValidNum = LVINPUTNUMMAX;
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"初始化DI回路超出范围!");
	}
	else 
	{
		DevLVinputInfo.LVinputValidNum = dev_info->input_num;  //C1_LVINPUTNUMMAX;
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"初始化DI回路 %d ",DevLVinputInfo.LVinputValidNum);
	}
	
	/*采用配置文件中的设置参数*/
	DevLVinputInfo.DevOffline = DevLVinputInfo.DevOfflineLast = DEV_IS_LINEUNINIT;   //在线状态初始化
	temp_len = DevLVinputInfo.LVinputValidNum*4;	//设置DI类型以及设置触发状态
	if((temp_len + LogicFile_DeviceInfo_InputSet) > data_len)
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"初始化DI数据长度不对 %d - %d ",data_len,(temp_len + LogicFile_DeviceInfo_InputSet));
	}
	
	temp_len = 0;
	for(uint8_t i=0;i<dev_info->input_num;i++)
	{
		input_set_flag = 0;
		input_type = data[LogicFile_DeviceInfo_InputSet + temp_len + 0];
		input_level = data[LogicFile_DeviceInfo_InputSet + temp_len + 1];
		input_time = data[LogicFile_DeviceInfo_InputSet + temp_len + 2];
		
		switch(input_type)
		{
			case INCH6_DI_Key_Type:
				input_set_flag++;
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"DI%d - 按键",i);
				DevLVinputInfo.DI_Type[i] = INCH6_DI_Key_Type;
				break;
			case INCH6_DI_Pir_Type:
				input_set_flag++;
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"DI%d - PIR",i);
				DevLVinputInfo.DI_Type[i] = INCH6_DI_Pir_Type;
				break;
			case INCH6_DI_Dry_Type:
				input_set_flag++;
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"DI%d - 干接点",i);
				DevLVinputInfo.DI_Type[i] = INCH6_DI_Dry_Type;
				break;
			default:
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"DI%d - 类型不对",i);
				break;
		}
		
		switch(input_level)
		{
			case 0x01:
				input_set_flag++;
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"DI%d - 触发电平:高电平 消抖时间:%d0ms",i,input_time);
			
				DevLVinputInfo.DI_Type[i] |= INCH6_DI_Level_HIGH;
				DevLVinputInfo.DI_Detection_Time[i] = input_time;
				break;
			case 0x02:
				input_set_flag++;
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"DI%d - 触发电平:高电平 消抖时间:%d0ms",i,input_time);
			
				DevLVinputInfo.DI_Type[i] |= INCH6_DI_Level_LOW;
				DevLVinputInfo.DI_Detection_Time[i] = input_time;
				break;
			default:
				Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"DI%d - 触发电平数据不对 消抖时间:%d0ms",i,input_time);
				break;
		}
		
		if(input_set_flag != 0x02)	//设置类型及触发电平不对，采用默认参数
		{
			DevLVinputInfo.DI_Type[i] = INCH6_DI_Key_Type | INCH6_DI_Level_LOW;
			DevLVinputInfo.DI_Detection_Time[i] = 0x02;	//设置消抖时间为20ms	
		}
		
		temp_len +=4;
		
	}
	
	DevLVinputInfo.DI_Report_En[DI_CH1] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH2] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH3] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH4] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH5] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH6] = 0x01;
	
	DevLVinputInfo.DI_set_flag = 0x3F;
	DevLVinputInfo.control_flag |= INCH6_Set_DIState_Flag;
	
	BUS_Public.port = Active_Port;		//设备发送端口
	Add_ACT_Device_To_List2(&BUS_Public,(uint8_t *)&DevLVinputInfo,sizeof(NOR_LVINPUT_INFO));

//	Add_POLL_Device_To_List2(&BUS_Public,(uint8_t *)&DevLVinputInfo,sizeof(NOR_LVINPUT_INFO));

}


void BLV_485_DEV_IN_CH6_Data_Init2(uint8_t addr)
{
	NOR_LVINPUT_INFO DevLVinputInfo;
	Device_Public_Information_G BUS_Public;
	memset(&BUS_Public,0,sizeof(Device_Public_Information_G));
	memset(&DevLVinputInfo,0,sizeof(NOR_LVINPUT_INFO));
	
	/*公共信息初始化*/
	BUS_Public.type = DEV_IN_CH6_Type;
	BUS_Public.addr = addr;
	BUS_Public.port = Active_Port;
	BUS_Public.baud = 9600;				//设备发送波特率
	BUS_Public.retry_num = 0x03;		//设备数据重发次数
	BUS_Public.wait_time = 0x64;		//设备数据发送等待回复时间 
	BUS_Public.polling_cf = (uint32_t)&BLV_485_DEV_IN_CH6_Cycle_Call;
	BUS_Public.processing_cf = (uint32_t)&BLV_485_DEV_IN_CH6_Data_Processing;

	/*设备信息初始化*/
	DevLVinputInfo.DI_Type[DI_CH1] = INCH6_DI_Key_Type | INCH6_DI_Level_LOW;
	DevLVinputInfo.DI_Type[DI_CH2] = INCH6_DI_Key_Type | INCH6_DI_Level_LOW;			
	DevLVinputInfo.DI_Type[DI_CH3] = INCH6_DI_Key_Type | INCH6_DI_Level_LOW;			
	DevLVinputInfo.DI_Type[DI_CH4] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;			
	DevLVinputInfo.DI_Type[DI_CH5] = INCH6_DI_Dry_Type | INCH6_DI_Level_HIGH;			
	DevLVinputInfo.DI_Type[DI_CH6] = INCH6_DI_Dry_Type | INCH6_DI_Level_HIGH;			
	
	DevLVinputInfo.DI_Detection_Time[DI_CH1] = 0x02;	//设置消抖时间为20ms	
	DevLVinputInfo.DI_Detection_Time[DI_CH2] = 0x02;	//设置消抖时间为20ms
	DevLVinputInfo.DI_Detection_Time[DI_CH3] = 0x02;	//设置消抖时间为20ms
	DevLVinputInfo.DI_Detection_Time[DI_CH4] = 0x02;	//设置消抖时间为20ms
	DevLVinputInfo.DI_Detection_Time[DI_CH5] = 0x02;	//设置消抖时间为20ms
	DevLVinputInfo.DI_Detection_Time[DI_CH6] = 0x02;	//设置消抖时间为20ms

	DevLVinputInfo.DI_Report_En[DI_CH1] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH2] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH3] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH4] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH5] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH6] = 0x01;
	
	DevLVinputInfo.DI_set_flag = 0x3F;
	DevLVinputInfo.control_flag |= INCH6_Set_DIState_Flag;
		
	Add_ACT_Device_To_List2(&BUS_Public,(uint8_t *)&DevLVinputInfo,sizeof(NOR_LVINPUT_INFO));
	Act485_Info.device_num += 1;
	
	Dbg_Print(DBG_BIT_DEVICE_STATUS_bit, "BLV_485_DEV_IN_CH6_Data_Init2 Active_Port Addr:%d",BUS_Public.addr);
}

/**
*@name 弱电输入输入检测函数
*@para
*  DevAddr      设备地址
*  DevInputLoop 回路输入地址  范围0~LVinputValidNum  
*  DevInputType 输入类型
*/

uint8_t Dev_IN_CH6_InType_Get(uint32_t DevAddr, uint16_t DevInputLoop, uint16_t DevInputType)
{
	Device_Public_Information_G BUS_Public;
	NOR_LVINPUT_INFO DevLVinputInfo;       //弱电输入局部变量
	uint8_t Ret = CtrlInvalid;         //控制无效
	
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),DevAddr);		
	SRAM_DMA_Read_Buff((uint8_t *)&DevLVinputInfo,sizeof(NOR_LVINPUT_INFO),DevAddr+Dev_Privately);/*拷贝设备私有信息*/
	
	if(DevInputLoop >= DevLVinputInfo.LVinputValidNum)
	{
		return Ret;
	}   
	   
	if(DevInputType == DevLVinputInfo.DevReadBuf[DevInputLoop])  //找到类型
	{
		DevLVinputInfo.DevReadBuf[DevInputLoop] = 0x00;          //将动作清空
		Ret = CtrlValid;
	}
	
	if(CtrlValid == Ret)
	{
		Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"6路弱电输入，输入动作类型: %d 动作清空", DevInputType);

		BUS_Public.check = 0x00;
		BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&DevLVinputInfo, sizeof(NOR_LVINPUT_INFO));
		SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),DevAddr);/*将数据保存*/
		SRAM_DMA_Write_Buff((uint8_t *)&DevLVinputInfo,sizeof(NOR_LVINPUT_INFO),DevAddr+Dev_Privately);
				
	}
	
	return Ret;
	
}

/*******************************************************************************
* Function Name  : INCH6_Query_State_Datasend 
* Description    : IN_CH6查询状态数据发送函数
* Input          : 
	port	: 数据发送端口
	DevLVinputInfo：设备信息
* Return         :
*******************************************************************************/
void INCH6_Query_State_Datasend(Device_Public_Information_G *info,NOR_LVINPUT_INFO *DevLVinputInfo)
{
	uint8_t send_buff[8];
	memset(send_buff,0,8);
	
	send_buff[PKT_ADD_FM] = 0x00;			//本机地址
	if(DevLVinputInfo->DevSendCnt == 0x00)
	{
		DevLVinputInfo->DevSn++;
		if(DevLVinputInfo->DevSn > 0x0F)	DevLVinputInfo->DevSn = 0x00;
		send_buff[PKT_TYPE] |= (DevLVinputInfo->DevSn & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		send_buff[PKT_TYPE] |= (DevLVinputInfo->DevSn & 0x0F);
		send_buff[PKT_TYPE] |= BUS_Retry_Flag;
	}
	send_buff[PKT_DevType] = INCH6TYPE;				//设备类型
	send_buff[PKT_ADD_TO] = info->addr;				//设备地址 
	send_buff[PKT_LEN] = 0x07;						//本次发送数据长度
	send_buff[PKT_CHKSUM] = 0x00;					//校验
	send_buff[PKT_CMD] = INCH6_Query_State_Cmd;		//设置DI命令
	
	send_buff[PKT_CHKSUM] = CheckSum(send_buff, send_buff[PKT_LEN]);
	
	DevLVinputInfo->Send_Type = INCH6_Query_State_Cmd; 

	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit, "INCH6_Query_State_Datasend:", send_buff, send_buff[PKT_LEN]);
	MCU485_SendString(info->port,send_buff, send_buff[PKT_LEN]);
	
	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(info->port,info->baud,send_buff,send_buff[PKT_LEN]);
}

/*******************************************************************************
* Function Name  : INCH6_Set_DIState_Datasend 
* Description    : IN_CH6设置DI状态数据发送函数
* Input          : 
	port	: 数据发送端口
	DevLVinputInfo：设备信息
* Return         :
*******************************************************************************/
void INCH6_Set_DIState_Datasend(Device_Public_Information_G *info,NOR_LVINPUT_INFO *DevLVinputInfo)
{
	uint8_t temp = 0;
	uint8_t send_buff[40];
	memset(send_buff,0,40);
	
	for(uint8_t i=0;i<INCH6_DI_CH_MAX;i++)
	{
		if((DevLVinputInfo->DI_set_flag & ( 0x01 << i )))
		{
			temp = PKT_PARA + (i/4);
			send_buff[temp] |= (DevLVinputInfo->DI_Type[i] & 0x03) << ((i%4)*2);
			temp = PKT_PARA + (i/4) + 4;
			send_buff[temp] |= ((DevLVinputInfo->DI_Type[i] >> 4) & 0x03) << ((i%4)*2);
			temp = PKT_PARA + 8 + i;
			send_buff[temp] = DevLVinputInfo->DI_Detection_Time[i];
			temp = PKT_PARA + 24 + (i/4);
			send_buff[temp] |= (DevLVinputInfo->DI_Report_En[i] & 0x03) << ((i%4)*2);
		}
	}
	DevLVinputInfo->Last_DI_set_flag = DevLVinputInfo->DI_set_flag;
	
	send_buff[PKT_ADD_FM] = 0x00;			//本机地址
	if(DevLVinputInfo->DevSendCnt == 0x00)
	{
		DevLVinputInfo->DevSn++;
		if(DevLVinputInfo->DevSn > 0x0F)	DevLVinputInfo->DevSn = 0x00;
		send_buff[PKT_TYPE] |= (DevLVinputInfo->DevSn & 0x0F);	//设置发送序号
	}else{	
		//本包数据为重发数据
		send_buff[PKT_TYPE] |= (DevLVinputInfo->DevSn & 0x0F);
		send_buff[PKT_TYPE] |= BUS_Retry_Flag;
	}
	
	send_buff[PKT_DevType] = INCH6TYPE;				//设备类型PKT_ADD_TO
	send_buff[PKT_ADD_TO] = info->addr;
	send_buff[PKT_LEN] = 0x23;						//本次发送数据长度
	send_buff[PKT_CHKSUM] = 0x00;					//校验
	send_buff[PKT_CMD] = INCH6_Set_DIState_Cmd;		//设置DI命令
	
	DevLVinputInfo->Send_Type = INCH6_Set_DIState_Cmd;
	
	send_buff[PKT_CHKSUM] = CheckSum(send_buff, send_buff[PKT_LEN]);
	MCU485_SendString(info->port,send_buff, send_buff[PKT_LEN]);
	/*日志记录*/
	LOG_Device_COMM_Send_Control_Record(info->port,info->baud,send_buff,send_buff[PKT_LEN]);
}

/*******************************************************************************
* Function Name  : BLV_485_DEV_IN_CH6_Cycle_Call 
* Description    : IN_CH6轮询发送函数
* Input          : 
	dev_addr	: 设备信息地址
* Return         :
	0x00：没问题
	0x01：错误 - 设备类型不对
*******************************************************************************/
uint8_t BLV_485_DEV_IN_CH6_Cycle_Call(uint32_t dev_addr)
{
	uint8_t send_flag = 0;
	uint8_t temp_control = 0;
	uint8_t temp_state = 0;
	Device_Public_Information_G BUS_Public;
	NOR_LVINPUT_INFO DevLVinputInfo;
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),dev_addr);				
	SRAM_DMA_Read_Buff((uint8_t *)&DevLVinputInfo,sizeof(NOR_LVINPUT_INFO),dev_addr+Dev_Privately);
	
	if(DevLVinputInfo.control_flag != 0x00)
	{
		for(uint8_t i=0;i<INCH6_Control_Num;i++)
		{
			temp_state = 0x01<<i;
			if((DevLVinputInfo.control_flag & temp_state))	break;
		}
		switch(temp_state)
		{
			case INCH6_Query_State_Flag:
				temp_control++;
				Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6_Query_State_Flag--------------------\r\n");
				INCH6_Query_State_Datasend(&BUS_Public,&DevLVinputInfo);
				send_flag = 0x01;
				break;
			case INCH6_Set_DIState_Flag:
				temp_control++;
				Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6_Set_DIState_Flag----------------------\r\n");
				INCH6_Set_DIState_Datasend(&BUS_Public,&DevLVinputInfo);
				send_flag = 0x01;
				break;
			default:
				break;
		}
		
		if(send_flag == 0x01)
		{
			BLV_Communication_Record(&DevLVinputInfo.comm_record,0x01,0x00);
			if(DevLVinputInfo.DevSendCnt > 0x03)
			{
				if(DevLVinputInfo.DevOffline != DEV_IS_OFFLINE)
				{
					Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"INCH6 OFFLINE");
					LOG_Device_Online_Record(BUS_Public.type,BUS_Public.addr,LogInfo_Device_Offline);	//记录设备离线
				}
				
				DevLVinputInfo.control_flag = 0x00;
				DevLVinputInfo.DevOffline = DEV_IS_OFFLINE;		//判为离线
				DevLVinputInfo.DevSendCnt = 0;
				if(DevLVinputInfo.DevOffline != DevLVinputInfo.DevOfflineLast)	//当前在线状态不等于上一次在线状态
				{
					DevLVinputInfo.DevOfflineLast = DevLVinputInfo.DevOffline;	//更新上一次在线状态
					Write_Device_Fault_State(BUS_Public.type,BUS_Public.addr,In_ErrFun_LineState,DEV_IS_OFFLINE);	//保存设备在线状态到SRAM
				}
			}else {
				DevLVinputInfo.DevSendCnt++;   				//发送次数累计
			}
			
			
			BUS_Public.check = 0x00;
			BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&DevLVinputInfo, sizeof(NOR_LVINPUT_INFO));
			SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),dev_addr);/*将数据保存*/
			SRAM_DMA_Write_Buff((uint8_t *)&DevLVinputInfo,sizeof(NOR_LVINPUT_INFO),dev_addr+Dev_Privately);
			
			return RS485OCCUPYTIME;
		}
		
	}
	
	return RS485OCCUPYNOTIME;
}

/*******************************************************************************
* Function Name  : INCH6_DIState_Report_Cmd_Processing 
* Description    : IN_CH6上报数据处理函数
* Input          : 
	data		: 数据内容
	len			：数据长度
* Return         : 
	0x00：处理成功
	0x01：处理失败
	0x02：处理成功，需要保存NOR_LVINPUT_INFO信息
*******************************************************************************/
uint8_t INCH6_DIState_Report_Cmd_Processing(Device_Public_Information_G* BUS_Public, NOR_LVINPUT_INFO *DevLVinputInfo,uint8_t *data,uint16_t len)
{
	Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6_DIState_Report_Cmd_Processing\r\n");
	
	uint8_t temp = 0,temp_1 = 0,temp_2 = 0,temp_3 = 0,temp_4 = 0;
	uint8_t rev = 0;
	for(uint8_t i=0;i<INCH6_DI_CH_MAX;i++)
	{
		temp_1 = i/4;
		temp_2 = i%4;
		
		temp = (data[temp_1] >> (temp_2*2)) & 0x03;
		temp_3 = DevLVinputInfo->DI_Type[i] & 0x0F;
		
		if(temp == temp_3)
		{
			switch(temp)
			{
				case INCH6_DI_Key_Type:
					temp_4 = (data[temp_1 + 4] >> (temp_2*2)) & 0x03;
					if(temp_4 != 0x00)
					{
						Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"6路弱电输入动作置位 回路:%d 状态:%d\r\n", i, temp_4);
						DevActionGlobal.Devi = BUS_Public->DevCoord;     //直接跳到指定的下标去处理
						DevLVinputInfo->DevReadBuf[i] = temp_4;          //按键状态置位
						DevLVinputInfo->DI_Start[i] = temp_4;
						Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6 DI_KEY Start%d %d ! \r\n",i,temp_4);
						rev = 0x02;
					}
					break;
				case INCH6_DI_Pir_Type:
					temp_4 = (data[temp_1 + 4] >> (temp_2*2)) & 0x03;
					if(temp_4 != DevLVinputInfo->DI_Start[i])
					{
						Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"6路弱电输入动作置位 回路:%d 状态:%d\r\n", i, temp_4);
						DevActionGlobal.Devi = BUS_Public->DevCoord;     //直接跳到指定的下标去处理						
						DevLVinputInfo->DevReadBuf[i] = temp_4;          //按键状态置位						
						DevLVinputInfo->DI_Start[i] = temp_4;
						Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6 DI_PIR Start%d %d ! \r\n",i,temp_4);
						rev = 0x02;
					}
					break;
				case INCH6_DI_Dry_Type:
					temp_4 = (data[temp_1 + 4] >> (temp_2*2)) & 0x03;
					if(temp_4 != DevLVinputInfo->DI_Start[i])
					{
						switch(temp_4)
						{
							case 0x00:    //	释放
								Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"6路弱电输入动作置位，回路:%d 状态:释放", i);
								DevActionGlobal.Devi = BUS_Public->DevCoord;     //直接跳到指定的下标去处理
								DevLVinputInfo->DevReadBuf[i] = KeyRelease;          //松开置位	

								break;
							case 0x01:    //按下
								Dbg_Println(DBG_BIT_LOGIC_STATUS_bit,"6路弱电输入动作置位，回路:%d 状态:按下", i);						
								DevActionGlobal.Devi = BUS_Public->DevCoord;     //直接跳到指定的下标去处理
								DevLVinputInfo->DevReadBuf[i] = KeyPress;          //长按置位
								break;
						}

						DevLVinputInfo->DI_Start[i] = temp_4;
						Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6 DI_DRY Start%d %d ! \r\n",i,temp_4);
						rev = 0x02;
					}
					break;
			}
		}else {
			//类型不对，需要重设DI状态
			Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6 Start%d Type Error ! \r\n",i);
		}
	}
	
	return rev;
}
#define IsMyData     0x00  
#define IsNotMyData  0x01
/*******************************************************************************
* Function Name  : BLV_485_DEV_IN_CH6_Data_Processing 
* Description    : IN_CH6数据处理函数
* Input          : 
	dev_addr	: 设备信息地址
	data_addr	: 数据地址
	len			：数据长度
* Return         : 
	0x00：处理成功
	0x01：处理失败
*******************************************************************************/
uint8_t BLV_485_DEV_IN_CH6_Data_Processing(uint32_t dev_addr,uint32_t data_addr,uint16_t len)
{
	uint8_t rev = IsNotMyData;
	Device_Public_Information_G BUS_Public;
	NOR_LVINPUT_INFO DevLVinputInfo;
	uint8_t data[INCH6_RecvData_Len_Max];
	
	if(len > INCH6_RecvData_Len_Max)
	{
		Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"6路弱电输入接收数据长度超出范围!!\r\n");
		return rev;     //长度
	}
	SRAM_DMA_Read_Buff(data,len,data_addr);   //拷贝485数据

	if((data[PKT_DevType] != INCH6TYPE)||(data[PKT_ADD_TO] != 0x00)||(data[PKT_LEN] != len) || (CheckSum(data,len) != 0x00)||(data[PKT_ADD_FM] != SRAM_Read_Byte(dev_addr+Dev_Addr)))
	{
		Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6 addr err or type err or len err Check Fail! \r\n");
		return rev;
	}
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),dev_addr);		
	SRAM_DMA_Read_Buff((uint8_t *)&DevLVinputInfo,sizeof(NOR_LVINPUT_INFO),dev_addr+Dev_Privately);
	
//	uint16_t deal_len = len;
//	if(deal_len > INCH6_RecvData_Len_Max)
//	{
//		Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6 Check_Len Fail! \r\n");
//		return 0x01;
//	}
	
//	uint8_t deal_buff[deal_len+2];
//	memset(deal_buff,0,sizeof(deal_buff));
//	SRAM_DMA_Read_Buff(deal_buff,deal_len,data_addr);		//读取处理数据长度
	
//	if()
//	{
//		Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6 Check Fail! \r\n");
//		return 0x01;	//和校验
//	}
//	
//	if()
//	{
//		Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6 PKT_ADD_FM Fail! \r\n");
//		return 0x01;						//发送地址不对
//	}
//	
//	if()	
//	{
//		Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6 PKT_DevType Fail! \r\n");
//		return 0x01;					//设备类型不对
//	}
//	
//	if()	
//	{
//		Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6 PKT_ADD_TO Fail! \r\n");
//		return 0x01;						//接收地址不对
//	}
//	
//	if()		
//	{
//		Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6 PKT_LEN Fail! \r\n");
//		return 0x01;						//长度不对
//	}
	
	if(DevLVinputInfo.DevOffline == DEV_IS_OFFLINE)	//设备处于离线状态
	{
		Dbg_Println(DBG_BIT_DEVICE_STATUS_bit,"INCH6 LogInfo_Device_Online...........");
		LOG_Device_Online_Record(BUS_Public.type,BUS_Public.addr,LogInfo_Device_Online);	//记录设备离线
	}
	
	BLV_Communication_Record(&DevLVinputInfo.comm_record,0x02,0x01);		//记录通讯成功
	
	DevLVinputInfo.DevSendCnt = 0x00;
	DevLVinputInfo.DevOffline = DEV_IS_ONLINE;    //设备在线
	if(DevLVinputInfo.DevOffline != DevLVinputInfo.DevOfflineLast)	//当前在线状态不等于上一次在线状态
	{
		DevLVinputInfo.DevOfflineLast = DevLVinputInfo.DevOffline;	//更新上一次在线状态
		Write_Device_Fault_State(BUS_Public.type,BUS_Public.addr,In_ErrFun_LineState,DEV_IS_ONLINE);	//保存设备在线状态到SRAM
	}
	Dbg_Print_Buff(DBG_BIT_DEVICE_STATUS_bit,"INCH6 DealBUFF...........",data,len);
	switch(data[PKT_CMD])
	{
		case INCH6_DIState_Report_Cmd:		//主动上报数据
			INCH6_DIState_Report_Cmd_Processing(&BUS_Public, &DevLVinputInfo,&data[PKT_PARA],len);
			break;
		case BLV_INCH6_Reply_CMD:			//回复ACK数据
			if((data[PKT_TYPE] & 0x0F) != DevLVinputInfo.DevSn)
			{
				Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6 PKT_TYPE Fail! \r\n");
				return 0x01;			//序号不对
			}
			
			switch(DevLVinputInfo.Send_Type)
			{
				case INCH6_Query_State_Cmd:	//查询状态回复
					if(data[PKT_PARA] == BLV_INCH6_Reply_Result)
					{
						
						INCH6_DIState_Report_Cmd_Processing(&BUS_Public, &DevLVinputInfo,&data[PKT_PARA + 1],len);
						DevLVinputInfo.control_flag &= ~(INCH6_Query_State_Flag);
						Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6 查询状态回复 %d\r\n",DevLVinputInfo.control_flag);
					}
					break;
				case INCH6_Set_DIState_Cmd:	//设置DI状态回复
					
					if(data[PKT_PARA] == BLV_INCH6_Di_Result)
					{
						
						DevLVinputInfo.DI_set_flag &= ~(DevLVinputInfo.Last_DI_set_flag);
						DevLVinputInfo.control_flag &= ~(INCH6_Set_DIState_Flag);
						Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6 设置DI状态回复 %d\r\n",DevLVinputInfo.control_flag);
					}
					break;
				default:
					break;
			}
			break;
	}
	
	BUS_Public.check = 0x00;
	BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&DevLVinputInfo, sizeof(NOR_LVINPUT_INFO));
	SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),dev_addr);/*将数据保存*/
	SRAM_DMA_Write_Buff((uint8_t *)&DevLVinputInfo,sizeof(NOR_LVINPUT_INFO),dev_addr+Dev_Privately);
	
	return 0x00;
}

void BLV_485_INCH6_Set_DIState(uint32_t dev_addr)
{
	Device_Public_Information_G BUS_Public;
	NOR_LVINPUT_INFO DevLVinputInfo;
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),dev_addr);		
	SRAM_DMA_Read_Buff((uint8_t *)&DevLVinputInfo,sizeof(NOR_LVINPUT_INFO),dev_addr+Dev_Privately);
	
	Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"BLV_485_INCH6_Set_DIState\r\n");
	
	DevLVinputInfo.DI_Type[DI_CH1] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;
	DevLVinputInfo.DI_Type[DI_CH2] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;			
	DevLVinputInfo.DI_Type[DI_CH3] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;			
	DevLVinputInfo.DI_Type[DI_CH4] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;			
	DevLVinputInfo.DI_Type[DI_CH5] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;			
	DevLVinputInfo.DI_Type[DI_CH6] = INCH6_DI_Dry_Type | INCH6_DI_Level_LOW;		
	
	DevLVinputInfo.DI_Detection_Time[DI_CH1] = 0x02;	//设置消抖时间为20ms	
	DevLVinputInfo.DI_Detection_Time[DI_CH2] = 0x02;	//设置消抖时间为20ms
	DevLVinputInfo.DI_Detection_Time[DI_CH3] = 0x02;	//设置消抖时间为20ms
	DevLVinputInfo.DI_Detection_Time[DI_CH4] = 0x02;	//设置消抖时间为20ms
	DevLVinputInfo.DI_Detection_Time[DI_CH5] = 0x02;	//设置消抖时间为20ms
	DevLVinputInfo.DI_Detection_Time[DI_CH6] = 0x02;	//设置消抖时间为20ms

	DevLVinputInfo.DI_Report_En[DI_CH1] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH2] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH3] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH4] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH5] = 0x01;
	DevLVinputInfo.DI_Report_En[DI_CH6] = 0x01;
	
	DevLVinputInfo.DI_set_flag = 0x3F;
	DevLVinputInfo.control_flag |= INCH6_Set_DIState_Flag;
	
	BUS_Public.check = 0x00;
	BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&DevLVinputInfo, sizeof(NOR_LVINPUT_INFO));
	SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),dev_addr);/*将数据保存*/
	SRAM_DMA_Write_Buff((uint8_t *)&DevLVinputInfo,sizeof(NOR_LVINPUT_INFO),dev_addr+Dev_Privately);
}

void BLV_485_INCH6_Query_State(uint32_t dev_addr)
{
	if(dev_addr == 0x00) return;
	Device_Public_Information_G BUS_Public;
	NOR_LVINPUT_INFO DevLVinputInfo;
	
	SRAM_DMA_Read_Buff((uint8_t *)&BUS_Public,sizeof(Device_Public_Information_G),dev_addr);		
	SRAM_DMA_Read_Buff((uint8_t *)&DevLVinputInfo,sizeof(NOR_LVINPUT_INFO),dev_addr+Dev_Privately);
	
	Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"BLV_485_INCH6_Query_State\r\n");
	DevLVinputInfo.control_flag |= INCH6_Query_State_Flag;
	
	
	
	BUS_Public.check = 0x00;
	BUS_Public.check = DoubleData_CheckSum((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G), (uint8_t *)&DevLVinputInfo, sizeof(NOR_LVINPUT_INFO));
	SRAM_DMA_Write_Buff((uint8_t *)&BUS_Public, sizeof(Device_Public_Information_G),dev_addr);/*将数据保存*/
	SRAM_DMA_Write_Buff((uint8_t *)&DevLVinputInfo,sizeof(NOR_LVINPUT_INFO),dev_addr+Dev_Privately);
}

/*楼下简易测试功能函数 */
void Device_INCH6_Scan_Signal(uint32_t devaddr)
{
	uint8_t temp_type = 0,temp_deal = 0;
	uint16_t temp = 0,temp1 = 0;
	uint8_t crc_val = 0;
//	uint32_t deal_addr = 0;
	
	temp = SRAM_Read_Byte(devaddr + Dev_Addr);
	
	if((temp == 0x0F) || (temp == 0x00))	temp_deal = 0x01;		//该测试主要针对于地址0x0F 的INCH6设备
	
	if(temp_deal == 0x00)	return ;
	
	NOR_LVINPUT_INFO 	DevLVinputInfo;
	SRAM_DMA_Read_Buff((uint8_t *)&DevLVinputInfo,sizeof(NOR_LVINPUT_INFO),devaddr+Dev_Privately);
	
	
	
	for(uint8_t i=0;i<DI_CH_MAX;i++)
	{
		temp_type = DevLVinputInfo.DI_Type[i] & 0x0F;
		switch(temp_type)
		{
			case INCH6_DI_Key_Type:
				if(DevLVinputInfo.DI_Start[i] != 0x00)
				{
					DevLVinputInfo.DI_Start[i] = 0x00;
					temp1++;
					
					Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6_DI_Key_Type Change\r\n");
					

				}
								
				break;
			case INCH6_DI_Pir_Type:
				if(DevLVinputInfo.DI_Start[i] != DevLVinputInfo.DI_LastStart[i])
				{
					DevLVinputInfo.DI_LastStart[i] = DevLVinputInfo.DI_Start[i];
					temp1++;
					
					Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6_DI_Pir_Type Change\r\n");
					

				}
				break;
			case INCH6_DI_Dry_Type:
				if(DevLVinputInfo.DI_Start[i] != DevLVinputInfo.DI_LastStart[i])
				{
					DevLVinputInfo.DI_LastStart[i] = DevLVinputInfo.DI_Start[i];
					temp1++;
					
					Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6_DI_Dry_Type Change\r\n");
					
				}
				break;
		}
	}
	
	
	if(temp1 != 0x00)
	{
		/*将数据保存进入SRAM中*/
		SRAM_DMA_Write_Buff((uint8_t *)&DevLVinputInfo,sizeof(NOR_LVINPUT_INFO),devaddr+Dev_Privately);
		
		/*计算校验值*/
		SRAM_Write_Byte(0x00,devaddr+Dev_Check);
		temp = sizeof(NOR_LVINPUT_INFO) + Dev_Privately;
		crc_val = Dev_CheckSum(devaddr,temp);
		SRAM_Write_Byte(crc_val,devaddr+Dev_Check);		//校验值重新写入
	}
}

/*******************************************************************************
* Function Name  : INCH6_Test_Task 
* Description    : IN_CH6测试函数
* Input          : 
* Return         : 
*******************************************************************************/
void INCH6_Test_Task(void)
{
	static uint32_t test_tick = 0;
	uint32_t dev_addr = 0;
	
	if(SysTick_1ms - test_tick > 3000) 
	{
		test_tick = SysTick_1ms;
		Dbg_Print(DBG_BIT_DEVICE_STATUS_bit,"INCH6_Test_Task\r\n");
		
		dev_addr = Find_Device_List_Information(DEV_IN_CH6_Type,0x02);
		
		BLV_485_INCH6_Query_State(dev_addr);
	}
}



#endif








