[svn] Fixed and optimized DTNInterface svn
authorsamo
Fri, 01 Dec 2006 17:21:19 +0000
branchsvn
changeset 69bf21bafe7bfa
parent 68 1705dee62466
child 70 972af01517e5
[svn] Fixed and optimized DTNInterface
x86/DTN/HexDumpBuffer.cc
x86/DTNInterface.cpp
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/x86/DTN/HexDumpBuffer.cc	Fri Dec 01 17:21:19 2006 +0000
     1.3 @@ -0,0 +1,63 @@
     1.4 +/*
     1.5 + * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
     1.6 + * downloading, copying, installing or using the software you agree to
     1.7 + * this license. If you do not agree to this license, do not download,
     1.8 + * install, copy or use the software.
     1.9 + * 
    1.10 + * Intel Open Source License 
    1.11 + * 
    1.12 + * Copyright (c) 2004 Intel Corporation. All rights reserved. 
    1.13 + * 
    1.14 + * Redistribution and use in source and binary forms, with or without
    1.15 + * modification, are permitted provided that the following conditions are
    1.16 + * met:
    1.17 + * 
    1.18 + *   Redistributions of source code must retain the above copyright
    1.19 + *   notice, this list of conditions and the following disclaimer.
    1.20 + * 
    1.21 + *   Redistributions in binary form must reproduce the above copyright
    1.22 + *   notice, this list of conditions and the following disclaimer in the
    1.23 + *   documentation and/or other materials provided with the distribution.
    1.24 + * 
    1.25 + *   Neither the name of the Intel Corporation nor the names of its
    1.26 + *   contributors may be used to endorse or promote products derived from
    1.27 + *   this software without specific prior written permission.
    1.28 + *  
    1.29 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.30 + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.31 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.32 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
    1.33 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.34 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.35 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.36 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.37 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.38 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.39 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.40 + */
    1.41 +
    1.42 +#include <ctype.h>
    1.43 +#include "HexDumpBuffer.h"
    1.44 +
    1.45 +namespace oasys {
    1.46 +
    1.47 +void
    1.48 +HexDumpBuffer::hexify()
    1.49 +{
    1.50 +    // make a copy of the current data
    1.51 +    size_t len = length();
    1.52 +    std::string contents(data(), len);
    1.53 +    // rewind the string buffer backwards
    1.54 +    trim(length());
    1.55 +
    1.56 +    // generate the dump
    1.57 +    u_char* bp = (u_char*)contents.data();
    1.58 +    appendf("Size:%d\n",len);
    1.59 +    for (size_t i = 0; i < len; ++i, ++bp)
    1.60 +    {
    1.61 +        // print the hex character
    1.62 +        appendf("%02x", *bp);
    1.63 +    }
    1.64 +}
    1.65 +
    1.66 +} // namespace oasys
     2.1 --- a/x86/DTNInterface.cpp	Tue Nov 28 13:20:58 2006 +0000
     2.2 +++ b/x86/DTNInterface.cpp	Fri Dec 01 17:21:19 2006 +0000
     2.3 @@ -182,7 +182,7 @@
     2.4  						if(bundleList.size()>0)
     2.5  						{
     2.6  							QString command;
     2.7 -							command.append("bundle dump_tcl ");
     2.8 +							command.append("bundle dump ");
     2.9  							command.append(QString("%1").arg(bundleList.at(bundleIndex).options));
    2.10  							client->appendCommand(0,command);
    2.11  							dtnState=PARSE;
    2.12 @@ -194,34 +194,44 @@
    2.13  						}
    2.14  			break;
    2.15  		case PARSE:	client->appendCommand(0,(QString)"bundle list");
    2.16 -
    2.17  						//First we extract the bundle payload size
    2.18 -						temp=response.mid(0,600);
    2.19 -						pos=temp.indexOf("payload_len ",0);			
    2.20 +						temp=response.mid(0,20);
    2.21 +						pos=temp.indexOf("Size:",0);			
    2.22  						int payloadSize;					
    2.23  						flag=0;
    2.24 -						pos2=temp.indexOf("payload_data {",0);
    2.25 -						if(pos2==-1)
    2.26 -						{
    2.27 -							pos2=temp.indexOf("payload_data ",0);
    2.28 -							flag=1;
    2.29 -						}
    2.30 -						temp=temp.mid(pos+12,pos2-(pos+13));
    2.31 +						pos2=temp.indexOf("\n",0);
    2.32 +						temp=temp.mid(pos+5,pos2-(pos+6));
    2.33  						payloadSize=temp.toInt(0,10);
    2.34  						if(payloadSize>0)
    2.35  						{
    2.36 +							
    2.37  							QByteArray tempData;
    2.38 -							//Using dump_tcl does not require any parsing
    2.39 -							//of actual data
    2.40 -							if(flag==0)
    2.41 -								tempData=response.mid(pos2+14,payloadSize);
    2.42 -							else
    2.43 -								tempData=response.mid(pos2+13,payloadSize);
    2.44 +							QString hexValue;
    2.45 +							char decValue;
    2.46 +							response.remove(0,pos2+1);
    2.47 +							pos=0;
    2.48 +							while(pos<(2*payloadSize))
    2.49 +							{
    2.50 +								//Decode hex value
    2.51 +								hexValue=response.mid(pos,2);
    2.52 +								decValue=hexValue.toShort(0,16);
    2.53 +								tempData.append(decValue);
    2.54 +								//Move to next value
    2.55 +								pos=pos+2;
    2.56 +
    2.57 +							}							
    2.58 +							
    2.59 +								
    2.60  							Bundle tempBundle=bundleList.at(bundleIndex);
    2.61 -							tempBundle.data=tempData;
    2.62 -							//Removing from the list
    2.63 +							tempBundle.data=tempData;
    2.64 +
    2.65 +						//Removing from the list
    2.66  							parsedList.append(tempBundle.options);
    2.67 -													
    2.68 +			
    2.69 +							
    2.70 +							
    2.71 +							
    2.72 +							
    2.73  							//Checking if this is not our bundle
    2.74  							QString temp;
    2.75  							QString destination;