[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/harvard/spaulding/src/gui Block.java, 1.1.1.1, 1.2 Makefile, 1.1.1.1, 1.2 RealTimeSamplesPanel.java, 1.1.1.1, 1.2 Session.java, 1.1.1.1, 1.2 SpauldingApp.java, 1.1.1.1, 1.2

Konrad Lorincz konradlorincz at users.sourceforge.net
Wed Dec 19 17:29:36 PST 2007


Update of /cvsroot/tinyos/tinyos-1.x/contrib/harvard/spaulding/src/gui
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv12615/gui

Modified Files:
	Block.java Makefile RealTimeSamplesPanel.java Session.java 
	SpauldingApp.java 
Log Message:
Added support for sampling multiple motes at different frequencies

Index: Block.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/harvard/spaulding/src/gui/Block.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** Block.java	22 Aug 2007 00:43:53 -0000	1.1.1.1
--- Block.java	20 Dec 2007 01:29:34 -0000	1.2
***************
*** 51,68 ****
      private long blockID;
      private short[] blockBytes = new short[FetchMsgs.FETCH_BLOCK_SIZE];
!     //private long blockTimeRaw = 11;
      private long localTime = 11;
      private long globalTime = 12;
      private int timeSynched = 0;
-     private int channelIDs[] = new int[MercurySampling.MERCURY_NBR_CHANS];
-     private int nbrChannels;
      private int nbrSamples;
      private long samples[][];
  
      // these should come from MIG
      private static final int RAW_BLOCK_TIMER_RATE = SpauldingApp.LOCAL_TIME_RATE_HZ;
!     private static final int NBR_SAMPLES_PER_BLOCK = 114;//120;
!     private static final int SIMULTCHAN_SAMPLES_PER_BLOCK = NBR_SAMPLES_PER_BLOCK / MercurySampling.MERCURY_NBR_CHANS;
!     private static final int SIMULTCHAN_SAMPLING_RATE = MercurySampling.MERCURY_SAMPLING_RATE;
  
      // ======================= Methods =============================
--- 51,72 ----
      private long blockID;
      private short[] blockBytes = new short[FetchMsgs.FETCH_BLOCK_SIZE];
! 
!     // Part of SampleChunk
      private long localTime = 11;
      private long globalTime = 12;
+     private int samplingRate = 1;
      private int timeSynched = 0;
      private int nbrSamples;
+     private int channelIDs[] = new int[MultiChanSampling.MCS_MAX_NBR_CHANNELS_SAMPLED];
      private long samples[][];
  
+     // other
+     private int nbrChannels;
+     private boolean wasParsed = false;
      // these should come from MIG
      private static final int RAW_BLOCK_TIMER_RATE = SpauldingApp.LOCAL_TIME_RATE_HZ;
! //    private static final int NBR_SAMPLES_PER_BLOCK = 114;//120;
! //    private static final int SIMULTCHAN_SAMPLES_PER_BLOCK = NBR_SAMPLES_PER_BLOCK / MercurySampling.MERCURY_NBR_CHANS;
! //    private static final int SIMULTCHAN_SAMPLING_RATE = MercurySampling.MERCURY_SAMPLING_RATE;
  
      // ======================= Methods =============================
***************
*** 76,88 ****
      public long getBlockID()  {return blockID;}
  
!     public static double nbrBlocksPerSamplingTimeMS(long samplingTimeMS)
!     {
!         final double SIMULTCHAN_SAMPLES_PER_MS = (double)SIMULTCHAN_SAMPLING_RATE/1000.0;
!         double nbrBlocks = (double)(samplingTimeMS * SIMULTCHAN_SAMPLES_PER_MS) / (double)SIMULTCHAN_SAMPLES_PER_BLOCK;
! 
!         System.out.println("********** Block.nbrBlocksPerSamplingTimeMS() - time= " + samplingTimeMS +
!                            " => nbrBlocks= " + nbrBlocks);
!         return nbrBlocks;
!     }
  
      public void setBlockBytes(int offset, short[] bytes)
--- 80,92 ----
      public long getBlockID()  {return blockID;}
  
! //    public static double nbrBlocksPerSamplingTimeMS(long samplingTimeMS)
! //    {
! //        final double SIMULTCHAN_SAMPLES_PER_MS = (double)SIMULTCHAN_SAMPLING_RATE/1000.0;
! //        double nbrBlocks = (double)(samplingTimeMS * SIMULTCHAN_SAMPLES_PER_MS) / (double)SIMULTCHAN_SAMPLES_PER_BLOCK;
! //
! //        System.out.println("********** Block.nbrBlocksPerSamplingTimeMS() - time= " + samplingTimeMS +
! //                           " => nbrBlocks= " + nbrBlocks);
! //        return nbrBlocks;
! //    }
  
      public void setBlockBytes(int offset, short[] bytes)
***************
*** 92,100 ****
      }
  
- //    public String toString()
- //    {
- //        return "Block [node " + node.getNodeID() + " blockID " + blockID + "] " + toLogString();
- //    }
- 
      /** Return a string representing the raw bytes in the block */
      public String toStringRaw()
--- 96,99 ----
***************
*** 119,123 ****
          String str = "nodeID= " + node.getNodeID() +
                       " blockID= " + blockID +
- //                     " blockTimeRaw= " + blockTimeRaw +
                       " localTime= " + localTime +
                       " globalTime= " + globalTime +
--- 118,121 ----
***************
*** 159,165 ****
          String str = "# nodeID= " + node.getNodeID() +
                       " blockID= " + blockID +
- //                     " blockTimeRaw= " + blockTimeRaw +
                       " localTime= " + localTime +
                       " globalTime= " + globalTime +
                       " timeSynched= " + timeSynched +
                       " localTimeMS= " + dbFormat.format(blockTimeRawToMS(localTime)) +
--- 157,163 ----
          String str = "# nodeID= " + node.getNodeID() +
                       " blockID= " + blockID +
                       " localTime= " + localTime +
                       " globalTime= " + globalTime +
+                      " samplingRate= " + samplingRate +
                       " timeSynched= " + timeSynched +
                       " localTimeMS= " + dbFormat.format(blockTimeRawToMS(localTime)) +
***************
*** 168,172 ****
          for (int samp = 0; samp < samples[0].length; ++samp) {
              double timeMS = blockTimeRawToMS(globalTime) +
!                             ((double)samp/(double)SIMULTCHAN_SAMPLING_RATE);
  
              str += "\n" + dbFormat.format(timeMS) + " ";
--- 166,170 ----
          for (int samp = 0; samp < samples[0].length; ++samp) {
              double timeMS = blockTimeRawToMS(globalTime) +
!                             ((double)samp/(double)this.samplingRate);
  
              str += "\n" + dbFormat.format(timeMS) + " ";
***************
*** 189,192 ****
--- 187,195 ----
      private void parseBlock()
      {
+         if (wasParsed)
+             return;
+         else
+             wasParsed = true;  // will get parsed
+ 
          // (1) - The Block part
          long seqno = bytesToUint32(0);
***************
*** 195,207 ****
  
          // (2) - The SampleChunk part
-         //blockTimeRaw = bytesToUint32(4);
          localTime = bytesToUint32(4);
          globalTime = bytesToUint32(8);
!         timeSynched = bytesToUint16(12);
!         nbrSamples = bytesToUint16(14);
!         nbrChannels = 0;
!         for (int chan = 0; chan < MercurySampling.MERCURY_NBR_CHANS; chan++) {
!             channelIDs[chan] = (int) (blockBytes[16 + chan] & 0xff);
!             if (channelIDs[chan] != MercurySampling.MERCURY_CHAN_INVALID)
                  nbrChannels++;
          }
--- 198,210 ----
  
          // (2) - The SampleChunk part
          localTime = bytesToUint32(4);
          globalTime = bytesToUint32(8);
!         samplingRate = bytesToUint16(12);
!         timeSynched = bytesToUint16(14);
!         nbrSamples = bytesToUint16(16);
!         nbrChannels = 0;  // MUST be set to Zero, else if parseBlock() runs multiple times, it will get incremented!
!         for (int chan = 0; chan < MultiChanSampling.MCS_MAX_NBR_CHANNELS_SAMPLED; chan++) {
!             channelIDs[chan] = (int) (blockBytes[18 + chan] & 0xff);
!             if (channelIDs[chan] != MultiChanSampling.CHAN_INVALID)
                  nbrChannels++;
          }
***************
*** 213,217 ****
          // Start of sample data
          final int NBR_BYTES_PER_SAMPLE = 2;
!         int offset = 22;
          int curChan = 0;
          int sampleIndex = 0;
--- 216,220 ----
          // Start of sample data
          final int NBR_BYTES_PER_SAMPLE = 2;
!         int offset = 24;
          int curChan = 0;
          int sampleIndex = 0;
***************
*** 222,227 ****
              }
              else {
!                 samples[curChan][sampleIndex] = bytesToUint16(offset);
!                 offset += NBR_BYTES_PER_SAMPLE;
              }
              curChan++;
--- 225,238 ----
              }
              else {
!                 try {
!                     samples[curChan][sampleIndex] = bytesToUint16(offset);
!                     offset += NBR_BYTES_PER_SAMPLE;
!                 }
!                 catch (ArrayIndexOutOfBoundsException e) {
!                     System.out.printf("offset= %d, curChan= %d, sampleIndex= %d, samplingRate= %d, nbrSamples= %d",
!                             offset, curChan, sampleIndex, samplingRate, nbrSamples);
!                     e.printStackTrace();
!                     System.exit(1);
!                 }
              }
              curChan++;

Index: Makefile
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/harvard/spaulding/src/gui/Makefile,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** Makefile	22 Aug 2007 00:43:54 -0000	1.1.1.1
--- Makefile	20 Dec 2007 01:29:34 -0000	1.2
***************
*** 5,10 ****
  	   SRC_../fetch/FetchMsgs.h__OUT_FetchReplyMsg \
             SRC_../lib/ErrorToLeds.h__OUT_ErrorToLedsMsg
! NCGFILES = SRC_../sampling/MercurySampling.h__OUT_MercurySampling \
! 	   SRC_../sampling/MultiChanSampling.h__OUT_MultiChanSampling \
  	   SRC_../realTimeSamples/RealTimeSamples.h__OUT_RealTimeSamples \
  	   SRC_../fetch/FetchMsgs.h__OUT_FetchMsgs \
--- 5,9 ----
  	   SRC_../fetch/FetchMsgs.h__OUT_FetchReplyMsg \
             SRC_../lib/ErrorToLeds.h__OUT_ErrorToLedsMsg
! NCGFILES = SRC_../sampling/MultiChanSampling.h__OUT_MultiChanSampling \
  	   SRC_../realTimeSamples/RealTimeSamples.h__OUT_RealTimeSamples \
  	   SRC_../fetch/FetchMsgs.h__OUT_FetchMsgs \

Index: RealTimeSamplesPanel.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/harvard/spaulding/src/gui/RealTimeSamplesPanel.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** RealTimeSamplesPanel.java	22 Aug 2007 00:43:54 -0000	1.1.1.1
--- RealTimeSamplesPanel.java	20 Dec 2007 01:29:34 -0000	1.2
***************
*** 57,69 ****
      public void newSamplesAdded(double firstMCSTimeSec, int[] samples)
      {
!         for (int i = 0; i < samples.length; ++i) {
!             int chanID = i % MercurySampling.MERCURY_NBR_CHANS;
!             double deltaTimeSec = (double) RealTimeSamples.REALTIMESAMPLES_DOWNSAMPLE_FACTOR *
!                                   (double)((int)i/(int)MercurySampling.MERCURY_NBR_CHANS) /
!                                   (double)MercurySampling.MERCURY_SAMPLING_RATE;
!             double currMCSTimeSec = firstMCSTimeSec + deltaTimeSec;
! 
!             getGraphPanel(chanID).addData(currMCSTimeSec, (samples[i] & 0x0fff));
!         }
      }
  
--- 57,69 ----
      public void newSamplesAdded(double firstMCSTimeSec, int[] samples)
      {
! //        for (int i = 0; i < samples.length; ++i) {
! //            int chanID = i % MercurySampling.MERCURY_NBR_CHANS;
! //            double deltaTimeSec = (double) RealTimeSamples.REALTIMESAMPLES_DOWNSAMPLE_FACTOR *
! //                                  (double)((int)i/(int)MercurySampling.MERCURY_NBR_CHANS) /
! //                                  (double)MercurySampling.MERCURY_SAMPLING_RATE;
! //            double currMCSTimeSec = firstMCSTimeSec + deltaTimeSec;
! //
! //            getGraphPanel(chanID).addData(currMCSTimeSec, (samples[i] & 0x0fff));
! //        }
      }
  

Index: Session.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/harvard/spaulding/src/gui/Session.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** Session.java	22 Aug 2007 00:43:54 -0000	1.1.1.1
--- Session.java	20 Dec 2007 01:29:34 -0000	1.2
***************
*** 61,64 ****
--- 61,65 ----
      private String sessionName = "DefaultSessionName"; // the session name
      private int subjectID = 0;
+     private Map<Node, Long> nodesDownloadTailBlockID = Collections.synchronizedMap(new HashMap<Node, Long>());
      private Map<Node, Long> nodesDownloadHeadBlockID = Collections.synchronizedMap(new HashMap<Node, Long>());
      // ---------------------
***************
*** 307,310 ****
--- 308,313 ----
                      // (b) Start sampling all nodes
                      System.out.println("=====>>>>> Session.run() - part 1");
+                     for (Node node: this.participatingNodes)
+                         this.nodesDownloadTailBlockID.put(node, node.getHeadBlockID());
                      setState(State.SAMPLING);
                      this.startSamplingPrivate();
***************
*** 334,342 ****
                      // Record the tailBlockID for each node.  This will be used when we download data for this session
                      String infoLog = "samplingDurationMS= " + this.samplingDuration +
!                                      ", nbrBlocksToDownload= " + this.nbrBlocksToDownload() +
!                                      ", <nodeID,headBlockID>=";
                      for (Node node: this.participatingNodes) {
                          nodesDownloadHeadBlockID.put(node, node.getHeadBlockID());
!                         infoLog += " <" + node.getNodeID() + "," + node.getHeadBlockID() + ">";
                      }
                      Logger.writeln(infoLog, getFileInfoStr(), true);
--- 337,344 ----
                      // Record the tailBlockID for each node.  This will be used when we download data for this session
                      String infoLog = "samplingDurationMS= " + this.samplingDuration +
!                                      ", <nodeID,tailBlockID,headBlockID>=";
                      for (Node node: this.participatingNodes) {
                          nodesDownloadHeadBlockID.put(node, node.getHeadBlockID());
!                         infoLog += " <" + node.getNodeID() + "," + node.getTailBlockID() + "," + node.getHeadBlockID() + ">";
                      }
                      Logger.writeln(infoLog, getFileInfoStr(), true);
***************
*** 405,412 ****
      }
  
!     private int nbrBlocksToDownload()
!     {
!         return (int) Math.round(Block.nbrBlocksPerSamplingTimeMS(samplingDuration));
!     }
  
      private void downloadSamples()
--- 407,415 ----
      }
  
! //    private int nbrBlocksToDownload(int nodeID)
! //    {
! //
! //        return (int) Math.round(Block.nbrBlocksPerSamplingTimeMS(samplingDuration));
! //    }
  
      private void downloadSamples()
***************
*** 420,425 ****
              //FetchRequest fetchRequest = new FetchRequest(spauldingApp, node, fetchLogger, -1, nbrBlockToDownload);
  
!             int nbrBlockToDownload = nbrBlocksToDownload();
!             long startBlockID = nodesDownloadHeadBlockID.get(node) - nbrBlockToDownload;
  
              FetchLogger fetchLogger = new FetchLogger(spauldingApp, node, FetchLogger.MANUAL_FETCH, getDate(), getSessionDir());
--- 423,429 ----
              //FetchRequest fetchRequest = new FetchRequest(spauldingApp, node, fetchLogger, -1, nbrBlockToDownload);
  
! //            int nbrBlockToDownload = nbrBlocksToDownload(node.getNodeID());
!             long startBlockID = nodesDownloadTailBlockID.get(node);
!             int nbrBlockToDownload = (int)(nodesDownloadHeadBlockID.get(node) - startBlockID + 1);
  
              FetchLogger fetchLogger = new FetchLogger(spauldingApp, node, FetchLogger.MANUAL_FETCH, getDate(), getSessionDir());

Index: SpauldingApp.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/harvard/spaulding/src/gui/SpauldingApp.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** SpauldingApp.java	22 Aug 2007 00:43:54 -0000	1.1.1.1
--- SpauldingApp.java	20 Dec 2007 01:29:34 -0000	1.2
***************
*** 59,63 ****
      private static final DecimalFormat dbFormat = new DecimalFormat("#.000");
      public static final int LOCAL_TIME_RATE_HZ = 32768;
!     private static final boolean PRINT_SAMPLES_ENABLED = false;
  
      public static final String SESSIONS_DIR_STR = "sessions";
--- 59,63 ----
      private static final DecimalFormat dbFormat = new DecimalFormat("#.000");
      public static final int LOCAL_TIME_RATE_HZ = 32768;
!     private static final boolean PRINT_SAMPLES_ENABLED = true;
  
      public static final String SESSIONS_DIR_STR = "sessions";
***************
*** 262,265 ****
--- 262,266 ----
      private void handleSamplingMsg(SamplingMsg sMsg)
      {
+         //System.out.println("=========================== handleSamplingMsg ===================");
          int srcAddr = sMsg.get_srcAddr();
          int sqnNbr = sMsg.get_sqnNbr();
***************
*** 269,272 ****
--- 270,275 ----
  
          int nbrSamples = sMsg.get_nbrSamples();
+         int samplingRate = sMsg.get_samplingRate();
+         short[] channelIDs = sMsg.get_channelIDs();
          int[] samples = new int[nbrSamples];
          //assert (samples.length <= sMsg.get_samples().length);
***************
*** 283,299 ****
                               "  timeSec= " + dbFormat.format(timeSec) +
                               "  nbrSamples= " + nbrSamples +
!                              "  chanMap= [");
!             for (int i = 0; i < MercurySampling.MERCURY_NBR_CHANS; ++i) {
!                 if (i != 0)
!                     System.out.print(" ");
!                 System.out.print((samples[i] >> 12));
              }
              System.out.print("], samples:");
  
              for (int i = 0; i < nbrSamples; ++i) {
!                 if (i % MercurySampling.MERCURY_NBR_CHANS == 0) { // newline
!                     double deltaTimeSec = (double) RealTimeSamples.REALTIMESAMPLES_DOWNSAMPLE_FACTOR *
!                                           (double)((int)i/(int)MercurySampling.MERCURY_NBR_CHANS) /
!                                           (double)MercurySampling.MERCURY_SAMPLING_RATE;
                      double currMCSTimeSec = timeSec + deltaTimeSec;
                      System.out.print("\n    timeSec= " + dbFormat.format(currMCSTimeSec) + ", samples= ");
--- 286,305 ----
                               "  timeSec= " + dbFormat.format(timeSec) +
                               "  nbrSamples= " + nbrSamples +
!                              "  samplingRate= " + samplingRate +
!                              "  channelIDs= [");
!             int nbrChannels = 0;
!             for (int i = 0; i < channelIDs.length; ++i) {
!                 System.out.print(channelIDs[i]);
!                 if (channelIDs[i] != MultiChanSampling.CHAN_INVALID)
!                     nbrChannels++;
              }
              System.out.print("], samples:");
  
              for (int i = 0; i < nbrSamples; ++i) {
!                 if (i % nbrChannels == 0) { // newline
!                     double deltaTimeSec = (double)(i/nbrChannels) / (double)samplingRate;
! //                            (double) RealTimeSamples.REALTIMESAMPLES_DOWNSAMPLE_FACTOR *
! //                                          (double)((int)i/(int)MercurySampling.MERCURY_NBR_CHANS) /
! //                                          (double)MercurySampling.MERCURY_SAMPLING_RATE;
                      double currMCSTimeSec = timeSec + deltaTimeSec;
                      System.out.print("\n    timeSec= " + dbFormat.format(currMCSTimeSec) + ", samples= ");
***************
*** 303,313 ****
          }
  
!         // Update the node
!         Node currNode = nodes.get(srcAddr);
!         if (currNode != null)
!             currNode.addSamples(timeSec, samples);
!         else {
!             // Drop it.  We firste need to receive a ReplyStatusMsg to create a node
!         }
      }
  
--- 309,319 ----
          }
  
! //        // Update the node
! //        Node currNode = nodes.get(srcAddr);
! //        if (currNode != null)
! //            currNode.addSamples(timeSec, samples);
! //        else {
! //            // Drop it.  We firste need to receive a ReplyStatusMsg to create a node
! //        }
      }
  



More information about the Tinyos-contrib-commits mailing list