[Tinyos-2-commits] CVS: tinyos-2.x/apps/tests/TestRadioPM/apps/TestSleepSchedulers/GenericReceiver GenericReceiverAppC.nc, NONE, 1.1.2.1 GenericReceiverC.nc, NONE, 1.1.2.1 Makefile, NONE, 1.1.2.1 NumSenderMsgs.java, NONE, 1.1.2.1 PrintNumSenderMsgs.java, NONE, 1.1.2.1

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


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

Added Files:
      Tag: tos-2-resource-pm-eval-cand
	GenericReceiverAppC.nc GenericReceiverC.nc Makefile 
	NumSenderMsgs.java PrintNumSenderMsgs.java 
Log Message:
Radio Power Management protocol architecture

--- NEW FILE: GenericReceiverAppC.nc ---
// $Id: GenericReceiverAppC.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 GenericReceiverAppC {}
implementation {
  components GenericReceiverC as App, LedsC, MainC;
  components SerialActiveMessageC as AMSerial;
  components ActiveMessageC as AMRadio;
  components new AMReceiverC(AM_SENDERADDRMSG);  
  components new TimerMilliC();
  
  
  MainC.SoftwareInit -> AMSerial;
  MainC.SoftwareInit -> AMRadio;
  
  App.Boot -> MainC.Boot;
  App.RadioReceive -> AMReceiverC;
  App.AMSerialSend -> AMSerial.AMSend[AM_NUMSENDERMSGS];
  App.Leds -> LedsC;
  App.MilliTimer -> TimerMilliC;
  App.SerialPacket -> AMRadio;
  App.RadioPacket -> AMSerial;
  App.AMSerialControl -> AMSerial;
  App.AMRadioControl -> AMRadio;
}



--- NEW FILE: GenericReceiverC.nc ---
// $Id: GenericReceiverC.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 GenericReceiverC {
  uses {
    interface SplitControl as AMSerialControl;
    interface SplitControl as AMRadioControl;
    interface Leds;
    interface Boot;
    interface Receive as RadioReceive;
    interface AMSend as AMSerialSend;
    interface Timer<TMilli> as MilliTimer;
    interface Packet as SerialPacket;
    interface Packet as RadioPacket;
//     interface LowPowerListening as Lpl;
//     interface RadioDutyCycling;
  }
}
implementation {

  #define TIMEOUT_LONG ((uint32_t)15000)
  #define NUM_TRIALS	5
  
  #define LPL_MODE	4
  #define SSS_ON_MODE   1
  #define SSS_OFF_MODE  1
  
  message_t packet;
  bool stopReceiving;
  int numTrials;
  
  void resetPackets() {
    int i;
    NumSenderMsgs* sm = (NumSenderMsgs*)call SerialPacket.getPayload(&packet, NULL);
    for(i=0; i<MAX_SENDERS; i++)
      sm->numMsgs[i] =0;
    call MilliTimer.startOneShot(TIMEOUT_LONG);
    stopReceiving = FALSE;
  }

  event void Boot.booted() {
    numTrials = 0;
//     call Lpl.setListeningMode(LPL_MODE);
//     call RadioDutyCycling.setModes(SSS_ON_MODE, SSS_OFF_MODE);
    call AMSerialControl.start();
  }
  
  event void MilliTimer.fired() {
    stopReceiving = TRUE;
    if(call AMSerialSend.send(AM_BROADCAST_ADDR, &packet, sizeof(NumSenderMsgs)) != SUCCESS)
      resetPackets();
  }

  event message_t* RadioReceive.receive(message_t* bufPtr, 
				   void* payload, uint8_t len) {
    if(stopReceiving == FALSE) {
      SenderAddrMsg* rm = (SenderAddrMsg*)call RadioPacket.getPayload(bufPtr, NULL);
      NumSenderMsgs* sm = (NumSenderMsgs*)call SerialPacket.getPayload(&packet, NULL);
      sm->numMsgs[rm->senderAddr]++;
      call Leds.led1Toggle();
    }
    return bufPtr;
  }

  event void AMSerialSend.sendDone(message_t* bufPtr, error_t error) {
    call Leds.led2Toggle();
//     call AMRadioControl.stop();
    if(numTrials++ < NUM_TRIALS) {
      resetPackets();
    }
  }

  event void AMSerialControl.startDone(error_t err) {
    call AMRadioControl.start();
  }
  event void AMSerialControl.stopDone(error_t err) {
    call AMSerialControl.start();
  }
  
  event void AMRadioControl.startDone(error_t err) {
    if(numTrials++ < NUM_TRIALS) {
          resetPackets();
    }
  }
  event void AMRadioControl.stopDone(error_t err) {
    call AMRadioControl.start();
  }

//   event void RadioDutyCycling.radioSwitchedOn() { call Leds.led0On(); }
//   event void RadioDutyCycling.radioSwitchedOff() { call Leds.led0Off(); }
}





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

COMPONENT=GenericReceiverAppC
CFLAGS += -I%T/lib/oski -I../

BUILD_EXTRA_DEPS += NumSenderMsgs.class PrintNumSenderMsgs.class

%.class: %.java
	javac $<

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

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

include $(MAKERULES)


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

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

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

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

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

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

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

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

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

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

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

    /**
     * Create a new NumSenderMsgs embedded in the given message
     * at the given base offset and length.
     */
    public NumSenderMsgs(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 <NumSenderMsgs> \n";
      try {
        s += "  [numMsgs=";
        for (int i = 0; i < 15; i++) {
          s += "0x"+Long.toHexString(getElement_numMsgs(i) & 0xff)+" ";
        }
        s += "]\n";
      } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ }
      return s;
    }

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

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

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

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

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

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

    /**
     * Return the entire array 'numMsgs' as a long[]
     */
    public long[] get_numMsgs() {
        long[] tmp = new long[15];
        for (int index0 = 0; index0 < numElements_numMsgs(0); index0++) {
            tmp[index0] = getElement_numMsgs(index0);
        }
        return tmp;
    }

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

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

    /**
     * Set an element of the array 'numMsgs'
     */
    public void setElement_numMsgs(int index1, long value) {
        setUIntBEElement(offsetBits_numMsgs(index1), 32, value);
    }

    /**
     * Return the total size, in bytes, of the array 'numMsgs'
     */
    public static int totalSize_numMsgs() {
        return (480 / 8);
    }

    /**
     * Return the total size, in bits, of the array 'numMsgs'
     */
    public static int totalSizeBits_numMsgs() {
        return 480;
    }

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

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

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

    /**
     * Return the number of elements in the array 'numMsgs'
     */
    public static int numElements_numMsgs() {
        return 15;
    }

    /**
     * Return the number of elements in the array 'numMsgs'
     * for the given dimension.
     */
    public static int numElements_numMsgs(int dimension) {
      int array_dims[] = { 15,  };
        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: PrintNumSenderMsgs.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 PrintNumSenderMsgs implements MessageListener {

  private MoteIF moteIF;
  
  public PrintNumSenderMsgs(MoteIF moteIF) {
    this.moteIF = moteIF;
    this.moteIF.registerListener(new NumSenderMsgs(), this);
  }

  public void messageReceived(int to, Message message) {
    NumSenderMsgs msg = (NumSenderMsgs)message;
    for(int i=1; i<6; i++) {
      System.out.print(msg.getElement_numMsgs(i) + ",");
    }
    System.out.println();
  }
  
  private static void usage() {
    System.err.println("usage: PrintNumSenderMsgs [-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);
    PrintNumSenderMsgs serial = new PrintNumSenderMsgs(mif);
  }


}



More information about the Tinyos-2-commits mailing list