]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - apps/BaseStation/BaseStationP.nc
Update tos-bsl for win32 python
[tinyos-2.x.git] / apps / BaseStation / BaseStationP.nc
index ff1c2f564277e0da3cfa18fa16cb99634237d111..2e647c7f83c6429b89f9c2ab7de285cc82cd507f 100644 (file)
@@ -46,7 +46,7 @@
 #include "AM.h"
 #include "Serial.h"
 
-module BaseStationP {
+module BaseStationP @safe() {
   uses {
     interface Boot;
     interface SplitControl as SerialControl;
@@ -59,6 +59,7 @@ module BaseStationP {
     
     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;
 
@@ -74,12 +75,12 @@ implementation
   };
 
   message_t  uartQueueBufs[UART_QUEUE_LEN];
-  message_t  *uartQueue[UART_QUEUE_LEN];
+  message_t  * ONE_NOK uartQueue[UART_QUEUE_LEN];
   uint8_t    uartIn, uartOut;
   bool       uartBusy, uartFull;
 
   message_t  radioQueueBufs[RADIO_QUEUE_LEN];
-  message_t  *radioQueue[RADIO_QUEUE_LEN];
+  message_t  * ONE_NOK radioQueue[RADIO_QUEUE_LEN];
   uint8_t    radioIn, radioOut;
   bool       radioBusy, radioFull;
 
@@ -129,9 +130,22 @@ implementation
   event void RadioControl.stopDone(error_t error) {}
 
   uint8_t count = 0;
+
+  message_t* ONE receive(message_t* ONE msg, void* payload, uint8_t len);
+  
+  event message_t *RadioSnoop.receive[am_id_t id](message_t *msg,
+                                                   void *payload,
+                                                   uint8_t len) {
+    return receive(msg, payload, len);
+  }
+  
   event message_t *RadioReceive.receive[am_id_t id](message_t *msg,
                                                    void *payload,
                                                    uint8_t len) {
+    return receive(msg, payload, len);
+  }
+
+  message_t* receive(message_t *msg, void *payload, uint8_t len) {
     message_t *ret = msg;
 
     atomic {
@@ -163,7 +177,7 @@ implementation
   task void uartSendTask() {
     uint8_t len;
     am_id_t id;
-    am_addr_t addr;
+    am_addr_t addr, src;
     message_t* msg;
     atomic
       if (uartIn == uartOut && !uartFull)
@@ -176,6 +190,9 @@ implementation
     tmpLen = len = call RadioPacket.payloadLength(msg);
     id = call RadioAMPacket.type(msg);
     addr = call RadioAMPacket.destination(msg);
+    src = call RadioAMPacket.source(msg);
+    call UartPacket.clear(msg);
+    call UartAMPacket.setSource(msg, src);
 
     if (call UartSend.send[id](addr, uartQueue[uartOut], len) == SUCCESS)
       call Leds.led1Toggle();
@@ -237,7 +254,7 @@ implementation
   task void radioSendTask() {
     uint8_t len;
     am_id_t id;
-    am_addr_t addr;
+    am_addr_t addr,source;
     message_t* msg;
     
     atomic
@@ -250,7 +267,12 @@ implementation
     msg = radioQueue[radioOut];
     len = call UartPacket.payloadLength(msg);
     addr = call UartAMPacket.destination(msg);
+    source = call UartAMPacket.source(msg);
     id = call UartAMPacket.type(msg);
+
+    call RadioPacket.clear(msg);
+    call RadioAMPacket.setSource(msg, source);
+    
     if (call RadioSend.send[id](addr, msg, len) == SUCCESS)
       call Leds.led0Toggle();
     else