Contiki-NG
shell.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, Inria.
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 * \addtogroup lib
34 * @{
35 *
36 * \defgroup shell Contiki-NG interactive management shell
37 *
38 * The shell enables to inspect and manage the network layer and provides
39 * other system functionalities
40 *
41 * @{
42 */
43 
44 /**
45  * \file
46  * Main header file for the Contiki shell
47  * \author
48  * Simon Duquennoy <simon.duquennoy@inria.fr>
49  */
50 #ifndef SHELL_H_
51 #define SHELL_H_
52 
53 #include "net/ipv6/uip.h"
54 #include "net/linkaddr.h"
55 #include "sys/process.h"
56 #include <stdio.h>
57 
58 /* Helper macros to parse arguments */
59 #define SHELL_ARGS_INIT(args, next_args) (next_args) = (args);
60 
61 #define SHELL_ARGS_NEXT(args, next_args) do { \
62  (args) = (next_args); \
63  if((args) != NULL) { \
64  if(*(args) == '\0') { \
65  (args) = NULL; \
66  } else { \
67  (next_args) = strchr((args), ' '); \
68  if((next_args) != NULL) { \
69  *(next_args) = '\0'; \
70  (next_args)++; \
71  } \
72  } \
73  } else { \
74  (next_args) = NULL; \
75  } \
76  } while(0)
77 
78 /* Printf-formatted output via a given output function */
79 #define SHELL_OUTPUT(output_func, format, ...) do { \
80  char buffer[192]; \
81  snprintf(buffer, sizeof(buffer), format, ##__VA_ARGS__); \
82  (output_func)(buffer); \
83  } while(0);
84 
85 typedef void (shell_output_func)(const char *str);
86 
87 /**
88  * Initializes Shell module
89  */
90 void shell_init(void);
91 
92 /**
93  * \brief A protothread that is spawned by a Shell driver when receiving a new line.
94  */
95 PT_THREAD(shell_input(struct pt *pt, shell_output_func output, const char *cmd));
96 
97 /**
98  * Prints an IPv6 address
99  *
100  * \param output The output function
101  * \param ipaddr The IPv6 to printed
102  */
103 void shell_output_6addr(shell_output_func output, const uip_ipaddr_t *ipaddr);
104 
105 /**
106  * Prints a link-layer address
107  *
108  * \param output The output function
109  * \param lladdr The link-layer to be printed
110  */
111 void shell_output_lladdr(shell_output_func output, const linkaddr_t *lladdr);
112 
113 #endif /* SHELL_H_ */
114 /**
115  * @}
116  * @}
117  */
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
Definition: uip-nd6.c:116
void shell_output_lladdr(shell_output_func output, const linkaddr_t *lladdr)
Prints a link-layer address.
Definition: shell.c:64
Header file for the link-layer address representation
static uint8_t output(const linkaddr_t *localdest)
Take an IP packet and format it to be sent on an 802.15.4 network using 6lowpan.
Definition: sicslowpan.c:1565
Header file for the Contiki process interface.
PT_THREAD(shell_input(struct pt *pt, shell_output_func output, const char *cmd))
A protothread that is spawned by a Shell driver when receiving a new line.
void shell_init(void)
Initializes Shell module.
Definition: shell.c:123
Header file for the uIP TCP/IP stack.
void shell_output_6addr(shell_output_func output, const uip_ipaddr_t *ipaddr)
Prints an IPv6 address.
Definition: shell.c:55