summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTobias Frust <tobiasfrust@gmail.com>2016-07-11 14:58:00 +0200
committerTobias Frust <tobiasfrust@gmail.com>2016-07-11 14:58:00 +0200
commitd71e5fe7330fa51cdce466ec0df876eb9b8e721e (patch)
tree35642a156031e14aae504ecee46dea74558597a4 /src
parent0c33319451deec9b5461b57856423bc619817245 (diff)
downloadods-d71e5fe7330fa51cdce466ec0df876eb9b8e721e.tar.gz
ods-d71e5fe7330fa51cdce466ec0df876eb9b8e721e.tar.bz2
ods-d71e5fe7330fa51cdce466ec0df876eb9b8e721e.tar.xz
ods-d71e5fe7330fa51cdce466ec0df876eb9b8e721e.zip
UDP packets are sent out correctly
Diffstat (limited to 'src')
-rw-r--r--src/Detector/Detector.cpp2
-rw-r--r--src/DetectorModule/DetectorModule.cpp36
-rw-r--r--src/main_client.cpp4
-rw-r--r--src/main_server.cpp6
4 files changed, 28 insertions, 20 deletions
diff --git a/src/Detector/Detector.cpp b/src/Detector/Detector.cpp
index 658f485..5dde6d1 100644
--- a/src/Detector/Detector.cpp
+++ b/src/Detector/Detector.cpp
@@ -14,7 +14,7 @@ Detector::Detector(const std::string& address, const std::string& configPath, co
timeIntervall_{timeIntervall},
numberOfDetectorModules_{27} {
modules_.reserve(numberOfDetectorModules_);
- for(auto i = 1; i <= numberOfDetectorModules_; i++){
+ for(auto i = 0; i < numberOfDetectorModules_; i++){
modules_.emplace_back(i, address, configPath);
}
}
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<int*>(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;
+}
+
diff --git a/src/main_client.cpp b/src/main_client.cpp
index ed7d285..b88341a 100644
--- a/src/main_client.cpp
+++ b/src/main_client.cpp
@@ -24,9 +24,9 @@ int main (int argc, char *argv[]){
std::cout << "Sending UDP packages: " << std::endl;
auto configPath = std::string { "config.cfg" };
- std::string address = "localhost";
+ std::string address = "127.0.0.1";
- Detector detector{address, configPath, 1000u};
+ Detector detector{address, configPath, 1000000u};
//DetectorModule detModule0 = DetectorModule(1, address, configPath);
diff --git a/src/main_server.cpp b/src/main_server.cpp
index a645f49..6e936e4 100644
--- a/src/main_server.cpp
+++ b/src/main_server.cpp
@@ -35,6 +35,7 @@ int main (int argc, char *argv[]){
UDPServer server = UDPServer(address, port);
std::size_t length{32768};
+ std::size_t lastIndex{0};
std::vector<unsigned short> buf(16000);
@@ -52,6 +53,11 @@ int main (int argc, char *argv[]){
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;
}