]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
New demo app demonstrating how to sample rssi readings from the network
authorklueska <klueska>
Tue, 15 Apr 2008 17:56:48 +0000 (17:56 +0000)
committerklueska <klueska>
Tue, 15 Apr 2008 17:56:48 +0000 (17:56 +0000)
14 files changed:
apps/tutorials/RssiDemo/InterceptBase/BaseStationC.nc [new file with mode: 0644]
apps/tutorials/RssiDemo/InterceptBase/BaseStationP.nc [new file with mode: 0644]
apps/tutorials/RssiDemo/InterceptBase/Makefile [new file with mode: 0644]
apps/tutorials/RssiDemo/RssiBase/ApplicationDefinitions.h [new file with mode: 0644]
apps/tutorials/RssiDemo/RssiBase/Makefile [new file with mode: 0644]
apps/tutorials/RssiDemo/RssiBase/RssiBaseAppC.nc [new file with mode: 0644]
apps/tutorials/RssiDemo/RssiBase/RssiBaseC.nc [new file with mode: 0644]
apps/tutorials/RssiDemo/RssiDemoMessages.h [new file with mode: 0644]
apps/tutorials/RssiDemo/SendingMote/ApplicationDefinitions.h [new file with mode: 0644]
apps/tutorials/RssiDemo/SendingMote/Makefile [new file with mode: 0644]
apps/tutorials/RssiDemo/SendingMote/SendingMoteAppC.nc [new file with mode: 0644]
apps/tutorials/RssiDemo/SendingMote/SendingMoteC.nc [new file with mode: 0644]
apps/tutorials/RssiDemo/java/Makefile [new file with mode: 0644]
apps/tutorials/RssiDemo/java/RssiDemo.java [new file with mode: 0644]

diff --git a/apps/tutorials/RssiDemo/InterceptBase/BaseStationC.nc b/apps/tutorials/RssiDemo/InterceptBase/BaseStationC.nc
new file mode 100644 (file)
index 0000000..e85194f
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * "Copyright (c) 2000-2003 The Regents of the University  of California.  
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ * 
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ * Copyright (c) 2002-2003 Intel Corporation
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached INTEL-LICENSE     
+ * file. If you do not find these files, copies can be found by writing to
+ * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, 
+ * 94704.  Attention:  Intel License Inquiry.
+ */
+
+/**
+ * The TinyOS 2.x base station that forwards packets between the UART
+ * and radio.It replaces the GenericBase of TinyOS 1.0 and the
+ * TOSBase of TinyOS 1.1.
+ *
+ * <p>On the serial link, BaseStation sends and receives simple active
+ * messages (not particular radio packets): on the radio link, it
+ * sends radio active messages, whose format depends on the network
+ * stack being used. BaseStation will copy its compiled-in group ID to
+ * messages moving from the serial link to the radio, and will filter
+ * out incoming radio messages that do not contain that group ID.</p>
+ *
+ * <p>BaseStation includes queues in both directions, with a guarantee
+ * that once a message enters a queue, it will eventually leave on the
+ * other interface. The queues allow the BaseStation to handle load
+ * spikes.</p>
+ *
+ * <p>BaseStation acknowledges a message arriving over the serial link
+ * only if that message was successfully enqueued for delivery to the
+ * radio link.</p>
+ *
+ * <p>The LEDS are programmed to toggle as follows:</p>
+ * <ul>
+ * <li><b>RED Toggle:</b>: Message bridged from serial to radio</li>
+ * <li><b>GREEN Toggle:</b> Message bridged from radio to serial</li>
+ * <li><b>YELLOW/BLUE Toggle:</b> Dropped message due to queue overflow in either direction</li>
+ * </ul>
+ *
+ * @author Phil Buonadonna
+ * @author Gilman Tolle
+ * @author David Gay
+ * @author Philip Levis
+ * @author Dimas Abreu Dutra
+ * @date January 29 2008
+ */
+
+configuration BaseStationC {
+  provides interface Intercept as RadioIntercept[am_id_t amid];
+  provides interface Intercept as SerialIntercept[am_id_t amid];
+}
+implementation {
+  components MainC, BaseStationP, LedsC;
+  components ActiveMessageC as Radio, SerialActiveMessageC as Serial;
+
+  RadioIntercept = BaseStationP.RadioIntercept;
+  SerialIntercept = BaseStationP.SerialIntercept;
+  
+  MainC.Boot <- BaseStationP;
+
+  BaseStationP.RadioControl -> Radio;
+  BaseStationP.SerialControl -> Serial;
+  
+  BaseStationP.UartSend -> Serial;
+  BaseStationP.UartReceive -> Serial;
+  BaseStationP.UartPacket -> Serial;
+  BaseStationP.UartAMPacket -> Serial;
+  
+  BaseStationP.RadioSend -> Radio;
+  BaseStationP.RadioReceive -> Radio.Receive;
+  BaseStationP.RadioSnoop -> Radio.Snoop;
+  BaseStationP.RadioPacket -> Radio;
+  BaseStationP.RadioAMPacket -> Radio;
+  
+  BaseStationP.Leds -> LedsC;
+}
diff --git a/apps/tutorials/RssiDemo/InterceptBase/BaseStationP.nc b/apps/tutorials/RssiDemo/InterceptBase/BaseStationP.nc
new file mode 100644 (file)
index 0000000..940d9ec
--- /dev/null
@@ -0,0 +1,316 @@
+/*
+ * "Copyright (c) 2000-2005 The Regents of the University  of California.  
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ * 
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ * Copyright (c) 2002-2005 Intel Corporation
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached INTEL-LICENSE     
+ * file. If you do not find these files, copies can be found by writing to
+ * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, 
+ * 94704.  Attention:  Intel License Inquiry.
+ */
+
+/*
+ * @author Phil Buonadonna
+ * @author Gilman Tolle
+ * @author David Gay
+ * @author Dimas Abreu Dutra
+ */
+  
+/* 
+ * BaseStationP bridges packets between a serial channel and the radio.
+ * Messages moving from serial to radio will be tagged with the group
+ * ID compiled into the TOSBase, and messages moving from radio to
+ * serial will be filtered by that same group id.
+ */
+
+#include "AM.h"
+#include "Serial.h"
+
+module BaseStationP {
+  uses {
+    interface Boot;
+    interface SplitControl as SerialControl;
+    interface SplitControl as RadioControl;
+
+    interface AMSend as UartSend[am_id_t id];
+    interface Receive as UartReceive[am_id_t id];
+    interface Packet as UartPacket;
+    interface AMPacket as UartAMPacket;
+    
+    interface AMSend as RadioSend[am_id_t id];
+    interface Receive as RadioReceive[am_id_t id];
+    interface Receive as RadioSnoop[am_id_t id];
+    interface Packet as RadioPacket;
+    interface AMPacket as RadioAMPacket;
+
+    interface Leds;
+  }
+  
+  provides interface Intercept as RadioIntercept[am_id_t amid];
+  provides interface Intercept as SerialIntercept[am_id_t amid];
+}
+
+implementation
+{
+  enum {
+    UART_QUEUE_LEN = 12,
+    RADIO_QUEUE_LEN = 12,
+  };
+
+  message_t  uartQueueBufs[UART_QUEUE_LEN];
+  message_t  *uartQueue[UART_QUEUE_LEN];
+  uint8_t    uartIn, uartOut;
+  bool       uartBusy, uartFull;
+
+  message_t  radioQueueBufs[RADIO_QUEUE_LEN];
+  message_t  *radioQueue[RADIO_QUEUE_LEN];
+  uint8_t    radioIn, radioOut;
+  bool       radioBusy, radioFull;
+
+  task void uartSendTask();
+  task void radioSendTask();
+
+  void dropBlink() {
+    call Leds.led2Toggle();
+  }
+
+  void failBlink() {
+    call Leds.led2Toggle();
+  }
+
+  event void Boot.booted() {
+    uint8_t i;
+
+    for (i = 0; i < UART_QUEUE_LEN; i++)
+      uartQueue[i] = &uartQueueBufs[i];
+    uartIn = uartOut = 0;
+    uartBusy = FALSE;
+    uartFull = TRUE;
+
+    for (i = 0; i < RADIO_QUEUE_LEN; i++)
+      radioQueue[i] = &radioQueueBufs[i];
+    radioIn = radioOut = 0;
+    radioBusy = FALSE;
+    radioFull = TRUE;
+
+    call RadioControl.start();
+    call SerialControl.start();
+  }
+
+  event void RadioControl.startDone(error_t error) {
+    if (error == SUCCESS) {
+      radioFull = FALSE;
+    }
+  }
+
+  event void SerialControl.startDone(error_t error) {
+    if (error == SUCCESS) {
+      uartFull = FALSE;
+    }
+  }
+
+  event void SerialControl.stopDone(error_t error) {}
+  event void RadioControl.stopDone(error_t error) {}
+
+  uint8_t count = 0;
+
+  message_t* receive(message_t* msg, void* payload,
+                    uint8_t len, am_id_t id);
+  
+  event message_t *RadioSnoop.receive[am_id_t id](message_t *msg,
+                                                   void *payload,
+                                                   uint8_t len) {
+    return receive(msg, payload, len, id);
+  }
+  
+  event message_t *RadioReceive.receive[am_id_t id](message_t *msg,
+                                                   void *payload,
+                                                   uint8_t len) {
+    return receive(msg, payload, len, id);
+  }
+
+  message_t* receive(message_t *msg, void *payload, uint8_t len, am_id_t id) {
+    message_t *ret = msg;
+    
+    if (!signal RadioIntercept.forward[id](msg,payload,len))
+      return ret;
+
+    atomic {
+      if (!uartFull)
+       {
+         ret = uartQueue[uartIn];
+         uartQueue[uartIn] = msg;
+
+         uartIn = (uartIn + 1) % UART_QUEUE_LEN;
+       
+         if (uartIn == uartOut)
+           uartFull = TRUE;
+
+         if (!uartBusy)
+           {
+             post uartSendTask();
+             uartBusy = TRUE;
+           }
+       }
+      else
+       dropBlink();
+    }
+    
+    return ret;
+  }
+
+  uint8_t tmpLen;
+  
+  task void uartSendTask() {
+    uint8_t len;
+    am_id_t id;
+    am_addr_t addr, src;
+    message_t* msg;
+    atomic
+      if (uartIn == uartOut && !uartFull)
+       {
+         uartBusy = FALSE;
+         return;
+       }
+
+    msg = uartQueue[uartOut];
+    tmpLen = len = call RadioPacket.payloadLength(msg);
+    id = call RadioAMPacket.type(msg);
+    addr = call RadioAMPacket.destination(msg);
+    src = call RadioAMPacket.source(msg);
+    call UartAMPacket.setSource(msg, src);
+
+    if (call UartSend.send[id](addr, uartQueue[uartOut], len) == SUCCESS)
+      call Leds.led1Toggle();
+    else
+      {
+       failBlink();
+       post uartSendTask();
+      }
+  }
+
+  event void UartSend.sendDone[am_id_t id](message_t* msg, error_t error) {
+    if (error != SUCCESS)
+      failBlink();
+    else
+      atomic
+       if (msg == uartQueue[uartOut])
+         {
+           if (++uartOut >= UART_QUEUE_LEN)
+             uartOut = 0;
+           if (uartFull)
+             uartFull = FALSE;
+         }
+    post uartSendTask();
+  }
+
+  event message_t *UartReceive.receive[am_id_t id](message_t *msg,
+                                                  void *payload,
+                                                  uint8_t len) {       
+    message_t *ret = msg;
+    bool reflectToken = FALSE;
+
+    if (!signal SerialIntercept.forward[id](msg,payload,len))
+      return ret;
+
+    atomic
+      if (!radioFull)
+       {
+         reflectToken = TRUE;
+         ret = radioQueue[radioIn];
+         radioQueue[radioIn] = msg;
+         if (++radioIn >= RADIO_QUEUE_LEN)
+           radioIn = 0;
+         if (radioIn == radioOut)
+           radioFull = TRUE;
+
+         if (!radioBusy)
+           {
+             post radioSendTask();
+             radioBusy = TRUE;
+           }
+       }
+      else
+       dropBlink();
+
+    if (reflectToken) {
+      //call UartTokenReceive.ReflectToken(Token);
+    }
+    
+    return ret;
+  }
+
+  task void radioSendTask() {
+    uint8_t len;
+    am_id_t id;
+    am_addr_t addr;
+    message_t* msg;
+    
+    atomic
+      if (radioIn == radioOut && !radioFull)
+       {
+         radioBusy = FALSE;
+         return;
+       }
+
+    msg = radioQueue[radioOut];
+    len = call UartPacket.payloadLength(msg);
+    addr = call UartAMPacket.destination(msg);
+    id = call UartAMPacket.type(msg);
+    if (call RadioSend.send[id](addr, msg, len) == SUCCESS)
+      call Leds.led0Toggle();
+    else
+      {
+       failBlink();
+       post radioSendTask();
+      }
+  }
+
+  event void RadioSend.sendDone[am_id_t id](message_t* msg, error_t error) {
+    if (error != SUCCESS)
+      failBlink();
+    else
+      atomic
+       if (msg == radioQueue[radioOut])
+         {
+           if (++radioOut >= RADIO_QUEUE_LEN)
+             radioOut = 0;
+           if (radioFull)
+             radioFull = FALSE;
+         }
+    
+    post radioSendTask();
+  }
+
+  default event bool
+  RadioIntercept.forward[am_id_t amid](message_t* msg,
+                                      void* payload,
+                                      uint8_t len) {
+    return TRUE;
+  }
+
+  default event bool
+  SerialIntercept.forward[am_id_t amid](message_t* msg,
+                                       void* payload,
+                                       uint8_t len) {
+    return TRUE;
+  }
+}  
diff --git a/apps/tutorials/RssiDemo/InterceptBase/Makefile b/apps/tutorials/RssiDemo/InterceptBase/Makefile
new file mode 100644 (file)
index 0000000..3c052e7
--- /dev/null
@@ -0,0 +1,6 @@
+COMPONENT=BaseStationC
+CFLAGS += -DCC2420_NO_ACKNOWLEDGEMENTS
+CFLAGS += -DCC2420_NO_ADDRESS_RECOGNITION
+
+include $(MAKERULES)
+
diff --git a/apps/tutorials/RssiDemo/RssiBase/ApplicationDefinitions.h b/apps/tutorials/RssiDemo/RssiBase/ApplicationDefinitions.h
new file mode 100644 (file)
index 0000000..163055d
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2008 Dimas Abreu Dutra
+ * All rights reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the
+ *   distribution.
+ * - Neither the name of the Stanford University nor the names of
+ *   its contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIMAS ABREU
+ * DUTRA OR HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @author Dimas Abreu Dutra
+ */
+
+#ifndef APPLICATIONDEFINITIONS_H__
+#define APPLICATIONDEFINITIONS_H__
+
+enum {
+  SEND_INTERVAL_MS = 250
+};
+
+#endif //APPLICATIONDEFINITIONS_H__
diff --git a/apps/tutorials/RssiDemo/RssiBase/Makefile b/apps/tutorials/RssiDemo/RssiBase/Makefile
new file mode 100644 (file)
index 0000000..cd63ce1
--- /dev/null
@@ -0,0 +1,9 @@
+COMPONENT=RssiBaseAppC
+
+INCLUDES= -I..               \
+          -I../InterceptBase
+
+CFLAGS += $(INCLUDES)
+
+include $(MAKERULES)
+
diff --git a/apps/tutorials/RssiDemo/RssiBase/RssiBaseAppC.nc b/apps/tutorials/RssiDemo/RssiBase/RssiBaseAppC.nc
new file mode 100644 (file)
index 0000000..bfb17e1
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2008 Dimas Abreu Dutra
+ * All rights reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the
+ *   distribution.
+ * - Neither the name of the Stanford University nor the names of
+ *   its contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIMAS ABREU
+ * DUTRA OR HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @author Dimas Abreu Dutra
+ */
+
+#include "RssiDemoMessages.h"
+#include "message.h"
+
+configuration RssiBaseAppC {
+} implementation {
+  components BaseStationC;
+  components RssiBaseC as App;
+
+#ifdef __CC2420_H__
+  components CC2420ActiveMessageC;
+  App -> CC2420ActiveMessageC.CC2420Packet;
+#endif //__CC2420_H__
+  
+  App-> BaseStationC.RadioIntercept[AM_RSSIMSG];
+}
diff --git a/apps/tutorials/RssiDemo/RssiBase/RssiBaseC.nc b/apps/tutorials/RssiDemo/RssiBase/RssiBaseC.nc
new file mode 100644 (file)
index 0000000..092a9a9
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2008 Dimas Abreu Dutra
+ * All rights reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the
+ *   distribution.
+ * - Neither the name of the Stanford University nor the names of
+ *   its contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIMAS ABREU
+ * DUTRA OR HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @author Dimas Abreu Dutra
+ */
+
+#include "ApplicationDefinitions.h"
+#include "RssiDemoMessages.h"  
+
+module RssiBaseC {
+  uses interface Intercept as RssiMsgIntercept;
+
+#ifdef __CC2420_H__
+  uses interface CC2420Packet;
+#endif //__CC2420_H__  
+} implementation {
+
+  uint16_t getRssi(message_t *msg);
+  
+  event bool RssiMsgIntercept.forward(message_t *msg,
+                                     void *payload,
+                                     uint8_t len) {
+    RssiMsg *rssiMsg = (RssiMsg*) payload;
+    rssiMsg->rssi = getRssi(msg);
+    
+    return TRUE;
+  }
+
+#ifdef __CC2420_H__  
+  uint16_t getRssi(message_t *msg){
+    return (uint16_t) call CC2420Packet.getRssi(msg);
+  }
+#elif defined(CC1K_RADIO_MSG_H)
+    uint16_t getRssi(message_t *msg){
+    cc1000_metadata_t *md =(cc1000_metadata_t*) msg->metadata;
+    return md->strength_or_preamble;
+  }
+#else
+  #error Radio chip not supported! This demo currently works only \
+         for motes with CC1000 or CC2420 radios.  
+#endif //__CC2420_H__
+  
+}
+
diff --git a/apps/tutorials/RssiDemo/RssiDemoMessages.h b/apps/tutorials/RssiDemo/RssiDemoMessages.h
new file mode 100644 (file)
index 0000000..ccd081d
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2008 Dimas Abreu Dutra
+ * All rights reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the
+ *   distribution.
+ * - Neither the name of the Stanford University nor the names of
+ *   its contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIMAS ABREU
+ * DUTRA OR HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @author Dimas Abreu Dutra
+ */
+
+#ifndef RSSIDEMOMESSAGES_H__
+#define RSSIDEMOMESSAGES_H__
+
+enum {
+  AM_RSSIMSG = 10
+};
+
+typedef nx_struct RssiMsg{
+  nx_int16_t rssi;
+} RssiMsg;
+
+#endif //RSSIDEMOMESSAGES_H__
diff --git a/apps/tutorials/RssiDemo/SendingMote/ApplicationDefinitions.h b/apps/tutorials/RssiDemo/SendingMote/ApplicationDefinitions.h
new file mode 100644 (file)
index 0000000..163055d
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2008 Dimas Abreu Dutra
+ * All rights reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the
+ *   distribution.
+ * - Neither the name of the Stanford University nor the names of
+ *   its contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIMAS ABREU
+ * DUTRA OR HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @author Dimas Abreu Dutra
+ */
+
+#ifndef APPLICATIONDEFINITIONS_H__
+#define APPLICATIONDEFINITIONS_H__
+
+enum {
+  SEND_INTERVAL_MS = 250
+};
+
+#endif //APPLICATIONDEFINITIONS_H__
diff --git a/apps/tutorials/RssiDemo/SendingMote/Makefile b/apps/tutorials/RssiDemo/SendingMote/Makefile
new file mode 100644 (file)
index 0000000..3ff539a
--- /dev/null
@@ -0,0 +1,7 @@
+COMPONENT=SendingMoteAppC
+
+INCLUDES= -I..
+
+CFLAGS += $(INCLUDES)
+
+include $(MAKERULES)
diff --git a/apps/tutorials/RssiDemo/SendingMote/SendingMoteAppC.nc b/apps/tutorials/RssiDemo/SendingMote/SendingMoteAppC.nc
new file mode 100644 (file)
index 0000000..c953fb2
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008 Dimas Abreu Dutra
+ * All rights reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the
+ *   distribution.
+ * - Neither the name of the Stanford University nor the names of
+ *   its contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIMAS ABREU
+ * DUTRA OR HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @author Dimas Abreu Dutra
+ */
+
+#include "RssiDemoMessages.h"
+
+configuration SendingMoteAppC {
+} implementation {
+  components ActiveMessageC, MainC;  
+  components new AMSenderC(AM_RSSIMSG) as RssiMsgSender;
+  components new TimerMilliC() as SendTimer;
+
+  components SendingMoteC as App;
+
+  App.Boot -> MainC;
+  App.SendTimer -> SendTimer;
+  
+  App.RssiMsgSend -> RssiMsgSender;
+  App.RadioControl -> ActiveMessageC;
+}
diff --git a/apps/tutorials/RssiDemo/SendingMote/SendingMoteC.nc b/apps/tutorials/RssiDemo/SendingMote/SendingMoteC.nc
new file mode 100644 (file)
index 0000000..8318cae
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2008 Dimas Abreu Dutra
+ * All rights reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the
+ *   distribution.
+ * - Neither the name of the Stanford University nor the names of
+ *   its contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIMAS ABREU
+ * DUTRA OR HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @author Dimas Abreu Dutra
+ */
+
+#include "ApplicationDefinitions.h"
+#include "RssiDemoMessages.h"
+
+module SendingMoteC {
+  uses interface Boot;
+  uses interface Timer<TMilli> as SendTimer;
+  
+  uses interface AMSend as RssiMsgSend;
+  uses interface SplitControl as RadioControl;
+} implementation {
+  message_t msg;
+  
+  event void Boot.booted(){
+    call RadioControl.start();
+  }
+
+  event void RadioControl.startDone(error_t result){
+    call SendTimer.startPeriodic(SEND_INTERVAL_MS);
+  }
+
+  event void RadioControl.stopDone(error_t result){}
+
+
+  event void SendTimer.fired(){
+    call RssiMsgSend.send(AM_BROADCAST_ADDR, &msg, sizeof(RssiMsg));    
+  }
+
+  event void RssiMsgSend.sendDone(message_t *m, error_t error){}
+}
diff --git a/apps/tutorials/RssiDemo/java/Makefile b/apps/tutorials/RssiDemo/java/Makefile
new file mode 100644 (file)
index 0000000..33fe237
--- /dev/null
@@ -0,0 +1,10 @@
+all: RssiDemo.class
+
+RssiMsg.class: RssiMsg.java
+       javac $<
+
+RssiDemo.class: RssiDemo.java RssiMsg.java
+       javac $^
+
+RssiMsg.java: ../RssiDemoMessages.h
+       mig java -target=null -java-classname=RssiMsg $< RssiMsg -o $@
diff --git a/apps/tutorials/RssiDemo/java/RssiDemo.java b/apps/tutorials/RssiDemo/java/RssiDemo.java
new file mode 100644 (file)
index 0000000..ea3da5f
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * "Copyright (c) 2005 The Regents of the University  of California.  
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and
+ * its documentation for any purpose, without fee, and without written
+ * agreement is hereby granted, provided that the above copyright
+ * notice, the following two paragraphs and the author appear in all
+ * copies of this software.
+ * 
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
+ * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
+ * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
+ * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/*
+ * This is a modified version of TestSerial.java, from apps/tests/TestSerial
+ * from TinyOS 2.x (www.tinyos.net)
+ */
+
+/**
+ * Java-side application for testing the RSSI demo
+ *
+ * @author Phil Levis <pal@cs.berkeley.edu>
+ * @author Dimas Abreu Dutra <dimas@dcc.ufmb.br>
+ * @date April 11 2008
+ */
+
+import java.io.IOException;
+
+import net.tinyos.message.*;
+import net.tinyos.packet.*;
+import net.tinyos.util.*;
+
+public class RssiDemo implements MessageListener {
+
+  private MoteIF moteIF;
+  
+  public RssiDemo(MoteIF moteIF) {
+    this.moteIF = moteIF;
+    this.moteIF.registerListener(new RssiMsg(), this);
+  }
+    
+  public void messageReceived(int to, Message message) {
+    RssiMsg msg = (RssiMsg) message;
+    int source = message.getSerialPacket().get_header_src();
+    System.out.println("Rssi Message received from node " + source + 
+                      ": Rssi = " +  msg.get_rssi());
+  }
+  
+  private static void usage() {
+    System.err.println("usage: RssiDemo [-comm <source>]");
+  }
+  
+  public static void main(String[] args) throws Exception {
+    String source = null;
+    if (args.length == 2) {
+      if (!args[0].equals("-comm")) {
+       usage();
+       System.exit(1);
+      }
+      source = args[1];
+    }
+    else if (args.length != 0) {
+      usage();
+      System.exit(1);
+    }
+    
+    PhoenixSource phoenix;
+    
+    if (source == null) {
+      phoenix = BuildSource.makePhoenix(PrintStreamMessenger.err);
+    }
+    else {
+      phoenix = BuildSource.makePhoenix(source, PrintStreamMessenger.err);
+    }
+
+    MoteIF mif = new MoteIF(phoenix);
+    RssiDemo serial = new RssiDemo(mif);
+  }
+
+
+}