[Tinyos-beta-commits]
CVS: tinyos-1.x/beta/Drain/tools/java/net/tinyos/drain
Drain.java, 1.5, 1.6
Kamin Whitehouse
kaminw at users.sourceforge.net
Tue Jul 5 15:02:43 PDT 2005
Update of /cvsroot/tinyos/tinyos-1.x/beta/Drain/tools/java/net/tinyos/drain
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25763/Drain/tools/java/net/tinyos/drain
Modified Files:
Drain.java
Log Message:
updated the Drain tool to have a function-based interface that can be used from the python command line. Otherwise, bash command line functionality should be exactly the same
Index: Drain.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/tools/java/net/tinyos/drain/Drain.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Drain.java 25 Jun 2005 22:40:58 -0000 1.5
--- Drain.java 5 Jul 2005 22:02:41 -0000 1.6
***************
*** 10,14 ****
public class Drain {
! private static boolean DEBUG = false;
private static int DRAIN_MAX_CHILDREN = 8;
private static int DRAIN_MAX_CHILDREN_LOG2 = 3;
--- 10,16 ----
public class Drain {
! public boolean DEBUG = false;
! public boolean VERBOSE = true;
!
private static int DRAIN_MAX_CHILDREN = 8;
private static int DRAIN_MAX_CHILDREN_LOG2 = 3;
***************
*** 20,25 ****
private static int BEACON_DELAY = 4;
! private static int BEACON_COUNT = 2;
!
public Drain() {
spAddr = DrainLib.setSPAddr();
--- 22,34 ----
private static int BEACON_DELAY = 4;
!
! private TreeMaintainer treeMaintainer = null;
!
! public short ttl = 15;
! public int delay = 4;
! public int count = 1;
! public boolean forever = false;
! public int treeInstance = (int)((double)Math.random() * (double)255);
!
public Drain() {
spAddr = DrainLib.setSPAddr();
***************
*** 40,44 ****
public void buildTree(int delay) {
! buildTree(delay, (int)((double)Math.random() * (double)255));
}
--- 49,53 ----
public void buildTree(int delay) {
! buildTree(delay, treeInstance);
}
***************
*** 55,59 ****
beaconMsg.set_parent(0xffff);
beaconMsg.set_cost(0);
! beaconMsg.set_ttl((short)15);
beaconMsg.set_beaconSeqno((short)0);
--- 64,68 ----
beaconMsg.set_parent(0xffff);
beaconMsg.set_cost(0);
! beaconMsg.set_ttl(ttl);
beaconMsg.set_beaconSeqno((short)0);
***************
*** 168,203 ****
}
! private static int delay = 4;
! private static int count = 1;
! private static boolean forever = false;
public static void main(String args[]) {
Drain drain = new Drain();
! parseArgs(args);
!
! int treeInstance = (int)((double)Math.random() * (double)255);
!
! System.err.println("Drain Tree Builder");
! System.err.println("myAddr = " + DrainLib.setSPAddr() +
! ", treeInstance = " + treeInstance +
! ", delay = " + delay +
! ", count = " + count +
! ", forever = " + forever);
! while (count > 0 || forever) {
! System.err.println("Sending beacon...");
! drain.buildTree(delay, treeInstance);
! try {
! Thread.sleep(delay * 1000);
! } catch (InterruptedException e) {}
! count--;
}
System.exit(0);
}
! private static void parseArgs(String args[]) {
ArrayList cleanedArgs = new ArrayList();
--- 177,230 ----
}
! private class TreeMaintainer extends Thread {
!
! public void run(){
! while (count > 0 || forever) {
! if (VERBOSE) {
! System.err.println("Sending beacon...");
! }
! buildTree(delay, treeInstance);
! try {
! Thread.sleep(delay * 1000);
! } catch (InterruptedException e) {}
! count--;
! }
! }
! }
+ public void maintainTree(){
+ if (treeMaintainer != null && treeMaintainer.isAlive() ){
+ return;
+ }
+ treeMaintainer = new TreeMaintainer();
+ treeMaintainer.start();
+ }
+
+ public void stopTreeMaintenance() {
+ if (treeMaintainer != null && treeMaintainer.isAlive() ){
+ treeMaintainer.stop();
+ }
+ }
public static void main(String args[]) {
Drain drain = new Drain();
! parseArgs(args, drain);
! if (drain.VERBOSE) {
! System.err.println("Drain Tree Builder");
! System.err.println("myAddr = " + DrainLib.setSPAddr() +
! ", treeInstance = " + drain.treeInstance +
! ", delay = " + drain.delay +
! ", count = " + drain.count +
! ", forever = " + drain.forever);
}
+ drain.maintainTree();
+
System.exit(0);
}
! private static void parseArgs(String args[], Drain drain) {
ArrayList cleanedArgs = new ArrayList();
***************
*** 219,227 ****
if (opt.equals("t")) {
! delay = Integer.parseInt(args[++i]);
} else if (opt.equals("c")) {
! count = Integer.parseInt(args[++i]);
} else if (opt.equals("n")) {
! forever = true;
} else if (opt.equals("h")) {
usage();
--- 246,254 ----
if (opt.equals("t")) {
! drain.delay = Integer.parseInt(args[++i]);
} else if (opt.equals("c")) {
! drain.count = Integer.parseInt(args[++i]);
} else if (opt.equals("n")) {
! drain.forever = true;
} else if (opt.equals("h")) {
usage();
More information about the Tinyos-beta-commits
mailing list