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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user