[Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/rincon/tools/java/com/rincon/blackbook/bdictionary
BDictionaryEvents.java, NONE, 1.1 BDictionaryArgParser.java,
NONE, 1.1 BDictionaryCommands.java, NONE,
1.1 BDictionaryCommands.class, NONE,
1.1 BDictionaryArgParser.class, NONE, 1.1 BDictionary.class,
NONE, 1.1 BDictionary.java, NONE, 1.1 BDictionaryEvents.class,
NONE, 1.1
dmm
rincon at users.sourceforge.net
Thu Apr 20 16:02:54 PDT 2006
- Previous message: [Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/rincon/tools/java/com/rincon/blackbook/messages
BlackbookConnectMsg.java, NONE, 1.1 BlackbookFileMsg.java,
NONE, 1.1 BlackbookSectorMsg.java, NONE,
1.1 BlackbookSectorMsg.class, NONE, 1.1 BlackbookFileMsg.class,
NONE, 1.1 BlackbookNodeMsg.class, NONE,
1.1 BlackbookNodeMsg.java, NONE, 1.1 BlackbookConnectMsg.class,
NONE, 1.1
- Next message: [Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/rincon/tools/java/com/rincon/blackbook/bfilewrite
BFileWriteEvents.class, NONE, 1.1 BFileWrite.class, NONE,
1.1 BFileWrite.java, NONE, 1.1 BFileWriteEvents.java, NONE,
1.1 BFileWriteArgParser.java, NONE,
1.1 BFileWriteArgParser.class, NONE,
1.1 BFileWriteCommands.class, NONE,
1.1 BFileWriteCommands.java, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/tinyos/tinyos-1.x/contrib/rincon/tools/java/com/rincon/blackbook/bdictionary
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15414/contrib/rincon/tools/java/com/rincon/blackbook/bdictionary
Added Files:
BDictionaryEvents.java BDictionaryArgParser.java
BDictionaryCommands.java BDictionaryCommands.class
BDictionaryArgParser.class BDictionary.class BDictionary.java
BDictionaryEvents.class
Log Message:
Fixed the java/com directory, and added in two more packages: Blackbook, and EavesLogger.
--- NEW FILE: BDictionaryEvents.java ---
package com.rincon.blackbook.bdictionary;
/*
* 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 interface BDictionaryEvents {
/**
* A Dictionary file was opened successfully.
* @param totalSize - the total amount of flash space dedicated to storing
* key-value pairs in the file
* @param remainingBytes - the remaining amount of space left to write to
* @param result - SUCCESS if the file was successfully opened.
*/
public void opened(int totalSize, boolean result);
/**
* The opened Dictionary file is now closed
* @param result - SUCCSESS if there are no open files
*/
public void closed(boolean result);
/**
* A key-value pair was inserted into the currently opened Dictionary file.
* @param key - the key used to insert the value
* @param value - pointer to the buffer containing the value.
* @param valueSize - the amount of bytes copied from the buffer into flash
* @param result - SUCCESS if the key was written successfully.
*/
public void inserted(long key, boolean result);
/**
* A value was retrieved from the given key.
* @param key - the key used to find the value
* @param valueHolder - pointer to the buffer where the value was stored
* @param valueSize - the actual size of the value.
* @param result - SUCCESS if the value was pulled out and is uncorrupted
*/
public void retrieved(short[] valueHolder, int valueSize, boolean result);
/**
* A key-value pair was removed
* @param key - the key that should no longer exist
* @param result - SUCCESS if the key was really removed
*/
public void removed(long key, boolean result);
/**
* The next key in the open Dictionary file
* @param nextKey - the next key
* @param result - SUCCESS if this is the really the next key,
* FAIL if the presentKey was invalid or there is no next key.
*/
public void nextKey(long nextKey, boolean result);
}
--- NEW FILE: BDictionaryArgParser.java ---
package com.rincon.blackbook.bdictionary;
/*
* 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.DataOutput;
import com.rincon.blackbook.Util;
import com.rincon.blackbook.messages.BlackbookConnectMsg;
public class BDictionaryArgParser implements BDictionaryEvents {
/** Transceiver communication with the mote */
private BDictionary bDictionary;
/**
* Constructor
* @param args
*/
public BDictionaryArgParser(String[] args) {
bDictionary = new BDictionary();
bDictionary.addListener(this);
if(args.length < 1) {
reportError("Not enough arguments");
}
if(args[0].toLowerCase().matches("-open")) {
if (args.length > 2) {
bDictionary.open(args[1], Util.parseInt(args[2]));
} else {
reportError("Missing parameter(s)");
}
} else if(args[0].toLowerCase().matches("-close")) {
bDictionary.close();
} else if(args[0].toLowerCase().matches("-insert")) {
if (args.length > 3) {
if(Util.parseShort(args[3]) > BlackbookConnectMsg.totalSize_data()) {
reportError("Cannot fit value size + " + Util.parseShort(args[3]) + " into a single UART message with data size " + BlackbookConnectMsg.totalSize_data());
}
bDictionary.insert(Util.parseLong(args[1]), Util.stringToData(args[2]), Util.parseShort(args[3]));
} else {
reportError("Missing parameter(s)");
}
} else if(args[0].toLowerCase().matches("-retrieve")) {
if(args.length > 1) {
bDictionary.retrieve(Util.parseLong(args[1]));
} else {
reportError("Missing parameter(s)");
}
} else if(args[0].toLowerCase().matches("-remove")) {
if(args.length > 1) {
bDictionary.remove(Util.parseLong(args[1]));
} else {
reportError("Missing parameter(s)");
}
} else if(args[0].toLowerCase().matches("-getfirstkey")) {
bDictionary.getFirstKey();
} else if(args[0].toLowerCase().matches("-getnextkey")) {
if(args.length > 1) {
bDictionary.getNextKey(Util.parseLong(args[1]));
} else {
reportError("Missing parameter(s)");
}
} else {
reportError("Unknown argument: " + args[0]);
}
}
private void reportError(String error) {
System.err.println(error);
System.err.println(getUsage());
System.exit(1);
}
public static String getUsage() {
String usage = "";
usage += " BDictionary\n";
usage += "\t-open <filename> <minimum size>\n";
usage += "\t-close\n";
usage += "\t-insert <key> <value> <length>\n";
usage += "\t-retrieve <key>\n";
usage += "\t-remove <key>\n";
usage += "\t-getFirstKey\n";
usage += "\t-getNextKey <current key>\n";
return usage;
}
/***************** BDictionary Events ****************/
public void opened(int totalSize, boolean result) {
System.out.print("BDictionary opened ");
if(result) {
System.out.println("SUCCESS: " + totalSize + " bytes");
} else {
System.out.println("FAIL");
}
System.exit(0);
}
public void inserted(long key, boolean result) {
System.out.print("BDictionary inserted ");
if(result) {
System.out.println("SUCCESS: Key 0x" + Long.toHexString(key).toUpperCase() + " Inserted");
} else {
System.out.println("FAIL");
}
System.exit(0);
}
public void retrieved(short[] valueHolder, int valueSize, boolean result) {
System.out.print("BDictionary retrieved ");
if(result) {
System.out.println("SUCCESS");
DataOutput output = new DataOutput();
output.output(valueHolder, valueSize);
output.flush();
} else {
System.out.println("FAIL");
}
System.exit(0);
}
public void removed(long key, boolean result) {
System.out.print("BDictionary removed ");
if(result) {
System.out.println("SUCCESS: Key 0x" + Long.toHexString(key).toUpperCase() + " Removed");
} else {
System.out.println("FAIL");
}
System.exit(0);
}
public void nextKey(long nextKey, boolean result) {
System.out.print("BDictionary next key ");
if(result) {
System.out.println("SUCCESS: Next Key is 0x" + Long.toHexString(nextKey).toUpperCase());
} else {
System.out.println("FAIL");
}
System.exit(0);
}
public void closed(boolean result) {
System.out.print("Closed ");
if(result) {
System.out.println("SUCCESS");
} else {
System.out.println("FAIL");
}
System.exit(0);
}
}
--- NEW FILE: BDictionaryCommands.java ---
package com.rincon.blackbook.bdictionary;
/*
* 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 interface BDictionaryCommands {
/**
* Open a Dictionary file.If the file does not exist on flash, the
* minimumSize will be used to set the length of the file.
* @param name - name of the Dictionary file to open
* @param minimumSize - the minimum reserved size for the file on flash.
* @return SUCCESS if the file will be opened
*/
public void open(String fileName, int minimumSize);
/**
* Close any opened Dictionary files
* @return SUCCESS if the open Dictionary file was closed.
*/
public void close();
/**
* Insert a key-value pair into the opened Dictionary file.
* This will invalidate any old key-value pairs using the
* associated key.
* @param key - the key to use
* @param value - pointer to a buffer containing the value to insert.
* @param valueSize - the amount of bytes to copy from the buffer
* @return SUCCESS if the key-value pair will be inserted
*/
public void insert(long key, short[] value, short valueSize);
/**
* Retrieve a key from the opened Dictionary file.
* @param key - the key to find
* @param valueHolder - pointer to the memory location to store the value
* @param maxValueSize - used to prevent buffer overflows incase the
* recorded size of the value does not match the space allocated to
* the valueHolder
* @return SUCCESS if the key will be retrieved.
*/
public void retrieve(long key);
/**
* Remove a key from the opened dictionary file
* @param key - the key for the key-value pair to remove
* @return SUCCESS if the attempt to remove the key will proceed
*/
public void remove(long key);
/**
* Get the next recorded key in the file.
* @return SUCCESS if the next recorded key will be returned.
* FAIL if no keys are defined.
*/
public void getNextKey(long presentKey);
/**
* Get the first key of the file
*
*/
public void getFirstKey();
}
--- NEW FILE: BDictionaryCommands.class ---
Êþº¾
getNextKey
SourceFile
--- NEW FILE: BDictionaryArgParser.class ---
Êþº¾
parseShort
getNextKey
SourceFile
--- NEW FILE: BDictionary.class ---
Êþº¾
get_length
get_result
set_length
set_result
getNextKey
presentKey
SourceFile
--- NEW FILE: BDictionary.java ---
package com.rincon.blackbook.bdictionary;
/*
* 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.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.rincon.blackbook.Commands;
import com.rincon.blackbook.Util;
import com.rincon.blackbook.messages.BlackbookConnectMsg;
import net.tinyos.message.Message;
import net.tinyos.message.MessageListener;
import net.tinyos.message.MoteIF;
import net.tinyos.util.Messenger;
public class BDictionary implements BDictionaryCommands, MessageListener {
/** Communication with the mote */
private MoteIF comm = new MoteIF((Messenger) null);
/** Command to send */
private BlackbookConnectMsg command = new BlackbookConnectMsg();
/** List of FileTransferEvents listeners */
private static List listeners = new ArrayList();
/** Current destination address */
private int dest = Commands.TOS_BCAST_ADDR;
/**
* Set the destination address of the next send command
* @param destination
*/
public void setDestination(int destination) {
dest = destination;
}
/**
* Constructor
*
*/
public BDictionary() {
comm.registerListener(new BlackbookConnectMsg(), this);
}
/**
* Send a message
* @param dest
* @param m
*/
private void send(Message m) {
try {
comm.send(dest, m);
} catch (IOException e) {
System.err.println("Couldn't contact the mote");
}
}
/**
* Add a FileTransferEvents listener
* @param listener
*/
public void addListener(BDictionaryEvents listener) {
if(!listeners.contains(listener)) {
listeners.add(listener);
}
}
/**
* Remove a FileTransferEvents listener
* @param listener
*/
public void removeListener(BDictionaryEvents listener) {
listeners.remove(listener);
}
public void messageReceived(int to, Message m) {
BlackbookConnectMsg inMsg = (BlackbookConnectMsg) m;
switch(inMsg.get_cmd()) {
case Commands.REPLY_BDICTIONARY_OPEN:
for(Iterator it = listeners.iterator(); it.hasNext(); ) {
((BDictionaryEvents) it.next()).opened((int) inMsg.get_length(), inMsg.get_result() == Commands.SUCCESS);
}
break;
case Commands.REPLY_BDICTIONARY_CLOSE:
for(Iterator it = listeners.iterator(); it.hasNext(); ) {
((BDictionaryEvents) it.next()).closed(inMsg.get_result() == Commands.SUCCESS);
}
break;
case Commands.REPLY_BDICTIONARY_INSERT:
for(Iterator it = listeners.iterator(); it.hasNext(); ) {
((BDictionaryEvents) it.next()).inserted(inMsg.get_length(), inMsg.get_result() == Commands.SUCCESS);
}
break;
case Commands.REPLY_BDICTIONARY_RETRIEVE:
for(Iterator it = listeners.iterator(); it.hasNext(); ) {
((BDictionaryEvents) it.next()).retrieved(inMsg.get_data(), (int) inMsg.get_length(), inMsg.get_result() == Commands.SUCCESS);
}
break;
case Commands.REPLY_BDICTIONARY_REMOVE:
for(Iterator it = listeners.iterator(); it.hasNext(); ) {
((BDictionaryEvents) it.next()).removed(inMsg.get_length(), inMsg.get_result() == Commands.SUCCESS);
}
break;
case Commands.REPLY_BDICTIONARY_NEXTKEY:
for(Iterator it = listeners.iterator(); it.hasNext(); ) {
((BDictionaryEvents) it.next()).nextKey((int) inMsg.get_length(), inMsg.get_result() == Commands.SUCCESS);
}
break;
case Commands.ERROR_BDICTIONARY_OPEN:
case Commands.ERROR_BDICTIONARY_CLOSE:
case Commands.ERROR_BDICTIONARY_INSERT:
case Commands.ERROR_BDICTIONARY_RETRIEVE:
case Commands.ERROR_BDICTIONARY_REMOVE:
case Commands.ERROR_BDICTIONARY_NEXTKEY:
case Commands.ERROR_BDICTIONARY_FIRSTKEY:
System.err.println("Command immediately failed");
System.exit(0);
default:
}
}
public void open(String fileName, int minimumSize) {
command.set_cmd(Commands.CMD_BDICTIONARY_OPEN);
command.set_length(minimumSize);
command.set_data(Util.filenameToData(fileName));
send(command);
}
public void close() {
command.set_cmd(Commands.CMD_BDICTIONARY_CLOSE);
send(command);
}
public void insert(long key, short[] value, short valueSize) {
command.set_cmd(Commands.CMD_BDICTIONARY_INSERT);
command.set_length(key);
command.set_data(value);
command.set_result(valueSize);
send(command);
}
public void retrieve(long key) {
command.set_cmd(Commands.CMD_BDICTIONARY_RETRIEVE);
command.set_length(key);
send(command);
}
public void remove(long key) {
command.set_cmd(Commands.CMD_BDICTIONARY_REMOVE);
command.set_length(key);
send(command);
}
public void getNextKey(long presentKey) {
command.set_cmd(Commands.CMD_BDICTIONARY_NEXTKEY);
command.set_length(presentKey);
send(command);
}
public void getFirstKey() {
command.set_cmd(Commands.CMD_BDICTIONARY_FIRSTKEY);
send(command);
}
}
--- NEW FILE: BDictionaryEvents.class ---
Êþº¾
SourceFile
- Previous message: [Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/rincon/tools/java/com/rincon/blackbook/messages
BlackbookConnectMsg.java, NONE, 1.1 BlackbookFileMsg.java,
NONE, 1.1 BlackbookSectorMsg.java, NONE,
1.1 BlackbookSectorMsg.class, NONE, 1.1 BlackbookFileMsg.class,
NONE, 1.1 BlackbookNodeMsg.class, NONE,
1.1 BlackbookNodeMsg.java, NONE, 1.1 BlackbookConnectMsg.class,
NONE, 1.1
- Next message: [Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/rincon/tools/java/com/rincon/blackbook/bfilewrite
BFileWriteEvents.class, NONE, 1.1 BFileWrite.class, NONE,
1.1 BFileWrite.java, NONE, 1.1 BFileWriteEvents.java, NONE,
1.1 BFileWriteArgParser.java, NONE,
1.1 BFileWriteArgParser.class, NONE,
1.1 BFileWriteCommands.class, NONE,
1.1 BFileWriteCommands.java, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-contrib-commits
mailing list