X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=apps%2Ftests%2FNxFloat%2FTestSerial.java;fp=apps%2Ftests%2FNxFloat%2FTestSerial.java;h=873fdec4761d259428645a029ddfe1a2a75808ad;hb=e9bfab607e051bae6afb47b44892ce37541d1b44;hp=0000000000000000000000000000000000000000;hpb=adf1de6c009d13b7b52e68535c63b28f59c97400;p=tinyos-2.x.git diff --git a/apps/tests/NxFloat/TestSerial.java b/apps/tests/NxFloat/TestSerial.java new file mode 100644 index 00000000..873fdec4 --- /dev/null +++ b/apps/tests/NxFloat/TestSerial.java @@ -0,0 +1,106 @@ +/* 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 + * @date August 12 2005 + */ + +import java.io.IOException; + +import net.tinyos.message.*; +import net.tinyos.packet.*; +import net.tinyos.util.*; + +public class TestSerial implements MessageListener { + + private MoteIF moteIF; + + public TestSerial(MoteIF moteIF) { + this.moteIF = moteIF; + this.moteIF.registerListener(new TestSerialMsg(), this); + } + + public void sendPackets() { + int counter = 0; + TestSerialMsg payload = new TestSerialMsg(); + + 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 (IOException exception) { + System.err.println("Exception thrown when sending packets. Exiting."); + System.err.println(exception); + } + } + + public void messageReceived(int to, Message message) { + TestSerialMsg msg = (TestSerialMsg)message; + System.out.println("Received packet sequence number " + msg.get_counter()); + } + + private static void usage() { + System.err.println("usage: TestSerial [-comm ]"); + } + + 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); + TestSerial serial = new TestSerial(mif); + serial.sendPackets(); + } + + +}