More implementation of UDS code, bug fixes to UDS, addition of
progress bar for UDS
This commit is contained in:
@@ -122,6 +122,15 @@ QVector<CODE_STRUCT> UDS_NEG_RESPONSE =
|
|||||||
{0x93, "VOLTAGE_LOW", "Cannot execute request until voltage is higher"},
|
{0x93, "VOLTAGE_LOW", "Cannot execute request until voltage is higher"},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
UDS_MESSAGE::UDS_MESSAGE()
|
||||||
|
{
|
||||||
|
subFunc = 0;
|
||||||
|
service = 0;
|
||||||
|
subFuncLen = 1;
|
||||||
|
extended = false;
|
||||||
|
isErrorReply = false;
|
||||||
|
}
|
||||||
|
|
||||||
UDS_HANDLER* UDS_HANDLER::mInstance = NULL;
|
UDS_HANDLER* UDS_HANDLER::mInstance = NULL;
|
||||||
|
|
||||||
UDS_HANDLER* UDS_HANDLER::getInstance()
|
UDS_HANDLER* UDS_HANDLER::getInstance()
|
||||||
@@ -198,27 +207,22 @@ void UDS_HANDLER::setReception(bool mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDS_HANDLER::sendUDSFrame(int bus, int ID, int service, QVector<unsigned char> payload)
|
|
||||||
{
|
|
||||||
QVector<unsigned char> data;
|
|
||||||
if (bus < 0) return;
|
|
||||||
if (bus >= CANConManager::getInstance()->getNumBuses()) return;
|
|
||||||
if (service < 0 || service > 0xFF) return;
|
|
||||||
data.append(service);
|
|
||||||
data.append(payload);
|
|
||||||
ISOTP_HANDLER::getInstance()->sendISOTPFrame(bus, ID, data);
|
|
||||||
qDebug() << "Sent UDS service: " << getServiceShortDesc(service) << " on bus " << bus;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UDS_HANDLER::sendUDSFrame(const UDS_MESSAGE &msg)
|
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 < 0 || msg.service > 0xFF) return;
|
||||||
|
|
||||||
data.append(msg.service);
|
data.append(msg.service);
|
||||||
|
for (int b = msg.subFuncLen - 1; b >= 0; b--)
|
||||||
|
{
|
||||||
|
data.append((msg.subFunc >> (8 * b)) & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
data.append(msg.data);
|
data.append(msg.data);
|
||||||
ISOTP_HANDLER::getInstance()->sendISOTPFrame(msg.bus, msg.ID, data);
|
ISOTP_HANDLER::getInstance()->sendISOTPFrame(msg.bus, msg.ID, data);
|
||||||
|
|
||||||
qDebug() << "Sent UDS service: " << getServiceShortDesc(msg.service) << " on bus " << msg.bus;
|
qDebug() << "Sent UDS service: " << getServiceShortDesc(msg.service) << " on bus " << msg.bus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,10 @@ class UDS_MESSAGE: public ISOTP_MESSAGE
|
|||||||
public:
|
public:
|
||||||
int service;
|
int service;
|
||||||
int subFunc;
|
int subFunc;
|
||||||
|
int subFuncLen;
|
||||||
bool isErrorReply;
|
bool isErrorReply;
|
||||||
|
|
||||||
|
UDS_MESSAGE();
|
||||||
};
|
};
|
||||||
|
|
||||||
class UDS_HANDLER : public QObject
|
class UDS_HANDLER : public QObject
|
||||||
@@ -85,7 +88,6 @@ public:
|
|||||||
void setExtendedAddressing(bool mode);
|
void setExtendedAddressing(bool mode);
|
||||||
static UDS_HANDLER* getInstance();
|
static UDS_HANDLER* getInstance();
|
||||||
void setReception(bool mode); //set whether to accept and forward frames or not
|
void setReception(bool mode); //set whether to accept and forward frames or not
|
||||||
void sendUDSFrame(int bus, int ID, int service, QVector<unsigned char> payload);
|
|
||||||
void sendUDSFrame(const UDS_MESSAGE &msg);
|
void sendUDSFrame(const UDS_MESSAGE &msg);
|
||||||
QString getServiceShortDesc(int service);
|
QString getServiceShortDesc(int service);
|
||||||
QString getServiceLongDesc(int service);
|
QString getServiceLongDesc(int service);
|
||||||
|
|||||||
@@ -343,7 +343,7 @@ bool CANConnection::removeAllTargettedFrames(QObject *receiver)
|
|||||||
void CANConnection::checkTargettedFrame(CANFrame &frame)
|
void CANConnection::checkTargettedFrame(CANFrame &frame)
|
||||||
{
|
{
|
||||||
unsigned int maskedID;
|
unsigned int maskedID;
|
||||||
qDebug() << "Got frame with ID " << frame.ID << " on bus " << frame.bus;
|
//qDebug() << "Got frame with ID " << frame.ID << " on bus " << frame.bus;
|
||||||
foreach (const CANFlt filt, mBusData_p[frame.bus].mTargettedFrames)
|
foreach (const CANFlt filt, mBusData_p[frame.bus].mTargettedFrames)
|
||||||
{
|
{
|
||||||
qDebug() << "Checking filter with id " << filt.id << " mask " << filt.mask;
|
qDebug() << "Checking filter with id " << filt.id << " mask " << filt.mask;
|
||||||
|
|||||||
+41
-17
@@ -223,6 +223,7 @@ void UDSScanWindow::scanUDS()
|
|||||||
test.subFunc = 0;
|
test.subFunc = 0;
|
||||||
sendOnBuses(test, buses);
|
sendOnBuses(test, buses);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ui->ckSession->isChecked())
|
if (ui->ckSession->isChecked())
|
||||||
{
|
{
|
||||||
for (typ = 1; typ < 4; typ++) //try each type of session access
|
for (typ = 1; typ < 4; typ++) //try each type of session access
|
||||||
@@ -232,22 +233,45 @@ void UDSScanWindow::scanUDS()
|
|||||||
sendOnBuses(test, buses);
|
sendOnBuses(test, buses);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
test.service = UDS_SERVICES::ECU_RESET;
|
||||||
test.subFunc = 1;
|
test.subFunc = 1;
|
||||||
sendOnBuses(test, buses);
|
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;
|
test.service = UDS_SERVICES::SECURITY_ACCESS;
|
||||||
test.subFunc = 1;
|
test.subFunc = 1;
|
||||||
sendOnBuses(test, buses);
|
sendOnBuses(test, buses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ui->ckReadByAddr->isChecked())
|
||||||
|
{
|
||||||
|
test.subFuncLen = ui->spinNumBytes->value();
|
||||||
|
test.service = UDS_SERVICES::READ_BY_ADDR;
|
||||||
|
for (int subf = ui->spinLowerSubfunc->value(); subf <= ui->spinUpperSubfunc->value(); subf++)
|
||||||
|
{
|
||||||
|
test.subFunc = subf;
|
||||||
|
sendOnBuses(test, buses);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ui->ckReadByID->isChecked())
|
||||||
|
{
|
||||||
|
test.subFuncLen = ui->spinNumBytes->value();
|
||||||
|
test.service = UDS_SERVICES::READ_BY_ID;
|
||||||
|
for (int subf = ui->spinLowerSubfunc->value(); subf <= ui->spinUpperSubfunc->value(); subf++)
|
||||||
|
{
|
||||||
|
test.subFunc = subf;
|
||||||
|
sendOnBuses(test, buses);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ui->ckWildcard->isChecked())
|
if (ui->ckWildcard->isChecked())
|
||||||
{
|
{
|
||||||
int numBytes = ui->spinNumBytes->value();
|
|
||||||
|
|
||||||
//preallocate the whole buffer so we don't have to keep updating the size and moving as we go.
|
//preallocate the whole buffer so we don't have to keep updating the size and moving as we go.
|
||||||
//TODO: this shows a downside to the current method - it might potentially need to create a huge
|
//TODO: this shows a downside to the current method - it might potentially need to create a huge
|
||||||
//number of frames here. Of course, the rest of the system will do the same so I guess it's a bad idea
|
//number of frames here. Of course, the rest of the system will do the same so I guess it's a bad idea
|
||||||
@@ -256,18 +280,14 @@ void UDSScanWindow::scanUDS()
|
|||||||
size *= (ui->spinUpperSubfunc->value() - ui->spinLowerSubfunc->value());
|
size *= (ui->spinUpperSubfunc->value() - ui->spinLowerSubfunc->value());
|
||||||
sendingFrames.reserve(size);
|
sendingFrames.reserve(size);
|
||||||
|
|
||||||
|
test.subFuncLen = ui->spinNumBytes->value();
|
||||||
|
|
||||||
for (typ = ui->spinLowerService->value(); typ <= ui->spinUpperService->value(); typ++)
|
for (typ = ui->spinLowerService->value(); typ <= ui->spinUpperService->value(); typ++)
|
||||||
{
|
{
|
||||||
test.service = typ;
|
test.service = typ;
|
||||||
for (int subTyp = ui->spinLowerSubfunc->value(); subTyp <= ui->spinUpperSubfunc->value(); subTyp++)
|
for (int subTyp = ui->spinLowerSubfunc->value(); subTyp <= ui->spinUpperSubfunc->value(); subTyp++)
|
||||||
{
|
{
|
||||||
test.data.clear();
|
test.subFunc = subTyp;
|
||||||
//multi-byte data sent big endian (largest value byte first) so plan accordingly.
|
|
||||||
test.subFunc = subTyp >> (8 * (numBytes - 1));
|
|
||||||
for (int by = 1; by < numBytes; by++)
|
|
||||||
{
|
|
||||||
test.data.append(subTyp >> (8 * (numBytes - by)));
|
|
||||||
}
|
|
||||||
sendOnBuses(test, buses);
|
sendOnBuses(test, buses);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -278,6 +298,8 @@ void UDSScanWindow::scanUDS()
|
|||||||
currIdx = -1;
|
currIdx = -1;
|
||||||
currentlyRunning = true;
|
currentlyRunning = true;
|
||||||
ui->btnScan->setText("Abort Scan");
|
ui->btnScan->setText("Abort Scan");
|
||||||
|
ui->progressBar->setValue(0);
|
||||||
|
ui->progressBar->setMaximum(sendingFrames.length());
|
||||||
sendNextMsg();
|
sendNextMsg();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,6 +333,8 @@ void UDSScanWindow::gotUDSReply(UDS_MESSAGE &msg)
|
|||||||
|
|
||||||
id = msg.ID;
|
id = msg.ID;
|
||||||
|
|
||||||
|
qDebug() << "UDS message ID " << msg.ID << " service: " << msg.service << " subfunc: " << msg.subFunc;
|
||||||
|
|
||||||
if ((id == (uint32_t)(sentFrame.ID + offset)) || ui->cbAllowAdaptiveOffset->isChecked())
|
if ((id == (uint32_t)(sentFrame.ID + offset)) || ui->cbAllowAdaptiveOffset->isChecked())
|
||||||
{
|
{
|
||||||
serviceShortName = UDS_HANDLER::getInstance()->getServiceShortDesc(sentFrame.service);
|
serviceShortName = UDS_HANDLER::getInstance()->getServiceShortDesc(sentFrame.service);
|
||||||
@@ -332,17 +356,21 @@ void UDSScanWindow::gotUDSReply(UDS_MESSAGE &msg)
|
|||||||
nodeSubFunc->setForeground(0, QBrush(Qt::darkGreen));
|
nodeSubFunc->setForeground(0, QBrush(Qt::darkGreen));
|
||||||
gotReply = true;
|
gotReply = true;
|
||||||
}
|
}
|
||||||
else if ( msg.service == 0x7F)
|
else if ( msg.isErrorReply && msg.service == sendingFrames[currIdx].service)
|
||||||
|
{
|
||||||
|
if (msg.data.length())
|
||||||
{
|
{
|
||||||
setupNodes();
|
setupNodes();
|
||||||
QTreeWidgetItem *nodeNegative = new QTreeWidgetItem();
|
QTreeWidgetItem *nodeNegative = new QTreeWidgetItem();
|
||||||
nodeNegative->setText(0, "NEGATIVE - " + UDS_HANDLER::getInstance()->getNegativeResponseShort(msg.data[1]));
|
qDebug() << ui->spinNumBytes->value();
|
||||||
|
nodeNegative->setText(0, "NEGATIVE - " + UDS_HANDLER::getInstance()->getNegativeResponseShort(msg.data[0]));
|
||||||
nodeNegative->setForeground(0, QBrush(Qt::darkRed));
|
nodeNegative->setForeground(0, QBrush(Qt::darkRed));
|
||||||
nodeSubFunc->addChild(nodeNegative);
|
nodeSubFunc->addChild(nodeNegative);
|
||||||
nodeSubFunc->setForeground(0, QBrush(Qt::darkRed));
|
nodeSubFunc->setForeground(0, QBrush(Qt::darkRed));
|
||||||
gotReply = true;
|
gotReply = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (gotReply)
|
if (gotReply)
|
||||||
{
|
{
|
||||||
//ui->listResults->addItem(result);
|
//ui->listResults->addItem(result);
|
||||||
@@ -391,15 +419,10 @@ void UDSScanWindow::timeOut()
|
|||||||
|
|
||||||
void UDSScanWindow::sendNextMsg()
|
void UDSScanWindow::sendNextMsg()
|
||||||
{
|
{
|
||||||
QVector<unsigned char> data;
|
|
||||||
|
|
||||||
currIdx++;
|
currIdx++;
|
||||||
if (currIdx < sendingFrames.count())
|
if (currIdx < sendingFrames.count())
|
||||||
{
|
{
|
||||||
data.clear();
|
UDS_HANDLER::getInstance()->sendUDSFrame(sendingFrames[currIdx]);
|
||||||
data.append(sendingFrames[currIdx].subFunc);
|
|
||||||
data.append(sendingFrames[currIdx].data);
|
|
||||||
UDS_HANDLER::getInstance()->sendUDSFrame(sendingFrames[currIdx].bus, sendingFrames[currIdx].ID, sendingFrames[currIdx].service, data);
|
|
||||||
waitTimer->start();
|
waitTimer->start();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -408,4 +431,5 @@ void UDSScanWindow::sendNextMsg()
|
|||||||
ui->btnScan->setText("Start Scan");
|
ui->btnScan->setText("Start Scan");
|
||||||
currentlyRunning = false;
|
currentlyRunning = false;
|
||||||
}
|
}
|
||||||
|
ui->progressBar->setValue(currIdx);
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-1
@@ -87,7 +87,7 @@
|
|||||||
<number>536870911</number>
|
<number>536870911</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<number>2024</number>
|
<number>2023</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="displayIntegerBase">
|
<property name="displayIntegerBase">
|
||||||
<number>16</number>
|
<number>16</number>
|
||||||
@@ -101,6 +101,9 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Show Tests with no Replies</string>
|
<string>Show Tests with no Replies</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@@ -116,6 +119,9 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSpinBox" name="spinReplyOffset">
|
<widget class="QSpinBox" name="spinReplyOffset">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>-128</number>
|
<number>-128</number>
|
||||||
</property>
|
</property>
|
||||||
@@ -132,6 +138,9 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Allow adaptive reply offset</string>
|
<string>Allow adaptive reply offset</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@@ -354,6 +363,13 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QProgressBar" name="progressBar">
|
||||||
|
<property name="value">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnScan">
|
<widget class="QPushButton" name="btnScan">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|||||||
Reference in New Issue
Block a user