从u-boot移植出来的shell命令界面 下载本文

USART_PutStr(COMMUNICATE_USART, ListFileName[*para - '0']); USART_PutStr(COMMUNICATE_USART, \

if(0 == ZmodemSendOneFile(NameBuff)){//ZMODEMOK USART_PutStr(COMMUNICATE_USART, \ }else{

USART_PutStr(COMMUNICATE_USART, \ } }

//返回根目录

void BackCmdExeFun(char *para) {

yaffs_closedir(pCurDirectory);

pCurDirectory = yaffs_opendir(ROOT_DIR_NAME); yaffs_rewinddir(pCurDirectory);

//设置当前目录名字

strncpy(CirDirName, ROOT_DIR_NAME, sizeof(CirDirName));

NextCmdExeFun(NULL); }

//下10个目录项

void NextCmdExeFun(char *para) {

struct yaffs_dirent *pDirent; int n;

//打印当前目录名字 ShowCurDirectory();

for(n=0; n

ListFileName[n][0] = 0; }else{

strncpy(ListFileName[n], pDirent->d_name, FILE_NAME_MAXLEN); ListFileName[n][FILE_NAME_MAXLEN-1] = 0; USART_PutChar(COMMUNICATE_USART, '0' + n);

if(YAFFS_OBJECT_TYPE_DIRECTORY == pDirent->d_type) USART_PutStr(COMMUNICATE_USART, \ else

USART_PutStr(COMMUNICATE_USART, \

USART_PutStr(COMMUNICATE_USART, ListFileName[n]); USART_PutStr(COMMUNICATE_USART, \ } }

if(NULL == pDirent){

USART_PutStr(COMMUNICATE_USART, \reach the bottom of directory, no more file\\n\\r\ } }

//返回目录开始位置

void TopCmdExeFun(char *para) {

yaffs_rewinddir(pCurDirectory); NextCmdExeFun(NULL); }

//从PC机下载一个文件

void DownloadCmdExeFun(char *para) {

ZmodemReceiveFiles(); } /*

* shell命令界面,进入shell界面之前,需要设置COMMUNICATE_USART * 工作串口波特率为115200,并关闭COMMUNICATE_USART工作串口中断。 */

void shell(void) {

int n, CmdIndex;

unsigned char CmdBuffer[32];

//执行帮助命令 HelpCmdExeFun(NULL); //打开根目录

pCurDirectory = yaffs_opendir(ROOT_DIR_NAME); yaffs_rewinddir(pCurDirectory);

strncpy(CirDirName, ROOT_DIR_NAME, sizeof(CirDirName));

while(1){

readline_into_buffer(\ if(0 == CmdBuffer[0]){

continue; }

//检查命令

if( ('f' == CmdBuffer[0] || 'o' == CmdBuffer[0] || 'g' == CmdBuffer[0]) ){ //f、o、g命令和参数之间用1个空格隔开 if(' ' != CmdBuffer[1]){

USART_PutStr(COMMUNICATE_USART, \, you can input h for help\\n\\r\

continue; } }else{

//其他命令不带参数,第二个字符必须是结束符'/0' if(0 != CmdBuffer[1]){

USART_PutStr(COMMUNICATE_USART, \, you can input h for help\\n\\r\

continue; } }

//查找命令 CmdIndex = -1;

for(n=0; n

} }

if(-1 == CmdIndex){ //查找命令失败

USART_PutStr(COMMUNICATE_USART, \error, you can input h for help\\n\\r\

continue; }

//如果是exit命令,则退出shell界面,机器进入正常工作模式 if('e' == CmdTbl[CmdIndex].name){ yaffs_closedir(pCurDirectory);

USART_PutStr(COMMUNICATE_USART, \bye!^_^\\n\\r\

delay_ms(1000); return; }

//检查enter和get命令参数

if( ('o' == CmdTbl[CmdIndex].name || 'g' == CmdTbl[CmdIndex].name)\\ && (CmdBuffer[2]<'0' || '9'

USART_PutStr(COMMUNICATE_USART, \ continue; }

//执行命令

(CmdTbl[CmdIndex].CmdFun)(&CmdBuffer[2]); USART_PutStr(COMMUNICATE_USART, \ }//end while }

nicholasldf