[Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/rincon/tools/java/com/rincon/blackbook/bfileread
BFileRead.java, NONE, 1.1 BFileReadArgParser.java, NONE,
1.1 BFileReadEvents.java, NONE, 1.1 BFileReadCommands.class,
NONE, 1.1 BFileReadArgParser.class, NONE,
1.1 BFileReadCommands.java, NONE, 1.1 BFileReadEvents.class,
NONE, 1.1 BFileRead.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/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
- Next message: [Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/rincon/tools/java/com/rincon/flashviewer/send
FlashViewerSender.class, NONE, 1.1 FlashViewerCommands.class,
NONE, 1.1 FlashViewerCommands.java, NONE,
1.1 FlashViewerSender.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/bfileread
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15414/contrib/rincon/tools/java/com/rincon/blackbook/bfileread
Added Files:
BFileRead.java BFileReadArgParser.java BFileReadEvents.java
BFileReadCommands.class BFileReadArgParser.class
BFileReadCommands.java BFileReadEvents.class BFileRead.class
Log Message:
Fixed the java/com directory, and added in two more packages: Blackbook, and EavesLogger.
--- NEW FILE: BFileRead.java ---
package com.rincon.blackbook.bfileread;
/*
* 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 BFileRead implements BFileReadCommands, 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;
/** Amount to return on a getRemaining command */
private long returnAmount;
/**
* Set the destination address of the next send command
* @param destination
*/
public void setDestination(int destination) {
dest = destination;
}
/**
* Constructor
*
*/
public BFileRead() {
comm.registerListener(new BlackbookConnectMsg(), this);
}
/**
* Send a message
* @param dest
* @param m
*/
private synchronized 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(BFileReadEvents listener) {
if(!listeners.contains(listener)) {
listeners.add(listener);
}
}
/**
* Remove a FileTransferEvents listener
* @param listener
*/
public void removeListener(BFileReadEvents listener) {
listeners.remove(listener);
}
public synchronized void messageReceived(int to, Message m) {
BlackbookConnectMsg inMsg = (BlackbookConnectMsg) m;
switch(inMsg.get_cmd()) {
case Commands.REPLY_BFILEREAD_OPEN:
for(Iterator it = listeners.iterator(); it.hasNext(); ) {
((BFileReadEvents) it.next()).opened(Util.dataToFilename(inMsg.get_data()), inMsg.get_length(), inMsg.get_result() == Commands.SUCCESS);
}
break;
case Commands.REPLY_BFILEREAD_CLOSE:
for(Iterator it = listeners.iterator(); it.hasNext(); ) {
((BFileReadEvents) it.next()).closed(inMsg.get_result() == Commands.SUCCESS);
}
break;
case Commands.REPLY_BFILEREAD_READ:
for(Iterator it = listeners.iterator(); it.hasNext(); ) {
((BFileReadEvents) it.next()).readDone(inMsg.get_data(), (int) inMsg.get_length(), inMsg.get_result() == Commands.SUCCESS);
}
break;
case Commands.REPLY_BFILEREAD_SEEK:
if(inMsg.get_result() == Commands.SUCCESS) {
System.out.println("Seek success");
} else {
System.out.println("Seek failed");
}
System.exit(0);
break;
case Commands.REPLY_BFILEREAD_SKIP:
if(inMsg.get_result() == Commands.SUCCESS) {
System.out.println("Skip success");
} else {
System.out.println("Skip failed");
}
System.exit(0);
break;
case Commands.REPLY_BFILEREAD_REMAINING:
returnAmount = inMsg.get_length();
notify();
break;
case Commands.ERROR_BFILEREAD_OPEN:
case Commands.ERROR_BFILEREAD_CLOSE:
case Commands.ERROR_BFILEREAD_READ:
case Commands.ERROR_BFILEREAD_SEEK:
case Commands.ERROR_BFILEREAD_SKIP:
case Commands.ERROR_BFILEREAD_REMAINING:
System.err.println("Command immediately failed");
System.exit(1);
default:
}
}
public void open(String fileName) {
command.set_data(Util.filenameToData(fileName));
command.set_cmd(Commands.CMD_BFILEREAD_OPEN);
send(command);
}
public void close() {
command.set_cmd(Commands.CMD_BFILEREAD_CLOSE);
send(command);
}
public void read(int amount) {
command.set_cmd(Commands.CMD_BFILEREAD_READ);
command.set_length(amount);
send(command);
}
public void seek(long fileAddress) {
command.set_cmd(Commands.CMD_BFILEREAD_SEEK);
command.set_length(fileAddress);
send(command);
}
public void skip(int skipLength) {
command.set_cmd(Commands.CMD_BFILEREAD_SKIP);
command.set_length(skipLength);
send(command);
}
public synchronized long getRemaining() {
command.set_cmd(Commands.CMD_BFILEREAD_REMAINING);
send(command);
try {
wait(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return returnAmount;
}
}
--- NEW FILE: BFileReadArgParser.java ---
package com.rincon.blackbook.bfileread;
/*
* 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;
public class BFileReadArgParser implements BFileReadEvents {
/** Transceiver communication with the mote */
private BFileRead bFileRead;
/**
* Constructor
* @param args
*/
public BFileReadArgParser(String[] args) {
bFileRead = new BFileRead();
bFileRead.addListener(this);
if(args.length < 1) {
reportError("Not enough arguments");
}
if(args[0].toLowerCase().matches("-open")) {
if (args.length > 1) {
bFileRead.open(args[1]);
} else {
reportError("Missing parameter(s)");
}
} else if(args[0].toLowerCase().matches("-close")) {
bFileRead.close();
} else if(args[0].toLowerCase().matches("-read")) {
// Keep in mind that a message can only hold so many bytes
// and the TestBlackbook app on the mote will automatically
// adjust to the correct size for a reply.
if (args.length > 1) {
bFileRead.read(Util.parseShort(args[1]));
} else {
reportError("Missing parameter(s)");
}
} else if(args[0].toLowerCase().matches("-seek")) {
if (args.length > 1) {
bFileRead.seek(Util.parseLong(args[1]));
} else {
reportError("Missing parameter(s)");
}
} else if(args[0].toLowerCase().matches("-skip")) {
if (args.length > 1) {
bFileRead.skip(Util.parseInt(args[1]));
} else {
reportError("Missing parameter(s)");
}
} else if(args[0].toLowerCase().matches("-getremaining")) {
System.out.println(bFileRead.getRemaining() + " bytes remaining");
System.exit(0);
} else {
System.err.println("Unknown argument: " + args[0]);
System.err.println(getUsage());
System.exit(1);
}
}
private void reportError(String error) {
System.err.println(error);
System.err.println(getUsage());
System.exit(1);
}
public static String getUsage() {
String usage = "";
usage += " BFileRead\n";
usage += "\t-open <filename>\n";
usage += "\t-close\n";
usage += "\t-read <amount>\n";
usage += "\t-seek <address>\n";
usage += "\t-skip <amount>\n";
usage += "\t-getRemaining\n";
return usage;
}
/***************** BFileRead Events ***************/
public void opened(String fileName, long amount, boolean result) {
System.out.print("BFileRead opened ");
if(result) {
System.out.println("SUCCESS: " + fileName);
System.out.println("\t" + amount + " bytes");
} 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);
}
public void readDone(short[] dataBuffer, int amount, boolean result) {
System.out.print("BFileRead readDone ");
if(result) {
System.out.println("SUCCESS: " + amount + " bytes read\n");
DataOutput output = new DataOutput();
output.output(dataBuffer, amount);
output.flush();
} else {
System.out.println("FAIL");
}
System.exit(0);
}
}
--- NEW FILE: BFileReadEvents.java ---
package com.rincon.blackbook.bfileread;
/*
* 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 BFileReadEvents {
/**
* A file has been opened
* @param fileName - name of the opened file
* @param len - the total data length of the file
* @param result - SUCCESS if the file was successfully opened
*/
public void opened(String fileName, long amount, boolean result);
/**
* Any previously opened file is now closed
* @param result - SUCCESS if the file was closed properly
*/
public void closed(boolean result);
/**
* File read complete
* @param *buf - this is the buffer that was initially passed in
* @param amount - the length of the data read into the buffer
* @param result - SUCCESS if there were no problems reading the data
*/
public void readDone(short[] dataBuffer, int amount, boolean result);
}
--- NEW FILE: BFileReadCommands.class ---
Êþº¾
SourceFile
--- NEW FILE: BFileReadArgParser.class ---
Êþº¾
parseShort
dataBuffer
SourceFile
--- NEW FILE: BFileReadCommands.java ---
package com.rincon.blackbook.bfileread;
/*
* 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 BFileReadCommands {
/**
* Open a file for reading
* @param fileName - name of the file to open
* @return SUCCESS if the attempt to open for reading proceeds
*/
public void open(String fileName);
/**
* Close any currently opened file
*/
public void close();
/**
* Read a specified amount of data from the open
* file into the given buffer
* @param *dataBuffer - the buffer to read data into
* @param amount - the amount of data to read
* @return SUCCESS if the public goes through
*/
public void read(int amount);
/**
* Seek a given address to read from in the file.
*
* This will point the current internal read pointer
* to the given address if the address is within
* bounds of the file.When BFileRead.read(...) is
* called, the first byte of the buffer
* will be the byte at the file address specified here.
*
* If the address is outside the bounds of the
* data in the file, the internal read pointer
* address will not change.
* @param fileAddress - the address to seek
* @return SUCCESS if the read pointer is adjusted,
* FAIL if the read pointer didn't change
*/
public void seek(long fileAddress);
/**
* Skip the specified number of bytes in the file
* @param skipLength - number of bytes to skip
* @return SUCCESS if the internal read pointer was
*adjusted, FAIL if it wasn't because
*the skip length is beyond the bounds of the file.
*/
public void skip(int skipLength);
/**
* Get the remaining bytes available to read from this file.
* This is the total size of the file minus your current position.
* @return the number of remaining bytes in this file
*/
public long getRemaining();
}
--- NEW FILE: BFileReadEvents.class ---
Êþº¾
SourceFile
--- NEW FILE: BFileRead.class ---
Êþº¾
get_length
get_result
set_length
skipLength
SourceFile
¶
- Previous 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
- Next message: [Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/rincon/tools/java/com/rincon/flashviewer/send
FlashViewerSender.class, NONE, 1.1 FlashViewerCommands.class,
NONE, 1.1 FlashViewerCommands.java, NONE,
1.1 FlashViewerSender.java, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-contrib-commits
mailing list