Continuage de dev

This commit is contained in:
jfmartel 2023-01-18 17:57:12 -05:00
parent 20e46bb60a
commit c6abea01d5
17 changed files with 461 additions and 80 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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;
}
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);
}

View File

@ -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;

View File

@ -2,5 +2,14 @@
CCANDBMessage::CCANDBMessage()
{
// QTimer *testTimer = new QTimer;
// connect(testTimer,&QTimer::timeout,this,&CCANDBMessage::SlotTest);
}
void CCANDBMessage::SlotTest()
{
}

View File

@ -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

View File

@ -16,8 +16,12 @@ CCANDatabase::~CCANDatabase()
}
int CCANDatabase::Init()
int CCANDatabase::Init(QString DatabaseFileName)
{
mDatabaseFileName = DatabaseFileName;
LoadDatabaseFile(DatabaseFileName);
return RET_OK;
}

View File

@ -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:

View File

@ -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;
}

View File

@ -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:

View File

@ -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;
}

View File

@ -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:

Binary file not shown.

View File

@ -0,0 +1,119 @@
/****************************************************************************
** Meta object code from reading C++ file 'CANDBMessage.h'
**
** Created by: The Qt Meta Object Compiler version 67 (Qt 5.14.2)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
#include <memory>
#include "../Sources/CANDatabase/CANDBMessage.h"
#include <QtCore/qbytearray.h>
#include <QtCore/qmetatype.h>
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'CANDBMessage.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 67
#error "This file was generated using the moc from 5.14.2. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif
QT_BEGIN_MOC_NAMESPACE
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
struct qt_meta_stringdata_CCANDBMessage_t {
QByteArrayData data[3];
char stringdata0[24];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
qptrdiff(offsetof(qt_meta_stringdata_CCANDBMessage_t, stringdata0) + ofs \
- idx * sizeof(QByteArrayData)) \
)
static const qt_meta_stringdata_CCANDBMessage_t qt_meta_stringdata_CCANDBMessage = {
{
QT_MOC_LITERAL(0, 0, 13), // "CCANDBMessage"
QT_MOC_LITERAL(1, 14, 8), // "SlotTest"
QT_MOC_LITERAL(2, 23, 0) // ""
},
"CCANDBMessage\0SlotTest\0"
};
#undef QT_MOC_LITERAL
static const uint qt_meta_data_CCANDBMessage[] = {
// content:
8, // revision
0, // classname
0, 0, // classinfo
1, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
0, // signalCount
// slots: name, argc, parameters, tag, flags
1, 0, 19, 2, 0x0a /* Public */,
// slots: parameters
QMetaType::Void,
0 // eod
};
void CCANDBMessage::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
if (_c == QMetaObject::InvokeMetaMethod) {
auto *_t = static_cast<CCANDBMessage *>(_o);
Q_UNUSED(_t)
switch (_id) {
case 0: _t->SlotTest(); break;
default: ;
}
}
Q_UNUSED(_a);
}
QT_INIT_METAOBJECT const QMetaObject CCANDBMessage::staticMetaObject = { {
QMetaObject::SuperData::link<CCANAnalyzer::staticMetaObject>(),
qt_meta_stringdata_CCANDBMessage.data,
qt_meta_data_CCANDBMessage,
qt_static_metacall,
nullptr,
nullptr
} };
const QMetaObject *CCANDBMessage::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
}
void *CCANDBMessage::qt_metacast(const char *_clname)
{
if (!_clname) return nullptr;
if (!strcmp(_clname, qt_meta_stringdata_CCANDBMessage.stringdata0))
return static_cast<void*>(this);
return CCANAnalyzer::qt_metacast(_clname);
}
int CCANDBMessage::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = CCANAnalyzer::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 1)
qt_static_metacall(this, _c, _id, _a);
_id -= 1;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 1)
*reinterpret_cast<int*>(_a[0]) = -1;
_id -= 1;
}
return _id;
}
QT_WARNING_POP
QT_END_MOC_NAMESPACE

View File

@ -64,7 +64,7 @@ void CCANDevice::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id,
}
QT_INIT_METAOBJECT const QMetaObject CCANDevice::staticMetaObject = { {
QMetaObject::SuperData::link<CCANDatabase::staticMetaObject>(),
QMetaObject::SuperData::link<QObject::staticMetaObject>(),
qt_meta_stringdata_CCANDevice.data,
qt_meta_data_CCANDevice,
qt_static_metacall,
@ -83,14 +83,12 @@ void *CCANDevice::qt_metacast(const char *_clname)
if (!_clname) return nullptr;
if (!strcmp(_clname, qt_meta_stringdata_CCANDevice.stringdata0))
return static_cast<void*>(this);
if (!strcmp(_clname, "CCANAnalyzer"))
return static_cast< CCANAnalyzer*>(this);
return CCANDatabase::qt_metacast(_clname);
return QObject::qt_metacast(_clname);
}
int CCANDevice::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = CCANDatabase::qt_metacall(_c, _id, _a);
_id = QObject::qt_metacall(_c, _id, _a);
return _id;
}
QT_WARNING_POP

View File

@ -20,4 +20,5 @@ debug/moc_ProgramSettingsPage.o
debug/moc_CANAnalyzer.o
debug/moc_CANViewerPage.o
debug/moc_CANDatabase.o
debug/moc_CANDBMessage.o
debug/moc_CANDevice.o

View File

@ -20,4 +20,5 @@ release/moc_ProgramSettingsPage.o
release/moc_CANAnalyzer.o
release/moc_CANViewerPage.o
release/moc_CANDatabase.o
release/moc_CANDBMessage.o
release/moc_CANDevice.o