📄 dcf_parser_cmd.c
字号:
/****************************************************************************/
/* CONEXANT PROPRIETARY AND CONFIDENTIAL */
/* SOFTWARE FILE/MODULE HEADER */
/* Copyright Conexant Systems Inc. 2005 */
/* Shanghai, China */
/* All Rights Reserved */
/****************************************************************************/
/*
* Filename: DCF_PARSER_CMD.C
*
*
* Description:
*
*
* Author: Yi Liu
*
****************************************************************************/
/* $Header: dcf_parser_cmd.c, 1, 2007-10-8 13:36:53, Yong Huang$
* $Id: dcf_parser_cmd.c,v 1.0, 2007-10-08 05:36:53Z, Yong Huang$
****************************************************************************/
/*****************/
/* Include Files */
/*****************/
#include "stbcfg.h"
#include "basetype.h"
#include "kal.h"
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "dcf_parser_cmd.h"
#include "dcf_test.h"
/*************************/
/* External Declarations */
/*************************/
/********************/
/* Global Variables */
/********************/
CNXT_DRVTEST_CMD *cmd_format_table;
drvtest_cmd_callback *cmd_callback_table;
u_int8 input_cmd[MAX_COMMAND_INPUT_LENGTH];
/*******************/
/* Local Variables */
/*******************/
static task_id_t DrvTestTaskId;
static void drvtest_main_task(void * param);
/***************************/
/* Local Utility Functions */
/***************************/
/****************************************************************************/
/* FUNCTION: RemoveCMDLeadingSpaces */
/* */
/* DESCRIPTION: remove the spaces before the command name */
/* */
/* INPUTS: */
/* */
/* OUTPUTS: */
/* */
/* RETURNS: */
/* */
/* NOTES: */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/****************************************************************************/
void RemoveCMDLeadingSpaces(u_int8 *pszStr)
{
u_int8 *p = pszStr;
while (*p && *p <= ' ')
{
p++;
}
pszStr = p;
}
/****************************************************************************/
/* FUNCTION: cnxt_stricmp */
/* */
/* DESCRIPTION: compare two strings but ignoring the uppercase and */
/* lowercase */
/* */
/* INPUTS: */
/* */
/* OUTPUTS: */
/* */
/* RETURNS: 0 -same */
/* */
/* NOTES: */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/****************************************************************************/
int cnxt_stricmp(char *dest, char *src)
{
u_int16 i;
for (i = 0; dest[i] != '\0' && src[i] != '\0'; i++)
{
if(((dest[i]>='A' && dest[i]<='Z') || (dest[i]>='a' && dest[i]<='z'))
&& ((src[i]>='A' && src[i]<='Z') || (src[i]>='a' && src[i]<='z')))
{
if((dest[i] & ~0x20)!= (src[i] & ~0x20))
{
return dest[i] - src[i];
}
}
else if (dest[i] != src[i])
{
return dest[i] - src[i];
}
}
if (dest[i] == '\0' && src[i] == '\0')
{
return 0;
}
else if (dest[i] == '\0')
{
return -1;
}
else
{
return 1;
}
}
/****************************************************************************/
/* FUNCTION: Str2Int */
/* */
/* DESCRIPTION: convert string to number (hex, decimal) */
/* INPUTS: pszStr - pointer to the command */
/* */
/* OUTPUTS: pszStr - pointer to terminating character */
/* puInt - pointer to the get value */
/* */
/* RETURNS: */
/* */
/* NOTES: if the iuput is hex, it must start as 0x, ignore the uppercase */
/* and lowercase */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/****************************************************************************/
bool Str2Int(u_int8 **pszStr, u_int32 *puInt)
{
u_int8 *s = *pszStr;
u_int32 i = 0;
u_int16 n;
int8 sign = 1;
u_int8 base = 10;
bool res = FALSE;
/*skip leading spaces */
while (s[i] && (s[i] <= ' '))
{
i++;
}
if (s[i] && (s[i] == '+' || s[i] == '-'))
{
sign = (s[i++] == '+') ? 1 : -1;
}
Base16:
n = 0;
while ((s[i]>='0' && s[i]<='9') ||
( ((s[i]>='A' && s[i]<='F') || (s[i]>='a' && s[i]<='f')) && base==16 ) ||
( ((s[i]=='X' || s[i]=='x') && base==10 && n==0) ))
{
res = TRUE;
if (s[i] == 'X' || s[i] == 'x')
{
base = 16;
sign = 1;
i++;
goto Base16;
}
if (base == 10)
{
n = base * n + s[i] - '0';
}
else if (s[i]>='0' && s[i]<='9')
{
n = base * n + s[i] - '0';
}
else
{
n = base * n + (s[i] & ~0x20) - 'A' + 10; /*ignore the uppercase and lowercase( lowercase transfor to uppercase)*/
}
i++;
}
*puInt = sign * n;
*pszStr = &s[i];
return res;
}
/****************************************************************************
** Public APIs */
/****************************************************************************/
/****************************************************************************/
/* FUNCTION: cnxt_drvtest_init */
/* */
/* DESCRIPTION: initialize the driver test module */
/* INPUTS: */
/* */
/* OUTPUTS: */
/* */
/* RETURNS: DRVTEST_OK -initialize successfully */
/* DRVTEST_ERROR - initialize failed */
/* */
/* NOTES: */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/****************************************************************************/
CNXT_DRVTEST_STATUS cnxt_drvtest_init()
{
u_int32 uFmtSize;
u_int32 uCallbackSize;
CNXT_DRVTEST_CMD *puTemp1;
drvtest_cmd_callback *puTemp2;
DrvTestTaskId=task_create(drvtest_main_task, 0, 0, DEFAULT_STACK_SIZE, DEFAULT_PRIORITY, "DTT");
if(DrvTestTaskId==0)
{
//trace("driver test initialize failed!\n");
return DRVTEST_ERROR;
}
{
extern CNXT_DRVTEST_CMD cmd_format_demod[DRVTEST_ITEM_NUM_DEMOD];
extern drvtest_cmd_callback cmd_callback_demod[DRVTEST_ITEM_NUM_DEMOD];
/*malloc the memory for format table of all modules*/
uFmtSize = sizeof(CNXT_DRVTEST_CMD) + sizeof(cmd_format_demod);
cmd_format_table=(CNXT_DRVTEST_CMD*)mem_malloc(uFmtSize);
if(!cmd_format_table)
{
return DRVTEST_ERROR;
}
puTemp1 = cmd_format_table;
/*demod format table*/
memcpy(puTemp1, cmd_format_demod, sizeof(cmd_format_demod));
puTemp1 += sizeof(cmd_format_demod) / sizeof(CNXT_DRVTEST_CMD);
/*add other module table here*/
/*end of the table*/
puTemp1->szFormat[0] = '\0';
/*malloc the memory for callback table of all modules*/
uCallbackSize = sizeof(cmd_callback_demod);
cmd_callback_table=(drvtest_cmd_callback*)mem_malloc(uCallbackSize);
if(!cmd_callback_table)
{
return DRVTEST_ERROR;
}
puTemp2 = cmd_callback_table;
/*demod callback table*/
memcpy(puTemp2, cmd_callback_demod, sizeof(cmd_callback_demod));
puTemp2 += sizeof(cmd_callback_demod) / sizeof(drvtest_cmd_callback);
/*add other module table here*/
return DRVTEST_OK;
}
}
CNXT_DRVTEST_STATUS cnxt_drvtest_get_cmd(u_int8 *pszCmd)
{
int i=0;
u_int8 *pCmdOrigin = pszCmd;
if(pszCmd == NULL)
{
return DRVTEST_ERROR;
}
while(i < MAX_COMMAND_INPUT_LENGTH)
{
extern int getcharQ(void);
*pszCmd = (u_int8)getcharQ();
if( *pszCmd == '\r' /*0x0D*/ ) /*carriage return*/
{
pszCmd++;
i++;
break;
}
if( *pszCmd==0x0A ) /*line feed*/
return DRVTEST_ERROR;
if( *pszCmd == '\b') /* Discard backspace and the previous char */
{
if(pCmdOrigin != pszCmd )
{
pszCmd--;
i--;
}
}
else
{
pszCmd++;
i++;
}
if(i == MAX_COMMAND_INPUT_LENGTH)
{
trace("DRVTEST: input too long!\n");
return DRVTEST_ERROR;
}
}
return DRVTEST_OK;
}
/****************************************************************************/
/* FUNCTION: cnxt_drvtest_get_cmd_name */
/* */
/* DESCRIPTION: get command name in an input command line */
/* INPUTS: pszStr - pointer to the start of the input command */
/* */
/* OUTPUTS: pszName - pointer to the string storing the name of the input */
/* command */
/* */
/* RETURNS: DRVTEST_OK -get name successfully */
/* DRVTEST_ERROR - get name failed */
/* */
/* NOTES: */
/* */
/* CONTEXT: Must be called from a non-interrupt context. */
/* */
/****************************************************************************/
CNXT_DRVTEST_STATUS cnxt_drvtest_get_cmd_name(u_int8 *pszStr, u_int8 *pszName)
{
u_int8 *p = pszStr;
u_int8 *pWordOrigin = pszName;
u_int8 uLength =0;
if(p == NULL || pWordOrigin == NULL)
{
return DRVTEST_ERROR;
}
// skip spaces
while (*p && *p <= ' ')
{
p++;
}
if (ISALPHA(p))
{
while (ISDIGITORALPHA(p))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -