/**
* @file cmdCli.c
* @brief: command client running independently out of mua application
*
* ----------------------------------------------------------------------
* History:
* date version author action
* 2007/07/06 0.0.1 liaoxx file created
* ----------------------------------------------------------------------
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include "nw_const.h"
#include "fw_env.h"
#include "cmdTypes.h"
NW_BOOL read_ini(TGlobalInfo *pInfo);
NW_BOOL write_ini(TGlobalInfo *pInfo);
NW_BOOL pack(NW_CHAR* str0,NW_CHAR* str1,NW_CHAR* str2,NW_CHAR* str3,NW_CHAR* str4,NW_CHAR* pszBuf);
NW_BOOL alive(NW_CHAR* name);
int main(int argc,char* argv[])
{
struct sockaddr_in tCli2BkgdAddr;
NW_INT32 nCli2BkgdAddrLen=0;
struct stat tMuaExe,tSymbols,tBkgd;
TGlobalInfo tGlobalInfo={0};
NW_INT32 nCli2BkgdSock=0;
NW_CHAR szCli2BkgdBuff[SOCK_SEND_BUF];
NW_CHAR* pszBuf=szCli2BkgdBuff;
NW_INT32 nArgc;
NW_INT32 nTotalLen=0;
NW_INT32 nLen=0;
NW_UINT32 nLocalIP;
NW_CHAR szLocalIP[MAX_IP_LEN];
NW_UINT32 nReused=1;
NW_BOOL bPacked=FALSE;
NW_UINT32 nMuaExeTime,nSymbolsTime;
NW_INT32 nMagic=0;
NW_INT32 nCnt;
NW_INT32 nRet;
if (argc < 1 || argc > MAX_CMD_LINE_ARG_NUM)
{
printf("Invalid cmd line arument num %d!\n",argc);
return -1;
}
if (1 == argc || (2 == argc && 0 == strcmp(argv[1],"--help")))
{
printf("DESCRIPTION\n");
printf(" cmd v1.00(%s),commands for debugging or updating mua system\n\n",__DATE__);
printf("SYNOPSIS\n");
printf(" %3s [option]\n\n", argv[0]);
printf("OPTIONS\n", argv[0]);
printf(" printenv : print uboot environments\n");
printf(" setenv [env] [val] : set 'env' to 'val'\n");
printf(" delenv [env] : delete 'env' \n\n");
printf(" show readme : print cmd readme\n");
printf(" show symbols : show symbol one by one\n");
printf(" show next [num] : show next 'num'(optional) symbols\n");
printf(" show restart : go back to the beginning\n");
printf(" find [keyword] : find all symbols matched by 'keyword'\n\n");
printf(" toggle 1/0 : toggle(1) or release(0) printing on current terminal\n");
printf(" syslog 1/0 : open(1) or close(0,default) muaExe's log msg printing\n");
printf(" endian 1/0 : display memory in little(0) or big(1,default) endian\n\n");
printf(" display [addr] [len] : display memory with 'addr' and 'len'\n");
printf(" modify [addr] [val] : modify memory with 'addr' and 'val'\n\n");
printf(" [var] [type:val]... : set 'var' to 'val' with 'type'(optional) concerned\n");
printf(" [func] [arg0]~[argN] : call 'func' with arguments from 'arg0' to 'argN'\n\n");
printf(" update pkg1 : update muapkg from ftp server\n");
printf(" update pkg2 : update muapkg from tftp server\n");
printf(" update muaExe : update muaExe from tftp server\n");
printf(" update firmware : update Firmware.out from tftp server\n");
#if defined(DEBUG)
printf(" update itself : update cmd itself from tftp server\n");
printf(" update bkgd : update bkgd from tftp server\n");
printf(" update cmdtest : update cmdtest from tftp server\n");
printf(" update readme : update readme.txt from tftp server\n");
#endif
printf("\n");
printf(" **************************************************************\n");
printf(" *注意:使用命令'cmd show readme'可以查看中文使用方法和注意事项*\n");
printf(" **************************************************************\n");
return 0;
}
if (argc == 3 && 0 == strcmp(argv[1],"show") && 0 == strcmp(argv[2],"readme"))
{
NW_UINT8 shell_line[256];
memset(shell_line,0x00,256);
sprintf(shell_line,"more %s",README);
system(shell_line);
return 0;
}
if (argc == 3 && 0 == strcmp(argv[1],"show") && 0 == strcmp(argv[2],"symbols"))
{
NW_UINT8 shell_line[256];
memset(shell_line,0x00,256);
sprintf(shell_line,"more %s",SYMBOL_TBL);
system(shell_line);
return 0;
}
if (argc > 1 && 0 == strcmp(argv[1],"printenv"))
{
uboot_env_t uboot_env;
uboot_env_t* p_uboot_env=&uboot_env;
unsigned char env_line[UBOOT_ENV_LINE_SIZE];
int idx;
if (load_uboot_env(p_uboot_env)!=0)
{
printf("Faild to load uboot env!\n");
return -1;;
}
for (idx=0;idx<p_uboot_env->ui_param_pair_num;idx++){
sprintf(env_line,"[uboot #]%s=%s\r\n",
p_uboot_env->p_param_pair[idx].uc_env_name,
p_uboot_env->p_param_pair[idx].uc_env_value);
printf(env_line);
}
return -1;
}
if (argc > 1 && 0 == strcmp(argv[1],"setenv"))
{
uboot_env_t uboot_env;
uboot_env_t* p_uboot_env=&uboot_env;
NW_UINT8 env_line[UBOOT_ENV_LINE_SIZE],*p_env=env_line;
NW_CHAR* pch;
NW_INT32 idx,nIndex;
NW_BOOL bChanged=FALSE;
if (3 > argc)
{
printf("Syntax error!\nIt should be '# cmd setenv [name] [val]'\n");
return -1;
}
if (load_uboot_env(&uboot_env)!=0)
{
printf("Faild to load uboot env!\n");
return -1;
}
for (idx = 3;idx < argc; idx++)
{
if (NULL != (pch = strstr(argv[idx],",")))
{
*pch = ';';
}
strcat(p_env,argv[idx]);
if (idx != argc -1)
strcat(p_env," ");
}
if((nIndex = search_env(&uboot_env,argv[2])) >=0)
{
if (0 != strcmp(uboot_env.p_param_pair[nIndex].uc_env_value,p_env))
{
if (-1 == modify_env(&uboot_env,argv[2],p_env) !=0)
{
printf("Failed to modify %s!\n",argv[2]);
return -1;
}
bChanged = TRUE;
}
}
else
{
if (add_env(&uboot_env,argv[2],p_env)!=0)
{
printf("Failed to add %s!\n",argv[2]);
return -1;
}
bChanged = TRUE;
}
return (bChanged? save_uboot_env(&uboot_env):0);
}
if (argc > 1 && 0 == strcmp(argv[1],"delenv"))
{
uboot_env_t uboot_env;
NW_INT32 nIndex;
if (3 != argc)
{
printf("Syntax error!\nIt should be '# cmd delenv [name]'\n");
return -1;
}
if (load_uboot_env(&uboot_env)!=0)
{
printf("Faild to load uboot env!\n");
return -1;
}
if (del_env(&uboot_env,argv[2])!=0)
{
printf("Failed to delete %s!\n",argv[2]);
return -1;
}
return save_uboot_env(&uboot_env);
}
if (argc > 1 && 0 == strcmp(argv[1],"update"))
{
uboot_env_t uboot_env;
NW_UINT8 shell_line[256];
NW_CHAR szServerIP[30];
NW_CHAR szUser[30];
NW_CHAR szPass[30];
NW_INT32 nIndex;
NW_BOOL bChanged=FALSE;
NW_BOOL bConfirmed=FALSE;
if (3 != argc)
{
printf("Syntax error!\nCheck cmd option you entered,argc %d!\n",argc);
return -1;
}
if (!alive("telnetd") && 0 != strcmp(argv[2],"itself2") && 0 != strcmp(argv[2],"itself3"))
{
printf("通过超级终端下栽速度很慢,建议通过telnet 下栽\n");
do
{
printf("继续操作键入'yes',退出键入'no' :\n");
memset(shell_line,0x00,256);
read(0, shell_line, sizeof (shell_line));
bConfirmed = (0 == strncmp(shell_line,"yes",strlen("yes"))
|| 0 == strncmp(shell_line,"no",strlen("no"))) ? TRUE:FALSE;
if (!bConfirmed)
{
printf("输入错误,请重输!\n");
}
}while(!bConfirmed);
if (0 == strncmp(shell_line,"no",strlen("no")))
{
return -1;
}
}
#if defined(DEBUG)
if (0 == strcmp(argv[2],"itself"))
{
system("cp /usr/bin/cmd /usr/bin/cmd2");
system("chmod 777 /usr/bin/cmd2");
system("/usr/bin/cmd2 update itself2");
return 0;
}
else if (0 == strcmp(argv[2],"itself2"))
{
if (load_uboot_env(&uboot_env)!=0)
{
printf("Faild to load uboot env!\n");
return -1;
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
cmd-comand,use command to debug your code in linux environment,it's a useful tool for linux programmer.you can add stub in your code and run the cmd tool to debug it.
资源推荐
资源详情
资源评论
收起资源包目录
cmd.rar (11个子文件)
uas3
muaMain.c 50B
include
source
cmd
cmdFilter.c 2KB
cmdServ.c 12KB
cmdBkgd.c 17KB
cmdCli.c 26KB
cmdTypes.h 2KB
cmdTest.c 3KB
cmdFilter.h 937B
Makefile 961B
cmd 20KB
Makefile 2KB
共 11 条
- 1
资源评论
embedesign
- 粉丝: 8
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功