Contiki 3.x
|
The Contiki shell provides both interactive and batch processing for Contiki. More...
Data Structures | |
struct | shell_command |
Holds a information about a shell command. More... | |
struct | shell_input |
Structure for shell input data. More... | |
Variables | |
int | shell_event_input |
The event number for shell input data. More... | |
Shell back-end API | |
The shell back-end API contains functions that are used by shell back-ends. | |
void | shell_input (char *commandline, int commandline_len) |
Send a line of input to the shell. More... | |
void | shell_init (void) |
Initialize the shell. More... | |
void | shell_start (void) |
Start the shell. More... | |
void | shell_stop (void) |
Stop the shell. More... | |
void | shell_quit (void) |
Quit the shell. More... | |
Shell back-end callback functions | |
These callback functions are called from the shell to the shell back-end. The shell back-end must implement all back-end callback functions. | |
void | shell_default_output (const char *data1, int size1, const char *data2, int size2) |
Print a line of output from the shell. More... | |
void | shell_prompt (char *prompt) |
Print a prompt. More... | |
void | shell_exit (void) |
Request shell exit. More... | |
Shell command API | |
These functions are used by shell commands. | |
int | shell_start_command (char *commandline, int commandline_len, struct shell_command *child, struct process **started_process) |
Start a shell command from another shell command. More... | |
void | shell_output_str (struct shell_command *c, char *str1, const char *str2) |
Output strings from a shell command. More... | |
void | shell_output (struct shell_command *c, void *data1, int size1, const void *data2, int size2) |
Output data from a shell command. More... | |
void | shell_unregister_command (struct shell_command *c) |
Unregister a previously registered shell command. More... | |
void | shell_register_command (struct shell_command *c) |
Register a command with the shell. More... | |
#define | SHELL_COMMAND(name, command, description, process) |
Define a shell command. More... | |
Shell convenience functions | |
These functions assist shell commands in parsing command lines | |
unsigned long | shell_strtolong (const char *str, const char **retstr) |
Convert a string to a number. More... | |
unsigned long | shell_time (void) |
void | shell_set_time (unsigned long seconds) |
Shell variables, definitions, and return values | |
enum | shell_retval |
int | shell_event_input |
The event number for shell input data. More... | |
The Contiki shell provides both interactive and batch processing for Contiki.
The shell consists of two parts: the shell application and a shell back-end. The shell application contains all the logic of the shell, whereas the shell back-end provides I/O for the shell. Examples of shell back-ends are a serial I/O shell back-end, that allows the shell to operate over a serial connection, and a telnet server back-end, that allows the shell to operate over a TCP/IP telnet connection.
#define SHELL_COMMAND | ( | name, | |
command, | |||
description, | |||
process | |||
) |
Define a shell command.
name | The variable name of the shell command definition |
command | A string with the name of the shell command |
description | A string that contains a one-line description of the command |
process | A pointer to the process that implements the shell command This macro defines and declares a shell command (struct shell_command). This is used with the shell_register_command() function to register the command with the shell. |
void shell_default_output | ( | const char * | data1, |
int | size1, | ||
const char * | data2, | ||
int | size2 | ||
) |
Print a line of output from the shell.
data1 | A pointer to the first half of the data |
size1 | The size of the first half of the data |
data2 | A pointer to the second half of the data |
size2 | The size of the second half of the data |
This function is called by a shell command to output data. The output is split into two halves to make it easier for shell commands to output data that contains a static part (such as a static string) and a dynamic part (a dynamically generated string).
Definition at line 58 of file serial-shell.c.
References NULL.
Referenced by shell_output(), and shell_output_str().
void shell_exit | ( | void | ) |
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.
Definition at line 89 of file serial-shell.c.
void shell_init | ( | void | ) |
Initialize the shell.
This function initializes the shell. It typically is called from the shell back-end.
Definition at line 501 of file shell.c.
References list_init(), NULL, process_alloc_event(), process_start(), shell_event_input, and shell_register_command().
void shell_input | ( | char * | commandline, |
int | commandline_len | ||
) |
Send a line of input to the shell.
commandline | A pointer to a string that contains the command line |
commandline_len | Length of the command line, in bytes This function is called by a shell back-end to send an incoming command line to the shell. The shell parses the command line and starts any commands found in the command line. |
Definition at line 359 of file shell.c.
References process_exit(), process_is_running(), process_post_synch(), and shell_event_input.
void shell_output | ( | struct shell_command * | c, |
void * | data1, | ||
int | size1, | ||
const void * | data2, | ||
int | size2 | ||
) |
Output data from a shell command.
c | The command that outputs data |
data1 | A pointer to the first half of the data |
size1 | The size of the first half of the data |
data2 | A pointer to the second half of the data |
size2 | The size of the second half of the data This function is called by a shell command to output data. The output is split into two halves to make it easier for shell commands to output data that contains a static part (such as a static string) and a dynamic part (a dynamically generated string). |
Definition at line 395 of file shell.c.
References NULL, and shell_default_output().
void shell_output_str | ( | struct shell_command * | c, |
char * | str1, | ||
const char * | str2 | ||
) |
Output strings from a shell command.
c | The command that outputs data |
str1 | A pointer to the first half of the string |
str2 | A pointer to the second half of the string This function is called by a shell command to output a string. Internally, the function uses the shell_output() function to output the data. The output is split into two halves to make it easier for shell commands to output data that contains a static part (such as a static string) and a dynamic part (a dynamically generated string). |
Definition at line 383 of file shell.c.
References NULL, and shell_default_output().
Referenced by shell_start().
void shell_prompt | ( | char * | prompt | ) |
Print a prompt.
prompt | A suggested prompt This function is called by the shell to print a prompt. The shell back-end may show the suggested prompt, or another prompt. |
Definition at line 82 of file serial-shell.c.
References linkaddr_node_addr.
Referenced by shell_start().
void shell_quit | ( | void | ) |
Quit the shell.
This function is called by a shell back-end to stop the shell processes.
Definition at line 576 of file shell.c.
References process_exit(), and shell_stop().
void shell_register_command | ( | struct shell_command * | c | ) |
Register a command with the shell.
c | A pointer to a shell command structure, defined with SHELL_COMMAND() This function registers a shell command with the shell. After becoming registered, the shell command will appear in the list of available shell commands and is possible to invoke by a user. The shell command must have been defined with the SHELL_COMMAND() macro. |
Definition at line 413 of file shell.c.
References list_add(), list_head(), list_insert(), list_push(), and NULL.
Referenced by shell_init().
void shell_start | ( | void | ) |
Start the shell.
This function starts the shell and prints out the shell prompt. It typically is called by the shell back-end to start a new shell session.
Definition at line 562 of file shell.c.
References NULL, shell_output_str(), and shell_prompt().
int shell_start_command | ( | char * | commandline, |
int | commandline_len, | ||
struct shell_command * | child, | ||
struct process ** | started_process | ||
) |
Start a shell command from another shell command.
commandline | A pointer to a string that contains the command line |
commandline_len | Length of the command line, in bytes |
child | A pointer to the shell command that starts the command |
started_process | A pointer to a shell command pointer that will be filled in with a pointer to the started command structure |
A | shell_retval indicating if the command was started as a foreground or a background process This function starts a command, or a set of commands. The function is called by a shell command to start other shell commands. |
Definition at line 308 of file shell.c.
References NULL.
void shell_stop | ( | void | ) |
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.
Definition at line 570 of file shell.c.
Referenced by shell_quit().
unsigned long shell_strtolong | ( | const char * | str, |
const char ** | retstr | ||
) |
Convert a string to a number.
str | The input string |
retstr | A pointer to a pointer to a string, is filled in with a pointer to the data after the number in the input string |
The | converted number This function converts a string to a number. The function returns the converted number and a pointer to the data that follows the number in the input string. |
Definition at line 521 of file shell.c.
References NULL.
void shell_unregister_command | ( | struct shell_command * | c | ) |
Unregister a previously registered shell command.
c | A pointer to a shell command structure This function unregisters a shell command that has previously been registered with eht shell_register_command() function. |
Definition at line 407 of file shell.c.
References list_remove().
int shell_event_input |
The event number for shell input data.
The shell sends data as Contiki events to shell command processes. This variable contains the number of the Contiki event.
Definition at line 70 of file shell.c.
Referenced by shell_init(), and shell_input().
int shell_event_input |
The event number for shell input data.
The shell sends data as Contiki events to shell command processes. This variable contains the number of the Contiki event.
Definition at line 70 of file shell.c.
Referenced by shell_init(), and shell_input().