#include "TerminalSlave485.h"
#include "TerminalSlave485_jt808.h"
#include "CollectMaster485.h"
#include "ScreenMaster485.h"
#include "KeySlave485.h"
#include "Elec_Seal.h"
#include "usart.h"	
#include <stdio.h>
#include <string.h>
#include "Data_deal.h"
#include "Randomcode.h"
#include "spi.h"
#include "Dwin.h"
#include "DS1302.h"
#include "leaf_ota.h"
#include "md5c.h"
#include "cmsis_os.h"
#include "func_queue_record.h"

/* zhuzl 20211220 增加为了内蒙定时上送*/
uint32_t circle_send;
uint8_t f3_flag=0;
const unsigned int exec_addr __attribute__((at(IR_ROM1+6144))) = IR_ROM1;
const char custurm_code[10] __attribute__((at(IR_ROM1+5120))) = "001200";						 //客户码


//zhuzl add end
////////////////////////////////////////////////////////////////////////////////// 
// uint8_t  com_name[20] = "Hangzhou   jialong";//公司名称
 uint8_t hardware_version[10]="V2.0.0";//硬件版本
//uint8_t product_code[20] ="JL-IMS-CJ-V2.0";//产品代码
// uint8_t product_ID[20] ="SIMS20210613001";//产品ID
// uint8_t custurm_code[10] ="001200";//客户码
 char Version[30];
 uint8_t Oil_Data_Reg[64];//通信参数与常规参数
 
 Data_From_Server_0x6401  Data_From_Server_0x6401_001;
 
 uni_Float flo000;
 
 extern uint8_t Array_Of_Valve[32];  // 91命令重新调整后，采集数板增加一个数组灵活处理，2021-1-30。
 
 static uint8_t  temp_buf2[64]={0};
 
static uint8_t FlagPrint =0;       // 按F4打印请求键后的标志位，!待实际应用中处理 ，2020-2-22 add in by Daiyf。
  

 //============================================================
 sT2C_RemoteCaliDat T2C_RemoteCaliDat001  =
{
 
   0x3901,
	 0x9551000,
	 0x0003,
   ADDR_Is_In_ElecFence,//0x0000,
	 0x0001,        //操作的数据个数
   0x55aa55aa,    //保留字4字节
   {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,\
	 25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44},
	 0x7788,//保留字2字节
   0x99aa   //校验2字节
};
sT2C_RemoteCaliDat *pT2C_RemoteCaliData = &T2C_RemoteCaliDat001; 


 //============================================================
 sT2C_SealByElec_Fence T2C_SealByElec_Fence001  =
{
 
   0x38,
	 0x30,
	 0x03,
   0x01,//0x0000,
	 
   {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,\
	 25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,
	 45,46,47,48,49,50,51,52,53,54,55,56}

};
sT2C_SealByElec_Fence *pT2C_SealByElec_Fence = &T2C_SealByElec_Fence001; 





 
 
 //============================================================
sT2C_SetupData T2C_SetupData[8]  =
{{
   2021,
	 1,
	 25,
   18,
	 03,
   30,
   00,
   /*****  14 val each 32 bit ***/
	   1,
   0.32243546,
	 0.0,//12301.3284, Vt
   0.0,//0.78932,  V20
	 	 5,//液位
   0,//温度
	 0,//倾角x
   0,//倾角y
	 0,//压力 9,
   0,//密度
	 0,//p1
   -0.092329,//p2
	   13,//p3
   0   //p4
},
{
   2021,
	 1,
	 25,
   18,
	 03,
   30,
   00,
   /*****  14 val each 32 bit ***/
	   1,
   0.32243546,
	 0.0,//12301.3284, Vt
   0.0,//0.78932,  V20
	 	 5,//液位
   0,//温度
	 0,//倾角x
   0,//倾角y
	 0,//压力 9,
   0,//密度
	 0,//p1
   -0.092329,//p2
	   13,//p3
   0   //p4
},
{
   2021,
	 1,
	 25,
   18,
	 03,
   30,
   00,
   /*****  14 val each 32 bit ***/
	   1,
   0.32243546,
	 0.0,//12301.3284, Vt
   0.0,//0.78932,  V20
	 	 5,//液位
   0,//温度
	 0,//倾角x
   0,//倾角y
	 0,//压力 9,
   0,//密度
	 0,//p1
   -0.092329,//p2
	   13,//p3
   0   //p4
},
{
   2021,
	 1,
	 25,
   18,
	 03,
   30,
   00,
   /*****  14 val each 32 bit ***/
	   1,
   0.32243546,
	 0.0,//12301.3284, Vt
   0.0,//0.78932,  V20
	 	 5,//液位
   0,//温度
	 0,//倾角x
   0,//倾角y
	 0,//压力 9,
   0,//密度
	 0,//p1
   -0.092329,//p2
	   13,//p3
   0   //p4
},
{
   2021,
	 1,
	 25,
   18,
	 03,
   30,
   00,
   /*****  14 val each 32 bit ***/
	   1,
   0.32243546,
	 0.0,//12301.3284, Vt
   0.0,//0.78932,  V20
	 	 5,//液位
   0,//温度
	 0,//倾角x
   0,//倾角y
	 0,//压力 9,
   0,//密度
	 0,//p1
   -0.092329,//p2
	   13,//p3
   0   //p4
},
{
   2021,
	 1,
	 25,
   18,
	 03,
   30,
   00,
   /*****  14 val each 32 bit ***/
	   1,
   0.32243546,
	 0.0,//12301.3284, Vt
   0.0,//0.78932,  V20
	 	 5,//液位
   0,//温度
	 0,//倾角x
   0,//倾角y
	 0,//压力 9,
   0,//密度
	 0,//p1
   -0.092329,//p2
	   13,//p3
   0   //p4
}
};

sT2C_SetupData *pT2C_SetupData = T2C_SetupData;


//============================================================
 sT2C_MoniLiang_Data T2C_MoniLiang_Data_Cang1to4  =
{
	{0x39,0x01,},
	{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,},
	{1,2,3,4,5,6,7,8},
	{1,2,3,4,5,6,7,8,9,10,11,
	1,2,3,4,5,6,7,8,9,10,11,
	1,2,3,4,5,6,7,8,9,10,11,
	1,2,3,4,5,6,7,8,9,10,11,},
	{0x01,0x02},
	{0x01,0x02}

};

 sT2C_MoniLiang_Data T2C_MoniLiang_Data_Cang5to8  =
{
	{0x39,0x01,},
	{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,},
	{1,2,3,4,5,6,7,8},
	{1,2,3,4,5,6,7,8,9,10,11,
	1,2,3,4,5,6,7,8,9,10,11,
	1,2,3,4,5,6,7,8,9,10,11,
	1,2,3,4,5,6,7,8,9,10,11,},
	{0x01,0x02},
	{0x01,0x02}

};

sT2C_MoniLiang_Data* pT2C_MoniLiang_Data = &T2C_MoniLiang_Data_Cang1to4;

sT2C_ALL_Sensor_Data_WholeCar T2C_ALL_Sensor_WholeCar01=
{
	{0x39,0x01,3,4,5,6,7,8,9,10,11,12,13,14,15,16},  				//帧头
	{0.1,0.2,0.3},	 	//3个倾角传感器
	0x00000001,				//电池开关状态
	91.2,	 						//电池电量
	0x00000001,				//壁挂油传感器霍尔传感器状态
	0x00000001,				//壁挂油传感器光电传感器状态
	{0x01,0x02,3,4,5,6,7,8,9,10,11,12,13},//13个浮点数  表示13个模拟量类的传感器
	{0x01,0x02}//CRC
};

sT2C_ALL_Sensor_Data_WholeCar* pT2C_ALL_Sensor_WholeCar = &T2C_ALL_Sensor_WholeCar01;
	
	

sT2C_ALL_Sensor_Data_Each_Cang T2C_ALL_Sensor_Data01  =
{
	{0x39,0x01,3,4,5,6,7,8,9,10,11,12,13,14,15,16},  				//帧头
	0x00,																										//铅封状态
	{0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,
	 0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,
	 0xA5,0xA5,0xA5,0xA5,0xA5},			//21组IO传感器状态
	{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
	 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
	 0.0,0.0,0.0},															//19组模拟量传感器状态
	{0x01,0x02}																							//CRC
};



sT2C_ALL_Sensor_Data_Each_Cang T2C_ALL_Sensor_Data02  =
{
	{0x39,0x01,3,4,5,6,7,8,9,10,11,12,13,14,15,16},  				//帧头
	0x00,																										//铅封状态
	{0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,
	 0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,
	 0xA5,0xA5,0xA5,0xA5,0xA5},			//21组IO传感器状态
	{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
	 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
	 0.0,0.0,0.0},															//19组模拟量传感器状态
	{0x01,0x02}																							//CRC
};

sT2C_ALL_Sensor_Data_Each_Cang T2C_ALL_Sensor_Data03  =
{
	{0x39,0x01,3,4,5,6,7,8,9,10,11,12,13,14,15,16},  				//帧头
	0x00,																										//铅封状态
	{0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,
	 0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,
	 0xA5,0xA5,0xA5,0xA5,0xA5},			//21组IO传感器状态
	{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
	 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
	 0.0,0.0,0.0},															//19组模拟量传感器状态
	{0x01,0x02}																							//CRC
};


sT2C_ALL_Sensor_Data_Each_Cang T2C_ALL_Sensor_Data04  =
{
	{0x39,0x01,3,4,5,6,7,8,9,10,11,12,0x95,0x51,0xAA,0xAA},  				//帧头
	0xaabbccdd,																										//铅封状态
	{0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,
	 0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,
	 0xA5,0xA5,0xA5,0xA5,0xA5},			//21组IO传感器状态
	{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
	 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
	 0.0,0.0,0.0},															//19组模拟量传感器状态
	{0x01,0x02}																							//CRC
};

sT2C_ALL_Sensor_Data_Each_Cang T2C_ALL_Sensor_Data05  =
{
	{0x39,0x01,3,4,5,6,7,8,9,10,11,12,13,14,15,16},  				//帧头
	0x00,																										//铅封状态
	{0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,
	 0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,
	 0xA5,0xA5,0xA5,0xA5,0xA5},			//21组IO传感器状态
	{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
	 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
	 0.0,0.0,0.0},															//19组模拟量传感器状态
	{0x01,0x02}																							//CRC
};

sT2C_ALL_Sensor_Data_Each_Cang T2C_ALL_Sensor_Data06  =
{
	{0x39,0x01,3,4,5,6,7,8,9,10,11,12,13,14,15,16},  				//帧头
	0x00,																										//铅封状态
	{0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,
	 0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,
	 0xA5,0xA5,0xA5,0xA5,0xA5},			//21组IO传感器状态
	{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
	 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
	 0.0,0.0,0.0},															//19组模拟量传感器状态
	{0x01,0x02}																							//CRC
};

sT2C_ALL_Sensor_Data_Each_Cang T2C_ALL_Sensor_Data07  =
{
	{0x39,0x01,3,4,5,6,7,8,9,10,11,12,13,14,15,16},  				//帧头
	0x00,																										//铅封状态
	{0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,
	 0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,
	 0xA5,0xA5,0xA5,0xA5,0xA5},			//21组IO传感器状态
	{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
	 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
	 0.0,0.0,0.0},															//19组模拟量传感器状态
	{0x01,0x02}																							//CRC
};

sT2C_ALL_Sensor_Data_Each_Cang T2C_ALL_Sensor_Data08  =
{
	{0x39,0x01,3,4,5,6,7,8,9,10,11,12,13,14,15,16},  				//帧头
	0x00,																										//铅封状态
	{0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,
	 0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,0xA5,
	 0xA5,0xA5,0xA5,0xA5,0xA5},			//21组IO传感器状态
	{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
	 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
	 0.0,0.0,0.0},															//19组模拟量传感器状态
	{0x01,0x02}																							//CRC
};

sT2C_ALL_Sensor_Data_Each_Cang* pT2C_ALL_Sensor_Data = &T2C_ALL_Sensor_Data01;





 
//李伟修改   20210301
//按下打印键之后对该变量进行赋值  将迪文屏屏幕上显示的内容发送给上位机
 //============================================================
 sT2C_SetupData T2C_SetupData_Con2Server  =
{
   2021,
	 1,
	 25,
   18,
	 03,
   30,
   00,
   /*****  14 val each 32 bit ***/
	   1,
   0.32243546,
	 0.0,//12301.3284,
   0.0,//0.78932,
	 	 5,//液位
   0,//温度
	 0,//倾角x
   0,//倾角y
	 0,//压力 9,
   0,//密度
	 0,//p1
   -0.092329,//p2
	   13,//p3
   0   //p4
};
sT2C_SetupData *pT2C_SetupData_Con2Server = &T2C_SetupData_Con2Server;
//20210301  按下打印键之后对该变量进行赋值  将迪文屏屏幕上显示的内容发送给上位机
//李伟修改结束   

 
 uint8_t Data_V20_From_Server[68];//来自平台的0x64数据帧
 
 
 //uint8_t CarLicensePlate[64]="浙A56708\0";//罐车牌号 车牌号
 uint8_t CarLicensePlate[64]="新AB0808\0";//罐车牌号 车牌号   AB0817;0808新疆一共两辆车
 
//可以考虑将车牌号写在FRAM中
uint8_t CarLicCodeArray[31][16]=
{
		{"北京市京"},//0
		{"天津市津"},
		{"上海市沪"},
		{"重庆市渝"},
		{"河北省冀"},
		{"河南省豫"},//5
		{"云南省云"},
		{"辽宁省辽"},
		{"黑龙江黑"},
		{"湖南省湘"},
		{"安徽省皖"},//10
		{"山东省鲁"},
		{"新疆维新"},//12
		{"江苏省苏"},
		{"浙江省浙"},
		{"江西省赣"},//15
		{"湖北省鄂"},
		{"广西省桂"},
		{"甘肃省甘"},
		{"山西省晋"},
		{"内蒙古蒙"},//20
		{"陕西省陕"},
		{"吉林省吉"},
		{"福建省闽"},
		{"贵州省贵"},
		{"广东省粤"},//25
		{"青海省青"},
		{"西藏区藏"},
		{"四川省川"},
		{"宁夏区宁"},
		{"海南省琼"}//30

 
 };//罐车牌号 车牌号
 
 
 
 

Oil_Data_frame Oil_Data;
IO_Data_frame IO_Date;
Seal_Data_frame Sealing_Data;
Version_Data_frame Version_Date;
IO_Data_Reg Io_data_reg;
//Oil_Data_Reg Oil_data_reg;
Update_data Updatadata;
Return_data *Return_Data;
//All_para_TypeDef  All_Para;
//All_para_TypeDef *ReAll_Para;
uint8_t UP_date_flag = 0;
Calibration_data Calibration_Data ;//标定数据包
Save_Calibration_Inof Save_Calibration_inof;//标定数据信息保存
uint32_t tempupdate_sum = 0;
uint32_t Read_update_sum =0;

//Data_frame data_frame,Tx_data_frame;
Data_frame_TypeDef data_frame,Tx_data_frame;

void Reboot_System()
{
	 __set_FAULTMASK(1);
#if (WATCH_DOG_ON)
	  while (1)
	  {
		  __nop();
	  }
#endif
	HAL_NVIC_SystemReset();
}

int Flash_MD5_Check(uint32_t addr,uint32_t len)
{
	unsigned char digest[16];
	unsigned char *md5_ptr=(unsigned char *)(StartMode_Addr+72);
	unsigned int i,update_len;
	MD5_CTX md5c;
	MD5Init(&md5c);
	for(i=0;i<len;)
	{
		if(len>(i+512))
			update_len = 512;
		else
			update_len = len-i;
		memcpy(USART1_TX_BUF,(const void *)(addr+i),update_len);
		MD5Update (&md5c, USART1_TX_BUF, update_len);
		i += update_len;
	}
	MD5Final(digest,&md5c);
	memcpy(USART1_TX_BUF,(const void *)(StartMode_Addr+72),16);
	for(i=0;i<16;++i)
	{
		if(digest[i]!=USART1_TX_BUF[i])
			break;
	}
	if(i>=16)
		return 1;
	else
		return 0;
}


void TestUsart1_Receive(void)
{
	if(usart1_rx_flag)
	{
		usart1_rx_flag=0;
		TerminalSlave485_Send_Data(USART1_RX_BUF,rx1_len);
	}
}
//RS485发送len个字节.
//buf:发送区首地址
uint8_t terminal_buf[1024];
void TerminalSlave485_Send_Data(uint8_t *buf,uint16_t len)
{
	if(buf==NULL || len==0)
		return;
	while(1)
	{
		osDelay(1);
		if(huart1.gState == HAL_UART_STATE_READY)
				break;
	}
	TerminalSlave485_TX_Set(1);			//设置为发送模式
  	//HAL_UART_Transmit(&huart1,buf,len,1000);//串口1发送数据  
//	TerminalSlave485_TX_Set(0);			//设置为接收模式	

	// 如果来自41串口的报文回应，需要粘合原样5字节头部，其中将长度内容适配下即可
	if(Pass41SensorScanParam.rx_buf[0] > 0){
		memcpy(terminal_buf,Pass41SensorScanParam.rx_buf,5);
		terminal_buf[2] = len;
		memcpy(terminal_buf+5,buf,len);
		len += 5;
		Pass41SensorScanParam.rx_buf[0] = 0;
	}else{
		memcpy(terminal_buf,buf,len);
	}
	
	if(HAL_UART_Transmit_IT(&huart1,terminal_buf,len)!=HAL_OK)
	{
		TerminalSlave485_TX_Set(0);			//设置为接收模式	
	}
}
//RS485模式控制.
//en:0,接收;1,发送.
void TerminalSlave485_TX_Set(uint8_t en)
{
	if(en==1)HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8,GPIO_PIN_RESET);
	else HAL_GPIO_WritePin(GPIOC,GPIO_PIN_8,GPIO_PIN_SET);
}

uint8_t TerminalSlave485_RTS()
{
	if(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_8)==GPIO_PIN_SET)
		return 0;
	else
		return 1;
}
uint8_t temp_dataFromUsart1[600];//看能不能换成指针，防止浪费空间
uint16_t lenRx1;
uint16_t temp_lrc;
uint8_t Lrc_temp;
uint8_t FunCodeOf_0x64;//新增的0x64数据帧功能码 李伟修改与20210204
int cmd39Cnt=0;


/*
*********************************************************************************************************
*	函 数 名: JumpToBootloader
*	功能说明: 跳转到系统BootLoader
*	形    参: 无
*	返 回 值: 无
*********************************************************************************************************
*/
void JumpToAPP2(void)
{
//	uint32_t i=0;
	void (*SysMemBootJump)(void);        /* 声明一个函数指针 */
	__IO uint32_t BootAddr =FLASHAXI_BASE | 0x00080000;// ADDR_FLASH_SECTOR_6;  


	__set_FAULTMASK(1);//DISABLE_INT(); 	// 关闭全局中断 
	HAL_GPIO_TogglePin(GPIOC, DWI_Pin);//看门狗sp706

//	/* 关闭滴答定时器，复位到默认值 */
//	SysTick->CTRL = 0;
//  SysTick->LOAD = 0;
//  SysTick->VAL = 0;

	/* 设置所有时钟到默认状态，使用HSI时钟 */
	HAL_RCC_DeInit();
  HAL_GPIO_TogglePin(GPIOC, DWI_Pin);//看门狗sp706
	
	//关闭所有中断，清除所有中断挂起标志  
//	for (i = 0; i < 8; i++)
//	{
//		NVIC->ICER[i]=0xFFFFFFFF;
//		NVIC->ICPR[i]=0xFFFFFFFF;
//	}	

	
	//ENABLE_INT();// 使能全局中断//

	/* 跳转到系统BootLoader，首地址是MSP，地址+4是复位中断服务程序地址 */
	SysMemBootJump = (void (*)(void)) (*((uint32_t *) (BootAddr + 4)));
	HAL_GPIO_TogglePin(GPIOC, DWI_Pin);//看门狗sp706
  __set_CONTROL(0);
	/* 设置主堆栈指针 */
	__set_MSP(*(uint32_t *)BootAddr);
	
//	/* 在RTOS工程，这条语句很重要，设置为特权级模式，使用MSP指针 */
	
  HAL_GPIO_TogglePin(GPIOC, DWI_Pin);//看门狗sp706
	/* 跳转到系统BootLoader */
	SysMemBootJump(); 
	HAL_GPIO_TogglePin(GPIOC, DWI_Pin);//看门狗sp706

	/* 跳转成功的话，不会执行到这里，用户可以在这里添加代码 */
	while (1)
	{

	}
}



//void (*pFunction)(void);

#define ApplicationAddress    0x08000000
//pFunction Jump_To_Application;

//
uint32_t JumpAddress;
typedef  void (*pFunction)(void);

void go_to_app(uint32_t AppAddress)
{
    uint32_t JumpAddress;
	pFunction Jump_To_Application;
    if(((*(__IO uint32_t *)AppAddress)&0x2FFE0000)==0x20000000)
    {
        //__disable_irq();
          /* close interruption*/
    __set_FAULTMASK(1);
			
			
        JumpAddress = *(__IO uint32_t *)(AppAddress+4); // Jump to user application
        Jump_To_Application = (pFunction)JumpAddress;   // Initialize user application’s Stack Pointer
			
			__set_CONTROL(0);
        __set_MSP(*(__IO uint32_t*)AppAddress);
			
			
        Jump_To_Application();
			while(1)
			{
			__NOP();
			}
    }
    else
    {
        ;//printf(“No Jump\n”);
    }
}

uint8_t FileName_IAP[64];//文件名称
uint32_t FileLength_IAP=0; //文件长度
uint8_t MD5Array[16];  //MD5校验
uint8_t FileBuffArray[1024];  //MD5校验

uint8_t YmodemID;
uint16_t packIndex,packTotalNum,packIndexbak;//当前包号，总包数
uint16_t crcIAP,crcTerminal;
uint32_t AddrToWrite=ADDR_FLASH_SECTOR_7;
uint32_t DataReadFlash,DataReadFlash1;

uint8_t ACK_Arr[16]="acknowlege";
uint8_t ERR_Arr[8]="error";

uint8_t upgrade_type=0;

extern void Set_Update_Down(void);
int AsciitoHexF3(char *buf,int len)
{
	int i;
	uint8_t Lrc_temp;
	FileBuffArray[0]=':';
	for(i=0;i<len;++i)
	{
		sprintf(FileBuffArray+1+2*i,"%02X",buf[i]);
	}
	Lrc_temp = MODBUS_ASCII_GetLrc(FileBuffArray + 1, len * 2);
	sprintf((char *)(&FileBuffArray[1 + len * 2]), "%02X", Lrc_temp);
	FileBuffArray[3+len*2]=0x0d;
	FileBuffArray[4+len*2]=0x0A;
	memcpy(buf,FileBuffArray,len*2+5);
	return len*2+5;
}
int Process_CMD_IAP_Update(void)
{
	
	int lenRx1;
	int txLen=0;
	int i;
	char should_reboot=0;
	/*for(i=0,lenRx1=0;i<rx1_len;++i,++lenRx1)
	{
		if(USART1_RX_BUF[i]==0x7D)
		{
			switch (USART1_RX_BUF[i+1])
			{
			case 1:
				USART1_RX_BUF[lenRx1] = 0x7D;
				++i;
				break;
			case 2:
				USART1_RX_BUF[lenRx1] = 0x7E;
				++i;
				break;
			default:
				USART1_RX_BUF[lenRx1] = USART1_RX_BUF[i];
				break;
			}
		}
		else
		{
			USART1_RX_BUF[lenRx1] = USART1_RX_BUF[i];
		}
	}*/
	//packIndex=USART1_RX_BUF[5]<<8+USART1_RX_BUF[6];
	packIndex		=(USART1_RX_BUF[5]<<8) +USART1_RX_BUF[6];
	packTotalNum=(USART1_RX_BUF[7]<<8) +USART1_RX_BUF[8];	
	lenRx1=(rx1_len);
	//AddrToWrite=ADDR_FLASH_SECTOR_7+(uint32_t)((packIndex-1)*(lenRx1/128)*128);
	//if((not packIndex)== packTotalNum)
	{
		YmodemID		=	USART1_RX_BUF[4];//只能是01,02
	}
	
 
	
 
	//lenRx1 = rx1_len; 
	rx1_len = 0;	
	
//  if((USART1_RX_BUF[0]<<24) +(USART1_RX_BUF[74]<<16)+(USART1_RX_BUF[75]<<8)+(USART1_RX_BUF[76]))
	
	switch (YmodemID)
  {
  	case 0x01: //起始帧与结束帧解析  根据包序号判别该帧为起始帧还是结束帧 
			
			if(packIndex==1)
			{//起始帧处理
				FileLength_IAP=(USART1_RX_BUF[73]<<24) +(USART1_RX_BUF[74]<<16)+(USART1_RX_BUF[75]<<8)+(USART1_RX_BUF[76]);
				crcIAP=CRC16_MODBUS(&USART1_RX_BUF[4], 133);//  
				
				crcTerminal=(USART1_RX_BUF[lenRx1-5]<<8) +USART1_RX_BUF[lenRx1-6];

				if(crcIAP==crcTerminal)
				{
					if(strstr(USART1_RX_BUF+9,"kzb")==NULL)
					{
						upgrade_type=2;
						return upgrade_type;
					}
					upgrade_type=1;
					for(i=0;i<88;++i)
					{
						if(*(unsigned char *)(StartMode_Addr+i+4)!=USART1_RX_BUF[9+i])
							break;
					}
					if(i<88)
					{	
						HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2);//看门狗sp706
						memcpy(FileBuffArray,(unsigned char *)StartMode_Addr,256);
						Erase_page(StartMode_Addr, 128);
						memcpy(FileBuffArray+4,&USART1_RX_BUF[9],88);
						WriteFlash2(StartMode_Addr,(uint32_t*)FileBuffArray,64);
						AddrToWrite=ADDR_FLASH_SECTOR_7;
						packIndexbak=0;
						HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2);//看门狗sp706
						Erase_page(Application_Buffer_Addr, Appear_si);
					}
					HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2);//看门狗sp706
					
					txLen = sprintf(USART1_TX_BUF,"file=%d\r\n",packIndexbak);
				}
				else
				{
					sprintf(USART1_TX_BUF,"%s",ERR_Arr);
				}
			}
				
  		break;
  	case 0x02://有效载荷帧数据处理
				crcIAP=CRC16_MODBUS(&USART1_RX_BUF[4], lenRx1-10);//  
				
				crcTerminal=(USART1_RX_BUF[lenRx1-5]<<8) +USART1_RX_BUF[lenRx1-6];
				if(crcIAP==crcTerminal && upgrade_type==2)
				{
					return upgrade_type;
				}

				if((crcIAP==crcTerminal) && (((packIndexbak+1)==packIndex) || ((packIndexbak)==packIndex)))
				{
					//写入文件至缓冲区
					if((packIndexbak+1)==packIndex)
					{
						memcpy(FileBuffArray,&USART1_RX_BUF[9],lenRx1-15);
						HAL_GPIO_TogglePin(GPIOC, DWI_Pin);//看门狗sp706
						WriteFlash2(AddrToWrite,(uint32_t*)FileBuffArray,(lenRx1-15+3)/4);
						for(i=0;i<(lenRx1-15+3)/4;++i)
						{
							DataReadFlash=*((__IO uint32_t*)(AddrToWrite+i));
							DataReadFlash1=(*(__IO uint32_t*)(FileBuffArray+i));
							if(DataReadFlash!=DataReadFlash1)
								break;
						}
					}
					
					HAL_GPIO_TogglePin(GPIOC, DWI_Pin);//看门狗sp706
					if(DataReadFlash==DataReadFlash1)
					{
						if((packIndexbak+1)==packIndex)
							AddrToWrite += lenRx1-15;
						packIndexbak=packIndex;
						txLen = sprintf(USART1_TX_BUF,"%s=%d\r\n",ACK_Arr,packIndex);
					}
					else
					{
						DataReadFlash=*((__IO uint32_t*)(StartMode_Addr));
  						txLen = sprintf(USART1_TX_BUF,"%s=%d\r\n",ERR_Arr,packIndex);
						Erase_page(StartMode_Addr, 128);
						WriteFlash2(StartMode_Addr,&DataReadFlash,1);
					}
				}
				else
				{
					txLen = sprintf(USART1_TX_BUF,"Rx Error lenRx1=%d crcIAP=%04X crcTerminal=%04X\r\n",lenRx1,crcIAP,crcTerminal);
				}			
		
  		break;
	case 3:
			//if(packIndex>2)
			{//结束帧处理
				crcIAP=CRC16_MODBUS(&USART1_RX_BUF[4], 133);//  
				
				crcTerminal=(USART1_RX_BUF[lenRx1-5]<<8) +USART1_RX_BUF[lenRx1-6];

				if(crcIAP==crcTerminal)
				{
					int all_len;
					if(upgrade_type==2)
					{
						return upgrade_type;
					}
					txLen = sprintf(USART1_TX_BUF,"%s\r\n",ACK_Arr);
					if(f3_flag)
						txLen = AsciitoHexF3(USART1_TX_BUF, txLen);
	  				TerminalSlave485_Send_Data(USART1_TX_BUF, txLen);

					for(i=0,all_len=0;i<4;++i)
					{
						all_len = all_len<<8;
						all_len |= *(unsigned char *)(StartMode_Addr+68+i);
					}
					
					if(Flash_MD5_Check(ADDR_FLASH_SECTOR_7,all_len)==0)
					{
						txLen = sprintf(USART1_TX_BUF,"md5 check=error\r\n");
					}
					else
					{
						if(strcmp(custurm_code,(const char*)Application_Buffer_Addr+5120))
						{
							txLen = sprintf(USART1_TX_BUF,"Product=error\r\n");
						}	
						else if((*(unsigned int*)(Application_Buffer_Addr+6144)!=Application_2_Addr) && (*(unsigned int*)(Application_Buffer_Addr+4)&0xffff0000 != Application_2_Addr))
						{
							txLen = sprintf(USART1_TX_BUF,"Link addr=error\r\n");
						}
						else
						{
							Set_Update_Down();//设定标志位  下次启动时进行程序拷贝
							txLen = sprintf(USART1_TX_BUF,"md5 check=ok\r\n");
							should_reboot=1;
						}
					}
				
				}
				else
				{
					txLen = sprintf(USART1_TX_BUF,"%s\r\n",ERR_Arr);		
				}		
			}
			break;
  	default:
  		break;
  }
  if(txLen)
  {
	  if(f3_flag)
		txLen = AsciitoHexF3(USART1_TX_BUF, txLen);
	  TerminalSlave485_Send_Data(USART1_TX_BUF, txLen);
  }
  if(should_reboot)
  {
	  HAL_Delay(100);
	  Reboot_System();
  }
  return 0;
}

uint8_t  Cang_IO_tbak[4][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];
uint32_t overflow_cnt_bak=0;
extern uint32_t overflow_cnt;
unsigned char overflow_flag_bak;
void Send_A1_Cmd()
{
	int send_pos=0;
	unsigned char emergy=0;
	unsigned char Lrc_temp;
	unsigned char overflow_flag=0;
	int i,j;
	USART1_TX_BUF[send_pos++]=':';
	sprintf(USART1_TX_BUF+send_pos,"%02X",0xA1);
	send_pos+=2;
	sprintf(USART1_TX_BUF+send_pos,"%02X",0x04);
	send_pos+=2;
	sprintf(USART1_TX_BUF+send_pos,"%02X",120);
	send_pos+=2;
	if(StoreNumber>0)
	{
		if(memcmp(Cang_IO_tbak[0],Cang01_IO,64))
		{
			emergy=0x80;
		}
		memcpy(Cang_IO_tbak[0],Cang01_IO,64);
	}
	if(StoreNumber>1)
	{
		if(memcmp(Cang_IO_tbak[1],Cang02_IO,64))
		{
			emergy=0x80;
		}
		memcpy(Cang_IO_tbak[1],Cang02_IO,64);
	}
	if(StoreNumber>2)
	{
		if(memcmp(Cang_IO_tbak[2],Cang03_IO,64))
		{
			emergy=0x80;
		}
		memcpy(Cang_IO_tbak[2],Cang03_IO,64);
	}
	if(StoreNumber>3)
	{
		if(memcmp(Cang_IO_tbak[3],Cang04_IO,64))
		{
			emergy=0x80;
		}
		memcpy(Cang_IO_tbak[3],Cang04_IO,64);
	}
	if((overflow_cnt==0) && (overflow_cnt==overflow_cnt_bak))
	{
		overflow_flag=0;
	}
	else
	{
		overflow_flag=1;
	}
	overflow_cnt_bak=overflow_cnt;
	if(overflow_flag_bak!=overflow_flag)
	{
		emergy=0x80;	
	}
	overflow_flag_bak=overflow_flag;
	sprintf(USART1_TX_BUF+send_pos,"%02X",emergy);
	send_pos+=2;
	sprintf(USART1_TX_BUF+send_pos,"%02X",StoreNumber);
	send_pos+=2;
	sprintf(USART1_TX_BUF+send_pos,"%02X",0x22);
	send_pos+=2;
	
	sprintf(USART1_TX_BUF+send_pos,"%02X",overflow_flag);
	send_pos+=2;
	if((Config_info_all.ManHole_Big_info>0) && (Config_info_all.ManHole_Big_info<8))
	{
		sprintf(USART1_TX_BUF+send_pos,"%02X",0x72);
		send_pos+=2;
		for (i = 0; i < StoreNumber; i++)
		{
			sprintf(USART1_TX_BUF+send_pos,"%02X",Config_info_all.ManHole_Big_info/StoreNumber);
			send_pos+=2;
			for(j=0;j<Config_info_all.ManHole_Big_info/StoreNumber;++j)
			{
				sprintf(USART1_TX_BUF+send_pos,"%02X",Cang_IO_tbak[i][indexDaGai01+10*j]);
				send_pos+=2;
			}
		}
	}
	if((Config_info_all.Dump_info>0) && (Config_info_all.Dump_info<8))
	{
		sprintf(USART1_TX_BUF+send_pos,"%02X",0x71);
		send_pos+=2;
		for (i = 0; i < StoreNumber; i++)
		{
			sprintf(USART1_TX_BUF+send_pos,"%02X",Config_info_all.Dump_info/StoreNumber);
			send_pos+=2;
			for(j=0;j<Config_info_all.Dump_info/StoreNumber;++j)
			{
				sprintf(USART1_TX_BUF+send_pos,"%02X",Cang_IO_tbak[i][indexXieYouFa01+10*j]);
				send_pos+=2;
			}
		}
	}
	if((Config_info_all.HaiDiFa_info>0) && (Config_info_all.HaiDiFa_info<8))
	{
		sprintf(USART1_TX_BUF+send_pos,"%02X",0x64);
		send_pos+=2;
		for (i = 0; i < StoreNumber; i++)
		{
			sprintf(USART1_TX_BUF+send_pos,"%02X",Config_info_all.HaiDiFa_info/StoreNumber);
			send_pos+=2;
			for(j=0;j<Config_info_all.HaiDiFa_info/StoreNumber;++j)
			{
				sprintf(USART1_TX_BUF+send_pos,"%02X",Cang_IO_tbak[i][indexHaiDiFa01+10*j]);
				send_pos+=2;
			}
		}
	}
	sprintf(USART1_TX_BUF + send_pos, "%02X", 0x73);
	send_pos += 2;

	sprintf(USART1_TX_BUF + send_pos, "%02X", StoreNumber);
	send_pos += 2;
	for (j = 0; j < StoreNumber; ++j)
	{
		uni_float uni_0x93;
		int k;
		uni_0x93.flo_Data = ExpansionRatio[j];
		if(j==0) 
			uni_0x93.flo_Data -= T2C_ALL_Sensor_Data01.MoniLiang_Data_Every_Cang[0];
		else if(j==1)
			uni_0x93.flo_Data -= T2C_ALL_Sensor_Data02.MoniLiang_Data_Every_Cang[0];
		for (k = 0; k < 4; ++k)
		{
			sprintf(USART1_TX_BUF + send_pos, "%02X", uni_0x93.array_u8[3 - k]);
			send_pos += 2;
		}
	}

	sprintf(USART1_TX_BUF + send_pos, "%02X", 0x6C);
	send_pos += 2;
	sprintf(USART1_TX_BUF + send_pos, "%02X", StoreNumber);
	send_pos += 2;
	for (j = 0; j < StoreNumber; ++j)
	{
		uni_float uni_0x93;
		int k;
		if(j==0)
			uni_0x93.flo_Data = T2C_ALL_Sensor_Data01.MoniLiang_Data_Every_Cang[0];
		else
			uni_0x93.flo_Data = T2C_ALL_Sensor_Data02.MoniLiang_Data_Every_Cang[0];
		for (k = 0; k < 4; ++k)
		{
			sprintf(USART1_TX_BUF + send_pos, "%02X", uni_0x93.array_u8[3 - k]);
			send_pos += 2;
		}
	}
	while (send_pos<(120*2+7))
	{
		sprintf(USART1_TX_BUF+send_pos,"%02X",0);
		send_pos+=2;
	}
	Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,send_pos-1);
	sprintf(USART1_TX_BUF+send_pos,"%02X",Lrc_temp);
	send_pos += 2;
	USART1_TX_BUF[send_pos++] =0x0D;
	USART1_TX_BUF[send_pos++] = 0x0A;
	TerminalSlave485_Send_Data(USART1_TX_BUF,send_pos);
}

#include "leaf_ota.h"
//uint32_t data_count=0;
//uint32_t re_count=0;
void Data_analysis(void)
{
	uint32_t startBytes=0x00000000,tmpU32,update_flag;
	if(usart1_rx_flag==1)//接收完成
	{
		//data_count++;
		//re_count+=rx1_len;
		usart1_rx_flag=0;
		usart_timesec=0;
		f3_flag=0;

		// xy，匹配到0x0139为首的5字节的头，表示是41串口透传下行的数据
		// 5字节的头定义为:
		//     [0][1] -- 01 39
		//     [2] -- 透传有效数据长度
		//     [3][4] -- 流水号
		if( (USART1_RX_BUF[0]==0x01) && (USART1_RX_BUF[1]==0x39)){
			memcpy(Pass41SensorScanParam.rx_buf,USART1_RX_BUF,5);
			memcpy(USART1_RX_BUF,USART1_RX_BUF+5,rx1_len-5);
			rx1_len -=5;
		}
		
		if((USART1_RX_BUF[0]==':') && (USART1_RX_BUF[1]==0xa5) && (USART1_RX_BUF[1]==0xa5))
		{
			memcpy(USART1_RX_BUF,USART1_RX_BUF+1,rx1_len-5);
			rx1_len -=5;
			f3_flag=1;
		}
		if((USART1_RX_BUF[0]=='j') && (USART1_RX_BUF[1]=='u') && (USART1_RX_BUF[2]=='m') && (USART1_RX_BUF[3]=='p'))
		{
			//go_to_app(FLASHAXI_BASE | 0x00040000);//
		JumpToAPP2();;//
		}
		
		
		if((USART1_RX_BUF[0]=='j') && (USART1_RX_BUF[1]=='u') && (USART1_RX_BUF[2]=='m') && (USART1_RX_BUF[3]=='q'))
		{
			JumpToAPP2();
		
		}	
		
		if((USART1_RX_BUF[0]=='s') && (USART1_RX_BUF[1]=='e') && (USART1_RX_BUF[2]=='t') && (USART1_RX_BUF[3]=='u') && (USART1_RX_BUF[4]=='p'))
		{ //进入升级之后再启动的模式    //setup  
			Set_Update_Down();//强制下次重启之后从缓冲区拷贝代码至APP2区
			__NOP();
		}		

		if((USART1_RX_BUF[0]=='b') && (USART1_RX_BUF[1]=='o') && (USART1_RX_BUF[2]=='o') && (USART1_RX_BUF[3]=='t') && (USART1_RX_BUF[4]=='l'))
		{ //进入升级之后再启动的模式   //bootl
			Start_BootLoader();//强制下次重启之后从缓冲区拷贝代码至APP2区
			__NOP();
		}
		else if ((USART1_RX_BUF[0] == 'm') && (USART1_RX_BUF[1] == 'o') && (USART1_RX_BUF[2] == 'd') && (USART1_RX_BUF[3] == 'e') && (USART1_RX_BUF[4] == ':'))
		{ //mode:1    //mode:2  //mode:31  //mode:4
			switch (USART1_RX_BUF[5])
			{
			case '1': //0x01:
				update_flag = Startup_Normal;
				break;
			case '2': //0x02:
				update_flag = Startup_APP2;
				break;
			case '3': //0x03:
				update_flag = Startup_Normal;
				break;
			case '4': //0x04:
				update_flag = Startup_Normal;
				break;
			default:
				update_flag = Startup_Normal;
				break;
			}

			Erase_page(StartMode_Addr, Appear_si);
			WriteFlash2(StartMode_Addr, &update_flag, 1);			 
			 
			Reboot_System();
		}

	//远程升级数据处理
		if((rx1_len>300) ||((USART1_RX_BUF[0]==0xa5) && (USART1_RX_BUF[1]==0x5a)  ))
		{
			tmpU32=(USART1_RX_BUF[0]<<24) | (USART1_RX_BUF[1]<<16) | (USART1_RX_BUF[2]<<8) | (USART1_RX_BUF[3]);
			
			if(StartBytes_IAP==tmpU32)
			{
				int rx_lenbak=rx1_len;
				int retrynum=0;
				circle_send=0;
				if(Process_CMD_IAP_Update()==2)
				{
					if(tmrForRemoteCali==0)
					{
						tmrForRemoteCali=SPAN_RemoteCali_INTERVAL;
						osDelay(50);
					}
					tmrForRemoteCali=SPAN_RemoteCali_INTERVAL;
					CollectMaster485_Send_Data(USART1_RX_BUF,rx_lenbak);
					for(retrynum=0;retrynum<200;++retrynum)
					{
						osDelay(5);
						if(usart2_rx_flag==True)
						{
							usart2_rx_flag=False;
							if(f3_flag)
								rx2_len=AsciitoHexF3(USART2_RX_BUF,rx2_len);
							TerminalSlave485_Send_Data(USART2_RX_BUF,rx2_len);
							rx2_len=0;
							break;
						}
					}
				}
					
			}
			return;
		}
		
		__nop();
		
		Tx_data_frame.Frame_head = FRAME_HEAD;			//回复帧头
		lenRx1 = rx1_len;
		rx1_len=0;
//		len = 15;
		if(lenRx1>600)lenRx1=600;//数据长度异常时会越界，这里没有好的处理方式，只能对len长度进行判读，防止溢出
		memcpy(temp_dataFromUsart1,USART1_RX_BUF,lenRx1);//首先取出值，防止下次被覆盖  
		
		if((USART1_RX_BUF[0]==0x39) && (USART1_RX_BUF[1]==0x01))
		{
			temp_dataFromUsart1[0]=':';
			memcpy(temp_dataFromUsart1+1,USART1_RX_BUF,lenRx1);
			memcpy(USART1_RX_BUF,temp_dataFromUsart1,lenRx1+1);
		}
		if((USART1_RX_BUF[1]==0x39) && (USART1_RX_BUF[2]==0x01))
		{
		
			__NOP();
			Process_CMD_0x39_RemoteCali(0x01);//十六进制格式
			return;//匹配上0x39之后不再进行其他命令的匹配
						
			
		}
		//加密数据解密
		
		//没加密数据
		if(FRAME_HEAD == temp_dataFromUsart1[0] )//帧头正确  0x3A
		{//帧头正确--开始
			//先校验数据
			data_frame.Frame_LRC =  MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+lenRx1-2);
		#if 0
			//2021-1-26 by Daiyf
			Tx_data_frame.Frame_length = (MODBUS_ASCII_AsciiToHex(temp_data+5));
			USART1_TX_BUF[0]= Tx_data_frame.Frame_length;
		;
			Tx_data_frame.Frame_length = (TempMODBUS_ASCII_AsciiToHex(temp_data+5));
			USART1_TX_BUF[1]= Tx_data_frame.Frame_length;
			USART1_TX_BUF[2]= temp_data[5];
			USART1_TX_BUF[3]= temp_data[6];
			TerminalSlave485_Send_Data(USART1_TX_BUF,4);
    #endif	
			temp_lrc = MODBUS_ASCII_GetLrc(temp_dataFromUsart1+1,lenRx1-3);
			//if(data_frame.Frame_LRC == temp_lrc)//校验通过，否则不做应答
			if(1)//校验通过，否则不做应答
			{
				//外设地址  液位 ：0x47~0x4E ，共 8个。 IO：0x91~0x92 : TERMINAL_CONTROL_GET_SENSOR_D1~2，共2个，包含32个IO信息
				data_frame.Frame_addr = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1);
				//判断地址是否正确
				if(((data_frame.Frame_addr>=0x47)&&(data_frame.Frame_addr<=0x4e))||
					(data_frame.Frame_addr==TERMINAL_CONTROL_GET_SENSOR_D1)||
					(data_frame.Frame_addr==0xA1)||
				(data_frame.Frame_addr==TERMINAL_CONTROL_GET_SENSOR_D2)||
				(data_frame.Frame_addr==0x40)||
				((data_frame.Frame_addr>=0x30)&&(data_frame.Frame_addr<=0x6f))||
				((data_frame.Frame_addr>=TERMINAL_CONTROL_GET_Store01_ALL_Sensor)&&(data_frame.Frame_addr<=TERMINAL_CONTROL_GET_Whole_Car_Sensor))
				)
				{//地址码或者功能码正确合法-----开始
					Sealing_Data.TerminalOnLineFlag = True;
					//功能码   升级：0x41 , 读数据：0x04(液位) ,读参数：0x03 (如波特率等)，写参数：0x10 (如更改外设地址)，读外设信息：0x2B(如版本号)，控制：0x0F(如状态改变等)
//=======================================================================================================================//		
				
			    if((data_frame.Frame_addr>= TERMINAL_CONTROL_CMD_RESPOND) && (data_frame.Frame_addr<= TERMINAL_CONTROL_CMD_RESPOND+7))//新增的与终端进行交互的一个通信命令 2021-1-26 by Daiyf
				   { //打印数据，温度，密度，液位等数据回传0x30命令处理--开始
						  pT2C_SetupData = &(T2C_SetupData[data_frame.Frame_addr-TERMINAL_CONTROL_CMD_RESPOND]);
						  Process_CMD_0x30_ManualFix();
						  return;//匹配上0x30之后不再进行其他命令的匹配
				   }//打印数据，温度，密度，液位等数据回传0x30命令处理--结束
					 
					 if(ElecFence_AutoSeal_EN) 
			   	 {//如果允许电子围栏自动施封 
						 
								if(data_frame.Frame_addr == TERMINAL_CONTROL_Seal_By_ElecFence)//李伟修改 出电子围栏进行施封  20210705
								{ //电子围栏自动施封--开始
								Process_CMD_0x38_AutoSeal_By_ElecFence();
								return;//匹配上0x30之后不再进行其他命令的匹配
								}//电子围栏自动施封----结束					 

					 
					 }//如果允许电子围栏自动施封 
					 
					 
					 //if((data_frame.Frame_addr>= TERMINAL_CONTROL_CMD_REMOTE_CAL) && (data_frame.Frame_addr<= TERMINAL_CONTROL_CMD_REMOTE_CAL+7))//新增的与终端进行交互的一个通信命令 2021-1-26 by Daiyf
				   if(data_frame.Frame_addr == TERMINAL_CONTROL_CMD_REMOTE_CAL)//李伟修改 远程标定命令  20210702
					 { //远程标定命令处理--开始
						  Process_CMD_0x39_RemoteCali(0x00);//老协议  ASCII格式解析数据
						  return;//匹配上0x39之后不再进行其他命令的匹配
				   }//远程标定命令处理--结束
					 
					 
					 
				 
//=======================================================================================================================//					
					data_frame.Frame_funcode = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+3);
					//根据功能码做回复应答
					switch(data_frame.Frame_funcode)
					{//老协议的功能码--开始
						case Read_data://通过
						{
							//读的寄存器号
							data_frame.Frame_message_id = (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+5)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+7);//获取寄存器的值
							//需要读的寄存器个数
							data_frame.Frame_length = (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+9)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+11);//获取寄存器的个数的值
							
							//if((data_frame.Frame_addr>=0x47)&&(data_frame.Frame_addr<=0x4e))//0x47---0x4e  //李伟修改  20210610  用宏定义替代绝对数字，增强维修性
							if((data_frame.Frame_addr>=TERMINAL_CONTROL_GET_CABINET01_STATE)&&(data_frame.Frame_addr<=TERMINAL_CONTROL_GET_CABINET08_STATE))//0x47---0x4e
							{
								if((Baseval_ID ==1)&&(data_frame.Frame_addr>=0x47)&&(data_frame.Frame_addr<=0x4B))
								{	
									data_frame.Frame_data = Oil_Tx_Readvalue(data_frame.Frame_addr,data_frame.Frame_message_id,data_frame.Frame_length);//返回具体的值  液位与压力
									//开始应答
									Tx_data_frame.Frame_addr = data_frame.Frame_addr;
									Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
									Tx_data_frame.Frame_length = data_frame.Frame_length*4;
									Tx_data_frame.Frame_data = data_frame.Frame_data;
									//开始组包
									USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok 
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length/2,USART1_TX_BUF+5);//56
									memcpy(USART1_TX_BUF+7,Tx_data_frame.Frame_data,Tx_data_frame.Frame_length);
									Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,Tx_data_frame.Frame_length+6);
									MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+Tx_data_frame.Frame_length+7);//56
									USART1_TX_BUF[Tx_data_frame.Frame_length+9] =0x0D;
									USART1_TX_BUF[Tx_data_frame.Frame_length+10] = 0x0A;
									//开始发送
	//								for(i=0;i<Tx_data_frame.Frame_length+11;i++)																					
	//								USART1_send(USART1_TX_BUF[i]);
	//								UartWrite(&huart1,USART1_TX_BUF,Tx_data_frame.Frame_length+11);
									TerminalSlave485_Send_Data(USART1_TX_BUF,Tx_data_frame.Frame_length+11);
								}
								else if((Baseval_ID ==2)&&(data_frame.Frame_addr>=0x4B)&&(data_frame.Frame_addr<=0x4E))
								{
									data_frame.Frame_data = Oil_Tx_Readvalue(data_frame.Frame_addr,data_frame.Frame_message_id,data_frame.Frame_length);//返回具体的值  液位与压力
									//开始应答
									Tx_data_frame.Frame_addr = data_frame.Frame_addr;
									Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
									Tx_data_frame.Frame_length = data_frame.Frame_length*4;
									Tx_data_frame.Frame_data = data_frame.Frame_data;
									//开始组包
									USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok 
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length/2,USART1_TX_BUF+5);//56

									memcpy(USART1_TX_BUF+7,Tx_data_frame.Frame_data,Tx_data_frame.Frame_length);
									Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,Tx_data_frame.Frame_length+6);
									MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+Tx_data_frame.Frame_length+7);//56
									
									USART1_TX_BUF[Tx_data_frame.Frame_length+9] =0x0D;
									USART1_TX_BUF[Tx_data_frame.Frame_length+10] = 0x0A;
									//开始发送
	//								for(i=0;i<Tx_data_frame.Frame_length+11;i++)																					
	//								USART1_send(USART1_TX_BUF[i]);
	//								UartWrite(&huart1,USART1_TX_BUF,Tx_data_frame.Frame_length+11);
									TerminalSlave485_Send_Data(USART1_TX_BUF,Tx_data_frame.Frame_length+11);
								}
							}
							else if((data_frame.Frame_addr==TERMINAL_CONTROL_GET_SENSOR_D1)||(data_frame.Frame_addr==TERMINAL_CONTROL_GET_SENSOR_D2))//0x91---0x92
							{
								if((Baseval_ID ==1)&&(data_frame.Frame_addr == TERMINAL_CONTROL_GET_SENSOR_D1))
								{	
	//									data_frame.Frame_data
									Return_Data = IO_Tx_Readvalue(data_frame.Frame_message_id,data_frame.Frame_length);//IO-----阀门状态
									//开始应答
									Tx_data_frame.Frame_addr = data_frame.Frame_addr;
									Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
									Tx_data_frame.Frame_length = Return_Data->length;//strlen(data_frame.Frame_data);
									Tx_data_frame.Frame_data = Return_Data->data;//data_frame.Frame_data;
									//开始组包
									USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok 
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length/2,USART1_TX_BUF+5);//56

									memcpy(USART1_TX_BUF+7,Tx_data_frame.Frame_data,Tx_data_frame.Frame_length);
									Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,Tx_data_frame.Frame_length+6);
									MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+Tx_data_frame.Frame_length+7);//56
									
									USART1_TX_BUF[Tx_data_frame.Frame_length+9] =0x0D;
									USART1_TX_BUF[Tx_data_frame.Frame_length+10]=0x0A;
									//开始发送
	//								for(i=0;i<Tx_data_frame.Frame_length+11;i++)																					
	//								USART1_send(USART1_TX_BUF[i]);
	//								UartWrite(&huart1,USART1_TX_BUF,Tx_data_frame.Frame_length+11);
									TerminalSlave485_Send_Data(USART1_TX_BUF,Tx_data_frame.Frame_length+11);
								}
								else if((Baseval_ID ==2)&&(data_frame.Frame_addr == 0x92))
								{
	//								data_frame.Frame_data 
									Return_Data = IO_Tx_Readvalue(data_frame.Frame_message_id,data_frame.Frame_length);//IO-----阀门状态
									//开始应答
									Tx_data_frame.Frame_addr = data_frame.Frame_addr;
									Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
									Tx_data_frame.Frame_length = Return_Data->length;//strlen(data_frame.Frame_data);
									Tx_data_frame.Frame_data = Return_Data->data;//data_frame.Frame_data;
									//开始组包
									USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok 
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length/2,USART1_TX_BUF+5);//56

									memcpy(USART1_TX_BUF+7,Tx_data_frame.Frame_data,Tx_data_frame.Frame_length);
									Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,Tx_data_frame.Frame_length+6);
									MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+Tx_data_frame.Frame_length+7);//56
									
									USART1_TX_BUF[Tx_data_frame.Frame_length+9] =0x0D;
									USART1_TX_BUF[Tx_data_frame.Frame_length+10] = 0x0A;
									//开始发送
	//								for(i=0;i<Tx_data_frame.Frame_length+11;i++)																					
	//								USART1_send(USART1_TX_BUF[i]);
	//								UartWrite(&huart1,USART1_TX_BUF,Tx_data_frame.Frame_length+11);
									TerminalSlave485_Send_Data(USART1_TX_BUF,Tx_data_frame.Frame_length+11);
								}
							}
							else if(data_frame.Frame_addr==TERMINAL_CONTROL_GET_ELEC_SEAL_STATE)//李伟修改20210610//else if(data_frame.Frame_addr==0x40)//后加的，需要兼容
							{
									Return_Data = Seal_Tx_Readvalue(data_frame.Frame_message_id,data_frame.Frame_length);//电子铅封状态
									//开始应答
									Tx_data_frame.Frame_addr = data_frame.Frame_addr;
									Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
									Tx_data_frame.Frame_length = Return_Data->length;//strlen(data_frame.Frame_data);
									Tx_data_frame.Frame_data = Return_Data->data;//data_frame.Frame_data;
									//开始组包
									USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok 
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length/2,USART1_TX_BUF+5);//56

									memcpy(USART1_TX_BUF+7,Tx_data_frame.Frame_data,Tx_data_frame.Frame_length);
									Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,Tx_data_frame.Frame_length+6);
									MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+Tx_data_frame.Frame_length+7);//56
									
									USART1_TX_BUF[Tx_data_frame.Frame_length+9] =0x0D;
									USART1_TX_BUF[Tx_data_frame.Frame_length+10] = 0x0A;
									//开始发送
	//								for(i=0;i<Tx_data_frame.Frame_length+11;i++)																					
	//								USART1_send(USART1_TX_BUF[i]);
	//								UartWrite(&huart1,USART1_TX_BUF,Tx_data_frame.Frame_length+11);
									TerminalSlave485_Send_Data(USART1_TX_BUF,Tx_data_frame.Frame_length+11);
							}
							else if(data_frame.Frame_addr==TERMINAL_CONTROL_CMD_REMOTE_CAL)//李伟修改 20210610 远程标定命令
							{//主要是设置标志位，简单的命令解析；耗时的任务放在任务函数中完成 //远程标定命令--开始
 
							}//远程标定命令--结束
							else if(data_frame.Frame_addr==TERMINAL_CONTROL_GET_Store01_ALL_Sensor)//第三套协议 一次获取所有的传感器数据：包括IO类与模拟量类
							{//十六进制传输而非之前的ASCII编码！！！！！！
									USART1_TX_BUF[0]=0x3A;								  								  
								  FormatEachStoreData(0x01);					
									TerminalSlave485_Send_Data(USART1_TX_BUF,148+4+7);//起始字符1+148+LRC+0x0d0a
							} 						
							
							else if(data_frame.Frame_addr==TERMINAL_CONTROL_GET_Store02_ALL_Sensor)//第三套协议 一次获取所有的传感器数据：包括IO类与模拟量类
							{//十六进制传输而非之前的ASCII编码！！！！！！
									USART1_TX_BUF[0]=0x3A;
									FormatEachStoreData(0x02);
					        TerminalSlave485_Send_Data(USART1_TX_BUF,LenthOf_Reply0x93);//起始字符1+148+LRC+0x0d0a
									return;
							} 							
							else if(data_frame.Frame_addr==TERMINAL_CONTROL_GET_Store03_ALL_Sensor)//第三套协议 一次获取所有的传感器数据：包括IO类与模拟量类
							{//十六进制传输而非之前的ASCII编码！！！！！！
									USART1_TX_BUF[0]=0x3A;
								  FormatEachStoreData(0x03);
					        TerminalSlave485_Send_Data(USART1_TX_BUF,LenthOf_Reply0x93);//起始字符1+148+LRC+0x0d0a
									return;
							}
							else if(data_frame.Frame_addr==TERMINAL_CONTROL_GET_Store04_ALL_Sensor)//第三套协议 一次获取所有的传感器数据：包括IO类与模拟量类
							{//十六进制传输而非之前的ASCII编码！！！！！！
									USART1_TX_BUF[0]=0x3A;
								  FormatEachStoreData(0x04);
					        TerminalSlave485_Send_Data(USART1_TX_BUF,LenthOf_Reply0x93);//起始字符1+148+LRC+0x0d0a
									return;
							}
							
							else if(data_frame.Frame_addr==TERMINAL_CONTROL_GET_Store05_ALL_Sensor)//第三套协议 一次获取所有的传感器数据：包括IO类与模拟量类
							{//十六进制传输而非之前的ASCII编码！！！！！！
									USART1_TX_BUF[0]=0x3A;
								  FormatEachStoreData(0x05);
					        TerminalSlave485_Send_Data(USART1_TX_BUF,LenthOf_Reply0x93);//起始字符1+148+LRC+0x0d0a
									return;
							}		
							else if(data_frame.Frame_addr==TERMINAL_CONTROL_GET_Store06_ALL_Sensor)//第三套协议 一次获取所有的传感器数据：包括IO类与模拟量类
							{//十六进制传输而非之前的ASCII编码！！！！！！
									USART1_TX_BUF[0]=0x3A;
								  FormatEachStoreData(0x06);
					        TerminalSlave485_Send_Data(USART1_TX_BUF,LenthOf_Reply0x93);//起始字符1+148+LRC+0x0d0a
									return;
							}		
							else if(data_frame.Frame_addr==TERMINAL_CONTROL_GET_Store07_ALL_Sensor)//第三套协议 一次获取所有的传感器数据：包括IO类与模拟量类
							{//十六进制传输而非之前的ASCII编码！！！！！！
									USART1_TX_BUF[0]=0x3A;
								  FormatEachStoreData(0x07);
					        TerminalSlave485_Send_Data(USART1_TX_BUF,LenthOf_Reply0x93);//起始字符1+148+LRC+0x0d0a
									return;
							}		
							else if(data_frame.Frame_addr==TERMINAL_CONTROL_GET_Store08_ALL_Sensor)//第三套协议 一次获取所有的传感器数据：包括IO类与模拟量类
							{//十六进制传输而非之前的ASCII编码！！！！！！
									USART1_TX_BUF[0]=0x3A;
								  FormatEachStoreData(0x08);
					        TerminalSlave485_Send_Data(USART1_TX_BUF,LenthOf_Reply0x93);//起始字符1+148+LRC+0x0d0a
									return;
							}									
							
							
							
							
							else if(data_frame.Frame_addr==TERMINAL_CONTROL_GET_Whole_Car_Sensor)//第三套协议 一次获取所有的传感器数据：包括IO类与模拟量类
							{//十六进制传输而非之前的ASCII编码！！！！！！
//									USART1_TX_BUF[0]=0x3A;
//								  memcpy(&USART1_TX_BUF[1],T2C_ALL_Sensor_WholeCar01.FrameHead,16);
//								  memcpy(&USART1_TX_BUF[17],T2C_ALL_Sensor_WholeCar01.tiltXYZ,3*4); //17--20
//									memcpy(&USART1_TX_BUF[29],&T2C_ALL_Sensor_WholeCar01.BeiDian_State_OnOff,1*4); //								
//                  memcpy(&USART1_TX_BUF[33],&T2C_ALL_Sensor_WholeCar01.BeiDianDianLiang,1*4); //
//								  memcpy(&USART1_TX_BUF[37],&T2C_ALL_Sensor_WholeCar01.YouQiHuiShou_State_OnOff,1*4); //								
//                  memcpy(&USART1_TX_BUF[41],&T2C_ALL_Sensor_WholeCar01.YouQiHuiShou_State_Photo,1*4); //
//									memcpy(&USART1_TX_BUF[45],&T2C_ALL_Sensor_WholeCar01.YouQiHuiShou_State_Photo,13*4); //			
//								
//									Lrc_temp = MODBUS_Hex_GetLrc(USART1_TX_BUF+1,16+80);
//								  USART1_TX_BUF[97]=Lrc_temp;
//								  USART1_TX_BUF[98]=0x0d;
//								  USART1_TX_BUF[99]=0x0a;
								  USART1_TX_BUF[0]=0x3A;
								  FormatWholeCarData();
					        TerminalSlave485_Send_Data(USART1_TX_BUF,96+4);//起始字符1+96+LRC+0x0d0a
									return;
								
							}
							else if(data_frame.Frame_addr==0xA1)
							{
								Send_A1_Cmd();
							}

 							
							
						}
							break;
						case Read_para://读传感器的常规参数   读取标定数据
						{
							//读的寄存器号
							data_frame.Frame_message_id = (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+5)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+7);//获取寄存器的值
							//需要读的寄存器个数
							data_frame.Frame_length = (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+9)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+11);//获取寄存器的个数的值
							//需要应答具体的值与个数
							if((Baseval_ID ==1)&&(data_frame.Frame_addr>=0x47)&&(data_frame.Frame_addr<=0x4a))//0x47---0x4e
							{
	//							data_frame.Frame_data = Oil_Tx_Readpara(data_frame.Frame_message_id,data_frame.Frame_length);//返回具体的值  液位与压力
								if((uint8_t)data_frame.Frame_message_id!=0x80)//非标定数据
								{
									Return_Data = Oil_Tx_Readpara(data_frame.Frame_message_id,data_frame.Frame_length);//返回具体的值  液位与压力;
									//开始应答
									Tx_data_frame.Frame_addr = data_frame.Frame_addr;
									Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
									Tx_data_frame.Frame_length = Return_Data->length;//strlen(data_frame.Frame_data);
									Tx_data_frame.Frame_data = Return_Data->data;//data_frame.Frame_data;
									//开始组包
									USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok 
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length/2,USART1_TX_BUF+5);//56

									memcpy(USART1_TX_BUF+7,Tx_data_frame.Frame_data,Tx_data_frame.Frame_length);
									Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,Tx_data_frame.Frame_length+6);
									MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+Tx_data_frame.Frame_length+7);//56
									
									USART1_TX_BUF[Tx_data_frame.Frame_length+9] =0x0D;
									USART1_TX_BUF[Tx_data_frame.Frame_length+10] = 0x0A;
									//开始发送
	//								for(i=0;i<Tx_data_frame.Frame_length+11;i++)																					
	//								USART1_send(USART1_TX_BUF[i]);
	//								UartWrite(&huart1,USART1_TX_BUF,Tx_data_frame.Frame_length+11);
									TerminalSlave485_Send_Data(USART1_TX_BUF,Tx_data_frame.Frame_length+11);
								}
								else//标定数据
								{
									//002A  54 0005 0000 
									data_frame.Carbration_len =MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+13);//标定数据长度（包括总包长度+子包长度）
									data_frame.Carbration_sum = (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+15)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+17);
									data_frame.Carbration_child =(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+19)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+21);
									//返回数据
									Return_Data = Read_Carlibration_data(data_frame.Frame_message_id,data_frame.Carbration_child,data_frame.Carbration_len);
									Tx_data_frame.Frame_addr = data_frame.Frame_addr;
									Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
									Tx_data_frame.Frame_data = Return_Data->data;
									Tx_data_frame.Frame_length = Return_Data->length;
									//应答
									USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok   3A
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2  0x47
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34  0x10
									MODBUS_S8_to_ASCII(data_frame.Frame_message_id>>8,USART1_TX_BUF+5); //0x41
									MODBUS_S8_to_ASCII(data_frame.Frame_message_id,USART1_TX_BUF+7); //0x80
									
									MODBUS_S8_to_ASCII(data_frame.Frame_length>>8,USART1_TX_BUF+9);//0x00
									MODBUS_S8_to_ASCII(data_frame.Frame_length,USART1_TX_BUF+11);//0x2A
									MODBUS_S8_to_ASCII(data_frame.Carbration_len,USART1_TX_BUF+13);//54
									
									MODBUS_S8_to_ASCII(data_frame.Carbration_sum>>8,USART1_TX_BUF+15);//0x00
									MODBUS_S8_to_ASCII(data_frame.Carbration_sum,USART1_TX_BUF+17);//0x03
									MODBUS_S8_to_ASCII(data_frame.Carbration_child>>8,USART1_TX_BUF+19);//0x00
									MODBUS_S8_to_ASCII(data_frame.Carbration_child,USART1_TX_BUF+21);//0x00
			
									memcpy(USART1_TX_BUF+23,Tx_data_frame.Frame_data,Tx_data_frame.Frame_length);
										Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,Tx_data_frame.Frame_length+22);
									MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+23+Tx_data_frame.Frame_length);
									USART1_TX_BUF[25+Tx_data_frame.Frame_length] = 0x0D;
									USART1_TX_BUF[26+Tx_data_frame.Frame_length] = 0x0A;  
									//开始发送
	//								for(i=0;i<(Tx_data_frame.Frame_length+27);i++)																					
	//									USART1_send(USART1_TX_BUF[i]);
	//								UartWrite(&huart1,USART1_TX_BUF,Tx_data_frame.Frame_length+27);
									TerminalSlave485_Send_Data(USART1_TX_BUF,Tx_data_frame.Frame_length+27);
								}
								
							}
							else if((Baseval_ID ==2)&&(data_frame.Frame_addr>=0x4b)&&(data_frame.Frame_addr<=0x4e))//0x47---0x4e
							{
	//							data_frame.Frame_data = Oil_Tx_Readpara(data_frame.Frame_message_id,data_frame.Frame_length);//返回具体的值  液位与压力
								if((uint8_t)data_frame.Frame_message_id!=0x80)//非标定数据
								{
									Return_Data = Oil_Tx_Readpara(data_frame.Frame_message_id,data_frame.Frame_length);//返回具体的值  液位与压力;
									//开始应答
									Tx_data_frame.Frame_addr = data_frame.Frame_addr;
									Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
									Tx_data_frame.Frame_length = Return_Data->length;//strlen(data_frame.Frame_data);
									Tx_data_frame.Frame_data = Return_Data->data;//data_frame.Frame_data;
									//开始组包
									USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok 
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length/2,USART1_TX_BUF+5);//56

									memcpy(USART1_TX_BUF+7,Tx_data_frame.Frame_data,Tx_data_frame.Frame_length);
									Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,Tx_data_frame.Frame_length+6);
									MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+Tx_data_frame.Frame_length+7);//56
									
									USART1_TX_BUF[Tx_data_frame.Frame_length+9] =0x0D;
									USART1_TX_BUF[Tx_data_frame.Frame_length+10] = 0x0A;
									//开始发送
	//								for(i=0;i<Tx_data_frame.Frame_length+11;i++)																					
	//								USART1_send(USART1_TX_BUF[i]);
	//								UartWrite(&huart1,USART1_TX_BUF,Tx_data_frame.Frame_length+11);
									TerminalSlave485_Send_Data(USART1_TX_BUF,Tx_data_frame.Frame_length+11);
								}
								else//标定数据
								{
									//002A  54 0005 0000 
									data_frame.Carbration_len =MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+13);//标定数据长度（包括总包长度+子包长度）
									data_frame.Carbration_sum = (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+15)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+17);
									data_frame.Carbration_child =(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+19)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+21);

									//返回数据
									Return_Data = Read_Carlibration_data(data_frame.Frame_message_id,data_frame.Carbration_child,data_frame.Carbration_len);
									Tx_data_frame.Frame_addr = data_frame.Frame_addr;
									Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
									Tx_data_frame.Frame_data = Return_Data->data;
									Tx_data_frame.Frame_length = Return_Data->length;
									//应答
									USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok   3A
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2  0x47
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34  0x10
									MODBUS_S8_to_ASCII(data_frame.Frame_message_id>>8,USART1_TX_BUF+5); //0x41
									MODBUS_S8_to_ASCII(data_frame.Frame_message_id,USART1_TX_BUF+7); //0x80
									
									MODBUS_S8_to_ASCII(data_frame.Frame_length>>8,USART1_TX_BUF+9);//0x00
									MODBUS_S8_to_ASCII(data_frame.Frame_length,USART1_TX_BUF+11);//0x2A
									MODBUS_S8_to_ASCII(data_frame.Carbration_len,USART1_TX_BUF+13);//54
									
									MODBUS_S8_to_ASCII(data_frame.Carbration_sum>>8,USART1_TX_BUF+15);//0x00
									MODBUS_S8_to_ASCII(data_frame.Carbration_sum,USART1_TX_BUF+17);//0x03
									MODBUS_S8_to_ASCII(data_frame.Carbration_child>>8,USART1_TX_BUF+19);//0x00
									MODBUS_S8_to_ASCII(data_frame.Carbration_child,USART1_TX_BUF+21);//0x00
			
									memcpy(USART1_TX_BUF+23,Tx_data_frame.Frame_data,Tx_data_frame.Frame_length);
										Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,Tx_data_frame.Frame_length+22);
									MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+23+Tx_data_frame.Frame_length);
									USART1_TX_BUF[25+Tx_data_frame.Frame_length] = 0x0D;
									USART1_TX_BUF[26+Tx_data_frame.Frame_length] = 0x0A;
									//开始发送
	//								for(i=0;i<(Tx_data_frame.Frame_length+27);i++)																					
	//									USART1_send(USART1_TX_BUF[i]);
	//								UartWrite(&huart1,USART1_TX_BUF,Tx_data_frame.Frame_length+27);
									TerminalSlave485_Send_Data(USART1_TX_BUF,Tx_data_frame.Frame_length+27);
								}
							}
							else if((Baseval_ID ==1)&&(data_frame.Frame_addr==TERMINAL_CONTROL_GET_SENSOR_D1))//||(data_frame.Frame_addr==TERMINAL_CONTROL_GET_SENSOR_D2))//0x91---0x92
							{
								data_frame.Frame_data = IO_Tx_Readpara(data_frame.Frame_message_id,data_frame.Frame_length);//IO-----阀门状态
								//开始应答
								Tx_data_frame.Frame_addr = data_frame.Frame_addr;
								Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
								Tx_data_frame.Frame_length = strlen((char*)data_frame.Frame_data);//
								Tx_data_frame.Frame_data = data_frame.Frame_data;
								//开始组包
								USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok 
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length/2,USART1_TX_BUF+5);//56

								memcpy(USART1_TX_BUF+7,Tx_data_frame.Frame_data,Tx_data_frame.Frame_length);
								Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,Tx_data_frame.Frame_length+6);
								MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+Tx_data_frame.Frame_length+7);//56
								
								USART1_TX_BUF[Tx_data_frame.Frame_length+9] =0x0D;
								USART1_TX_BUF[Tx_data_frame.Frame_length+10] = 0x0A;
								//开始发送
	//							for(i=0;i<Tx_data_frame.Frame_length+11;i++)																					
	//							USART1_send(USART1_TX_BUF[i]);
	//							UartWrite(&huart1,USART1_TX_BUF,Tx_data_frame.Frame_length+11);
								TerminalSlave485_Send_Data(USART1_TX_BUF,Tx_data_frame.Frame_length+11);
							}
							else if((Baseval_ID ==2)&&(data_frame.Frame_addr==TERMINAL_CONTROL_GET_SENSOR_D2))//||(data_frame.Frame_addr==TERMINAL_CONTROL_GET_SENSOR_D2))//0x91---0x92
							{
								data_frame.Frame_data = IO_Tx_Readpara(data_frame.Frame_message_id,data_frame.Frame_length);//IO-----阀门状态
								//开始应答
								Tx_data_frame.Frame_addr = data_frame.Frame_addr;
								Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
								Tx_data_frame.Frame_length = strlen((char*)data_frame.Frame_data);//
								Tx_data_frame.Frame_data = data_frame.Frame_data;
								//开始组包
								USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok 
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length/2,USART1_TX_BUF+5);//56

								memcpy(USART1_TX_BUF+7,Tx_data_frame.Frame_data,Tx_data_frame.Frame_length);
								Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,Tx_data_frame.Frame_length+6);
								MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+Tx_data_frame.Frame_length+7);//56
								
								USART1_TX_BUF[Tx_data_frame.Frame_length+9] =0x0D;
								USART1_TX_BUF[Tx_data_frame.Frame_length+10] = 0x0A;
								//开始发送
	//							for(i=0;i<Tx_data_frame.Frame_length+11;i++)																					
	//							USART1_send(USART1_TX_BUF[i]);
	//							UartWrite(&huart1,USART1_TX_BUF,Tx_data_frame.Frame_length+11);
								TerminalSlave485_Send_Data(USART1_TX_BUF,Tx_data_frame.Frame_length+11);
							}
						}
							break;
						case Set_para://应该可以通过  里面添加标定
						{
	//						uint8_t Set_flag=0;
							
							//读的寄存器号
							data_frame.Frame_message_id = (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+5)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+7);//获取寄存器的值
							//需要读的寄存器个数
							data_frame.Frame_length = (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+9)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+11);//获取寄存器的个数的值  28* 2=56
								//设置参数
							if(((Baseval_ID ==1)&&(data_frame.Frame_addr>=0x47)&&(data_frame.Frame_addr<=0x4a))\
								||((Baseval_ID ==2)&&(data_frame.Frame_addr>=0x4b)&&(data_frame.Frame_addr<=0x4e))\
								||(data_frame.Frame_addr>=0x40))
							{
							if((Baseval_ID ==1)&&(data_frame.Frame_addr>=0x47)&&(data_frame.Frame_addr<=0x4a))//0x47---0x4e
							{
								if((uint8_t)data_frame.Frame_message_id!=0x80)
	//								Set_flag = 
									Set_Oil_Paravalue(data_frame.Frame_message_id,data_frame.Frame_length,temp_dataFromUsart1+13);//设置油位传感器
								else//标定数据
								{
									data_frame.Carbration_len =MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+13);//标定数据长度（包括总包长度+子包长度）
									data_frame.Carbration_sum = (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+15)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+17);
									data_frame.Carbration_child =(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+19)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+21);
									//;
									//处理数据
									Calibration_Data.All_pack =data_frame.Carbration_sum;
									Calibration_Data.Child_pack_len[data_frame.Carbration_child] = data_frame.Carbration_len;
									
									Set_Carlibration_data(data_frame.Frame_message_id,data_frame.Carbration_child,data_frame.Frame_length,temp_dataFromUsart1+15);//ID  80  pack 第几包  length1当前报的长度  data数据
								}
							}
							else if((Baseval_ID ==2)&&(data_frame.Frame_addr>=0x4b)&&(data_frame.Frame_addr<=0x4e))//0x47---0x4e
							{
								if((uint8_t)data_frame.Frame_message_id!=0x80)
	//								Set_flag = 
									Set_Oil_Paravalue(data_frame.Frame_message_id,data_frame.Frame_length,temp_dataFromUsart1+13);//设置油位传感器
								else//标定数据
								{
									data_frame.Carbration_len =MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+13);//标定数据长度（包括总包长度+子包长度）
									data_frame.Carbration_sum = (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+15)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+17);
									data_frame.Carbration_child =(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+19)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+21);
									//;
									//处理数据
									Calibration_Data.All_pack =data_frame.Carbration_sum;
									Calibration_Data.Child_pack_len[data_frame.Carbration_child] = data_frame.Carbration_len;
									
									Set_Carlibration_data(data_frame.Frame_message_id,data_frame.Carbration_child,data_frame.Frame_length,temp_dataFromUsart1+15);//ID  80  pack 第几包  length1当前报的长度  data数据
								}
							}
							else if((Baseval_ID ==1)&&(data_frame.Frame_addr==TERMINAL_CONTROL_GET_SENSOR_D1))
							{
	//							Set_flag = 
								Set_Io_Paravalue(data_frame.Frame_message_id,data_frame.Frame_length,temp_dataFromUsart1+13);//设外接IO传感器
							}
							else if((Baseval_ID ==2)&&(data_frame.Frame_addr==0x92))
							{
	//							Set_flag = 
								Set_Io_Paravalue(data_frame.Frame_message_id,data_frame.Frame_length,temp_dataFromUsart1+13);//设外接IO传感器
							}
							else if(data_frame.Frame_addr==0x40)//下发解封码
							{
	//							Set_flag = 
								Get_Ask_code_value(data_frame.Frame_message_id,data_frame.Frame_length,temp_dataFromUsart1+13);
							}
							//数据应答
							if((uint8_t)data_frame.Frame_message_id!=0x80)//非标定数据的应答
							{
								//开始应答  4710 4734 001C 12  
								Tx_data_frame.Frame_addr = data_frame.Frame_addr;
								Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
								//开始组包
								USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok 
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34
								MODBUS_S8_to_ASCII(data_frame.Frame_message_id>>8,USART1_TX_BUF+5);
								MODBUS_S8_to_ASCII(data_frame.Frame_message_id,USART1_TX_BUF+7);
								MODBUS_S8_to_ASCII(data_frame.Frame_length>>8,USART1_TX_BUF+9);
								MODBUS_S8_to_ASCII(data_frame.Frame_length,USART1_TX_BUF+11);
					
								Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,12);
								MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+13);
								USART1_TX_BUF[15] = 0x0D;
								USART1_TX_BUF[16] = 0x0A;
								//开始发送
	//							for(i=0;i<17;i++)																					
	//								USART1_send(USART1_TX_BUF[i]);
	//							UartWrite(&huart1,USART1_TX_BUF,17);
								TerminalSlave485_Send_Data(USART1_TX_BUF,17);
							}
							else//标定数据的应答
							{
								Tx_data_frame.Frame_addr = data_frame.Frame_addr;
								Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
								//开始组包
								USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok   3A
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2  0x47
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34  0x10
								MODBUS_S8_to_ASCII(data_frame.Frame_message_id>>8,USART1_TX_BUF+5); //0x41
								MODBUS_S8_to_ASCII(data_frame.Frame_message_id,USART1_TX_BUF+7); //0x80
								
								MODBUS_S8_to_ASCII(data_frame.Frame_length>>8,USART1_TX_BUF+9);//0x00
								MODBUS_S8_to_ASCII(data_frame.Frame_length,USART1_TX_BUF+11);//0x2A
								MODBUS_S8_to_ASCII(data_frame.Carbration_len,USART1_TX_BUF+13);//54
								
								MODBUS_S8_to_ASCII(data_frame.Carbration_sum>>8,USART1_TX_BUF+15);//0x00
								MODBUS_S8_to_ASCII(data_frame.Carbration_sum,USART1_TX_BUF+17);//0x03
								MODBUS_S8_to_ASCII(data_frame.Carbration_child>>8,USART1_TX_BUF+19);//0x00
								MODBUS_S8_to_ASCII(data_frame.Carbration_child,USART1_TX_BUF+21);//0x00
		
								Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,22);
								MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+23);
								USART1_TX_BUF[25] = 0x0D;
								USART1_TX_BUF[26] = 0x0A;
								//开始发送
	//							for(i=0;i<27;i++)																					
	//								USART1_send(USART1_TX_BUF[i]);
	//							UartWrite(&huart1,USART1_TX_BUF,27);
								TerminalSlave485_Send_Data(USART1_TX_BUF,27);
								}
							}
						}
							break;
						case Update://升级
						{/*
							data_frame.Frame_message_id = (MODBUS_ASCII_AsciiToHex(temp_data+5)<<8)+MODBUS_ASCII_AsciiToHex(temp_data+7);
							data_frame.Frame_length = (MODBUS_ASCII_AsciiToHex(temp_data+9)<<8)+MODBUS_ASCII_AsciiToHex(temp_data+11);//获取寄存器的个数的值  28* 2=56
							//升级指令
							if(((Baseval_ID ==1)&&(((data_frame.Frame_addr>=0x47)&&(data_frame.Frame_addr<=0x4a))||(data_frame.Frame_addr ==TERMINAL_CONTROL_GET_SENSOR_D1)))\
								||((Baseval_ID ==2)&&(((data_frame.Frame_addr>=0x4b)&&(data_frame.Frame_addr<=0x4e))||(data_frame.Frame_addr ==TERMINAL_CONTROL_GET_SENSOR_D2))))
							{
							if(data_frame.Frame_message_id ==  0x0001 )
							{
								UP_date_flag = 1;
								Tx_data_frame.Frame_addr = data_frame.Frame_addr;
								Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
								Tx_data_frame.Frame_message_id = data_frame.Frame_message_id;
								Tx_data_frame.Frame_length = 1;
									//开始组包
								USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//3A
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//47
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//41
								MODBUS_S8_to_ASCII(data_frame.Frame_message_id>>8,USART1_TX_BUF+5);//00
								MODBUS_S8_to_ASCII(data_frame.Frame_message_id,USART1_TX_BUF+7);//01
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length>>8,USART1_TX_BUF+9);//00
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length,USART1_TX_BUF+11);//01
								MODBUS_S8_to_ASCII(0x00,USART1_TX_BUF+13);
								Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,14);
								MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+15);
								USART1_TX_BUF[17] =0x0D;
								USART1_TX_BUF[18] = 0x0A;
								//开始发送
	//							for(i=0;i<19;i++)																					
	//							USART1_send(USART1_TX_BUF[i]);
								UartWrite(&huart1,USART1_TX_BUF,19);
								//回复 00
							}
							//	删除原有程序
							else if(data_frame.Frame_message_id ==  0x0002 )
							{
	//							Read_Card_size();//检查SD卡的大小，删除不必要的文件
								//回复 00
								Tx_data_frame.Frame_addr = data_frame.Frame_addr;
								Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
								Tx_data_frame.Frame_message_id = data_frame.Frame_message_id;
								Tx_data_frame.Frame_length = 1;
									//开始组包
								USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok 
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34
								MODBUS_S8_to_ASCII(data_frame.Frame_message_id>>8,USART1_TX_BUF+5);
								MODBUS_S8_to_ASCII(data_frame.Frame_message_id,USART1_TX_BUF+7);
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length>>8,USART1_TX_BUF+9);
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length,USART1_TX_BUF+11);
								MODBUS_S8_to_ASCII(0x00,USART1_TX_BUF+13);
								Delete_BIN_data(data_frame.Frame_addr);//删除原有程序
								Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,14);
								MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+15);
								USART1_TX_BUF[17] =0x0D;
								USART1_TX_BUF[18] = 0x0A;
								//开始发送
	//							for(i=0;i<19;i++)																					
	//							USART1_send(USART1_TX_BUF[i]);
								UartWrite(&huart1,USART1_TX_BUF,19);
							}
							//接收升级包
							else if(data_frame.Frame_message_id ==  0x0003 )
							{
								uint32_t temp_SUM =0;
								//Updatadata
								Updatadata.All_pack_no = (MODBUS_ASCII_AsciiToHex(temp_data+13)<<8)+MODBUS_ASCII_AsciiToHex(temp_data+15);//2字节总包数
								Updatadata.pack_no = (MODBUS_ASCII_AsciiToHex(temp_data+17)<<8)+MODBUS_ASCII_AsciiToHex(temp_data+19);//2字节子包数
								if(Updatadata.pack_no == 0x0000)
								{
									Updatadata.Sum_all = (MODBUS_ASCII_AsciiToHex(temp_data+21)<<24)+(MODBUS_ASCII_AsciiToHex(temp_data+23)<<16)+(MODBUS_ASCII_AsciiToHex(temp_data+25)<<8)+MODBUS_ASCII_AsciiToHex(temp_data+27);//4字节校验和
									temp_SUM =0xff;
									tempupdate_sum =0;
								}
								else
								//校验 ok 回复00  error 回复02  接收失败 01
								//数据保存到SD卡
								{
									if(Updatadata.pack_no<=(Updatadata.All_pack_no))
									{
										temp_SUM = 	Save_Bin_Sd(data_frame.Frame_addr,temp_data+21, data_frame.Frame_length-4);// -4  
										if((temp_SUM!=0)&&(temp_SUM!=1))
											tempupdate_sum +=temp_SUM;
									}
								}
									Tx_data_frame.Frame_addr = data_frame.Frame_addr;
									Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
									Tx_data_frame.Frame_message_id = data_frame.Frame_message_id;
									Tx_data_frame.Frame_length = 1;
										//开始组包
									USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok 
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34
									MODBUS_S8_to_ASCII(data_frame.Frame_message_id>>8,USART1_TX_BUF+5);
									MODBUS_S8_to_ASCII(data_frame.Frame_message_id,USART1_TX_BUF+7);
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length>>8,USART1_TX_BUF+9);
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length,USART1_TX_BUF+11);
									if((temp_SUM!=0)&&(temp_SUM!=1))
										MODBUS_S8_to_ASCII(0x00,USART1_TX_BUF+13);
									else	
										MODBUS_S8_to_ASCII(0x01,USART1_TX_BUF+13);//接收失败
									Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,14);
									MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+15);
									USART1_TX_BUF[17] =0x0D;
									USART1_TX_BUF[18] = 0x0A;
									//开始发送
	//								for(i=0;i<19;i++)																					
	//								USART1_send(USART1_TX_BUF[i]);
									UartWrite(&huart1,USART1_TX_BUF,19);
							}
							//开始升级
							else if(data_frame.Frame_message_id ==  0x0004 )
							{
								UP_date_flag = 0;
								Tx_data_frame.Frame_addr = data_frame.Frame_addr;
								Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
								Tx_data_frame.Frame_message_id = data_frame.Frame_message_id;
								Tx_data_frame.Frame_length = 1;
									//开始组包
								USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok 
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34
								MODBUS_S8_to_ASCII(data_frame.Frame_message_id>>8,USART1_TX_BUF+5);
								MODBUS_S8_to_ASCII(data_frame.Frame_message_id,USART1_TX_BUF+7);
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length>>8,USART1_TX_BUF+9);
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length,USART1_TX_BUF+11);
								if(tempupdate_sum == Updatadata.Sum_all )
									MODBUS_S8_to_ASCII(0x00,USART1_TX_BUF+13);
								else
									MODBUS_S8_to_ASCII(0x02,USART1_TX_BUF+13);//回复校验码错误
								Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,14);
								MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+15);
								USART1_TX_BUF[17] =0x0D;
								USART1_TX_BUF[18] = 0x0A;
								UP_date_flag = 0;
								
								//开始发送
	//							for(i=0;i<19;i++)																					
	//							USART1_send(USART1_TX_BUF[i]);
								UartWrite(&huart1,USART1_TX_BUF,19);
								Read_update_sum = Read_Bin_Sd(data_frame.Frame_addr);
								if((tempupdate_sum == Updatadata.Sum_all )||(Read_update_sum == Updatadata.Sum_all ))
								{
									if((data_frame.Frame_addr == 0x47)||(data_frame.Frame_addr ==0x4B))//采集板升级
									{
	//									iap_jump(FLASH_IAP_ADDR);//后续升级
										 __set_FAULTMASK(1);//关闭总中断
										NVIC_SystemReset();//请求单片机重启
									}
									else
									{//升级信号板
										Read_Bin_to_Signle(Updatadata.Sum_all);
									}
								}
								else
									Delete_BIN_data(data_frame.Frame_addr);
							}
						}*/
						}
							break;
						case Read_Version://传感器基本信息上报   OK
						{
							if((Baseval_ID ==1)&&(data_frame.Frame_addr>=0x47)&&(data_frame.Frame_addr<=0x4a))//0x47---0x4e
							{
							//读的寄存器号
							data_frame.Frame_message_id = (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+5)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+7);//获取寄存器的值
							//需要读的寄存器个数
							data_frame.Frame_length = (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+9)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+11);//获取寄存器的个数的值
	//							data_frame.Frame_data 
							Return_Data = Version_Tx_Readvalue(data_frame.Frame_message_id,data_frame.Frame_length);//版本信息
								//开始应答
								Tx_data_frame.Frame_addr = data_frame.Frame_addr;
								Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
								Tx_data_frame.Frame_length = Return_Data->length;//strlen(data_frame.Frame_data);
								Tx_data_frame.Frame_data = Return_Data->data;//data_frame.Frame_data;
								//开始组包
								USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok 
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34
								MODBUS_S8_to_ASCII(data_frame.Frame_length>>8,USART1_TX_BUF+5);//56
								MODBUS_S8_to_ASCII(data_frame.Frame_length,USART1_TX_BUF+7);//78
								memcpy(USART1_TX_BUF+9,Tx_data_frame.Frame_data,Tx_data_frame.Frame_length);
								Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,Tx_data_frame.Frame_length+8);
								MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+Tx_data_frame.Frame_length+9);//56
								USART1_TX_BUF[Tx_data_frame.Frame_length+11] =0x0D;
								USART1_TX_BUF[Tx_data_frame.Frame_length+12] = 0x0A;
								//开始发送
	//							for(i=0;i<Tx_data_frame.Frame_length+13;i++)																					
	//							USART1_send(USART1_TX_BUF[i]);
								UartWrite(&huart1,USART1_TX_BUF,Tx_data_frame.Frame_length+13);
							}
							if((Baseval_ID ==2)&&(data_frame.Frame_addr>=0x4b)&&(data_frame.Frame_addr<=0x4e))//0x47---0x4e
							{
							//读的寄存器号
							data_frame.Frame_message_id = (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+5)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+7);//获取寄存器的值
							//需要读的寄存器个数
							data_frame.Frame_length = (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+9)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+11);//获取寄存器的个数的值
	//							data_frame.Frame_data 
							Return_Data = Version_Tx_Readvalue(data_frame.Frame_message_id,data_frame.Frame_length);//版本信息
								//开始应答
								Tx_data_frame.Frame_addr = data_frame.Frame_addr;
								Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
								Tx_data_frame.Frame_length = Return_Data->length;//strlen(data_frame.Frame_data);
								Tx_data_frame.Frame_data = Return_Data->data;//data_frame.Frame_data;
								//开始组包
								USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok 
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2
								MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34
								MODBUS_S8_to_ASCII(data_frame.Frame_length>>8,USART1_TX_BUF+5);//56
								MODBUS_S8_to_ASCII(data_frame.Frame_length,USART1_TX_BUF+7);//78
								memcpy(USART1_TX_BUF+9,Tx_data_frame.Frame_data,Tx_data_frame.Frame_length);
								Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,Tx_data_frame.Frame_length+8);
								MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+Tx_data_frame.Frame_length+9);//56
								USART1_TX_BUF[Tx_data_frame.Frame_length+11] =0x0D;
								USART1_TX_BUF[Tx_data_frame.Frame_length+12] = 0x0A;
								//开始发送
	//							for(i=0;i<Tx_data_frame.Frame_length+13;i++)																					
	//							USART1_send(USART1_TX_BUF[i]);
								UartWrite(&huart1,USART1_TX_BUF,Tx_data_frame.Frame_length+13);
							}
						}
							break;
						case Control_IO :
						{
							//后续再了解怎么做
						}
							break;
						case TEST_State ://测试通信状态是否正常
						{
							//回复 当前AD值  阀门状态   版本信息  
							
						}
							break;
						case PlatformTransfer :
						{
							if(data_frame.Frame_addr==0x61)//0x61
							{
								data_frame.Frame_length = (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+5)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+7);//获取寄存器的个数的值
								PlatformCalibrat.DeviceNum = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+9);
								PlatformCalibrat.FunctionCode = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+11);
								PlatformCalibrat.DeviceAddr = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+13);
//								Tx_data_frame.Frame_addr = data_frame.Frame_addr;
//								Tx_data_frame.Frame_funcode = data_frame.Frame_funcode;
//								Tx_data_frame.Frame_length = data_frame.Frame_length;
//								PlatformCalibrat.Restart_Function=MODBUS_ASCII_AsciiToHex(temp_data+9);
								switch(PlatformCalibrat.DeviceNum)
								{
									case 0://控制器
									{
										if(PlatformCalibrat.FunctionCode == 0x01)//restart
										{
											PlatformCalibrat.ReturnData = 0;
											MODBUS_S8_to_ASCII(PlatformCalibrat.ReturnData,USART1_TX_BUF);//0-1
											USART1_TX_BUF[2] =0x0D;
											USART1_TX_BUF[3] = 0x0A;
										//开始发送
											TerminalSlave485_Send_Data(USART1_TX_BUF,4);
											PlatformCalibrat.Restart_Controller=True;
										}
										else if(PlatformCalibrat.FunctionCode == 0x02)//set auto seal time //
										{
											PlatformCalibrat.ReturnData = 0;
											Config_info_all.Config_fun_id = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+17);
											Config_info_all.Auto_Seal_Time= (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+19)<<8)|MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+21);
											FM25L16B_WriteByte(ADDR_Config_fun_id,Config_info_all.Config_fun_id);
											FM25L16B_WriteByte(ADDR_AutoSealed_Time+0,(Config_info_all.Auto_Seal_Time>>8)&0xFF);
											FM25L16B_WriteByte(ADDR_AutoSealed_Time+1,Config_info_all.Auto_Seal_Time&0xFF);
											MODBUS_S8_to_ASCII(PlatformCalibrat.ReturnData,USART1_TX_BUF);//0-1
											USART1_TX_BUF[2] =0x0D;
											USART1_TX_BUF[3] = 0x0A;
											//开始发送
											TerminalSlave485_Send_Data(USART1_TX_BUF,4);
										}
										else //error
										{
											PlatformCalibrat.ReturnData = 1;
											MODBUS_S8_to_ASCII(PlatformCalibrat.ReturnData,USART1_TX_BUF);//0-1
											USART1_TX_BUF[2] =0x0D;
											USART1_TX_BUF[3] = 0x0A;
											//开始发送
											TerminalSlave485_Send_Data(USART1_TX_BUF,4);
										}
									}
									break;
									case 1://采集器
									{
										if(PlatformCalibrat.FunctionCode == 0x01)//restart
										{
											PlatformCalibrat.ReturnData = 0;
											MODBUS_S8_to_ASCII(PlatformCalibrat.ReturnData,USART1_TX_BUF);//0-1
											USART1_TX_BUF[2] =0x0D;
											USART1_TX_BUF[3] = 0x0A;
										//开始发送
											TerminalSlave485_Send_Data(USART1_TX_BUF,4);
											PlatformCalibrat.Restart_Collect=True;
										}
										else if(PlatformCalibrat.FunctionCode == 0x02)//set auto seal time
										{
											PlatformCalibrat.ReturnData = 0;
											PlatformCalibrat.Threshold_Angle=(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+15)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+17);//获取寄存器的值
											PlatformCalibrat.Times=(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+19)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+21);//获取寄存器的值
											USART1_TX_BUF[2] =0x0D;
											USART1_TX_BUF[3] = 0x0A;
											//开始发送
											TerminalSlave485_Send_Data(USART1_TX_BUF,4);
											PlatformCalibrat.StartCalibrat_Flag=True;
										}
										else //error
										{
											PlatformCalibrat.ReturnData = 1;
											MODBUS_S8_to_ASCII(PlatformCalibrat.ReturnData,USART1_TX_BUF);//0-1
											USART1_TX_BUF[2] =0x0D;
											USART1_TX_BUF[3] = 0x0A;
											//开始发送
											TerminalSlave485_Send_Data(USART1_TX_BUF,4);
										}
									}
									break;
									case 2://二合一
									{
										if(PlatformCalibrat.FunctionCode == 0x01)//restart
										{
											PlatformCalibrat.ReturnData = 0;
											MODBUS_S8_to_ASCII(PlatformCalibrat.ReturnData,USART1_TX_BUF);//0-1
											USART1_TX_BUF[2] =0x0D;
											USART1_TX_BUF[3] = 0x0A;
										//开始发送
											TerminalSlave485_Send_Data(USART1_TX_BUF,4);
											PlatformCalibrat.Restart_ErHeYi=True;
										}
										else if(PlatformCalibrat.FunctionCode == 0x02)//set auto seal time
										{
											PlatformCalibrat.ReturnData = 0;
											MODBUS_S8_to_ASCII(PlatformCalibrat.ReturnData,USART1_TX_BUF);//0-1
											USART1_TX_BUF[2] =0x0D;
											USART1_TX_BUF[3] = 0x0A;
										//开始发送
											TerminalSlave485_Send_Data(USART1_TX_BUF,4);
										}
										else
										{
											PlatformCalibrat.ReturnData = 1;
											MODBUS_S8_to_ASCII(PlatformCalibrat.ReturnData,USART1_TX_BUF);//0-1
											USART1_TX_BUF[2] =0x0D;
											USART1_TX_BUF[3] = 0x0A;
											//开始发送
											TerminalSlave485_Send_Data(USART1_TX_BUF,4);
										}
									}
									break;
									case 3://磁电编码器
									{
										if(PlatformCalibrat.FunctionCode == 0x01)//restart
										{
											PlatformCalibrat.ReturnData = 0;
											MODBUS_S8_to_ASCII(PlatformCalibrat.ReturnData,USART1_TX_BUF);//0-1
											USART1_TX_BUF[2] =0x0D;
											USART1_TX_BUF[3] = 0x0A;
										//开始发送
											TerminalSlave485_Send_Data(USART1_TX_BUF,4);
											PlatformCalibrat.Restart_Encoder=True;
										}
										else if(PlatformCalibrat.FunctionCode == 0x02)
										{
											PlatformCalibrat.ReturnData = 0;
											MODBUS_S8_to_ASCII(PlatformCalibrat.ReturnData,USART1_TX_BUF);//0-1
											USART1_TX_BUF[2] =0x0D;
											USART1_TX_BUF[3] = 0x0A;
										//开始发送
											TerminalSlave485_Send_Data(USART1_TX_BUF,4);
										}
										else if(PlatformCalibrat.FunctionCode == 0x03)
										{
											PlatformCalibrat.ReturnData = 0;
											MODBUS_S8_to_ASCII(PlatformCalibrat.ReturnData,USART1_TX_BUF);//0-1
											USART1_TX_BUF[2] =0x0D;
											USART1_TX_BUF[3] = 0x0A;
										//开始发送
											TerminalSlave485_Send_Data(USART1_TX_BUF,4);
										}
										else 
										{
											PlatformCalibrat.ReturnData = 1;
											MODBUS_S8_to_ASCII(PlatformCalibrat.ReturnData,USART1_TX_BUF);//0-1
											USART1_TX_BUF[2] =0x0D;
											USART1_TX_BUF[3] = 0x0A;
											//开始发送
											TerminalSlave485_Send_Data(USART1_TX_BUF,4);
										}
									}
									break;
								}
							}
						}
							break;
						 default:
							break;
					}////老协议的功能码--结束
				}////地址码或者功能码正确合法-----结束
				else if(data_frame.Frame_addr==0x00)
				{
					;//广播命令中抓取 速度，行驶里程
				}
				else
				{
					Sealing_Data.TerminalOnLineFlag = False;
				}
		  }//校验
		}////帧头正确--结束
//		memset(temp_data,0,600);
	}
	/*else
	{
		if(circle_send>=CIRCLE_SEND_TIME)
		{
			int len;
			circle_send=0;
			len = Assamble_Frame(USART1_TX_BUF);
			if(len>0)
			{
				TerminalSlave485_Send_Data(USART1_TX_BUF,len);
			}
		}
	}*/
}

uint32_t Serial_Num=0;
extern SDateTime m_datetime;
int32_t Assamble_Frame(uint8_t *buf)
{
	int storeNo;
	int len,lenstore;
	uint16_t crc;
	sNEIMENG_FRAME *frame_buf = (sNEIMENG_FRAME *)buf;
	//frame_buf->Frame_41 = 0x41;
	frame_buf->Frame_Identification = 0x93110000;
	frame_buf->Time[0] = m_datetime.year;
	frame_buf->Time[1] = m_datetime.month;
	frame_buf->Time[2] = m_datetime.day;
	frame_buf->Time[3] = m_datetime.hour;
	frame_buf->Time[4] = m_datetime.min;
	frame_buf->Time[5] = m_datetime.sec;
	memset(frame_buf->Frame_Head,0,16);
	len = WholeCarData(frame_buf->Data);
	for(storeNo=0;storeNo<StoreNumber;++storeNo)
	{
		lenstore = StoreData(frame_buf->Data+len,storeNo);
		if(lenstore>0)
		{
			len += lenstore;
		}
		else
		{
			break;
		}
	}
	Serial_Num += 1;
	frame_buf->Serial_Num = ((Serial_Num>>8)&0xff) | ((Serial_Num&0xff)<<8);
	frame_buf->Total_Packages = 0x100;
	frame_buf->Current_Package = 0x100;
	storeNo+=1;
	frame_buf->Message_Num = ((storeNo>>8)&0xff) | ((storeNo&0xff)<<8);
	len = len + ((uint32_t)frame_buf->Data - (uint32_t)&(frame_buf->Serial_Num));
	frame_buf->Frame_Len = ((len>>8)&0xff) | ((len&0xff)<<8);

	crc = CRC16_MODBUS(buf,len+6);
	buf[len+6] = crc&0xff;
	buf[len+7] = (crc>>8)&0xff;
	len +=8;
	return len;
}
/*
storeNo:从0开始
*/
int32_t StoreData(uint8_t *buf,int storeNo)
{
	int32_t ret=0;
	int ptr,i;
	sT2C_ALL_Sensor_Data_Each_Cang *p_Sensor[8] = {&T2C_ALL_Sensor_Data01,&T2C_ALL_Sensor_Data02,
	&T2C_ALL_Sensor_Data03,&T2C_ALL_Sensor_Data04,
	&T2C_ALL_Sensor_Data05,&T2C_ALL_Sensor_Data06,
	&T2C_ALL_Sensor_Data07,&T2C_ALL_Sensor_Data08};

	if(storeNo>StoreNumber)
		return ret;
	buf[ret++] = 0xA5; 
	//装卸油状态
	if(Full_Oil_allinfo.Loading_Oil_state&&(1<<storeNo))
	{
		buf[ret] = 0x01;
	}else if(Full_Oil_allinfo.Start_Decrease_flag&&(1<<storeNo))
	{
		buf[ret] = 0x02;
	}
	else
		buf[ret] = 0;
	++ret;

	if(Full_Oil_allinfo.Full_Oil_Mode)
	{
		buf[ret] = 0x02;
	}else
	{
		buf[ret] = 0x01;
	}

	++ret;

	if(Full_Oil_allinfo.Auto_sealedOK_ID&&(1<<storeNo))
	{
		buf[ret] = 0x01;
	}
	else if(Full_Oil_allinfo.Auto_Sealing_state&&(1<<storeNo))
	{
		buf[ret] = 0x02;
	}
	else if(Full_Oil_allinfo.Break_sealing_Id&&(1<<storeNo))
	{
		buf[ret] = 0x03;
	}
	else
	{
		buf[ret] = 0x02;
	}
	++ret;
	for(i=0;i<40;++i)
	{
		memcpy(buf+ret,&(p_Sensor[storeNo]->IO_Valve_Data_Every_Cang[i]),4);
		ret += 4;
	}
	return ret;
}
int32_t WholeCarData(uint8_t *buf)
{
	int32_t ret=0;
	int i=0;
	for(i=0;i<19;++i)
	{
		memcpy(buf,&(T2C_ALL_Sensor_WholeCar01.tiltXYZ[i]),4);
		ret += 4;
	}
	return ret;
}
//按照内蒙古协议格式化数据--整车数据
void FormatWholeCarData(void)
{
	int i_0x9b;	
	uni_float uni_0x9b;
	sT2C_ALL_Sensor_Data_WholeCar* pT2C_ALL_Sensor_Data0x9b;	

	pT2C_ALL_Sensor_Data0x9b=&T2C_ALL_Sensor_WholeCar01;
	
	memcpy(&USART1_TX_BUF[1],&USART1_RX_BUF[1],4);
	sprintf((char*)USART1_TX_BUF+5,"%02X",0x4a);//(16+4*33)/1
 	
	memcpy(&USART1_TX_BUF[1+6],pT2C_ALL_Sensor_Data0x9b->FrameHead,16);
	
	
	//pT2C_ALL_Sensor_Data0x9b->tiltXYZ[2]=98.76;//for test  仅用于测试
								 
	//3个浮点数转换
	for(i_0x9b=0;i_0x9b<3;i_0x9b++)
	{
		uni_0x9b.flo_Data=pT2C_ALL_Sensor_Data0x9b->tiltXYZ[i_0x9b];
		USART1_TX_BUF[17+0+i_0x9b*4+0+6]=uni_0x9b.array_u8[3];
		USART1_TX_BUF[17+0+i_0x9b*4+1+6]=uni_0x9b.array_u8[2];
		USART1_TX_BUF[17+0+i_0x9b*4+2+6]=uni_0x9b.array_u8[1];
		USART1_TX_BUF[17+0+i_0x9b*4+3+6]=uni_0x9b.array_u8[0];
	
	}
	
//pT2C_ALL_Sensor_Data0x9b->BeiDian_State_OnOff=0x11223346;//for test  仅用于测试
	uni_0x9b.u32Dat=pT2C_ALL_Sensor_Data0x9b->BeiDian_State_OnOff;//T2C_ALL_Sensor_Data01.ElecSealState;
	USART1_TX_BUF[17+12+0+6]=uni_0x9b.array_u8[3];
	USART1_TX_BUF[17+12+1+6]=uni_0x9b.array_u8[2];
	USART1_TX_BUF[17+12+2+6]=uni_0x9b.array_u8[1];
	USART1_TX_BUF[17+12+3+6]=uni_0x9b.array_u8[0];
	
	
	
	//pT2C_ALL_Sensor_Data0x9b->BeiDianDianLiang=78.95;//for test  仅用于测试
	
	uni_0x9b.flo_Data=pT2C_ALL_Sensor_Data0x9b->BeiDianDianLiang;//T2C_ALL_Sensor_Data01.ElecSealState;
	USART1_TX_BUF[17+16+0+6]=uni_0x9b.array_u8[3];
	USART1_TX_BUF[17+16+1+6]=uni_0x9b.array_u8[2];
	USART1_TX_BUF[17+16+2+6]=uni_0x9b.array_u8[1];
	USART1_TX_BUF[17+16+3+6]=uni_0x9b.array_u8[0];
  
	
	pT2C_ALL_Sensor_Data0x9b->YouQiHuiShou_State_OnOff=0x11223345;//for test  仅用于测试
	uni_0x9b.u32Dat=pT2C_ALL_Sensor_Data0x9b->YouQiHuiShou_State_OnOff;//T2C_ALL_Sensor_Data01.ElecSealState;
	USART1_TX_BUF[17+20+0+6]=uni_0x9b.array_u8[3];
	USART1_TX_BUF[17+20+1+6]=uni_0x9b.array_u8[2];
	USART1_TX_BUF[17+20+2+6]=uni_0x9b.array_u8[1];
	USART1_TX_BUF[17+20+3+6]=uni_0x9b.array_u8[0];
	
	
	
	//pT2C_ALL_Sensor_Data0x9b->YouQiHuiShou_State_Photo=0x11223344;//for test  仅用于测试
	uni_0x9b.u32Dat=pT2C_ALL_Sensor_Data0x9b->YouQiHuiShou_State_Photo;//T2C_ALL_Sensor_Data01.ElecSealState;
	USART1_TX_BUF[17+24+0+6]=uni_0x9b.array_u8[3];
	USART1_TX_BUF[17+24+1+6]=uni_0x9b.array_u8[2];
	USART1_TX_BUF[17+24+2+6]=uni_0x9b.array_u8[1];
	USART1_TX_BUF[17+24+3+6]=uni_0x9b.array_u8[0];
	
	
		//13个u32Dat转换
	for(i_0x9b=0;i_0x9b<13;i_0x9b++)
	{
		
		//pT2C_ALL_Sensor_Data0x9b->ResPara[i_0x9b]=0xaabbccdd+(i_0x9b+1);//*123.45f;//for test  仅用于测试
		uni_0x9b.u32Dat=pT2C_ALL_Sensor_Data0x9b->ResPara[i_0x9b];
		USART1_TX_BUF[17+28+i_0x9b*4+0+6]=uni_0x9b.array_u8[3];
		USART1_TX_BUF[17+28+i_0x9b*4+1+6]=uni_0x9b.array_u8[2];
		USART1_TX_BUF[17+28+i_0x9b*4+2+6]=uni_0x9b.array_u8[1];
		USART1_TX_BUF[17+28+i_0x9b*4+3+6]=uni_0x9b.array_u8[0];
	
	}
	
	
	Lrc_temp = MODBUS_Hex_GetLrc(USART1_TX_BUF+1,96+6);
	
	
	USART1_TX_BUF[97+6]=Lrc_temp;
	
	USART1_TX_BUF[98+7]=0x0d;
	USART1_TX_BUF[99+7]=0x0a;
	
	
	
	
	
}



//按照内蒙古协议格式化数据--单仓数据
//
void FormatEachStoreData(uint8_t storeNum)
{
int i_0x93;	
uni_float uni_0x93;
sT2C_ALL_Sensor_Data_Each_Cang* pT2C_ALL_Sensor_Data0x93;

	switch (storeNum)
  {
  	case 1:	pT2C_ALL_Sensor_Data0x93=&T2C_ALL_Sensor_Data01;
		
		  if((Full_Oil_allinfo.Auto_sealedOK_ID & 0x01) !=0 )
			{
				pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000001;//施封
			}
			else
			{
				if((Full_Oil_allinfo.Break_sealing_Id & 0x01) !=0)
				{
					pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000002;//破封
				}
				else
				{
					pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000000;//解封
				}
				
			}
			
  		break;
				
				
  	case 2:	pT2C_ALL_Sensor_Data0x93=&T2C_ALL_Sensor_Data02;
			
			if((Full_Oil_allinfo.Auto_sealedOK_ID & 0x02) !=0 )
			{
				pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000001;//施封
			}
			else
			{
				if((Full_Oil_allinfo.Break_sealing_Id & 0x02) !=0)
				{
					pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000002;//破封
				}
				else
				{
					pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000000;//解封
				}
				
			}
			
  		break;
  	case 3:	pT2C_ALL_Sensor_Data0x93=&T2C_ALL_Sensor_Data03;
			if((Full_Oil_allinfo.Auto_sealedOK_ID & 0x04) !=0 )
			{
				pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000001;//施封
			}
			else
			{
				if((Full_Oil_allinfo.Break_sealing_Id & 0x04) !=0)
				{
					pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000002;//破封
				}
				else
				{
					pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000000;//解封
				}
				
			}			
			
			
			
  		break;
  	case 4:	pT2C_ALL_Sensor_Data0x93=&T2C_ALL_Sensor_Data04;
			
			if((Full_Oil_allinfo.Auto_sealedOK_ID & 0x08) !=0 )
			{
				pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000001;//施封
			}
			else
			{
				if((Full_Oil_allinfo.Break_sealing_Id & 0x08) !=0)
				{
					pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000002;//破封
				}
				else
				{
					pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000000;//解封
				}
				
			}					
			
			
			
  		break;
		
  	case 5:	pT2C_ALL_Sensor_Data0x93=&T2C_ALL_Sensor_Data05;
			
			if((Full_Oil_allinfo.Auto_sealedOK_ID & 0x10) !=0 )
			{
				pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000001;//施封
			}
			else
			{
				if((Full_Oil_allinfo.Break_sealing_Id & 0x10) !=0)
				{
					pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000002;//破封
				}
				else
				{
					pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000000;//解封
				}
				
			}				
			
			
			
			
			
			
			
  		break;
  	case 6:	pT2C_ALL_Sensor_Data0x93=&T2C_ALL_Sensor_Data06;
			
			if((Full_Oil_allinfo.Auto_sealedOK_ID & 0x20) !=0 )
			{
				pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000001;//施封
			}
			else
			{
				if((Full_Oil_allinfo.Break_sealing_Id & 0x20) !=0)
				{
					pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000002;//破封
				}
				else
				{
					pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000000;//解封
				}
				
			}					
  		break;
  	case 7:	pT2C_ALL_Sensor_Data0x93=&T2C_ALL_Sensor_Data07;
			if((Full_Oil_allinfo.Auto_sealedOK_ID & 0x40) !=0 )
			{
				pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000001;//施封
			}
			else
			{
				if((Full_Oil_allinfo.Break_sealing_Id & 0x40) !=0)
				{
					pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000002;//破封
				}
				else
				{
					pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000000;//解封
				}
				
			}					
			
			
  		break;
  	case 8:	pT2C_ALL_Sensor_Data0x93=&T2C_ALL_Sensor_Data08;
			
			if((Full_Oil_allinfo.Auto_sealedOK_ID & 0x80) !=0 )
			{
				pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000001;//施封
			}
			else
			{
				if((Full_Oil_allinfo.Break_sealing_Id & 0x80) !=0)
				{
					pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000002;//破封
				}
				else
				{
					pT2C_ALL_Sensor_Data0x93->ElecSealState=0x00000000;//解封
				}
				
			}					
  		break;		
		
		
  	default:
  		break;
  }

	
									memcpy(&USART1_TX_BUF[1],&USART1_RX_BUF[1],4);
									sprintf((char*)USART1_TX_BUF+5,"%02X",0x4a);//(16+4*33)/1
	
	
									memcpy(&USART1_TX_BUF[1+6],pT2C_ALL_Sensor_Data0x93->FrameHead,16);
								 
								  //pT2C_ALL_Sensor_Data0x93->ElecSealState=0x12345678;
								  //memcpy(&USART1_TX_BUF[17],&T2C_ALL_Sensor_Data01.ElecSealState,4); //17--20
									
									//pT2C_ALL_Sensor_Data0x93->ElecSealState=0x1122aacc;//*123.45f;//for test  仅用于测试
								  uni_0x93.u32Dat=pT2C_ALL_Sensor_Data0x93->ElecSealState;//T2C_ALL_Sensor_Data01.ElecSealState;
									USART1_TX_BUF[17+0+6]=uni_0x93.array_u8[3];
									USART1_TX_BUF[17+1+6]=uni_0x93.array_u8[2];
									USART1_TX_BUF[17+2+6]=uni_0x93.array_u8[1];
									USART1_TX_BUF[17+3+6]=uni_0x93.array_u8[0];
								
								
								
									//memcpy(&USART1_TX_BUF[21],&T2C_ALL_Sensor_Data01.IO_Valve_Data_Every_Cang,21*4); //17--20
								
									//21个u32转换
									for(i_0x93=0;i_0x93<21;i_0x93++)
									{
										uni_0x93.u32Dat=pT2C_ALL_Sensor_Data0x93->IO_Valve_Data_Every_Cang[i_0x93];
										USART1_TX_BUF[21+0+i_0x93*4+0+6]=uni_0x93.array_u8[3];
										USART1_TX_BUF[21+0+i_0x93*4+1+6]=uni_0x93.array_u8[2];
										USART1_TX_BUF[21+0+i_0x93*4+2+6]=uni_0x93.array_u8[1];
										USART1_TX_BUF[21+0+i_0x93*4+3+6]=uni_0x93.array_u8[0];
									
									}
								
								
								  
                  //memcpy(&USART1_TX_BUF[21+84],&T2C_ALL_Sensor_Data01.MoniLiang_Data_Every_Cang,11*4); //17--20
								  
								 
								  //11个浮点数转换
									for(i_0x93=0;i_0x93<11;i_0x93++)
									{
										uni_0x93.flo_Data=pT2C_ALL_Sensor_Data0x93->MoniLiang_Data_Every_Cang[i_0x93];
										USART1_TX_BUF[21+84+i_0x93*4+0+6]=uni_0x93.array_u8[3];
										USART1_TX_BUF[21+84+i_0x93*4+1+6]=uni_0x93.array_u8[2];
										USART1_TX_BUF[21+84+i_0x93*4+2+6]=uni_0x93.array_u8[1];
										USART1_TX_BUF[21+84+i_0x93*4+3+6]=uni_0x93.array_u8[0];
									
									}
								
								
								
									//Lrc_temp = MODBUS_Hex_GetLrc(USART1_TX_BUF+1,148);//154
									Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,154);//154
									
								  //USART1_TX_BUF[149+6]=Lrc_temp;
									//sprintf(&USART1_TX_BUF[149+6],"%02X",Lrc_temp);
									sprintf((char*)USART1_TX_BUF+149+6,"%02X",Lrc_temp);
								  USART1_TX_BUF[LenthOf_Reply0x93-2]=0x0d;
								  USART1_TX_BUF[LenthOf_Reply0x93-1]=0x0a;
}

//数据的应答
/*******************************************************************************
* Function Name  : MODBUS_ASCII_GetLrc
* Description    : LRC校验
* Input          : pCyAsciiBuf--要校验的数组 cyLen--长度
* Output         : None
* Return         : cyLrcVal 校验后的值
*******************************************************************************/
uint8_t * Oil_Tx_Readvalue(uint8_t exaddr,uint16_t ID,uint16_t length)//读取液位的应答
{
	uint8_t  temp_buf[64]={0};
//	uint32_t sd003;//浮点数转换为实时显示的参数，4字节
//	float f000;//临时变量，存储倾角数据进行类型转换。--李伟
	
	// uint8_t id =ID ,00 -4Byte -高度AD值,02-4Byte-液体温度,04-环境温度，06-加油量，08-漏油量，0a-油箱油量，0c-压力/液位百分比，0e-液位高度
	switch(exaddr)
	{
		case 0x47://一仓数据   F3协议   第一仓的模拟量类传感器数据   1仓传感器数据 0x47数据帧
 			{
				
			//	if(1==1)
				{
				   
  	
           //第一点的温度数据  -最接近罐顶的
					uni_TempToPlatForm001.flo_Data=T2C_ALL_Sensor_Data01.MoniLiang_Data_Every_Cang[2];//ArrOfTempeSensor_Flo[0];//Stor[0].Temperature;
					
 					#if(En_AnHuiKaiLe==1)
						uni_TempToPlatForm001.flo_Data=16.01;
					#endif
					
					
					Oil_Data.Level_ADvalue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
					
					uni_TempToPlatForm001.flo_Data=T2C_ALL_Sensor_Data01.MoniLiang_Data_Every_Cang[3];//ArrOfTempeSensor_Flo[1];//Stor[1].Temperature;
					//Oil_Data.Liquid_Temp=uni_TempToPlatForm001.u32Dat;//Stor[1].Temperature;//0 ; //替换为第2个温度数据
					
					#if(En_AnHuiKaiLe==1)
						uni_TempToPlatForm001.flo_Data=16.01;
					#endif
					
					Oil_Data.Liquid_Temp=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
					
					
					#if(En_AnHuiKaiLe==1)
						uni_TempToPlatForm001.flo_Data=16.01;
					#endif					
					
					uni_TempToPlatForm001.flo_Data=T2C_ALL_Sensor_Data01.MoniLiang_Data_Every_Cang[4];//ArrOfTempeSensor_Flo[2];//Stor[2].Temperature;
					//Oil_Data.EnvTemperature=uni_TempToPlatForm001.u32Dat;//Stor[2].Temperature;//0 ; //环境温度替换为第3个温度数据
					Oil_Data.EnvTemperature=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
								 
				}
			/*	else
				{//测试代码
				
				  Oil_Data.Level_ADvalue=0x67 ; 
					Oil_Data.Liquid_Temp=0x76;//Stor[0].Temppretrua;
					Oil_Data.EnvTemperature=0x78;//Stor[0].Temppretrua;
						
				
				}*/
					
				 
					
				
				//20201219李伟同龚天平、张毅商量后更改；将加油量替换为倾角数据
					//Oil_Data.Add_oilvalue=0; 
//				  f000=Stor[0].QingJiaoFlo;   //倾角x
//				  Oil_Data.Add_oilvalue=(uint32_t)(f000);//单位就是自然单位度,不用除以10或者100.正常范围为0--359
				 
				
 
					uni_TempToPlatForm001.flo_Data=pT2C_ALL_Sensor_WholeCar->tiltXYZ[0];//16.01;
					////倾角传感器x
					Oil_Data.Add_oilvalue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
				
				
				  
				  //20210227根据戴永峰的协议修改——原来漏油量的位置变更为倾角2
				  //Oil_Data.Dec_oilvalue=0xAAAAAAAA;//漏油量此位暂时未用，设定为标记位，便于区分阅读0x56781234;
//					f000=Stor[1].QingJiaoFlo;   //倾角2
//				  Oil_Data.Dec_oilvalue=(uint32_t)(f000);//单位就是自然单位度,不用除以10或者100.正常范围为0--359
					//__nop();		

					uni_TempToPlatForm001.flo_Data=pT2C_ALL_Sensor_WholeCar->tiltXYZ[1];//16.01;98100;//
					//倾角传感器y
					Oil_Data.Dec_oilvalue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
				
  

					//uni_OilDensity001.flo_Data=-2.0f;//测试用
//					sd003=uni_OilDensity001.u32Dat;// u32上发至平台，解析为浮点数 
//					__nop();			    
//				  Oil_Data.Oil_boxvalue=sd003;//密度数据
					uni_TempToPlatForm001.flo_Data=0;
 		    
				  Oil_Data.Oil_boxvalue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);					
					//__nop();
				
          ////此位暂时未用，设定为标记位，便于区分阅读
					

					Oil_Data.LevelPercent_or_PressValue=0x55667799;//Stor[0].Press; //压力
					
					#if(En_AnHuiKaiLe==1)
						uni_TempToPlatForm001.flo_Data=98100.0;
					#endif
					uni_TempToPlatForm001.flo_Data=0.0;
					
					Oil_Data.LevelPercent_or_PressValue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
																	
																	
 				
				
				  //液位高度					
					//uni_YeweiToPlatForm001.flo_Data=
				  //Oil_Data.Level_value=Stor[0].yewei[0];
				  //Oil_Data.Level_value=uni_YeweiToPlatForm001.u32Dat;//Stor[0].yewei[0];
					
					uni_YeweiToPlatForm001.flo_Data=T2C_ALL_Sensor_Data01.MoniLiang_Data_Every_Cang[0];
					
					
					Oil_Data.Level_value=(uni_YeweiToPlatForm001.farray[3]<<24) | (uni_YeweiToPlatForm001.farray[2]<<16)  \
																	| (uni_YeweiToPlatForm001.farray[1]<<8) | (uni_YeweiToPlatForm001.farray[0]);
																	
					
					//__nop();
				  //Oil_Data.Level_value=uni_LiqLev001.flo_Data;
			}
		break;
			
		case 0x48://二仓数据
//		case 0x4C:
		{
//					Oil_Data.Level_ADvalue=0 ; 
//					Oil_Data.Liquid_Temp=Stor[1].Temperature;
//					Oil_Data.EnvTemperature=Stor[1].Temperature;
			    uni_TempToPlatForm001.flo_Data=T2C_ALL_Sensor_Data02.MoniLiang_Data_Every_Cang[2];
					Oil_Data.Level_ADvalue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);

			    uni_TempToPlatForm001.flo_Data=T2C_ALL_Sensor_Data02.MoniLiang_Data_Every_Cang[3];
					Oil_Data.Liquid_Temp=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
			
			    uni_TempToPlatForm001.flo_Data=T2C_ALL_Sensor_Data02.MoniLiang_Data_Every_Cang[4];
					Oil_Data.EnvTemperature=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);			
			
			
//					Oil_Data.Add_oilvalue=0; 
//					Oil_Data.Dec_oilvalue=0;
			
//				  f000=Stor[0].QingJiaoFlo;   //倾角
//				  Oil_Data.Add_oilvalue=(uint32_t)(f000);//单位就是自然单位度,不用除以10或者100.正常范围为0--359
//				  __nop();
//				  
//				  //20210227根据戴永峰的协议修改——原来漏油量的位置变更为倾角2
//				  //Oil_Data.Dec_oilvalue=0xAAAAAAAA;//漏油量此位暂时未用，设定为标记位，便于区分阅读0x56781234;
//					f000=Stor[1].QingJiaoFlo;   //倾角2
//				  Oil_Data.Dec_oilvalue=(uint32_t)(f000);//单位就是自然单位度,不用除以10或者100.正常范围为0--359
//					__nop();	



 
				 // __nop();
				
 
					uni_TempToPlatForm001.flo_Data=pT2C_ALL_Sensor_WholeCar->tiltXYZ[0];//16.01;
					////倾角传感器x
					Oil_Data.Add_oilvalue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
				
 
					//__nop();		

					uni_TempToPlatForm001.flo_Data=pT2C_ALL_Sensor_WholeCar->tiltXYZ[1];//16.01;98100;//
					//倾角传感器y
					Oil_Data.Dec_oilvalue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
																	
																	
					
					
//					Oil_Data.Oil_boxvalue=Stor[1].Volume;   
//					//Oil_Data.LevelPercent_or_PressValue=0x556677bb;//Stor[1].Press;

					uni_TempToPlatForm001.flo_Data=0.0; 		    
				  Oil_Data.Oil_boxvalue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);	
					
					uni_TempToPlatForm001.flo_Data=0;					
					Oil_Data.LevelPercent_or_PressValue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
																	
						
						
						
			
			    uni_TempToPlatForm002.flo_Data=T2C_ALL_Sensor_Data02.MoniLiang_Data_Every_Cang[0];
					Oil_Data.Level_value=(uni_YeweiToPlatForm002.farray[3]<<24) | (uni_YeweiToPlatForm002.farray[2]<<16)  \
												| (uni_YeweiToPlatForm002.farray[1]<<8) | (uni_YeweiToPlatForm002.farray[0]);
					//Oil_Data.Level_value=Stor[1].yewei[0];
			    
		}
		break;
		case 0x49://三仓数据
{
				
				//if(1==1)
				{
				   
  	
           //第一点的温度数据  -最接近罐顶的
					uni_TempToPlatForm001.flo_Data=T2C_ALL_Sensor_Data03.MoniLiang_Data_Every_Cang[2];//ArrOfTempeSensor_Flo[0];//Stor[0].Temperature;
					
 					#if(En_AnHuiKaiLe==1)
						uni_TempToPlatForm001.flo_Data=16.01;
					#endif
					
					
					Oil_Data.Level_ADvalue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
										
					uni_TempToPlatForm001.flo_Data=T2C_ALL_Sensor_Data03.MoniLiang_Data_Every_Cang[3];//ArrOfTempeSensor_Flo[1];//Stor[1].Temperature;
					//Oil_Data.Liquid_Temp=uni_TempToPlatForm001.u32Dat;//Stor[1].Temperature;//0 ; //替换为第2个温度数据
					
					#if(En_AnHuiKaiLe==1)
						uni_TempToPlatForm001.flo_Data=16.01;
					#endif
					
					Oil_Data.Liquid_Temp=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
					
										
					#if(En_AnHuiKaiLe==1)
						uni_TempToPlatForm001.flo_Data=16.01;
					#endif					
					
					uni_TempToPlatForm001.flo_Data=T2C_ALL_Sensor_Data03.MoniLiang_Data_Every_Cang[4];//ArrOfTempeSensor_Flo[2];//Stor[2].Temperature;
					//Oil_Data.EnvTemperature=uni_TempToPlatForm001.u32Dat;//Stor[2].Temperature;//0 ; //环境温度替换为第3个温度数据
					Oil_Data.EnvTemperature=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
									 
				}
				/*else
				{//测试代码
				
				  Oil_Data.Level_ADvalue=0x67 ; 
					Oil_Data.Liquid_Temp=0x76;//Stor[0].Temppretrua;
					Oil_Data.EnvTemperature=0x78;//Stor[0].Temppretrua;
						
				
				}*/
					
				//20201219李伟同龚天平、张毅商量后更改；将加油量替换为倾角数据
					//Oil_Data.Add_oilvalue=0; 
//				  f000=Stor[0].QingJiaoFlo;   //倾角x
//				  Oil_Data.Add_oilvalue=(uint32_t)(f000);//单位就是自然单位度,不用除以10或者100.正常范围为0--359
			
					uni_TempToPlatForm001.flo_Data=pT2C_ALL_Sensor_WholeCar->tiltXYZ[0];//16.01;
					////倾角传感器x
					Oil_Data.Add_oilvalue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
				
				
				  
				  //20210227根据戴永峰的协议修改——原来漏油量的位置变更为倾角2
				  //Oil_Data.Dec_oilvalue=0xAAAAAAAA;//漏油量此位暂时未用，设定为标记位，便于区分阅读0x56781234;
//					f000=Stor[1].QingJiaoFlo;   //倾角2
//				  Oil_Data.Dec_oilvalue=(uint32_t)(f000);//单位就是自然单位度,不用除以10或者100.正常范围为0--359
					
					uni_TempToPlatForm001.flo_Data=pT2C_ALL_Sensor_WholeCar->tiltXYZ[1];//16.01;98100;//
					//倾角传感器y
					Oil_Data.Dec_oilvalue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
				
  

					//uni_OilDensity001.flo_Data=-2.0f;//测试用
//					sd003=uni_OilDensity001.u32Dat;// u32上发至平台，解析为浮点数 
//					__nop();			    
//				  Oil_Data.Oil_boxvalue=sd003;//密度数据
					uni_TempToPlatForm001.flo_Data=0.0;
 		    
				  Oil_Data.Oil_boxvalue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);					
			
          ////此位暂时未用，设定为标记位，便于区分阅读
					
					Oil_Data.LevelPercent_or_PressValue=0x55667799;//Stor[0].Press; //压力
					
					#if(En_AnHuiKaiLe==1)
						uni_TempToPlatForm001.flo_Data=98100.0;
					#endif
					uni_TempToPlatForm001.flo_Data=0.0;
					
					Oil_Data.LevelPercent_or_PressValue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
																	
																	
 				
				
				  //液位高度					
					//uni_YeweiToPlatForm001.flo_Data=
				  //Oil_Data.Level_value=Stor[0].yewei[0];
				  //Oil_Data.Level_value=uni_YeweiToPlatForm001.u32Dat;//Stor[0].yewei[0];
					
					//uni_YeweiToPlatForm001.flo_Data=T2C_ALL_Sensor_Data03.MoniLiang_Data_Every_Cang[0];
					
					
					Oil_Data.Level_value=(uni_YeweiToPlatForm003.farray[3]<<24) | (uni_YeweiToPlatForm003.farray[2]<<16)  \
																	| (uni_YeweiToPlatForm003.farray[1]<<8) | (uni_YeweiToPlatForm003.farray[0]);
																	
					
				  //Oil_Data.Level_value=uni_LiqLev001.flo_Data;
			}
			break;
		case 0x4A://四仓数据
{
				
				//if(1==1)
				{
				   
  	
           //第一点的温度数据  -最接近罐顶的
					uni_TempToPlatForm001.flo_Data=T2C_ALL_Sensor_Data04.MoniLiang_Data_Every_Cang[2];//ArrOfTempeSensor_Flo[0];//Stor[0].Temperature;
					
 					#if(En_AnHuiKaiLe==1)
						uni_TempToPlatForm001.flo_Data=16.01;
					#endif
					
					
					Oil_Data.Level_ADvalue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
					
					uni_TempToPlatForm001.flo_Data=T2C_ALL_Sensor_Data04.MoniLiang_Data_Every_Cang[3];//ArrOfTempeSensor_Flo[1];//Stor[1].Temperature;
					//Oil_Data.Liquid_Temp=uni_TempToPlatForm001.u32Dat;//Stor[1].Temperature;//0 ; //替换为第2个温度数据
					
					#if(En_AnHuiKaiLe==1)
						uni_TempToPlatForm001.flo_Data=16.01;
					#endif
					
					Oil_Data.Liquid_Temp=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
						
					
					#if(En_AnHuiKaiLe==1)
						uni_TempToPlatForm001.flo_Data=16.01;
					#endif					
					
					uni_TempToPlatForm001.flo_Data=T2C_ALL_Sensor_Data04.MoniLiang_Data_Every_Cang[4];//ArrOfTempeSensor_Flo[2];//Stor[2].Temperature;
					//Oil_Data.EnvTemperature=uni_TempToPlatForm001.u32Dat;//Stor[2].Temperature;//0 ; //环境温度替换为第3个温度数据
					Oil_Data.EnvTemperature=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
					
				}
				/*else
				{//测试代码
				
				  Oil_Data.Level_ADvalue=0x67 ; 
					Oil_Data.Liquid_Temp=0x76;//Stor[0].Temppretrua;
					Oil_Data.EnvTemperature=0x78;//Stor[0].Temppretrua;
				}*/
					
				 
					
				
				//20201219李伟同龚天平、张毅商量后更改；将加油量替换为倾角数据
					//Oil_Data.Add_oilvalue=0; 
//				  f000=Stor[0].QingJiaoFlo;   //倾角x
//				  Oil_Data.Add_oilvalue=(uint32_t)(f000);//单位就是自然单位度,不用除以10或者100.正常范围为0--359
			 
					uni_TempToPlatForm001.flo_Data=pT2C_ALL_Sensor_WholeCar->tiltXYZ[0];//16.01;
					////倾角传感器x
					Oil_Data.Add_oilvalue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
				
				
				  
				  //20210227根据戴永峰的协议修改——原来漏油量的位置变更为倾角2
				  //Oil_Data.Dec_oilvalue=0xAAAAAAAA;//漏油量此位暂时未用，设定为标记位，便于区分阅读0x56781234;
//					f000=Stor[1].QingJiaoFlo;   //倾角2
//				  Oil_Data.Dec_oilvalue=(uint32_t)(f000);//单位就是自然单位度,不用除以10或者100.正常范围为0--359
					
					uni_TempToPlatForm001.flo_Data=pT2C_ALL_Sensor_WholeCar->tiltXYZ[1];//16.01;98100;//
					//倾角传感器y
					Oil_Data.Dec_oilvalue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
				
  

					//uni_OilDensity001.flo_Data=-2.0f;//测试用
//					sd003=uni_OilDensity001.u32Dat;// u32上发至平台，解析为浮点数 
//					__nop();			    
//				  Oil_Data.Oil_boxvalue=sd003;//密度数据
					uni_TempToPlatForm001.flo_Data=0;
 		    
				  Oil_Data.Oil_boxvalue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);					
					__nop();
				
          ////此位暂时未用，设定为标记位，便于区分阅读
					

					Oil_Data.LevelPercent_or_PressValue=0x55667799;//Stor[0].Press; //压力
					
					#if(En_AnHuiKaiLe==1)
						uni_TempToPlatForm001.flo_Data=98100.0;
					#endif
					uni_TempToPlatForm001.flo_Data=0;
					
					Oil_Data.LevelPercent_or_PressValue=(uni_TempToPlatForm001.farray[3]<<24) | (uni_TempToPlatForm001.farray[2]<<16)  \
																	| (uni_TempToPlatForm001.farray[1]<<8) | (uni_TempToPlatForm001.farray[0]);
																	
																	
 				
				
				  //液位高度					
					//uni_YeweiToPlatForm001.flo_Data=
				  //Oil_Data.Level_value=Stor[0].yewei[0];
				  //Oil_Data.Level_value=uni_YeweiToPlatForm001.u32Dat;//Stor[0].yewei[0];
					
					//uni_YeweiToPlatForm001.flo_Data=T2C_ALL_Sensor_Data04.MoniLiang_Data_Every_Cang[0];
					
					
					Oil_Data.Level_value=(uni_YeweiToPlatForm004.farray[3]<<24) | (uni_YeweiToPlatForm004.farray[2]<<16)  \
																	| (uni_YeweiToPlatForm004.farray[1]<<8) | (uni_YeweiToPlatForm004.farray[0]);
																	
				  //Oil_Data.Level_value=uni_LiqLev001.flo_Data;
			}
		break;
		case 0x4B:
		{
					Oil_Data.Level_ADvalue=0 ; 
					Oil_Data.Liquid_Temp=Stor[4].Temperature;
					Oil_Data.EnvTemperature=Stor[4].Temperature;
					Oil_Data.Add_oilvalue=0; 
					Oil_Data.Dec_oilvalue=0;
					Oil_Data.Oil_boxvalue=Stor[4].Volume;   
					Oil_Data.LevelPercent_or_PressValue=Stor[4].Press; 
					Oil_Data.Level_value=Stor[4].yewei[0];
		}
		break;
		default:break;
	}
	//Oil_Data.Level_ADvalue   4字节，最高位的一个字节的最高位的bit7为1则为重要数据
	//组成数据包
	MODBUS_S32_to_ASCII(Oil_Data.Level_ADvalue, temp_buf);
	
	MODBUS_S32_to_ASCII(Oil_Data.Level_ADvalue, temp_buf);

	MODBUS_S32_to_ASCII(Oil_Data.Liquid_Temp,temp_buf+8);

	MODBUS_S32_to_ASCII(Oil_Data.EnvTemperature,temp_buf+16);

	MODBUS_S32_to_ASCII(Oil_Data.Add_oilvalue,temp_buf+24);

	MODBUS_S32_to_ASCII(Oil_Data.Dec_oilvalue,temp_buf+32);
	
	MODBUS_S32_to_ASCII(Oil_Data.Oil_boxvalue,temp_buf+40);
	
	MODBUS_S32_to_ASCII(Oil_Data.LevelPercent_or_PressValue,temp_buf+48);
	
	MODBUS_S32_to_ASCII(Oil_Data.Level_value,temp_buf+56);

	//从固定长度中截取数据,取出指定的寄存器的值
	if((uint8_t)ID<=0x0e)
	{
		if((length >0)&&(length<=(16-((uint8_t)ID))))
			 memcpy(temp_buf2,temp_buf+((uint8_t)ID*4),length*4);
	}
	return temp_buf2;
}



///*******************************************************************************
//* Function Name  : MODBUS_ASCII_GetLrc
//* Description    : LRC校验
//* Input          : pCyAsciiBuf--要校验的数组 cyLen--长度
//* Output         : None
//* Return         : cyLrcVal 校验后的值
//*******************************************************************************/
uint8_t Var_data_flag = 0;
uint32_t TTTTemp_data[2][8];
extern uni_float  tmp_uni_trans;
uint8_t  temp_buf_Tx_Read[137]={0};//大小+1  136

Return_data * IO_Tx_Readvalue(uint16_t ID,uint16_t length)//读取IO阀门开关的应答
{
	
	static Return_data temp;
	uint8_t  i;
	// uint8_t id =ID ,00 -4Byte -高度AD值,02-4Byte-液体温度,04-环境温度，06-加油量，08-漏油量，0a-油箱油量，0c-压力/液位百分比，0e-液位高度
	#if 1
	#if 1
	   //StoreNumber = 1;   // for debug !  temp modify for test by Daiyf.
	#endif
//	 IO_Date.IO_allnum = 4 * StoreNumber;			//IO总数  m uint8_t
//	 IO_Date.IO_statenum = 1;//IO_Date.IO_allnum/32+1;	//IO状态组数   n(1~8)  n=(m/32)+1       uint8_t
//	
	
	//20210222李伟修改，根据张毅的反馈，按照新疆现场实际情况修改。一个仓，3个泄油阀，一个海底阀，2个大盖，2个小盖
	IO_Date.IO_allnum = 8;// 1+3+2+2  海底阀  泄油阀 大盖   小盖 
	IO_Date.IO_statenum = 3;//取实际种类的最大值。泄油阀数量为3
	
	
	#else
	 IO_Date.IO_allnum = 4* 4;			//IO总数  m uint8_t
	 IO_Date.IO_statenum = 3;	//IO状态组数  
	#endif
/*
	if((IO_Date.IO_allnum/32)<1)
	{
		for(i=0;i<StoreNumber;i++)
		{
			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_normalstate[0] &=~a;//置0，取消异常
			}
			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] &=~a;//把当前位置0
				IO_Date.IO_state[0] |= Statetemp.rkg[i] <<(i*4+1);//获取当前位的值
				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);
				IO_Date.IO_state[0] &=~a;//把当前位置0
				IO_Date.IO_state[0] |= Statetemp.xyf[i]<<(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_normalstate[0] &=~a;//置0，取消异常
			}
		}
  }
*/
//IO_Date.IO_normaldata=1;//1:带有正常异常数据    0:不带
	for(i=0;i<StoreNumber;i++)
	{
		if(IO_Date.Updata_TempVar[i] == 1)
		{
			if((Full_Oil_allinfo.Break_sealing_Id&(1<<i))==(1<<i))
			{
					IO_Date.Updata_TempVar[i] = 0;
					IO_Date.IO_state[0] = IO_Date.Temp_IO_state[0];
			}
		}
	}
	if(IO_Date.IO_normalstate[0]>0)
	{
		if(TTTTemp_data[0][1]!=IO_Date.IO_normalstate[0])//异常状态改变
		{
			TTTTemp_data[0][1] = IO_Date.IO_normalstate[0];
			Var_data_flag = 0;
		}
		IO_Date.IO_normaldata=1;		//正常或者异常数据  0/1           uint8_t  带有异常数据
		//开或者异常
		if(Var_data_flag == 0)
		{
			IO_Date.IO_emergencyflag |=1<<7;					//重要数据标识  bit7  0/1  bit 1作为语音报警  uint8_t
			Var_data_flag = 1;
		}
		else
		{
			IO_Date.IO_emergencyflag &=~(0x80);//同一个报警已经上去了，不在一直报警
		}
//		IO_Date.IO_emergencyflag = 0;//测数据，最后删除
	}
	else
	{
		IO_Date.IO_normaldata=0;   //不带异常数据
		if(IO_Date.IO_state[0]>0)
		{
				if(TTTTemp_data[0][0]!=IO_Date.IO_state[0])//状态改变
				{
					TTTTemp_data[0][0] = IO_Date.IO_state[0];
					Var_data_flag = 0;
				}
				if(Var_data_flag == 0)
				{
					IO_Date.IO_emergencyflag |=1<<7;	//开关打开  重要数据
					Var_data_flag = 1;
				}
				else
				{
					IO_Date.IO_emergencyflag &=~(0x80);
				}
		}
		else
		{
			if(Var_data_flag ==1 )
				Var_data_flag = 0;
			IO_Date.IO_emergencyflag &=~(0x80);	//非重要数据
		}
	}
	
	//组成数据包
	MODBUS_S8_to_ASCII(IO_Date.IO_emergencyflag ,temp_buf_Tx_Read );//重要数据 1字节
	
	MODBUS_S8_to_ASCII(IO_Date.IO_allnum ,temp_buf_Tx_Read+2 );//IO总数  1字节
	
	MODBUS_S8_to_ASCII(IO_Date.IO_normaldata ,temp_buf_Tx_Read+4 );//是否有正常异常标识
	
	MODBUS_S8_to_ASCII(IO_Date.IO_statenum ,temp_buf_Tx_Read+6 );//IO状态的字节组数  没超过32个开关就是1组
	
	for(i=0;i<IO_Date.IO_statenum;i++)//正常状态
	{
		MODBUS_S32_to_ASCII(IO_Date.IO_state[i], temp_buf_Tx_Read+8+(i*8));
	}
//	if(IO_Date.IO_normaldata == 1)//带有异常数据
//	{
		for(i=0;i<IO_Date.IO_statenum;i++)//异常状态
		{
			MODBUS_S32_to_ASCII(IO_Date.IO_normalstate[i], temp_buf_Tx_Read+8+IO_Date.IO_statenum*8+(i*8));
		}
//	}

/********                扩展91的返回报文数据由12增加至36个，补足不用的数据为0，modify by Daiyf at 2021-1-28 	                 ********/
#if 1	 
	#if 0	
	 uint8_t j,k;
		
	 j= 4;//IO_Date.IO_statenum * 3;
		k=0;
	 for(i=0;i<j;i++)
	   {
			 //1.正常状态  ...temp test data!
       IO_Date.IO_state[i] = 0x00000000;

		   MODBUS_S32_to_ASCII(IO_Date.IO_state[i], temp_buf+8+(i*8)+k);
			 k += 8;
			 //2.异常状态 ...temp test data!
			 IO_Date.IO_normalstate[i] = 0x00000000;

			 MODBUS_S32_to_ASCII(IO_Date.IO_normalstate[i], temp_buf+IO_Date.IO_statenum*8+(i*8)+k);
     
	   }
	#else
//	 uint8_t j=0,k =0;
//	 uint32_t tmp_val=0;	
//	 k= 8;//IO_Date.IO_statenum * 3;
	 
	 //按照新的协议0x0020----直接修改32字节的io状态    李修改伟20211016
	 
	 
   //memcpy(Array_Of_Valve,"0123456789ABCDEF1111222233334444",32);    // for debug !  temp modify for test by Daiyf.
//	 for(i=0;i<k;i++)
//	   {//0x91查询阀门状态指令
//        j = i * 4;  
//       tmp_val= (Array_Of_Valve[j] <<24 | Array_Of_Valve[j+1] <<16 | Array_Of_Valve[j+2] << 8 | Array_Of_Valve[j+3]);
//			 
//			 //tmp_val= (Array_Of_Valve[j+3] <<24 | Array_Of_Valve[j+2] <<16 | Array_Of_Valve[j+1] << 8 | Array_Of_Valve[j+0]);
//		   MODBUS_S32_to_ASCII(tmp_val, temp_buf+8+(i*8));
//      
//	   }
			 
		IO_OnOff_StateArr[0]=IO_OnOff_State01;
		IO_OnOff_StateArr[1]=IO_OnOff_State02;
		IO_OnOff_StateArr[2]=IO_OnOff_State03;
		IO_OnOff_StateArr[3]=IO_OnOff_State04;
		
		IO_Exception_StateArr[0]=IO_Exception_State01;
		IO_Exception_StateArr[1]=IO_Exception_State02;
		IO_Exception_StateArr[2]=IO_Exception_State03;
		IO_Exception_StateArr[3]=IO_Exception_State04;
		
		
#if 0			 
	//第一组异常状态----1-8仓
		//IO_Exception_State01=0xaabbccdd;//仅供测试
		tmp_uni_trans.u32Dat=IO_Exception_State01;
		Array_Of_Valve[7+8*0]=tmp_uni_trans.array_u8[0];
		Array_Of_Valve[6+8*0]=tmp_uni_trans.array_u8[1];
		Array_Of_Valve[5+8*0]=tmp_uni_trans.array_u8[2];
		Array_Of_Valve[4+8*0]=tmp_uni_trans.array_u8[3];
		
		
		////第一组开关状态----1-8仓
		//IO_OnOff_State01=0x55667788;//仅供测试
		tmp_uni_trans.u32Dat=IO_OnOff_State01;
		Array_Of_Valve[3+8*0]=tmp_uni_trans.array_u8[0];
		Array_Of_Valve[2+8*0]=tmp_uni_trans.array_u8[1];
		Array_Of_Valve[1+8*0]=tmp_uni_trans.array_u8[2];
		Array_Of_Valve[0+8*0]=tmp_uni_trans.array_u8[3];
#endif


		 for(i=0;i<4;i++)
	   	{ 
			 
		//第i组异常状态----1-8仓
		//IO_Exception_State01=0xaabbccdd;//仅供测试
		tmp_uni_trans.u32Dat=IO_Exception_StateArr[i];
		Array_Of_Valve[7+8*i]=tmp_uni_trans.array_u8[0];
		Array_Of_Valve[6+8*i]=tmp_uni_trans.array_u8[1];
		Array_Of_Valve[5+8*i]=tmp_uni_trans.array_u8[2];
		Array_Of_Valve[4+8*i]=tmp_uni_trans.array_u8[3];
		
		
		////第i组开关状态----1-8仓
		//IO_OnOff_State01=0x55667788;//仅供测试
		tmp_uni_trans.u32Dat=IO_OnOff_StateArr[i];
		Array_Of_Valve[3+8*i]=tmp_uni_trans.array_u8[0];
		Array_Of_Valve[2+8*i]=tmp_uni_trans.array_u8[1];
		Array_Of_Valve[1+8*i]=tmp_uni_trans.array_u8[2];
		Array_Of_Valve[0+8*i]=tmp_uni_trans.array_u8[3]; 
			 
			 
			 
	   }
		 
		
		
		 for(i=0;i<32;i++)
	   {//0x91查询阀门状态指令      将二进制数据转换为ASCII 
 		 
			 sprintf((char*)(temp_buf_Tx_Read+8+i*2),"%02X",Array_Of_Valve[i]);
      
	   } 
	#endif	
	/*	
	i = strlen((char*)temp_buf);
	while(i< 72)
	{
		temp_buf[i] = 0x30;
		i++;
	}
	*/
	
	
#endif	
//================================================================================================================//
	temp.data = temp_buf_Tx_Read;
	temp.length = strlen((char*)temp_buf_Tx_Read);//
	return &temp;
}


///*******************************************************************************
//* Function Name  : Seal_Tx_Readvalue
//* Description    : LRC校验
//* Input          : pCyAsciiBuf--要校验的数组 cyLen--长度
//* Output         : None
//* Return         : cyLrcVal 校验后的值
//*******************************************************************************/
static uint8_t test_send_cnt = 0;//重要数据连续上报5次
static uint8_t Emergencyflag  =0 ;//重要数据发送标志
uint8_t  temp_buf[137]={0};//大小+1  136
Return_data * Seal_Tx_Readvalue(uint16_t ID,uint16_t length)//读取电子铅封的应答 0：默认 1:解封 2 ：施封 3：破封
{
	static Return_data temp;
	uint8_t  i,j=0;
	uint8_t Byte_high,Byte_low;

	memset(temp_buf,0x00,sizeof(temp_buf));
	
	if(Sealing_Data.Sealing_up_datetype != 1)//常规数据上报
	{
		Emergencyflag = 0;
		if(Sealing_Data.Sealing_up_datetype != 0)//上传数据类型   常规数据、解封施封等破封  0：默认 1:解封   2 ：施封   3：破封
		{
			Sealing_Data.Sealing_emergencyflag = 0x80;//施封和破封上报重要数据
			test_send_cnt++;
			if(test_send_cnt>1) //重要数据连续上报5次 
			{
				test_send_cnt = 0;//防止累加太大溢出，不超过255
				Sealing_Data.Sealing_emergencyflag = 0x00;
				Sealing_Data.Sealing_up_datetype = 0;
			}
		}
		else
		{
			Sealing_Data.Sealing_emergencyflag = 0x00;
			test_send_cnt = 0;
		}
		MODBUS_S8_to_ASCII(Sealing_Data.Sealing_emergencyflag ,temp_buf );//重要数据 1字节
		Sealing_Data.Sealing_type = 0x00; //上报数据类型 01 上报解封码
		MODBUS_S8_to_ASCII(Sealing_Data.Sealing_type ,temp_buf+2 );//上报数据类型 1字节
		
		for(i = 0;i<StoreNumber;i++)
		{//8仓遍历
			if(Sealing_Data.Sealing_emergencyflag != 0x80)
			{
				Sealing_Data.Sesling_ID[i] = i+1;//仓号
				MODBUS_S8_to_ASCII(Sealing_Data.Sesling_ID[i] ,temp_buf+8+i*8 );//仓号		
				if(((Full_Oil_allinfo.Start_Decrease_flag&(1<<i)) ==(1<<i))&&((Full_Oil_allinfo.Real_operation_ID&(1<<i))==(1<<i)))//卸油 
							Byte_high = 3;
				else if(((Full_Oil_allinfo.Loading_Oil_state&(0x01<<i)) == (1<<i))&&((Full_Oil_allinfo.Real_operation_ID&(1<<i))==(1<<i)))//装油
					Byte_high = 1;
				else if((IO_Date.IO_unload_switch&(1<<i))==(1<<i))//有油
					Byte_high = 2;//其他改为有油======================有油
				else						//空仓代表无油，通过卸尽传感器检测上报
					Byte_high = 4;//无油 
				if(Byte_high!=4)  //油品默认 92汽油
					Byte_low = 1;
				else Byte_low  = 0;
					Sealing_Data.Sealing_state_oiltype[i] = (Byte_high<<4)|Byte_low;
				MODBUS_S8_to_ASCII(Sealing_Data.Sealing_state_oiltype[i] ,temp_buf+10+i*8 );//空仓(bit7)  卸油(bit6) 
				
				
				if((Full_Oil_allinfo.Break_sealing_Id&(1<<i)) == (1<<i))//破封状态
					Byte_high = 3;
				else
				{
					if((Full_Oil_allinfo.Auto_sealedOK_ID&(1<<i)) == (1<<i))//施封状态
							Byte_high = 1;
					else 	Byte_high = 2;//解封状态
				}
				if((Sealing_Data.Sealing_state_oiltype[i]&0x10)==0x10)
				{
					if(Full_Oil_allinfo.Full_Oil_Mode ==0)//下装
						Byte_low = 2;
					else Byte_low = 1;//上装
				}
				else
					Byte_low = 0;
				Sealing_Data.Sealing_Mode[i] = (Byte_high<<4)|(Byte_low);
				MODBUS_S8_to_ASCII(Sealing_Data.Sealing_Mode[i] ,temp_buf+12+i*8 );
					
				//默认都正常
				//Sealing_Data.Sealing_IO_state[i] = 0x00;//逻辑是否正常(bit7)  预留(bit6)   预留(bit5)  预留(bit4)   人孔小盖(bit3)  人孔大盖(bit2) 卸油阀(bit1)  底阀(bit0)
				Sealing_Data.Sealing_IO_state[i] = (((IO_Date.Temp_IO_normalstate[0]>>(i*4))&0x0f)<<4) | (IO_Date.Temp_IO_state[0]>>(i*4)&0x0f);
				MODBUS_S8_to_ASCII(Sealing_Data.Sealing_IO_state[i] ,temp_buf+14+i*8 );//逻辑是否正常
				
			}
			else
			{
				if(Sealing_Data.Sealing_up_datetype == 3)
				{
					j++;
					Sealing_Data.Sesling_ID[i] = i+1;//仓号
					MODBUS_S8_to_ASCII(Sealing_Data.Sesling_ID[i] ,temp_buf+8+(j-1)*8 );//仓号
					if(((Full_Oil_allinfo.Start_Decrease_flag&(1<<i)) ==(1<<i))&&((Full_Oil_allinfo.Real_operation_ID&(1<<i))==(1<<i)))//卸油 
						Byte_high = 3;
					else if(((Full_Oil_allinfo.Loading_Oil_state&(0x01<<i)) == (1<<i))&&((Full_Oil_allinfo.Real_operation_ID&(1<<i))==(1<<i)))//装油
						Byte_high = 1;
					else if((IO_Date.IO_unload_switch&(1<<i))==(1<<i))//有油
						Byte_high = 2;//其他改为有油======================有油
					else						//空仓代表无油，通过卸尽传感器检测上报
						Byte_high = 4;//无油 
					if(Byte_high!=4)  //油品默认 92汽油
						Byte_low = 1;
					else Byte_low  = 0;
						Sealing_Data.Sealing_state_oiltype[i] = (Byte_high<<4)|Byte_low;
					MODBUS_S8_to_ASCII(Sealing_Data.Sealing_state_oiltype[i] ,temp_buf+10+(j-1)*8 );//空仓(bit7)  卸油(bit6) 
					if((Full_Oil_allinfo.Break_sealing_Id&(1<<i)) == (1<<i))//破封状态
						Byte_high = 3;
					else
					{
						if((Full_Oil_allinfo.Auto_sealedOK_ID&(1<<i)) == (1<<i))//施封状态
								Byte_high = 1;
						else 	Byte_high = 2;//解封状态
					}
					if((Sealing_Data.Sealing_state_oiltype[i]&0x10)==0x10)
					{
						if(Full_Oil_allinfo.Full_Oil_Mode ==0)//下装
							Byte_low = 2;
						else Byte_low = 1;//上装
					}
					else
						Byte_low = 0;
					Sealing_Data.Sealing_Mode[i] = (Byte_high<<4)|(Byte_low);
					MODBUS_S8_to_ASCII(Sealing_Data.Sealing_Mode[i] ,temp_buf+12+(j-1)*8 );
						
					//默认都正常
					//Sealing_Data.Sealing_IO_state[i] = 0x00;//逻辑是否正常(bit7)  预留(bit6)   预留(bit5)  预留(bit4)   人孔小盖(bit3)  人孔大盖(bit2) 卸油阀(bit1)  底阀(bit0)
					Sealing_Data.Sealing_IO_state[i] = (((IO_Date.Temp_IO_normalstate[0]>>(i*4))&0x0f)<<4) | (IO_Date.Temp_IO_state[0]>>(i*4)&0x0f);
					MODBUS_S8_to_ASCII(Sealing_Data.Sealing_IO_state[i] ,temp_buf+14+(j-1)*8 );//逻辑是否正常
				}	
				else if(Sealing_Data.Sealing_up_datetype == 2)
				{
					j++;
					Sealing_Data.Sesling_ID[i] = i+1;//仓号
					MODBUS_S8_to_ASCII(Sealing_Data.Sesling_ID[i] ,temp_buf+8+(j-1)*8 );//仓号
					if(((Full_Oil_allinfo.Start_Decrease_flag&(1<<i)) ==(1<<i))&&((Full_Oil_allinfo.Real_operation_ID&(1<<i))==(1<<i)))//卸油 
						Byte_high = 3;
					else if(((Full_Oil_allinfo.Loading_Oil_state&(0x01<<i)) == (1<<i))&&((Full_Oil_allinfo.Real_operation_ID&(1<<i))==(1<<i)))//装油
						Byte_high = 1;
					else if((IO_Date.IO_unload_switch&(1<<i))==(1<<i))//有油
						Byte_high = 2;//其他改为有油======================有油
					else						//空仓代表无油，通过卸尽传感器检测上报
						Byte_high = 4;//无油 
					if(Byte_high!=4)  //油品默认 92汽油
						Byte_low = 1;
					else Byte_low  = 0;
						Sealing_Data.Sealing_state_oiltype[i] = (Byte_high<<4)|Byte_low;
					MODBUS_S8_to_ASCII(Sealing_Data.Sealing_state_oiltype[i] ,temp_buf+10+(j-1)*8 );//空仓(bit7)  卸油(bit6) 
					if((Full_Oil_allinfo.Break_sealing_Id&(1<<i)) == (1<<i))//破封状态
						Byte_high = 3;
					else
					{
						if((Full_Oil_allinfo.Auto_sealedOK_ID&(1<<i)) == (1<<i))//施封状态
								Byte_high = 1;
						else 	Byte_high = 2;//解封状态
					}
					if((Sealing_Data.Sealing_state_oiltype[i]&0x10)==0x10)
					{
						if(Full_Oil_allinfo.Full_Oil_Mode ==0)//下装
							Byte_low = 2;
						else Byte_low = 1;//上装
					}
					else
						Byte_low = 0;
					Sealing_Data.Sealing_Mode[i] = (Byte_high<<4)|(Byte_low);
					MODBUS_S8_to_ASCII(Sealing_Data.Sealing_Mode[i] ,temp_buf+12+(j-1)*8 );
						
					//默认都正常
					Sealing_Data.Sealing_IO_state[i] = 0x00;//逻辑是否正常(bit7)  预留(bit6)   预留(bit5)  预留(bit4)   人孔小盖(bit3)  人孔大盖(bit2) 卸油阀(bit1)  底阀(bit0)
					MODBUS_S8_to_ASCII(Sealing_Data.Sealing_IO_state[i] ,temp_buf+14+(j-1)*8 );//逻辑是否正常
				}
			}
		}//8仓遍历
		if(Sealing_Data.Sealing_emergencyflag != 0x80)
		{
			Sealing_Data.Sesling_All_num = StoreNumber;//u16 仓数量   需要考虑特殊仓
		}
		/*2020.6.30配合张毅修改破封仓优先上传的代码，改成破封上传所有仓数据
		else
		{
			Sealing_Data.Sesling_All_num = j;//上报的仓数
		}
		*/
		else
		{
			Sealing_Data.Sesling_All_num = StoreNumber;//上报的仓数
		}
		MODBUS_S16_to_ASCII(Sealing_Data.Sesling_All_num ,temp_buf+4 );//仓数量

	}
	else if(Sealing_Data.Sealing_up_datetype == 1)//解封  开始定时，如果超时3次没有收到数据，则解封失败，转换到手动解封
	{
		uint8_t j = 0;
		
		if(Emergencyflag == 0)//重要数据连续上报5次
		{
			Emergencyflag = 1;
			Sealing_Data.Sealing_emergencyflag = 0x80;//重要数据
		}
		else
		{
			Sealing_Data.Sealing_emergencyflag = 0x00;
		}
		MODBUS_S8_to_ASCII(Sealing_Data.Sealing_emergencyflag ,temp_buf );//重要数据 1字节  封包
		
		Sealing_Data.Sealing_type = 0x01;//上报解封码
		MODBUS_S8_to_ASCII(Sealing_Data.Sealing_type ,temp_buf+2 );//上报数据类型 1字节 封包
		
			for(i = 0;i<StoreNumber;i++)
		{
				if((Full_Oil_allinfo.Real_operation_ID&(1<<i))==(1<<i))
				{
					j=j+1;
					Sealing_Data.Sealing_num_id[i] =i+1;//解封仓号
					MODBUS_S8_to_ASCII(Sealing_Data.Sealing_num_id[i] ,temp_buf+8+(j-1)*8 );//仓号 封包
					
					Sealing_Data.Sealing_Random_code[0] = 0x00;//解封码最高位
					MODBUS_S8_to_ASCII(Sealing_Data.Sealing_Random_code[0] ,temp_buf+10+(j-1)*8 );//封包
					
					Sealing_Data.Sealing_Random_code[1] = Full_Oil_allinfo.Random_code>>8;
					MODBUS_S8_to_ASCII(Sealing_Data.Sealing_Random_code[1] ,temp_buf+12+(j-1)*8 );// 封包
					
					Sealing_Data.Sealing_Random_code[2] = Full_Oil_allinfo.Random_code;
					MODBUS_S8_to_ASCII(Sealing_Data.Sealing_Random_code[2] ,temp_buf+14+(j-1)*8);//封包
				}
		}
		Sealing_Data.Sealing_num = j;//解封仓数量
		MODBUS_S16_to_ASCII(Sealing_Data.Sealing_num ,temp_buf+4 );//仓数量 封包
	}
	temp.data = temp_buf;
	temp.length = strlen((char*)temp_buf);//
	return &temp;
}


//ID 0x0047  48 49 4A ...
Return_data * Version_Tx_Readvalue(uint16_t ID,uint16_t length1)//
{
	uint8_t  temp_buf[200]={0};
	static Return_data temp;
	extern uint8_t com_name[20];
	extern uint8_t product_code[20];
	extern uint8_t product_ID[20];//产品ID
//	extern char  custurm_code[10];//客户码
	
// char *com_name = "SHjialong";//公司名称
// char *hardware_version="V2.0.0";//硬件版本
// char *product_code ="DH1000";//产品代码
// char* product_ID ="2018355001";//产品ID
// char * custurm_code ="001200";//客户码
	uint16_t i,len,length=0;
	
	// uint8_t id =ID ,00 -4Byte -高度AD值,02-4Byte-液体温度,04-环境温度，06-加油量，08-漏油量，0a-油箱油量，0c-压力/液位百分比，0e-液位高度
	 
	Version_Date.Version_comname=(uint8_t*)com_name;					//公司名称 SHJy
	Version_Date.Version_allnum = (uint8_t*)product_code;			//产品代码  02
	Version_Date.Version_normaldata=(uint8_t*)(hardware_version);						//硬件版本号
	Version_Date.Version_statenum=(uint8_t*)Version;					//软件版本号 99.33.22长度不超过8字节
	Version_Date.Version_state=(uint8_t*)product_ID;					//设备ID 
	Version_Date.Version_normalstate=(uint8_t*)custurm_code;				//客户代码  
//包含E0	
	//组成数据包  需要加入数据大小判断，防止溢出
	MODBUS_S8_to_ASCII(0XE0 ,temp_buf);//E0  
	length = length + 2;
	len = strlen((char*)Version_Date.Version_comname);
	MODBUS_S8_to_ASCII(len ,temp_buf+length);//len
	length = length + 2;
	for(i=0;i<len;i++)
	{
		MODBUS_S8_to_ASCII(Version_Date.Version_comname[i] ,temp_buf+length+i*2 );// E0 data
	}
	length = length+len*2;//头+数据
	if(length1 == 1)
	{
		temp.data = temp_buf;
		temp.length = length;
		return &temp;
	}
	
	MODBUS_S8_to_ASCII(0XE1 ,temp_buf+length);//E1  
	length = length + 2;
	len = strlen((char*)Version_Date.Version_allnum);
	MODBUS_S8_to_ASCII(len ,temp_buf+length);//len
	length = length + 2;
	for(i=0;i<len;i++)
	{
		MODBUS_S8_to_ASCII(Version_Date.Version_allnum[i] ,temp_buf+length+i*2 );//E1 data
	}
	length = length+len*2;
	if(length1 == 2)
	{
		temp.data = temp_buf;
		temp.length = length;
		return &temp;
	}
	
	MODBUS_S8_to_ASCII(0XE2 ,temp_buf+length);//E2
	length = length + 2;
	len = strlen((char*)Version_Date.Version_normaldata);
	MODBUS_S8_to_ASCII(len ,temp_buf+length);//len
	length = length + 2;
	for(i=0;i<len;i++)
	{
		MODBUS_S8_to_ASCII(Version_Date.Version_normaldata[i] ,temp_buf+length+i*2 );//E2 data
	}
	length = length+len*2;
		if(length1 == 3)
	{
		temp.data = temp_buf;
		temp.length = length;
		return &temp;
	}
	
	MODBUS_S8_to_ASCII(0XE3 ,temp_buf+length);//E3
	length = length + 2;
	len = strlen((char*)Version_Date.Version_statenum);
	MODBUS_S8_to_ASCII(len ,temp_buf+length);//len
	length = length + 2;
	for(i=0;i<len;i++)
	{
		MODBUS_S8_to_ASCII(Version_Date.Version_statenum[i] ,temp_buf+length+i*2 );//E3 data
	}
	length = length+len*2;
		if(length1 == 4)
	{
		temp.data = temp_buf;
		temp.length = length;
		return &temp;
	}
	
	MODBUS_S8_to_ASCII(0XE4 ,temp_buf+length);//E4
	length = length + 2;
	len = strlen((char*)Version_Date.Version_state);
	MODBUS_S8_to_ASCII(len ,temp_buf+length);//len
	length = length + 2;
	for(i=0;i<len;i++)
	{
		MODBUS_S8_to_ASCII(Version_Date.Version_state[i] ,temp_buf+length+i*2 );//E4 data
	}
	length = length+len*2;
		if(length1 == 5)
	{
		temp.data = temp_buf;
		temp.length = length;
		return &temp;
	}
	
	MODBUS_S8_to_ASCII(0XE5 ,temp_buf+length);//E5
	length = length + 2;
	len = strlen((char*)Version_Date.Version_normalstate);
	MODBUS_S8_to_ASCII(len ,temp_buf+length);//len
	length = length + 2;
	for(i=0;i<len;i++)
	{
		MODBUS_S8_to_ASCII(Version_Date.Version_normalstate[i] ,temp_buf+length+i*2 );//data
	}
	length = length+len*2;
	
	
	temp.data = temp_buf;
	temp.length = length;
	return &temp;
//	return temp_buf;
}

uint8_t  Set_Io_Paravalue(uint16_t ID,uint16_t length1,uint8_t*data)//设置参数应答  length1为i收到寄存器的个数
{
	uint8_t sucess_flag = 0;
//	uint8_t length=0;
	return sucess_flag;
}

//获取平台下发的解封码 
uint8_t Get_Ask_code_value(uint16_t ID,uint16_t length1,uint8_t*data)
{
	if(ID ==0x4034)//解封码ID
	{
		if(MODBUS_ASCII_AsciiToHex(data)==0x38)
		{
//			auto_unsealing_id = ( (MODBUS_ASCII_AsciiToHex(data+2))<<8)+MODBUS_ASCII_AsciiToHex(data+4);//解封的仓数
//			unsealing_id = MODBUS_ASCII_AsciiToHex(data+6);//解封的仓号
//			int i =0 ;
//			for(i = 0;i++;i<2)
//				get_ask_code_value[i] = MODBUS_ASCII_AsciiToHex(data+8+i*2);//获取匹配码
			Full_Oil_allinfo.Ask_code =  (MODBUS_ASCII_AsciiToHex(data+10)<<8)|(MODBUS_ASCII_AsciiToHex(data+12));
			if(Full_Oil_allinfo.Ask_code  == Four_num_encrypt(Full_Oil_allinfo.Random_code))//验证解封码对不对
			{
				Full_Oil_allinfo.Auto_Sealing_state =1;//解封成功
				return 0;
			}
		}
	}
	 return 1;
}

uint8_t Cang_ID(uint16_t ID)
{
	uint8_t Cang_id = 0;
	switch(ID>>8)
	{
		case 0x47:
		case 0x4B:
			Cang_id = 1;
		break;
		case 0x48:
		case 0x4C:
					Cang_id = 2;
		break;
		case 0x49:
		case 0x4D:
				Cang_id = 3;
		break;
		case 0x4a:
		case 0x4E:
				Cang_id = 4;
		break;
		default:break;	
	}
	return Cang_id;
}
uint8_t  Set_Oil_Paravalue(uint16_t ID,uint16_t length1,uint8_t * data)//设置参数应答  length1为i收到寄存器的个数  Id为起始寄存器地址
{
	uint8_t sucess_flag = 0;
	uint8_t i =0;
	uint8_t Cang_id = 0;
	
	if(Cang_id==0)
	{
		__nop();
	
	}
	
	Cang_id = Cang_ID(ID);
	
	if(Cang_id==0)
	{
		__nop();
	
	}
	switch((uint8_t)ID)
	{
		case 0x30:
			if(length1<=4)
			{
				for(i=0;i<length1*2 ;i++)
				{
					Oil_Data_Reg[i] = MODBUS_ASCII_AsciiToHex(data+i*2+2);
				}
			}
/*					AT24CXX_Write(70+(Cang_id-1)*64, Oil_Data_Reg,8);*/
			break;
		case 0x34:
			if(length1<=28)
			{
				for(i=0;i<length1*2 ;i++)
				{
					Oil_Data_Reg[i+8] = MODBUS_ASCII_AsciiToHex(data+i*2+2);
				}
			}
/*					AT24CXX_Write(78+(Cang_id-1)*64, Oil_Data_Reg+8,56);*/
			break;
			default:break;
	}
//		Save_config( ID>>8,Oil_Data_Reg,length);//一直报错
//		for(i=1;i<6;i++)//给信号板发送参数 前期田工说是他会死机，不让下发，20180914屏蔽
//			Set_can_data(Cang_id,i);		
	return sucess_flag;
}

Return_data * Oil_Tx_Readpara(uint16_t ID,uint16_t length)
{
	static Return_data  Temp;
	uint8_t i=0;
	uint8_t  temp_buf[112]={0x30,0x30,0x30,0x31,
		0x30,0x30,0x30,0x32,
		0x30,0x30,0x30,0x31,
		0x30,0x30,0x36,0x34,
		0x30,0x30,0x36,0x34,
		0x30,0x30,0x30,0x30,
		0x30,0x30,0x30,0x30,
		0x30,0x30,0x30,0x30,
		0x30,0x30,0x30,0x30,
		0x30,0x30,0x30,0x30,
		0x30,0x30,0x30,0x30,
		0x30,0x43,0x42,0x32,
		0x30,0x30,0x30,0x32,
		0x30,0x30,0x30,0x31,
		0x30,0x30,0x30,0x31,
		0x30,0x33,0x45,0x38,
		0x30,0x33,0x38,0x34,
		0x30,0x31,0x37,0x43,
		0x30,0x30,0x30,0x30,
		0x30,0x30,0x32,0x38,
		0x30,0x30,0x32,0x38,
		0x30,0x30,0x32,0x38,
		0x30,0x30,0x32,0x38,
		0x30,0x30,0x30,0x30,
		0x30,0x30,0x30,0x30,
		0x30,0x30,0x30,0x30,
		0x30,0x30,0x30,0x30,
		0x30,0x30,0x30,0x30};
	
	uint8_t  temp_buf1[16]={0x30,0x30,0x34,0x37,//0x47
		0x30,0x30,0x30,0x33,//0x01 :2400 0x02 :4800 0x03 :9600  04 19200 05 38400 06 57600 07 115200
		0x30,0x30,0x30,0x33,//0x01  奇校验  02 偶校验 03  无校验
		0x30,0x30,0x30,0x30
	};
	uint8_t Cang_id = 0;
	
		if(Cang_id==0)
	{
		__nop();
	
	}
	
	
	Cang_id = Cang_ID(ID);
	
	
		if(Cang_id==0)
	{
		__nop();
	
	}
	//length  4
	//SD卡读出数据
//	Read_config(ID>>8,tttmp,0x38);
/*		 AT24CXX_Read(70+(Cang_id-1)*64,Oil_Data_Reg,64);*/
	switch((uint8_t)ID)
	{
		case 0x30:
			if(Oil_Data_Reg[0]!=0xFF)
			{
				if(length<=4)
				{
					for(i=0;i<length*2 ;i++)
					{
						MODBUS_S8_to_ASCII(Oil_Data_Reg[i] ,temp_buf1+i*2 );
					}
					Temp.length = length*2*2;
				}
				else
				{
					Temp.length = 16;
				}
			}
			else
			{
				MODBUS_S8_to_ASCII(ID>>8,temp_buf1+2);
				Temp.length = 16;
			}
			Temp.data = temp_buf1;
			break;
		case 0x34:
			if(Oil_Data_Reg[8]!=0xFF)
			{
				if(length <=28)
				{
					for(i=0;i<length*2 ;i++)
					{
						MODBUS_S8_to_ASCII(Oil_Data_Reg[i+8] ,temp_buf+i*2 );
					}
					Temp.length = length*2*2;
				}
			}
			else
			{
				Temp.length = strlen((char*)temp_buf);//
			}
			Temp.data = temp_buf;
			break;
			default:
			break;
	}
	return &Temp;
}

uint8_t * IO_Tx_Readpara(uint16_t ID,uint16_t length)
{
		static uint8_t  temp_buf[200]={0x30,0x30,0x30,0x31,0x30,0x30,0x30,0x32,0x30,0x30,
		0x30,0x31,0x30,0x30,0x36,0x34,0x30,0x30,0x36,0x34,
		0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,
		0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,
		0x30,0x30,0x30,0x30,0x30,0x43,0x42,0x32,0x30,0x30,
		0x30,0x32,0x30,0x30,0x30,0x31,0x30,0x30,0x30,0x31,
		0x30,0x33,0x45,0x38,0x30,0x33,0x38,0x34,0x30,0x31,
		0x37,0x43,0x30,0x30,0x30,0x30,0x30,0x30,0x32,0x38,
		0x30,0x30,0x32,0x38,0x30,0x30,0x32,0x38,0x30,0x30,
		0x32,0x38,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,
		0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,
		0x30,0x30};
		
	return temp_buf;
}
//u16 test_len =0;
uint8_t Set_Carlibration_data(uint16_t ID,uint8_t pack,uint16_t length1,uint8_t*data)//ID  80  pack 第几包  length1当前报的长度  data数据
{
	uint8_t i=0;
	uint16_t len = 0;
	uint8_t Cang_id = 0;	
	Cang_id = Cang_ID(ID);
	if(Calibration_Data.Old_ID != (uint8_t)ID)
	{
		Calibration_Data.Old_ID = (uint8_t)ID;
		memset(Calibration_Data.Oil_Carlibration_data,0,420);
	}
	if((uint8_t)ID == 0x80)//标定数据的保存
	{
		for(i=0;i<pack;i++)
		{
				len =len+ Calibration_Data.Child_pack_len[i];
		}
		if(len<500)
		{
			for(i=0;i<(length1*2) ;i++)
			{
				Calibration_Data.Oil_Carlibration_data[i+len] = MODBUS_ASCII_AsciiToHex(data+i*2);
			}
			len = len +length1*2;
			//从326处开始保存数据
//				AT24CXX_Write(326+(Cang_id-1)*420, Calibration_Data.Oil_Carlibration_data,len);
/*			AT24CXX_Write(326+(Cang_id-1)*420+pack*84, Calibration_Data.Oil_Carlibration_data+pack*84,length1*2);//326~2005之内*/		
			Save_Calibration_inof.id[Cang_id-1]= Cang_id;
			Save_Calibration_inof.ALL_pack[Cang_id-1] = Calibration_Data.All_pack;
			Save_Calibration_inof.Length[Cang_id-1] =len;
/*			AT24CXX_Write(2006,(uint8_t*)&Save_Calibration_inof,sizeof(Save_Calibration_Inof));*/
//			test_len = sizeof(Save_Calibration_Inof);
//			Save_Calibration_data((ID>>8),Oil_Carlibration_data , len);  报错。0
			return 0;
		}
		else
			return 1;//数组越界了
	}
	return 0;
}


Return_data * Read_Carlibration_data(uint16_t ID,uint8_t pack,uint16_t length)
{
	static Return_data  Temp;
	uint8_t i =0 ;
	uint8_t temp_buf[161];//160-》161
	uint16_t len = 0;
	uint8_t Cang_id = 0;
	Cang_id = Cang_ID(ID);
	len = Save_Calibration_inof.Length[Cang_id-1] ;	
//	for(i=0;i<pack;i++)
//		len += Calibration_Data.Child_pack_len[i];//取出长度  pack= 0 len= 0 pack= 1 len= 84  2  168
	memset(temp_buf,0x46,160);
	if((len!=0)&&(pack*length<=len))//len!=0  有标定   pack*length<=len 数据长度范围内取值
	{
		if(((len-pack*84)<84)&&((len-pack*84)>=0))
		{
			len =len-pack*84;
		}
		else
			len =84;
/*		 AT24CXX_Read(326+(Cang_id-1)*420+pack*84,Calibration_Data.Oil_Carlibration_data+pack*84,len);*/	
	//	 Read_Calibration_data((ID>>8), len);//报错
		Calibration_Data.All_pack =(uint16_t)(Calibration_Data.Oil_Carlibration_data[0]<<8)+Calibration_Data.Oil_Carlibration_data[1];
		if(Save_Calibration_inof.ALL_pack[Cang_id-1] <= Calibration_Data.All_pack)
		{
			if((pack<Save_Calibration_inof.ALL_pack[Cang_id-1])&&(Save_Calibration_inof.ALL_pack[Cang_id-1]<=5))
			{
				for(i=0;i<(len-4);i++)
				{
					MODBUS_S8_to_ASCII(Calibration_Data.Oil_Carlibration_data[i+pack*84+4] ,temp_buf+i*2 );
				}
			}
		}
	}
	Temp.length = 160;
	Temp.data = temp_buf;
	return &Temp;
}
	

/*modbus协议超时时间计算：协议超时时间1 = 1.5*1000000*( 1 +数据位+奇偶校验+ 停止位)/ 波特率＋ set_adjust_time_bps（波特率）
*/
int speed_arr[] = { 115200, 57600, 38400, 19200, 9600, 4800, 2400, 1200,300,150, 134, 110, 75 };
int name_arr[] = {115200, 57600, 38400, 19200, 9600, 4800, 2400, 1200, 300, 150, 134, 110,75 };
int adjust_time_bps_arr[]={1000,4000,10000,11000,25000,40000,70000,140000,600000,0,0,0,0};
/*
功能: 设定某一波特率下校验时间的调整值
参数: baud_rate 波特率
返回: 当前波特率下的校验时间的调整值
*/
int set_adjust_time_bps(int baud_rate)
{
	int adjust_time;
	int i;
	for(i=0;i<sizeof(speed_arr)/sizeof(int);i++)
	{
		if(baud_rate==name_arr[i])
		{
			adjust_time=adjust_time_bps_arr[i];
			break;
		}
	}
	return adjust_time;
}



/*
功能: 处理0x30命令   主要是应对新疆现场的特殊数据处理
参数: 修改全局变量，解析体积，温度，经纬度，时间等数据
返回: 当前波特率下的校验时间的调整值
*/
int Process_CMD_0x30_ManualFix(void)
{
 //打印数据，温度，密度，液位等数据回传0x30命令处理--开始
	//						 
								//开始组包
								
							#ifdef  DEBUG_FJ_CX_PRJ
						 //2021-1-26 by Daiyf    for test 
						     static  unsigned char i = 0,j=0;
						     // USART1_TX_BUF[0]= TERMINAL_CONTROL_CMD_RESPOND;//ok   3A
								  //USART1_TX_BUF[1]= 01;//For temp test!
						 			
						     
						   if (i< 3){
						         //							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	
						           Foce_Full_Oil();  //for test
						     }
						   else{
								  j = i;
								  i = i - 3;
								 
						      IO_Date.Temp_IO_state[0] = IO_Date.IO_state[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;   //???
						 			Full_Oil_allinfo.Auto_sealedOK_ID &=~(1<<i);//施封清除破封信息
//							    FM25L16B_WriteByte(100,Full_Oil_allinfo.Auto_sealedOK_ID);//保存施封状态20200423
//							    FM25L16B_WriteByte(ADDR_Break_sealing_Id,(uint8_t)Full_Oil_allinfo.Break_sealing_Id);//保存施封状态20200423
									
									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
									
							    
								  i = j;
							   }
							   i += 1;
								 
						 	    Tx_data_frame.Frame_addr = data_frame.Frame_addr;
									Tx_data_frame.Frame_funcode = MODBUS_ASCII_AsciiToHex(temp_data+3);
									Tx_data_frame.Frame_length = (MODBUS_ASCII_AsciiToHex(temp_data+5));
									Tx_data_frame.Frame_data = temp_data+7;
									//开始组包
									USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok 
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//34
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length,USART1_TX_BUF+5);//56
									memcpy(USART1_TX_BUF+7,Tx_data_frame.Frame_data,Tx_data_frame.Frame_length);
									Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,Tx_data_frame.Frame_length+6);
									MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+Tx_data_frame.Frame_length+7);//56
									USART1_TX_BUF[Tx_data_frame.Frame_length+9] =0x0D;
									USART1_TX_BUF[Tx_data_frame.Frame_length+10] = 0x0A;
									TerminalSlave485_Send_Data(USART1_TX_BUF,Tx_data_frame.Frame_length+11);
									

             
						 #else						 
	                Tx_data_frame.Frame_addr = data_frame.Frame_addr;
									Tx_data_frame.Frame_funcode = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+3);
									Tx_data_frame.Frame_length = (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+5)); 
									Tx_data_frame.Frame_data = temp_dataFromUsart1+7;
						
             //==============================================================================================================================================================
						 //Note:此部发是将终端下传的数据进行解析，形成一个统一的数据结构元素，方便使用,数据传送格式为小端模式，即低地址为低位数据，高地址为高位数据。         New addin by Daiyf at  2021-2-2 .
									pT2C_SetupData->year = (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+7) << 8) |  (MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+9));
									pT2C_SetupData->year = BCD2HEX(pT2C_SetupData->year);                  //加入了HEX转BCD处理   addin by Daiyf at  2021-2-24 .
									
									pT2C_SetupData->month = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+11);
									pT2C_SetupData->month = BCDtoHEX(pT2C_SetupData->month);
									
									pT2C_SetupData->day = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+13);
									pT2C_SetupData->day = BCDtoHEX(pT2C_SetupData->day);
									
									pT2C_SetupData->hour = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+15);
									pT2C_SetupData->hour = BCDtoHEX(pT2C_SetupData->hour);
									
									pT2C_SetupData->minute = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+17);
									pT2C_SetupData->minute = BCDtoHEX(pT2C_SetupData->minute);
									
									pT2C_SetupData->second = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+19);
									pT2C_SetupData->second = BCDtoHEX(pT2C_SetupData->second);
									
									pT2C_SetupData->m_second = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+21);
									pT2C_SetupData->m_second = BCDtoHEX(pT2C_SetupData->m_second);

							//Next Get 14 Variables / parameters	
                #if 1
								   #if 0     /*** For only debug test!  2021-2-19 by Daiyf ***/
			
		   	            pT2C_SetupData->longitude = 44.25541;
									  pT2C_SetupData->latitude  = 87.66003;
										pT2C_SetupData->Capacity_Vt = -12;
										pT2C_SetupData->Capacity_V20 = 12;
										MODBUS_Float_to_ASCII(pT2C_SetupData->longitude ,temp_data+23 );
										MODBUS_Float_to_ASCII(pT2C_SetupData->latitude ,temp_data+31 );
										MODBUS_Float_to_ASCII(pT2C_SetupData->Capacity_Vt ,temp_data+39 );
										MODBUS_Float_to_ASCII(pT2C_SetupData->Capacity_V20 ,temp_data+47 );
									 #endif	
									 
                  pT2C_SetupData->longitude = MODBUS_ASCII_AsciiToFlaot(temp_dataFromUsart1+23); 	
									MODBUS_Float_to_ASCII(pT2C_SetupData->longitude ,temp_dataFromUsart1+23 );			
                  pT2C_SetupData->latitude  = MODBUS_ASCII_AsciiToFlaot(temp_dataFromUsart1+31);	
									pT2C_SetupData->Capacity_Vt  = MODBUS_ASCII_AsciiToFlaot(temp_dataFromUsart1+39);
                  pT2C_SetupData->Capacity_V20  = MODBUS_ASCII_AsciiToFlaot(temp_dataFromUsart1+47);
									pT2C_SetupData->liquid_level  = MODBUS_ASCII_AsciiToFlaot(temp_dataFromUsart1+55);
									pT2C_SetupData->temperature  = MODBUS_ASCII_AsciiToFlaot(temp_dataFromUsart1+63);	
                  pT2C_SetupData->inclination_angle_x  = MODBUS_ASCII_AsciiToFlaot(temp_dataFromUsart1+71);
									pT2C_SetupData->inclination_angle_y  = MODBUS_ASCII_AsciiToFlaot(temp_dataFromUsart1+79);
									pT2C_SetupData->pressure  = MODBUS_ASCII_AsciiToFlaot(temp_dataFromUsart1+87);	
                  pT2C_SetupData->density  = MODBUS_ASCII_AsciiToFlaot(temp_dataFromUsart1+95);
									pT2C_SetupData->Reserved_parameters_1  = MODBUS_ASCII_AsciiToFlaot(temp_dataFromUsart1+103);
									pT2C_SetupData->Reserved_parameters_2  = MODBUS_ASCII_AsciiToFlaot(temp_dataFromUsart1+111);	
                  pT2C_SetupData->Reserved_parameters_3  = MODBUS_ASCII_AsciiToFlaot(temp_dataFromUsart1+119);
									pT2C_SetupData->Reserved_parameters_4  = MODBUS_ASCII_AsciiToFlaot(temp_dataFromUsart1+127);
									
							
									MODBUS_Float_to_ASCII(pT2C_SetupData->Reserved_parameters_4 ,temp_dataFromUsart1+127);	
                

							  #else		
								  //这部分不用了！  Note  by Daiyf 2020-2-22
									pT2C_SetupData->longitude = (MODBUS_ASCII_AsciiToHex(temp_data+23)) | (MODBUS_ASCII_AsciiToHex(temp_data+25)) << 8 | (MODBUS_ASCII_AsciiToHex(temp_data+27)) << 16 | (MODBUS_ASCII_AsciiToHex(temp_data+29) << 24) ;
   								pT2C_SetupData->latitude = MODBUS_ASCII_AsciiToHex(temp_data+31) | MODBUS_ASCII_AsciiToHex(temp_data+33) << 8 | MODBUS_ASCII_AsciiToHex(temp_data+35) << 16 | MODBUS_ASCII_AsciiToHex(temp_data+37) << 24 ;
									pT2C_SetupData->Capacity_Vt = MODBUS_ASCII_AsciiToHex(temp_data+39) | MODBUS_ASCII_AsciiToHex(temp_data+41) << 8 | MODBUS_ASCII_AsciiToHex(temp_data+43) << 16 | MODBUS_ASCII_AsciiToHex(temp_data+45) << 24 ;
									pT2C_SetupData->Capacity_V20 = MODBUS_ASCII_AsciiToHex(temp_data+47) | MODBUS_ASCII_AsciiToHex(temp_data+49) << 8 | MODBUS_ASCII_AsciiToHex(temp_data+51) << 16 | MODBUS_ASCII_AsciiToHex(temp_data+53) << 24 ;
									pT2C_SetupData->liquid_level = MODBUS_ASCII_AsciiToHex(temp_data+55) | MODBUS_ASCII_AsciiToHex(temp_data+57) << 8 | MODBUS_ASCII_AsciiToHex(temp_data+59) << 16 | MODBUS_ASCII_AsciiToHex(temp_data+61) << 24 ;
									pT2C_SetupData->temperature = MODBUS_ASCII_AsciiToHex(temp_data+63) | MODBUS_ASCII_AsciiToHex(temp_data+65) << 8 | MODBUS_ASCII_AsciiToHex(temp_data+67) << 16 | MODBUS_ASCII_AsciiToHex(temp_data+69) << 24 ;
										pT2C_SetupData->inclination_angle_x = MODBUS_ASCII_AsciiToHex(temp_data+71) | MODBUS_ASCII_AsciiToHex(temp_data+73) << 8 | MODBUS_ASCII_AsciiToHex(temp_data+75) << 16 | MODBUS_ASCII_AsciiToHex(temp_data+77) << 24 ;
											pT2C_SetupData->inclination_angle_y = MODBUS_ASCII_AsciiToHex(temp_data+79) | MODBUS_ASCII_AsciiToHex(temp_data+81) << 8 | MODBUS_ASCII_AsciiToHex(temp_data+83) << 16 | MODBUS_ASCII_AsciiToHex(temp_data+85) << 24 ;
												pT2C_SetupData->pressure = MODBUS_ASCII_AsciiToHex(temp_data+87) | MODBUS_ASCII_AsciiToHex(temp_data+89) << 8 | MODBUS_ASCII_AsciiToHex(temp_data+91) << 16 | MODBUS_ASCII_AsciiToHex(temp_data+93) << 24 ;
													pT2C_SetupData->density = MODBUS_ASCII_AsciiToHex(temp_data+95) | MODBUS_ASCII_AsciiToHex(temp_data+97) << 8 | MODBUS_ASCII_AsciiToHex(temp_data+99) << 16 | MODBUS_ASCII_AsciiToHex(temp_data+101) << 24 ;
														pT2C_SetupData->Reserved_parameters_1 = MODBUS_ASCII_AsciiToHex(temp_data+103) | MODBUS_ASCII_AsciiToHex(temp_data+105) << 8 | MODBUS_ASCII_AsciiToHex(temp_data+107) << 16 | MODBUS_ASCII_AsciiToHex(temp_data+109) << 24 ;
															pT2C_SetupData->Reserved_parameters_2 = MODBUS_ASCII_AsciiToHex(temp_data+111) | MODBUS_ASCII_AsciiToHex(temp_data+113) << 8 | MODBUS_ASCII_AsciiToHex(temp_data+115) << 16 | MODBUS_ASCII_AsciiToHex(temp_data+117) << 24 ;
																pT2C_SetupData->Reserved_parameters_3 = MODBUS_ASCII_AsciiToHex(temp_data+119) | MODBUS_ASCII_AsciiToHex(temp_data+121) << 8 | MODBUS_ASCII_AsciiToHex(temp_data+123) << 16 | MODBUS_ASCII_AsciiToHex(temp_data+125) << 24 ;
																	pT2C_SetupData->Reserved_parameters_4 = MODBUS_ASCII_AsciiToHex(temp_data+127) | MODBUS_ASCII_AsciiToHex(temp_data+129) << 8 | MODBUS_ASCII_AsciiToHex(temp_data+131) << 16 | MODBUS_ASCII_AsciiToHex(temp_data+133) << 24 ;

                 #endif
			       //==============================================================================================================================================================
								//开始组包           Addin start by Daiyf 2020-2-22
									USART1_TX_BUF[0]= Tx_data_frame.Frame_head;//ok 
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_addr,USART1_TX_BUF+1);//1-2
									MODBUS_S8_to_ASCII(Tx_data_frame.Frame_funcode,USART1_TX_BUF+3);//3-4

							//========================================================================================================================		
									Tx_data_frame.Frame_length = 128; //协议修订后，打印上传的信息长度为128个字节。 note by Daiyf at 2021-2-25
									memset(Tx_data_frame.Frame_data,0x30,Tx_data_frame.Frame_length);
									if(pT2C_SetupData->Reserved_parameters_4 > 0)
									{
									   //这里可以加入对保留参数判断的处理,建立与平台间临时约定处理机制
									} 	
									if(FlagPrint)//如果有打印请求，发相关打印的信息。   
									{    
																			MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length/2,USART1_TX_BUF+5);//5-6   // 以ASCII计2个字符算一个字节的长度 ？
										Tx_data_frame.Frame_length = 128; //协议修订后，打印上传的信息长度为128个字节。 note by Daiyf at 2021-2-25
									   	memcpy(USART1_TX_BUF+7,Tx_data_frame.Frame_data,Tx_data_frame.Frame_length);//7-8  ,!这里要改成要打印上传的数据,还要分仓位发相应信息！

										  FlagPrint = 0;
									}
									else        //无打印请求，正常回复状态信息。   Addin by Daiyf 2020-2-22
									{   
										Tx_data_frame.Frame_length = 2; //正常回复上传的信息长度为2个字节。
                    										MODBUS_S8_to_ASCII(Tx_data_frame.Frame_length/2,USART1_TX_BUF+5);//5-6   // 以ASCII计2个字符算一个字节的长度 ？
                      Tx_data_frame.Frame_data[0] = 0x30;	//正常回0x30,不正常回大于0x30;									
                      Tx_data_frame.Frame_data[1] = 0x30;	//正常回0x30,不正常回大于0x30;	
										
											memcpy(USART1_TX_BUF+7,Tx_data_frame.Frame_data,Tx_data_frame.Frame_length);//7-8

									}
									// Addin end by Daiyf 2020-2-22
							//========================================================================================================================			
								  Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,Tx_data_frame.Frame_length+6);
									MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+Tx_data_frame.Frame_length+7);//56
									USART1_TX_BUF[Tx_data_frame.Frame_length+9] =0x0D;
									USART1_TX_BUF[Tx_data_frame.Frame_length+10] = 0x0A;
									TerminalSlave485_Send_Data(USART1_TX_BUF,Tx_data_frame.Frame_length+11);
									
		          #endif

  return 1;

}




/*
功能: 处理0x38命令   出电子围栏进行施封
参数: 修改全局变量，根据地址、功能码进行处理;比较耗费时间的函数（执行时间大于100ms）则设置标志位;其他函数直接处理
返回: 1  或者系统重启(系统重启命令)   读取的寄存器数据封装成64字节的长度发回给终端
帧头为:383003+1字节的电子围栏类型(01-离开油库；02--离开油站；03：速度超过xx公里)+56个字节的30.


*/
int Process_CMD_0x38_AutoSeal_By_ElecFence(void)
{
	int i; //i000,i001,

	pT2C_SealByElec_Fence->FrameHead = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1 + 1 + 0);	//<<8;
	pT2C_SealByElec_Fence->FrmLength = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1 + 1 + 2);	//<<8;
	pT2C_SealByElec_Fence->FunctionCode = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1 + 1 + 4); //<<8;
	pT2C_SealByElec_Fence->TypeOf_Seal = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1 + 1 + 6);	//<<8;
	pT2C_SealByElec_Fence->TpyeOfUnSeal = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1 + 1 + 8); //<<8;

	//待解封的仓号
	for (i = 0; i < 8; i++)
	{
		pT2C_SealByElec_Fence->Array_NumOfCab_To_UnSeal[7 - i] = MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1 + 1 + 10 + i * 2); //<<8;
	}

	if (((pT2C_SealByElec_Fence->TypeOf_Seal == 0x01) ||
			(pT2C_SealByElec_Fence->TypeOf_Seal == 0x02) || (pT2C_SealByElec_Fence->TypeOf_Seal == 0x03)) &&
		(pT2C_SealByElec_Fence->FunctionCode == 0x03))
	{ //施封命令

		//==0x08对应于bit3-----可以重复施封
		//if(((Config_info_all.Config_fun_id&0x08) == 0x08))
		Full_Oil_allinfo.Start_Seal_flag = 1;

		if (Full_Oil_allinfo.Break_sealing_Id > 0)
		{
			if (((Config_info_all.Config_fun_id & 0x08) == 0x08)) //==0x08对应于bit3-----可以重复施封
			{
				for (i = 0; i < StoreNumber; i++)
				{
					if (((Full_Oil_allinfo.Break_sealing_Id & (1 << i)) == (1 << i)) &&

						(((IO_Date.IO_unload_switch & (1 << i)) == (1 << i)) || (flag_En_BlankSeal == 0x01)) //允许空仓施封
					)
					{
						if (((~IO_Date.IO_state[0]) & (0x0f << (i * 4))) == (0x0f << (i * 4)))
						{
							Full_Oil_allinfo.Break_sealing_Id &= ~(1 << i);										   //清除本仓破封信息
							Full_Oil_allinfo.Auto_sealedOK_ID |= 1 << i;										   //本仓可以重新施封   --施封对应的仓位
							Sealing_Data.Sealing_up_datetype = 2;												   //上报报平台，进行施封
							FM25L16B_WriteByte(ADDR_Auto_sealedOK_ID, Full_Oil_allinfo.Auto_sealedOK_ID);		   //保存施封状态20200428
							FM25L16B_WriteByte(ADDR_Break_sealing_Id, (uint8_t)Full_Oil_allinfo.Break_sealing_Id); //保存破封状态20200428
						}
					}
				}
			}
		}

		/////////////////以下拷贝自elec_seal.c----未看懂
		/*骏鹏要求有油就可以施封，不需要施封流程*/
		if (Full_Oil_allinfo.Start_Seal_flag == 1) //保存施封状态20200604
		{
			uint8_t j = 0;
			for (j = 0; j < StoreNumber; j++)
			{
				if (((Full_Oil_allinfo.Break_sealing_Id & (1 << j)) != (1 << j)))
				{
					if (((~IO_Date.IO_state[0]) & (0x0f << (j * 4))) == (0x0f << (j * 4)))
					{

						if (flag_En_BlankSeal == 0x01)
						{		   //允许空仓施封
							if (1) //if((IO_Date.IO_unload_switch&(0x01<<j))==(0x01<<j))
							{
								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 ((IO_Date.IO_unload_switch & (0x01 << j)) == (0x01 << j))
							{
								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;
			}
		}

		if (0)
		{
			memcpy(USART1_TX_BUF, temp_dataFromUsart1, 16 * 2 + 1); //前16字节原样返回,共33字符 1表示起始字符英文下的冒号，hex为0x3a
			memset(USART1_TX_BUF + 33, 'A', 90);
			__nop();
			//memset(&USART1_TX_BUF[33],'A',sizeof(USART1_TX_BUF)-33);
			Lrc_temp = MODBUS_ASCII_GetLrc(temp_dataFromUsart1 + 1, 60 * 2 + 1);
			//MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+Tx_data_frame.Frame_length+7);//56
			sprintf((char *)(&USART1_TX_BUF[119]), "%02X", Lrc_temp);
			USART1_TX_BUF[rx1_len + 0] = 0x0D;
			USART1_TX_BUF[rx1_len + 1] = 0x0A;
			//TerminalSlave485_Send_Data(USART1_TX_BUF,120+3);
			TerminalSlave485_Send_Data(USART1_TX_BUF, rx1_len + 2);
		}
		else
		{
			memcpy(USART1_TX_BUF, temp_dataFromUsart1, 61 * 2 + 3);
			TerminalSlave485_Send_Data(USART1_TX_BUF, 69);
		}

		return 2;
	}
	else if (pT2C_SealByElec_Fence->FunctionCode == 0x04) //平台下发命令强制进入解封状态----解封命令
	{													  //李伟修改   20211208   强制解封

		if (pT2C_SealByElec_Fence->TpyeOfUnSeal == 0x02)
		{
			for (i = 0; i < 8; i++)
			{
				if (pT2C_SealByElec_Fence->Array_NumOfCab_To_UnSeal[i] == 0x00)
				{
					continue;
				}

				Full_Oil_allinfo.Break_sealing_Id &= ~(1 << i); //空仓清除破封信息
				Full_Oil_allinfo.Auto_sealedOK_ID &= ~(1 << i);										   //施封清除破封信息
				FM25L16B_WriteByte(ADDR_Auto_sealedOK_ID, Full_Oil_allinfo.Auto_sealedOK_ID);		   //保存施封状态
				FM25L16B_WriteByte(ADDR_Break_sealing_Id, (uint8_t)Full_Oil_allinfo.Break_sealing_Id); //保存施封状态
			}
		}
		else if (pT2C_SealByElec_Fence->TpyeOfUnSeal == 0x01)
		{
			for (i = 0; i < 8; i++)
			{
				if (pT2C_SealByElec_Fence->Array_NumOfCab_To_UnSeal[i] == 0x00)
				{
					continue;
				}

				//只能由破封进入解封状态
				if ((Full_Oil_allinfo.Break_sealing_Id & (1 << i)) == (1 << i)) //破封
				{
					Full_Oil_allinfo.Break_sealing_Id &= ~(1 << i); //

					Full_Oil_allinfo.Auto_sealedOK_ID &= ~(1 << i);										   //
					FM25L16B_WriteByte(ADDR_Auto_sealedOK_ID, Full_Oil_allinfo.Auto_sealedOK_ID);		   //保存施封状态
					FM25L16B_WriteByte(ADDR_Break_sealing_Id, (uint8_t)Full_Oil_allinfo.Break_sealing_Id); //保存施封状态
				}
			}
		}
		memcpy(USART1_TX_BUF, temp_dataFromUsart1, 61 * 2 + 3);
		TerminalSlave485_Send_Data(USART1_TX_BUF, 69);
	}

	return 1;
}
/*
功能: 处理0x39命令   主要是远程标定命令   详见《罐车安全智能监控系统标定通用协议及远程标定协议》
参数: 修改全局变量，根据地址、功能码进行处理;比较耗费时间的函数（执行时间大于100ms）则设置标志位;其他函数直接处理
返回: 1  或者系统重启(系统重启命令)   读取的寄存器数据封装成64字节的长度发回给终端

具体是指：分析地址码，功能码，然后修改相应的寄存器或者将终端发来的命令进行广播；
如果地址码是本机地址，则分析指令；
如果不是则进行转发；
如果是广播，则向串口2,3,4原数据直接转发.备注：终端接的是单片机的USART1
数据格式简述：
总长度为64字节；后期自己研发终端可以扩大，预计1k字节可以实现。
帧头2字节0x 3901
地址码 4字节，比如0x95510001
功能码2字节   只能是0x0003、0x0006或者0x0010
寄存器起始地址2字节：合法范围为0x0000~0xffff
数据个数2字节：最多读取0xffff字节；实际取决于终端限制，目前为256字节
保留字4字节
有效载荷44字节
保留字2字节
校验2字节


*/
uint32_t addr_ext_controllBoard;
extern 	uint32_t totalRunTimeCnt;
uni_float uni_flo001;
uni_float uni_floArray_uart1[32];//标定数据用联合体 按照浮点数解析的32个数据 ----来自终端的标定数据
uint8_t Num_Of_Cang_HaiDifa_0x39[8];//用于标定的仓数 大盖  小盖  卸油阀  海底阀  数量
uint8_t SensorEnable_ReSeal[8],tmp0x39;//用于标定是否	开启相应的功能

uint8_t flag_RemCal=0;//用于标定是否	开启相应的功能
uni_float uni_flo001_init;

//dataMode=0x00表示之前的ASCII格式，0x01表示新的十六进制格式
int 	Process_CMD_0x39_RemoteCali(uint8_t dataMode)
{
		int i000,i001;
		//uint8_t TempData;//,TmpValState00,TmpValState01;

  		extern	uint16_t  bufText00[256];
		extern  uint16_t  bufText01Password[256];
		extern 	uint32_t FunDebugCode;	

	
		cmd39Cnt++;
	
	  tmrForRemoteCali=SPAN_RemoteCali_INTERVAL;//
	
	
	if(dataMode==0x00)
	{//兼容老协议，ASCII转换为十六进制--开始
	  	T2C_RemoteCaliDat001.FrameHead=(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+0)<<8)+MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+2);//获取寄存器的值
		T2C_RemoteCaliDat001.AddrExtModule=(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+4)<<24)+(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+6)<<16)+
																				(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+8)<<8)+(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+10));// 
	
		addr_ext_controllBoard=(FM25L16B_ReadByte(ADDR_Extended_ContBoard+0)<<24)+(FM25L16B_ReadByte(ADDR_Extended_ContBoard+1)<<16)+
							(FM25L16B_ReadByte(ADDR_Extended_ContBoard+2)<<8)+(FM25L16B_ReadByte(ADDR_Extended_ContBoard+3));
		//地址解析完毕后，如果发现不是本模块地址则直接将命令转发给采集器
	  __nop();
	
	
		T2C_RemoteCaliDat001.FunctionCode=(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+12)<<8)+(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+14));//
																	

		T2C_RemoteCaliDat001.AddrRegStart=(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+16)<<8)+(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+18));//

		T2C_RemoteCaliDat001.NumberOfRegs=(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+20)<<8)+(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+22));// 

		T2C_RemoteCaliDat001.ReserveData001=(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+24)<<24)+(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+26)<<16)+
																				(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+28)<<8)+(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+30));//
	 
	  __nop();
		
		
		for(i000=0;i000<44;i000++)
		{
			T2C_RemoteCaliDat001.PayLoadData[i000]=MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+32+i000*2);

		}
					
	}//兼容老协议，ASCII转换为十六进制--结束
	else
	{//新协议，直接用十六进制传输数据--开始
		T2C_RemoteCaliDat001.FrameHead=((temp_dataFromUsart1[1+0])<<8)+(temp_dataFromUsart1[1+1]);//获取寄存器的值
		T2C_RemoteCaliDat001.AddrExtModule=((temp_dataFromUsart1[1+2])<<24)+((temp_dataFromUsart1[1+3])<<16)+
																				(temp_dataFromUsart1[1+4]<<8)+(temp_dataFromUsart1[1+5]);// 
	
		addr_ext_controllBoard=(FM25L16B_ReadByte(ADDR_Extended_ContBoard+0)<<24)+(FM25L16B_ReadByte(ADDR_Extended_ContBoard+1)<<16)+
							(FM25L16B_ReadByte(ADDR_Extended_ContBoard+2)<<8)+(FM25L16B_ReadByte(ADDR_Extended_ContBoard+3));
		//地址解析完毕后，如果发现不是本模块地址则直接将命令转发给采集器
	  __nop();
	
	
		T2C_RemoteCaliDat001.FunctionCode=((temp_dataFromUsart1[1+6])<<8)+((temp_dataFromUsart1[1+7]));//
																	

		T2C_RemoteCaliDat001.AddrRegStart=((temp_dataFromUsart1[1+8])<<8)+((temp_dataFromUsart1[1+9]));//

		T2C_RemoteCaliDat001.NumberOfRegs=((temp_dataFromUsart1[1+10])<<8)+((temp_dataFromUsart1[1+11]));// 

		T2C_RemoteCaliDat001.ReserveData001=((temp_dataFromUsart1[1+12])<<24)+((temp_dataFromUsart1[1+13])<<16)+
																				((temp_dataFromUsart1[1+14])<<8)+((temp_dataFromUsart1[1+15]));//
	 
	  __nop();
		
		
		for(i000=0;i000<T2C_RemoteCaliDat001.NumberOfRegs;i000++)
		{
			T2C_RemoteCaliDat001.PayLoadData[i000]=temp_dataFromUsart1[17+i000];//(temp_dataFromUsart1+1+32+i000*2);

		}
		
	}//新协议，直接用十六进制传输数据--结束
	
 
	
	   //地址匹配 广播地址、0x9501001是2个例外均表示控制板
	  if((addr_ext_controllBoard!=T2C_RemoteCaliDat001.AddrExtModule) && (T2C_RemoteCaliDat001.AddrExtModule!=0x00000000)
			&& (T2C_RemoteCaliDat001.AddrExtModule!=ExtAddr_ControllBoard)  && (T2C_RemoteCaliDat001.AddrExtModule!=ExtAddr_ControllBoard2) ) 
		{
			//数据转发给采集器
			osDelay(100);
			if(DataMode_For_RemCali==0x00)//数据模式是ASCII或者HEX
			{//ASCII模式下，只发送64*2+3字节	
				CollectMaster485_Send_Data(temp_dataFromUsart1,128+3);//起始字符为“:”，结束字符0x0d 0x0a，+128=131字节			
			}
			else
			{//十六进制模式下，只发送64字节	
				CollectMaster485_Send_Data(&temp_dataFromUsart1[1],64);//十六进制模式下，只发送64字节			
			}

			//接收64字节的返回数据
			//HAL_Delay(500);
			//HAL_GPIO_TogglePin(GPIOC, DWI_Pin);//复位看门狗sp706
			for(i000=0;i000<25;++i000)
			{
				if(usart2_rx_flag==True)
					break;
				osDelay(15);
			}
			if(usart2_rx_flag==True)
			//if(CheckInFrame_Collect485(64,0)==0x95) //返回数据:390195500001
			{//如果 采集器在500ms之内有返回数据则返回采集器的数据----开始
				//HAL_GPIO_TogglePin(GPIOE,LED1_Pin);
				
				usart2_rx_flag=False;
				USART1_TX_BUF[0]=':';
				if(rx2_len>128)
					rx2_len=128;

				for(i000=0;i000<rx2_len;i000++)
				{
					sprintf((char*)&USART1_TX_BUF[1+i000*2],"%02X",USART2_RX_BUF[i000]);
				}
				Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,rx2_len*2);
	 			sprintf((char*)(&USART1_TX_BUF[rx2_len*2+1]),"%02X",Lrc_temp);
				USART1_TX_BUF[rx2_len*2+3]=0x0d;
				USART1_TX_BUF[rx2_len*2+4]=0x0a;
				TerminalSlave485_Send_Data(USART1_TX_BUF,rx2_len*2+5);
			}//如果 采集器在500ms之内有返回数据则返回采集器的数据----结束
			else
			{//如果采集器无返回数据则返回终端发过来的数据----开始
						
					if(dataMode==0x00)
					{//兼容老协议，ASCII转换为十六进制--开始
								//回复给终端数据	
								Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,127);
								//memcpy(USART1_TX_BUF,temp_dataFromUsart1,16*2+1);//前16字节原样返回,共33字符 1表示起始字符英文下的冒号，hex为0x3a
								memcpy(USART1_TX_BUF,temp_dataFromUsart1,131);// 
								//memset(&USART1_TX_BUF[33],'A',sizeof(USART1_TX_BUF)-33);

								//MODBUS_S8_to_ASCII(Lrc_temp,USART1_TX_BUF+Tx_data_frame.Frame_length+7);//56
								//sprintf((char*)(&USART1_TX_BUF[128]),"%02X",Lrc_temp);
				//				USART1_TX_BUF[129] =0x0D;
				//				USART1_TX_BUF[130] = 0x0A;
								TerminalSlave485_Send_Data(USART1_TX_BUF,128+3);	
						}
						else
						{//按照十六进制的方式回复
//								Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,64);
//								//memcpy(USART1_TX_BUF,temp_dataFromUsart1,16*2+1);//前16字节原样返回,共33字符 1表示起始字符英文下的冒号，hex为0x3a
//								memcpy(USART1_TX_BUF,temp_dataFromUsart1,67+2);// 
//							  USART1_TX_BUF[67]=0x0D;
//								USART1_TX_BUF[68]=0x0A;
//								TerminalSlave485_Send_Data(USART1_TX_BUF,69);
//							
							
							//lenRx1
								memcpy(USART1_TX_BUF,temp_dataFromUsart1,lenRx1+0);// 
//							  USART1_TX_BUF[67]=0x0D;
//								USART1_TX_BUF[68]=0x0A;
								TerminalSlave485_Send_Data(USART1_TX_BUF,lenRx1+0);
							
							
								/*Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,64);
								//张毅反应去掉开头的冒号0x3A,去掉结尾的校验2字节、0x0d0a
								memcpy(USART1_TX_BUF,&temp_dataFromUsart1[1],64);// 

								TerminalSlave485_Send_Data(USART1_TX_BUF,64);	*/

								__NOP();
						
						
						}
				

				//memset(temp_dataFromUsart1,0,sizeof(temp_dataFromUsart1));//清零
				
			}//如果采集器无返回数据则返回终端发过来的数据----结束
			return 2;
		}
		
		
	
	  
 
		
		//有效载荷解码，共44或者88字节；44字节为字符直接拷贝；88字节则调用函数解码
		/*if((T2C_RemoteCaliDat001.AddrRegStart==ADDR_Version_ContBoard) ||(T2C_RemoteCaliDat001.AddrRegStart==ADDR_VersionOf_Software)
			||(ADDR_VersionOf_Hardware==T2C_RemoteCaliDat001.AddrRegStart) ||(T2C_RemoteCaliDat001.AddrRegStart==ADDR_VersionOf_LCD)
			||(ADDR_Unique_ID_ContBoard==T2C_RemoteCaliDat001.AddrRegStart))
		{//版本号信息、唯一ID编号共5种情况会出现英文字母，其他信息均为十六进制的ASCII编码   
				memcpy(T2C_RemoteCaliDat001.PayLoadData,temp_dataFromUsart1+33,44);
				__nop();
		}
		else   //两个ASCII字符表示一个0x0000-FF之间的数字；比如'39'表示0x09
		{//所有字符均为0~9，A~F；不可能有例外！！！！
				
			switch (T2C_RemoteCaliDat001.NumberOfRegs)
      {  //分为两种，一种是纯数据，只能是0--9，A--F，可以解析为浮点数或者u32类型的数据；
				//另一种是字符表示的十六进制数据，范围是0x00--ff;两个字符传输一个字节的数据，可以传输汉字，英文字符等；一个字符就表示一个字节
      	case 0x40://定长64字节数据------实际终端后边485串口接收到起始字符+64*2+2个结束字符=131字节
					for(i000=0;i000<44;i000++)
					{
						T2C_RemoteCaliDat001.PayLoadData[i000]=MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+32+i000*2);

					}	
      		break;
      	case 0x60://定长96字节数据------实际终端后边485串口接收到起始字符+96*2+2个结束字符=195字节
					for(i000=0;i000<44+32;i000++)
					{
						T2C_RemoteCaliDat001.PayLoadData[i000]=MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+32+i000*2);

					}	
      		break;
				case 0x80://定长128字节数据------实际终端后边485串口接收到起始字符+128*2+2个结束字符=259字符
					for(i000=0;i000<44+32+32;i000++)
					{
						T2C_RemoteCaliDat001.PayLoadData[i000]=MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+32+i000*2);

					}	
      		break;	
					
      	default:
					
					for(i000=0;i000<44;i000++)
					{
						T2C_RemoteCaliDat001.PayLoadData[i000]=MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+32+i000*2);

					}	
      		break;
      }
 			
				
		}*/

		
		
/*
:390195510001000357478942F0508D41F16E01946667E66466C766644256666777788884423C0000111122223333444455556666777788889999abcdCCCCBBBB
		
		
			switch (T2C_RemoteCaliDat001.NumberOfRegs)
      {  //分为两种，一种是纯数据，只能是0--9，A--F，可以解析为浮点数或者u32类型的数据；
				//另一种是字符表示的十六进制数据，范围是0x00--ff;两个字符传输一个字节的数据，可以传输汉字，英文字符等；一个字符就表示一个字节
      	case 0x40://定长64字节数据------实际终端后边485串口接收到起始字符+64*2+2个结束字符=131字节
					T2C_RemoteCaliDat001.ReserveData002=(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+120)<<8)+(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+122));// 
					T2C_RemoteCaliDat001.CheckSum=(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+124)<<8)+(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+126));// 
      		break;
      	case 0x60://定长96字节数据------实际终端后边485串口接收到起始字符+96*2+2个结束字符=195字节
					T2C_RemoteCaliDat001.ReserveData002=(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+120+64)<<8)+(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+122+64));// 
					T2C_RemoteCaliDat001.CheckSum=(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+124+64)<<8)+(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+126+64));// 
      		break;
				case 0x80://定长128字节数据------实际终端后边485串口接收到起始字符+128*2+2个结束字符=259字符
 					T2C_RemoteCaliDat001.ReserveData002=(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+120+64*2)<<8)+(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+122+64*2));// 
					T2C_RemoteCaliDat001.CheckSum=(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+124+64*2)<<8)+(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+126+64*2));//
      		break;	
					
      	default:
					T2C_RemoteCaliDat001.ReserveData002=(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+120)<<8)+(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+122));// 
					T2C_RemoteCaliDat001.CheckSum=(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+124)<<8)+(MODBUS_ASCII_AsciiToHex(temp_dataFromUsart1+1+126));// 
				
      		break;
      }
			
			  
		
	  memset(&USART1_TX_BUF[33],'=',sizeof(USART1_TX_BUF)-33);//后边的数据全部用A填充
		*/
		if(T2C_RemoteCaliDat001.FunctionCode==JL_COMMON_CMD_WriteRegs10)
		{
			T2C_RemoteCaliDat001.FunctionCode=JL_COMMON_CMD_WriteReg06;//命令兼容  10 06两个命令等效
		}
		
		if(T2C_RemoteCaliDat001.FunctionCode==JL_COMMON_CMD_ReadReg03)
		{//读取寄存器指令----开始
			switch (T2C_RemoteCaliDat001.AddrRegStart)
      {
      	case ADDR_Restart_ContBoard: //控制板复位指令
					//:3901955100010003020c8942F0508D41F16E01946667E66466C766644256666777788884423C0000111122223333444455556666777788889999abcdCCCCBBBB
					//:3901955100010003020c    只要前边能够匹配上就行，剩余的字节数不用管.
				
						
						memcpy(USART1_TX_BUF,temp_dataFromUsart1,16*2+1);//前16字节原样返回,共33字符 1表示起始字符英文下的冒号，hex为0x3a
						memset(&USART1_TX_BUF[33],'=',sizeof(USART1_TX_BUF)-33);
						sprintf((char*)(&USART1_TX_BUF[33]),"System will reboot... %5d",cmd39Cnt);
						Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,64);
						sprintf((char*)(&USART1_TX_BUF[65]),"%02X",Lrc_temp);
						USART1_TX_BUF[67] =0x0D;
						USART1_TX_BUF[68] = 0x0A;
						TerminalSlave485_Send_Data(USART1_TX_BUF,69);
				    	osDelay(100);
						memset(temp_dataFromUsart1,0,sizeof(temp_dataFromUsart1));//清零
						Reboot_System();
						
						break;
      	case	ADDR_Extended_ContBoard://读取控制板扩展地址
				    	T2C_RemoteCaliDat001.PayLoadData[0]=FM25L16B_ReadByte(ADDR_Extended_ContBoard+0);
						T2C_RemoteCaliDat001.PayLoadData[1]=FM25L16B_ReadByte(ADDR_Extended_ContBoard+1);
						T2C_RemoteCaliDat001.PayLoadData[2]=FM25L16B_ReadByte(ADDR_Extended_ContBoard+2);
						T2C_RemoteCaliDat001.PayLoadData[3]=FM25L16B_ReadByte(ADDR_Extended_ContBoard+3);
				    	T2C_RemoteCaliDat001.NumberOfRegs=4;
						break;
				
				
				case	ADDR_Version_ContBoard:
						FM25L16B_Read_N_Bytes(ADDR_Version_ContBoard,T2C_RemoteCaliDat001.PayLoadData,32); //读取32字节的版本号	
						T2C_RemoteCaliDat001.NumberOfRegs=32;	
				  					
						break;
				
				case	ADDR_Unique_ID_ContBoard:// 
						FM25L16B_Read_N_Bytes(ADDR_Unique_ID_ContBoard,T2C_RemoteCaliDat001.PayLoadData,16); 	
						T2C_RemoteCaliDat001.NumberOfRegs=16;	
						break;
				case	ADDR_VersionOf_Software:// 
						//FM25L16B_Read_N_Bytes(ADDR_VersionOf_Software,T2C_RemoteCaliDat001.PayLoadData,32); 	
						//memset(&USART1_TX_BUF[33],'=',sizeof(USART1_TX_BUF)-33);
						//sprintf((char*)(&USART1_TX_BUF[33]),"%s\r\n",T2C_RemoteCaliDat001.PayLoadData);
			 			// for(i000=0;i000<strlen(Version_software);++i000)
						// {
						// 	sprintf(USART1_TX_BUF+33+2*i000,"%02X",Version_software[i000]);
						// }
						//strcpy(T2C_RemoteCaliDat001.PayLoadData,Version_software);
						//T2C_RemoteCaliDat001.NumberOfRegs = strlen(Version_software);
						for(i000=0;i000<8;++i000)
						{
							T2C_RemoteCaliDat001.PayLoadData[i000*4] = (Version_Soft[i000]>>24)&0xff;
							T2C_RemoteCaliDat001.PayLoadData[i000*4+1] = (Version_Soft[i000]>>16)&0xff;
							T2C_RemoteCaliDat001.PayLoadData[i000*4+2] = (Version_Soft[i000]>>8)&0xff;
							T2C_RemoteCaliDat001.PayLoadData[i000*4+3] = (Version_Soft[i000]>>0)&0xff;
						}
						T2C_RemoteCaliDat001.NumberOfRegs = 32;
						break;
				
				case	ADDR_VersionOf_Hardware:// 
						FM25L16B_Read_N_Bytes(ADDR_VersionOf_Hardware,T2C_RemoteCaliDat001.PayLoadData,32); 	
						T2C_RemoteCaliDat001.NumberOfRegs=32;	
						break;
				case	ADDR_VersionOf_LCD:// 
						FM25L16B_Read_N_Bytes(ADDR_VersionOf_LCD,T2C_RemoteCaliDat001.PayLoadData,32); 
						T2C_RemoteCaliDat001.NumberOfRegs=32;	
						break;
				case	ADDR_ManHoLe_Number:
						FM25L16B_Read_N_Bytes(ADDR_StoreNumber,T2C_RemoteCaliDat001.PayLoadData,1); 
						FM25L16B_Read_N_Bytes(ADDR_ManHole_Big_info,T2C_RemoteCaliDat001.PayLoadData+1,1); 
						FM25L16B_Read_N_Bytes(ADDR_ManHole_small_info,T2C_RemoteCaliDat001.PayLoadData+2,1);
						FM25L16B_Read_N_Bytes(ADDR_Dump_info,T2C_RemoteCaliDat001.PayLoadData+3,1);
						FM25L16B_Read_N_Bytes(ADDR_Foot_info,T2C_RemoteCaliDat001.PayLoadData+4,1);
						T2C_RemoteCaliDat001.NumberOfRegs = 5;
						break;
				case	ADDR_RTC_ScreenDwin:
					ds1302_SynTime(&m_datetime);
					T2C_RemoteCaliDat001.PayLoadData[0] = m_datetime.year;
					T2C_RemoteCaliDat001.PayLoadData[1] = m_datetime.month;
					T2C_RemoteCaliDat001.PayLoadData[2] = m_datetime.day;
					T2C_RemoteCaliDat001.PayLoadData[3] = m_datetime.hour;
					T2C_RemoteCaliDat001.PayLoadData[4] = m_datetime.min;
					T2C_RemoteCaliDat001.PayLoadData[5] = m_datetime.sec;
				
					T2C_RemoteCaliDat001.NumberOfRegs = 6;
					break;
				case ADDR_RTC_ScreenDwin+1:
					memset(T2C_RemoteCaliDat001.PayLoadData,0,24);
					ds1302_SynTime(&m_datetime);
					T2C_RemoteCaliDat001.PayLoadData[3] = m_datetime.year;
					T2C_RemoteCaliDat001.PayLoadData[7] = m_datetime.month;
					T2C_RemoteCaliDat001.PayLoadData[11] = m_datetime.day;
					T2C_RemoteCaliDat001.PayLoadData[15] = m_datetime.hour;
					T2C_RemoteCaliDat001.PayLoadData[19] = m_datetime.min;
					T2C_RemoteCaliDat001.PayLoadData[23] = m_datetime.sec;
					T2C_RemoteCaliDat001.NumberOfRegs = 24;
					break;
				case	ADDR_Zero_Of_LiquidMeter://兼容8仓	液位计零点
					//数据回读
					FM25L16B_Read_N_Bytes(ADDR_Zero_Of_LiquidMeter,T2C_RemoteCaliDat001.PayLoadData,32);
					T2C_RemoteCaliDat001.NumberOfRegs=32;			
      				break;
				case ADDR_Zero_Of_TankCapacity:
				//数据回读
					FM25L16B_Read_N_Bytes(ADDR_Zero_Of_TankCapacity,T2C_RemoteCaliDat001.PayLoadData,32);
			 		T2C_RemoteCaliDat001.NumberOfRegs=32;
					break;
				case ADDR_RunAn_AlarmThreshold:
					//湖南润安项目  李伟修改  20211130   压力报警上限、下限、温度上限、下限、温度修正、压力窗口时长、压力正偏门限、负偏门限、压力修正、算法类型等

					//数据回读
					FM25L16B_Read_N_Bytes(ADDR_RunAn_AlarmThreshold, T2C_RemoteCaliDat001.PayLoadData, 44);
					T2C_RemoteCaliDat001.NumberOfRegs = 44;
					break;
				case ADDR_USART1_RE_TIMEOUT:
					FM25L16B_Read_N_Bytes(ADDR_USART1_RE_TIMEOUT, T2C_RemoteCaliDat001.PayLoadData, 4);
					T2C_RemoteCaliDat001.NumberOfRegs = 4;
					break;
				case ADDR_DISP_VT_TYPE:
				case ADDR_Enable_BlankSeal:
					FM25L16B_Read_N_Bytes(T2C_RemoteCaliDat001.AddrRegStart, T2C_RemoteCaliDat001.PayLoadData, 1);
					T2C_RemoteCaliDat001.NumberOfRegs = 1;
					break;
				case	ADDR_AutoSealed_Time://自动施封时长
					T2C_RemoteCaliDat001.PayLoadData[0] = Config_info_all.Auto_Seal_Time>>8;
					T2C_RemoteCaliDat001.PayLoadData[1] = Config_info_all.Auto_Seal_Time;
				  T2C_RemoteCaliDat001.NumberOfRegs = 2;	
					break;
				case	ADDR_Enable_ReSeal://是否允许重复施封 断电保存 
					T2C_RemoteCaliDat001.PayLoadData[0] = Config_info_all.Config_fun_id;
				  T2C_RemoteCaliDat001.NumberOfRegs = 1;	
					break;
				case	ADDR_OiLType_Data://油品参数   膨胀系数
 					FM25L16B_Read_N_Bytes(ADDR_OiLType_Data,T2C_RemoteCaliDat001.PayLoadData,32);
					T2C_RemoteCaliDat001.NumberOfRegs = 32;
					break;
				case	IDEX_ADDR_Scan_Param:
 					FM25L16B_Read_N_Bytes(FRAM_ADDR_Scan_Param,T2C_RemoteCaliDat001.PayLoadData,16);
					T2C_RemoteCaliDat001.NumberOfRegs = 16; 
      		        break;	
				case	IDEX_ADDR_Read_WorkSt: 					
					T2C_RemoteCaliDat001.NumberOfRegs = jt808_Build_Read_WorkSt(T2C_RemoteCaliDat001.PayLoadData); 
      		break;
				default:

					//memset(&USART1_TX_BUF[33], '=', sizeof(USART1_TX_BUF) - 33);
					T2C_RemoteCaliDat001.NumberOfRegs=sprintf(T2C_RemoteCaliDat001.PayLoadData, "Read Address Error! %08X\r\n", T2C_RemoteCaliDat001.AddrRegStart);
					break;
				} //读取寄存器指令

		}//读取寄存器指令----结束
		else if(T2C_RemoteCaliDat001.FunctionCode==JL_COMMON_CMD_WriteReg06)
		{//写入寄存器指令----开始
			
			switch (T2C_RemoteCaliDat001.AddrRegStart)
      {
				//:3901955100010006020c8942F0508D41F16E01946667E66466C766644256666777788884423C0000111122223333444455556666777788889999abcdCCCCBBBB
      	case ADDR_Restart_ContBoard: //控制板复位指令
						memcpy(USART1_TX_BUF,temp_dataFromUsart1,16*2+1);//前16字节原样返回,共33字符 1表示起始字符英文下的冒号，hex为0x3a
						memset(&USART1_TX_BUF[33],'=',sizeof(USART1_TX_BUF)-33);
						sprintf((char*)(&USART1_TX_BUF[33]),"System will reboot... %5d",cmd39Cnt);
						Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,64);
						sprintf((char*)(&USART1_TX_BUF[65]),"%02X",Lrc_temp);
						USART1_TX_BUF[67] =0x0D;
						USART1_TX_BUF[68] = 0x0A;
						TerminalSlave485_Send_Data(USART1_TX_BUF,69);
						//memset(temp_dataFromUsart1,0,sizeof(temp_dataFromUsart1));//清零
						osDelay(100);
						Reboot_System();
						break;
      	case	ADDR_Extended_ContBoard://设定扩展地址
					//addr_ext_controllBoard=(T2C_RemoteCaliDat001.PayLoadData[0]<<24)+(T2C_RemoteCaliDat001.PayLoadData[1]<<16)+(T2C_RemoteCaliDat001.PayLoadData[2]<<8)+(T2C_RemoteCaliDat001.PayLoadData[3]);
					FM25L16B_WriteByte(ADDR_Extended_ContBoard+0,T2C_RemoteCaliDat001.PayLoadData[0]);
					FM25L16B_WriteByte(ADDR_Extended_ContBoard+1,T2C_RemoteCaliDat001.PayLoadData[1]);
					FM25L16B_WriteByte(ADDR_Extended_ContBoard+2,T2C_RemoteCaliDat001.PayLoadData[2]);
					FM25L16B_WriteByte(ADDR_Extended_ContBoard+3,T2C_RemoteCaliDat001.PayLoadData[3]);
					/*memset(&USART1_TX_BUF[33],'=',sizeof(USART1_TX_BUF)-33);
					sprintf((char*)(&USART1_TX_BUF[33]),"%02X%02X%02X%02X",T2C_RemoteCaliDat001.PayLoadData[0],
								T2C_RemoteCaliDat001.PayLoadData[1],T2C_RemoteCaliDat001.PayLoadData[2],T2C_RemoteCaliDat001.PayLoadData[3]);
					*/
					break;
				
				case	ADDR_Version_ContBoard://STM32F746VGT6+2021v1.06	版本号  32字节
					//addr_ext_controllBoard=(T2C_RemoteCaliDat001.PayLoadData[0]<<24)+(T2C_RemoteCaliDat001.PayLoadData[1]<<16)+(T2C_RemoteCaliDat001.PayLoadData[2]<<8)+(T2C_RemoteCaliDat001.PayLoadData[3]);
//					FM25L16B_WriteByte(ADDR_Extended_ContBoard+0,T2C_RemoteCaliDat001.PayLoadData[0]);
//					FM25L16B_WriteByte(ADDR_Extended_ContBoard+1,T2C_RemoteCaliDat001.PayLoadData[1]);
//					FM25L16B_WriteByte(ADDR_Extended_ContBoard+2,T2C_RemoteCaliDat001.PayLoadData[2]);
//					FM25L16B_WriteByte(ADDR_Extended_ContBoard+3,T2C_RemoteCaliDat001.PayLoadData[3]);
					FM25L16B_Write_N_Bytes(ADDR_Version_ContBoard,T2C_RemoteCaliDat001.PayLoadData,32);

					/*for(i001=0;i001<32;i001++)
					{
						sprintf((char*)(&USART1_TX_BUF[33+i001]),"%02X",T2C_RemoteCaliDat001.PayLoadData[i001]);
					
					}*/
					
					break;
				
				case	ADDR_AutoSealed_Time://自动施封时长
 					FM25L16B_Write_N_Bytes(ADDR_AutoSealed_Time,T2C_RemoteCaliDat001.PayLoadData,2);
					Config_info_all.Auto_Seal_Time = (FM25L16B_ReadByte(ADDR_AutoSealed_Time + 0) << 8) | FM25L16B_ReadByte(ADDR_AutoSealed_Time + 1);
					if(Config_info_all.Auto_Seal_Time==0)
					{
						Config_info_all.Auto_Seal_Time = 300;
					}
					T2C_RemoteCaliDat001.PayLoadData[0] = Config_info_all.Auto_Seal_Time>>8;
					T2C_RemoteCaliDat001.PayLoadData[1] = Config_info_all.Auto_Seal_Time;
				  T2C_RemoteCaliDat001.NumberOfRegs = 2;	
					break;
				case	ADDR_DataSource_LiquidoMeter://液晶屏数据显示来源——液位参数
					
				
 					FM25L16B_Write_N_Bytes(ADDR_DataSource_LiquidoMeter,T2C_RemoteCaliDat001.PayLoadData,4);	
					for(i001=0;i001<4;i001++)
					{
						sprintf((char*)(&USART1_TX_BUF[33+i001]),"%02X",T2C_RemoteCaliDat001.PayLoadData[i001]);
					
					}				
					
					
								//读取数据显示来源

					uni_flo001_init.array_u8[3]=FM25L16B_ReadByte(ADDR_DataSource_LiquidoMeter+0+0*4);
					uni_flo001_init.array_u8[2]=FM25L16B_ReadByte(ADDR_DataSource_LiquidoMeter+1+0*4);
					uni_flo001_init.array_u8[1]=FM25L16B_ReadByte(ADDR_DataSource_LiquidoMeter+2+0*4);
					uni_flo001_init.array_u8[0]=FM25L16B_ReadByte(ADDR_DataSource_LiquidoMeter+3+0*4);

					data_Src_To_Disp=uni_flo001_init.u32Dat;//(FM25L16B_ReadByte(ADDR_Zero_Of_LiquidMeter+0)<<8)  +  FM25L16B_ReadByte(ADDR_Zero_Of_LiquidMeter+1);			
					break;
					
					
				case	ADDR_DataSource_ElecSeal://液晶屏数据显示来源——铅封参数
 					FM25L16B_Write_N_Bytes(ADDR_DataSource_ElecSeal,T2C_RemoteCaliDat001.PayLoadData,4); 
					/*for(i001=0;i001<4;i001++)
					{
						sprintf((char*)(&USART1_TX_BUF[33+i001]),"%02X",T2C_RemoteCaliDat001.PayLoadData[i001]);
					
					}		*/		
					break;
  
				
				case	ADDR_V20_Point://V20计算温度点的选择
 					FM25L16B_Write_N_Bytes(ADDR_V20_Point,T2C_RemoteCaliDat001.PayLoadData,16); 
					/*for(i001=0;i001<16;i001++)
					{
						sprintf((char*)(&USART1_TX_BUF[33+i001]),"%02X",T2C_RemoteCaliDat001.PayLoadData[i001]);
					
					}*/				
					break;				
 
				
				
				
				
				case ADDR_CarPlate_Number: //设定车牌号
					memset(bufText01Password,0,sizeof(bufText01Password));
					sprintf((char*)bufText01Password,"车牌号:%s AB\r\n",T2C_RemoteCaliDat001.PayLoadData);
					FunDebugCode=DebugFun_Show_Terminal;
					memcpy(CarLicensePlate,T2C_RemoteCaliDat001.PayLoadData,16);//拷贝16字节的车牌号，格式如：新M56454				
					//WriteCarLicensePlate();//保存车牌号
					FM25L16B_Write_N_Bytes(ADDR_CarPlate_Number,T2C_RemoteCaliDat001.PayLoadData,16);
				
					/*for(i001=0;i001<8;i001++)
					{
						sprintf((char*)(&USART1_TX_BUF[33+i001]),"%02X",T2C_RemoteCaliDat001.PayLoadData[i001]);
					
					}	*/	
					break;
				  					
 
				
				case	ADDR_Zero_Of_LiquidMeter://兼容8仓	液位计零点
 					FM25L16B_Write_N_Bytes(ADDR_Zero_Of_LiquidMeter,T2C_RemoteCaliDat001.PayLoadData,32); 
				  //解析8个浮点数数据
					for(i001=0;i001<8;i001++)
					{
						//下边4行代码顺序是反的   终端发过来的数据为1=0x3f800000
						uni_flo001.array_u8[3]=T2C_RemoteCaliDat001.PayLoadData[0+i001*4];
						uni_flo001.array_u8[2]=T2C_RemoteCaliDat001.PayLoadData[1+i001*4];
						uni_flo001.array_u8[1]=T2C_RemoteCaliDat001.PayLoadData[2+i001*4];
						uni_flo001.array_u8[0]=T2C_RemoteCaliDat001.PayLoadData[3+i001*4];
						Zero_Of_LiquidMeter[i001]=uni_flo001.flo_Data;
						OffsetYewei[i001]=Zero_Of_LiquidMeter[i001];
					}	
					
					//数据回读
					FM25L16B_Read_N_Bytes(ADDR_Zero_Of_LiquidMeter,T2C_RemoteCaliDat001.PayLoadData,32);
					T2C_RemoteCaliDat001.NumberOfRegs=32;			
      				break;
				case	ADDR_Zero_Of_TankCapacity://兼容8仓	罐容Vt零点
 					FM25L16B_Write_N_Bytes(ADDR_Zero_Of_TankCapacity,T2C_RemoteCaliDat001.PayLoadData,32); 
					//解析8个浮点数数据
					for(i001=0;i001<8;i001++)
					{
						uni_flo001.array_u8[3]=T2C_RemoteCaliDat001.PayLoadData[0+i001*4];
						uni_flo001.array_u8[2]=T2C_RemoteCaliDat001.PayLoadData[1+i001*4];
						uni_flo001.array_u8[1]=T2C_RemoteCaliDat001.PayLoadData[2+i001*4];
						uni_flo001.array_u8[0]=T2C_RemoteCaliDat001.PayLoadData[3+i001*4];						
						Zero_Of_TankCapacity[i001]=uni_flo001.flo_Data;
						OffsetTankCapacity[i001]=Zero_Of_TankCapacity[i001];
					}	
					
					//offsetLeiDa005=(FM25L16B_ReadByte(ADDR_Zero_Of_LiquidMeter+2)<<8)  +  FM25L16B_ReadByte(ADDR_Zero_Of_LiquidMeter+3);
				 
					//数据回读
					FM25L16B_Read_N_Bytes(ADDR_Zero_Of_TankCapacity,T2C_RemoteCaliDat001.PayLoadData,32);
			 		T2C_RemoteCaliDat001.NumberOfRegs=32;			
					break;
				case	ADDR_ManHoLe_Number://人孔盖卸油阀数量
					
					//解析8个浮点数数据
					for(i001=0;i001<8;i001++)
					{
						//下边4行代码顺序是反的   终端发过来的数据为1=0x3f800000
						uni_flo001.array_u8[3]=T2C_RemoteCaliDat001.PayLoadData[0+i001*4];
						uni_flo001.array_u8[2]=T2C_RemoteCaliDat001.PayLoadData[1+i001*4];
						uni_flo001.array_u8[1]=T2C_RemoteCaliDat001.PayLoadData[2+i001*4];
						uni_flo001.array_u8[0]=T2C_RemoteCaliDat001.PayLoadData[3+i001*4];
						
						if((uni_flo001.flo_Data>8) && (uni_flo001.flo_Data!=128))
						{
							uni_flo001.flo_Data=8;
						}
						
					  	if(uni_flo001.flo_Data<1)
						{
						  uni_flo001.flo_Data=1;
						}						
						
						Num_Of_Cang_HaiDifa_0x39[i001]=(uint8_t)uni_flo001.flo_Data;	
					}	

					Config_info_all.All_number = Num_Of_Cang_HaiDifa_0x39[0];
					StoreNumber = Config_info_all.All_number;					
					FM25L16B_WriteByte(ADDR_StoreNumber,StoreNumber);
					
					
					Config_info_all.ManHole_Big_info = Num_Of_Cang_HaiDifa_0x39[1];//人孔盖信息（大盖）bit7标定大盖有没有 1没有 0有
					FM25L16B_WriteByte(ADDR_ManHole_Big_info,Config_info_all.ManHole_Big_info);
					
					Config_info_all.ManHole_small_info = Num_Of_Cang_HaiDifa_0x39[2];// UART4_RX_BUF[6];//小盖单独标定，bit7标定大盖有没有 1没有 0有
					FM25L16B_WriteByte(ADDR_ManHole_small_info,Config_info_all.ManHole_small_info);
					
					
					Config_info_all.Dump_info =  Num_Of_Cang_HaiDifa_0x39[3];//UART4_RX_BUF[7];//卸油阀标定bit7=0常规一仓一个，bit7=1特殊一仓两个
					FM25L16B_WriteByte(ADDR_Dump_info,Config_info_all.Dump_info);
					
					Config_info_all.HaiDiFa_info =  Num_Of_Cang_HaiDifa_0x39[4];//UART4_RX_BUF[8];//底阀标定bit7=0气阀，bit7=1特殊485（日后可能会改）
					FM25L16B_WriteByte(ADDR_Foot_info,Config_info_all.HaiDiFa_info);
					all_Store = StoreNumber;
					Go_homepage();//回到首页
					
					
				
		/*		
						//控制器参数标定：大盖、小盖、卸油阀、海底阀数量
		else if((UART4_RX_BUF[0]==0x50)&&(UART4_RX_BUF[1]==0x81))//设置控制器参数：buf2
		{			
			Config_info_all.Config_fun_id=UART4_RX_BUF[2];//功能配置ID
			FM25L16B_WriteByte(ADDR_Config_fun_id,Config_info_all.Config_fun_id);
			Config_info_all.Collection_id = UART4_RX_BUF[3];
			Baseval_ID = Config_info_all.Collection_id;//默认一个初始化
			FM25L16B_WriteByte(ADDR_Baseval_ID,Baseval_ID);
			
		}
			
		*/    //大盖，小盖，卸油阀，底阀数量
 					//FM25L16B_Write_N_Bytes(ADDR_ManHoLe_Number,T2C_RemoteCaliDat001.PayLoadData,32); 
					/*for(i001=0;i001<64;i001++)
					{
						sprintf((char*)(&USART1_TX_BUF[33+i001]),"%02X",T2C_RemoteCaliDat001.PayLoadData[i001]);
					
					}			*/
					FM25L16B_Read_N_Bytes(ADDR_StoreNumber,T2C_RemoteCaliDat001.PayLoadData,1); 
					FM25L16B_Read_N_Bytes(ADDR_ManHole_Big_info,T2C_RemoteCaliDat001.PayLoadData+1,1); 
					FM25L16B_Read_N_Bytes(ADDR_ManHole_small_info,T2C_RemoteCaliDat001.PayLoadData+2,1);
					FM25L16B_Read_N_Bytes(ADDR_Dump_info,T2C_RemoteCaliDat001.PayLoadData+3,1);
					FM25L16B_Read_N_Bytes(ADDR_Foot_info,T2C_RemoteCaliDat001.PayLoadData+4,1);
					T2C_RemoteCaliDat001.NumberOfRegs = 5;
 			
      		break;
					
				case	ADDR_Enable_ReSeal://是否允许重复施封 断电保存 
          //解析8个浮点数数据----合法的取值只有两种0,1
#if 0				
					for(i001=0;i001<8;i001++)
					{
						//下边4行代码顺序是反的   终端发过来的数据为1=0x3f800000
						uni_flo001.array_u8[3]=T2C_RemoteCaliDat001.PayLoadData[0+i001*4];
						uni_flo001.array_u8[2]=T2C_RemoteCaliDat001.PayLoadData[1+i001*4];
						uni_flo001.array_u8[1]=T2C_RemoteCaliDat001.PayLoadData[2+i001*4];
						uni_flo001.array_u8[0]=T2C_RemoteCaliDat001.PayLoadData[3+i001*4];
						
						if(uni_flo001.flo_Data>8)
						{
						  uni_flo001.flo_Data=1;
						}
						
					  if(uni_flo001.flo_Data<0)
						{
						  uni_flo001.flo_Data=0;
						}						
						
						//借用仓数的变量名称
						Num_Of_Cang_HaiDifa_0x39[i001]=(uint8_t)uni_flo001.flo_Data;
						

					}	
					__nop();		
					
					
					for(i001=0;i001<8;i001++)
					{
            			SensorEnable_ReSeal[i001]=0;//1<<(7-i001);
					  	if(Num_Of_Cang_HaiDifa_0x39[i001]>0)
						{
						  	Num_Of_Cang_HaiDifa_0x39[i001]=1;
							SensorEnable_ReSeal[i001]=1<<(7-i001);
						}	
					}
					
          			tmp0x39=0;
					for(i001=0;i001<8;i001++)
					{
						tmp0x39=tmp0x39 | SensorEnable_ReSeal[i001];
					}			
#endif
					Config_info_all.Config_fun_id=T2C_RemoteCaliDat001.PayLoadData[0];//UART4_RX_BUF[2];//功能配置ID
					FM25L16B_WriteByte(ADDR_Config_fun_id,Config_info_all.Config_fun_id);
					/*Config_info_all.Collection_id = UART4_RX_BUF[3];
					Baseval_ID = Config_info_all.Collection_id;//默认一个初始化*/
					//FM25L16B_WriteByte(ADDR_Baseval_ID,Baseval_ID);
					T2C_RemoteCaliDat001.NumberOfRegs = 1; 				
      		break;					
					
				
				case	ADDR_OiLType_Data://油品参数   膨胀系数
 					FM25L16B_Write_N_Bytes(ADDR_OiLType_Data,T2C_RemoteCaliDat001.PayLoadData,32);
					for (i000 = 0; i000 < 8; i000++)
					{
						uni_flo001_init.array_u8[3] = FM25L16B_ReadByte(ADDR_OiLType_Data + 0 + i000 * 4);
						uni_flo001_init.array_u8[2] = FM25L16B_ReadByte(ADDR_OiLType_Data + 1 + i000 * 4);
						uni_flo001_init.array_u8[1] = FM25L16B_ReadByte(ADDR_OiLType_Data + 2 + i000 * 4);
						uni_flo001_init.array_u8[0] = FM25L16B_ReadByte(ADDR_OiLType_Data + 3 + i000 * 4);

						ExpansionRatio[i000] = uni_flo001_init.flo_Data; //(FM25L16B_ReadByte(ADDR_Zero_Of_LiquidMeter+0)<<8)  +  FM25L16B_ReadByte(ADDR_Zero_Of_LiquidMeter+1);
					}
					T2C_RemoteCaliDat001.NumberOfRegs = 32; 
      		break;
      		
				case	IDEX_ADDR_Scan_Param:
 					FM25L16B_Write_N_Bytes(FRAM_ADDR_Scan_Param,T2C_RemoteCaliDat001.PayLoadData,16);
					jt808_InitSensorScanParam();
					T2C_RemoteCaliDat001.NumberOfRegs = 16; 
      			break;	

      			case	IDEX_ADDR_Read_WorkSt:
      			    memset(queue_record_obj.cmd,0,sizeof(queue_record_obj.cmd));
 					strncpy(queue_record_obj.cmd, (char *)T2C_RemoteCaliDat001.PayLoadData, sizeof(queue_record_obj.cmd)-1);
					T2C_RemoteCaliDat001.NumberOfRegs = 16; 
      			break;
      			
				case	ADDR_TiltAngle_Sensor://倾角补偿参数  ----长度为16字节
 					FM25L16B_Write_N_Bytes(ADDR_TiltAngle_Sensor,T2C_RemoteCaliDat001.PayLoadData,16);
					T2C_RemoteCaliDat001.NumberOfRegs=16;	
      				break;					
					
				
				case	ADDR_Zero_Of_TempSensor://温度偏移参数
 					FM25L16B_Write_N_Bytes(ADDR_Zero_Of_TempSensor,T2C_RemoteCaliDat001.PayLoadData,32); 	
					T2C_RemoteCaliDat001.NumberOfRegs=32;			
      				break;
				
				case	ADDR_SampIntervaL_Collector://单位为毫秒。取值范围为800--1200	同采集板的采样间隔
 					FM25L16B_Write_N_Bytes(ADDR_SampIntervaL_Collector,T2C_RemoteCaliDat001.PayLoadData,16); 	
					T2C_RemoteCaliDat001.NumberOfRegs=16;				
					break;
					
 
				
				case	ADDR_SleepTime_ScreenDwin://单位为秒。取值范围为300--3000	屏幕休眠时间
 					FM25L16B_Write_N_Bytes(ADDR_SleepTime_ScreenDwin,T2C_RemoteCaliDat001.PayLoadData,8); 	
					T2C_RemoteCaliDat001.NumberOfRegs=8;				
		 			break;
				
				case	ADDR_RTC_ScreenDwin://屏幕RTC标定
 					//FM25L16B_Write_N_Bytes(ADDR_RTC_ScreenDwin,T2C_RemoteCaliDat001.PayLoadData,16); 	
					//5A A5 0B 82 00 9C 5A A5 32 0A 01 0B 0C 0D
					//:390195510001000601CC8942778899AA15060c01020366466C766644256666777788884423C0000111122223333444455556666777788889999abcdCCCCBBBB
				  memcpy(&time_Set_Dwin[8],T2C_RemoteCaliDat001.PayLoadData,6);
				  ScreenMaster485_Send_Data(time_Set_Dwin,14);
					//memcpy(TimeBuf+1,T2C_RemoteCaliDat001.PayLoadData,6);
#if 	1				
					uint8_t times_buf[32];
					memset(times_buf, 0x00,sizeof(times_buf));
					memcpy(times_buf+1,T2C_RemoteCaliDat001.PayLoadData,6);
					ds1302_Write_Time(times_buf);
#else				
					ds1302_Write_Time(T2C_RemoteCaliDat001.PayLoadData-1);
#endif				
					ds1302_SynTime(&m_datetime);
					fram_time_write(m_datetime);
					/*for(i001=0;i001<6;i001++)
					{
						sprintf((char*)(&USART1_TX_BUF[33+i001]),"%02X",T2C_RemoteCaliDat001.PayLoadData[i001]);
					
					}*/
					T2C_RemoteCaliDat001.NumberOfRegs = 6;
      			break;
				case ADDR_RTC_ScreenDwin+1:
					for(i000=0;i000<6;++i000)
					{
						time_Set_Dwin[8+i000] = T2C_RemoteCaliDat001.PayLoadData[i000*4+3];
					}
					ScreenMaster485_Send_Data(time_Set_Dwin,14);
					ds1302_Write_Time(time_Set_Dwin+7);
					T2C_RemoteCaliDat001.NumberOfRegs = 24;
					break;
				
				case	ADDR_Unique_ID_ContBoard:// 
 					FM25L16B_Write_N_Bytes(ADDR_Unique_ID_ContBoard,T2C_RemoteCaliDat001.PayLoadData,16); 	
					FM25L16B_Read_N_Bytes(ADDR_Unique_ID_ContBoard,T2C_RemoteCaliDat001.PayLoadData,16); 
					T2C_RemoteCaliDat001.NumberOfRegs=sprintf(T2C_RemoteCaliDat001.PayLoadData,"%s",T2C_RemoteCaliDat001.PayLoadData);
      		break;
				/*case	ADDR_VersionOf_Software:// 
 					FM25L16B_Write_N_Bytes(ADDR_VersionOf_Software,T2C_RemoteCaliDat001.PayLoadData,32); 	
					FM25L16B_Read_N_Bytes(ADDR_VersionOf_Software,T2C_RemoteCaliDat001.PayLoadData,32); 
					T2C_RemoteCaliDat001.NumberOfRegs=sprintf(T2C_RemoteCaliDat001.PayLoadData,"%s",T2C_RemoteCaliDat001.PayLoadData);
      		break;*/
				
				case	ADDR_VersionOf_Hardware:// 
 					FM25L16B_Write_N_Bytes(ADDR_VersionOf_Hardware,T2C_RemoteCaliDat001.PayLoadData,32); 
					FM25L16B_Read_N_Bytes(ADDR_VersionOf_Hardware,T2C_RemoteCaliDat001.PayLoadData,32); 
					T2C_RemoteCaliDat001.NumberOfRegs=sprintf(T2C_RemoteCaliDat001.PayLoadData,"%s",T2C_RemoteCaliDat001.PayLoadData);
	   
      		break;
				case	ADDR_VersionOf_LCD:// 
 					FM25L16B_Write_N_Bytes(ADDR_VersionOf_LCD,T2C_RemoteCaliDat001.PayLoadData,32); 
					FM25L16B_Read_N_Bytes(ADDR_VersionOf_LCD,T2C_RemoteCaliDat001.PayLoadData,32); 
					T2C_RemoteCaliDat001.NumberOfRegs=sprintf(T2C_RemoteCaliDat001.PayLoadData,"%s",T2C_RemoteCaliDat001.PayLoadData);
	   
      		break;
				
				case	ADDR_TotalRunTime://设定运行总时间 
 					FM25L16B_Write_N_Bytes(ADDR_TotalRunTime,T2C_RemoteCaliDat001.PayLoadData,4); 
					FM25L16B_Read_N_Bytes(ADDR_TotalRunTime,T2C_RemoteCaliDat001.PayLoadData,4); 
				  totalRunTimeCnt=(FM25L16B_ReadByte(ADDR_TotalRunTime+0)<<24)+(FM25L16B_ReadByte(ADDR_TotalRunTime+1)<<16)+(FM25L16B_ReadByte(ADDR_TotalRunTime+2)<<8)
									+(FM25L16B_ReadByte(ADDR_TotalRunTime+3));
					T2C_RemoteCaliDat001.NumberOfRegs=4;	
	   			break;
				
				
				case	ADDR_Sw_VoicePlay://远程切换语音播报 
					FunDebugCode=DebugFun_Sw_VoicePlay;
					//sprintf((char*)(&USART1_TX_BUF[33]),"%s\r\n",T2C_RemoteCaliDat001.PayLoadData);
					T2C_RemoteCaliDat001.NumberOfRegs=sprintf(T2C_RemoteCaliDat001.PayLoadData,"%8u",DebugFun_Sw_VoicePlay);
	   
      				break;				
				
				case	ADDR_Sw_ValveRaw://远程屏幕显示阀门原始数据或者汉字信息 
					FunDebugCode=DebugFun_Sw_ValveRaw;
					T2C_RemoteCaliDat001.NumberOfRegs=sprintf(T2C_RemoteCaliDat001.PayLoadData,"%8u",DebugFun_Sw_ValveRaw);
      				break;

				case ADDR_Reserve002_ContBoard: //远程设定控制板数据用于测试
					memcpy(&T2C_ALL_Sensor_Data01.IO_Valve_Data_Every_Cang[0], T2C_RemoteCaliDat001.PayLoadData, 32 * 4);
					break;
				case ADDR_Reserve003_ContBoard: //远程设定控制板数据用于测试
					memcpy(&T2C_ALL_Sensor_WholeCar01.tiltXYZ, T2C_RemoteCaliDat001.PayLoadData, 28);
					break;
				case ADDR_RunAn_AlarmThreshold:
					//湖南润安项目  李伟修改  20211130   压力报警上限、下限、温度上限、下限、温度修正、压力窗口时长、压力正偏门限、负偏门限、压力修正、算法类型等

					FM25L16B_Write_N_Bytes(ADDR_RunAn_AlarmThreshold, T2C_RemoteCaliDat001.PayLoadData, 44);
					//解析8个浮点数数据
					for (i001 = 0; i001 < 11; i001++)
					{
						//下边4行代码顺序是反的   终端发过来的数据为1=0x3f800000
						uni_flo001.array_u8[3] = T2C_RemoteCaliDat001.PayLoadData[0 + i001 * 4];
						uni_flo001.array_u8[2] = T2C_RemoteCaliDat001.PayLoadData[1 + i001 * 4];
						uni_flo001.array_u8[1] = T2C_RemoteCaliDat001.PayLoadData[2 + i001 * 4];
						uni_flo001.array_u8[0] = T2C_RemoteCaliDat001.PayLoadData[3 + i001 * 4];

						AlarmArrayData[i001] = uni_flo001.flo_Data;
					}

					AlarmOfPressureThreshold_Upper = AlarmArrayData[0];
					AlarmOfPressureThreshold_Lower = AlarmArrayData[1];
					AlarmOfTempeThreshold_Upper = AlarmArrayData[2];
					AlarmOfTempeThreshold_Lower = AlarmArrayData[3];

					BiasOfTempe = AlarmArrayData[4];
					PressureWindowsSpan = AlarmArrayData[5];
					PressurePositiveThreshold = AlarmArrayData[6];
					PressureNegativeThreshold = AlarmArrayData[7];

					BiasOfPressure = AlarmArrayData[8];
					AlgType = (uint32_t)AlarmArrayData[9];

					//数据回读
					FM25L16B_Read_N_Bytes(ADDR_RunAn_AlarmThreshold, T2C_RemoteCaliDat001.PayLoadData, 44);
					T2C_RemoteCaliDat001.NumberOfRegs = 44;
					break;
				case ADDR_USART1_RE_TIMEOUT:
					for (i001 = 0; i001 < 1; i001++)
					{
						//下边4行代码顺序是反的   终端发过来的数据为1=0x3f800000
						uni_flo001.array_u8[3] = T2C_RemoteCaliDat001.PayLoadData[0 + i001 * 4];
						uni_flo001.array_u8[2] = T2C_RemoteCaliDat001.PayLoadData[1 + i001 * 4];
						uni_flo001.array_u8[1] = T2C_RemoteCaliDat001.PayLoadData[2 + i001 * 4];
						uni_flo001.array_u8[0] = T2C_RemoteCaliDat001.PayLoadData[3 + i001 * 4];
						AlarmArrayData[i001] = uni_flo001.flo_Data;
					}
					if (AlarmArrayData[0] > 60)
					{
						usart_timeout = (uint32_t)AlarmArrayData[0];
					}
					else
					{
						usart_timeout = 0;
					}
					FM25L16B_Write_N_Bytes(ADDR_USART1_RE_TIMEOUT, T2C_RemoteCaliDat001.PayLoadData, 4);
					T2C_RemoteCaliDat001.NumberOfRegs = 4;
					break;
				case ADDR_DISP_VT_TYPE:
					vt_disp_type = T2C_RemoteCaliDat001.PayLoadData[0];
					FM25L16B_Write_N_Bytes(ADDR_DISP_VT_TYPE, T2C_RemoteCaliDat001.PayLoadData, 1);
					T2C_RemoteCaliDat001.NumberOfRegs = 1;
					break;
				case ADDR_Enable_BlankSeal:
					flag_En_BlankSeal = T2C_RemoteCaliDat001.PayLoadData[0];
					FM25L16B_Write_N_Bytes(ADDR_Enable_BlankSeal, T2C_RemoteCaliDat001.PayLoadData, 1);
					T2C_RemoteCaliDat001.NumberOfRegs = 1;
					break;
				//add boly 20221021
				case IDEX_ADDR_JT808_DataBack:
				{
					jt808_recv_func_DataBack(T2C_RemoteCaliDat001.PayLoadData, T2C_RemoteCaliDat001.NumberOfRegs);
					memset((void *)&T2C_RemoteCaliDat001, 0x00, sizeof(T2C_RemoteCaliDat001));	
					memset((void *)Pass41SensorScanParam.rx_buf, 0x00, sizeof(Pass41SensorScanParam.rx_buf));
					
					if(tmrForRemoteCali > (SPAN_RemoteCali_INTERVAL - 10))
					{
						tmrForRemoteCali = 0;
					}
					return 1;
				};//break;				
				//end boly
				default:
					T2C_RemoteCaliDat001.NumberOfRegs = sprintf(T2C_RemoteCaliDat001.PayLoadData, "Write Address Error! %08X\r\n", T2C_RemoteCaliDat001.AddrRegStart);
					break;
	  }
		}//写入寄存器指令----结束
		else
		{
			T2C_RemoteCaliDat001.NumberOfRegs = sprintf(T2C_RemoteCaliDat001.PayLoadData,"Modbus Command Error! %08X\r\n",T2C_RemoteCaliDat001.FunctionCode);
		}
		
		
#if  0		
			if(DataMode_For_RemCali==0x00)//数据模式是ASCII或者HEX
			{//ASCII模式下，只发送64*2+3字节	
					memcpy(USART1_TX_BUF,temp_dataFromUsart1,16*2+1);//前16字节原样返回,共33字符 1表示起始字符英文下的冒号，hex为0x3a 
					Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF+1,T2C_RemoteCaliDat001.NumberOfRegs);
					sprintf((char*)(&USART1_TX_BUF[T2C_RemoteCaliDat001.NumberOfRegs*2+33]),"%02X",Lrc_temp);
					USART1_TX_BUF[T2C_RemoteCaliDat001.NumberOfRegs*2+35] =0x0D;
					USART1_TX_BUF[T2C_RemoteCaliDat001.NumberOfRegs*2+36] = 0x0A;
					TerminalSlave485_Send_Data(USART1_TX_BUF,T2C_RemoteCaliDat001.NumberOfRegs*2+37);
			 		
			}
			else
			{//十六进制模式下，只发送64字节	
				
					memcpy(USART1_TX_BUF,temp_dataFromUsart1,16*1+1);//前16字节原样返回,共33字符 1表示起始字符英文下的冒号，hex为0x3a 
					Lrc_temp = MODBUS_GetLrc(USART1_TX_BUF+1,T2C_RemoteCaliDat001.NumberOfRegs);
					sprintf((char*)(&USART1_TX_BUF[T2C_RemoteCaliDat001.NumberOfRegs+1]),"%02X",Lrc_temp);
					USART1_TX_BUF[T2C_RemoteCaliDat001.NumberOfRegs+3] =0x0D;
					USART1_TX_BUF[T2C_RemoteCaliDat001.NumberOfRegs+4] = 0x0A;
					TerminalSlave485_Send_Data(USART1_TX_BUF,T2C_RemoteCaliDat001.NumberOfRegs+5);//64+3
 		
			}
#else
		if (dataMode == 0x00)
		{
			memcpy(USART1_TX_BUF, temp_dataFromUsart1, 16 * 2 + 1); //前16字节原样返回,共33字符 1表示起始字符英文下的冒号，hex为0x3a
		}
		else
		{
			memcpy(USART1_TX_BUF, temp_dataFromUsart1, 1);
			for (i001 = 0; i001 < 16; i001++)
			{
				sprintf((char *)(&USART1_TX_BUF[1 + i001 * 2]), "%02X", temp_dataFromUsart1[i001 + 1]);
			}
		}

		for (i001 = 0; i001 < T2C_RemoteCaliDat001.NumberOfRegs; i001++)
		{
			sprintf((char *)(&USART1_TX_BUF[33 + i001 * 2]), "%02X", T2C_RemoteCaliDat001.PayLoadData[i001]);
		}

		Lrc_temp = MODBUS_ASCII_GetLrc(USART1_TX_BUF + 1, 32 + T2C_RemoteCaliDat001.NumberOfRegs * 2);
		sprintf((char *)(&USART1_TX_BUF[33 + T2C_RemoteCaliDat001.NumberOfRegs * 2]), "%02X", Lrc_temp);
		USART1_TX_BUF[35 + T2C_RemoteCaliDat001.NumberOfRegs * 2] = 0x0D;
		USART1_TX_BUF[36 + T2C_RemoteCaliDat001.NumberOfRegs * 2] = 0x0A;
		TerminalSlave485_Send_Data(USART1_TX_BUF, 37 + T2C_RemoteCaliDat001.NumberOfRegs * 2);
#endif
	//	memset(temp_dataFromUsart1,0,sizeof(temp_dataFromUsart1));//清零
		return 1;
}


void WriteCarLicensePlate() //保存车牌号
{
			FM25L16B_WriteByte(ADDR_CarPlate_Number+0,CarLicensePlate[0]);
			FM25L16B_WriteByte(ADDR_CarPlate_Number+1,CarLicensePlate[1]);
			FM25L16B_WriteByte(ADDR_CarPlate_Number+2,CarLicensePlate[2]);
			FM25L16B_WriteByte(ADDR_CarPlate_Number+3,CarLicensePlate[3]);
			FM25L16B_WriteByte(ADDR_CarPlate_Number+4,CarLicensePlate[4]);
			FM25L16B_WriteByte(ADDR_CarPlate_Number+5,CarLicensePlate[5]);
			FM25L16B_WriteByte(ADDR_CarPlate_Number+6,CarLicensePlate[6]);
			FM25L16B_WriteByte(ADDR_CarPlate_Number+7,CarLicensePlate[7]);
}


