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:
+7
-2
@@ -6,7 +6,12 @@
|
|||||||
int CANFrameModel::rowCount(const QModelIndex &parent) const
|
int CANFrameModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
Q_UNUSED(parent);
|
||||||
return filteredFrames.count();
|
if (filteredFrames.data()) return filteredFrames.count();
|
||||||
|
|
||||||
|
//just in case somehow data is invalid which I have seen before.
|
||||||
|
//But, this should not happen so issue a debugging message too
|
||||||
|
qDebug() << "Invalid data for filteredFrames. Returning 0.";
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CANFrameModel::totalFrameCount()
|
int CANFrameModel::totalFrameCount()
|
||||||
@@ -341,7 +346,7 @@ void CANFrameModel::sendRefresh()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
filteredFrames.clear();
|
filteredFrames.clear();
|
||||||
filteredFrames = tempContainer;
|
filteredFrames.append(tempContainer);
|
||||||
lastUpdateNumFrames = filteredFrames.count();
|
lastUpdateNumFrames = filteredFrames.count();
|
||||||
endResetModel();
|
endResetModel();
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
|
|||||||
+27
-7
@@ -69,7 +69,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
connect(&serialWorkerThread, &QThread::finished, worker, &QObject::deleteLater);
|
connect(&serialWorkerThread, &QThread::finished, worker, &QObject::deleteLater);
|
||||||
connect(&serialWorkerThread, &QThread::started, worker, &SerialWorker::run); //setup timers within the proper thread
|
connect(&serialWorkerThread, &QThread::started, worker, &SerialWorker::run); //setup timers within the proper thread
|
||||||
connect(this, &MainWindow::sendSerialPort, worker, &SerialWorker::setSerialPort, Qt::QueuedConnection);
|
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::updateBaudRates, worker, &SerialWorker::updateBaudRates, Qt::QueuedConnection);
|
||||||
connect(this, &MainWindow::sendCANFrame, worker, &SerialWorker::sendFrame, Qt::QueuedConnection);
|
connect(this, &MainWindow::sendCANFrame, worker, &SerialWorker::sendFrame, Qt::QueuedConnection);
|
||||||
connect(worker, &SerialWorker::connectionSuccess, this, &MainWindow::connectionSucceeded, Qt::QueuedConnection);
|
connect(worker, &SerialWorker::connectionSuccess, this, &MainWindow::connectionSucceeded, Qt::QueuedConnection);
|
||||||
@@ -101,6 +101,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
dbcHandler = new DBCHandler;
|
dbcHandler = new DBCHandler;
|
||||||
bDirty = false;
|
bDirty = false;
|
||||||
inhibitFilterUpdate = false;
|
inhibitFilterUpdate = false;
|
||||||
|
rxFrames = 0;
|
||||||
|
|
||||||
model->setDBCHandler(dbcHandler);
|
model->setDBCHandler(dbcHandler);
|
||||||
|
|
||||||
@@ -150,6 +151,13 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
ui->lbFPS->setText("0");
|
ui->lbFPS->setText("0");
|
||||||
ui->lbNumFrames->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;
|
isConnected = false;
|
||||||
allowCapture = true;
|
allowCapture = true;
|
||||||
|
|
||||||
@@ -266,6 +274,8 @@ MainWindow::~MainWindow()
|
|||||||
delete udsScanWindow;
|
delete udsScanWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete elapsedTime;
|
||||||
|
|
||||||
delete ui;
|
delete ui;
|
||||||
delete dbcHandler;
|
delete dbcHandler;
|
||||||
model->clearFrames();
|
model->clearFrames();
|
||||||
@@ -493,20 +503,30 @@ void MainWindow::filterClearAll()
|
|||||||
model->setAllFilters(false);
|
model->setAllFilters(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
//most of the work is handled elsewhere. Need only to update the # of frames
|
void MainWindow::tickGUIUpdate()
|
||||||
//and maybe auto scroll
|
|
||||||
void MainWindow::gotFrames(int FPS, int framesSinceLastUpdate)
|
|
||||||
{
|
{
|
||||||
|
framesPerSec += rxFrames * 1000 / elapsedTime->elapsed() - (framesPerSec / 4);
|
||||||
|
elapsedTime->restart();
|
||||||
|
model->sendBulkRefresh(rxFrames);
|
||||||
|
|
||||||
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));
|
ui->lbFPS->setText(QString::number(framesPerSec / 4));
|
||||||
if (framesSinceLastUpdate > 0)
|
if (rxFrames > 0)
|
||||||
{
|
{
|
||||||
bDirty = true;
|
bDirty = true;
|
||||||
emit framesUpdated(framesSinceLastUpdate); //anyone care that frames were updated?
|
emit framesUpdated(rxFrames); //anyone care that frames were updated?
|
||||||
}
|
}
|
||||||
|
|
||||||
if (model->needsFilterRefresh()) updateFilterList();
|
if (model->needsFilterRefresh()) updateFilterList();
|
||||||
|
|
||||||
|
rxFrames = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::gotFrames(int framesSinceLastUpdate)
|
||||||
|
{
|
||||||
|
rxFrames += framesSinceLastUpdate;
|
||||||
|
emit frameUpdateRapid(framesSinceLastUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::addFrameToDisplay(CANFrame &frame, bool autoRefresh = false)
|
void MainWindow::addFrameToDisplay(CANFrame &frame, bool autoRefresh = false)
|
||||||
|
|||||||
+7
-1
@@ -75,6 +75,7 @@ private slots:
|
|||||||
void gridDoubleClicked(QModelIndex);
|
void gridDoubleClicked(QModelIndex);
|
||||||
void interpretToggled(bool);
|
void interpretToggled(bool);
|
||||||
void overwriteToggled(bool);
|
void overwriteToggled(bool);
|
||||||
|
void tickGUIUpdate();
|
||||||
void toggleCapture();
|
void toggleCapture();
|
||||||
void normalizeTiming();
|
void normalizeTiming();
|
||||||
void updateFilterList();
|
void updateFilterList();
|
||||||
@@ -83,7 +84,7 @@ private slots:
|
|||||||
void filterClearAll();
|
void filterClearAll();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void gotFrames(int, int);
|
void gotFrames(int);
|
||||||
void updateSettings();
|
void updateSettings();
|
||||||
void gotCenterTimeID(int32_t ID, double timestamp);
|
void gotCenterTimeID(int32_t ID, double timestamp);
|
||||||
void updateConnectionSettings(QString connectionType, QString port, int speed0, int speed1);
|
void updateConnectionSettings(QString connectionType, QString port, int speed0, int speed1);
|
||||||
@@ -98,6 +99,7 @@ signals:
|
|||||||
|
|
||||||
//-1 = frames cleared, -2 = a new file has been loaded (so all frames are different), otherwise # of new frames
|
//-1 = frames cleared, -2 = a new file has been loaded (so all frames are different), otherwise # of new frames
|
||||||
void framesUpdated(int numFrames); //something has updated the frame list
|
void framesUpdated(int numFrames); //something has updated the frame list
|
||||||
|
void frameUpdateRapid(int numFrames);
|
||||||
void settingsUpdated();
|
void settingsUpdated();
|
||||||
void sendCenterTimeID(int32_t ID, double timestamp);
|
void sendCenterTimeID(int32_t ID, double timestamp);
|
||||||
|
|
||||||
@@ -111,6 +113,10 @@ private:
|
|||||||
QThread serialWorkerThread;
|
QThread serialWorkerThread;
|
||||||
SerialWorker *worker;
|
SerialWorker *worker;
|
||||||
QByteArray inputBuffer;
|
QByteArray inputBuffer;
|
||||||
|
QTimer updateTimer;
|
||||||
|
QTime *elapsedTime;
|
||||||
|
int framesPerSec;
|
||||||
|
int rxFrames;
|
||||||
bool inhibitFilterUpdate;
|
bool inhibitFilterUpdate;
|
||||||
bool useHex;
|
bool useHex;
|
||||||
bool allowCapture;
|
bool allowCapture;
|
||||||
|
|||||||
+8
-13
@@ -12,10 +12,8 @@ SerialWorker::SerialWorker(CANFrameModel *model, QObject *parent) : QObject(pare
|
|||||||
rx_step = 0;
|
rx_step = 0;
|
||||||
buildFrame = new CANFrame;
|
buildFrame = new CANFrame;
|
||||||
canModel = model;
|
canModel = model;
|
||||||
gotFrames = 0;
|
|
||||||
ticker = NULL;
|
ticker = NULL;
|
||||||
elapsedTime = NULL;
|
framesRapid = 0;
|
||||||
framesPerSec = 0;
|
|
||||||
capturing = true;
|
capturing = true;
|
||||||
gotValidated = true;
|
gotValidated = true;
|
||||||
isAutoRestart = false;
|
isAutoRestart = false;
|
||||||
@@ -45,9 +43,6 @@ void SerialWorker::run()
|
|||||||
ticker = new QTimer;
|
ticker = new QTimer;
|
||||||
connect(ticker, SIGNAL(timeout()), this, SLOT(handleTick()));
|
connect(ticker, SIGNAL(timeout()), this, SLOT(handleTick()));
|
||||||
|
|
||||||
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();
|
||||||
@@ -148,6 +143,11 @@ void SerialWorker::readSerialData()
|
|||||||
c = data.at(i);
|
c = data.at(i);
|
||||||
procRXChar(c);
|
procRXChar(c);
|
||||||
}
|
}
|
||||||
|
if (framesRapid > 0)
|
||||||
|
{
|
||||||
|
emit frameUpdateRapid(framesRapid);
|
||||||
|
framesRapid = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialWorker::sendFrame(const CANFrame *frame, int bus = 0)
|
void SerialWorker::sendFrame(const CANFrame *frame, int bus = 0)
|
||||||
@@ -162,7 +162,7 @@ void SerialWorker::sendFrame(const CANFrame *frame, int bus = 0)
|
|||||||
|
|
||||||
//show our sent frames in the list too. This happens even if we're not connected.
|
//show our sent frames in the list too. This happens even if we're not connected.
|
||||||
canModel->addFrame(tempFrame, false);
|
canModel->addFrame(tempFrame, false);
|
||||||
gotFrames++;
|
framesRapid++;
|
||||||
|
|
||||||
if (serial == NULL) return;
|
if (serial == NULL) return;
|
||||||
if (!serial->isOpen()) return;
|
if (!serial->isOpen()) return;
|
||||||
@@ -316,7 +316,7 @@ void SerialWorker::procRXChar(unsigned char c)
|
|||||||
{
|
{
|
||||||
buildFrame->isReceived = true;
|
buildFrame->isReceived = true;
|
||||||
canModel->addFrame(*buildFrame, false);
|
canModel->addFrame(*buildFrame, false);
|
||||||
gotFrames++;
|
framesRapid++;
|
||||||
if (buildFrame->ID == targetID) emit gotTargettedFrame(canModel->rowCount() - 1);
|
if (buildFrame->ID == targetID) emit gotTargettedFrame(canModel->rowCount() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -447,11 +447,6 @@ void SerialWorker::handleTick()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
framesPerSec += gotFrames * 1000 / elapsedTime->elapsed() - (framesPerSec / 4);
|
|
||||||
elapsedTime->restart();
|
|
||||||
emit frameUpdateTick(framesPerSec / 4, gotFrames); //sends stats to interested parties
|
|
||||||
canModel->sendBulkRefresh(gotFrames);
|
|
||||||
gotFrames = 0;
|
|
||||||
if (doValidation && serial && serial->isOpen()) sendCommValidation();
|
if (doValidation && serial && serial->isOpen()) sendCommValidation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -41,7 +41,7 @@ public:
|
|||||||
|
|
||||||
signals: //we emit signals
|
signals: //we emit signals
|
||||||
void error(const QString &);
|
void error(const QString &);
|
||||||
void frameUpdateTick(int, int); //update interested parties about the # of frames that have come in
|
void frameUpdateRapid(int); //sent *much* more rapidly than the above signal - one param for # of frames
|
||||||
void connectionSuccess(int, int);
|
void connectionSuccess(int, int);
|
||||||
void connectionFailure();
|
void connectionFailure();
|
||||||
void deviceInfo(int, int);
|
void deviceInfo(int, int);
|
||||||
@@ -75,10 +75,8 @@ private:
|
|||||||
QSerialPortInfo *currentPort;
|
QSerialPortInfo *currentPort;
|
||||||
CANFrameModel *canModel;
|
CANFrameModel *canModel;
|
||||||
QTimer *ticker;
|
QTimer *ticker;
|
||||||
QTime *elapsedTime;
|
|
||||||
QMutex sendBulkMutex;
|
QMutex sendBulkMutex;
|
||||||
int framesPerSec;
|
int framesRapid;
|
||||||
int gotFrames;
|
|
||||||
int targetID;
|
int targetID;
|
||||||
STATE rx_state;
|
STATE rx_state;
|
||||||
int rx_step;
|
int rx_step;
|
||||||
|
|||||||
Reference in New Issue
Block a user