2014-01-10 16:21:35 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Kaspar Schleiser <kaspar@schleiser.de>
|
2014-02-03 23:03:13 +01:00
|
|
|
* Copyright (C) 2013 Freie Universität Berlin
|
2014-01-10 16:21:35 +01:00
|
|
|
*
|
2014-07-31 19:45:27 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2014-01-10 16:21:35 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief shows how to set up own and use the system shell commands.
|
|
|
|
* By typing help in the serial console, all the supported commands
|
|
|
|
* are listed.
|
|
|
|
*
|
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
|
|
|
* @author Zakaria Kasmi <zkasmi@inf.fu-berlin.de>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2014-03-01 09:54:09 +01:00
|
|
|
|
|
|
|
#include "shell_commands.h"
|
|
|
|
#include "posix_io.h"
|
|
|
|
#include "shell.h"
|
|
|
|
#include "board_uart0.h"
|
2014-01-10 16:21:35 +01:00
|
|
|
|
|
|
|
#define SHELL_BUFSIZE (UART0_BUFSIZE)
|
|
|
|
|
2014-02-21 19:40:58 +01:00
|
|
|
static void print_teststart(int argc, char **argv)
|
2014-01-10 16:21:35 +01:00
|
|
|
{
|
2014-02-21 19:40:58 +01:00
|
|
|
(void) argc;
|
|
|
|
(void) argv;
|
2014-01-10 16:21:35 +01:00
|
|
|
printf("[TEST_START]\n");
|
|
|
|
}
|
|
|
|
|
2014-02-21 19:40:58 +01:00
|
|
|
static void print_testend(int argc, char **argv)
|
2014-01-10 16:21:35 +01:00
|
|
|
{
|
2014-02-21 19:40:58 +01:00
|
|
|
(void) argc;
|
|
|
|
(void) argv;
|
2014-01-10 16:21:35 +01:00
|
|
|
printf("[TEST_END]\n");
|
|
|
|
}
|
|
|
|
|
2014-02-21 19:40:58 +01:00
|
|
|
static void print_echo(int argc, char **argv)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
printf("“%s” ", argv[i]);
|
|
|
|
}
|
|
|
|
puts("");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int shell_readc(void)
|
2014-01-10 16:21:35 +01:00
|
|
|
{
|
2014-03-10 13:47:33 +01:00
|
|
|
char c;
|
2014-03-10 13:48:00 +01:00
|
|
|
int result = posix_read(uart0_handler_pid, &c, 1);
|
|
|
|
if (result != 1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2014-03-10 13:47:33 +01:00
|
|
|
return (unsigned char) c;
|
2014-01-10 16:21:35 +01:00
|
|
|
}
|
|
|
|
|
2014-02-21 19:40:58 +01:00
|
|
|
static void shell_putchar(int c)
|
2014-01-10 16:21:35 +01:00
|
|
|
{
|
|
|
|
putchar(c);
|
|
|
|
}
|
|
|
|
|
2014-02-21 19:40:58 +01:00
|
|
|
static const shell_command_t shell_commands[] = {
|
2014-01-10 16:21:35 +01:00
|
|
|
{ "start_test", "starts a test", print_teststart },
|
|
|
|
{ "end_test", "ends a test", print_testend },
|
2014-02-21 19:40:58 +01:00
|
|
|
{ "echo", "prints the input command", print_echo },
|
2014-01-10 16:21:35 +01:00
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("test_shell.\n");
|
|
|
|
|
|
|
|
board_uart0_init();
|
|
|
|
|
|
|
|
posix_open(uart0_handler_pid, 0);
|
|
|
|
|
|
|
|
/* define own shell commands */
|
|
|
|
shell_t shell;
|
2014-01-25 11:29:35 +01:00
|
|
|
shell_init(&shell, shell_commands, SHELL_BUFSIZE, shell_readc,
|
2014-01-10 16:21:35 +01:00
|
|
|
shell_putchar);
|
|
|
|
shell_run(&shell);
|
|
|
|
|
|
|
|
/* or use only system shell commands */
|
|
|
|
/*
|
|
|
|
shell_t sys_shell;
|
|
|
|
shell_init(&sys_shell, NULL, SHELL_BUFSIZE, shell_readc, shell_putchar);
|
|
|
|
shell_run(&sys_shell);
|
|
|
|
*/
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|