📄 myshell.c
字号:
//**********************************************************************************
//杨屹 2002/08/21 第一版
//shell界面命令执行程序
//联系方法:gdtyy@ri.gdt.com.cn(2003/07/31以前有效)
//**********************************************************************************
#include <general.h>
//#include <string.h>
//#include <mystring.h>
//#include <serial.h>
//#include <SerEEROM.h>
//#include <word.h>
//#include <myshell.h>
//#include <myconfig51.h>
//Command execute.
void WriteBdSel(WORDTABLE *WordTable)//输出板选4bit16板位
{
long int Num;
if(WordTable->Num==1) PrintStr("Syntax error!\7\n");
else{
if(StrToNum(WordTable->wt[1].Str,&Num)==0) PrintStr("Board number error!\7\n");
else{
opBoardSel(Num);PrintStr("Sir:Write board select finished!\n");
}
}
}
void WriteDataX(WORDTABLE *WordTable)//向X5045中给定地址写入数据
{
long int Num;
int i,adr,len,tadr;
unsigned char WIP,dat[MaxLenWordTable-1];
if(WordTable->Num<3) PrintStr("Syntax error!\7\n");
else{
if(StrToNum(WordTable->wt[1].Str,&Num)==0) PrintStr("Address error!\7\n");
else{
if((strcmp(WordTable->wt[2].Str,"x")==0)|(strcmp(WordTable->wt[2].Str,"X")==0)){
adr=Num;len=WordTable->Num-3;
for(i=0;i<len;i++){
if(StrToHEX(WordTable->wt[i+3].Str,&Num)==0){PrintStr("Data error!\7\n");return;}
dat[i]=Num;
}
for(i=0;i<len;i++){
//
do{
opx5045(RDSR,0,0,&WIP);
}while((WIP&0x1)==1);
//
tadr=adr;tadr=tadr+i;tadr=tadr&0x1FF;
opx5045(WREN,tadr,1,&dat[i]);
opx5045(WRITE,tadr,1,&dat[i]);
}
PrintStr("Sir:Write X5045 finished!\n");
}
else{
adr=Num;len=WordTable->Num-2;
for(i=0;i<len;i++){
if(StrToNum(WordTable->wt[i+2].Str,&Num)==0){PrintStr("Data error!\7\n");return;}
dat[i]=Num;
}
for(i=0;i<len;i++){
//
do{
opx5045(RDSR,0,0,&WIP);
}while((WIP&0x1)==1);
//
tadr=adr;tadr=tadr+i;tadr=tadr&0x1FF;
opx5045(WREN,tadr,1,&dat[i]);
opx5045(WRITE,tadr,1,&dat[i]);
}
PrintStr("Sir:Write X5045 finished!\n");
}
}
}
}
void ReadDataX(WORDTABLE *WordTable)//读出X5045给定地址数据
{
long int Num;
int i,j,adr,LineNum;
unsigned char dat[ROMSIZE];
unsigned char ch;
if(WordTable->Num==1) {adr=0;LineNum=1;}
else if(WordTable->Num==2){
if(StrToNum(WordTable->wt[1].Str,&Num)==0){PrintStr("Address error!\7\n");return;}
adr=Num;LineNum=1;
}
else{
if(StrToNum(WordTable->wt[1].Str,&Num)==0){PrintStr("Address error!\7\n");return;}
adr=Num;
if(StrToNum(WordTable->wt[2].Str,&Num)==0){PrintStr("Line number error!\7\n");return;}
LineNum=Num;
}
if(LineNum>(ROMSIZE/16)){PrintStr("Line number error!\7\n");return;}
opx5045(READ,adr,LineNum*16,dat);
for(i=0;i<LineNum;i++){
adr=adr&0x1FF;
ch=adr>>8;PrintByte(ch);ch=adr&0xFF;PrintByte(ch);PrintStr(" ");adr=adr+0x10;
for(j=0;j<8;j++){
PrintByte(dat[i*16+j]);
PrintStr(" ");
}
PrintStr(" ");
for(j=0;j<8;j++){
PrintByte(dat[i*16+j+8]);
PrintStr(" ");
}
PrintStr(" ");
for(j=0;j<16;j++){
ch=dat[i*16+j];
if((ch>=0x20)&&(ch<=0x7F)) PrintChar(ch);
else PrintChar('.');
}
PrintStr("\n");
}
}
void WriteXReg(WORDTABLE *WordTable)//写X5045寄存器
{
long int Num;
unsigned char dat;
if(WordTable->Num==1) PrintStr("Syntax error!\7\n");
else{
if(StrToNum(WordTable->wt[1].Str,&Num)==0) PrintStr("Data error!\7\n");
else{
dat=Num;
opx5045(WRSR,0,0,&dat);PrintStr("Sir:Write X5045 register finished!\n");
}
}
}
void ReadXReg(WORDTABLE *WordTable)//读X5045寄存器
{
unsigned char dat;
opx5045(RDSR,0,0,&dat);
PrintStr("RDSR=");PrintByte(dat);PrintStr("H\n");
}
void Erase66(WORDTABLE *WordTable)//擦除93LC66B
{
long int Num;
unsigned char adr;
unsigned int dat;
unsigned char ch;
if(WordTable->Num==1) PrintStr("Syntax error!\7\n");
else{
yystrlwr(WordTable->wt[1].Str);
if(strcmp(WordTable->wt[1].Str,"all")==0){
PrintStr("This command is too danger!Are you sure to run?(Y/N)");
while(yygetch(&ch)==0);
if(ch!='y'&&ch!='Y'){PrintStr("\n\nAbort!\7\7\7\n");return;}
op93LC66B(EWEN,0,0,&dat);
op93LC66B(ERAL,0,0,&dat);
op93LC66B(EWDS,0,0,&dat);
PrintStr("\n\nSir:Erase all 93LC66B finished!\n");
}
else if(StrToNum(WordTable->wt[1].Str,&Num)==0) PrintStr("Data error!\7\n");
else{
adr=Num;
op93LC66B(EWEN,0,0,&dat);
op93LC66B(ERASE,adr,0,&dat);
op93LC66B(EWDS,0,0,&dat);
PrintStr("Sir:Erase 93LC66B finished!\n");
}
}
}
void Read66(WORDTABLE *WordTable)//按字读93LC66B数据
{
long int Num;
int i,j,adr,LineNum;
unsigned int dat[ROMSIZE],x;
unsigned char ch;
if(WordTable->Num==1) {adr=0;LineNum=1;}
else if(WordTable->Num==2){
if(StrToNum(WordTable->wt[1].Str,&Num)==0){PrintStr("Address error!\7\n");return;}
adr=Num;LineNum=1;
}
else{
if(StrToNum(WordTable->wt[1].Str,&Num)==0){PrintStr("Address error!\7\n");return;}
adr=Num;
if(StrToNum(WordTable->wt[2].Str,&Num)==0){PrintStr("Line number error!\7\n");return;}
LineNum=Num;
}
if(LineNum>(ROMSIZE/16)){PrintStr("Line number error!\7\n");return;}
op93LC66B(READB,adr,LineNum*8,dat);//(*8)93LC66B 16bit/data,(*16)but x5045 8bit/data.
for(i=0;i<LineNum;i++){
adr=adr&0x1FF;
ch=adr>>8;PrintByte(ch);ch=adr&0xFF;PrintByte(ch);PrintStr(" ");adr=adr+0x8;
for(j=0;j<4;j++){
x=dat[i*8+j];
PrintByte(x>>8);
//PrintStr(" ");
PrintByte(x);
PrintStr(" ");
}
PrintStr(" ");
for(j=0;j<4;j++){
x=dat[i*8+j+4];
PrintByte(x>>8);
//PrintStr(" ");
PrintByte(x);
PrintStr(" ");
}
PrintStr(" ");
for(j=0;j<8;j++){
x=dat[i*8+j];
ch=x>>8;
if((ch>=0x20)&&(ch<=0x7F)) PrintChar(ch);
else PrintChar('.');
ch=x;
if((ch>=0x20)&&(ch<=0x7F)) PrintChar(ch);
else PrintChar('.');
}
PrintStr("\n");
}
}
void ReadByte66(WORDTABLE *WordTable)//按字节读93LC66B数据
{
long int Num;
int i,j,adr,LineNum;
unsigned int dat[ROMSIZE],x;
unsigned char ch;
if(WordTable->Num==1) {adr=0;LineNum=1;}
else if(WordTable->Num==2){
if(StrToNum(WordTable->wt[1].Str,&Num)==0){PrintStr("Address error!\7\n");return;}
adr=Num;LineNum=1;
}
else{
if(StrToNum(WordTable->wt[1].Str,&Num)==0){PrintStr("Address error!\7\n");return;}
adr=Num;
if(StrToNum(WordTable->wt[2].Str,&Num)==0){PrintStr("Line number error!\7\n");return;}
LineNum=Num;
}
if(LineNum>(ROMSIZE/16)){PrintStr("Line number error!\7\n");return;}
op93LC66B(READB,adr,LineNum*8,dat);//(*8)93LC66B 16bit/data,(*16)but x5045 8bit/data.
for(i=0;i<LineNum;i++){
adr=adr&0x1FF;
ch=adr>>8;PrintByte(ch);ch=adr&0xFF;PrintByte(ch);PrintStr(" ");adr=adr+0x10;
for(j=0;j<4;j++){
x=dat[i*8+j];
PrintByte(x);
PrintStr(" ");
PrintByte(x>>8);
PrintStr(" ");
}
PrintStr(" ");
for(j=0;j<4;j++){
x=dat[i*8+j+4];
PrintByte(x);
PrintStr(" ");
PrintByte(x>>8);
PrintStr(" ");
}
PrintStr(" ");
for(j=0;j<8;j++){
x=dat[i*8+j];
ch=x;
if((ch>=0x20)&&(ch<=0x7F)) PrintChar(ch);
else PrintChar('.');
ch=x>>8;
if((ch>=0x20)&&(ch<=0x7F)) PrintChar(ch);
else PrintChar('.');
}
PrintStr("\n");
}
}
void Write66(WORDTABLE *WordTable)//写93LC66B
{
long int Num;
int i,adr,len,tadr;
unsigned int dat[MaxLenWordTable-1];
if(WordTable->Num<3) PrintStr("Syntax error!\7\n");
else{
yystrlwr(WordTable->wt[1].Str);
if(strcmp(WordTable->wt[1].Str,"all")==0){
if(StrToNum(WordTable->wt[2].Str,&Num)==0) {PrintStr("Data error!\7\n");return;}
dat[0]=Num;
op93LC66B(EWEN,0,0,dat);
op93LC66B(WRAL,0,1,dat);
op93LC66B(EWDS,0,0,dat);
PrintStr("Sir:Write all 93LC66B finished!\n");
}
else if(StrToNum(WordTable->wt[1].Str,&Num)==0) PrintStr("Address error!\7\n");
else{
if((strcmp(WordTable->wt[2].Str,"x")==0)||(strcmp(WordTable->wt[2].Str,"X")==0)){
adr=Num;len=WordTable->Num-3;
for(i=0;i<len;i++){
if(StrToHEX(WordTable->wt[i+3].Str,&Num)==0){PrintStr("Data error!\7\n");return;}
dat[i]=Num;
}
for(i=0;i<len;i++){
tadr=adr;tadr=tadr+i;tadr=tadr&0x1FF;
op93LC66B(EWEN,tadr,0,&dat[i]);
op93LC66B(WRITEB,tadr,1,&dat[i]);
op93LC66B(EWDS,tadr,0,&dat[i]);
}
PrintStr("Sir:Write 93LC66B finished!\n");
}
else{
adr=Num;len=WordTable->Num-2;
for(i=0;i<len;i++){
if(StrToNum(WordTable->wt[i+2].Str,&Num)==0){PrintStr("Data error!\7\n");return;}
dat[i]=Num;
}
for(i=0;i<len;i++){
tadr=adr;tadr=tadr+i;tadr=tadr&0x1FF;
op93LC66B(EWEN,tadr,0,&dat[i]);
op93LC66B(WRITEB,tadr,1,&dat[i]);
op93LC66B(EWDS,tadr,0,&dat[i]);
}
PrintStr("Sir:Write 93LC66B finished!\n");
}
}
}
}
void DisplayPortValue(WORDTABLE *WordTable)//显示IO端口数据
{
PrintStr("\n");
PrintStr("ISIN=");PrintByte(isin);PrintStr(" ");
PrintStr("LINKOK=");PrintByte(linkok);PrintStr(" ");
PrintStr("TXSPEED=");PrintByte(txspeed);PrintStr(" ");
PrintStr("POW0=");PrintByte(pow0);PrintStr(" ");
PrintStr("POW1=");PrintByte(pow1);PrintStr("\n\n");
}
void DisplayHelpMenu(WORDTABLE *WordTable)//显示帮助采单
{
PrintStr("\n");
PrintStr("\trdp Read port data.\n");
PrintStr("\twrbs Write board select.\n");
PrintStr("\twdx Write data to X5045.\n");
PrintStr("\trdx Read data from X5045.\n");
PrintStr("\twxr Write X5045 register.\n");
PrintStr("\trxr Read X5045 register.\n");
PrintStr("\terase66 Erase 93LC66B.\n");
PrintStr("\trd66 Read data from 93LC66B.\n");
PrintStr("\trdb66 Read data from 93LC66B.(Byte mode)\n");
PrintStr("\twd66 Write data to 93LC66B.\n");
PrintStr("\tConfigNet host/gateway/mask/snmphost/macadr/lc.\n");
PrintStr("\tping/udp net command.\n");
PrintStr("\tclr Clear screen.\n");
PrintStr("\tls/lt List ARP cache/List transmit buffer.\n");
PrintStr("\texit Exit.\n");
PrintStr("\thelp Display this menu.\n\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -