Additional work on UDS - now UDS scan window can get results from UDS
handler instead of trying to do it all itself.
This commit is contained in:
+2
-1
@@ -113,7 +113,8 @@ HEADERS += mainwindow.h \
|
|||||||
signalviewerwindow.h \
|
signalviewerwindow.h \
|
||||||
bus_protocols/isotp_handler.h \
|
bus_protocols/isotp_handler.h \
|
||||||
bus_protocols/j1939_handler.h \
|
bus_protocols/j1939_handler.h \
|
||||||
bus_protocols/uds_handler.h
|
bus_protocols/uds_handler.h \
|
||||||
|
bus_protocols/isotp_message.h
|
||||||
|
|
||||||
FORMS += ui/candatagrid.ui \
|
FORMS += ui/candatagrid.ui \
|
||||||
ui/connectionwindow.ui \
|
ui/connectionwindow.ui \
|
||||||
|
|||||||
@@ -7,20 +7,7 @@
|
|||||||
#include "can_structs.h"
|
#include "can_structs.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "canframemodel.h"
|
#include "canframemodel.h"
|
||||||
|
#include "isotp_message.h"
|
||||||
//the same as the CANFrame struct but with arbitrary data size.
|
|
||||||
struct ISOTP_MESSAGE
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
uint32_t ID;
|
|
||||||
int bus;
|
|
||||||
bool extended;
|
|
||||||
bool isReceived;
|
|
||||||
int len; //# of bytes this message should have (as reported)
|
|
||||||
int actualSize; //# we actually got
|
|
||||||
QVector<unsigned char> data;
|
|
||||||
uint64_t timestamp;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ISOTP_HANDLER : public QObject
|
class ISOTP_HANDLER : public QObject
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef ISOTP_MESSAGE_H
|
||||||
|
#define ISOTP_MESSAGE_H
|
||||||
|
|
||||||
|
//the same as the CANFrame struct but with arbitrary data size.
|
||||||
|
class ISOTP_MESSAGE
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
uint32_t ID;
|
||||||
|
int bus;
|
||||||
|
bool extended;
|
||||||
|
bool isReceived;
|
||||||
|
int len; //# of bytes this message should have (as reported)
|
||||||
|
int actualSize; //# we actually got
|
||||||
|
QVector<unsigned char> data;
|
||||||
|
uint64_t timestamp;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ISOTP_MESSAGE_H
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "uds_handler.h"
|
#include "uds_handler.h"
|
||||||
#include "connections/canconmanager.h"
|
#include "connections/canconmanager.h"
|
||||||
|
#include "mainwindow.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
QVector<CODE_STRUCT> UDS_SERVICE_DESC = {
|
QVector<CODE_STRUCT> UDS_SERVICE_DESC = {
|
||||||
@@ -143,6 +144,18 @@ UDS_HANDLER::UDS_HANDLER()
|
|||||||
void UDS_HANDLER::gotISOTPFrame(ISOTP_MESSAGE &msg)
|
void UDS_HANDLER::gotISOTPFrame(ISOTP_MESSAGE &msg)
|
||||||
{
|
{
|
||||||
qDebug() << "UDS handler got ISOTP frame";
|
qDebug() << "UDS handler got ISOTP frame";
|
||||||
|
UDS_MESSAGE udsMsg;
|
||||||
|
udsMsg.bus = msg.bus;
|
||||||
|
udsMsg.extended = msg.extended;
|
||||||
|
udsMsg.ID = msg.ID;
|
||||||
|
udsMsg.isReceived = msg.isReceived;
|
||||||
|
udsMsg.timestamp = msg.timestamp;
|
||||||
|
udsMsg.actualSize = msg.actualSize;
|
||||||
|
udsMsg.len = msg.len;
|
||||||
|
udsMsg.service = msg.data.at(0);
|
||||||
|
udsMsg.subFunc = msg.data.at(1);
|
||||||
|
udsMsg.data = msg.data.mid(1, -1); //don't copy data[0] which was service number
|
||||||
|
emit newUDSMessage(udsMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDS_HANDLER::setReception(bool mode)
|
void UDS_HANDLER::setReception(bool mode)
|
||||||
@@ -177,6 +190,18 @@ void UDS_HANDLER::sendUDSFrame(int bus, int ID, int service, QVector<unsigned ch
|
|||||||
qDebug() << "Sent UDS service: " << getServiceShortDesc(service) << " on bus " << bus;
|
qDebug() << "Sent UDS service: " << getServiceShortDesc(service) << " on bus " << bus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UDS_HANDLER::sendUDSFrame(const UDS_MESSAGE &msg)
|
||||||
|
{
|
||||||
|
QVector<unsigned char> data;
|
||||||
|
if (msg.bus < 0) return;
|
||||||
|
if (msg.bus >= CANConManager::getInstance()->getNumBuses()) return;
|
||||||
|
if (msg.service < 0 || msg.service > 0xFF) return;
|
||||||
|
data.append(msg.service);
|
||||||
|
data.append(msg.data);
|
||||||
|
ISOTP_HANDLER::getInstance()->sendISOTPFrame(msg.bus, msg.ID, data);
|
||||||
|
qDebug() << "Sent UDS service: " << getServiceShortDesc(msg.service) << " on bus " << msg.bus;
|
||||||
|
}
|
||||||
|
|
||||||
QString UDS_HANDLER::getServiceShortDesc(int service)
|
QString UDS_HANDLER::getServiceShortDesc(int service)
|
||||||
{
|
{
|
||||||
foreach (CODE_STRUCT code, UDS_SERVICE_DESC)
|
foreach (CODE_STRUCT code, UDS_SERVICE_DESC)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "can_structs.h"
|
#include "can_structs.h"
|
||||||
#include "isotp_handler.h"
|
#include "isotp_message.h"
|
||||||
|
|
||||||
namespace UDS_SERVICES
|
namespace UDS_SERVICES
|
||||||
{
|
{
|
||||||
@@ -68,6 +68,13 @@ struct CODE_STRUCT
|
|||||||
QString longDesc;
|
QString longDesc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class UDS_MESSAGE: public ISOTP_MESSAGE
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int service;
|
||||||
|
int subFunc;
|
||||||
|
};
|
||||||
|
|
||||||
class UDS_HANDLER : public QObject
|
class UDS_HANDLER : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -78,6 +85,7 @@ public:
|
|||||||
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(int bus, int ID, int service, QVector<unsigned char> payload);
|
||||||
|
void sendUDSFrame(const UDS_MESSAGE &msg);
|
||||||
QString getServiceShortDesc(int service);
|
QString getServiceShortDesc(int service);
|
||||||
QString getServiceLongDesc(int service);
|
QString getServiceLongDesc(int service);
|
||||||
QString getNegativeResponseShort(int respCode);
|
QString getNegativeResponseShort(int respCode);
|
||||||
@@ -87,7 +95,7 @@ public slots:
|
|||||||
void gotISOTPFrame(ISOTP_MESSAGE &msg);
|
void gotISOTPFrame(ISOTP_MESSAGE &msg);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void newUDSMessage(ISOTP_MESSAGE &msg);
|
void newUDSMessage(UDS_MESSAGE &msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<ISOTP_MESSAGE> messageBuffer;
|
QList<ISOTP_MESSAGE> messageBuffer;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef CONFIG
|
#ifndef CONFIG
|
||||||
#define CONFIG
|
#define CONFIG
|
||||||
|
|
||||||
#define VERSION 167
|
#define VERSION 168
|
||||||
|
|
||||||
//try to keep this in sync.
|
//try to keep this in sync.
|
||||||
//SavvyCAN will complain if you connect a GVRET board with a revision
|
//SavvyCAN will complain if you connect a GVRET board with a revision
|
||||||
|
|||||||
+13
-18
@@ -17,8 +17,10 @@ UDSScanWindow::UDSScanWindow(const QVector<CANFrame> *frames, QWidget *parent) :
|
|||||||
waitTimer = new QTimer;
|
waitTimer = new QTimer;
|
||||||
waitTimer->setInterval(100);
|
waitTimer->setInterval(100);
|
||||||
|
|
||||||
|
UDS_HANDLER::getInstance()->setReception(true);
|
||||||
|
|
||||||
connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int)));
|
connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int)));
|
||||||
connect(CANConManager::getInstance(), &CANConManager::framesReceived, this, &UDSScanWindow::rapidFrames);
|
connect(UDS_HANDLER::getInstance(), &UDS_HANDLER::newUDSMessage, this, &UDSScanWindow::gotUDSReply);
|
||||||
connect(ui->btnScan, &QPushButton::clicked, this, &UDSScanWindow::scanUDS);
|
connect(ui->btnScan, &QPushButton::clicked, this, &UDSScanWindow::scanUDS);
|
||||||
connect(waitTimer, &QTimer::timeout, this, &UDSScanWindow::timeOut);
|
connect(waitTimer, &QTimer::timeout, this, &UDSScanWindow::timeOut);
|
||||||
connect(ui->btnSaveResults, &QPushButton::clicked, this, &UDSScanWindow::saveResults);
|
connect(ui->btnSaveResults, &QPushButton::clicked, this, &UDSScanWindow::saveResults);
|
||||||
@@ -73,7 +75,7 @@ void UDSScanWindow::saveResults()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDSScanWindow::sendOnBuses(UDS_TESTS test, int buses)
|
void UDSScanWindow::sendOnBuses(UDS_MESSAGE test, int buses)
|
||||||
{
|
{
|
||||||
int busList = buses;
|
int busList = buses;
|
||||||
if (busList < ui->cbBuses->count() - 1)
|
if (busList < ui->cbBuses->count() - 1)
|
||||||
@@ -107,7 +109,7 @@ void UDSScanWindow::scanUDS()
|
|||||||
ui->listResults->clear();
|
ui->listResults->clear();
|
||||||
sendingFrames.clear();
|
sendingFrames.clear();
|
||||||
|
|
||||||
UDS_TESTS test;
|
UDS_MESSAGE test;
|
||||||
int typ, id;
|
int typ, id;
|
||||||
int startID, endID;
|
int startID, endID;
|
||||||
startID = Utility::ParseStringToNum(ui->txtStartID->text());
|
startID = Utility::ParseStringToNum(ui->txtStartID->text());
|
||||||
@@ -169,47 +171,40 @@ void UDSScanWindow::updatedFrames(int numFrames)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Updates here are nearly once per millisecond if there is heavy traffic. That's more like it!
|
void UDSScanWindow::gotUDSReply(UDS_MESSAGE &msg)
|
||||||
//TODO: I really doubt this works anymore with the new connection system. This breaks the UDS scanner for now! ;(
|
|
||||||
void UDSScanWindow::rapidFrames(const CANConnection* conn, const QVector<CANFrame>& pFrames)
|
|
||||||
{
|
{
|
||||||
QString result;
|
QString result;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
int offset = ui->spinReplyOffset->value();
|
int offset = ui->spinReplyOffset->value();
|
||||||
UDS_TESTS sentFrame;
|
UDS_MESSAGE sentFrame;
|
||||||
bool gotReply = false;
|
bool gotReply = false;
|
||||||
|
|
||||||
if (pFrames.length() <= 0) return;
|
|
||||||
|
|
||||||
int numSending = sendingFrames.length();
|
int numSending = sendingFrames.length();
|
||||||
if (numSending == 0) return;
|
if (numSending == 0) return;
|
||||||
if (currIdx >= numSending) return;
|
if (currIdx >= numSending) return;
|
||||||
sentFrame = sendingFrames[currIdx];
|
sentFrame = sendingFrames[currIdx];
|
||||||
|
|
||||||
foreach(const CANFrame& thisFrame, pFrames)
|
id = msg.ID;
|
||||||
{
|
|
||||||
if (currIdx >= numSending) return;
|
|
||||||
id = thisFrame.ID;
|
|
||||||
|
|
||||||
if ((id == (uint32_t)(sentFrame.ID + offset)) || ui->cbAllowAdaptiveOffset->isChecked())
|
if ((id == (uint32_t)(sentFrame.ID + offset)) || ui->cbAllowAdaptiveOffset->isChecked())
|
||||||
{
|
{
|
||||||
//int temp = thisFrame.data[0] >> 4;
|
//int temp = thisFrame.data[0] >> 4;
|
||||||
//if (temp == 0) //single frame reply (maybe)
|
//if (temp == 0) //single frame reply (maybe)
|
||||||
//{
|
//{
|
||||||
if (thisFrame.data[1] == 0x40 + sendingFrames[currIdx].service)
|
if (msg.service == 0x40 + sendingFrames[currIdx].service)
|
||||||
{
|
{
|
||||||
result = "Request on bus " + QString::number(sentFrame.bus) + " ID: " + QString::number(sentFrame.ID, 16) + " got response to mode "
|
result = "Request on bus " + QString::number(sentFrame.bus) + " ID: " + QString::number(sentFrame.ID, 16) + " got response to mode "
|
||||||
+ QString::number(sentFrame.service, 16)
|
+ QString::number(sentFrame.service, 16)
|
||||||
+ " " + QString::number(sentFrame.subFunc, 16) + " with affirmation from ID " + QString::number(id, 16)
|
+ " " + QString::number(sentFrame.subFunc, 16) + " with affirmation from ID " + QString::number(id, 16)
|
||||||
+ " on bus " + QString::number(thisFrame.bus) + ".";
|
+ " on bus " + QString::number(msg.bus) + ".";
|
||||||
gotReply = true;
|
gotReply = true;
|
||||||
}
|
}
|
||||||
else if ( thisFrame.data[1] == 0x7F)
|
else if ( msg.service == 0x7F)
|
||||||
{
|
{
|
||||||
result = "Request on bus " + QString::number(sentFrame.bus) + " ID: " + QString::number(sentFrame.ID, 16) + " got response to mode "
|
result = "Request on bus " + QString::number(sentFrame.bus) + " ID: " + QString::number(sentFrame.ID, 16) + " got response to mode "
|
||||||
+ QString::number(sentFrame.service, 16)
|
+ QString::number(sentFrame.service, 16)
|
||||||
+ " " + QString::number(sentFrame.subFunc, 16) + " with an error from ID " + QString::number(id, 16)
|
+ " " + QString::number(sentFrame.subFunc, 16) + " with an error from ID " + QString::number(id, 16)
|
||||||
+ " on bus " + QString::number(thisFrame.bus) + ".";
|
+ " on bus " + QString::number(msg.bus) + ".";
|
||||||
gotReply = true;
|
gotReply = true;
|
||||||
}
|
}
|
||||||
//}
|
//}
|
||||||
@@ -226,7 +221,7 @@ void UDSScanWindow::rapidFrames(const CANConnection* conn, const QVector<CANFram
|
|||||||
}
|
}
|
||||||
//error replies are never multiframe so the check doesn't have to be done here.
|
//error replies are never multiframe so the check doesn't have to be done here.
|
||||||
} */
|
} */
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (gotReply)
|
if (gotReply)
|
||||||
{
|
{
|
||||||
|
|||||||
+4
-11
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "can_structs.h"
|
#include "can_structs.h"
|
||||||
#include "connections/canconnection.h"
|
#include "connections/canconnection.h"
|
||||||
|
#include "bus_protocols/uds_handler.h"
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
@@ -10,14 +11,6 @@ namespace Ui {
|
|||||||
class UDSScanWindow;
|
class UDSScanWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UDS_TESTS
|
|
||||||
{
|
|
||||||
int ID;
|
|
||||||
int bus;
|
|
||||||
int service;
|
|
||||||
int subFunc;
|
|
||||||
};
|
|
||||||
|
|
||||||
class UDSScanWindow : public QDialog
|
class UDSScanWindow : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -28,7 +21,7 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updatedFrames(int numFrames);
|
void updatedFrames(int numFrames);
|
||||||
void rapidFrames(const CANConnection* conn, const QVector<CANFrame>& pFrames);
|
void gotUDSReply(UDS_MESSAGE &msg);
|
||||||
void scanUDS();
|
void scanUDS();
|
||||||
void saveResults();
|
void saveResults();
|
||||||
void timeOut();
|
void timeOut();
|
||||||
@@ -37,12 +30,12 @@ private:
|
|||||||
Ui::UDSScanWindow *ui;
|
Ui::UDSScanWindow *ui;
|
||||||
const QVector<CANFrame> *modelFrames;
|
const QVector<CANFrame> *modelFrames;
|
||||||
QTimer *waitTimer;
|
QTimer *waitTimer;
|
||||||
QList<UDS_TESTS> sendingFrames;
|
QList<UDS_MESSAGE> sendingFrames;
|
||||||
int currIdx = 0;
|
int currIdx = 0;
|
||||||
bool currentlyRunning;
|
bool currentlyRunning;
|
||||||
|
|
||||||
void sendNextMsg();
|
void sendNextMsg();
|
||||||
void sendOnBuses(UDS_TESTS frame, int buses);
|
void sendOnBuses(UDS_MESSAGE frame, int buses);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // UDSSCANWINDOW_H
|
#endif // UDSSCANWINDOW_H
|
||||||
|
|||||||
Reference in New Issue
Block a user