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

📄 util.c

📁 利用51单片机对RTL8109进行控制
💻 C
📖 第 1 页 / 共 2 页
字号:
			}

			if(string_compare("@",1)!=0)
			{
				if(retransmit_buffer[rt_size].rtframe.status!=0)
				{
					FunAddCommand(command_length-1);goto roll;
				}

				txdnet.tcpframe.tcpdata[0]=0x55;
				txdnet.tcpframe.tcpdata[1]=0xaa;
				txdnet.tcpframe.tcpdata[2]=0x55;
				txdnet.tcpframe.tcpdata[3]=rt_size;
				for(i=1,j=4;i<command_length;i++,j++){txdnet.tcpframe.tcpdata[j]=command_buffer[i];}
				txdnet.tcpframe.tcpdata[j]='a';

				c_txcount++;

				for(i=0;i<3;i++){txdnet.etherframe.destnodeid[i]=ping_ethernet_address.words[i];}

				create_tcp_packet(command_length+4);
			}

			if(string_compare("&",1)!=0)
			{
				i=FunCheckEmpty();
				if(i==rt_size)goto roll;
				txdnet.tcpframe.tcpdata[0]=0x55;
				txdnet.tcpframe.tcpdata[1]=0xaa;
				txdnet.tcpframe.tcpdata[2]=0x55;
				txdnet.tcpframe.tcpdata[3]=i;
				for(i=1,j=4;i<command_length;i++,j++){txdnet.tcpframe.tcpdata[j]=command_buffer[i];}
				txdnet.tcpframe.tcpdata[j]='a';

				c_txcount++;

				for(i=0;i<3;i++){txdnet.etherframe.destnodeid[i]=ping_ethernet_address.words[i];}

				create_tcp_packet(command_length+4);
			}

			if(string_compare("$",1)!=0)
			{
			/*	if(command_length<5)goto roll;

				txdnet.tcpframe.tcpdata[0]=0x55;
				txdnet.tcpframe.tcpdata[1]=0xaa;
				txdnet.tcpframe.tcpdata[2]=0xaa;
				for(i=4,j=4;i<command_length;i++,j++){txdnet.tcpframe.tcpdata[j]=command_buffer[i];}
				txdnet.tcpframe.tcpdata[j]='a';

				ping_ip_address.bytes[3]=(command_buffer[1]-0x30)*100+(command_buffer[2]-0x30)*10+command_buffer[3]-0x30;

				for(i=0;i<3;i++){txdnet.etherframe.destnodeid[i]=ping_ethernet_address.words[i];}

				create_tcp_packet(command_length+4);*/
				txdnet.udpframe.udpdata[0]=0x55;
				txdnet.udpframe.udpdata[1]=0xaa;	
				txdnet.udpframe.udpdata[2]=0x55;
				
				for(i=1,j=4;i<command_length;i++,j++){txdnet.udpframe.udpdata[j]=command_buffer[i];}
				txdnet.udpframe.udpdata[j]='a';

				for(i=0;i<3;i++){txdnet.etherframe.destnodeid[i]=ping_ethernet_address.words[i];}
				
				rxdnet.ipframe.sourceip[0]=ping_ip_address.words[0];
				rxdnet.ipframe.sourceip[1]=ping_ip_address.words[1];
				
				udp_dstport=1521;
				
				create_udp_packet(command_length+4);


			}

			if(string_compare("TELNET",6)!=0)//以下为TELNET命令的解析和执行
                        {

                               	ip=0;

                         	for(i=6,j=0;i<command_length;i++)//取得ip地址
                         	{
					if(command_buffer[i]!='.')
                                        {
                                        	command_buffer[i]=command_buffer[i]&0x0f;
                                                ip=ip*10;
                                                ip=ip+command_buffer[i];
                                        }
                              		else
                              		{
                                        	ping_ip_address.bytes[j]=ip;
                                        	if(j==3)break;
                                                j++;ip=0;
                                   	}
                       		}
                          	if(j==3)
                          	{

                          		if((ping_ip_address.dwords&mask_ip_address.dwords)==(my_ip_address.dwords&mask_ip_address.dwords))
                                        {
        	                             	//表示位于同一子网.
                                     		arp_request(ping_ip_address.dwords);
                                        }
                                        else
                                        {
                                        	//表示属于不同的子网,需要通过网关.
                                           	ping_ip_address_ttl=10;

                                                for(j=0;j<6;j++)
                                                {
                                           		ping_ethernet_address.bytes[j]=gateway_ethernet_address.bytes[j];
                                                }
                                          	if(gateway_ip_address_ttl==0)
                                                {
//							send_string("\r\nGateWay Not Found!\r\nC:>");
                                                       // tcp_count=0;
                                                }
                                   	}
                          	}

			}

			if(string_compare("DVR",3)!=0)
			{
				ip=0;
                          	//取得ip地址
                         	for(i=3,j=0;i<command_length;i++)
                         	{
                          		if(command_buffer[i]!='.')
                                 	{
                                 		if(j==4)
                                 		{
                                 			command_buffer[i]=command_buffer[i]&0x0f;
                                      	     		s_port=s_port*10;
                                             	  	s_port=s_port+command_buffer[i];
                                 		}
                                 		else
                                 		{
                                   			command_buffer[i]=command_buffer[i]&0x0f;
                                      	     		ip=ip*10;
                                             	  	ip=ip+command_buffer[i];
                                               	}
                                        }
                              		else
                              		{
                                        	if(j==4)
                                        	{
                                        	//	c_camnumber=s_port;
                                        		break;
                                        	}
                                        	else
                                        	{
                                        		temp_ip_address.bytes[j]=ip;
                                        	}

                                               	j++;ip=0;
                                   	}
                                }
                                if(j==4)
                                {
                                 //    	tcp_count=20;//20second

                                    // 	local_use_port=Local_Dvr_Port;

                                  //   	socketnumber=Dvr_Port;
                                  	dvr_buffer[c_DvrWriteBuffer].dstipaddress=temp_ip_address.dwords;
                                  	dvr_buffer[c_DvrWriteBuffer].cam_number=s_port;
                                  	
                                  	c_DvrWriteBuffer++;
                                  	if(c_DvrWriteBuffer>=dvr_length)c_DvrWriteBuffer=0;
                                  	
                                  	/*

                                     	if((dvr_ip_address.dwords&mask_ip_address.dwords)==(my_ip_address.dwords&mask_ip_address.dwords))
                                        {
        	                             	//表示位于同一子网.
                                     		arp_request(dvr_ip_address.dwords);
                                        }
                                        else
                                        {
                                        	//表示属于不同的子网,需要通过网关.
                                           	ping_ip_address_ttl=10;
                                                for(j=0;j<6;j++)
                                                {
                                           		dvr_ethernet_address.bytes[j]=gateway_ethernet_address.bytes[j];
                                                }
                                          	if(gateway_ip_address_ttl==0)
                                                {
//							send_string("\r\nGateWay Not Found!\r\nC:>");
                                                        tcp_count=0;
                                                        ping_ip_address_ttl=0;
                                                }
                                   	}*/
                       		}
                       	}

roll:			command_length=0;

		}
	}
}


void process_data()
{
	uchar i,j,temp;

	command_length=0;

	while(comrxdread!=comcommandend)
	{
		pwdi=!pwdi;
		
	     	temp=get_char();
      		command_buffer[command_length]=temp;
		if((temp!=' ')&&(temp<'a')) //表示不是空格和回车
    		{
    			command_length++;
     			if(command_length==command_buffer_size)command_length=0;
     		}
      		if(temp>='a')
        	{
        	//	pwdi=!pwdi;

        		txdnet.tcpframe.tcpdata[0]=0x55;
        		txdnet.tcpframe.tcpdata[1]=0xaa;
        		txdnet.tcpframe.tcpdata[2]=0xaa;

	       		for(i=4,j=0;j<=command_length;i++,j++)
			{
      				txdnet.tcpframe.tcpdata[i]=command_buffer[j];
			}

			for(i=0;i<3;i++){txdnet.etherframe.destnodeid[i]=ping_ethernet_address.words[i];}

        		create_tcp_packet(command_length+5);

        		command_length=0;

        	}
        }

}



void timer0() interrupt 1
{
	/*工作在16位定时模式,中断时间为10毫秒中断一次,误差小于千分之1,晶振使用22.1184Mhz*/
	unsigned char i;

	tl0=9;
	th0=184;

	msec++;

	for(i=0;i<=rt_size;i++)
	{
		if(retransmit_buffer[i].rtframe.status!=0)
		{
			retransmit_buffer[i].rtframe.timeout--;

			//if(retransmit_buffer[i].rtframe.timeout==0){retransmit_packet(i);}
		}
		if(retransmitpacket[i].status!=0)
		{retransmitpacket[i].timeout--;}

	}
	
	if((msec%20)==0)b_100ms=1;

	if(msec==100)
	{
			/*100分频,就是1秒一次*/
		msec=0;

                sec++;
                double_second=1;
		if(sec==60)
		{
			sec=0;
			if(gateway_ip_address_ttl>0)gateway_ip_address_ttl--;
		}

		if(ping_ip_address_ttl>1)ping_ip_address_ttl--;
		if(c_net_delay>0)c_net_delay--;
		if(c_DvrRunTime>0)c_DvrRunTime--;
	}


}


void serial(void) interrupt 4
{
	unsigned char temp;

	if(ti)
	{
		ti=0;
		
		if(comtxdread!=comtxdwrite)
		{
			sbuf=comtxdbuf[comtxdread];
			comtxdread++;
			if(comtxdread>=com_txd_buffer_size)comtxdread=0;
			comtxdbufempty=0;
		}
        	else {comtxdbufempty=1;}

	}
  	if (ri)
  	{
  		ri=0;
		temp=sbuf;
		comrxdbuf[comrxdwrite]=temp;

		comrxdwrite++;
		if(comrxdwrite>=com_txd_buffer_size)comrxdwrite=0;
		//if(c_type==0)
		//{
			if(temp>='a'){bDataFlag=1;comcommandend=comrxdwrite;}
		//}

		if(temp==0x0d){bCommandFlag=1;comcommandend=comrxdwrite;}

	}
}                         		

⌨️ 快捷键说明

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