[Tinyos-2-commits] CVS: tinyos-2.x/tos/sensorboards/im2sb/examples Makefile, NONE, 1.1.2.1 TestSensor.h, NONE, 1.1.2.1 TestSensor.java, NONE, 1.1.2.1 TestSensorMsg.java, NONE, 1.1.2.1

Philip Buonadonna philipb at users.sourceforge.net
Mon Nov 13 16:58:26 PST 2006


Update of /cvsroot/tinyos/tinyos-2.x/tos/sensorboards/im2sb/examples
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv19689

Added Files:
      Tag: tinyos-2_0_devel-BRANCH
	Makefile TestSensor.h TestSensor.java TestSensorMsg.java 
Log Message:
Addition of code examples for Intel Mote 2 sensorboard chips

--- NEW FILE: Makefile ---
COMPONENT=TestSensorC
CFLAGS += -I%T/lib/oski
BUILD_EXTRA_DEPS += TestSensor.class
CLEAN_EXTRA = *.class TestSensorMsg.java
SENSORBOARD ?= im2sb

TestSensor.class: $(wildcard *.java) TestSensorMsg.java
	javac *.java

TestSensorMsg.java:
	mig java -target=null $(CFLAGS) -java-classname=TestSensorMsg TestSensor.h TestSensorMsg -o $@


include $(MAKERULES)
--- NEW FILE: TestSensor.h ---
#ifndef TEST_SENSOR_H
#define TEST_SENSOR_H

typedef nx_struct TestSensorMsg {
  nx_uint16_t value;
} TestSensorMsg;

enum {
  AM_TESTSENSORMSG = 10,
};

#endif

--- NEW FILE: TestSensor.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.
 * 
 *
 * @author Phil Levis <pal at cs.berkeley.edu>
 * @date August 12 2005
 */

import java.io.IOException;

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

public class TestSensor implements MessageListener {

    private MoteIF moteIF;
  
    public TestSensor(MoteIF moteIF) {
				this.moteIF = moteIF;
				this.moteIF.registerListener(new TestSensorMsg(), this);
    }

    public void sendPackets() {
				int counter = 0;
				TestSensorMsg payload = new TestSensorMsg();
    
				try {
						while (true) {
								/*
									System.out.println("Sending packet " + counter);
									payload.set_counter(counter);
									moteIF.send(0, payload);
									counter++;
								*/
								try {Thread.sleep(1000);}
								catch (InterruptedException exception) {}
						}
				}
				catch (Exception exception) {
						System.err.println("Exception thrown when sending packets. Exiting.");
						System.err.println(exception);
				}
    }

    public void messageReceived(int to, Message message) {
				TestSensorMsg msg = (TestSensorMsg)message;
				System.out.println("Received packet. Value= " + msg.get_value());
    }
  
    private static void usage() {
				System.err.println("usage: TestSensor [-comm <source>]");
    }
  
    public static void main(String[] args) throws Exception {
				String source = null;
				if (args.length == 2) {
						if (!args[0].equals("-comm")) {
								usage();
								System.exit(1);
						}
						source = args[1];
				}
				else if (args.length != 0) {
						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);
				TestSensor serial = new TestSensor(mif);
				serial.sendPackets();
    }


}

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

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

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

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

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

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

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

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

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

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

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

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

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

    /////////////////////////////////////////////////////////
    // Accessor methods for field: value
    //   Field type: int, unsigned
    //   Offset (bits): 0
    //   Size (bits): 16
    /////////////////////////////////////////////////////////

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

    /**
     * Return whether the field 'value' is an array (false).
     */
    public static boolean isArray_value() {
        return false;
    }

    /**
     * Return the offset (in bytes) of the field 'value'
     */
    public static int offset_value() {
        return (0 / 8);
    }

    /**
     * Return the offset (in bits) of the field 'value'
     */
    public static int offsetBits_value() {
        return 0;
    }

    /**
     * Return the value (as a int) of the field 'value'
     */
    public int get_value() {
        return (int)getUIntBEElement(offsetBits_value(), 16);
    }

    /**
     * Set the value of the field 'value'
     */
    public void set_value(int value) {
        setUIntBEElement(offsetBits_value(), 16, value);
    }

    /**
     * Return the size, in bytes, of the field 'value'
     */
    public static int size_value() {
        return (16 / 8);
    }

    /**
     * Return the size, in bits, of the field 'value'
     */
    public static int sizeBits_value() {
        return 16;
    }

}



More information about the Tinyos-2-commits mailing list