Plusieurs développements, dont l'implémentation du endian Intel
This commit is contained in:
@@ -91,7 +91,9 @@ void CCANAnalyzer::CANTimerExpired()
|
||||
{
|
||||
QList<CCANMessage *> NewMessagesList = mCANDriverIF->ReadCANFullBuffer(mCANDeviceHandle);
|
||||
|
||||
qDebug("CAN Buffer size: %d",NewMessagesList.size());
|
||||
int BufferSize = NewMessagesList.size();
|
||||
// qDebug("CAN Buffer size: %d",BufferSize);
|
||||
|
||||
|
||||
|
||||
for(int i = 0 ; i < NewMessagesList.size(); i++)
|
||||
@@ -113,7 +115,7 @@ void CCANAnalyzer::CANTimerExpired()
|
||||
}
|
||||
|
||||
|
||||
mDevicePtr->NewMessageParsed();
|
||||
mDevicePtr->NewMessageParsed(BufferSize);
|
||||
|
||||
|
||||
if(NewMessagesList.isEmpty())
|
||||
|
||||
@@ -72,12 +72,14 @@ int CCANDevice::Init()
|
||||
{
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Le dispositif [%1] n'a pas pu s'initialiser").arg(mDeviceConfigInfo.mDeviceName),true,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_ERROR_STATUS);
|
||||
mProgramPtr->SetCANConnectionStatusRequest(false);
|
||||
mProgramPtr->UpdateCANModuleStatusRequest(mDeviceConfigInfo.mDeviceName,"Déconnecté","NOUPDATE");
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
|
||||
mCANDataLogger.SetMQTTTopicDevice(QString("CANBus/%1/").arg(mDeviceConfigInfo.mDeviceName));
|
||||
mCANDataLogger.SetMQTTClient(mCANMQTTClient);
|
||||
mProgramPtr->SetCANConnectionStatusRequest(true);
|
||||
mProgramPtr->UpdateCANModuleStatusRequest(mDeviceConfigInfo.mDeviceName,"Connecté","NOUPDATE");
|
||||
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Dispositif [%1] initialisé avec succès!").arg(mDeviceConfigInfo.mDeviceName),true,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_SUCCESS_STATUS);
|
||||
return RET_OK;
|
||||
@@ -97,10 +99,11 @@ int CCANDevice::Init(QString DatabaseFileName, TPCANHandle CANDeviceID, TPCANBau
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CCANDevice::NewMessageParsed()
|
||||
int CCANDevice::NewMessageParsed(int BufferSize)
|
||||
{
|
||||
mCANDataLogger.LogNewData(&mMessageList);
|
||||
mProgramPtr->UpdateCANViewerDataRequest(&mMessageList);
|
||||
mProgramPtr->UpdateCANModuleStatusRequest(mDeviceConfigInfo.mDeviceName,"NOUPDATE",QString("%1").arg(BufferSize));
|
||||
|
||||
for(int i = 0; i < mMessageList.size(); i++)
|
||||
mMessageList.at(i)->mPendingData = false;
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
|
||||
// CCANDevice &operator=(const CCANDevice *source);
|
||||
|
||||
int NewMessageParsed();
|
||||
int NewMessageParsed(int BufferSize = 0);
|
||||
|
||||
private:
|
||||
bool mConfigSet;
|
||||
|
||||
@@ -40,19 +40,19 @@ QDataStream &operator<<(QDataStream &out, const CCANDeviceConfig &source)
|
||||
return out;
|
||||
}
|
||||
|
||||
CCANDeviceConfig& CCANDeviceConfig::operator=(const CCANDeviceConfig *source)
|
||||
CCANDeviceConfig& CCANDeviceConfig::operator=(const CCANDeviceConfig &source)
|
||||
{
|
||||
if(source == this)
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
QString mDeviceName;
|
||||
unsigned int mDevicePollPeriod;
|
||||
|
||||
CCANDeviceConfig &operator=(const CCANDeviceConfig *source);
|
||||
CCANDeviceConfig &operator=(const CCANDeviceConfig &source);
|
||||
};
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const CCANDeviceConfig &source);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "CANSignal.h"
|
||||
#include "defines.h"
|
||||
#include <QtEndian>
|
||||
|
||||
|
||||
CCANSignal::CCANSignal():
|
||||
@@ -14,12 +15,18 @@ int CCANSignal::ComputeNewSignalValue(quint64 NewValue, quint16 MessageSize)
|
||||
{
|
||||
if(mEncoding == CAN_SIGNAL_ENCODING_INTEL)
|
||||
{
|
||||
//TODO: trouver un device qui crache du intel??
|
||||
mRawValue = NewValue;
|
||||
|
||||
mRawValue = qFromBigEndian(NewValue);
|
||||
// mRawValue = NewValue;
|
||||
mRawValue >>= mStartBit;
|
||||
quint64 mask = 1;
|
||||
mask <<= mSignalSize;
|
||||
mask -= 1;
|
||||
mRawValue &= mask;
|
||||
|
||||
}
|
||||
else if(mEncoding == CAN_SIGNAL_ENCODING_MOTOROLA)
|
||||
{
|
||||
//mRawValue = MotorolaValue;
|
||||
mRawValue = NewValue;
|
||||
int StartIndex = mStartBit - (mStartBit % 8) + 7 - (mStartBit % 8);
|
||||
int shift = ((MessageSize * 8) - StartIndex -1);
|
||||
@@ -36,9 +43,67 @@ int CCANSignal::ComputeNewSignalValue(quint64 NewValue, quint16 MessageSize)
|
||||
}
|
||||
|
||||
|
||||
mPhysicalValue = ((signed) mRawValue * mValueFactor) + mValueOffset;
|
||||
// mPhysicalValueUINT = ((quint64)((quint64) mRawValue * mValueFactor)) + (quint64)mValueOffset;
|
||||
// mPhysicalValue = (qint64)((qint64) mRawValue * mValueFactor) + (qint64)mValueOffset;
|
||||
//JFM 2023-06-13 - Ajout casting des variables en fonction du data size.
|
||||
//L'idée c'est de contenir la valeur physique dans un double, ce qui permet de ne pas avoir à gérer le type
|
||||
//à chaque fois qu'on accède à la donnée. Mais pour que ça marche, il faut initialiser ce double comme il faut
|
||||
//en castant en fonction de la taille et du signe de la donnée
|
||||
qint64 SignedRawValue = 0;
|
||||
if(mSignalSize <= 8)
|
||||
{
|
||||
if(mValueType == CAN_SIGNAL_TYPE_SIGNED_INT)
|
||||
{
|
||||
SignedRawValue = (double)((qint8)mRawValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
SignedRawValue = (double)((quint8)mRawValue);
|
||||
}
|
||||
|
||||
}
|
||||
else if(mSignalSize <= 16)
|
||||
{
|
||||
if(mValueType == CAN_SIGNAL_TYPE_SIGNED_INT)
|
||||
{
|
||||
SignedRawValue = (double)((qint16)mRawValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
SignedRawValue = (double)((quint16)mRawValue);
|
||||
}
|
||||
// qint16 RawShort = (qint16)mRawValue;
|
||||
// SignedRawValue = (double)RawShort;
|
||||
}
|
||||
else if(mSignalSize <= 32)
|
||||
{
|
||||
if(mValueType == CAN_SIGNAL_TYPE_SIGNED_INT)
|
||||
{
|
||||
SignedRawValue = (double)((qint32)mRawValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
SignedRawValue = (double)((quint32)mRawValue);
|
||||
}
|
||||
//SignedRawValue = (signed)mRawValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(mValueType == CAN_SIGNAL_TYPE_SIGNED_INT)
|
||||
{
|
||||
SignedRawValue = (double)((signed)mRawValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
SignedRawValue = (double)(mRawValue);
|
||||
}
|
||||
}
|
||||
mPhysicalValue = (double)SignedRawValue;
|
||||
mPhysicalValue *= mValueFactor;
|
||||
mPhysicalValue += mValueOffset;
|
||||
|
||||
//JFM 2023-06-13 tentative de corriger le casting avec la vraie patente
|
||||
//mPhysicalValue = ((signed) mRawValue * mValueFactor) + mValueOffset;
|
||||
|
||||
|
||||
|
||||
return RET_OK;
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
|
||||
#include "CANWatchdog.h"
|
||||
#include "GeneralMessagesLogDispatcher.h"
|
||||
|
||||
CCANWatchdog::CCANWatchdog()
|
||||
{
|
||||
mCANDriverIF = new CPCANInterface;
|
||||
mIsCANInitialized = false;
|
||||
|
||||
mWatchdogTimer = new QTimer;
|
||||
mWatchdogTimer->setSingleShot(false);
|
||||
|
||||
connect(mWatchdogTimer,&QTimer::timeout,this,&CCANWatchdog::WatchdogTimeoutTimerExpired);
|
||||
}
|
||||
|
||||
int CCANWatchdog::Init(quint8 CANDeviceID, WORD CANDeviceBaudrate, unsigned int WDTPeriod)
|
||||
{
|
||||
if(WDTPeriod < 200)
|
||||
{
|
||||
WDTPeriod = 200;
|
||||
qDebug("CANWatchdog:: Trying to init with WDT period lower tan 200ms");
|
||||
}
|
||||
|
||||
mCANDeviceID = CANDeviceID;
|
||||
mWDTPeriod = WDTPeriod;
|
||||
mCANDeviceBaudrate = CANDeviceBaudrate;
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage("Démarrage du Watchdog CAN...");
|
||||
|
||||
if(mCANDriverIF->GetDeviceHandle(mCANDeviceID,mCANDeviceHandle) != RET_OK)
|
||||
{
|
||||
QString Log = QString("Impossible de trouver le module CAN Watchdog sur le channel %1").arg(mCANDeviceID);
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(Log,true,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_ERROR_STATUS);
|
||||
mIsCANInitialized = false;
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
|
||||
if(mCANDriverIF->Init(mCANDeviceHandle,mCANDeviceBaudrate) != RET_OK)
|
||||
{
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage("Impossible d'initialiser la puck CAN du Watchdog",true,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_ERROR_STATUS);
|
||||
mIsCANInitialized = false;
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
// mCANReadTimer->start(mCANPollPeriod);
|
||||
mIsCANInitialized = true;
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void CCANWatchdog::WatchdogTimeoutTimerExpired()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef CANWATCHDOG_H
|
||||
#define CANWATCHDOG_H
|
||||
|
||||
#include <QObject>
|
||||
#include "PCANInterface.h"
|
||||
#include <QTimer>
|
||||
|
||||
class CCANWatchdog: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CCANWatchdog();
|
||||
|
||||
int Init(quint8 CANDeviceID, TPCANBaudrate CANDeviceBaudrate, unsigned int WDTPeriod);
|
||||
|
||||
CPCANInterface *mCANDriverIF;
|
||||
unsigned int mWDTPeriod;
|
||||
quint8 mCANDeviceID;
|
||||
TPCANBaudrate mCANDeviceBaudrate;
|
||||
QTimer *mWatchdogTimer;
|
||||
|
||||
private:
|
||||
bool mIsCANInitialized;
|
||||
TPCANHandle mCANDeviceHandle;
|
||||
|
||||
public slots:
|
||||
void WatchdogTimeoutTimerExpired();
|
||||
|
||||
};
|
||||
|
||||
#endif // CANWATCHDOG_H
|
||||
@@ -0,0 +1,35 @@
|
||||
#include "CANWatchdogConfig.h"
|
||||
|
||||
CCANWatchdogConfig::CCANWatchdogConfig()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CCANWatchdogConfig& CCANWatchdogConfig::operator=(const CCANWatchdogConfig &source)
|
||||
{
|
||||
if(&source == this)
|
||||
return *this;
|
||||
|
||||
this->mCANDeviceID = source.mCANDeviceID;
|
||||
this->mCANDeviceBaudrate = source.mCANDeviceBaudrate;
|
||||
this->mWatchdogTimeout = source.mWatchdogTimeout;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &in, CCANWatchdogConfig &dest)
|
||||
{
|
||||
in >> dest.mCANDeviceID
|
||||
>> dest.mCANDeviceBaudrate
|
||||
>> dest.mWatchdogTimeout;
|
||||
return in;
|
||||
}
|
||||
QDataStream &operator<<(QDataStream &out, const CCANWatchdogConfig &source)
|
||||
{
|
||||
out << source.mCANDeviceID
|
||||
<< source.mCANDeviceBaudrate
|
||||
<< source.mWatchdogTimeout;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef CANWATCHDOGCONFIG_H
|
||||
#define CANWATCHDOGCONFIG_H
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QString>
|
||||
|
||||
#include "PCANBasic.h"
|
||||
|
||||
|
||||
class CCANWatchdogConfig
|
||||
{
|
||||
public:
|
||||
CCANWatchdogConfig();
|
||||
|
||||
quint8 mCANDeviceID;
|
||||
TPCANBaudrate mCANDeviceBaudrate;
|
||||
unsigned int mWatchdogTimeout;
|
||||
|
||||
CCANWatchdogConfig &operator=(const CCANWatchdogConfig &source);
|
||||
|
||||
};
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const CCANWatchdogConfig &source);
|
||||
QDataStream &operator>>(QDataStream &in, CCANWatchdogConfig &dest);
|
||||
#endif // CANWATCHDOGCONFIG_H
|
||||
Reference in New Issue
Block a user