新增shell命令动态注册接口
This commit is contained in:
parent
2e17a9ceb4
commit
2ef669be37
@ -124,5 +124,20 @@ int32_t set_clk_mode(clk_flag_e pseudo_flag);
|
||||
int arm_csu_dma_1D_transfer(uint64_t addrSrc, uint64_t addrDst, uint32_t dataLen);
|
||||
int arm_csu_wait_done(uint8_t tag);
|
||||
|
||||
/*
|
||||
函数名称:osp_insert_cmd
|
||||
函数入参:name : shell命令,长度不要超过11个字符
|
||||
函数入参:pfunc : 对应shell命令的回调函数
|
||||
函数入参:desc : 对应shell命令的描述
|
||||
函数入参:argnum : 对应shell命令的参数个数,小于等于6
|
||||
函数功能:动态注册shell命令
|
||||
return value:0:success -1:error
|
||||
说明:动态注册命令中的打印需使用USHELL_PRINT
|
||||
比如:USHELL_PRINT("arg1:%d arg2:%d arg3:%d\n", arg1, arg2, arg3);
|
||||
*/
|
||||
int32_t osp_insert_cmd(char *name, OSP_FUNCPTR pfunc, char *desc, uint32_t argnum);
|
||||
void osp_ushell_output(const char *fmt, ...);
|
||||
#define USHELL_PRINT(fmt, args...) osp_ushell_output(fmt "\n", ##args)
|
||||
|
||||
#endif /* __ARM_INTERFACE_H__ */
|
||||
|
||||
|
@ -28,4 +28,6 @@ typedef unsigned long int uint64_t;
|
||||
//typedef long long int int64_t;
|
||||
//typedef unsigned long long int uint64_t;
|
||||
|
||||
typedef uint64_t (*OSP_FUNCPTR)();
|
||||
|
||||
#endif
|
||||
|
@ -18,6 +18,7 @@ extern "C" {
|
||||
#define SPU_SHELL_MSG_DADA_LEN(x) (x->u16DataLen - OSP_SW_MSG_INFO_SIZE)
|
||||
#define SPU_SHELL_MSG_HEAD_TO_COMM(x) (char *)((uint64_t)x + OSP_SW_MSG_INFO_SIZE)
|
||||
#define SPU_SHELL_DADA_LEN(x) (x->u16DataLen)
|
||||
#define USHELL_PRINT(fmt, args...) osp_ushell_output(fmt "\n", ##args)
|
||||
|
||||
typedef struct tag_Osp_Ape_Msg_Head
|
||||
{
|
||||
@ -69,8 +70,7 @@ extern int32_t osp_shell_main();
|
||||
extern int32_t osp_execcmd(void);
|
||||
extern int32_t osp_getcmdarg(char *cmd);
|
||||
extern void osp_set_prompt();
|
||||
extern int32_t osp_insert_cmd(char *name, OSP_FUNCPTR pfunc);
|
||||
extern int32_t osp_insert_cmd_ext(char *name, OSP_FUNCPTR pfunc, char *desc, int32_t argnum);
|
||||
extern int32_t osp_insert_cmd(char *name, OSP_FUNCPTR pfunc, char *desc, uint32_t argnum);
|
||||
int32_t osp_shell_init(void);
|
||||
bool osp_is_ape_cmd(char *pCmd);
|
||||
void osp_get_ape_id(uint8_t ucApeid);
|
||||
@ -109,6 +109,8 @@ void osp_set_clk_mode(clk_flag_e pseudo_flag);*/
|
||||
void osp_show_swqueue_info();
|
||||
void osp_show_info_by_coreid(osp_sw_msg_info_t *pMsg);
|
||||
void osp_set_oam(uint8_t ucOam);
|
||||
void osp_ushell_output(const char *fmt, ...);
|
||||
void osp_ushell_test();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "osp.h"
|
||||
#include "ospShell.h"
|
||||
#include "ospDbg.h"
|
||||
@ -34,8 +34,6 @@ extern uint8_t g_ucPlatformMode; /*0: platform log日志写入文件 1: 网
|
||||
extern OSP_CMD_RTN ospCmdRtnTbl[];
|
||||
extern int32_t SHELL_CMD_NUM;
|
||||
|
||||
extern char *pShellBuf;
|
||||
|
||||
/*function prototype */
|
||||
extern void osp_set_prompt();
|
||||
|
||||
@ -972,56 +970,63 @@ void osp_shell_get_line()
|
||||
}
|
||||
}
|
||||
|
||||
int32_t osp_insert_cmd(char *name, OSP_FUNCPTR pfunc)
|
||||
int32_t osp_insert_cmd(char *name, OSP_FUNCPTR pfunc, char *desc, uint32_t argnum)
|
||||
{
|
||||
OSP_CMD_RTN *tlb;
|
||||
int32_t num;
|
||||
OSP_CMD_RTN *tlb = NULL;
|
||||
uint8_t num = 0;
|
||||
uint8_t i = 0;
|
||||
uint8_t u8str_len = 0;
|
||||
|
||||
if ((name == NULL) || pfunc == NULL)
|
||||
if ((NULL == name) || NULL == pfunc || NULL == desc)
|
||||
{
|
||||
return -1;
|
||||
|
||||
UCP_PRINT_ERROR("osp_insert_cmd_ext name:%p pfunc:%p desc:%p", name, pfunc, desc);
|
||||
return OSP_ERROR;
|
||||
}
|
||||
|
||||
if (argnum > 6)
|
||||
{
|
||||
UCP_PRINT_ERROR("osp_insert_cmd argnum:%u beyond 6", argnum);
|
||||
return OSP_ERROR;
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX_EXT_CMD_NUM; i++)
|
||||
{
|
||||
if (strcmp(ospCmdRtnTblExt[i].cmd, name) == 0)
|
||||
{
|
||||
UCP_PRINT_ERROR("osp_insert_cmd i:%u cmd:%s has exist name:%s", i, ospCmdRtnTblExt[i].cmd, name);
|
||||
return OSP_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
osp_sem_take(ospCmdInsertSem, -1);
|
||||
|
||||
tlb = ospCmdRtnTblExt;
|
||||
num = SHELL_CMD_NUM_EXT;
|
||||
|
||||
memcpy(tlb[num].cmd, name, strlen(name) + 1);
|
||||
tlb[num].wrapper = (OSP_FUNCPTR)osp_shell_wrapper;
|
||||
tlb[num].routine = pfunc;
|
||||
|
||||
SHELL_CMD_NUM_EXT++;
|
||||
osp_sem_give(ospCmdInsertSem);
|
||||
return 0;
|
||||
}
|
||||
int32_t osp_insert_cmd_ext(char *name, OSP_FUNCPTR pfunc, char *desc, int32_t argnum)
|
||||
{
|
||||
OSP_CMD_RTN *tlb;
|
||||
int32_t num;
|
||||
|
||||
if ((name == NULL) || pfunc == NULL)
|
||||
if(num >= MAX_EXT_CMD_NUM)
|
||||
{
|
||||
return -1;
|
||||
|
||||
UCP_PRINT_ERROR("osp_insert_cmd num:%u beyond MAX_EXT_CMD_NUM:%d\r\n", num, MAX_EXT_CMD_NUM);
|
||||
return OSP_ERROR;
|
||||
}
|
||||
|
||||
u8str_len = strlen(name);
|
||||
if(u8str_len > 12)
|
||||
{
|
||||
UCP_PRINT_ERROR("osp_insert_cmd u8str_len:%u beyond 12", u8str_len);
|
||||
return OSP_ERROR;
|
||||
}
|
||||
tlb = ospCmdRtnTblExt;
|
||||
num = SHELL_CMD_NUM_EXT;
|
||||
|
||||
memcpy(tlb[num].cmd, name, strlen(name) + 1);
|
||||
memcpy(tlb[num].descption, desc, strlen(desc) + 1);
|
||||
|
||||
tlb[num].wrapper = (OSP_FUNCPTR)osp_ape_shell_wrapper;
|
||||
//tlb[num].routine = pfunc;
|
||||
tlb[num].argnum = argnum;
|
||||
|
||||
UCP_PRINT_SHELL("osp_insert_cmd_ext cmd:%s num:%u descption:%s desc:%s argnum:%u",
|
||||
tlb[num].cmd,num, tlb[num].descption, desc, tlb[num].argnum);
|
||||
tlb[num].wrapper = (OSP_FUNCPTR)osp_shell_wrapper;
|
||||
tlb[num].routine = pfunc;
|
||||
tlb[num].argnum = argnum;
|
||||
|
||||
SHELL_CMD_NUM_EXT++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
osp_sem_give(ospCmdInsertSem);
|
||||
|
||||
return OSP_OK;
|
||||
}
|
||||
|
||||
int32_t osp_shell_init(void)
|
||||
{
|
||||
@ -1038,9 +1043,48 @@ int32_t osp_shell_init(void)
|
||||
|
||||
/*配置文件读取server ip ,port*/
|
||||
osp_server_get();
|
||||
|
||||
osp_insert_cmd("test", (OSP_FUNCPTR)osp_ushell_test, "test", 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void osp_ushell_output(const char *fmt, ...)
|
||||
{
|
||||
uint32_t u32str_len = 0;
|
||||
char acstr[256] = {0};
|
||||
va_list st_va_list;
|
||||
|
||||
if(NULL == fmt)
|
||||
{
|
||||
UCP_PRINT_ERROR("osp_ushell_output fmt is null");
|
||||
return;
|
||||
}
|
||||
|
||||
va_start(st_va_list, fmt);
|
||||
u32str_len = vsprintf((char *)acstr, fmt, st_va_list);
|
||||
va_end(st_va_list);
|
||||
|
||||
osp_net_shell_out(acstr, u32str_len);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void osp_ushell_test()
|
||||
{
|
||||
OSP_RTCTIME osptime;
|
||||
|
||||
osp_get_rtc_time(&osptime);
|
||||
sprintf((char *)g_time_now, \
|
||||
"[%04d-%02d-%02d-%02d:%02d:%02d:%02d]", \
|
||||
osptime.year, osptime.month, osptime.day, \
|
||||
osptime.hour, osptime.minute, osptime.second, osptime.usecond);
|
||||
|
||||
USHELL_PRINT("%s", g_time_now);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool osp_is_ape_cmd(char *pCmd)
|
||||
{
|
||||
if(NULL == pCmd)
|
||||
|
Loading…
x
Reference in New Issue
Block a user