]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - apps/BaseStation/BaseStationP.nc
copy the group id from the radio to the serial (it was always 0x00)
[tinyos-2.x.git] / apps / BaseStation / BaseStationP.nc
index a918a6db87437fd9ecb53e5d3383ffb54da3fd14..908e395d08c072d534887b8ccfa8d8220ce901d5 100644 (file)
 /* 
  * 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
+ * ID compiled into the BaseStation, and messages moving from radio to
  * serial will be filtered by that same group id.
  */
 
 #include "AM.h"
 #include "Serial.h"
 
-module BaseStationP {
+module BaseStationP @safe() {
   uses {
     interface Boot;
     interface SplitControl as SerialControl;
@@ -75,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;
 
@@ -131,7 +131,7 @@ implementation
 
   uint8_t count = 0;
 
-  message_t* receive(message_t* msg, void* payload, uint8_t len);
+  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,
@@ -177,8 +177,9 @@ implementation
   task void uartSendTask() {
     uint8_t len;
     am_id_t id;
-    am_addr_t addr;
+    am_addr_t addr, src;
     message_t* msg;
+    am_group_t grp;
     atomic
       if (uartIn == uartOut && !uartFull)
        {
@@ -190,6 +191,11 @@ implementation
     tmpLen = len = call RadioPacket.payloadLength(msg);
     id = call RadioAMPacket.type(msg);
     addr = call RadioAMPacket.destination(msg);
+    src = call RadioAMPacket.source(msg);
+    grp = call RadioAMPacket.group(msg);
+    call UartPacket.clear(msg);
+    call UartAMPacket.setSource(msg, src);
+    call UartAMPacket.setGroup(msg, grp);
 
     if (call UartSend.send[id](addr, uartQueue[uartOut], len) == SUCCESS)
       call Leds.led1Toggle();
@@ -251,7 +257,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
@@ -264,7 +270,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