LAN Devices presence
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user