Skip to content

Commit

Permalink
Fix for signal/slots firing in the wrong threads. This is a direct fi…
Browse files Browse the repository at this point in the history
…x for issue #879, but may also help with issue #884, since it prioritizes packet decoding over serial reading.
  • Loading branch information
malcom2073 committed Dec 20, 2013
1 parent f70dbf8 commit 8df02d6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
51 changes: 25 additions & 26 deletions core/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,32 +666,31 @@ void MainWindow::setPlugin(QString plugin)
m_logFileName = QDateTime::currentDateTime().toString("yyyy.MM.dd-hh.mm.ss");
emsComms->setLogFileName(m_logFileName);
emsComms->setLogDirectory(m_logDirectory);
connect(emsComms,SIGNAL(resetDetected(int)),this,SLOT(ecuResetDetected(int)));
connect(emsComms,SIGNAL(dataLogPayloadDecoded(QVariantMap)),this,SLOT(dataLogDecoded(QVariantMap)));
connect(emsComms,SIGNAL(interrogationProgress(int,int)),this,SLOT(interrogationProgress(int,int)));
connect(emsComms,SIGNAL(interrogationComplete()),this,SLOT(interrogationComplete()));
connect(emsComms,SIGNAL(interrogateTaskStart(QString,int)),this,SLOT(interrogateTaskStart(QString,int)));
connect(emsComms,SIGNAL(interrogateTaskSucceed(int)),this,SLOT(interrogateTaskSucceed(int)));
connect(emsComms,SIGNAL(interrogateTaskFail(int)),this,SLOT(interrogateTaskFail(int)));
connect(emsComms,SIGNAL(connected()),this,SLOT(emsCommsConnected()));
connect(emsComms,SIGNAL(emsSilenceStarted()),this,SLOT(emsCommsSilence()));
connect(emsComms,SIGNAL(emsSilenceBroken()),this,SLOT(emsCommsSilenceBroken()));
connect(emsComms,SIGNAL(error(QString)),this,SLOT(error(QString)));
connect(emsComms,SIGNAL(error(SerialPortStatus,QString)),this,SLOT(error(SerialPortStatus,QString)));

connect(emsComms,SIGNAL(disconnected()),this,SLOT(emsCommsDisconnected()));
connect(emsComms,SIGNAL(dataLogPayloadReceived(QByteArray,QByteArray)),this,SLOT(logPayloadReceived(QByteArray,QByteArray)));
connect(emsComms,SIGNAL(resetDetected(int)),this,SLOT(ecuResetDetected(int)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(dataLogPayloadDecoded(QVariantMap)),this,SLOT(dataLogDecoded(QVariantMap)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(interrogationProgress(int,int)),this,SLOT(interrogationProgress(int,int)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(interrogationComplete()),this,SLOT(interrogationComplete()),Qt::QueuedConnection);
connect(emsComms,SIGNAL(interrogateTaskStart(QString,int)),this,SLOT(interrogateTaskStart(QString,int)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(interrogateTaskSucceed(int)),this,SLOT(interrogateTaskSucceed(int)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(interrogateTaskFail(int)),this,SLOT(interrogateTaskFail(int)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(connected()),this,SLOT(emsCommsConnected()),Qt::QueuedConnection);
connect(emsComms,SIGNAL(emsSilenceStarted()),this,SLOT(emsCommsSilence()),Qt::QueuedConnection);
connect(emsComms,SIGNAL(emsSilenceBroken()),this,SLOT(emsCommsSilenceBroken()),Qt::QueuedConnection);
connect(emsComms,SIGNAL(error(QString)),this,SLOT(error(QString)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(error(SerialPortStatus,QString)),this,SLOT(error(SerialPortStatus,QString)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(disconnected()),this,SLOT(emsCommsDisconnected()),Qt::QueuedConnection);
connect(emsComms,SIGNAL(dataLogPayloadReceived(QByteArray,QByteArray)),this,SLOT(logPayloadReceived(QByteArray,QByteArray)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(locationIdList(QList<unsigned short>)),this,SLOT(locationIdList(QList<unsigned short>)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(unknownPacket(QByteArray,QByteArray)),this,SLOT(unknownPacket(QByteArray,QByteArray)));
connect(emsComms,SIGNAL(commandSuccessful(int)),this,SLOT(commandSuccessful(int)));
connect(emsComms,SIGNAL(commandTimedOut(int)),this,SLOT(commandTimedOut(int)));
connect(emsComms,SIGNAL(commandFailed(int,unsigned short)),this,SLOT(commandFailed(int,unsigned short)));
connect(emsComms,SIGNAL(locationIdInfo(unsigned short,MemoryLocationInfo)),this,SLOT(locationIdInfo(unsigned short,MemoryLocationInfo)));
connect(emsComms,SIGNAL(packetSent(unsigned short,QByteArray,QByteArray)),packetStatus,SLOT(passPacketSent(unsigned short,QByteArray,QByteArray)));
connect(emsComms,SIGNAL(packetAcked(unsigned short,QByteArray,QByteArray)),packetStatus,SLOT(passPacketAck(unsigned short,QByteArray,QByteArray)));
connect(emsComms,SIGNAL(packetNaked(unsigned short,QByteArray,QByteArray,unsigned short)),packetStatus,SLOT(passPacketNak(unsigned short,QByteArray,QByteArray,unsigned short)));
connect(emsComms,SIGNAL(decoderFailure(QByteArray)),packetStatus,SLOT(passDecoderFailure(QByteArray)));
connect(emsComms,SIGNAL(interrogationData(QMap<QString,QString>)),this,SLOT(interrogationData(QMap<QString,QString>)));
connect(emsComms,SIGNAL(unknownPacket(QByteArray,QByteArray)),this,SLOT(unknownPacket(QByteArray,QByteArray)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(commandSuccessful(int)),this,SLOT(commandSuccessful(int)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(commandTimedOut(int)),this,SLOT(commandTimedOut(int)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(commandFailed(int,unsigned short)),this,SLOT(commandFailed(int,unsigned short)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(locationIdInfo(unsigned short,MemoryLocationInfo)),this,SLOT(locationIdInfo(unsigned short,MemoryLocationInfo)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(packetSent(unsigned short,QByteArray,QByteArray)),packetStatus,SLOT(passPacketSent(unsigned short,QByteArray,QByteArray)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(packetAcked(unsigned short,QByteArray,QByteArray)),packetStatus,SLOT(passPacketAck(unsigned short,QByteArray,QByteArray)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(packetNaked(unsigned short,QByteArray,QByteArray,unsigned short)),packetStatus,SLOT(passPacketNak(unsigned short,QByteArray,QByteArray,unsigned short)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(decoderFailure(QByteArray)),packetStatus,SLOT(passDecoderFailure(QByteArray)),Qt::QueuedConnection);
connect(emsComms,SIGNAL(interrogationData(QMap<QString,QString>)),this,SLOT(interrogationData(QMap<QString,QString>)),Qt::QueuedConnection);
emsComms->setBaud(m_comBaud);
emsComms->setPort(m_comPort);
emsComms->setLogsEnabled(m_saveLogs);
Expand Down Expand Up @@ -1226,7 +1225,7 @@ void MainWindow::loadWizards(QString dir)
if (file.endsWith(".qml"))
{
WizardView *view = new WizardView();
connect(emsComms,SIGNAL(configRecieved(ConfigBlock,QVariant)),view,SLOT(configRecieved(ConfigBlock,QVariant)));
connect(emsComms,SIGNAL(configRecieved(ConfigBlock,QVariant)),view,SLOT(configRecieved(ConfigBlock,QVariant)),Qt::QueuedConnection);
m_wizardList.append(view);
for (int i=0;i<emsComms->getConfigList().size();i++)
{
Expand Down
10 changes: 6 additions & 4 deletions plugins/freeems/freeemscomms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ int FreeEmsComms::startBenchTest(unsigned char eventspercycle,unsigned short num
QMutexLocker locker(&m_reqListMutex);
RequestClass req;
req.type = BENCHTEST;
req.addArg(0x01,sizeof(char));
req.addArg(0x08,sizeof(char)); //Was 0x01, changed to 0x08 for testing command failures.
req.addArg(eventspercycle,sizeof(eventspercycle));
req.addArg(numcycles,sizeof(numcycles));
req.addArg(ticksperevent,sizeof(ticksperevent));
Expand Down Expand Up @@ -938,8 +938,8 @@ void FreeEmsComms::run()
}
QLOG_INFO() << "Serial connected!";
rxThread = new SerialRXThread();
connect(rxThread,SIGNAL(incomingPacket(QByteArray)),this,SLOT(parseEverything(QByteArray)));
connect(rxThread,SIGNAL(dataRead(QByteArray)),this,SLOT(dataLogRead(QByteArray)));
connect(rxThread,SIGNAL(incomingPacket(QByteArray)),this,SLOT(parseEverything(QByteArray)),Qt::DirectConnection);
connect(rxThread,SIGNAL(dataRead(QByteArray)),this,SLOT(dataLogRead(QByteArray)),Qt::DirectConnection);

//Before we finish emitting the fact that we are connected, let's verify this is a freeems system we are talking to.
if (!sendPacket(GET_FIRMWARE_VERSION))
Expand Down Expand Up @@ -1426,7 +1426,7 @@ void FreeEmsComms::run()
}

m_waitingInfoMutex.lock();
if (QDateTime::currentDateTime().currentMSecsSinceEpoch() - m_timeoutMsecs > 500 && m_waitingForResponse)
if (((QDateTime::currentDateTime().currentMSecsSinceEpoch() - m_timeoutMsecs) > 500) && m_waitingForResponse)
{
//5 seconds
QLOG_WARN() << "TIMEOUT waiting for response to payload:" << "0x" + QString::number(m_payloadWaitingForResponse,16).toUpper() << "Sequence:" << m_currentWaitingRequest.sequencenumber;
Expand Down Expand Up @@ -1591,6 +1591,7 @@ bool FreeEmsComms::sendSimplePacket(unsigned short payloadid)

void FreeEmsComms::packetNakedRec(unsigned short payloadid,QByteArray header,QByteArray payload,unsigned short errornum)
{
QMutexLocker locker(&m_waitingInfoMutex);
if (m_waitingForResponse)
{
if (m_interrogateInProgress)
Expand Down Expand Up @@ -1697,6 +1698,7 @@ void FreeEmsComms::packetNakedRec(unsigned short payloadid,QByteArray header,QBy

void FreeEmsComms::packetAckedRec(unsigned short payloadid,QByteArray header,QByteArray payload)
{
QMutexLocker locker(&m_waitingInfoMutex);
if (m_waitingForResponse)
{
if (m_interrogateInProgress)
Expand Down

0 comments on commit 8df02d6

Please sign in to comment.