Add missing includes
[contiki-2.x.git] / apps / shell / shell-vars.c
blobdd1982b6791445a787805d51b9a261dcd171dd28
1 /*
2 * Copyright (c) 2008, Swedish Institute of Computer Science.
3 * All rights reserved.
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.
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.
29 * This file is part of the Contiki operating system.
31 * $Id: shell-vars.c,v 1.1 2008/02/04 23:42:17 adamdunkels Exp $
34 /**
35 * \file
36 * A brief description of what this file is.
37 * \author
38 * Adam Dunkels <adam@sics.se>
41 #include "contiki.h"
42 #include "contiki-conf.h"
43 #include "shell-vars.h"
45 #include "loader/symbols.h"
47 #include <stdio.h>
48 #include <string.h>
50 #ifdef SHELL_VARS_CONF_RAM_BEGIN
51 #define SHELL_VARS_RAM_BEGIN SHELL_VARS_CONF_RAM_BEGIN
52 #define SHELL_VARS_RAM_END SHELL_VARS_CONF_RAM_END
53 #else /* SHELL_VARS_CONF_RAM_BEGIN */
54 #define SHELL_VARS_RAM_BEGIN 0
55 #define SHELL_VARS_RAM_END (unsigned int)-1
56 #endif /* SHELL_VARS_CONF_RAM_BEGIN */
58 /*---------------------------------------------------------------------------*/
59 PROCESS(shell_vars_process, "vars");
60 SHELL_COMMAND(vars_command,
61 "vars",
62 "vars: list all variables in RAM",
63 &shell_vars_process);
64 /*---------------------------------------------------------------------------*/
65 PROCESS(shell_var_process, "var");
66 SHELL_COMMAND(var_command,
67 "var",
68 "var <variable>: show content of a variable",
69 &shell_var_process);
70 /*---------------------------------------------------------------------------*/
71 PROCESS_THREAD(shell_vars_process, ev, data)
73 int i;
75 PROCESS_BEGIN();
77 shell_output_str(&vars_command, "Variables in RAM:", "");
79 for(i = 0; i < symbols_nelts; ++i) {
80 if(symbols[i].name != NULL &&
81 (unsigned int)symbols[i].value >= SHELL_VARS_RAM_BEGIN &&
82 (unsigned int)symbols[i].value <= SHELL_VARS_RAM_END) {
83 shell_output_str(&vars_command, (char *)symbols[i].name, "");
87 PROCESS_END();
89 /*---------------------------------------------------------------------------*/
90 PROCESS_THREAD(shell_var_process, ev, data)
92 int i;
94 PROCESS_BEGIN();
96 if(data == NULL) {
97 shell_output_str(&var_command, "syntax: var <variable name>", "");
98 } else {
99 for(i = 0; i < symbols_nelts; ++i) {
100 if(symbols[i].name != NULL &&
101 strncmp(symbols[i].name, data, strlen(symbols[i].name)) == 0) {
102 char numbuf[32];
103 int j;
105 sprintf(numbuf, " %d", *((int *)symbols[i].value));
106 shell_output_str(&var_command, (char *)symbols[i].name, numbuf);
108 for(j = 0; j < 8 * 8; j += 8) {
109 sprintf(numbuf, "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x",
110 ((unsigned char *)symbols[i].value)[j],
111 ((unsigned char *)symbols[i].value)[j + 1],
112 ((unsigned char *)symbols[i].value)[j + 2],
113 ((unsigned char *)symbols[i].value)[j + 3],
114 ((unsigned char *)symbols[i].value)[j + 4],
115 ((unsigned char *)symbols[i].value)[j + 5],
116 ((unsigned char *)symbols[i].value)[j + 6],
117 ((unsigned char *)symbols[i].value)[j + 7]);
118 shell_output_str(&var_command, numbuf, "");
120 PROCESS_EXIT();
123 shell_output_str(&var_command, data, ": variable name not found");
126 PROCESS_END();
128 /*---------------------------------------------------------------------------*/
129 void
130 shell_vars_init(void)
132 shell_register_command(&var_command);
133 shell_register_command(&vars_command);
135 /*---------------------------------------------------------------------------*/