[Tinyos-2-commits] CVS: tinyos-2.x/apps/tests/TestRadioPM/apps/TestSleepSchedulers/ChainedLpl/ChainedSender ChainedSenderAppC.nc, NONE, 1.1.2.1 ChainedSenderC.nc, NONE, 1.1.2.1 DelayChainedMsgs.java, NONE, 1.1.2.1 Makefile, NONE, 1.1.2.1 PrintDelayChainedMsgs.java, NONE, 1.1.2.1

Kevin Klues klueska at users.sourceforge.net
Mon May 15 12:36:09 PDT 2006


Update of /cvsroot/tinyos/tinyos-2.x/apps/tests/TestRadioPM/apps/TestSleepSchedulers/ChainedLpl/ChainedSender
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv9561/apps/tests/TestRadioPM/apps/TestSleepSchedulers/ChainedLpl/ChainedSender

Added Files:
      Tag: tos-2-resource-pm-eval-cand
	ChainedSenderAppC.nc ChainedSenderC.nc DelayChainedMsgs.java 
	Makefile PrintDelayChainedMsgs.java 
Log Message:
Radio Power Management protocol architecture

--- NEW FILE: ChainedSenderAppC.nc ---
// $Id: ChainedSenderAppC.nc,v 1.1.2.1 2006/05/15 19:36:07 klueska Exp $

/*									tab:4
 * "Copyright (c) 2000-2005 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."
 *
 * Copyright (c) 2002-2005 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.
 */

/**
 * Application to test that the TinyOS java toolchain can communicate
 * with motes over the serial port. The application sends packets to
 * the serial port at 1Hz: the packet contains an incrementing
 * counter. When the application receives a counter packet, it
 * displays the bottom three bits on its LEDs. This application is
 * very similar to RadioCountToLeds, except that it operates over the
 * serial port. There is Java application for testing the mote
 * application: run TestSerial to print out the received packets and
 * send packets to the mote.
 *
 *  @author Gilman Tolle
 *  @author Philip Levis
 *  
 *  @date   Aug 12 2005
 *
 **/

includes SenderAddr;

configuration ChainedSenderAppC {}
implementation {
  components ChainedSenderC as App, LedsC, MainC;
  components ActiveMessageC as AMRadio;
  components new AMSenderC(AM_CHAINEDMSGS);
  components new AMReceiverC(AM_CHAINEDMSGS);  
  components new TimerMilliC();
  components SerialActiveMessageC as AMSerial;
  components new LowPowerListeningC();
  
  MainC.SoftwareInit -> AMRadio;
  MainC.SoftwareInit -> AMSerial;
  
  App.Boot -> MainC.Boot;
  App.AMRadioSend -> AMSenderC;
  App.RadioReceive -> AMReceiverC;
  App.Leds -> LedsC;
  App.AMRadioControl -> AMRadio;
  App.Timer -> TimerMilliC;
  App.RadioPacket -> AMRadio;
  App.AMPacket -> AMRadio;
  

  App.AMSerialSend -> AMSerial.AMSend[AM_DELAYCHAINEDMSGS];
  App.AMSerialControl -> AMSerial;
  
  App.LowPowerListeningControl -> LowPowerListeningC;
  App.LowPowerListening -> LowPowerListeningC;
  App.SerialPacket -> AMSerial;
}



--- NEW FILE: ChainedSenderC.nc ---
// $Id: ChainedSenderC.nc,v 1.1.2.1 2006/05/15 19:36:07 klueska Exp $

/*									tab:4
 * "Copyright (c) 2000-2005 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."
 *
 * Copyright (c) 2002-2003 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.
 */

/**
 * Application to test that the TinyOS java toolchain can communicate
 * with motes over the serial port. The application sends packets to
 * the serial port at 1Hz: the packet contains an incrementing
 * counter. When the application receives a counter packet, it
 * displays the bottom three bits on its LEDs. This application is
 * very similar to RadioCountToLeds, except that it operates over the
 * serial port. There is Java application for testing the mote
 * application: run TestSerial to print out the received packets and
 * send packets to the mote.
 *
 *  @author Gilman Tolle
 *  @author Philip Levis
 *  
 *  @date   Aug 12 2005
 *
 **/

includes Timer;
includes SenderAddr;

module ChainedSenderC {
  uses {
    interface SplitControl as AMRadioControl;
    interface SplitControl as LowPowerListeningControl;
    interface Leds;
    interface Boot;
    interface Receive as RadioReceive;
    interface AMSend as AMRadioSend;
    interface Timer<TMilli> as Timer;
    interface Packet as RadioPacket; 
    interface SplitControl as AMSerialControl;
    interface AMSend as AMSerialSend;
    interface Packet as SerialPacket;
    interface AMPacket;
    interface LowPowerListening;
  }
}
implementation {

  #define SEND_RADIO_PERIOD 2000
  #define SEND_SERIAL_PERIOD 2000
  #define SEND_TO_ADDR (call AMPacket.address()+1)

  message_t radioPacket;
  message_t serialPacket;
  uint32_t sendTime;

  event void Boot.booted() {
    ChainedMsg* m = (ChainedMsg*)call RadioPacket.getPayload(&radioPacket, NULL);
    m->goingForward = TRUE;
    m->seqNo = 0;
    call LowPowerListening.setListeningMode(CURRENT_LPL_MODE);
    call AMSerialControl.start();
  }

  event void Timer.fired() {
    ChainedMsg* m = (ChainedMsg*)call RadioPacket.getPayload(&radioPacket, NULL);
    if(++(m->seqNo) >= MAX_NUM_MESSAGES)
      call AMSerialSend.send(AM_BROADCAST_ADDR, &serialPacket, sizeof(DelayChainedMsgs));
    else call AMRadioSend.send(SEND_TO_ADDR, &radioPacket, TOSH_DATA_LENGTH);
  }

  event void AMSerialSend.sendDone(message_t* bufPtr, error_t error) {
    call Leds.led0Toggle();
    //call Timer.startOneShot(SEND_SERIAL_PERIOD);
  }

  event void AMRadioSend.sendDone(message_t* bufPtr, error_t error) {
    sendTime = call Timer.getNow();
    call Leds.led2Toggle();
    call Timer.startOneShot(SEND_RADIO_PERIOD);
  }

  event message_t* RadioReceive.receive(message_t* bufPtr, 
           void* payload, uint8_t len) {
    ChainedMsg* rm = (ChainedMsg*)call RadioPacket.getPayload(bufPtr, NULL);
    DelayChainedMsgs* sm = (DelayChainedMsgs*)call SerialPacket.getPayload(&serialPacket, NULL);
    sm->delay[rm->seqNo] = call Timer.getNow() - sendTime;
    call Leds.led1Toggle();
    return bufPtr;
  }
  
  event void AMSerialControl.startDone(error_t err) {
    call AMRadioControl.start();
  }

  event void AMSerialControl.stopDone(error_t err) {
  }
  
  event void AMRadioControl.startDone(error_t err) {
    call LowPowerListeningControl.start();
  }
  event void AMRadioControl.stopDone(error_t err) {
    call LowPowerListeningControl.stop();
  }

  event void LowPowerListeningControl.startDone(error_t err) {
    call AMRadioSend.send(SEND_TO_ADDR, &radioPacket, TOSH_DATA_LENGTH);
  }

  event void LowPowerListeningControl.stopDone(error_t err) {
  }
  
}






--- NEW FILE: DelayChainedMsgs.java ---
/**
 * This class is automatically generated by mig. DO NOT EDIT THIS FILE.
 * This class implements a Java interface to the 'DelayChainedMsgs'
 * message type.
 */

public class DelayChainedMsgs extends net.tinyos.message.Message {

    /** The default size of this message type in bytes. */
    public static final int DEFAULT_MESSAGE_SIZE = 80;

    /** The Active Message type associated with this message. */
    public static final int AM_TYPE = 243;

    /** Create a new DelayChainedMsgs of size 80. */
    public DelayChainedMsgs() {
        super(DEFAULT_MESSAGE_SIZE);
        amTypeSet(AM_TYPE);
    }

    /** Create a new DelayChainedMsgs of the given data_length. */
    public DelayChainedMsgs(int data_length) {
        super(data_length);
        amTypeSet(AM_TYPE);
    }

    /**
     * Create a new DelayChainedMsgs with the given data_length
     * and base offset.
     */
    public DelayChainedMsgs(int data_length, int base_offset) {
        super(data_length, base_offset);
        amTypeSet(AM_TYPE);
    }

    /**
     * Create a new DelayChainedMsgs using the given byte array
     * as backing store.
     */
    public DelayChainedMsgs(byte[] data) {
        super(data);
        amTypeSet(AM_TYPE);
    }

    /**
     * Create a new DelayChainedMsgs using the given byte array
     * as backing store, with the given base offset.
     */
    public DelayChainedMsgs(byte[] data, int base_offset) {
        super(data, base_offset);
        amTypeSet(AM_TYPE);
    }

    /**
     * Create a new DelayChainedMsgs using the given byte array
     * as backing store, with the given base offset and data length.
     */
    public DelayChainedMsgs(byte[] data, int base_offset, int data_length) {
        super(data, base_offset, data_length);
        amTypeSet(AM_TYPE);
    }

    /**
     * Create a new DelayChainedMsgs embedded in the given message
     * at the given base offset.
     */
    public DelayChainedMsgs(net.tinyos.message.Message msg, int base_offset) {
        super(msg, base_offset, DEFAULT_MESSAGE_SIZE);
        amTypeSet(AM_TYPE);
    }

    /**
     * Create a new DelayChainedMsgs embedded in the given message
     * at the given base offset and length.
     */
    public DelayChainedMsgs(net.tinyos.message.Message msg, int base_offset, int data_length) {
        super(msg, base_offset, data_length);
        amTypeSet(AM_TYPE);
    }

    /**
    /* Return a String representation of this message. Includes the
     * message type name and the non-indexed field values.
     */
    public String toString() {
      String s = "Message <DelayChainedMsgs> \n";
      try {
        s += "  [delay=";
        for (int i = 0; i < 20; i++) {
          s += "0x"+Long.toHexString(getElement_delay(i) & 0xff)+" ";
        }
        s += "]\n";
      } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ }
      return s;
    }

    // Message-type-specific access methods appear below.

    /////////////////////////////////////////////////////////
    // Accessor methods for field: delay
    //   Field type: long[], unsigned
    //   Offset (bits): 0
    //   Size of each element (bits): 32
    /////////////////////////////////////////////////////////

    /**
     * Return whether the field 'delay' is signed (false).
     */
    public static boolean isSigned_delay() {
        return false;
    }

    /**
     * Return whether the field 'delay' is an array (true).
     */
    public static boolean isArray_delay() {
        return true;
    }

    /**
     * Return the offset (in bytes) of the field 'delay'
     */
    public static int offset_delay(int index1) {
        int offset = 0;
        if (index1 < 0 || index1 >= 20) throw new ArrayIndexOutOfBoundsException();
        offset += 0 + index1 * 32;
        return (offset / 8);
    }

    /**
     * Return the offset (in bits) of the field 'delay'
     */
    public static int offsetBits_delay(int index1) {
        int offset = 0;
        if (index1 < 0 || index1 >= 20) throw new ArrayIndexOutOfBoundsException();
        offset += 0 + index1 * 32;
        return offset;
    }

    /**
     * Return the entire array 'delay' as a long[]
     */
    public long[] get_delay() {
        long[] tmp = new long[20];
        for (int index0 = 0; index0 < numElements_delay(0); index0++) {
            tmp[index0] = getElement_delay(index0);
        }
        return tmp;
    }

    /**
     * Set the contents of the array 'delay' from the given long[]
     */
    public void set_delay(long[] value) {
        for (int index0 = 0; index0 < value.length; index0++) {
            setElement_delay(index0, value[index0]);
        }
    }

    /**
     * Return an element (as a long) of the array 'delay'
     */
    public long getElement_delay(int index1) {
        return (long)getUIntBEElement(offsetBits_delay(index1), 32);
    }

    /**
     * Set an element of the array 'delay'
     */
    public void setElement_delay(int index1, long value) {
        setUIntBEElement(offsetBits_delay(index1), 32, value);
    }

    /**
     * Return the total size, in bytes, of the array 'delay'
     */
    public static int totalSize_delay() {
        return (640 / 8);
    }

    /**
     * Return the total size, in bits, of the array 'delay'
     */
    public static int totalSizeBits_delay() {
        return 640;
    }

    /**
     * Return the size, in bytes, of each element of the array 'delay'
     */
    public static int elementSize_delay() {
        return (32 / 8);
    }

    /**
     * Return the size, in bits, of each element of the array 'delay'
     */
    public static int elementSizeBits_delay() {
        return 32;
    }

    /**
     * Return the number of dimensions in the array 'delay'
     */
    public static int numDimensions_delay() {
        return 1;
    }

    /**
     * Return the number of elements in the array 'delay'
     */
    public static int numElements_delay() {
        return 20;
    }

    /**
     * Return the number of elements in the array 'delay'
     * for the given dimension.
     */
    public static int numElements_delay(int dimension) {
      int array_dims[] = { 20,  };
        if (dimension < 0 || dimension >= 1) throw new ArrayIndexOutOfBoundsException();
        if (array_dims[dimension] == 0) throw new IllegalArgumentException("Array dimension "+dimension+" has unknown size");
        return array_dims[dimension];
    }

}

--- NEW FILE: Makefile ---
BASE = $(TOSROOT)/apps/tests/TestRadioPM/apps

COMPONENT=ChainedSenderAppC

BUILD_EXTRA_DEPS += DelayChainedMsgs.class PrintDelayChainedMsgs.class

%.class: %.java
	javac $<

DelayChainedMsgs.java: $(BASE)/TestSleepSchedulers/SenderAddr.h
	mig java -target=$(PLATFORM) $(CFLAGS) -java-classname=DelayChainedMsgs $(BASE)/TestSleepSchedulers/SenderAddr.h DelayChainedMsgs -o $@

CFLAGS += -I$(BASE)/../apps/TestSleepSchedulers
include $(BASE)/TestSleepSchedulers/MakeIncludes

include $(MAKERULES)



--- NEW FILE: PrintDelayChainedMsgs.java ---
/*									tab:4
 * "Copyright (c) 2005 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."
 *
 */

/**
 * Java-side application for testing serial port communication.
 * Modified to just receive packets of type NumSenderMsgs and
 * print them out
 * 
 *
 * @author Phil Levis <pal at cs.berkeley.edu>
 * @author Kevin Klues <klueska at cs.wustl.edu>
 * @date August 12 2005
 */

import java.io.IOException;

import net.tinyos.message.*;
import net.tinyos.packet.*;
import net.tinyos.util.*;

public class PrintDelayChainedMsgs implements MessageListener {

  private MoteIF moteIF;
  
  public PrintDelayChainedMsgs(MoteIF moteIF) {
    this.moteIF = moteIF;
    this.moteIF.registerListener(new DelayChainedMsgs(), this);
  }

  public void messageReceived(int to, Message message) {
    DelayChainedMsgs msg = (DelayChainedMsgs)message;
    for(int i=0; i<20; i++) {
      System.out.print(msg.getElement_delay(i) + ",");
    }
    System.out.println();
  }
  
  private static void usage() {
    System.err.println("usage: PrintDelayChainedMsgs [-comm <source>]");
  }
  
  public static void main(String[] args) throws Exception {
    String source = "";
    if (args.length == 2) {
      if (!args[0].equals("-comm")) {
	       usage();
	       System.exit(1);
      }
      source = args[1];
    }
    else {
      usage();
      System.exit(1);
    }
    
    PhoenixSource phoenix;
    
    if (source == null) {
      phoenix = BuildSource.makePhoenix(PrintStreamMessenger.err);
    }
    else {
      phoenix = BuildSource.makePhoenix(source, PrintStreamMessenger.err);
    }
    MoteIF mif = new MoteIF(phoenix);
    PrintDelayChainedMsgs serial = new PrintDelayChainedMsgs(mif);
  }


}



More information about the Tinyos-2-commits mailing list