From c6c19b38aaec371a96b2c519786276f4d6e7ee8e Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Fri, 14 Oct 2022 16:25:03 -0500 Subject: [PATCH 1/3] for clint --- mainwindow.cpp | 159 +++++++++++++++++++++++++++++++++++++++++- mainwindow.h | 1 + re/graphingwindow.cpp | 4 +- 3 files changed, 161 insertions(+), 3 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index e84da30..bd69a8e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1006,11 +1006,168 @@ void MainWindow::handleSaveDecoded() { filename = dialog.selectedFiles()[0]; if (!filename.contains('.')) filename += ".txt"; - saveDecodedTextFile(filename); + //saveDecodedTextFile(filename); + saveDecodedTextFileAsColumns(filename); settings.setValue("FileIO/LoadSaveDirectory", dialog.directory().path()); } } +void MainWindow::saveDecodedTextFileAsColumns(QString filename) +{ + QFile *outFile = new QFile(filename); + const QVector *frames = model->getFilteredListReference(); + + const unsigned char *data; + int dataLen; + const CANFrame *frame; + + if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text)) + return; +/* +Time: 205.173000 ID: 0x20E Std Bus: 0 Len: 8 +Data Bytes: 88 10 00 13 BB 00 06 00 + SignalName Value +*/ + QList> msgsAndColumns; + int columnsAdded = 0; + int dataStartCol = 0; + + QString builderString; + //time + builderString += tr("Time") + ","; + dataStartCol++; + //id + builderString += tr("ID") + ","; + dataStartCol++; + //if (frame->hasExtendedFrameFormat()) builderString += tr(" Ext "); + //else builderString += tr(" Std "); + //bus + builderString += tr("Bus") + ","; + dataStartCol++; + //len + builderString += tr("DataLen") + ","; + dataStartCol++; + + columnsAdded = dataStartCol; + + //loop through all the frames and the message data therein + for (int c = 0; c < frames->count(); c++) + { + frame = &frames->at(c); + data = reinterpret_cast(frame->payload().constData()); + dataLen = frame->payload().count(); + + //add all column names + if (dbcHandler != nullptr) + { + DBC_MESSAGE *msg = dbcHandler->findMessage(*frame); + if (msg != nullptr) + { + bool found = false; + for (int j = 0; j < msg->sigHandler->getCount(); j++) + { + if(j==0) + { + for(int m=0; mID) + found = true; + } + if(found == false) + msgsAndColumns.append(QPair(msg->ID, columnsAdded)); + } + + if(found == false) + { + QString temp; + if (msg->sigHandler->findSignalByIdx(j)->processAsText(*frame, temp)) + { + builderString.append(msg->sigHandler->findSignalByIdx(j)->name); + builderString.append(","); + columnsAdded++; + } + } + } + } + } + } + + //add EOL + builderString += "\n"; + //write out the header row + outFile->write(builderString.toUtf8()); + + //builderString = tr("Data Bytes: "); + //for (int temp = 0; temp < dataLen; temp++) + //{ + // builderString += Utility::formatNumber(data[temp]) + " "; + //} + //builderString += "\n"; + //outFile->write(builderString.toUtf8()); + + int dataColumnsAdded = 0; + builderString = ""; + for (int c = 0; c < frames->count(); c++) + { + dataColumnsAdded = 0; + frame = &frames->at(c); + data = reinterpret_cast(frame->payload().constData()); + dataLen = frame->payload().count(); + + QString builderString; + builderString += QString::number((frame->timeStamp().microSeconds() / 1000000.0), 'f', 6) + ","; + dataColumnsAdded++; + //id + builderString += Utility::formatCANID(frame->frameId(), frame->hasExtendedFrameFormat()) + ","; + dataColumnsAdded++; + //if (frame->hasExtendedFrameFormat()) builderString += tr(" Ext "); + //else builderString += tr(" Std "); + //bus + builderString += QString::number(frame->bus) + ","; + dataColumnsAdded++; + //len + builderString += QString::number(dataLen) + ","; + dataColumnsAdded++; + + if (dbcHandler != nullptr) + { + DBC_MESSAGE *msg = dbcHandler->findMessage(*frame); + if (msg != nullptr) + { + for (int j = 0; j < msg->sigHandler->getCount(); j++) + { + if(j==0) + { + for(int i = 0; iID) + { + int startCol = msgsAndColumns[i].second; + while(dataColumnsAdded < startCol) + { + builderString += ","; + dataColumnsAdded++; + } + } + } + } + + QString temp; + if (msg->sigHandler->findSignalByIdx(j)->processAsText(*frame, temp, false)) + { + builderString.append(temp); + builderString.append(","); + dataColumnsAdded++; + } + } + } + builderString.append("\n"); + outFile->write(builderString.toUtf8()); + } + } + outFile->close(); +} + void MainWindow::saveDecodedTextFile(QString filename) { QFile *outFile = new QFile(filename); diff --git a/mainwindow.h b/mainwindow.h index 9967215..d4c716c 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -196,6 +196,7 @@ private: QString getSignalNameFromPosition(QPoint pos); uint32_t getMessageIDFromPosition(QPoint pos); void saveDecodedTextFile(QString); + void saveDecodedTextFileAsColumns(QString); void addFrameToDisplay(CANFrame &, bool); void updateFileStatus(); void closeEvent(QCloseEvent *event); diff --git a/re/graphingwindow.cpp b/re/graphingwindow.cpp index 44b10bc..30c67e9 100644 --- a/re/graphingwindow.cpp +++ b/re/graphingwindow.cpp @@ -136,7 +136,7 @@ void GraphingWindow::changeEvent(QEvent *event) } else { - setWindowOpacity(0.25); + //setWindowOpacity(0.25); // widget is now inactive qDebug() << "Hide"; } @@ -199,7 +199,7 @@ void GraphingWindow::updatedFrames(int numFrames) ui->graphingView->replot(); //now, redisplay them all } else //just got some new frames. See if they are relevant. - { + { if (numFrames > modelFrames->count()) return; for (int j = 0; j < graphParams.count(); j++) From ef762e5ae51591fe842192c2308dd876201bb2d6 Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Mon, 17 Oct 2022 10:33:13 -0500 Subject: [PATCH 2/3] Added menu items to export csv decoded data, still need wiring --- connections/socketcand.cpp | 4 ++-- mainwindow.cpp | 18 ++++++++++++++++-- mainwindow.h | 2 ++ ui/mainwindow.ui | 8 +++++++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/connections/socketcand.cpp b/connections/socketcand.cpp index a049d8c..d1c772c 100644 --- a/connections/socketcand.cpp +++ b/connections/socketcand.cpp @@ -326,8 +326,8 @@ QString SocketCANd::decodeFrames(QString data, int busNum) getQueue().queue(); } } - else - qDebug() << "can't get a frame, capture suspended"; + //else + // qDebug() << "can't get a frame, capture suspended"; //take out the data that we just processed and anything that is in front of it //this should keep broken frames from accumulating at in the data buffer diff --git a/mainwindow.cpp b/mainwindow.cpp index bd69a8e..9428090 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -988,6 +988,16 @@ void MainWindow::handleLoadFilters() } void MainWindow::handleSaveDecoded() +{ + handleSaveDecodedMethod(false); +} + +void MainWindow::handleSaveDecodedCsv() +{ + handleSaveDecodedMethod(true); +} + +void MainWindow::handleSaveDecodedMethod(bool csv) { QString filename; QFileDialog dialog(this); @@ -1006,8 +1016,12 @@ void MainWindow::handleSaveDecoded() { filename = dialog.selectedFiles()[0]; if (!filename.contains('.')) filename += ".txt"; - //saveDecodedTextFile(filename); - saveDecodedTextFileAsColumns(filename); + + if(csv) + saveDecodedTextFileAsColumns(filename); + else + saveDecodedTextFile(filename); + settings.setValue("FileIO/LoadSaveDirectory", dialog.directory().path()); } } diff --git a/mainwindow.h b/mainwindow.h index d4c716c..64b8cdf 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -91,6 +91,7 @@ private slots: void showDBCComparisonWindow(); void exitApp(); void handleSaveDecoded(); + void handleSaveDecodedCsv(); void connectionStatusUpdated(int conns); void gridClicked(QModelIndex); void gridDoubleClicked(QModelIndex); @@ -195,6 +196,7 @@ private: //private methods QString getSignalNameFromPosition(QPoint pos); uint32_t getMessageIDFromPosition(QPoint pos); + void handleSaveDecodedMethod(bool csv); void saveDecodedTextFile(QString); void saveDecodedTextFileAsColumns(QString); void addFrameToDisplay(CANFrame &, bool); diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 77e1b5a..0136c80 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -368,7 +368,7 @@ 0 0 800 - 22 + 21 @@ -415,6 +415,7 @@ + @@ -615,6 +616,11 @@ DBC Comparison + + + Save Decoded Frames CSV + + From 61f1113d7605d8b3b8892377d94cd5fd55839781 Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Mon, 17 Oct 2022 11:01:10 -0500 Subject: [PATCH 3/3] Added menu option to export decoded frames as CSV More standard way of looking at parsed data Handles multiple message types. Each message gets its own columns. With many message types there are a lot of blank cells but its easy to analyze. --- mainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/mainwindow.cpp b/mainwindow.cpp index 9428090..dde7691 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -119,6 +119,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->actionFuzzy_Scope, &QAction::triggered, this, &MainWindow::showFuzzyScopeWindow); connect(ui->actionRange_State_2, &QAction::triggered, this, &MainWindow::showRangeWindow); connect(ui->actionSave_Decoded_Frames, &QAction::triggered, this, &MainWindow::handleSaveDecoded); + connect(ui->actionSave_Decoded_Frames_CSV, &QAction::triggered, this, &MainWindow::handleSaveDecodedCsv); connect(ui->actionSingle_Multi_State_2, &QAction::triggered, this, &MainWindow::showSingleMultiWindow); connect(ui->actionFile_Comparison, &QAction::triggered, this, &MainWindow::showComparisonWindow); connect(ui->actionDBC_Comparison, &QAction::triggered, this, &MainWindow::showDBCComparisonWindow);