Switch ISOTP and UDS handlers to no longer be static.
Now each can be instantiated multiple times with each instance handling a different ISOTP or UDS stream. This should streamline some upcoming code
This commit is contained in:
@@ -1,19 +1,6 @@
|
||||
#include "isotp_handler.h"
|
||||
#include "connections/canconmanager.h"
|
||||
|
||||
ISOTP_HANDLER* ISOTP_HANDLER::mInstance = NULL;
|
||||
|
||||
ISOTP_HANDLER* ISOTP_HANDLER::getInstance()
|
||||
{
|
||||
if(!mInstance)
|
||||
{
|
||||
mInstance = new ISOTP_HANDLER();
|
||||
mInstance->modelFrames = MainWindow::getReference()->getCANFrameModel()->getListReference();
|
||||
}
|
||||
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
ISOTP_HANDLER::ISOTP_HANDLER()
|
||||
{
|
||||
useExtendedAddressing = false;
|
||||
@@ -23,9 +10,16 @@ ISOTP_HANDLER::ISOTP_HANDLER()
|
||||
lastSenderBus = 0;
|
||||
lastSenderID = 0;
|
||||
|
||||
modelFrames = MainWindow::getReference()->getCANFrameModel()->getListReference();
|
||||
|
||||
connect(&frameTimer, SIGNAL(timeout()), this, SLOT(frameTimerTick()));
|
||||
}
|
||||
|
||||
ISOTP_HANDLER::~ISOTP_HANDLER()
|
||||
{
|
||||
disconnect(&frameTimer, SIGNAL(timeout()), this, SLOT(frameTimerTick()));
|
||||
}
|
||||
|
||||
void ISOTP_HANDLER::setExtendedAddressing(bool mode)
|
||||
{
|
||||
useExtendedAddressing = mode;
|
||||
|
||||
@@ -16,8 +16,8 @@ class ISOTP_HANDLER : public QObject
|
||||
|
||||
public:
|
||||
ISOTP_HANDLER();
|
||||
~ISOTP_HANDLER();
|
||||
void setExtendedAddressing(bool mode);
|
||||
static ISOTP_HANDLER* getInstance();
|
||||
void setReception(bool mode); //set whether to accept and forward frames or not
|
||||
void sendISOTPFrame(int bus, int ID, QVector<unsigned char> data);
|
||||
void setProcessAll(bool state);
|
||||
@@ -51,8 +51,6 @@ private:
|
||||
|
||||
void processFrame(const CANFrame &frame);
|
||||
void checkNeedFlush(uint64_t ID);
|
||||
|
||||
static ISOTP_HANDLER* mInstance;
|
||||
};
|
||||
|
||||
#endif // ISOTP_HANDLER_H
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "uds_handler.h"
|
||||
#include "connections/canconmanager.h"
|
||||
#include "mainwindow.h"
|
||||
#include "isotp_handler.h"
|
||||
#include <QDebug>
|
||||
|
||||
QVector<CODE_STRUCT> UDS_SERVICE_DESC = {
|
||||
@@ -131,23 +132,17 @@ UDS_MESSAGE::UDS_MESSAGE()
|
||||
isErrorReply = false;
|
||||
}
|
||||
|
||||
UDS_HANDLER* UDS_HANDLER::mInstance = NULL;
|
||||
|
||||
UDS_HANDLER* UDS_HANDLER::getInstance()
|
||||
{
|
||||
if(!mInstance)
|
||||
{
|
||||
mInstance = new UDS_HANDLER();
|
||||
mInstance->modelFrames = MainWindow::getReference()->getCANFrameModel()->getListReference();
|
||||
}
|
||||
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
UDS_HANDLER::UDS_HANDLER()
|
||||
{
|
||||
isReceiving = false;
|
||||
useExtendedAddressing = false;
|
||||
modelFrames = MainWindow::getReference()->getCANFrameModel()->getListReference();
|
||||
isoHandler = new ISOTP_HANDLER();
|
||||
}
|
||||
|
||||
UDS_HANDLER::~UDS_HANDLER()
|
||||
{
|
||||
delete isoHandler;
|
||||
}
|
||||
|
||||
void UDS_HANDLER::gotISOTPFrame(ISOTP_MESSAGE msg)
|
||||
@@ -189,7 +184,7 @@ void UDS_HANDLER::gotISOTPFrame(ISOTP_MESSAGE msg)
|
||||
|
||||
void UDS_HANDLER::setFlowCtrl(bool state)
|
||||
{
|
||||
ISOTP_HANDLER::getInstance()->setFlowCtrl(state);
|
||||
isoHandler->setFlowCtrl(state);
|
||||
}
|
||||
|
||||
void UDS_HANDLER::setReception(bool mode)
|
||||
@@ -200,14 +195,14 @@ void UDS_HANDLER::setReception(bool mode)
|
||||
|
||||
if (isReceiving)
|
||||
{
|
||||
connect(ISOTP_HANDLER::getInstance(), SIGNAL(newISOMessage(ISOTP_MESSAGE)), this, SLOT(gotISOTPFrame(ISOTP_MESSAGE)));
|
||||
ISOTP_HANDLER::getInstance()->setReception(true); //must enable ISOTP reception too.
|
||||
connect(isoHandler, SIGNAL(newISOMessage(ISOTP_MESSAGE)), this, SLOT(gotISOTPFrame(ISOTP_MESSAGE)));
|
||||
isoHandler->setReception(true); //must enable ISOTP reception too.
|
||||
qDebug() << "Enabling reception of ISO-TP frames in UDS handler";
|
||||
}
|
||||
else
|
||||
{
|
||||
disconnect(ISOTP_HANDLER::getInstance(), SIGNAL(newISOMessage(ISOTP_MESSAGE)), this, SLOT(gotISOTPFrame(ISOTP_MESSAGE)));
|
||||
//can't disable ISOTP reception because something else might be using it.
|
||||
disconnect(isoHandler, SIGNAL(newISOMessage(ISOTP_MESSAGE)), this, SLOT(gotISOTPFrame(ISOTP_MESSAGE)));
|
||||
isoHandler->setReception(false);
|
||||
qDebug() << "Disabling reception of ISOTP frames in UDS handler";
|
||||
}
|
||||
}
|
||||
@@ -226,7 +221,7 @@ void UDS_HANDLER::sendUDSFrame(const UDS_MESSAGE &msg)
|
||||
}
|
||||
|
||||
data.append(msg.data);
|
||||
ISOTP_HANDLER::getInstance()->sendISOTPFrame(msg.bus, msg.ID, data);
|
||||
isoHandler->sendISOTPFrame(msg.bus, msg.ID, data);
|
||||
|
||||
qDebug() << "Sent UDS service: " << getServiceShortDesc(msg.service) << " on bus " << msg.bus;
|
||||
}
|
||||
@@ -272,22 +267,22 @@ QString UDS_HANDLER::getNegativeResponseLong(int respCode)
|
||||
//Little shim functions that drop straight through to the ISO_TP handler
|
||||
void UDS_HANDLER::setProcessAllIDs(bool state)
|
||||
{
|
||||
ISOTP_HANDLER::getInstance()->setProcessAll(state);
|
||||
isoHandler->setProcessAll(state);
|
||||
}
|
||||
|
||||
void UDS_HANDLER::addID(uint32_t id)
|
||||
{
|
||||
ISOTP_HANDLER::getInstance()->addID(id);
|
||||
isoHandler->addID(id);
|
||||
}
|
||||
|
||||
void UDS_HANDLER::removeID(uint32_t id)
|
||||
{
|
||||
ISOTP_HANDLER::getInstance()->removeID(id);
|
||||
isoHandler->removeID(id);
|
||||
}
|
||||
|
||||
void UDS_HANDLER::clearAllIDs()
|
||||
{
|
||||
ISOTP_HANDLER::getInstance()->clearAllIDs();
|
||||
isoHandler->clearAllIDs();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "can_structs.h"
|
||||
#include "isotp_message.h"
|
||||
|
||||
class ISOTP_HANDLER;
|
||||
|
||||
namespace UDS_SERVICES
|
||||
{
|
||||
enum
|
||||
@@ -85,6 +87,7 @@ class UDS_HANDLER : public QObject
|
||||
|
||||
public:
|
||||
UDS_HANDLER();
|
||||
~UDS_HANDLER();
|
||||
void setExtendedAddressing(bool mode);
|
||||
static UDS_HANDLER* getInstance();
|
||||
void setReception(bool mode); //set whether to accept and forward frames or not
|
||||
@@ -113,7 +116,7 @@ private:
|
||||
|
||||
void processFrame(const CANFrame &frame);
|
||||
|
||||
static UDS_HANDLER* mInstance;
|
||||
ISOTP_HANDLER *isoHandler;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ ISOTP_InterpreterWindow::ISOTP_InterpreterWindow(const QVector<CANFrame> *frames
|
||||
ui->setupUi(this);
|
||||
modelFrames = frames;
|
||||
|
||||
decoder = ISOTP_HANDLER::getInstance();
|
||||
decoder = new ISOTP_HANDLER;
|
||||
|
||||
decoder->setReception(true);
|
||||
decoder->setProcessAll(true);
|
||||
|
||||
+14
-11
@@ -18,8 +18,10 @@ UDSScanWindow::UDSScanWindow(const QVector<CANFrame> *frames, QWidget *parent) :
|
||||
waitTimer = new QTimer;
|
||||
waitTimer->setInterval(100);
|
||||
|
||||
udsHandler = new UDS_HANDLER;
|
||||
|
||||
connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int)));
|
||||
connect(UDS_HANDLER::getInstance(), &UDS_HANDLER::newUDSMessage, this, &UDSScanWindow::gotUDSReply);
|
||||
connect(udsHandler, &UDS_HANDLER::newUDSMessage, this, &UDSScanWindow::gotUDSReply);
|
||||
connect(ui->btnScan, &QPushButton::clicked, this, &UDSScanWindow::scanUDS);
|
||||
connect(waitTimer, &QTimer::timeout, this, &UDSScanWindow::timeOut);
|
||||
connect(ui->btnSaveResults, &QPushButton::clicked, this, &UDSScanWindow::saveResults);
|
||||
@@ -44,6 +46,7 @@ UDSScanWindow::~UDSScanWindow()
|
||||
delete ui;
|
||||
waitTimer->stop();
|
||||
delete waitTimer;
|
||||
delete udsHandler;
|
||||
}
|
||||
|
||||
void UDSScanWindow::adaptiveToggled()
|
||||
@@ -184,17 +187,17 @@ void UDSScanWindow::scanUDS()
|
||||
{
|
||||
waitTimer->stop();
|
||||
sendingFrames.clear();
|
||||
UDS_HANDLER::getInstance()->setReception(false);
|
||||
UDS_HANDLER::getInstance()->setProcessAllIDs(false);
|
||||
UDS_HANDLER::getInstance()->setFlowCtrl(false);
|
||||
udsHandler->setReception(false);
|
||||
udsHandler->setProcessAllIDs(false);
|
||||
udsHandler->setFlowCtrl(false);
|
||||
currentlyRunning = false;
|
||||
ui->btnScan->setText("Start Scan");
|
||||
return;
|
||||
}
|
||||
|
||||
UDS_HANDLER::getInstance()->setReception(true);
|
||||
UDS_HANDLER::getInstance()->setProcessAllIDs(true);
|
||||
UDS_HANDLER::getInstance()->setFlowCtrl(true);
|
||||
udsHandler->setReception(true);
|
||||
udsHandler->setProcessAllIDs(true);
|
||||
udsHandler->setFlowCtrl(true);
|
||||
|
||||
waitTimer->setInterval(ui->spinDelay->value());
|
||||
|
||||
@@ -342,7 +345,7 @@ void UDSScanWindow::gotUDSReply(UDS_MESSAGE msg)
|
||||
|
||||
if ((id == (uint32_t)(sentFrame.ID + offset)) || ui->cbAllowAdaptiveOffset->isChecked())
|
||||
{
|
||||
serviceShortName = UDS_HANDLER::getInstance()->getServiceShortDesc(sentFrame.service);
|
||||
serviceShortName = udsHandler->getServiceShortDesc(sentFrame.service);
|
||||
if (serviceShortName.length() < 3) serviceShortName = QString::number(sentFrame.service, 16);
|
||||
if (msg.service == 0x40 + sendingFrames[currIdx].service)
|
||||
{
|
||||
@@ -368,7 +371,7 @@ void UDSScanWindow::gotUDSReply(UDS_MESSAGE msg)
|
||||
setupNodes();
|
||||
QTreeWidgetItem *nodeNegative = new QTreeWidgetItem();
|
||||
qDebug() << ui->spinNumBytes->value();
|
||||
nodeNegative->setText(0, "NEGATIVE - " + UDS_HANDLER::getInstance()->getNegativeResponseShort(msg.data[0]));
|
||||
nodeNegative->setText(0, "NEGATIVE - " + udsHandler->getNegativeResponseShort(msg.data[0]));
|
||||
nodeNegative->setForeground(0, QBrush(Qt::darkRed));
|
||||
nodeSubFunc->addChild(nodeNegative);
|
||||
nodeSubFunc->setForeground(0, QBrush(Qt::darkRed));
|
||||
@@ -385,7 +388,7 @@ void UDSScanWindow::gotUDSReply(UDS_MESSAGE msg)
|
||||
|
||||
void UDSScanWindow::setupNodes()
|
||||
{
|
||||
QString serviceShortName = UDS_HANDLER::getInstance()->getServiceShortDesc(sendingFrames[currIdx].service);
|
||||
QString serviceShortName = udsHandler->getServiceShortDesc(sendingFrames[currIdx].service);
|
||||
if (serviceShortName.length() < 3) serviceShortName = QString::number(sendingFrames[currIdx].service, 16);
|
||||
|
||||
if (!nodeID || nodeID->text(0) != Utility::formatHexNum(sendingFrames[currIdx].ID))
|
||||
@@ -427,7 +430,7 @@ void UDSScanWindow::sendNextMsg()
|
||||
currIdx++;
|
||||
if (currIdx < sendingFrames.count())
|
||||
{
|
||||
UDS_HANDLER::getInstance()->sendUDSFrame(sendingFrames[currIdx]);
|
||||
udsHandler->sendUDSFrame(sendingFrames[currIdx]);
|
||||
waitTimer->start();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -38,6 +38,7 @@ private slots:
|
||||
private:
|
||||
Ui::UDSScanWindow *ui;
|
||||
const QVector<CANFrame> *modelFrames;
|
||||
UDS_HANDLER *udsHandler;
|
||||
QTimer *waitTimer;
|
||||
QList<UDS_MESSAGE> sendingFrames;
|
||||
QTreeWidgetItem *nodeID;
|
||||
|
||||
Reference in New Issue
Block a user