Implémentation des lectures des messages
Ajout de la page CAN View
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
#include "CANAnalyzer.h"
|
||||
#include "PCANInterface.h"
|
||||
#include "GeneralMessagesLogDispatcher.h"
|
||||
#include "CANDatabase.h"
|
||||
|
||||
CCANAnalyzer::CCANAnalyzer(QObject *parent) : QObject(parent)
|
||||
{
|
||||
mCANDriverIF = 0;
|
||||
mCANDatabase = 0;
|
||||
mIsCANInitialized = false;
|
||||
|
||||
mCANReadTimer = new QTimer;
|
||||
mCANReadTimer->setInterval(1000);
|
||||
mCANReadTimer->setSingleShot(true);
|
||||
connect(mCANReadTimer,SIGNAL(timeout()),this,SLOT(CANTimerExpired()));
|
||||
}
|
||||
|
||||
CCANAnalyzer::~CCANAnalyzer()
|
||||
{
|
||||
mCANDriverIF->DeInit(0);
|
||||
delete mCANReadTimer;
|
||||
while (!mLastMessagesList.isEmpty())
|
||||
{
|
||||
delete mLastMessagesList.takeFirst();
|
||||
}
|
||||
}
|
||||
|
||||
int CCANAnalyzer::Init(CPCANInterface *CANDriverInterface,CCANDatabase *CANDatabaseHandle)
|
||||
{
|
||||
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)
|
||||
{
|
||||
mIsCANInitialized = false;
|
||||
}
|
||||
|
||||
mCANReadTimer->start();
|
||||
mIsCANInitialized = true;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CCANAnalyzer::ReadCAN()
|
||||
{
|
||||
// TPCANMsg CANMsg;
|
||||
// TPCANTimestamp CANTimeStamp;
|
||||
|
||||
// // We execute the "Read" function of the PCANBasic
|
||||
// TPCANStatus stsResult = CAN_Read(PcanHandle, &CANMsg, &CANTimeStamp);
|
||||
|
||||
// if (stsResult != PCAN_ERROR_QRCVEMPTY)
|
||||
// {
|
||||
// // We process the received message
|
||||
// ProcessMessageCan(CANMsg, CANTimeStamp);
|
||||
// }
|
||||
|
||||
// return stsResult;
|
||||
}
|
||||
|
||||
void CCANAnalyzer::CANTimerExpired()
|
||||
{
|
||||
QList<CCANMessage *> NewMessagesList = mCANDriverIF->ReadCANFullBuffer(0x51U);
|
||||
|
||||
unsigned int DeletedPtrs = 0;
|
||||
if(NewMessagesList.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i = 0; i < NewMessagesList.size(); i++)
|
||||
{
|
||||
if(mLastMessagesList.isEmpty())
|
||||
{
|
||||
mLastMessagesList.append(NewMessagesList.at(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
//Check if new message ID for this device already exists in the list.
|
||||
bool found = false;
|
||||
for(int j = 0; j < mLastMessagesList.size(); j++)
|
||||
{
|
||||
if(NewMessagesList[i]->mCANChannel == mLastMessagesList[j]->mCANChannel &&
|
||||
NewMessagesList[i]->mCANMsgID == mLastMessagesList[j]->mCANMsgID)
|
||||
{
|
||||
//This message ID is already populated in the list. Update the value and delete the new instance
|
||||
mLastMessagesList[j]->mCANMsgData = NewMessagesList[i]->mCANMsgData;
|
||||
mLastMessagesList[j]->mCANMsgMicrosecs = NewMessagesList[i]->mCANMsgMicrosecs;
|
||||
mLastMessagesList[j]->mCANMsgMillisecs = NewMessagesList[i]->mCANMsgMillisecs;
|
||||
mLastMessagesList[j]->mCANMsgMillisecsOverflow = NewMessagesList[i]->mCANMsgMillisecsOverflow;
|
||||
|
||||
delete NewMessagesList[i];
|
||||
DeletedPtrs++;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!found)
|
||||
{
|
||||
//This is the first time we receive this message, just add it to the list.
|
||||
mLastMessagesList.append(NewMessagesList[i]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
NewMessagesList.clear();
|
||||
|
||||
mCANReadTimer->start();
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef CANANALYZER_H
|
||||
#define CANANALYZER_H
|
||||
|
||||
#include <QObject>
|
||||
#include "defines.h"
|
||||
#include <QTimer>
|
||||
#include <QList>
|
||||
#include "CANMessage.h"
|
||||
|
||||
class CPCANInterface;
|
||||
class CCANDatabase;
|
||||
|
||||
class CCANAnalyzer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CCANAnalyzer(QObject *parent = 0);
|
||||
~CCANAnalyzer();
|
||||
|
||||
CPCANInterface *mCANDriverIF;
|
||||
CCANDatabase *mCANDatabase;
|
||||
|
||||
QTimer *mCANReadTimer;
|
||||
|
||||
int Init(CPCANInterface *CANDriverInterface,CCANDatabase *CANDatabaseHandle);
|
||||
int ReadCAN();
|
||||
|
||||
QList<CCANMessage *> mLastMessagesList;
|
||||
|
||||
private:
|
||||
bool mIsCANInitialized;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void CANTimerExpired();
|
||||
};
|
||||
|
||||
#endif // CANANALYZER_H
|
||||
@@ -31,7 +31,7 @@ int CCANDatabase::LoadDatabaseFile(QString Filename)
|
||||
KvaDbMessageHnd mh = 0;
|
||||
KvaDbSignalHnd sh = 0;
|
||||
unsigned int flags = 0;
|
||||
char filename[] = "mazda_3_2019.dbc";
|
||||
char filename[] = "IVT-S_all-variations_12082020.dbc";
|
||||
|
||||
|
||||
// Open a database handle
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
#include "CANMessage.h"
|
||||
|
||||
|
||||
CCANMessage::CCANMessage()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CCANMessage::CCANMessage(const CCANMessage &Src)
|
||||
{
|
||||
*this = Src;
|
||||
}
|
||||
|
||||
CCANMessage::CCANMessage(const quint32 Channel, const TPCANMsg CANMsg, const TPCANTimestamp CANTimeStamp)
|
||||
{
|
||||
SetDataFromDriver(Channel,CANMsg,CANTimeStamp);
|
||||
}
|
||||
|
||||
int CCANMessage::SetDataFromDriver(quint32 Channel, TPCANMsg CANMsg, TPCANTimestamp CANTimeStamp)
|
||||
{
|
||||
mCANChannel = Channel;
|
||||
mCANMsgID = (unsigned long long)CANMsg.ID;
|
||||
mCANMsgLength = (unsigned char)CANMsg.LEN;
|
||||
mCANMsgType = CANMsg.MSGTYPE;
|
||||
mCANMsgData = QByteArray((const char*)&CANMsg.DATA);
|
||||
mCANMsgMicrosecs = CANTimeStamp.micros;
|
||||
mCANMsgMillisecs = CANTimeStamp.millis;
|
||||
mCANMsgMillisecsOverflow = CANTimeStamp.millis_overflow;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const CCANMessage &source)
|
||||
{
|
||||
out << source.mCANChannel
|
||||
<< source.mCANMsgID
|
||||
<< source.mCANMsgType
|
||||
<< source.mCANMsgLength
|
||||
<< source.mCANMsgData
|
||||
<< source.mCANMsgMillisecs
|
||||
<< source.mCANMsgMillisecsOverflow
|
||||
<< source.mCANMsgMicrosecs;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &in, CCANMessage &dest)
|
||||
{
|
||||
in >> dest.mCANChannel
|
||||
>> dest.mCANMsgID
|
||||
>> dest.mCANMsgType
|
||||
>> dest.mCANMsgLength
|
||||
>> dest.mCANMsgData
|
||||
>> dest.mCANMsgMillisecs
|
||||
>> dest.mCANMsgMillisecsOverflow
|
||||
>> dest.mCANMsgMicrosecs;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
CCANMessage& CCANMessage::operator=(const CCANMessage *source)
|
||||
{
|
||||
if(source == this)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
this->mCANChannel = source->mCANChannel;
|
||||
this->mCANMsgID = source->mCANMsgID;
|
||||
this->mCANMsgType = source->mCANMsgType;
|
||||
this->mCANMsgLength = source->mCANMsgLength;
|
||||
this->mCANMsgData = source->mCANMsgData;
|
||||
this->mCANMsgMillisecs = source->mCANMsgMillisecs;
|
||||
this->mCANMsgMillisecsOverflow = source->mCANMsgMillisecsOverflow;
|
||||
this->mCANMsgMicrosecs = source->mCANMsgMicrosecs;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef CANMESSAGE_H
|
||||
#define CANMESSAGE_H
|
||||
#include <QByteArray>
|
||||
#include <QDataStream>
|
||||
#include "PCANBasic.h"
|
||||
|
||||
class CCANMessage
|
||||
{
|
||||
public:
|
||||
CCANMessage();
|
||||
CCANMessage(const CCANMessage &Src);
|
||||
CCANMessage(const quint32 Channel,const TPCANMsg CANMsg,const TPCANTimestamp CANTimeStamp);
|
||||
|
||||
|
||||
quint32 mCANChannel; //Channel from which the message has been read
|
||||
|
||||
quint64 mCANMsgID; // 11/29-bit message identifier
|
||||
quint8 mCANMsgType; // Type of the message, using the PCAN interface driver encoding defined in PCANbasic.h
|
||||
quint8 mCANMsgLength; // Data Length Code of the message (0..8)
|
||||
QByteArray mCANMsgData; // Data of the message, max size = 8 bytes
|
||||
|
||||
//Timestamp
|
||||
quint64 mCANMsgMillisecs; // Base-value: milliseconds: 0.. 2^32-1
|
||||
quint32 mCANMsgMillisecsOverflow; // Roll-arounds of millis
|
||||
quint32 mCANMsgMicrosecs; // Microseconds: 0..999
|
||||
|
||||
CCANMessage &operator=(const CCANMessage *source);
|
||||
int SetDataFromDriver(quint32 Channel,TPCANMsg CANMsg,TPCANTimestamp CANTimeStamp);
|
||||
};
|
||||
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const CCANMessage &source);
|
||||
QDataStream &operator>>(QDataStream &in, CCANMessage &dest);
|
||||
|
||||
|
||||
#endif // CANMESSAGE_H
|
||||
@@ -46,7 +46,7 @@ CGeneralMessagesLogDispatcher::~CGeneralMessagesLogDispatcher()
|
||||
int CGeneralMessagesLogDispatcher::Init()
|
||||
{
|
||||
QString FileName;
|
||||
FileName = "./SystemLog.txt";
|
||||
FileName = "./Logs/SystemLog.txt";
|
||||
|
||||
mSystemLogFile = new QFile(FileName);
|
||||
if(mSystemLogFile)
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
static CGeneralMessagesLogDispatcher mSingleton;
|
||||
|
||||
CGeneralMessagesLogDispatcher();
|
||||
virtual ~CGeneralMessagesLogDispatcher();
|
||||
~CGeneralMessagesLogDispatcher();
|
||||
|
||||
int AddLogMessage(QString LogLine, bool AddToGUILogPanel = true, eGenMsgTextErrorStatus TxtErrStatus = GEN_MSG_TXT_NO_ERROR_STATUS);
|
||||
CGeneralStatusPage *mGeneralStatusPageHandle;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "CANViewerPage.h"
|
||||
#include "ui_CANViewerPage.h"
|
||||
|
||||
CCANViewerPage::CCANViewerPage(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::CCANViewerPage)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
CCANViewerPage::~CCANViewerPage()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef CANVIEWERPAGE_H
|
||||
#define CANVIEWERPAGE_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class CCANViewerPage;
|
||||
}
|
||||
|
||||
class CCANViewerPage : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CCANViewerPage(QWidget *parent = 0);
|
||||
~CCANViewerPage();
|
||||
|
||||
private:
|
||||
Ui::CCANViewerPage *ui;
|
||||
};
|
||||
|
||||
#endif // CANVIEWERPAGE_H
|
||||
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CCANViewerPage</class>
|
||||
<widget class="QWidget" name="CCANViewerPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1140</width>
|
||||
<height>581</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<widget class="QTableWidget" name="tableWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>60</y>
|
||||
<width>1051</width>
|
||||
<height>411</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>70</x>
|
||||
<y>500</y>
|
||||
<width>80</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Reset</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -26,10 +26,12 @@ CMainWindow::CMainWindow(QWidget *parent) :
|
||||
mGeneralStatusPage = new CGeneralStatusPage(this);
|
||||
mMainWindowWidget = new QTabWidget(this);
|
||||
mProgramSettingsPage = new CProgramSettingsPage(this);
|
||||
mCANViewerPage = new CCANViewerPage(this);
|
||||
|
||||
setCentralWidget(mMainWindowWidget);
|
||||
mMainWindowWidget->addTab(mGeneralStatusPage,"Status");
|
||||
mMainWindowWidget->addTab(mProgramSettingsPage,"Settings");
|
||||
mMainWindowWidget->addTab(mCANViewerPage,"CAN Data");
|
||||
|
||||
resize(1700,768);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "GeneralStatusPage.h"
|
||||
#include "ProgramSettingsPage.h"
|
||||
#include "CANViewerPage.h"
|
||||
|
||||
|
||||
namespace Ui {
|
||||
@@ -24,6 +25,7 @@ public:
|
||||
QTabWidget *mMainWindowWidget;
|
||||
CGeneralStatusPage *mGeneralStatusPage;
|
||||
CProgramSettingsPage *mProgramSettingsPage;
|
||||
CCANViewerPage *mCANViewerPage;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@@ -20,11 +20,15 @@ COtarcikCan::COtarcikCan(QObject *parent) : QObject(parent)
|
||||
{
|
||||
mPCANInterface = new CPCANInterface;
|
||||
mCANDatabase = new CCANDatabase;
|
||||
mCANAnalyzer = new CCANAnalyzer(mPCANInterface);
|
||||
}
|
||||
|
||||
COtarcikCan::~COtarcikCan()
|
||||
{
|
||||
delete mCANAnalyzer;
|
||||
delete mPCANInterface;
|
||||
delete mCANDatabase;
|
||||
|
||||
}
|
||||
|
||||
int COtarcikCan::Start()
|
||||
@@ -34,9 +38,7 @@ int COtarcikCan::Start()
|
||||
CGeneralMessagesLogDispatcher::instance()->BindGuiPageHandle(w.mGeneralStatusPage);
|
||||
CGeneralMessagesLogDispatcher::instance()->Init();
|
||||
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage("OtarcikCan modules starting...");
|
||||
|
||||
mPCANInterface->Init();
|
||||
mCANAnalyzer->Init(mPCANInterface,mCANDatabase);
|
||||
|
||||
mCANDatabase->Init();
|
||||
mCANDatabase->LoadDatabaseFile("");
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "PCANInterface.h"
|
||||
#include "GeneralMessagesLogDispatcher.h"
|
||||
#include "CANDatabase.h"
|
||||
#include "CANAnalyzer.h"
|
||||
|
||||
class COtarcikCan : public QObject
|
||||
{
|
||||
@@ -18,9 +19,12 @@ public:
|
||||
int Start();
|
||||
|
||||
private:
|
||||
|
||||
CCANAnalyzer *mCANAnalyzer;
|
||||
CPCANInterface *mPCANInterface;
|
||||
CCANDatabase *mCANDatabase;
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#ifndef __PCANBASICH__
|
||||
#define __PCANBASICH__
|
||||
|
||||
#include <windows.h>
|
||||
////////////////////////////////////////////////////////////
|
||||
// Value definitions
|
||||
////////////////////////////////////////////////////////////
|
||||
@@ -582,4 +583,4 @@ TPCANStatus __stdcall CAN_LookUpChannel(
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
#include "PCANInterface.h"
|
||||
#include "GeneralMessagesLogDispatcher.h"
|
||||
//#include "CANMessage.h"
|
||||
|
||||
|
||||
|
||||
CPCANInterface::CPCANInterface(QObject *parent) : QObject(parent)
|
||||
@@ -38,6 +40,7 @@ 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);
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -48,8 +51,43 @@ int CPCANInterface::Init()
|
||||
|
||||
int CPCANInterface::DeInit(unsigned short Channel)
|
||||
{
|
||||
CAN_Uninitialize(Channel);
|
||||
CAN_Uninitialize(PCAN_USBBUS1);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
QList<CCANMessage *> CPCANInterface::ReadCANFullBuffer(unsigned short Channel)
|
||||
{
|
||||
TPCANMsg CANMsg;
|
||||
TPCANTimestamp CANTimeStamp;
|
||||
TPCANStatus stsResult;
|
||||
int cnt = 0;
|
||||
|
||||
QList<CCANMessage *> MessagesList;
|
||||
MessagesList.clear();
|
||||
|
||||
do
|
||||
{
|
||||
// We execute the "Read" function of the PCANBasic
|
||||
stsResult = CAN_Read(Channel, &CANMsg, &CANTimeStamp);
|
||||
if (stsResult != PCAN_ERROR_QRCVEMPTY)
|
||||
{
|
||||
CCANMessage *NewMsg = new CCANMessage(Channel,CANMsg,CANTimeStamp);
|
||||
MessagesList.append(NewMsg);
|
||||
|
||||
// We process the received message
|
||||
qDebug("Type: 0x%X ",CANMsg.MSGTYPE);
|
||||
qDebug("ID: 0x%X",CANMsg.ID);
|
||||
qDebug("Length: %d",CANMsg.LEN);
|
||||
qDebug("Time: micros %d - millis %d - overflow %d", CANTimeStamp.micros, CANTimeStamp.millis, CANTimeStamp.millis_overflow);
|
||||
// qDebug("Data: " << GetDataString(CANMsg.DATA, CANMsg.MSGTYPE, GetLengthFromDLC(CANMsg.DLC)) << "\n";
|
||||
qDebug("Count: %d",cnt++);
|
||||
qDebug("----------------------------------------------------------");
|
||||
|
||||
}
|
||||
}
|
||||
while (!(stsResult & PCAN_ERROR_QRCVEMPTY));
|
||||
|
||||
return MessagesList;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,14 @@
|
||||
#define PCANINTERFACE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <windows.h>
|
||||
#include "CANMessage.h"
|
||||
#include "PCANBasic.h"
|
||||
|
||||
#include <QList>
|
||||
|
||||
|
||||
//class CCANMessage;
|
||||
|
||||
class CPCANInterface : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -13,6 +18,9 @@ public:
|
||||
int Init();
|
||||
int DeInit(unsigned short Channel);
|
||||
|
||||
QList<CCANMessage*> ReadCANFullBuffer(unsigned short Channel);
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
Reference in New Issue
Block a user