Watchdog fonctionnel
This commit is contained in:
@@ -67,7 +67,6 @@ int CCANDevice::Init()
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
|
||||
mIsCANInitialized = true;
|
||||
|
||||
if(mCANDatabase.Init(mDeviceConfigInfo.mCANDeviceDatabaseFilename) == RET_OK)
|
||||
{
|
||||
@@ -82,6 +81,9 @@ int CCANDevice::Init()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// if(mCANAnalyzer.Init(mDeviceConfigInfo.mCANDeviceID,mDeviceConfigInfo.mCANDeviceBaudrate,&mMessageList,mDeviceConfigInfo.mDevicePollPeriod) != RET_OK)
|
||||
if(mCANAnalyzer.Init(mCANDriverIF,mDeviceHandle,mDeviceConfigInfo.mCANDeviceID,&mMessageList,mDeviceConfigInfo.mDevicePollPeriod) != RET_OK)
|
||||
{
|
||||
@@ -91,6 +93,20 @@ int CCANDevice::Init()
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
|
||||
if(mDeviceConfigInfo.mDeviceWatchdogActivated == true)
|
||||
{
|
||||
if(mCANWatchdog.Init(mCANDriverIF,mDeviceHandle,mDeviceConfigInfo.mWatchdogPeriod,mDeviceConfigInfo.mWatchdogCANMsgID) != RET_OK)
|
||||
{
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage("Impossible d'initialiser un watchdog CAN",true,1,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_ERROR_STATUS);
|
||||
}
|
||||
mCANWatchdog.StartWDT();
|
||||
|
||||
QString Log = QString("Watchdog CAN initialisé pour le module sur le channel %1").arg(mDeviceConfigInfo.mCANDeviceID);
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(Log,true,1,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_SUCCESS_STATUS);
|
||||
}
|
||||
|
||||
mIsCANInitialized = true;
|
||||
|
||||
#ifdef USE_TOPIC_PREFIX
|
||||
mCANDataLogger.SetMQTTTopicDevice(QString("%2CANBus/%1/").arg(mDeviceConfigInfo.mDeviceName).arg(mDeviceTopicPrefix));
|
||||
#else
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "CANDeviceConfig.h"
|
||||
#include "CANDataLogger.h"
|
||||
#include "MQTTMessage.h"
|
||||
#include "CANWatchdog.h"
|
||||
//#include "MQTTClientWrapper.h"
|
||||
|
||||
class CMQTTClientWrapper;
|
||||
@@ -39,6 +40,7 @@ public:
|
||||
CCANDataLogger mCANDataLogger;
|
||||
CMQTTClientWrapper *mCANMQTTClient;
|
||||
QString mDeviceTopicPrefix;
|
||||
CCANWatchdog mCANWatchdog;
|
||||
|
||||
QList<CCANMessage*> mMessageList;
|
||||
QList<CMQTTMessage> *GetMQTTMessagesList();
|
||||
|
||||
@@ -9,47 +9,66 @@ CCANWatchdog::CCANWatchdog()
|
||||
|
||||
mWatchdogTimer = new QTimer;
|
||||
mWatchdogTimer->setSingleShot(false);
|
||||
mCANDriverIF = 0;
|
||||
mWDTInitialized = false;
|
||||
|
||||
connect(mWatchdogTimer,&QTimer::timeout,this,&CCANWatchdog::WatchdogTimeoutTimerExpired);
|
||||
}
|
||||
|
||||
int CCANWatchdog::Init(quint8 CANDeviceID, WORD CANDeviceBaudrate, unsigned int WDTPeriod)
|
||||
int CCANWatchdog::Init(CPCANInterface *CANDriverIF, TPCANHandle CANDeviceHandle, unsigned int WDTPeriod, unsigned int CANMsgID)
|
||||
{
|
||||
if(WDTPeriod < 200)
|
||||
{
|
||||
WDTPeriod = 200;
|
||||
qDebug("CANWatchdog:: Trying to init with WDT period lower tan 200ms");
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
|
||||
mCANDeviceID = CANDeviceID;
|
||||
mCANDeviceHandle = CANDeviceHandle;
|
||||
mWDTPeriod = WDTPeriod;
|
||||
mCANDeviceBaudrate = CANDeviceBaudrate;
|
||||
mCANDriverIF = CANDriverIF;
|
||||
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,1,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_ERROR_STATUS);
|
||||
mIsCANInitialized = false;
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
mWatchdogTimer->setInterval(mWDTPeriod);
|
||||
mWatchdogTimer->setSingleShot(false);
|
||||
|
||||
if(mCANDriverIF->Init(mCANDeviceHandle,mCANDeviceBaudrate) != RET_OK)
|
||||
{
|
||||
CGeneralMessagesLogDispatcher::instance()->AddLogMessage("Impossible d'initialiser la puck CAN du Watchdog",true,1,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_ERROR_STATUS);
|
||||
mIsCANInitialized = false;
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
// mCANReadTimer->start(mCANPollPeriod);
|
||||
mIsCANInitialized = true;
|
||||
}
|
||||
mWDTCANMsg.mCANMsgID = CANMsgID;
|
||||
mWDTCANMsg.mCANMsgLength = 1;
|
||||
mWDTCANMsg.mCANMsgData.clear();
|
||||
mWDTCANMsg.mCANMsgData.append(8,(char)0x00);
|
||||
mWDTCANMsg.mCANMsgName = "Watchdog";
|
||||
|
||||
mWDTInitialized = true;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void CCANWatchdog::WatchdogTimeoutTimerExpired()
|
||||
{
|
||||
|
||||
char data = mWDTCANMsg.mCANMsgData[0];
|
||||
data ^= (char)0x01;
|
||||
mWDTCANMsg.mCANMsgData[0] = data;
|
||||
mCANDriverIF->SendCANMessage(mCANDeviceHandle,mWDTCANMsg);
|
||||
// qDebug("Sending 0x%X to CAN",data);
|
||||
}
|
||||
|
||||
int CCANWatchdog::StartWDT()
|
||||
{
|
||||
if(mWDTInitialized == false)
|
||||
{
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
|
||||
mWatchdogTimer->start();
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int CCANWatchdog::StopWDT()
|
||||
{
|
||||
if(mWDTInitialized == false)
|
||||
{
|
||||
return RET_GENERAL_ERROR;
|
||||
}
|
||||
mWatchdogTimer->stop();
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QObject>
|
||||
#include "PCANInterface.h"
|
||||
#include <QTimer>
|
||||
#include "CANMessage.h"
|
||||
|
||||
class CCANWatchdog: public QObject
|
||||
{
|
||||
@@ -12,18 +13,22 @@ class CCANWatchdog: public QObject
|
||||
public:
|
||||
CCANWatchdog();
|
||||
|
||||
int Init(quint8 CANDeviceID, TPCANBaudrate CANDeviceBaudrate, unsigned int WDTPeriod);
|
||||
int Init(CPCANInterface *CANDriverIF, TPCANHandle CANDeviceHandle, unsigned int WDTPeriod,unsigned int CANMsgID);
|
||||
int StartWDT();
|
||||
int StopWDT();
|
||||
bool IsInitialized(){return mWDTInitialized;}
|
||||
|
||||
CPCANInterface *mCANDriverIF;
|
||||
unsigned int mWDTPeriod;
|
||||
quint8 mCANDeviceID;
|
||||
TPCANBaudrate mCANDeviceBaudrate;
|
||||
QTimer *mWatchdogTimer;
|
||||
bool mWDTInitialized;
|
||||
CCANMessage mWDTCANMsg;
|
||||
|
||||
private:
|
||||
bool mIsCANInitialized;
|
||||
TPCANHandle mCANDeviceHandle;
|
||||
|
||||
|
||||
public slots:
|
||||
void WatchdogTimeoutTimerExpired();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user