From 8f0b5b4fef246e17f7da3448f10151eabe36a361 Mon Sep 17 00:00:00 2001 From: Hoop77 <p.badenhoop@gmx.de> Date: Thu, 17 May 2018 09:46:11 +0200 Subject: [PATCH] MessageGui finally working --- .../include/NetworkingLib/DatagramReceiver.h | 3 +++ .../catkin_ws/src/PCGui/PCGui/CMakeLists.txt | 2 +- .../MostRecentMessageFiltertProxyModel.h | 11 +++++----- .../PCGui/include/{MessageGui => }/Utils.h | 0 .../MostRecentMessageFilterProxyModel.cpp | 21 ++++++++----------- .../catkin_ws/src/car/src/logging/Logging.cpp | 2 +- .../src/car/src/ultrasonic/Ultrasonic.cpp | 6 ++++-- scripts/AdHoc_Wifi/root@10.5.37.177 | 14 +++++++++++++ 8 files changed, 38 insertions(+), 21 deletions(-) rename modules/catkin_ws/src/PCGui/PCGui/include/{MessageGui => }/Utils.h (100%) create mode 100644 scripts/AdHoc_Wifi/root@10.5.37.177 diff --git a/modules/catkin_ws/src/NetworkingLib/include/NetworkingLib/DatagramReceiver.h b/modules/catkin_ws/src/NetworkingLib/include/NetworkingLib/DatagramReceiver.h index dc16c5d8..4751dfe7 100644 --- a/modules/catkin_ws/src/NetworkingLib/include/NetworkingLib/DatagramReceiver.h +++ b/modules/catkin_ws/src/NetworkingLib/include/NetworkingLib/DatagramReceiver.h @@ -95,6 +95,9 @@ private: void newSocket() { + if (!socket.is_open()) + return; + socket = Socket(net.getIoService(), Udp::v4()); socket.set_option(boost::asio::socket_base::reuse_address{true}); socket.set_option(boost::asio::socket_base::broadcast{true}); diff --git a/modules/catkin_ws/src/PCGui/PCGui/CMakeLists.txt b/modules/catkin_ws/src/PCGui/PCGui/CMakeLists.txt index abe911b5..8ee382bb 100644 --- a/modules/catkin_ws/src/PCGui/PCGui/CMakeLists.txt +++ b/modules/catkin_ws/src/PCGui/PCGui/CMakeLists.txt @@ -46,7 +46,7 @@ add_executable(MessageGui ${SOURCE_FILES} include/MessageGui/MessageList.h include/MessageGui/SignalProducer.h include/MessageGui/SignalConsumer.h - include/MessageGui/Utils.h + include/Utils.h include/MessageGui/MostRecentMessageFiltertProxyModel.h include/MessageGui/MessageRole.h include/MessageGui/Message.h diff --git a/modules/catkin_ws/src/PCGui/PCGui/include/MessageGui/MostRecentMessageFiltertProxyModel.h b/modules/catkin_ws/src/PCGui/PCGui/include/MessageGui/MostRecentMessageFiltertProxyModel.h index 58c137a3..d719b216 100644 --- a/modules/catkin_ws/src/PCGui/PCGui/include/MessageGui/MostRecentMessageFiltertProxyModel.h +++ b/modules/catkin_ws/src/PCGui/PCGui/include/MessageGui/MostRecentMessageFiltertProxyModel.h @@ -46,9 +46,9 @@ class MostRecentMessageFilterProxyModel : public QSortFilterProxyModel { Q_OBJECT - Q_PROPERTY(int count READ count NOTIFY countChanged) - Q_PROPERTY(QObject * source READ source WRITE setSource) - Q_PROPERTY(bool enabled READ enabled WRITE enable ) +Q_PROPERTY(int count READ count NOTIFY countChanged) +Q_PROPERTY(QObject * source READ source WRITE setSource) +Q_PROPERTY(bool enabled READ enabled WRITE enable ) public: explicit MostRecentMessageFilterProxyModel(QObject * parent = nullptr); @@ -74,9 +74,10 @@ protected slots: void onRowsRemoved(const QModelIndex & parent, int first, int last); protected: - QHash<int, QByteArray> roleNames() const; - bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const override; + bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; + + QHash<int, QByteArray> roleNames() const; private: diff --git a/modules/catkin_ws/src/PCGui/PCGui/include/MessageGui/Utils.h b/modules/catkin_ws/src/PCGui/PCGui/include/Utils.h similarity index 100% rename from modules/catkin_ws/src/PCGui/PCGui/include/MessageGui/Utils.h rename to modules/catkin_ws/src/PCGui/PCGui/include/Utils.h diff --git a/modules/catkin_ws/src/PCGui/PCGui/src/MessageGui/MostRecentMessageFilterProxyModel.cpp b/modules/catkin_ws/src/PCGui/PCGui/src/MessageGui/MostRecentMessageFilterProxyModel.cpp index e135b950..f286d46c 100644 --- a/modules/catkin_ws/src/PCGui/PCGui/src/MessageGui/MostRecentMessageFilterProxyModel.cpp +++ b/modules/catkin_ws/src/PCGui/PCGui/src/MessageGui/MostRecentMessageFilterProxyModel.cpp @@ -26,9 +26,9 @@ void MostRecentMessageFilterProxyModel::setSource(QObject * source) setSourceModel(qobject_cast<QAbstractItemModel *>(source)); - connect(this, SIGNAL(rowsInserted(QModelIndex, int, int)), + connect(sourceModel(), SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(onRowsInserted(const QModelIndex &, int, int))); - connect(this, SIGNAL(rowsRemoved(QModelIndex, int, int)), + connect(sourceModel(), SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(onRowsRemoved(const QModelIndex &, int, int))); endResetModel(); @@ -39,6 +39,9 @@ int MostRecentMessageFilterProxyModel::count() const return rowCount(); } +#include <QDebug> +#include <include/Utils.h> + void MostRecentMessageFilterProxyModel::enable(bool flag) { enabledFlag = flag; @@ -65,12 +68,8 @@ void MostRecentMessageFilterProxyModel::onRowsInserted(const QModelIndex & paren invalidateFilter(); } -#include <QDebug> - void MostRecentMessageFilterProxyModel::onRowsRemoved(const QModelIndex & parent, int first, int last) { - for (int i = first; i <= last; i++) - qDebug() << "ID to remove: " << idFromRow(i, parent); } MessageKey MostRecentMessageFilterProxyModel::messageKeyFromRow(int row, const QModelIndex & parent) const @@ -89,15 +88,13 @@ int MostRecentMessageFilterProxyModel::idFromRow(int row, const QModelIndex & pa bool MostRecentMessageFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const { - if (!enabled() || !sourceModel()->index(sourceRow, 0, sourceParent).isValid() || - sourceRow < 0 || sourceRow >= rowCount()) + if (!enabled()) return true; auto key = messageKeyFromRow(sourceRow, sourceParent); - auto id = idFromRow(sourceRow, sourceParent); - - if (id != mostRecent.at(key)) - qDebug() << "ID not accepted: " << id; + if (!utils::contains(mostRecent, key)) + return true; + auto id = idFromRow(sourceRow, sourceParent); return id == mostRecent.at(key); } diff --git a/modules/catkin_ws/src/car/src/logging/Logging.cpp b/modules/catkin_ws/src/car/src/logging/Logging.cpp index eee4cc0a..47834f74 100644 --- a/modules/catkin_ws/src/car/src/logging/Logging.cpp +++ b/modules/catkin_ws/src/car/src/logging/Logging.cpp @@ -46,7 +46,7 @@ void Logging::camDataCallback(const camDataMsg::ConstPtr & inMsg) void Logging::environmentDataCallback(const environmentDataMsg::ConstPtr & inMsg) { - *messageServer << message::Message{"environment", "distance", std::to_string(inMsg->distance)}; + *messageServer << message::Message{"environmentData", "distance", std::to_string(inMsg->distance)}; } void Logging::laneDataCallback(const laneDataMsg::ConstPtr & inMsg) diff --git a/modules/catkin_ws/src/car/src/ultrasonic/Ultrasonic.cpp b/modules/catkin_ws/src/car/src/ultrasonic/Ultrasonic.cpp index 847e7b17..4137e638 100644 --- a/modules/catkin_ws/src/car/src/ultrasonic/Ultrasonic.cpp +++ b/modules/catkin_ws/src/car/src/ultrasonic/Ultrasonic.cpp @@ -22,14 +22,16 @@ void Ultrasonic::onInit() messageOStream.write("onInit", "START"); ussData = nh.advertise<ussDataMsg>("ussData", 1); - sensor.init(); + //sensor.init(); timer = networking::time::Timer::create(net); timer->startPeriodicTimeout( std::chrono::milliseconds(UltrasonicSensor::DELAY), [&] { ussDataMsg msg; - auto distance = streamMedianFilter.moveWindow(sensor.getDistance()); + //auto distance = streamMedianFilter.moveWindow(sensor.getDistance()); + static int distance = 0; + distance++; msg.distance = distance; msg.timestamp = ros::Time::now(); ussData.publish(msg); diff --git a/scripts/AdHoc_Wifi/root@10.5.37.177 b/scripts/AdHoc_Wifi/root@10.5.37.177 new file mode 100644 index 00000000..86051ddf --- /dev/null +++ b/scripts/AdHoc_Wifi/root@10.5.37.177 @@ -0,0 +1,14 @@ +# Switch from AdHoc Network to eduroam + +IFACE="wlan0" + +# Reset wifi card +sudo ifconfig IFACE down +sudo iw IFACE set type managed +sudo ifconfig IFACE up +sleep 0.5 + +# Connect to wifi and obtain IP address +sudo wpa_cli +sudo dhclient -r +sudo dhclient -- GitLab