]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Copy of Printf test application into tutorials directory
authorklueska <klueska>
Tue, 4 Sep 2007 21:19:25 +0000 (21:19 +0000)
committerklueska <klueska>
Tue, 4 Sep 2007 21:19:25 +0000 (21:19 +0000)
apps/tutorials/Printf/Makefile [new file with mode: 0644]
apps/tutorials/Printf/PrintfClient.java [new file with mode: 0644]
apps/tutorials/Printf/TestPrintfAppC.nc [new file with mode: 0644]
apps/tutorials/Printf/TestPrintfC.nc [new file with mode: 0644]

diff --git a/apps/tutorials/Printf/Makefile b/apps/tutorials/Printf/Makefile
new file mode 100644 (file)
index 0000000..a3b9020
--- /dev/null
@@ -0,0 +1,14 @@
+COMPONENT=TestPrintfAppC
+CFLAGS += -I$(TOSDIR)/lib/printf
+
+BUILD_EXTRA_DEPS += PrintfMsg.class PrintfClient.class
+
+%.class: %.java
+       javac $<
+
+PrintfMsg.java: $(TOSDIR)/lib/printf/printf.h
+       mig java -target=$(PLATFORM) $(CFLAGS) \
+               -java-classname=PrintfMsg \
+               $(TOSDIR)/lib/printf/printf.h printf_msg -o $@
+
+include $(MAKERULES)
diff --git a/apps/tutorials/Printf/PrintfClient.java b/apps/tutorials/Printf/PrintfClient.java
new file mode 100644 (file)
index 0000000..6d98473
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * "Copyright (c) 2006 Washington University in St. Louis.
+ * 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 WASHINGTON UNIVERSITY IN ST. LOUIS 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 WASHINGTON
+ * UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * WASHINGTON UNIVERSITY IN ST. LOUIS 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 WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
+ * MODIFICATIONS."
+ */
+
+/**
+ * @author Kevin Klues (klueska@cs.wustl.edu)
+ * @version $Revision$
+ * @date $Date$
+ */
+
+import java.io.IOException;
+
+import net.tinyos.message.*;
+import net.tinyos.packet.*;
+import net.tinyos.util.*;
+
+public class PrintfClient implements MessageListener {
+
+  private MoteIF moteIF;
+  
+  public PrintfClient(MoteIF moteIF) {
+    this.moteIF = moteIF;
+    this.moteIF.registerListener(new PrintfMsg(), this);
+  }
+
+  public void messageReceived(int to, Message message) {
+    PrintfMsg msg = (PrintfMsg)message;
+    for(int i=0; i<msg.totalSize_buffer(); i++) {
+      char nextChar = (char)(msg.getElement_buffer(i));
+      if(nextChar != 0)
+        System.out.print(nextChar);
+    }
+  }
+  
+  private static void usage() {
+    System.err.println("usage: PrintfClient [-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);
+    }
+    System.out.print(phoenix);
+    MoteIF mif = new MoteIF(phoenix);
+    PrintfClient client = new PrintfClient(mif);
+  }
+}
diff --git a/apps/tutorials/Printf/TestPrintfAppC.nc b/apps/tutorials/Printf/TestPrintfAppC.nc
new file mode 100644 (file)
index 0000000..8e2b565
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * "Copyright (c) 2006 Washington University in St. Louis.
+ * 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 WASHINGTON UNIVERSITY IN ST. LOUIS 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 WASHINGTON
+ * UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * WASHINGTON UNIVERSITY IN ST. LOUIS 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 WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
+ * MODIFICATIONS."
+ */
+/**
+ * This application is used to test the basic functionality of the printf service.  
+ * It is initiated by calling the start() command of the SplitControl interface 
+ * provided by the PrintfC component.  After starting the printf service, calls to 
+ * the standard c-style printf command are made to print various strings of text 
+ * over the serial line.  Only upon calling PrintfFlush.flush() does the data 
+ * actually get sent out over the serial line.
+ *
+ * @author Kevin Klues (klueska@cs.wustl.edu)
+ * @version $Revision$
+ * @date $Date$
+ */
+#include "printf.h"
+
+configuration TestPrintfAppC{
+}
+implementation {
+  components MainC, TestPrintfC, LedsC;
+  components PrintfC;
+
+  TestPrintfC.Boot -> MainC;
+  TestPrintfC.Leds -> LedsC;
+  TestPrintfC.PrintfControl -> PrintfC;
+  TestPrintfC.PrintfFlush -> PrintfC;
+}
+
diff --git a/apps/tutorials/Printf/TestPrintfC.nc b/apps/tutorials/Printf/TestPrintfC.nc
new file mode 100644 (file)
index 0000000..47fe191
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * "Copyright (c) 2006 Washington University in St. Louis.
+ * 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 WASHINGTON UNIVERSITY IN ST. LOUIS 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 WASHINGTON
+ * UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * WASHINGTON UNIVERSITY IN ST. LOUIS 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 WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
+ * MODIFICATIONS."
+ */
+/**
+ *
+ * This application is used to test the basic functionality of the printf service.  
+ * It is initiated by calling the start() command of the SplitControl interface 
+ * provided by the PrintfC component.  After starting the printf service, calls to 
+ * the standard c-style printf command are made to print various strings of text 
+ * over the serial line.  Only upon calling PrintfFlush.flush() does the data 
+ * actually get sent out over the serial line.
+ *
+ * @author Kevin Klues (klueska@cs.wustl.edu)
+ * @version $Revision$
+ * @date $Date$
+ */
+
+#include "printf.h"
+module TestPrintfC {
+  uses {
+    interface Boot;  
+    interface Leds;
+    interface SplitControl as PrintfControl;
+    interface PrintfFlush;
+  }
+}
+implementation {
+       
+  #define NUM_TIMES_TO_PRINT   5
+  uint16_t counter=0;
+  uint8_t dummyVar1 = 123;
+  uint16_t dummyVar2 = 12345;
+  uint32_t dummyVar3 = 1234567890;
+
+  event void Boot.booted() {
+    call PrintfControl.start();
+  }
+  
+  event void PrintfControl.startDone(error_t error) {
+       printf("Hi I am writing to you from my TinyOS application!!\n");
+       printf("Here is a uint8: %u\n", dummyVar1);
+       printf("Here is a uint16: %u\n", dummyVar2);
+       printf("Here is a uint32: %ld\n", dummyVar3);
+       call PrintfFlush.flush();
+  }
+
+  event void PrintfControl.stopDone(error_t error) {
+       counter = 0;
+    call Leds.led2Toggle();
+       printf("This should not be printed...");
+       call PrintfFlush.flush();
+  }
+  
+  event void PrintfFlush.flushDone(error_t error) {
+       if(counter < NUM_TIMES_TO_PRINT) {
+      printf("I am now iterating: %d\n", counter);
+         call PrintfFlush.flush();
+    }
+    else if(counter == NUM_TIMES_TO_PRINT) {
+      printf("This is a really short string...\n");
+      printf("I am generating this string to have just less than 250\ncharacters since that is the limit of the size I put on my\nmaximum buffer when I instantiated the PrintfC component.\n");
+      printf("Only part of this line should get printed because by writing\nthis sentence, I go over my character limit that the internal Printf buffer can hold.\n");
+      call PrintfFlush.flush();
+    }
+    else call PrintfControl.stop();
+    counter++;
+  }
+}
+