[Tinyos-beta-commits] CVS: tinyos-1.x/beta/Deluge/delugetools Deluge.java, 1.8, 1.9 Eraser.java, 1.4, 1.5 ImageInjector.java, 1.4, 1.5 Rebooter.java, 1.3, 1.4 TOSBootImage.java, 1.2, 1.3

Cory Sharp cssharp at users.sourceforge.net
Wed May 4 19:18:51 PDT 2005


Update of /cvsroot/tinyos/tinyos-1.x/beta/Deluge/delugetools
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1567

Modified Files:
	Deluge.java Eraser.java ImageInjector.java Rebooter.java 
	TOSBootImage.java 
Log Message:
Change all System.exit's to throw new IllegalArgumentException's, except for
one in main(), otherwise certain errors (like if MoteIF is already running)
don't terminate the program.

Added support for -f --force to most operations.



Index: Deluge.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/delugetools/Deluge.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** Deluge.java	15 Mar 2005 19:55:32 -0000	1.8
--- Deluge.java	5 May 2005 02:18:47 -0000	1.9
***************
*** 51,74 ****
    private boolean verbose = false;
    private String infile = "";
  
    private MoteIF moteif;
  
    private void usage() {
!     System.err.println("usage: java net.tinyos.tools.Deluge <action> [options]");
!     System.err.println("  actions are:");
!     System.err.println("   -p,  --ping            : ping status of node");
!     System.err.println("   -i,  --inject          : inject a binary");
!     System.err.println("   -r,  --reboot          : send reboot command");
!     System.err.println("   -e,  --erase           : erase an object");
!     System.err.println("   -d,  --dump            : dumps data injected to node");
!     System.err.println("  options are:");
!     System.err.println("   -ti, --tosimage=<xml>  : tos_image.xml file (program images)");
!     System.err.println("   -in, --imgnum=<num>    : image num");
!     System.err.println("   -v,  --verbose         : print all sent/received msgs");
!     System.err.println("   -h,  --help            : print this message");
!     System.exit(1);
    }
  
!   Deluge(String[] args) {
  
      int modeCount = 0;
--- 51,81 ----
    private boolean verbose = false;
    private String infile = "";
+   private boolean force = false;
  
    private MoteIF moteif;
  
    private void usage() {
!     throw new IllegalArgumentException( getUsage() );
    }
  
!   public String getUsage() {
!     return
!       "usage: java net.tinyos.tools.Deluge <action> [options]\n"
!     + "  actions are:\n"
!     + "   -p,  --ping            : ping status of node\n"
!     + "   -i,  --inject          : inject a binary\n"
!     + "   -r,  --reboot          : send reboot command\n"
!     + "   -e,  --erase           : erase an object\n"
!     + "   -d,  --dump            : dumps data injected to node\n"
!     + "  options are:\n"
!     + "   -ti, --tosimage=<xml>  : tos_image.xml file (program images)\n"
!     + "   -in, --imgnum=<num>    : image num\n"
!     + "   -f,  --force           : force the operation, do not ask y/n\n"
!     + "   -v,  --verbose         : print all sent/received msgs\n"
!     + "   -h,  --help            : print this message\n"
!     ;
!   }
! 
!   private void init( String args[] ) {
  
      int modeCount = 0;
***************
*** 110,113 ****
--- 117,123 ----
  	imageNum = Short.parseShort(args[i].substring(9,args[i].length()));
        }
+       else if (args[i].equals("-f") || args[i].equals("--force")) {
+ 	force = true;
+       }
        else if (args[i].equals("-v") || args[i].equals("--verbose")) {
  	verbose = true;
***************
*** 121,127 ****
  
      if (modeCount > 1) {
!       System.out.println("ERROR: Only one action may be specified.");
!       System.exit(0);
      }
  
      try {
--- 131,140 ----
  
      if (modeCount > 1) {
!       throw new IllegalArgumentException( "only one action may be specified" );
      }
+   }
+ 
+   public Deluge( String[] args ) {
+     init( args );
  
      try {
***************
*** 132,136 ****
--- 145,158 ----
  
      moteif.start();
+   }
  
+   public Deluge( MoteIF moteif, String[] args ) {
+     try {
+       init( args );
+       this.moteif = moteif;
+       execute();
+     } catch( IllegalArgumentException e ) {
+       System.err.println("Error: "+e.getMessage());
+     }
    }
  
***************
*** 195,200 ****
  
        if (imageNum < 1 || imageNum >= pinger.getNumImages()) {
! 	System.out.println("ERROR: Invalid image number.");
! 	System.exit(0);
        }
  
--- 217,221 ----
  
        if (imageNum < 1 || imageNum >= pinger.getNumImages()) {
!         throw new IllegalArgumentException( "invalid image number" );
        }
  
***************
*** 204,208 ****
  
        ImageInjector injector = new ImageInjector(pinger, imageNum, newImage,
! 						 moteif, verbose);
  
        injector.inject();
--- 225,229 ----
  
        ImageInjector injector = new ImageInjector(pinger, imageNum, newImage,
! 						 moteif, verbose, force);
  
        injector.inject();
***************
*** 213,221 ****
  
        if (imageNum < 1 || imageNum >= pinger.getNumImages()) {
! 	System.out.println("ERROR: Invalid image number.");
! 	System.exit(0);
        }
  
!       Eraser eraser = new Eraser(pinger, imageNum, moteif, verbose);
  
        eraser.erase();
--- 234,241 ----
  
        if (imageNum < 1 || imageNum >= pinger.getNumImages()) {
!         throw new IllegalArgumentException( "invalid image number" );
        }
  
!       Eraser eraser = new Eraser(pinger, imageNum, moteif, verbose, force);
  
        eraser.erase();
***************
*** 226,234 ****
  
        if (imageNum < 0 || imageNum >= pinger.getNumImages()) {
! 	System.out.println("ERROR: Invalid image number.");
! 	System.exit(0);
        }
  
!       Rebooter rebooter = new Rebooter(pinger, imageNum, moteif, verbose);
        rebooter.reboot();
  
--- 246,253 ----
  
        if (imageNum < 0 || imageNum >= pinger.getNumImages()) {
!         throw new IllegalArgumentException( "invalid image number" );
        }
  
!       Rebooter rebooter = new Rebooter(pinger, imageNum, moteif, verbose, force);
        rebooter.reboot();
  
***************
*** 236,241 ****
  
      default:
!       System.out.println("ERROR: Unknown mode.");
!       break;
  
      }
--- 255,259 ----
  
      default:
!       throw new IllegalArgumentException( "unknown mode" );
  
      }
***************
*** 248,259 ****
  
    public static void main(String[] args) {
! 
!     Deluge deluge = new Deluge(args);
! 
!     deluge.execute();
! 
!     System.exit(0);
! 
    }
- 
  }
--- 266,282 ----
  
    public static void main(String[] args) {
!     Deluge deluge = null;
!     try {
!       deluge = new Deluge(args);
!       deluge.execute();
!     } catch( IllegalArgumentException e ) {
!       if( e.getMessage().startsWith("usage:") ) {
! 	System.out.println( e.getMessage() );
!       } else {
! 	System.err.println( "Error: "+e.getMessage() );
! 	System.exit(0);
!       }
!     }
    }
  }
+ 

Index: Eraser.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/delugetools/Eraser.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Eraser.java	25 Apr 2005 19:14:42 -0000	1.4
--- Eraser.java	5 May 2005 02:18:48 -0000	1.5
***************
*** 43,50 ****
    private TOSBootImage oldTOSBootImage;
    private boolean verbose;
    private boolean injectAcked = false;
  
    public Eraser(Pinger pinger, int imageNum, 
! 		MoteIF moteif, boolean verbose) {
  
      this.pinger = pinger;
--- 43,51 ----
    private TOSBootImage oldTOSBootImage;
    private boolean verbose;
+   private boolean force = false;
    private boolean injectAcked = false;
  
    public Eraser(Pinger pinger, int imageNum, 
! 		MoteIF moteif, boolean verbose, boolean force) {
  
      this.pinger = pinger;
***************
*** 53,56 ****
--- 54,58 ----
      this.moteif = moteif;
      this.verbose = verbose;
+     this.force = force;
  
      advMsg = (DelugeAdvMsg)pingReply.clone();
***************
*** 72,79 ****
        DelugeAdvMsg tmpAdvMsg = pinger.getPingReply(i);
        if (tmpAdvMsg.get_imgDesc_numPgs() != tmpAdvMsg.get_imgDesc_numPgsComplete()) {
! 	System.out.println("ERROR: Image " + i + " is incomplete.");
! 	System.out.println("       Please complete or erase image " + i + " before");
! 	System.out.println("       modifying image " + pingReply.get_imgDesc_imgNum() + ".");
! 	System.exit(0);
        }
      }
--- 74,80 ----
        DelugeAdvMsg tmpAdvMsg = pinger.getPingReply(i);
        if (tmpAdvMsg.get_imgDesc_numPgs() != tmpAdvMsg.get_imgDesc_numPgsComplete()) {
! 	throw new IllegalArgumentException(
!           "Image " + i + " is incomplete.\nPlease complete or erase image " + i
! 	  + " before modifying image " + pingReply.get_imgDesc_imgNum() );
        }
      }
***************
*** 97,116 ****
      }
  
!     System.out.print("Continue operation? (y/[n]) " );
!     BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
!     try {
!       for (;;) {
! 	String ans = in.readLine();
! 	ans = ans.toLowerCase();
! 	if (ans.equals("") || ans.equals("n") || ans.equals("no")) {
! 	  System.out.println("Operation canceled.");
! 	  System.exit(0);
  	}
! 	if (ans.equals("y") || ans.equals("yes"))
! 	  break;
! 	System.out.print("Please enter yes or no: ");
        }
-     } catch (IOException e) {
-       e.printStackTrace();
      }
  
--- 98,119 ----
      }
  
!     if( !force )
!     {
!       System.out.print("Continue operation? (y/[n]) " );
!       BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
!       try {
! 	for (;;) {
! 	  String ans = in.readLine();
! 	  ans = ans.toLowerCase();
! 	  if (ans.equals("") || ans.equals("n") || ans.equals("no")) {
! 	    throw new IllegalArgumentException("operation cancelled");
! 	  }
! 	  if (ans.equals("y") || ans.equals("yes"))
! 	    break;
! 	  System.out.print("Please enter yes or no: ");
  	}
!       } catch (IOException e) {
! 	e.printStackTrace();
        }
      }
  
***************
*** 162,164 ****
    }
  
! }
\ No newline at end of file
--- 165,167 ----
    }
  
! }

Index: ImageInjector.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/delugetools/ImageInjector.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** ImageInjector.java	2 Mar 2005 17:15:59 -0000	1.4
--- ImageInjector.java	5 May 2005 02:18:48 -0000	1.5
***************
*** 46,54 ****
    private PageInjector pageInjector;
    private boolean verbose;
    private boolean injectAcked = false;
  
    public ImageInjector(Pinger pinger, int imageNum,
  		       TOSBootImage newTOSBootImage, 
! 		       MoteIF moteif, boolean verbose) {
  
      byte[] tbimageBytes = newTOSBootImage.getBytes();
--- 46,55 ----
    private PageInjector pageInjector;
    private boolean verbose;
+   private boolean force = false;
    private boolean injectAcked = false;
  
    public ImageInjector(Pinger pinger, int imageNum,
  		       TOSBootImage newTOSBootImage, 
! 		       MoteIF moteif, boolean verbose, boolean force) {
  
      byte[] tbimageBytes = newTOSBootImage.getBytes();
***************
*** 61,64 ****
--- 62,66 ----
      this.moteif = moteif;
      this.verbose = verbose;
+     this.force = force;
  
      advMsg = (DelugeAdvMsg)pingReply.clone();
***************
*** 81,88 ****
        DelugeAdvMsg tmpAdvMsg = pinger.getPingReply(i);
        if (tmpAdvMsg.get_imgDesc_numPgs() != tmpAdvMsg.get_imgDesc_numPgsComplete()) {
! 	System.out.println("ERROR: Image " + i + " is incomplete.");
! 	System.out.println("       Please complete or erase image " + i + " before");
! 	System.out.println("       modifying image " + pingReply.get_imgDesc_imgNum() + ".");
! 	System.exit(0);
        }
      }
--- 83,89 ----
        DelugeAdvMsg tmpAdvMsg = pinger.getPingReply(i);
        if (tmpAdvMsg.get_imgDesc_numPgs() != tmpAdvMsg.get_imgDesc_numPgsComplete()) {
! 	throw new IllegalArgumentException(
!           "Image " + i + " is incomplete.\nPlease complete or erase image " + i
! 	  + " before modifying image " + pingReply.get_imgDesc_imgNum() );
        }
      }
***************
*** 134,153 ****
      advMsg.set_imgDesc_vNum(newVersion);
  
!     System.out.print("Continue operation? (y/[n]) " );
!     BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
!     try {
!       for (;;) {
! 	String ans = in.readLine();
! 	ans = ans.toLowerCase();
! 	if (ans.equals("") || ans.equals("n") || ans.equals("no")) {
! 	  System.out.println("Operation canceled.");
! 	  System.exit(0);
  	}
! 	if (ans.equals("y") || ans.equals("yes"))
! 	  break;
! 	System.out.print("Please enter yes or no: ");
        }
-     } catch (IOException e) {
-       e.printStackTrace();
      }
  
--- 135,155 ----
      advMsg.set_imgDesc_vNum(newVersion);
  
!     if( !force ) {
!       System.out.print("Continue operation? (y/[n]) " );
!       BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
!       try {
! 	for (;;) {
! 	  String ans = in.readLine();
! 	  ans = ans.toLowerCase();
! 	  if (ans.equals("") || ans.equals("n") || ans.equals("no")) {
! 	    throw new IllegalArgumentException("operation cancelled");
! 	  }
! 	  if (ans.equals("y") || ans.equals("yes"))
! 	    break;
! 	  System.out.print("Please enter yes or no: ");
  	}
!       } catch (IOException e) {
! 	e.printStackTrace();
        }
      }
  
***************
*** 321,323 ****
    }
  
! }
\ No newline at end of file
--- 323,325 ----
    }
  
! }

Index: Rebooter.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/delugetools/Rebooter.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Rebooter.java	15 Mar 2005 19:55:33 -0000	1.3
--- Rebooter.java	5 May 2005 02:18:48 -0000	1.4
***************
*** 47,54 ****
    private boolean rebootAcked = false;
    private Pinger pinger;
  
    private DelugeAdvMsg advMsg = new DelugeAdvMsg();
  
!   public Rebooter(Pinger pinger, int imageNum, MoteIF moteif, boolean verbose) {
      this.pinger = pinger;
      this.pingReply = pinger.getPingReply(imageNum);
--- 47,55 ----
    private boolean rebootAcked = false;
    private Pinger pinger;
+   private boolean force;
  
    private DelugeAdvMsg advMsg = new DelugeAdvMsg();
  
!   public Rebooter(Pinger pinger, int imageNum, MoteIF moteif, boolean verbose, boolean force) {
      this.pinger = pinger;
      this.pingReply = pinger.getPingReply(imageNum);
***************
*** 57,60 ****
--- 58,62 ----
      this.moteif = moteif;
      this.verbose = verbose;
+     this.force = force;
      this.moteif.registerListener(new DelugeAdvMsg(), this);
  
***************
*** 68,77 ****
      if (pingReply.get_imgDesc_imgNum() != 0) {
        if (pingReply.get_imgDesc_numPgs() != pingReply.get_imgDesc_numPgsComplete()) {
! 	System.out.println("ERROR: Cannot reboot to an incomplete image.");
! 	System.exit(0);
        }
        else if (pingReply.get_imgDesc_numPgs() == 0) {
! 	System.out.println("ERROR: Cannot reboot to an empty image.");
! 	System.exit(0);
        }
      }
--- 70,77 ----
      if (pingReply.get_imgDesc_imgNum() != 0) {
        if (pingReply.get_imgDesc_numPgs() != pingReply.get_imgDesc_numPgsComplete()) {
! 	throw new IllegalArgumentException( "cannot reboot to an incomplete image" );
        }
        else if (pingReply.get_imgDesc_numPgs() == 0) {
! 	throw new IllegalArgumentException( "cannot reboot to an empty image" );
        }
      }
***************
*** 86,105 ****
  
  
!     System.out.print("Continue operation? (y/[n]) " );
!     BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
!     try {
!       for (;;) {
! 	String ans = in.readLine();
! 	ans = ans.toLowerCase();
! 	if (ans.equals("") || ans.equals("n") || ans.equals("no")) {
! 	  System.out.println("Operation canceled.");
! 	  System.exit(0);
  	}
! 	if (ans.equals("y") || ans.equals("yes"))
! 	  break;
! 	System.out.print("Please enter yes or no: ");
        }
-     } catch (IOException e) {
-       e.printStackTrace();
      }
  
--- 86,107 ----
  
  
!     if( !force )
!     {
!       System.out.print("Continue operation? (y/[n]) " );
!       BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
!       try {
! 	for (;;) {
! 	  String ans = in.readLine();
! 	  ans = ans.toLowerCase();
! 	  if (ans.equals("") || ans.equals("n") || ans.equals("no")) {
! 	    throw new IllegalArgumentException( "operation cancelled" );
! 	  }
! 	  if (ans.equals("y") || ans.equals("yes"))
! 	    break;
! 	  System.out.print("Please enter yes or no: ");
  	}
!       } catch (IOException e) {
! 	e.printStackTrace();
        }
      }
  

Index: TOSBootImage.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/delugetools/TOSBootImage.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TOSBootImage.java	18 Jan 2005 20:46:55 -0000	1.2
--- TOSBootImage.java	5 May 2005 02:18:48 -0000	1.3
***************
*** 59,70 ****
  
      if (filename.equals("")) {
!       System.out.println("ERROR: No file specified.");
!       System.exit(0);
      }
  
      File file = new File(filename);
      if (!file.exists()) {
!       System.out.println("ERROR: No such file: " + filename);
!       System.exit(0);
      }
  
--- 59,68 ----
  
      if (filename.equals("")) {
!       throw new IllegalArgumentException( "no file specified" );
      }
  
      File file = new File(filename);
      if (!file.exists()) {
!       throw new IllegalArgumentException( "no such file "+filename );
      }
  
***************
*** 197,199 ****
    public boolean getDelugeSupport() { return delugeSupport; }
  
! }
\ No newline at end of file
--- 195,197 ----
    public boolean getDelugeSupport() { return delugeSupport; }
  
! }



More information about the Tinyos-beta-commits mailing list