[Firebug-cvs] fireboard/beta/fireworks/tools/java/net/sf/firebug/DataCollection DataCollect.java,NON
Brought to you by:
doolin
From: Karthik D. <da...@us...> - 2005-08-28 20:01:52
|
Update of /cvsroot/firebug/fireboard/beta/fireworks/tools/java/net/sf/firebug/DataCollection In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32086 Added Files: DataCollect.java Makefile Log Message: Java modules for data collection --- NEW FILE: DataCollect.java --- /* * Author: Mike Chen <mik...@cs...> * Inception Date: October 22th, 2000 * * This software is copyrighted by Mike Chen and the Regents of * the University of California. The following terms apply to all * files associated with the software unless explicitly disclaimed in * individual files. * * The authors hereby grant permission to use this software without * fee or royalty for any non-commercial purpose. The authors also * grant permission to redistribute this software, provided this * copyright and a copy of this license (for reference) are retained * in all distributed copies. * * For commercial use of this software, contact the authors. * * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES * ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY * DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE * IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE * NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR * MODIFICATIONS. * * Copyright (c) 2005 Moteiv Corporation * All rights reserved. * * This file is distributed under the terms in the attached MOTEIV-LICENSE * file. If you do not find these files, copies can be found at * http://www.moteiv.com/MOTEIV-LICENSE.txt and by emailing in...@mo.... * * Modified September 11, 2004 by Rob Szewczyk <in...@mo...> * to display readings from the contrib/moteiv/apps/PressureTest application */ //============================================================================== //=== DataCollect.java ============================================== package net.sf.firebug.DataCollection; import net.tinyos.message.MessageListener; import net.tinyos.message.*; import java.util.*; /** * * Init the serial port and reads data from it. * * @author <A HREF="http://www.cs.berkeley.edu/~mikechen/">Mike Chen</A> * (<A HREF="mailto:mik...@cs...">mik...@cs...</A>) * @since 1.1.6 * * modified by bwhull to work with the serialforwarder */ public class DataCollect implements MessageListener, Runnable { //========================================================================= //=== CONSTANTS ======================================================= private static int MSG_SIZE = 36; // 4 header bytes, 30 msg bytes, 2 crc // bytes; 2 strength bytes are not // transmitted //========================================================================= //=== PRIVATE VARIABLES ================================================ String strAddr; int nPort; MoteIF dataCollectStub; MoteIF calibrateStub; List dlist, clist; public static double pressure_mbar(int raw_pressure, int raw_temperature, int[] calibration) { int c1,c2,c3,c4,c5,c6; if (calibration.length != 4) return 0; c1 = calibration[0] >> 1; c2 = calibration[2] & 0x3F; c2 <<= 6; c2 |= (calibration[3] & 0x3F); c3 = calibration[3] >> 6; c4 = calibration[2] >> 6; c5 = calibration[0] << 10; c5 &= 0x400; c5 += calibration[1] >> 6; c6 = calibration[1] & 0x3F; int ut1 = 8*c5+20224; int dt = raw_temperature - ut1; double temp = 200 + dt*(c6+50)/(Math.pow(2,10)); double off = c2*4 + ((c4-512)*dt)/(Math.pow(2,12)); double sens = c1 + (c3*dt)/(Math.pow(2,10)) + 24576; double x = (sens * (raw_pressure - 7168))/ (Math.pow(2,14)) - off; double p = x*100/(Math.pow(2,5)) + 250*100; //System.out.println("Press (mbar) : " + p/100); //System.out.println("Press (inHg) : " + p/(100*33.864)); return (p/100); } public static double pressure_inHg(int raw_pressure, int raw_temperature, int[] calibration) { int c1,c2,c3,c4,c5,c6; if (calibration.length != 4) return 0; c1 = calibration[0] >> 1; c2 = calibration[2] & 0x3F; c2 <<= 6; c2 |= (calibration[3] & 0x3F); c3 = calibration[3] >> 6; c4 = calibration[2] >> 6; c5 = calibration[0] << 10; c5 &= 0x400; c5 += calibration[1] >> 6; c6 = calibration[1] & 0x3F; int ut1 = 8*c5+20224; int dt = raw_temperature - ut1; double off = c2*4 + ((c4-512)*dt)/(Math.pow(2,12)); double sens = c1 + (c3*dt)/(Math.pow(2,10)) + 24576; double x = (sens * (raw_pressure - 7168))/ (Math.pow(2,14)) - off; double p = x*100/(Math.pow(2,5)) + 250*100; return (p/(100*33.864)); } public static double pressure_temp(int raw_temperature, int[] calibration) { int c1,c2,c3,c4,c5,c6; if (calibration.length != 4) return 0; c1 = calibration[0] >> 1; c2 = calibration[2] & 0x3F; c2 <<= 6; c2 |= (calibration[3] & 0x3F); c3 = calibration[3] >> 6; c4 = calibration[2] >> 6; c5 = calibration[0] << 10; c5 &= 0x400; c5 += calibration[1] >> 6; c6 = calibration[1] & 0x3F; int ut1 = 8*c5+20224; int dt = raw_temperature - ut1; double temp = 200 + dt*(c6+50)/(Math.pow(2,10)); return (temp/10); } public DataCollect() { this.dataCollectStub = null; try { this.dataCollectStub = new MoteIF(); dataCollectStub.registerListener(new DataCollectionMsg(), this); dataCollectStub.start(); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use Options | File Templates. System.exit(1); } try { this.calibrateStub = new MoteIF(); calibrateStub.registerListener(new CalibrationMsg(), this); calibrateStub.start(); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use Options | File Templates. System.exit(1); } } public void packetReceived(byte[] packet) { } public static void main(String args[]) { DataCollect reader = new DataCollect(); Thread th = new Thread(reader); th.start(); } public void run() { while (true) { try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } } public void messageReceived(int to, Message m) { int index=0; if (m.amType() == DataCollectionMsg.AM_TYPE) { DataCollectionMsg msg = new DataCollectionMsg(m,0); if(get_data(msg.get_seq_no(), (long)msg.get_src()) == 0) { /* Not a duplicate */ if((index = get_calibration(msg.get_seq_no(), (long)msg.get_src())) == 0) { /* No calibration data received yet. So, add to the list */ dlist.add(msg); } else { dlist.add(msg); printData(index, get_data(msg.get_seq_no(), (long)msg.get_src())); } } } else if(m.amType() == CalibrationMsg.AM_TYPE) { CalibrationMsg cMsg = new CalibrationMsg(m,0); if(get_calibration(cMsg.get_seq_no(), (long)cMsg.get_src()) == 0) { /* Not a duplicate */ if((index = get_data(cMsg.get_seq_no(), (long)cMsg.get_src())) == 0) { /* No calibration data received yet. So, add to the list */ clist.add(cMsg); } else { clist.add(cMsg); printData(get_calibration(cMsg.get_seq_no(), (long)cMsg.get_src()), index); } } } } void printData(int cindex, int dindex) { DataCollectionMsg dMsg = (DataCollectionMsg) dlist.get(dindex); CalibrationMsg cMsg = (CalibrationMsg) clist.get(cindex); System.out.println("--reading--"); System.out.println("Source : "+ dMsg.get_src()); System.out.println("Sequence Number: "+ dMsg.get_seq_no()); System.out.println("Raw temperature: "+ dMsg.get_temperature()); System.out.println("Raw humidity : "+ dMsg.get_humidity()); System.out.println("Raw voltage : "+ dMsg.get_ivolt()); System.out.println("Temperature : "+pressure_temp(dMsg.get_temperature(), cMsg.get_calibration())); System.out.println("Pressure : "+pressure_mbar(dMsg.get_pressure(), dMsg.get_temperature(), cMsg.get_calibration())); /* Delete the printed data */ dlist.remove(dindex); clist.remove(cindex); System.out.println("\n\nSize of dlist:"+dlist.size() +" and clist:"+clist.size()+" \n\n"); } private int get_data(long seqno, long src) { boolean found=false; ListIterator it=dlist.listIterator(); int index=0; while(it.hasNext()) { DataCollectionMsg msg = (DataCollectionMsg) it.next(); if(msg.get_seq_no() == seqno && msg.get_src() == src) { found=true; break; } else { index++; } } if(!found) { index=0; } return index; } private int get_calibration(long seqno, long src) { boolean found=false; ListIterator it=clist.listIterator(); int index=0; while(it.hasNext()) { CalibrationMsg msg = (CalibrationMsg) it.next(); if(msg.get_seq_no() == seqno && msg.get_src() == src) { found=true; break; } else { index++; } } if(!found) { index=0; } return index; } } --- NEW FILE: Makefile --- TOS = $(shell ncc -print-tosdir) PACKAGE = net.sf.firebug.DataCollection APP=$(FWROOT)/beta/fireworks/apps/DataCollection MIG = mig java # List of message classes to build MSGS = DataCollectionMsg.java CalibrationMsg.java INITIAL_TARGETS = $(MSGS) OTHER_CLEAN = cleanmig ROOT = $(TOS)/../contrib/moteiv/tools/java include $(ROOT)/Makefile.include DataCollectionMsg.java: $(MIG) -java-classname=$(PACKAGE).DataCollectionMsg $(APP)/DataCollection.h DataCollectionMsg >$@ CalibrationMsg.java: $(MIG) -java-classname=$(PACKAGE).CalibrationMsg $(APP)/Calibration.h CalibrationMsg >$@ cleanmig: rm -f $(MSGS) |