diff options
author | Tobias Frust <tobiasfrust@gmail.com> | 2016-06-30 10:13:01 +0200 |
---|---|---|
committer | Tobias Frust <tobiasfrust@gmail.com> | 2016-06-30 10:13:01 +0200 |
commit | 5680aa99001cb50c707c4187cd8ada0c41a573dd (patch) | |
tree | fcbe575cd20e35dbe3d2b7def5e7c801d576aaf8 /src/DetectorModule | |
parent | 1dc95b4eed7974549ef43a87e0777aa343b30fd4 (diff) | |
download | ods-5680aa99001cb50c707c4187cd8ada0c41a573dd.tar.gz ods-5680aa99001cb50c707c4187cd8ada0c41a573dd.tar.bz2 ods-5680aa99001cb50c707c4187cd8ada0c41a573dd.tar.xz ods-5680aa99001cb50c707c4187cd8ada0c41a573dd.zip |
implemented virtual DetectorModule with simple send via udp
Diffstat (limited to 'src/DetectorModule')
-rw-r--r-- | src/DetectorModule/DetectorModule.cpp | 60 | ||||
-rw-r--r-- | src/DetectorModule/DetectorModule.h | 39 |
2 files changed, 97 insertions, 2 deletions
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 <exception> +#include <fstream> + +template<typename T> +DetectorModule<T>::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 <typename T> +auto DetectorModule<T>::sendPeriodically(unsigned int timeIntervall) -> void { + client_.send(buffer_.data(), sizeof(T)*numberOfDetectorsPerModule_*numberOfProjections_); +} + +template <typename T> +auto DetectorModule<T>::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<typename T> +auto DetectorModule<T>::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 <vector> +#include <iostream> +#include <chrono> +#include <thread> +#include <functional> + +void timer_start(std::function<void(void)> func, unsigned int interval){ + std::thread([func, interval]() { + while (true) + { + func(); + std::this_thread::sleep_for(std::chrono::milliseconds(interval)); + } + }).detach(); +} + template <typename T> 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<std::vector<T>> buffer_; + std::vector<T> 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 |