S60/Trk: Change trkutils to be a library of its own.

To be able to share TrkDevices between Debugger and Qt4ProjectManager.
This commit is contained in:
Friedemann Kleint
2010-02-05 12:24:46 +01:00
parent 5548721662
commit f2b3e9f2df
22 changed files with 213 additions and 116 deletions

View File

@@ -1,5 +1,6 @@
TEMPLATE = subdirs TEMPLATE = subdirs
CONFIG += ordered CONFIG += ordered
QT += core gui
SUBDIRS = \ SUBDIRS = \
qtconcurrent \ qtconcurrent \
@@ -8,7 +9,8 @@ SUBDIRS = \
utils \ utils \
utils/process_stub.pro \ utils/process_stub.pro \
cplusplus \ cplusplus \
qmljs qmljs \
symbianutils
SUPPORT_QT_MAEMO = $$(QTCREATOR_WITH_MAEMO) SUPPORT_QT_MAEMO = $$(QTCREATOR_WITH_MAEMO)
!isEmpty(SUPPORT_QT_MAEMO) { !isEmpty(SUPPORT_QT_MAEMO) {

View File

@@ -0,0 +1,3 @@
INCLUDEPATH *= $$PWD/../../shared/trk
DEPENDPATH += $$PWD/../../shared/trk
LIBS *= -l$$qtLibraryTarget(symbianutils)

View File

@@ -0,0 +1,6 @@
TEMPLATE = lib
CONFIG+=dll
TARGET = symbianutils
DEFINES += SYMBIANUTILS_BUILD_LIB
include(../../qtcreatorlibrary.pri)
include(../../shared/trk/trk.pri)

View File

@@ -1,5 +1,4 @@
include(../../../shared/trk/trk.pri) include(../../../libs/symbianutils/symbianutils.pri)
HEADERS += \ HEADERS += \
$$PWD/gdbmi.h \ $$PWD/gdbmi.h \
$$PWD/gdbengine.h \ $$PWD/gdbengine.h \

View File

@@ -75,6 +75,8 @@ namespace Internal {
enum { KnownRegisters = RegisterPSGdb + 1}; enum { KnownRegisters = RegisterPSGdb + 1};
static inline void appendByte(QByteArray *ba, trk::byte b) { ba->append(b); }
static const char *registerNames[KnownRegisters] = static const char *registerNames[KnownRegisters] =
{ {
"A1", "A2", "A3", "A4", "A1", "A2", "A3", "A4",
@@ -330,7 +332,7 @@ QByteArray TrkGdbAdapter::trkReadRegistersMessage()
return ba; return ba;
} }
QByteArray TrkGdbAdapter::trkWriteRegisterMessage(byte reg, uint value) QByteArray TrkGdbAdapter::trkWriteRegisterMessage(trk::byte reg, uint value)
{ {
QByteArray ba; QByteArray ba;
appendByte(&ba, 0); // ? appendByte(&ba, 0); // ?
@@ -372,7 +374,7 @@ QByteArray TrkGdbAdapter::trkWriteMemoryMessage(uint addr, const QByteArray &dat
return ba; return ba;
} }
QByteArray TrkGdbAdapter::trkStepRangeMessage(byte option) QByteArray TrkGdbAdapter::trkStepRangeMessage(trk::byte option)
{ {
QByteArray ba; QByteArray ba;
ba.reserve(17); ba.reserve(17);
@@ -510,7 +512,7 @@ void TrkGdbAdapter::readGdbServerCommand()
} }
//logMessage(QString("Packet checksum: %1").arg(checkSum)); //logMessage(QString("Packet checksum: %1").arg(checkSum));
byte sum = 0; trk::byte sum = 0;
for (int i = 0; i < pos; ++i) for (int i = 0; i < pos; ++i)
sum += ba.at(i); sum += ba.at(i);
@@ -557,7 +559,7 @@ void TrkGdbAdapter::sendGdbServerAck()
void TrkGdbAdapter::sendGdbServerMessage(const QByteArray &msg, const QByteArray &logNote) void TrkGdbAdapter::sendGdbServerMessage(const QByteArray &msg, const QByteArray &logNote)
{ {
byte sum = 0; trk::byte sum = 0;
for (int i = 0; i != msg.size(); ++i) for (int i = 0; i != msg.size(); ++i)
sum += msg.at(i); sum += msg.at(i);
@@ -1071,7 +1073,7 @@ void TrkGdbAdapter::handleGdbServerCommand(const QByteArray &cmd)
} }
} }
void TrkGdbAdapter::sendTrkMessage(byte code, TrkCallback callback, void TrkGdbAdapter::sendTrkMessage(trk::byte code, TrkCallback callback,
const QByteArray &data, const QVariant &cookie) const QByteArray &data, const QVariant &cookie)
{ {
if (m_verbose >= 2) if (m_verbose >= 2)
@@ -1080,7 +1082,7 @@ void TrkGdbAdapter::sendTrkMessage(byte code, TrkCallback callback,
m_trkDevice->sendTrkMessage(code, callback, data, cookie); m_trkDevice->sendTrkMessage(code, callback, data, cookie);
} }
void TrkGdbAdapter::sendTrkAck(byte token) void TrkGdbAdapter::sendTrkAck(trk::byte token)
{ {
//logMessage(QString("SENDING ACKNOWLEDGEMENT FOR TOKEN %1").arg(int(token))); //logMessage(QString("SENDING ACKNOWLEDGEMENT FOR TOKEN %1").arg(int(token)));
m_trkDevice->sendTrkAck(token); m_trkDevice->sendTrkAck(token);
@@ -1184,9 +1186,9 @@ void TrkGdbAdapter::handleTrkResult(const TrkResult &result)
debugMessage(_("RESET SNAPSHOT (NOTIFY CREATED)")); debugMessage(_("RESET SNAPSHOT (NOTIFY CREATED)"));
m_snapshot.reset(); m_snapshot.reset();
const char *data = result.data.data(); const char *data = result.data.data();
const byte error = result.data.at(0); const trk::byte error = result.data.at(0);
// type: 1 byte; for dll item, this value is 2. // type: 1 byte; for dll item, this value is 2.
const byte type = result.data.at(1); const trk::byte type = result.data.at(1);
const uint pid = extractInt(data + 2); const uint pid = extractInt(data + 2);
const uint tid = extractInt(data + 6); const uint tid = extractInt(data + 6);
const uint codeseg = extractInt(data + 10); const uint codeseg = extractInt(data + 10);

View File

@@ -186,7 +186,7 @@ private:
// //
// TRK // TRK
// //
void sendTrkMessage(byte code, void sendTrkMessage(trk::byte code,
TrkCallback callback = TrkCallback(), TrkCallback callback = TrkCallback(),
const QByteArray &data = QByteArray(), const QByteArray &data = QByteArray(),
const QVariant &cookie = QVariant()); const QVariant &cookie = QVariant());
@@ -194,7 +194,7 @@ private:
Q_SLOT void handleTrkError(const QString &msg); Q_SLOT void handleTrkError(const QString &msg);
// convenience messages // convenience messages
void sendTrkAck(byte token); void sendTrkAck(trk::byte token);
void handleCpuType(const TrkResult &result); void handleCpuType(const TrkResult &result);
void handleCreateProcess(const TrkResult &result); void handleCreateProcess(const TrkResult &result);
@@ -245,12 +245,12 @@ private:
QByteArray trkContinueMessage(); QByteArray trkContinueMessage();
QByteArray trkReadRegistersMessage(); QByteArray trkReadRegistersMessage();
QByteArray trkWriteRegisterMessage(byte reg, uint value); QByteArray trkWriteRegisterMessage(trk::byte reg, uint value);
QByteArray trkReadMemoryMessage(const MemoryRange &range); QByteArray trkReadMemoryMessage(const MemoryRange &range);
QByteArray trkReadMemoryMessage(uint addr, uint len); QByteArray trkReadMemoryMessage(uint addr, uint len);
QByteArray trkWriteMemoryMessage(uint addr, const QByteArray &date); QByteArray trkWriteMemoryMessage(uint addr, const QByteArray &date);
QByteArray trkBreakpointMessage(uint addr, uint len, bool armMode = true); QByteArray trkBreakpointMessage(uint addr, uint len, bool armMode = true);
QByteArray trkStepRangeMessage(byte option); QByteArray trkStepRangeMessage(trk::byte option);
QByteArray trkDeleteProcessMessage(); QByteArray trkDeleteProcessMessage();
QByteArray trkInterruptMessage(); QByteArray trkInterruptMessage();

View File

@@ -31,4 +31,4 @@ HEADERS += $$PWD/s60devices.h \
$$PWD/rvctparser.h \ $$PWD/rvctparser.h \
$$PWD/winscwparser.h $$PWD/winscwparser.h
FORMS += $$PWD/s60devicespreferencepane.ui FORMS += $$PWD/s60devicespreferencepane.ui
include(../../../shared/trk/trk.pri)||error("could not include trk.pri") include(../../libs/symbianutils/symbianutils.pri)||error("could not include symbianutils.pri")

View File

@@ -30,6 +30,8 @@
#ifndef BLUETOOTHLISTENER_H #ifndef BLUETOOTHLISTENER_H
#define BLUETOOTHLISTENER_H #define BLUETOOTHLISTENER_H
#include "symbianutils_global.h"
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QProcess> #include <QtCore/QProcess>
@@ -41,7 +43,7 @@ struct BluetoothListenerPrivate;
* The rfcomm command is used. It process can be started in the background * The rfcomm command is used. It process can be started in the background
* while connection attempts (TrkDevice::open()) are made in the foreground. */ * while connection attempts (TrkDevice::open()) are made in the foreground. */
class BluetoothListener : public QObject class SYMBIANUTILS_EXPORT BluetoothListener : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(BluetoothListener) Q_DISABLE_COPY(BluetoothListener)

View File

@@ -38,7 +38,7 @@
namespace trk { namespace trk {
PromptStartCommunicationResult SYMBIANUTILS_EXPORT PromptStartCommunicationResult
promptStartCommunication(BaseCommunicationStarter &starter, promptStartCommunication(BaseCommunicationStarter &starter,
const QString &msgBoxTitle, const QString &msgBoxTitle,
const QString &msgBoxText, const QString &msgBoxText,
@@ -76,7 +76,7 @@ PromptStartCommunicationResult
return PromptStartCommunicationConnected; return PromptStartCommunicationConnected;
} }
PromptStartCommunicationResult SYMBIANUTILS_EXPORT PromptStartCommunicationResult
promptStartSerial(BaseCommunicationStarter &starter, promptStartSerial(BaseCommunicationStarter &starter,
QWidget *msgBoxParent, QWidget *msgBoxParent,
QString *errorMessage) QString *errorMessage)
@@ -86,7 +86,7 @@ PromptStartCommunicationResult
return promptStartCommunication(starter, title, message, msgBoxParent, errorMessage); return promptStartCommunication(starter, title, message, msgBoxParent, errorMessage);
} }
PromptStartCommunicationResult SYMBIANUTILS_EXPORT PromptStartCommunicationResult
promptStartBluetooth(BaseCommunicationStarter &starter, promptStartBluetooth(BaseCommunicationStarter &starter,
QWidget *msgBoxParent, QWidget *msgBoxParent,
QString *errorMessage) QString *errorMessage)

View File

@@ -30,6 +30,8 @@
#ifndef BLUETOOTHLISTENER_GUI_H #ifndef BLUETOOTHLISTENER_GUI_H
#define BLUETOOTHLISTENER_GUI_H #define BLUETOOTHLISTENER_GUI_H
#include "symbianutils_global.h"
#include <QtCore/QtGlobal> #include <QtCore/QtGlobal>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@@ -50,7 +52,7 @@ enum PromptStartCommunicationResult {
PromptStartCommunicationError PromptStartCommunicationError
}; };
PromptStartCommunicationResult SYMBIANUTILS_EXPORT PromptStartCommunicationResult
promptStartCommunication(BaseCommunicationStarter &starter, promptStartCommunication(BaseCommunicationStarter &starter,
const QString &msgBoxTitle, const QString &msgBoxTitle,
const QString &msgBoxText, const QString &msgBoxText,
@@ -59,14 +61,14 @@ PromptStartCommunicationResult
// Convenience to start a serial connection (messages prompting // Convenience to start a serial connection (messages prompting
// to launch Trk). // to launch Trk).
PromptStartCommunicationResult SYMBIANUTILS_EXPORT PromptStartCommunicationResult
promptStartSerial(BaseCommunicationStarter &starter, promptStartSerial(BaseCommunicationStarter &starter,
QWidget *msgBoxParent, QWidget *msgBoxParent,
QString *errorMessage); QString *errorMessage);
// Convenience to start blue tooth connection (messages // Convenience to start blue tooth connection (messages
// prompting to connect). // prompting to connect).
PromptStartCommunicationResult SYMBIANUTILS_EXPORT PromptStartCommunicationResult
promptStartBluetooth(BaseCommunicationStarter &starter, promptStartBluetooth(BaseCommunicationStarter &starter,
QWidget *msgBoxParent, QWidget *msgBoxParent,
QString *errorMessage); QString *errorMessage);

View File

@@ -30,7 +30,7 @@
#ifndef DEBUGGER_CALLBACK_H #ifndef DEBUGGER_CALLBACK_H
#define DEBUGGER_CALLBACK_H #define DEBUGGER_CALLBACK_H
#include <QtCore/QtGlobal> #include "symbianutils_global.h"
namespace trk { namespace trk {
namespace Internal { namespace Internal {

View File

@@ -30,6 +30,8 @@
#ifndef COMMUNICATIONSTARTER_H #ifndef COMMUNICATIONSTARTER_H
#define COMMUNICATIONSTARTER_H #define COMMUNICATIONSTARTER_H
#include "symbianutils_global.h"
#include <QtCore/QSharedPointer> #include <QtCore/QSharedPointer>
#include <QtCore/QObject> #include <QtCore/QObject>
@@ -48,7 +50,7 @@ struct BaseCommunicationStarterPrivate;
* The base class can be used as is to prompt the user to launch App TRK for a * The base class can be used as is to prompt the user to launch App TRK for a
* serial communication as this requires no further resource setup. */ * serial communication as this requires no further resource setup. */
class BaseCommunicationStarter : public QObject { class SYMBIANUTILS_EXPORT BaseCommunicationStarter : public QObject {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(BaseCommunicationStarter) Q_DISABLE_COPY(BaseCommunicationStarter)
public: public:
@@ -105,7 +107,7 @@ private:
* implement as a factory function that creates and sets up the * implement as a factory function that creates and sets up the
* listener (mode, message connection, etc). */ * listener (mode, message connection, etc). */
class AbstractBluetoothStarter : public BaseCommunicationStarter { class SYMBIANUTILS_EXPORT AbstractBluetoothStarter : public BaseCommunicationStarter {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(AbstractBluetoothStarter) Q_DISABLE_COPY(AbstractBluetoothStarter)
public: public:
@@ -122,7 +124,7 @@ protected:
/* ConsoleBluetoothStarter: Convenience class for console processes. Creates a /* ConsoleBluetoothStarter: Convenience class for console processes. Creates a
* listener in "Listen" mode with the messages redirected to standard output. */ * listener in "Listen" mode with the messages redirected to standard output. */
class ConsoleBluetoothStarter : public AbstractBluetoothStarter { class SYMBIANUTILS_EXPORT ConsoleBluetoothStarter : public AbstractBluetoothStarter {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(ConsoleBluetoothStarter) Q_DISABLE_COPY(ConsoleBluetoothStarter)
public: public:

View File

@@ -29,6 +29,7 @@
#include "launcher.h" #include "launcher.h"
#include "trkutils.h" #include "trkutils.h"
#include "trkutils_p.h"
#include "trkdevice.h" #include "trkdevice.h"
#include "bluetoothlistener.h" #include "bluetoothlistener.h"
@@ -604,9 +605,7 @@ void Launcher::cleanUp()
// Sub Cmd: Delete Process // Sub Cmd: Delete Process
//ProcessID: 0x0000071F (1823) //ProcessID: 0x0000071F (1823)
// [41 24 00 00 00 00 07 1F] // [41 24 00 00 00 00 07 1F]
QByteArray ba; QByteArray ba(2, char(0));
appendByte(&ba, 0x00);
appendByte(&ba, 0x00);
appendInt(&ba, d->m_session.pid); appendInt(&ba, d->m_session.pid);
d->m_device->sendTrkMessage(TrkDeleteItem, TrkCallback(), ba, "Delete process"); d->m_device->sendTrkMessage(TrkDeleteItem, TrkCallback(), ba, "Delete process");
@@ -659,7 +658,7 @@ void Launcher::copyFileToRemote()
{ {
emit copyingStarted(); emit copyingStarted();
QByteArray ba; QByteArray ba;
appendByte(&ba, 0x10); ba.append(char(10));
appendString(&ba, d->m_copyState.destinationFileName.toLocal8Bit(), TargetByteOrder, false); appendString(&ba, d->m_copyState.destinationFileName.toLocal8Bit(), TargetByteOrder, false);
d->m_device->sendTrkMessage(TrkOpenFile, TrkCallback(this, &Launcher::handleFileCreation), ba); d->m_device->sendTrkMessage(TrkOpenFile, TrkCallback(this, &Launcher::handleFileCreation), ba);
} }
@@ -668,7 +667,7 @@ void Launcher::installRemotePackageSilently()
{ {
emit installingStarted(); emit installingStarted();
QByteArray ba; QByteArray ba;
appendByte(&ba, 'C'); ba.append('C');
appendString(&ba, d->m_installFileName.toLocal8Bit(), TargetByteOrder, false); appendString(&ba, d->m_installFileName.toLocal8Bit(), TargetByteOrder, false);
d->m_device->sendTrkMessage(TrkInstallFile, TrkCallback(this, &Launcher::handleInstallPackageFinished), ba); d->m_device->sendTrkMessage(TrkInstallFile, TrkCallback(this, &Launcher::handleInstallPackageFinished), ba);
} }
@@ -695,7 +694,7 @@ QByteArray Launcher::startProcessMessage(const QString &executable,
// It's not started yet // It's not started yet
QByteArray ba; QByteArray ba;
appendShort(&ba, 0, TargetByteOrder); // create new process appendShort(&ba, 0, TargetByteOrder); // create new process
appendByte(&ba, 0); // options - currently unused ba.append(char(0)); // options - currently unused
if(arguments.isEmpty()) { if(arguments.isEmpty()) {
appendString(&ba, executable.toLocal8Bit(), TargetByteOrder); appendString(&ba, executable.toLocal8Bit(), TargetByteOrder);
return ba; return ba;

View File

@@ -43,7 +43,7 @@ struct LauncherPrivate;
typedef QSharedPointer<TrkDevice> TrkDevicePtr; typedef QSharedPointer<TrkDevice> TrkDevicePtr;
class Launcher : public QObject class SYMBIANUTILS_EXPORT Launcher : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(Launcher) Q_DISABLE_COPY(Launcher)

View File

@@ -0,0 +1,43 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef SYMBIANUTILS_GLOBAL_H
#define SYMBIANUTILS_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(SYMBIANUTILS_BUILD_LIB)
# define SYMBIANUTILS_EXPORT Q_DECL_EXPORT
#elif defined(SYMBIANUTILS_BUILD_STATIC_LIB) || defined(SYMBIANUTILS_INCLUDE_PRI)
# define SYMBIANUTILS_EXPORT
#else
# define SYMBIANUTILS_EXPORT Q_DECL_IMPORT
#endif
#endif // SYMBIANUTILS_GLOBAL_H

View File

@@ -1,8 +1,10 @@
INCLUDEPATH *= $$PWD INCLUDEPATH *= $$PWD
# Input # Input
HEADERS += $$PWD/callback.h \ HEADERS += $$PWD/symbianutils_global.h \
$$PWD/callback.h \
$$PWD/trkutils.h \ $$PWD/trkutils.h \
$$PWD/trkutils_p.h \
$$PWD/trkdevice.h \ $$PWD/trkdevice.h \
$$PWD/launcher.h \ $$PWD/launcher.h \
$$PWD/bluetoothlistener.h \ $$PWD/bluetoothlistener.h \

View File

@@ -29,6 +29,7 @@
#include "trkdevice.h" #include "trkdevice.h"
#include "trkutils.h" #include "trkutils.h"
#include "trkutils_p.h"
#include <QtCore/QString> #include <QtCore/QString>
#include <QtCore/QDebug> #include <QtCore/QDebug>
@@ -844,8 +845,8 @@ void UnixReaderThread::terminate()
{ {
// Trigger select() by writing to the pipe // Trigger select() by writing to the pipe
char c = 0; char c = 0;
int written = write(m_terminatePipeFileDescriptors[1], &c, 1); const int written = write(m_terminatePipeFileDescriptors[1], &c, 1);
// FIXME: Use result. Q_UNUSED(written)
wait(); wait();
} }

View File

@@ -30,6 +30,7 @@
#ifndef TRKDEVICE_H #ifndef TRKDEVICE_H
#define TRKDEVICE_H #define TRKDEVICE_H
#include "symbianutils_global.h"
#include "callback.h" #include "callback.h"
#include <QtCore/QObject> #include <QtCore/QObject>
@@ -62,7 +63,7 @@ enum { TRK_WRITE_QUEUE_NOOP_CODE = 0x7f };
typedef trk::Callback<const TrkResult &> TrkCallback; typedef trk::Callback<const TrkResult &> TrkCallback;
class TrkDevice : public QObject class SYMBIANUTILS_EXPORT TrkDevice : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool serialFrame READ serialFrame WRITE setSerialFrame) Q_PROPERTY(bool serialFrame READ serialFrame WRITE setSerialFrame)

View File

@@ -74,7 +74,7 @@ void Session::reset()
trkAppVersion.reset(); trkAppVersion.reset();
} }
QString formatCpu(int major, int minor) static QString formatCpu(int major, int minor)
{ {
//: CPU description of an S60 device //: CPU description of an S60 device
//: %1 major verison, %2 minor version //: %1 major verison, %2 minor version
@@ -131,6 +131,38 @@ QString Session::deviceDescription(unsigned verbose) const
return msg.arg(formatTrkVersion(trkAppVersion)); return msg.arg(formatTrkVersion(trkAppVersion));
} }
// --------------
QByteArray decode7d(const QByteArray &ba)
{
QByteArray res;
res.reserve(ba.size());
for (int i = 0; i < ba.size(); ++i) {
byte c = byte(ba.at(i));
if (c == 0x7d) {
++i;
c = 0x20 ^ byte(ba.at(i));
}
res.append(c);
}
return res;
}
QByteArray encode7d(const QByteArray &ba)
{
QByteArray res;
res.reserve(ba.size() + 2);
for (int i = 0; i < ba.size(); ++i) {
byte c = byte(ba.at(i));
if (c == 0x7e || c == 0x7d) {
res.append(0x7d);
res.append(0x20 ^ c);
} else {
res.append(c);
}
}
return res;
}
// FIXME: Use the QByteArray based version below? // FIXME: Use the QByteArray based version below?
static inline QString stringFromByte(byte c) static inline QString stringFromByte(byte c)
@@ -138,7 +170,7 @@ static inline QString stringFromByte(byte c)
return QString::fromLatin1("%1").arg(c, 2, 16, QChar('0')); return QString::fromLatin1("%1").arg(c, 2, 16, QChar('0'));
} }
QString stringFromArray(const QByteArray &ba, int maxLen) SYMBIANUTILS_EXPORT QString stringFromArray(const QByteArray &ba, int maxLen)
{ {
QString str; QString str;
QString ascii; QString ascii;
@@ -158,7 +190,7 @@ QString stringFromArray(const QByteArray &ba, int maxLen)
return str + " " + ascii; return str + " " + ascii;
} }
QByteArray hexNumber(uint n, int digits) SYMBIANUTILS_EXPORT QByteArray hexNumber(uint n, int digits)
{ {
QByteArray ba = QByteArray::number(n, 16); QByteArray ba = QByteArray::number(n, 16);
if (digits == 0 || ba.size() == digits) if (digits == 0 || ba.size() == digits)
@@ -166,7 +198,7 @@ QByteArray hexNumber(uint n, int digits)
return QByteArray(digits - ba.size(), '0') + ba; return QByteArray(digits - ba.size(), '0') + ba;
} }
QByteArray hexxNumber(uint n, int digits) SYMBIANUTILS_EXPORT QByteArray hexxNumber(uint n, int digits)
{ {
return "0x" + hexNumber(n, digits); return "0x" + hexNumber(n, digits);
} }
@@ -295,12 +327,12 @@ bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *result, QByt
return true; return true;
} }
ushort extractShort(const char *data) SYMBIANUTILS_EXPORT ushort extractShort(const char *data)
{ {
return byte(data[0]) * 256 + byte(data[1]); return byte(data[0]) * 256 + byte(data[1]);
} }
uint extractInt(const char *data) SYMBIANUTILS_EXPORT uint extractInt(const char *data)
{ {
uint res = byte(data[0]); uint res = byte(data[0]);
res *= 256; res += byte(data[1]); res *= 256; res += byte(data[1]);
@@ -309,7 +341,7 @@ uint extractInt(const char *data)
return res; return res;
} }
QString quoteUnprintableLatin1(const QByteArray &ba) SYMBIANUTILS_EXPORT QString quoteUnprintableLatin1(const QByteArray &ba)
{ {
QString res; QString res;
char buf[10]; char buf[10];
@@ -325,49 +357,7 @@ QString quoteUnprintableLatin1(const QByteArray &ba)
return res; return res;
} }
QByteArray decode7d(const QByteArray &ba) SYMBIANUTILS_EXPORT void appendShort(QByteArray *ba, ushort s, Endianness endian)
{
QByteArray res;
res.reserve(ba.size());
for (int i = 0; i < ba.size(); ++i) {
byte c = byte(ba.at(i));
if (c == 0x7d) {
++i;
c = 0x20 ^ byte(ba.at(i));
}
res.append(c);
}
//if (res != ba)
// logMessage("DECODED: " << stringFromArray(ba)
// << " -> " << stringFromArray(res));
return res;
}
QByteArray encode7d(const QByteArray &ba)
{
QByteArray res;
res.reserve(ba.size() + 2);
for (int i = 0; i < ba.size(); ++i) {
byte c = byte(ba.at(i));
if (c == 0x7e || c == 0x7d) {
res.append(0x7d);
res.append(0x20 ^ c);
} else {
res.append(c);
}
}
//if (res != ba)
// logMessage("ENCODED: " << stringFromArray(ba)
// << " -> " << stringFromArray(res));
return res;
}
void appendByte(QByteArray *ba, byte b)
{
ba->append(b);
}
void appendShort(QByteArray *ba, ushort s, Endianness endian)
{ {
if (endian == BigEndian) { if (endian == BigEndian) {
ba->append(s / 256); ba->append(s / 256);
@@ -378,7 +368,7 @@ void appendShort(QByteArray *ba, ushort s, Endianness endian)
} }
} }
void appendInt(QByteArray *ba, uint i, Endianness endian) SYMBIANUTILS_EXPORT void appendInt(QByteArray *ba, uint i, Endianness endian)
{ {
const uchar b3 = i % 256; i /= 256; const uchar b3 = i % 256; i /= 256;
const uchar b2 = i % 256; i /= 256; const uchar b2 = i % 256; i /= 256;

View File

@@ -30,19 +30,21 @@
#ifndef DEBUGGER_TRK_UTILS #ifndef DEBUGGER_TRK_UTILS
#define DEBUGGER_TRK_UTILS #define DEBUGGER_TRK_UTILS
#include "symbianutils_global.h"
#include <QtCore/QByteArray> #include <QtCore/QByteArray>
#include <QtCore/QHash> #include <QtCore/QHash>
#include <QtCore/QStringList> #include <QtCore/QStringList>
#include <QtCore/QVariant> #include <QtCore/QVariant>
typedef unsigned char byte;
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QDateTime; class QDateTime;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace trk { namespace trk {
typedef unsigned char byte;
enum Command { enum Command {
TrkPing = 0x00, TrkPing = 0x00,
TrkConnect = 0x01, TrkConnect = 0x01,
@@ -73,17 +75,14 @@ enum Command {
TrkNotifyProcessorReset = 0xa7 TrkNotifyProcessorReset = 0xa7
}; };
QByteArray decode7d(const QByteArray &ba);
QByteArray encode7d(const QByteArray &ba);
inline byte extractByte(const char *data) { return *data; } inline byte extractByte(const char *data) { return *data; }
ushort extractShort(const char *data); SYMBIANUTILS_EXPORT ushort extractShort(const char *data);
uint extractInt(const char *data); SYMBIANUTILS_EXPORT uint extractInt(const char *data);
QString quoteUnprintableLatin1(const QByteArray &ba); SYMBIANUTILS_EXPORT QString quoteUnprintableLatin1(const QByteArray &ba);
// produces "xx xx xx " // produces "xx xx xx "
QString stringFromArray(const QByteArray &ba, int maxLen = - 1); SYMBIANUTILS_EXPORT QString stringFromArray(const QByteArray &ba, int maxLen = - 1);
enum Endianness enum Endianness
{ {
@@ -92,13 +91,11 @@ enum Endianness
TargetByteOrder = BigEndian, TargetByteOrder = BigEndian,
}; };
void appendByte(QByteArray *ba, byte b); SYMBIANUTILS_EXPORT void appendShort(QByteArray *ba, ushort s, Endianness = TargetByteOrder);
void appendShort(QByteArray *ba, ushort s, Endianness = TargetByteOrder); SYMBIANUTILS_EXPORT void appendInt(QByteArray *ba, uint i, Endianness = TargetByteOrder);
void appendInt(QByteArray *ba, uint i, Endianness = TargetByteOrder); SYMBIANUTILS_EXPORT void appendString(QByteArray *ba, const QByteArray &str, Endianness = TargetByteOrder, bool appendNullTerminator = true);
void appendString(QByteArray *ba, const QByteArray &str, Endianness = TargetByteOrder, bool appendNullTerminator = true);
void appendDateTime(QByteArray *ba, QDateTime dateTime, Endianness = TargetByteOrder);
struct Library struct SYMBIANUTILS_EXPORT Library
{ {
Library() {} Library() {}
@@ -107,7 +104,7 @@ struct Library
uint dataseg; uint dataseg;
}; };
struct TrkAppVersion struct SYMBIANUTILS_EXPORT TrkAppVersion
{ {
TrkAppVersion(); TrkAppVersion();
void reset(); void reset();
@@ -118,7 +115,7 @@ struct TrkAppVersion
int protocolMinor; int protocolMinor;
}; };
struct Session struct SYMBIANUTILS_EXPORT Session
{ {
Session(); Session();
void reset(); void reset();
@@ -151,7 +148,7 @@ struct Session
QStringList modules; QStringList modules;
}; };
struct TrkResult struct SYMBIANUTILS_EXPORT TrkResult
{ {
TrkResult(); TrkResult();
void clear(); void clear();
@@ -167,15 +164,10 @@ struct TrkResult
bool isDebugOutput; bool isDebugOutput;
}; };
// returns a QByteArray containing optionally SYMBIANUTILS_EXPORT QByteArray errorMessage(byte code);
// the serial frame [0x01 0x90 <len>] and 0x7e encoded7d(ba) 0x7e SYMBIANUTILS_EXPORT QByteArray hexNumber(uint n, int digits = 0);
QByteArray frameMessage(byte command, byte token, const QByteArray &data, bool serialFrame); SYMBIANUTILS_EXPORT QByteArray hexxNumber(uint n, int digits = 0); // prepends '0x', too
ushort isValidTrkResult(const QByteArray &buffer, bool serialFrame); SYMBIANUTILS_EXPORT uint swapEndian(uint in);
bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *r, QByteArray *rawData = 0);
QByteArray errorMessage(byte code);
QByteArray hexNumber(uint n, int digits = 0);
QByteArray hexxNumber(uint n, int digits = 0); // prepends '0x', too
uint swapEndian(uint in);
} // namespace trk } // namespace trk

View File

@@ -0,0 +1,50 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef DEBUGGER_TRK_PRIVATE_UTILS
#define DEBUGGER_TRK_PRIVATE_UTILS
#include "trkutils.h"
#include "symbianutils_global.h"
QT_BEGIN_NAMESPACE
class QDateTime;
QT_END_NAMESPACE
namespace trk {
void appendDateTime(QByteArray *ba, QDateTime dateTime, Endianness = TargetByteOrder);
// returns a QByteArray containing optionally
// the serial frame [0x01 0x90 <len>] and 0x7e encoded7d(ba) 0x7e
QByteArray frameMessage(byte command, byte token, const QByteArray &data, bool serialFrame);
bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *r, QByteArray *rawData = 0);
} // namespace trk
#endif // DEBUGGER_TRK_PRIVATE_UTILS

View File

@@ -1,5 +1,6 @@
TEMPLATE = app TEMPLATE = app
QT = core QT = core
DEFINES += SYMBIANUTILS_INCLUDE_PRI
CONFIG += console CONFIG += console
include(../../../src/shared/trk/trk.pri) include(../../../src/shared/trk/trk.pri)
SOURCES += main.cpp SOURCES += main.cpp