[Tinyos-beta-commits] CVS: tinyos-1.x/beta/Deluge/delugetools
Downloader.java, NONE, 1.1 Deluge.java, 1.12, 1.13 Eraser.java,
1.6, 1.7 ImageInjector.java, 1.5, 1.6 Pinger.java, 1.8,
1.9 Rebooter.java, 1.5, 1.6 TOSBootImage.java, 1.3, 1.4
Jonathan Hui
jwhui at users.sourceforge.net
Tue Jun 21 16:38:15 PDT 2005
- Previous message: [Tinyos-beta-commits]
CVS: tinyos-1.x/beta/Deluge/Deluge DelugeM.nc, 1.19,
1.20 DelugeMetadataC.nc, 1.7, 1.8 DelugeMetadataM.nc, 1.16,
1.17 DelugeMsgs.h, 1.4, 1.5
- Next message: [Tinyos-beta-commits] CVS: tinyos-1.x/beta/platform/imote2
hardware.h, 1.4, 1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/tinyos/tinyos-1.x/beta/Deluge/delugetools
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12980
Modified Files:
Deluge.java Eraser.java ImageInjector.java Pinger.java
Rebooter.java TOSBootImage.java
Added Files:
Downloader.java
Log Message:
- Added support for injecting opaque data along with the program
image. This data is useful for PC side tools that want to keep program
image specific information.
- The '--dump' option is actually useful now. It will download a
program image from a node and reconstruct the tos_image.xml for it.
- Added ability to inject program images into Golden Image slot. Also
checks to make sure that a Deluge node is directly connected for added
safety.
--- NEW FILE: Downloader.java ---
// $Id: Downloader.java,v 1.1 2005/06/21 23:38:12 jwhui Exp $
/* tab:2
*
*
* "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
*/
/**
* @author Jonathan Hui <jwhui at cs.berkeley.edu>
*/
package net.tinyos.deluge;
import net.tinyos.message.*;
import java.io.*;
public class Downloader implements MessageListener {
private static final int PAGE_SIZE = DelugeConsts.DELUGE_PKTS_PER_PAGE*DelugeConsts.DELUGE_PKT_PAYLOAD_SIZE;
private Pinger pinger;
private DelugeAdvMsg pingReply;
private MoteIF moteif;
private TOSBootImage tosBootImage;
private boolean verbose;
private short pktsToReceive[] = new short[DelugeReqMsg.totalSize_requestedPkts()];
private int pktsReceived;
private short imageData[] = new short[60*PAGE_SIZE];
private short curPage;
private String outfile;
public Downloader(Pinger pinger, int imageNum,
MoteIF moteif, boolean verbose,
String outfile) {
if (imageNum < 0 || imageNum >= pinger.getNumImages()) {
throw new IllegalArgumentException( "invalid image number" );
}
if (outfile == "") {
throw new IllegalArgumentException(
"No outfile specified.");
}
this.pinger = pinger;
this.pingReply = pinger.getPingReply(imageNum);
this.moteif = moteif;
this.tosBootImage = pinger.getImage(imageNum);
this.verbose = verbose;
this.outfile = outfile;
}
public void extract() {
if (pingReply.get_imgDesc_numPgsComplete() == 0) {
throw new IllegalArgumentException(
"Image " + pingReply.get_imgDesc_imgNum() + " is empty.");
}
System.out.println("Download image:");
System.out.println(" Image: " + pingReply.get_imgDesc_imgNum());
System.out.println(tosBootImage);
setupNextPage();
curPage = 0;
moteif.registerListener(new DelugeDataMsg(), this);
for (;;) {
try {
Thread.currentThread().sleep(600);
if ( curPage >= pingReply.get_imgDesc_numPgs() )
break;
System.out.print("\rDownloading page [" + (curPage+1) + "] of [" + pingReply.get_imgDesc_numPgs() + "] ...");
DelugeReqMsg reqMsg = new DelugeReqMsg();
reqMsg.set_sourceAddr(pinger.getPCAddr());
reqMsg.set_dest(pingReply.get_sourceAddr());
reqMsg.set_vNum(pingReply.get_imgDesc_vNum());
reqMsg.set_imgNum(pingReply.get_imgDesc_imgNum());
reqMsg.set_pgNum(curPage);
reqMsg.set_requestedPkts(pktsToReceive);
if (verbose) System.out.print(reqMsg);
send(reqMsg);
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println();
byte[] bytes = new byte[TOSBootImage.METADATA_SIZE];
for ( int i = 0; i < bytes.length; i++ )
bytes[i] = (byte)(imageData[i+256] & 0xff);
TOSBootImage receivedImage = new TOSBootImage(bytes);
try {
BufferedWriter out = new BufferedWriter(new FileWriter(outfile));
out.write("<tos_image>\n");
out.write(" <ident>\n");
out.write(" <program_name>" + receivedImage.getName() + "</program_name>\n");
out.write(" <unix_time>" + Long.toHexString(receivedImage.getUnixTime()).toUpperCase() + "L</unix_time>\n");
out.write(" <platform>" + receivedImage.getPlatform() + "</platform>\n");
out.write(" <deluge_support>" + (receivedImage.getDelugeSupport() ? "yes" : "no") + "</deluge_support>\n");
out.write(" <user_id>" + receivedImage.getUserID() + "</user_id>\n");
out.write(" <hostname>" + receivedImage.getHostname() + "</hostname>\n");
out.write(" <user_hash>" + Long.toHexString(receivedImage.getUserHash()).toUpperCase() + "L</user_hash>\n");
out.write(" </ident>\n");
out.write(" <image format=\"ihex\">\n");
int curOffset = 256 + TOSBootImage.METADATA_SIZE;
int addr = 0;
int length = 0;
for ( int i = 0; i < 4; i++ )
addr |= (imageData[curOffset++] & 0xff) << i*8;
for ( int i = 0; i < 4; i++ )
length |= (imageData[curOffset++] & 0xff) << i*8;
byte record[] = new byte[21];
while ( length > 0 ) {
if (length >= 16)
record[0] = 16;
else
record[0] = (byte)length;
record[1] = (byte)((addr >> 8) & 0xff);
record[2] = (byte)(addr & 0xff);
record[3] = 0;
for ( int i = 0; i < record[0]; i++, curOffset++ )
record[4+i] = (byte)imageData[curOffset];
int checkSum = 0;
for ( int i = 0; i < 4 + record[0]; i++ )
checkSum += record[i];
record[4+record[0]] = (byte)((~(checkSum & 0xff) + 1) & 0xff);
out.write(":");
for ( int i = 0; i < 5 + record[0]; i++ )
printByte(out, record[i], true);
out.write("\n");
addr += record[0];
length -= record[0];
if (length == 0) {
addr = length = 0;
for ( int i = 0; i < 4; i++ )
addr |= (imageData[curOffset++] & 0xff) << i*8;
for ( int i = 0; i < 4; i++ )
length |= (imageData[curOffset++] & 0xff) << i*8;
}
}
out.write(":0400000300005000A9\n");
out.write(":00000001FF\n");
out.write(" </image>\n");
addr = length = 0;
for ( int i = 0; i < 4; i++ )
addr |= (imageData[curOffset++] & 0xff) << i*8;
for ( int i = 0; i < 4; i++ )
length |= (imageData[curOffset++] & 0xff) << i*8;
if ( length > 0 ) {
out.write(" <supplement format=\"hex\">\n");
int hexOffset = 0;
for ( int i = 0; i < length; i++ ) {
printByte(out, (byte)imageData[curOffset++], false);
if ((++hexOffset % 32) == 0)
out.write("\n");
}
if ((++hexOffset % 32) != 0)
out.write("\n");
out.write(" </supplement>\n");
}
out.write("</tos_image>\n");
out.close();
} catch ( IOException e ) {
e.printStackTrace();
}
}
private void printByte(BufferedWriter out, byte byteVal, boolean uppercase) {
try {
if (byteVal >= 0 && byteVal < 16)
out.write("0");
String tmpStr = Integer.toHexString(byteVal & 0xff);
if (uppercase)
tmpStr = tmpStr.toUpperCase();
out.write( tmpStr );
} catch (Exception e) {
e.printStackTrace();
}
}
private void setupNextPage() {
for ( int i = 0; i < pktsToReceive.length; i++ )
pktsToReceive[i] = 0xff;
pktsReceived = 0;
}
private void send(Message m) {
try {
moteif.send(MoteIF.TOS_BCAST_ADDR, m);
} catch (Exception e) {
e.printStackTrace();
}
}
public void messageReceived(int to, Message m) {
switch(m.amType()) {
case DelugeDataMsg.AM_TYPE:
DelugeDataMsg data = (DelugeDataMsg)m;
short pgNum = data.get_pgNum();
short pktNum = data.get_pktNum();
if (verbose) System.out.print(data);
if ((pktsToReceive[pktNum/8] & (0x1 << (pktNum%8))) != 0) {
pktsToReceive[pktNum/8] &= ~(0x1 << (pktNum%8));
pktsReceived++;
System.arraycopy(data.get_data(), 0, imageData,
pgNum*PAGE_SIZE + pktNum*DelugeConsts.DELUGE_PKT_PAYLOAD_SIZE,
DelugeConsts.DELUGE_PKT_PAYLOAD_SIZE);
if (pktsReceived >= DelugeConsts.DELUGE_PKTS_PER_PAGE) {
setupNextPage();
curPage++;
}
}
break;
}
}
}
Index: Deluge.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/delugetools/Deluge.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** Deluge.java 14 Jun 2005 20:53:36 -0000 1.12
--- Deluge.java 21 Jun 2005 23:38:12 -0000 1.13
***************
*** 4,8 ****
*
*
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 4,8 ----
*
*
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
***************
*** 52,55 ****
--- 52,56 ----
private boolean verbose = false;
private String infile = "";
+ private String outfile = "";
private boolean force = false;
***************
*** 73,76 ****
--- 74,78 ----
+ " -ti, --tosimage=<xml> : tos_image.xml file (program images)\n"
+ " -in, --imgnum=<num> : image num\n"
+ + " -o, --outfile=<xml> : output file for dump\n"
+ " -f, --force : force the operation, do not ask y/n\n"
+ " -v, --verbose : print all sent/received msgs\n"
***************
*** 123,126 ****
--- 125,134 ----
imageNum = Short.parseShort(args[i].substring(9,args[i].length()));
}
+ else if (args[i].length() > 2 && args[i].substring(0,3).equals("-o=")) {
+ outfile = args[i].substring(3,args[i].length());
+ }
+ else if (args[i].length() > 9 && args[i].substring(0,10).equals("--outfile=")) {
+ outfile = args[i].substring(10,args[i].length());
+ }
else if (args[i].equals("-f") || args[i].equals("--force")) {
force = true;
***************
*** 167,174 ****
Pinger pinger = null;
! if (mode != S_DUMP) {
pinger = new Pinger(moteif, verbose);
pinger.ping();
! }
System.out.println("--------------------------------------------------");
--- 175,182 ----
Pinger pinger = null;
! // if (mode != S_DUMP) {
pinger = new Pinger(moteif, verbose);
pinger.ping();
! // }
System.out.println("--------------------------------------------------");
***************
*** 182,186 ****
for ( int i = 0; i < pinger.getNumImages(); i++ ) {
! System.out.println(" Stored Image " + i);
TOSBootImage image = pinger.getImage(i);
--- 190,197 ----
for ( int i = 0; i < pinger.getNumImages(); i++ ) {
! if (i == 0)
! System.out.println(" Stored Image 0 - (Golden Image)");
! else
! System.out.println(" Stored Image " + i);
TOSBootImage image = pinger.getImage(i);
***************
*** 198,201 ****
--- 209,213 ----
System.out.println(" Prog Name: <unavailable>");
System.out.println(" Compiled On: <unavailable>");
+ System.out.println(" Platform: <unavailable>");
System.out.println(" User ID: <unavailable>");
System.out.println(" Hostname: <unavailable>");
***************
*** 209,212 ****
--- 221,225 ----
System.out.println(" Prog Name: N/A");
System.out.println(" Compiled On: N/A");
+ System.out.println(" Platform: N/A");
System.out.println(" User ID: N/A");
System.out.println(" Hostname: N/A");
***************
*** 220,237 ****
case S_DUMP:
! TOSBootImage tbimage = new TOSBootImage(infile);
! byte[] tbimageBytes = tbimage.getBytes();
! DelugeImage delugeImage = new DelugeImage(tbimageBytes, tbimageBytes.length);
!
! delugeImage.dump();
break;
case S_INJECT:
- if (imageNum < 1 || imageNum >= pinger.getNumImages()) {
- throw new IllegalArgumentException( "invalid image number" );
- }
-
TOSBootImage newImage = new TOSBootImage(infile);
--- 233,244 ----
case S_DUMP:
! Downloader downloader = new Downloader(pinger, imageNum, moteif, verbose, outfile);
+ downloader.extract();
+
break;
case S_INJECT:
TOSBootImage newImage = new TOSBootImage(infile);
***************
*** 247,254 ****
case S_ERASE:
- if (imageNum < 1 || imageNum >= pinger.getNumImages()) {
- throw new IllegalArgumentException( "invalid image number" );
- }
-
Eraser eraser = new Eraser(pinger, imageNum, moteif, verbose, force);
--- 254,257 ----
***************
*** 259,266 ****
case S_RESET:
- if (imageNum < 1 || imageNum >= pinger.getNumImages()) {
- throw new IllegalArgumentException( "invalid image number" );
- }
-
Eraser resetter = new Eraser(pinger, imageNum, moteif, verbose, force);
--- 262,265 ----
***************
*** 271,279 ****
case S_REBOOT:
- if (imageNum < 0 || imageNum >= pinger.getNumImages()) {
- throw new IllegalArgumentException( "invalid image number" );
- }
-
Rebooter rebooter = new Rebooter(pinger, imageNum, moteif, verbose, force);
rebooter.reboot();
--- 270,275 ----
case S_REBOOT:
Rebooter rebooter = new Rebooter(pinger, imageNum, moteif, verbose, force);
+
rebooter.reboot();
Index: Eraser.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/delugetools/Eraser.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Eraser.java 9 Jun 2005 22:12:25 -0000 1.6
--- Eraser.java 21 Jun 2005 23:38:12 -0000 1.7
***************
*** 4,8 ****
*
*
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 4,8 ----
*
*
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
***************
*** 49,52 ****
--- 49,61 ----
MoteIF moteif, boolean verbose, boolean force) {
+ if (imageNum < 0 || imageNum >= pinger.getNumImages()) {
+ throw new IllegalArgumentException( "invalid image number" );
+ }
+
+ if (imageNum == DelugeConsts.DELUGE_GOLDEN_IMAGE_NUM
+ && pinger.getPCAddr() != Pinger.TOS_UART_ADDR) {
+ throw new IllegalArgumentException( "must have direct connection to erase Golden Image" );
+ }
+
this.pinger = pinger;
this.pingReply = pinger.getPingReply(imageNum);
***************
*** 158,161 ****
--- 167,182 ----
if (newVersion == DelugeConsts.DELUGE_INVALID_VNUM)
newVersion = 0;
+
+ if (pingReply.get_imgDesc_imgNum() == DelugeConsts.DELUGE_GOLDEN_IMAGE_NUM
+ && !force ) {
+ System.out.println();
+ System.out.println("--------------------------------------------------");
+ System.out.println("| WARNING: Erasing Golden Image. This operation |");
+ System.out.println("| is not epidemic and only affects the |");
+ System.out.println("| directly connected node. |");
+ System.out.println("--------------------------------------------------");
+ System.out.println();
+ }
+
}
Index: ImageInjector.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/delugetools/ImageInjector.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** ImageInjector.java 5 May 2005 02:18:48 -0000 1.5
--- ImageInjector.java 21 Jun 2005 23:38:12 -0000 1.6
***************
*** 4,8 ****
*
*
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 4,8 ----
*
*
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
***************
*** 53,56 ****
--- 53,65 ----
MoteIF moteif, boolean verbose, boolean force) {
+ if (imageNum < 0 || imageNum >= pinger.getNumImages()) {
+ throw new IllegalArgumentException( "invalid image number" );
+ }
+
+ if (imageNum == DelugeConsts.DELUGE_GOLDEN_IMAGE_NUM
+ && pinger.getPCAddr() != Pinger.TOS_UART_ADDR) {
+ throw new IllegalArgumentException( "must have direct connection to overwrite Golden Image" );
+ }
+
byte[] tbimageBytes = newTOSBootImage.getBytes();
***************
*** 133,136 ****
--- 142,156 ----
}
+ if (pingReply.get_imgDesc_imgNum() == DelugeConsts.DELUGE_GOLDEN_IMAGE_NUM
+ && !force ) {
+ System.out.println();
+ System.out.println("--------------------------------------------------");
+ System.out.println("| WARNING: Writing to Golden Image. This |");
+ System.out.println("| operation is not epidemic and only |");
+ System.out.println("| affects the directly connected node. |");
+ System.out.println("--------------------------------------------------");
+ System.out.println();
+ }
+
advMsg.set_imgDesc_vNum(newVersion);
Index: Pinger.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/delugetools/Pinger.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** Pinger.java 14 Jun 2005 20:55:35 -0000 1.8
--- Pinger.java 21 Jun 2005 23:38:12 -0000 1.9
***************
*** 4,8 ****
*
*
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 4,8 ----
*
*
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
***************
*** 38,49 ****
public class Pinger implements MessageListener {
! private static final short TOS_UART_ADDR = 0x007e;
private static final int STRING_SIZE = 16;
private static final int MAX_ATTEMPTS = 3;
private static final int START_PKT = DelugeConsts.DELUGE_CRC_BLOCK_SIZE/DelugeConsts.DELUGE_PKT_PAYLOAD_SIZE;
! // TWO PACKETS WORTH OF DATA ARE RESERVED BUT UNUSED
// IF MORE IDENT DATA IS REQUIRED, REMOVE SUBTRACTION ON END POINT
! private static final int END_PKT = DelugeConsts.DELUGE_IDENT_SIZE/DelugeConsts.DELUGE_PKT_PAYLOAD_SIZE - 2;
private MoteIF moteif;
--- 38,49 ----
public class Pinger implements MessageListener {
! public static final short TOS_UART_ADDR = 0x007e;
private static final int STRING_SIZE = 16;
private static final int MAX_ATTEMPTS = 3;
private static final int START_PKT = DelugeConsts.DELUGE_CRC_BLOCK_SIZE/DelugeConsts.DELUGE_PKT_PAYLOAD_SIZE;
! // ONE PACKET WORTH OF DATA ARE RESERVED BUT UNUSED
// IF MORE IDENT DATA IS REQUIRED, REMOVE SUBTRACTION ON END POINT
! private static final int END_PKT = DelugeConsts.DELUGE_IDENT_SIZE/DelugeConsts.DELUGE_PKT_PAYLOAD_SIZE - 1;
private MoteIF moteif;
Index: Rebooter.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/delugetools/Rebooter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Rebooter.java 14 Jun 2005 03:38:27 -0000 1.5
--- Rebooter.java 21 Jun 2005 23:38:12 -0000 1.6
***************
*** 4,8 ****
*
*
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 4,8 ----
*
*
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
***************
*** 52,55 ****
--- 52,60 ----
public Rebooter(Pinger pinger, int imageNum, MoteIF moteif, boolean verbose, boolean force) {
+
+ if (imageNum < 0 || imageNum >= pinger.getNumImages()) {
+ throw new IllegalArgumentException( "invalid image number" );
+ }
+
this.pinger = pinger;
this.pingReply = pinger.getPingReply(imageNum);
Index: TOSBootImage.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Deluge/delugetools/TOSBootImage.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** TOSBootImage.java 5 May 2005 02:18:48 -0000 1.3
--- TOSBootImage.java 21 Jun 2005 23:38:12 -0000 1.4
***************
*** 4,8 ****
*
*
! * "Copyright (c) 2000-2004 The Regents of the University of California.
* All rights reserved.
*
--- 4,8 ----
*
*
! * "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
***************
*** 44,51 ****
--- 44,53 ----
private final static int UNIX_TIME_SIZE = 4;
private final static int USER_HASH_SIZE = 4;
+ private final static int MAX_SUPPLEMENT_SIZE = 10*1024;
private String name; // 16
private String userid; // 16
private String hostname; // 16
+ private String platform; // 16
private int size; // 4
private long unixTime; // 4
***************
*** 54,58 ****
private boolean delugeSupport = false;
! private IhexReader image;
TOSBootImage(String filename) {
--- 56,62 ----
private boolean delugeSupport = false;
! private IhexReader image = null;
! private byte supplement[] = null;
! private int supplementSize;
TOSBootImage(String filename) {
***************
*** 91,98 ****
--- 95,120 ----
userHash = Long.parseLong(tmp.substring(0,tmp.indexOf('L')),16);
+ nlist=doc.getElementsByTagName("platform");
+ tmp = nlist.item(0).getFirstChild().getNodeValue();
+ platform = nlist.item(0).getFirstChild().getNodeValue();
+
nlist=doc.getElementsByTagName("image");
String imageStr = nlist.item(0).getFirstChild().getNodeValue();
image = new IhexReader(imageStr);
+ nlist=doc.getElementsByTagName("supplement");
+ if (nlist.item(0) != null) {
+ String supplementStr = nlist.item(0).getFirstChild().getNodeValue().trim();
+ supplement = new byte[MAX_SUPPLEMENT_SIZE];
+ supplementSize = 0;
+ for ( int i = 0; i < supplementStr.length(); i++ ) {
+ if (supplementStr.charAt(i) == '\n') continue;
+ supplement[supplementSize++] = (byte)Integer.parseInt(supplementStr.substring(i,i+2), 16);
+ i++;
+ }
+ System.out.println("Supplement read complete:");
+ System.out.println(" Total bytes = " + supplementSize);
+ }
+
nlist=doc.getElementsByTagName("deluge_support");
tmp = nlist.item(0).getFirstChild().getNodeValue();
***************
*** 135,138 ****
--- 157,169 ----
hostname = "N/A";
+ for ( int i = 0; i < STRING_SIZE; i++ )
+ tmpBytes[i] = (byte)(bytes[curOffset++] & 0xff);
+ platform = new String(tmpBytes);
+
+ if (platform.indexOf('\0') != -1)
+ platform = platform.substring(0, platform.indexOf('\0'));
+ if (platform.length() == 0)
+ platform = "N/A";
+
unixTime = 0;
for ( int i = 0; i < UNIX_TIME_SIZE; i++ )
***************
*** 143,153 ****
userHash |= (long)(bytes[curOffset++] & 0xff) << (i*8);
}
public byte[] getBytes() {
! byte bytes[] = new byte[METADATA_SIZE + image.getSize()];
int curOffset = 0;
!
byte tmpBytes[] = name.getBytes();
System.arraycopy(tmpBytes, 0, bytes, curOffset, tmpBytes.length);
--- 174,191 ----
userHash |= (long)(bytes[curOffset++] & 0xff) << (i*8);
+ delugeSupport = ( bytes[curOffset++] != 0 ) ? true : false;
+
}
public byte[] getBytes() {
! byte bytes[];
int curOffset = 0;
!
! if ( supplementSize != 0 )
! bytes = new byte[METADATA_SIZE + image.getSize() + supplementSize + 8];
! else
! bytes = new byte[METADATA_SIZE + image.getSize() + 8];
!
byte tmpBytes[] = name.getBytes();
System.arraycopy(tmpBytes, 0, bytes, curOffset, tmpBytes.length);
***************
*** 162,165 ****
--- 200,207 ----
curOffset += STRING_SIZE;
+ tmpBytes = platform.getBytes();
+ System.arraycopy(tmpBytes, 0, bytes, curOffset, tmpBytes.length);
+ curOffset += STRING_SIZE;
+
for ( int i = 0; i < 4; i++ )
bytes[curOffset++] = (byte)((unixTime >> (8*i)) & 0xff);
***************
*** 168,173 ****
--- 210,231 ----
bytes[curOffset++] = (byte)((userHash >> (8*i)) & 0xff);
+ bytes[curOffset++] = (byte)((delugeSupport) ? 0x1 : 0x0);
+
System.arraycopy(image.getBytes(), 0, bytes, METADATA_SIZE, image.getSize());
+ if (supplementSize != 0) {
+ for ( int i = 0; i < 4; i++ )
+ bytes[METADATA_SIZE + image.getSize() + i] = 0;
+ for ( int i = 0; i < 4; i++ )
+ bytes[METADATA_SIZE + image.getSize() + 4 + i] = (byte)((supplementSize >> (8*i)) & 0xff);
+ System.arraycopy(supplement, 0, bytes,
+ METADATA_SIZE + image.getSize() + 8, supplementSize);
+ }
+ else {
+ for ( int i = 0; i < 8; i++ ) {
+ bytes[bytes.length - i - 1] = 0;
+ }
+ }
+
return bytes;
***************
*** 184,187 ****
--- 242,246 ----
return (" Prog Name: " + name + "\n" +
" Compiled On: " + date + "\n" +
+ " Platform: " + platform + "\n" +
" User ID: " + userid + "\n" +
" Hostname: " + hostname + "\n" +
***************
*** 190,193 ****
--- 249,255 ----
public String getName() { return name; }
+ public String getHostname() { return hostname; }
+ public String getUserID() { return userid; }
+ public String getPlatform() { return platform; }
public int getSize() { return size; }
public long getUnixTime() { return unixTime; }
- Previous message: [Tinyos-beta-commits]
CVS: tinyos-1.x/beta/Deluge/Deluge DelugeM.nc, 1.19,
1.20 DelugeMetadataC.nc, 1.7, 1.8 DelugeMetadataM.nc, 1.16,
1.17 DelugeMsgs.h, 1.4, 1.5
- Next message: [Tinyos-beta-commits] CVS: tinyos-1.x/beta/platform/imote2
hardware.h, 1.4, 1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-beta-commits
mailing list