Skip to content

Commit

Permalink
runonphone - Implement CODA autodetection
Browse files Browse the repository at this point in the history
If runonphone is executed without specifying the debug agent, then
it will attempt to autodetect it by sending a CODA ping to the USB
port.
If there is a reply within 1 second, then CODA mode is used.
If not, then TRK mode is used.

TRK drops unrecognised messages, so the CODA ping is ignored and
initialisation starts normally when the TRK ping is sent.

Autodetect can be skipped by using the --coda or --trk arguments on
the command line to force use of a specific debug agent.

Reviewed-By: mread
  • Loading branch information
Shane Kearns committed Oct 4, 2011
1 parent d22211b commit c9ff25e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
10 changes: 7 additions & 3 deletions tools/runonphone/codasignalhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,22 @@ int CodaSignalHandler::run()
connect(this, SIGNAL(done()), this, SLOT(finished()));

d->codaDevice->sendSerialPing(false);
if (d->timeout > 0)
QTimer::singleShot(d->timeout, this, SLOT(timeout()));
QTimer timer;
if (d->timeout > 0) {
connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
timer.setSingleShot(true);
timer.start(d->timeout);
}
d->eventLoop = new QEventLoop();
d->eventLoop->exec();
timer.stop();
int result = d->result;
reportMessage(tr("Done."));

delete traceHandler;
disconnect(d->codaDevice.data(), 0, this, 0);
SymbianUtils::SymbianDeviceManager::instance()->releaseCodaDevice(d->codaDevice);

QCoreApplication::quit();
return result;
}

Expand Down
31 changes: 26 additions & 5 deletions tools/runonphone/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ void printUsage(QTextStream& outstream, QString exeName)
<< "-T, --tempfile <remote file> specify temporary sis file name" << endl
<< "--nocrashlog Don't capture call stack if test crashes" << endl
<< "--crashlogpath <dir> Path to save crash logs (default=working dir)" << endl
<< "--coda Use CODA instead of TRK (default agent)" << endl
<< "--coda Use CODA instead of detecting the debug agent" << endl
<< "--trk Use TRK instead of detecting the debug agent" << endl
<< endl
<< "USB COM ports can usually be autodetected, use -p or -f to force a specific port." << endl
<< "TRK is the default debugging agent, use --coda option when using CODA instead of TRK." << endl
Expand Down Expand Up @@ -99,7 +100,7 @@ int main(int argc, char *argv[])
int loglevel=1;
int timeout=0;
bool crashlog = true;
bool coda = false;
enum {AgentUnknown, AgentCoda, AgentTRK} debugAgent = AgentUnknown;
QString crashlogpath;
QListIterator<QString> it(args);
it.next(); //skip name of program
Expand Down Expand Up @@ -154,7 +155,9 @@ int main(int argc, char *argv[])
}
}
else if (arg == "--coda")
coda = true;
debugAgent = AgentCoda;
else if (arg == "--trk")
debugAgent = AgentTRK;
else if (arg == "--tempfile" || arg == "-T") {
CHECK_PARAMETER_EXISTS
dstName = it.next();
Expand Down Expand Up @@ -225,7 +228,24 @@ int main(int argc, char *argv[])
QFileInfo info(exeFile);
QFileInfo uploadInfo(uploadLocalFile);

if (coda) {
if (debugAgent == AgentUnknown) {
outstream << "detecting debug agent..." << endl;
CodaSignalHandler codaDetector;
//auto detect agent
codaDetector.setSerialPortName(serialPortName);
codaDetector.setLogLevel(loglevel);
codaDetector.setActionType(ActionPingOnly);
codaDetector.setTimeout(1000);
if (!codaDetector.run()) {
debugAgent = AgentCoda;
outstream << " - Coda is found" << endl;
} else {
debugAgent = AgentTRK;
outstream << " - Coda is not found, defaulting to TRK" << endl;
}
}

if (debugAgent == AgentCoda) {
codaHandler.setSerialPortName(serialPortName);
codaHandler.setLogLevel(loglevel);

Expand Down Expand Up @@ -257,7 +277,8 @@ int main(int argc, char *argv[])
return codaHandler.run();

} else {
launcher.reset(new trk::Launcher(trk::Launcher::ActionPingOnly));
launcher.reset(new trk::Launcher(trk::Launcher::ActionPingOnly,
SymbianUtils::SymbianDeviceManager::instance()->acquireDevice(serialPortName)));
QStringList srcNames, dstNames;
if (!sisFile.isEmpty()) {
launcher->addStartupActions(trk::Launcher::ActionCopyInstall);
Expand Down
3 changes: 3 additions & 0 deletions tools/runonphone/symbianutils/symbiandevicemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ SymbianDevice::TrkDevicePtr SymbianDevice::acquireDevice()
<< "acquired: " << m_data->deviceAcquired << " open: " << isOpen();
if (isNull() || m_data->deviceAcquired)
return TrkDevicePtr();
//if port was opened for coda (but is not acquired) then close it first.
if (m_data->codaDevice)
m_data->codaDevice->device()->close();
if (m_data->device.isNull()) {
m_data->device = TrkDevicePtr(new trk::TrkDevice);
m_data->device->setPort(m_data->portName);
Expand Down

0 comments on commit c9ff25e

Please sign in to comment.