]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Incorporated patches and bug fixes from community (tweaked slightly).
authorscipio <scipio>
Tue, 4 Sep 2007 17:19:22 +0000 (17:19 +0000)
committerscipio <scipio>
Tue, 4 Sep 2007 17:19:22 +0000 (17:19 +0000)
  - Added support for getting RSSI of packets (Razvan Musaliou-E. from
    JHU). Added interface TossimPacket for getting this value without
    needing to know metadata layout. This required changing
    TossimActiveMessageP to TossimActiveMessageC as applications may need
    to wire to it.
  - Tweaked noise simulation so output values are not quantized.
    Tal Rusak from Cornell observed that quantization made borderline
    links behave badly.
  - Modified apps/tests/TestSimComm so that it prints out the RSSI
    of packets.

apps/tests/TestSimComm/TestCommAppC.nc
apps/tests/TestSimComm/TestCommC.nc
tos/lib/tossim/ActiveMessageC.nc
tos/lib/tossim/CpmModelC.nc
tos/lib/tossim/MainC.nc
tos/lib/tossim/TossimActiveMessageC.nc [new file with mode: 0644]
tos/lib/tossim/TossimActiveMessageP.nc [deleted file]
tos/lib/tossim/TossimPacket.nc [new file with mode: 0644]
tos/lib/tossim/TossimRadioMsg.h
tos/lib/tossim/sim_noise.c
tos/lib/tossim/sim_noise.h

index 1ef8638ebccf80062047c42fc54d934682b416ba..5cd94d2e840dcf5e2f2b1b98605d463a6e8447c7 100644 (file)
@@ -52,7 +52,7 @@ implementation {
     AM_TEST  = 5
   };
   
-  components MainC, TestCommC as App, RandomC, ActiveMessageC;
+  components MainC, TestCommC as App, RandomC, ActiveMessageC, TossimActiveMessageC;
   components new TimerMilliC(), new AMSenderC(AM_TEST), new AMReceiverC(AM_TEST);
   
   App.Boot -> MainC.Boot;
@@ -63,6 +63,7 @@ implementation {
   App.Random -> RandomC;
   App.AMPacket -> AMSenderC;
   App.PacketAcknowledgements -> AMSenderC;
+  App.TossimPacket -> TossimActiveMessageC;
 }
 
 
index 0ad5de3f0e6c3357dcc5841e07470eb5917155f6..5aa09d2025974ae6d8ba9ae00e32347ff11e6078 100644 (file)
@@ -47,6 +47,7 @@ module TestCommC {
     interface SplitControl;
     interface AMPacket;
     interface PacketAcknowledgements;
+    interface TossimPacket;
   }
 }
 implementation {
@@ -93,7 +94,7 @@ implementation {
 
 
   event message_t* Receive.receive(message_t* msg, void* p, uint8_t l) {
-    dbg("TestComm", "Received message from %hu @ %s\n", call AMPacket.source(msg), sim_time_string());
+    dbg("TestComm", "Received message from %hu @ %s with strength %hhi\n", call AMPacket.source(msg), sim_time_string(), call TossimPacket.strength(msg));
     return msg;
   }
 }
index e13837d80513d89a45e0e995cf3d5c93d819aa32..d463afa6e7a640a3a0908bdf6b6462b0ae59535d 100644 (file)
@@ -45,7 +45,7 @@ configuration ActiveMessageC {
   }
 }
 implementation {
-  components TossimActiveMessageP as AM;
+  components TossimActiveMessageC as AM;
   components TossimPacketModelC as Network;
 
   components CpmModelC as Model;
index 97076322167319ad062910223d9804d962d66e15..167b6a8574a44df354025c3875cfe355bb7eefd2 100644 (file)
 /**
  *
  * CPM (closest-pattern matching) is a wireless noise simulation model
- * based on statistical extraction from empirical noise data.
- * This model provides far more precise
- * software simulation environment by exploiting time-correlated noise
- * characteristic and shadowing effect as well as path-loss model. For
- * details, please refer to the paper
+ * based on statistical extraction from empirical noise data.  This
+ * model provides far more precise software simulation environment by
+ * exploiting time-correlated noise characteristics. For details,
+ * please refer to the paper
  *
  * "Improving Wireless Simulation through Noise Modeling." HyungJune
  * Lee and Philip Levis, IPSN 2007. You can find a copy at
@@ -60,6 +59,7 @@ implementation {
     sim_time_t end;
     double power;
     double reversePower;
+    int8_t strength;
     bool lost;
     bool ack;
     message_t* msg;
@@ -309,6 +309,12 @@ implementation {
       mine->lost = 1;
     }
     if (!mine->lost) {
+      // Copy this receiver's packet signal strength to the metadata region
+      // of the packet. Note that this packet is actually shared across all
+      // receivers: a higher layer performs the copy.
+      tossim_metadata_t* meta = (tossim_metadata_t*)(&mine->msg->metadata);
+      meta->strength = mine->strength;
+      
       dbg_clear("CpmModelC,SNRLoss", "  -signaling reception\n");
       signal Model.receive(mine->msg);
       if (mine->ack) {
@@ -359,10 +365,14 @@ implementation {
     rcv->end = endTime;
     rcv->power = power;
     rcv->reversePower = reversePower;
+    // The strength of a packet is the sum of the signal and noise. In most cases, this means
+    // the signal. By sampling this here, it assumes that the packet RSSI is sampled at
+    // the beginning of the packet. This is true for the CC2420, but is not true for all
+    // radios. But generalizing seems like complexity for minimal gain at this point.
+    rcv->strength = (int8_t)(floor(10.0 * log(pow(10.0, power/10.0) + pow(10.0, noiseStr/10.0)) / log(10.0)));
     rcv->msg = msg;
     rcv->lost = 0;
     rcv->ack = receive;
-    
     // If I'm off, I never receive the packet, but I need to keep track of
     // it in case I turn on and someone else starts sending me a weaker
     // packet. So I don't set receiving to 1, but I keep track of
index 6babd8687d8978d61be59b9dbf6006a6ba2e2c47..8ffff3cfe23bfe1a294b47bf2f436ff2817c110e 100644 (file)
@@ -61,7 +61,7 @@ implementation {
   // the application does not wire this up to, e.g., ActiveMessageC,
   // the default handlers make sure nothing happens when a script
   // tries to deliver a packet to a node that has no radio stack.
-  components TossimActiveMessageP;
+  components TossimActiveMessageC;
   
 }
 
diff --git a/tos/lib/tossim/TossimActiveMessageC.nc b/tos/lib/tossim/TossimActiveMessageC.nc
new file mode 100644 (file)
index 0000000..47a2921
--- /dev/null
@@ -0,0 +1,264 @@
+// $Id$
+/*
+ * "Copyright (c) 2005 Stanford University. 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 STANFORD UNIVERSITY 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 STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * 
+ * STANFORD UNIVERSITY 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 STANFORD UNIVERSITY
+ * HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
+ * ENHANCEMENTS, OR MODIFICATIONS."
+ */
+
+/**
+ *
+ * The basic chip-independent TOSSIM Active Message layer for radio chips
+ * that do not have simulation support.
+ *
+ * @author Philip Levis
+ * @date December 2 2005
+ */
+
+#include <AM.h>
+
+module TossimActiveMessageC {
+  provides {
+    
+    interface AMSend[am_id_t id];
+    interface Receive[am_id_t id];
+    interface Receive as Snoop[am_id_t id];
+
+    interface Packet;
+    interface AMPacket;
+    interface TossimPacket;
+  }
+  uses {
+    interface TossimPacketModel as Model;
+    command am_addr_t amAddress();
+  }
+}
+implementation {
+
+  message_t buffer;
+  message_t* bufferPointer = &buffer;
+  
+  tossim_header_t* getHeader(message_t* amsg) {
+    return (tossim_header_t*)(amsg->data - sizeof(tossim_header_t));
+  }
+
+  tossim_metadata_t* getMetadata(message_t* amsg) {
+    return (tossim_metadata_t*)(&amsg->metadata);
+  }
+  
+  command error_t AMSend.send[am_id_t id](am_addr_t addr,
+                                         message_t* amsg,
+                                         uint8_t len) {
+    error_t err;
+    tossim_header_t* header = getHeader(amsg);
+    dbg("AM", "AM: Sending packet (id=%hhu, len=%hhu) to %hu\n", id, len, addr);
+    header->type = id;
+    header->dest = addr;
+    header->src = call AMPacket.address();
+    header->length = len;
+    err = call Model.send((int)addr, amsg, len + sizeof(tossim_header_t));
+    return err;
+  }
+
+  command error_t AMSend.cancel[am_id_t id](message_t* msg) {
+    return call Model.cancel(msg);
+  }
+  
+  command uint8_t AMSend.maxPayloadLength[am_id_t id]() {
+    return call Packet.maxPayloadLength();
+  }
+
+  command void* AMSend.getPayload[am_id_t id](message_t* m) {
+    return call Packet.getPayload(m, NULL);
+  }
+
+  command void* Receive.getPayload[am_id_t id](message_t* m, uint8_t* len) {
+    return call Packet.getPayload(m, len);
+  }
+
+  command uint8_t Receive.payloadLength[am_id_t id](message_t* m) {
+    return call Packet.payloadLength(m);
+  }
+  
+  command void* Snoop.getPayload[am_id_t id](message_t* m, uint8_t* len) {
+    return call Packet.getPayload(m, len);
+  }
+
+  command uint8_t Snoop.payloadLength[am_id_t id](message_t* m) {
+    return call Packet.payloadLength(m);
+  }
+  
+  command int8_t TossimPacket.strength(message_t* msg) {
+    return getMetadata(msg)->strength;
+  }
+  
+  event void Model.sendDone(message_t* msg, error_t result) {
+    signal AMSend.sendDone[call AMPacket.type(msg)](msg, result);
+  }
+
+  /* Receiving a packet */
+
+  event void Model.receive(message_t* msg) {
+    uint8_t len;
+    void* payload;
+
+    memcpy(bufferPointer, msg, sizeof(message_t));
+    payload = call Packet.getPayload(bufferPointer, &len);
+
+    if (call AMPacket.isForMe(msg)) {
+      dbg("AM", "Received active message (%p) of type %hhu and length %hhu for me @ %s.\n", bufferPointer, call AMPacket.type(bufferPointer), len, sim_time_string());
+      bufferPointer = signal Receive.receive[call AMPacket.type(bufferPointer)](bufferPointer, payload, len);
+    }
+    else {
+      dbg("AM", "Snooped on active message of type %hhu and length %hhu for %hu @ %s.\n", call AMPacket.type(bufferPointer), len, call AMPacket.destination(bufferPointer), sim_time_string());
+      bufferPointer = signal Snoop.receive[call AMPacket.type(bufferPointer)](bufferPointer, payload, len);
+    }
+  }
+
+  event bool Model.shouldAck(message_t* msg) {
+    tossim_header_t* header = getHeader(msg);
+    if (header->dest == call amAddress()) {
+      dbg("Acks", "Received packet addressed to me so ack it\n");
+      return TRUE;
+    }
+    return FALSE;
+  }
+  
+  command am_addr_t AMPacket.address() {
+    return call amAddress();
+  }
+  command am_addr_t AMPacket.destination(message_t* amsg) {
+    tossim_header_t* header = getHeader(amsg);
+    return header->dest;
+  }
+
+  command void AMPacket.setDestination(message_t* amsg, am_addr_t addr) {
+    tossim_header_t* header = getHeader(amsg);
+    header->dest = addr;
+  }
+
+  command am_addr_t AMPacket.source(message_t* amsg) {
+    tossim_header_t* header = getHeader(amsg);
+    return header->src;
+  }
+
+  command void AMPacket.setSource(message_t* amsg, am_addr_t addr) {
+    tossim_header_t* header = getHeader(amsg);
+    header->src = addr;
+  }
+  
+  command bool AMPacket.isForMe(message_t* amsg) {
+    return (call AMPacket.destination(amsg) == call AMPacket.address() ||
+           call AMPacket.destination(amsg) == AM_BROADCAST_ADDR);
+  }
+
+  command am_id_t AMPacket.type(message_t* amsg) {
+    tossim_header_t* header = getHeader(amsg);
+    return header->type;
+  }
+
+  command void AMPacket.setType(message_t* amsg, am_id_t t) {
+    tossim_header_t* header = getHeader(amsg);
+    header->type = t;
+  }
+  command void Packet.clear(message_t* msg) {}
+  
+  command uint8_t Packet.payloadLength(message_t* msg) {
+    return getHeader(msg)->length;
+  }
+  
+  command void Packet.setPayloadLength(message_t* msg, uint8_t len) {
+    getHeader(msg)->length = len;
+  }
+  
+  command uint8_t Packet.maxPayloadLength() {
+    return TOSH_DATA_LENGTH;
+  }
+  
+  command void* Packet.getPayload(message_t* msg, uint8_t* len) {
+    if (len != NULL) {
+      *len = call Packet.payloadLength(msg);
+    }
+    return msg->data;
+  }
+
+  command am_group_t AMPacket.group(message_t* amsg) {
+    tossim_header_t* header = getHeader(amsg);
+    return header->group;
+  }
+  
+  command void AMPacket.setGroup(message_t* msg, am_group_t group) {
+    tossim_header_t* header = getHeader(msg);
+    header->group = group;
+  }
+
+  command am_group_t AMPacket.localGroup() {
+    return TOS_AM_GROUP;
+  }
+
+ default event message_t* Receive.receive[am_id_t id](message_t* msg, void* payload, uint8_t len) {
+    return msg;
+  }
+  
+  default event message_t* Snoop.receive[am_id_t id](message_t* msg, void* payload, uint8_t len) {
+    return msg;
+  }
+
+ default event void AMSend.sendDone[uint8_t id](message_t* msg, error_t err) {
+   return;
+ }
+
+ default command error_t Model.send(int node, message_t* msg, uint8_t len) {
+   return FAIL;
+ }
+
+ default command error_t Model.cancel(message_t* msg) {
+   return FAIL;
+ }
+
+ default command am_addr_t amAddress() {
+   return 0;
+ }
+  
+ void active_message_deliver_handle(sim_event_t* evt) {
+   message_t* m = (message_t*)evt->data;
+   dbg("Packet", "Delivering packet to %i at %s\n", (int)sim_node(), sim_time_string());
+   signal Model.receive(m);
+ }
+ sim_event_t* allocate_deliver_event(int node, message_t* msg, sim_time_t t) {
+   sim_event_t* evt = (sim_event_t*)malloc(sizeof(sim_event_t));
+   evt->mote = node;
+   evt->time = t;
+   evt->handle = active_message_deliver_handle;
+   evt->cleanup = sim_queue_cleanup_event;
+   evt->cancelled = 0;
+   evt->force = 0;
+   evt->data = msg;
+   return evt;
+ }
+ void active_message_deliver(int node, message_t* msg, sim_time_t t) __attribute__ ((C, spontaneous)) {
+   sim_event_t* evt = allocate_deliver_event(node, msg, t);
+   sim_queue_insert(evt);
+ }
+}
diff --git a/tos/lib/tossim/TossimActiveMessageP.nc b/tos/lib/tossim/TossimActiveMessageP.nc
deleted file mode 100644 (file)
index d55e7ce..0000000
+++ /dev/null
@@ -1,255 +0,0 @@
-// $Id$
-/*
- * "Copyright (c) 2005 Stanford University. 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 STANFORD UNIVERSITY 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 STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- * 
- * STANFORD UNIVERSITY 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 STANFORD UNIVERSITY
- * HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
- * ENHANCEMENTS, OR MODIFICATIONS."
- */
-
-/**
- *
- * The basic chip-independent TOSSIM Active Message layer for radio chips
- * that do not have simulation support.
- *
- * @author Philip Levis
- * @date December 2 2005
- */
-
-#include <AM.h>
-
-module TossimActiveMessageP {
-  provides {
-    
-    interface AMSend[am_id_t id];
-    interface Receive[am_id_t id];
-    interface Receive as Snoop[am_id_t id];
-
-    interface Packet;
-    interface AMPacket;
-  }
-  uses {
-    interface TossimPacketModel as Model;
-    command am_addr_t amAddress();
-  }
-}
-implementation {
-
-  message_t buffer;
-  message_t* bufferPointer = &buffer;
-  
-  tossim_header_t* getHeader(message_t* amsg) {
-    return (tossim_header_t*)(amsg->data - sizeof(tossim_header_t));
-  }
-  
-  command error_t AMSend.send[am_id_t id](am_addr_t addr,
-                                         message_t* amsg,
-                                         uint8_t len) {
-    error_t err;
-    tossim_header_t* header = getHeader(amsg);
-    dbg("AM", "AM: Sending packet (id=%hhu, len=%hhu) to %hu\n", id, len, addr);
-    header->type = id;
-    header->dest = addr;
-    header->src = call AMPacket.address();
-    header->length = len;
-    err = call Model.send((int)addr, amsg, len + sizeof(tossim_header_t));
-    return err;
-  }
-
-  command error_t AMSend.cancel[am_id_t id](message_t* msg) {
-    return call Model.cancel(msg);
-  }
-  
-  command uint8_t AMSend.maxPayloadLength[am_id_t id]() {
-    return call Packet.maxPayloadLength();
-  }
-
-  command void* AMSend.getPayload[am_id_t id](message_t* m) {
-    return call Packet.getPayload(m, NULL);
-  }
-
-  command void* Receive.getPayload[am_id_t id](message_t* m, uint8_t* len) {
-    return call Packet.getPayload(m, len);
-  }
-
-  command uint8_t Receive.payloadLength[am_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
-  
-  command void* Snoop.getPayload[am_id_t id](message_t* m, uint8_t* len) {
-    return call Packet.getPayload(m, len);
-  }
-
-  command uint8_t Snoop.payloadLength[am_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
-  
-  event void Model.sendDone(message_t* msg, error_t result) {
-    signal AMSend.sendDone[call AMPacket.type(msg)](msg, result);
-  }
-
-  /* Receiving a packet */
-
-  event void Model.receive(message_t* msg) {
-    uint8_t len;
-    void* payload;
-
-    memcpy(bufferPointer, msg, sizeof(message_t));
-    payload = call Packet.getPayload(bufferPointer, &len);
-
-    if (call AMPacket.isForMe(msg)) {
-      dbg("AM", "Received active message (%p) of type %hhu and length %hhu for me @ %s.\n", bufferPointer, call AMPacket.type(bufferPointer), len, sim_time_string());
-      bufferPointer = signal Receive.receive[call AMPacket.type(bufferPointer)](bufferPointer, payload, len);
-    }
-    else {
-      dbg("AM", "Snooped on active message of type %hhu and length %hhu for %hu @ %s.\n", call AMPacket.type(bufferPointer), len, call AMPacket.destination(bufferPointer), sim_time_string());
-      bufferPointer = signal Snoop.receive[call AMPacket.type(bufferPointer)](bufferPointer, payload, len);
-    }
-  }
-
-  event bool Model.shouldAck(message_t* msg) {
-    tossim_header_t* header = getHeader(msg);
-    if (header->dest == call amAddress()) {
-      dbg("Acks", "Received packet addressed to me so ack it\n");
-      return TRUE;
-    }
-    return FALSE;
-  }
-  
-  command am_addr_t AMPacket.address() {
-    return call amAddress();
-  }
-  command am_addr_t AMPacket.destination(message_t* amsg) {
-    tossim_header_t* header = getHeader(amsg);
-    return header->dest;
-  }
-
-  command void AMPacket.setDestination(message_t* amsg, am_addr_t addr) {
-    tossim_header_t* header = getHeader(amsg);
-    header->dest = addr;
-  }
-
-  command am_addr_t AMPacket.source(message_t* amsg) {
-    tossim_header_t* header = getHeader(amsg);
-    return header->src;
-  }
-
-  command void AMPacket.setSource(message_t* amsg, am_addr_t addr) {
-    tossim_header_t* header = getHeader(amsg);
-    header->src = addr;
-  }
-  
-  command bool AMPacket.isForMe(message_t* amsg) {
-    return (call AMPacket.destination(amsg) == call AMPacket.address() ||
-           call AMPacket.destination(amsg) == AM_BROADCAST_ADDR);
-  }
-
-  command am_id_t AMPacket.type(message_t* amsg) {
-    tossim_header_t* header = getHeader(amsg);
-    return header->type;
-  }
-
-  command void AMPacket.setType(message_t* amsg, am_id_t t) {
-    tossim_header_t* header = getHeader(amsg);
-    header->type = t;
-  }
-  command void Packet.clear(message_t* msg) {}
-  
-  command uint8_t Packet.payloadLength(message_t* msg) {
-    return getHeader(msg)->length;
-  }
-  
-  command void Packet.setPayloadLength(message_t* msg, uint8_t len) {
-    getHeader(msg)->length = len;
-  }
-  
-  command uint8_t Packet.maxPayloadLength() {
-    return TOSH_DATA_LENGTH;
-  }
-  
-  command void* Packet.getPayload(message_t* msg, uint8_t* len) {
-    if (len != NULL) {
-      *len = call Packet.payloadLength(msg);
-    }
-    return msg->data;
-  }
-
-  command am_group_t AMPacket.group(message_t* amsg) {
-    tossim_header_t* header = getHeader(amsg);
-    return header->group;
-  }
-  
-  command void AMPacket.setGroup(message_t* msg, am_group_t group) {
-    tossim_header_t* header = getHeader(msg);
-    header->group = group;
-  }
-
-  command am_group_t AMPacket.localGroup() {
-    return TOS_AM_GROUP;
-  }
-
- default event message_t* Receive.receive[am_id_t id](message_t* msg, void* payload, uint8_t len) {
-    return msg;
-  }
-  
-  default event message_t* Snoop.receive[am_id_t id](message_t* msg, void* payload, uint8_t len) {
-    return msg;
-  }
-
- default event void AMSend.sendDone[uint8_t id](message_t* msg, error_t err) {
-   return;
- }
-
- default command error_t Model.send(int node, message_t* msg, uint8_t len) {
-   return FAIL;
- }
-
- default command error_t Model.cancel(message_t* msg) {
-   return FAIL;
- }
-
- default command am_addr_t amAddress() {
-   return 0;
- }
-  
- void active_message_deliver_handle(sim_event_t* evt) {
-   message_t* m = (message_t*)evt->data;
-   dbg("Packet", "Delivering packet to %i at %s\n", (int)sim_node(), sim_time_string());
-   signal Model.receive(m);
- }
- sim_event_t* allocate_deliver_event(int node, message_t* msg, sim_time_t t) {
-   sim_event_t* evt = (sim_event_t*)malloc(sizeof(sim_event_t));
-   evt->mote = node;
-   evt->time = t;
-   evt->handle = active_message_deliver_handle;
-   evt->cleanup = sim_queue_cleanup_event;
-   evt->cancelled = 0;
-   evt->force = 0;
-   evt->data = msg;
-   return evt;
- }
- void active_message_deliver(int node, message_t* msg, sim_time_t t) __attribute__ ((C, spontaneous)) {
-   sim_event_t* evt = allocate_deliver_event(node, msg, t);
-   sim_queue_insert(evt);
- }
-}
diff --git a/tos/lib/tossim/TossimPacket.nc b/tos/lib/tossim/TossimPacket.nc
new file mode 100644 (file)
index 0000000..7c3f35b
--- /dev/null
@@ -0,0 +1,46 @@
+// $Id$
+/*
+ * Copyright (c) 2007 Stanford University.
+ * 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 STANFORD
+ * UNIVERSITY OR ITS 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.
+ */
+
+/**
+ * Metadata interface for TOSSIM packets.
+ *
+ * @author Philip Levis
+ * @date   September 4 2007
+ */ 
+
+
+#include <TinyError.h>
+#include <message.h>
+
+interface TossimPacket {
+  command int8_t strength(message_t* msg);
+}
index 27355e8fbb52ffc052da16b2d8ce79dbeac095ed..e9df8dbcd30f5801b37833efbce826f418475813 100644 (file)
@@ -16,7 +16,7 @@ typedef nx_struct tossim_footer {
 } tossim_footer_t;
 
 typedef nx_struct tossim_metadata {
-  nx_uint16_t strength;
+  nx_int8_t strength;
   nx_uint8_t ack;
   nx_uint16_t time;
 } tossim_metadata_t;
index 73cfe854805b3c0599f0aadf205b50b58a9c4a65..7744b0d97b59d3f02df879880ea52901b932b733 100644 (file)
 #include "hashtable.h"
 #include "sim_noise.h"
 
+//Tal Debug, to count how often simulation hits the one match case
+int numCase1 = 0;
+int numCase2 = 0;
+int numTotal = 0;
+//End Tal Debug
+
 uint32_t FreqKeyNum = 0;
 
 sim_noise_node_t noiseData[TOSSIM_MAX_NODES];
@@ -145,7 +151,7 @@ void sim_noise_add(uint16_t node_id, char noise)__attribute__ ((C, spontaneous))
     memset((void *)noise_hash->elements, 0, sizeof(char)*noise_hash->size);
 
     noise_hash->flag = 0;
-    for(i=0; i<NOISE_BIN_SIZE; i++) {
+    for(i=0; i<NOISE_NUM_VALUES; i++) {
        noise_hash->dist[i] = 0;
     }
     hashtable_insert(pnoiseTable, key, noise_hash);
@@ -171,6 +177,7 @@ void sim_noise_add(uint16_t node_id, char noise)__attribute__ ((C, spontaneous))
     }
 
   noise_hash->elements[noise_hash->numElements] = noise;
+//  printf("I hear noise %i\n", noise);
   noise_hash->numElements++;
 }
 
@@ -185,23 +192,27 @@ void sim_noise_dist(uint16_t node_id)__attribute__ ((C, spontaneous))
   sim_noise_hash_t *noise_hash;
   noise_hash = (sim_noise_hash_t *)hashtable_search(pnoiseTable, key);
 
+//  noise_hash->flag;
+
   if (noise_hash->flag == 1)
     return;
 
-  for (i=0; i < NOISE_BIN_SIZE; i++) {
+  for (i=0; i < NOISE_NUM_VALUES; i++) {
     noise_hash->dist[i] = 0.0;
   }
   
   for (i=0; i< noise_hash->numElements; i++)
     {
       float val;
-      bin = search_bin_num(noise_hash->elements[i]) - 1;
+      dbg("Noise_output", "Noise is found to be %i\n", noise_hash->elements[i]);
+      bin = noise_hash->elements[i] - NOISE_MIN_QUANTIZE; //search_bin_num(noise_hash->elements[i]) - 1;
+//      printf("Bin %i, Noise %i\n", bin, (NOISE_MIN_QUANTIZE + bin));
       val = noise_hash->dist[bin];
       val += (float)1.0;
       noise_hash->dist[bin] = val;
     }
 
-  for (i=0; i < NOISE_BIN_SIZE ; i++)
+  for (i=0; i < NOISE_NUM_VALUES ; i++)
     {
       noise_hash->dist[i] = (noise_hash->dist[i])/(noise_hash->numElements);
       cmf += noise_hash->dist[i];
@@ -241,7 +252,7 @@ void makePmfDistr(uint16_t node_id)__attribute__ ((C, spontaneous))
 
   FreqKeyNum = 0;
   for(i=0; i<NOISE_HISTORY; i++) {
-    pKey[i] = search_bin_num(noiseData[node_id].noiseTrace[i]);
+    pKey[i] = /* noiseData[node_id].noiseTrace[i]; // */ search_bin_num(noiseData[node_id].noiseTrace[i]);
   }
   sim_noise_dist(node_id);
   arrangeKey(node_id);
@@ -249,7 +260,7 @@ void makePmfDistr(uint16_t node_id)__attribute__ ((C, spontaneous))
     if (i == NOISE_HISTORY) {
       //printf("Inserting first element.\n");
     }
-    pKey[NOISE_HISTORY-1] = search_bin_num(noiseData[node_id].noiseTrace[i]);
+    pKey[NOISE_HISTORY-1] = /*noiseData[node_id].noiseTrace[i]; //*/ search_bin_num(noiseData[node_id].noiseTrace[i]);
     sim_noise_dist(node_id);
     arrangeKey(node_id);
   }
@@ -280,6 +291,9 @@ char sim_noise_gen(uint16_t node_id)__attribute__ ((C, spontaneous))
   noise_hash = (sim_noise_hash_t *)hashtable_search(pnoiseTable, pKey);
 
   if (noise_hash == NULL) {
+    //Tal Debug
+    dbg("Noise_c", "Did not pattern match");
+    //End Tal Debug
     sim_noise_alarm();
     noise = 0;
     dbg_clear("HASH", "(N)Noise\n");
@@ -296,13 +310,28 @@ char sim_noise_gen(uint16_t node_id)__attribute__ ((C, spontaneous))
   
   dbg("HASH", "Printing Key\n");
   dbg("HASH", "noise_hash->numElements=%d\n", noise_hash->numElements);
+  
+  //Tal Debug
+  numTotal++;
+  //End Tal Debug
+
   if (noise_hash->numElements == 1) {
     noise = noise_hash->elements[0];
-    dbg_clear("HASH", "(E)Noise = %d\n", noise);                       
+    dbg_clear("HASH", "(E)Noise = %d\n", noise);
+    //Tal Debug
+    numCase1++;
+    dbg("Noise_c", "In case 1: %i of %i\n", numCase1, numTotal);
+    //End Tal Debug
+    dbg("NoiseAudit", "Noise: %i\n", noise);
     return noise;
   }
-  
-  for (i = 0; i < NOISE_BIN_SIZE - 1; i++) {
+
+  //Tal Debug
+  numCase2++;
+  dbg("Noise_c", "In case 2: %i of %i\n", numCase2, numTotal);
+  //End Tal Debug
+  for (i = 0; i < NOISE_NUM_VALUES - 1; i++) {
     dbg("HASH", "IN:for i=%d\n", i);
     if (i == 0) {      
       if (ranNum <= noise_hash->dist[i]) {
@@ -320,8 +349,8 @@ char sim_noise_gen(uint16_t node_id)__attribute__ ((C, spontaneous))
   }
   dbg("HASH", "OUT:for i=%d\n", i);
   
-  noise = search_noise_from_bin_num(i+1);
-  dbg_clear("HASH", "(B)Noise = %d\n", noise);
+  noise = NOISE_MIN_QUANTIZE + i; //TODO search_noise_from_bin_num(i+1);
+  dbg("NoiseAudit", "Noise: %i\n", noise);             
   return noise;
 }
 
@@ -372,6 +401,7 @@ char sim_noise_generate(uint16_t node_id, uint32_t cur_t)__attribute__ ((C, spon
   if (noise == 0) {
     dbg("HashZeroDebug", "Generated noise of zero.\n");
   }
+//  printf("%i\n", noise);
   return noise;
 }
 
@@ -397,4 +427,3 @@ void makeNoiseModel(uint16_t node_id)__attribute__ ((C, spontaneous)) {
   noiseData[node_id].generated = 1;
 }
 
-
index 6c9ddfe173301cc77db2988803dd0fd389b26939..c5387254f3360fae300b038cdea1f46a2e803be2 100644 (file)
@@ -40,8 +40,6 @@
 extern "C" {
 #endif
 
-// BIN_SIZE (the number of bins) has a + 1 in case the range is not
-// evenly divisible by INTERVAL -pal 5.aug.07
 enum {
   NOISE_MIN = -115,
   NOISE_MAX = -5,
@@ -52,6 +50,7 @@ enum {
   NOISE_DEFAULT_ELEMENT_SIZE = 8,
   NOISE_HASHTABLE_SIZE = 128,
   NOISE_MIN_TRACE = 128, 
+  NOISE_NUM_VALUES = NOISE_MAX - NOISE_MIN + 1,    //TODO check the + 1, also in NOISE_BIN_SIZE above in the inner parens
 };
   
 typedef struct sim_noise_hash_t {
@@ -60,7 +59,7 @@ typedef struct sim_noise_hash_t {
   int size;
   char *elements;
   char flag;
-  float dist[NOISE_BIN_SIZE];
+  float dist[NOISE_NUM_VALUES];
 } sim_noise_hash_t;
 
 typedef struct sim_noise_node_t {
@@ -86,4 +85,3 @@ void sim_noise_create_model(uint16_t node_id);
 #endif
   
 #endif // _SIM_NOISE_HASH_H_
-