Watchdog fonctionnel
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user