]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - apps/AntiTheft/Root/AntiTheftRootC.nc
comments, etc
[tinyos-2.x.git] / apps / AntiTheft / Root / AntiTheftRootC.nc
index 19bc9430303fb3e94069e21bfd8f1a26fd4a0f04..c86b240395221cf558e2686ee5b9d1ec08f3f198 100644 (file)
@@ -1,3 +1,21 @@
+// $Id$
+/*
+ * Copyright (c) 2007 Intel Corporation
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached INTEL-LICENSE     
+ * file. If you do not find these files, copies can be found by writing to
+ * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, 
+ * 94704.  Attention:  Intel License Inquiry.
+ */
+/**
+ * Root node code for the antitheft demo app, just acts as a bridge with the PC:
+ * - disseminates settings received from the PC
+ * - acts as a root forthe theft alert collection tree
+ * - forwards theft alerts received from the collection tree to the PC
+ *
+ * @author David Gay
+ */
 module AntiTheftRootC
 {
   uses
@@ -20,6 +38,7 @@ module AntiTheftRootC
 }
 implementation
 {
+  /* Start the radio and serial ports when booting */
   event void Boot.booted()
   {
     call SerialControl.start();
@@ -28,7 +47,11 @@ implementation
 
   event void SerialControl.startDone(error_t error) { }
   event void SerialControl.stopDone(error_t error) { }
-  event void RadioControl.startDone(error_t error) { 
+  event void RadioControl.startDone(error_t error) {
+    /* Once the radio has started, we can setup low-power listening, and
+       start the collection and dissemination services. Additionally, we
+       set ourselves as the (sole) root for the theft alert dissemination
+       tree */
     if (error == SUCCESS)
       {
        call LowPowerListening.setLocalDutyCycle(200);
@@ -38,6 +61,8 @@ implementation
   }
   event void RadioControl.stopDone(error_t error) { }
 
+  /* When we receive new settings from the serial port, we disseminate
+     them by calling the change command */
   event message_t *SettingsReceive.receive(message_t* msg, void* payload, uint8_t len)
   {
     settings_t *newSettings = payload;
@@ -53,7 +78,10 @@ implementation
   message_t fwdMsg;
   bool fwdBusy;
 
-  event message_t *AlertsReceive.receive(message_t* msg, void* payload, uint8_t len)
+  /* When we (as root of the collection tree) receive a new theft alert,
+     we forward it to the PC via the serial port */
+  event message_t *AlertsReceive.receive(message_t* msg, void* payload, 
+                                        uint8_t len)
   {
     alert_t *newAlert = payload;
 
@@ -61,6 +89,8 @@ implementation
 
     if (len == sizeof(*newAlert) && !fwdBusy)
       {
+       /* Copy payload (newAlert) from collection system to our serial
+          message buffer (fwdAlert), then send our serial message */
        alert_t *fwdAlert = call AlertsForward.getPayload(&fwdMsg);
 
        *fwdAlert = *newAlert;