FIX: fixed closing issue

This commit is contained in:
Henry Winkel
2023-01-18 14:37:01 +01:00
parent 193336e7fb
commit 3bc56734da
2 changed files with 45 additions and 40 deletions

View File

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