Weight.c 3.11 KB
#include "includes.h"
#include "hardware.h"
#include "all_value.h"

short WeightAll;
short F_WeightInitVa;//称重校准值/KG

u8 TIM4_USART5_SendNums;//串口5发送信息时间计数
u16 F_WeightMax;
#if WeightEn==1
	void UART5_IRQHandler(void)//串口5中断服务程序
	{
		u8 res;
		OSIntEnter();    
		if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET)  
		{
			res=USART_ReceiveData(UART5); 

			if(USART5_RX_CNT<Length_Usart5_RX)
			{
				USART5_RX_BUF[USART5_RX_CNT]=res;		//记录接收到的值
				if( ((res==0x01) && (USART5_RX_CNT==0))|
						((res==0x03) && (USART5_RX_CNT==1))|
	//				  ((res==0x24) && (USART5_RX_CNT==2))|			
						((USART5_RX_BUF[0]==0x01)&& (USART5_RX_BUF[1]==0x03)&& (USART5_RX_BUF[2]==0x24))   ){ CCD_M[1].Tim4_Usart56Nums=0;USART5_RX_CNT++;}//接收数据增加1
			} 
			
		} 
		USART_ClearITPendingBit(UART5,USART_IT_RXNE);
		OSIntExit();  											 
	} 




	void Weight_Data_Analysis(u8*Buffer)//相机数据解析+位置转换函数
	{ 
		u32 Va32;		
		u32 Weight;	
		u8 Va8[4];
		u8 S_index;	
		
		if(USART5_RX_CNT==Length_Usart5_RX)		                                                
		{
			Weight=0;
			if( (Buffer[0]==0x01) &&(Buffer[1]==0x03)&& (Buffer[2]==0x24) )
			{
				S_index=3;
				Va8[3]=Buffer[S_index];
				Va8[2]=Buffer[S_index+1];
				Va8[1]=Buffer[S_index+2];
				Va8[0]=Buffer[S_index+3];
				memcpy(&Va32,Va8,4);//第1路压力数值
				Weight+=Va32;
				
				S_index=7;
				Va8[3]=Buffer[S_index];
				Va8[2]=Buffer[S_index+1];
				Va8[1]=Buffer[S_index+2];
				Va8[0]=Buffer[S_index+3];
				memcpy(&Va32,Va8,4);//第2路压力数值
				Weight+=Va32;
				
				S_index=11;
				Va8[3]=Buffer[S_index];
				Va8[2]=Buffer[S_index+1];
				Va8[1]=Buffer[S_index+2];
				Va8[0]=Buffer[S_index+3];			
				memcpy(&Va32,Va8,4);//第3路压力数值
				Weight+=Va32;
				
				S_index=15;
				Va8[3]=Buffer[S_index];
				Va8[2]=Buffer[S_index+1];
				Va8[1]=Buffer[S_index+2];
				Va8[0]=Buffer[S_index+3];			
				memcpy(&Va32,Va8,4);//第4路压力数值
				Weight+=Va32;//单位*0.1KG
				

				Weight=Weight/10;//kg,
//				if (Weight>F_WeightInitVa)WeightAll=Weight-F_WeightInitVa;
//				else WeightAll=0;
				WeightAll=(short)((float)Weight-(float)F_WeightInitVa);
				
				if(SysKey==89)
				{ 
					if(VaIndexDW_R(&Touch_Contr,13))F_WeightInitVa=(short)Weight;//强制称重归零
				}
				
			}		
			memset(Buffer,0,9);	
			USART5_RX_CNT=0;

		}
		
	}


	u8 USART5_SX_BUF[Length_Usart5_SX];

	void Usart5_Sx_Deal(void)//称重发送指令信息
	{

	
				USART5_SX_BUF[0]=0x01;//通讯地址
				USART5_SX_BUF[1]=0x03;
				USART5_SX_BUF[2]=0x03;
				USART5_SX_BUF[3]=0x00;
				USART5_SX_BUF[4]=0x00;
				USART5_SX_BUF[5]=0x12;
				USART5_SX_BUF[6]=0xC5;
				USART5_SX_BUF[7]=0x83;
	}

#endif



void Weight_Pro(void)//相机相关程序外部总入口
{

#if WeightEn==1	
	if(VaIndexDW_R(&F_AgvContr,12))//有称重器件时
	{	if (TIM4_USART5_SendNums>Usart5_SendPerNums)
		{ Usart5_Sx_Deal();
			usart5_senddata(Length_Usart5_SX,USART5_SX_BUF);
			TIM4_USART5_SendNums=0;
		}	
			
		Weight_Data_Analysis(USART5_RX_BUF);//称重信息解析
		if (CCD_M[1].Tim4_Usart56Nums>100)
		{ VaIndexW_W(&NodeOnLine,14,0);
			Set_ErrID(59,1);} //ErrID=59;称重异常
		else{ VaIndexW_W(&NodeOnLine,14,1);Set_ErrID(59,0);}
	}
#endif
		


}