Continuage de dev
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#include "CANAnalyzer.h"
|
||||
#include "PCANInterface.h"
|
||||
|
||||
#include "GeneralMessagesLogDispatcher.h"
|
||||
#include "CANDatabase.h"
|
||||
#include "OtarcikCan.h"
|
||||
@@ -7,10 +7,9 @@
|
||||
|
||||
CCANAnalyzer::CCANAnalyzer(QObject *parent) : QObject(parent)
|
||||
{
|
||||
mCANDriverIF = 0;
|
||||
mCANDatabase = 0;
|
||||
mCANDriverIF = new CPCANInterface;
|
||||
mIsCANInitialized = false;
|
||||
mProgramPtr = 0;
|
||||
mDevicePtr = 0;
|
||||
|
||||
mCANReadTimer = new QTimer;
|
||||
mCANReadTimer->setInterval(200);
|
||||
@@ -20,7 +19,8 @@ CCANAnalyzer::CCANAnalyzer(QObject *parent) : QObject(parent)
|
||||
|
||||
CCANAnalyzer::~CCANAnalyzer()
|
||||
{
|
||||
mCANDriverIF->DeInit(0);
|
||||
mCANDriverIF->DeInit();
|
||||
delete mCANDriverIF;
|
||||
delete mCANReadTimer;
|
||||
while (!mLastMessagesList.isEmpty())
|
||||
{
|
||||
@@ -28,26 +28,22 @@ CCANAnalyzer::~CCANAnalyzer()
|
||||
}
|
||||
}
|
||||
|
||||
int CCANAnalyzer::Init(CPCANInterface *CANDriverInterface,CCANDatabase *CANDatabaseHandle)
|
||||
int CCANAnalyzer::Init(TPCANHandle CANDeviceChannel,TPCANBaudrate CANDeviceBaudrate)
|
||||
{
|
||||
if(CANDriverInterface == 0 || CANDatabaseHandle == 0)
|
||||
{
|
||||
return RET_GENERAL_ERROR;
|
||||
mIsCANInitialized = false;
|
||||
}
|
||||
|
||||
mCANDriverIF = CANDriverInterface;
|
||||
mCANDatabase = CANDatabaseHandle;
|
||||
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage("OtarcikCan modules starting...");
|
||||
|
||||
if(mCANDriverIF->Init() != RET_OK)
|
||||
if(mCANDriverIF->Init(CANDeviceChannel,CANDeviceBaudrate) != RET_OK)
|
||||
{
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage("Could not initialize CAN hardware",true,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_ERROR_STATUS);
|
||||
mIsCANInitialized = false;
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
mCANReadTimer->start();
|
||||
mIsCANInitialized = true;
|
||||
}
|
||||
|
||||
mCANReadTimer->start();
|
||||
mIsCANInitialized = true;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
@@ -67,6 +63,7 @@ int CCANAnalyzer::ReadCAN()
|
||||
// }
|
||||
|
||||
// return stsResult;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void CCANAnalyzer::CANTimerExpired()
|
||||
@@ -120,5 +117,5 @@ void CCANAnalyzer::CANTimerExpired()
|
||||
|
||||
mCANReadTimer->start();
|
||||
|
||||
mProgramPtr->UpdateCANViewerDataRequest(mLastMessagesList);
|
||||
// mProgramPtr->UpdateCANViewerDataRequest(mLastMessagesList);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,9 @@
|
||||
#include <QTimer>
|
||||
#include <QList>
|
||||
#include "CANMessage.h"
|
||||
#include "PCANInterface.h"
|
||||
|
||||
class CPCANInterface;
|
||||
class CCANDatabase;
|
||||
class COtarcikCan;
|
||||
class CCANDevice;
|
||||
|
||||
class CCANAnalyzer : public QObject
|
||||
{
|
||||
@@ -17,14 +16,13 @@ class CCANAnalyzer : public QObject
|
||||
public:
|
||||
explicit CCANAnalyzer(QObject *parent = 0);
|
||||
~CCANAnalyzer();
|
||||
COtarcikCan *mProgramPtr;
|
||||
CCANDevice *mDevicePtr;
|
||||
|
||||
CPCANInterface *mCANDriverIF;
|
||||
CCANDatabase *mCANDatabase;
|
||||
|
||||
QTimer *mCANReadTimer;
|
||||
|
||||
int Init(CPCANInterface *CANDriverInterface,CCANDatabase *CANDatabaseHandle);
|
||||
int Init(TPCANHandle CANDeviceChannel,TPCANBaudrate CANDeviceBaudrate);
|
||||
int ReadCAN();
|
||||
|
||||
QList<CCANMessage *> mLastMessagesList;
|
||||
|
||||
@@ -2,5 +2,14 @@
|
||||
|
||||
CCANDBMessage::CCANDBMessage()
|
||||
{
|
||||
// QTimer *testTimer = new QTimer;
|
||||
|
||||
// connect(testTimer,&QTimer::timeout,this,&CCANDBMessage::SlotTest);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CCANDBMessage::SlotTest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -2,11 +2,17 @@
|
||||
#define CANDBMESSAGE_H
|
||||
#include "CANDBSignal.h"
|
||||
#include <QList>
|
||||
#include "CANAnalyzer.h"
|
||||
|
||||
class CCANDBMessage
|
||||
class CCANDBMessage : public CCANAnalyzer
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CCANDBMessage();
|
||||
|
||||
public slots:
|
||||
void SlotTest();
|
||||
};
|
||||
|
||||
#endif // CANDBMESSAGE_H
|
||||
|
||||
@@ -16,8 +16,12 @@ CCANDatabase::~CCANDatabase()
|
||||
|
||||
}
|
||||
|
||||
int CCANDatabase::Init()
|
||||
int CCANDatabase::Init(QString DatabaseFileName)
|
||||
{
|
||||
mDatabaseFileName = DatabaseFileName;
|
||||
|
||||
LoadDatabaseFile(DatabaseFileName);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,11 @@ public:
|
||||
explicit CCANDatabase(QObject *parent = 0);
|
||||
~CCANDatabase();
|
||||
|
||||
int Init();
|
||||
int Init(QString DatabaseFileName);
|
||||
int LoadDatabaseFile(QString Filename);
|
||||
|
||||
private:
|
||||
QString mDatabaseFileName;
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
@@ -4,3 +4,16 @@ CCANDevice::CCANDevice(QObject *parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CCANDevice::~CCANDevice()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CCANDevice::Init(QString DatabaseFileName, unsigned short CANDeviceID, unsigned short CANDeviceBaudRate)
|
||||
{
|
||||
mCANDatabase.Init(DatabaseFileName);
|
||||
mCANAnalyzer.Init(CANDeviceID,CANDeviceBaudRate);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef CANDEVICE_H
|
||||
#define CANDEVICE_H
|
||||
|
||||
#include "defines.h"
|
||||
#include <QObject>
|
||||
#include "CANAnalyzer.h"
|
||||
#include "CANMessage.h"
|
||||
@@ -8,13 +9,23 @@
|
||||
#include "CANDatabase.h"
|
||||
#include <QList>
|
||||
|
||||
class CCANDevice : public CCANDatabase, public CCANAnalyzer
|
||||
class CCANDevice : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CCANDevice(QObject *parent = 0);
|
||||
~CCANDevice();
|
||||
|
||||
CCANAnalyzer mCANAnalyzer;
|
||||
int Init(QString DatabaseFileName, unsigned short CANDeviceID, unsigned short CANDeviceBaudRate);
|
||||
|
||||
|
||||
private:
|
||||
QString mDeviceDatabaseFileName;
|
||||
unsigned int mCANDeviceID;
|
||||
|
||||
|
||||
CCANAnalyzer mCANAnalyzer; //The module that handles the USB puck and decodes the data
|
||||
CCANDatabase mCANDatabase; //The device's database loaded from dbc file
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
@@ -22,14 +22,20 @@
|
||||
|
||||
CPCANInterface::CPCANInterface(QObject *parent) : QObject(parent)
|
||||
{
|
||||
//Init only... values not used.
|
||||
mInterfaceBaudrate = PCAN_BAUD_500K;
|
||||
mInterfaceCANHandle = PCAN_USBBUS1;
|
||||
CANInterfaceOpened = false;
|
||||
}
|
||||
|
||||
int CPCANInterface::Init()
|
||||
int CPCANInterface::Init(TPCANHandle CANDeviceChannel, TPCANBaudrate CANBaudRate)
|
||||
{
|
||||
QString LogMsg;
|
||||
mInterfaceBaudrate = CANBaudRate;
|
||||
mInterfaceCANHandle = CANDeviceChannel;
|
||||
|
||||
TPCANStatus Result;
|
||||
Result = CAN_Initialize(PCAN_USBBUS1, PCAN_BAUD_500K);
|
||||
// Result = CAN_Initialize(PCAN_USBBUS1, PCAN_BAUD_500K);
|
||||
Result = CAN_Initialize(CANDeviceChannel, CANBaudRate);
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Initializing PCAN USB module. Channel:%1, Baudrate:%2").arg(PCAN_USBBUS1).arg(PCAN_BAUD_500K));
|
||||
|
||||
if(Result != PCAN_ERROR_OK)
|
||||
@@ -40,18 +46,32 @@ int CPCANInterface::Init()
|
||||
CAN_GetErrorText(Result, 0, strMsg);
|
||||
qDebug("%s",strMsg);
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Could not initialize PCAN USB module. Error:%1").arg(strMsg),true,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_ERROR_STATUS);
|
||||
CANInterfaceOpened = false;
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
CANInterfaceOpened = true;
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage("PCAN USB init SUCCESS");
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CPCANInterface::DeInit(unsigned short Channel)
|
||||
int CPCANInterface::DeInit()
|
||||
{
|
||||
CAN_Uninitialize(PCAN_USBBUS1);
|
||||
TPCANStatus Result;
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Uninitializing PCAN USB module ID %1").arg(mInterfaceCANHandle));
|
||||
Result = CAN_Uninitialize(mInterfaceCANHandle) != PCAN_ERROR_OK;
|
||||
if(Result)
|
||||
{
|
||||
char strMsg[256];
|
||||
CAN_GetErrorText(Result, 0, strMsg);
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Could not uninitialize PCAN USB module. Error:%1").arg(strMsg),true,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_ERROR_STATUS);
|
||||
}
|
||||
else
|
||||
{
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage("Uninitializing PCAN USB module...");
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
@@ -15,11 +15,16 @@ class CPCANInterface : public QObject
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CPCANInterface(QObject *parent = 0);
|
||||
int Init();
|
||||
int DeInit(unsigned short Channel);
|
||||
int Init(TPCANHandle CANDeviceChannel, TPCANBaudrate CANBaudRate);
|
||||
int DeInit();
|
||||
bool IsInterfaceOpened(){return CANInterfaceOpened;}
|
||||
|
||||
bool CANInterfaceOpened;
|
||||
QList<CCANMessage*> ReadCANFullBuffer(unsigned short Channel);
|
||||
|
||||
private:
|
||||
TPCANBaudrate mInterfaceBaudrate;
|
||||
TPCANHandle mInterfaceCANHandle;
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user