Implémentation LanDeviceMonitor

This commit is contained in:
2024-03-04 14:35:42 -05:00
parent 4400ff6144
commit bd720d25dc
13 changed files with 1217 additions and 174 deletions
+2 -2
View File
@@ -256,8 +256,8 @@
<rect>
<x>1210</x>
<y>290</y>
<width>301</width>
<height>161</height>
<width>201</width>
<height>121</height>
</rect>
</property>
<property name="title">
+90
View File
@@ -0,0 +1,90 @@
#include "LANDeviceMonitor.h"
CLANDeviceMonitor::CLANDeviceMonitor(QString IPAddress, unsigned int CANBit, bool Active, QString Description)
{
mDeviceIPAddress = IPAddress;
mCANStatusBit = CANBit;
mIsDetectionActive = Active;
mDeviceDescription = Description;
mIsDeviceOnline = false;
mDevMonitorTimer = 0;
mPingProcess = 0;
mIsPingInProgress = false;
if(mIsDetectionActive == true)
{
mDevMonitorTimer = new QTimer();
mDevMonitorTimer->setSingleShot(true);
connect(mDevMonitorTimer,&QTimer::timeout,this,&CLANDeviceMonitor::MonitorTimeExpired);
mPingProcess = new QProcess(this);
connect(mPingProcess,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(PingProcessFinished(int,QProcess::ExitStatus)));
PingDevice();
}
else
{
}
}
int CLANDeviceMonitor::PingDevice()
{
int PingTimeout = LAN_DEVICE_MONITOR_PING_TIMEOUT - 500;
QString Cmd = QString("ping /n 1 /w %1 %2").arg(PingTimeout).arg(mDeviceIPAddress);
mPingProcess->start(Cmd);
//mDevMonitorTimer->start(4000);
return RET_OK;
}
CLANDeviceMonitor::~CLANDeviceMonitor()
{
if(mDevMonitorTimer != 0)
delete mDevMonitorTimer;
if(mPingProcess != 0)
delete mPingProcess;
}
void CLANDeviceMonitor::MonitorTimeExpired()
{
PingDevice();
}
void CLANDeviceMonitor::PingProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
QString Result = mPingProcess->readAllStandardOutput();
if(Result.toLower().contains("ttl="))
{
//Online
mIsDeviceOnline = true;
qDebug("Device Online");
}
else
{
//Offline
mIsDeviceOnline = false;
qDebug("Device Offline");
}
GetDeviceCANStatusMask();
mDevMonitorTimer->start(LAN_DEVICE_MONITOR_PRESENCE_CHECK_TIMEOUT);
// qDebug("%s",qPrintable(Result));
}
quint64 CLANDeviceMonitor::GetDeviceCANStatusMask()
{
quint64 Mask = 0;
if(mIsDeviceOnline == false)
{
Mask = 1;
Mask <<= mCANStatusBit;
}
}
+42
View File
@@ -0,0 +1,42 @@
#ifndef LANDEVICEMONITOR_H
#define LANDEVICEMONITOR_H
#include <QObject>
#include "defines.h"
#include "LANDevicePresenceConfig.h"
#include <QProcess>
#include <QTimer>
#define LAN_DEVICE_MONITOR_PING_TIMEOUT 3000
#define LAN_DEVICE_MONITOR_PRESENCE_CHECK_TIMEOUT 5000
class CLANDeviceMonitor : public QObject
{
Q_OBJECT
public:
CLANDeviceMonitor(QString IPAddress, unsigned int CANBit, bool Active, QString Description = "");
~CLANDeviceMonitor();
int PingDevice();
quint64 GetDeviceCANStatusMask();
private:
QTimer *mDevMonitorTimer;
QString mDeviceIPAddress;
unsigned int mCANStatusBit;
bool mIsDetectionActive;
QString mDeviceDescription;
bool mIsDeviceOnline;
QProcess *mPingProcess;
bool mIsPingInProgress;
public slots:
void MonitorTimeExpired();
void PingProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
};
#endif // LANDEVICEMONITOR_H
+2 -1
View File
@@ -19,7 +19,8 @@
#include "QtEndian"
COtarcikCan::COtarcikCan(QObject *parent) : QObject(parent)
COtarcikCan::COtarcikCan(QObject *parent) : QObject(parent),
TestMonitor("192.168.50.40",32,true,"Test")
{
mGPTimer = new QTimer;
connect(mGPTimer,SIGNAL(timeout()),this,SLOT(GPTimerExpired()));
+2
View File
@@ -13,6 +13,7 @@
#include "SysLogger.h"
#include "InternetMonitor.h"
#include "LANDeviceMonitor.h"
class COtarcikCan : public QObject
{
@@ -29,6 +30,7 @@ public:
CSysLogger mSysLogger;
CInternetMonitor mInternetMonitor;
CLANDeviceMonitor TestMonitor;
int Start();