Some Telnet server enhancements:

- PETSCII sending support
- Option to customize shell prompt and banner
- Stop all running commands on shell close
- New 'exit' and 'quit' commands to close shell
This commit is contained in:
Oliver Schmidt 2011-04-16 21:10:22 +02:00
parent aa968309af
commit 831312e311
5 changed files with 78 additions and 10 deletions

View file

@ -77,6 +77,11 @@ shell_prompt(char *str)
str);
}
/*---------------------------------------------------------------------------*/
void
shell_exit(void)
{
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(serial_shell_process, ev, data)
{
PROCESS_BEGIN();

View file

@ -102,6 +102,12 @@ shell_prompt(char *str)
{
}
/*-----------------------------------------------------------------------------------*/
void
shell_exit(char *str)
{
ctk_window_close(&window);
}
/*-----------------------------------------------------------------------------------*/
PROCESS_THREAD(shell_gui_process, ev, data)
{
PROCESS_BEGIN();

View file

@ -54,6 +54,14 @@
#include <string.h>
#include <stdio.h>
#ifndef SHELL_CONF_PROMPT
#define SHELL_CONF_PROMPT "Contiki> "
#endif
#ifndef SHELL_CONF_BANNER
#define SHELL_CONF_BANNER "Contiki command shell"
#endif
LIST(commands);
int shell_event_input;
@ -77,10 +85,13 @@ PROCESS(shell_kill_process, "kill");
SHELL_COMMAND(kill_command, "kill", "kill <command>: stop a specific command",
&shell_kill_process);
PROCESS(shell_null_process, "null");
SHELL_COMMAND(null_command,
"null",
"null: discard input",
SHELL_COMMAND(null_command, "null", "null: discard input",
&shell_null_process);
PROCESS(shell_exit_process, "exit");
SHELL_COMMAND(exit_command, "exit", "exit: exit shell",
&shell_exit_process);
SHELL_COMMAND(quit_command, "quit", "quit: exit shell",
&shell_exit_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_null_process, ev, data)
{
@ -168,7 +179,16 @@ PROCESS_THREAD(help_command_process, ev, data)
c = c->next) {
shell_output_str(&help_command, c->description, "");
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_exit_process, ev, data)
{
PROCESS_BEGIN();
shell_exit();
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
@ -418,7 +438,7 @@ PROCESS_THREAD(shell_process, ev, data)
PROCESS_PAUSE();
while(1) {
shell_prompt("Contiki> ");
shell_prompt(SHELL_CONF_PROMPT);
PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
{
@ -483,6 +503,8 @@ shell_init(void)
shell_register_command(&killall_command);
shell_register_command(&kill_command);
shell_register_command(&null_command);
shell_register_command(&exit_command);
shell_register_command(&quit_command);
shell_event_input = process_alloc_event();
@ -536,15 +558,21 @@ shell_set_time(unsigned long seconds)
void
shell_start(void)
{
shell_output_str(NULL, "Contiki command shell", "");
shell_output_str(NULL, SHELL_CONF_BANNER, "");
shell_output_str(NULL, "Type '?' and return for help", "");
shell_prompt("Contiki> ");
shell_prompt(SHELL_CONF_PROMPT);
}
/*---------------------------------------------------------------------------*/
void
shell_stop(void)
{
killall();
}
/*---------------------------------------------------------------------------*/
void
shell_quit(void)
{
killall();
shell_stop();
process_exit(&shell_process);
process_exit(&shell_server_process);
}

View file

@ -119,11 +119,21 @@ void shell_start(void);
*/
void shell_input(char *commandline, int commandline_len);
/**
* \brief Stop the shell
*
* This function stops all running commands. It typically
* is called by a shell back-end to to indicate that the
* user has quit the shell.
*
*/
void shell_stop(void);
/**
* \brief Quit the shell
*
* This function is called by a shell back-end to indicate
* that the user has quit the shell.
* This function is called by a shell back-end to stop the
* shell processes.
*
*/
void shell_quit(void);
@ -171,6 +181,16 @@ void shell_prompt(char *prompt);
void shell_default_output(const char *data1, int size1,
const char *data2, int size2);
/**
* \brief Request shell exit
*
* This function is called by the shell to request exiting
* the current session. The shell back-end will later call
* shell_stop() when the session was successfully exited.
*
*/
void shell_exit(void);
/**
* @}
*/

View file

@ -110,6 +110,7 @@ buf_append(struct telnetd_buf *buf, const char *data, int len)
PRINTF("buf_append len %d (%d) '%.*s'\n", len, buf->ptr, len, data);
copylen = MIN(len, buf->size - buf->ptr);
memcpy(&buf->bufmem[buf->ptr], data, copylen);
petsciiconv_toascii(&buf->bufmem[buf->ptr], copylen);
buf->ptr += copylen;
return copylen;
@ -175,6 +176,12 @@ shell_default_output(const char *str1, int len1, const char *str2, int len2)
buf_append(&buf, "\r\n", 2);
}
/*---------------------------------------------------------------------------*/
void
shell_exit(void)
{
s.state = STATE_CLOSE;
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(telnetd_process, ev, data)
{
PROCESS_BEGIN();
@ -259,6 +266,7 @@ sendopt(u8_t option, u8_t value)
line[1] = option;
line[2] = value;
line[3] = 0;
petsciiconv_topetscii(line, 4);
buf_append(&buf, line, 4);
}
/*---------------------------------------------------------------------------*/
@ -354,6 +362,7 @@ telnetd_appcall(void *ts)
if(uip_closed() ||
uip_aborted() ||
uip_timedout()) {
shell_stop();
closed();
}
if(uip_acked()) {