Contiki-NG中shell使用

给项目添加shell

只需要在项目的Makefile里添加如下代码即可:

MODULES += $(CONTIKI_NG_SERVICES_DIR)/shell

$(CONTIKI_NG_SERVICES_DIR)所指的目录就是contiki-ng/os/services

通过串口和板子相连就可以使用shell了

#0012:4b00:192e:4337>

使用help命令,可以看到shell提供的所有指令帮助信息

#0012.4b00.192e.4337> help
Available commands:
'> help': Shows this help
'> reboot': Reboot the board by watchdog_reboot()
'> log module level': Sets log level (0--4) for a given module (or "all"). For m
odule "mac", level 4 also enables per-slot logging.
'> mac-addr': Shows the node's MAC address
'> ip-addr': Shows all IPv6 addresses
'> ip-nbr': Shows all IPv6 neighbors
'> ping addr': Pings the IPv6 address 'addr'
'> routes': Shows the route entries
'> rpl-set-root 0/1 [prefix]': Sets node as root (1) or not (0). A /64 prefix ca
n be optionally specified.                                                      
'> rpl-local-repair': Triggers a RPL local repair                               
'> rpl-refresh-routes': Refreshes all routes through a DTSN increment           
'> rpl-status': Shows a summary of the current RPL state                        
'> rpl-nbr': Shows the RPL neighbor table                                       
'> rpl-global-repair': Triggers a RPL global repair 

可以试一下其中的命令,比如:

#0012.4b00.192e.4337> ip-addr                                                   
Node IPv6 addresses:                                                            
-- fd00::212:4b00:192e:4337                                                     
-- fe80::212:4b00:192e:4337 

定制shell命令

Contiki-ng/os/services目录里的shell-commands.c文件中,找到:

const struct shell_command_t builtin_shell_commands[]

按照代码里现有的命令的样子,定制自己的shell命令,比如添加如下代码:

{ "config",      cmd_hello,     "'> hello': Just say hello." },

然后,添加命令的实现代码,在同一个文件中:

static
PT_THREAD(cmd_hello(struct pt *pt, shell_output_func output, char *args))
{
  PT_BEGIN(pt);

  SHELL_OUTPUT(output, "Hello, world!\n");

  PT_END(pt);
}

重新编译即可。

#0012.4b00.192e.4337> hello                                                
Hello, world!
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 官网 中文版本 好的网站 Content-type: text/htmlBASH Section: User ...
    不排版阅读 4,433评论 0 5
  • 第 2 章 SHELL 基础知识2.1 shell脚本我们在上面简单介绍了一下什么是shell脚本,现在我们来进一...
    LiWei_9e4b阅读 1,589评论 0 0
  • 2014-05-26 21:21:38构建Linux 编译Linux BeagleBone Black 14年即将...
    外星间谍阅读 3,473评论 0 9
  • 作者简介:洪仲清临床心理师 台湾大学心理学系、心理研究所所临床组毕业,持有临床心理师合格证书。曾任心理治疗所所长5...
    言西小熊阅读 820评论 0 0
  • 90天打卡累计天数:56/90 宣言:不带着情绪和孩子沟通 孩子第二个30天目标:每周三次运动半小时 每天朗读 家...
    彭春艳_282877阅读 123评论 0 0