Contiki 3.x
shell-sensors.c
Go to the documentation of this file.
1 /**
2  * \addtogroup mbxxx-platform
3  *
4  * @{
5  */
6 /*
7  * Copyright (c) 2010, STMicroelectronics.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the Institute nor the names of its contributors
19  * may be used to endorse or promote products derived from this software
20  * without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  * This file is part of the Contiki operating system.
35  *
36  */
37 
38  /**
39  * \file
40  * Shell function for temp and acc sensors.
41  * \author
42  * Salvatore Pitrulli <salvopitru@users.sourceforge.net>
43  */
44 
45 #include <string.h>
46 #include <stdio.h>
47 
48 #include "contiki.h"
49 #include "shell.h"
50 #include "contiki-net.h"
51 #include "dev/temperature-sensor.h"
52 #include "dev/acc-sensor.h"
53 
54 /*---------------------------------------------------------------------------*/
55 PROCESS(shell_sensors_process, "sensors");
56 SHELL_COMMAND(sensors_command,
57  "sensors",
58  "sensors {temp|acc}: get sensor value",
59  &shell_sensors_process);
60 /*---------------------------------------------------------------------------*/
61 PROCESS_THREAD(shell_sensors_process, ev, data)
62 {
63 
64  char str_buf[22];
65 
66  PROCESS_BEGIN();
67 
68  if(data == NULL) {
69  shell_output_str(&sensors_command,
70  "sensors {temp|acc}: a sensor must be specified", "");
71  PROCESS_EXIT();
72  }
73 
74  if(strcmp(data,"temp")==0) {
75 
76  unsigned int temp = temperature_sensor.value(0);
77 
78  snprintf(str_buf,sizeof(str_buf),"%d.%d degC",temp/10,temp-(temp/10)*10);
79 
80  shell_output_str(&sensors_command, "Temp: ", str_buf);
81 
82  }
83  else if (strcmp(data,"acc")==0) {
84 
85  snprintf(str_buf,sizeof(str_buf),"%d,%d,%d) mg",acc_sensor.value(ACC_X_AXIS),acc_sensor.value(ACC_Y_AXIS),acc_sensor.value(ACC_Z_AXIS));
86 
87  shell_output_str(&sensors_command, "(X,Y,Z): (", str_buf);
88 
89  }
90 
91  PROCESS_END();
92 }
93 /*---------------------------------------------------------------------------*/
94 void
95 shell_sensors_init(void)
96 {
97  SENSORS_ACTIVATE(acc_sensor);
98 
99  shell_register_command(&sensors_command);
100 }
101 /*---------------------------------------------------------------------------*/
102 /** @} */
void shell_output_str(struct shell_command *c, char *text1, const char *text2)
Output strings from a shell command.
Definition: shell.c:383
struct sensors_sensor temperature_sensor
NOTE: For the temperature measurement, the ADC extended range mode is needed; but this is inaccurate ...
#define PROCESS_EXIT()
Exit the currently running process.
Definition: process.h:200
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition: process.h:120
Main header file for the Contiki shell
#define NULL
The null pointer.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
Definition: process.h:273
#define PROCESS_END()
Define the end of a process.
Definition: process.h:131
void shell_register_command(struct shell_command *c)
Register a command with the shell.
Definition: shell.c:413
#define PROCESS(name, strname)
Declare a process.
Definition: process.h:307
#define SHELL_COMMAND(name, command, description, process)
Define a shell command.
Definition: shell.h:219