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

📄 yyshell.c

📁 Keil C51的UCOS-2操作系统源代码
💻 C
字号:
//**********************************************************************************
//杨屹    2002/08/21    第一版
//我的主程序(SNMP网管板)
//联系方法:gdtyy@ri.gdt.com.cn(2003/07/31以前有效)
//**********************************************************************************

#include   <includes.h>

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<MaxComNum&&!ComMatchFlag;tem++)
						if(yystrcmp(WordTable.wt[0].Str,ComTable[tem])==0) ComMatchFlag=1;
					if(ComMatchFlag){
						tem--;
						switch(tem){
							case 0:{DisplayTask(&WordTable);break;}
							case 1:{Kill(&WordTable);break;}
							case 2:{PingCommand(&WordTable);break;}
							case 3:{UDPCommand(&WordTable);break;}
							case 4:{CfgHost(&WordTable);break;}
                           				case 5:{CfgMask(&WordTable);break;}
							case 6:{CfgGateway(&WordTable);break;}							
                            				case 7:{
								//ShellEnd=1;
								PrintStr("\n\tThis Command is limited!\n\n");
								break;
							}
							case 8:{PrintConfig(&WordTable);break;}
							case 9:{clrscr();break;}
							case 10:{DisplayHelpMenu(&WordTable);break;}
						}							
					}
					else
						PrintStr("    Bad command!\n\n");
				}
				else{
					if(WordTable.Num) PrintStr("    Bad command!\n\n");
				}

				ComMatchFlag=0;
				State=StatInputCom;
				if(ShellEnd) {PrintStr("\n\n");}
				else PrintStr("% ");
				i=-1;
				break;
			}
			default:{
				//ShellEnd=1;
				PrintStr("System fatal error!\n");
				PrintChar(7);PrintChar(7);PrintChar(7);
			}
		}
	}
}

⌨️ 快捷键说明

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