Dev
This commit is contained in:
@@ -11,9 +11,10 @@ CCANAnalyzer::CCANAnalyzer(QObject *parent) : QObject(parent)
|
||||
mIsCANInitialized = false;
|
||||
mDevicePtr = 0;
|
||||
mDeviceMessagesList = 0;
|
||||
mCANPollPeriod = 0;
|
||||
|
||||
mCANReadTimer = new QTimer;
|
||||
mCANReadTimer->setInterval(200);
|
||||
mCANReadTimer->setInterval(1000);
|
||||
mCANReadTimer->setSingleShot(true);
|
||||
connect(mCANReadTimer,SIGNAL(timeout()),this,SLOT(CANTimerExpired()));
|
||||
}
|
||||
@@ -25,16 +26,21 @@ CCANAnalyzer::~CCANAnalyzer()
|
||||
delete mCANReadTimer;
|
||||
}
|
||||
|
||||
int CCANAnalyzer::Init(TPCANHandle CANDeviceChannel, TPCANBaudrate CANDeviceBaudrate, QList<CCANMessage *> *MsgList)
|
||||
int CCANAnalyzer::Init(TPCANHandle CANDeviceChannel, TPCANBaudrate CANDeviceBaudrate, QList<CCANMessage *> *MsgList, unsigned int PollPeriod)
|
||||
{
|
||||
|
||||
if(MsgList == 0)
|
||||
{
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
if(PollPeriod < 200)
|
||||
{
|
||||
PollPeriod = 200;
|
||||
qDebug("CANAnalyzer:: Trying to init with poll period lower tan 200ms");
|
||||
}
|
||||
|
||||
|
||||
mCANDeviceChannel = CANDeviceChannel;
|
||||
mCANPollPeriod = PollPeriod;
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage("Démarrage d'un module CAN...");
|
||||
|
||||
mDeviceMessagesList = MsgList;
|
||||
@@ -47,7 +53,7 @@ int CCANAnalyzer::Init(TPCANHandle CANDeviceChannel, TPCANBaudrate CANDeviceBaud
|
||||
}
|
||||
else
|
||||
{
|
||||
// mCANReadTimer->start();
|
||||
mCANReadTimer->start(mCANPollPeriod);
|
||||
mIsCANInitialized = true;
|
||||
}
|
||||
|
||||
@@ -94,6 +100,8 @@ void CCANAnalyzer::CANTimerExpired()
|
||||
delete NewMessagesList.takeFirst();
|
||||
}
|
||||
|
||||
mDevicePtr->NewMessageParsed();
|
||||
|
||||
|
||||
if(NewMessagesList.isEmpty())
|
||||
{
|
||||
@@ -101,43 +109,6 @@ void CCANAnalyzer::CANTimerExpired()
|
||||
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();
|
||||
|
||||
|
||||
@@ -21,8 +21,9 @@ public:
|
||||
CPCANInterface *mCANDriverIF;
|
||||
|
||||
QTimer *mCANReadTimer;
|
||||
unsigned int mCANPollPeriod;
|
||||
|
||||
int Init(TPCANHandle CANDeviceChannel, TPCANBaudrate CANDeviceBaudrate, QList<CCANMessage *> *MsgList);
|
||||
int Init(TPCANHandle CANDeviceChannel, TPCANBaudrate CANDeviceBaudrate, QList<CCANMessage *> *MsgList, unsigned int PollPeriod);
|
||||
int ReadCAN();
|
||||
|
||||
QList<CCANMessage *> *mDeviceMessagesList;
|
||||
|
||||
@@ -40,6 +40,7 @@ int CCANDatabase::LoadDatabaseFile(QString Filename)
|
||||
|
||||
// Load the database file
|
||||
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Chargement de la base de données %1").arg(Filename),true);
|
||||
status = kvaDbReadFile(mDatabaseDriverHandle, Filename.toLocal8Bit().data());
|
||||
if (status != kvaDbOK)
|
||||
{
|
||||
|
||||
@@ -1,9 +1,32 @@
|
||||
#include "CANDevice.h"
|
||||
#include "OtarcikCan.h"
|
||||
|
||||
CCANDevice::CCANDevice(QObject *parent)
|
||||
{
|
||||
mMessageList.clear();
|
||||
mMessagesListLoaded = false;
|
||||
mCANAnalyzer.mDevicePtr = this;
|
||||
mProgramPtr = 0;
|
||||
mCANDeviceDatabaseFilename.clear();
|
||||
mCANDeviceID = -1;
|
||||
mCANDeviceBaudrate = -1;
|
||||
mDeviceDescription.clear();
|
||||
mDeviceName.clear();
|
||||
mDevicePollPeriod = 0;
|
||||
}
|
||||
|
||||
CCANDevice::CCANDevice(CCANDevice &Other)
|
||||
{
|
||||
mMessageList.clear();
|
||||
mMessagesListLoaded = false;
|
||||
mCANAnalyzer.mDevicePtr = this;
|
||||
mProgramPtr = 0;
|
||||
|
||||
mCANDeviceID = Other.mCANDeviceID;
|
||||
mCANDeviceBaudrate = Other.mCANDeviceBaudrate;
|
||||
mCANDeviceDatabaseFilename = Other.mCANDeviceDatabaseFilename;
|
||||
mDeviceName = Other.mDeviceName;
|
||||
mDeviceDescription = Other.mDeviceDescription;
|
||||
}
|
||||
|
||||
CCANDevice::~CCANDevice()
|
||||
@@ -14,26 +37,98 @@ CCANDevice::~CCANDevice()
|
||||
}
|
||||
}
|
||||
|
||||
int CCANDevice::Init(QString DatabaseFileName, TPCANHandle CANDeviceID, TPCANBaudrate CANDeviceBaudRate, QString DevDescription, QString DeviceName)
|
||||
int CCANDevice::Init()
|
||||
{
|
||||
mCANDeviceID = CANDeviceID;
|
||||
mCANDeviceBaudrate = CANDeviceBaudRate;
|
||||
mCANDeviceDatabaseFilename = DatabaseFileName;
|
||||
mDeviceDescription = DevDescription;
|
||||
mDeviceName = DeviceName;
|
||||
if(mCANDeviceID < 0 || mCANDeviceBaudrate < 0 || mDevicePollPeriod == 0 || mCANDeviceDatabaseFilename.isEmpty() || mDeviceName.isEmpty())
|
||||
{
|
||||
qDebug("CCANDevice: trying to initialize a CCANDevice with invalid parameters");
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
|
||||
if(mCANDatabase.Init(DatabaseFileName) == RET_OK)
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Initialisation du dispositif [%1]").arg(mDeviceName));
|
||||
|
||||
if(mCANDatabase.Init(mCANDeviceDatabaseFilename) == RET_OK)
|
||||
{
|
||||
if(mCANDatabase.BuildMessageList(&mMessageList) == RET_OK)
|
||||
{
|
||||
mMessagesListLoaded = true;
|
||||
mProgramPtr->InitCANViewer(&mMessageList);
|
||||
}
|
||||
else
|
||||
{
|
||||
mMessagesListLoaded = false;
|
||||
}
|
||||
}
|
||||
mCANAnalyzer.Init(CANDeviceID,CANDeviceBaudRate,&mMessageList);
|
||||
if(mCANAnalyzer.Init(mCANDeviceID,mCANDeviceBaudrate,&mMessageList,mDevicePollPeriod) != RET_OK)
|
||||
{
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Le dispositif [%1] n'a pas pu s'initialiser").arg(mDeviceName),true,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_ERROR_STATUS);
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Dispositif [%1] initialisé avec succès!").arg(mDeviceName));
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CCANDevice::Init(QString DatabaseFileName, TPCANHandle CANDeviceID, TPCANBaudrate CANDeviceBaudRate, QString DevDescription, QString DeviceName, unsigned int DevicePollPeriod)
|
||||
{
|
||||
mCANDeviceID = CANDeviceID;
|
||||
mCANDeviceBaudrate = CANDeviceBaudRate;
|
||||
mCANDeviceDatabaseFilename = DatabaseFileName;
|
||||
mDeviceDescription = DevDescription;
|
||||
mDeviceName = DeviceName;
|
||||
mDevicePollPeriod = DevicePollPeriod;
|
||||
|
||||
Init();
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CCANDevice::NewMessageParsed()
|
||||
{
|
||||
mProgramPtr->UpdateCANViewerDataRequest(&mMessageList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const CCANDevice &source)
|
||||
{
|
||||
out << source.mCANDeviceID
|
||||
<< source.mCANDeviceBaudrate
|
||||
<< source.mCANDeviceDatabaseFilename
|
||||
<< source.mDeviceDescription
|
||||
<< source.mDeviceName
|
||||
<< source.mDevicePollPeriod;
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &in, CCANDevice &dest)
|
||||
{
|
||||
in >> dest.mCANDeviceID
|
||||
>> dest.mCANDeviceBaudrate
|
||||
>> dest.mCANDeviceDatabaseFilename
|
||||
>> dest.mDeviceDescription
|
||||
>> dest.mDeviceName
|
||||
>> dest.mDevicePollPeriod;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
//CAREFUL!!! OPERATOR = DOES NOT COPY THE MESSAGES, ONLY THE DEVICE DESCRIPTION !!//
|
||||
CCANDevice& CCANDevice::operator=(const CCANDevice *source)
|
||||
{
|
||||
if(source == this)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
this->mCANDeviceID = source->mCANDeviceID;
|
||||
this->mCANDeviceBaudrate = source->mCANDeviceBaudrate;
|
||||
this->mCANDeviceDatabaseFilename = source->mCANDeviceDatabaseFilename;
|
||||
this->mDeviceDescription = source->mDeviceDescription;
|
||||
this->mDeviceName = source->mDeviceName;
|
||||
this->mDevicePollPeriod = source->mDevicePollPeriod;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -10,15 +10,18 @@
|
||||
#include <QList>
|
||||
#include "PCANBasic.h"
|
||||
|
||||
class COtarcikCan;
|
||||
|
||||
class CCANDevice : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CCANDevice(QObject *parent = 0);
|
||||
CCANDevice(CCANDevice &Other);
|
||||
~CCANDevice();
|
||||
|
||||
int Init(QString DatabaseFileName, TPCANHandle CANDeviceID, TPCANBaudrate CANDeviceBaudRate, QString DevDescription, QString DeviceName);
|
||||
|
||||
int Init(QString DatabaseFileName, TPCANHandle CANDeviceID, TPCANBaudrate CANDeviceBaudRate, QString DevDescription, QString DeviceName, unsigned int DevicePollPeriod);
|
||||
int Init();
|
||||
|
||||
public:
|
||||
TPCANHandle mCANDeviceID;
|
||||
@@ -26,6 +29,8 @@ public:
|
||||
QString mCANDeviceDatabaseFilename;
|
||||
QString mDeviceDescription;
|
||||
QString mDeviceName;
|
||||
COtarcikCan *mProgramPtr;
|
||||
unsigned int mDevicePollPeriod;
|
||||
|
||||
bool mMessagesListLoaded;
|
||||
CCANAnalyzer mCANAnalyzer; //The module that handles the USB puck and decodes the data
|
||||
@@ -33,9 +38,19 @@ public:
|
||||
|
||||
QList<CCANMessage*> mMessageList;
|
||||
|
||||
CCANDevice &operator=(const CCANDevice *source);
|
||||
|
||||
int NewMessageParsed();
|
||||
|
||||
private:
|
||||
bool mConfigSet;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
};
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const CCANDevice &source);
|
||||
QDataStream &operator>>(QDataStream &in, CCANDevice &dest);
|
||||
|
||||
#endif // CANDEVICE_H
|
||||
|
||||
@@ -68,20 +68,26 @@ int CCANMessage::UpdateValue(CCANMessage *NewDeviceMessage)
|
||||
|
||||
mCANMsgData = QByteArray(NewDeviceMessage->mCANMsgData);
|
||||
|
||||
// if(NewDeviceMessage->mCANMsgID == 0x524)
|
||||
// int toto = 5;
|
||||
|
||||
mCANRawDataMotorola = mCANRawDataIntel= 0;
|
||||
|
||||
for(int i = 0; i < mCANMsgLength; i++)
|
||||
for(unsigned int i = 0; i < mCANMsgLength; i++)
|
||||
{
|
||||
mCANRawDataIntel += mCANMsgData[i];
|
||||
mCANRawDataMotorola += mCANMsgData[(mCANMsgLength - 1) - i];
|
||||
mCANRawDataIntel += ((unsigned char)(mCANMsgData[i]) & 0xFF);
|
||||
mCANRawDataMotorola += ((unsigned char)(mCANMsgData[(mCANMsgLength - 1) - i]) & 0xFF);
|
||||
|
||||
mCANRawDataIntel <<= 8;
|
||||
mCANRawDataMotorola <<= 8;
|
||||
if(i < mCANMsgLength-1)
|
||||
{
|
||||
mCANRawDataIntel <<= 8;
|
||||
mCANRawDataMotorola <<= 8;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < mSignalsList.size(); i++)
|
||||
{
|
||||
mSignalsList.at(i)->ComputeNewSignalValue(mCANRawDataMotorola,mCANRawDataIntel);
|
||||
mSignalsList.at(i)->ComputeNewSignalValue(mCANRawDataIntel, mCANMsgLength);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,32 +1,45 @@
|
||||
#include "CANSignal.h"
|
||||
#include "defines.h"
|
||||
|
||||
|
||||
CCANSignal::CCANSignal()
|
||||
{
|
||||
mEncoding = CAN_SIGNAL_ENCODING_INVALID;
|
||||
|
||||
}
|
||||
|
||||
int CCANSignal::ComputeNewSignalValue(quint64 MotorolaValue, quint64 IntelValue)
|
||||
int CCANSignal::ComputeNewSignalValue(quint64 NewValue, quint16 MessageSize)
|
||||
{
|
||||
if(mEncoding == CAN_SIGNAL_ENCODING_INTEL)
|
||||
{
|
||||
mRawValue = IntelValue;
|
||||
//TODO: trouver un device qui crache du intel??
|
||||
mRawValue = NewValue;
|
||||
}
|
||||
else if(mEncoding == CAN_SIGNAL_ENCODING_MOTOROLA)
|
||||
{
|
||||
mRawValue = MotorolaValue;
|
||||
//mRawValue = MotorolaValue;
|
||||
mRawValue = NewValue;
|
||||
int StartIndex = mStartBit - (mStartBit % 8) + 7 - (mStartBit % 8);
|
||||
int shift = ((MessageSize * 8) - StartIndex -1);
|
||||
mRawValue >>= shift;
|
||||
quint64 mask = 1;
|
||||
mask <<= mSignalSize;
|
||||
mask -= 1;
|
||||
mRawValue &= mask;
|
||||
}
|
||||
else
|
||||
{
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
|
||||
mRawValue >>= mStartBit;
|
||||
quint64 mask = ((1 << mSignalSize)-1);
|
||||
mRawValue &= mask;
|
||||
// mRawValue >>= mStartBit;
|
||||
// quint64 mask = ((1 << mSignalSize)-1);
|
||||
// mRawValue &= mask;
|
||||
|
||||
mPhysicalValue = ((double) mRawValue * mValueFactor) + mValueOffset;
|
||||
|
||||
mPhysicalValue = ((signed) mRawValue * mValueFactor) + mValueOffset;
|
||||
// mPhysicalValue = (test * mValueFactor) + mValueOffset;
|
||||
//mPhysicalValue = test;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -49,13 +49,13 @@ public:
|
||||
unsigned int mValueType;
|
||||
double mValueFactor;
|
||||
double mValueOffset;
|
||||
double mMinValue;
|
||||
double mMaxValue;
|
||||
int mMinValue;
|
||||
int mMaxValue;
|
||||
QString mSignalUnit;
|
||||
|
||||
int ComputeNewSignalValue(quint64 MotorolaValue, quint64 IntelValue);
|
||||
int ComputeNewSignalValue(quint64 NewValue, quint16 MessageSize);
|
||||
|
||||
|
||||
private:
|
||||
quint64 mRawValue;
|
||||
double mPhysicalValue;
|
||||
|
||||
|
||||
@@ -6,10 +6,25 @@ CCANViewerPage::CCANViewerPage(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::CCANViewerPage)
|
||||
{
|
||||
|
||||
mMsgList = 0;
|
||||
|
||||
|
||||
ui->setupUi(this);
|
||||
ui->mCANDataTableWidget->setColumnCount(6);
|
||||
ui->mCANDataTableWidget->setHorizontalHeaderLabels(QStringList() << "Time" << "Channel" << "Msg ID" << "Msg Type" << "Msg Length" << "Data");
|
||||
|
||||
ui->mCANDataTableWidget->clearContents();
|
||||
ui->mCANDataTableWidget->setRowCount(0);
|
||||
ui->mCANDataTableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
|
||||
ui->mCANSignalTableWidget->setColumnCount(4);
|
||||
ui->mCANSignalTableWidget->setHorizontalHeaderLabels(QStringList() << "Nom du signal" << "Val. physique" << "Val. brute" << "Unités");
|
||||
|
||||
|
||||
|
||||
|
||||
connect(ui->mCANDataTableWidget,&QTableWidget::itemSelectionChanged,this,&CCANViewerPage::MessageSelectionChanged);
|
||||
}
|
||||
|
||||
CCANViewerPage::~CCANViewerPage()
|
||||
@@ -17,52 +32,167 @@ CCANViewerPage::~CCANViewerPage()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
int CCANViewerPage::UpdateCANTable(QList<CCANMessage *> MsgList)
|
||||
int CCANViewerPage::InitCANTable(QList<CCANMessage *> *MsgList)
|
||||
{
|
||||
for(int Col = 0; Col < ui->mCANDataTableWidget->columnCount(); Col++)
|
||||
if(MsgList == 0)
|
||||
{
|
||||
for(int Row = 0; Row < ui->mCANDataTableWidget->rowCount(); Row++)
|
||||
{
|
||||
delete ui->mCANDataTableWidget->item(Row,Col);
|
||||
}
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
ui->mCANDataTableWidget->clearContents();
|
||||
ui->mCANDataTableWidget->setRowCount(0);
|
||||
|
||||
ui->mCANDataTableWidget->setRowCount(MsgList.size());
|
||||
for(int Msg = 0; Msg < MsgList.size(); Msg++)
|
||||
mMsgList = MsgList;
|
||||
|
||||
int row = ui->mCANDataTableWidget->rowCount();
|
||||
ui->mCANDataTableWidget->setRowCount(MsgList->size());
|
||||
for(int Msg = 0; Msg < MsgList->size(); Msg++)
|
||||
{
|
||||
QTableWidgetItem *NewItem;
|
||||
|
||||
NewItem = new QTableWidgetItem("Time");
|
||||
ui->mCANDataTableWidget->setItem(Msg,0,NewItem);
|
||||
ui->mCANDataTableWidget->setItem(row,0,NewItem);
|
||||
|
||||
//Set chanel value
|
||||
NewItem = new QTableWidgetItem(QString("%1").arg(MsgList.at(Msg)->mCANChannel));
|
||||
ui->mCANDataTableWidget->setItem(Msg,1,NewItem);
|
||||
//Set Msg name
|
||||
NewItem = new QTableWidgetItem(QString("%1").arg(MsgList->at(Msg)->mCANMsgName));
|
||||
ui->mCANDataTableWidget->setItem(row,1,NewItem);
|
||||
|
||||
//Set message ID value
|
||||
NewItem = new QTableWidgetItem(QString("0x%1").arg(MsgList.at(Msg)->mCANMsgID,0,16));
|
||||
ui->mCANDataTableWidget->setItem(Msg,2,NewItem);
|
||||
NewItem = new QTableWidgetItem(QString("0x%1").arg(MsgList->at(Msg)->mCANMsgID,0,16));
|
||||
ui->mCANDataTableWidget->setItem(row,2,NewItem);
|
||||
NewItem->setData(Qt::UserRole,MsgList->at(Msg)->mCANMsgID); //Set message ID as reference to easily find the row when updating...
|
||||
|
||||
//Set message type value
|
||||
NewItem = new QTableWidgetItem(QString("0x%1").arg(MsgList.at(Msg)->mCANMsgType,0,16));
|
||||
ui->mCANDataTableWidget->setItem(Msg,3,NewItem);
|
||||
NewItem = new QTableWidgetItem(QString("0x%1").arg(MsgList->at(Msg)->mCANMsgType,0,16));
|
||||
ui->mCANDataTableWidget->setItem(row,3,NewItem);
|
||||
|
||||
//Set message length value
|
||||
NewItem = new QTableWidgetItem(QString("%1").arg(MsgList.at(Msg)->mCANMsgLength));
|
||||
ui->mCANDataTableWidget->setItem(Msg,4,NewItem);
|
||||
NewItem = new QTableWidgetItem(QString(" "));
|
||||
ui->mCANDataTableWidget->setItem(row,4,NewItem);
|
||||
|
||||
//Set data value
|
||||
QString Data;
|
||||
for(int i = 0; i < MsgList.at(Msg)->mCANMsgLength; i++)
|
||||
{
|
||||
unsigned char DataByte = MsgList.at(Msg)->mCANMsgData.at(i);
|
||||
Data.append(QString("%1 ").arg(DataByte,2,16,QLatin1Char('0')));
|
||||
}
|
||||
NewItem = new QTableWidgetItem(Data);
|
||||
ui->mCANDataTableWidget->setItem(Msg,5,NewItem);
|
||||
NewItem = new QTableWidgetItem(QString(" "));
|
||||
ui->mCANDataTableWidget->setItem(row,5,NewItem);
|
||||
|
||||
row++;
|
||||
|
||||
|
||||
|
||||
// //Set data value
|
||||
// QString Data;
|
||||
// for(unsigned int i = 0; i < MsgList->at(Msg)->mCANMsgLength; i++)
|
||||
// {
|
||||
// unsigned char DataByte = MsgList->at(Msg)->mCANMsgData.at(i);
|
||||
// Data.append(QString("%1 ").arg(DataByte,2,16,QLatin1Char('0')));
|
||||
// }
|
||||
// NewItem = new QTableWidgetItem(Data);
|
||||
// ui->mCANDataTableWidget->setItem(Msg,5,NewItem);
|
||||
}
|
||||
// ui->mCANSignalTableWidget->setCurrentItem(ui->mCANDataTableWidget->item(0,0));
|
||||
// MessageSelectionChanged();
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CCANViewerPage::UpdateCANTable(QList<CCANMessage *> *MsgList)
|
||||
{
|
||||
//Find the row of each message and update values in table
|
||||
for(int msg = 0; msg < MsgList->size(); msg++)
|
||||
{
|
||||
int row = 0;
|
||||
for(row = 0; row < ui->mCANDataTableWidget->rowCount(); row++)
|
||||
{
|
||||
// if(ui->mCANDataTableWidget->item(row,2)->text() == QString("0x%1").arg(MsgList->at(msg)->mCANMsgID,0,16))
|
||||
if(ui->mCANDataTableWidget->item(row,2)->data(Qt::UserRole).toUInt() == MsgList->at(msg)->mCANMsgID)
|
||||
{
|
||||
//Set message length value
|
||||
ui->mCANDataTableWidget->item(row,4)->setText(QString("%1").arg(MsgList->at(msg)->mCANMsgLength));
|
||||
|
||||
|
||||
QString Data;
|
||||
for(int byte = 0; byte < MsgList->at(msg)->mCANMsgData.size();byte++)
|
||||
{
|
||||
// Data.append(QString("%1 ").arg((unsigned int)MsgList->at(msg)->mCANMsgData.at(byte),2,16));
|
||||
Data.append(QString().sprintf("%.2X ",(unsigned char)MsgList->at(msg)->mCANMsgData.at(byte)));
|
||||
}
|
||||
ui->mCANDataTableWidget->item(row,5)->setText(Data);
|
||||
}
|
||||
}
|
||||
}
|
||||
// UpdateSignalsTable();
|
||||
MessageSelectionChanged();
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void CCANViewerPage::MessageSelectionChanged()
|
||||
{
|
||||
if(mMsgList == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ui->mCANSignalTableWidget->clearContents();
|
||||
//Find message based on current table selection
|
||||
int row = ui->mCANDataTableWidget->currentRow();
|
||||
if(row == -1)
|
||||
return;
|
||||
for (int msg = 0; msg < mMsgList->size(); msg++)
|
||||
{
|
||||
unsigned int ID = ui->mCANDataTableWidget->item(row,2)->data(Qt::UserRole).toUInt();
|
||||
if(ID == mMsgList->at(msg)->mCANMsgID)
|
||||
{
|
||||
CCANMessage *Msg = mMsgList->at(msg);
|
||||
ui->mCANSignalTableWidget->clearContents();
|
||||
ui->mCANSignalTableWidget->setRowCount(Msg->mSignalsList.size());
|
||||
|
||||
for(int signal = 0; signal < Msg->mSignalsList.size(); signal++)
|
||||
{
|
||||
//Signal name
|
||||
QTableWidgetItem *NewItem = new QTableWidgetItem(Msg->mSignalsList.at(signal)->mSignalName);
|
||||
ui->mCANSignalTableWidget->setItem(signal,0,NewItem);
|
||||
|
||||
//Phys value
|
||||
NewItem = new QTableWidgetItem(QString("%1").arg(Msg->mSignalsList.at(signal)->mPhysicalValue,0,'f',1));
|
||||
ui->mCANSignalTableWidget->setItem(signal,1,NewItem);
|
||||
|
||||
//Raw value
|
||||
NewItem = new QTableWidgetItem(QString("0x%1").arg(Msg->mSignalsList.at(signal)->mRawValue,0,16));
|
||||
ui->mCANSignalTableWidget->setItem(signal,2,NewItem);
|
||||
|
||||
//Units
|
||||
NewItem = new QTableWidgetItem(Msg->mSignalsList.at(signal)->mSignalUnit);
|
||||
ui->mCANSignalTableWidget->setItem(signal,3,NewItem);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int CCANViewerPage::UpdateSignalsTable()
|
||||
{
|
||||
int row = ui->mCANDataTableWidget->currentRow();
|
||||
for (int msg = 0; msg < mMsgList->size(); msg++)
|
||||
{
|
||||
unsigned int ID = ui->mCANDataTableWidget->item(row,2)->data(Qt::UserRole).toUInt();
|
||||
if(ID == mMsgList->at(msg)->mCANMsgID)
|
||||
{
|
||||
CCANMessage *Msg = mMsgList->at(msg);
|
||||
ui->mCANSignalTableWidget->clearContents();
|
||||
ui->mCANSignalTableWidget->setRowCount(Msg->mSignalsList.size());
|
||||
|
||||
for(int signal = 0; signal < Msg->mSignalsList.size(); signal++)
|
||||
{
|
||||
//Signal name
|
||||
ui->mCANSignalTableWidget->item(row,0)->setText(Msg->mSignalsList.at(signal)->mSignalName);
|
||||
|
||||
//Phys value
|
||||
ui->mCANSignalTableWidget->item(row,0)->setText(QString("%1").arg(Msg->mSignalsList.at(signal)->mPhysicalValue,0,'f',1));
|
||||
|
||||
//Raw value
|
||||
ui->mCANSignalTableWidget->item(row,0)->setText(QString("0x%1").arg(Msg->mSignalsList.at(signal)->mRawValue,0,16));
|
||||
|
||||
//Units
|
||||
ui->mCANSignalTableWidget->item(row,0)->setText(Msg->mSignalsList.at(signal)->mSignalUnit);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,15 @@ public:
|
||||
~CCANViewerPage();
|
||||
|
||||
|
||||
int UpdateCANTable(QList<CCANMessage*> MsgList);
|
||||
int UpdateCANTable(QList<CCANMessage*> *MsgList);
|
||||
int InitCANTable(QList<CCANMessage*> *MsgList);
|
||||
int UpdateSignalsTable();
|
||||
|
||||
|
||||
QList<CCANMessage*> *mMsgList;
|
||||
|
||||
public slots:
|
||||
void MessageSelectionChanged();
|
||||
|
||||
private:
|
||||
Ui::CCANViewerPage *ui;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1140</width>
|
||||
<width>1848</width>
|
||||
<height>581</height>
|
||||
</rect>
|
||||
</property>
|
||||
@@ -18,7 +18,7 @@
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>60</y>
|
||||
<width>1051</width>
|
||||
<width>671</width>
|
||||
<height>411</height>
|
||||
</rect>
|
||||
</property>
|
||||
@@ -36,6 +36,16 @@
|
||||
<string>Reset</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTableWidget" name="mCANSignalTableWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>720</x>
|
||||
<y>60</y>
|
||||
<width>831</width>
|
||||
<height>411</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
@@ -22,6 +22,14 @@
|
||||
<height>451</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>System</family>
|
||||
<pointsize>12</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
#include "ui_ProgramSettingsPage.h"
|
||||
|
||||
#include "CANDevice.h"
|
||||
//#include "CANMessage.h"
|
||||
//#include "CANSignal.h"
|
||||
//#include "PCANBasic.h"
|
||||
#include "OtarcikCan.h"
|
||||
|
||||
|
||||
CProgramSettingsPage::CProgramSettingsPage(QWidget *parent) :
|
||||
@@ -13,11 +11,13 @@ CProgramSettingsPage::CProgramSettingsPage(QWidget *parent) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
mProgramPtr = 0;
|
||||
mDevicesList = 0;
|
||||
|
||||
ui->mDBSignalDetailsTable->setColumnCount(10);
|
||||
ui->mDBSignalDetailsTable->setHorizontalHeaderLabels(QStringList() << "Signal" << "Bit No" << "Length" << "Type" << "Max Val" << "Min Val" << "Offset" << "Scale factor" << "Unit" << "Byte order");
|
||||
|
||||
ui->mDevicePollPeriodSpinBx->setRange(200,60000);
|
||||
|
||||
|
||||
ui->mCANBaudrateComboBx->clear();
|
||||
@@ -59,10 +59,14 @@ CProgramSettingsPage::CProgramSettingsPage(QWidget *parent) :
|
||||
ui->mDatabaseFileSelectBtn->hide();
|
||||
ui->mCANBaudrateComboBx->setEnabled(false);
|
||||
ui->mCANIDComboBx->setEnabled(false);
|
||||
ui->mDevicePollPeriodSpinBx->setEnabled(false);
|
||||
ui->mCancelModifyParamsBtn->hide();
|
||||
|
||||
|
||||
connect(ui->mDevicesList,&QListWidget::itemSelectionChanged,this,&CProgramSettingsPage::DeviceSelectionChanged);
|
||||
connect(ui->mDBMessagesListWidget,&QListWidget::itemSelectionChanged,this,&CProgramSettingsPage::MessageSelectionChanged);
|
||||
connect(ui->mModifyDevParamsBtn,&QPushButton::clicked,this,&CProgramSettingsPage::ModifyDeviceBtnPressed);
|
||||
connect(ui->mCancelModifyParamsBtn,&QPushButton::clicked,this,&CProgramSettingsPage::CancelModifyDevBtnPressed);
|
||||
// connect(ui->mDBSignalDetailsTable,&QTableWidget::itemSelectionChanged,this,&CProgramSettingsPage::SignalSelectionChanged);
|
||||
|
||||
}
|
||||
@@ -128,6 +132,9 @@ int CProgramSettingsPage::UpdatePage()
|
||||
ui->mCANIDComboBx->setCurrentIndex(ui->mCANIDComboBx->findData(Device->mCANDeviceID));
|
||||
ui->mDeviceDescriptionTxtEdit->setPlainText(Device->mDeviceDescription);
|
||||
ui->mDatabaseFileNameLbl->setText(QString("Database: %1").arg(Device->mCANDeviceDatabaseFilename));
|
||||
// ui->mDevicePollPeriodSpinBx->setEnabled(true);
|
||||
ui->mDevicePollPeriodSpinBx->setValue(Device->mDevicePollPeriod);
|
||||
// ui->mDevicePollPeriodSpinBx->setEnabled(false);
|
||||
|
||||
//update device database information
|
||||
ui->mDBMessagesListWidget->clear();
|
||||
@@ -208,15 +215,42 @@ int CProgramSettingsPage::UpdateMessageInformation()
|
||||
ui->mDBSignalDetailsTable->setItem(Sig,2,NewItem);
|
||||
|
||||
//Type
|
||||
NewItem = new QTableWidgetItem(QString("%1").arg(Signal->mValueType));
|
||||
switch(Signal->mValueType)
|
||||
{
|
||||
case CCANSignal::CAN_SIGNAL_TYPE_INVALID:
|
||||
{
|
||||
NewItem = new QTableWidgetItem(QString("INVALIDE"));
|
||||
break;
|
||||
}
|
||||
case CCANSignal::CAN_SIGNAL_TYPE_SIGNED_INT:
|
||||
{
|
||||
NewItem = new QTableWidgetItem(QString("int"));
|
||||
break;
|
||||
}
|
||||
case CCANSignal::CAN_SIGNAL_TYPE_UNSIGNED_INT:
|
||||
{
|
||||
NewItem = new QTableWidgetItem(QString("uint"));
|
||||
break;
|
||||
}
|
||||
case CCANSignal::CAN_SIGNAL_TYPE_32_BIT_FLOAT:
|
||||
{
|
||||
NewItem = new QTableWidgetItem(QString("Float_32"));
|
||||
break;
|
||||
}
|
||||
case CCANSignal::CAN_SIGNAL_TYPE_64_BIT_DOUBLE:
|
||||
{
|
||||
NewItem = new QTableWidgetItem(QString("Double"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
ui->mDBSignalDetailsTable->setItem(Sig,3,NewItem);
|
||||
|
||||
//Max Val
|
||||
NewItem = new QTableWidgetItem(QString("%1").arg(Signal->mMaxValue,0,'f',1));
|
||||
NewItem = new QTableWidgetItem(QString("%1").arg(Signal->mMaxValue));
|
||||
ui->mDBSignalDetailsTable->setItem(Sig,4,NewItem);
|
||||
|
||||
//Min Val
|
||||
NewItem = new QTableWidgetItem(QString("%1").arg(Signal->mMinValue,0,'f',1));
|
||||
NewItem = new QTableWidgetItem(QString("%1").arg(Signal->mMinValue));
|
||||
ui->mDBSignalDetailsTable->setItem(Sig,5,NewItem);
|
||||
|
||||
//Offset
|
||||
@@ -232,7 +266,26 @@ int CProgramSettingsPage::UpdateMessageInformation()
|
||||
ui->mDBSignalDetailsTable->setItem(Sig,8,NewItem);
|
||||
|
||||
//Endian
|
||||
NewItem = new QTableWidgetItem(QString("%1").arg(Signal->mValueType));
|
||||
switch(Signal->mEncoding)
|
||||
{
|
||||
case CCANSignal::CAN_SIGNAL_ENCODING_INTEL:
|
||||
{
|
||||
NewItem = new QTableWidgetItem(QString("Intel"));
|
||||
break;
|
||||
}
|
||||
case CCANSignal::CAN_SIGNAL_ENCODING_MOTOROLA:
|
||||
{
|
||||
NewItem = new QTableWidgetItem(QString("Motorola"));
|
||||
break;
|
||||
}
|
||||
case CCANSignal::CAN_SIGNAL_ENCODING_INVALID:
|
||||
{
|
||||
NewItem = new QTableWidgetItem(QString("INVALID"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ui->mDBSignalDetailsTable->setItem(Sig,9,NewItem);
|
||||
|
||||
}
|
||||
@@ -259,22 +312,47 @@ void CProgramSettingsPage::ModifyDeviceBtnPressed()
|
||||
{
|
||||
if(mDeviceChangeModeEnabled)
|
||||
{
|
||||
//Save Data
|
||||
ui->mDeviceDescriptionTxtEdit->setEnabled(false);
|
||||
ui->mDatabaseFileSelectBtn->hide();
|
||||
ui->mCANBaudrateComboBx->setEnabled(false);
|
||||
ui->mCANIDComboBx->setEnabled(false);
|
||||
ui->mDevicesList->setEnabled(true);
|
||||
ui->mDevicePollPeriodSpinBx->setEnabled(false);
|
||||
ui->mModifyDevParamsBtn->setText("Modifier");
|
||||
ui->mCancelModifyParamsBtn->hide();
|
||||
mDeviceChangeModeEnabled = false;
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//Modify data
|
||||
ui->mDeviceDescriptionTxtEdit->setEnabled(true);
|
||||
ui->mDatabaseFileSelectBtn->show();
|
||||
ui->mCANBaudrateComboBx->setEnabled(true);
|
||||
ui->mCANIDComboBx->setEnabled(true);
|
||||
ui->mDevicesList->setEnabled(false);
|
||||
ui->mDevicePollPeriodSpinBx->setEnabled(true);
|
||||
ui->mModifyDevParamsBtn->setText("Sauvegarder");
|
||||
ui->mCancelModifyParamsBtn->show();
|
||||
|
||||
mDeviceChangeModeEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
void CProgramSettingsPage::CancelModifyDevBtnPressed()
|
||||
{
|
||||
ui->mDeviceDescriptionTxtEdit->setEnabled(false);
|
||||
ui->mDatabaseFileSelectBtn->hide();
|
||||
ui->mCANBaudrateComboBx->setEnabled(false);
|
||||
ui->mCANIDComboBx->setEnabled(false);
|
||||
ui->mDevicesList->setEnabled(true);
|
||||
ui->mDevicePollPeriodSpinBx->setEnabled(false);
|
||||
ui->mModifyDevParamsBtn->setText("Modifier");
|
||||
ui->mCancelModifyParamsBtn->hide();
|
||||
mDeviceChangeModeEnabled = false;
|
||||
|
||||
UpdatePage();
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
class CCANDevice;
|
||||
class CCANMessage;
|
||||
class CCANSignal;
|
||||
class COtarcikCan;
|
||||
|
||||
|
||||
namespace Ui {
|
||||
@@ -26,6 +27,8 @@ public:
|
||||
int UpdateMessageInformation();
|
||||
|
||||
|
||||
COtarcikCan *mProgramPtr;
|
||||
|
||||
private:
|
||||
Ui::CProgramSettingsPage *ui;
|
||||
QList<CCANDevice *> *mDevicesList;
|
||||
@@ -36,6 +39,7 @@ public slots:
|
||||
void SignalSelectionChanged();
|
||||
void MessageSelectionChanged();
|
||||
void ModifyDeviceBtnPressed();
|
||||
void CancelModifyDevBtnPressed();
|
||||
};
|
||||
|
||||
#endif // PROGRAMSETTINGSPAGE_H
|
||||
|
||||
@@ -57,10 +57,10 @@
|
||||
<widget class="QGroupBox" name="mDeviceParamsGroupBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>280</x>
|
||||
<x>270</x>
|
||||
<y>100</y>
|
||||
<width>311</width>
|
||||
<height>331</height>
|
||||
<width>321</width>
|
||||
<height>371</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
@@ -128,60 +128,11 @@
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="mDeviceDatabaseLbl">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>100</y>
|
||||
<width>111</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Fichier database:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="mDatabaseFileNameLbl">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>120</y>
|
||||
<width>301</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Fichier...</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="mDatabaseFileSelectBtn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>280</x>
|
||||
<y>120</y>
|
||||
<width>31</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="mModifyDevParamsBtn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>300</y>
|
||||
<x>220</x>
|
||||
<y>330</y>
|
||||
<width>80</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
@@ -194,23 +145,115 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>180</y>
|
||||
<y>210</y>
|
||||
<width>291</width>
|
||||
<height>101</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<widget class="QLabel" name="mRefreshRateLbl">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>182</y>
|
||||
<width>181</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Période rafraîchissement (ms):</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QGroupBox" name="mDeviceDatabaseGrpBx">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>100</y>
|
||||
<width>301</width>
|
||||
<height>51</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Base de données</string>
|
||||
</property>
|
||||
<widget class="QLabel" name="mDatabaseFileNameLbl">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>27</y>
|
||||
<width>301</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Fichier...</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="mDatabaseFileSelectBtn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>270</x>
|
||||
<y>24</y>
|
||||
<width>31</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QLabel" name="mCANBaudrateLbl_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>160</y>
|
||||
<width>81</width>
|
||||
<width>91</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Description</string>
|
||||
<string>CAN Baudrate:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QSpinBox" name="mDevicePollPeriodSpinBx">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>200</x>
|
||||
<y>180</y>
|
||||
<width>91</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="mCancelModifyParamsBtn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>330</y>
|
||||
<width>80</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Annuler</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
@@ -30,6 +30,7 @@ COtarcikCan::~COtarcikCan()
|
||||
delete mCANDevicesList.takeFirst();
|
||||
}
|
||||
mCANDevicesList.clear();
|
||||
mMainWindow.mProgramSettingsPage->mProgramPtr = this;
|
||||
|
||||
}
|
||||
|
||||
@@ -37,26 +38,83 @@ int COtarcikCan::Start()
|
||||
{
|
||||
mMainWindow.show();
|
||||
|
||||
|
||||
|
||||
CGeneralMessagesLogDispatcher::instance()->BindGuiPageHandle(mMainWindow.mGeneralStatusPage);
|
||||
CGeneralMessagesLogDispatcher::instance()->Init();
|
||||
|
||||
CCANDevice *NewCANDevice = new CCANDevice();
|
||||
mCANDevicesList.append(NewCANDevice);
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Démarrage du logiciel OtarcikCAN"));
|
||||
|
||||
NewCANDevice->Init("IVT-S_all-variations_12082020.dbc",PCAN_USBBUS1,PCAN_BAUD_500K,"Puck CAN USB branchée sur le module Parker qui contrôle la patente", "Module Parker");
|
||||
if(mSystemConfig.LoadConfig(&mCANDevicesList) == RET_OK)
|
||||
{
|
||||
for(int i = 0; i < mCANDevicesList.size(); i++)
|
||||
{
|
||||
mCANDevicesList[i]->mProgramPtr = this;
|
||||
mCANDevicesList.at(i)->Init();
|
||||
|
||||
NewCANDevice = new CCANDevice();
|
||||
mCANDevicesList.append(NewCANDevice);
|
||||
}
|
||||
|
||||
NewCANDevice->Init("Database.dbc",PCAN_USBBUS3,PCAN_BAUD_800K,"Puck CAN USB branchée sur une autre patente", "Module Cossin");
|
||||
|
||||
mMainWindow.mProgramSettingsPage->SetDevicesList(&mCANDevicesList);
|
||||
mMainWindow.mProgramSettingsPage->SetDevicesList(&mCANDevicesList);
|
||||
// CCANDevice *NewCANDevice = new CCANDevice();
|
||||
// mCANDevicesList.append(NewCANDevice);
|
||||
// NewCANDevice->mProgramPtr = this;
|
||||
|
||||
// NewCANDevice->Init("IVT-S_all-variations_12082020.dbc",PCAN_USBBUS1,PCAN_BAUD_500K,"Puck CAN USB branchée sur le module Parker qui contrôle la patente", "Module Parker",1000);
|
||||
|
||||
// NewCANDevice = new CCANDevice();
|
||||
// mCANDevicesList.append(NewCANDevice);
|
||||
// NewCANDevice->mProgramPtr = this;
|
||||
|
||||
// NewCANDevice->Init("mazda_3_2019.dbc",PCAN_USBBUS3,PCAN_BAUD_800K,"Puck CAN USB branchée sur une autre patente", "Module Cossin",200);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int COtarcikCan::UpdateCANViewerDataRequest(QList<CCANMessage *> MsgList)
|
||||
int COtarcikCan::UpdateCANViewerDataRequest(QList<CCANMessage *> *MsgList)
|
||||
{
|
||||
return mMainWindow.mCANViewerPage->UpdateCANTable(MsgList);
|
||||
}
|
||||
|
||||
int COtarcikCan::InitCANViewer(QList<CCANMessage *> *MsgList)
|
||||
{
|
||||
return mMainWindow.mCANViewerPage->InitCANTable(MsgList);
|
||||
}
|
||||
|
||||
|
||||
int COtarcikCan::SaveSystemConfigRequest(QList<CCANDevice *> *DevicesList)
|
||||
{
|
||||
if(DevicesList == 0)
|
||||
{
|
||||
qDebug("COtarcikCan::Trying to save a config with an invalid devices list");
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
|
||||
if(mSystemConfig.SaveConfig(DevicesList) == RET_OK)
|
||||
{
|
||||
while(mCANDevicesList.size() != 0)
|
||||
{
|
||||
delete mCANDevicesList.takeFirst();
|
||||
}
|
||||
while(DevicesList->size() != 0)
|
||||
{
|
||||
delete DevicesList->takeFirst();
|
||||
}
|
||||
if(mSystemConfig.LoadConfig(&mCANDevicesList) == RET_OK)
|
||||
{
|
||||
for(int i = 0; i < mCANDevicesList.size(); i++)
|
||||
{
|
||||
mCANDevicesList[i]->mProgramPtr = this;
|
||||
mCANDevicesList.at(i)->Init();
|
||||
|
||||
}
|
||||
mMainWindow.mProgramSettingsPage->SetDevicesList(&mCANDevicesList);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "GeneralMessagesLogDispatcher.h"
|
||||
#include "CANDevice.h"
|
||||
#include <QList>
|
||||
#include "SystemConfig.h"
|
||||
|
||||
class COtarcikCan : public QObject
|
||||
{
|
||||
@@ -15,11 +16,16 @@ public:
|
||||
explicit COtarcikCan(QObject *parent = 0);
|
||||
~COtarcikCan();
|
||||
CMainWindow mMainWindow;
|
||||
CSystemConfig mSystemConfig;
|
||||
|
||||
int Start();
|
||||
|
||||
|
||||
int UpdateCANViewerDataRequest(QList<CCANMessage*> MsgList);
|
||||
int InitCANViewer(QList<CCANMessage *> *MsgList);
|
||||
int UpdateCANViewerDataRequest(QList<CCANMessage *> *MsgList);
|
||||
|
||||
|
||||
int SaveSystemConfigRequest(QList<CCANDevice*> *DevicesList);
|
||||
|
||||
private:
|
||||
QList<CCANDevice*> mCANDevicesList;
|
||||
|
||||
@@ -94,14 +94,14 @@ QList<CCANMessage *> CPCANInterface::ReadCANFullBuffer(unsigned short Channel)
|
||||
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("----------------------------------------------------------");
|
||||
// // 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("----------------------------------------------------------");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
#include "SystemConfig.h"
|
||||
#include "GeneralMessagesLogDispatcher.h"
|
||||
|
||||
CSystemConfig::CSystemConfig()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CSystemConfig::LoadConfig(QList<CCANDevice *> *DevicesList)
|
||||
{
|
||||
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Chargement de la configuration système..."));
|
||||
if(DevicesList == 0)
|
||||
{
|
||||
qDebug("CSystemConfig: Trying to load a config into an invalid devices list");
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Échec de sauvegarde de la config système. Pointeur vers liste de devices invalide!!!"),true,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_ERROR_STATUS);
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
|
||||
QFile* ConfigFile = new QFile("./Config/Station.cfg");
|
||||
if(ConfigFile)
|
||||
{
|
||||
if(ConfigFile->open(QIODevice::ReadOnly | QIODevice::Unbuffered) == false)
|
||||
{
|
||||
// LoadDefaultSettings(Settings);
|
||||
// SaveSettings(Settings);
|
||||
qDebug("CSystemConfig: Failed to open config file in config loading");
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Échec de sauvegarde de la config système. Impossible d'ouvrir le fichier /Config/Station.cfg"),true,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_ERROR_STATUS);
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// LoadDefaultSettings(Settings);
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Échec de sauvegarde de la config système. Pointeur vers QFile invalide !!!"),true,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_ERROR_STATUS);
|
||||
qDebug("CSystemConfig: Invalid QFile pointer in config loading...");
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
|
||||
QDataStream * InputStream = new QDataStream(ConfigFile);
|
||||
|
||||
quint32 MagicNbr;// = 0xBAADCAFE;
|
||||
quint32 FileVersion;
|
||||
|
||||
|
||||
*InputStream >> MagicNbr;
|
||||
if(MagicNbr != OTARCIK_CONFIG_FILE_MAGIC_NBR)
|
||||
{
|
||||
// LoadDefaultSettings(Settings);
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
|
||||
*InputStream >> FileVersion;
|
||||
|
||||
int NbDevices;
|
||||
*InputStream >> NbDevices;
|
||||
for(int i = 0; i < NbDevices; i++)
|
||||
{
|
||||
CCANDevice *NewDevice = new CCANDevice;
|
||||
*InputStream >> *NewDevice;
|
||||
DevicesList->append(NewDevice);
|
||||
}
|
||||
|
||||
|
||||
ConfigFile->close();
|
||||
delete ConfigFile;
|
||||
delete InputStream;
|
||||
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Configuration système chargée avec succès!"));
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CSystemConfig::SaveConfig(QList<CCANDevice *> *DevicesList)
|
||||
{
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Sauvegarde de la configuration système..."));
|
||||
|
||||
QFile *ConfigFile = new QFile("./Config/Station.cfg");
|
||||
if(ConfigFile)
|
||||
{
|
||||
if(ConfigFile->open(QIODevice::WriteOnly | QIODevice::Unbuffered) == false)
|
||||
{
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Échec de sauvegarde de la config système. Impossible d'ouvrir le fichier /Config/Station.cfg"),true,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_ERROR_STATUS);
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Échec de sauvegarde de la config système. Pointeur vers QFile invalide !!!"),true,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_ERROR_STATUS);
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
|
||||
|
||||
QDataStream * OutputStream = new QDataStream(ConfigFile);
|
||||
|
||||
quint32 MagicNbr = OTARCIK_CONFIG_FILE_MAGIC_NBR;
|
||||
quint32 FileVersion = OTARCIK_CURRENT_CONFIG_FILE_VERSION;
|
||||
|
||||
//Setup the config file header
|
||||
*OutputStream << MagicNbr;
|
||||
*OutputStream << FileVersion;
|
||||
|
||||
//Save the CAN devices config info
|
||||
*OutputStream << DevicesList->size(); //Number of devices
|
||||
for(int i = 0; i < DevicesList->size(); i++)
|
||||
{
|
||||
*OutputStream << *DevicesList->at(i); //Add each device info to config file
|
||||
}
|
||||
|
||||
ConfigFile->flush();
|
||||
ConfigFile->close();
|
||||
|
||||
delete ConfigFile;
|
||||
delete OutputStream;
|
||||
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Configuration système sauvegardée avec succès."));
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef SYSTEMCONFIG_H
|
||||
#define SYSTEMCONFIG_H
|
||||
|
||||
#include "CANDevice.h"
|
||||
#include <QList>
|
||||
#include <QFile>
|
||||
#include <QDataStream>
|
||||
|
||||
#define OTARCIK_CURRENT_CONFIG_FILE_VERSION 0x01
|
||||
#define OTARCIK_CONFIG_FILE_MAGIC_NBR 0xDEADBEEF
|
||||
|
||||
class CSystemConfig
|
||||
{
|
||||
public:
|
||||
CSystemConfig();
|
||||
|
||||
int LoadConfig(QList<CCANDevice*> *DevicesList);
|
||||
int SaveConfig(QList<CCANDevice*> *DevicesList);
|
||||
};
|
||||
|
||||
|
||||
#endif // SYSTEMCONFIG_H
|
||||
Reference in New Issue
Block a user