From cdf8aac7e3a88df0fb93586bbf47b17c192ae2fc Mon Sep 17 00:00:00 2001 From: Tobias Frust Date: Thu, 21 Jul 2016 09:33:42 +0200 Subject: added ReceiverThreads for tests with 40GBE --- src/CMakeLists.txt | 1 + src/CMakeLists.txt~ | 14 ++++++++-- src/DetectorModule/DetectorModule.cpp | 2 +- src/ReceiverThreads/ReceiverThreads.cpp | 48 +++++++++++++++++++++++++++++++++ src/ReceiverThreads/ReceiverThreads.h | 35 ++++++++++++++++++++++++ src/UDPServer/UDPServer.cpp | 26 +++++------------- src/main_server.cpp | 33 ++++++++++++----------- 7 files changed, 122 insertions(+), 37 deletions(-) create mode 100644 src/ReceiverThreads/ReceiverThreads.cpp create mode 100644 src/ReceiverThreads/ReceiverThreads.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d77a039..d4ee49d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -45,6 +45,7 @@ set(SOURCES_CLIENT ) set(SOURCES_SERVER + "${CMAKE_SOURCE_DIR}/ReceiverThreads/ReceiverThreads.cpp" "${CMAKE_SOURCE_DIR}/UDPServer/UDPServer.cpp" "${CMAKE_SOURCE_DIR}/main_server.cpp" ) diff --git a/src/CMakeLists.txt~ b/src/CMakeLists.txt~ index 80196d9..ebe2f50 100644 --- a/src/CMakeLists.txt~ +++ b/src/CMakeLists.txt~ @@ -31,9 +31,18 @@ include_directories( ${BOOST_INCLUDE_DIRS} ) +set(LINK_LIBRARIES ${LINK_LIBRARIES} + ${LIBCONFIGPP_LIBRARY} + ${Boost_LIBRARIES} +) + set(SOURCES_CLIENT + "${CMAKE_SOURCE_DIR}/ConfigReader/ConfigReader.cpp" "${CMAKE_SOURCE_DIR}/UDPClient/UDPClient.cpp" - "${CMAKE_SOURCE_DIR}/main.cpp" + "${CMAKE_SOURCE_DIR}/DetectorModule/DetectorModule.cpp" + "${CMAKE_SOURCE_DIR}/Detector/Detector.cpp" + "${CMAKE_SOURCE_DIR}/main_client.cpp" + "${CMAKE_SOURCE_DIR}/ReceiverThreads/ReceiverThreads.cpp" ) set(SOURCES_SERVER @@ -43,5 +52,6 @@ set(SOURCES_SERVER add_executable(onlineDetectorSimulatorServer ${SOURCES_SERVER}) add_executable(onlineDetectorSimulatorClient ${SOURCES_CLIENT}) - +target_link_libraries(onlineDetectorSimulatorClient ${LINK_LIBRARIES}) +target_link_libraries(onlineDetectorSimulatorServer ${LINK_LIBRARIES}) diff --git a/src/DetectorModule/DetectorModule.cpp b/src/DetectorModule/DetectorModule.cpp index bee50e9..9c3d98f 100644 --- a/src/DetectorModule/DetectorModule.cpp +++ b/src/DetectorModule/DetectorModule.cpp @@ -28,7 +28,7 @@ void timer_start(std::function func, unsigned int interval){ DetectorModule::DetectorModule(const int detectorID, const std::string& address, const std::string& configPath) : detectorID_{detectorID}, numberOfDetectorsPerModule_{16}, - index_{0}, + index_{1}, client_{address, detectorID+4000} { printf("Creating %d\n", detectorID); diff --git a/src/ReceiverThreads/ReceiverThreads.cpp b/src/ReceiverThreads/ReceiverThreads.cpp new file mode 100644 index 0000000..6f389f2 --- /dev/null +++ b/src/ReceiverThreads/ReceiverThreads.cpp @@ -0,0 +1,48 @@ +/* + * Copyright 2016 + * + * ReceiverThreads.cpp + * + * Created on: 21.07.2016 + * Author: Tobias Frust + */ + +#include "ReceiverThreads.h" +#include "../UDPServer/UDPServer.h" + +#include + +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 buf(16000); + 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(), buf.size()*sizeof(unsigned short), timeIntervall_); + if(bytes < 0){ + break; + } + std::size_t index = *((std::size_t *)buf.data()); + int diff = index - lastIndex - 1; + if(diff > 0){ + BOOST_LOG_TRIVIAL(warning) << "Packet loss or wrong order! new: " << index << " old: " << lastIndex; + } + loss_ += diff; + lastIndex = index; + } + BOOST_LOG_TRIVIAL(info) << "Lost " << loss_ << " from " << lastIndex << " packets; (" << loss_/(double)lastIndex << "%)"; +} + diff --git a/src/ReceiverThreads/ReceiverThreads.h b/src/ReceiverThreads/ReceiverThreads.h new file mode 100644 index 0000000..7cb04c0 --- /dev/null +++ b/src/ReceiverThreads/ReceiverThreads.h @@ -0,0 +1,35 @@ +/* + * Copyright 2016 + * + * ReceiverThreads.h + * + * Created on: 21.07.2016 + * Author: Tobias Frust + */ + +#ifndef RECEIVERTHREADS_H_ +#define RECEIVERTHREADS_H_ + +#include +#include + +class ReceiverThreads { +public: + ReceiverThreads(const std::string& address, const int timeIntervall, const int numberOfDetectorModules); + + auto run() -> void; +private: + auto receiverThread(const int port) -> void; + + std::vector receiverModules_; + + std::size_t loss_; + + int timeIntervall_; + int numberOfDetectorModules_; + + std::string address_; + +}; + +#endif /* RECEIVERTHREADS_H_ */ diff --git a/src/UDPServer/UDPServer.cpp b/src/UDPServer/UDPServer.cpp index 3a50d0c..8c9decf 100644 --- a/src/UDPServer/UDPServer.cpp +++ b/src/UDPServer/UDPServer.cpp @@ -168,31 +168,19 @@ int UDPServer::recv(char *msg, size_t max_size) * * \param[in] msg The buffer where the message will be saved. * \param[in] max_size The size of the \p msg buffer in bytes. - * \param[in] max_wait_ms The maximum number of milliseconds to wait for a message. + * \param[in] max_wait_s The maximum number of seconds to wait for a message. * * \return -1 if an error occurs or the function timed out, the number of bytes received otherwise. */ -int UDPServer::timed_recv(char *msg, size_t max_size, int max_wait_ms) +int UDPServer::timed_recv(char *msg, size_t max_size, int max_wait_s) { fd_set s; FD_ZERO(&s); FD_SET(f_socket, &s); struct timeval timeout; - timeout.tv_sec = max_wait_ms / 1000; - timeout.tv_usec = (max_wait_ms % 1000) * 1000; - int retval = select(f_socket + 1, &s, &s, &s, &timeout); - if(retval == -1) - { - // select() set errno accordingly - return -1; - } - if(retval > 0) - { - // our socket has data - return ::recv(f_socket, msg, max_size, 0); - } - - // our socket has no data - errno = EAGAIN; - return -1; + timeout.tv_sec = max_wait_s; + timeout.tv_usec = 0; + setsockopt(f_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,sizeof(struct timeval)); + // our socket has data + return ::recv(f_socket, msg, max_size, 0); } diff --git a/src/main_server.cpp b/src/main_server.cpp index 6e936e4..90b3835 100644 --- a/src/main_server.cpp +++ b/src/main_server.cpp @@ -1,4 +1,5 @@ #include "UDPServer/UDPServer.h" +#include "ReceiverThreads/ReceiverThreads.h" #include #include @@ -30,9 +31,9 @@ int main (int argc, char *argv[]){ initLog(); std::string address = "localhost"; - int port = 4002; - - UDPServer server = UDPServer(address, port); +// int port = 4002; +// +// UDPServer server = UDPServer(address, port); std::size_t length{32768}; std::size_t lastIndex{0}; @@ -41,6 +42,8 @@ int main (int argc, char *argv[]){ std::cout << "Receiving UDP packages: " << std::endl; + ReceiverThreads(address, 10, 27); + // for(auto i = 0; i < 27; i++){ // std::function f = [=]() { // server.recv(); @@ -48,18 +51,18 @@ int main (int argc, char *argv[]){ // start(); // } - while(true){ - int bytes = server.recv((char*)buf.data(), length); - std::size_t index = *((std::size_t *)buf.data()); - if(index%1000 == 99) printf("%lu\n", index); - - if(lastIndex != (index-1)) - BOOST_LOG_TRIVIAL(warning) << "Packet loss or wrong order!"; - - lastIndex = index; - - BOOST_LOG_TRIVIAL(debug) << "Server: Received " << bytes << " Bytes with Index " << index; - } +// while(true){ +// int bytes = server.recv((char*)buf.data(), length); +// std::size_t index = *((std::size_t *)buf.data()); +// if(index%1000 == 99) printf("%lu\n", index); +// +// if(lastIndex != (index-1)) +// BOOST_LOG_TRIVIAL(warning) << "Packet loss or wrong order!"; +// +// lastIndex = index; +// +// BOOST_LOG_TRIVIAL(debug) << "Server: Received " << bytes << " Bytes with Index " << index; +// } return 0; -- cgit v1.2.1 From 8940620375c3bd9fef263fe9352c22384215cb13 Mon Sep 17 00:00:00 2001 From: Tobias Frust Date: Thu, 21 Jul 2016 09:50:16 +0200 Subject: sending out always the same packet --- src/DetectorModule/DetectorModule.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/DetectorModule/DetectorModule.cpp b/src/DetectorModule/DetectorModule.cpp index 9c3d98f..c98a3e2 100644 --- a/src/DetectorModule/DetectorModule.cpp +++ b/src/DetectorModule/DetectorModule.cpp @@ -41,6 +41,8 @@ DetectorModule::DetectorModule(const int detectorID, const std::string& address, //read the input data from the file corresponding to the detectorModuleID readInput(); + unsigned int sinoSize = numberOfDetectorsPerModule_*numberOfProjections_; + std::copy(((char*)buffer_.data()), ((char*)buffer_.data())+sinoSize*sizeof(unsigned short), sendBuffer_.begin()+sizeof(std::size_t)); printf("Created %d\n", detectorID); } @@ -57,8 +59,8 @@ auto DetectorModule::send() -> void{ unsigned int bufferSizeIndex = index_ % 1000; unsigned int sinoSize = numberOfDetectorsPerModule_*numberOfProjections_; *reinterpret_cast(sendBuffer_.data()) = index_; - std::copy(((char*)buffer_.data())+sinoSize*bufferSizeIndex*sizeof(unsigned short), ((char*)buffer_.data())+(sinoSize*(1+bufferSizeIndex))*sizeof(unsigned short), sendBuffer_.begin()+sizeof(std::size_t)); - client_.send(sendBuffer_.data(), sizeof(unsigned short)*numberOfDetectorsPerModule_*numberOfProjections_+sizeof(std::size_t)); + //std::copy(((char*)buffer_.data())+sinoSize*bufferSizeIndex*sizeof(unsigned short), ((char*)buffer_.data())+(sinoSize*(1+bufferSizeIndex))*sizeof(unsigned short), sendBuffer_.begin()+sizeof(std::size_t)); + client_.send(sendBuffer_.data(), sizeof(unsigned short)*sinoSize+sizeof(std::size_t)); ++index_; } -- cgit v1.2.1 From ebcd23f3d86976fbfe2768d3ee0925db2cff773a Mon Sep 17 00:00:00 2001 From: Tobias Frust Date: Thu, 21 Jul 2016 10:23:08 +0200 Subject: packet size is now configurable --- src/Detector/Detector.cpp | 4 ++-- src/Detector/Detector.h | 2 +- src/DetectorModule/DetectorModule.cpp | 13 +++++++------ src/DetectorModule/DetectorModule.h | 4 +++- src/ReceiverThreads/ReceiverThreads.cpp | 9 +++++---- src/main_client.cpp | 8 +++++--- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/Detector/Detector.cpp b/src/Detector/Detector.cpp index 5dde6d1..03abffe 100644 --- a/src/Detector/Detector.cpp +++ b/src/Detector/Detector.cpp @@ -10,12 +10,12 @@ #include "Detector.h" -Detector::Detector(const std::string& address, const std::string& configPath, const unsigned int timeIntervall) : +Detector::Detector(const std::string& address, const std::string& configPath, const unsigned int timeIntervall, const int packetSize) : timeIntervall_{timeIntervall}, numberOfDetectorModules_{27} { modules_.reserve(numberOfDetectorModules_); for(auto i = 0; i < numberOfDetectorModules_; i++){ - modules_.emplace_back(i, address, configPath); + modules_.emplace_back(i, address, configPath, packetSize); } } diff --git a/src/Detector/Detector.h b/src/Detector/Detector.h index 1969dbd..16f946a 100644 --- a/src/Detector/Detector.h +++ b/src/Detector/Detector.h @@ -17,7 +17,7 @@ class Detector { public: - Detector(const std::string& address, const std::string& configPath, const unsigned int timeIntervall); + Detector(const std::string& address, const std::string& configPath, const unsigned int timeIntervall, const int packetSize); auto run() -> void; private: diff --git a/src/DetectorModule/DetectorModule.cpp b/src/DetectorModule/DetectorModule.cpp index c98a3e2..b222341 100644 --- a/src/DetectorModule/DetectorModule.cpp +++ b/src/DetectorModule/DetectorModule.cpp @@ -25,11 +25,12 @@ void timer_start(std::function func, unsigned int interval){ }).detach(); } -DetectorModule::DetectorModule(const int detectorID, const std::string& address, const std::string& configPath) : +DetectorModule::DetectorModule(const int detectorID, const std::string& address, const std::string& configPath, const int packetSize) : detectorID_{detectorID}, numberOfDetectorsPerModule_{16}, index_{1}, - client_{address, detectorID+4000} { + client_{address, detectorID+4000}, + packetSize_{packetSize} { printf("Creating %d\n", detectorID); @@ -37,12 +38,12 @@ DetectorModule::DetectorModule(const int detectorID, const std::string& address, throw std::runtime_error("DetectorModule: Configuration file could not be loaded successfully. Please check!"); } - sendBuffer_.resize(numberOfDetectorsPerModule_*numberOfProjections_*sizeof(unsigned short) + sizeof(std::size_t)); + sendBuffer_.resize(packetSize); //read the input data from the file corresponding to the detectorModuleID readInput(); - unsigned int sinoSize = numberOfDetectorsPerModule_*numberOfProjections_; - std::copy(((char*)buffer_.data()), ((char*)buffer_.data())+sinoSize*sizeof(unsigned short), sendBuffer_.begin()+sizeof(std::size_t)); + //unsigned int sinoSize = numberOfDetectorsPerModule_*numberOfProjections_; + //std::copy(((char*)buffer_.data()), ((char*)buffer_.data())+sinoSize*sizeof(unsigned short), sendBuffer_.begin()+sizeof(std::size_t)); printf("Created %d\n", detectorID); } @@ -60,7 +61,7 @@ auto DetectorModule::send() -> void{ unsigned int sinoSize = numberOfDetectorsPerModule_*numberOfProjections_; *reinterpret_cast(sendBuffer_.data()) = index_; //std::copy(((char*)buffer_.data())+sinoSize*bufferSizeIndex*sizeof(unsigned short), ((char*)buffer_.data())+(sinoSize*(1+bufferSizeIndex))*sizeof(unsigned short), sendBuffer_.begin()+sizeof(std::size_t)); - client_.send(sendBuffer_.data(), sizeof(unsigned short)*sinoSize+sizeof(std::size_t)); + client_.send(sendBuffer_.data(), sendBuffer_.size()); ++index_; } diff --git a/src/DetectorModule/DetectorModule.h b/src/DetectorModule/DetectorModule.h index 1bc36bb..5e540cb 100644 --- a/src/DetectorModule/DetectorModule.h +++ b/src/DetectorModule/DetectorModule.h @@ -21,7 +21,7 @@ class DetectorModule { public: - DetectorModule(const int detectorID, const std::string& address, const std::string& configPath); + DetectorModule(const int detectorID, const std::string& address, const std::string& configPath, const int packetSize); auto sendPeriodically(unsigned int timeIntervall) -> void; @@ -32,6 +32,8 @@ private: int detectorID_; UDPClient client_; + int packetSize_; + int numberOfDetectors_; int numberOfPlanes_; int numberOfProjections_; diff --git a/src/ReceiverThreads/ReceiverThreads.cpp b/src/ReceiverThreads/ReceiverThreads.cpp index 6f389f2..a99467a 100644 --- a/src/ReceiverThreads/ReceiverThreads.cpp +++ b/src/ReceiverThreads/ReceiverThreads.cpp @@ -27,20 +27,21 @@ ReceiverThreads::ReceiverThreads(const std::string& address, const int timeInter auto ReceiverThreads::receiverThread(const int port) -> void { UDPServer server = UDPServer(address_, port); - std::vector buf(16000); + std::vector 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(), buf.size()*sizeof(unsigned short), timeIntervall_); + 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){ - BOOST_LOG_TRIVIAL(warning) << "Packet loss or wrong order! new: " << index << " old: " << lastIndex; + loss_ += diff; + BOOST_LOG_TRIVIAL(debug) << "Packet loss or wrong order! new: " << index << " old: " << lastIndex; } - loss_ += diff; lastIndex = index; } BOOST_LOG_TRIVIAL(info) << "Lost " << loss_ << " from " << lastIndex << " packets; (" << loss_/(double)lastIndex << "%)"; diff --git a/src/main_client.cpp b/src/main_client.cpp index 2b9927d..19f366e 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -19,13 +19,15 @@ void initLog() { int main (int argc, char *argv[]){ - if(argc < 2){ - BOOST_LOG_TRIVIAL(error) << "Program usage: ./onlineDetectorSimulatorClient !"; + if(argc < 3){ + BOOST_LOG_TRIVIAL(error) << "Program usage: ./onlineDetectorSimulatorClient !"; return 0; } int imagesPerSec = std::stoi(argv[1]); + int packetSize = std::stoi(argv[2]); + double timegap = 1./(double)imagesPerSec; unsigned int intervall = timegap*1000*1000; @@ -36,7 +38,7 @@ int main (int argc, char *argv[]){ auto configPath = std::string { "config.cfg" }; std::string address = "127.0.0.1"; - Detector detector{address, configPath, intervall}; + Detector detector{address, configPath, intervall, packetSize}; //DetectorModule detModule0 = DetectorModule(1, address, configPath); -- cgit v1.2.1 From 9199713922540eabf475a76ff0bb8344a478391d Mon Sep 17 00:00:00 2001 From: Tobias Frust Date: Fri, 22 Jul 2016 08:15:26 +0200 Subject: corrected percentage calculation --- src/ReceiverThreads/ReceiverThreads.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ReceiverThreads/ReceiverThreads.cpp b/src/ReceiverThreads/ReceiverThreads.cpp index a99467a..3d22c66 100644 --- a/src/ReceiverThreads/ReceiverThreads.cpp +++ b/src/ReceiverThreads/ReceiverThreads.cpp @@ -44,6 +44,6 @@ auto ReceiverThreads::receiverThread(const int port) -> void { } lastIndex = index; } - BOOST_LOG_TRIVIAL(info) << "Lost " << loss_ << " from " << lastIndex << " packets; (" << loss_/(double)lastIndex << "%)"; + BOOST_LOG_TRIVIAL(info) << "Lost " << loss_ << " from " << lastIndex << " packets; (" << loss_/(double)lastIndex*100.0 << "%)"; } -- cgit v1.2.1 From 15075baf177290511eac810025048ccd346cf66e Mon Sep 17 00:00:00 2001 From: Tobias Frust Date: Wed, 12 Oct 2016 14:46:40 +0200 Subject: send configurable parts of the projection data --- src/DetectorModule/DetectorModule.cpp | 18 ++++++++++++------ src/DetectorModule/DetectorModule.h | 1 + src/main_client.cpp | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/DetectorModule/DetectorModule.cpp b/src/DetectorModule/DetectorModule.cpp index b222341..798c529 100644 --- a/src/DetectorModule/DetectorModule.cpp +++ b/src/DetectorModule/DetectorModule.cpp @@ -28,7 +28,7 @@ void timer_start(std::function func, unsigned int interval){ DetectorModule::DetectorModule(const int detectorID, const std::string& address, const std::string& configPath, const int packetSize) : detectorID_{detectorID}, numberOfDetectorsPerModule_{16}, - index_{1}, + index_{0u}, client_{address, detectorID+4000}, packetSize_{packetSize} { @@ -38,7 +38,7 @@ DetectorModule::DetectorModule(const int detectorID, const std::string& address, throw std::runtime_error("DetectorModule: Configuration file could not be loaded successfully. Please check!"); } - sendBuffer_.resize(packetSize); + sendBuffer_.resize(16010); //read the input data from the file corresponding to the detectorModuleID readInput(); @@ -49,6 +49,8 @@ DetectorModule::DetectorModule(const int detectorID, const std::string& address, auto DetectorModule::send() -> void{ BOOST_LOG_TRIVIAL(debug) << "Detectormodule " << detectorID_ << " :sending udp packet with index " << index_ << "."; + int numberOfProjectionsPerPacket = 500; + int numberOfParts = numberOfProjections_/numberOfProjectionsPerPacket; // sendBuffer_[0] = (sizeof(std::size_t)) & 0xff; // sendBuffer_[1] = (sizeof(std::size_t) >> 8) & 0xff; // sendBuffer_[2] = (sizeof(std::size_t) >> 16) & 0xff; @@ -58,11 +60,15 @@ auto DetectorModule::send() -> void{ // sendBuffer_[6] = (sizeof(std::size_t) >> 48) & 0xff; // sendBuffer_[7] = (sizeof(std::size_t) >> 56) & 0xff; unsigned int bufferSizeIndex = index_ % 1000; - unsigned int sinoSize = numberOfDetectorsPerModule_*numberOfProjections_; - *reinterpret_cast(sendBuffer_.data()) = index_; - //std::copy(((char*)buffer_.data())+sinoSize*bufferSizeIndex*sizeof(unsigned short), ((char*)buffer_.data())+(sinoSize*(1+bufferSizeIndex))*sizeof(unsigned short), sendBuffer_.begin()+sizeof(std::size_t)); + unsigned int sinoSize = numberOfDetectorsPerModule_*numberOfProjectionsPerPacket; + *reinterpret_cast(sendBuffer_.data()) = index_; + *reinterpret_cast(sendBuffer_.data()+sizeof(std::size_t)) = partID_; + std::copy(((char*)buffer_.data())+sinoSize*(bufferSizeIndex*numberOfParts+partID_)*sizeof(unsigned short), ((char*)buffer_.data())+(sinoSize*(1+bufferSizeIndex*numberOfParts+partID_))*sizeof(unsigned short), sendBuffer_.begin()+sizeof(std::size_t)+sizeof(unsigned short)); + BOOST_LOG_TRIVIAL(debug) << "INDEX: " << (bufferSizeIndex*numberOfParts+partID_); client_.send(sendBuffer_.data(), sendBuffer_.size()); - ++index_; + partID_ = (partID_+1) % numberOfParts; + if(partID_ == 0) + ++index_; } auto DetectorModule::sendPeriodically(unsigned int timeIntervall) -> void { diff --git a/src/DetectorModule/DetectorModule.h b/src/DetectorModule/DetectorModule.h index 5e540cb..a2d2fe9 100644 --- a/src/DetectorModule/DetectorModule.h +++ b/src/DetectorModule/DetectorModule.h @@ -42,6 +42,7 @@ private: std::string path_, fileName_, fileEnding_; std::size_t index_; + unsigned short partID_{0}; auto readConfig(const std::string& configFile) -> bool; auto readInput() -> void; diff --git a/src/main_client.cpp b/src/main_client.cpp index 19f366e..e97e911 100644 --- a/src/main_client.cpp +++ b/src/main_client.cpp @@ -36,7 +36,7 @@ int main (int argc, char *argv[]){ std::cout << "Sending UDP packages: " << std::endl; auto configPath = std::string { "config.cfg" }; - std::string address = "127.0.0.1"; + std::string address = "10.0.0.10"; Detector detector{address, configPath, intervall, packetSize}; -- cgit v1.2.1 From cdab7a0b05f655a2f98f00f3fb8928e54b8c28d2 Mon Sep 17 00:00:00 2001 From: Tobias Frust Date: Wed, 12 Oct 2016 14:53:28 +0200 Subject: added configuration options --- src/DetectorModule/DetectorModule.cpp | 11 ++++++----- src/DetectorModule/DetectorModule.h | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/DetectorModule/DetectorModule.cpp b/src/DetectorModule/DetectorModule.cpp index 798c529..8193a03 100644 --- a/src/DetectorModule/DetectorModule.cpp +++ b/src/DetectorModule/DetectorModule.cpp @@ -38,7 +38,7 @@ DetectorModule::DetectorModule(const int detectorID, const std::string& address, throw std::runtime_error("DetectorModule: Configuration file could not be loaded successfully. Please check!"); } - sendBuffer_.resize(16010); + sendBuffer_.resize(numberOfProjectionsPerPacket_*numberOfDetectorsPerModule_+sizeof(std::size_t)+sizeof(unsigned short)); //read the input data from the file corresponding to the detectorModuleID readInput(); @@ -49,8 +49,7 @@ DetectorModule::DetectorModule(const int detectorID, const std::string& address, auto DetectorModule::send() -> void{ BOOST_LOG_TRIVIAL(debug) << "Detectormodule " << detectorID_ << " :sending udp packet with index " << index_ << "."; - int numberOfProjectionsPerPacket = 500; - int numberOfParts = numberOfProjections_/numberOfProjectionsPerPacket; + int numberOfParts = numberOfProjections_/numberOfProjectionsPerPacket_; // sendBuffer_[0] = (sizeof(std::size_t)) & 0xff; // sendBuffer_[1] = (sizeof(std::size_t) >> 8) & 0xff; // sendBuffer_[2] = (sizeof(std::size_t) >> 16) & 0xff; @@ -60,7 +59,7 @@ auto DetectorModule::send() -> void{ // sendBuffer_[6] = (sizeof(std::size_t) >> 48) & 0xff; // sendBuffer_[7] = (sizeof(std::size_t) >> 56) & 0xff; unsigned int bufferSizeIndex = index_ % 1000; - unsigned int sinoSize = numberOfDetectorsPerModule_*numberOfProjectionsPerPacket; + unsigned int sinoSize = numberOfDetectorsPerModule_*numberOfProjectionsPerPacket_; *reinterpret_cast(sendBuffer_.data()) = index_; *reinterpret_cast(sendBuffer_.data()+sizeof(std::size_t)) = partID_; std::copy(((char*)buffer_.data())+sinoSize*(bufferSizeIndex*numberOfParts+partID_)*sizeof(unsigned short), ((char*)buffer_.data())+(sinoSize*(1+bufferSizeIndex*numberOfParts+partID_))*sizeof(unsigned short), sendBuffer_.begin()+sizeof(std::size_t)+sizeof(unsigned short)); @@ -108,7 +107,9 @@ auto DetectorModule::readConfig(const std::string& configFile) -> bool { && configReader.lookupValue("numberOfPlanes", numberOfPlanes_) && configReader.lookupValue("samplingRate", samplingRate) && configReader.lookupValue("scanRate", scanRate) - && configReader.lookupValue("numberOfDataFrames", numberOfFrames_)) { + && configReader.lookupValue("numberOfDataFrames", numberOfFrames_) + && configReader.lookupValue("numberOfProjectionsPerPacket", numberOfProjectionsPerPacket_) + && configReader.lookupValue("numberOfDetectorsPerModule", numberOfProjectionsPerPacket_)) { numberOfProjections_ = samplingRate * 1000000 / scanRate; return EXIT_SUCCESS; } diff --git a/src/DetectorModule/DetectorModule.h b/src/DetectorModule/DetectorModule.h index a2d2fe9..3ca5f23 100644 --- a/src/DetectorModule/DetectorModule.h +++ b/src/DetectorModule/DetectorModule.h @@ -38,6 +38,7 @@ private: int numberOfPlanes_; int numberOfProjections_; int numberOfDetectorsPerModule_; + int numberOfProjectionsPerPacket_; unsigned int numberOfFrames_; std::string path_, fileName_, fileEnding_; -- cgit v1.2.1