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