Commit 7e0b2081 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Trk: Ping mode, better argument parsing.

parent 5b6ab144
......@@ -117,6 +117,7 @@ struct LauncherPrivate {
QString m_copySrcFileName;
QString m_copyDstFileName;
QString m_installFileName;
int m_verbose;
};
LauncherPrivate::LauncherPrivate() :
......@@ -125,7 +126,8 @@ LauncherPrivate::LauncherPrivate() :
#endif
m_trkWriteToken(0),
m_trkWriteBusy(false),
m_timerId(-1)
m_timerId(-1),
m_verbose(0)
{
}
......@@ -165,6 +167,11 @@ void Launcher::setInstallFileName(const QString &name)
bool Launcher::startServer(QString *errorMessage)
{
if (d->m_verbose) {
const QString msg = QString::fromLatin1("Port=%1 Executable=%2 Package=%3 Remote Package=%4 Install file=%5")
.arg(d->m_trkServerName, d->m_fileName, d->m_copySrcFileName, d->m_copyDstFileName, d->m_installFileName);
logMessage(msg);
}
if (!openTrkPort(d->m_trkServerName, errorMessage))
return false;
d->m_timerId = startTimer(100);
......@@ -172,7 +179,9 @@ bool Launcher::startServer(QString *errorMessage)
sendTrkMessage(TrkConnect); // Connect
sendTrkMessage(TrkSupported, CB(handleSupportMask));
sendTrkMessage(TrkCpuType, CB(handleCpuType));
sendTrkMessage(TrkVersions); // Versions
sendTrkMessage(TrkVersions, CB(handleTrkVersion));
if (d->m_fileName.isEmpty())
return true;
if (!d->m_copySrcFileName.isEmpty() && !d->m_copyDstFileName.isEmpty())
copyFileToRemote();
else
......@@ -180,6 +189,11 @@ bool Launcher::startServer(QString *errorMessage)
return true;
}
void Launcher::setVerbose(int v)
{
d->m_verbose = v;
}
void Launcher::installAndRun()
{
if (!d->m_installFileName.isEmpty()) {
......@@ -190,7 +204,7 @@ void Launcher::installAndRun()
}
void Launcher::logMessage(const QString &msg)
{
if (DEBUG_TRK)
if (d->m_verbose)
qDebug() << "ADAPTER: " << qPrintable(msg);
}
......@@ -464,6 +478,27 @@ void Launcher::handleResult(const TrkResult &result)
}
}
void Launcher::handleTrkVersion(const TrkResult &result)
{
if (result.data.size() < 5)
return;
const int trkMajor = result.data.at(1);
const int trkMinor = result.data.at(2);
const int protocolMajor = result.data.at(3);
const int protocolMinor = result.data.at(4);
// Ping mode: Log & Terminate
if (d->m_fileName.isEmpty()) {
QString msg;
QTextStream(&msg) << "CPU: " << d->m_session.cpuMajor << '.' << d->m_session.cpuMinor << ' '
<< (d->m_session.bigEndian ? "big endian" : "little endian")
<< " type size: " << d->m_session.defaultTypeSize
<< " float size: " << d->m_session.fpTypeSize
<< " Trk: v" << trkMajor << '.' << trkMinor << " Protocol: " << protocolMajor << '.' << protocolMinor;
qWarning("%s", qPrintable(msg));
sendTrkMessage(TrkPing, CB(waitForTrkFinished));
}
}
void Launcher::handleFileCreation(const TrkResult &result)
{
// we don't do any error handling yet, which is bad
......@@ -502,12 +537,12 @@ void Launcher::handleCpuType(const TrkResult &result)
// Command: 0x80 Acknowledge
// Error: 0x00
// [80 03 00 04 00 00 04 00 00 00]
d->m_session.cpuMajor = result.data[0];
d->m_session.cpuMinor = result.data[1];
d->m_session.bigEndian = result.data[2];
d->m_session.defaultTypeSize = result.data[3];
d->m_session.fpTypeSize = result.data[4];
d->m_session.extended1TypeSize = result.data[5];
d->m_session.cpuMajor = result.data.at(1);
d->m_session.cpuMinor = result.data.at(2);
d->m_session.bigEndian = result.data.at(3);
d->m_session.defaultTypeSize = result.data.at(4);
d->m_session.fpTypeSize = result.data.at(5);
d->m_session.extended1TypeSize = result.data.at(6);
//d->m_session.extended2TypeSize = result.data[6];
}
......@@ -521,10 +556,12 @@ void Launcher::handleCreateProcess(const TrkResult &result)
d->m_session.tid = extractInt(data + 5);
d->m_session.codeseg = extractInt(data + 9);
d->m_session.dataseg = extractInt(data + 13);
logMessage(QString(" READ PID: %1").arg(d->m_session.pid));
logMessage(QString(" READ TID: %1").arg(d->m_session.tid));
logMessage(QString(" READ CODE: %1").arg(d->m_session.codeseg));
logMessage(QString(" READ DATA: %1").arg(d->m_session.dataseg));
if (d->m_verbose) {
const QString msg = QString::fromLatin1("Process id: %1 Thread id: %2 code: 0x%3 data: 0x%4").
arg(d->m_session.pid).arg(d->m_session.tid).arg(d->m_session.codeseg, 0, 16).
arg(d->m_session.dataseg, 0 ,16);
logMessage(msg);
}
emit applicationRunning(d->m_session.pid);
QByteArray ba;
appendInt(&ba, d->m_session.pid);
......
......@@ -51,6 +51,7 @@ public:
void setCopyFileName(const QString &srcName, const QString &dstName);
void setInstallFileName(const QString &name);
bool startServer(QString *errorMessage);
void setVerbose(int v);
signals:
void copyingStarted();
......@@ -93,6 +94,7 @@ private:
void handleWaitForFinished(const TrkResult &result);
void handleStop(const TrkResult &result);
void handleSupportMask(const TrkResult &result);
void handleTrkVersion(const TrkResult &result);
void waitForTrkFinished(const TrkResult &data);
void handleAndReportCreateProcess(const TrkResult &result);
......
......@@ -2,32 +2,94 @@
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtCore/QStringList>
int main(int argc, char *argv[])
static const char *usageC =
"\nUsage: %1 <trk_port_name> [-v] [-i remote_sis_file | -I local_sis_file remote_sis_file] <remote_executable_name>\n"
"\nOptions:\n -v verbose\n\n"
"\nPing:\n"
"%1 COM5\n"
"\nRemote launch:\n"
"%1 COM5 C:\\sys\\bin\\test.exe\n"
"\nInstallation and remote launch:\n"
"%1 COM5 -i C:\\Data\\test_gcce_udeb.sisx C:\\sys\\bin\\test.exe\n"
"\nCopy from local file, installation and remote launch:\n"
"%1 COM5 -I C:\\Projects\\test\\test_gcce_udeb.sisx C:\\Data\\test_gcce_udeb.sisx C:\\sys\\bin\\test.exe\n";
static void usage()
{
if ((argc != 3 && argc != 5 && argc != 6)
|| (argc == 5 && QString(argv[2]) != "-i")
|| (argc == 6 && QString(argv[2]) != "-I")) {
qDebug() << "Usage: " << argv[0] << "<trk_port_name> [-i remote_sis_file | -I local_sis_file remote_sis_file] <remote_executable_name>";
qDebug() << "for example" << argv[0] << "COM5 C:\\sys\\bin\\test.exe";
qDebug() << " " << argv[0] << "COM5 -i C:\\Data\\test_gcce_udeb.sisx C:\\sys\\bin\\test.exe";
qDebug() << " " << argv[0] << "COM5 -I C:\\Projects\\test\\test_gcce_udeb.sisx C:\\Data\\test_gcce_udeb.sisx C:\\sys\\bin\\test.exe";
return 1;
const QString msg = QString::fromLatin1(usageC).arg(QCoreApplication::applicationName());
qWarning("%s", qPrintable(msg));
}
static bool parseArguments(const QStringList &arguments, trk::Launcher &launcher)
{
// Parse away options
bool install = false;
bool customInstall = false;
const int argCount = arguments.size();
int verbosity = 0;
int a = 1;
for ( ; a < argCount; a++) {
const QString option = arguments.at(a);
if (!option.startsWith(QLatin1Char('-')))
break;
if (option.size() != 2)
return false;
switch (option.at(1).toAscii()) {
case 'v':
verbosity++;
break;
case 'i':
install = true;
break;
case 'I':
customInstall = true;
break;
default:
return false;
}
}
launcher.setVerbose(verbosity);
// Evaluate arguments
const int remainingArgsCount = argCount - a;
if (remainingArgsCount == 1 && !install && !customInstall) {
launcher.setTrkServerName(arguments.at(a)); // ping
return true;
}
if (remainingArgsCount == 2 && !install && !customInstall) {
// remote exec
launcher.setTrkServerName(arguments.at(a)); // ping
launcher.setFileName(arguments.at(a + 1));
return true;
}
if (remainingArgsCount == 3 && install && !customInstall) {
launcher.setTrkServerName(arguments.at(a)); // ping
launcher.setInstallFileName(arguments.at(a + 1));
launcher.setFileName(arguments.at(a + 2));
return true;
}
if (remainingArgsCount == 4 && !install && customInstall) {
launcher.setTrkServerName(arguments.at(a)); // ping
launcher.setCopyFileName(arguments.at(a + 1), arguments.at(a + 2));
launcher.setInstallFileName(arguments.at(a + 2));
launcher.setFileName(arguments.at(a + 3));
return true;
}
return false;
}
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QCoreApplication::setApplicationName(QLatin1String("trklauncher"));
QCoreApplication::setOrganizationName(QLatin1String("Nokia"));
trk::Launcher launcher;
launcher.setTrkServerName(argv[1]);
if (argc == 3) {
launcher.setFileName(argv[2]);
} else if (argc == 5) {
launcher.setInstallFileName(argv[3]);
launcher.setFileName(argv[4]);
} else {
launcher.setCopyFileName(argv[3], argv[4]);
launcher.setInstallFileName(argv[4]);
launcher.setFileName(argv[5]);
if (!parseArguments(app.arguments(), launcher)) {
usage();
return 1;
}
QObject::connect(&launcher, SIGNAL(finished()), &app, SLOT(quit()));
QString errorMessage;
......
TEMPLATE = app
QT = core
include($$PWD/trklauncher.pri)
DEFINES += DEBUG_TRK=1
win32:CONFIG += console
SOURCES += main_launcher.cpp
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment