[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/rincon/tools/java/com/rincon/blackbook readme.txt, NONE, 1.1 DataOutput.class, NONE, 1.1 Util.class, NONE, 1.1 DataOutput.java, NONE, 1.1 Util.java, NONE, 1.1 Commands.java, NONE, 1.1 Commands.class, NONE, 1.1 BlackbookConnect.java, NONE, 1.1 BlackbookConnect.class, NONE, 1.1

dmm rincon at users.sourceforge.net
Thu Apr 20 16:02:55 PDT 2006


Update of /cvsroot/tinyos/tinyos-1.x/contrib/rincon/tools/java/com/rincon/blackbook
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15414/contrib/rincon/tools/java/com/rincon/blackbook

Added Files:
	readme.txt DataOutput.class Util.class DataOutput.java 
	Util.java Commands.java Commands.class BlackbookConnect.java 
	BlackbookConnect.class 
Log Message:
Fixed the java/com directory, and added in two more packages:  Blackbook, and EavesLogger.

--- NEW FILE: readme.txt ---
>From the com.rincon.blackbook directory, you can run the following
applications with the mote as long as apps\Blackbook3\demos\BlackbookConnect 
is installed on the mote:

com.rincon.blackbook.BlackbookConnect - gives you direct access to the
    Blackbook interface from your computer.  See the readme in the
    nesC BlackbookConnect directory.
    
com.rincon.blackbook.memorystick.MemoryStick - lets you control files
    by uploading/downloading/deleting on the mote from your computer.
    See the readme in the nesC BlackbookConnect directory.
    
com.rincon.blackbook.printstatus.PrintFile -
com.rincon.blackbook.printstatus.PrintNode -
com.rincon.blackbook.printstatus.PrintSector -
    All three of these applications help in debugging Blackbook and show
    you the status of files, nodes, and sectors through BlackbookConnect
    on the mote.
    

See the readme file in that directory for more information.

@author David Moss (dmm at rincon.com)


--- NEW FILE: DataOutput.class ---
Êþº¾
numberNext

	










STORAGE_OK



SourceFile








--- NEW FILE: Util.class ---
Êþº¾






returnData





longString
parseShort

shortValue

SourceFile















--- NEW FILE: DataOutput.java ---
package com.rincon.blackbook;

/*
 * Copyright (c) 2004-2006 Rincon Research Corporation.  
 * All rights reserved.
 * 
 * Rincon Research will permit distribution and use by others subject to
 * the restrictions of a licensing agreement which contains (among other things)
 * the following restrictions:
 * 
 *  1. No credit will be taken for the Work of others.
 *  2. It will not be resold for a price in excess of reproduction and 
 *      distribution costs.
 *  3. Others are not restricted from copying it or using it except as 
 *      set forward in the licensing agreement.
 *  4. Commented source code of any modifications or additions will be 
 *      made available to Rincon Research on the same terms.
 *  5. This notice will remain intact and displayed prominently.
 * 
 * Copies of the complete licensing agreement may be obtained by contacting 
 * Rincon Research, 101 N. Wilmot, Suite 101, Tucson, AZ 85711.
 * 
 * There is no warranty with this product, either expressed or implied.  
 * Use at your own risk.  Rincon Research is not liable or responsible for 
 * damage or loss incurred or resulting from the use or misuse of this software.
 */

import java.io.File;
import java.util.Arrays;


public class DataOutput {

	/** True if we save to a file, False if we print to screen */
	private boolean toFile = false;

	/** File to dump the image to */
	private File outFile;

	/** The index we're writing to the screen */
	private int screenIndex = 0;

	/** Characters get printed at the end of every row */
	private char[] characterView = new char[0x16];

	/** Keep track of multi-messaged debug numbers */
	private boolean numberNext = false;

	/** Keep track of multi-messaged hex debug number formatting */
	private boolean hex = false;

	/**
	 * Method to output data either to the screen in a nice format, or to a
	 * binary file
	 * 
	 * @param data
	 * @param
	 */
	public void output(short[] data, int length) {
		// Print nicely to the screen
		for (int i = 0; i < length; i++) {
			characterView[screenIndex] = (char) data[i];

			// Here's where we do our formatting
			if (screenIndex == 8) {
				// New 8-bit column space
				System.out.print("  ");
			}

			if (screenIndex > 15) { // used to be 15
				// Print out the character view and start a new line
				dumpCharacters();
				System.out.println();
				screenIndex = 0;
			}

			if (Integer.toHexString(data[i]).length() < 2) {
				// Numbers 0-F only prints 1 character instead of 2.
				System.out.print("0");
			}
			System.out.print(Integer.toHexString(data[i]).toUpperCase() + " ");
			screenIndex++;
		}
	}

	private String resultToString(int result) {
		if (result == 0) {
			return "STORAGE_OK";
		} else if (result == 1) {
			return "STORAGE_FAIL";
		} else if (result == 2) {
			return "STORAGE_INVALID_SIGNATURE";
		} else if (result == 3) {
			return "STORAGE_INVALID_CRC";
		}
		return "INVALID RETURN CODE";
	}

	/**
	 * Turn an array of short[]'s to a String
	 * 
	 * @param data
	 * @return
	 */
	private String dataToString(short[] data) {
		String returnString = "";

		for (int i = 0; i < data.length; i++) {
			returnString += (char) data[i];
		}
		return returnString;
	}

	/**
	 * Dump the character representation of the last line to the screen
	 * 
	 */
	private void dumpCharacters() {
		System.out.print("  |  ");
		for (int charIndex = 0; charIndex < characterView.length; charIndex++) {
			if (charIndex == 8) {
				// 8-bit character column space
				System.out.print("  ");
			}
			System.out.print(characterView[charIndex]);
		}
		Arrays.fill(characterView, ' ');
	}

	/**
	 * Flush out the remaining data
	 * 
	 */
	public void flush() {
		// to screen
		for (int i = screenIndex; i < 16; i++) {
			System.out.print("   ");
			if (i == 8) {
				// column
				System.out.print("  ");
			}
		}
		dumpCharacters();
		System.out.println();
	}
}

--- NEW FILE: Util.java ---
package com.rincon.blackbook;

/*
 * Copyright (c) 2004-2006 Rincon Research Corporation.  
 * All rights reserved.
 * 
 * Rincon Research will permit distribution and use by others subject to
 * the restrictions of a licensing agreement which contains (among other things)
 * the following restrictions:
 * 
 *  1. No credit will be taken for the Work of others.
 *  2. It will not be resold for a price in excess of reproduction and 
 *      distribution costs.
 *  3. Others are not restricted from copying it or using it except as 
 *      set forward in the licensing agreement.
 *  4. Commented source code of any modifications or additions will be 
 *      made available to Rincon Research on the same terms.
 *  5. This notice will remain intact and displayed prominently.
 * 
 * Copies of the complete licensing agreement may be obtained by contacting 
 * Rincon Research, 101 N. Wilmot, Suite 101, Tucson, AZ 85711.
 * 
 * There is no warranty with this product, either expressed or implied.  
 * Use at your own risk.  Rincon Research is not liable or responsible for 
 * damage or loss incurred or resulting from the use or misuse of this software.
 */

public class Util {

	
	/**
	 * Turn an array of short[]'s to a String
	 * 
	 * @param data
	 * @return
	 */
	public static String dataToString(short[] data) {
		String returnString = "";

		for (int i = 0; i < data.length; i++) {
			returnString += (char) data[i];
		}
		return returnString;
	}

	/**
	 * Turn a string into a short[] array of data
	 * @param string
	 * @return
	 */
	public static short[] stringToData(String string) {
		char[] charData = string.toCharArray();
		short[] returnData = new short[charData.length];
		
		
		for(int i = 0; i < charData.length; i++) {
			returnData[i] = (short) charData[i];
		}
		
		return returnData;
	}
	
	/**
	 * Attempt to decode the int value, and deal with any illegible remarks.
	 * 
	 * @param intString
	 * @return
	 */
	public static int parseInt(String intString) {
		try {
			return Integer.decode(intString).intValue();
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		return 0;
	}

	/**
	 * Attempt to decode the long value, and deal with any illegible remarks.
	 * 
	 * @param longString
	 * @return
	 */
	public static long parseLong(String longString) {
		try {			
			return Long.decode(longString).longValue();
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}

		return 0;
	}

	/**
	 * Attempt to decode the short value, and deal with any illegible remarks.
	 * 
	 * @param shortString
	 * @return
	 */
	public static short parseShort(String shortString) {
		try {			
			return Short.decode(shortString).shortValue();
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}

		return 0;
	}
	
	/**
	 * Convert some data to a filename
	 * @param data
	 * @return
	 */
	public static String dataToFilename(short[] data) {
		String returnString = "";
		
		for(int i = 0; i < 14; i++) {
			returnString += (char) data[i];
		}
		return returnString;
	}

	/**
	 * Takes a filename string and converts it to a 14 element
	 * filename short array
	 * @param s
	 * @return
	 */
	public static short[] filenameToData(String filename) {
		int filenameLength = 14;
		short[] returnData = new short[filenameLength];
		char[] charData = filename.toCharArray();
		
		for(int i = 0; i < charData.length && i < filenameLength; i++) {
			returnData[i] = (short) charData[i];
		}
		
		for(int i = charData.length; i < filenameLength; i++) {
			returnData[i] = 0;
		}
		
		return returnData;
	}

	
	/**
	 * Turn an array of shorts into an array of bytes
	 * @param shortData
	 * @return
	 */
	public static byte[] shortsToBytes(short[] shortData, int length) {
		byte[] byteData = new byte[length];
		for(int i = 0; i < length; i++) {
			byteData[i] = (byte) shortData[i];
		}
		
		return byteData;
	}
	

	/**
	 * Convert a byte array to short array.
	 * @param byteData
	 * @return
	 */
	public static short[] bytesToShorts(byte[] byteData) {
		short[] shortData = new short[byteData.length];
		for(int i = 0; i < byteData.length; i++) {
			shortData[i] = (short) byteData[i];
		}
		
		return shortData;
	}

}

--- NEW FILE: Commands.java ---
package com.rincon.blackbook;

/*
 * Copyright (c) 2004-2006 Rincon Research Corporation.  
 * All rights reserved.
 * 
 * Rincon Research will permit distribution and use by others subject to
 * the restrictions of a licensing agreement which contains (among other things)
 * the following restrictions:
 * 
 *  1. No credit will be taken for the Work of others.
 *  2. It will not be resold for a price in excess of reproduction and 
 *      distribution costs.
 *  3. Others are not restricted from copying it or using it except as 
 *      set forward in the licensing agreement.
 *  4. Commented source code of any modifications or additions will be 
 *      made available to Rincon Research on the same terms.
 *  5. This notice will remain intact and displayed prominently.
 * 
 * Copies of the complete licensing agreement may be obtained by contacting 
 * Rincon Research, 101 N. Wilmot, Suite 101, Tucson, AZ 85711.
 * 
 * There is no warranty with this product, either expressed or implied.  
 * Use at your own risk.  Rincon Research is not liable or responsible for 
 * damage or loss incurred or resulting from the use or misuse of this software.
 */

public class Commands {


	public static final int TOS_BCAST_ADDR = 0xFFFF;
	public static final short SUCCESS = 1;
	public static final short FAIL = 0;
	
	
	public static final short CMD_BFILEWRITE_OPEN = 0;

	public static final short CMD_BFILEWRITE_CLOSE = 1;
	public static final short CMD_BFILEWRITE_APPEND = 2;
	public static final short CMD_BFILEWRITE_SAVE = 3;
	public static final short CMD_BFILEWRITE_REMAINING = 4;
	 
	public static final short CMD_BFILEREAD_OPEN = 10;
	public static final short CMD_BFILEREAD_CLOSE = 11;
	public static final short CMD_BFILEREAD_READ = 12;
	public static final short CMD_BFILEREAD_SEEK = 13;
	public static final short CMD_BFILEREAD_SKIP = 14;
	public static final short CMD_BFILEREAD_REMAINING = 15;
	 
	public static final short CMD_BFILEDELETE_DELETE = 20;
	 
	public static final short CMD_BFILEDIR_TOTALFILES = 30;
	public static final short CMD_BFILEDIR_TOTALNODES = 31;
	public static final short CMD_BFILEDIR_EXISTS = 32;
	public static final short CMD_BFILEDIR_READNEXT = 33;
	public static final short CMD_BFILEDIR_RESERVEDLENGTH = 34;
	public static final short CMD_BFILEDIR_DATALENGTH = 35;
	public static final short CMD_BFILEDIR_CHECKCORRUPTION = 36;
	public static final short CMD_BFILEDIR_READFIRST = 37;
	public static final short CMD_BFILEDIR_GETFREESPACE = 38;
	
	public static final short CMD_BDICTIONARY_OPEN = 40;
	public static final short CMD_BDICTIONARY_CLOSE = 41;
	public static final short CMD_BDICTIONARY_INSERT = 42;
	public static final short CMD_BDICTIONARY_RETRIEVE = 43;
	public static final short CMD_BDICTIONARY_REMOVE = 44; 
	public static final short CMD_BDICTIONARY_NEXTKEY = 45;
	public static final short CMD_BDICTIONARY_FIRSTKEY = 46;
	
	public static final short ERROR_BFILEWRITE_OPEN = 100;
	public static final short ERROR_BFILEWRITE_CLOSE = 101;
	public static final short ERROR_BFILEWRITE_APPEND = 102;
	public static final short ERROR_BFILEWRITE_SAVE = 103;
	public static final short ERROR_BFILEWRITE_REMAINING = 104;
	 
	public static final short ERROR_BFILEREAD_OPEN = 110;
	public static final short ERROR_BFILEREAD_CLOSE = 111;
	public static final short ERROR_BFILEREAD_READ = 112;
	public static final short ERROR_BFILEREAD_SEEK = 113;
	public static final short ERROR_BFILEREAD_SKIP = 114;
	public static final short ERROR_BFILEREAD_REMAINING = 115;
	 
	public static final short ERROR_BFILEDELETE_DELETE = 120;
	 
	public static final short ERROR_BFILEDIR_TOTALFILES = 130;
	public static final short ERROR_BFILEDIR_TOTALNODES = 131;
	public static final short ERROR_BFILEDIR_EXISTS = 132;
	public static final short ERROR_BFILEDIR_READNEXT = 133;
	public static final short ERROR_BFILEDIR_RESERVEDLENGTH = 134;
	public static final short ERROR_BFILEDIR_DATALENGTH = 135;
	public static final short ERROR_BFILEDIR_CHECKCORRUPTION = 136;
	public static final short ERROR_BFILEDIR_READFIRST = 137;
	public static final short ERROR_BFILEDIR_GETFREESPACE = 138;
	
	public static final short ERROR_BDICTIONARY_OPEN = 140;
	public static final short ERROR_BDICTIONARY_CLOSE = 141;
	public static final short ERROR_BDICTIONARY_INSERT = 142;
	public static final short ERROR_BDICTIONARY_RETRIEVE = 143;
	public static final short ERROR_BDICTIONARY_REMOVE = 144;
	public static final short ERROR_BDICTIONARY_NEXTKEY = 145;
	public static final short ERROR_BDICTIONARY_FIRSTKEY = 146;
	
	
	public static final short REPLY_BFILEWRITE_OPEN = 200;
	public static final short REPLY_BFILEWRITE_CLOSE = 201;
	public static final short REPLY_BFILEWRITE_APPEND = 202;
	public static final short REPLY_BFILEWRITE_SAVE = 203;
	public static final short REPLY_BFILEWRITE_REMAINING = 204;
	 
	public static final short REPLY_BFILEREAD_OPEN = 210;
	public static final short REPLY_BFILEREAD_CLOSE = 211;
	public static final short REPLY_BFILEREAD_READ = 212;
	public static final short REPLY_BFILEREAD_SEEK = 213;
	public static final short REPLY_BFILEREAD_SKIP = 214;
	public static final short REPLY_BFILEREAD_REMAINING = 215;
	 
	public static final short REPLY_BFILEDELETE_DELETE = 220;
	 
	public static final short REPLY_BFILEDIR_TOTALFILES = 230;
	public static final short REPLY_BFILEDIR_TOTALNODES = 231;
	public static final short REPLY_BFILEDIR_EXISTS = 232;
	public static final short REPLY_BFILEDIR_READNEXT = 233;
	public static final short REPLY_BFILEDIR_RESERVEDLENGTH = 234;
	public static final short REPLY_BFILEDIR_DATALENGTH = 235;
	public static final short REPLY_BFILEDIR_CHECKCORRUPTION = 236;
	public static final short REPLY_BFILEDIR_GETFREESPACE = 238;
	
	public static final short REPLY_BDICTIONARY_OPEN = 240;
	public static final short REPLY_BDICTIONARY_CLOSE = 241;
	public static final short REPLY_BDICTIONARY_INSERT = 242;
	public static final short REPLY_BDICTIONARY_RETRIEVE = 243;
	public static final short REPLY_BDICTIONARY_REMOVE = 244;
	public static final short REPLY_BDICTIONARY_NEXTKEY = 245;
	public static final short REPLY_BDICTIONARY_FIRSTKEY = 246;
	 
	public static final short REPLY_BOOT = 250;
	public static final short REPLY_BCLEAN_ERASING = 251;
	public static final short REPLY_BCLEAN_DONE = 252;
}

--- NEW FILE: Commands.class ---
Êþº¾

REPLY_BOOT

SourceFile
























































































--- NEW FILE: BlackbookConnect.java ---
package com.rincon.blackbook;

/*
 * Copyright (c) 2004-2006 Rincon Research Corporation.  
 * All rights reserved.
 * 
 * Rincon Research will permit distribution and use by others subject to
 * the restrictions of a licensing agreement which contains (among other things)
 * the following restrictions:
 * 
 *  1. No credit will be taken for the Work of others.
 *  2. It will not be resold for a price in excess of reproduction and 
 *      distribution costs.
 *  3. Others are not restricted from copying it or using it except as 
 *      set forward in the licensing agreement.
 *  4. Commented source code of any modifications or additions will be 
 *      made available to Rincon Research on the same terms.
 *  5. This notice will remain intact and displayed prominently.
 * 
 * Copies of the complete licensing agreement may be obtained by contacting 
 * Rincon Research, 101 N. Wilmot, Suite 101, Tucson, AZ 85711.
 * 
 * There is no warranty with this product, either expressed or implied.  
 * Use at your own risk.  Rincon Research is not liable or responsible for 
 * damage or loss incurred or resulting from the use or misuse of this software.
 */

import com.rincon.blackbook.bclean.BClean;
import com.rincon.blackbook.bclean.BCleanEvents;
import com.rincon.blackbook.bdictionary.BDictionaryArgParser;
import com.rincon.blackbook.bfiledelete.BFileDeleteArgParser;
import com.rincon.blackbook.bfiledir.BFileDirArgParser;
import com.rincon.blackbook.bfileread.BFileReadArgParser;
import com.rincon.blackbook.bfilewrite.BFileWriteArgParser;
import com.rincon.blackbook.bboot.BBoot;
import com.rincon.blackbook.bboot.BBootEvents;

public class BlackbookConnect implements BBootEvents, BCleanEvents {
	
	/** Boot Transceiver */
	private BBoot bBoot;
	
	/** BClean Transceiver */
	private BClean bClean;
	
	/**
	 * Constructor
	 */
	public BlackbookConnect(String[] args) {
		bBoot = new BBoot();
		bBoot.addListener(this);
		
		bClean = new BClean();
		bClean.addListener(this);
		
		processArguments(args);
	}

	/**
	 * Process the command line arguments and send the
	 * commands to the mote for execution
	 * @param args
	 */
	private void processArguments(String[] args) {
		if(args.length < 1) {
			System.err.println("Not enough arguments!");
			usage();
			System.exit(1);
		}
		
		if(args[0].toLowerCase().matches("bdictionary")) {
			new BDictionaryArgParser(getSubArgs(args));
			
		} else if(args[0].toLowerCase().matches("bfiledelete")) {
			new BFileDeleteArgParser(getSubArgs(args));
			
		} else if(args[0].toLowerCase().matches("bfiledir")) {
			new BFileDirArgParser(getSubArgs(args));
			
		} else if(args[0].toLowerCase().matches("bfileread")) {
			new BFileReadArgParser(getSubArgs(args));
			
		} else if(args[0].toLowerCase().matches("bfilewrite")) {
			new BFileWriteArgParser(getSubArgs(args));
			
		} else {
			System.err.println("Unknown Argument: " + args[0]);
			usage();
			System.exit(1);
		}
	}

	
	/**
	 * Print all argument parsers' command line usage
	 *
	 */
	private void usage() {
		System.out.println("\nBlackbook Usage:");
		System.out.println("com.rincon.blackbook.TestBlackbook [interface] -[command] <params>");
		System.out.println("_____________________________________");
		System.out.println(BDictionaryArgParser.getUsage());
		System.out.println(BFileDeleteArgParser.getUsage());
		System.out.println(BFileDirArgParser.getUsage());
		System.out.println(BFileReadArgParser.getUsage());
		System.out.println(BFileWriteArgParser.getUsage());
	}
	
	/** 
	 * Extract the sub-arguments for a given command
	 * @param args
	 * @return everything but the first index
	 */
	private String[] getSubArgs(String[] args) {
		String[] subArgs = new String[args.length - 1];
		
		for(int i = 0; i < args.length - 1; i++) {
			subArgs[i] = args[i+1];
		}
		
		return subArgs;
	}
	

	/***************** Boot Events ****************/
	/**
	 * Boot Event
	 * This will only occur when the mote is reset while 
	 * the TestBlackbook application is running, which
	 * isn't likely.
	 */
	public void booted(int totalNodes, short totalFiles, boolean result) {
		System.out.print("Blackbook Boot: ");
		if(result) {
			System.out.println("SUCCESS");
		} else {
			System.out.println("FAIL");
		}
		System.out.println("\t" + totalNodes + " nodes; " + totalFiles + " files.");
		System.exit(0);
	}

	
	/***************** BClean Events ****************/
	public void erasing() {
		System.out.println("Erasing Sector... Please wait.");
	}

	public void gcDone(boolean result) {
		System.out.println("Done Erasing Sectors");
	}
	
	/**
	 * Main Method
	 * @param args
	 */
	public static void main(String[] args) {
		new BlackbookConnect(args);
	}


}

--- NEW FILE: BlackbookConnect.class ---
Êþº¾


	









getSubArgs





bfilewrite




Blackbook Usage:







totalNodes
totalFiles

SourceFile







More information about the Tinyos-contrib-commits mailing list