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