Added frames per second read out. Fixed some crashes.
This commit is contained in:
@@ -128,9 +128,11 @@ QVariant CANFrameModel::headerData(int section, Qt::Orientation orientation,
|
|||||||
|
|
||||||
void CANFrameModel::addFrame(CANFrame &frame, bool autoRefresh = false)
|
void CANFrameModel::addFrame(CANFrame &frame, bool autoRefresh = false)
|
||||||
{
|
{
|
||||||
|
mutex.lock();
|
||||||
if (autoRefresh) beginInsertRows(QModelIndex(), frames.count() + 1, frames.count() + 1);
|
if (autoRefresh) beginInsertRows(QModelIndex(), frames.count() + 1, frames.count() + 1);
|
||||||
frames.append(frame);
|
frames.append(frame);
|
||||||
if (autoRefresh) endInsertRows();
|
if (autoRefresh) endInsertRows();
|
||||||
|
mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CANFrameModel::sendRefresh()
|
void CANFrameModel::sendRefresh()
|
||||||
@@ -151,15 +153,23 @@ void CANFrameModel::sendRefresh(int pos)
|
|||||||
void CANFrameModel::sendBulkRefresh(int num)
|
void CANFrameModel::sendBulkRefresh(int num)
|
||||||
{
|
{
|
||||||
//qDebug() << "Bulk refresh of " << 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);
|
beginInsertRows(QModelIndex(), frames.count() - num, frames.count() - 1);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CANFrameModel::clearFrames()
|
void CANFrameModel::clearFrames()
|
||||||
{
|
{
|
||||||
|
mutex.lock();
|
||||||
this->beginResetModel();
|
this->beginResetModel();
|
||||||
frames.clear();
|
frames.clear();
|
||||||
this->endResetModel();
|
this->endResetModel();
|
||||||
|
mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Is this safe? Maybe not but if we don't change it then that's OK
|
//Is this safe? Maybe not but if we don't change it then that's OK
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
QVector<CANFrame> frames;
|
QVector<CANFrame> frames;
|
||||||
DBCHandler *dbcHandler;
|
DBCHandler *dbcHandler;
|
||||||
|
QMutex mutex;
|
||||||
bool interpretFrames; //should we use the dbcHandler?
|
bool interpretFrames; //should we use the dbcHandler?
|
||||||
bool overwriteDups; //should we display all frames or only the newest for each ID?
|
bool overwriteDups; //should we display all frames or only the newest for each ID?
|
||||||
};
|
};
|
||||||
|
|||||||
+9
-5
@@ -118,22 +118,25 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
ui->statusBar->addWidget(&lbStatusBauds);
|
ui->statusBar->addWidget(&lbStatusBauds);
|
||||||
ui->statusBar->addWidget(&lbStatusDatabase);
|
ui->statusBar->addWidget(&lbStatusDatabase);
|
||||||
|
|
||||||
|
ui->lbFPS->setText("0");
|
||||||
|
ui->lbNumFrames->setText("0");
|
||||||
|
|
||||||
isConnected = false;
|
isConnected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete ui;
|
serialWorkerThread.quit();
|
||||||
|
serialWorkerThread.wait();
|
||||||
|
|
||||||
if (graphingWindow) delete graphingWindow;
|
if (graphingWindow) delete graphingWindow;
|
||||||
if (frameInfoWindow) delete frameInfoWindow;
|
if (frameInfoWindow) delete frameInfoWindow;
|
||||||
if (playbackWindow) delete playbackWindow;
|
if (playbackWindow) delete playbackWindow;
|
||||||
if (flowViewWindow) delete flowViewWindow;
|
if (flowViewWindow) delete flowViewWindow;
|
||||||
if (frameSenderWindow) delete frameSenderWindow;
|
if (frameSenderWindow) delete frameSenderWindow;
|
||||||
|
|
||||||
|
delete ui;
|
||||||
delete dbcHandler;
|
delete dbcHandler;
|
||||||
|
|
||||||
serialWorkerThread.quit();
|
|
||||||
serialWorkerThread.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateBaudLabel(int baud0, int baud1)
|
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
|
//most of the work is handled elsewhere. Need only to update the # of frames
|
||||||
//and maybe auto scroll
|
//and maybe auto scroll
|
||||||
void MainWindow::gotFrames()
|
void MainWindow::gotFrames(int FPS)
|
||||||
{
|
{
|
||||||
ui->lbNumFrames->setText(QString::number(model->rowCount()));
|
ui->lbNumFrames->setText(QString::number(model->rowCount()));
|
||||||
if (ui->cbAutoScroll->isChecked()) ui->canFramesView->scrollToBottom();
|
if (ui->cbAutoScroll->isChecked()) ui->canFramesView->scrollToBottom();
|
||||||
|
ui->lbFPS->setText(QString::number(FPS));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::addFrameToDisplay(CANFrame &frame, bool autoRefresh = false)
|
void MainWindow::addFrameToDisplay(CANFrame &frame, bool autoRefresh = false)
|
||||||
|
|||||||
+2
-2
@@ -13,7 +13,7 @@
|
|||||||
#include "framesenderwindow.h"
|
#include "framesenderwindow.h"
|
||||||
#include "dbchandler.h"
|
#include "dbchandler.h"
|
||||||
|
|
||||||
#define VERSION 102
|
#define VERSION 103
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
@@ -46,7 +46,7 @@ private slots:
|
|||||||
void connectionSucceeded(int, int);
|
void connectionSucceeded(int, int);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void gotFrames();
|
void gotFrames(int);
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|||||||
+27
-1
@@ -151,7 +151,7 @@
|
|||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string># Of Frames:</string>
|
<string>Total Frames Captured:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@@ -168,6 +168,32 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
<item>
|
||||||
<widget class="QPushButton" name="btnClearFrames">
|
<widget class="QPushButton" name="btnClearFrames">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|||||||
+13
-4
@@ -13,6 +13,8 @@ SerialWorker::SerialWorker(CANFrameModel *model, QObject *parent) : QObject(pare
|
|||||||
canModel = model;
|
canModel = model;
|
||||||
gotFrames = 0;
|
gotFrames = 0;
|
||||||
ticker = NULL;
|
ticker = NULL;
|
||||||
|
elapsedTime = NULL;
|
||||||
|
framesPerSec = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SerialWorker::~SerialWorker()
|
SerialWorker::~SerialWorker()
|
||||||
@@ -69,6 +71,11 @@ void SerialWorker::setSerialPort(QSerialPortInfo *port)
|
|||||||
ticker = new QTimer;
|
ticker = new QTimer;
|
||||||
connect(ticker, SIGNAL(timeout()), this, SLOT(handleTick()));
|
connect(ticker, SIGNAL(timeout()), this, SLOT(handleTick()));
|
||||||
}
|
}
|
||||||
|
if (elapsedTime == NULL)
|
||||||
|
{
|
||||||
|
elapsedTime = new QTime;
|
||||||
|
elapsedTime->start();
|
||||||
|
}
|
||||||
ticker->setInterval(250); //tick four times per second
|
ticker->setInterval(250); //tick four times per second
|
||||||
ticker->setSingleShot(false); //keep ticking
|
ticker->setSingleShot(false); //keep ticking
|
||||||
ticker->start();
|
ticker->start();
|
||||||
@@ -341,12 +348,14 @@ void SerialWorker::procRXChar(unsigned char c)
|
|||||||
void SerialWorker::handleTick()
|
void SerialWorker::handleTick()
|
||||||
{
|
{
|
||||||
//qDebug() << "Tick!";
|
//qDebug() << "Tick!";
|
||||||
if (gotFrames > 0)
|
framesPerSec += gotFrames * 1000 / elapsedTime->elapsed() - (framesPerSec / 4);
|
||||||
{
|
elapsedTime->restart();
|
||||||
emit receivedFrames(); //notify interested parties that there are new frames
|
//if (gotFrames > 0)
|
||||||
|
//{
|
||||||
|
emit receivedFrames(framesPerSec / 4); //misnamed now. Just notifies of FPS and that frames might exist
|
||||||
canModel->sendBulkRefresh(gotFrames);
|
canModel->sendBulkRefresh(gotFrames);
|
||||||
gotFrames = 0;
|
gotFrames = 0;
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
//totally shuts down the whole thing
|
//totally shuts down the whole thing
|
||||||
|
|||||||
+4
-1
@@ -1,6 +1,7 @@
|
|||||||
#ifndef SERIALWORKER_H
|
#ifndef SERIALWORKER_H
|
||||||
#define SERIALWORKER_H
|
#define SERIALWORKER_H
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSerialPort>
|
#include <QSerialPort>
|
||||||
#include <QSerialPortInfo>
|
#include <QSerialPortInfo>
|
||||||
@@ -32,7 +33,7 @@ public:
|
|||||||
|
|
||||||
signals: //we emit signals
|
signals: //we emit signals
|
||||||
void error(const QString &);
|
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 connectionSuccess(int, int);
|
||||||
void connectionFailure();
|
void connectionFailure();
|
||||||
void deviceInfo(int, int);
|
void deviceInfo(int, int);
|
||||||
@@ -55,6 +56,8 @@ private:
|
|||||||
QSerialPort *serial;
|
QSerialPort *serial;
|
||||||
CANFrameModel *canModel;
|
CANFrameModel *canModel;
|
||||||
QTimer *ticker;
|
QTimer *ticker;
|
||||||
|
QTime *elapsedTime;
|
||||||
|
int framesPerSec;
|
||||||
int gotFrames;
|
int gotFrames;
|
||||||
STATE rx_state;
|
STATE rx_state;
|
||||||
int rx_step;
|
int rx_step;
|
||||||
|
|||||||
Reference in New Issue
Block a user