⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lfp.cpp

📁 基于PC104平台
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	  test3=0x01;
	  temp1/=16;
	  temp2-=temp1*16;
	  test3<<=temp2;
	  test4=~test3;
	  test1=0x01;
	  temp3=temp4=protect_yx[temp][2]&0xff;
	  temp3/=16;
	  temp4-=temp3*16;
	  test1<<=temp4;
	  if((tempd[temp3]&test1)!=0)
		prot_yx[temp1]|=test3;
	  else
		prot_yx[temp1]&=test4;
	}
	 }
  }
}//process_R19;

void CLfp::process_R20(BYTE *pointer)
{
  unsigned int test=0x01;
  unsigned int temp,len;
  //unsigned int add;
  unsigned int temp1,temp2,j;
  SOE1 temp_soe;
  struct time_tt soe_time;
  phaddre=*(pointer+1);
  if(datasource.protect_yx==0)	return;

  if ((protect_yx[0][0]!=4096)||(protect_yx[1][0]!=4096)) {
	 len=(*(pointer+5))-4;
	 for (int i=0;i<len;i+=7) {
		 temp=lfpyxno(iportno,phaddre,(*(pointer+i+11)),1);
		 if (temp!=0xffff) {
			temp1=temp2=temp;//17*(add-1)+temp;
			test=0x01;
			temp1/=16;
			temp2-=temp1*16;
			test<<=temp2;
			if (((*(pointer+12+i))&0x01)!=0) {
			   prot_yx[temp1]|=test;  //save yx value
			   temp_soe.status = 0xaa;
			}
			else {
			   prot_yx[temp1]&=~test;
			   temp_soe.status = 0x55;
			}
			temp_soe.orderno = temp + datasource.board_yx;
			for (j = 0; j < 10; j++) temp_soe.send_status[j] = 3;

			struct date d;
		    getdate(&d);
		    soe_time.year=d.da_year;
		    soe_time.month=d.da_mon;
		    soe_time.day=d.da_day;

			soe_time.hour=(*(pointer+i+6))&0xff;
		    soe_time.minute=(*(pointer+i+7))&0xff;
		    soe_time.second=(*(pointer+i+8))&0xff;
		    temp=(*(pointer+i+10))&0xff;
		    temp<<=0x08;
		    temp+=(*(pointer+i+9))&0xff;
		    soe_time.mil_second=temp;
		    temp_soe.time = soe_time;

			insertsoe( &temp_soe );
		 }//    if(temp1!=0xffff)
	  }//    for(int i=0;i<len;i+=7)
  }//if((protect_yx[0][0]!=4096)||(protect_yx[1][0]!=4096))
  sendinfo.send_ack=TRUE;
  return;
}

void CLfp::process_R10(BYTE *pointer)
{
  unsigned int test=0x01;
  unsigned int temp,len;
  unsigned int temp1,temp2,tmp3,test1,j;
  struct time_tt soe_time;
  yx_bw_tt tempyxbw;

  phaddre=*(pointer+1);
  if (datasource.protect_yx==0)	return;
  if ((protect_yx[0][0]!=4096)||(protect_yx[1][0]!=4096)) {
	 len=(*(pointer+5))-4;
	 for (int i=0;i<len;i+=2) {
		 temp=lfpyxno(iportno,phaddre,(*(pointer+i+6)),1);
		 if (temp!=0xffff) {
			temp1=temp2=temp;//17*(add-1)+temp;
			test=0x01;
			temp1/=16;
			temp2-=temp1*16;
			test<<=temp2;
			if (((*(pointer+7+i))&0x01)!=0) prot_yx[temp1]|=test;  //save yx value
			else prot_yx[temp1]&=~test;

			tmp3=temp + datasource.board_yx;
			tempyxbw.func_code = tmp3 / 32 + 0xf0;

			if (prot_yx[temp1]&test) port_yx[tmp3/16]|=test;
			else port_yx[tmp3/16]&=~test;                         // modify port_yx

			tempyxbw.two_yx_word[0] = port_yx[tmp3 / 32 * 2];
			tempyxbw.two_yx_word[1] = port_yx[tmp3 / 32 * 2 + 1];
			for ( j = 0; j < 8; j++ )
				tempyxbw.send_count[j] = 3;
			insertyxbw( &tempyxbw );                               // record yxbw to fifo
		 }//    if(temp1!=0xffff)
	 }//    for(int i=0;i<len;i+=7)
  }//if((protect_yx[0][0]!=4096)||(protect_yx[1][0]!=4096))
  sendinfo.send_ack=TRUE;
}//process_R10;

/*********************process receive information end   ******************/

/***************************phiscal end   ********************************/
void CLfp::send_ack_frame()
{
  if((sendinfo.current_send_flag==FALSE)&&(sendinfo.send_ack==TRUE))
  {
	sendinfo.send_ack=FALSE;
	sendinfo.current_frame_type=LFP_ACK;
	sendinfo.current_send_flag=TRUE;
	sendinfo.start_a_send=TRUE;
  }//if((sendinfo.current_send_flag==FALSE)&&(sendinfo.send_ack==TRUE))
}//send_ack_frame();
void CLfp::send_nak_frame()
{
  if((sendinfo.current_send_flag==FALSE)&&(sendinfo.send_nak==TRUE))
  {
	 sendinfo.send_nak=FALSE;
	 sendinfo.current_frame_type=LFP_NAK;
	 sendinfo.current_send_flag=TRUE;
	 sendinfo.start_a_send=TRUE;
  }//if((sendinfo.current_send_flag==FALSE)&&(sendinfo.send_ack==TRUE))
}//send_nak_frame();
/**************************************************************************/
void CLfp::putdata(BYTE data)
{  dataque.buf[dataque.next++]=data&0xff;
  if(dataque.next>=dataque.size)dataque.next=0;
  dataque.count++;
  if(dataque.count>dataque.size)
  { dataque.count=dataque.size;    dataque.start++;
	if(dataque.start>=dataque.size)dataque.start=0;
  }//if(dataque.count>dataque.size)
}//void CTop::putdata(BYTE data)

void CLfp::dropdata()
{
  if(dataque.count>0)
  { dataque.start++;
	if(dataque.start>=dataque.size)dataque.start=0;
	dataque.count--;
  }//if(dataque.count>0)
}//void CTop::dropdata()

unsigned int CLfp::check(BYTE *pointer,int len)
{
   int i;
   unsigned int result=0;
   for(i=0;i<len;i++)result+=*(pointer+i);
   return(result);
}//check

unsigned int CLfp::mod(unsigned int par1,unsigned int par2)
{
 if(par1>=par2)return(par1-(par1/par2)*par2);
 else return(par1);
}//unsigned int CLfp::mod(unsigned int par1,unsigned int par2)

void CLfp::getlfpcmd()
{
  unsigned int test,temp2;
  unsigned int i,codeg,temp,temp1;
  unsigned int rec_buf[256];
  while (get_in(iportno)) {
		putdata(getchin[iportno]&0xff);
		if (displaymode == TRUE)
		   disptbuf(getchin[iportno]&0xff,iportno);
  }
  while ((dataque.count>=5)&&((dataque.buf[dataque.start]!=0xeb)
		||(dataque.buf[mod(dataque.start+1,dataque.size)]!=0x90)
		||(dataque.buf[mod(dataque.start+2,dataque.size)]!=0xeb)
		||(dataque.buf[mod(dataque.start+3,dataque.size)]!=0x90)
		||(dataque.buf[mod(dataque.start+4,dataque.size)]!=0x02)))
		dropdata();

  if (dataque.count<10) return;

  if (dataque.count<(dataque.buf[mod(dataque.start+9,dataque.size)]+9) )
	 return;

  if (dataque.buf[mod(dataque.start+dataque.buf[mod(dataque.start+9,dataque.size)]+8,dataque.size)]!=0x03) {
	 dropdata();
	 return;
  }
  else {
	 temp=0;
	 for (i=0;i<=dataque.buf[mod(dataque.start+9,dataque.size)];i++)
		 temp += (dataque.buf[mod(dataque.start+5+i,dataque.size)]&0xff)&0xff;
	 temp &= 0xffff;
	 if ((dataque.buf[mod(dataque.start+dataque.buf[mod(dataque.start+9,dataque.size)]+6,dataque.size)]!=(temp&0xff))
		||(dataque.buf[mod(dataque.start+dataque.buf[mod(dataque.start+9,dataque.size)]+7,dataque.size)]!=((temp>>8)&0xff))) {
		temp = dataque.buf[mod(dataque.start+9,dataque.size)]+9;
		for(i=0;i<temp;i++) dropdata();
		return;
	 }
	 else {
		temp = dataque.buf[mod(dataque.start+9,dataque.size)]+9;
		for (i=0;i<temp;i++) {
			rec_buf[i] = dataque.buf[dataque.start];
			dropdata();
			if (displaymode == FALSE) disptbuf(rec_buf[i], iportno);
		}
	 }
  }
  codeg = (rec_buf[6]&0xff);
  switch (codeg)	{
	   case 0x06:
	////////////////////////////////add dmu watch ggg 1.14///////////////////////////////////
		   WatchDev[rec_buf[5]]=0;
		   temp=lfpyxno(iportno,rec_buf[5],140,1);
			if (temp!=0xffff) {
			   temp1=temp2=temp;
			   test=0x01;
			   temp1/=16;
			   temp2-=temp1*16;
			   test<<=temp2;
			   prot_yx[temp1]&=~test;
			   }
	   ///////////////////////////////////////////////////////////////////////////
	   break;
	   case 0x40:	process_R1();		     break;
	   case 0x49:   process_R10(rec_buf+4);  break;
	   case 0x47:	process_R8();    	     break;
	   case 0x52:	process_R17(rec_buf+4);	 break;
	   case 0x54:	process_R19(rec_buf+4);	 break;
	   case 0x55:	process_R20(rec_buf+4);	 break;
	   case 0x41:   process_R2(rec_buf+5);   break;
	   case 0x50:	process_R15(rec_buf+4);	 break;
	   case 0x43:   process_BH_YC(rec_buf+4); break;
	   default:				                 break;
  }//switch(codeg)
}//getlfpcmd();

void CLfp::getnbbcmd()
{
	send_protect_flag = FALSE;
	if(port_free(iportno)){
	  while (get_in_protect(iportno))  {
	  if( send_protect_flag == FALSE ) {
			comput(0xeb,iportno);    disprbuf(0xeb,iportno);
			comput(0x90,iportno);    disprbuf(0x90,iportno);
			comput(0xeb,iportno);    disprbuf(0xeb,iportno);
			comput(0x90,iportno);    disprbuf(0x90,iportno);
			comput(0x02,iportno);    disprbuf(0x02,iportno);
		   send_protect_flag=TRUE;
	  }
	  if (getinprotect[10] == 0){
		   quick_send=TRUE;
		   isatimer[iportno].querycount=0;
		 }
	  while(port_free(iportno)==0) { }
	  comput((getinprotect[iportno]&0xff),iportno);
	  disprbuf((getinprotect[iportno]&0xff),iportno);
	  }
	}
}//getnbbcmd();

void CLfp::send_frame()
{
  int i;
  if(sendinfo.start_a_send==TRUE)
  {
	switch(sendinfo.current_frame_type)
	{
	case LFP_ACK:      send_ack();	   break;
	case LFP_NAK:	   send_nak();	   break;
	case LFP_C1_C20:   send_C1_C20();  break;
	case LFP_C8:	   send_C8();	   break;
	case LFP_C15:	   send_C15();	   break;
	case LFP_BH_YC:    send_bh_yc();   break;
	case LFP_C19:	   send_C19();	   break;
	case YK_PRESET:    send_ykpre();   break;
	case YK_EXEC:      send_ykexec();  break;
	case YK_ESC:       send_ykesc();   break;
	default:			   break;
	}//switch(sendinfo.current_frame_type)
	sendinfo.start_a_send=FALSE;
	sendinfo.current_send_ptr=0;
  }//if(sendinfo.start_a_send==TRUE)
  if(sendinfo.current_send_flag==TRUE)
  {
//	gotoxy(3,5);printf("in");
	if(port_free(iportno))
	{
	  if(sendinfo.current_num_nosend>12)
	  {
	for(i=0;i<12;i++)
	{
		if(i==11)
		quick_send=TRUE; //must send quickly
		comput(((askbuf[sendinfo.current_send_ptr+i])&0xff),iportno);
		disprbuf(((askbuf[sendinfo.current_send_ptr+i])&0xff),iportno);//tang
	//    send_dog[iportno]=0;
	}//for(i=0;i<12;i++)
	sendinfo.current_num_nosend-=12;
	sendinfo.current_send_ptr+=12;
	  }//if(sendinfo.current_num_nosend>12)
	  else
	  {
	for(i=0;i<sendinfo.current_num_nosend;i++)
	{
	  if(i==(sendinfo.current_num_nosend-1))quick_send=TRUE;
	  comput(((askbuf[sendinfo.current_send_ptr+i])&0xff),iportno);
	  disprbuf(((askbuf[sendinfo.current_send_ptr+i])&0xff),iportno);//tang
	}//for(i=0;i<sendinfo.current_num_nosend;i++)
	sendinfo.current_num_nosend=0;
	sendinfo.current_send_ptr=0;
	sendinfo.current_send_flag=FALSE;
	  }//else
	}//if(port_free(iportno))
  }//if(sendinfo.current_send_flag==TRUE)
}//send_frame();

void CLfp::send_frame_on_time()
{
	if ((sendinfo.current_send_flag==TRUE)
	   ||(isatimer[iportno].querycount<isatimer[iportno].querylimit)) return;

	if ((comyk_info.Y_PRESET == TRUE)
	  &&(comyk_tbl[comyk_info.yk_order][0]==(iportno+1)) ) {
	   sendinfo.current_send_flag=TRUE;
	   sendinfo.start_a_send=TRUE;
	   sendinfo.current_frame_type=YK_PRESET;
	   isatimer[iportno].querycount=0;
	   yk_flag=TRUE;
	   return;
	}

	if ((comyk_info.Y_EXEC==TRUE)
	   &&(comyk_tbl[comyk_info.yk_order][0]==(iportno+1)) ) {
	   sendinfo.current_send_flag=TRUE;
	   sendinfo.start_a_send=TRUE;
	   sendinfo.current_frame_type=YK_EXEC;
	   isatimer[iportno].querycount=0;
	   return;
	}

	if ( (comyk_info.Y_ESC==TRUE)
	   &&(comyk_tbl[comyk_info.yk_order][0]==(iportno+1)) ) {
	   sendinfo.current_send_flag=TRUE;
	   sendinfo.start_a_send=TRUE;
	   sendinfo.current_frame_type=YK_ESC;
	   isatimer[iportno].querycount=0;
	   return;
	}

	if (yk_flag==FALSE) getnbbcmd();
	if ( send_protect_flag==TRUE )
	 return;

	if ((first_on_time[iportno]<=2)&&(sendinfo.send_ack==FALSE)
	   &&(sendinfo.send_nak==FALSE)&&(yk_flag==FALSE)) {
	   isatimer[iportno].checktime=5000;
	   isatimer[iportno].querycount=0;
	   sendinfo.current_send_flag=TRUE;
	   sendinfo.start_a_send=TRUE;
	   sendinfo.current_frame_type=LFP_C19;
	   return;
	}                                          // all yx collect

	if ((isatimer[iportno].checktime>isatimer[iportno].checklimit/4)
	   &&(first_on_time[iportno]>2)&&(sendinfo.send_ack==FALSE)
	   &&(sendinfo.send_nak==FALSE)&&(yk_flag==FALSE)) {
	   isatimer[iportno].checktime=0;
	   isatimer[iportno].querycount=0;
	   sendinfo.current_send_flag=TRUE;
	   sendinfo.start_a_send=TRUE;
	   sendinfo.current_frame_type=LFP_C8;
	   return;
	}

	if ((first_on_time[iportno]>2)&&(sendinfo.send_ack==FALSE)
	   &&(sendinfo.send_nak==FALSE)&&(yk_flag==FALSE)) {
	   isatimer[iportno].querycount=0;
	   sendinfo.current_send_flag=TRUE;
	   sendinfo.start_a_send=TRUE;

	   if (frame_type++>30) {
		  frame_type=0;
		  sendinfo.current_frame_type=LFP_C19;
	   }
	   else if ((frame_type % 3) == 0)sendinfo.current_frame_type = LFP_C1_C20; // query yxbw
			else if( ( frame_type % 3) == 1 ) sendinfo.current_frame_type = LFP_C15;   // query yc
			else if( (frame_type % 3) == 2 )  sendinfo.current_frame_type = LFP_BH_YC;     //query bhyc;
	}
}//send_frame_on_time();

void CLfp::deal()
{
  send_frame_on_time();
  send_frame();
  getlfpcmd();
  send_ack_frame();
  send_nak_frame();
}//deal();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -