]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Fixed CpmModelP to correctly lose packets caused by subsequent transmissions.
authorscipio <scipio>
Thu, 17 May 2007 22:03:59 +0000 (22:03 +0000)
committerscipio <scipio>
Thu, 17 May 2007 22:03:59 +0000 (22:03 +0000)
Adjust constants in CSMA to reflect the current CC2420 stack.

tos/lib/tossim/CpmModelC.nc
tos/lib/tossim/TossimActiveMessageP.nc
tos/lib/tossim/sim_csma.h

index bfa4f60f9ba9098503e80d46167f0f071057420d..e6f097c4cc0b44691be46257b27bb253c183acb5 100644 (file)
@@ -248,14 +248,13 @@ implementation {
     else {
       dbgerror("CpmModelC", "Incoming packet list structure is corrupted: entry is not the head and no entry points to it.\n");
     }
-    
+    dbg("CpmModelC,SNRLoss", "Packet from %i to %i\n", (int)mine->source, (int)sim_node());
     if (!checkReceive(mine)) {
-      dbg("CpmModelC", "Lost packet as SNR was too low.\n");
+      dbg("CpmModelC,SNRLoss", " - lost packet from as SNR was too low.\n");
       mine->lost = 1;
     }
-    
     if (!mine->lost) {
-      dbg_clear("CpmModelC", "  -signaling reception, ");
+      dbg_clear("CpmModelC,SNRLoss", "  -signaling reception\n");
       signal Model.receive(mine->msg);
       if (mine->ack) {
         dbg_clear("CpmModelC", " acknowledgment requested, ");
@@ -273,7 +272,7 @@ implementation {
     } // If the packet was lost, then we're searching for new packets again
     else {
       receiving = 0;
-      dbg_clear("CpmModelC", "  -packet was lost.\n");
+      dbg_clear("CpmModelC,SNRLoss", "  -packet was lost.\n");
     }
     free(mine);
   }
@@ -282,6 +281,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 noiseStr = packetNoise(rcv);
     rcv->source = source;
@@ -302,18 +302,31 @@ implementation {
       rcv->lost = 1;
     }
     else if (!shouldReceive(power - noiseStr)) {
+      dbg("CpmModelC,SNRLoss", "Lost packet from %i to %i due to SNR being too low (%i)\n", source, sim_node(), (int)(power - noiseStr));
       rcv->lost = 1;
     }
     else if (receiving) {
+      dbg("CpmModelC,SNRLoss", "Lost packet from %i due to %i being mid-reception\n", source, sim_node());
       rcv->lost = 1;
     }
     else {
       receiving = 1;
-      rcv->next = outstandingReceptionHead;
-      outstandingReceptionHead = rcv;
-      evt = allocate_receive_event(endTime, rcv);
-      sim_queue_insert(evt);
     }
+
+    list = outstandingReceptionHead;
+    while (list != NULL) {
+      if (!shouldReceive(list->power - rcv->power)) {
+       dbg("Gain,SNRLoss", "Going to lose packet from %i with signal %lf as am receiving a packet from %i with signal %lf\n", list->source, list->power, source, rcv->power);
+       list->lost = 1;
+      }
+      list = list->next;
+    }
+    
+    rcv->next = outstandingReceptionHead;
+    outstandingReceptionHead = rcv;
+    evt = allocate_receive_event(endTime, rcv);
+    sim_queue_insert(evt);
+
   }
   
   void sim_gain_put(int dest, message_t* msg, sim_time_t endTime, bool receive, double power) {
index f31aaf6fc4390ec19204eb52659d9ac0fc8a1283..79cb9da170e7a4bb5633d7ca81d947b5befbeda5 100644 (file)
@@ -125,7 +125,7 @@ implementation {
   event bool Model.shouldAck(message_t* msg) {
     tossim_header_t* header = getHeader(msg);
     if (header->dest == call amAddress()) {
-      dbg("Acks", "addressed to me so ack it,");
+      dbg("Acks", "Received packet addressed to me so ack it\n");
       return TRUE;
     }
     return FALSE;
index 4795f8ea120455fe991fb5b74a69bf854675555e..977c2047237ce11ffb5cf5867b4b63a41d42983d 100644 (file)
@@ -35,7 +35,7 @@
 #define SIM_CSMA_H_INCLUDED
 
 #ifndef SIM_CSMA_INIT_HIGH
-#define SIM_CSMA_INIT_HIGH 400
+#define SIM_CSMA_INIT_HIGH 640
 #endif 
 
 #ifndef SIM_CSMA_INIT_LOW
 #endif
 
 #ifndef SIM_CSMA_MIN_FREE_SAMPLES
-#define SIM_CSMA_MIN_FREE_SAMPLES 2
+#define SIM_CSMA_MIN_FREE_SAMPLES 1
 #endif
 
 // 500 us ~= 32 symbols
 #ifndef SIM_CSMA_RXTX_DELAY 
-#define SIM_CSMA_RXTX_DELAY 32
+#define SIM_CSMA_RXTX_DELAY 11
 #endif
 
 // 12 symbol delay + 11 bytes length * (2 bytes/symbol) = 34 symbols