diff --git a/libs/whisper-com b/libs/whisper-com index 49bdb28..f7d57cc 160000 --- a/libs/whisper-com +++ b/libs/whisper-com @@ -1 +1 @@ -Subproject commit 49bdb28535a4ef5e9e35a04fdc898d93d1f8af13 +Subproject commit f7d57ccbb8230f5b6039a6c9b3566ae8ebd77c4b diff --git a/src/SimCore/Sensor.cpp b/src/SimCore/Sensor.cpp index b8196c6..1438e23 100644 --- a/src/SimCore/Sensor.cpp +++ b/src/SimCore/Sensor.cpp @@ -26,32 +26,30 @@ namespace SimCore { GroundTruthUDPService_ = std::make_shared(OwnID.getNumber(),WHISPER::SENSOR,8000,SimCore::UtilFunctions::implode(ip,'.'),ownIP); ParentUDPService_ = std::make_shared(OwnID.getNumber(),WHISPER::SENSOR,ParentPort,ParentIPAddress_,ownIP); - ReloadCharacteristicts(); }; Sensor::~Sensor(){ + // this->stop(); + if (ReceivingGroundThruthIsRunnung && sendCalculatedDataIsRunnung && CalculationIsRunnung) { this->stop(); - - while (!this->incommingGroundThruthMessages.unique()) { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); } + + this->incommingGroundThruthMessages.reset(); - while (!this->outgoingGroundThruthMessages.unique()) { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } + this->outgoingGroundThruthMessages.reset(); - GroundTruthUDPService_->disconnect(); + // GroundTruthUDPService_->disconnect(); while (!this->GroundTruthUDPService_.unique()) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); } this->GroundTruthUDPService_.reset(); - + LOG_S(INFO)<<"groundThruth is closed"; ParentUDPService_->disconnect(); while (!this->ParentUDPService_.unique()) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); @@ -59,19 +57,22 @@ namespace SimCore { this->ParentUDPService_.reset(); - + LOG_S(INFO)<<"all destructed"; } void Sensor::start(){ + ReloadCharacteristicts(); + + stopReceivingGroundThruth = false; receiveGroundTruthThread = std::thread(&Sensor::receivingData,this); - // stopsendCalculatedData = false; - // sendCalculatedDataThread = std::thread(&Sensor::sendingData,this); + stopsendCalculatedData = false; + sendCalculatedDataThread = std::thread(&Sensor::sendingData,this); - // stopCalculationData = false; - // sensorCalculationThread = std::thread(&Sensor::SensorCalculations,this); + stopCalculationData = false; + sensorCalculationThread = std::thread(&Sensor::SensorCalculations,this); } void Sensor::stop() { @@ -79,7 +80,7 @@ namespace SimCore { while (ReceivingGroundThruthIsRunnung == true ) { stopReceivingGroundThruth = true; - LOG_S(INFO)<<"waiting for receiving thread thread"; + LOG_S(INFO)<<"waiting for groundthruth thread thread"; if (receiveGroundTruthThread.joinable() == true ) { receiveGroundTruthThread.join(); } @@ -87,7 +88,7 @@ namespace SimCore { while (sendCalculatedDataIsRunnung == true ) { stopsendCalculatedData = true; - LOG_S(INFO)<<"waiting for receiving thread thread"; + LOG_S(INFO)<<"waiting for parent sending thread thread"; if (sendCalculatedDataThread.joinable() == true ) { sendCalculatedDataThread.join(); } @@ -95,11 +96,13 @@ namespace SimCore { while (CalculationIsRunnung == true ) { stopCalculationData = true; - LOG_S(INFO)<<"waiting for receiving thread thread"; - if (sensorCalculationThread.joinable() == true ) { + LOG_S(INFO)<<"waiting for calculation thread thread"; + if (sensorCalculationThread.joinable() == true ) { + sensorCalculationThread.join(); - } + } } + LOG_S(INFO)<<"all stopped"; } @@ -107,27 +110,27 @@ namespace SimCore { void Sensor::receivingData() { this->ReceivingGroundThruthIsRunnung = true; - // GroundTruthUDPService_->connect(incommingGroundThruthMessages); - // GroundTruthUDPService_->subscribe(WHISPER::MsgTopicsMap[WHISPER::MsgTopics::TRACK]); + GroundTruthUDPService_->connect(incommingGroundThruthMessages); + GroundTruthUDPService_->subscribe(WHISPER::MsgTopicsMap[WHISPER::MsgTopics::TRACK]); - // while (stopReceivingGroundThruth == false) { - // if (incommingGroundThruthMessages->size() > 0) { - // WHISPER::Message msg; - // incommingGroundThruthMessages->get(msg); - // if (msg.msgType_ == WHISPER::MsgType::RAW_TRACK) { - // auto Track = SimCore::Track(msg.serialize()); - // incommingTrackMessages->addElement(Track); - // } - // } + while (stopReceivingGroundThruth == false) { + if (incommingGroundThruthMessages->size() > 0) { + WHISPER::Message msg; + incommingGroundThruthMessages->get(msg); + if (msg.msgType_ == WHISPER::MsgType::RAW_TRACK) { + auto Track = SimCore::Track(msg.serialize()); + incommingTrackMessages->addElement(Track); + } + } - // if (outgoingGroundThruthMessages->size() > 0) { - // WHISPER::Message msg; - // outgoingGroundThruthMessages->get(msg); - // GroundTruthUDPService_->publish(msg.serialize(), WHISPER::MsgTopicsMap[(WHISPER::MsgTopics)msg.topic_]); - // } + if (outgoingGroundThruthMessages->size() > 0) { + WHISPER::Message msg; + outgoingGroundThruthMessages->get(msg); + GroundTruthUDPService_->publish(msg.serialize(), WHISPER::MsgTopicsMap[(WHISPER::MsgTopics)msg.topic_]); + } - // } - // GroundTruthUDPService_->disconnect(); + } + GroundTruthUDPService_->disconnect(); this->ReceivingGroundThruthIsRunnung = false; } @@ -165,16 +168,18 @@ namespace SimCore { while (!stopCalculationData) { specificSensorCalculations(); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + } + LOG_S(INFO)<<"calculation is stopt"; CalculationIsRunnung = false; } void Sensor::ReloadCharacteristicts() { - LOG_S(INFO)<<"loading specs"; - // specificReloadCharacteristicts(); + specificReloadCharacteristicts(); }