Skip to content
This repository was archived by the owner on Jan 21, 2022. It is now read-only.

Commit f07cdaf

Browse files
authored
Merge pull request #11 from Yang-Wu-Altran/master
Add new functionality: send out osi::sensordata to network while playing playback files
2 parents df7c523 + 19bdc4c commit f07cdaf

File tree

8 files changed

+361
-64
lines changed

8 files changed

+361
-64
lines changed

include/appconfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ class AppConfig
2424
QString ch1LoadFile_;
2525
DataType ch1PlaybackDataType_;
2626
int ch1DeltaDelay_;
27+
bool ch1EnableSendOut_;
28+
QString ch1SendOutPortNum_;
2729

2830
QString ch2IPAddress_;
2931
QString ch2PortNum_;
3032
DataType ch2DataType_;
3133
QString ch2LoadFile_;
3234
DataType ch2PlaybackDataType_;
3335
int ch2DeltaDelay_;
36+
bool ch2EnableSendOut_;
37+
QString ch2SendOutPortNum_;
3438

3539
bool combineChannel_;
3640
bool showGrid_;

include/mainwindow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class MainWindow : public QMainWindow
9797
void LoadFileEdited2(const QString& text);
9898
void LoadFileBrowse2();
9999

100+
void EnableSendToNetwork();
101+
void EnableSendToNetwork2();
102+
100103
void PlayPauseButtonClicked();
101104
void PlayPauseButtonClicked2();
102105

include/osireader.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <osi_version.pb.h>
1212
#include <osi_sensordata.pb.h>
1313

14+
#include <zmq.hpp>
15+
1416
#include <fstream>
1517
#include <iostream>
1618
#include <unistd.h>
@@ -27,7 +29,13 @@ class OsiReader: public QObject, public IMessageSource
2729
Q_OBJECT
2830

2931
public:
30-
OsiReader(int* deltaDelay);
32+
OsiReader(int* deltaDelay,
33+
const bool& enableSendOut,
34+
const std::string& zmqPubPortNum);
35+
36+
QString SetupConnection(bool enable);
37+
38+
void SetSendOutPortNum(const std::string& port) { zmqPubPortNumber_ = port; }
3139

3240
signals:
3341
void Connected(DataType dataType);
@@ -52,6 +60,8 @@ class OsiReader: public QObject, public IMessageSource
5260

5361
void SendMessageLoop();
5462

63+
void ZMQSendOutMessage(const osi::SensorData& sd);
64+
5565

5666

5767
bool isRunning_;
@@ -69,6 +79,11 @@ class OsiReader: public QObject, public IMessageSource
6979

7080
const int* const deltaDelay_;
7181

82+
const bool& enableSendOut_;
83+
std::string zmqPubPortNumber_;
84+
zmq::context_t zmqContext_;
85+
zmq::socket_t zmqPublisher_;
86+
7287
// read from input file: data type is always SensorData
7388
DataType defaultDatatype_ = DataType::Groundtruth;
7489
const QString defaultHeaderPrifix_ = "Header_";

src/appconfig.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ AppConfig::AppConfig(QString fileName)
1313
, ch1LoadFile_("")
1414
, ch1PlaybackDataType_(DataType::Groundtruth)
1515
, ch1DeltaDelay_(0)
16+
, ch1EnableSendOut_(false)
17+
, ch1SendOutPortNum_("5564")
1618

1719
, ch2IPAddress_("")
1820
, ch2PortNum_("")
1921
, ch2DataType_(DataType::Groundtruth)
2022
, ch2LoadFile_("")
2123
, ch2PlaybackDataType_(DataType::Groundtruth)
2224
, ch2DeltaDelay_(0)
25+
, ch2EnableSendOut_(false)
26+
, ch2SendOutPortNum_("5564")
2327

2428
, combineChannel_(false)
2529
, showGrid_(true)
@@ -58,16 +62,20 @@ AppConfig::Load()
5862
ch1DataType_ = (DataType)root.elementsByTagName("CH1DataType").at(0).toElement().text().toInt();
5963
ch1LoadFile_ = root.elementsByTagName("CH1LoadFile").at(0).toElement().text();
6064
ch1PlaybackDataType_ = (DataType)root.elementsByTagName("CH1PlaybackDataType").at(0).toElement().text().toInt();
61-
ch1DeltaDelay_ = root.elementsByTagName("CH1DeltaDelay").at(0).toElement().text().toInt();
65+
ch1DeltaDelay_ = root.elementsByTagName("CH1DeltaDelay").at(0).toElement().text().toInt();
66+
ch1EnableSendOut_ = root.elementsByTagName("CH1EnableSendOut").at(0).toElement().text() == "1" ? true : false;
67+
ch1SendOutPortNum_ = root.elementsByTagName("CH1SendOutPortNumber").at(0).toElement().text();
6268

6369
ch2IPAddress_ = root.elementsByTagName("CH2IpAddress").at(0).toElement().text();
6470
ch2PortNum_ = root.elementsByTagName("CH2PortNumber").at(0).toElement().text();
6571
ch2DataType_ = (DataType)root.elementsByTagName("CH2DataType").at(0).toElement().text().toInt();
6672
ch2LoadFile_ = root.elementsByTagName("CH2LoadFile").at(0).toElement().text();
6773
ch2PlaybackDataType_ = (DataType)root.elementsByTagName("CH2PlaybackDataType").at(0).toElement().text().toInt();
68-
ch2DeltaDelay_ = root.elementsByTagName("CH2DeltaDelay").at(0).toElement().text().toInt();
74+
ch2DeltaDelay_ = root.elementsByTagName("CH2DeltaDelay").at(0).toElement().text().toInt();
75+
ch2EnableSendOut_ = root.elementsByTagName("CH2EnableSendOut").at(0).toElement().text() == "1" ? true : false;
76+
ch2SendOutPortNum_ = root.elementsByTagName("CH2SendOutPortNumber").at(0).toElement().text();
6977

70-
combineChannel_ = root.elementsByTagName("CombineChannel").at(0).toElement().text() == "1" ? true : false;
78+
combineChannel_ = root.elementsByTagName("CombineChannel").at(0).toElement().text() == "1" ? true : false;
7179
showGrid_ = root.elementsByTagName("ShowGrid").at(0).toElement().text() == "1" ? true : false;
7280
showObjectDetails_ = root.elementsByTagName("ShowObjectDetails").at(0).toElement().text() == "1" ? true : false;
7381
lockCamera_ = root.elementsByTagName("LockCamera").at(0).toElement().text() == "1" ? true : false;
@@ -109,13 +117,17 @@ AppConfig::Save()
109117
writer.writeTextElement("CH1LoadFile", ch1LoadFile_);
110118
writer.writeTextElement("CH1PlaybackDataType", QString::number(static_cast<int>(ch1PlaybackDataType_)));
111119
writer.writeTextElement("CH1DeltaDelay", QString::number(static_cast<int>(ch1DeltaDelay_)));
120+
writer.writeTextElement("CH1EnableSendOut", QString::number(ch1EnableSendOut_));
121+
writer.writeTextElement("CH1SendOutPortNumber", ch1SendOutPortNum_);
112122

113123
writer.writeTextElement("CH2IpAddress", ch2IPAddress_);
114124
writer.writeTextElement("CH2PortNumber", ch2PortNum_);
115125
writer.writeTextElement("CH2DataType", QString::number(static_cast<int>(ch2DataType_)));
116126
writer.writeTextElement("CH2LoadFile", ch2LoadFile_);
117127
writer.writeTextElement("CH2PlaybackDataType", QString::number(static_cast<int>(ch2PlaybackDataType_)));
118128
writer.writeTextElement("CH2DeltaDelay", QString::number(static_cast<int>(ch2DeltaDelay_)));
129+
writer.writeTextElement("CH2EnableSendOut", QString::number(ch2EnableSendOut_));
130+
writer.writeTextElement("CH2SendOutPortNumber", ch2SendOutPortNum_);
119131

120132
writer.writeTextElement("CombineChannel", QString::number(combineChannel_));
121133
writer.writeTextElement("ShowGrid", QString::number(showGrid_));

src/mainwindow.cpp

Lines changed: 107 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ MainWindow::MainWindow(QWidget *parent)
4747

4848
, glWidget_(nullptr)
4949
, receiver_(new TCPReceiver())
50-
, reader_(new OsiReader(&config_.ch1DeltaDelay_))
50+
, reader_(new OsiReader(&config_.ch1DeltaDelay_, config_.ch1EnableSendOut_, config_.ch1SendOutPortNum_.toStdString()))
5151
, osiparser_(new OsiParser(config_.osiMsgSaveThreshold_))
5252

5353
, glWidget2_(nullptr)
5454
, receiver2_(new TCPReceiver())
55-
, reader2_(new OsiReader(&config_.ch2DeltaDelay_))
55+
, reader2_(new OsiReader(&config_.ch2DeltaDelay_, config_.ch2EnableSendOut_, config_.ch2SendOutPortNum_.toStdString()))
5656
, osiparser2_(new OsiParser(config_.osiMsgSaveThreshold_))
5757

5858
, colorWidgets_()
@@ -199,6 +199,18 @@ MainWindow::LoadFileBrowse2()
199199
}
200200
}
201201

202+
void
203+
MainWindow::EnableSendToNetwork()
204+
{
205+
ui_->sendOutPortNum->setEnabled(ui_->enableSendToNetwork->checkState() == Qt::Checked);
206+
}
207+
208+
void
209+
MainWindow::EnableSendToNetwork2()
210+
{
211+
ui_->sendOutPortNum_2->setEnabled(ui_->enableSendToNetwork_2->checkState() == Qt::Checked);
212+
}
213+
202214
void
203215
MainWindow::UpdateCombineChannelMenu()
204216
{
@@ -432,11 +444,15 @@ MainWindow::ConnectSignalsToSlots()
432444
connect(ui_->rbPlayback_2, &QRadioButton::clicked, this, &MainWindow::RBPlayback2);
433445

434446
// load/save playback file
435-
connect(ui_->loadFile, &QLineEdit::textEdited, this, &MainWindow::LoadFileEdited);
447+
connect(ui_->loadFile, &QLineEdit::textEdited, this, &MainWindow::LoadFileEdited);
436448
connect(ui_->loadFileBrowse, &QPushButton::clicked, this, &MainWindow::LoadFileBrowse);
437-
connect(ui_->loadFile_2, &QLineEdit::textEdited, this, &MainWindow::LoadFileEdited2);
449+
connect(ui_->loadFile_2, &QLineEdit::textEdited, this, &MainWindow::LoadFileEdited2);
438450
connect(ui_->loadFileBrowse_2, &QPushButton::clicked, this, &MainWindow::LoadFileBrowse2);
439451

452+
// enable sent out
453+
connect(ui_->enableSendToNetwork, &QCheckBox::clicked, this, &MainWindow::EnableSendToNetwork);
454+
connect(ui_->enableSendToNetwork_2, &QCheckBox::clicked, this, &MainWindow::EnableSendToNetwork2);
455+
440456
// Play/Pause
441457
connect(ui_->playPauseButton, &QToolButton::clicked, this, &MainWindow::PlayPauseButtonClicked);
442458
connect(ui_->playPauseButton_2, &QToolButton::clicked, this, &MainWindow::PlayPauseButtonClicked2);
@@ -617,6 +633,8 @@ MainWindow::EnablePlaybackGroup1(bool enable)
617633
ui_->loadFileBrowse->setEnabled(enable);
618634
ui_->playbackDataType->setEnabled(enable);
619635
ui_->deltaDelay->setEnabled(enable);
636+
ui_->enableSendToNetwork->setEnabled(enable);
637+
ui_->sendOutPortNum->setEnabled(enable && ui_->enableSendToNetwork->checkState() == Qt::Checked);
620638
}
621639

622640
void
@@ -626,6 +644,8 @@ MainWindow::EnablePlaybackGroup2(bool enable)
626644
ui_->loadFileBrowse_2->setEnabled(enable);
627645
ui_->playbackDataType_2->setEnabled(enable);
628646
ui_->deltaDelay_2->setEnabled(enable);
647+
ui_->enableSendToNetwork_2->setEnabled(enable);
648+
ui_->sendOutPortNum_2->setEnabled(enable && ui_->enableSendToNetwork_2->checkState() == Qt::Checked);
629649
}
630650

631651
void
@@ -756,6 +776,7 @@ bool
756776
MainWindow::UpdateConfigure()
757777
{
758778
bool hasChange (false);
779+
bool saveChange (false);
759780

760781
if(config_.ch1IPAddress_ != ui_->ipAddress->text())
761782
{
@@ -789,10 +810,24 @@ MainWindow::UpdateConfigure()
789810

790811
if(config_.ch1DeltaDelay_ != ui_->deltaDelay->text().toInt())
791812
{
813+
saveChange = true;
792814
config_.ch1DeltaDelay_ = ui_->deltaDelay->text().toInt();
793-
config_.Save();
794815
}
795-
else if(hasChange)
816+
817+
if(config_.ch1EnableSendOut_ != (ui_->enableSendToNetwork->checkState() == Qt::Checked))
818+
{
819+
saveChange = true;
820+
config_.ch1EnableSendOut_ = (ui_->enableSendToNetwork->checkState() == Qt::Checked);
821+
}
822+
823+
if(config_.ch1SendOutPortNum_ != ui_->sendOutPortNum->text())
824+
{
825+
saveChange = true;
826+
config_.ch1SendOutPortNum_ = ui_->sendOutPortNum->text();
827+
reader_->SetSendOutPortNum(config_.ch1SendOutPortNum_.toStdString());
828+
}
829+
830+
if(hasChange || saveChange)
796831
config_.Save();
797832

798833
return hasChange;
@@ -802,6 +837,7 @@ bool
802837
MainWindow::UpdateConfigure2()
803838
{
804839
bool hasChange (false);
840+
bool saveChange (false);
805841

806842
if(config_.ch2IPAddress_ != ui_->ipAddress_2->text())
807843
{
@@ -835,10 +871,24 @@ MainWindow::UpdateConfigure2()
835871

836872
if(config_.ch2DeltaDelay_ != ui_->deltaDelay_2->text().toInt())
837873
{
874+
saveChange = true;
838875
config_.ch2DeltaDelay_ = ui_->deltaDelay_2->text().toInt();
839-
config_.Save();
840876
}
841-
else if(hasChange)
877+
878+
if(config_.ch2EnableSendOut_ != (ui_->enableSendToNetwork_2->checkState() == Qt::Checked))
879+
{
880+
saveChange = true;
881+
config_.ch2EnableSendOut_ = (ui_->enableSendToNetwork_2->checkState() == Qt::Checked);
882+
}
883+
884+
if(config_.ch2SendOutPortNum_ != ui_->sendOutPortNum_2->text())
885+
{
886+
saveChange = true;
887+
config_.ch2SendOutPortNum_ = ui_->sendOutPortNum_2->text();
888+
reader2_->SetSendOutPortNum(config_.ch2SendOutPortNum_.toStdString());
889+
}
890+
891+
if(hasChange || saveChange)
842892
config_.Save();
843893

844894
return hasChange;
@@ -855,13 +905,25 @@ MainWindow::InitLoadConfigure()
855905
ui_->loadFile->setText(config_.ch1LoadFile_);
856906
ui_->playbackDataType->setCurrentIndex( static_cast<int>(config_.ch1PlaybackDataType_) );
857907
ui_->deltaDelay->setText(QString::number(config_.ch1DeltaDelay_));
908+
if(config_.ch1EnableSendOut_)
909+
ui_->enableSendToNetwork->setCheckState(Qt::Checked);
910+
else
911+
ui_->enableSendToNetwork->setCheckState(Qt::Unchecked);
912+
ui_->sendOutPortNum->setText(config_.ch1SendOutPortNum_);
913+
reader_->SetSendOutPortNum(config_.ch1SendOutPortNum_.toStdString());
858914

859915
ui_->ipAddress_2->setText(config_.ch2IPAddress_);
860916
ui_->portNumber_2->setText(config_.ch2PortNum_);
861917
ui_->dataType_2->setCurrentIndex( static_cast<int>(config_.ch2DataType_) );
862918
ui_->loadFile_2->setText(config_.ch2LoadFile_);
863919
ui_->playbackDataType_2->setCurrentIndex( static_cast<int>(config_.ch2PlaybackDataType_) );
864920
ui_->deltaDelay_2->setText(QString::number(config_.ch2DeltaDelay_));
921+
if(config_.ch2EnableSendOut_)
922+
ui_->enableSendToNetwork_2->setCheckState(Qt::Checked);
923+
else
924+
ui_->enableSendToNetwork_2->setCheckState(Qt::Unchecked);
925+
ui_->sendOutPortNum_2->setText(config_.ch2SendOutPortNum_);
926+
reader2_->SetSendOutPortNum(config_.ch2SendOutPortNum_.toStdString());
865927

866928
ui_->actionCombiCh->setChecked(config_.combineChannel_);
867929
ui_->actionShowGrid->setChecked(config_.showGrid_);
@@ -1122,17 +1184,32 @@ MainWindow::Play()
11221184
void
11231185
MainWindow::TogglePause()
11241186
{
1187+
QString errMsg;
1188+
11251189
if(isConnected_)
11261190
{
11271191
receiver_->isPaused_ = isPlaying_;
11281192
}
11291193

11301194
if(isPlayed_)
11311195
{
1132-
reader_->isPaused_ = isPlaying_;
1196+
if(isPlaying_)
1197+
{
1198+
reader_->isPaused_ = true;
1199+
reader_->SetupConnection(false);
1200+
}
1201+
else
1202+
{
1203+
errMsg = reader_->SetupConnection(true);
1204+
if(errMsg.isEmpty())
1205+
reader_->isPaused_ = false;
1206+
else
1207+
ShowErrorMessage(errMsg);
1208+
}
11331209
}
11341210

1135-
isPlaying_ = !isPlaying_;
1211+
if(errMsg.isEmpty())
1212+
isPlaying_ = !isPlaying_;
11361213
}
11371214

11381215
void
@@ -1167,17 +1244,31 @@ MainWindow::Play2()
11671244
void
11681245
MainWindow::TogglePause2()
11691246
{
1247+
QString errMsg;
1248+
11701249
if(isConnected2_)
11711250
{
11721251
receiver2_->isPaused_ = isPlaying2_;
11731252
}
1174-
1175-
if(isPlayed2_)
1253+
else if(isPlayed2_)
11761254
{
1177-
reader2_->isPaused_ = isPlaying2_;
1255+
if(isPlaying2_)
1256+
{
1257+
reader2_->isPaused_ = true;
1258+
reader2_->SetupConnection(false);
1259+
}
1260+
else
1261+
{
1262+
errMsg = reader2_->SetupConnection(true);
1263+
if(errMsg.isEmpty())
1264+
reader2_->isPaused_ = false;
1265+
else
1266+
ShowErrorMessage(errMsg);
1267+
}
11781268
}
11791269

1180-
isPlaying2_ = !isPlaying2_;
1270+
if(errMsg.isEmpty())
1271+
isPlaying2_ = !isPlaying2_;
11811272
}
11821273

11831274
void
@@ -1269,7 +1360,8 @@ MainWindow::Disconnected2(const QString& message)
12691360
UpdateCombineChannelMenu();
12701361
}
12711362

1272-
QString MainWindow::GetStringFromMilliSecond(int milliSec)
1363+
QString
1364+
MainWindow::GetStringFromMilliSecond(int milliSec)
12731365
{
12741366
QString varString;
12751367

0 commit comments

Comments
 (0)