From c54b66120c3749e349fc526d95174d2cbc231dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Wed, 19 Feb 2020 17:08:08 -0300 Subject: [PATCH 1/7] DeviceManagerViewer: Remove connection arguments from user viewer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removes baudrate and UDP port from user interface Signed-off-by: Patrick José Pereira --- qml/DeviceManagerViewer.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qml/DeviceManagerViewer.qml b/qml/DeviceManagerViewer.qml index 21bdcbf4a..67e0832c9 100644 --- a/qml/DeviceManagerViewer.qml +++ b/qml/DeviceManagerViewer.qml @@ -209,7 +209,7 @@ PingPopup { Label { Layout.fillWidth: true horizontalAlignment: Text.AlignHCenter - text: connection.typeToString() + " " + connection.createConfString() + text: connection.typeToString() + " " + connection.argsAsConst()[0] } StatusIndicator { From 46eba0bf5bd2439b6f6a8263b9a3331e6aa9aa99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Wed, 19 Feb 2020 17:09:11 -0300 Subject: [PATCH 2/7] devicemanager: Add some missing const MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- src/devicemanager/devicemanager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/devicemanager/devicemanager.cpp b/src/devicemanager/devicemanager.cpp index ac226b3fc..d5347eed9 100644 --- a/src/devicemanager/devicemanager.cpp +++ b/src/devicemanager/devicemanager.cpp @@ -29,7 +29,7 @@ DeviceManager::DeviceManager() void DeviceManager::append(const LinkConfiguration& linkConf, const QString& deviceName, const QString& detectorName) { for (int i {0}; i < _sensors[Connection].size(); i++) { - auto vectorLinkConf = _sensors[Connection][i].value>().get(); + const auto vectorLinkConf = _sensors[Connection][i].value>().get(); if (*vectorLinkConf == linkConf) { qCDebug(DEVICEMANAGER) << "Connection configuration already exist for:" << _sensors[Name][i] << linkConf << linkConf.argsAsConst(); @@ -153,7 +153,7 @@ void DeviceManager::updateAvailableConnections( qCDebug(DEVICEMANAGER) << "Available devices:" << availableLinkConfigurations; // Make all connections unavailable by default for (int i {0}; i < _sensors[Available].size(); i++) { - auto linkConf = _sensors[Connection][i].value>(); + const auto linkConf = _sensors[Connection][i].value>(); if (linkConf->isSimulation() || _sensors[DetectorName][i] != detector) { continue; } From 196ae930cb23a0d0c2bc216680cdbca16009347e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Wed, 19 Feb 2020 17:12:14 -0300 Subject: [PATCH 3/7] linkconfiguration: Define operator!= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- src/link/linkconfiguration.cpp | 2 ++ src/link/linkconfiguration.h | 1 + 2 files changed, 3 insertions(+) diff --git a/src/link/linkconfiguration.cpp b/src/link/linkconfiguration.cpp index 9ad67b536..5c55c7d1b 100644 --- a/src/link/linkconfiguration.cpp +++ b/src/link/linkconfiguration.cpp @@ -145,6 +145,8 @@ bool operator==(const LinkConfiguration& first, const LinkConfiguration& second) && (firstLinkconf.deviceType == secondLinkconf.deviceType); } +bool operator!=(const LinkConfiguration& first, const LinkConfiguration& second) { return !(first == second); } + QDebug operator<<(QDebug d, const LinkConfiguration& other) { QString text(QStringLiteral("LinkConfiguration{Name: %1, Sensor: %2, LinkType: %3, Arguments: (%4)}")); diff --git a/src/link/linkconfiguration.h b/src/link/linkconfiguration.h index c7a54fd27..34ce4ba4c 100644 --- a/src/link/linkconfiguration.h +++ b/src/link/linkconfiguration.h @@ -319,6 +319,7 @@ class LinkConfiguration : public QObject { }; bool operator==(const LinkConfiguration& first, const LinkConfiguration& second); +bool operator!=(const LinkConfiguration& first, const LinkConfiguration& second); QDebug operator<<(QDebug d, const LinkConfiguration& other); QDataStream& operator<<(QDataStream& out, const LinkConfiguration linkConfiguration); QDataStream& operator>>(QDataStream& in, LinkConfiguration& linkConfiguration); From 1efe3da296d9272944c6fe142782c2866835e4dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Wed, 19 Feb 2020 17:12:46 -0300 Subject: [PATCH 4/7] protocoldetector: Add debug text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- src/sensor/protocoldetector.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sensor/protocoldetector.cpp b/src/sensor/protocoldetector.cpp index 7f0464fd9..2029d7aff 100644 --- a/src/sensor/protocoldetector.cpp +++ b/src/sensor/protocoldetector.cpp @@ -68,6 +68,7 @@ void ProtocolDetector::doScan() // Scan until something is connected while (_active) { auto linksConf = updateLinkConfigurations(_linkConfigs); + qCDebug(PING_PROTOCOL_PROTOCOLDETECTOR) << "Looking for devices in:" << linksConf; for (LinkConfiguration& tryLinkConf : linksConf) { if (!_active) { break; From 9c1bcebbd7245686db8823d6c5ff73d3f20f16ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Wed, 19 Feb 2020 17:13:08 -0300 Subject: [PATCH 5/7] protocoldetector: Remove 9600 baudrate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sensor should deal with automatic baud rate procedure or communicate under 115200 Signed-off-by: Patrick José Pereira --- src/sensor/protocoldetector.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/sensor/protocoldetector.cpp b/src/sensor/protocoldetector.cpp index 2029d7aff..1c10bea64 100644 --- a/src/sensor/protocoldetector.cpp +++ b/src/sensor/protocoldetector.cpp @@ -117,13 +117,9 @@ QVector ProtocolDetector::updateLinkConfigurations(QVector
  • Date: Wed, 19 Feb 2020 17:11:43 -0300 Subject: [PATCH 6/7] devicemanager: Add max number of fails in communication and device serial filter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- src/devicemanager/devicemanager.cpp | 43 +++++++++++++++++++++++++++-- src/devicemanager/devicemanager.h | 2 ++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/devicemanager/devicemanager.cpp b/src/devicemanager/devicemanager.cpp index d5347eed9..d8ab169c8 100644 --- a/src/devicemanager/devicemanager.cpp +++ b/src/devicemanager/devicemanager.cpp @@ -50,6 +50,7 @@ void DeviceManager::append(const LinkConfiguration& linkConf, const QString& dev _sensors[Connected].append(false); _sensors[DetectorName].append(detectorName); _sensors[Name].append(deviceName); + _sensors[UnavailableCounter].append(0); const auto& indexRow = index(line); endInsertRows(); @@ -151,19 +152,57 @@ void DeviceManager::updateAvailableConnections( const QVector& availableLinkConfigurations, const QString& detector) { qCDebug(DEVICEMANAGER) << "Available devices:" << availableLinkConfigurations; - // Make all connections unavailable by default + for (int i {0}; i < _sensors[Available].size(); i++) { const auto linkConf = _sensors[Connection][i].value>(); if (linkConf->isSimulation() || _sensors[DetectorName][i] != detector) { continue; } + + // Make all connections unavailable by default _sensors[Available][i] = false; const auto indexRow = index(i); emit dataChanged(indexRow, indexRow, _roles); } + // Check if the configuration already exists for a sensor + // Serial ports does not support multiple devices connected + // Some sensors, like Ping1D, can fail to answer a ABR procedure for (const auto& link : availableLinkConfigurations) { - append(link, PingHelper::nameFromDeviceType(link.deviceType()), detector); + const bool sameSerialDevice = std::any_of( + _sensors[Connection].cbegin(), _sensors[Connection].cend(), [&link](const QVariant& variantLink) { + const auto sensorLink = variantLink.value>().get(); + qCDebug(DEVICEMANAGER) << "Device" << sensorLink + << "already already provided by a different connection:" << link; + return link.serialPort() == sensorLink->serialPort() && link != *sensorLink; + }); + + if (!sameSerialDevice) { + append(link, PingHelper::nameFromDeviceType(link.deviceType()), detector); + } + } + + // We'll let the link to fail the communication attempt "a max number of fails" before making it unavailable + // This is necessary to avoid any problem related to automatic baud rates problem from the sensor side. + static const int maxNumberOfFails = 3; + for (int i {0}; i < _sensors[Available].size(); i++) { + const auto linkConf = _sensors[Connection][i].value>(); + if (linkConf->isSimulation()) { + continue; + } + + const auto indexRow = index(i); + + // The sensor was detected, we can remove unavailable counter + if (_sensors[Available][i].toBool()) { + _sensors[UnavailableCounter][i] = 0; + emit dataChanged(indexRow, indexRow, _roles); + continue; + } + _sensors[Available][i] = _sensors[UnavailableCounter][i].toInt() < maxNumberOfFails; + _sensors[UnavailableCounter][i] = _sensors[UnavailableCounter][i].toInt() + 1; + + emit dataChanged(indexRow, indexRow, _roles); } } diff --git a/src/devicemanager/devicemanager.h b/src/devicemanager/devicemanager.h index af340fe2b..ad1038bb6 100644 --- a/src/devicemanager/devicemanager.h +++ b/src/devicemanager/devicemanager.h @@ -179,6 +179,7 @@ class DeviceManager : public QAbstractListModel { Connection, Name, DetectorName, + UnavailableCounter, }; QHash _roleNames { {Available, "available"}, @@ -186,6 +187,7 @@ class DeviceManager : public QAbstractListModel { {Connection, "connection"}, {Name, "name"}, {DetectorName, "detectorName"}, + {UnavailableCounter, "unavailableCounter"}, }; QSharedPointer _primarySensor; From 8a2d9e8e7c2371d85b4b03201263517a474256a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Fri, 21 Feb 2020 11:27:25 -0300 Subject: [PATCH 7/7] devicemanager: Use shared pointer over raw pointer. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- src/devicemanager/devicemanager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/devicemanager/devicemanager.cpp b/src/devicemanager/devicemanager.cpp index d8ab169c8..2252f9e76 100644 --- a/src/devicemanager/devicemanager.cpp +++ b/src/devicemanager/devicemanager.cpp @@ -29,8 +29,8 @@ DeviceManager::DeviceManager() void DeviceManager::append(const LinkConfiguration& linkConf, const QString& deviceName, const QString& detectorName) { for (int i {0}; i < _sensors[Connection].size(); i++) { - const auto vectorLinkConf = _sensors[Connection][i].value>().get(); - if (*vectorLinkConf == linkConf) { + const auto vectorLinkConf = _sensors[Connection][i].value>(); + if (!vectorLinkConf.isNull() && *vectorLinkConf == linkConf) { qCDebug(DEVICEMANAGER) << "Connection configuration already exist for:" << _sensors[Name][i] << linkConf << linkConf.argsAsConst(); _sensors[Available][i] = true; @@ -171,8 +171,8 @@ void DeviceManager::updateAvailableConnections( for (const auto& link : availableLinkConfigurations) { const bool sameSerialDevice = std::any_of( _sensors[Connection].cbegin(), _sensors[Connection].cend(), [&link](const QVariant& variantLink) { - const auto sensorLink = variantLink.value>().get(); - qCDebug(DEVICEMANAGER) << "Device" << sensorLink + const auto sensorLink = variantLink.value>(); + qCDebug(DEVICEMANAGER) << "Device" << *sensorLink << "already already provided by a different connection:" << link; return link.serialPort() == sensorLink->serialPort() && link != *sensorLink; });