From d3eed3f3da593323d77e469dee12985b1c167304 Mon Sep 17 00:00:00 2001 From: kusy Date: Mon, 16 Jun 2008 11:07:43 +0000 Subject: [PATCH] committing java logger. --- apps/tests/TestFTSP/FTSPDataLogger.java | 120 ++++++++++++++++++++++++ apps/tests/TestFTSP/Makefile | 12 +-- 2 files changed, 126 insertions(+), 6 deletions(-) create mode 100644 apps/tests/TestFTSP/FTSPDataLogger.java diff --git a/apps/tests/TestFTSP/FTSPDataLogger.java b/apps/tests/TestFTSP/FTSPDataLogger.java new file mode 100644 index 00000000..3b96c8fc --- /dev/null +++ b/apps/tests/TestFTSP/FTSPDataLogger.java @@ -0,0 +1,120 @@ +/* tab:4 + * "Copyright (c) 2000-2003 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-2007 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. + */ + + +/** + * @author Brano Kusy + */ + +import java.io.FileOutputStream; +import java.io.PrintStream; +import net.tinyos.message.*; +import net.tinyos.util.*; + +public class FTSPDataLogger implements MessageListener { + public class RunWhenShuttingDown extends Thread { + public void run() + { + System.out.println("Control-C caught. Shutting down..."); + if (outReport!=null) + outReport.close(); + } + } + + MoteIF mote; // For talking to the antitheft root node + + void connect() + { + try { + mote = new MoteIF(PrintStreamMessenger.err); + mote.registerListener(new TestFTSPMsg(), this); + System.out.println("Connection ok!"); + } + catch(Exception e) { + e.printStackTrace(); + System.exit(2); + } + } + PrintStream outReport = null; + + public FTSPDataLogger() { + connect(); + Runtime.getRuntime().addShutdownHook(new RunWhenShuttingDown()); + String name=""+System.currentTimeMillis(); + try + { + outReport = new PrintStream(new FileOutputStream(name+".report")); + outReport.println("#[JAVA_TIME] [NODE_ID] [SEQ_NUM] [GLOB_TIME] [IS_TIME_VALID]"); + } + catch (Exception e) + { + System.out.println("FTSPDataLogger.FTSPDataLogger(): "+e.toString()); + } + } + + public void writeReprot(TestFTSPMsg tspr) + { + String foo = (System.currentTimeMillis() + +" "+tspr.get_src_addr()+" "+tspr.get_counter() + +" "+tspr.get_global_rx_timestamp()+" "+tspr.get_is_synced()); + outReport.println(foo); + System.out.println(foo); + outReport.flush(); + } + + public void writeFullReprot(TestFTSPMsg tspr) + { + String foo = (System.currentTimeMillis() + +" "+tspr.get_src_addr() + +" "+tspr.get_counter() + +" "+tspr.get_local_rx_timestamp() + +" "+tspr.get_global_rx_timestamp() + +" "+tspr.get_skew_times_1000000() + +" "+tspr.get_is_synced() + +" "+tspr.get_ftsp_root_addr() + +" "+tspr.get_ftsp_seq() + +" "+tspr.get_ftsp_table_entries()); + outReport.println(foo); + System.out.println(foo); + outReport.flush(); + } + + public void messageReceived(int dest_addr, Message msg) + { + if (msg instanceof TestFTSPMsg) + //writeFullReprot((TestFTSPMsg)msg); + writeReprot((TestFTSPMsg)msg); + } + + /* Just start the app... */ + public static void main(String[] args) + { + new FTSPDataLogger(); + } +} \ No newline at end of file diff --git a/apps/tests/TestFTSP/Makefile b/apps/tests/TestFTSP/Makefile index accc415e..fd9f815f 100644 --- a/apps/tests/TestFTSP/Makefile +++ b/apps/tests/TestFTSP/Makefile @@ -1,18 +1,18 @@ -BUILD_EXTRA_DEPS = TestFTSPMsg.class +BUILD_EXTRA_DEPS = FTSPDataLogger.class CLEAN_EXTRA = *.class TestFTSPMsg.java -TestFTSPMsg.class: TestFTSPMsg.java - javac TestFTSPMsg.java +FTSPDataLogger.class: TestFTSPMsg.java + javac *.java TestFTSPMsg.java: TestFTSP.h mig java -target=$(PLATFORM) $(CFLAGS) -java-classname=TestFTSPMsg TestFTSP.h test_ftsp_msg -o $@ COMPONENT=TestFTSPC -PFLAGS += -v -DTIMESYNC_RATE=10 +PFLAGS += -DTIMESYNC_RATE=3 #PFLAGS += -DTIMESYNC_DEBUG -PFLAGS += -I$(TOSDIR)/lib/FTSP -I$(TOSDIR)/../apps/RadioCountToLeds +PFLAGS += -I$(TOSDIR)/lib/ftsp -I$(TOSDIR)/../apps/RadioCountToLeds -include $(MAKERULES) +include ../../Makerules -- 2.39.2