YULTek/Otarcik_CAN/Sources/ComputerBoardInterface.cpp

109 lines
2.3 KiB
C++

#include "ComputerBoardInterface.h"
#include "defines.h"
#include "AxUfiAPI.h"
#include "GeneralMessagesLogDispatcher.h"
CComputerBoardInterface::CComputerBoardInterface()
{
}
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);
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(int TimeoutInSeconds)
{
if(TimeoutInSeconds > (255*60) ) //Max of 255 minutes
{
return RET_GENERAL_ERROR;
}
int Ret;
quint16 RawTimeout = bWDT_SECOND;
if(TimeoutInSeconds <= 60)
{
RawTimeout = TimeoutInSeconds;
}
else
{
RawTimeout = TimeoutInSeconds/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(TimeoutInSeconds));
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;
}
return Ret;
}
int CComputerBoardInterface::KickCPUWatchdog()
{
AxWDTexec(bWDT_RELOAD);
return RET_OK;
}