Hello everyone
I’m a RIOT new user and i’m teaching myself into building a custom module.
I was wondering if there was a way to include my custom shell commands (module related commands)
during auto-init with no involvment of the application using the module.
thanks folks
Hi Stephane,
in order to register your own commands (which is then accessible through the
shell after auto_init) you have to do three things:
-
Add a handler for your shell command into a file under the directory
sys/shell/commands. By convention you would call the file sc_.c
(e.g. the command handler file for ps is called sc_ps.c).
-
Add two ifdefs in the file sys/shell/commands/shell_commands.c .
One ifdef at the top of the file declaring your handler function from the previous step
as extern. The ifdef would have the form:
#ifdef MODULE_
extern int (int argc, char **argv);
#endif
At the bottom of the file you need to add a second ifdef in the form:
#ifdef MODULE_
{"", “”, },
#endif
- The last thing you need to do is to change the Makefile in sys/shell/commands
Add a statement in the form:
ifneq (,$(filter ,$(USEMODULE)))
SRC += sc_.c
endif
After this your commands will be available in the shell if you put both
USEMODULE += shell
and
USEMODULE +=
into your application Makefile.
Also: if you need some inspiration on how to write the shell handler take a look at
the one for the mersenne module: sys/shell/commands/sc_mersenne.c
I hope this helps.
Best,
Philipp
2015-07-01 20:18 GMT+02:00 Stephane Kamga <kamga.stephane@gmail.com>:
Oh great
I thought i did not have to mess with the schell_commands.c file.
Thanks for the quick answer
Hi Stephane,
in order to register your own commands (which is then accessible through the
shell after auto_init) you have to do three things:
-
Add a handler for your shell command into a file under the directory
sys/shell/commands. By convention you would call the file sc_.c
(e.g. the command handler file for ps is called sc_ps.c).
-
Add two ifdefs in the file sys/shell/commands/shell_commands.c .
One ifdef at the top of the file declaring your handler function from the previous step
as extern. The ifdef would have the form:
#ifdef MODULE_
extern int (int argc, char **argv);
#endif
At the bottom of the file you need to add a second ifdef in the form:
#ifdef MODULE_
{"", “”, },
#endif
- The last thing you need to do is to change the Makefile in sys/shell/commands
Add a statement in the form:
ifneq (,$(filter ,$(USEMODULE)))
SRC += sc_.c
endif
After this your commands will be available in the shell if you put both
USEMODULE += shell
and
USEMODULE +=
into your application Makefile.
Also: if you need some inspiration on how to write the shell handler take a look at
the one for the mersenne module: sys/shell/commands/sc_mersenne.c
I hope this helps.
Best,
Philipp
2015-07-01 20:18 GMT+02:00 Stephane Kamga <kamga.stephane@gmail.com>: