add discovery to wifi detector

This commit is contained in:
Simon Stürz 2016-02-21 19:38:41 +01:00 committed by Michael Zanetti
parent d33f170106
commit 6e52d10185

View File

@ -28,7 +28,7 @@
This plugin allows to find and monitor network devices in your local network by using the MAC address. This plugin allows to find and monitor network devices in your local network by using the MAC address.
\underline{NOTE}: the application \c nmap has to be installed. \underline{NOTE}: the application \c nmap has to be installed and guh has to run as root.
\chapter Plugin properties \chapter Plugin properties
Following JSON file contains the definition and the description of all available \l{DeviceClass}{DeviceClasses} Following JSON file contains the definition and the description of all available \l{DeviceClass}{DeviceClasses}
@ -129,7 +129,6 @@ void DevicePluginWifiDetector::processFinished(int exitCode, QProcess::ExitStatu
if (result.startsWith("MAC Address:")) { if (result.startsWith("MAC Address:")) {
QStringList lineParts = result.split(' '); QStringList lineParts = result.split(' ');
if (lineParts.count() > 3) { if (lineParts.count() > 3) {
//qCDebug(dcWifiDetector) << result.remove("/n");
foundDevices << lineParts.at(2).toLower(); foundDevices << lineParts.at(2).toLower();
} }
} }
@ -137,10 +136,8 @@ void DevicePluginWifiDetector::processFinished(int exitCode, QProcess::ExitStatu
// check states // check states
foreach (Device *device, myDevices()) { foreach (Device *device, myDevices()) {
bool wasFound = foundDevices.contains(device->paramValue("mac address").toString().toLower()); bool found = foundDevices.contains(device->paramValue("mac address").toString().toLower());
if (device->stateValue(inRangeStateTypeId).toBool() != wasFound) { device->setStateValue(inRangeStateTypeId, found);
device->setStateValue(inRangeStateTypeId, wasFound);
}
} }
process->deleteLater(); process->deleteLater();
} }
@ -151,12 +148,10 @@ void DevicePluginWifiDetector::discoveryProcessFinished(int exitCode, QProcess::
qCDebug(dcWifiDetector) << "Discovery finished"; qCDebug(dcWifiDetector) << "Discovery finished";
if (m_discoveryProcesses.contains(process)) { if (!m_discoveryProcesses.contains(process))
m_discoveryProcesses.removeAll(process);
} else {
return; return;
}
m_discoveryProcesses.removeAll(process);
if (exitCode != 0 || exitStatus != QProcess::NormalExit) { if (exitCode != 0 || exitStatus != QProcess::NormalExit) {
qCWarning(dcWifiDetector) << "Network scan error:" << process->readAllStandardError(); qCWarning(dcWifiDetector) << "Network scan error:" << process->readAllStandardError();
process->deleteLater(); process->deleteLater();
@ -168,19 +163,20 @@ void DevicePluginWifiDetector::discoveryProcessFinished(int exitCode, QProcess::
if (result.startsWith("MAC Address:")) { if (result.startsWith("MAC Address:")) {
QStringList lineParts = result.split(' '); QStringList lineParts = result.split(' ');
if (lineParts.count() > 4) { if (lineParts.count() > 4) {
qCDebug(dcWifiDetector) << "-----------------------------------";
QString macAddress = lineParts.at(2).toLower(); QString macAddress = lineParts.at(2).toLower();
int index = result.indexOf(lineParts.at(2)); int index = result.indexOf(lineParts.at(2));
QString name = result.right(result.length() - index - macAddress.length() - 1); QString name = result.right(result.length() - index - macAddress.length() - 1).remove(QRegExp("\\(|\\)"));
qCDebug(dcWifiDetector) << "Address :" << macAddress; qCDebug(dcWifiDetector) << "Found" << name << macAddress.toLower();
qCDebug(dcWifiDetector) << "Interface:" << name.remove(QRegExp("\\(|\\)")); DeviceDescriptor descriptor(wifiDeviceClassId, name, macAddress);
m_deviceDescriptors.append(DeviceDescriptor(wifiDeviceClassId, macAddress, name.remove(QRegExp("\\(|\\)")))); ParamList params;
params.append(Param("name", name));
params.append(Param("mac address", macAddress));
descriptor.setParams(params);
m_deviceDescriptors.append(descriptor);
} }
} }
} }
if (m_discoveryProcesses.isEmpty()) { if (m_discoveryProcesses.isEmpty())
emit devicesDiscovered(wifiDeviceClassId, m_deviceDescriptors); emit devicesDiscovered(wifiDeviceClassId, m_deviceDescriptors);
}
} }