Skip to content

Commit

Permalink
Add a save function to ISO-TP decoder window
Browse files Browse the repository at this point in the history
  • Loading branch information
collin80 committed Aug 14, 2024
1 parent 1f5b16b commit 6d5bc49
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 6 deletions.
33 changes: 27 additions & 6 deletions bus_protocols/uds_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const unsigned char *>(msg.payload().constData());
int dataLen = msg.payload().count();
*result = true;
UDS_MESSAGE udsMsg;
udsMsg.bus = msg.bus;
udsMsg.setExtendedFrameFormat(msg.hasExtendedFrameFormat());
Expand All @@ -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
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions bus_protocols/uds_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class UDS_HANDLER : public QObject
QString getShortDesc(QVector<CODE_STRUCT> &codeVector, int code);
QString getLongDesc(QVector<CODE_STRUCT> &codeVector, int code);
QString getDetailedMessageAnalysis(const UDS_MESSAGE &msg);
UDS_MESSAGE tryISOtoUDS(ISOTP_MESSAGE msg, bool *result);

public slots:
void gotISOTPFrame(ISOTP_MESSAGE msg);
Expand Down
75 changes: 75 additions & 0 deletions re/isotp_interpreterwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ISOTP_InterpreterWindow::ISOTP_InterpreterWindow(const QVector<CANFrame> *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;
Expand Down Expand Up @@ -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<const unsigned char *>(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);
Expand Down
1 change: 1 addition & 0 deletions re/isotp_interpreterwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ private slots:
void showDetailView();
void updatedFrames(int);
void clearList();
void saveList();
void listFilterItemChanged(QListWidgetItem *item);
void filterAll();
void filterNone();
Expand Down
7 changes: 7 additions & 0 deletions ui/isotp_interpreterwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnSaveList">
<property name="text">
<string>Save List</string>
</property>
</widget>
</item>
</layout>
</item>
<item alignment="Qt::AlignLeft">
Expand Down

0 comments on commit 6d5bc49

Please sign in to comment.