semf
esh

General

The embedded shell (esh) is a shell like environment emulated on top of UART. esh can be used to create simple text-based user interfaces (TUI).

Features

  • custom commands
  • command parameters
  • tab autocompletion
  • echoing
  • command history
  • C-like execution environment

Example

#include <semf/hardwareabstraction/stm32f1/stm32f1gpio.h>
#include <semf/hardwareabstraction/stm32f1/stm32f1uart.h>
#include "main.h"
#include <cstdlib>
extern UART_HandleTypeDef huart1;
static semf::Stm32F1Gpio led(User_LED_GPIO_Port, User_LED_Pin);
static semf::Stm32F1Uart eshUart(huart1);
void ledctl([[maybe_unused]] int argc, char** argv, [[maybe_unused]] semf::esh::Printer& out, int& retCode)
{
int v = atoi(argv[1]);
if (v)
led.set();
else
led.reset();
retCode = 0;
}
extern "C" void cppMain()
{
static char lineBuffer[32];
static char historyBuffer[5 * sizeof(lineBuffer)];
static char* argv[sizeof(lineBuffer) / 2];
lineBuffer,
sizeof(lineBuffer),
argv,
sizeof(lineBuffer) / 2,
historyBuffer,
5,
true,
"> ",
});
static semf::esh::Command ledctlCmd("ledctl", "help of ledctl", ledctlCb, esh);
esh.start();
while (true)
esh.loop();
}
StaticSlot for lightweight signal/slot implementation. This StaticSlot ist for connecting a signal to...
Definition: staticslot.h:27
Wrapper class for shell command. The user has to create object of this class for adding their functio...
Definition: command.h:28
Class for string related UART communication. Using this class outside of an esh-context can make sens...
Definition: printer.h:25
This class manages a semf's embedded shell (esh) operating on a single UART. The esh can be used for ...
Definition: shell.h:34
Configuarion parameters of the shell.
Definition: shell.h:40

This example is based on a STM32F1 chip and controls the user LED with the command ledctl. The callback function gets passed the typical parameters argc and argv which contain the parameters. The Printer out represents stdout and can be used to write to the user of the esh. The reference retCode is an out parameter for writing the return code to. The esh expects that once the callback has returned, the command execution will be complete.