tools/runonphone/trk/trkutils.h
branchRCL_3
changeset 4 3b1da2848fc7
child 5 d3bac044e0f0
equal deleted inserted replaced
3:41300fa6a67c 4:3b1da2848fc7
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the tools applications of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef DEBUGGER_TRK_UTILS
       
    43 #define DEBUGGER_TRK_UTILS
       
    44 
       
    45 #include <QtCore/QByteArray>
       
    46 #include <QtCore/QHash>
       
    47 #include <QtCore/QStringList>
       
    48 #include <QtCore/QVariant>
       
    49 
       
    50 typedef unsigned char byte;
       
    51 
       
    52 QT_BEGIN_NAMESPACE
       
    53 class QDateTime;
       
    54 QT_END_NAMESPACE
       
    55 
       
    56 namespace trk {
       
    57 
       
    58 enum Command {
       
    59     TrkPing = 0x00,
       
    60     TrkConnect = 0x01,
       
    61     TrkDisconnect = 0x02,
       
    62     TrkVersions = 0x04,
       
    63     TrkSupported = 0x05,
       
    64     TrkCpuType = 0x06,
       
    65     TrkHostVersions = 0x09,
       
    66     TrkContinue = 0x18,
       
    67     TrkCreateItem = 0x40,
       
    68     TrkDeleteItem = 0x41,
       
    69 
       
    70     TrkWriteFile = 0x48,
       
    71     TrkOpenFile = 0x4a,
       
    72     TrkCloseFile = 0x4b,
       
    73     TrkInstallFile = 0x4d,
       
    74     TrkInstallFile2 = 0x4e,
       
    75 
       
    76     TrkNotifyAck = 0x80,
       
    77     TrkNotifyNak = 0xff,
       
    78     TrkNotifyStopped = 0x90,
       
    79     TrkNotifyException = 0x91,
       
    80     TrkNotifyInternalError = 0x92,
       
    81     TrkNotifyCreated = 0xa0,
       
    82     TrkNotifyDeleted = 0xa1,
       
    83     TrkNotifyProcessorStarted = 0xa2,
       
    84     TrkNotifyProcessorStandBy = 0xa6,
       
    85     TrkNotifyProcessorReset = 0xa7
       
    86 };
       
    87 
       
    88 QByteArray decode7d(const QByteArray &ba);
       
    89 QByteArray encode7d(const QByteArray &ba);
       
    90 
       
    91 inline byte extractByte(const char *data) { return *data; }
       
    92 ushort extractShort(const char *data);
       
    93 uint extractInt(const char *data);
       
    94 
       
    95 QString quoteUnprintableLatin1(const QByteArray &ba);
       
    96 
       
    97 // produces "xx xx xx "
       
    98 QString stringFromArray(const QByteArray &ba, int maxLen = - 1);
       
    99 
       
   100 enum Endianness
       
   101 {
       
   102     LittleEndian,
       
   103     BigEndian,
       
   104     TargetByteOrder = BigEndian,
       
   105 };
       
   106 
       
   107 void appendByte(QByteArray *ba, byte b);
       
   108 void appendShort(QByteArray *ba, ushort s, Endianness = TargetByteOrder);
       
   109 void appendInt(QByteArray *ba, uint i, Endianness = TargetByteOrder);
       
   110 void appendString(QByteArray *ba, const QByteArray &str, Endianness = TargetByteOrder, bool appendNullTerminator = true);
       
   111 void appendDateTime(QByteArray *ba, QDateTime dateTime, Endianness = TargetByteOrder);
       
   112 
       
   113 struct Library
       
   114 {
       
   115     Library() {}
       
   116 
       
   117     QByteArray name;
       
   118     uint codeseg;
       
   119     uint dataseg;
       
   120 };
       
   121 
       
   122 struct TrkAppVersion {
       
   123     TrkAppVersion();
       
   124     void reset();    
       
   125 
       
   126     int trkMajor;
       
   127     int trkMinor;
       
   128     int protocolMajor;
       
   129     int protocolMinor;
       
   130 };
       
   131 
       
   132 struct Session
       
   133 {
       
   134     Session();
       
   135     void reset();
       
   136     QString deviceDescription(unsigned verbose) const;
       
   137 
       
   138     // Trk feedback
       
   139     byte cpuMajor;
       
   140     byte cpuMinor;
       
   141     byte bigEndian;
       
   142     byte defaultTypeSize;
       
   143     byte fpTypeSize;
       
   144     byte extended1TypeSize;
       
   145     byte extended2TypeSize;
       
   146     TrkAppVersion trkAppVersion;
       
   147     uint pid;
       
   148     uint tid;
       
   149     uint codeseg;
       
   150     uint dataseg;
       
   151     QHash<uint, uint> addressToBP;
       
   152 
       
   153     typedef QList<Library> Libraries;
       
   154     Libraries libraries;
       
   155 
       
   156     // Gdb request
       
   157     uint currentThread;
       
   158     QStringList modules;
       
   159 };
       
   160 
       
   161 struct TrkResult
       
   162 {
       
   163     TrkResult();
       
   164     void clear();
       
   165     QString toString() const;
       
   166     // 0 for no error.
       
   167     int errorCode() const;
       
   168     QString errorString() const;
       
   169 
       
   170     byte code;
       
   171     byte token;
       
   172     QByteArray data;
       
   173     QVariant cookie;
       
   174     bool isDebugOutput;
       
   175 };
       
   176 
       
   177 // returns a QByteArray containing optionally
       
   178 // the serial frame [0x01 0x90 <len>] and 0x7e encoded7d(ba) 0x7e
       
   179 QByteArray frameMessage(byte command, byte token, const QByteArray &data, bool serialFrame);
       
   180 ushort isValidTrkResult(const QByteArray &buffer, bool serialFrame);
       
   181 bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *r, QByteArray *rawData = 0);
       
   182 QByteArray errorMessage(byte code);
       
   183 QByteArray hexNumber(uint n, int digits = 0);
       
   184 QByteArray hexxNumber(uint n, int digits = 0); // prepends '0x', too
       
   185 uint swapEndian(uint in);
       
   186 
       
   187 } // namespace trk
       
   188 
       
   189 #endif // DEBUGGER_TRK_UTILS