Added ability for sub windows to get frames much more rapidly than

before. Decoupled SerialWorker from MainWindow a bit and refactored
things.
This commit is contained in:
Collin Kidder
2016-02-28 16:10:55 -05:00
parent 07b63ac127
commit 4767a7349f
5 changed files with 55 additions and 31 deletions
+27 -7
View File
@@ -69,7 +69,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(&serialWorkerThread, &QThread::finished, worker, &QObject::deleteLater);
connect(&serialWorkerThread, &QThread::started, worker, &SerialWorker::run); //setup timers within the proper thread
connect(this, &MainWindow::sendSerialPort, worker, &SerialWorker::setSerialPort, Qt::QueuedConnection);
connect(worker, &SerialWorker::frameUpdateTick, this, &MainWindow::gotFrames, Qt::QueuedConnection);
connect(worker, &SerialWorker::frameUpdateRapid, this, &MainWindow::gotFrames, Qt::QueuedConnection);
connect(this, &MainWindow::updateBaudRates, worker, &SerialWorker::updateBaudRates, Qt::QueuedConnection);
connect(this, &MainWindow::sendCANFrame, worker, &SerialWorker::sendFrame, Qt::QueuedConnection);
connect(worker, &SerialWorker::connectionSuccess, this, &MainWindow::connectionSucceeded, Qt::QueuedConnection);
@@ -101,6 +101,7 @@ MainWindow::MainWindow(QWidget *parent) :
dbcHandler = new DBCHandler;
bDirty = false;
inhibitFilterUpdate = false;
rxFrames = 0;
model->setDBCHandler(dbcHandler);
@@ -150,6 +151,13 @@ MainWindow::MainWindow(QWidget *parent) :
ui->lbFPS->setText("0");
ui->lbNumFrames->setText("0");
connect(&updateTimer, &QTimer::timeout, this, &MainWindow::tickGUIUpdate);
updateTimer.setInterval(250);
updateTimer.start();
elapsedTime = new QTime;
elapsedTime->start();
isConnected = false;
allowCapture = true;
@@ -266,6 +274,8 @@ MainWindow::~MainWindow()
delete udsScanWindow;
}
delete elapsedTime;
delete ui;
delete dbcHandler;
model->clearFrames();
@@ -493,20 +503,30 @@ void MainWindow::filterClearAll()
model->setAllFilters(false);
}
//most of the work is handled elsewhere. Need only to update the # of frames
//and maybe auto scroll
void MainWindow::gotFrames(int FPS, int framesSinceLastUpdate)
void MainWindow::tickGUIUpdate()
{
framesPerSec += rxFrames * 1000 / elapsedTime->elapsed() - (framesPerSec / 4);
elapsedTime->restart();
model->sendBulkRefresh(rxFrames);
ui->lbNumFrames->setText(QString::number(model->rowCount()));
if (ui->cbAutoScroll->isChecked()) ui->canFramesView->scrollToBottom();
ui->lbFPS->setText(QString::number(FPS));
if (framesSinceLastUpdate > 0)
ui->lbFPS->setText(QString::number(framesPerSec / 4));
if (rxFrames > 0)
{
bDirty = true;
emit framesUpdated(framesSinceLastUpdate); //anyone care that frames were updated?
emit framesUpdated(rxFrames); //anyone care that frames were updated?
}
if (model->needsFilterRefresh()) updateFilterList();
rxFrames = 0;
}
void MainWindow::gotFrames(int framesSinceLastUpdate)
{
rxFrames += framesSinceLastUpdate;
emit frameUpdateRapid(framesSinceLastUpdate);
}
void MainWindow::addFrameToDisplay(CANFrame &frame, bool autoRefresh = false)