[Tinyos-2-commits] CVS: tinyos-2.x/apps/tutorials/PacketParrot Makefile, NONE, 1.1 PacketParrotC.nc, NONE, 1.1 PacketParrotP.nc, NONE, 1.1 README.txt, NONE, 1.1 volumes-at45db.xml, NONE, 1.1 volumes-stm25p.xml, NONE, 1.1

Prabal Dutta prabal at users.sourceforge.net
Sat Apr 7 14:53:27 PDT 2007


Update of /cvsroot/tinyos/tinyos-2.x/apps/tutorials/PacketParrot
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv357

Added Files:
	Makefile PacketParrotC.nc PacketParrotP.nc README.txt 
	volumes-at45db.xml volumes-stm25p.xml 
Log Message:
Initial checkin for Logging tuturial

--- NEW FILE: Makefile ---
COMPONENT=PacketParrotC
include $(MAKERULES)

--- NEW FILE: PacketParrotC.nc ---
/*                                                                     tab:2
 *
 * "Copyright (c) 2000-2007 The Regents of the University of
 * California.  All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software and
 * its documentation for any purpose, without fee, and without written
 * agreement is hereby granted, provided that the above copyright
 * notice, the following two paragraphs and the author appear in all
 * copies of this software.
 * 
 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
 * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
 * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE
 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
 * UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
 *
 */

/**
 * Demonstrates the <code>LogRead</code> and <code>LogWrite</code>
 * abstractions.  The application logs packets it receives from the
 * radio to flash.  On a subsequent power cycle, the application
 * transmits logged packets, erases the log, and then continues to log
 * packets again.  The red LED is on when the log is being erased.
 * The blue (yellow) LED blinks when packets are being received and
 * logged, and remains on when packets are being received but are not
 * logged (because the log is being erased).  The green LED blinks
 * rapidly after a power cycle when logged packets are transmitted.
 *
 * @author Prabal Dutta
 * @date   Apr 6, 2007
 */
#include <Timer.h>
#include "StorageVolumes.h"

configuration PacketParrotC {
}
implementation {
  components MainC;
  components LedsC;
  components PacketParrotP as App;
  components ActiveMessageC;
  components CC2420CsmaC;
  components new LogStorageC(VOLUME_LOGTEST, TRUE);
  components new TimerMilliC() as Timer0;

  App.Boot -> MainC;
  App.Leds -> LedsC;
  App.Packet -> ActiveMessageC;
  App.AMControl -> ActiveMessageC;
  App.Send -> CC2420CsmaC;
  App.Receive -> CC2420CsmaC;
  App.LogRead -> LogStorageC;
  App.LogWrite -> LogStorageC;
  App.Timer0 -> Timer0;
}

--- NEW FILE: PacketParrotP.nc ---
/*                                                                      tab:2
 *
 * "Copyright (c) 2000-2007 The Regents of the University of
 * California.  All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software and
 * its documentation for any purpose, without fee, and without written
 * agreement is hereby granted, provided that the above copyright
 * notice, the following two paragraphs and the author appear in all
 * copies of this software.
 * 
 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
 * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
 * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE
 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
 * UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
 *
 */

/**
 * Implementation of the <code>PacketParrot</code> application.
 *
 * @author Prabal Dutta
 * @date   Apr 6, 2007
 */
module PacketParrotP {
  uses {
    interface Boot;
    interface Leds;
    interface Packet;
    interface Send;
    interface Receive;
    interface SplitControl as AMControl;
    interface LogRead;
    interface LogWrite;
    interface Timer<TMilli> as Timer0;
  }
}
implementation {

  enum {
    INTER_PACKET_INTERVAL = 25
  };

  typedef nx_struct logentry_t {
    nx_uint8_t len;
    message_t msg;
  } logentry_t;

  bool m_busy = TRUE;
  logentry_t m_entry;

  event void Boot.booted() {
    call AMControl.start();
  }


  event void AMControl.startDone(error_t err) {
    if (err == SUCCESS) {
      error_t e;
      do {
        e = call LogRead.read(&m_entry, sizeof(logentry_t));
      } while (e != SUCCESS);
    }
    else {
      call AMControl.start();
    }
  }


  event void AMControl.stopDone(error_t err) {
  }


  event void LogRead.readDone(void* buf, storage_len_t len, error_t err) {
    if ( (len == sizeof(logentry_t)) && (buf == &m_entry) ) {
      call Send.send(&m_entry.msg, m_entry.len);
      call Leds.led1On();
    }
    else {
      error_t e;
      do {
	e = call LogWrite.erase();
      } while (e != SUCCESS);
      call Leds.led0On();
    }
  }


  event void Send.sendDone(message_t* msg, error_t err) {
    call Leds.led1Off();
    if ( (err == SUCCESS) && (msg == &m_entry.msg) ) {
      error_t e;
      call Packet.clear(&m_entry.msg);
      do {
        e = call LogRead.read(&m_entry, sizeof(logentry_t));
      } while (e != SUCCESS);
    }
    else {
      call Timer0.startOneShot(INTER_PACKET_INTERVAL);
    }
  }


  event void Timer0.fired() {
    call Send.send(&m_entry.msg, m_entry.len);
  }


  event void LogWrite.eraseDone(error_t err) {
    if (err == SUCCESS) {
      m_busy = FALSE;
    }
    else {
      // Handle error.
    }
    call Leds.led0Off();
  }


  event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len){
    call Leds.led2On();
    if (!m_busy) {
      m_busy = TRUE;
      m_entry.len = len;
      m_entry.msg = *msg;
      if (call LogWrite.append(&m_entry, sizeof(message_t)) != SUCCESS) {
	m_busy = FALSE;
      }
    }
    return msg;
  }

  event void LogWrite.appendDone(void* buf, storage_len_t len, 
                                 bool recordsLost, error_t err) {
    m_busy = FALSE;
    call Leds.led2Off();
  }

  event void LogRead.seekDone(error_t err) {
  }

  event void LogWrite.syncDone(error_t err) {
  }

}

--- NEW FILE: README.txt ---
$Id: README.txt,v 1.1 2007/04/07 21:53:25 prabal Exp $

README for PacketParrot

Author/Contact:

  tinyos-help at millennium.berkeley.edu

Description:

  PacketParrot demonstrates use of LogWrite and LogRead abstractions.
  A node writes received packets to a circular log and retransmits the
  logged packets (or at least the part of the packets above the AM
  layer) when power cycled.

  The application logs packets it receives from the radio to flash.
  On a subsequent power cycle, the application transmits logged
  packets, erases the log, and then continues to log packets again.
  The red LED is on when the log is being erased.  The blue (yellow)
  LED turns on when a packets is received and turns off when a packet 
  has been logged.  The blue (yellow) LED remains on when packets are 
  being received but are not logged (because the log is being erased).  
  The green LED flickers rapidly after a power cycle when logged 
  packets are transmitted.

  To use this application:

  (i)   Program one node (the "parrot") with this application using 
        the typical command (e.g. make telosb install)
  (ii)  Program a second node with the BlinkToRadio application.
  (iii) Turn the parrot node on.  The red LED will turn on briefly, 
        indicating that the flash volume is being erased.
  (iv)  Turn the second node on.  Nothing should happen on the second 
        node but the blue (yellow) LED on the parrot node should start
        to blink, indicating it is receiving packets and logging them 
        to flash.
  (v)   After a few tens of seconds, focus you attention on the second 
        node's LEDs and then power cycle the parrot node.  The LEDs on 
        the second node should rapidly flash as if they were displaying 
        the three low-order bits of a counter.  At the same time, the 
        green LED on the parrot node should flicker rapidly, in unison 
        with the LEDs on the second node, indicating that packets are 
        being transmitted.
  (vi)  Repeat step (v) a few times and notice that the parrot's blue 
        (yellow) LED turns on and doesn't turn off until just a bit 
        after the red LED, indicating that one or more packets were 
        received (the LED turned on) but these packets were not logged 
        (since the LED does not turn off) because the log is being 
        erased.

Tools:

  None

Known bugs/limitations:

  Only works on motes with the CC2420 radio.  Known to work with
  TelosB and Tmote nodes but currently flaky on the MicaZ nodes.

--- NEW FILE: volumes-at45db.xml ---
<volume_table>
  <volume name="LOGTEST" size="262144"/>
  <volume name="CONFIGTEST" size="4608"/>
</volume_table>

--- NEW FILE: volumes-stm25p.xml ---
<volume_table>
  <volume name="LOGTEST" size="262144"/>
  <volume name="CONFIGTEST" size="131072"/>
</volume_table>



More information about the Tinyos-2-commits mailing list