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

📄 nettask.c

📁 Vxworks 下重矿设备应用开发
💻 C
📖 第 1 页 / 共 3 页
字号:
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8PktNum = DC_SLOWINFOR_PKTNUM  ;
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8FormatNum = DC_SLOWDATA_INFOR_FMTNUM ;
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8FormatVer = DC_SLOWINFOR_FMTVER ;        
   }

 else if(packagetype == DC_FASTDATA_INFORX1)
   {
      net_gtx.uTx.sMsg.sTcpHeader.u8Cmd1 = ASCII_CMD1;
      net_gtx.uTx.sMsg.sTcpHeader.u8Cmd2 = ASCII_CMD2;    
      net_gtx.uTx.sMsg.sTcpHeader.u8Len1 = 0;
      net_gtx.uTx.sMsg.sTcpHeader.u8Len2 = 0;
      net_gtx.uTx.sMsg.sTcpHeader.u8Len3 = (char)(0x10);
      net_gtx.uTx.sMsg.sTcpHeader.u8Len4 = (char)(0xc);
       length = ((net_gtx.uTx.sMsg.sTcpHeader.u8Len1*0x1000000)&0xFF000000)
               +((net_gtx.uTx.sMsg.sTcpHeader.u8Len2*0x10000)&0xFF0000)
	           +((net_gtx.uTx.sMsg.sTcpHeader.u8Len3*0x100)&0xFF00)
	           +net_gtx.uTx.sMsg.sTcpHeader.u8Len4;
      memcpy(net_gtx.uTx.sMsg.uNetMsg.Msg.MsgData.x1.fastdatax1,x1buf,4096);
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8PktNum = DC_FASTINFOR_PKTNUM  ;
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8FormatNum =  DC_FASTDATA_INFOR_FMTNUM ;
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8FormatVer = DC_FASTINFOR_FMTVERX1 ;        
   }

else if(packagetype == DC_FASTDATA_INFORX2)
   {
      net_gtx.uTx.sMsg.sTcpHeader.u8Cmd1 = ASCII_CMD1;
      net_gtx.uTx.sMsg.sTcpHeader.u8Cmd2 = ASCII_CMD2;    
      net_gtx.uTx.sMsg.sTcpHeader.u8Len1 = 0;
      net_gtx.uTx.sMsg.sTcpHeader.u8Len2 = 0;
      net_gtx.uTx.sMsg.sTcpHeader.u8Len3 = (char)(0x10);
      net_gtx.uTx.sMsg.sTcpHeader.u8Len4 = (char)(0xc);
       length = ((net_gtx.uTx.sMsg.sTcpHeader.u8Len1*0x1000000)&0xFF000000)
               +((net_gtx.uTx.sMsg.sTcpHeader.u8Len2*0x10000)&0xFF0000)
	           +((net_gtx.uTx.sMsg.sTcpHeader.u8Len3*0x100)&0xFF00)
	           +net_gtx.uTx.sMsg.sTcpHeader.u8Len4;
      memcpy(net_gtx.uTx.sMsg.uNetMsg.Msg.MsgData.x2.fastdatax2,x2buf,4096);
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8PktNum = DC_FASTINFOR_PKTNUM  ;
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8FormatNum = DC_FASTDATA_INFOR_FMTNUM ;
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8FormatVer = DC_FASTINFOR_FMTVERX2 ;        
   }
else if(packagetype == DC_FASTDATA_INFORY1)
   {
      net_gtx.uTx.sMsg.sTcpHeader.u8Cmd1 = ASCII_CMD1;
      net_gtx.uTx.sMsg.sTcpHeader.u8Cmd2 = ASCII_CMD2;    
      net_gtx.uTx.sMsg.sTcpHeader.u8Len1 = 0;
      net_gtx.uTx.sMsg.sTcpHeader.u8Len2 = 0;
      net_gtx.uTx.sMsg.sTcpHeader.u8Len3 = (char)(0x10);
      net_gtx.uTx.sMsg.sTcpHeader.u8Len4 = (char)(0xc);
       length = ((net_gtx.uTx.sMsg.sTcpHeader.u8Len1*0x1000000)&0xFF000000)
               +((net_gtx.uTx.sMsg.sTcpHeader.u8Len2*0x10000)&0xFF0000)
	           +((net_gtx.uTx.sMsg.sTcpHeader.u8Len3*0x100)&0xFF00)
	           +net_gtx.uTx.sMsg.sTcpHeader.u8Len4;
      memcpy(net_gtx.uTx.sMsg.uNetMsg.Msg.MsgData.y1.fastdatay1,y1buf,4096);
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8PktNum = DC_FASTINFOR_PKTNUM  ;
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8FormatNum =  DC_FASTDATA_INFOR_FMTNUM ;
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8FormatVer = DC_FASTINFOR_FMTVERY1 ; 
   }

else if(packagetype == DC_FASTDATA_INFORY2)
   {
      net_gtx.uTx.sMsg.sTcpHeader.u8Cmd1 = ASCII_CMD1;
      net_gtx.uTx.sMsg.sTcpHeader.u8Cmd2 = ASCII_CMD2;    
      net_gtx.uTx.sMsg.sTcpHeader.u8Len1 = 0;
      net_gtx.uTx.sMsg.sTcpHeader.u8Len2 = 0;
      net_gtx.uTx.sMsg.sTcpHeader.u8Len3 = (char)(0x10);
      net_gtx.uTx.sMsg.sTcpHeader.u8Len4 =(char)(0xc) ;
       length = ((net_gtx.uTx.sMsg.sTcpHeader.u8Len1*0x1000000)&0xFF000000)
               +((net_gtx.uTx.sMsg.sTcpHeader.u8Len2*0x10000)&0xFF0000)
	           +((net_gtx.uTx.sMsg.sTcpHeader.u8Len3*0x100)&0xFF00)
	           +net_gtx.uTx.sMsg.sTcpHeader.u8Len4;	   
      memcpy(net_gtx.uTx.sMsg.uNetMsg.Msg.MsgData.y2.fastdatay2,y2buf,4096);
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8PktNum = DC_FASTINFOR_PKTNUM  ;
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8FormatNum =  DC_FASTDATA_INFOR_FMTNUM ;
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8FormatVer = DC_FASTINFOR_FMTVERY2 ;      
   }
   
   else if(packagetype == DC_COMMAND_ACK)
   {
      net_gtx.uTx.sMsg.sTcpHeader.u8Cmd1 = ASCII_CMD1;
      net_gtx.uTx.sMsg.sTcpHeader.u8Cmd2 = ASCII_CMD2;
      net_gtx.uTx.sMsg.sTcpHeader.u8Len1 = 0;
      net_gtx.uTx.sMsg.sTcpHeader.u8Len2 = 0;
      net_gtx.uTx.sMsg.sTcpHeader.u8Len3 = 0;
      net_gtx.uTx.sMsg.sTcpHeader.u8Len4 = 0xd;
       length = ((net_gtx.uTx.sMsg.sTcpHeader.u8Len1*0x1000000)&0xFF000000)
               +((net_gtx.uTx.sMsg.sTcpHeader.u8Len2*0x10000)&0xFF0000)
	           +((net_gtx.uTx.sMsg.sTcpHeader.u8Len3*0x100)&0xFF00)
	           +net_gtx.uTx.sMsg.sTcpHeader.u8Len4;
      net_gtx.uTx.sMsg.uNetMsg.Msg.MsgData.f.state='Y';	   
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8PktNum = DC_INFOR_REQ;
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8FormatNum = DC_COMMAND_REQ_FMTNUM;
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8FormatVer = DC_COMMAND_FMTVER;
   }

else if(packagetype == DC_VIDEO_ACK)
   {
      net_gtx.uTx.sMsg.sTcpHeader.u8Cmd1 = ASCII_CMD1;
      net_gtx.uTx.sMsg.sTcpHeader.u8Cmd2 = ASCII_CMD2;    
      net_gtx.uTx.sMsg.sTcpHeader.u8Len1 = 0;
      net_gtx.uTx.sMsg.sTcpHeader.u8Len2 = 0;
      net_gtx.uTx.sMsg.sTcpHeader.u8Len3 = (char)(0x10);
      net_gtx.uTx.sMsg.sTcpHeader.u8Len4 =(char)(0xc) ;
       length = ((net_gtx.uTx.sMsg.sTcpHeader.u8Len1*0x1000000)&0xFF000000)
               +((net_gtx.uTx.sMsg.sTcpHeader.u8Len2*0x10000)&0xFF0000)
	           +((net_gtx.uTx.sMsg.sTcpHeader.u8Len3*0x100)&0xFF00)
	           +net_gtx.uTx.sMsg.sTcpHeader.u8Len4;   
      memcpy(net_gtx.uTx.sMsg.uNetMsg.Msg.MsgData.videoa.s7,video,4096);
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8PktNum = DC_VIDEO_PKTNUM;
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8FormatNum = DC_VIDEO_ACK_FMTNUM ;
      net_gtx.uTx.sMsg.uNetMsg.Msg.u8FormatVer = DC_VIDEO_FMTVER ;      
   }  
   else
   {
      return 0;
   } 
   
   return (net_writesocket(newFd,length));
}
/*****************************************************************************
void net_writesocket()
 函数说明:	
				
 参数:		无
 返回:		无
 调用:		无
 被调用:	
*****************************************************************************/
static int net_writesocket(int newFd,int len)
{
   short int  sendret;
   int alllen=len;
   int taskid;
   if(  alllen  == 0)
   {
      return;
   }
      
   sendret = send(newFd, net_gtx.uTx.u8TxDataBuf,  alllen , 0);
   if(sendret == 0)
   {
     printf("send :ok\n");
   }
   else
   {	
    return (-1);
	}
   }
  


/*****************************************************************************
net_applayer()
 函数说明:	接受到消息的解析函数
				
 参数:		无
 返回:		无
 调用:		无
 被调用:	
*****************************************************************************/


static void net_applayer(int fd)
{

 int fd;
  //主机请求的数据命令
if( net_grx.uRx.sMsg.uNetMsg.Msg.u8PktNum == DC_COMMAND_PKTNUM//172 AC
   &&net_grx.uRx.sMsg.uNetMsg.Msg.u8FormatNum == DC_COMMAND_REQ_FMTNUM)
      {             

          //拷贝到全局变量CPI		  
         int i=(int)net_grx.uRx.sMsg.uNetMsg.Msg.MsgData.a.CmdId;
         
         
//		  switch(i)
//		  	{
//		  		case 0: 
//		  			cb_DCpoweron(); break;
//				case 1:
//					cb_DCpoweroff(); break;
//				case 2: 
//					cb_DCstart(); break;
//				case 3: 
//					cb_DCstop(); break;
//				case 4: 
//					cb_DCreset(); break;
//				case 5: 
//					cb_DCemcstop(); break;
//				case 6: 
//					cb_BWstart(); break;
//				case 7: 
//					cb_BWstop(); break;
//				default: 
//					break;
//		  	}

//		 if(CPI[i]==0)  
//		 	{

		 if (i>=0 && i<=7)  {
//			 	do
//			 		CPI[i]=1;
//			 	while (CPI[i] != 1);
			 	
			 	do
			 		Flag_SPLC_NET = 1;
			 	while (Flag_SPLC_NET!= 1);

			 	do
			 		Flag_SPLC_NET_NO = i;
			 	while (Flag_SPLC_NET_NO != i);

		 }
//		 	}		    	 
		  net_send(newFd,DC_COMMAND_ACK);
        		
      }




 //网络通断报告
   if( net_grx.uRx.sMsg.uNetMsg.Msg.u8PktNum == HEALTH_REPORT_PKTNUM//182  B6
   &&net_grx.uRx.sMsg.uNetMsg.Msg.u8FormatNum == 0x02)
      {             
		 net_send(newFd,HEALTH_REPORT_ACK);	
      }

   
//信息请求
else if(net_grx.uRx.sMsg.uNetMsg.Msg.u8PktNum == DC_INFOR_PKTNUM //169 A9
                   &&net_grx.uRx.sMsg.uNetMsg.Msg.u8FormatNum == 0x02)
		 {		 	

			 net_send(newFd,DC_SLOWDATA_INFOR);		
			 net_send(newFd,DC_FASTDATA_INFORX1);
			 net_send(newFd,DC_FASTDATA_INFORX2);
			 net_send(newFd,DC_FASTDATA_INFORY1);
			 net_send(newFd,DC_FASTDATA_INFORY2);
         }

//视频信息数据请求
else if(net_grx.uRx.sMsg.uNetMsg.Msg.u8PktNum == DC_VIDEO_PKTNUM   //176  B0
                   &&net_grx.uRx.sMsg.uNetMsg.Msg.u8FormatNum == 0x01)        
		 {		 	

                 //开始视频采集任务,并回传采集的视频信息      			   
                  net_send(newFd,DC_VIDEO_ACK);
			
         }                       
   
   else if(net_grx.uRx.sMsg.uNetMsg.Msg.u8PktNum ==  DC_SPLC_PKTNUM   //187  BB
      &&net_grx.uRx.sMsg.uNetMsg.Msg.u8FormatNum ==  DC_SPLC_REQ_FMTNUM )
   {
       int tmp;    
       tmp = write_il();
	
       Flag_Chgil = 1;
	   while (Flag_Chgil != 1)
			Flag_Chgil = 1;

	//不正常
	if(!tmp) 
     	net_send(newFd,HEALTH_REPORT_ACK);
	else
		return;	
   }
   
   else
   {
      //unknown message
      return;
   }  

   return;
}
/**********************************************************************
  static char netrecvsize(int handle1, unsigned char *pbuff,int len)
 函数说明:	底层函数,从网络接收数据
 参数:		pbuff,	接收数据存储的地方
 			len,		需要接受的总长度
 返回:		正确执行返回STATUS_NORMAL,否则返回错误
 调用:		无	
 被调用:	void netCMDRecv();
 **********************************************************************/
static char netrecvsize(int handle1, unsigned char *pbuff,int len)
{

      int recvLen;
	if((len<=0) || (tcp_conn_state!=ST_TCP_IDLE))
		return(STATUS_INVALID);
	else			
	{
		recvLen = recv(handle1,pbuff, len,0);
		if( (recvLen==ERROR) || (recvLen ==0) )
		{
			semGive(semNetLink);
			return(STATUS_ERROR);
		}
		
	}
	return(STATUS_NORMAL);
}

//建立客户端任务

void cltnet(void* p)
{
    unsigned32 net_client_id2;
    
    
    struct sockaddr_in serverAddr;
	int sFd2,taskid;
	int sockAddrSize;	
	int n;
	volatile SRx  net_grx2;
	volatile STx  net_gtx2;
	unsigned char  tcpdatar2[16];  
	if((sFd2 = socket(AF_INET, SOCK_STREAM, 0)) < 0)
	{
		printf("socket error\n");
		return;
	}
	sockAddrSize = sizeof(struct sockaddr_in);
	serverAddr.sin_family = AF_INET;
	serverAddr.sin_port = htons (TCP_CLIENT_PORT); 
	serverAddr.sin_addr.s_addr = inet_addr("90.0.0.99");
	
	if(connect(sFd2, (struct sockaddr *)&serverAddr, sockAddrSize) < 0)
	{
		ConnectState=0;
		//printf("connect error\n");
		close(sFd2);
	    taskid=taskIdSelf();
	    printf("delete taskseif  task ok .......\n"); 
//   taskSpawn("NETCLIENT",90,0,8*1024,cltnet,0,0,0,0,0,0,0,0,0,0);
    sc = taskDelete(0);
    if (sc != OK)	{
		printf("Can't delete task \n");
		return 0;
	}

	}
	
	//0d 0b 00 00 00 00 00 00 AC 01 00 00 06
		
	
	for(;;){
		
		ConnectState=1;
	  net_gtx2.uTx.sMsg.sTcpHeader.u8Cmd1 = ASCII_CMD1;
      net_gtx2.uTx.sMsg.sTcpHeader.u8Cmd2 = ASCII_CMD2;        
      net_gtx2.uTx.sMsg.sTcpHeader.u8Len1 = 0;
      net_gtx2.uTx.sMsg.sTcpHeader.u8Len2 = 0;
      net_gtx2.uTx.sMsg.sTcpHeader.u8Len3 = 0;
      net_gtx2.uTx.sMsg.sTcpHeader.u8Len4 = (char)(0x10);
       /*length = ((net_gtx.uTx.sMsg.sTcpHeader.u8Len1*0x1000000)&0xFF000000)
               +((net_gtx.uTx.sMsg.sTcpHeader.u8Len2*0x10000)&0xFF0000)
	           +((net_gtx.uTx.sMsg.sTcpHeader.u8Len3*0x100)&0xFF00)
	           +net_gtx.uTx.sMsg.sTcpHeader.u8Len4;
	 */
      net_gtx2.uTx.sMsg.uNetMsg.Msg.u8PktNum = BW_INFOR_PKTNUM ;
      net_gtx2.uTx.sMsg.uNetMsg.Msg.u8FormatNum = BW_INFOR_REQ_FMTNUM ;
      net_gtx2.uTx.sMsg.uNetMsg.Msg.u8FormatVer = BW_INFOR_FMTVER;
	  send(sFd2, net_gtx2.uTx.u8TxDataBuf,16 , 0);
	  //  net_send(sFd2,BW_INFOR_REQ);
	    //net_send(sFd2,BW_COMMAND_REQ);
	   
	   memset(tcpdatar2, 0x10, 16);
   if(n=recv(sFd2, tcpdatar2,16,0)<=0)
{
	 ConnectState=0;
	 taskid=taskNameToId(TNAME_SERVERTASK);
	 if(taskid!= ERROR && taskid != taskIdSelf());
     taskDelete(taskid);	
     close (sFd2);
     taskid=taskIdSelf();
     tcp_conn_state = ST_ETH_LINK;  
     sc = taskDelete(0);
    if (sc != OK)	{
		printf("Can't delete task \n");
		return ;
	}
}
//将电流信息送显示
         memset(net_grx2.uRx.u8RxDataBuf, 0x00, 20);                      
          memcpy(net_grx2.uRx.u8RxDataBuf,tcpdatar2,20); 
        current=net_grx2.uRx.sMsg.uNetMsg.Msg.MsgData.h.bwinf;
       //  current=net_grx2.urx.sMsg.uNetMsg.Msg.MsgData.h.bwinf;

		 printf(" Flag_BW =%d\n",Flag_BW);	
		 
		
	//判断是否是板位机命令	
		if(Flag_BW)
		{
      net_gtx2.uTx.sMsg.sTcpHeader.u8Cmd1 = ASCII_CMD1;
      net_gtx2.uTx.sMsg.sTcpHeader.u8Cmd2 = ASCII_CMD2;        
      net_gtx2.uTx.sMsg.sTcpHeader.u8Len1 = 0;
      net_gtx2.uTx.sMsg.sTcpHeader.u8Len2 = 0;
      net_gtx2.uTx.sMsg.sTcpHeader.u8Len3 = 0;
      net_gtx2.uTx.sMsg.sTcpHeader.u8Len4 = (char)(0x10);
	  if(CPO2[6])
      net_gtx2.uTx.sMsg.uNetMsg.Msg.MsgData.bwcmd.CmdId=1;   //若为1表示上电,否则为下电
	else{net_gtx2.uTx.sMsg.uNetMsg.Msg.MsgData.bwcmd.CmdId=0; } 
      net_gtx2.uTx.sMsg.uNetMsg.Msg.u8PktNum = BW_COMMAND_PKTNUM ;
      net_gtx2.uTx.sMsg.uNetMsg.Msg.u8FormatNum = BW_COMMAND_REQ_FMTNUM ;
      net_gtx2.uTx.sMsg.uNetMsg.Msg.u8FormatVer = BW_COMMAND_FMTVER;
			
		  printf(" prepare to send the CPI 6 or 7*************\n");	
		  
		  if( send(sFd2, net_gtx2.uTx.u8TxDataBuf,16 , 0)< 0)
	{
		close(sFd2);
		close (sFd2);
        taskid=taskIdSelf();
        tcp_conn_state = ST_ETH_LINK;  
        sc = taskDelete(0);
		
		
	}
		Flag_BW=0; 
		//return;
	}
		
		   
		OSTaskDelay(800);
		}
		

  close(sFd2);

 }

⌨️ 快捷键说明

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