Many changes to improve UDS decoding.
This commit is contained in:
+178
-20
@@ -4,6 +4,33 @@
|
|||||||
#include "isotp_handler.h"
|
#include "isotp_handler.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
QVector<CODE_STRUCT> UDS_DIAG_CTRL_SUB = {
|
||||||
|
{1,"DFLT_SESS", "Default session"},
|
||||||
|
{2,"PROG_SESS", "Programming Session"},
|
||||||
|
{3,"EXT_SESS", "Extended Diagnostics Session"},
|
||||||
|
{4,"SAFETY_SESS", "Safety System Diagnostics Session"},
|
||||||
|
};
|
||||||
|
|
||||||
|
QVector<CODE_STRUCT> UDS_ECU_RESET_SUB = {
|
||||||
|
{1,"HARD_RESET", "Hard reset of ECU"},
|
||||||
|
{2,"KEYOFFON_RESET", "Simulated key off then on reset"},
|
||||||
|
{3,"SOFT_RESET", "Soft reset - leaving RAM intact"},
|
||||||
|
{4,"EN_POWERDOWN_RESET", "Enable sleep mode"},
|
||||||
|
{5,"DIS_POWERDOWN_RESET", "Disable sleep mode"},
|
||||||
|
};
|
||||||
|
|
||||||
|
QVector<CODE_STRUCT> UDS_COMM_CTRL_SUB = {
|
||||||
|
{0,"COMM_NORMAL", "Enable both Rx and Tx of normal messages"},
|
||||||
|
{1,"COMM_DIS_TX", "Enable reception of normal messages but don't Tx them"},
|
||||||
|
{3,"COMM_DIS_ALL", "Disable both Rx and Tx of non-diagnostics messages"},
|
||||||
|
};
|
||||||
|
|
||||||
|
QVector<CODE_STRUCT> UDS_ROUTINE_SUB = {
|
||||||
|
{1,"START_ROUTINE", "Start routine by given ID"},
|
||||||
|
{2,"STOP_ROUTINE", "Stop routine by given ID"},
|
||||||
|
{3,"GET_ROUTINE_RESULTS", "Get results from routine specified by ID"},
|
||||||
|
};
|
||||||
|
|
||||||
QVector<CODE_STRUCT> UDS_SERVICE_DESC = {
|
QVector<CODE_STRUCT> UDS_SERVICE_DESC = {
|
||||||
{1, "OBDII_SHOW_CURRENT", "OBDII - Show current data"},
|
{1, "OBDII_SHOW_CURRENT", "OBDII - Show current data"},
|
||||||
{2, "OBDII_SHOW_FREEZE", "OBDII - Show freeze data"},
|
{2, "OBDII_SHOW_FREEZE", "OBDII - Show freeze data"},
|
||||||
@@ -214,7 +241,7 @@ void UDS_HANDLER::sendUDSFrame(const UDS_MESSAGE &msg)
|
|||||||
QVector<unsigned char> data;
|
QVector<unsigned char> data;
|
||||||
if (msg.bus < 0) return;
|
if (msg.bus < 0) return;
|
||||||
if (msg.bus >= CANConManager::getInstance()->getNumBuses()) return;
|
if (msg.bus >= CANConManager::getInstance()->getNumBuses()) return;
|
||||||
if (msg.service < 0 || msg.service > 0xFF) return;
|
if (msg.service > 0xFF) return;
|
||||||
|
|
||||||
data.append(msg.service);
|
data.append(msg.service);
|
||||||
for (int b = msg.subFuncLen - 1; b >= 0; b--)
|
for (int b = msg.subFuncLen - 1; b >= 0; b--)
|
||||||
@@ -228,42 +255,173 @@ void UDS_HANDLER::sendUDSFrame(const UDS_MESSAGE &msg)
|
|||||||
qDebug() << "Sent UDS service: " << getServiceShortDesc(msg.service) << " on bus " << msg.bus;
|
qDebug() << "Sent UDS service: " << getServiceShortDesc(msg.service) << " on bus " << msg.bus;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString UDS_HANDLER::getServiceShortDesc(int service)
|
QString UDS_HANDLER::getShortDesc(QVector<CODE_STRUCT> &codeVector, int code)
|
||||||
{
|
{
|
||||||
foreach (CODE_STRUCT code, UDS_SERVICE_DESC)
|
foreach (CODE_STRUCT codeRec, codeVector)
|
||||||
{
|
{
|
||||||
if (code.code == service) return code.shortDesc;
|
if (codeRec.code == code) return codeRec.shortDesc;
|
||||||
if (code.code == (service + 0x40)) return code.shortDesc;
|
|
||||||
}
|
}
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString UDS_HANDLER::getLongDesc(QVector<CODE_STRUCT> &codeVector, int code)
|
||||||
|
{
|
||||||
|
foreach (CODE_STRUCT codeRec, codeVector)
|
||||||
|
{
|
||||||
|
if (codeRec.code == code) return codeRec.longDesc;
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString UDS_HANDLER::getServiceShortDesc(int service)
|
||||||
|
{
|
||||||
|
QString ret;
|
||||||
|
ret = getShortDesc(UDS_SERVICE_DESC, service);
|
||||||
|
if (ret.length() == 0)
|
||||||
|
ret = getShortDesc(UDS_SERVICE_DESC, service + 0x40);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
QString UDS_HANDLER::getServiceLongDesc(int service)
|
QString UDS_HANDLER::getServiceLongDesc(int service)
|
||||||
{
|
{
|
||||||
foreach (CODE_STRUCT code, UDS_SERVICE_DESC)
|
QString ret;
|
||||||
{
|
ret = getLongDesc(UDS_SERVICE_DESC, service);
|
||||||
if (code.code == service) return code.longDesc;
|
if (ret.length() == 0)
|
||||||
if (code.code == (service + 0x40)) return code.longDesc;
|
ret = getLongDesc(UDS_SERVICE_DESC, service + 0x40);
|
||||||
}
|
return ret;
|
||||||
return QString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString UDS_HANDLER::getNegativeResponseShort(int respCode)
|
QString UDS_HANDLER::getNegativeResponseShort(int respCode)
|
||||||
{
|
{
|
||||||
foreach (CODE_STRUCT code, UDS_NEG_RESPONSE)
|
QString ret;
|
||||||
{
|
ret = getShortDesc(UDS_NEG_RESPONSE, respCode);
|
||||||
if (code.code == respCode) return code.shortDesc;
|
return ret;
|
||||||
}
|
|
||||||
return QString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString UDS_HANDLER::getNegativeResponseLong(int respCode)
|
QString UDS_HANDLER::getNegativeResponseLong(int respCode)
|
||||||
{
|
{
|
||||||
foreach (CODE_STRUCT code, UDS_NEG_RESPONSE)
|
QString ret;
|
||||||
{
|
ret = getLongDesc(UDS_NEG_RESPONSE, respCode);
|
||||||
if (code.code == respCode) return code.longDesc;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function kind of breaks the hands off approach of the rest of the class. In here
|
||||||
|
* we dig deep into nitty gritty details of UDS and much more of this is hardcoded
|
||||||
|
* to the UDS standard than the rest of the code where the code doesn't really know anything
|
||||||
|
* about what it is doing - it just reads arrays and such.
|
||||||
|
* No, in here we end up with hard coded handlers to figure out each type of message and how to
|
||||||
|
* interpret it to a fine level of detail. Look away code purists, this is likely to be a mess.
|
||||||
|
* The output here is potentially multi-line and is useful for debugging a UDS problem. You'll
|
||||||
|
* get a finely detailed dump of exactly what the message means.
|
||||||
|
*/
|
||||||
|
QString UDS_HANDLER::getDetailedMessageAnalysis(const UDS_MESSAGE &msg)
|
||||||
|
{
|
||||||
|
QString buildString;
|
||||||
|
bool isResponse = true;
|
||||||
|
|
||||||
|
if (msg.service < 0x3F || (msg.service > 0x7F && msg.service < 0xAF)) {
|
||||||
|
isResponse = false;
|
||||||
|
buildString.append("UDS Request\n");
|
||||||
|
buildString.append("Service: " + getServiceLongDesc(msg.service) + "\n");
|
||||||
}
|
}
|
||||||
return QString();
|
else
|
||||||
|
{
|
||||||
|
isResponse = true;
|
||||||
|
buildString.append("UDS Response\n");
|
||||||
|
buildString.append("Service: " + getServiceLongDesc(msg.service - 0x40) + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.isErrorReply)
|
||||||
|
{
|
||||||
|
//Negative responses replace the sub function with an error code instead
|
||||||
|
buildString.append("Negative response: " + getLongDesc(UDS_NEG_RESPONSE, msg.subFunc) + "\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (msg.service)
|
||||||
|
{
|
||||||
|
case UDS_SERVICES::DIAG_CONTROL:
|
||||||
|
//diag control requests have one parameter - which type of session we want.
|
||||||
|
buildString.append("Session Request: " + getLongDesc(UDS_DIAG_CTRL_SUB, msg.subFunc));
|
||||||
|
break;
|
||||||
|
case UDS_SERVICES::DIAG_CONTROL + 0x40: //positive response
|
||||||
|
buildString.append("Session Request: " + getLongDesc(UDS_DIAG_CTRL_SUB, msg.subFunc));
|
||||||
|
//there should be four extra bytes now
|
||||||
|
if (msg.data.length() < 4)
|
||||||
|
{
|
||||||
|
//buildString.append("\nReturned data payload wasn't at least \n4 bytes like it should have been");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int p2 = msg.data[0] * 256 + msg.data[1];
|
||||||
|
buildString.append("\nP2MAX: " + QString::number(p2));
|
||||||
|
p2 = msg.data[2] * 256 + msg.data[3];
|
||||||
|
buildString.append("\nP2*MAX: " + QString::number(p2));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case UDS_SERVICES::ECU_RESET:
|
||||||
|
//ECU reset has one parameter - which reset type to ask for
|
||||||
|
buildString.append("Reset Type: " + getLongDesc(UDS_ECU_RESET_SUB, msg.subFunc));
|
||||||
|
break;
|
||||||
|
case UDS_SERVICES::ECU_RESET + 0x40:
|
||||||
|
buildString.append("Reset Type: " + getLongDesc(UDS_ECU_RESET_SUB, msg.subFunc));
|
||||||
|
//There should be one additional byte which encodes power down time
|
||||||
|
if (msg.data.length() > 0)
|
||||||
|
{
|
||||||
|
if (msg.data[0] < 0xFF)
|
||||||
|
{
|
||||||
|
buildString.append("\nMinimum powered down time: " + QString::number(msg.data[0]));
|
||||||
|
}
|
||||||
|
else buildString.append("\nPowerdown time not available");
|
||||||
|
}
|
||||||
|
else buildString.append("\nNo powerdown time returned");
|
||||||
|
break;
|
||||||
|
case UDS_SERVICES::COMM_CTRL:
|
||||||
|
//Comm control has two parameters, sub funct and the next byte should be 1. But it's always one so ignore for now
|
||||||
|
buildString.append("Comm type: " + getLongDesc(UDS_COMM_CTRL_SUB, msg.subFunc));
|
||||||
|
break;
|
||||||
|
case UDS_SERVICES::SECURITY_ACCESS:
|
||||||
|
if ((msg.subFunc % 2) == 1)
|
||||||
|
{
|
||||||
|
buildString.append("Seed request for security level: " + QString::number(msg.subFunc) + "\n");
|
||||||
|
if (msg.data.length()> 0)
|
||||||
|
{
|
||||||
|
buildString.append("Data payload: ");
|
||||||
|
for (int j = 0; j < msg.data.length(); j++) buildString.append(Utility::formatHexNum(msg.data[j]) + " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buildString.append("Key sending for security level: " + QString::number(msg.subFunc - 1));
|
||||||
|
if (msg.data.length()> 0) //and it sure as hell should be!
|
||||||
|
{
|
||||||
|
buildString.append("KEY: ");
|
||||||
|
for (int j = 0; j < msg.data.length(); j++) buildString.append(Utility::formatHexNum(msg.data[j]) + " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case UDS_SERVICES::SECURITY_ACCESS + 0x40:
|
||||||
|
if ((msg.subFunc % 2) == 1)
|
||||||
|
{
|
||||||
|
buildString.append("Seed response for security level: " + QString::number(msg.subFunc) + "\n");
|
||||||
|
if (msg.data.length()> 0) //be kinda pointless if it weren't
|
||||||
|
{
|
||||||
|
buildString.append("SEED: ");
|
||||||
|
for (int j = 0; j < msg.data.length(); j++) buildString.append(Utility::formatHexNum(msg.data[j]) + " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buildString.append("Positive response to key for security level: " + QString::number(msg.subFunc - 1));
|
||||||
|
buildString.append("\nECU is now unlocked");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//qDebug() << buildString;
|
||||||
|
return buildString;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Little shim functions that drop straight through to the ISO_TP handler
|
//Little shim functions that drop straight through to the ISO_TP handler
|
||||||
|
|||||||
@@ -102,6 +102,9 @@ public:
|
|||||||
QString getServiceLongDesc(int service);
|
QString getServiceLongDesc(int service);
|
||||||
QString getNegativeResponseShort(int respCode);
|
QString getNegativeResponseShort(int respCode);
|
||||||
QString getNegativeResponseLong(int respCode);
|
QString getNegativeResponseLong(int respCode);
|
||||||
|
QString getShortDesc(QVector<CODE_STRUCT> &codeVector, int code);
|
||||||
|
QString getLongDesc(QVector<CODE_STRUCT> &codeVector, int code);
|
||||||
|
QString getDetailedMessageAnalysis(const UDS_MESSAGE &msg);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void gotISOTPFrame(ISOTP_MESSAGE msg);
|
void gotISOTPFrame(ISOTP_MESSAGE msg);
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
uint32_t ID;
|
uint32_t ID;
|
||||||
uint32_t mask;
|
uint32_t mask;
|
||||||
uint32_t bus;
|
int bus;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CANFILTER_H
|
#endif // CANFILTER_H
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ ISOTP_InterpreterWindow::ISOTP_InterpreterWindow(const QVector<CANFrame> *frames
|
|||||||
connect(udsDecoder, &UDS_HANDLER::newUDSMessage, this, &ISOTP_InterpreterWindow::newUDSMessage);
|
connect(udsDecoder, &UDS_HANDLER::newUDSMessage, this, &ISOTP_InterpreterWindow::newUDSMessage);
|
||||||
|
|
||||||
connect(ui->tableIsoFrames, &QTableWidget::itemSelectionChanged, this, &ISOTP_InterpreterWindow::showDetailView);
|
connect(ui->tableIsoFrames, &QTableWidget::itemSelectionChanged, this, &ISOTP_InterpreterWindow::showDetailView);
|
||||||
connect(ui->btnClearList, &QAbstractButton::click, this, &ISOTP_InterpreterWindow::clearList);
|
connect(ui->btnClearList, &QPushButton::clicked, this, &ISOTP_InterpreterWindow::clearList);
|
||||||
|
|
||||||
QStringList headers;
|
QStringList headers;
|
||||||
headers << "Timestamp" << "ID" << "Bus" << "Dir" << "Length" << "Data";
|
headers << "Timestamp" << "ID" << "Bus" << "Dir" << "Length" << "Data";
|
||||||
@@ -85,7 +85,9 @@ void ISOTP_InterpreterWindow::writeSettings()
|
|||||||
|
|
||||||
void ISOTP_InterpreterWindow::clearList()
|
void ISOTP_InterpreterWindow::clearList()
|
||||||
{
|
{
|
||||||
ui->tableIsoFrames->clear();
|
qDebug() << "Clearing the table";
|
||||||
|
while (ui->tableIsoFrames->rowCount() > 0)
|
||||||
|
ui->tableIsoFrames->removeRow(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ISOTP_InterpreterWindow::updatedFrames(int numFrames)
|
void ISOTP_InterpreterWindow::updatedFrames(int numFrames)
|
||||||
@@ -144,6 +146,7 @@ void ISOTP_InterpreterWindow::newUDSMessage(UDS_MESSAGE msg)
|
|||||||
|
|
||||||
buildText = ui->txtFrameDetails->toPlainText();
|
buildText = ui->txtFrameDetails->toPlainText();
|
||||||
|
|
||||||
|
/*
|
||||||
buildText.append("UDS Message:\n");
|
buildText.append("UDS Message:\n");
|
||||||
if (msg.isErrorReply)
|
if (msg.isErrorReply)
|
||||||
{
|
{
|
||||||
@@ -156,7 +159,10 @@ void ISOTP_InterpreterWindow::newUDSMessage(UDS_MESSAGE msg)
|
|||||||
buildText.append("Request for service " + udsDecoder->getServiceShortDesc(msg.service) + " Sub Func: " + QString::number(msg.subFunc));
|
buildText.append("Request for service " + udsDecoder->getServiceShortDesc(msg.service) + " Sub Func: " + QString::number(msg.subFunc));
|
||||||
else
|
else
|
||||||
buildText.append("Response on service " + udsDecoder->getServiceShortDesc(msg.service - 0x40) + " Sub Func: " + QString::number(msg.subFunc));
|
buildText.append("Response on service " + udsDecoder->getServiceShortDesc(msg.service - 0x40) + " Sub Func: " + QString::number(msg.subFunc));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
//Much more detailed analysis than the code above. You'll like it.
|
||||||
|
buildText.append(udsDecoder->getDetailedMessageAnalysis(msg));
|
||||||
|
|
||||||
ui->txtFrameDetails->setPlainText(buildText);
|
ui->txtFrameDetails->setPlainText(buildText);
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-6
@@ -97,6 +97,7 @@ void UDSScanWindow::readByToggled()
|
|||||||
void UDSScanWindow::numBytesChanged()
|
void UDSScanWindow::numBytesChanged()
|
||||||
{
|
{
|
||||||
uint64_t upperBound = (1 << (8 * ui->spinNumBytes->value())) - 1;
|
uint64_t upperBound = (1 << (8 * ui->spinNumBytes->value())) - 1;
|
||||||
|
if (upperBound > 0x7FFFFFFF) upperBound = 0x7FFFFFFF;
|
||||||
ui->spinUpperSubfunc->setMaximum(upperBound);
|
ui->spinUpperSubfunc->setMaximum(upperBound);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,16 +233,22 @@ void UDSScanWindow::scanUDS()
|
|||||||
|
|
||||||
if (ui->ckReset->isChecked()) //try to command a reset of the ECU. You're likely to know if it works. ;)
|
if (ui->ckReset->isChecked()) //try to command a reset of the ECU. You're likely to know if it works. ;)
|
||||||
{
|
{
|
||||||
test.service = UDS_SERVICES::ECU_RESET;
|
for (typ = 1; typ < 4; typ++) //try each type of session access
|
||||||
test.subFunc = 1;
|
{
|
||||||
sendOnBuses(test, buses);
|
test.service = UDS_SERVICES::ECU_RESET;
|
||||||
|
test.subFunc = typ;
|
||||||
|
sendOnBuses(test, buses);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ui->ckSecurity->isChecked()) //try to enter security mode - very likely to get a response if an ECU exists.
|
if (ui->ckSecurity->isChecked()) //try to enter security mode - very likely to get a response if an ECU exists.
|
||||||
{
|
{
|
||||||
test.service = UDS_SERVICES::SECURITY_ACCESS;
|
for (typ = 1; typ < 0x42; typ = typ + 2) //try each type of session access. In practice only the first 1-3 are likely to work
|
||||||
test.subFunc = 1;
|
{
|
||||||
sendOnBuses(test, buses);
|
test.service = UDS_SERVICES::SECURITY_ACCESS;
|
||||||
|
test.subFunc = typ;
|
||||||
|
sendOnBuses(test, buses);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ui->ckReadByAddr->isChecked())
|
if (ui->ckReadByAddr->isChecked())
|
||||||
|
|||||||
+1
-1
@@ -160,7 +160,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_7">
|
<widget class="QLabel" name="label_7">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Maximum reply delay</string>
|
<string>Maximum reply delay (ms)</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user