YULTek/Otarcik_CAN/Sources/ComputerBoardInterface.cpp

193 lines
4.7 KiB
C++

#include "defines.h"
#ifdef ENABLE_CHIPSET_DRIVER
#include "ComputerBoardInterface.h"
#include "AxUfiAPI.h"
#include "GeneralMessagesLogDispatcher.h"
#include "CPUWatchdogConfig.h"
CComputerBoardInterface::CComputerBoardInterface()
{
mWatchdogTimeout = CPU_DEFAULT_WATCHDOG_TIMEOUT;
mWatchdogEnabled = false;
}
int CComputerBoardInterface::Init()
{
if(LoadAxiomtekLibrary() == RET_OK)
{
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Librairie Axiomtek chargée avec succès"),"CComputerBoardInterface",true,1,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_SUCCESS_STATUS);
StopCPUWatchdog();
return RET_OK;
}
else
{
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Impossible de charger la librairie Axiomtek"),"CComputerBoardInterface",true,1,CGeneralMessagesLogDispatcher::GEN_MSG_TXT_ERROR_STATUS);
}
return RET_OK;
}
int CComputerBoardInterface::LoadAxiomtekLibrary()
{
int result, Direction;
Direction = 1;
char libname[] = CPU_LIBRARY_NAME;
// Suppress system error dialogs
result = AxBoardLoadLibrary(libname);
if(result)
{
AxSetDIODirection(0,&Direction);
AxSetDIODirection(1,&Direction);
AxSetDIODirection(2,&Direction);
AxSetDIODirection(3,&Direction);
AxSetDIODirection(4,&Direction);
AxSetDIODirection(5,&Direction);
AxSetDIODirection(6,&Direction);
AxSetDIODirection(7,&Direction);
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;
}
#include <windows.h>
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),"CComputerBoardInterface");
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é"),"CComputerBoardInterface");
}
return Ret;
}
int CComputerBoardInterface::KickCPUWatchdog()
{
AxWDTexec(bWDT_RELOAD);
return RET_OK;
}
int CComputerBoardInterface::SetWatchdogSettings(CCPUWatchdogConfig *Settings)
{
mWatchdogEnabled = Settings->mWatchdogEnabled;
mWatchdogTimeout = Settings->mWatchdogTimeout;
return RET_OK;
}
CComputerBoardState CComputerBoardInterface::GetComputerBoardState()
{
CComputerBoardState CPUState;
float tmp;
AxGetCPUTemp(&CPUState.mSystemTemperature);
// qDebug("CPUState.mSystemTemperature %f",CPUState.mSystemTemperature);
AxGetSYSTemp(&CPUState.mSystemTemperature);
// qDebug("CPUState.mSystemTemperature %f",CPUState.mSystemTemperature);
// AxGetGMCHTemp(&tmp);
// qDebug("AxGetGMCHTemp %f",tmp);
AxGetCPUVcore(&CPUState.mCPUVcore);
// qDebug("CPUState.mCPUVcore %f",CPUState.mCPUVcore);
// AxGetNBVTT(&tmp);
// qDebug("NBVTT %f",tmp);
AxGet3V(&CPUState.mSystem3V3);
// qDebug("CPUState.mSystem3V3 %f",CPUState.mSystem3V3);
AxGet5V(&CPUState.mSystem5V);
// qDebug("CPUState.mSystem5V %f",CPUState.mSystem5V);
AxGet12V(&CPUState.mSystem12V);
// qDebug("AxGet12V %f",tmp);
// AxGetNeg5V(&tmp);
// qDebug("AxGetNeg5V %f",tmp);
// AxGetNeg12V(&tmp);
// qDebug("AxGetNeg12V %f",tmp);
// AxGetVbat(&tmp);
// qDebug("AxGetVbat %f",tmp);
unsigned char IOPortState = 0;
int temp;
for(int i = 0; i < 7; i++)
{
unsigned char mask = 1;
AxGetDI(i,&temp);
if(temp != 0)
{
mask <<= i+1;
}
IOPortState |= mask;
}
CPUState.mIOPortState = IOPortState;
return CPUState;
}
#endif