A tiny and flexible shell implementation to be used on embedded devices.
Strobel, Stefan | Friedrich Lütze GmbH fdb07f12c7 Added superuser flag to auth user. | 9 mesiacov pred | |
---|---|---|
.vscode | 9 mesiacov pred | |
api | 9 mesiacov pred | |
cfg | 3 rokov pred | |
doc | 9 mesiacov pred | |
example | 9 mesiacov pred | |
src | 9 mesiacov pred | |
test | 9 mesiacov pred | |
.gitignore | 5 rokov pred | |
LICENSE | 4 rokov pred | |
README.md | 1 rok pred | |
makefile | 9 mesiacov pred |
A tiny and flexible shell implementation to be used on embedded devices.
The name shellmatta
is the combination of shell
and shimatta
.
What the hell is shimatta
you might ask.
...well if you really wanna know you might reach out to these nerds that are running domains like shimatta.net or shimatta.de.
Do not pretend i didn't warn you.
The intention is to enable a software project of nearly any size to have a runtime command line interface to simplify debugging or configuration/calibration of any kind of device.
The shellmatta
is designed to fit in most tiny microcontroller.
It is based on a simple character based interface and can work with for example network sockets or simple uarts. Some features are removable at build time to save ressources on really tiny platforms.
The shellmatta
piled up some features over time:
Besides this readme most documentation is integrated directly in the sourcecode as doxygen parsable comments.
To build the doxygen documentation just run make doc
.
The html and latex documentation will be exported to output/doc
The basic integration into a softwareproject is quite easy.
src
to your buildapi/shellmatta.h
fileCode example:
#include "shellmatta.h"
#include <unistd.h>
shellmatta_retCode_t writeFct(const char* data, uint32_t length)
{
write(1, data, length);
return SHELLMATTA_OK;
}
static shellmatta_retCode_t exampleCmdFct(shellmatta_handle_t handle, const char *arguments, uint32_t length)
{
shellmatta_retCode_t ret;
char option;
static const shellmatta_opt_long_t options[] =
{
{"version", 'v', SHELLMATTA_OPT_ARG_NONE},
{NULL, '\0', SHELLMATTA_OPT_ARG_NONE}
};
ret = shellmatta_opt_long(handle, options, &option, NULL, NULL);
while(SHELLMATTA_OK == ret)
{
switch(option)
{
case 'v':
shellmatta_printf(handle, "This should represent the version of this command");
break;
default:
shellmatta_printf(handle, "Unknown option: %c\r\n", option);
break;
}
ret = shellmatta_opt_long(handle, options, &option, NULL, NULL);
}
(void)arguments;
(void)length;
return SHELLMATTA_OK;
}
shellmatta_cmd_t exampleCmd = { "example", /**< command name */
"e", /**< command alias */
"example command", /**< command help */
"example [options]\n" /**< command usage text */
"\t-v, --version - print the version of the command",
exampleCmdFct, /**< command function */
NULL}; /**< intenally used */
int main(void)
{
static char buffer[1024]; /**< memory for inptu buffer */
static char historyBuffer[4096]; /**< memory for history buffer */
static shellmatta_instance_t instance; /**< instance variable */
shellmatta_handle_t handle; /**< handle used for accessing */
/** -# initialize the shellmatta instance */
shellmatta_doInit( &instance,
&handle,
buffer,
sizeof(buffer),
historyBuffer,
sizeof(historyBuffer),
"shellmatta->", /**< prompt text */
NULL, /**< optional static command list */
writeFct); /**< write function */
/** -# add the command - one command can only be added to one instance */
shellmatta_addCmd(handle, &exampleCmd);
/** -# ready to put some data in there */
shellmatta_processData(handle, "example --version\r", 18u);
return 0;
}
There are some defines you can use to change the behaviour of the shellmatta:
Define | Description |
---|---|
SHELLMATTA_STRIP_PRINTF | removes stdio dependencies to reduce footprint |
SHELLMATTA_HELP_COMMAND | string to overwrite the help command name |
SHELLMATTA_HELP_ALIAS | string to overwrite the help command alias |
SHELLMATTA_HELP_HELP_TEXT | string to overwrite the help command help |
SHELLMATTA_HELP_USAGE_TEXT | string to overwrite the help command usage |
SHELLMATTA_AUTHENTICATION | if defined this enables the authentication |
There is a quite confusing example in this repo to show and test some features.
To build it just rum make example
.
The binary will be built to output/example/example
It requires a serial device as parameter to run e.g. /dev/tty0
To be able to play around a bit you can create a local serial loopback using socat.
socat -d -d pty,raw,echo=0 pty,raw,echo=0
This will create two serial devices which are connected with a loopback. The device numbers in this example might change on your system.
You can use one of them starting the example e.g.
./output/example/example /dev/pts2
And use the other one to connect using the terminal tool of your choice e.g.
minicom -D /dev/pts3
There are some tests implemented using catch2 and the function fake framework.
To run the tests just do:
make test
To be able to build the coverage report you need an installation of (gcovr)[https://pypi.org/project/gcovr].