From 055df99f20ff04fae399af2a66781410ed18b246 Mon Sep 17 00:00:00 2001 From: nreischl <40063770+nreischl@users.noreply.github.com> Date: Thu, 10 Oct 2019 09:02:49 +0200 Subject: [PATCH] Updated osi-visualizer to handle ZMQ Push/Pull configuration in LiME (#34) * Updated README with FMI dependency. * Updated OsiReader and TCPReceiver for ZMQ Push/Pull. * Updated MainWindow to handle different ZMQ communication types. * Improved shutdown and pause handling. --- include/mainwindow.h | 9 +- include/osireader.h | 2 + include/tcpreceiver.h | 3 +- src/mainwindow.cpp | 221 +++++-- src/mainwindow.ui | 1472 +++++++++++++++++++++-------------------- src/osireader.cpp | 12 +- src/tcpreceiver.cpp | 11 +- 7 files changed, 941 insertions(+), 789 deletions(-) diff --git a/include/mainwindow.h b/include/mainwindow.h index c2fe247..3795195 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -155,6 +155,11 @@ class MainWindow : public QMainWindow void ShowFOV(); void ShowFOV2(); + void CBZmqTypeChangeConnect1(const QString&); + void CBZmqTypeChangePlayback1(const QString&); + + void CBZmqTypeChangeConnect2(const QString&); + void CBZmqTypeChangePlayback2(const QString&); private: @@ -230,7 +235,6 @@ class MainWindow : public QMainWindow void EnableShowFOV(const bool enable); void EnableShowFOV2(const bool enable); - // Configurations AppConfig config_; @@ -277,5 +281,8 @@ class MainWindow : public QMainWindow DisplayObjectDialog* displayObjectDlg_; DisplayObjectDialog* displayObjectDlg2_; + + const QString zmqPushPull_{"Push/Pull"}; + const QString zmqPubSub_{"Pub/Sub"}; }; diff --git a/include/osireader.h b/include/osireader.h index c82688d..2bf529c 100644 --- a/include/osireader.h +++ b/include/osireader.h @@ -55,6 +55,7 @@ class OsiReader: public QObject, public IMessageSource const bool& enableSendOut, const std::string& pubPortNum, const bool &enalbeFMU, + int socketType, const std::string &fmuPath = ""); QString SetupConnection(bool enable); @@ -124,6 +125,7 @@ class OsiReader: public QObject, public IMessageSource std::string currentBuffer_; // ZMQ + int socketType_; zmq::context_t zmqContext_; zmq::socket_t zmqPublisher_; diff --git a/include/tcpreceiver.h b/include/tcpreceiver.h index 45eb72b..7f9f7c8 100644 --- a/include/tcpreceiver.h +++ b/include/tcpreceiver.h @@ -21,7 +21,7 @@ class TCPReceiver : public QObject, public IMessageSource public: - TCPReceiver(); + TCPReceiver(int type); signals: void Connected(DataType dataType); @@ -43,6 +43,7 @@ class TCPReceiver : public QObject, public IMessageSource bool isRunning_; bool isThreadTerminated_; + int socketType_; std::string currentPort_; std::string currentEndpoint_; zmq::context_t context_; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 06b5201..98f821a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -25,6 +25,27 @@ #include #include +#define CONNECT_OSIREADER(number) \ + connect(this, &MainWindow::StartPlaybackRequested##number, reader##number##_, &OsiReader::StartReadFile, Qt::QueuedConnection); \ + connect(reader##number##_, &OsiReader::Connected, this, &MainWindow::Connected##number); \ + connect(reader##number##_, &OsiReader::Disconnected, this, &MainWindow::Disconnected##number); \ + connect(reader##number##_, &OsiReader::Connected, glWidget##number##_, &GLWidget::Connected, Qt::DirectConnection); \ + connect(reader##number##_, &OsiReader::Disconnected, glWidget##number##_, &GLWidget::Disconnected, Qt::DirectConnection); \ + connect(reader##number##_, &OsiReader::UpdateSliderRange, this, &MainWindow::UpdateSliderRange##number); \ + connect(reader##number##_, &OsiReader::UpdateSliderValue, this, &MainWindow::UpdateSliderValue##number); \ + connect(reader##number##_, &OsiReader::MessageSDSendout, osiparser##number##_, &OsiParser::ParseReceivedSDMessage, Qt::QueuedConnection); \ + connect(reader##number##_, &OsiReader::MessageSVSendout, osiparser##number##_, &OsiParser::ParseReceivedSVMessage, Qt::QueuedConnection);\ + connect(ui_->hSlider_##number, &QSlider::valueChanged, reader##number##_, &OsiReader::SliderValueChanged); + +#define CONNECT_TCP_RECEIVER(number) \ + connect(this, &MainWindow::ConnectRequested##number, tcpReceiver##number##_, &TCPReceiver::ConnectRequested, Qt::QueuedConnection); \ + connect(tcpReceiver##number##_, &TCPReceiver::Connected, this, &MainWindow::Connected##number); \ + connect(tcpReceiver##number##_, &TCPReceiver::Disconnected, this, &MainWindow::Disconnected##number); \ + connect(tcpReceiver##number##_, &TCPReceiver::Connected, glWidget##number##_, &GLWidget::Connected, Qt::DirectConnection); \ + connect(tcpReceiver##number##_, &TCPReceiver::Disconnected, glWidget##number##_, &GLWidget::Disconnected, Qt::DirectConnection); \ + connect(tcpReceiver##number##_, &TCPReceiver::UpdateSliderTime, this, &MainWindow::UpdateSliderTime##number); \ + connect(tcpReceiver##number##_, &TCPReceiver::MessageSDReceived, osiparser##number##_, &OsiParser::ParseReceivedSDMessage, Qt::QueuedConnection); \ + connect(tcpReceiver##number##_, &TCPReceiver::MessageSVReceived, osiparser##number##_, &OsiParser::ParseReceivedSVMessage, Qt::QueuedConnection); MainWindow::MainWindow(QWidget *parent) @@ -47,15 +68,15 @@ MainWindow::MainWindow(QWidget *parent) , ui_(new Ui::MainWindow) , glWidget_(nullptr) - , tcpReceiver_(new TCPReceiver()) + , tcpReceiver_(nullptr) , fmuReceiver_(new FMUReceiver()) - , reader_(new OsiReader(&config_.ch1DeltaDelay_, config_.ch1EnableSendOut_, config_.ch1SendOutPortNum_.toStdString(), config_.ch1FMUTxCheck_, config_.ch1LoadFMUTx_.toStdString())) + , reader_(nullptr) , osiparser_(new OsiParser(config_)) , glWidget2_(nullptr) - , tcpReceiver2_(new TCPReceiver()) + , tcpReceiver2_(nullptr) , fmuReceiver2_(new FMUReceiver()) - , reader2_(new OsiReader(&config_.ch2DeltaDelay_, config_.ch2EnableSendOut_, config_.ch2SendOutPortNum_.toStdString(), config_.ch2FMUTxCheck_, config_.ch2LoadFMUTx_.toStdString())) + , reader2_(nullptr) , osiparser2_(new OsiParser(config_)) , colorWidgets_() @@ -126,6 +147,22 @@ MainWindow::LocalUpdate() MainWindow::~MainWindow() { + if (isConnected2_) + { + tcpReceiver2_->DisconnectRequested(); + } + if (isConnected_) + { + tcpReceiver_->DisconnectRequested(); + } + if (isPlayed_) + { + reader_->StopReadFile(); + } + if (isPlayed2_) + { + reader2_->StopReadFile(); + } // Call all deletes in reversed order! delete glWidget_; delete glWidget2_; @@ -464,6 +501,8 @@ MainWindow::PlayPauseButtonClicked() LocalPlayPause2(); UpdateCombineChannelMenu(); + ui_->zmq_type_connect_1->setEnabled(false); + ui_->zmq_type_playback_1->setEnabled(false); } void @@ -499,9 +538,9 @@ MainWindow::LocalPlayPause() Stop(); Play(); - ui_->hSlider->blockSignals(true); - ui_->hSlider->setValue(0); - ui_->hSlider->blockSignals(false); + ui_->hSlider_->blockSignals(true); + ui_->hSlider_->setValue(0); + ui_->hSlider_->blockSignals(false); } else { @@ -521,6 +560,8 @@ MainWindow::PlayPauseButtonClicked2() LocalPlayPause(); UpdateCombineChannelMenu(); + ui_->zmq_type_connect_2->setEnabled(false); + ui_->zmq_type_playback_2->setEnabled(false); } void @@ -745,24 +786,7 @@ MainWindow::ConnectSignalsToSlots() connect(ui_->playPauseButton, &QToolButton::clicked, this, &MainWindow::PlayPauseButtonClicked); connect(ui_->playPauseButton_2, &QToolButton::clicked, this, &MainWindow::PlayPauseButtonClicked2); - // signals and slots related to connection status - // If not queued, this signal will block the GUI. Same applies for Connect/Disconnect in TCPReceiver. - connect(this, &MainWindow::ConnectRequested, tcpReceiver_, &TCPReceiver::ConnectRequested, Qt::QueuedConnection); - connect(tcpReceiver_, &TCPReceiver::Connected, this, &MainWindow::Connected); - connect(tcpReceiver_, &TCPReceiver::Disconnected, this, &MainWindow::Disconnected); - connect(tcpReceiver_, &TCPReceiver::Connected, glWidget_, &GLWidget::Connected, Qt::DirectConnection); - connect(tcpReceiver_, &TCPReceiver::Disconnected, glWidget_, &GLWidget::Disconnected, Qt::DirectConnection); - - connect(tcpReceiver_, &TCPReceiver::UpdateSliderTime, this, &MainWindow::UpdateSliderTime); - - connect(this, &MainWindow::ConnectRequested2, tcpReceiver2_, &TCPReceiver::ConnectRequested, Qt::QueuedConnection); - connect(tcpReceiver2_, &TCPReceiver::Connected, this, &MainWindow::Connected2); - connect(tcpReceiver2_, &TCPReceiver::Disconnected, this, &MainWindow::Disconnected2); - connect(tcpReceiver2_, &TCPReceiver::Connected, glWidget2_, &GLWidget::Connected, Qt::DirectConnection); - connect(tcpReceiver2_, &TCPReceiver::Disconnected, glWidget2_, &GLWidget::Disconnected, Qt::DirectConnection); - - connect(tcpReceiver2_, &TCPReceiver::UpdateSliderTime, this, &MainWindow::UpdateSliderTime2); - + // Signals and slots related to connection status of FMU connect(this, &MainWindow::FMUConnectRequested, fmuReceiver_, &FMUReceiver::ConnectRequested, Qt::QueuedConnection); connect(fmuReceiver_, &FMUReceiver::Connected, this, &MainWindow::Connected); connect(fmuReceiver_, &FMUReceiver::Disconnected, this, &MainWindow::Disconnected); @@ -776,43 +800,13 @@ MainWindow::ConnectSignalsToSlots() connect(fmuReceiver2_, &FMUReceiver::Disconnected, this, &MainWindow::Disconnected2); connect(fmuReceiver2_, &FMUReceiver::Connected, glWidget2_, &GLWidget::Connected, Qt::DirectConnection); connect(fmuReceiver2_, &FMUReceiver::Disconnected, glWidget2_, &GLWidget::Disconnected, Qt::DirectConnection); - connect(fmuReceiver2_, &FMUReceiver::UpdateSliderTime, this, &MainWindow::UpdateSliderTime2); - connect(this, &MainWindow::StartPlaybackRequested, reader_, &OsiReader::StartReadFile, Qt::QueuedConnection); - connect(reader_, &OsiReader::Connected, this, &MainWindow::Connected); - connect(reader_, &OsiReader::Disconnected, this, &MainWindow::Disconnected); - connect(reader_, &OsiReader::Connected, glWidget_, &GLWidget::Connected, Qt::DirectConnection); - connect(reader_, &OsiReader::Disconnected, glWidget_, &GLWidget::Disconnected, Qt::DirectConnection); - - connect(reader_, &OsiReader::UpdateSliderRange, this, &MainWindow::UpdateSliderRange); - connect(reader_, &OsiReader::UpdateSliderValue, this, &MainWindow::UpdateSliderValue); - - connect(this, &MainWindow::StartPlaybackRequested2, reader2_, &OsiReader::StartReadFile, Qt::QueuedConnection); - connect(reader2_, &OsiReader::Connected, this, &MainWindow::Connected2); - connect(reader2_, &OsiReader::Disconnected, this, &MainWindow::Disconnected2); - connect(reader2_, &OsiReader::Connected, glWidget2_, &GLWidget::Connected, Qt::DirectConnection); - connect(reader2_, &OsiReader::Disconnected, glWidget2_, &GLWidget::Disconnected, Qt::DirectConnection); - - connect(reader2_, &OsiReader::UpdateSliderRange, this, &MainWindow::UpdateSliderRange2); - connect(reader2_, &OsiReader::UpdateSliderValue, this, &MainWindow::UpdateSliderValue2); - - //Main loop: receive(read) -> parse -> update objects - connect(tcpReceiver_, &TCPReceiver::MessageSDReceived, osiparser_, &OsiParser::ParseReceivedSDMessage, Qt::QueuedConnection); - connect(tcpReceiver_, &TCPReceiver::MessageSVReceived, osiparser_, &OsiParser::ParseReceivedSVMessage, Qt::QueuedConnection); - connect(tcpReceiver2_, &TCPReceiver::MessageSDReceived, osiparser2_, &OsiParser::ParseReceivedSDMessage, Qt::QueuedConnection); - connect(tcpReceiver2_, &TCPReceiver::MessageSVReceived, osiparser2_, &OsiParser::ParseReceivedSVMessage, Qt::QueuedConnection); - connect(fmuReceiver_, &FMUReceiver::MessageSDReceived, osiparser_, &OsiParser::ParseReceivedSDMessage, Qt::QueuedConnection); connect(fmuReceiver_, &FMUReceiver::MessageSVReceived, osiparser_, &OsiParser::ParseReceivedSVMessage, Qt::QueuedConnection); connect(fmuReceiver2_, &FMUReceiver::MessageSDReceived, osiparser2_, &OsiParser::ParseReceivedSDMessage, Qt::QueuedConnection); connect(fmuReceiver2_, &FMUReceiver::MessageSVReceived, osiparser2_, &OsiParser::ParseReceivedSVMessage, Qt::QueuedConnection); - connect(reader_, &OsiReader::MessageSDSendout, osiparser_, &OsiParser::ParseReceivedSDMessage, Qt::QueuedConnection); - connect(reader_, &OsiReader::MessageSVSendout, osiparser_, &OsiParser::ParseReceivedSVMessage, Qt::QueuedConnection); - connect(reader2_, &OsiReader::MessageSDSendout, osiparser2_, &OsiParser::ParseReceivedSDMessage, Qt::QueuedConnection); - connect(reader2_, &OsiReader::MessageSVSendout, osiparser2_, &OsiParser::ParseReceivedSVMessage, Qt::QueuedConnection); - connect(osiparser_, &OsiParser::MessageParsed, glWidget_, &GLWidget::MessageParsed, Qt::QueuedConnection); connect(osiparser2_, &OsiParser::MessageParsed, glWidget2_, &GLWidget::MessageParsed, Qt::QueuedConnection); @@ -837,10 +831,6 @@ MainWindow::ConnectSignalsToSlots() connect(ui_->objectTree_2, &QTreeWidget::itemChanged, glWidget2_, &GLWidget::TreeItemChanged); connect(ui_->objectTree_2, &QTreeWidget::itemClicked, this, &MainWindow::ConnectDisplayObjectInformation2); - // slider - connect(ui_->hSlider, &QSlider::valueChanged, reader_, &OsiReader::SliderValueChanged); - connect(ui_->hSlider_2, &QSlider::valueChanged, reader2_, &OsiReader::SliderValueChanged); - //Tracking connect(glWidget_, &GLWidget::SetTrackingEnabled, this, &MainWindow::SetTrackingEnabled); connect(ui_->startStopTrackingButton, &QPushButton::clicked, glWidget_, &GLWidget::StartTracking); @@ -882,6 +872,97 @@ MainWindow::ConnectSignalsToSlots() connect(ui_->dataType_2, static_cast(&QComboBox::currentIndexChanged), this, &MainWindow::CBDataTypeCon2); connect(ui_->playbackDataType_2, static_cast(&QComboBox::currentIndexChanged), this, &MainWindow::CBDataTypePlay2); + // ZMQ communication type (push/pull or pub/sub) connection + connect(ui_->zmq_type_connect_1, static_cast(&QComboBox::currentIndexChanged), this, &MainWindow::CBZmqTypeChangeConnect1); + connect(ui_->zmq_type_playback_1, static_cast(&QComboBox::currentIndexChanged), this, &MainWindow::CBZmqTypeChangePlayback1); + + connect(ui_->zmq_type_connect_2, static_cast(&QComboBox::currentIndexChanged), this, &MainWindow::CBZmqTypeChangeConnect2); + connect(ui_->zmq_type_playback_2, static_cast(&QComboBox::currentIndexChanged), this, &MainWindow::CBZmqTypeChangePlayback2); +} + +void +MainWindow::CBZmqTypeChangeConnect1(const QString& type) +{ + if (tcpReceiver_ != nullptr) + { + delete tcpReceiver_; + } + + if (type == "Push/Pull") + { + tcpReceiver_ = new TCPReceiver{ZMQ_PULL}; + } + else if (type == "Pub/Sub") + { + tcpReceiver_ = new TCPReceiver{ZMQ_SUB}; + } + + CONNECT_TCP_RECEIVER(); + UpdateGLWidgetMessageSource(); +} + +void +MainWindow::CBZmqTypeChangePlayback1(const QString& type) +{ + if (reader_ != nullptr) + { + delete reader_; + reader_ = nullptr; + } + + if (type == "Push/Pull") + { + reader_ = new OsiReader(&config_.ch1DeltaDelay_, config_.ch1EnableSendOut_, config_.ch1SendOutPortNum_.toStdString(), config_.ch1FMUTxCheck_, ZMQ_PUSH, config_.ch1LoadFMUTx_.toStdString()); + } + else if (type == "Pub/Sub") + { + reader_ = new OsiReader(&config_.ch1DeltaDelay_, config_.ch1EnableSendOut_, config_.ch1SendOutPortNum_.toStdString(), config_.ch1FMUTxCheck_, ZMQ_PUB, config_.ch1LoadFMUTx_.toStdString()); + } + + CONNECT_OSIREADER(); + UpdateGLWidgetMessageSource(); +} + +void +MainWindow::CBZmqTypeChangeConnect2(const QString& type) +{ + if (tcpReceiver2_ != nullptr) + { + delete tcpReceiver2_; + } + + if (type == "Push/Pull") + { + tcpReceiver2_ = new TCPReceiver{ZMQ_PULL}; + } + else if (type == "Pub/Sub") + { + tcpReceiver2_ = new TCPReceiver{ZMQ_SUB}; + } + + CONNECT_TCP_RECEIVER(2); + UpdateGLWidgetMessageSource2(); +} + +void +MainWindow::CBZmqTypeChangePlayback2(const QString& type) +{ + if (reader2_ != nullptr) + { + delete reader2_; + reader2_ = nullptr; + } + if (type == "Push/Pull") + { + reader2_ = new OsiReader(&config_.ch2DeltaDelay_, config_.ch2EnableSendOut_, config_.ch2SendOutPortNum_.toStdString(), config_.ch2FMUTxCheck_, ZMQ_PUSH, config_.ch2LoadFMUTx_.toStdString()); + } + else if (type == "Pub/Sub") + { + reader2_ = new OsiReader(&config_.ch2DeltaDelay_, config_.ch2EnableSendOut_, config_.ch2SendOutPortNum_.toStdString(), config_.ch2FMUTxCheck_, ZMQ_PUB, config_.ch2LoadFMUTx_.toStdString()); + } + + CONNECT_OSIREADER(2); + UpdateGLWidgetMessageSource2(); } void @@ -1013,7 +1094,7 @@ MainWindow::EnablePlaybackGroup2(bool enable) void MainWindow::EnableSlider(bool enable) { - ui_->hSlider->setEnabled(enable); + ui_->hSlider_->setEnabled(enable); } void @@ -1435,6 +1516,18 @@ MainWindow::InitComboBoxes() ui_->playbackDataType->addItem("SensorData"); ui_->playbackDataType_2->addItem("SensorView"); ui_->playbackDataType_2->addItem("SensorData"); + + ui_->zmq_type_connect_1->addItem(zmqPushPull_); + ui_->zmq_type_connect_1->addItem("Pub/Sub"); + + ui_->zmq_type_playback_1->addItem(zmqPushPull_); + ui_->zmq_type_playback_1->addItem("Pub/Sub"); + + ui_->zmq_type_connect_2->addItem(zmqPushPull_); + ui_->zmq_type_connect_2->addItem("Pub/Sub"); + + ui_->zmq_type_playback_2->addItem(zmqPushPull_); + ui_->zmq_type_playback_2->addItem("Pub/Sub"); } void @@ -2026,7 +2119,7 @@ MainWindow::GetStringFromMilliSecond(int milliSec) void MainWindow::UpdateSliderRange(int sliderRange) { - ui_->hSlider->setRange(0, sliderRange); + ui_->hSlider_->setRange(0, sliderRange); ui_->hSliderTimeRange->setText(GetStringFromMilliSecond(sliderRange)); } @@ -2040,9 +2133,9 @@ MainWindow::UpdateSliderRange2(int sliderRange) void MainWindow::UpdateSliderValue(int sliderValue) { - ui_->hSlider->blockSignals(true); - ui_->hSlider->setValue(sliderValue); - ui_->hSlider->blockSignals(false); + ui_->hSlider_->blockSignals(true); + ui_->hSlider_->setValue(sliderValue); + ui_->hSlider_->blockSignals(false); UpdateSliderTime(sliderValue); } diff --git a/src/mainwindow.ui b/src/mainwindow.ui index a65d6cf..a67e906 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -209,7 +209,7 @@ - + 0 @@ -300,10 +300,10 @@ 0 0 244 - 599 + 661 - + 2 @@ -322,27 +322,44 @@ 4 + + + + + 0 + 0 + + + + Playback + + + false + + + - - - - - - - - - - - 25 - 25 - - - - ... - - - - + + + + + Port: + + + + + + + IP: + + + + + + + FMU: + + @@ -369,21 +386,40 @@ - - - - Data: + + + + Qt::Horizontal - - - - - - IP: + + + 40 + 20 + - + + + + + + + + + + 25 + 25 + + + + ... + + + + + + @@ -405,6 +441,20 @@ + + + + Data: + + + + + + + + + + @@ -424,20 +474,6 @@ - - - - Port: - - - - - - - FMU: - - - @@ -451,88 +487,86 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - + + - - + + - + ZMQ: - - - - - 0 - 0 - - - - Playback - - - false - - - - - - - Show Field of View - - - - - + + 0 - - - - - - - - - - 25 - 25 - - - - ... - - - - + + + + AP + + + + + - + + + + + + deg + + + + + + + + + + MinR + + + + + + + m + + + + + + + deg + + + + + + + AN + + + + + - + - Data: + MaxR - + Qt::Horizontal @@ -544,33 +578,142 @@ - - - - - 0 - 0 - + + + + m + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Show Field of View + + + + + + + 30 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false - 25 - 25 + 160 + 0 + + Qt::LeftToRight + - Load: + Save OSI Message + + + true + + + false - - + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + 0 + + + - FMU: + Send - + + + + + + + + + + 25 + 25 + + + + ... + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + 0 @@ -612,14 +755,110 @@ - - + + + + + 0 + 0 + + + + + 25 + 25 + + - Send + Load: - + + + + + 0 + 0 + + + + Delay: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + FMU: + + + + + + + Data: + + + + + + + + + + + + + + + + to Port: + + + + + + + + 60 + 16777215 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + @@ -655,74 +894,7 @@ - - - - - - to Port: - - - - - - - - 60 - 16777215 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - 0 - 0 - - - - Delay: - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - + @@ -732,127 +904,20 @@ - - - - - - - 0 - 0 - - - - Connection - - - false - - - - - - - 0 - - - - - AP - - - - - - - - - - - - deg - - - - - - - - - - MinR - - - - - - - m - - - - - - - deg - - - - - - - AN - - - - - + - - - MaxR - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - + - m + ZMQ: - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - + + Qt::Vertical @@ -864,8 +929,24 @@ - - + + + + + 0 + 0 + + + + Connection + + + false + + + + + Qt::Vertical @@ -877,67 +958,6 @@ - - - - 30 - - - 0 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - false - - - - 160 - 0 - - - - Qt::LeftToRight - - - Save OSI Message - - - true - - - false - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - @@ -1203,7 +1223,7 @@ 0 0 244 - 619 + 681 @@ -1241,254 +1261,60 @@ - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - 0 - + + - - - - - - Send - - - - - - - 0 - - - - - - 50 - 0 - - - - - 80 - 16777215 - - - - 0 - - - - - - - ms - - - - - - - - - - - to Port: - - - - - - - - 60 - 16777215 - - - - - - - - Qt::Horizontal - - - - 20 - 20 - - - - - - - - + - + 0 0 - 25 + 80 25 - - Load: - - - - - - - - - - - - - 25 - 25 - - - - ... - - - - - - - - - Qt::Horizontal - - + - 40 - 20 + 16777215 + 16777215 - - - - - - FMU: - - - - - - Delay: + - - - - 0 - - - - - - 50 - 25 - - - - - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - - 25 - 25 - - - - - 25 - 25 - - - - ... - - - - - - - + + - Data: + FMU: - - - - Qt::Horizontal - - + + + - 40 - 20 + 80 + 25 - - - - - - - - - + + + 16777215 + 16777215 + - - - - - - - - - + @@ -1510,14 +1336,14 @@ - - + + - FMU: + Data: - + @@ -1537,66 +1363,121 @@ - + + + + Qt::Horizontal + + + + 40 + 20 + + + + + IP: - - - - - 0 - 0 - - - - - 80 - 25 - - - - - 16777215 - 16777215 - - + + - - - - - 80 - 25 - + + + + Qt::Horizontal - + - 16777215 - 16777215 + 40 + 20 + + + + - + Port: + + + - + - Data: + ZMQ: - - + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + 0 + + + + + deg + + + + + + + + + + MaxR + + + + + + + + + + + + + + + + deg + + + + + Qt::Horizontal @@ -1608,15 +1489,43 @@ - - + + - Port: + m + + + + + + + m + + + + + + + AP + + + + + + + AN + + + + + + + MinR - + Qt::Horizontal @@ -1628,16 +1537,25 @@ - - - - - - - - + + + + + 0 + 0 + + + + Playback + + + false + + + + 30 @@ -1696,45 +1614,108 @@ - + + + Show Field of View + + + + + 0 - - + + - deg + FMU: - - - - - + + - MaxR + Data: - - - - - - - + - - + + + + + 0 + 0 + + + + + 25 + 25 + + - deg + Load: - - + + + + + + + + + + 25 + 25 + + + + ... + + + + + + + + + 0 + + + + + + 50 + 0 + + + + + 80 + 16777215 + + + + 0 + + + + + + + ms + + + + + + + Qt::Horizontal @@ -1746,80 +1727,139 @@ - - - - m + + + + Qt::Horizontal - + + + 40 + 20 + + + - - + + + + + + to Port: + + + + + + + + 60 + 16777215 + + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + - m + - - + + - AP + Send - + - AN + Delay: - - + + + + 0 + + + + + + 50 + 25 + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + 25 + 25 + + + + + 25 + 25 + + + + ... + + + + + + + + + + - MinR + - - - - Qt::Horizontal - - - - 40 - 20 - + + + + + + + ZMQ: - + - - - - - 0 - 0 - - - - Playback - - - false - - - - - - - Show Field of View - - - - + Qt::Vertical @@ -2060,7 +2100,7 @@ saveOSIMessage_2 startStopTrackingButton startStopTrackingButton_2 - hSlider + hSlider_ objectTree objectTree_2 hSlider_2 diff --git a/src/osireader.cpp b/src/osireader.cpp index b04984a..39a88cd 100644 --- a/src/osireader.cpp +++ b/src/osireader.cpp @@ -60,6 +60,7 @@ OsiReader::OsiReader(int* deltaDelay, const bool& enableSendOut, const std::string& pubPortNum, const bool& enalbeFMU, + int socketType, const std::string& fmuPath) : IMessageSource() , isRunning_(false) @@ -79,8 +80,9 @@ OsiReader::OsiReader(int* deltaDelay, , enableSendOut_(enableSendOut) , pubPortNumber_(pubPortNum) + , socketType_(socketType) , zmqContext_(1) - , zmqPublisher_(zmqContext_, ZMQ_PUB) + , zmqPublisher_(zmqContext_, socketType) , enableFMU_(enalbeFMU) , fmu_(nullptr) @@ -574,7 +576,11 @@ OsiReader::SetupConnection(bool enable) { if(zmqPublisher_.connected()) { - errMsg = FreeZMQConnection(); + isPaused_ = true; + if (isReadTerminated_) + { + errMsg = FreeZMQConnection(); + } } } @@ -587,7 +593,7 @@ OsiReader::SetZMQConnection() QString errMsg; if(!zmqPublisher_.connected()) { - zmqPublisher_ = zmq::socket_t(zmqContext_, ZMQ_PUB); + zmqPublisher_ = zmq::socket_t(zmqContext_, socketType_); zmqPublisher_.setsockopt(ZMQ_LINGER, 100); try { diff --git a/src/tcpreceiver.cpp b/src/tcpreceiver.cpp index b2f3b5c..4b02e60 100644 --- a/src/tcpreceiver.cpp +++ b/src/tcpreceiver.cpp @@ -9,16 +9,16 @@ * */ -TCPReceiver::TCPReceiver() +TCPReceiver::TCPReceiver(int type) : IMessageSource() , isRunning_(false) , isThreadTerminated_(false) - + , socketType_(type) , currentPort_("") , currentEndpoint_("") , context_(1) - , socket_(context_, ZMQ_SUB) + , socket_(context_, type) , currentDataType_(DataType::SensorView) { // Disable buffering @@ -52,7 +52,10 @@ TCPReceiver::ConnectRequested(const QString &ipAddress, return; } - socket_.setsockopt(ZMQ_SUBSCRIBE, 0, 0); + if (socketType_ == ZMQ_SUB) + { + socket_.setsockopt(ZMQ_SUBSCRIBE, 0, 0); + } isPaused_ = false; isRunning_ = true;