[Firebug-cvs] fireboard/beta/fireworks/tools/java/net/sf/firebug/DataCollection DataCollect.java,1.7
Brought to you by:
doolin
From: Karthik D. <da...@us...> - 2005-08-31 08:39:54
|
Update of /cvsroot/firebug/fireboard/beta/fireworks/tools/java/net/sf/firebug/DataCollection In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23744/net/sf/firebug/DataCollection Modified Files: DataCollect.java Log Message: Working new queueing system Index: DataCollect.java =================================================================== RCS file: /cvsroot/firebug/fireboard/beta/fireworks/tools/java/net/sf/firebug/DataCollection/DataCollect.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DataCollect.java 30 Aug 2005 00:28:35 -0000 1.7 --- DataCollect.java 31 Aug 2005 08:39:46 -0000 1.8 *************** *** 43,47 **** int nPort; MoteIF dataCollectStub; ! List dlist, clist; private static void prt(String s) { --- 43,47 ---- int nPort; MoteIF dataCollectStub; ! List dataQueue, calibrationList; private static void prt(String s) { *************** *** 145,150 **** public DataCollect() { ! dlist = new LinkedList(); ! clist = new LinkedList(); this.dataCollectStub = null; try { --- 145,150 ---- public DataCollect() { ! dataQueue = new LinkedList(); ! calibrationList = new LinkedList(); this.dataCollectStub = null; try { *************** *** 161,165 **** --- 161,179 ---- public void packetReceived(byte[] packet) { } + + private void processData() { + int counter=0; + for(counter=0;counter<dataQueue.size();counter++) { + // while(data.hasNext()) { + DataCollectionMsg msg = (DataCollectionMsg) dataQueue.get(counter); + + if(get_calibration((long)msg.get_src()) != -1) { + prt("In process data - processing element"); + printData(get_calibration(msg.get_src()),msg); + break; + } + } + } public static void main(String args[]) { *************** *** 195,198 **** --- 209,213 ---- public void messageReceived(int to, Message m) { // prt("Message Received with AM Type " + m.amType()); + printCalibrationList(); if(m.amType() == DataCollectionMsg.AM_TYPE) { MultihopMsg msg = new MultihopMsg(m.dataGet()); *************** *** 202,206 **** public void pReceived(MultihopMsg m) { ! int index=0; int i; --- 217,221 ---- public void pReceived(MultihopMsg m) { ! int index=-1; int i; *************** *** 210,226 **** System.out.println("Sensor reading"); ! if(get_data((long)msg.get_seq_no(), (long)msg.get_src()) == 0) { prt("not duplicate with seq no " + msg.get_seq_no()); /* Not a duplicate */ ! if((index = get_calibration((long)msg.get_seq_no(), (long)msg.get_src())) == 0) { /* No calibration data received yet. So, add to the list */ prt("Added to list"); ! dlist.add(msg); } else { ! dlist.add(msg); prt("Sending to print"); ! printData(index, get_data((long)msg.get_seq_no(), (long)msg.get_src())); } } --- 225,243 ---- System.out.println("Sensor reading"); ! if(get_data((long)msg.get_seq_no(), (long)msg.get_src()) == -1) { prt("not duplicate with seq no " + msg.get_seq_no()); /* Not a duplicate */ ! if((index = get_calibration((long)msg.get_src())) == -1) { /* No calibration data received yet. So, add to the list */ prt("Added to list"); ! dataQueue.add(msg); ! if(dataQueue.size() > 50) ! processData(); } else { ! dataQueue.add(msg); prt("Sending to print"); ! printData(index,msg); // get_data((long)msg.get_seq_no(), (long)msg.get_src())); } } *************** *** 231,234 **** --- 248,265 ---- CalibrationMsg cMsg = new CalibrationMsg(m.dataGet(), m.offset_data(0)); if(cMsg.get_type() == CALIBRATION) { + System.out.println("Calibration"); + prt("Calibration data received for node "+cMsg.get_src()); + index = get_calibration(cMsg.get_src()); + prt("Calibration index is " + index); + if(index == -1) + calibrationList.add(cMsg); + + prt("processing data now"); + processData(); + } + } + + + /* prt("2. Type is " + msg.get_type()); // System.out.println("Data received is " + DataCollect.byteArrayToHexString(m.dataGet())); *************** *** 241,266 **** // CalibrationMsg cMsg = new CalibrationMsg(m.dataGet(),m.offset_data(0)); if(get_calibration((long)cMsg.get_seq_no(), (long)cMsg.get_src()) == 0) { ! /* Not a duplicate */ prt("not duplicate with seq no " + msg.get_seq_no()); if((index = get_data((long)cMsg.get_seq_no(), (long)cMsg.get_src())) == 0) { /* No calibration data received yet. ! So, add to the list */ prt("Added to list"); ! clist.add(cMsg); } else { ! clist.add(cMsg); prt("Send to print"); printData(get_calibration((long)cMsg.get_seq_no(), (long)cMsg.get_src()), index); } ! } ! } ! } ! void printData(int cindex, int dindex) { ! prt("In print data"); ! DataCollectionMsg dMsg = (DataCollectionMsg) dlist.get(dindex); ! CalibrationMsg cMsg = (CalibrationMsg) clist.get(cindex); ! int source; long seqno; --- 272,293 ---- // CalibrationMsg cMsg = new CalibrationMsg(m.dataGet(),m.offset_data(0)); if(get_calibration((long)cMsg.get_seq_no(), (long)cMsg.get_src()) == 0) { ! /* Not a duplicate prt("not duplicate with seq no " + msg.get_seq_no()); if((index = get_data((long)cMsg.get_seq_no(), (long)cMsg.get_src())) == 0) { /* No calibration data received yet. ! So, add to the list prt("Added to list"); ! calibrationList.add(cMsg); } else { ! calibrationList.add(cMsg); prt("Send to print"); printData(get_calibration((long)cMsg.get_seq_no(), (long)cMsg.get_src()), index); } ! } ! } ! */ ! void printData(DataCollectionMsg dMsg, CalibrationMsg cMsg) { int source; long seqno; *************** *** 285,289 **** prt("Raw humidity : "+ dMsg.get_humidity()); prt("Raw voltage : "+ dMsg.get_ivolt()); ! prt("Raw itemp : "+ dMsg.get_itemp()); prt("Raw Pressure : "+ dMsg.get_pressure()); prt("Raw calibration readings "+DataCollect.byteArrayToHexString(DataCollect.intToByteArray(cMsg.get_calibration()))); --- 312,316 ---- prt("Raw humidity : "+ dMsg.get_humidity()); prt("Raw voltage : "+ dMsg.get_ivolt()); ! // prt("Raw itemp : "+ dMsg.get_itemp()); prt("Raw Pressure : "+ dMsg.get_pressure()); prt("Raw calibration readings "+DataCollect.byteArrayToHexString(DataCollect.intToByteArray(cMsg.get_calibration()))); *************** *** 307,323 **** } /* 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(((long)msg.get_seq_no()) == seqno && ((long)msg.get_src()) == src) { --- 334,389 ---- } /* Delete the printed data */ ! dataQueue.remove(dMsg); ! System.out.println("\n\nSize of dataQueue:"+dataQueue.size() +" and calibrationList:"+calibrationList.size()+" \n\n"); ! } ! ! void printData(int cindex, int dindex) { ! prt("In print data"); ! if(!((dataQueue.size() >0) || (calibrationList.size() > 0))) ! return; ! DataCollectionMsg dMsg = (DataCollectionMsg) dataQueue.get(dindex); ! CalibrationMsg cMsg = (CalibrationMsg) calibrationList.get(cindex); ! ! printData(dMsg, cMsg); ! } ! ! void printData(CalibrationMsg cMsg, int dindex) { ! prt("In print data"); ! if(!(dataQueue.size() >0)) ! return; ! DataCollectionMsg dMsg = (DataCollectionMsg) dataQueue.get(dindex); ! ! if(cMsg.get_src() == dMsg.get_src()) ! printData(dMsg, cMsg); } + void printData(int cindex, DataCollectionMsg dMsg) { + prt("In print data"); + if(!(calibrationList.size() >0)) + return; + + /* + if(get_calibration((long)cindex) == -1) { + return; + } + */ + + CalibrationMsg cMsg = (CalibrationMsg) calibrationList.get(cindex); + + if(cMsg.get_src() == dMsg.get_src()) { + printData(dMsg, cMsg); + } + else { + prt("Weird. It should not come here"); + } + } + private int get_data(long seqno, long src) { boolean found=false; ! int index=-1; ! for(index=0;index<dataQueue.size();index++) { ! DataCollectionMsg msg = (DataCollectionMsg) dataQueue.get(index); if(((long)msg.get_seq_no()) == seqno && ((long)msg.get_src()) == src) { *************** *** 325,362 **** 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(((long)msg.get_seq_no()) == seqno && ((long)msg.get_src()) == src) { found=true; break; } - else { - index++; - } } ! if(!found) { ! index=0; ! } ! ! return index; } --- 391,423 ---- break; } } if(!found) { ! index=-1; } return index; } ! ! private int get_calibration(long src) { ! int retval = -1; ! int counter = 0; boolean found=false; ! ! for(counter=0;counter<calibrationList.size();counter++) { ! if((((CalibrationMsg)calibrationList.get(counter)).get_src()) == src) { ! retval = counter; found=true; break; } } ! if(!found) ! retval = -1; ! return retval; ! } ! ! private int get_calibration(long seqno, long src) { ! return get_calibration(src); } *************** *** 423,426 **** --- 484,502 ---- return byteArray; } + + void printCalibrationList() { + int i=0; + for(i=0;i<calibrationList.size();i++) + prt(" " + ((CalibrationMsg)calibrationList.get(i)).get_src()); + prt(""); + } + + + void printDataQueue() { + int i=0; + for(i=0;i<dataQueue.size();i++) + prt(" " + ((DataCollectionMsg)dataQueue.get(i)).get_src()); + prt(""); + } } |