]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/tossim/UscGainInterferenceModelC.nc
Incorporate new modular tos-bsl.
[tinyos-2.x.git] / tos / lib / tossim / UscGainInterferenceModelC.nc
index 71a18bc54c2ce0f4b63764e5969185f7ef301a18..284d2d6329067361e177844172415551f8ad53b3 100644 (file)
@@ -134,18 +134,23 @@ implementation {
     receive_message_t* predecessor = NULL;
     receive_message_t* list = outstandingReceptionHead;
     dbg("Gain", "Handling reception event @ %s.\n", sim_time_string());
+    // Scan the list for the node which precedes the one pointing
+    // to the received packet.
     while (list != NULL) {
       if (list->next == mine) {
        predecessor = list;
       }
       if (list != mine) {
-       if ((list->power - sim_gain_sensitivity()) < heardSignal()) {
-         dbg("Gain", "Lost packet from %i as power %lf was too low\n", list->source, list->power);
+       if ((list->power - sim_gain_sensitivity()) < mine->power) {
+         dbg("Gain", "Lost packet from %i as I concurrently received a packet stronger than %lf\n", list->source, list->power);
          list->lost = 1;
        }
       }
       list = list->next;
     }
+    // Remove the received packet from the oustanding list by updating
+    // the list pointers: A->B->C becomes A->C. If the received packet
+    // is the head of the queue, then update the head pointer.
     if (predecessor) {
       predecessor->next = mine->next;
     }
@@ -155,9 +160,12 @@ implementation {
     else {
       dbgerror("Gain", "Incoming packet list structure is corrupted: entry is not the head and no entry points to it.\n");
     }
-
+    // Because the packet has been removed from the queue, it is not
+    // included in heardSignal(): this line tests if the Signal of the
+    // packet is above the threshold over the Noise of all other RF
+    // energy sources (local noise, other packets, etc.).
     if ((mine->power - sim_gain_sensitivity()) < heardSignal()) {
-      dbg("Gain", "Lost packet as power %lf was too low\n", mine->power);
+      dbg("Gain", "Lost packet from %i as its power %lf was below sensitivity threshold\n", mine->source, mine->power);
       mine->lost = 1;
     }
     
@@ -190,6 +198,7 @@ implementation {
   // enqueue a receive event to figure out what happens.
   void enqueue_receive_event(int source, sim_time_t endTime, message_t* msg, bool receive, double power) {
     sim_event_t* evt;
+    receive_message_t* list;
     receive_message_t* rcv = allocate_receive_message();
     double sigStr = heardSignal();
     rcv->source = source;
@@ -208,19 +217,27 @@ implementation {
       dbg("Gain", "Lost packet from %i due to %i being off\n", source, sim_node());
       rcv->lost = 1;
     }
-    else {
-      if ((sigStr + sim_gain_sensitivity()) >= power) {
-       dbg("Gain", "Lost packet from %i due to power being too low (%f >= %f)\n", source, sigStr, power);
-       rcv->lost = 1;
-      }
-      else if (receiving) {
-       dbg("Gain", "Lost packet from %i due to being in the midst of a reception.\n", source);
-       rcv->lost = 1;
-      }
-      if (power >= sim_gain_noise_mean(sim_node()) + sim_gain_noise_range(sim_node())) {
-       receiving = 1;
+    else if ((sigStr + sim_gain_sensitivity()) >= power) {
+      dbg("Gain", "Lost packet from %i due to power being below reception threshold (%f >= %f)\n", source, sigStr, power);
+      rcv->lost = 1;
+    }
+    else if (receiving) {
+      dbg("Gain", "Lost packet from %i due to being in the midst of a reception.\n", source);
+      rcv->lost = 1;
+    }
+    else { // We are on, are not receiving a packet, and the packet is above the noise floor
+      receiving = 1;
+    }
+
+    list = outstandingReceptionHead;
+    while (list != NULL) {
+      if ((list->power - sim_gain_sensitivity()) < power) {
+       dbg("Gain", "Lost packet from %i as I concurrently received a packet from %i stronger than %lf\n", list->source, source, list->power);
+       list->lost = 1;
       }
+      list = list->next;
     }
+    
     rcv->next = outstandingReceptionHead;
     
     outstandingReceptionHead = rcv;