diff --git a/include/Entities/SensorManager.hpp b/include/Entities/SensorManager.hpp index ae9e94a..5064098 100644 --- a/include/Entities/SensorManager.hpp +++ b/include/Entities/SensorManager.hpp @@ -23,9 +23,12 @@ namespace Entities { public: - SensorManager(SimCore::Identifier OwnID,std::shared_ptr PodController, ushort sensorPort = 5557); - - + SensorManager(std::shared_ptr OwnShipTrack,std::shared_ptr PodController, ushort sensorPort = 5557); + + /** + * @brief stops the sensor manager + */ + void stop(); /** *@brief starts a Sensor based on a KubePod Object *@param KubePod - a KubePod Item ready to start @@ -116,10 +119,16 @@ namespace Entities */ std::unique_ptr getTrackListUpdate(); + /** + * @brief send the ownShipTrack to all connected Sensors + */ + void sendOwnShipTrackToSensors(); + private: const SimCore::Identifier OwnId_; + std::shared_ptr OwnShiptrack_; ushort SensorPort_ = 5557; std::map> SensorStore; @@ -128,6 +137,9 @@ namespace Entities TrackList::Trackfusion Trackfusion_; + std::thread sensorUpdater_; + std::atomic_bool stopUpdater_; + std::shared_ptr SensorServer_ = nullptr; diff --git a/libs/KubeControl b/libs/KubeControl index 7bc5e3f..a413b41 160000 --- a/libs/KubeControl +++ b/libs/KubeControl @@ -1 +1 @@ -Subproject commit 7bc5e3f22e092c7eeb58e389aa7f399da81329bc +Subproject commit a413b412df277e5e8a9cf4e3109c48b6e9379255 diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 6394af2..4a7db40 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -61,11 +61,12 @@ namespace Entities { PodController_ = std::make_shared("docs/config"); - SensorManager_ = std::make_unique(OwnID, PodController_,SensorPort_); OwnShipTrack = std::make_shared(OwnID, EnttityName, EntityKind,EntitySide); OwnShipTrack->setPosition(SimCore::Position()); OwnShipTrack->RCS.setValue(RCS_); + SensorManager_ = std::make_unique(OwnShipTrack, PodController_,SensorPort_); + MovemtServer_ = std::make_shared(__MOVEMENT_SERVER_PORT__,OwnID.getUUID()); CommandCommsServer_ = std::make_shared(CommandPort,OwnID.getUUID()); @@ -154,7 +155,8 @@ namespace Entities LOG_S(INFO)<<"Pods stoppt"; stopChild(); LOG_S(INFO)<<"childs stoppt"; - + + SensorManager_->stop(); for (std::vector::iterator it = threads.begin(); it != threads.end();) @@ -296,12 +298,12 @@ namespace Entities auto TrackListRequest = Orders::TracklistRequest::unpack(whisperMsg); if (TrackListRequest == nullptr) { - break; + break; } if (TrackListRequest->EntityID == OwnShipTrack->getIdentifier()) { std::string senderUUID = whisperMsg.senderUUID_; - CommandCommsServer_->sendMessage(SensorManager_->getTrackListUpdate()->buildMessage().serialize(OwnShipTrack->getIdentifier().getUUID()),senderUUID); + CommandCommsServer_->sendMessage(SensorManager_->getTrackListUpdate()->buildMessage(),senderUUID); } break; } diff --git a/src/Entities/SensorManager.cpp b/src/Entities/SensorManager.cpp index 9e19db7..f9c33a9 100644 --- a/src/Entities/SensorManager.cpp +++ b/src/Entities/SensorManager.cpp @@ -12,13 +12,27 @@ namespace Entities { - SensorManager::SensorManager(SimCore::Identifier OwnID,std::shared_ptr PodController,ushort sensorPort): - OwnId_(OwnID),PodController_(PodController) + SensorManager::SensorManager(std::shared_ptr OwnShipTrack,std::shared_ptr PodController,ushort sensorPort): + OwnId_(OwnShipTrack->getIdentifier()),OwnShiptrack_(OwnShipTrack),PodController_(PodController) { - SensorServer_ = std::make_shared(SensorPort_,OwnID.getUUID()); + SensorServer_ = std::make_shared(SensorPort_,OwnId_.getUUID()); SensorServer_->registerMessageCallback(std::bind(&SensorManager::handlSensorMessages,this,std::placeholders::_1)); + stopUpdater_ = false; + sensorUpdater_ = std::thread(&SensorManager::sendOwnShipTrackToSensors,this); } + void SensorManager::stop() + { + for(auto sensor: SensorStore) + { + PodController_->stopPod(sensor.first); + } + SensorStore.clear(); + stopUpdater_ = true; + sensorUpdater_.join(); + } + + void SensorManager::startSensor(std::shared_ptr pod,SimCore::SensorKinds SensorKind) { PodController_->startPod(pod); @@ -120,7 +134,7 @@ namespace Entities { return; } - sensor->TrackStore.addTrack(std::move(track)); + sensor->TrackStore.addTrack(track); // auto it = SensorStore.find(uuidSensor); // if( it != SensorStore.end()) // { @@ -237,6 +251,23 @@ namespace Entities } + void SensorManager::sendOwnShipTrackToSensors() + { + while(stopUpdater_ == false) + { + if(SensorServer_->countClients() > 0) + { + SensorServer_->sendMessage(this->OwnShiptrack_->buildMessage()); + } + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + + } + + + } + + + diff --git a/src/Entities/Tracklist/Trackfusion.cpp b/src/Entities/Tracklist/Trackfusion.cpp index d4c1232..cadadc2 100644 --- a/src/Entities/Tracklist/Trackfusion.cpp +++ b/src/Entities/Tracklist/Trackfusion.cpp @@ -116,7 +116,7 @@ namespace TrackList for (auto it :TrackStore_) { - // update->addTrack(*it.second); + update->addTrack(*it.second); }