From fa5acf612b4da00329f38f69186f7adce5519226 Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Sun, 9 Aug 2015 19:34:19 -0400 Subject: [PATCH] Add progressbar to loading on main form, add ability to graph DBC defined signals, make graphing bias/scale work like DBC bias/scale to be consistent. --- config.h | 2 +- framefileio.cpp | 79 +++++++++++++ framefileio.h | 1 + graphingwindow.cpp | 15 ++- graphingwindow.h | 4 +- mainwindow.cpp | 15 ++- newgraphdialog.cpp | 71 +++++++++++- newgraphdialog.h | 8 +- newgraphdialog.ui | 270 ++++++++++++++++++++++++++++----------------- 9 files changed, 350 insertions(+), 115 deletions(-) diff --git a/config.h b/config.h index 53645e5..d0ee917 100644 --- a/config.h +++ b/config.h @@ -1,7 +1,7 @@ #ifndef CONFIG #define CONFIG -#define VERSION 129 +#define VERSION 130 //try to keep this in sync. //SavvyCAN will complain if you connect a GVRET board with a revision diff --git a/framefileio.cpp b/framefileio.cpp index 0b4c25d..b58adab 100644 --- a/framefileio.cpp +++ b/framefileio.cpp @@ -69,6 +69,7 @@ bool FrameFileIO::loadCRTDFile(QString filename, QVector* frames) QFile *inFile = new QFile(filename); CANFrame thisFrame; QByteArray line; + int lineCounter = 0; if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -79,6 +80,12 @@ bool FrameFileIO::loadCRTDFile(QString filename, QVector* frames) line = inFile->readLine(); //read out the header first and discard it. while (!inFile->atEnd()) { + lineCounter++; + if (lineCounter > 100) + { + qApp->processEvents(); + lineCounter = 0; + } line = inFile->readLine().simplified(); if (line.length() > 2) { @@ -124,6 +131,7 @@ bool FrameFileIO::loadCRTDFile(QString filename, QVector* frames) bool FrameFileIO::saveCRTDFile(QString filename, const QVector* frames) { QFile *outFile = new QFile(filename); + int lineCounter = 0; if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text)) { @@ -137,6 +145,13 @@ bool FrameFileIO::saveCRTDFile(QString filename, const QVector* frames for (int c = 0; c < frames->count(); c++) { + lineCounter++; + if (lineCounter > 100) + { + qApp->processEvents(); + lineCounter = 0; + } + outFile->write(QString::number(frames->at(c).timestamp / 1000000.0, 'f', 6).toUtf8()); outFile->putChar(' '); if (frames->at(c).extended) @@ -168,6 +183,7 @@ bool FrameFileIO::loadNativeCSVFile(QString filename, QVector* frames) CANFrame thisFrame; QByteArray line; long long timeStamp = Utility::GetTimeMS(); + int lineCounter = 0; if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -178,6 +194,13 @@ bool FrameFileIO::loadNativeCSVFile(QString filename, QVector* frames) line = inFile->readLine(); //read out the header first and discard it. while (!inFile->atEnd()) { + lineCounter++; + if (lineCounter > 100) + { + qApp->processEvents(); + lineCounter = 0; + } + line = inFile->readLine(); if (line.length() > 2) { @@ -212,6 +235,7 @@ bool FrameFileIO::loadNativeCSVFile(QString filename, QVector* frames) bool FrameFileIO::saveNativeCSVFile(QString filename, const QVector* frames) { QFile *outFile = new QFile(filename); + int lineCounter = 0; if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text)) { @@ -224,6 +248,13 @@ bool FrameFileIO::saveNativeCSVFile(QString filename, const QVector* f for (int c = 0; c < frames->count(); c++) { + lineCounter++; + if (lineCounter > 100) + { + qApp->processEvents(); + lineCounter = 0; + } + outFile->write(QString::number(frames->at(c).timestamp).toUtf8()); outFile->putChar(44); @@ -262,6 +293,7 @@ bool FrameFileIO::loadGenericCSVFile(QString filename, QVector* frames CANFrame thisFrame; QByteArray line; long long timeStamp = Utility::GetTimeMS(); + int lineCounter = 0; if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -272,6 +304,13 @@ bool FrameFileIO::loadGenericCSVFile(QString filename, QVector* frames line = inFile->readLine(); //read out the header first and discard it. while (!inFile->atEnd()) { + lineCounter++; + if (lineCounter > 100) + { + qApp->processEvents(); + lineCounter = 0; + } + line = inFile->readLine(); if (line.length() > 2) { @@ -300,6 +339,7 @@ bool FrameFileIO::loadGenericCSVFile(QString filename, QVector* frames bool FrameFileIO::saveGenericCSVFile(QString filename, const QVector* frames) { QFile *outFile = new QFile(filename); + int lineCounter = 0; if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text)) { @@ -312,6 +352,13 @@ bool FrameFileIO::saveGenericCSVFile(QString filename, const QVector* for (int c = 0; c < frames->count(); c++) { + lineCounter++; + if (lineCounter > 100) + { + qApp->processEvents(); + lineCounter = 0; + } + outFile->write(QString::number(frames->at(c).ID, 16).toUpper().rightJustified(8, '0').toUtf8()); outFile->putChar(44); @@ -367,6 +414,7 @@ bool FrameFileIO::loadLogFile(QString filename, QVector* frames) CANFrame thisFrame; QByteArray line; uint64_t timeStamp = Utility::GetTimeMS(); + int lineCounter = 0; if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -377,6 +425,13 @@ bool FrameFileIO::loadLogFile(QString filename, QVector* frames) line = inFile->readLine(); //read out the header first and discard it. while (!inFile->atEnd()) { + lineCounter++; + if (lineCounter > 100) + { + qApp->processEvents(); + lineCounter = 0; + } + line = inFile->readLine(); if (line.startsWith("***")) continue; if (line.length() > 1) @@ -404,6 +459,7 @@ bool FrameFileIO::saveLogFile(QString filename, const QVector* frames) { QFile *outFile = new QFile(filename); QDateTime timestamp, tempStamp; + int lineCounter = 0; timestamp = QDateTime::currentDateTime(); @@ -431,6 +487,13 @@ bool FrameFileIO::saveLogFile(QString filename, const QVector* frames) for (int c = 0; c < frames->count(); c++) { + lineCounter++; + if (lineCounter > 100) + { + qApp->processEvents(); + lineCounter = 0; + } + tempStamp = timestamp.addMSecs(frames->at(c).timestamp / 1000); outFile->write(tempStamp.toString("h:m:s:z").toUtf8()); outFile->write(" Rx "); @@ -470,6 +533,7 @@ bool FrameFileIO::loadMicrochipFile(QString filename, QVector* frames) QByteArray line; bool inComment = false; long long timeStamp = Utility::GetTimeMS(); + int lineCounter = 0; if (!inFile->open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -480,6 +544,13 @@ bool FrameFileIO::loadMicrochipFile(QString filename, QVector* frames) //line = inFile->readLine(); //read out the header first and discard it. while (!inFile->atEnd()) { + lineCounter++; + if (lineCounter > 100) + { + qApp->processEvents(); + lineCounter = 0; + } + line = inFile->readLine(); if (line.length() > 2) { @@ -526,6 +597,7 @@ bool FrameFileIO::saveMicrochipFile(QString filename, const QVector* f { QFile *outFile = new QFile(filename); QDateTime timestamp, tempStamp; + int lineCounter = 0; timestamp = QDateTime::currentDateTime(); @@ -546,6 +618,13 @@ bool FrameFileIO::saveMicrochipFile(QString filename, const QVector* f for (int c = 0; c < frames->count(); c++) { + lineCounter++; + if (lineCounter > 100) + { + qApp->processEvents(); + lineCounter = 0; + } + outFile->write(QString::number((int)(frames->at(c).timestamp / 1000)).toUtf8()); outFile->write(";RX;"); outFile->write("0x" + QString::number(frames->at(c).ID, 16).toUpper().rightJustified(8, '0').toUtf8() + ";"); diff --git a/framefileio.h b/framefileio.h index 0dac85e..0e86402 100644 --- a/framefileio.h +++ b/framefileio.h @@ -5,6 +5,7 @@ #include "config.h" #include +#include #include #include #include diff --git a/graphingwindow.cpp b/graphingwindow.cpp index 64dca96..2ef9460 100644 --- a/graphingwindow.cpp +++ b/graphingwindow.cpp @@ -4,7 +4,7 @@ #include "mainwindow.h" #include -GraphingWindow::GraphingWindow(const QVector *frames, QWidget *parent) : +GraphingWindow::GraphingWindow(DBCHandler *handler, const QVector *frames, QWidget *parent) : QDialog(parent), ui(new Ui::GraphingWindow) { @@ -13,6 +13,7 @@ GraphingWindow::GraphingWindow(const QVector *frames, QWidget *parent) readSettings(); modelFrames = frames; + dbcHandler = handler; ui->graphingView->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes | QCP::iSelectLegend | QCP::iSelectPlottables); @@ -479,7 +480,9 @@ void GraphingWindow::loadDefinitions() void GraphingWindow::showParamsDialog(int idx = -1) { - NewGraphDialog *thisDialog = new NewGraphDialog(); + NewGraphDialog *thisDialog = new NewGraphDialog(dbcHandler); + QString oldName; + if (idx > -1) oldName = graphParams[idx].graphName; if (idx > -1) thisDialog->setParams(graphParams[idx]); if (thisDialog->exec() == QDialog::Accepted) { @@ -491,6 +494,7 @@ void GraphingWindow::showParamsDialog(int idx = -1) //create a new graph with the returned parameters. GraphParams params; thisDialog->getParams(params); + params.graphName = oldName; createGraph(params); } delete thisDialog; @@ -540,12 +544,11 @@ void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam) { x[j] = frameCache[j].timestamp; } - y[j] = (tempVal + params.bias) * params.scale; + y[j] = (tempVal * params.scale) + params.bias; if (y[j] < yminval) yminval = y[j]; if (y[j] > ymaxval) ymaxval = y[j]; if (x[j] < xminval) xminval = x[j]; if (x[j] > xmaxval) xmaxval = x[j]; - } } else if (params.endByte > params.startByte) //big endian @@ -591,7 +594,7 @@ void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam) x[j] = frameCache[j].timestamp; } - y[j] = (tempValue + params.bias) * params.scale; + y[j] = (tempValue * params.scale) + params.bias; if (y[j] < yminval) yminval = y[j]; if (y[j] > ymaxval) ymaxval = y[j]; if (x[j] < xminval) xminval = x[j]; @@ -640,7 +643,7 @@ void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam) x[j] = frameCache[j].timestamp; } - y[j] = (tempValue + params.bias) * params.scale; + y[j] = (tempValue * params.scale) + params.bias; if (y[j] < yminval) yminval = y[j]; if (y[j] > ymaxval) ymaxval = y[j]; if (x[j] < xminval) xminval = x[j]; diff --git a/graphingwindow.h b/graphingwindow.h index bb0ddfd..f88e0b4 100644 --- a/graphingwindow.h +++ b/graphingwindow.h @@ -3,6 +3,7 @@ #include "qcustomplot.h" #include "can_structs.h" +#include "dbchandler.h" #include @@ -30,7 +31,7 @@ class GraphingWindow : public QDialog Q_OBJECT public: - explicit GraphingWindow(const QVector *, QWidget *parent = 0); + explicit GraphingWindow(DBCHandler *handler, const QVector *, QWidget *parent = 0); ~GraphingWindow(); void showEvent(QShowEvent*); @@ -55,6 +56,7 @@ private slots: private: Ui::GraphingWindow *ui; + DBCHandler *dbcHandler; QList frameCache; const QVector *modelFrames; QList graphParams; diff --git a/mainwindow.cpp b/mainwindow.cpp index 1e02481..b51ba38 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -443,11 +443,24 @@ void MainWindow::handleLoadFile() QVector tempFrames; + QProgressDialog progress(this); + progress.setWindowModality(Qt::WindowModal); + progress.setLabelText("Loading file..."); + progress.setCancelButton(0); + progress.setRange(0,0); + progress.setMinimumDuration(0); + progress.show(); + + qApp->processEvents(); + if (dialog.selectedNameFilter() == filters[0]) result = FrameFileIO::loadCRTDFile(filename, &tempFrames); if (dialog.selectedNameFilter() == filters[1]) result = FrameFileIO::loadNativeCSVFile(filename, &tempFrames); if (dialog.selectedNameFilter() == filters[2]) result = FrameFileIO::loadGenericCSVFile(filename, &tempFrames); if (dialog.selectedNameFilter() == filters[3]) result = FrameFileIO::loadLogFile(filename, &tempFrames); if (dialog.selectedNameFilter() == filters[4]) result = FrameFileIO::loadMicrochipFile(filename, &tempFrames); + + progress.cancel(); + if (result) { model->insertFrames(tempFrames); @@ -840,7 +853,7 @@ void MainWindow::showSettingsDialog() void MainWindow::showGraphingWindow() { if (!graphingWindow) { - graphingWindow = new GraphingWindow(model->getListReference()); + graphingWindow = new GraphingWindow(dbcHandler, model->getListReference()); } graphingWindow->show(); } diff --git a/newgraphdialog.cpp b/newgraphdialog.cpp index f5c371d..2888c3b 100644 --- a/newgraphdialog.cpp +++ b/newgraphdialog.cpp @@ -3,12 +3,14 @@ #include #include "utility.h" -NewGraphDialog::NewGraphDialog(QWidget *parent) : +NewGraphDialog::NewGraphDialog(DBCHandler *handler, QWidget *parent) : QDialog(parent), ui(new Ui::NewGraphDialog) { ui->setupUi(this); + dbcHandler = handler; + connect(ui->colorSwatch, SIGNAL(clicked(bool)), this, SLOT(colorSwatchClick())); connect(ui->btnAddGraph, SIGNAL(clicked(bool)), this, SLOT(addButtonClicked())); @@ -21,6 +23,10 @@ NewGraphDialog::NewGraphDialog(QWidget *parent) : p.setColor(QPalette::Button, QColor(qrand() % 160,qrand() % 160,qrand() % 160)); ui->colorSwatch->setPalette(p); + connect(ui->cbMessages, SIGNAL(currentIndexChanged(int)), this, SLOT(loadSignals(int))); + connect(ui->cbSignals, SIGNAL(currentIndexChanged(int)), this, SLOT(fillFormFromSignal(int))); + + loadMessages(); } NewGraphDialog::~NewGraphDialog() @@ -52,6 +58,8 @@ void NewGraphDialog::setParams(GraphParams ¶ms) ui->txtStride->setText(QString::number(params.stride)); ui->cbSigned->setChecked(params.isSigned); + graphName = params.graphName; + if (params.endByte > -1) { ui->txtData->setText(QString::number(params.startByte) + "-" + QString::number(params.endByte)); @@ -92,5 +100,66 @@ void NewGraphDialog::getParams(GraphParams ¶ms) if (params.mask == 0) params.mask = 0xFFFFFFFF; if (fabs(params.scale) < 0.00000001) params.scale = 1.0f; if (params.stride < 1) params.stride = 1; + params.graphName = graphName; +} +void NewGraphDialog::loadMessages() +{ + ui->cbMessages->clear(); + if (dbcHandler == NULL) return; + for (int x = 0; x < dbcHandler->dbc_messages.count(); x++) + { + ui->cbMessages->addItem(dbcHandler->dbc_messages[x].name); + } +} + +void NewGraphDialog::loadSignals(int idx) +{ + //messages were placed into the list in the same order as they exist + //in the data structure so it should have been possible to just + //look it up based on index but by name is probably safer and this operation + //is not time critical at all. + DBC_MESSAGE *msg = dbcHandler->findMsgByName(ui->cbMessages->currentText()); + + if (msg == NULL) return; + ui->cbSignals->clear(); + for (int x = 0; x < msg->msgSignals.count(); x++) + { + ui->cbSignals->addItem(msg->msgSignals[x].name); + } +} + +void NewGraphDialog::fillFormFromSignal(int idx) +{ + GraphParams params; + DBC_MESSAGE *msg = dbcHandler->findMsgByName(ui->cbMessages->currentText()); + + if (msg == NULL) return; + + DBC_SIGNAL *sig = dbcHandler->findSignalByName(msg, ui->cbSignals->currentText()); + + if (sig == NULL) return; + + params.graphName = sig->name; + params.ID = msg->ID; + params.bias = sig->bias; + params.scale = sig->factor; + params.stride = 1; + params.mask = (1 << (sig->signalSize)) - 1; + params.color = ui->colorSwatch->palette().color(QPalette::Button); + if (sig->intelByteOrder) + { + //for this ordering the byte order is reserved and starting byte + //will be the higher value + params.endByte = sig->startBit / 8; + params.startByte = (sig->startBit + sig->signalSize - 1) / 8; + } + else + { + //for this ordering it goes in normal numerical order + params.startByte = sig->startBit / 8; + params.endByte = (sig->startBit + sig->signalSize - 1) / 8; + } + + setParams(params); } diff --git a/newgraphdialog.h b/newgraphdialog.h index 54c88a2..8c6f537 100644 --- a/newgraphdialog.h +++ b/newgraphdialog.h @@ -3,6 +3,7 @@ #include #include "graphingwindow.h" +#include "dbchandler.h" namespace Ui { class NewGraphDialog; @@ -13,7 +14,7 @@ class NewGraphDialog : public QDialog Q_OBJECT public: - explicit NewGraphDialog(QWidget *parent = 0); + explicit NewGraphDialog(DBCHandler *handler, QWidget *parent = 0); ~NewGraphDialog(); void getParams(GraphParams &); void setParams(GraphParams &); @@ -21,9 +22,14 @@ public: private slots: void addButtonClicked(); void colorSwatchClick(); + void loadMessages(); + void loadSignals(int idx); + void fillFormFromSignal(int idx); private: Ui::NewGraphDialog *ui; + DBCHandler *dbcHandler; + QString graphName; }; #endif // NEWGRAPHDIALOG_H diff --git a/newgraphdialog.ui b/newgraphdialog.ui index 0fb3e37..fa0570c 100644 --- a/newgraphdialog.ui +++ b/newgraphdialog.ui @@ -6,7 +6,7 @@ 0 0 - 273 + 492 309 @@ -15,110 +15,172 @@ - - - - - ID: - - + + + + + + + ID: + + + + + + + + + + Data: + + + + + + + + + + Signed: + + + + + + + + + + + + + + QFrame::NoFrame + + + Mask: + + + + + + + + + + Bias: + + + + + + + + + + Scale + + + + + + + + + + Stride + + + + + + + + + + Color + + + + + + + true + + + CHANGE + + + true + + + + + + + Add this graph + + + + - - - - Data: - - - - - - - Signed: - - - - - - - QFrame::NoFrame - - - Mask: - - - - - - - Bias: - - - - - - - Scale - - - - - - - Stride - - - - - - - Color - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Add this graph - - - - - - - true - - - CHANGE - - - true - - + + + + + + + 0 + 0 + + + + Graph a DBC Signal: + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + Message: + + + Qt::AlignCenter + + + + + + + + + + + 0 + 0 + + + + Signal: + + + Qt::AlignCenter + + + + + + +