Command Line Interface

Add a Terminal Command

/* At terminal.cpp, add the following code at the taskEntry() function */
bool terminalTask::taskEntry()
{
	// ...
	CMD_HANDLER_FUNC(myCmdHandler);
	cp.addHandler(myCmdHandler,   "newcmd",  "This is help message. 'newcmd test' will display: 'OK'");
	// ...
	return true;
}

/* ----------------------------------------------
 * Your source file, such as "my_source.cpp"
 * We will add our command handler function here
 */
#include "command_handler.hpp"

CMD_HANDLER_FUNC(myCmdHandler)
{
	/* cmdParams is a str passed to you after user's command.
	 * If command was "newcmd test 123" then cmdParams will be "test 123".
	 *
	 * output is a CharDev class where the command came from, so
	 * we can use this to output a reply message.
	 * See "handlers.cpp" for more examples
	 */
	if (cmdParams == "test")
	{
		output.printf("OK!\n");
	}
	else
	{
		output.printf("ERROR for my command\n");
	}
	/* return false will display command's help to the user */
	return true; /* return true if command was successful */
}
Back to top