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

📄 input.lst

📁 51单片机上实现tcp/ip的源代码
💻 LST
字号:
C51 COMPILER V7.06   INPUT                                                                 05/27/2008 11:02:08 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE INPUT
OBJECT MODULE PLACED IN .\RUN\input.obj
COMPILER INVOKED BY: D:\Keil7_06\C51\BIN\C51.EXE input.c OBJECT(.\RUN\input.obj)

stmt level    source

   1          /*********************************************************************
   2           *            Copright(c) 2004,张会福 湖南科技大学计算机学院 
   3           *                        All rights reserved.
   4           *
   5           *文件名称:    INPUT.C
   6           *文件标识: 
   7           *摘    要: 接收串口输入的信息,并进行“解析”,引发相应的操作
   8           *            1.输入命令:setgate xxx.xxx.xxx.xxx,并输入回车键后,将会按照输入的值设定网关地址
   9           *            2.输入命令:setip xxx.xxx.xxx.xxx,并输入回车键后,将会按照输入的值设定IP地址
  10           *            3.输入命令:ping xxx.xxx.xxx.xxx,并输入回车键后,将会引发ping操作
  11           *            4.输入命令:UDP xxx.xxx.xxx.xxx.1025.data,并输入回车键后,将会引发udp操作,其中,
  12           *            端口号为1025,端口号以前的内容为对方主机IP地址,1025后面的是待发送的数据.
  13           *当前版本: V1.0
  14           *作    者: 张会福
  15           *完成日期: 2004.4.10
  16           *
  17           *
  18           *
  19           *********************************************************************/
  20          #define  INPUT_GLOBALS
  21          #include "net_cfg.h"
  22          
  23          uint    Command_Len;        //命令长度
  24          /**********************************************************************
  25          **函数原型:    uchar  Str_Compare(unsigned char code *string,uchar number)
  26          **入口参数:    unsigned char code *string  :
  27          **             uchar number                :
  28          **出口参数:    uchar
  29          **返 回 值:    0    :
  30          **             1    :
  31          **说    明:    用给定的字符串与从串口输入的字符串进行比较,如果串口输入的字符串
  32          **             中包含给定的字符串,则返回1,否则返回0.
  33          ************************************************************************/
  34          uchar Str_Compare(unsigned char code *string,uchar number)
  35          {
  36   1        uchar i;
  37   1        uchar temp;
  38   1        for (i=0;i<number;i++)
  39   1        {
  40   2            temp=Command_Buf[i];
  41   2            if(temp!=(*string))
  42   2                {return(0);}
  43   2            string++;
  44   2        }
  45   1        return(1);
  46   1      }
  47          
  48          /**********************************************************************
  49          **函数原型:   void     process_command()
  50          **入口参数:   无
  51          **出口参数:   无
  52          **返 回 值:   无              
  53          **说    明:   处理用户从串口输入的命令
  54          ************************************************************************/
  55          void process_command()
C51 COMPILER V7.06   INPUT                                                                 05/27/2008 11:02:08 PAGE 2   

  56          {
  57   1        uchar temp;
  58   1        uchar i;
  59   1        uint ip;
  60   1        uchar j;
  61   1      
  62   1        while(ComRxdRead!=ComRxdWrite)
  63   1        {
  64   2            temp=Get_Char();
  65   2            Command_Buf[Command_Len]=temp;
  66   2            if((temp!=' ')&&(temp!=0x0d)) Command_Len++;//表示不是空格和回车
  67   2            if(Command_Len==COMMAND_BUFF_SIZE) Command_Len=0;
  68   2            if(temp==0x0d) //回车键
  69   2            {
  70   3                if(Command_Len>9) //一个ping命令的指令最少要10个字符
  71   3      //======================================================================================    
  72   3                if(( Str_Compare("ping",4)!=0 )||( Str_Compare("PING",4)!=0 ))
  73   3              //==========================以下为ping命令的解析和执行
  74   3                {
  75   4                    ip=0;
  76   4                    for(i=4,j=0;i<Command_Len;i++)
  77   4                    {
  78   5                        if(Command_Buf[i]!='.')
  79   5                        {
  80   6                            Command_Buf[i]=Command_Buf[i]&0x0f;
  81   6                            ip=ip*10;
  82   6                            ip=ip+Command_Buf[i];
  83   6                        }
  84   5                        else
  85   5                        {
  86   6                            Ping_Ip_Address.bytes[j]=ip;
  87   6                            j++;
  88   6                            ip=0;
  89   6                        }
  90   5                    }//for
  91   4                    if(j==3)
  92   4                    {
  93   5                        Ping_Ip_Address.bytes[j]=ip;
  94   5                        // 表示命令正确
  95   5                        Printf_String("\r\nPing IP=") ;
  96   5                        Printf_IPStr(Ping_Ip_Address);
  97   5                        Printf_String("\r\n") ;
  98   5                        Ping_Count=6;
  99   5                        if((Ping_Ip_Address.dwords & Mask_Ip_Address.dwords)==(My_Ip_Address.dwords & Mask_Ip_Ad
             -dress.dwords))
 100   5                        {//表示位于同一子网
 101   6                             if((Ping_Ip_Address.dwords==Gateway_Ip_Address.dwords)&(Gateway_IP_TTL>5))
 102   6                             {
 103   7                                  for (i=0;i<3;i++)
 104   7                                  {
 105   8                                      Ping_MAC.words[i]=Gateway_MAC.words[i];//=RxdNetBuff.ArpFrame.SourceMacId[
             -i];
 106   8                                  }
 107   7                                  Ping_Request();
 108   7                             }
 109   6                             else
 110   6                             {
 111   7                                  Arp_Request(Ping_Ip_Address.dwords);
 112   7                             }
 113   6                        }//表示位于同一子网
 114   5                        else
 115   5                        {//表示属于不同的子网,需要通过网关.
C51 COMPILER V7.06   INPUT                                                                 05/27/2008 11:02:08 PAGE 3   

 116   6                            Printf_String("\r\nThe Host IS In other Subnet");
 117   6                            Ping_IP_TTL=10;
 118   6                            for(j=0;j<6;j++)
 119   6                            {
 120   7                                Ping_MAC.bytes[j]=Gateway_MAC.bytes[j];
 121   7                            }
 122   6                            if(Gateway_IP_TTL==0)
 123   6                            {
 124   7                                Printf_String("\r\nGateWay Not Found!\r\nC:>");
 125   7                                Ping_Count=0;
 126   7                            }
 127   6                        }//表示属于不同的子网,需要通过网关.
 128   5                    }//if(j==3)
 129   4                    else
 130   4                    {
 131   5                        Printf_String("\r\nPing Command Error\r\nC:>");
 132   5                    }
 133   4                }//PING command
 134   3      //====================================================================================
 135   3                //设置IP值
 136   3                if ((Str_Compare("setip",5)!=0)||(Str_Compare("SETIP",5)!=0))
 137   3                {
 138   4                    ip = 0;
 139   4                    for(i=5,j=0;i<Command_Len;i++)
 140   4                    {  
 141   5                       if(Command_Buf[i]!='.')
 142   5                       {
 143   6                           Command_Buf[i]=Command_Buf[i]&0x0f;
 144   6                           ip=ip*10;
 145   6                           ip=ip+Command_Buf[i];
 146   6                       }
 147   5                       else
 148   5                       {
 149   6                           My_Ip_Address.bytes[j]=ip;
 150   6                           j++;
 151   6                           ip=0;
 152   6                       }
 153   5                    }
 154   4                                              //命令执行
 155   4                    if(j==3)
 156   4                    {
 157   5                        My_Ip_Address.bytes[j]=ip;
 158   5                    }
 159   4                    //Printf_String("IP IS SET");
 160   4                    Printf_String("\r\nLOCAL IP WAS SET TO ") ;
 161   4                    Printf_IPStr(My_Ip_Address);
 162   4                    Printf_String("\n");
 163   4                }//SETIP
 164   3      //================================================================================
 165   3                //设置网关值
 166   3                if ((Str_Compare("setgate",7)!=0)||(Str_Compare("SETGATE",7)!=0))
 167   3                {
 168   4                    ip = 0;
 169   4                    for(i=7,j=0;i<Command_Len;i++)
 170   4                    {  
 171   5                        if(Command_Buf[i]!='.')
 172   5                        {
 173   6                            Command_Buf[i]=Command_Buf[i]&0x0f;
 174   6                            ip=ip*10;
 175   6                            ip=ip+Command_Buf[i];
 176   6                           
 177   6                        }
C51 COMPILER V7.06   INPUT                                                                 05/27/2008 11:02:08 PAGE 4   

 178   5                        else
 179   5                        {
 180   6                            Gateway_Ip_Address.bytes[j]=ip;
 181   6                            j++;
 182   6                            ip=0;
 183   6                        }
 184   5                    }
 185   4                                              //命令执行
 186   4                    if(j==3)
 187   4                    {
 188   5                        Gateway_Ip_Address.bytes[j]=ip;
 189   5                    }
 190   4                    Printf_String("GATEWAY WAS SET TO ");
 191   4                    Printf_IPStr(Gateway_Ip_Address);
 192   4                    Printf_String("\n");
 193   4                }//setgate
 194   3      //================================================================================
 195   3                //=================以下处理udp command
 196   3                if((Str_Compare("udp",3)!=0)||(Str_Compare("UDP",3)!=0))
 197   3                {
 198   4                    ip=0;
 199   4                    for(i=3,j=0;i<Command_Len;i++)
 200   4                    {//取得ip地址
 201   5                        if(Command_Buf[i]!='.')
 202   5                        { 
 203   6                            Command_Buf[i]=Command_Buf[i]&0x0f;
 204   6                            ip=ip*10;
 205   6                            ip=ip+Command_Buf[i];
 206   6                        }
 207   5                        else
 208   5                        {
 209   6                            if(j<4)Ping_Ip_Address.bytes[j]=ip;
 210   6                            if(j==4)
 211   6                            {
 212   7                                 RemotePort.word=ip;
 213   7                                 //if(j==5)RemotePort.bytes.low=ip;
 214   7                                 Printf_PortStr(RemotePort.word);
 215   7                            }
 216   6                            j++;
 217   6                            if(j==5)
 218   6                            {
 219   7                                 Command_Buf[0]=i+1;
 220   7                                 Command_Len=Command_Len-i-1;
 221   7                                 Command_Buf[1]=Command_Len>>8;
 222   7                                 Command_Buf[2]=Command_Len&0xff;
 223   7                                 break;//
 224   7                            }
 225   6                            ip=0;
 226   6                        }
 227   5                    }
 228   4                    if(j==5)
 229   4                    {// 表示命令正确
 230   5                        Printf_String("\r\nUDP:DestIP=") ;
 231   5                        Printf_IPStr(Ping_Ip_Address);
 232   5                        Printf_String(" RemotePort=");
 233   5                        Printf_PortStr(RemotePort.word);
 234   5                        Udp_Count=10;//10second
 235   5                        if((Ping_Ip_Address.dwords&Mask_Ip_Address.dwords)==
 236   5                                                 (My_Ip_Address.dwords&Mask_Ip_Address.dwords))
 237   5                        {//表示位于同一子网.
 238   6                            Arp_Request(Ping_Ip_Address.dwords);
 239   6                        }
C51 COMPILER V7.06   INPUT                                                                 05/27/2008 11:02:08 PAGE 5   

 240   5                        else
 241   5                        {//表示属于不同的子网,需要通过网关.
 242   6                            Ping_IP_TTL=10;
 243   6                            for(j=0;j<6;j++)
 244   6                            {
 245   7                                Ping_MAC.bytes[j]=Gateway_MAC.bytes[j];
 246   7                            }
 247   6                            if(Gateway_IP_TTL==0)
 248   6                            {
 249   7                                 Printf_String("\r\nGateWay Not Found!\r\nC:>");
 250   7                                 Udp_Count=0;
 251   7                            }
 252   6                        }
 253   5                    }
 254   4                    else
 255   4                    {
 256   5                        Printf_String("\r\nudp Command Error\r\nC:>");
 257   5                    }
 258   4                }//UDP
 259   3      
 260   3      //================================================================================
 261   3                //张会福 增加 2004-10
 262   3                //显示帮助命令

⌨️ 快捷键说明

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