Contiki 3.x
shell.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 /**
34  * \file
35  * Main header file for the Contiki shell
36  * \author
37  * Adam Dunkels <adam@sics.se>
38  */
39 
40 /** \addtogroup apps
41  * @{ */
42 
43 /**
44  * \defgroup shell The Contiki shell
45  * @{
46  *
47  * The Contiki shell provides both interactive and batch processing
48  * for Contiki.
49  *
50  * The shell consists of two parts: the shell application and a shell
51  * back-end. The shell application contains all the logic of the
52  * shell, whereas the shell back-end provides I/O for the
53  * shell. Examples of shell back-ends are a serial I/O shell back-end,
54  * that allows the shell to operate over a serial connection, and a
55  * telnet server back-end, that allows the shell to operate over a
56  * TCP/IP telnet connection.
57  *
58  */
59 
60 #ifndef SHELL_H_
61 #define SHELL_H_
62 
63 #include "sys/process.h"
64 
65 /**
66  * \brief Holds a information about a shell command
67  *
68  * This structure contains information about a shell
69  * command. It is an opaque structure with no user-visible
70  * elements.
71  *
72  */
73 struct shell_command {
74  struct shell_command *next;
75  char *command;
76  char *description;
77  struct process *process;
78  struct shell_command *child;
79 };
80 
81 /**
82  * \name Shell back-end API
83  *
84  * The shell back-end API contains functions that are used
85  * by shell back-ends.
86  * @{
87  */
88 
89 /**
90  * \brief Initialize the shell.
91  *
92  * This function initializes the shell. It typically is
93  * called from the shell back-end.
94  *
95  */
96 void shell_init(void);
97 
98 /**
99  * \brief Start the shell.
100  *
101  * This function starts the shell and prints out the shell
102  * prompt. It typically is called by the shell back-end to
103  * start a new shell session.
104  *
105  */
106 void shell_start(void);
107 
108 /**
109  * \brief Send a line of input to the shell
110  * \param commandline A pointer to a string that contains the command line
111  * \param commandline_len Length of the command line, in bytes
112  *
113  * This function is called by a shell back-end to send an
114  * incoming command line to the shell. The shell parses
115  * the command line and starts any commands found in the
116  * command line.
117  *
118  */
119 void shell_input(char *commandline, int commandline_len);
120 
121 /**
122  * \brief Stop the shell
123  *
124  * This function stops all running commands. It typically
125  * is called by a shell back-end to to indicate that the
126  * user has quit the shell.
127  *
128  */
129 void shell_stop(void);
130 
131 /**
132  * \brief Quit the shell
133  *
134  * This function is called by a shell back-end to stop the
135  * shell processes.
136  *
137  */
138 void shell_quit(void);
139 
140 /**
141  * @}
142  */
143 
144 /**
145  * \name Shell back-end callback functions
146  *
147  * These callback functions are called from the shell to
148  * the shell back-end. The shell back-end must implement
149  * all back-end callback functions.
150  * @{
151  */
152 
153 
154 /**
155  * \brief Print a prompt
156  * \param prompt A suggested prompt
157  *
158  * This function is called by the shell to print a
159  * prompt. The shell back-end may show the suggested
160  * prompt, or another prompt.
161  *
162  */
163 void shell_prompt(char *prompt);
164 
165 /**
166  * \brief Print a line of output from the shell
167  * \param data1 A pointer to the first half of the data
168  * \param size1 The size of the first half of the data
169  * \param data2 A pointer to the second half of the data
170  * \param size2 The size of the second half of the data
171  *
172  *
173  * This function is called by a shell command to output
174  * data. The output is split into two halves to make it
175  * easier for shell commands to output data that contains
176  * a static part (such as a static string) and a dynamic
177  * part (a dynamically generated string).
178  *
179  */
180 void shell_default_output(const char *data1, int size1,
181  const char *data2, int size2);
182 
183 /**
184  * \brief Request shell exit
185  *
186  * This function is called by the shell to request exiting
187  * the current session. The shell back-end will later call
188  * shell_stop() when the session was successfully exited.
189  *
190  */
191 void shell_exit(void);
192 
193 /**
194  * @}
195  */
196 
197 /**
198  * \name Shell command API
199  *
200  * These functions are used by shell commands.
201  * @{
202  */
203 
204 
205 /**
206  * \brief Define a shell command
207  * \param name The variable name of the shell command definition
208  * \param command A string with the name of the shell command
209  * \param description A string that contains a one-line description of the command
210  * \param process A pointer to the process that implements the shell command
211  *
212  * This macro defines and declares a shell command (struct
213  * shell_command). This is used with the
214  * shell_register_command() function to register the
215  * command with the shell.
216  *
217  * \hideinitializer
218  */
219 #define SHELL_COMMAND(name, command, description, process) \
220 static struct shell_command name = { NULL, command, \
221  description, process }
222 
223 
224 /**
225  * \brief Output data from a shell command
226  * \param c The command that outputs data
227  * \param data1 A pointer to the first half of the data
228  * \param size1 The size of the first half of the data
229  * \param data2 A pointer to the second half of the data
230  * \param size2 The size of the second half of the data
231  *
232  * This function is called by a shell command to output
233  * data. The output is split into two halves to make it
234  * easier for shell commands to output data that contains
235  * a static part (such as a static string) and a dynamic
236  * part (a dynamically generated string).
237  *
238  */
239 void shell_output(struct shell_command *c,
240  void *data1, int size1,
241  const void *data2, int size2);
242 /**
243  * \brief Output strings from a shell command
244  * \param c The command that outputs data
245  * \param str1 A pointer to the first half of the string
246  * \param str2 A pointer to the second half of the string
247  *
248  * This function is called by a shell command to output a
249  * string. Internally, the function uses the
250  * shell_output() function to output the data. The output
251  * is split into two halves to make it easier for shell
252  * commands to output data that contains a static part
253  * (such as a static string) and a dynamic part (a
254  * dynamically generated string).
255  *
256  */
257 void shell_output_str(struct shell_command *c,
258  char *str1, const char *str2);
259 
260 /**
261  * \brief Register a command with the shell
262  * \param c A pointer to a shell command structure, defined with SHELL_COMMAND()
263  *
264  * This function registers a shell command with the
265  * shell. After becoming registered, the shell command
266  * will appear in the list of available shell commands and
267  * is possible to invoke by a user. The shell command must
268  * have been defined with the SHELL_COMMAND() macro.
269  *
270  */
271 void shell_register_command(struct shell_command *c);
272 
273 /**
274  * \brief Unregister a previously registered shell command
275  * \param c A pointer to a shell command structure
276  *
277  * This function unregisters a shell command that has
278  * previously been registered with eht
279  * shell_register_command() function.
280  *
281  */
283 
284 /**
285  * \brief Start a shell command from another shell command
286  * \param commandline A pointer to a string that contains the command line
287  * \param commandline_len Length of the command line, in bytes
288  * \param child A pointer to the shell command that starts the command
289  * \param started_process A pointer to a shell command pointer that will be filled in with a pointer to the started command structure
290  * \retval A shell_retval indicating if the command was started as a foreground or a background process
291  *
292  * This function starts a command, or a set of
293  * commands. The function is called by a shell command to
294  * start other shell commands.
295  *
296  */
297 int shell_start_command(char *commandline, int commandline_len,
298  struct shell_command *child,
299  struct process **started_process);
300 
301 /**
302  * @}
303  */
304 
305 /**
306  * \name Shell convenience functions
307  *
308  * These functions assist shell commands in parsing
309  * command lines
310  * @{
311  */
312 
313 /**
314  * \brief Convert a string to a number
315  * \param str The input string
316  * \param 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
317  * \retval The converted number
318  *
319  * This function converts a string to a number. The
320  * function returns the converted number and a pointer to
321  * the data that follows the number in the input string.
322  *
323  */
324 unsigned long shell_strtolong(const char *str, const char **retstr);
325 
326 unsigned long shell_time(void);
327 void shell_set_time(unsigned long seconds);
328 
329 /**
330  * @}
331  */
332 
333 /**
334  * \name Shell variables, definitions, and return values
335  *
336  * @{
337  */
338 
339 enum shell_retval {
340  SHELL_FOREGROUND,
341  SHELL_BACKGROUND,
342  SHELL_NOTHING,
343 };
344 
345 /**
346  * \brief The event number for shell input data
347  *
348  * The shell sends data as Contiki events to shell command
349  * processes. This variable contains the number of the
350  * Contiki event.
351  *
352  */
353 extern int shell_event_input;
354 
355 /**
356  * \brief Structure for shell input data
357  *
358  * The shell sends data as Contiki events to shell command
359  * processes. This structure contains the data in the
360  * event. The data is split into two halves, data1 and
361  * data2. The length of the data in the two halves is
362  * given by len1 and len2.
363  *
364  */
365 struct shell_input {
366  char *data1;
367  const char *data2;
368  int len1, len2;
369 };
370 
371 /**
372  * @}
373  */
374 
375 #include "shell-base64.h"
376 #include "shell-blink.h"
377 #include "shell-collect-view.h"
378 #include "shell-coffee.h"
379 #include "shell-download.h"
380 #include "shell-exec.h"
381 #include "shell-file.h"
382 #include "shell-httpd.h"
383 #include "shell-irc.h"
384 #include "shell-memdebug.h"
385 #include "shell-netfile.h"
386 #include "shell-netperf.h"
387 #include "shell-netstat.h"
388 #include "shell-ping.h"
389 #include "shell-power.h"
390 #include "shell-powertrace.h"
391 #include "shell-ps.h"
392 #include "shell-reboot.h"
393 #include "shell-rime-debug.h"
395 #include "shell-rime-neighbors.h"
396 #include "shell-rime-netcmd.h"
397 #include "shell-rime-ping.h"
398 #include "shell-rime-sendcmd.h"
399 #include "shell-rime-sniff.h"
400 #include "shell-rime-unicast.h"
401 #include "shell-rime.h"
402 #include "shell-rsh.h"
403 #include "shell-run.h"
404 #include "shell-sendtest.h"
405 #include "shell-sky.h"
406 #include "shell-tcpsend.h"
407 #include "shell-text.h"
408 #include "shell-time.h"
409 #include "shell-udpsend.h"
410 #include "shell-vars.h"
411 #include "shell-wget.h"
412 
413 #endif /* SHELL_H_ */
414 
415 
416 /** @} */
417 /** @} */
void shell_prompt(char *str)
Print a prompt.
Definition: serial-shell.c:82
Header file for Contik shell command httpd
A brief description of what this file is.
void shell_stop(void)
Stop the shell.
Definition: shell.c:570
A brief description of what this file is.
Header file for reboot Contik shell command
void shell_init(void)
Initialize the shell.
Definition: shell.c:501
void shell_output_str(struct shell_command *c, char *text1, const char *text2)
Output strings from a shell command.
Definition: shell.c:383
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.
Definition: shell.c:308
Header file for Contik shell command netstat
A brief description of what this file is.
A brief description of what this file is.
A brief description of what this file is.
Header file for the Contiki shell Rime netcmd application
Header file for the Contiki shell Rime neighbors application
Header file for CFS Coffee-specific Contiki shell commands
void shell_input(char *commandline, int commandline_len)
Send a line of input to the shell.
Definition: shell.c:359
Header file for Contik shell command tcpsend
void shell_quit(void)
Quit the shell.
Definition: shell.c:576
Header file for Tmote Sky-specific Contiki shell commands
A brief description of what this file is.
Shell commands for base64 decoding
void shell_start(void)
Start the shell.
Definition: shell.c:562
Shell interface to the powertrace app
void shell_output(struct shell_command *c, void *data1, int len1, const void *data2, int len2)
Output data from a shell command.
Definition: shell.c:395
Header file for Contik shell command irc
Header file for the Contiki shell Rime sniffer application
unsigned long shell_strtolong(const char *str, const char **retstr)
Convert a string to a number.
Definition: shell.c:521
Header file for CFS Coffee-specific Contiki shell commands
A brief description of what this file is.
Header file for Contik shell command ping
Header file for Contik shell command udpsend
Structure for shell input data.
Definition: shell.h:365
void shell_register_command(struct shell_command *c)
Register a command with the shell.
Definition: shell.c:413
Header file for the Contiki shell Rime ping application
Header file for process-related Contiki shell commands
int shell_event_input
The event number for shell input data.
Definition: shell.c:70
Text-related shell commands
void shell_unregister_command(struct shell_command *c)
Unregister a previously registered shell command.
Definition: shell.c:407
A brief description of what this file is.
A brief description of what this file is.
A brief description of what this file is.
A brief description of what this file is.
Holds a information about a shell command.
Definition: shell.h:73
void shell_default_output(const char *text1, int len1, const char *text2, int len2)
Print a line of output from the shell.
Definition: serial-shell.c:58
Header file for Contik shell command wget
void shell_exit(void)
Request shell exit.
Definition: serial-shell.c:89
A brief description of what this file is.
Header file for the Contiki process interface.
Shell commands for memory debugging
A brief description of what this file is.
Header file for the Contiki shell power functions