LAN Devices presence

This commit is contained in:
2024-03-05 16:29:13 -05:00
parent bd720d25dc
commit 32a0f76bf2
20 changed files with 1821 additions and 559 deletions
@@ -12,6 +12,11 @@ CDeviceDetectionConfig::CDeviceDetectionConfig()
mReportingCANMsgID = 300;
}
QList<CLANDevicePresenceConfig> *CDeviceDetectionConfig::GetLANDevicesConfigList()
{
return &mLANDeviceDetectConfigList;
}
QDataStream &operator>>(QDataStream &in, CDeviceDetectionConfig &dest)
{
in >> dest.mInternetDetectionCANStatusBit
@@ -9,11 +9,14 @@ class CDeviceDetectionConfig
public:
CDeviceDetectionConfig();
QList<CLANDevicePresenceConfig> *GetLANDevicesConfigList();
unsigned int mReportingCANMsgID;
quint64 mInternetDetectionCANStatusBit;
quint64 mMQTTDetectionCANStatusBit;
QList<CLANDevicePresenceConfig> mLANDeviceDetectConfigList;
CDeviceDetectionConfig &operator=(const CDeviceDetectionConfig &source);
};
@@ -53,7 +53,7 @@ CLoggingSettingsPage::CLoggingSettingsPage(QWidget *parent) :
ui->mDevicePresenceAdd5LineEdit->setText("192.168.10.555");
QStringList BitsList;
for(int i = 31; i < 64; i++)
for(int i = 32; i < 64; i++)
{
//BitsList.append(QString("%1").arg(i));
@@ -260,6 +260,100 @@ int CLoggingSettingsPage::UpdateCPUWatchdogParams()
return RET_OK;
}
int CLoggingSettingsPage::SetLANDevicesPresenceStatus(QList<bool> LANDevicesPresenceList)
{
if(LANDevicesPresenceList.size() != MAX_NB_LAN_DEVICE_DETECTION)
{
return RET_GENERAL_ERROR;
}
if(ui->mDevicePresenceActive1ChkBx->isChecked())
{
if(LANDevicesPresenceList.at(0) == true)
ui->mLANDevice1PresStatusLbl->setText("ONLINE");
else
ui->mLANDevice1PresStatusLbl->setText("OFFLINE");
}
else
{
ui->mLANDevice1PresStatusLbl->setText("N/A");
}
if(ui->mDevicePresenceActive2ChkBx->isChecked())
{
if(LANDevicesPresenceList.at(1) == true)
ui->mLANDevice2PresStatusLbl->setText("ONLINE");
else
ui->mLANDevice2PresStatusLbl->setText("OFFLINE");
}
else
{
ui->mLANDevice2PresStatusLbl->setText("N/A");
}
if(ui->mDevicePresenceActive3ChkBx->isChecked())
{
if(LANDevicesPresenceList.at(2) == true)
ui->mLANDevice3PresStatusLbl->setText("ONLINE");
else
ui->mLANDevice3PresStatusLbl->setText("OFFLINE");
}
else
{
ui->mLANDevice3PresStatusLbl->setText("N/A");
}
if(ui->mDevicePresenceActive4ChkBx->isChecked())
{
if(LANDevicesPresenceList.at(3) == true)
ui->mLANDevice4PresStatusLbl->setText("ONLINE");
else
ui->mLANDevice4PresStatusLbl->setText("OFFLINE");
}
else
{
ui->mLANDevice4PresStatusLbl->setText("N/A");
}
if(ui->mDevicePresenceActive5ChkBx->isChecked())
{
if(LANDevicesPresenceList.at(4) == true)
ui->mLANDevice5PresStatusLbl->setText("ONLINE");
else
ui->mLANDevice5PresStatusLbl->setText("OFFLINE");
}
else
{
ui->mLANDevice5PresStatusLbl->setText("N/A");
}
return RET_OK;
}
void CLoggingSettingsPage::SetInternetPresenceStatus(bool IsPresent)
{
if(IsPresent == true)
{
ui->mInternetPresenceStatusLbl->setText("ONLINE");
}
else
{
ui->mInternetPresenceStatusLbl->setText("OFFLINE");
}
}
int CLoggingSettingsPage::SetMQTTPresenceStatus(bool IsPresent)
{
if(IsPresent)
{
ui->mMQTTPresenceStatusLbl->setText("ONLINE");
}
else
{
ui->mMQTTPresenceStatusLbl->setText("OFFLINE");
}
return RET_OK;
}
void CLoggingSettingsPage::VerbosityParamsChanged(int value)
{
Q_UNUSED(value)
@@ -25,6 +25,8 @@ public:
int SetGeneralSettingsParams(const CGeneralSystemParams *GeneralParams);
int SetCPUWatchdogSettings(const CCPUWatchdogConfig *CPUWatchdogParams);
int SetDeviceConfigSettings(const CDeviceDetectionConfig *DevDetectCfgParams);
int SetMQTTPresenceStatus(bool);
int SetLANDevicesPresenceStatus(QList<bool> LANDevicesPresenceList);
@@ -60,6 +62,9 @@ public slots:
void DevicePresenceEnableChkBxChanged(int state);
void DevicePresenceModifyParamsBtnPressed();
void DevicePresenceCancelBtnPressed();
void SetInternetPresenceStatus(bool);
};
+121 -26
View File
@@ -508,19 +508,19 @@
<rect>
<x>1020</x>
<y>80</y>
<width>341</width>
<width>421</width>
<height>311</height>
</rect>
</property>
<property name="title">
<string>Assignations des flags à un signal CAN</string>
</property>
<widget class="QLabel" name="mInternetPresenceLbl_3">
<widget class="QLabel" name="mBITLbl">
<property name="geometry">
<rect>
<x>280</x>
<x>190</x>
<y>70</y>
<width>41</width>
<width>51</width>
<height>20</height>
</rect>
</property>
@@ -530,7 +530,7 @@
</font>
</property>
<property name="text">
<string>BIT</string>
<string>BIT CAN</string>
</property>
</widget>
<widget class="QLabel" name="mWatchdogMsgIDLbl">
@@ -576,7 +576,7 @@
<widget class="QLabel" name="mInternetPresenceLbl">
<property name="geometry">
<rect>
<x>120</x>
<x>40</x>
<y>100</y>
<width>131</width>
<height>16</height>
@@ -618,7 +618,7 @@
<widget class="QComboBox" name="mInternetPresBitComboBox">
<property name="geometry">
<rect>
<x>260</x>
<x>180</x>
<y>100</y>
<width>65</width>
<height>22</height>
@@ -628,10 +628,10 @@
<number>63</number>
</property>
</widget>
<widget class="QLabel" name="mMQTTPresenceLbl_4">
<widget class="QLabel" name="mMQTTPresenceLbl">
<property name="geometry">
<rect>
<x>110</x>
<x>30</x>
<y>130</y>
<width>141</width>
<height>16</height>
@@ -652,7 +652,7 @@
<widget class="QComboBox" name="mMQTTPresenceBitComboBox">
<property name="geometry">
<rect>
<x>260</x>
<x>180</x>
<y>130</y>
<width>65</width>
<height>22</height>
@@ -686,7 +686,7 @@
<rect>
<x>70</x>
<y>160</y>
<width>171</width>
<width>101</width>
<height>21</height>
</rect>
</property>
@@ -694,7 +694,7 @@
<widget class="QComboBox" name="mDevicePresenceBit1ComboBox">
<property name="geometry">
<rect>
<x>260</x>
<x>180</x>
<y>160</y>
<width>65</width>
<height>22</height>
@@ -719,7 +719,7 @@
<rect>
<x>70</x>
<y>190</y>
<width>171</width>
<width>101</width>
<height>21</height>
</rect>
</property>
@@ -727,7 +727,7 @@
<widget class="QComboBox" name="mDevicePresenceBit2ComboBox">
<property name="geometry">
<rect>
<x>260</x>
<x>180</x>
<y>190</y>
<width>65</width>
<height>22</height>
@@ -739,7 +739,7 @@
<rect>
<x>70</x>
<y>220</y>
<width>171</width>
<width>101</width>
<height>21</height>
</rect>
</property>
@@ -747,7 +747,7 @@
<widget class="QComboBox" name="mDevicePresenceBit3ComboBox">
<property name="geometry">
<rect>
<x>260</x>
<x>180</x>
<y>220</y>
<width>65</width>
<height>22</height>
@@ -783,7 +783,7 @@
<widget class="QComboBox" name="mDevicePresenceBit4ComboBox">
<property name="geometry">
<rect>
<x>260</x>
<x>180</x>
<y>250</y>
<width>65</width>
<height>22</height>
@@ -795,7 +795,7 @@
<rect>
<x>70</x>
<y>250</y>
<width>171</width>
<width>101</width>
<height>21</height>
</rect>
</property>
@@ -818,7 +818,7 @@
<rect>
<x>70</x>
<y>280</y>
<width>171</width>
<width>101</width>
<height>21</height>
</rect>
</property>
@@ -826,7 +826,7 @@
<widget class="QComboBox" name="mDevicePresenceBit5ComboBox">
<property name="geometry">
<rect>
<x>260</x>
<x>180</x>
<y>280</y>
<width>65</width>
<height>22</height>
@@ -836,10 +836,10 @@
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>20</x>
<y>60</y>
<width>241</width>
<height>31</height>
<x>290</x>
<y>20</y>
<width>121</width>
<height>51</height>
</rect>
</property>
<property name="font">
@@ -847,9 +847,104 @@
<pointsize>10</pointsize>
</font>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="text">
<string>Les bits 0 à 30 sont utilisés pour
la date et l'heure</string>
<string>Les bits 0 à 31 sont
utilisés pour la date
et l'heure</string>
</property>
</widget>
<widget class="QLabel" name="mLANDevice1PresStatusLbl">
<property name="geometry">
<rect>
<x>250</x>
<y>160</y>
<width>47</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>OFFLINE</string>
</property>
</widget>
<widget class="QLabel" name="mLANDevice2PresStatusLbl">
<property name="geometry">
<rect>
<x>250</x>
<y>190</y>
<width>47</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>OFFLINE</string>
</property>
</widget>
<widget class="QLabel" name="mLANDevice3PresStatusLbl">
<property name="geometry">
<rect>
<x>250</x>
<y>220</y>
<width>47</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>OFFLINE</string>
</property>
</widget>
<widget class="QLabel" name="mLANDevice4PresStatusLbl">
<property name="geometry">
<rect>
<x>250</x>
<y>250</y>
<width>47</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>OFFLINE</string>
</property>
</widget>
<widget class="QLabel" name="mLANDevice5PresStatusLbl">
<property name="geometry">
<rect>
<x>250</x>
<y>280</y>
<width>47</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>OFFLINE</string>
</property>
</widget>
<widget class="QLabel" name="mMQTTPresenceStatusLbl">
<property name="geometry">
<rect>
<x>250</x>
<y>130</y>
<width>47</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>OFFLINE</string>
</property>
</widget>
<widget class="QLabel" name="mInternetPresenceStatusLbl">
<property name="geometry">
<rect>
<x>250</x>
<y>100</y>
<width>47</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>OFFLINE</string>
</property>
</widget>
</widget>
+28 -5
View File
@@ -1,4 +1,6 @@
#include "LANDeviceMonitor.h"
#include <QString>
#include "GeneralMessagesLogDispatcher.h"
CLANDeviceMonitor::CLANDeviceMonitor(QString IPAddress, unsigned int CANBit, bool Active, QString Description)
{
@@ -43,9 +45,15 @@ int CLANDeviceMonitor::PingDevice()
CLANDeviceMonitor::~CLANDeviceMonitor()
{
if(mDevMonitorTimer != 0)
{
mDevMonitorTimer->stop();
delete mDevMonitorTimer;
}
if(mPingProcess != 0)
{
mPingProcess->terminate();
delete mPingProcess;
}
}
@@ -54,26 +62,39 @@ void CLANDeviceMonitor::MonitorTimeExpired()
PingDevice();
}
bool CLANDeviceMonitor::IsDeviceOnline()
{
return mIsDeviceOnline;
}
void CLANDeviceMonitor::PingProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
QString Result = mPingProcess->readAllStandardOutput();
if(Result.toLower().contains("ttl="))
{
//Online
if(mIsDeviceOnline == false)
{
QString Msg = QString("LAN Device %1 is now ONLINE on network").arg(mDeviceIPAddress);
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(Msg,"CLANDeviceMonitor");
}
mIsDeviceOnline = true;
qDebug("Device Online");
}
else
{
//Offline
if(mIsDeviceOnline == true)
{
QString Msg = QString("LAN Device %1 is now OFFLINE on network").arg(mDeviceIPAddress);
CGeneralMessagesLogDispatcher::instance()->AddLogMessage(Msg,"CLANDeviceMonitor");
}
mIsDeviceOnline = false;
qDebug("Device Offline");
}
GetDeviceCANStatusMask();
mDevMonitorTimer->start(LAN_DEVICE_MONITOR_PRESENCE_CHECK_TIMEOUT);
// qDebug("%s",qPrintable(Result));
}
@@ -82,9 +103,11 @@ void CLANDeviceMonitor::PingProcessFinished(int exitCode, QProcess::ExitStatus e
quint64 CLANDeviceMonitor::GetDeviceCANStatusMask()
{
quint64 Mask = 0;
if(mIsDeviceOnline == false)
if(mIsDetectionActive == true && mIsDeviceOnline == false)
{
Mask = 1;
Mask <<= mCANStatusBit;
}
return Mask;
}
+2 -1
View File
@@ -19,8 +19,8 @@ public:
CLANDeviceMonitor(QString IPAddress, unsigned int CANBit, bool Active, QString Description = "");
~CLANDeviceMonitor();
int PingDevice();
quint64 GetDeviceCANStatusMask();
bool IsDeviceOnline();
private:
QTimer *mDevMonitorTimer;
@@ -32,6 +32,7 @@ private:
QProcess *mPingProcess;
bool mIsPingInProgress;
int PingDevice();
public slots:
void MonitorTimeExpired();
@@ -0,0 +1,68 @@
#include "LANDevicesPresenceMonitor.h"
#include "OtarcikCan.h"
CLANDevicesPresenceMonitor::CLANDevicesPresenceMonitor()
{
mProgramPtr = 0;
mLANDevicesPresenceStateUpdateTimer = new QTimer;
mLANDevicesPresenceStateUpdateTimer->setInterval(LAN_DEVICE_MONITOR_PRESENCE_CHECK_TIMEOUT);
mLANDevicesPresenceStateUpdateTimer->setSingleShot(false);
connect(mLANDevicesPresenceStateUpdateTimer,&QTimer::timeout,this,&CLANDevicesPresenceMonitor::DevicesPresenceUpdateTimerExpired);
}
CLANDevicesPresenceMonitor::~CLANDevicesPresenceMonitor()
{
Stop();
delete mLANDevicesPresenceStateUpdateTimer;
}
int CLANDevicesPresenceMonitor::Start(QList<CLANDevicePresenceConfig> *LANDevicesList)
{
mLANMonitorList.clear();
for(int i = 0; i < LANDevicesList->size(); i++)
{
CLANDeviceMonitor *NewMonitor = new CLANDeviceMonitor(LANDevicesList->at(i).mDeviceIPAddress,LANDevicesList->at(i).mCANStatusBit,LANDevicesList->at(i).mIsDetectionActive,LANDevicesList->at(i).mDeviceDescription);
mLANMonitorList.append(NewMonitor);
}
mLANDevicesPresenceStateUpdateTimer->start();
return RET_OK;
}
int CLANDevicesPresenceMonitor::Stop()
{
//destroy all LAN monitors.
for(int i = 0; i < mLANMonitorList.size(); i++)
{
delete mLANMonitorList[i];
}
mLANMonitorList.clear();
mLANDevicesPresenceStateUpdateTimer->stop();
return RET_OK;
}
quint64 CLANDevicesPresenceMonitor::GetDevicesPresenceCANMask()
{
quint64 Mask = 0;
for(int i = 0; i < mLANMonitorList.size(); i++)
{
Mask |= mLANMonitorList[i]->GetDeviceCANStatusMask();
}
return Mask;
}
void CLANDevicesPresenceMonitor::DevicesPresenceUpdateTimerExpired()
{
QList<bool> DevicesStatusList;
for(int i = 0; i < mLANMonitorList.size(); i++)
{
bool Status = mLANMonitorList.at(i)->IsDeviceOnline();
DevicesStatusList.append(Status);
}
mProgramPtr->UpdateLANDevicesPresenceStatusRequest(DevicesStatusList);
}
@@ -0,0 +1,34 @@
#ifndef LANDEVICESPRESENCEMONITOR_H
#define LANDEVICESPRESENCEMONITOR_H
#include <QObject>
#include "LANDeviceMonitor.h"
#include "LANDevicePresenceConfig.h"
#include <QList>
#include <QTimer>
class COtarcikCan;
class CLANDevicesPresenceMonitor: public QObject
{
Q_OBJECT
public:
CLANDevicesPresenceMonitor();
~CLANDevicesPresenceMonitor();
int Start(QList<CLANDevicePresenceConfig> *LANDevicesList);
int Stop();
quint64 GetDevicesPresenceCANMask();
QTimer *mLANDevicesPresenceStateUpdateTimer;
COtarcikCan *mProgramPtr;
private:
QList<CLANDeviceMonitor*> mLANMonitorList;
public slots:
void DevicesPresenceUpdateTimerExpired();
};
#endif // LANDEVICESPRESENCEMONITOR_H
+16 -2
View File
@@ -19,8 +19,7 @@
#include "QtEndian"
COtarcikCan::COtarcikCan(QObject *parent) : QObject(parent),
TestMonitor("192.168.50.40",32,true,"Test")
COtarcikCan::COtarcikCan(QObject *parent) : QObject(parent)
{
mGPTimer = new QTimer;
connect(mGPTimer,SIGNAL(timeout()),this,SLOT(GPTimerExpired()));
@@ -55,6 +54,7 @@ int COtarcikCan::Start()
mMainWindow.mDataLoggingSettingsPage->mProgramHandle = this;
mMainWindow.mGeneralStatusPage->mProgramPtr = this;
mMainWindow.mGeneralStatusPage->mCPUInterface = &mCPUInterface;
mLANDevicesPresenceMonitor.mProgramPtr = this;
// mMainWindow.mCANWatchdogSettingsPage->mProgramHandle = this;
mMainWindow.show();
@@ -95,6 +95,9 @@ int COtarcikCan::Start()
mDeviceDetectionConfigParams = *mSystemConfig.GetDeviceDetectionConfig();
mMainWindow.mDataLoggingSettingsPage->SetDeviceConfigSettings(mSystemConfig.GetDeviceDetectionConfig());
mLANDevicesPresenceMonitor.Start(mSystemConfig.GetDeviceDetectionConfig()->GetLANDevicesConfigList());
// mMainWindow.mCANWatchdogSettingsPage->SetCANWatchdogConfig(mSystemConfig.GetCANWatchdogConfig());
// mGPTimer->setSingleShot(false);
@@ -120,6 +123,7 @@ int COtarcikCan::Start()
mMainWindow.mCANbusSettingsPage->SetDevicesList(&mCANDevicesList);
connect(&mInternetMonitor,&CInternetMonitor::InternetStateChanged,mMainWindow.mGeneralStatusPage,&CGeneralStatusPage::InternetStatusChanged);
connect(&mInternetMonitor,&CInternetMonitor::InternetStateChanged,mMainWindow.mDataLoggingSettingsPage,&CLoggingSettingsPage::SetInternetPresenceStatus);
mInternetMonitor.Start();
@@ -255,6 +259,9 @@ int COtarcikCan::SaveDeviceDetectionSettingsRequest(CDeviceDetectionConfig *Devi
mDeviceDetectionConfigParams = *DeviceDetectconfig;
mSystemConfig.SetDeviceDetectionConfig(DeviceDetectconfig);
mSystemConfig.SaveConfig();
mLANDevicesPresenceMonitor.Stop();
mLANDevicesPresenceMonitor.Start(DeviceDetectconfig->GetLANDevicesConfigList());
return RET_OK;
}
void COtarcikCan::GPTimerExpired()
@@ -269,6 +276,7 @@ int COtarcikCan::SetCANConnectionStatusRequest(bool Connected)
int COtarcikCan::SetMQTTConnectionSatusRequest(bool Connected)
{
mMainWindow.mDataLoggingSettingsPage->SetMQTTPresenceStatus(Connected);
return mMainWindow.mGeneralStatusPage->SetMQTTConnectionStatus(Connected);
}
@@ -283,6 +291,12 @@ int COtarcikCan::UpdateMQTTBufferingStatusRequest(QString BufferingMode, QString
return RET_OK;
}
int COtarcikCan::UpdateLANDevicesPresenceStatusRequest(QList<bool> LanDevicesStatus)
{
mMainWindow.mDataLoggingSettingsPage->SetLANDevicesPresenceStatus(LanDevicesStatus);
return RET_OK;
}
int COtarcikCan::SaveCANWatchdogSettingsRequest(CCANWatchdogConfig *CANWatchdogConfig)
{
mSystemConfig.SetCANWatchdogConfig(CANWatchdogConfig);
+4 -4
View File
@@ -12,8 +12,8 @@
#include "ComputerBoardInterface.h"
#include "SysLogger.h"
#include "InternetMonitor.h"
#include "LANDevicesPresenceMonitor.h"
#include "LANDeviceMonitor.h"
class COtarcikCan : public QObject
{
@@ -29,8 +29,8 @@ public:
QTimer *mWatchdogTimer;
CSysLogger mSysLogger;
CInternetMonitor mInternetMonitor;
CLANDevicesPresenceMonitor mLANDevicesPresenceMonitor;
CLANDeviceMonitor TestMonitor;
int Start();
@@ -46,10 +46,10 @@ public:
int SetCANConnectionStatusRequest(bool Connected);
int SetMQTTConnectionSatusRequest(bool Connected);
int UpdateCANModuleStatusRequest(QString ModuleName, QString ModuleStatus, QString Buffer);
int UpdateMQTTBufferingStatusRequest(QString BufferingMode, QString FIFOSize,QString RemainingTime);
int SaveCANWatchdogSettingsRequest(CCANWatchdogConfig *CANWatchdogConfig);
int UpdateLANDevicesPresenceStatusRequest(QList<bool> LanDevicesStatus);