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:
Collin Kidder
2017-08-20 21:34:05 -04:00
parent 0fd4ca9b3f
commit d869b6a126
7 changed files with 46 additions and 52 deletions
+7 -13
View File
@@ -1,19 +1,6 @@
#include "isotp_handler.h" #include "isotp_handler.h"
#include "connections/canconmanager.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() ISOTP_HANDLER::ISOTP_HANDLER()
{ {
useExtendedAddressing = false; useExtendedAddressing = false;
@@ -23,9 +10,16 @@ ISOTP_HANDLER::ISOTP_HANDLER()
lastSenderBus = 0; lastSenderBus = 0;
lastSenderID = 0; lastSenderID = 0;
modelFrames = MainWindow::getReference()->getCANFrameModel()->getListReference();
connect(&frameTimer, SIGNAL(timeout()), this, SLOT(frameTimerTick())); connect(&frameTimer, SIGNAL(timeout()), this, SLOT(frameTimerTick()));
} }
ISOTP_HANDLER::~ISOTP_HANDLER()
{
disconnect(&frameTimer, SIGNAL(timeout()), this, SLOT(frameTimerTick()));
}
void ISOTP_HANDLER::setExtendedAddressing(bool mode) void ISOTP_HANDLER::setExtendedAddressing(bool mode)
{ {
useExtendedAddressing = mode; useExtendedAddressing = mode;
+1 -3
View File
@@ -16,8 +16,8 @@ class ISOTP_HANDLER : public QObject
public: public:
ISOTP_HANDLER(); ISOTP_HANDLER();
~ISOTP_HANDLER();
void setExtendedAddressing(bool mode); void setExtendedAddressing(bool mode);
static ISOTP_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 sendISOTPFrame(int bus, int ID, QVector<unsigned char> data); void sendISOTPFrame(int bus, int ID, QVector<unsigned char> data);
void setProcessAll(bool state); void setProcessAll(bool state);
@@ -51,8 +51,6 @@ private:
void processFrame(const CANFrame &frame); void processFrame(const CANFrame &frame);
void checkNeedFlush(uint64_t ID); void checkNeedFlush(uint64_t ID);
static ISOTP_HANDLER* mInstance;
}; };
#endif // ISOTP_HANDLER_H #endif // ISOTP_HANDLER_H
+18 -23
View File
@@ -1,6 +1,7 @@
#include "uds_handler.h" #include "uds_handler.h"
#include "connections/canconmanager.h" #include "connections/canconmanager.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "isotp_handler.h"
#include <QDebug> #include <QDebug>
QVector<CODE_STRUCT> UDS_SERVICE_DESC = { QVector<CODE_STRUCT> UDS_SERVICE_DESC = {
@@ -131,23 +132,17 @@ UDS_MESSAGE::UDS_MESSAGE()
isErrorReply = false; 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() UDS_HANDLER::UDS_HANDLER()
{ {
isReceiving = false; isReceiving = false;
useExtendedAddressing = 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) void UDS_HANDLER::gotISOTPFrame(ISOTP_MESSAGE msg)
@@ -189,7 +184,7 @@ void UDS_HANDLER::gotISOTPFrame(ISOTP_MESSAGE msg)
void UDS_HANDLER::setFlowCtrl(bool state) void UDS_HANDLER::setFlowCtrl(bool state)
{ {
ISOTP_HANDLER::getInstance()->setFlowCtrl(state); isoHandler->setFlowCtrl(state);
} }
void UDS_HANDLER::setReception(bool mode) void UDS_HANDLER::setReception(bool mode)
@@ -200,14 +195,14 @@ void UDS_HANDLER::setReception(bool mode)
if (isReceiving) if (isReceiving)
{ {
connect(ISOTP_HANDLER::getInstance(), SIGNAL(newISOMessage(ISOTP_MESSAGE)), this, SLOT(gotISOTPFrame(ISOTP_MESSAGE))); connect(isoHandler, SIGNAL(newISOMessage(ISOTP_MESSAGE)), this, SLOT(gotISOTPFrame(ISOTP_MESSAGE)));
ISOTP_HANDLER::getInstance()->setReception(true); //must enable ISOTP reception too. isoHandler->setReception(true); //must enable ISOTP reception too.
qDebug() << "Enabling reception of ISO-TP frames in UDS handler"; qDebug() << "Enabling reception of ISO-TP frames in UDS handler";
} }
else else
{ {
disconnect(ISOTP_HANDLER::getInstance(), SIGNAL(newISOMessage(ISOTP_MESSAGE)), this, SLOT(gotISOTPFrame(ISOTP_MESSAGE))); disconnect(isoHandler, SIGNAL(newISOMessage(ISOTP_MESSAGE)), this, SLOT(gotISOTPFrame(ISOTP_MESSAGE)));
//can't disable ISOTP reception because something else might be using it. isoHandler->setReception(false);
qDebug() << "Disabling reception of ISOTP frames in UDS handler"; 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); 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; 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 //Little shim functions that drop straight through to the ISO_TP handler
void UDS_HANDLER::setProcessAllIDs(bool state) void UDS_HANDLER::setProcessAllIDs(bool state)
{ {
ISOTP_HANDLER::getInstance()->setProcessAll(state); isoHandler->setProcessAll(state);
} }
void UDS_HANDLER::addID(uint32_t id) void UDS_HANDLER::addID(uint32_t id)
{ {
ISOTP_HANDLER::getInstance()->addID(id); isoHandler->addID(id);
} }
void UDS_HANDLER::removeID(uint32_t id) void UDS_HANDLER::removeID(uint32_t id)
{ {
ISOTP_HANDLER::getInstance()->removeID(id); isoHandler->removeID(id);
} }
void UDS_HANDLER::clearAllIDs() void UDS_HANDLER::clearAllIDs()
{ {
ISOTP_HANDLER::getInstance()->clearAllIDs(); isoHandler->clearAllIDs();
} }
+4 -1
View File
@@ -7,6 +7,8 @@
#include "can_structs.h" #include "can_structs.h"
#include "isotp_message.h" #include "isotp_message.h"
class ISOTP_HANDLER;
namespace UDS_SERVICES namespace UDS_SERVICES
{ {
enum enum
@@ -85,6 +87,7 @@ class UDS_HANDLER : public QObject
public: public:
UDS_HANDLER(); UDS_HANDLER();
~UDS_HANDLER();
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
@@ -113,7 +116,7 @@ private:
void processFrame(const CANFrame &frame); void processFrame(const CANFrame &frame);
static UDS_HANDLER* mInstance; ISOTP_HANDLER *isoHandler;
}; };
+1 -1
View File
@@ -9,7 +9,7 @@ ISOTP_InterpreterWindow::ISOTP_InterpreterWindow(const QVector<CANFrame> *frames
ui->setupUi(this); ui->setupUi(this);
modelFrames = frames; modelFrames = frames;
decoder = ISOTP_HANDLER::getInstance(); decoder = new ISOTP_HANDLER;
decoder->setReception(true); decoder->setReception(true);
decoder->setProcessAll(true); decoder->setProcessAll(true);
+14 -11
View File
@@ -18,8 +18,10 @@ UDSScanWindow::UDSScanWindow(const QVector<CANFrame> *frames, QWidget *parent) :
waitTimer = new QTimer; waitTimer = new QTimer;
waitTimer->setInterval(100); waitTimer->setInterval(100);
udsHandler = new UDS_HANDLER;
connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int))); 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(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);
@@ -44,6 +46,7 @@ UDSScanWindow::~UDSScanWindow()
delete ui; delete ui;
waitTimer->stop(); waitTimer->stop();
delete waitTimer; delete waitTimer;
delete udsHandler;
} }
void UDSScanWindow::adaptiveToggled() void UDSScanWindow::adaptiveToggled()
@@ -184,17 +187,17 @@ void UDSScanWindow::scanUDS()
{ {
waitTimer->stop(); waitTimer->stop();
sendingFrames.clear(); sendingFrames.clear();
UDS_HANDLER::getInstance()->setReception(false); udsHandler->setReception(false);
UDS_HANDLER::getInstance()->setProcessAllIDs(false); udsHandler->setProcessAllIDs(false);
UDS_HANDLER::getInstance()->setFlowCtrl(false); udsHandler->setFlowCtrl(false);
currentlyRunning = false; currentlyRunning = false;
ui->btnScan->setText("Start Scan"); ui->btnScan->setText("Start Scan");
return; return;
} }
UDS_HANDLER::getInstance()->setReception(true); udsHandler->setReception(true);
UDS_HANDLER::getInstance()->setProcessAllIDs(true); udsHandler->setProcessAllIDs(true);
UDS_HANDLER::getInstance()->setFlowCtrl(true); udsHandler->setFlowCtrl(true);
waitTimer->setInterval(ui->spinDelay->value()); 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()) 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 (serviceShortName.length() < 3) serviceShortName = QString::number(sentFrame.service, 16);
if (msg.service == 0x40 + sendingFrames[currIdx].service) if (msg.service == 0x40 + sendingFrames[currIdx].service)
{ {
@@ -368,7 +371,7 @@ void UDSScanWindow::gotUDSReply(UDS_MESSAGE msg)
setupNodes(); setupNodes();
QTreeWidgetItem *nodeNegative = new QTreeWidgetItem(); QTreeWidgetItem *nodeNegative = new QTreeWidgetItem();
qDebug() << ui->spinNumBytes->value(); 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)); nodeNegative->setForeground(0, QBrush(Qt::darkRed));
nodeSubFunc->addChild(nodeNegative); nodeSubFunc->addChild(nodeNegative);
nodeSubFunc->setForeground(0, QBrush(Qt::darkRed)); nodeSubFunc->setForeground(0, QBrush(Qt::darkRed));
@@ -385,7 +388,7 @@ void UDSScanWindow::gotUDSReply(UDS_MESSAGE msg)
void UDSScanWindow::setupNodes() 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 (serviceShortName.length() < 3) serviceShortName = QString::number(sendingFrames[currIdx].service, 16);
if (!nodeID || nodeID->text(0) != Utility::formatHexNum(sendingFrames[currIdx].ID)) if (!nodeID || nodeID->text(0) != Utility::formatHexNum(sendingFrames[currIdx].ID))
@@ -427,7 +430,7 @@ void UDSScanWindow::sendNextMsg()
currIdx++; currIdx++;
if (currIdx < sendingFrames.count()) if (currIdx < sendingFrames.count())
{ {
UDS_HANDLER::getInstance()->sendUDSFrame(sendingFrames[currIdx]); udsHandler->sendUDSFrame(sendingFrames[currIdx]);
waitTimer->start(); waitTimer->start();
} }
else else
+1
View File
@@ -38,6 +38,7 @@ private slots:
private: private:
Ui::UDSScanWindow *ui; Ui::UDSScanWindow *ui;
const QVector<CANFrame> *modelFrames; const QVector<CANFrame> *modelFrames;
UDS_HANDLER *udsHandler;
QTimer *waitTimer; QTimer *waitTimer;
QList<UDS_MESSAGE> sendingFrames; QList<UDS_MESSAGE> sendingFrames;
QTreeWidgetItem *nodeID; QTreeWidgetItem *nodeID;