Added frames per second read out. Fixed some crashes.

This commit is contained in:
Collin Kidder
2015-05-24 10:10:27 -04:00
parent f18411c567
commit 06ee0c9301
7 changed files with 66 additions and 13 deletions
+10
View File
@@ -128,9 +128,11 @@ QVariant CANFrameModel::headerData(int section, Qt::Orientation orientation,
void CANFrameModel::addFrame(CANFrame &frame, bool autoRefresh = false)
{
mutex.lock();
if (autoRefresh) beginInsertRows(QModelIndex(), frames.count() + 1, frames.count() + 1);
frames.append(frame);
if (autoRefresh) endInsertRows();
mutex.unlock();
}
void CANFrameModel::sendRefresh()
@@ -151,15 +153,23 @@ void CANFrameModel::sendRefresh(int pos)
void CANFrameModel::sendBulkRefresh(int num)
{
//qDebug() << "Bulk refresh of " << num;
//the next three lines protect against a crash in case someone clicked clear frames
//in between the time we got some frames and the time this was called
//otherwise it's possible that the grid is in an odd state.
if (num == 0) return;
if (frames.count() == 0) return;
if (num > frames.count()) num = frames.count();
beginInsertRows(QModelIndex(), frames.count() - num, frames.count() - 1);
endInsertRows();
}
void CANFrameModel::clearFrames()
{
mutex.lock();
this->beginResetModel();
frames.clear();
this->endResetModel();
mutex.unlock();
}
//Is this safe? Maybe not but if we don't change it then that's OK
+1
View File
@@ -35,6 +35,7 @@ public:
private:
QVector<CANFrame> frames;
DBCHandler *dbcHandler;
QMutex mutex;
bool interpretFrames; //should we use the dbcHandler?
bool overwriteDups; //should we display all frames or only the newest for each ID?
};
+9 -5
View File
@@ -118,22 +118,25 @@ MainWindow::MainWindow(QWidget *parent) :
ui->statusBar->addWidget(&lbStatusBauds);
ui->statusBar->addWidget(&lbStatusDatabase);
ui->lbFPS->setText("0");
ui->lbNumFrames->setText("0");
isConnected = false;
}
MainWindow::~MainWindow()
{
delete ui;
serialWorkerThread.quit();
serialWorkerThread.wait();
if (graphingWindow) delete graphingWindow;
if (frameInfoWindow) delete frameInfoWindow;
if (playbackWindow) delete playbackWindow;
if (flowViewWindow) delete flowViewWindow;
if (frameSenderWindow) delete frameSenderWindow;
delete ui;
delete dbcHandler;
serialWorkerThread.quit();
serialWorkerThread.wait();
}
void MainWindow::updateBaudLabel(int baud0, int baud1)
@@ -150,10 +153,11 @@ void MainWindow::updateBaudLabel(int baud0, int baud1)
//most of the work is handled elsewhere. Need only to update the # of frames
//and maybe auto scroll
void MainWindow::gotFrames()
void MainWindow::gotFrames(int FPS)
{
ui->lbNumFrames->setText(QString::number(model->rowCount()));
if (ui->cbAutoScroll->isChecked()) ui->canFramesView->scrollToBottom();
ui->lbFPS->setText(QString::number(FPS));
}
void MainWindow::addFrameToDisplay(CANFrame &frame, bool autoRefresh = false)
+2 -2
View File
@@ -13,7 +13,7 @@
#include "framesenderwindow.h"
#include "dbchandler.h"
#define VERSION 102
#define VERSION 103
namespace Ui {
class MainWindow;
@@ -46,7 +46,7 @@ private slots:
void connectionSucceeded(int, int);
public slots:
void gotFrames();
void gotFrames(int);
signals:
+27 -1
View File
@@ -151,7 +151,7 @@
</sizepolicy>
</property>
<property name="text">
<string># Of Frames:</string>
<string>Total Frames Captured:</string>
</property>
</widget>
</item>
@@ -168,6 +168,32 @@
</property>
</widget>
</item>
<item alignment="Qt::AlignHCenter">
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Frames Per Second:</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignHCenter">
<widget class="QLabel" name="lbFPS">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnClearFrames">
<property name="text">
+13 -4
View File
@@ -13,6 +13,8 @@ SerialWorker::SerialWorker(CANFrameModel *model, QObject *parent) : QObject(pare
canModel = model;
gotFrames = 0;
ticker = NULL;
elapsedTime = NULL;
framesPerSec = 0;
}
SerialWorker::~SerialWorker()
@@ -69,6 +71,11 @@ void SerialWorker::setSerialPort(QSerialPortInfo *port)
ticker = new QTimer;
connect(ticker, SIGNAL(timeout()), this, SLOT(handleTick()));
}
if (elapsedTime == NULL)
{
elapsedTime = new QTime;
elapsedTime->start();
}
ticker->setInterval(250); //tick four times per second
ticker->setSingleShot(false); //keep ticking
ticker->start();
@@ -341,12 +348,14 @@ void SerialWorker::procRXChar(unsigned char c)
void SerialWorker::handleTick()
{
//qDebug() << "Tick!";
if (gotFrames > 0)
{
emit receivedFrames(); //notify interested parties that there are new frames
framesPerSec += gotFrames * 1000 / elapsedTime->elapsed() - (framesPerSec / 4);
elapsedTime->restart();
//if (gotFrames > 0)
//{
emit receivedFrames(framesPerSec / 4); //misnamed now. Just notifies of FPS and that frames might exist
canModel->sendBulkRefresh(gotFrames);
gotFrames = 0;
}
//}
}
//totally shuts down the whole thing
+4 -1
View File
@@ -1,6 +1,7 @@
#ifndef SERIALWORKER_H
#define SERIALWORKER_H
#include <QDateTime>
#include <QObject>
#include <QSerialPort>
#include <QSerialPortInfo>
@@ -32,7 +33,7 @@ public:
signals: //we emit signals
void error(const QString &);
void receivedFrames(); //since the last tick we got at least one more frame
void receivedFrames(int); //since the last tick we got at least one more frame
void connectionSuccess(int, int);
void connectionFailure();
void deviceInfo(int, int);
@@ -55,6 +56,8 @@ private:
QSerialPort *serial;
CANFrameModel *canModel;
QTimer *ticker;
QTime *elapsedTime;
int framesPerSec;
int gotFrames;
STATE rx_state;
int rx_step;