From 16e83c0afcec0cea8af82189d4e98cd232bdf154 Mon Sep 17 00:00:00 2001 From: Tobias Frust Date: Wed, 29 Jun 2016 14:49:55 +0200 Subject: created project structure --- src/DetectorModule/DetectorModule.cpp | 0 src/DetectorModule/DetectorModule.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/DetectorModule/DetectorModule.cpp create mode 100644 src/DetectorModule/DetectorModule.h (limited to 'src/DetectorModule') diff --git a/src/DetectorModule/DetectorModule.cpp b/src/DetectorModule/DetectorModule.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/DetectorModule/DetectorModule.h b/src/DetectorModule/DetectorModule.h new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From 5ecc4dde3731724f28d4629f8a563f30bb260617 Mon Sep 17 00:00:00 2001 From: Tobias Frust Date: Wed, 29 Jun 2016 15:22:50 +0200 Subject: added udpClient, which will later send out the packages --- src/DetectorModule/DetectorModule.cpp | 9 +++++++++ src/DetectorModule/DetectorModule.h | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) (limited to 'src/DetectorModule') diff --git a/src/DetectorModule/DetectorModule.cpp b/src/DetectorModule/DetectorModule.cpp index e69de29..ac9ee27 100644 --- a/src/DetectorModule/DetectorModule.cpp +++ b/src/DetectorModule/DetectorModule.cpp @@ -0,0 +1,9 @@ +/* + * Copyright 2016 Tobias Frust + * + * DetectorModule.cpp + * + * Created on: 29.06.2016 + * Author: Tobias Frust + */ + diff --git a/src/DetectorModule/DetectorModule.h b/src/DetectorModule/DetectorModule.h index e69de29..aa63d82 100644 --- a/src/DetectorModule/DetectorModule.h +++ b/src/DetectorModule/DetectorModule.h @@ -0,0 +1,24 @@ +/* + * Copyright 2016 Tobias Frust + * + * DetectorModule.h + * + * Created on: 29.06.2016 + * Author: Tobias Frust + */ + +#ifndef DETECTORMODULE_H_ +#define DETECTORMODULE_H_ + +#include + +template +class DetectorModule { +public: + DetectorModule(); + +private: + std::vector> buffer_; +}; + +#endif -- cgit v1.2.3 From 5680aa99001cb50c707c4187cd8ada0c41a573dd Mon Sep 17 00:00:00 2001 From: Tobias Frust Date: Thu, 30 Jun 2016 10:13:01 +0200 Subject: implemented virtual DetectorModule with simple send via udp --- src/DetectorModule/DetectorModule.cpp | 60 +++++++++++++++++++++++++++++++++++ src/DetectorModule/DetectorModule.h | 39 +++++++++++++++++++++-- 2 files changed, 97 insertions(+), 2 deletions(-) (limited to 'src/DetectorModule') diff --git a/src/DetectorModule/DetectorModule.cpp b/src/DetectorModule/DetectorModule.cpp index ac9ee27..f0c1a06 100644 --- a/src/DetectorModule/DetectorModule.cpp +++ b/src/DetectorModule/DetectorModule.cpp @@ -7,3 +7,63 @@ * Author: Tobias Frust */ +#include "DetectorModule.h" +#include "../ConfigReader/ConfigReader.h" + +#include +#include + +template +DetectorModule::DetectorModule(const int detectorID, const std::string& address, const std::string& configPath) : + detectorID_{detectorID}, + numberOfDetectorsPerModule_{16}, + index_{0}, + client_{address, detectorID + 4000} { + + if (readConfig(configPath)) { + throw std::runtime_error("DetectorModule: Configuration file could not be loaded successfully. Please check!"); + } + + //read the input data from the file corresponding to the detectorModuleID + readInput(); +} + +template +auto DetectorModule::sendPeriodically(unsigned int timeIntervall) -> void { + client_.send(buffer_.data(), sizeof(T)*numberOfDetectorsPerModule_*numberOfProjections_); +} + +template +auto DetectorModule::readInput() -> void { + if(path_.back() != '/') + path_.append("/"); + //open file + std::ifstream input(path_ + fileName_ + std::to_string(detectorID_) + fileEnding_, std::ios::in | std::ios::binary); + //allocate memory in vector + std::streampos fileSize; + input.seekg(0, std::ios::end); + fileSize = input.tellg(); + input.seekg(0, std::ios::beg); + buffer_.resize(fileSize / sizeof(T)); + input.read((char*) &buffer_[0], fileSize); +} + +template +auto DetectorModule::readConfig(const std::string& configFile) -> bool { + ConfigReader configReader = ConfigReader(configFile.data()); + int samplingRate, scanRate; + if (configReader.lookupValue("numberOfFanDetectors", numberOfDetectors_) + && configReader.lookupValue("dataInputPath", path_) + && configReader.lookupValue("dataFileName", fileName_) + && configReader.lookupValue("dataFileEnding", fileEnding_) + && configReader.lookupValue("numberOfPlanes", numberOfPlanes_) + && configReader.lookupValue("samplingRate", samplingRate) + && configReader.lookupValue("scanRate", scanRate) + && configReader.lookupValue("numberOfDataFrames", numberOfFrames_)) { + numberOfProjections_ = samplingRate * 1000000 / scanRate; + return EXIT_SUCCESS; + } + + return EXIT_FAILURE; + } + diff --git a/src/DetectorModule/DetectorModule.h b/src/DetectorModule/DetectorModule.h index aa63d82..de259fa 100644 --- a/src/DetectorModule/DetectorModule.h +++ b/src/DetectorModule/DetectorModule.h @@ -10,15 +10,50 @@ #ifndef DETECTORMODULE_H_ #define DETECTORMODULE_H_ +#include "../UDPClient/UDPClient.h" + #include +#include +#include +#include +#include + +void timer_start(std::function func, unsigned int interval){ + std::thread([func, interval]() { + while (true) + { + func(); + std::this_thread::sleep_for(std::chrono::milliseconds(interval)); + } + }).detach(); +} + template class DetectorModule { public: - DetectorModule(); + DetectorModule(const int detectorID, const std::string& address, const std::string& configPath); + + auto sendPeriodically(unsigned int timeIntervall) -> void; private: - std::vector> buffer_; + std::vector buffer_; + + int detectorID_; + UDPClient client_; + + int numberOfDetectors_; + int numberOfPlanes_; + int numberOfProjections_; + int numberOfDetectorsPerModule_; + std::size_t numberOfFrames_; + std::string path_, fileName_, fileEnding_; + + std::size_t index_; + + auto readConfig(const std::string& configFile) -> bool; + auto readInput() -> void; + }; #endif -- cgit v1.2.3 From dbf28e725f062744222559257abe64d8a39a9d50 Mon Sep 17 00:00:00 2001 From: Tobias Frust Date: Thu, 30 Jun 2016 10:27:20 +0200 Subject: bug fixes --- src/DetectorModule/DetectorModule.cpp | 16 ++++++---------- src/DetectorModule/DetectorModule.h | 25 ++++++++++++------------- 2 files changed, 18 insertions(+), 23 deletions(-) (limited to 'src/DetectorModule') diff --git a/src/DetectorModule/DetectorModule.cpp b/src/DetectorModule/DetectorModule.cpp index f0c1a06..d2c8298 100644 --- a/src/DetectorModule/DetectorModule.cpp +++ b/src/DetectorModule/DetectorModule.cpp @@ -13,8 +13,7 @@ #include #include -template -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) : detectorID_{detectorID}, numberOfDetectorsPerModule_{16}, index_{0}, @@ -28,13 +27,11 @@ DetectorModule::DetectorModule(const int detectorID, const std::string& addre readInput(); } -template -auto DetectorModule::sendPeriodically(unsigned int timeIntervall) -> void { - client_.send(buffer_.data(), sizeof(T)*numberOfDetectorsPerModule_*numberOfProjections_); +auto DetectorModule::sendPeriodically(unsigned int timeIntervall) -> void { + client_.send((char*)buffer_.data(), sizeof(unsigned short)*numberOfDetectorsPerModule_*numberOfProjections_); } -template -auto DetectorModule::readInput() -> void { +auto DetectorModule::readInput() -> void { if(path_.back() != '/') path_.append("/"); //open file @@ -44,12 +41,11 @@ auto DetectorModule::readInput() -> void { input.seekg(0, std::ios::end); fileSize = input.tellg(); input.seekg(0, std::ios::beg); - buffer_.resize(fileSize / sizeof(T)); + buffer_.resize(fileSize / sizeof(unsigned short)); input.read((char*) &buffer_[0], fileSize); } -template -auto DetectorModule::readConfig(const std::string& configFile) -> bool { +auto DetectorModule::readConfig(const std::string& configFile) -> bool { ConfigReader configReader = ConfigReader(configFile.data()); int samplingRate, scanRate; if (configReader.lookupValue("numberOfFanDetectors", numberOfDetectors_) diff --git a/src/DetectorModule/DetectorModule.h b/src/DetectorModule/DetectorModule.h index de259fa..a1c2754 100644 --- a/src/DetectorModule/DetectorModule.h +++ b/src/DetectorModule/DetectorModule.h @@ -19,17 +19,16 @@ #include #include -void timer_start(std::function func, unsigned int interval){ - std::thread([func, interval]() { - while (true) - { - func(); - std::this_thread::sleep_for(std::chrono::milliseconds(interval)); - } - }).detach(); -} - -template +//void timer_start(std::function func, unsigned int interval){ +// std::thread([func, interval]() { +// while (true) +// { +// func(); +// std::this_thread::sleep_for(std::chrono::milliseconds(interval)); +// } +// }).detach(); +//} + class DetectorModule { public: DetectorModule(const int detectorID, const std::string& address, const std::string& configPath); @@ -37,7 +36,7 @@ public: auto sendPeriodically(unsigned int timeIntervall) -> void; private: - std::vector buffer_; + std::vector buffer_; int detectorID_; UDPClient client_; @@ -46,7 +45,7 @@ private: int numberOfPlanes_; int numberOfProjections_; int numberOfDetectorsPerModule_; - std::size_t numberOfFrames_; + unsigned long long numberOfFrames_; std::string path_, fileName_, fileEnding_; std::size_t index_; -- cgit v1.2.3 From 0c33319451deec9b5461b57856423bc619817245 Mon Sep 17 00:00:00 2001 From: Tobias Frust Date: Thu, 30 Jun 2016 15:22:07 +0200 Subject: added classes for detector; Sending out in n different streams with n different ports --- src/DetectorModule/DetectorModule.cpp | 62 +++++++++++++++++++++++++++++------ src/DetectorModule/DetectorModule.h | 14 ++------ 2 files changed, 55 insertions(+), 21 deletions(-) (limited to 'src/DetectorModule') diff --git a/src/DetectorModule/DetectorModule.cpp b/src/DetectorModule/DetectorModule.cpp index d2c8298..789ac0e 100644 --- a/src/DetectorModule/DetectorModule.cpp +++ b/src/DetectorModule/DetectorModule.cpp @@ -10,39 +10,81 @@ #include "DetectorModule.h" #include "../ConfigReader/ConfigReader.h" +#include + #include #include +void timer_start(std::function func, unsigned int interval){ + std::thread([func, interval]() { + while (true) + { + func(); + std::this_thread::sleep_for(std::chrono::microseconds(interval)); + } + }).detach(); +} + DetectorModule::DetectorModule(const int detectorID, const std::string& address, const std::string& configPath) : detectorID_{detectorID}, numberOfDetectorsPerModule_{16}, index_{0}, - client_{address, detectorID + 4000} { + client_{address, detectorID+4000} { + + printf("Creating %d\n", detectorID); if (readConfig(configPath)) { 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)); + //read the input data from the file corresponding to the detectorModuleID readInput(); + printf("Created %d\n", detectorID); +} + +auto DetectorModule::send() -> void{ + BOOST_LOG_TRIVIAL(debug) << "Detectormodule " << detectorID_ << " :sending udp packet with index " << index_ << "."; +// sendBuffer_[0] = (sizeof(std::size_t)) & 0xff; +// sendBuffer_[1] = (sizeof(std::size_t) >> 8) & 0xff; +// sendBuffer_[2] = (sizeof(std::size_t) >> 16) & 0xff; +// sendBuffer_[3] = (sizeof(std::size_t) >> 24) & 0xff; +// sendBuffer_[4] = (sizeof(std::size_t) >> 32) & 0xff; +// sendBuffer_[5] = (sizeof(std::size_t) >> 40) & 0xff; +// sendBuffer_[6] = (sizeof(std::size_t) >> 48) & 0xff; +// sendBuffer_[7] = (sizeof(std::size_t) >> 56) & 0xff; + *reinterpret_cast(sendBuffer_.data()) = index_; + std::copy(buffer_.cbegin(), buffer_.cbegin()+numberOfDetectorsPerModule_*numberOfProjections_, sendBuffer_.begin()+sizeof(std::size_t)); + client_.send(sendBuffer_.data(), sizeof(unsigned short)*numberOfDetectorsPerModule_*numberOfProjections_+sizeof(std::size_t)); + ++index_; } auto DetectorModule::sendPeriodically(unsigned int timeIntervall) -> void { - client_.send((char*)buffer_.data(), sizeof(unsigned short)*numberOfDetectorsPerModule_*numberOfProjections_); + std::function f = [=]() { + this->send(); + }; + timer_start(f, timeIntervall); } auto DetectorModule::readInput() -> void { if(path_.back() != '/') path_.append("/"); //open file - std::ifstream input(path_ + fileName_ + std::to_string(detectorID_) + fileEnding_, std::ios::in | std::ios::binary); - //allocate memory in vector - std::streampos fileSize; - input.seekg(0, std::ios::end); - fileSize = input.tellg(); - input.seekg(0, std::ios::beg); - buffer_.resize(fileSize / sizeof(unsigned short)); - input.read((char*) &buffer_[0], fileSize); + const std::string filePath = path_ + fileName_ + std::to_string(detectorID_) + fileEnding_; + BOOST_LOG_TRIVIAL(debug) << "DetectorModule: Path = " << filePath; + std::ifstream input(filePath, std::ios::in | std::ios::binary); + if(input){ + //allocate memory in vector + std::streampos fileSize; + input.seekg(0, std::ios::end); + fileSize = input.tellg(); + input.seekg(0, std::ios::beg); + buffer_.resize(fileSize / sizeof(unsigned short)); + input.read((char*) &buffer_[0], fileSize); + }else{ + throw std::runtime_error("File not found."); + } } auto DetectorModule::readConfig(const std::string& configFile) -> bool { diff --git a/src/DetectorModule/DetectorModule.h b/src/DetectorModule/DetectorModule.h index a1c2754..1bc36bb 100644 --- a/src/DetectorModule/DetectorModule.h +++ b/src/DetectorModule/DetectorModule.h @@ -19,16 +19,6 @@ #include #include -//void timer_start(std::function func, unsigned int interval){ -// std::thread([func, interval]() { -// while (true) -// { -// func(); -// std::this_thread::sleep_for(std::chrono::milliseconds(interval)); -// } -// }).detach(); -//} - class DetectorModule { public: DetectorModule(const int detectorID, const std::string& address, const std::string& configPath); @@ -37,6 +27,7 @@ public: private: std::vector buffer_; + std::vector sendBuffer_; int detectorID_; UDPClient client_; @@ -45,13 +36,14 @@ private: int numberOfPlanes_; int numberOfProjections_; int numberOfDetectorsPerModule_; - unsigned long long numberOfFrames_; + unsigned int numberOfFrames_; std::string path_, fileName_, fileEnding_; std::size_t index_; auto readConfig(const std::string& configFile) -> bool; auto readInput() -> void; + auto send() -> void; }; -- cgit v1.2.3 From d71e5fe7330fa51cdce466ec0df876eb9b8e721e Mon Sep 17 00:00:00 2001 From: Tobias Frust Date: Mon, 11 Jul 2016 14:58:00 +0200 Subject: UDP packets are sent out correctly --- src/DetectorModule/DetectorModule.cpp | 36 ++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'src/DetectorModule') diff --git a/src/DetectorModule/DetectorModule.cpp b/src/DetectorModule/DetectorModule.cpp index 789ac0e..bee50e9 100644 --- a/src/DetectorModule/DetectorModule.cpp +++ b/src/DetectorModule/DetectorModule.cpp @@ -54,8 +54,10 @@ auto DetectorModule::send() -> void{ // sendBuffer_[5] = (sizeof(std::size_t) >> 40) & 0xff; // 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(buffer_.cbegin(), buffer_.cbegin()+numberOfDetectorsPerModule_*numberOfProjections_, sendBuffer_.begin()+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)*numberOfDetectorsPerModule_*numberOfProjections_+sizeof(std::size_t)); ++index_; } @@ -71,7 +73,7 @@ auto DetectorModule::readInput() -> void { if(path_.back() != '/') path_.append("/"); //open file - const std::string filePath = path_ + fileName_ + std::to_string(detectorID_) + fileEnding_; + const std::string filePath = path_ + fileName_ + std::to_string(detectorID_+1) + fileEnding_; BOOST_LOG_TRIVIAL(debug) << "DetectorModule: Path = " << filePath; std::ifstream input(filePath, std::ios::in | std::ios::binary); if(input){ @@ -88,20 +90,20 @@ auto DetectorModule::readInput() -> void { } auto DetectorModule::readConfig(const std::string& configFile) -> bool { - ConfigReader configReader = ConfigReader(configFile.data()); - int samplingRate, scanRate; - if (configReader.lookupValue("numberOfFanDetectors", numberOfDetectors_) - && configReader.lookupValue("dataInputPath", path_) - && configReader.lookupValue("dataFileName", fileName_) - && configReader.lookupValue("dataFileEnding", fileEnding_) - && configReader.lookupValue("numberOfPlanes", numberOfPlanes_) - && configReader.lookupValue("samplingRate", samplingRate) - && configReader.lookupValue("scanRate", scanRate) - && configReader.lookupValue("numberOfDataFrames", numberOfFrames_)) { - numberOfProjections_ = samplingRate * 1000000 / scanRate; - return EXIT_SUCCESS; - } - - return EXIT_FAILURE; + ConfigReader configReader = ConfigReader(configFile.data()); + int samplingRate, scanRate; + if (configReader.lookupValue("numberOfFanDetectors", numberOfDetectors_) + && configReader.lookupValue("dataInputPath", path_) + && configReader.lookupValue("dataFileName", fileName_) + && configReader.lookupValue("dataFileEnding", fileEnding_) + && configReader.lookupValue("numberOfPlanes", numberOfPlanes_) + && configReader.lookupValue("samplingRate", samplingRate) + && configReader.lookupValue("scanRate", scanRate) + && configReader.lookupValue("numberOfDataFrames", numberOfFrames_)) { + numberOfProjections_ = samplingRate * 1000000 / scanRate; + return EXIT_SUCCESS; } + return EXIT_FAILURE; +} + -- cgit v1.2.3