[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/GGB/tools/java/net/tinyos/sentri CmdP.java, NONE, 1.1 Counter.java, NONE, 1.1 DataCenter.java, NONE, 1.1 DriveTest.java, NONE, 1.1 Makefile, NONE, 1.1 NodeList.java, NONE, 1.1 README, NONE, 1.1 TosP.java, NONE, 1.1 collect_data.py, NONE, 1.1 old_run_app.py, NONE, 1.1 prepare_app.py, NONE, 1.1 run_app.py, NONE, 1.1 stressTest.sh, NONE, 1.1 test_app.py, NONE, 1.1

Sukun Kim binetude at users.sourceforge.net
Thu Nov 30 16:57:03 PST 2006


Update of /cvsroot/tinyos/tinyos-1.x/contrib/GGB/tools/java/net/tinyos/sentri
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2575

Added Files:
	CmdP.java Counter.java DataCenter.java DriveTest.java Makefile 
	NodeList.java README TosP.java collect_data.py old_run_app.py 
	prepare_app.py run_app.py stressTest.sh test_app.py 
Log Message:


--- NEW FILE: CmdP.java ---
// $Id: CmdP.java,v 1.1 2006/12/01 00:57:00 binetude Exp $

/*									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-2003 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.
 */

/**
 * File: CmdP.java
 *
 * @author <a href="mailto:binetude at cs.berkeley.edu">Sukun Kim</a>
 */

package net.tinyos.sentri;

class Arg {
  static final short NO_ARG =5; // change when new arg is added
  static final String[] nm = new String[NO_ARG];
 
  static final short DEST = 0; {nm[DEST] = "dest";}
  static final short NSAMPLES =1; {nm[NSAMPLES] = "nSamples";}
  static final short INTRV = 2; {nm[INTRV] = "intrv";}
  static final short CHNLNO = 3; {nm[CHNLNO] = "chnlNo";}
  static final short SAMPLENO = 4; {nm[SAMPLENO] = "sampleNo";}

  static String getString(short arg) {
    return "<" + nm[arg] + ">";
  }
};



class Optn {
  static final short NO_OPTN = 6; // change when new optn is added
  static final String[] nm = new String[NO_OPTN];
  static final boolean[] arg = new boolean[NO_OPTN];
 
  static final short DEST = 0; {nm[DEST] = "dest";
    arg[DEST] = true;}
  static final short CHNLSELECT = 1; {nm[CHNLSELECT] = "chnlSelect";
    arg[CHNLSELECT] = true;}
  static final short SAMPLESTOAVG  = 2; {nm[SAMPLESTOAVG] = "samplesToAvg";
    arg[SAMPLESTOAVG] = true;}
  static final short NM  = 3; {nm[NM] = "nm";
    arg[NM] = true;}
  static final short TOUART = 4; {nm[TOUART] = "toUART";
    arg[TOUART] = false;}
  static final short VERBOSE = 5; {nm[VERBOSE] = "verbose";
    arg[VERBOSE] = false;}

  static String getString(short optn) {
    String outString = "[-" + nm[optn];
    if (arg[optn]) outString += " " + nm[optn];
    outString += "]";
    return outString;
  }
};



class Cmd {

  static final short NO_CMD = 18; // change when new cmd is added
  static final String[] nm = new String[NO_CMD];
  static final short[] argNo = new short[NO_CMD];
  static final short[][] argList= new short[NO_CMD][];
  static final short[] optnNo = new short[NO_CMD];
  static final short[][] optnList = new short[NO_CMD][];

  static final short LEDON = 0; {nm[LEDON] = "ledOn";
    argNo[LEDON] = 0;
    argList[LEDON] = new short[argNo[LEDON]];

    optnNo[LEDON] = 2;
    optnList[LEDON] = new short[optnNo[LEDON]];
    optnList[LEDON][0] = Optn.DEST;
    optnList[LEDON][1] = Optn.VERBOSE;
  }

  static final short LEDOFF = 1; {nm[LEDOFF] = "ledOff";
    argNo[LEDOFF] = 0;
    argList[LEDOFF] = new short[argNo[LEDOFF]];
    
    optnNo[LEDOFF] = 2;
    optnList[LEDOFF] = new short[optnNo[LEDOFF]];
    optnList[LEDOFF][0] = Optn.DEST;
    optnList[LEDOFF][1] = Optn.VERBOSE;
  }



  static final short PINGNODE = 2; {nm[PINGNODE] = "pingNode";
    argNo[PINGNODE] = 1;
    argList[PINGNODE] = new short[argNo[PINGNODE]];
    argList[PINGNODE][0] = Arg.DEST;
    
    optnNo[PINGNODE] = 2;
    optnList[PINGNODE] = new short[optnNo[PINGNODE]];
    optnList[PINGNODE][0] = Optn.TOUART;
    optnList[PINGNODE][1] = Optn.VERBOSE;
  }

  static final short NODELIST = 3; {nm[NODELIST] = "nodeList";
    argNo[NODELIST] = 0;
    argList[NODELIST] = new short[argNo[NODELIST]];

    optnNo[NODELIST] = 2;
    optnList[NODELIST] = new short[optnNo[NODELIST]];
    optnList[NODELIST][0] = Optn.TOUART;
    optnList[NODELIST][1] = Optn.VERBOSE;
  }



  static final short RESET = 4; {nm[RESET] = "reset";
    argNo[RESET] = 0;
    argList[RESET] = new short[argNo[RESET]];
    
    optnNo[RESET] = 2;
    optnList[RESET] = new short[optnNo[RESET]];
    optnList[RESET][0] = Optn.DEST;
    optnList[RESET][1] = Optn.VERBOSE;
  }

  static final short ERASEFLASH = 5; {nm[ERASEFLASH] = "eraseFlash";
    argNo[ERASEFLASH] = 0;
    argList[ERASEFLASH] = new short[argNo[ERASEFLASH]];
    
    optnNo[ERASEFLASH] = 2;
    optnList[ERASEFLASH] = new short[optnNo[ERASEFLASH]];
    optnList[ERASEFLASH][0] = Optn.DEST;
    optnList[ERASEFLASH][1] = Optn.VERBOSE;
  }

  static final short STARTSENSING = 6; {nm[STARTSENSING] = "startSensing";
    argNo[STARTSENSING] = 2;
    argList[STARTSENSING] = new short[argNo[STARTSENSING]];
    argList[STARTSENSING][0] = Arg.NSAMPLES;
    argList[STARTSENSING][1] = Arg.INTRV;
    
    optnNo[STARTSENSING] = 5;
    optnList[STARTSENSING] = new short[optnNo[STARTSENSING]];
    optnList[STARTSENSING][0] = Optn.DEST;
    optnList[STARTSENSING][1] = Optn.CHNLSELECT;
    optnList[STARTSENSING][2] = Optn.SAMPLESTOAVG;
    optnList[STARTSENSING][3] = Optn.NM;
    optnList[STARTSENSING][4] = Optn.VERBOSE;
  }

  static final short ERASESTART = 7; {nm[ERASESTART] = "eraseStart";
    argNo[ERASESTART] = 2;
    argList[ERASESTART] = new short[argNo[ERASESTART]];
    argList[ERASESTART][0] = Arg.NSAMPLES;
    argList[ERASESTART][1] = Arg.INTRV;
    
    optnNo[ERASESTART] = 5;
    optnList[ERASESTART] = new short[optnNo[ERASESTART]];
    optnList[ERASESTART][0] = Optn.DEST;
    optnList[ERASESTART][1] = Optn.CHNLSELECT;
    optnList[ERASESTART][2] = Optn.SAMPLESTOAVG;
    optnList[ERASESTART][3] = Optn.NM;
    optnList[ERASESTART][4] = Optn.VERBOSE;
  }



  static final short READPROFILE = 8; {nm[READPROFILE] = "readProfile";
    argNo[READPROFILE] = 0;
    argList[READPROFILE] = new short[argNo[READPROFILE]];
    
    optnNo[READPROFILE] = 3;
    optnList[READPROFILE] = new short[optnNo[READPROFILE]];
    optnList[READPROFILE][0] = Optn.DEST;
    optnList[READPROFILE][1] = Optn.TOUART;
    optnList[READPROFILE][2] = Optn.VERBOSE;
  }

  static final short READDATA = 9; {nm[READDATA] = "readData";
    argNo[READDATA] = 0;
    argList[READDATA] = new short[argNo[READDATA]];
    
    optnNo[READDATA] = 3;
    optnList[READDATA] = new short[optnNo[READDATA]];
    optnList[READDATA][0] = Optn.DEST;
    optnList[READDATA][1] = Optn.TOUART;
    optnList[READDATA][2] = Optn.VERBOSE;
  }



  static final short RANDOMREAD = 10; {nm[RANDOMREAD] = "randomRead";
    argNo[RANDOMREAD] = 3;
    argList[RANDOMREAD] = new short[argNo[RANDOMREAD]];
    argList[RANDOMREAD][0] = Arg.DEST;
    argList[RANDOMREAD][1] = Arg.CHNLNO;
    argList[RANDOMREAD][2] = Arg.SAMPLENO;
   
    optnNo[RANDOMREAD] = 2;
    optnList[RANDOMREAD] = new short[optnNo[RANDOMREAD]];
    optnList[RANDOMREAD][0] = Optn.TOUART;
    optnList[RANDOMREAD][1] = Optn.VERBOSE;
  }

  static final short TIMESYNCINFO = 11; {nm[TIMESYNCINFO] = "timesyncInfo";
    argNo[TIMESYNCINFO] = 1;
    argList[TIMESYNCINFO] = new short[argNo[TIMESYNCINFO]];
    argList[TIMESYNCINFO][0] = Arg.DEST;
   
    optnNo[TIMESYNCINFO] = 2;
    optnList[TIMESYNCINFO] = new short[optnNo[TIMESYNCINFO]];
    optnList[TIMESYNCINFO][0] = Optn.TOUART;
    optnList[TIMESYNCINFO][1] = Optn.VERBOSE;
  }

  static final short NETWORKINFO = 12; {nm[NETWORKINFO] = "networkInfo";
    argNo[NETWORKINFO] = 1;
    argList[NETWORKINFO] = new short[argNo[NETWORKINFO]];
    argList[NETWORKINFO][0] = Arg.DEST;
   
    optnNo[NETWORKINFO] = 2;
    optnList[NETWORKINFO] = new short[optnNo[NETWORKINFO]];
    optnList[NETWORKINFO][0] = Optn.TOUART;
    optnList[NETWORKINFO][1] = Optn.VERBOSE;
  }



  static final short FIXROUTE = 13; {nm[FIXROUTE] = "fixRoute";
    argNo[FIXROUTE] = 0;
    argList[FIXROUTE] = new short[argNo[FIXROUTE]];
    
    optnNo[FIXROUTE] = 2;
    optnList[FIXROUTE] = new short[optnNo[FIXROUTE]];
    optnList[FIXROUTE][0] = Optn.DEST;
    optnList[FIXROUTE][1] = Optn.VERBOSE;
  }
  
  static final short RELEASEROUTE = 14; {nm[RELEASEROUTE] = "releaseRoute";
    argNo[RELEASEROUTE] = 0;
    argList[RELEASEROUTE] = new short[argNo[RELEASEROUTE]];
    
    optnNo[RELEASEROUTE] = 2;
    optnList[RELEASEROUTE] = new short[optnNo[RELEASEROUTE]];
    optnList[RELEASEROUTE][0] = Optn.DEST;
    optnList[RELEASEROUTE][1] = Optn.VERBOSE;
  }



  static final short FORDEBUG = 15; {nm[FORDEBUG] = "forDebug";
    argNo[FORDEBUG] = 0;
    argList[FORDEBUG] = new short[argNo[FORDEBUG]];
    
    optnNo[FORDEBUG] = 3;
    optnList[FORDEBUG] = new short[optnNo[FORDEBUG]];
    optnList[FORDEBUG][0] = Optn.DEST;
    optnList[FORDEBUG][1] = Optn.TOUART;
    optnList[FORDEBUG][2] = Optn.VERBOSE;
  }



  static final short RESETBCSEQNO = 16; {nm[RESETBCSEQNO] = "resetBcSeqNo";
    argNo[RESETBCSEQNO] = 0;
    argList[RESETBCSEQNO] = new short[argNo[RESETBCSEQNO]];
    
    optnNo[RESETBCSEQNO] = 1;
    optnList[RESETBCSEQNO] = new short[optnNo[RESETBCSEQNO]];
    optnList[RESETBCSEQNO][0] = Optn.VERBOSE;
  }

  static final short HELP = 17; {nm[HELP] = "help";
    argNo[HELP] = 0;
    argList[HELP] = new short[argNo[HELP]];
    
    optnNo[HELP] = 1;
    optnList[HELP] = new short[optnNo[HELP]];
    optnList[HELP][0] = Optn.VERBOSE;
  }



  static String getString(short cmd) {
    String outString = nm[cmd];
    for (short i = 0; i < argNo[cmd]; i++)
      outString += " " + Arg.getString(argList[cmd][i]);
    for (short i = 0; i < optnNo[cmd]; i++) {
      outString += " " + Optn.getString(optnList[cmd][i]);
    }
    return outString;
  }

};



class CmdP {

  //  Command parameters  //
  short cmd = Cmd.NO_CMD;

  boolean broadcasting = true;
  int dest = TosP.TOS_BCAST_ADDR;

  long nSamples = 0;
  long intrv = 0;

  short chnlNo = 0;
  long sampleNo = 0;  

  short chnlSelect = (1 << SentriConsts.MAX_CHANNEL) - 1;
  int samplesToAvg = 1;
  boolean spclNm = false;
  String nm = null;
  short toUART = 0;
  boolean verbose = false;

  private int init() {
    cmd = Cmd.NO_CMD;
  
    broadcasting = true;
    dest = TosP.TOS_BCAST_ADDR;
  
    nSamples = 0;
    intrv = 0;
  
    chnlNo = 0;
    sampleNo = 0;  
  
    chnlSelect = (1 << SentriConsts.MAX_CHANNEL) - 1;
    samplesToAvg = 1;
    spclNm = false;
    nm = null;
    toUART = 0;
    verbose = false;

    return 0;
  }



  private int procArg(String[] args, int argsIndex, short arg) {
    switch (arg) {
    case Arg.DEST:
      broadcasting = false;
      dest = Integer.parseInt(args[argsIndex]);
      break;
    case Arg.NSAMPLES:
      nSamples = Long.parseLong(args[argsIndex]);
      break;
    case Arg.INTRV:
      intrv = Long.parseLong(args[argsIndex]);
      break;
    case Arg.CHNLNO:
      chnlNo = Short.parseShort(args[argsIndex]);
      break;
    case Arg.SAMPLENO:
      sampleNo = Long.parseLong(args[argsIndex]);
      break;
    default:
      System.out.println("ERROR: CmdP.procArg");
      break;
    }
    return 0;
  }

  private int procOptn(String[] args, int argsIndex, short optn) {
    switch (optn) {
    case Optn.DEST:
      broadcasting = false;
      dest = Integer.parseInt(args[argsIndex + 1]);
      break;
    case Optn.CHNLSELECT:
      chnlSelect = Short.parseShort(args[argsIndex + 1]);
      break;
    case Optn.SAMPLESTOAVG:
      samplesToAvg = Integer.parseInt(args[argsIndex + 1]);
      break;
    case Optn.NM:
      spclNm = true;
      nm = args[argsIndex + 1];
      break;
    case Optn.TOUART:
      toUART = 1;
      break;
    case Optn.VERBOSE:
      verbose = true;
      break;
    default:
      System.out.println("ERROR: CmdP.procOptn");
      break;
    }
    return 0;
  }

  int parse(String[] args) {
    int argsIndex = 0;
    short i;
    init();

    //  Parse cmd  //
    if (args.length < 1) {
      System.out.println(getUsage());
      return 1;
    }
    for (i = 0; i < Cmd.NO_CMD; i++)
      if (args[argsIndex].equals(Cmd.nm[i]))
	break;
    if (i == Cmd.NO_CMD) {
      System.out.println(getUsage());
      return 2;
    }
    cmd = i;
    ++argsIndex;


    //  Parse arg  //
    if (args.length < argsIndex + Cmd.argNo[cmd]) {
      System.out.println(getSpecificUsage(cmd));
      return 3;
    }
    for (i = 0; i < Cmd.argNo[cmd]; i++) {
      procArg(args, argsIndex, Cmd.argList[cmd][i]);
      ++argsIndex;
    }

    //  Parse optn  //
    boolean[] optnCheck = new boolean[Optn.NO_OPTN];
    for (i = 0; i < Optn.NO_OPTN; i++) optnCheck[i] = false;
    while (argsIndex < args.length) {
      for (i = 0; i < Optn.NO_OPTN; i++)
        if (args[argsIndex].equals("-" + Optn.nm[i]))
	  break;
	  
      if ((i == Optn.NO_OPTN)
        || (Optn.arg[i] && (args.length < argsIndex + 2))
	|| optnCheck[i]) {
        System.out.println(getSpecificUsage(cmd));
        return 4;
      }
      short j = 0;
      for (j = 0; j < Cmd.optnNo[cmd]; j++) {
        if (Cmd.optnList[cmd][j] == i)
	  break;
      }
      if (j == Cmd.optnNo[cmd]) {
        System.out.println(getSpecificUsage(cmd));
        return 5;
      }
      
      procOptn(args, argsIndex, i);
      ++argsIndex;
      if (Optn.arg[i]) ++argsIndex;
      optnCheck[i] = true;
    }

    if (cmd == Cmd.HELP) System.out.println(getUsage());
    else System.out.println("********  " + Cmd.nm[cmd] + "  ********");
    return 0;
  }



  static final Arg dummyArg = new Arg();
  static final Optn dummyOptn = new Optn();
  static final Cmd dummyCmd = new Cmd();
  private String getUsage() {
    String outString = "Usage: java net.tinyos.SMT.DataCenter"
      + " <command> <arguments> [options] where" + "\n"
      + "\t" + "<command> <arguments> [options] can be"
      + " one of the following:" + "\n\n";
    for (short i = 0; i < Cmd.NO_CMD; i++)
      outString += Cmd.getString(i) + "\n";
    return outString;
  }
  private String getSpecificUsage(short aCmd) {
    return "Usage: java net.tinyos.SMT.DataCenter " + Cmd.getString(aCmd)
      + "\n";
  }

  public String toString() {
    String outString = "";
    outString += "cmd = " + cmd + "\n"
      + "broadcasting = " + broadcasting + ", dest = " + dest + "\n"
      + "nSamples = " + nSamples + ", intrv = " + intrv + "\n"
      + "chnlNo = " + chnlNo + ", sampleNo = " + sampleNo + "\n"
      + "chnlSelect = " + chnlSelect + ", samplesToAvg = " + samplesToAvg + "\n"
      + "spclNm = " + spclNm + ", nm = " + nm + "\n"
      + "toUART = " + toUART + ", verbose = " + verbose + "\n";
    return outString;
  }

}


--- NEW FILE: Counter.java ---
// $Id: Counter.java,v 1.1 2006/12/01 00:57:00 binetude Exp $

/*									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-2003 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.
 */

/**
 * File: Counter.java
 *
 * @author <a href="mailto:binetude at cs.berkeley.edu">Sukun Kim</a>
 */

package net.tinyos.sentri;

import java.io.*;

class Counter {

  private String nm;
  private int no;

  Counter(String aNm) {
    nm = aNm;
  }
  
  int get() {
    try {
      FileReader fr = new FileReader(nm);
      BufferedReader br = new BufferedReader(fr);

      no = Integer.parseInt(br.readLine());
      
      br.close();
      fr.close();
    } catch (IOException e) {
      no = 1;
    }
    return no;
  }
  
  int set(int newNo) {
    try {
      FileOutputStream fos = new FileOutputStream(nm);
      PrintWriter pr = new PrintWriter(fos);
 
      no = newNo;
      pr.println("" + no);
      
      pr.close();
      fos.close();
    } catch (IOException e) {
      System.out.println("Exception: Counter.set"
        + " - while storing number to " + nm);
      return 1;
    }
    return 0;
  }

  int incr() {
    ++no;
    return set(no);
  }

  int reset() {
    return set(1);
  }
  
};


--- NEW FILE: DataCenter.java ---
// $Id: DataCenter.java,v 1.1 2006/12/01 00:57:00 binetude Exp $

/*									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-2003 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.
 */

/**
 * File: DataCenter.java
 *
 * @author <a href="mailto:binetude at cs.berkeley.edu">Sukun Kim</a>
 */

package net.tinyos.sentri;

import java.io.*;
import java.util.*;
import net.tinyos.util.*;
import net.tinyos.message.*;
import net.tinyos.straw.*;

public class DataCenter implements MessageListener {

  //  All in millisecond  //
  private static final short RADIUS_OF_INTERFERENCE = 5;
  private static final long MAX_RLB_TRY = 10;
  private static final long MAX_HOP_CNT = 50;
  private static final long SFTY_FCTR = 1000;

  private static final long RTT = (MAX_HOP_CNT * (2 + 1)
    + RADIUS_OF_INTERFERENCE) * 30 + 100;
  private static final long TIME_TO_ERASE_FLASH
    = SentriConsts.MAX_EEPROM_USAGE / 33 + SFTY_FCTR;
  private static final long TIME_BETWEEN_ERASE_START = SFTY_FCTR;
  private static final long TIME_UNTIL_START = MAX_RLB_TRY * RTT + SFTY_FCTR;
  private static final long TIME_AFTER_START = SFTY_FCTR;
 


  CmdP cmdP = new CmdP();
  TosP tosP = new TosP();
  Counter seqNo = new Counter("Sentri_seqNo.txt");
  int actlSeqNo;
  NodeList nodeList = new NodeList("Sentri_NodeList.txt");

  private MoteIF mote = new MoteIF(PrintStreamMessenger.err); {
    mote.registerListener(new ReplyMsg(), this);
    mote.registerListener(new UARTMsg(), this);
  }
  private CmdBcastMsg bcastMsg = new CmdBcastMsg();
  private CmdMsg cmdMsg = new CmdMsg(bcastMsg,
    SentriConsts.DIVERGENCE_HEADER_LENGTH);
  private boolean msgArrvd = true;

  Straw straw = new Straw();



  private int toPositive(byte inByte) {
    return inByte < 0 ? inByte + 256 : (int)inByte;
  }
 
  private int easyWait(long dur) {
    synchronized (this) {
      try {
        wait(dur);
      } catch (InterruptedException e) {
        System.out.println("EXCEPTION: DataCenter.easyWait");
	return 1;
      }
    }
    return 0;
  }



  private int sendMsg(short type) {
    cmdMsg.set_dest(cmdP.dest);
    cmdMsg.set_seqNo(0);
    cmdMsg.set_type(type);

    switch (type) {
      //  Empty  //
      case SentriConsts.LED_ON:
      case SentriConsts.LED_OFF:
      case SentriConsts.RESET:
      case SentriConsts.ERASE_FLASH:
      case SentriConsts.FIX_ROUTE:
      case SentriConsts.RELEASE_ROUTE:
      case SentriConsts.TIMESYNC_ON:
      case SentriConsts.TIMESYNC_OFF:
        break;

      //  elementaryShared  //
      case SentriConsts.PING_NODE:
      case SentriConsts.READ_PROFILE1:
      case SentriConsts.READ_PROFILE2:
      case SentriConsts.TIMESYNC_INFO:
      case SentriConsts.NETWORK_INFO:
        cmdMsg.set_args_es_toUART(cmdP.toUART);
        break;

      case SentriConsts.FIND_NODE:
        cmdMsg.set_args_fn_noOfNode((short)nodeList.noOfNode);
        for (int i = 0; i < nodeList.noOfNode; i++)
          cmdMsg.setElement_args_fn_nodes(i, nodeList.nodeNo[i]);
        break;
 
      //  sensingShared  //
      case SentriConsts.START_SENSING:
        cmdMsg.set_seqNo(actlSeqNo);
        cmdMsg.set_args_ss_nSamples(cmdP.nSamples);
        cmdMsg.set_args_ss_intrv(cmdP.intrv);
	cmdMsg.set_args_ss_chnlSelect(cmdP.chnlSelect);
	cmdMsg.set_args_ss_samplesToAvg(cmdP.samplesToAvg);
	cmdMsg.set_args_ss_startTime(tosP.tir.globalTime
	  + TIME_UNTIL_START * TosP.TICKS_PER_SECOND / 1000);
 
	String tempNn = null;
	if (cmdP.spclNm) tempNn = cmdP.nm;
	else tempNn = "s" + actlSeqNo;
	short tempLenOfNn = (short)tempNn.length();
        if (tempLenOfNn > SentriConsts.MAX_START_SENSING_NAME)
	  tempLenOfNn = SentriConsts.MAX_START_SENSING_NAME;

  	cmdMsg.set_args_ss_lenOfNm(tempLenOfNn);
        for (int i = 0; i < tempLenOfNn; i++)
          cmdMsg.setElement_args_ss_nm(i, (short)tempNn.charAt(i));
        break;

      case SentriConsts.FOR_DEBUG:
        cmdMsg.set_args_fd_toUART(cmdP.toUART);
        break;

      default:
        System.out.println("ERROR: DataCenter.sendMsg");
	return 1;
    }

    bcastMsg.set_seqno((short)0);

    System.out.println("[Send Msg] " + TosP.getString(cmdMsg));
    if (cmdP.verbose) {
      System.out.println("" + cmdMsg);
      System.out.println("" + bcastMsg);
    }
    try {
      mote.send(TosP.TOS_BCAST_ADDR, bcastMsg);
    } catch (IOException e) {
      System.out.println("EXCEPTION: DataCenter.sendMsg - mote.send failed");
      return 2;
    }
    return 0;
  }

  private boolean sendMsgGetReply(short type, long dur) {
    msgArrvd = false;
    sendMsg(type);
    easyWait(dur);
    if (!msgArrvd)
      System.out.println("Node " + cmdP.dest + " does not respond");
    else if ((cmdP.dest != TosP.TOS_BCAST_ADDR)
      && (tosP.src != cmdP.dest))
      System.out.println("ERROR: DataCenter.sendMsgGetReply"
        + " - dest = " + cmdP.dest + ", src = " + tosP.src);
    return msgArrvd;
  }

  private boolean sendMsgGetReplyRlb(short type) {
    int i;
    for (i = 0; i < MAX_RLB_TRY; i++)
      if (sendMsgGetReply(type, RTT)) break;
    if (i == MAX_RLB_TRY) {
      for (i = 0; i < MAX_RLB_TRY; i++)
        if (sendMsgGetReply(type, 2 * RTT)) break;
    }
    if (i == MAX_RLB_TRY) {
      for (i = 0; i < MAX_RLB_TRY; i++)
        if (sendMsgGetReply(type, 8 * RTT)) break;
    }
    if (i == MAX_RLB_TRY) {
      System.out.println("[Rlb] Node " + cmdP.dest + " does not respond");
      return false;
    } else {
      return true;
    }
  }
  
  //  only for Bcast  //
  private int sendMsgRlb(short type) {
    int returnResult = 1;
    for (int i = 0; i < MAX_RLB_TRY; i++) {
      if (sendMsg(type) == 0) returnResult = 0;
      easyWait(RTT / 2);
    }
    return returnResult;
  }



  public void messageReceived(int src_node, Message msg) {
    ReplyMsg rm = new ReplyMsg(msg, SentriConsts.CONVERGENCE_HEADER_LENGTH);
    tosP.parse(rm);
    System.out.print("[Receive Msg] ");
    System.out.println(tosP);
    if (cmdP.verbose) {
      System.out.println("" + rm);
//      System.out.println("" + (MultihopMsg)msg);
    }
    if (msgArrvd) System.out.println("ERROR: DataCenter.messageReceived"
      + " - unexpected packet");
    msgArrvd = true;
    synchronized (this) {
      notifyAll();
    }
  }



  private int nodeList() {
    nodeList.loadNodeList();
    for (int i = 0; i < nodeList.noOfNode; i++) {
      cmdP.dest = nodeList.nodeNo[i];
      nodeList.nodeVld[i] = sendMsgGetReplyRlb(SentriConsts.PING_NODE);
    }

    nodeList.compactNodeList();
    cmdP.dest = TosP.TOS_BCAST_ADDR;
    while (true) {
      if (sendMsgGetReplyRlb(SentriConsts.FIND_NODE)) {
        nodeList.nodeNo[nodeList.noOfNode] = tosP.src;
        nodeList.nodeVld[nodeList.noOfNode] = true;
        ++nodeList.noOfNode;
      } else {
        break;
      }
    }
    nodeList.saveNodeList();
    nodeList.dumpLodeList();
    return 0;
  }

  private int startSensing() {
    if (cmdP.broadcasting) {
      cmdP.dest = 0;
    }
    if (!sendMsgGetReplyRlb(SentriConsts.TIMESYNC_INFO)) return 1;
    if (cmdP.broadcasting) cmdP.dest = TosP.TOS_BCAST_ADDR;

    actlSeqNo = seqNo.get();
    seqNo.incr();
    sendMsgRlb(SentriConsts.START_SENSING);
    Date sampleTime = new Date();
    System.out.println(sampleTime);
    easyWait((long)(TIME_UNTIL_START
	  + cmdP.nSamples * cmdP.intrv * cmdP.samplesToAvg / 1000
	  + TIME_AFTER_START));
    return 0;
  }

  private int eraseStart() {
    sendMsgRlb(SentriConsts.ERASE_FLASH);
    easyWait(TIME_TO_ERASE_FLASH);
    easyWait(TIME_BETWEEN_ERASE_START);
    return startSensing(); 
  }

  private int readProfile() {
    if (cmdP.broadcasting) {
      nodeList.loadNodeList();
    } else {
      nodeList.noOfNode = 1;
      nodeList.nodeNo[0]  = cmdP.dest;
      nodeList.nodeVld[0] = true;
    }
    for (int i = 0; i < nodeList.noOfNode; i++) {
      cmdP.dest = nodeList.nodeNo[i];
      if (sendMsgGetReplyRlb(SentriConsts.READ_PROFILE1))
        sendMsgGetReplyRlb(SentriConsts.READ_PROFILE2);
    }
    if (cmdP.broadcasting) cmdP.dest = TosP.TOS_BCAST_ADDR;
    return 0;
  }

  private int readData() {
    if (cmdP.broadcasting) {
      nodeList.loadNodeList();
    } else {
      nodeList.noOfNode = 1;
      nodeList.nodeNo[0]  = cmdP.dest;
      nodeList.nodeVld[0] = true;
    }

    for (int i = 0; i < nodeList.noOfNode; i++) {
    
      cmdP.dest = nodeList.nodeNo[i];
      if (!sendMsgGetReplyRlb(SentriConsts.READ_PROFILE1) ||
        !sendMsgGetReplyRlb(SentriConsts.READ_PROFILE2)) {
	return 1;
      }

      if (tosP.rp1r.integrity != 2) return 2;


      //sendMsgRlb(SentriConsts.TIMESYNC_OFF);
      straw.toUART = cmdP.toUART;
      straw.verbose = (short) (cmdP.verbose ? 5 : 2);
      long rawDataSize = tosP.rp1r.nSamples * tosP.rp1r.noOfChnl * 2;
      byte[] rawData = new byte[(int)rawDataSize];
//      if (cmdP.toUART != 0 || rawDataSize <= (long)600000) {
      int tmpResult = straw.read(cmdP.dest, SentriConsts.STRAW_DATA_ID, 0,
        rawDataSize, rawData);
      if (tmpResult != 0)
	return tmpResult + 10;
/*      } else {  //  To prevent blacking out routing layer  //
        straw.read(cmdP.dest, SentriConsts.STRAW_DATA_ID, rawDataSize / 2,
	  rawDataSize / 2, rawData);
        for (int j = 0; j < rawDataSize / 2; j++) {
          rawData[(int)(rawDataSize / 2 + j)] = rawData[j];
        }
	
	for (int j = 0; j < 6; j++) {
	  easyWait(30000);
          sendMsgGetReply(SentriConsts.PING_NODE);
	}
	
        straw.read(cmdP.dest, SentriConsts.STRAW_DATA_ID, 0, rawDataSize / 2,
	  rawData);
      }*/
      //for (int l = 0; l < rawDataSize; l++) {
      //  System.out.print((int)(rawData[l]) + " ");
      //}
      //System.out.println("");
      //sendMsgRlb(SentriConsts.TIMESYNC_ON);


      int chnlIndex = 0;
      for (int j = 0; j < SentriConsts.MAX_CHANNEL; j++) {
        if (!tosP.rp1r.chnlSelectVector[j]) continue;
	FileOutputStream fos = null;
	PrintWriter pr = null;
	try {
  	  fos = new FileOutputStream(tosP.rp2r.nm + "_n" + cmdP.dest
	    + "_c" + (j + 1) + ".txt");
	  pr = new PrintWriter(fos);
	} catch (IOException e) {
          System.out.println("EXCEPTION: DataCenter.transferData - open");
	}

	for (int k = 0; k < tosP.rp1r.nSamples; k++) {
	  int dataIndex = (k * tosP.rp1r.noOfChnl + chnlIndex) * 2;
	  int intprdData = toPositive(rawData[dataIndex])
	    + (toPositive(rawData[dataIndex + 1]) << 8);
	  pr.println((k + 1) + " " + intprdData);
	}

	try {
	  pr.close();
	  fos.close();
	} catch (IOException e) {
          System.out.println("EXCEPTION: DataCenter.transferData - close");
	}
	++chnlIndex;
      }

    }
    if (cmdP.broadcasting) cmdP.dest = TosP.TOS_BCAST_ADDR;
    return 0;
  }

  private int forDebug() {
    return sendMsgGetReply(SentriConsts.FOR_DEBUG, RTT) ? 0 : 1;
  }



  public int execute(String[] args) {
    if (cmdP.parse(args) != 0) return -1;
 
    switch (cmdP.cmd) {
      case Cmd.LEDON:
        return sendMsg(SentriConsts.LED_ON);
      case Cmd.LEDOFF:
        return sendMsg(SentriConsts.LED_OFF);

      case Cmd.PINGNODE:
        return sendMsgGetReply(SentriConsts.PING_NODE, RTT) ? 0 : 1;
      case Cmd.NODELIST:
        return nodeList();

      case Cmd.RESET:
        return sendMsgRlb(SentriConsts.RESET);
      case Cmd.ERASEFLASH:
        sendMsgRlb(SentriConsts.ERASE_FLASH);
        easyWait(TIME_TO_ERASE_FLASH);
	return 0;
      case Cmd.STARTSENSING:
        return startSensing();
      case Cmd.ERASESTART:
        return eraseStart();

      case Cmd.READPROFILE:
        return readProfile();
      case Cmd.READDATA:
        return readData();

      case Cmd.RANDOMREAD:
        System.out.println("Deprecated");
	return 0;
      case Cmd.TIMESYNCINFO:
        return sendMsgGetReplyRlb(SentriConsts.TIMESYNC_INFO) ? 0 : 1;
      case Cmd.NETWORKINFO:
        return sendMsgGetReplyRlb(SentriConsts.NETWORK_INFO) ? 0 : 1;

      case Cmd.FIXROUTE:
        return sendMsgRlb(SentriConsts.FIX_ROUTE);
      case Cmd.RELEASEROUTE:
        return sendMsgRlb(SentriConsts.RELEASE_ROUTE);
	
      case Cmd.FORDEBUG:
        return forDebug();

      case Cmd.RESETBCSEQNO:
        System.out.println("Deprecated");
	return 0;
      case Cmd.HELP:
        return 0;

      default:
        System.out.println("ERROR: DataCenter.execute");
	return 0;
    }
  }

  public static void main(String[] args) {
    DataCenter dc = new DataCenter();
    System.exit(dc.execute(args));
  }
 
};
 

--- NEW FILE: DriveTest.java ---
// $Id: DriveTest.java,v 1.1 2006/12/01 00:57:00 binetude Exp $

/*									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-2003 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.
 */

/**
 * File: DriveTest.java
 *
 * @author <a href="mailto:binetude at cs.berkeley.edu">Sukun Kim</a>
 */

package net.tinyos.sentri;
import java.util.*;

class DriveTest {

  DataCenter dc = new DataCenter();

  private int easyWait(long dur) {
    synchronized (this) {
      try {
        wait(dur);
      } catch (InterruptedException e) {
        System.out.println("EXCEPTION: DataCenter.easyWait");
      }
    }
    return 0;
  }



  private int ledOff() {
    String[] inputArgs;
    inputArgs = new String[1];
    inputArgs[0] = "ledOff";
    //inputArgs[1] = "-verbose";
    return dc.execute(inputArgs);
  }

  private int eraseFlash() {
    String[] inputArgs;
    inputArgs = new String[1];
    inputArgs[0] = "eraseFlash";
    //inputArgs[1] = "-verbose";
    return dc.execute(inputArgs);
  }

  private int startSensing() {
    String[] inputArgs;
    inputArgs = new String[7];
    inputArgs[0] = "startSensing";
    inputArgs[1] = "48000";
    inputArgs[2] = "1000";
    inputArgs[3] = "-chnlSelect";
    inputArgs[4] = "31";
    inputArgs[5] = "-samplesToAvg";
    inputArgs[6] = "5";
    //inputArgs[7] = "-verbose";
    return dc.execute(inputArgs);
  }
  
  private int readData(int dest) {
    String[] inputArgs;
    inputArgs = new String[3];
    inputArgs[0] = "readData";
    inputArgs[1] = "-dest";
    inputArgs[2] = "" + dest;
    //inputArgs[3] = "-verbose";
    return dc.execute(inputArgs);
  }

  private int networkInfo(int dest) {
    String[] inputArgs;
    inputArgs = new String[2];
    inputArgs[0] = "networkInfo";
    inputArgs[1] = "" + dest;
    //inputArgs[2] = "-verbose";
    return dc.execute(inputArgs);
  }

  private int fixRoute() {
    String[] inputArgs;
    inputArgs = new String[1];
    inputArgs[0] = "fixRoute";
    //inputArgs[1] = "-verbose";
    return dc.execute(inputArgs);
  }

  private int releaseRoute() {
    String[] inputArgs;
    inputArgs = new String[1];
    inputArgs[0] = "releaseRoute";
    //inputArgs[1] = "-verbose";
    return dc.execute(inputArgs);
  }



  private int probing() {
    easyWait(10000);
    ledOff();
    easyWait(10000);
    return 0;
  }
  
  private int stressTest() {
    releaseRoute();
    easyWait(1000);
    eraseFlash();
    
    for (int i = 0; i < 6; i++) {
      probing();
    }
    for (int i = 1; i <= 6; i++) {
      if (networkInfo(i) != 0) {
        easyWait(10000);
      }
      easyWait(1000);
    }
    easyWait(120000);
    fixRoute();

    easyWait(60000);
    startSensing();
    easyWait(1000);
/*    for (int i = 1; i <= 6; i++) {
      readData(i);
      easyWait(1000);
    }

    releaseRoute();
*/
    return 0;
  }

  private int batteryTest() {
    for (int i = 14; i <= 15; i++) {
      if (networkInfo(i) != 0) {
        easyWait(10000);
      }
      easyWait(1000);
    }

    return 0;
  }

  public int drive(String[] args) {
    for (int i = 0; i < 1; i++) {
//      System.out.println("################  run " + i);
//      Date currentDate = new Date();
//      System.out.println(currentDate);
      stressTest();
//      batteryTest();
    }

    return 0;
  }

  public static void main(String[] args) {
    DriveTest dt = new DriveTest();
    System.exit(dt.drive(args));
  }

}


--- NEW FILE: Makefile ---
TOS = $(shell ncc -print-tosdir)
PACKAGE = net.tinyos.sentri
APP=$(TOSROOT)/contrib/GGB/apps/Sentri
MIG = mig java
NCG = ncg java
INCLUDES = -I$(TOS)/lib/CC2420Radio
PLATFORM = micaz

MSGS = CmdBcastMsg.java MultihopMsg.java CmdMsg.java ReplyMsg.java UARTMsg.java
CONSTS = SentriConsts.java

INITIAL_TARGETS = $(MSGS) $(CONSTS)
OTHER_CLEAN = cleanmig

ROOT = $(TOS)/../tools/java
include $(ROOT)/Makefile.include


CmdBcastMsg.java:
	$(MIG) -target=$(PLATFORM) $(INCLUDES) -java-classname=$(PACKAGE).CmdBcastMsg $(APP)/CmdBcast.h CmdBcastMsg -o $@

MultihopMsg.java:
	$(MIG) -target=$(PLATFORM) $(INCLUDES) -java-classname=$(PACKAGE).MultihopMsg $(TOS)/lib/MintRoute/MultiHop.h MultihopMsg -o $@

CmdMsg.java:
	$(MIG) -target=$(PLATFORM) $(INCLUDES) -java-classname=$(PACKAGE).CmdMsg $(APP)/CmdMsg.h CmdMsg -o $@

ReplyMsg.java:
	$(MIG) -target=$(PLATFORM) $(INCLUDES) -java-classname=$(PACKAGE).ReplyMsg $(APP)/ReplyMsg.h ReplyMsg -o $@

UARTMsg.java:
	$(MIG) -target=$(PLATFORM) $(INCLUDES) -java-classname=$(PACKAGE).UARTMsg $(APP)/ReplyMsg.h UARTMsg -o $@


SentriConsts.java: $(APP)/DataCollector.h $(APP)/CmdMsg.h $(APP)/ReplyMsg.h
	$(NCG) -target=$(PLATFORM) $(INCLUDES) -java-classname=$(PACKAGE).SentriConsts -I$(APP) $(APP)/DataCollector.h $(APP)/CmdMsg.h $(APP)/ReplyMsg.h DataCollector.h CmdMsg.h ReplyMsg.h -o $@


cleanmig:
	rm -f $(MSGS) $(CONSTS)


--- NEW FILE: NodeList.java ---
// $Id: NodeList.java,v 1.1 2006/12/01 00:57:00 binetude Exp $

/*									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-2003 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.
 */

/**
 * File: NodeList.java
 *
 * @author <a href="mailto:binetude at cs.berkeley.edu">Sukun Kim</a>
 */

package net.tinyos.sentri;

import java.io.*;
//import net.tinyos.util.*;
//import net.tinyos.message.*;

class NodeList {

  String nm;
  //TreeSet nodeSet;
  static final int MAX_NO_OF_NODE = 100;
  int[] nodeNo = new int[MAX_NO_OF_NODE];
  boolean[] nodeVld = new boolean[MAX_NO_OF_NODE];
    { for (int i = 0; i < MAX_NO_OF_NODE; i++) {
      nodeNo[i] = 0;
      nodeVld[i] = false;
    } }
  short noOfNode = 0;

  NodeList(String aNm) {
    nm = aNm;
  }

  void loadNodeList() {
    try {
      FileReader fr = new FileReader(nm);
      BufferedReader br = new BufferedReader(fr);
      noOfNode = Short.parseShort(br.readLine());
      for (int i = 0; i < noOfNode; i++) {
        nodeNo[i] = Integer.parseInt(br.readLine());
        nodeVld[i] = true;
      }
      br.close();
      fr.close();
    } catch (IOException e) {
      for (int i = 0; i < MAX_NO_OF_NODE; i++) {
        nodeNo[i] = 0;
        nodeVld[i] = false;
      }
      noOfNode = 0;
    }
  }
  void saveNodeList() {
    compactNodeList();
    try {
      FileOutputStream fos = new FileOutputStream(nm);
      PrintWriter pr = new PrintWriter(fos);
      pr.println("" + noOfNode);
      for (int i = 0; i < noOfNode; i++)
        pr.println("" + nodeNo[i]);
      pr.close();
      fos.close();
    } catch (IOException e) {
      System.out.println("EXCEPTION while storing node list" + e);
      e.printStackTrace();
    }
  }

  void compactNodeList() {
    short nodeIndex = 0;
    for (int i = 0; i < noOfNode; i++) {
      if (nodeVld[i]) {
        nodeNo[nodeIndex] = nodeNo[i];
        nodeVld[nodeIndex] = true;
        ++nodeIndex;
      }
    }
    noOfNode = nodeIndex;
    for (int i = noOfNode; i < MAX_NO_OF_NODE; i++) {
      nodeNo[i] = 0;
      nodeVld[i] = false;
    }
  }

  void dumpLodeList() {
    int nodeIndex = 0;
    System.out.println("****  NodeList - " + nm);
    for (int i = 0; i < noOfNode; i++)
      if (nodeVld[i]) ++nodeIndex;
    System.out.println("actual noOfNode = " + nodeIndex);
    System.out.println("noOfNode = " + noOfNode);
    for (int i = 0; i < noOfNode; i++)
      System.out.println("nodeNo[" + i + "] = " + nodeNo[i]
        + ", nodeVld[" + i + "] = " + nodeVld[i]);
  }

};
 

--- NEW FILE: README ---
Sentri (Structural hEalth moNiToRing toolkIt)

--- NEW FILE: TosP.java ---
// $Id: TosP.java,v 1.1 2006/12/01 00:57:00 binetude Exp $

/*									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-2003 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.
 */

/**
 * File: TosP.java
 *
 * @author <a href="mailto:binetude at cs.berkeley.edu">Sukun Kim</a>
 */

package net.tinyos.sentri;

class TosP {

  //  TOS related constants  //
  static final long TICKS_PER_SECOND = 921600;
  static final short TOS_BCAST_ADDR = (short)0xffff;



  class readProfile1Reply {
    int seqNo;
    long nSamples;
    long intrv;
    short chnlSelect;
    int samplesToAvg;
    long startTime;
    short integrity;
    
    int noOfChnl;
    boolean[] chnlSelectVector = new boolean[SentriConsts.MAX_CHANNEL];
  };

  class readProfile2Reply {
    short lenOfNm;
    String nm;
  };

  class timesyncInfoReply {
    long sysTime;
    long localTime;
    long globalTime;
  };

  class networkInfoReply {
    int parent;
    int treeParent;
    short depth;
    short treeDepth;
    short occupancy;
    short quality;
    short fixedRoute;
  };

  class forDebugReply {
    short type;
    int[] data = new int[SentriConsts.MAX_FOR_DEBUG_REPLY_DATA];
  };



  int src;
  int type;

  readProfile1Reply rp1r = new readProfile1Reply();
  readProfile2Reply rp2r = new readProfile2Reply();

  timesyncInfoReply tir = new timesyncInfoReply();
  networkInfoReply nir = new networkInfoReply();

  forDebugReply fdr = new forDebugReply();



  int parse(ReplyMsg reply) {
    src = reply.get_src();
    type = reply.get_type();
    switch (type) {
    case SentriConsts.PING_NODE_REPLY:
    case SentriConsts.FIND_NODE_REPLY:
      break;
      
    case SentriConsts.READ_PROFILE1_REPLY:
      rp1r.seqNo = reply.get_args_rp1r_seqNo();
      rp1r.nSamples = reply.get_args_rp1r_nSamples();
      rp1r.intrv = reply.get_args_rp1r_intrv();
      rp1r.chnlSelect = reply.get_args_rp1r_chnlSelect();
      rp1r.samplesToAvg = reply.get_args_rp1r_samplesToAvg();
      rp1r.startTime = reply.get_args_rp1r_startTime();
      rp1r.integrity = reply.get_args_rp1r_integrity();
      rp1r.noOfChnl = 0;
      short tempChnlSelect = rp1r.chnlSelect;
      for (int i = 0; i < SentriConsts.MAX_CHANNEL; i++) {
        if (tempChnlSelect % 2 == 1) {
	  rp1r.chnlSelectVector[i] = true;
	  ++rp1r.noOfChnl;
	} else {
          rp1r.chnlSelectVector[i] = false;
	}
	tempChnlSelect >>= 1;
      }
      break;
    case SentriConsts.READ_PROFILE2_REPLY:
      rp2r.lenOfNm = reply.get_args_rp2r_lenOfNm();
      if (rp2r.lenOfNm > SentriConsts.MAX_READ_PROFILE2_REPLY_NAME)
        rp2r.lenOfNm = SentriConsts.MAX_READ_PROFILE2_REPLY_NAME;
      rp2r.nm = "";
      for (int i = 0; i < rp2r.lenOfNm; i++)
        rp2r.nm += "" + (char)reply.getElement_args_rp2r_nm(i);
      break;
      
    case SentriConsts.TIMESYNC_INFO_REPLY:
      tir.sysTime = reply.get_args_tir_sysTime();
      tir.localTime = reply.get_args_tir_localTime();
      tir.globalTime = reply.get_args_tir_globalTime();
      break;
    case SentriConsts.NETWORK_INFO_REPLY:
      nir.parent = reply.get_args_nir_parent();
      nir.treeParent = reply.get_args_nir_treeParent();
      nir.depth = reply.get_args_nir_depth();
      nir.treeDepth = reply.get_args_nir_treeDepth();
      nir.occupancy = reply.get_args_nir_occupancy();
      nir.quality = reply.get_args_nir_quality();
      nir.fixedRoute = reply.get_args_nir_fixedRoute();
      break;

    case SentriConsts.FOR_DEBUG_REPLY:
      fdr.type = reply.get_args_fdr_type();
      for (int i = 0; i < SentriConsts.MAX_FOR_DEBUG_REPLY_DATA; i++)
        fdr.data[i] = reply.getElement_args_fdr_data(i);
      break;
    
    case SentriConsts.ERROR_REPLY:
      break;
      
    default:
      System.out.println("ERROR: TosP.parse");
      break;
    }
    return 0;
  }

  public String toString() {
    String outString = "src = " + src + ", ";
    switch (type) {
      case SentriConsts.PING_NODE_REPLY:
        outString += "PING_NODE_REPLY";
	break;
      case SentriConsts.FIND_NODE_REPLY:
        outString += "FIND_NODE_REPLY";
        break;
	
      case SentriConsts.READ_PROFILE1_REPLY:
        outString += "READ_PROFILE1_REPLY\n";
	outString += "seqNo = " + rp1r.seqNo
	  + ", nSamples = " + rp1r.nSamples
	  + ", intrv = " + rp1r.intrv + "\n"
	  + "chnlSelect = " + rp1r.chnlSelect
	  + ", samplesToAvg = " + rp1r.samplesToAvg + "\n"
	  + "startTime = " + rp1r.startTime
	  + ", integrity = " + rp1r.integrity;
        break;
      case SentriConsts.READ_PROFILE2_REPLY:
        outString += "READ_PROFILE2_REPLY\n";
	outString += "lenOfNm = " + rp2r.lenOfNm
	  + ", nm= " + rp2r.nm;
        break;
	
      case SentriConsts.TIMESYNC_INFO_REPLY:
        outString += "TIMESYNC_INFO_REPLY\n";
	outString += "sysTime = " + tir.sysTime
	  + ", localTime = " + tir.localTime
	  + ", globalTime = " + tir.globalTime;
        break;
      case SentriConsts.NETWORK_INFO_REPLY:
        outString += "NETWORK_INFO_REPLY\n";
	outString += "parent = " + nir.parent
	  + ", treeParent = " + nir.treeParent
	  + ", depth = " + nir.depth + ", treeDepth = " + nir.treeDepth + "\n"
	  + "occupancy = " + nir.occupancy + ", quality = " + nir.quality
	  + ", fixedRoute = " + nir.fixedRoute;
        break;
	
      case SentriConsts.FOR_DEBUG_REPLY:
        outString += "FOR_DEBUG_REPLY\n";
	outString += "type = " + fdr.type + "\n";
	outString += "data = ";
	for (int i = 0; i < SentriConsts.MAX_FOR_DEBUG_REPLY_DATA; i++)
	  outString += fdr.data[i] + " ";
        break;
      case SentriConsts.ERROR_REPLY:
        outString += "ERROR_REPLY";
        break;
      default:
        outString = "Invalid type: " + type;
        break;
    }
    outString += "\n";
    return outString;
  }



  static String getString(CmdMsg cmdMsg) {
    String outString = "dest = ";
    outString += ((short)cmdMsg.get_dest() == TOS_BCAST_ADDR)
      ? "BC" : "" + cmdMsg.get_dest();
    outString += ", seqNo = " + cmdMsg.get_seqNo() + ", type = ";
    switch (cmdMsg.get_type()) {
    case SentriConsts.LED_ON: outString += "LED_ON"; break;
    case SentriConsts.LED_OFF: outString += "LED_OFF"; break;
  
    case SentriConsts.PING_NODE: outString += "PING_NODE"; break;
    case SentriConsts.FIND_NODE: outString += "FIND_NODE"; break;
  
    case SentriConsts.RESET: outString += "RESET"; break;
    case SentriConsts.ERASE_FLASH: outString += "ERASE_FLASH"; break;
    case SentriConsts.START_SENSING: outString += "START_SENSING"; break;
  
    case SentriConsts.READ_PROFILE1: outString += "READ_PROFILE1"; break;
    case SentriConsts.READ_PROFILE2: outString += "READ_PROFILE2"; break;
  
    case SentriConsts.TIMESYNC_INFO: outString += "TIMESYNC_INFO"; break;
    case SentriConsts.NETWORK_INFO: outString += "NETWORK_INFO"; break;
  
    case SentriConsts.FIX_ROUTE: outString += "FIX_ROUTE"; break;
    case SentriConsts.RELEASE_ROUTE: outString += "RELEASE_ROUTE"; break;
    case SentriConsts.TIMESYNC_ON: outString += "TIMESYNC_ON"; break;
    case SentriConsts.TIMESYNC_OFF: outString += "TIMESYNC_OFF"; break;
    
    case SentriConsts.FOR_DEBUG: outString += "FOR_DEBUG"; break;

    default: outString += "invalid'"; break;
    }
    return outString;
  }

};


--- NEW FILE: collect_data.py ---
#!/usr/bin/python
# $Id: collect_data.py,v 1.1 2006/12/01 00:57:00 binetude Exp $

# "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-2003 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 Sukun Kim <binetude at cs.berkeley.edu>
#

import os

motes = [81, 80, 52, 49, 42, \
46, 21,  7, 43, 60, \
47, 59, 45, 54, 37, \
48, 76,  6, 38, 75, \

14, 50, 86, 92, \
82, 78, 77, \
69,  5, 12, 79, \

73,  9, 65, 71, 44, \
70, 63, 62, 64, 89, \
57, 51, 40, 53, 67, \
74, 68, 34, 36, 30, \

25, 24, 28, 23, \
26, 41, 27, 58]



MAX_RETRY = 10



while True:

#  for i in motes:
#    mote = str(i)
#    os.system('sleep 3')
#    result = 0
#    os.system('java net.tinyos.sentri.DataCenter networkInfo ' + mote)
#    if result != 0:
#      os.system('sleep 10')
  
  for i in motes:
    mote = str(i)
    for j in range(MAX_RETRY):
      os.system('date')
      os.system('sleep 1')
      result = 0
      os.system('java net.tinyos.sentri.DataCenter networkInfo ' + mote)
      result = os.system('java net.tinyos.sentri.DataCenter readData -dest ' + mote)
      if result == 0:
        break


--- NEW FILE: old_run_app.py ---
#!/usr/bin/python
# $Id: old_run_app.py,v 1.1 2006/12/01 00:57:00 binetude Exp $

# "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-2003 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 Sukun Kim <binetude at cs.berkeley.edu>
#

import os

motes = [58, 27, 41, 26, \
30, 36, 34, 68, 74, \
67, 53, 40, 51, 57, \
55, 64, 62, 63, 70, \
44, 71]
MAX_RETRY = 10



while True:

  os.system('date')
  os.system('sleep 1')
  os.system('java net.tinyos.sentri.DataCenter releaseRoute')
  
  
  
  os.system('sleep 1')
  os.system('java net.tinyos.sentri.DataCenter eraseFlash')
  
  
  
  for i in range(6):
    os.system('sleep 20')
    os.system('java net.tinyos.sentri.DataCenter ledOff')
  
  for i in motes:
    mote = str(i)
    os.system('sleep 1')
    result = 0
    os.system('java net.tinyos.sentri.DataCenter networkInfo ' + mote)
    if result != 0:
      os.system('sleep 10')
  
  os.system('sleep 120')
  os.system('java net.tinyos.sentri.DataCenter fixRoute')
  
  
  
  os.system('sleep 60')
  os.system('java net.tinyos.sentri.DataCenter startSensing 48000 1000 -chnlSelect 31 -samplesToAvg 5')
  
  for i in motes:
    mote = str(i)
    for j in range(MAX_RETRY):
      os.system('sleep 1')
      result = 0
      os.system('java net.tinyos.sentri.DataCenter readData -dest ' + mote)
      if result == 0:
        break
  
  
  
  os.system('sleep 1')
  os.system('java net.tinyos.sentri.DataCenter releaseRoute')
  

--- NEW FILE: prepare_app.py ---
#!/usr/bin/python
# $Id: prepare_app.py,v 1.1 2006/12/01 00:57:00 binetude Exp $

# "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-2003 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 Sukun Kim <binetude at cs.berkeley.edu>
#

import os

motes = [1, \
2]
MAX_RETRY = 10

for k in range(2):
  
  os.system('date')
  os.system('sleep 1')
  print 'java net.tinyos.sentri.DataCenter releaseRoute'
  
  
  
  os.system('sleep 1')
  print 'java net.tinyos.sentri.DataCenter eraseFlash'
  
  
  
  for i in range(6):
    os.system('sleep 2')
    print 'java net.tinyos.sentri.DataCenter ledOff'
  
  for i in motes:
    mote = str(i)
    os.system('sleep 1')
    result = 0
    print 'java net.tinyos.sentri.DataCenter networkInfo ' + mote
    if result != 0:
      os.system('sleep 10')
  
  os.system('sleep 12')
  print 'java net.tinyos.sentri.DataCenter fixRoute'
  
  
  
  os.system('sleep 6')
  print 'java net.tinyos.sentri.DataCenter startSensing 48000 1000 -chnlSelect 31 -samplesToAvg 5'
  
  for i in motes:
    mote = str(i)
    for j in range(MAX_RETRY):
      os.system('sleep 1')
      result = 0
      print 'java net.tinyos.sentri.DataCenter readData -dest ' + mote
      if result == 0:
        break
  
  
  
  os.system('sleep 1')
  print 'java net.tinyos.sentri.DataCenter releaseRoute'
  

--- NEW FILE: run_app.py ---
#!/usr/bin/python
# $Id: run_app.py,v 1.1 2006/12/01 00:57:00 binetude Exp $

# "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-2003 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 Sukun Kim <binetude at cs.berkeley.edu>
#

import os

motes = [81, 80, 52, 49, 42, \
46, 21,  7, 43, 60, \
47, 59, 45, 54, 37, \
48, 76,  6, 38, 75, \

14, 50, 86, 92, \
82, 78, 77, \
69,  5, 12, 79, \

73,  9, 65, 71, 44, \
70, 63, 62, 64, 89, \
57, 51, 40, 53, 67, \
74, 68, 34, 36, 30, \

25, 24, 28, 23, \
26, 41, 27, 58]



MAX_RETRY = 6



while True:

  os.system('date')
  os.system('sleep 1')
#  os.system('java net.tinyos.sentri.DataCenter releaseRoute')
  
  
  
  os.system('sleep 1')
  os.system('java net.tinyos.sentri.DataCenter eraseFlash')
  
  
  
  for i in range(6):
    os.system('sleep 20')
    os.system('java net.tinyos.sentri.DataCenter ledOff')
  
  os.system('sleep 600')
  for i in motes:
    mote = str(i)
    os.system('sleep 3')
    result = 0
    result = os.system('java net.tinyos.sentri.DataCenter networkInfo ' + mote)
    if result != 0:
      os.system('sleep 10')
  
  os.system('sleep 600')
#  os.system('java net.tinyos.sentri.DataCenter fixRoute')
  
  
  
  os.system('sleep 60')
  os.system('java net.tinyos.sentri.DataCenter startSensing 48000 1000 -chnlSelect 31 -samplesToAvg 5')
  
  os.system('sleep 600')
  for i in motes:
    mote = str(i)
    for j in range(MAX_RETRY):
      os.system('date')
      os.system('sleep 1')
      result = 0
      result = os.system('java net.tinyos.sentri.DataCenter readData -dest ' + mote)
      if result == 0:
        break
	
      os.system('sleep 60')
      if j == MAX_RETRY / 2 - 1:
        os.system('java net.tinyos.sentri.DataCenter releaseRoute')
        os.system('sleep 600')
        os.system('java net.tinyos.sentri.DataCenter fixRoute')
  
  
  
  os.system('sleep 1')
#  os.system('java net.tinyos.sentri.DataCenter releaseRoute')
  

--- NEW FILE: stressTest.sh ---
#!/bin/sh
# $Id: stressTest.sh,v 1.1 2006/12/01 00:57:00 binetude Exp $

# "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-2003 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 Sukun Kim <binetude at cs.berkeley.edu>
#

while [ 1 ]; do
  date
  java net.tinyos.sentri.DriveTest
  for i in 1 2 3 4 5 6; do
    java net.tinyos.sentri.DataCenter readData -dest $i
    sleep 1
  done
  java net.tinyos.sentri.DataCenter releaseRoute
  sleep 1
done

--- NEW FILE: test_app.py ---
#!/usr/bin/python
# $Id: test_app.py,v 1.1 2006/12/01 00:57:00 binetude Exp $

# "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-2003 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 Sukun Kim <binetude at cs.berkeley.edu>
#

import os

motes = [81, 80, 52, 49, 42, \
46, 21,  7, 43, 60, \
47, 59, 45, 54, 37, \
48, 76,  6, 38, 75, \

14, 50, 86, 92, \
82, 78, 77, \
69,  5, 12, 79, \

73,  9, 65, 71, 44, \
70, 63, 62, 64, 89, \
57, 51, 40, 53, 67, \
74, 68, 34, 36, 30, \

25, 24, 28, 23, \
26, 41, 27, 58]



MAX_RETRY = 6



while True:

  os.system('date')
  os.system('sleep 1')
#  os.system('java net.tinyos.sentri.DataCenter releaseRoute')
  
  
  
  os.system('sleep 1')
  os.system('java net.tinyos.sentri.DataCenter eraseFlash')
  
  
  
  for i in range(6):
    os.system('sleep 20')
    os.system('java net.tinyos.sentri.DataCenter ledOff')
  
  os.system('sleep 600')
  for i in motes:
    mote = str(i)
    os.system('sleep 3')
    result = 0
    result = os.system('java net.tinyos.sentri.DataCenter networkInfo ' + mote)
    if result != 0:
      os.system('sleep 10')
  
  os.system('sleep 600')
#  os.system('java net.tinyos.sentri.DataCenter fixRoute')
  
  
  
  os.system('sleep 60')
  os.system('java net.tinyos.sentri.DataCenter startSensing 60000 1000 -chnlSelect 3 -samplesToAvg 10')
  
  os.system('sleep 600')
  for i in motes:
    mote = str(i)
    for j in range(MAX_RETRY):
      os.system('date')
      os.system('sleep 1')
      result = 0
      result = os.system('java net.tinyos.sentri.DataCenter readData -dest ' + mote)
      if result == 0:
        break
	
      os.system('sleep 60')
      if j == MAX_RETRY / 2 - 1:
        os.system('java net.tinyos.sentri.DataCenter releaseRoute')
        os.system('sleep 600')
        os.system('java net.tinyos.sentri.DataCenter fixRoute')
  
  
  
  os.system('sleep 1')
#  os.system('java net.tinyos.sentri.DataCenter releaseRoute')
  



More information about the Tinyos-contrib-commits mailing list