Ajout Watchdog hardware au programme + autres gossages

This commit is contained in:
2023-10-28 13:04:55 -04:00
parent 868d07b879
commit efc3b85456
48 changed files with 1876 additions and 126 deletions
Binary file not shown.
+198
View File
@@ -0,0 +1,198 @@
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the ICO1000_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// ICO1000_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
//#ifdef ICO1000_EXPORTS
//#define ICO1000_API __declspec(dllexport)
//#else
//#define AxHWInfo_API __declspec(dllimport)
//#endif
#ifndef AxHWInfo_H
#define AxHWInfo_H
#define ID_SBC86831 1
#define ID_SBC84620 2
#define ID_SBC86837 3
// Windows OS Version define
//32bit OS
#define OS_WIN95 0x0001
#define OS_WIN98 0x0002
#define OS_WINME 0x0003
#define OS_WIN2000 0x0004
#define OS_WINNT 0x0005
#define OS_WINXP 0x0006
#define OS_VISTA 0x0007
#define OS_SERVER2003 0x0008
#define OS_WINDOWS7 0x0009
//64bit OS
#define OS64_WINXP 0x0101
#define OS64_VISTA 0x0102
#define OS64_WINDOWS7 0x0103
//Digital IO pin define
#define DIO_PIN0 0x01
#define DIO_PIN1 0x02
#define DIO_PIN2 0x04
#define DIO_PIN3 0x08
#define DIO_PIN4 0x10
#define DIO_PIN5 0x20
#define DIO_PIN6 0x40
#define DIO_PIN7 0x80
// DIO Direction Setting
#define DIO0_OUTPUT 0x00
#define DIO0_INPUT 0x01
#define DIO1_OUTPUT 0x00
#define DIO1_INPUT 0x02
#define DIO2_OUTPUT 0x00
#define DIO2_INPUT 0x04
#define DIO3_OUTPUT 0x00
#define DIO3_INPUT 0x08
#define DIO4_OUTPUT 0x00
#define DIO4_INPUT 0x10
#define DIO5_OUTPUT 0x00
#define DIO5_INPUT 0x20
#define DIO6_OUTPUT 0x00
#define DIO6_INPUT 0x40
#define DIO7_OUTPUT 0x00
#define DIO7_INPUT 0x80
//Watch Dog Timer define
#define bWDT_MINUTE 0x0100
#define bWDT_SECOND 0x0000
#define bWDT_ENABLE 0x0001
#define bWDT_DISABLE 0x0002
#define bWDT_RELOAD 0x0003
#define bWDT_EVENT 0x0004
#define bWDT_EVENT_CLR 0x0005
//*******************************
//**** Smart Battery Kit define
//*******************************
//AxGetBatteryKitStatus
#define fExist_BatteryCharger 0x00000001 //bit 0~7 BatteryKit Exist
#define fExist_BatteryData 0x00000002
#define fExist_BatterySelector 0x00000004
#define fChargerInhibit 0x00000100 //bit 8~15 charger status
#define fAC_Present 0x00000200
#define fBattery_Present 0x00000400
#define fBatteryFullCharged 0x00010000 //bit 16~23 battery status
#define fBatteryDischarging 0x00020000
#define fBatteryOverTempAlarm 0x00040000
// //bit 24~31 selector status
//AxSetChargerMode
#define bInhibitCharge 0x0001
#define bEnablePolling 0x0002
#define bPowerOnDefault 0x0004
#define bChargingToZero 0x0008
//AxSetBatteryMode
#define bEnableInternalCharger 0x0100 //bit8
#define bPrimaryBattery 0x0200 //bit9
#define bDisableAlarmBroadcasts 0x2000 //bit13
#define bDisableBroadcastsCharging 0x4000 //bit14,disable charging vlotage and current broadcasts
#define bReportWattMode 0x8000 //bit15, set mA to mW
typedef struct BATTERY_MANUFACTURER {
wchar_t sManufacturerName[33];
wchar_t sDeviceName[33];
wchar_t sDeviceChemistry[33];
}AxBatteryManufacturer;
typedef struct BATTERY_CAPACITY {
unsigned short PercentageOfFull;
unsigned short PercentageOfDesign;
unsigned short RemainingCapacity;
unsigned short FullChargeCapacity;
unsigned short DesignCapacity;
}AxBatteryCapacity;
typedef struct BATTERY_RUNTIME {
short PercentageOfFull;
short BatteryCurrent;
short BatteryVoltage;
unsigned short RunTimeToEmpty;
unsigned short Temperature;
}AxBatteryRuntime;
typedef struct SBC_DS2401 {
long double dlBoardID;
unsigned char bBoardID[6];
unsigned char sBoardID[13];
}sbc_ds2401;
#ifdef AXuAPI_DLL
#define AXuAPI _declspec(dllexport)
#else
//#define AXuAPI _declspec(dllimport)
#define AXuAPI
#endif
extern "C"
{
/** Hardware Library Control Function **/
AXuAPI BOOL __stdcall AxBoardLoadLibrary(char *dllname);
AXuAPI BOOL __stdcall AxBoardReleaseLibrary(void);
/*************** Needs Boadr Level Library -Start- ***************/
/** Hardware Monitor Function ***/
AXuAPI BOOL __stdcall AxGetCPUTemp(float * fValue);
AXuAPI BOOL __stdcall AxGetSYSTemp(float * fValue);
AXuAPI BOOL __stdcall AxGetGMCHTemp(float * fValue);
AXuAPI BOOL __stdcall AxGetCPUFAN(float * fValue);
AXuAPI BOOL __stdcall AxGetSYSFAN(float * fValue);
AXuAPI BOOL __stdcall AxGetGMCHFAN(float * fValue);
AXuAPI BOOL __stdcall AxGetCPUVcore(float * fValue);
AXuAPI BOOL __stdcall AxGetNBVTT(float * fValue);
AXuAPI BOOL __stdcall AxGet3V(float * fValue);
AXuAPI BOOL __stdcall AxGet5V(float * fValue);
AXuAPI BOOL __stdcall AxGet12V(float * fValue);
AXuAPI BOOL __stdcall AxGetNeg5V(float * fValue);
AXuAPI BOOL __stdcall AxGetNeg12V(float * fValue);
AXuAPI BOOL __stdcall AxGetVbat(float * fValue);
/** Digital IO Function **/
AXuAPI BOOL __stdcall AxGetDI(int pin, int *pinData);
AXuAPI BOOL __stdcall AxGetDO(int pin, int *pinData);
AXuAPI BOOL __stdcall AxSetDO(int pin, int *pinData);
AXuAPI BOOL __stdcall AxGetDIOValidPin(int pin, int *pinData);
AXuAPI BOOL __stdcall AxSetDIODirection(int pin, int *pinData);
/** Watch dog Timer Function **/
AXuAPI BOOL __stdcall AxWDTSetCounter(int timeCounter);
AXuAPI BOOL __stdcall AxWDTexec(int subFunction);
AXuAPI BOOL __stdcall AxWDTOutputPin(int sunFunction);
AXuAPI BOOL __stdcall AxWDTEvent(int sunFunction, int *repData);
/*************** Needs Boadr Level Library -End- ******************/
/** Unique Board ID Function **/
AXuAPI BOOL __stdcall AxGetBoardID(SBC_DS2401 *sbc_bid);
/* Utilities Function **/
AXuAPI int __stdcall AxOS_Version(void);
AXuAPI BOOL __stdcall AxSystemReboot(void);
AXuAPI BOOL __stdcall AxSystemShutdown(void);
AXuAPI BOOL __stdcall AxSBC_BIOSID(char *biosid);
/* SMBus I2C Function */
AXuAPI BOOL __stdcall AxQueryI2CDevice(UCHAR I2CAddress);
AXuAPI BOOL __stdcall AxReadI2CByte(UCHAR I2CAddress, UCHAR I2CRegister, LPBYTE pDataBuffer);
AXuAPI BOOL __stdcall AxReadI2CWord(UCHAR I2CAddress, UCHAR I2CRegister, LPBYTE pDataBuffer);
AXuAPI BOOL __stdcall AxWriteI2CByte(UCHAR I2CAddress, UCHAR I2CRegister, LPBYTE pDataBuffer);
AXuAPI BOOL __stdcall AxWriteI2CWord(UCHAR I2CAddress, UCHAR I2CRegister, LPBYTE pDataBuffer);
AXuAPI BOOL __stdcall AxGetSMBusAddress(USHORT * pSMBusAddress);
AXuAPI BOOL __stdcall AxReadI2CBlock(UCHAR I2CAddress, UCHAR I2CRegister, LPBYTE pDataBuffer);
/* Smart Battery Kit Function */
AXuAPI BOOL __stdcall AxGetBatteryKitStatus(ULONG * plBatteryKitStatus);
AXuAPI BOOL __stdcall AxGetBatteryManufacturer(AxBatteryManufacturer * pBatteryManufacturer);
AXuAPI BOOL __stdcall AxGetBatteryCapacity(AxBatteryCapacity * pBatteryCapacity);
AXuAPI BOOL __stdcall AxGetBatteryRuntime(AxBatteryRuntime * pBatteryRuntime);
AXuAPI BOOL __stdcall AxSetChargerMode(USHORT wChargerMode);
AXuAPI BOOL __stdcall AxSetBatteryMode(USHORT wBatteryMode);
AXuAPI BOOL __stdcall AxGetBatteryMode(USHORT * pwBatteryMode);
}
#endif
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,108 @@
#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;
}
@@ -0,0 +1,23 @@
#ifndef COMPUTERBOARDINTERFACE_H
#define COMPUTERBOARDINTERFACE_H
#include "minwindef.h"
#define CPU_DEFAULT_WATCHDOG_TIMEOUT 600 //10 minutes.
#define CPU_LIBRARY_NAME "dtSBC87853x64"
class CComputerBoardInterface
{
public:
CComputerBoardInterface();
int Init();
int DeInit();
int StartCPUWatchdog(int TimeoutInSeconds = CPU_DEFAULT_WATCHDOG_TIMEOUT); //Timeout in seconds
int StopCPUWatchdog();
int KickCPUWatchdog();
private:
int LoadLibrary();
int UnloadLibrary();
};
#endif // COMPUTERBOARDINTERFACE_H
@@ -3,6 +3,7 @@
#include "QStringList"
#include <QScrollBar>
#include <QLibrary>
#include "OtarcikCan.h"
CGeneralStatusPage::CGeneralStatusPage(QWidget *parent) :
QWidget(parent),
@@ -11,6 +12,7 @@ CGeneralStatusPage::CGeneralStatusPage(QWidget *parent) :
ui->setupUi(this);
connect(ui->mClearGenMsgTxtBtn,&QPushButton::clicked,this,&CGeneralStatusPage::ClearGenMsgAreaBtnPressed);
connect(ui->mQuitAppBtn,&QPushButton::clicked,this,&CGeneralStatusPage::QuitAppBtnPressed);
SetMQTTConnectionStatus(false);
SetCANConnectionStatus(false);
@@ -194,3 +196,8 @@ int CGeneralStatusPage::UpdateCANModuleStatus(QString ModuleName, QString Module
return RET_OK;
}
void CGeneralStatusPage::QuitAppBtnPressed()
{
mProgramPtr->QuitApplicationRequest();
}
@@ -9,6 +9,8 @@ namespace Ui {
class CGeneralStatusPage;
}
class COtarcikCan;
class CGeneralStatusPage : public QWidget
{
Q_OBJECT
@@ -24,6 +26,8 @@ public:
GEN_STATUS_PG_MAX_TEXT_VALUE
};
COtarcikCan *mProgramPtr;
explicit CGeneralStatusPage(QWidget *parent = 0);
~CGeneralStatusPage();
@@ -45,6 +49,7 @@ private:
public slots:
void ClearGenMsgAreaBtnPressed();
void QuitAppBtnPressed();
};
@@ -153,6 +153,19 @@
<string>Statut des module CAN </string>
</property>
</widget>
<widget class="QPushButton" name="mQuitAppBtn">
<property name="geometry">
<rect>
<x>1529</x>
<y>560</y>
<width>131</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>Quitter l'application</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
+2 -2
View File
@@ -22,7 +22,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
ui(new Ui::CMainWindow)
{
ui->setupUi(this);
QMainWindow::statusBar()->showMessage("V1.04");
QMainWindow::statusBar()->showMessage("V1.05");
mGeneralStatusPage = new CGeneralStatusPage(this);
mMainWindowWidget = new QTabWidget(this);
@@ -41,7 +41,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
// mProgramsSettingsTabWidget->addTab(mCANWatchdogSettingsPage,"Watchdog");
mProgramsSettingsTabWidget->addTab(mDataLoggingSettingsPage,"Archivage");
setWindowFlags(Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint);
resize(1700,768);
}
+1
View File
@@ -32,6 +32,7 @@ public:
CCANWatchdogSettingsPage *mCANWatchdogSettingsPage;
private:
Ui::CMainWindow *ui;
};
+34 -6
View File
@@ -18,15 +18,22 @@
#include "PCANBasic.h"
#include "QtEndian"
COtarcikCan::COtarcikCan(QObject *parent) : QObject(parent)
{
mGPTimer = new QTimer;
connect(mGPTimer,SIGNAL(timeout()),this,SLOT(GPTimerExpired()));
mCANBusMQTTClient.mProgramPtr = this;
mWatchdogTimer = new QTimer;
connect(mWatchdogTimer,&QTimer::timeout,this,&COtarcikCan::WatchdogUpdateTimerExpired);
mWatchdogTimer->setSingleShot(false);
mWatchdogTimer->setInterval(1000);
}
COtarcikCan::~COtarcikCan()
{
qDebug("Destruction");
while (!mCANDevicesList.isEmpty())
{
@@ -38,15 +45,14 @@ COtarcikCan::~COtarcikCan()
delete mGPTimer;
delete mWatchdogTimer;
}
int COtarcikCan::Start()
{
mMainWindow.mCANbusSettingsPage->mProgramPtr = this;
mMainWindow.mDataLoggingSettingsPage->mProgramHandle = this;
mMainWindow.mGeneralStatusPage->mProgramPtr = this;
// mMainWindow.mCANWatchdogSettingsPage->mProgramHandle = this;
mMainWindow.show();
@@ -58,6 +64,8 @@ int COtarcikCan::Start()
// CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Démarrage du logiciel OtarcikCAN"));
mCPUInterface.Init();
if(mSystemConfig.LoadConfig() == RET_OK)
{
QList<CCANDeviceConfig*> *CANDeviceConfigList;
@@ -66,9 +74,6 @@ int COtarcikCan::Start()
{
PopulateCANDevicesList(CANDeviceConfigList);
}
mMainWindow.mCANbusSettingsPage->SetDevicesList(&mCANDevicesList);
mMainWindow.mCANViewerPage->InitCANTable(&mCANDevicesList);
@@ -86,8 +91,15 @@ int COtarcikCan::Start()
// mGPTimer->setSingleShot(false);
// mGPTimer->start(5000);
mCPUInterface.StartCPUWatchdog(25);
mWatchdogTimer->start();
}
else
{
mCPUInterface.StartCPUWatchdog();
mWatchdogTimer->start();
}
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(QString("Démarrage du logiciel OtarcikCAN"));
@@ -96,6 +108,8 @@ int COtarcikCan::Start()
mCANBusMQTTClient.StartMQTTClient();
mMainWindow.mCANbusSettingsPage->SetDevicesList(&mCANDevicesList);
return 0;
}
@@ -234,3 +248,17 @@ int COtarcikCan::SaveCANWatchdogSettingsRequest(CCANWatchdogConfig *CANWatchdogC
return mSystemConfig.SaveConfig();
}
void COtarcikCan::WatchdogUpdateTimerExpired() //Time to kick the CPU watchdog
{
mCPUInterface.KickCPUWatchdog();
}
void COtarcikCan::QuitApplicationRequest()
{
qDebug("Quit app request");
mWatchdogTimer->stop();
mCPUInterface.StopCPUWatchdog();
mCPUInterface.DeInit();
QCoreApplication::quit();
}
+6
View File
@@ -9,6 +9,7 @@
#include <QList>
#include "SystemConfig.h"
#include "MQTTClientWrapper.h"
#include "ComputerBoardInterface.h"
class COtarcikCan : public QObject
@@ -21,6 +22,8 @@ public:
CSystemConfig mSystemConfig;
CMQTTClientWrapper mCANBusMQTTClient;
QTimer *mGPTimer;
CComputerBoardInterface mCPUInterface;
QTimer *mWatchdogTimer;
int Start();
@@ -38,6 +41,8 @@ public:
int SaveCANWatchdogSettingsRequest(CCANWatchdogConfig *CANWatchdogConfig);
void QuitApplicationRequest();
private:
QList<CCANDevice*> mCANDevicesList;
CCloudParams mCloudLoggingParams;
@@ -50,6 +55,7 @@ signals:
public slots:
void GPTimerExpired();
void WatchdogUpdateTimerExpired();
};
#endif // OTARCIKCAN_H