
/*Fuction: 处理电子铅封流程（装油、卸油、施封、破封、屏上显示等）*/
#include "Elec_Seal.h"
#include "TerminalSlave485.h"
#include "CollectMaster485.h"
#include "KeySlave485.h"
#include "Dwin.h"
#include <math.h>
#include "tim.h"
#include "spi.h"

//李伟增加宏定义   20210227   李伟修改

Full_Oil_Info_TypeDef Full_Oil_allinfo;

uint8_t Send_data_nu = 0;//发送命令编号  0表示空白  1表示实时状态发送  2表示询问装油、卸油信息  3表示切换窗口
uint8_t Auto_unload_clear_info_flag = 0,Auto_unload_clear_start_flag = 0;//清除空仓破封信息标志  开始清除标志
uint8_t FUll_to_Oil_time =0;//
uint8_t SealedOK_backup =0;//解封时备份施封信息
uint8_t Full_oil_flag =0;//允许装油标注
uint8_t Dislpay_flag =0;//装油动画只显示一次
uint8_t Star_fulloil_flag =0;//1 开始装油 2等待关闭所有阀门  3装油完成 进行施封  4.等待打开所有阀门
uint8_t Fill_Oil_fish_ID = 0,Fill_Oil_Nfish_ID = 0;
uint32_t PID=0;

extern uint8_t flag_En_BlankSeal;//1=允许空仓施封  0=禁止空仓施封
extern uint8_t (*ptrIO_EachCang)[64];
extern uint8_t  Cang01_IO[64];
extern uint8_t  Cang02_IO[64];
extern uint8_t  Cang03_IO[64];
extern uint8_t  Cang04_IO[64];	
extern uint8_t  Cang05_IO[64];
extern uint8_t  Cang06_IO[64];
extern uint8_t  Cang07_IO[64];
extern uint8_t  Cang08_IO[64];	
//装油逻辑开始处理
void Fill_Oil( void)//装油
{
	//全自动装油
	if((Full_Oil_allinfo.Start_Full_flag ==1)&&(Full_Oil_allinfo.Start_Decrease_flag ==0))//开始装油
	{
		//2.检查打开的阀门确认上装和下装
		int i =0;
							//没有操作仓需要显示空仓  Full_oil_flag
		for(i= 0;i<StoreNumber;i++)//注意对特殊仓没有做处理
		{
					//((Full_Oil_allinfo.Null_ID&(0x01<<i))==(0x01<<i))||(FUll_to_Oil_time ==0)
			if(((IO_Date.IO_unload_switch&(0x01<<i))!=(0x01<<i)))//找到空仓  或短时进油可以装油||(FUll_to_Oil_time ==0)
//		  if(((Full_Oil_allinfo.Break_sealing_Id&(0x01<<i))!=(0x01<<i))&&((Full_Oil_allinfo.Auto_sealedOK_ID&(0x01<<i))!=(0x01<<i))) //没有施封或者没有破封就可以进行装油
			{
					if(((IO_Date.IO_state[0]&(0x0c<<(i*4)))==(0x0c<<(i*4)))\
							&&((IO_Date.IO_normalstate[0]&(0x0c<<(i*4)))==0))//底阀和卸油阀同时打开 且没有异常 为下装  下装优先
					{
						Full_Oil_allinfo.Real_operation_ID |= (0x01<<i);
						if((Full_Oil_allinfo.Real_operation_ID&(0x01<<i))!=(Full_Oil_allinfo.Loading_Oil_state&(0x01<<i)))
						{
							Full_Oil_allinfo.Full_Oil_Mode = 0x00; //装油仓提前打开了阀门
							Full_Oil_allinfo.Loading_Oil_state |= (0x01<<i);								
							Jump_page_id(Run_mode_key_info.Full_oil_id);//进入装油界面
							FULL_oil_draw(Full_Oil_allinfo.Full_Oil_Mode,Full_Oil_allinfo.Loading_Oil_state);//显示装油动画
							Star_fulloil_flag  = 1;
						}
					}
					else if(((IO_Date.IO_state[0]&(0x03<<(i*4)))==(0x03<<(i*4)))\
							   &&((IO_Date.IO_normalstate[0]&(0x03<<(i*4)))==0))//人孔盖和人空小盖同时打开且没有异常 为上装
					{
						Full_Oil_allinfo.Real_operation_ID |= (0x01<<i);
						if((Full_Oil_allinfo.Real_operation_ID&(0x01<<i))!=(Full_Oil_allinfo.Loading_Oil_state&(0x01<<i)))
						{
							Full_Oil_allinfo.Full_Oil_Mode = 0x01;//装油仓提前打开了阀门
							Star_fulloil_flag  = 1;
							Full_Oil_allinfo.Loading_Oil_state |= (0x01<<i);
							FULL_oil_draw(Full_Oil_allinfo.Full_Oil_Mode,Full_Oil_allinfo.Loading_Oil_state);//5											
						}
					}
			}
		}
		if(Full_Oil_allinfo.Real_operation_ID ==0)
		{
			if((Full_Oil_allinfo.Start_Seal_flag ==1)||(PID>0))//防止被人提前按了施封//防止被人提前按了施封
			{
				PID = 0;
				Full_Oil_allinfo.Start_Seal_flag =0;
				Full_Oil_allinfo.Start_Full_flag =0;
				Go_homepage();
			}
		}
		if(Star_fulloil_flag == 1)//开始装油
		{
			int i =0;
			for(i= 0;i<StoreNumber;i++)
			{
				if((Full_Oil_allinfo.Loading_Oil_state&(0x01<<i))== (0x01<<i))//仓
				{
					if(Full_Oil_allinfo.Full_Oil_Mode ==0)//下装
					{
						if(((IO_Date.IO_state[0])&(0x0c<<(i*4)))!=(0x0c<<(i*4)))
						{
//							Star_fulloil_flag = 2;//装油结束跳出
							Full_Oil_allinfo.Read_NULL_ID  |= (0x01<<i);//开始判断对应仓是否有油
							Full_Oil_allinfo.Loading_Oil_state  &=~(1<<i);
							FULL_oil_draw(Full_Oil_allinfo.Full_Oil_Mode,Full_Oil_allinfo.Loading_Oil_state);//5
						}
					}
					else//上装
					{
						if(((IO_Date.IO_state[0])&(0x03<<(i*4)))!=(0x03<<(i*4)))
						{
//							Star_fulloil_flag = 2;//装油结束跳出
							Full_Oil_allinfo.Read_NULL_ID  |= (0x01<<i);//开始判断对应仓是否有油
							Full_Oil_allinfo.Loading_Oil_state &=~(1<<i);
							FULL_oil_draw(Full_Oil_allinfo.Full_Oil_Mode,Full_Oil_allinfo.Loading_Oil_state);//5						
						}
					}
				}
			}
			if(Full_Oil_allinfo.Loading_Oil_state ==0)
			{
				Star_fulloil_flag =2;
			}
		}
		if(Star_fulloil_flag == 2)
		{
			int  i = 0;
			for(i= 0;i<StoreNumber;i++)
			{
				if((Full_Oil_allinfo.Real_operation_ID&(0x01<<i)))
				{
					if(((~IO_Date.IO_state[0])&(0x0f<<(i*4)))==(0x0f<<(i*4)))//底阀和卸油阀、人孔盖和人孔小盖同时全关 且没有异常
						{
							if((IO_Date.IO_normalstate[0]&(0x0f<<(i*4)))==0) //传感器是否异常
								Fill_Oil_fish_ID |=0x01<<i;
							else
							{
								Fill_Oil_Nfish_ID |=0x01<<i;
							}	
						}
				}
			}
			if(((Fill_Oil_fish_ID &Full_Oil_allinfo.Real_operation_ID )\
					|(Fill_Oil_Nfish_ID&Full_Oil_allinfo.Real_operation_ID))\
					==Full_Oil_allinfo.Real_operation_ID)
			{
				Star_fulloil_flag = 3;
			}
		}
		
		
		
			//装油完成，装油仓的所有阀门关闭，自动施封仓号   ****************************************************??????????????????
		if(Star_fulloil_flag ==3)
		{
						//				//自动需要换手动
			if((Full_Oil_allinfo.Start_Seal_flag ==1)||(PID>0))//手动施封
			{	
				if((IO_Date.IO_unload_switch&Full_Oil_allinfo.Real_operation_ID)>0)//==Full_Oil_allinfo.Real_operation_ID) 只要操作了有油就可以施封
				//	if(1)//20210104 李伟更改   只要按下F2按键，不管有没有油均可以施封(根据周例会同童赟、张毅的讨论结果，龚经理拍板：按下F2键，强制阀门关闭状态下可以施封，不管有没有油，不管二合一传感器)
			
				{
					Full_Oil_allinfo.Read_NULL_ID |= IO_Date.IO_unload_switch&Full_Oil_allinfo.Real_operation_ID;
/*					AT24CXX_WriteOneByte(2032,Full_Oil_allinfo.Read_NULL_ID);//保存信息，用于开机是否检查对应的仓是否有油*/
					Full_Oil_allinfo.Auto_sealedOK_ID |= Fill_Oil_fish_ID&IO_Date.IO_unload_switch;
					if(SealedOK_backup>0)
					{
						Full_Oil_allinfo.Auto_sealedOK_ID |=SealedOK_backup;
					}
					Full_Oil_allinfo.Auto_sealedNOK_ID |=Fill_Oil_Nfish_ID;
	//							Full_Oil_allinfo.Break_sealing_Id = 0;
					Full_Oil_allinfo.Start_Full_flag =0;
					Full_Oil_allinfo.Start_Seal_flag = 0;//
					Sealing_Data.Sealing_up_datetype = 2;//上报报平台，进行施封 
					Full_Oil_allinfo.Auto_Write_history_flag =1;//写入历史数据
					Full_Oil_allinfo.Save_flag =1;//保存到EEPROM
					//发送标志
					Dislpay_flag =0;
					Star_fulloil_flag = 0;
					Fill_Oil_Nfish_ID =0;
					Fill_Oil_fish_ID = 0;
					Full_Oil_allinfo.Real_operation_ID = 0;
					FUll_to_Oil_time =2;
					Go_homepage();							
				}
				else//没有油进行施封，或者操作仓不匹配，施封掉有油的，没有的不施封
				{
					//Full_Oil_allinfo.Read_NULL_ID &= (IO_Date.IO_unload_switch);
					Full_Oil_allinfo.Null_ID &= ~(IO_Date.IO_unload_switch&Full_Oil_allinfo.Real_operation_ID);
					Full_Oil_allinfo.Read_NULL_ID = ~Full_Oil_allinfo.Null_ID;
/*					AT24CXX_WriteOneByte(2032,Full_Oil_allinfo.Read_NULL_ID);//保存信息，用于开机是否检查对应的仓是否有油*/
					
					Full_Oil_allinfo.Start_Full_flag =0;
					Full_Oil_allinfo.Start_Seal_flag = 0;//
					Dislpay_flag =0;
					Star_fulloil_flag = 0;
					Fill_Oil_Nfish_ID =0;
					Fill_Oil_fish_ID = 0;
					Full_Oil_allinfo.Real_operation_ID = 0;
					Go_homepage();								
				}
				PID = 0;
				Full_oil_flag =0;
				Full_Oil_allinfo.Auto_full_oil_mode =0;
				//FM25L16B_WriteByte(100,Full_Oil_allinfo.Auto_sealedOK_ID);//保存施封状态20200423
				FM25L16B_WriteByte(ADDR_Auto_sealedOK_ID,Full_Oil_allinfo.Auto_sealedOK_ID);//保存施封状态20200423
				
			}
			else
			{
				if((IO_Date.IO_unload_switch&Full_Oil_allinfo.Real_operation_ID)==0)//没装进去油
				{
//								Full_Oil_allinfo.Null_ID &= ~(IO_Date.IO_unload_switch&Full_Oil_allinfo.Real_operation_ID);
//								Full_Oil_allinfo.Read_NULL_ID = ~Full_Oil_allinfo.Null_ID;
//								AT24CXX_WriteOneByte(2032,Full_Oil_allinfo.Read_NULL_ID);//保存信息，用于开机是否检查对应的仓是否有油
								
					Full_Oil_allinfo.Start_Full_flag =0;
					Full_Oil_allinfo.Start_Seal_flag = 0;//
					Dislpay_flag =0;
					Star_fulloil_flag = 0;
					Fill_Oil_Nfish_ID =0;
					Fill_Oil_fish_ID = 0;
					Full_Oil_allinfo.Real_operation_ID = 0;
					Full_Oil_allinfo.Auto_full_oil_mode = 0;
				}
			}
		}		
	}
	
	/*骏鹏要求有油就可以施封，不需要施封流程*/
	//if(Full_Oil_allinfo.Start_Seal_flag ==1)//保存施封状态20200604
	{
	//	Star_fulloil_flag=3;
#if 0
//		if ((Config_info_all.Config_fun_id&0x08) == 0x08) //?? 李工让苏祥临时做的修改，只要有油就可施封。4-5  ，note by Daiyf at 2021-4-12.
//		{//==0x08对应于bit3-----可以重复施封
			uint8_t j = 0;
			for(j = 0;j < StoreNumber;j ++)
			{

				switch (j)
				{
				case 0:
					ptrIO_EachCang = &Cang01_IO;
					break;
				case 1:
					ptrIO_EachCang = &Cang02_IO;
					break;
				case 2:
					ptrIO_EachCang = &Cang03_IO;
					break;
				case 3:
					ptrIO_EachCang = &Cang04_IO;
					break;

				case 4:
					ptrIO_EachCang = &Cang05_IO;
					break;
				case 5:
					ptrIO_EachCang = &Cang06_IO;
					break;
				case 6:
					ptrIO_EachCang = &Cang07_IO;
					break;
				case 7:
					ptrIO_EachCang = &Cang08_IO;
					break;

				default:
					ptrIO_EachCang = &Cang01_IO;
					break;
				}

				if(((Full_Oil_allinfo.Break_sealing_Id&(1<<j))!=(1<<j)))//如果该仓不是施封状态？？？？？待核实
				{//如果该仓不是施封状态？？？？？待核实
					if(((~IO_Date.IO_state[0])&(0x0f<<(j*4)))==(0x0f<<(j*4))) //4个bit代表的阀门状态均为1
					{
						
						
						if(flag_En_BlankSeal==0x01)
						{//允许空仓施封
								if(((IO_Date.IO_unload_switch&(0x01<<j))==(0x01<<j))  || (flag_En_BlankSeal==1))//该仓的卸尽传感器状态   卸尽开关监测 有油=1，无油=0
								{    //如果该仓有油则允许施封----开始
									Full_Oil_allinfo.Auto_sealedOK_ID |= (0x01<<j);  //施封对应的仓位
									Full_Oil_allinfo.Start_Seal_flag = 0;
									Sealing_Data.Sealing_up_datetype = 2;//上报报平台，进行施封 
									FM25L16B_WriteByte(ADDR_Auto_sealedOK_ID,Full_Oil_allinfo.Auto_sealedOK_ID);//保存施封状态20200604
								} //如果该仓有油则允许施封----结束
								else 
									Full_Oil_allinfo.Start_Seal_flag = 0;									
							
						
						}//允许空仓施封
						else
						{//不允许空仓施封
							
							//if(*ptrIO_EachCang+18==0x00)
							{//专门针对人孔盖
							
								if(((IO_Date.IO_unload_switch&(0x01<<j))==(0x01<<j)))//该仓的卸尽传感器状态   卸尽开关监测 有油=1，无油=0
								{    //如果该仓有油则允许施封----开始
									Full_Oil_allinfo.Auto_sealedOK_ID |= (0x01<<j);  //施封对应的仓位
									Full_Oil_allinfo.Start_Seal_flag = 0;
									Sealing_Data.Sealing_up_datetype = 2;//上报报平台，进行施封 
									FM25L16B_WriteByte(ADDR_Auto_sealedOK_ID,Full_Oil_allinfo.Auto_sealedOK_ID);//保存施封状态20200604
								} //如果该仓有油则允许施封----结束
								else 
									Full_Oil_allinfo.Start_Seal_flag = 0;								
							
							}
								
						
						}//不允许空仓施封
		 				
						
					}
					else 
						Full_Oil_allinfo.Start_Seal_flag = 0;
				}//如果该仓不是施封状态？？？？？待核实
				else 
					
					Full_Oil_allinfo.Start_Seal_flag = 0;
				  
			}
		//}
#endif
	}
	
}
uint8_t Finish_Decreaceoil_flag = 0;
//u8 Pro_unload_id = 0;//上一次卸油的仓号
uint8_t Off_loading_mark = 0;//卸油的仓号
uint8_t Star_Decreaceoil_flag =0;// 1 开始卸油 2等待打开所有阀门  4卸油完成 进行跳转  3.等待关闭所有阀门
//卸油
void Offloading_Oil( void)//卸油
{
//	u16 temp_Null =0;
	uint8_t i = 0;
	//新的卸油方式，去掉触摸操作Full_oil_flag
	//不是空仓
	if(Full_Oil_allinfo.Start_Full_flag ==0)//没有装油&&(FUll_to_Oil_time==2)
	{
		for(i= 0;i<StoreNumber;i++)//循环
		{
			//1.判断是否有油
			if(((IO_Date.IO_unload_switch&(1<<i))==(1<<i))&&((Full_Oil_allinfo.Break_sealing_Id&(1<<i))==(1<<i)))//有油&破封
			{
			//2.判断是否在卸油
					//3.查找打开的阀门
				if((IO_Date.IO_state[0]&(0x0c<<(i*4)))==(0x0c<<(i*4)))//底阀打开
				{
						//4.记录卸油的仓号
					Full_Oil_allinfo.Real_operation_ID |= 1<<i;//卸油的仓号
					Full_Oil_allinfo.Start_Decrease_flag |= 1<<i;//卸油的仓号
						//Off_loading_mark
					if(Off_loading_mark!=Full_Oil_allinfo.Start_Decrease_flag)
						//if((Full_Oil_allinfo.Real_operation_ID&Full_Oil_allinfo.Start_Decrease_flag)==0)
					{
						Off_loading_mark = Full_Oil_allinfo.Start_Decrease_flag;
						Jump_page_id(Run_mode_key_info.offLoading_oil_id);//进入卸油界面
						Off_loading_draw(Full_Oil_allinfo.Start_Decrease_flag);//5
						Star_Decreaceoil_flag =1;//开始卸油
							//7.判断本仓是否破封或者施封，上报给平台
						if(((Full_Oil_allinfo.Auto_sealedOK_ID &(0x01<<i))==(0x01<<i))||(Full_Oil_allinfo.Break_sealing_Id&(0x01<<i))==(0x01<<i))//有破封或者施封进行上报
						{
	//							Sealing_Data.Sealing_up_datetype = 1;//开始解封，上报
						}
						else//没有破封和施封
						{
							//不处理
						}
					}
				}
			}
		}
		
		
		if(Star_Decreaceoil_flag ==1)//开始卸油
		{
			for(i= 0;i<StoreNumber;i++)
			{
				if((Full_Oil_allinfo.Start_Decrease_flag&(0x01<<i))== (0x01<<i))//仓
				{
					if((((IO_Date.IO_state[0])&(0x0c<<(i*4)))!=(0x0c<<(i*4)))||((IO_Date.IO_unload_switch&(1<<i))==(0<<i)))//底阀卸油阀有一个关闭了
					{
						Full_Oil_allinfo.Start_Decrease_flag  &=~(1<<i);
						Off_loading_draw(Full_Oil_allinfo.Start_Decrease_flag);//5				
					}
				}
			}
			if(Full_Oil_allinfo.Start_Decrease_flag ==0)//没有卸完关闭阀门或者卸尽 
			{
				Off_loading_mark =0;
				Star_Decreaceoil_flag =2;
			}
		}

		
		if(Star_Decreaceoil_flag == 2)
		{
			for(i= 0;i<StoreNumber;i++)
			{
				if((Full_Oil_allinfo.Real_operation_ID&(1<<i))==(1<<i))
				{
					Full_Oil_allinfo.Real_operation_ID &=~(1<<i);
					Star_Decreaceoil_flag = 0;					
					if((IO_Date.IO_unload_switch&(1<<i))==(0<<i))//本仓没有油了
					{
						Full_Oil_allinfo.Auto_Sealing_state =0;//解封状态 
						Full_Oil_allinfo.Break_sealing_Id &=~(0x01<<i);//Full_Oil_allinfo.Real_operation_ID;//破封的仓清除
						Full_Oil_allinfo.Auto_sealedOK_ID &=~(0x01<<i);//施封信息清零
						Full_Oil_allinfo.Auto_sealedNOK_ID &=~(0x01<<i);
						Full_Oil_allinfo.Null_ID |=(0x01<<i);//置空仓
						Full_Oil_allinfo.Read_NULL_ID &=~(0x01<<i);//不在读取本仓是否有油
/*						AT24CXX_WriteOneByte(2032,Full_Oil_allinfo.Read_NULL_ID);//保存标志*/
						
						FM25L16B_WriteByte(ADDR_Break_sealing_Id,(uint8_t)Full_Oil_allinfo.Break_sealing_Id);//保存破封状态20200423
					}
				}
			}
			if(Full_Oil_allinfo.Real_operation_ID ==0)
			{
				Full_Oil_allinfo.Start_Decrease_flag = 0;
				Jump_page_id(Run_mode_key_info.Main_Page_id);//进入主界面//5				
			}
		}		
	}	
}
//上报解封码，等待解封成功

void Un_sealing_loading(void)
{
	uint8_t i =0;
	//指纹解封
	if((PID>0)&&(Full_Oil_allinfo.Start_Full_flag!=1))//检测到指纹
	{
		if(Full_Oil_allinfo.Auto_sealedOK_ID>0)//1 1 1
		{
			if(SealedOK_backup ==0)
			{
				SealedOK_backup = Full_Oil_allinfo.Auto_sealedOK_ID;//备份施封仓
				//去掉施封的锁			
				Full_Oil_allinfo.Auto_sealedOK_ID = 0;
			}
		}
		PID =0;
	}
	if(SealedOK_backup>0)
	{
		for(i= 0;i<StoreNumber;i++)
		{
			if((SealedOK_backup&(0x01<<i)))//找到施封的仓
			{
					//监测打开的阀门
				if(((IO_Date.IO_state[0])&(0x0f<<(i*4)))!=(0x00<<(i*4)))//有一个打开
				{
					SealedOK_backup&=~(0x01<<i);//去掉施封
					Sealing_Data.Sealing_up_datetype = 1;
				}
			}
		}
	}
			//监测打开的阀门			
			//没有打开的阀门的仓自动施封（10分钟）
	if(Full_Oil_allinfo.finger_mark_time ==1)
	{
		Full_Oil_allinfo.finger_mark_time =0;
		//自动施封
		Full_Oil_allinfo.Auto_sealedOK_ID |=  SealedOK_backup ;
		SealedOK_backup = 0;		
	}
}

//破封
uint8_t Break_seal_cnt_10[8]={0};//破封次数
#include<string.h>
#include "FreeRTOS.h"
#include "task.h"
void Break_Seal(void)
{
	if(Full_Oil_allinfo.Auto_sealedOK_ID>0)//有施封的仓
	{
		int i =0;
		for(i= 0;i<StoreNumber;i++)
		{//所有仓位依次遍历--开始
			if((Full_Oil_allinfo.Auto_sealedOK_ID&(0x01<<i)))//找到施封的仓
			{//找到施封的仓----如果该仓位是施封状态----开始
				if(((~IO_Date.IO_state[0])&(0x0f<<(i*4)))==(0x0f<<(i*4)))//底阀和卸油阀、人孔盖和人孔小盖同时全关 
				{/////////////阀门均为关闭状态；但是异常状态事件使得破封条件成立----开始

					if ((IO_Date.IO_normalstate[0] & (0x0f << (i * 4))) != 0) //人孔小盖、人孔盖、卸油阀、底阀有一个有异常
					{

						if ((Full_Oil_allinfo.Break_sealing_Id & (0x01 << i)) != (0x01 << i)) //破封报警 -------如果该仓位非破封状态 即破封bit=0
						{																	  //满足破封条件则破封bit置1 -------如果该仓位非破封状态 即破封bit=0------开始
																							  //								Full_Oil_allinfo.Break_sealing_taiId = i+1;
							Break_seal_cnt_10[i]++;
							if (Break_seal_cnt_10[i] >= TIME_OF_Break_seal_cnt) //???原来设了30，造成实际破封延时有约8S，引起客户投诉，现在改为7,约1.8S； By Daiyf at 2021-02-03.
							{													////门限次数判定算法---早期的传感器算法不稳定，多次连续破封才判定为破封------开始
								Full_Oil_allinfo.Break_sealing_Id |= 0x01 << i; //破仓报警   表示破封的仓号     将破封的对应bit置1
								IO_Date.Temp_IO_state[0] = IO_Date.IO_state[0];//破封原因
								IO_Date.Temp_IO_normalstate[0] = IO_Date.IO_normalstate[0];
								Sealing_Data.Sealing_up_datetype = 3;			//通知平台
								Full_Oil_allinfo.Auto_sealedOK_ID &= ~(0x01 << i);
								Sealing_Data.Sealing_up_datetype = 3; //通知平台

								//								Full_Oil_allinfo.Car_state =1;//车辆状态NOK
								Full_Oil_allinfo.Auto_Write_history_flag = 1;	//做记录
								Full_Oil_allinfo.Auto_Write_history_ID = i + 1; //仓号
								Full_Oil_allinfo.Save_flag = 1;					//保存到EEPROM
								flag_Seal_Break = 1;							//破封声音控制
								Break_seal_cnt_10[i] = 0;
								Send_alarm10S();   //破封报警发送
								HAL_Delay(10 * 2); //阻塞时间
								////李伟添加  20211027 破封时保存当前的破封信息
								memcpy(ValStateArr_PoFeng_0x13, ValStateArr_0x13, 64);
								memcpy(ValStateArr_PoFeng_0x20, ValStateArr_0x20, 64);

								//KeySlave485_Send_Data((uint8_t *)ValStateArr_0x13, 64);
								TerminalSlave485_Send_Data((uint8_t *)ValStateArr_0x13,64);
								//								  memset(PrintBuff,0,sizeof(PrintBuff));
//								HAL_GPIO_TogglePin(GPIOC, DWI_Pin); //看门狗sp706

								//__NOP();
								//HAL_Delay(10 * 2); //阻塞时间

								//KeySlave485_Send_Data((uint8_t *)ValStateArr_0x13, 64);
								//memset(PrintBuff,0,sizeof(PrintBuff));
//								HAL_GPIO_TogglePin(GPIOC, DWI_Pin); //看门狗sp706

								//__NOP();
								//HAL_Delay(10 * 2); //阻塞时间

								//KeySlave485_Send_Data((uint8_t *)ValStateArr_0x20, 64);
								TerminalSlave485_Send_Data((uint8_t *)ValStateArr_0x20, 64);
//								HAL_GPIO_TogglePin(GPIOC, DWI_Pin); //看门狗sp706

								Full_Oil_allinfo.Auto_sealedOK_ID &= ~(1 << i);										   //破封后清除施封信息   将施封的对应bit置0
								FM25L16B_WriteByte(ADDR_Auto_sealedOK_ID, Full_Oil_allinfo.Auto_sealedOK_ID);		   //保存施封状态20200423
								FM25L16B_WriteByte(ADDR_Break_sealing_Id, (uint8_t)Full_Oil_allinfo.Break_sealing_Id); //保存破封状态20200423
							}																						   ////门限次数判定算法---早期的传感器算法不稳定，多次连续破封才判定为破封------结束
						}																							   //满足破封条件则破封bit置1 -------如果该仓位非破封状态 即破封bit=0------结束
					}
					else
					{
						Break_seal_cnt_10[i]=0;
					}
				}/////////////阀门均为关闭状态；但是异常状态事件使得破封条件成立----开始
				else//施封仓有一个阀门被打开了，破封报警
				{/////////////任何一个阀门由关闭变为打开的状态导致状态由破封变为施封-----开始
					// debug_point_01:  setup by Daiyf
					if(((Full_Oil_allinfo.Break_sealing_Id&(1<<i))!=(1<<i))&&(PID==0))//????????????????????PID
					{//-------如果该仓为非破封状态 即破封bit=0----开始
//								Full_Oil_allinfo.Car_state =1;//车辆状态NOK
						
						HAL_GPIO_TogglePin(GPIOE,LED5_Pin);  // 有破风信息，LED5闪亮提示。  By Daiyf at 2021-02-03.

						Break_seal_cnt_10[i]++;
						//???原来设了30，造成实际破封延时有约8S，引起客户投诉，现在改为7,约1.8S； By Daiyf at 2021-02-03.
						if(Break_seal_cnt_10[i]>=TIME_OF_Break_seal_cnt)  //20210608经龚经理，童赟，讨论后由7次变更为2次--因为二合一传感器已经做了滤波    李伟修改
						{  
							
							//taskENTER_CRITICAL();
							IO_Date.Temp_IO_state[0] = IO_Date.IO_state[0];//破封原因
							IO_Date.Temp_IO_normalstate[0] = IO_Date.IO_normalstate[0];
							IO_Date.Updata_TempVar[i] = 1;
							Full_Oil_allinfo.Break_sealing_Id |=0x01<<i;//破仓报警
							Full_Oil_allinfo.Auto_sealedOK_ID &=~(0x01<<i);
							Sealing_Data.Sealing_up_datetype = 3;//通知平台
							Full_Oil_allinfo.Auto_Write_history_flag = 1;
							Full_Oil_allinfo.Auto_Write_history_ID = i+1;//仓号
							Full_Oil_allinfo.Save_flag =1;//保存到EEPROM
							flag_Seal_Break =1;//破封声音控制
							Break_seal_cnt_10[i]=0;
							
							Send_alarm10S();//破封报警发送	
							HAL_Delay(10*2);//阻塞时间
//							//李伟添加  20211027 破封时保存当前的破封信息
							memcpy(ValStateArr_PoFeng_0x13,ValStateArr_0x13,64);
							memcpy(ValStateArr_PoFeng_0x20_Cang01,ValStateArr_0x20_Cang01,64);
							memcpy(ValStateArr_PoFeng_0x20_Cang02,ValStateArr_0x20_Cang02,64);
							
							
							//KeySlave485_Send_Data((uint8_t *)ValStateArr_0x13,64);
							TerminalSlave485_Send_Data((uint8_t *)ValStateArr_0x13,64);
							//								  memset(PrintBuff,0,sizeof(PrintBuff));
//							HAL_GPIO_TogglePin(GPIOC, DWI_Pin);//看门狗sp706

							__NOP();
							HAL_Delay(10*1);//阻塞时间
							
							
							
							//KeySlave485_Send_Data((uint8_t *)ValStateArr_0x13,64);
							TerminalSlave485_Send_Data((uint8_t *)ValStateArr_0x13,64);
							//								  memset(PrintBuff,0,sizeof(PrintBuff));
//							HAL_GPIO_TogglePin(GPIOC, DWI_Pin);//看门狗sp706

							__NOP();
							HAL_Delay(10*1);//阻塞时间
							
							//KeySlave485_Send_Data((uint8_t *)ValStateArr_0x20_Cang01,64);
							TerminalSlave485_Send_Data((uint8_t *)ValStateArr_0x20_Cang01,64);
//							HAL_GPIO_TogglePin(GPIOC, DWI_Pin);//看门狗sp706
							
							
							HAL_Delay(10*1);//阻塞时间
							
							//KeySlave485_Send_Data((uint8_t *)ValStateArr_0x20_Cang02,64);
							TerminalSlave485_Send_Data((uint8_t *)ValStateArr_0x20_Cang02,64);
//							HAL_GPIO_TogglePin(GPIOC, DWI_Pin);//看门狗sp706
							
							HAL_Delay(10*1);//阻塞时间
							
							//KeySlave485_Send_Data((uint8_t *)Array_Of_IO_0xA1,64);
							TerminalSlave485_Send_Data((uint8_t *)Array_Of_IO_0xA1,64);
//							HAL_GPIO_TogglePin(GPIOC, DWI_Pin);//看门狗sp706							
							
							
							//taskEXIT_CRITICAL();
									
									
							
							Full_Oil_allinfo.Auto_sealedOK_ID &=~(1<<i);//施封清除破封信息
							FM25L16B_WriteByte(ADDR_Auto_sealedOK_ID,Full_Oil_allinfo.Auto_sealedOK_ID);//保存施封状态20200423
							FM25L16B_WriteByte(ADDR_Break_sealing_Id,(uint8_t)Full_Oil_allinfo.Break_sealing_Id);//保存施封状态20200423
							HAL_GPIO_WritePin(GPIOE, LED5_Pin, GPIO_PIN_RESET);   // 破风信息成立，LED5长亮。  By Daiyf at 2021-02-03.
						}
						//做记录
					}//-------如果该仓为非破封状态 即破封bit=0----开始
					else
					{
						
						if(PID>0)//??????????????????????????????????????????????????PID
						{
							PID=0;
							Full_Oil_allinfo.Auto_sealedOK_ID &=~(0x01<<i);
							Sealing_Data.Sealing_up_datetype = 1;//通知平台
							Full_Oil_allinfo.Auto_Write_history_flag = 1;
							
						}
						Break_seal_cnt_10[i]=0;
					}
				}/////////////任何一个阀门由关闭变为打开的状态导致状态由破封变为施封-----结束
			}//找到施封的仓----如果该仓位是施封状态----结束
		}//所有仓位依次遍历--结束
	}
}
//卸尽检测，并去除破封信息，防止卸油时还存有底油，去除底油信息
void Auto_unload_clear_info(void)
{
	uint8_t i = 0;
	for(i = 0;i<StoreNumber;i++)
	{//for(i = 0;i<StoreNumber;i++)
		if((Full_Oil_allinfo.Null_ID&(1<<i))==(1<<i))//是空仓
		{//该仓位是空仓----开始
			if((Full_Oil_allinfo.Break_sealing_Id&(1<<i))==(1<<i))//有破封
			{//该仓位铅封状态是破封状态----开始
				if((IO_Date.IO_state[0]&(0x0c<<(i*4)))==(0x0c<<(i*4)))//底阀和卸油阀都开
				{//底阀和卸油阀都开----开始
					
					//一定需要开30S,否则会有漏洞
					if(Auto_unload_clear_start_flag == 1)//10S
					{
						Full_Oil_allinfo.Break_sealing_Id  &=~(1<<i);//空仓清除破封信息
//						Full_Oil_allinfo.Auto_sealedOK_ID &=~(1<<i);//施封清除破封信息
						Full_Oil_allinfo.Read_NULL_ID &=~(1<<i);//不在读取本仓信息
						Auto_unload_clear_start_flag = 0;
//						FM25L16B_WriteByte(ADDR_Auto_sealedOK_ID,Full_Oil_allinfo.Auto_sealedOK_ID);//保存施封状态20200423
						FM25L16B_WriteByte(ADDR_Break_sealing_Id,Full_Oil_allinfo.Break_sealing_Id);//保存施封状态20200423
					}
					else
					{
						if(Auto_unload_clear_info_flag == 0)
								Auto_unload_clear_info_flag = 1;//开始计时
					}
				}//底阀和卸油阀都开----结束
				else
				{
					if(Auto_unload_clear_start_flag == 1)//阀门没开或者开的时间不够，标志清掉
						Auto_unload_clear_start_flag = 0;
				}
			}//该仓位铅封状态是破封状态----结束
		}//该仓位是空仓----结束
	}//for(i = 0;i<StoreNumber;i++)
}
//自动监测施封所有装油仓
/*
思路：装完油，拔出静电控制器，没有脉冲，10分钟，所有的阀门关闭，则自动施封,置施封标志为1
*/
/*
void Auto_check_Seal_all(void)
{
	if((Config_info_all.Config_fun_id&0x01)==0x01)//开启自动施封功能
	{	
		if((overflow_cnt ==0)&&(Full_Oil_allinfo.Start_Full_flag ==1))
		{
			if(Start_auto_seal_flag ==1)//计时达到10分钟
			{
				Full_Oil_allinfo.Start_Seal_flag =1;//开始施封
				Start_auto_seal_flag =0;
			}
		}
	}
}
*/
//电子铅封系统处理
void Elect_cover(void)
{
	Fill_Oil();//装油检测
	Break_Seal();//破封检测
	Offloading_Oil();//卸油检测
//	Write_State_history();//历史数据记录
//	Save_elect_data();//保存数据到EEPROM
	//清除空仓破封信息
	Auto_unload_clear_info();//智能清除破封信息
	Un_sealing_loading();//智能解封
/*
	Auto_check_Seal_all();//装完后关闭所有阀门，10min后自动施封
*/		
 
//#endif
}
//车辆状态判断，0 OK，1 NOK
void Car_stateUpdate(void)
{
	uint8_t temp =0;//3 4  1 1  2 3  3 7  4 15  2^n-1
	temp = pow(2,StoreNumber)-1;
	if(((Full_Oil_allinfo.Break_sealing_Id &temp) !=0))//没有异常并且没有破封
	{
		Full_Oil_allinfo.Car_state =2;//车辆状态破封
	}
	else if(IO_Date.IO_normalstate[0] != 0)
	{
		Full_Oil_allinfo.Car_state =1;//车辆状态NOK
	}
	else
		Full_Oil_allinfo.Car_state =0;//车辆状态OK
}

void Oil_Generater(void)
{
	IO_Date.IO_unload_switch = 0;
	if (Config_info_all.Dump_info & 0x0f)
	{
		if (Collect485.UnloadState_Num1 != 0x55)
		{
			if (Collect485.UnloadState_Num1 & 1)
			{
				IO_Date.IO_unload_switch |= 1;
			}
		}
		if (Collect485.UnloadState_Num2 != 0x55)
		{
			if (Collect485.UnloadState_Num2 & 1)
			{
				IO_Date.IO_unload_switch |= 2;
			}
		}
		if (Collect485.UnloadState_Num3 != 0x55)
		{
			if (Collect485.UnloadState_Num3 & 1)
			{
				IO_Date.IO_unload_switch |= 4;
			}
		}
		if (Collect485.UnloadState_Num4 != 0x55)
		{
			if (Collect485.UnloadState_Num4 & 1)
			{
				IO_Date.IO_unload_switch |= 8;
			}
		}
		if (Collect485.UnloadState_Num5 != 0x55)
		{
			if (Collect485.UnloadState_Num5 & 1)
			{
				IO_Date.IO_unload_switch |= 0x10;
			}
		}
		if (Collect485.UnloadState_Num6 != 0x55)
		{
			if (Collect485.UnloadState_Num6 & 1)
			{
				IO_Date.IO_unload_switch |= 0x20;
			}
		}
		if (Collect485.UnloadState_Num7 != 0x55)
		{
			if (Collect485.UnloadState_Num7 & 1)
			{
				IO_Date.IO_unload_switch |= 0x40;
			}
		}
		if (Collect485.UnloadState_Num8 != 0x55)
		{
			if (Collect485.UnloadState_Num8 & 1)
			{
				IO_Date.IO_unload_switch |= 0x80;
			}
		}
	}
}

//uint8_t Temp_data_flag = 0;
//实时获取阀门状态
void Test_get_state(void)
{
	 uint8_t  i;
	 IO_Date.IO_allnum=4*StoreNumber;			//IO总数  m                               u8
	 IO_Date.IO_statenum=IO_Date.IO_allnum/32+1;	//IO状态组数   n(1~8)  n=(m/32)+1       u8
	
	  //20210227  李伟更改  同龚天平、张毅商定之后的结论
	  IO_Date.IO_allnum = 8;//4*StoreNumber;			//IO总数  m                               u8
	  IO_Date.IO_statenum = 3;//IO_Date.IO_allnum/32+1;	//IO状态组数   n(1~8)  n=(m/32)+1       u8
	
	if((IO_Date.IO_allnum/32)<1)
	{
		Oil_Generater();
		for(i=0;i<StoreNumber;i++)
		{
//			if(Sealing_Data.TerminalOnLineFlag == False)
//			{
				if(Statetemp.rkg[i]== 0x55)
				{
					int a = 1<<(i*4+1);
					IO_Date.IO_state[0]&=~a;//置0
					IO_Date.IO_normalstate[0]|=a;//置1 报异常
				}
				else
				{
					int a = 1<<(i*4+1);
					IO_Date.IO_state[0] = (IO_Date.IO_state[0]&(~a))|Statetemp.rkg[i]<<(i*4+1);		
					IO_Date.IO_normalstate[0] &=~a;//置0，取消异常
				}
				if(Statetemp.rkgx[i]== 0x55)
				{
					int a = 1<<(i*4+0);//8->4
					IO_Date.IO_state[0]&=~a;//置0c
					IO_Date.IO_normalstate[0]|=a;//置1 报异常
				}
				else
				{
					int a = 1<<(i*4+0);
	//						IO_Date.IO_state[0] &=~a;//把当前位置0
	//						IO_Date.IO_state[0] |= Statetemp.rkgx[i]<<(i*4+0);//获取当前位的值
					IO_Date.IO_state[0]	=( IO_Date.IO_state[0]&~a)|		Statetemp.rkgx[i]<<(i*4+0);
					IO_Date.IO_normalstate[0] &=~a;//置0，取消异常
				}			
				if(Statetemp.xyf[i] ==0x55)//卸油阀
				{
					int a = 1<<(i*4+2);
					IO_Date.IO_state[0]&=~a;//置0
					IO_Date.IO_normalstate[0]|=a;//置1 报异常
				}
				else
				{
					int a = 1<<(i*4+2);
					//int a=0;
	//				IO_Date.IO_state[0] &=~a;//把当前位置0
	//				IO_Date.IO_state[0] |= Statetemp.xyf[i]<<(i*4+2);//获取当前位的值
					IO_Date.IO_state[0]  = (IO_Date.IO_state[0]&(~a))|Statetemp.xyf[i]<<(i*4+2);//0<<(i*4+2);//
					IO_Date.IO_normalstate[0] &=~a;//置0，取消异常
				}
				if(Statetemp.bottm[i] ==0x55)//异常 底阀
				{
					int a = 1<<(i*4+3);
					IO_Date.IO_state[0]&=~a;//置0
					IO_Date.IO_normalstate[0]|=a;//置1 报异常
				}
				else //正常
				{
					int a = 1<<(i*4+3);
	//					IO_Date.IO_state[0] &=~a;//把当前位置0
	//					IO_Date.IO_state[0] |= Statetemp.bottm[i]<<(i*4+3);//获取当前位的值
					IO_Date.IO_state[0] = (IO_Date.IO_state[0]&(~a))|Statetemp.bottm[i]<<(i*4+3);
					IO_Date.IO_normalstate[0] &=~a;//置0，取消异常
				}
//			}
#if 0
				//获取卸尽传感器的IO状态，因为太敏感，所以除了装油和运输以为，卸完油不在监测是否还有油
			if((Config_info_all.Config_fun_id&0x10)==0x00)//默认一边有油则有油，两边无油则无油
			{
				int j = (Config_info_all.Dump_info & 0x0f) / StoreNumber;
				int mask=0,k;
				for(k=0;k<j;++k)
				{
					mask<<=1;
					mask |=1;
				}
				IO_Date.IO_unload_switch=0;
				if ((((Config_info_all.Dump_info & 0x0f) % StoreNumber) == 0) && j)
				{
					if (Collect485.UnloadState_Num1 != 0x55)
					{
						if(Collect485.UnloadState_Num1&mask)
						{
							IO_Date.IO_unload_switch |= 1;
						}
					}	
					if (Collect485.UnloadState_Num2 != 0x55)
					{
						if(Collect485.UnloadState_Num2&mask)
						{
							IO_Date.IO_unload_switch |= 2;
						}
					}
					if (Collect485.UnloadState_Num3 != 0x55)
					{
						if(Collect485.UnloadState_Num3&mask)
						{
							IO_Date.IO_unload_switch |= 4;
						}
					}
					if (Collect485.UnloadState_Num4 != 0x55)
					{
						if(Collect485.UnloadState_Num4&mask)
						{
							IO_Date.IO_unload_switch |= 8;
						}
					}
					if (Collect485.UnloadState_Num5 != 0x55)
					{
						if(Collect485.UnloadState_Num5&mask)
						{
							IO_Date.IO_unload_switch |= 0x10;
						}
					}
					if (Collect485.UnloadState_Num6 != 0x55)
					{
						if(Collect485.UnloadState_Num6&mask)
						{
							IO_Date.IO_unload_switch |= 0x20;
						}
					}
					if (Collect485.UnloadState_Num7 != 0x55)
					{
						if(Collect485.UnloadState_Num7&mask)
						{
							IO_Date.IO_unload_switch |= 0x40;
						}
					}
					if (Collect485.UnloadState_Num8 != 0x55)
					{
						if(Collect485.UnloadState_Num8&mask)
						{
							IO_Date.IO_unload_switch |= 0x80;
						}
					}
				}
			}
			else if((Config_info_all.Config_fun_id&0x10)==0x10)//一边无油则无油，两边有油则有油
			{
					int j = (Config_info_all.Dump_info & 0x0f) / StoreNumber;
					int mask=0,k;
					for(k=0;k<j;++k)
					{
						mask<<=1;
						mask |=1;
					}
					IO_Date.IO_unload_switch=0;
					if (Collect485.UnloadState_Num1 != 0x55)
					{
						if((Collect485.UnloadState_Num1&mask)==mask)
						{
							IO_Date.IO_unload_switch |= 1;
						}
					}	
					if (Collect485.UnloadState_Num2 != 0x55)
					{
						if((Collect485.UnloadState_Num2&mask)==mask)
						{
							IO_Date.IO_unload_switch |= 2;
						}
					}
					if (Collect485.UnloadState_Num3 != 0x55)
					{
						if((Collect485.UnloadState_Num3&mask)==mask)
						{
							IO_Date.IO_unload_switch |= 4;
						}
					}
					if (Collect485.UnloadState_Num4 != 0x55)
					{
						if((Collect485.UnloadState_Num4&mask)==mask)
						{
							IO_Date.IO_unload_switch |= 8;
						}
					}
					if (Collect485.UnloadState_Num5 != 0x55)
					{
						if((Collect485.UnloadState_Num5&mask)==mask)
						{
							IO_Date.IO_unload_switch |= 0x10;
						}
					}
					if (Collect485.UnloadState_Num6 != 0x55)
					{
						if((Collect485.UnloadState_Num6&mask)==mask)
						{
							IO_Date.IO_unload_switch |= 0x20;
						}
					}
					if (Collect485.UnloadState_Num7 != 0x55)
					{
						if((Collect485.UnloadState_Num7&mask)==mask)
						{
							IO_Date.IO_unload_switch |= 0x40;
						}
					}
					if (Collect485.UnloadState_Num8 != 0x55)
					{
						if((Collect485.UnloadState_Num8&mask)==mask)
						{
							IO_Date.IO_unload_switch |= 0x80;
						}
					}
			}
#endif			
/*			
			else
			{
				//new
				IO_Date.IO_Discharge_state =(IO_Date.IO_Discharge_state&(0xf0));//|((Pneumatic_newPR1<<0)|(Pneumatic_newPR2<<1)|(Pneumatic_newPR3<<2)|(Pneumatic_newPR4<<3));
				if((Config_info_all.Dump_info&0x0f)>StoreNumber)//
				{
					IO_Date.IO_unload_switch =((((IO_Date.IO_Discharge_state>>4)&0x01)|((IO_Date.IO_Discharge_state>>5)&0x01))<<0)|\
														((((IO_Date.IO_Discharge_state>>6)&0x01)|((IO_Date.IO_Discharge_state>>7)&0x01))<<1);//2个卸油阀并一个卸油阀  只有2仓车会用到的
				}
			 else
				{
					IO_Date.IO_unload_switch = IO_Date.IO_Discharge_state>>4;//高四位;
				}
			}		
*/			
			if((Full_Oil_allinfo.Break_sealing_Id&(1<<i))==(1<<i))//有破封
			{
				if(((IO_Date.IO_unload_switch&(1<<i))==(0<<i))&&((IO_Date.IO_state[0]&(0x08<<(i*4)))==(0x08<<(i*4))))//底阀打开并且没油则为无油
				{
					Full_Oil_allinfo.Null_ID |=(1<<i);
				}
				else //if((IO_Date.IO_unload_switch&(1<<i))==(1<<i))//有油则为有油
				{
					Full_Oil_allinfo.Null_ID &=~(1<<i);
				}
			}
			else
			{
				if((IO_Date.IO_unload_switch&(1<<i))==(0<<i))//&&((IO_Date.IO_state[0]&(0x08<<(i*4)))==(0x08<<(i*4))))//底阀打开并且没油则为无油1有油0无油
				{
					Full_Oil_allinfo.Null_ID |=(1<<i);
					FUll_to_Oil_time =0;
				}
				else //if((IO_Date.IO_unload_switch&(1<<i))==(1<<i))//有油则为有油  --------------------解封可能有问题-------------------------
				{
					Full_Oil_allinfo.Null_ID &=~(1<<i);
					if(FUll_to_Oil_time ==0)
					{
						FUll_to_Oil_time =1;
					}
				}
			}
			if((IO_Date.IO_unload_switch ==0)&&(Full_Oil_allinfo.Start_Decrease_flag == 0)&&(Full_Oil_allinfo.Break_sealing_Id == 0))//没有并且完成卸油了
				FUll_to_Oil_time =0;
		}
//		if(IO_Date.IO_normalstate[0] == 0)
//		{
//			IO_Date.IO_normaldata=0;   //不带异常数据
//			if(IO_Date.IO_state[0]>0)
//			{
//				if(IO_Date.Temp_IO_state[0]!=IO_Date.IO_state[0])//状态改变
//				{
//					IO_Date.Temp_IO_state[0] = IO_Date.IO_state[0];
//					Temp_data_flag = 0;
//				}
//				if(Temp_data_flag == 0)
//				{
//					IO_Date.IO_emergencyflag |=1<<7;	//开关打开  重要数据
//					Temp_data_flag = 1;
//				}
//				else
//				{
//					IO_Date.IO_emergencyflag &=~(0x80);
//				}
//			}
//		 }
	}
	Car_stateUpdate();//车辆状态判断
}
