]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - apps/RadioSenseToLeds/RadioSenseToLedsC.nc
Merge TinyOS 2.1.1 into master.
[tinyos-2.x.git] / apps / RadioSenseToLeds / RadioSenseToLedsC.nc
index 53efff01a8ce4786bb37171d7d8022189ad42702..dd8710b2dde67fd34de3d4e526cff89f2fcb7da6 100644 (file)
  * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, 
  * 94704.  Attention:  Intel License Inquiry.
  */
-
-/**
- *  Implementation of the OSKI RadioSenseToLeds application. This
- *  application periodically broadcasts a reading from its platform's
- *  demo sensor, and displays broadcasts it hears on its LEDs. It displays
- *  the two most signficant bits of the value on LEDs 1 and 2; if there is
- *  an error, it lights LED 0.
- *
- *  @author Philip Levis
- *  @date   June 12 2005
- *
- **/
-
 #include "Timer.h"
 #include "RadioSenseToLeds.h"
 
-module RadioSenseToLedsC {
+/**
+ * Implementation of the RadioSenseToLeds application.  RadioSenseToLeds samples 
+ * a platform's default sensor at 4Hz and broadcasts this value in an AM packet. 
+ * A RadioSenseToLeds node that hears a broadcast displays the bottom three bits 
+ * of the value it has received. This application is a useful test to show that 
+ * basic AM communication, timers, and the default sensor work.
+ * 
+ * @author Philip Levis
+ * @date   June 6 2005
+ */
+
+module RadioSenseToLedsC @safe(){
   uses {
     interface Leds;
     interface Boot;
@@ -67,7 +66,7 @@ implementation {
 
   event void RadioControl.startDone(error_t err) {
     if (err == SUCCESS) {
-      call MilliTimer.startPeriodic(1000);
+      call MilliTimer.startPeriodic(250);
     }
   }
   event void RadioControl.stopDone(error_t err) {}
@@ -81,15 +80,15 @@ implementation {
       return;
     }
     else {
-      RadioSenseMsg* rsm;
+      radio_sense_msg_t* rsm;
 
-      rsm = (RadioSenseMsg*)call Packet.getPayload(&packet, NULL);
-      if (call Packet.maxPayloadLength() < sizeof(RadioSenseMsg)) {
+      rsm = (radio_sense_msg_t*)call Packet.getPayload(&packet, sizeof(radio_sense_msg_t));
+      if (rsm == NULL) {
        return;
       }
       rsm->error = result;
       rsm->data = data;
-      if (call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(RadioSenseMsg)) == SUCCESS) {
+      if (call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(radio_sense_msg_t)) == SUCCESS) {
        locked = TRUE;
       }
     }
@@ -98,23 +97,22 @@ implementation {
   event message_t* Receive.receive(message_t* bufPtr, 
                                   void* payload, uint8_t len) {
     call Leds.led1Toggle();
-    if (len != sizeof(RadioSenseMsg)) {return bufPtr;}
+    if (len != sizeof(radio_sense_msg_t)) {return bufPtr;}
     else {
-      RadioSenseMsg* rsm = (RadioSenseMsg*)payload;
+      radio_sense_msg_t* rsm = (radio_sense_msg_t*)payload;
       uint16_t val = rsm->data;
-      call Leds.led0Toggle();
-      if (val & 0x8000) {
-       call Leds.led1On();
-      }
-      else {
-       call Leds.led1Off();
-      }
-      if (val & 0x4000) {
-       call Leds.led2On();
-      }
-      else {
-       call Leds.led2Off();
-      }
+      if (val & 0x0004)
+        call Leds.led2On();
+      else
+        call Leds.led2Off();
+      if (val & 0x0002)
+        call Leds.led1On();
+      else
+        call Leds.led1Off();
+      if (val & 0x0001)
+        call Leds.led0On();
+      else
+        call Leds.led0Off();
       return bufPtr;
     }
   }