YULTek/Otarcik_CAN/Sources/ComputerBoardInterface.cpp

123 lines
2.8 KiB
C++

#include "ComputerBoardInterface.h"
#include "defines.h"
#include "AxUfiAPI.h"
#include "GeneralMessagesLogDispatcher.h"
#include "CPUWatchdogConfig.h"
CComputerBoardInterface::CComputerBoardInterface()
{
mWatchdogTimeout = CPU_DEFAULT_WATCHDOG_TIMEOUT;
mWatchdogEnabled = false;
}
int CComputerBoardInterface::Init()
{
if(LoadLibrary() == RET_OK)
{
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Librairie Axiomtek chargée avec succès"),true,1,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_SUCCESS_STATUS);
StopCPUWatchdog();
return RET_OK;
}
else
{
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Impossible de charger la librairie Axiomtek"),true,1,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_ERROR_STATUS);
}
return RET_OK;
}
int CComputerBoardInterface::LoadLibrary()
{
int result;
char libname[] = CPU_LIBRARY_NAME;
result = AxBoardLoadLibrary(libname);
if(result)
return RET_OK;
return RET_GENERAL_ERROR;
}
int CComputerBoardInterface::UnloadLibrary()
{
if(AxBoardReleaseLibrary() != 0)
{
return RET_OK;
}
return RET_GENERAL_ERROR;
}
int CComputerBoardInterface::DeInit()
{
return RET_OK;
}
int CComputerBoardInterface::StartCPUWatchdog()
{
// if(TimeoutInSeconds > (255*60) ) //Max of 255 minutes
// {
// return RET_GENERAL_ERROR;
// }
if(mWatchdogEnabled == false)
return RET_GENERAL_ERROR;
int Ret;
quint16 RawTimeout = bWDT_SECOND;
if(mWatchdogTimeout <= 60)
{
RawTimeout = mWatchdogTimeout;
}
else
{
RawTimeout = mWatchdogTimeout/60;
RawTimeout |= bWDT_MINUTE; //set the counter time base in minutes (high byte = 1)
}
if(AxWDTSetCounter(RawTimeout) != true)
{
Ret = RET_GENERAL_ERROR;
}
else
{
if(AxWDTexec(bWDT_ENABLE) == true)
{
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Watchdog CPU démarré. Timeout: %1 secondes").arg(mWatchdogTimeout));
Ret = RET_OK;
}
else
{
Ret = RET_GENERAL_ERROR;
}
}
return Ret;
}
int CComputerBoardInterface::StopCPUWatchdog()
{
int Ret = RET_OK;
if(AxWDTexec(bWDT_DISABLE) == false)
{
Ret = RET_GENERAL_ERROR;
}
else
{
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Watchdog CPU arrêté"));
}
return Ret;
}
int CComputerBoardInterface::KickCPUWatchdog()
{
AxWDTexec(bWDT_RELOAD);
return RET_OK;
}
int CComputerBoardInterface::SetWatchdogSettings(CCPUWatchdogConfig *Settings)
{
mWatchdogEnabled = Settings->mWatchdogEnabled;
mWatchdogTimeout = Settings->mWatchdogTimeout;
}