From 48fb208f8b989b5a582d2b66d1e09ff223e3a00c Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Fri, 29 Jan 2016 15:03:29 -0500 Subject: [PATCH] Fixed crash bug found in many sub screens, made UDS scanner work better. --- discretestatewindow.cpp | 1 + flowviewwindow.cpp | 1 + frameinfowindow.cpp | 1 + framesenderwindow.cpp | 3 +- fuzzingwindow.cpp | 1 + graphingwindow.cpp | 1 + rangestatewindow.cpp | 1 + scriptingwindow.cpp | 1 + udsscanwindow.cpp | 102 +++++++++++++++++++++++++--------------- udsscanwindow.h | 6 +++ 10 files changed, 79 insertions(+), 39 deletions(-) diff --git a/discretestatewindow.cpp b/discretestatewindow.cpp index d198ae3..d5b5f80 100644 --- a/discretestatewindow.cpp +++ b/discretestatewindow.cpp @@ -44,6 +44,7 @@ void DiscreteStateWindow::updatedFrames(int numFrames) } else //just got some new frames. See if they are relevant. { + if (numFrames > modelFrames->count()) return; for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++) { thisFrame = modelFrames->at(i); diff --git a/flowviewwindow.cpp b/flowviewwindow.cpp index b52766e..d4fe69d 100644 --- a/flowviewwindow.cpp +++ b/flowviewwindow.cpp @@ -370,6 +370,7 @@ void FlowViewWindow::updatedFrames(int numFrames) } else //just got some new frames. See if they are relevant. { + if (numFrames > modelFrames->count()) return; int refID = frameCache[0].ID; bool needRefresh = false; for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++) diff --git a/frameinfowindow.cpp b/frameinfowindow.cpp index 2c25331..72d20a0 100644 --- a/frameinfowindow.cpp +++ b/frameinfowindow.cpp @@ -83,6 +83,7 @@ void FrameInfoWindow::updatedFrames(int numFrames) } else //just got some new frames. See if they are relevant. { + if (numFrames > modelFrames->count()) return; int currID = ui->listFrameID->currentItem()->text().toInt(NULL, 16); bool foundID = false; for (int x = modelFrames->count() - numFrames; x < modelFrames->count(); x++) diff --git a/framesenderwindow.cpp b/framesenderwindow.cpp index dce5d09..61cc598 100644 --- a/framesenderwindow.cpp +++ b/framesenderwindow.cpp @@ -109,7 +109,8 @@ void FrameSenderWindow::updatedFrames(int numFrames) buildFrameCache(); } else //just got some new frames. See if they are relevant. - { + { + if (numFrames > modelFrames->count()) return; qDebug() << "New frames in sender window"; //run through the supposedly new frames in order for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++) diff --git a/fuzzingwindow.cpp b/fuzzingwindow.cpp index e378859..45e564c 100644 --- a/fuzzingwindow.cpp +++ b/fuzzingwindow.cpp @@ -64,6 +64,7 @@ void FuzzingWindow::updatedFrames(int numFrames) } else //just got some new frames. See if they are relevant. { + if (numFrames > modelFrames->count()) return; for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++) { id = modelFrames->at(i).ID; diff --git a/graphingwindow.cpp b/graphingwindow.cpp index 2f9463e..05df3ed 100644 --- a/graphingwindow.cpp +++ b/graphingwindow.cpp @@ -142,6 +142,7 @@ void GraphingWindow::updatedFrames(int numFrames) } else //just got some new frames. See if they are relevant. { + if (numFrames > modelFrames->count()) return; for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++) { thisFrame = modelFrames->at(i); diff --git a/rangestatewindow.cpp b/rangestatewindow.cpp index 371f8aa..4171fc1 100644 --- a/rangestatewindow.cpp +++ b/rangestatewindow.cpp @@ -131,6 +131,7 @@ void RangeStateWindow::updatedFrames(int numFrames) } else //just got some new frames. See if we need to update the filters list. Otherwise nothing to do - no recalc happens until the button is pressed { + if (numFrames > modelFrames->count()) return; for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++) { thisFrame = modelFrames->at(i); diff --git a/scriptingwindow.cpp b/scriptingwindow.cpp index 0b0520d..19ab11d 100644 --- a/scriptingwindow.cpp +++ b/scriptingwindow.cpp @@ -39,6 +39,7 @@ void ScriptingWindow::updatedFrames(int numFrames) //-1 means all frames deleted and -2 means a full refresh, neither of which we care about here. if (numFrames > 0) { + if (numFrames > modelFrames->count()) return; qDebug() << "Got frames into script window: " << numFrames; //for every new frame pass it on to each script container. The container will determine if it needs to actually //notify the script and do that if applicable. diff --git a/udsscanwindow.cpp b/udsscanwindow.cpp index 4dd6847..3ac94e6 100644 --- a/udsscanwindow.cpp +++ b/udsscanwindow.cpp @@ -10,8 +10,12 @@ UDSScanWindow::UDSScanWindow(const QVector *frames, QWidget *parent) : modelFrames = frames; + waitTimer = new QTimer; + waitTimer->setInterval(500); + connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int))); connect(ui->btnScan, &QPushButton::clicked, this, &UDSScanWindow::scanUDS); + connect(waitTimer, &QTimer::timeout, this, &UDSScanWindow::timeOut); ui->cbBuses->addItem("0"); ui->cbBuses->addItem("1"); @@ -22,48 +26,49 @@ UDSScanWindow::UDSScanWindow(const QVector *frames, QWidget *parent) : UDSScanWindow::~UDSScanWindow() { delete ui; + waitTimer->stop(); + delete waitTimer; } void UDSScanWindow::scanUDS() { ui->listResults->clear(); + sendingFrames.clear(); - CANFrame *frame; + CANFrame frame; int buses = ui->cbBuses->currentIndex(); buses++; if (buses < 1) buses = 1; - for (int id = 0x7E0; id < 0x7E8; id++) + for (int typ = 1; typ < 5; typ++) { - if (buses & 1) + for (int id = 0x7E0; id < 0x7E8; id++) { - frame = new CANFrame; - frame->ID = id; - frame->len = 8; - frame->extended = false; - frame->data[0] = 2; - frame->data[1] = 0x10; - frame->data[2] = 1; - frame->data[3] = 0;frame->data[4] = 0;frame->data[5] = 0; - frame->data[6] = 0;frame->data[7] = 0; - frame->bus = 0; - emit sendCANFrame(frame, 0); - } - if (buses & 2) - { - frame = new CANFrame; - frame->ID = id; - frame->len = 8; - frame->extended = false; - frame->data[0] = 2; - frame->data[1] = 0x10; - frame->data[2] = 1; - frame->data[3] = 0;frame->data[4] = 0;frame->data[5] = 0; - frame->data[6] = 0;frame->data[7] = 0; - frame->bus = 1; - emit sendCANFrame(frame, 1); + frame.ID = id; + frame.len = 8; + frame.extended = false; + frame.data[0] = 2; + frame.data[1] = 0x10; + frame.data[2] = typ; + frame.data[3] = 0;frame.data[4] = 0;frame.data[5] = 0; + frame.data[6] = 0;frame.data[7] = 0; + + if (buses & 1) + { + frame.bus = 0; + sendingFrames.append(frame); + } + if (buses & 2) + { + frame.bus = 1; + sendingFrames.append(frame); + } } } + + waitTimer->start(); + currIdx = -1; + sendNextMsg(); } void UDSScanWindow::updatedFrames(int numFrames) @@ -79,23 +84,44 @@ void UDSScanWindow::updatedFrames(int numFrames) } else //just got some new frames. See if they are relevant. { + if (numFrames > modelFrames->count()) return; for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++) { thisFrame = modelFrames->at(i); id = thisFrame.ID; if (id >= 0x7E8 && id <= 0x7EF) { - if (thisFrame.data[1] == 0x50) - { - result = "ECU at 0x" + QString::number(id, 16) + " bus " + QString::number(thisFrame.bus) + " accepts UDS standard diag"; - ui->listResults->addItem(result); - } - if (thisFrame.data[i] == 0x7f) - { - result = "ECU at 0x" + QString::number(id, 16) + " bus " + QString::number(thisFrame.bus) + " rejects UDS standard diag"; - ui->listResults->addItem(result); - } + id -= 8; //back to original ECU id + result = "ECU at bus " + QString::number(thisFrame.bus) + " ID: " + QString::number(id, 16) + " responds to mode " + + QString::number(sendingFrames[currIdx].data[2]) + " with: " + QString::number(thisFrame.data[0], 16) + " " + + QString::number(thisFrame.data[1], 16) + " " + QString::number(thisFrame.data[2], 16) + + " " + QString::number(thisFrame.data[3], 16); + ui->listResults->addItem(result); + sendNextMsg(); } } } } + +void UDSScanWindow::timeOut() +{ + QString result; + result = "ECU at bus " + QString::number(sendingFrames[currIdx].bus) + " ID: " + QString::number(sendingFrames[currIdx].ID, 16) + " did not respond to mode " + + QString::number(sendingFrames[currIdx].data[2]); + ui->listResults->addItem(result); + + sendNextMsg(); +} + +void UDSScanWindow::sendNextMsg() +{ + currIdx++; + if (currIdx < sendingFrames.count()) + { + emit sendCANFrame(&sendingFrames[currIdx], sendingFrames[currIdx].bus); + } + else + { + waitTimer->stop(); + } +} diff --git a/udsscanwindow.h b/udsscanwindow.h index ccf1579..39b06d5 100644 --- a/udsscanwindow.h +++ b/udsscanwindow.h @@ -23,10 +23,16 @@ signals: private slots: void updatedFrames(int numFrames); void scanUDS(); + void timeOut(); private: Ui::UDSScanWindow *ui; const QVector *modelFrames; + QTimer *waitTimer; + QList sendingFrames; + int currIdx = 0; + + void sendNextMsg(); }; #endif // UDSSCANWINDOW_H