2 * Copyright (c) 2008, Swedish Institute of Computer Science.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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
29 * This file is part of the Contiki operating system.
31 * $Id: shell-sky.c,v 1.14 2010/01/14 15:05:40 joxe Exp $
36 * Tmote Sky-specific Contiki shell commands
38 * Adam Dunkels <adam@sics.se>
42 #include "shell-sky.h"
44 #include "dev/watchdog.h"
47 #include "dev/cc2420.h"
49 #include "dev/light-sensor.h"
50 #include "dev/battery-sensor.h"
51 #include "dev/sht11.h"
53 #include "net/rime/timesynch.h"
60 /*---------------------------------------------------------------------------*/
61 PROCESS(shell_nodeid_process
, "nodeid");
62 SHELL_COMMAND(nodeid_command
,
64 "nodeid: set node ID",
65 &shell_nodeid_process
);
66 PROCESS(shell_sense_process
, "sense");
67 SHELL_COMMAND(sense_command
,
69 "sense: print out sensor data",
70 &shell_sense_process
);
71 PROCESS(shell_senseconv_process
, "senseconv");
72 SHELL_COMMAND(senseconv_command
,
74 "senseconv: convert 'sense' data to human readable format",
75 &shell_senseconv_process
);
76 PROCESS(shell_txpower_process
, "txpower");
77 SHELL_COMMAND(txpower_command
,
79 "txpower <power>: change CC2420 transmission power (0 - 31)",
80 &shell_txpower_process
);
81 PROCESS(shell_rfchannel_process
, "rfchannel");
82 SHELL_COMMAND(rfchannel_command
,
84 "rfchannel <channel>: change CC2420 radio channel (11 - 26)",
85 &shell_rfchannel_process
);
86 /*---------------------------------------------------------------------------*/
87 #define MAX(a, b) ((a) > (b)? (a): (b))
88 #define MIN(a, b) ((a) < (b)? (a): (b))
93 static struct spectrum rssi_samples
[NUM_SAMPLES
];
103 for(channel
= 11; channel
<= 26; ++channel
) {
104 cc2420_set_channel(channel
);
105 rssi_samples
[sample
].channel
[channel
- 11] = cc2420_rssi() + 53;
110 sample
= (sample
+ 1) % NUM_SAMPLES
;
115 for(channel
= 0; channel
< 16; ++channel
) {
118 for(i
= 0; i
< NUM_SAMPLES
; ++i
) {
119 max
= MAX(max
, rssi_samples
[i
].channel
[channel
]);
126 /*---------------------------------------------------------------------------*/
130 uint16_t timesynch_time
;
138 /*---------------------------------------------------------------------------*/
139 PROCESS_THREAD(shell_sense_process
, ev
, data
)
141 struct sense_msg msg
;
145 msg
.clock
= clock_time();
146 msg
.timesynch_time
= timesynch_time();
147 msg
.light1
= light_sensor
.value(0);
148 msg
.light2
= light_sensor
.value(1);
149 msg
.temp
= sht11_temp();
150 msg
.humidity
= sht11_humidity();
151 msg
.rssi
= do_rssi();
152 msg
.voltage
= battery_sensor
.value(0);
154 shell_output(&sense_command
, &msg
, sizeof(msg
), "", 0);
157 /*---------------------------------------------------------------------------*/
158 PROCESS_THREAD(shell_senseconv_process
, ev
, data
)
160 struct shell_input
*input
;
161 struct sense_msg
*msg
;
164 PROCESS_WAIT_EVENT_UNTIL(ev
== shell_event_input
);
167 if(input
->len1
+ input
->len2
== 0) {
170 msg
= (struct sense_msg
*)input
->data1
;
174 snprintf(buf
, sizeof(buf
),
175 "%d", 10 * msg
->light1
/ 7);
176 shell_output_str(&senseconv_command
, "Light 1 ", buf
);
177 snprintf(buf
, sizeof(buf
),
178 "%d", 46 * msg
->light2
/ 10);
179 shell_output_str(&senseconv_command
, "Light 2 ", buf
);
180 snprintf(buf
, sizeof(buf
),
181 "%d.%d", (msg
->temp
/ 10 - 396) / 10,
182 (msg
->temp
/ 10 - 396) % 10);
183 shell_output_str(&senseconv_command
, "Temperature ", buf
);
184 snprintf(buf
, sizeof(buf
),
185 "%d", (int)(-4L + 405L * msg
->humidity
/ 10000L));
186 shell_output_str(&senseconv_command
, "Relative humidity ", buf
);
187 snprintf(buf
, sizeof(buf
),
189 shell_output_str(&senseconv_command
, "RSSI ", buf
);
190 snprintf(buf
, sizeof(buf
), /* 819 = 4096 / 5 */
191 "%d.%d", (msg
->voltage
/ 819), (10 * msg
->voltage
/ 819) % 10);
192 shell_output_str(&senseconv_command
, "Voltage ", buf
);
197 /*---------------------------------------------------------------------------*/
198 PROCESS_THREAD(shell_txpower_process
, ev
, data
)
207 msg
.txpower
= shell_strtolong(data
, &newptr
);
209 /* If no transmission power was given on the command line, we print
210 out the current txpower. */
213 msg
.txpower
= cc2420_get_txpower();
215 cc2420_set_txpower(msg
.txpower
);
220 shell_output(&txpower_command
, &msg
, sizeof(msg
), "", 0);
224 /*---------------------------------------------------------------------------*/
225 PROCESS_THREAD(shell_rfchannel_process
, ev
, data
)
234 msg
.channel
= shell_strtolong(data
, &newptr
);
236 /* If no channel was given on the command line, we print out the
239 msg
.channel
= cc2420_get_channel();
241 cc2420_set_channel(msg
.channel
);
246 shell_output(&txpower_command
, &msg
, sizeof(msg
), "", 0);
250 /*---------------------------------------------------------------------------*/
251 PROCESS_THREAD(shell_nodeid_process
, ev
, data
)
258 nodeid
= shell_strtolong(data
, &newptr
);
260 /* If no node ID was given on the command line, we print out the
261 current channel. Else we burn the new node ID. */
265 nodeid
= shell_strtolong(data
, &newptr
);
268 node_id_burn(nodeid
);
271 leds_off(LEDS_RED
+ LEDS_BLUE
);
275 snprintf(buf
, sizeof(buf
), "%d", nodeid
);
276 shell_output_str(&nodeid_command
, "Node ID: ", buf
);
280 /*---------------------------------------------------------------------------*/
284 shell_register_command(&txpower_command
);
285 shell_register_command(&rfchannel_command
);
286 shell_register_command(&sense_command
);
287 shell_register_command(&senseconv_command
);
288 shell_register_command(&nodeid_command
);
291 /*---------------------------------------------------------------------------*/