summaryrefslogtreecommitdiffstats
path: root/src/ReceiverThreads/ReceiverThreads.cpp
diff options
context:
space:
mode:
authorTobias Frust <tobiasfrust@gmail.com>2016-10-13 10:27:01 +0200
committerGitHub <noreply@github.com>2016-10-13 10:27:01 +0200
commita38a5f1b646cdc992c3b602330a41036bc9bf7b1 (patch)
tree7fc93e5f5c3729d0fa013946fe60fa881a53579c /src/ReceiverThreads/ReceiverThreads.cpp
parent8af3d595e2856f81a46a91d67e96f53cb3b25d0f (diff)
parentcdab7a0b05f655a2f98f00f3fb8928e54b8c28d2 (diff)
downloadods-a38a5f1b646cdc992c3b602330a41036bc9bf7b1.tar.gz
ods-a38a5f1b646cdc992c3b602330a41036bc9bf7b1.tar.bz2
ods-a38a5f1b646cdc992c3b602330a41036bc9bf7b1.tar.xz
ods-a38a5f1b646cdc992c3b602330a41036bc9bf7b1.zip
Merge pull request #2 from tobiasfrust/master
Merge of the DetectorSimulator
Diffstat (limited to 'src/ReceiverThreads/ReceiverThreads.cpp')
-rw-r--r--src/ReceiverThreads/ReceiverThreads.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/ReceiverThreads/ReceiverThreads.cpp b/src/ReceiverThreads/ReceiverThreads.cpp
new file mode 100644
index 0000000..3d22c66
--- /dev/null
+++ b/src/ReceiverThreads/ReceiverThreads.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2016
+ *
+ * ReceiverThreads.cpp
+ *
+ * Created on: 21.07.2016
+ * Author: Tobias Frust
+ */
+
+#include "ReceiverThreads.h"
+#include "../UDPServer/UDPServer.h"
+
+#include <boost/log/trivial.hpp>
+
+ReceiverThreads::ReceiverThreads(const std::string& address, const int timeIntervall, const int numberOfDetectorModules)
+ : timeIntervall_{timeIntervall}, numberOfDetectorModules_{numberOfDetectorModules}, address_{address}, loss_{0} {
+
+ for(auto i = 0; i < numberOfDetectorModules; i++){
+ receiverModules_.emplace_back(&ReceiverThreads::receiverThread, this, 4000+i);
+ }
+
+ for(auto i = 0; i < numberOfDetectorModules; i++){
+ receiverModules_[i].join();
+ }
+
+}
+
+auto ReceiverThreads::receiverThread(const int port) -> void {
+ UDPServer server = UDPServer(address_, port);
+ std::vector<unsigned short> buf(33000);
+ std::size_t lastIndex{0};
+ BOOST_LOG_TRIVIAL(info) << "Address: " << address_ << " port: " << port << " timeout: " << timeIntervall_;
+ while(true){
+ int bytes = server.timed_recv((char*)buf.data(), 65536, timeIntervall_);
+ if(bytes < 0){
+ break;
+ }
+ BOOST_LOG_TRIVIAL(debug) << "Received " << bytes << " Bytes.";
+ std::size_t index = *((std::size_t *)buf.data());
+ int diff = index - lastIndex - 1;
+ if(diff > 0){
+ loss_ += diff;
+ BOOST_LOG_TRIVIAL(debug) << "Packet loss or wrong order! new: " << index << " old: " << lastIndex;
+ }
+ lastIndex = index;
+ }
+ BOOST_LOG_TRIVIAL(info) << "Lost " << loss_ << " from " << lastIndex << " packets; (" << loss_/(double)lastIndex*100.0 << "%)";
+}
+