www.pudn.com > ucos_shell.rar > yyshell.c


//********************************************************************************** 
//杨屹    2002/08/21    第一版 
//我的主程序(SNMP网管板) 
//联系方法:gdtyy@ri.gdt.com.cn(2003/07/31以前有效) 
//********************************************************************************** 
 
#include    
 
static unsigned char ComTable[MaxComNum][MaxLenCom+1]={"lt","kill","ping","udp","host","mask","gateway","exit","ipcfg","clr","help"};			 
			 
int State=StatInputCom; 
unsigned char ch; 
int ShellEnd=0;		/*Shell end flag*/ 
unsigned char ComBuf[MaxLenComBuf+1];	/*store '\0'*/ 
int i=-1;			/*ComBuf pointer*/ 
int tem;			/*Temp variable*/ 
int ComMatchFlag=0;		/*Command match flag*/ 
 
WORDTABLE WordTable; 
	 
int Matched=0;	/*Match flag*/ 
 
OS_STK yyshellStk[MaxStkSize];//注意:我在ASM文件中设置?STACK空间为40H即64,不要超出范围。用户栈多一个字节存长度 
	 
xdata union ip_address_type my_ip_address;      //本机的ip地址 
xdata union ip_address_type temp_ip_address;    //临时变量 
xdata union ip_address_type mask_ip_address;    //子网掩码 
xdata union ip_address_type gateway_ip_address;	//网关的ip地址 
xdata union ip_address_type ping_ip_address;	//用于ping命令 
 
void main(void) 
{ 
    OSInit(); 
     
    InitTimer0(); 
    InitSerial(); 
    InitSerialBuffer(); 
     
    //初始化网络参数 
    IPadrToHEX("172.18.92.87",&my_ip_address.bytes[0]); 
    IPadrToHEX("255.255.255.0",&mask_ip_address.bytes[0]); 
    IPadrToHEX("172.18.91.5",&gateway_ip_address.bytes[0]);     
     
    OSTaskCreate(yyshell, (void *)0, &yyshellStk[0],8);     
     
    OSStart(); 
} 
 
void yyshell(void *yydata) reentrant 
{ 
	yydata=yydata; 
	clrscr(); 
	PrintStr("\t\t***********************************************\n"); 
	PrintStr("\t\t*         Welcom to use this program          *\n"); 
	PrintStr("\t\t*                   Author:YangYi 20020715    *\n"); 
	PrintStr("\t\t***********************************************\n\n\n"); 
		 
	/*Login & Password*/ 
 
	PrintStr("% "); 
	while(!ShellEnd){ 
 
		switch(State){ 
			case StatInputCom:{ 
				if(yygetch(&ch)){ 
					if(ch==13)	/*Enter return key*/ 
					{ 
						PrintStr("\n"); 
						ComBuf[i+1]='\0';					 
						if(i+1==0) PrintStr("% "); 
						else					 
						State=StatExeCom; 
					} 
					else{ 
						i=i+1; 
						if((i>=MaxLenComBuf)&&(ch!=8)){ 
							PrintChar(7); 
							i=MaxLenComBuf-1; 
						} 
						else{ 
							if(ch==8){ 
								i=i-2; 
								if(i<-1) {i=-1;PrintChar(7);} 
								else{ 
									PrintChar(8); 
									PrintChar(' '); 
									PrintChar(8); 
								} 
							} 
							else{ 
								PrintChar(ch); 
								ComBuf[i]=ch; 
							} 
						} 
					} 
					break; 
				} 
				else{ 
					//OSTimeDly(10); 
					break; 
				} 
			} 
			case StatExeCom:{ 
				if(GetWord(ComBuf,&WordTable)==1&&WordTable.Num!=0){ 
					yystrlwr(WordTable.wt[0].Str); 
					for(tem=0;tem