给项目添加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!