56 lines
1.7 KiB
C++
56 lines
1.7 KiB
C++
|
|
#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,1,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,1,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_ERROR_STATUS);
|
|
mIsCANInitialized = false;
|
|
return RET_GENERAL_ERROR;
|
|
}
|
|
else
|
|
{
|
|
// mCANReadTimer->start(mCANPollPeriod);
|
|
mIsCANInitialized = true;
|
|
}
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
void CCANWatchdog::WatchdogTimeoutTimerExpired()
|
|
{
|
|
|
|
}
|