From 6d5bc49cffa9785bbeeaf97081f014afc98f2b7d Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Tue, 13 Aug 2024 20:59:52 -0400 Subject: [PATCH] Add a save function to ISO-TP decoder window --- bus_protocols/uds_handler.cpp | 33 ++++++++++++--- bus_protocols/uds_handler.h | 1 + re/isotp_interpreterwindow.cpp | 75 ++++++++++++++++++++++++++++++++++ re/isotp_interpreterwindow.h | 1 + ui/isotp_interpreterwindow.ui | 7 ++++ 5 files changed, 111 insertions(+), 6 deletions(-) diff --git a/bus_protocols/uds_handler.cpp b/bus_protocols/uds_handler.cpp index 697f758b..f39b5bb6 100644 --- a/bus_protocols/uds_handler.cpp +++ b/bus_protocols/uds_handler.cpp @@ -182,11 +182,11 @@ UDS_HANDLER::~UDS_HANDLER() delete isoHandler; } -void UDS_HANDLER::gotISOTPFrame(ISOTP_MESSAGE msg) +UDS_MESSAGE UDS_HANDLER::tryISOtoUDS(ISOTP_MESSAGE msg, bool *result) { - qDebug() << "UDS handler got ISOTP frame"; const unsigned char *data = reinterpret_cast(msg.payload().constData()); int dataLen = msg.payload().count(); + *result = true; UDS_MESSAGE udsMsg; udsMsg.bus = msg.bus; udsMsg.setExtendedFrameFormat(msg.hasExtendedFrameFormat()); @@ -208,9 +208,17 @@ void UDS_HANDLER::gotISOTPFrame(ISOTP_MESSAGE msg) { udsMsg.service = data[1]; if (dataLen > 2) udsMsg.subFunc = data[2]; - else return; + else + { + *result = false; + return udsMsg; + }; } - else return; + else + { + *result = false; + return udsMsg; + }; udsMsg.payload().remove(0, 2); } else @@ -220,9 +228,22 @@ void UDS_HANDLER::gotISOTPFrame(ISOTP_MESSAGE msg) udsMsg.payload().remove(0, 1); } } - else return; + else + { + *result = false; + }; + return udsMsg; +} + +void UDS_HANDLER::gotISOTPFrame(ISOTP_MESSAGE msg) +{ + qDebug() << "UDS handler got ISOTP frame"; + UDS_MESSAGE udsMsg; + + bool result; + udsMsg = tryISOtoUDS(msg, &result); - emit newUDSMessage(udsMsg); + if (result) emit newUDSMessage(udsMsg); } void UDS_HANDLER::setFlowCtrl(bool state) diff --git a/bus_protocols/uds_handler.h b/bus_protocols/uds_handler.h index 5c5ea4f3..b1578ed5 100644 --- a/bus_protocols/uds_handler.h +++ b/bus_protocols/uds_handler.h @@ -105,6 +105,7 @@ class UDS_HANDLER : public QObject QString getShortDesc(QVector &codeVector, int code); QString getLongDesc(QVector &codeVector, int code); QString getDetailedMessageAnalysis(const UDS_MESSAGE &msg); + UDS_MESSAGE tryISOtoUDS(ISOTP_MESSAGE msg, bool *result); public slots: void gotISOTPFrame(ISOTP_MESSAGE msg); diff --git a/re/isotp_interpreterwindow.cpp b/re/isotp_interpreterwindow.cpp index 5f8bb10b..045d6080 100644 --- a/re/isotp_interpreterwindow.cpp +++ b/re/isotp_interpreterwindow.cpp @@ -31,6 +31,7 @@ ISOTP_InterpreterWindow::ISOTP_InterpreterWindow(const QVector *frames connect(ui->tableIsoFrames, &QTableWidget::itemSelectionChanged, this, &ISOTP_InterpreterWindow::showDetailView); connect(ui->btnClearList, &QPushButton::clicked, this, &ISOTP_InterpreterWindow::clearList); + connect(ui->btnSaveList, &QPushButton::clicked, this, &ISOTP_InterpreterWindow::saveList); connect(ui->cbUseExtendedAddressing, SIGNAL(toggled(bool)), this, SLOT(useExtendedAddressing(bool))); QStringList headers; @@ -172,6 +173,80 @@ void ISOTP_InterpreterWindow::clearList() //idFilters.clear(); } +/* + * A bit complicated as the list doesn't have the detailed analysis in it. Have to take each list entry + * and process it to get the details then save those details to the file as well. + */ +void ISOTP_InterpreterWindow::saveList() +{ + QString buildString; + QString filename; + QFileDialog dialog(this); + QSettings settings; + + QStringList filters; + filters.append(QString(tr("Text File (*.txt)"))); + + dialog.setFileMode(QFileDialog::AnyFile); + dialog.setNameFilters(filters); + dialog.setViewMode(QFileDialog::Detail); + dialog.setAcceptMode(QFileDialog::AcceptSave); + dialog.setDirectory(settings.value("FrameInfo/LoadSaveDirectory", dialog.directory().path()).toString()); + + if (dialog.exec() == QDialog::Accepted) + { + settings.setValue("FrameInfo/LoadSaveDirectory", dialog.directory().path()); + filename = dialog.selectedFiles()[0]; + if (!filename.contains('.')) filename += ".txt"; + if (dialog.selectedNameFilter() == filters[0]) + { + QFile *outFile = new QFile(filename); + + if (!outFile->open(QIODevice::WriteOnly | QIODevice::Text)) + { + delete outFile; + return; + } + + int rows = messages.count(); + for (int r = 0 ; r < rows; r++) + { + ISOTP_MESSAGE msg = messages.at(r); + const unsigned char *data = reinterpret_cast(msg.payload().constData()); + int dataLen = msg.payload().length(); + + if (msg.reportedLength != dataLen) + { + continue; + } + + buildString.append(QString::number(msg.timeStamp().microSeconds()) + " " + QString::number(msg.frameId(), 16) + " "); + + //buildString.append(tr("Raw Payload: ")); + + for (int i = 0; i < dataLen; i++) + { + buildString.append(Utility::formatNumber(data[i])); + buildString.append(" "); + } + buildString.append("\n\n"); + + UDS_MESSAGE udsMsg; + bool result; + udsMsg = udsDecoder->tryISOtoUDS(msg, &result); + if (result) + buildString.append(udsDecoder->getDetailedMessageAnalysis(udsMsg)); + buildString.append("\n*********************************************************\n"); + outFile->write(buildString.toUtf8()); + } + + outFile->close(); + delete outFile; + } + } +} + + void ISOTP_InterpreterWindow::useExtendedAddressing(bool checked) { decoder->setExtendedAddressing(checked); diff --git a/re/isotp_interpreterwindow.h b/re/isotp_interpreterwindow.h index 14167ded..3b3a6b21 100644 --- a/re/isotp_interpreterwindow.h +++ b/re/isotp_interpreterwindow.h @@ -26,6 +26,7 @@ private slots: void showDetailView(); void updatedFrames(int); void clearList(); + void saveList(); void listFilterItemChanged(QListWidgetItem *item); void filterAll(); void filterNone(); diff --git a/ui/isotp_interpreterwindow.ui b/ui/isotp_interpreterwindow.ui index ec1ed3ba..6f7f67db 100644 --- a/ui/isotp_interpreterwindow.ui +++ b/ui/isotp_interpreterwindow.ui @@ -40,6 +40,13 @@ + + + + Save List + + +