📄 cmdstr.c
字号:
/***********************************************Copyright (c)*********************************************
** Guangzou ZLG-MCU Development Co.,LTD.
**
** http://www.zlgmcu.com
**
**--------------File Info---------------------------------------------------------------------------------
** File name: CmdStr.C
** Last modified Date: 2007-09-20
** Last Version: 1.0
** Descriptions: 对以前的代码进行了整理
**
**--------------------------------------------------------------------------------------------------------
** Created by: chengmingji
** Created date: 2007-07-08
** Version: 1.0
** Descriptions: 第一版
**
**--------------------------------------------------------------------------------------------------------
** Modified by: lixiaocheng
** Modified Date: 2007-09-20
** Version: 1.0
** Descriptions: 对代码进行了重新的整理
**
**--------------------------------------------------------------------------------------------------------
** Modified by: lixiaocheng
** Modified Date: 2007-10-16
** Version: 1.1
** Descriptions: 改进了ImpCmd函数,对用户传入参数进行拷贝后在操作,并优化了堆栈操作
** 改进了ExpCmd函数,减少了一个参数输入,减少了部件参数数量的输入
**
*********************************************************************************************************/
#include "config.h"
/*********************************************************************************************************
** Function name: CmdStr
** Descriptions: 用户命令初级处理
** input parameters: pstr : 用户数组
** pargv :处理后的字符串指针
** Returned value: 操作成功:返回处理成功的字符命令个数
*********************************************************************************************************/
static int CmdStr (char *pstr, char *pargv[])
{
int argc;
char ch, ch1;
/* 除去开始的空格 */
while (*pstr==' ') {
pstr++;
}
argc = 0;
while (1) {
if (*pstr == '\"') {
pstr++;
pargv[argc] = pstr;
while (1) {
ch = *pstr;
if (ch == 0) {
pstr++;
break;
}
if (ch == '\"') {
ch1 = pstr[1];
if (ch1 == ' ') {
*pstr++ = 0;
break;
}
if (ch1 == 0) {
*pstr++ = 0;
ch = 0;
break;
}
}
pstr++;
}
} else {
pargv[argc] = pstr;
while (1) {
ch = *pstr;
if (ch == ' ' || ch == 0) {
*pstr++ = 0;
break;
}
pstr++;
}
}
argc++;
if (ch == 0) {
break;
}
/* 除去多余的空格 */
while ((ch = *pstr) == ' ') {
pstr++;
}
if (ch == 0) {
break;
}
}
return argc;
}
/*********************************************************************************************************
** Function name: ImpCmd
** Descriptions: 用户字符命令转换为系统可设置的数字参数:
** input parameters: uiID : 外设编号:Tab_UART,Tab_I2C,Tab_SSP,Tab_SPI,Tab_RTC
** pcarg : 用户输入的字符串指针
** puiPara : 转换后的数字参数地址
** Returned value: 操作成功:返回处理成功的字符命令个数
*********************************************************************************************************/
int ImpCmd (uint32 uiID,
char *pcarg,
uint32 *puiPara )
{
int iArgc;
int i,j;
int iSucc=0;
uint32 uiNum;
char *pcArgv[12];
char temp2[3]={'%','i','\0'};
uiNum = GucCmdTabNum[uiID]; /* 获取命令参数表参数的个数 */
if ( pcarg == NULL || puiPara == NULL ) {
return OPERATE_FAIL;
} else {
char temp[160];
strcpy( temp, pcarg); /* 拷贝用户参数进行修改 */
iArgc = CmdStr(temp, pcArgv);
}
for (i=0; i<iArgc; i++) {
for (j=0; j<uiNum; j++) {
char temp[16];
strcpy(temp, Cmd_Tab[uiID][j]);
strcat(temp, temp2);
if ( sscanf((char *)pcArgv[i],temp,(puiPara+j)) != 0 ) {
iSucc ++;
break;
}
}
}
return iSucc; /* 解析完参数的个数 */
}
/*********************************************************************************************************
** Function name: ExpCmd
** Descriptions: 系统设置的数字参数转换为字符串输出
** input parameters: uiID : 外设编号:Tab_UART,Tab_I2C,Tab_SSP,Tab_SPI,Tab_RTC
** pcarg : 用户的字符串指针
** puiPara : 系统的数字参数地址
** Returned value: 操作成功:OPERATE_SUCCESS
*********************************************************************************************************/
int ExpCmd (uint32 uiID,
char *pcarg,
uint32 *puiPara )
{
int n;
uint32 uiNum;
char temp[8];
uiNum = GucCmdTabNum[uiID];
if ( pcarg == NULL || puiPara == NULL ) {
return OPERATE_FAIL;
}
*pcarg = '\0';
for(n=0;n<uiNum;n++) {
strcat(pcarg,Cmd_Tab[uiID][n]);
sprintf(temp,"%i ",puiPara[n]);
strcat(pcarg,temp);
}
return OPERATE_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -