向vivi加入命令 - xgc94418297的日志 [转载]

嵌入式系统移植 2009-05-19 09:47:43

vivilib/command.c中添加自己的命令

核心数据结构user_command

typedef struct user_command {

    const char *name;                          //命令名

    void (*cmdfunc)(int argc, const char **);  //命令执行函数

    struct user_command *next_cmd;             //下一个命令

    const char *helpstr;                       //帮助

} user_command_t;

 

添加自定义命令的步骤-1

首先构造一个user_command的实例,比如:

user_command_t mytest_cmd = {

    “mytest",

    command_mytest,

    NULL,

    “mytest [{cmds}] /t/t/t– Add my command for test?"

};

 

添加自定义命令的步骤-2

然后实现命令的真正函数command_test

void command_mytest(int argc, const char **argv)

{

if(argc == 2)

  if((strncmp(argv[1],“help”,strlen(argv[1]))) ==0)

    {

       printk(“myTest Command Help/n”);

       return;

    }

printk(“myTest Command exec/n”);  //这用printk输出信息

return;

}

 

在程序的后面 extern user_command_t ……. 之前添加,应该先写函数,再写结构体

 

添加自定义命令的步骤-3

将命令加入到系统

command.c中的

int init_builtin_cmds(void)函数的最后加入add_command(&mytest_cmd);

 这个函数在程序的最后面

生成vivi镜像

make clean

make menuconfig

make

烧录:load flash vivi x

测试:进入vivi,执行命令:mytest

 

执行help,在命令列表里就能看到mytest这个命令

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值