diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d9e8ee..1035134 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,14 @@ add_library(EntityLibrary STATIC include/Entities/Tracklist/TracklistItem.hpp src/Entities/Tracklist/TrackListItem.cpp + + + include/Entities/SensorManager.hpp + src/Entities/SensorManager.cpp + + include/Entities/SensorControl.hpp + src/Entities/SensorControl.cpp + ) diff --git a/include/Entities/Entity.hpp b/include/Entities/Entity.hpp index ae6afdd..99beb0e 100644 --- a/include/Entities/Entity.hpp +++ b/include/Entities/Entity.hpp @@ -4,6 +4,7 @@ #include "DirectCommunicationServer.hpp" #include "Entities/Movement.hpp" +#include "Entities/SensorManager.hpp" #include "SimCore/Messages/SimTrack.hpp" #include "SimCore/Orientation.hpp" #include "SimCore/SafeMap.hpp" @@ -59,6 +60,7 @@ namespace Entities { std::string GroundTruthAddr, std::uint32_t GroundTruthPort, ushort CommandPort, + ushort SensorPort, bool online); ~Entity(); @@ -89,11 +91,12 @@ namespace Entities { SimCore::Side::EntitySide EntitySide_; double RCS_; - ushort MovemntWorkerPort_; + ushort SensorPort_; - std::unique_ptr PodController_; + std::shared_ptr PodController_; + std::unique_ptr SensorManager_; std::shared_ptr BroadcastServer_; @@ -105,6 +108,7 @@ namespace Entities { private: bool online_; + std::vector threads; std::atomic stopMainLoop = false; diff --git a/include/Entities/Sensor.hpp b/include/Entities/Sensor.hpp index 0f7ee79..4bb996a 100644 --- a/include/Entities/Sensor.hpp +++ b/include/Entities/Sensor.hpp @@ -20,6 +20,9 @@ namespace Entities { + /** + *@brief this class represents a template class example for senor Applications like Radar, Sonar, eg. + */ class Sensor { public: Sensor( diff --git a/include/Entities/SensorControl.hpp b/include/Entities/SensorControl.hpp new file mode 100644 index 0000000..53c7642 --- /dev/null +++ b/include/Entities/SensorControl.hpp @@ -0,0 +1,72 @@ +#pragma once +#include "SimCore/SimCore.hpp" +#include +#include +#include +#include +#include +#include +#include + +namespace Entities +{ + + class SensorControl + { + public: + SensorControl(std::string ID, std::string Name, std::string IP, SimCore::SensorKinds sensorKind); + + + + /** + * @brief Get the Name of the Sensor + * + * @return std::string + */ + std::string getName(); + + /** + * @brief Get the UUID of the Sensor + * + * @return std::string + */ + std::string getID(); + + /** + * @brief Get the Sensor Kind + * + * @return SimCore::SensorKinds + */ + SimCore::SensorKinds getSensorKind(); + + /** + * @brief Get the Sensor Status + * + * @return SimCore::Status + */ + SimCore::Status getSensorStatus(); + + /** + * @brief updates the sensor status + * + * @param SimCore::Status + */ + void updateStatus(SimCore::Status status); + + + std::unique_ptr TrackStore; + + + private: + + const std::string ID_; + std::string Name_; + std::string IP_; + SimCore::SensorKinds SensorKind_; + SimCore::Status SensorSatus_; + + + + }; + +} \ No newline at end of file diff --git a/include/Entities/SensorManager.hpp b/include/Entities/SensorManager.hpp new file mode 100644 index 0000000..3b0b2ad --- /dev/null +++ b/include/Entities/SensorManager.hpp @@ -0,0 +1,79 @@ +#pragma once + +#include "DirectCommunicationServer.hpp" +#include "Entities/SensorControl.hpp" +#include "SimCore/Identifier.hpp" +#include "SimCore/Messages/SimTrack.hpp" +#include "SimCore/SimCore.hpp" +#include "kubecontrol/PodController.hpp" +#include + +#include +#include +#include +#include +namespace Entities +{ + + + class SensorManager + { + public: + + SensorManager(SimCore::Identifier OwnID,std::shared_ptr PodController, ushort sensorPort = 5557); + + + /** + *@brief starts a Sensor based on a KubePod Object + *@param KubePod - a KubePod Item ready to start + *@param SensorKind - numeric value of the SensorKind from SimCore + */ + void startSensor(std::shared_ptr pod, SimCore::SensorKinds SensorKind); + + /** + *@brief stops a Sensor based on a uuid ( the sensors just stops to operate) + *@param string uuid sensor + */ + void stopSenser(std::string uuid); + + /** + *@brief deletes a sensor pod based on the uuid + *@param string uuid sensor + */ + void deleteSensor(std::string uuid); + + /** + *@brief get the Tracklist as JSON formatted string where you can see the tracks every sensor detects + *@return string - JSON formatted string + */ + std::string getTracklistStringBySensor(); + + + /** + *@brief get the Tracklist as JSON formatted string where the tracks are fusiond with a list for each track which sensor has detected that track + *@return string - JSON formatted string + */ + std::string getTracklistStringFusioned(); + + /** + *@brief Updates the Tracklist for the Specific Sensor + *@param string uuid for the Sensor + *@param SimTrack updated Track + */ + void updateTracklistForSensor(std::string uuidSensor, std::shared_ptr track); + + + + private: + const SimCore::Identifier OwnId_; + ushort SensorPort_ = 5557; + + std::map> SensorStore; + std::shared_ptr PodController_; + + std::shared_ptr SensorServer_ = nullptr; + void handlSensorMessages(std::string Message); + + + }; +} \ No newline at end of file diff --git a/libs/KubeControl b/libs/KubeControl index d1024de..2377948 160000 --- a/libs/KubeControl +++ b/libs/KubeControl @@ -1 +1 @@ -Subproject commit d1024de907ee38e75a7b13375da9f9fe3aaa7a71 +Subproject commit 2377948049cf6a41ee74e5b03b33db96215fe476 diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 459e191..c66df47 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1,5 +1,6 @@ #include "DirectCommunicationServer.hpp" #include "Entities/Movement.hpp" +#include "Entities/SensorManager.hpp" #include "Orders/MoveOrder.hpp" #include "Orders/Order.hpp" #include "SimCore/Messages/Control.hpp" @@ -45,6 +46,7 @@ namespace Entities std::string GroundTruthAddr, std::uint32_t GroundTruthPort, ushort CommandPort, + ushort SensorPort, bool online): EntityName_(EnttityName), EntityKind_(EntityKind), @@ -52,24 +54,30 @@ namespace Entities EntitySide_(EntitySide), GroundTruthPort_(GroundTruthPort), GroundTruthAddr_(GroundTruthAddr), + SensorPort_(SensorPort), online_(online) { - PodController_ = std::make_unique("docs/config"); + 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_); - MovemtServer_ = std::make_shared(__MOVEMENT_SERVER_PORT__); + MovemtServer_ = std::make_shared(__MOVEMENT_SERVER_PORT__,OwnID.getUUID()); - CommandCommsServer_ = std::make_shared(CommandPort); + CommandCommsServer_ = std::make_shared(CommandPort,OwnID.getUUID()); CommandCommsServer_->registerMessageCallback(std::bind(&Entity::handleExternalComms,this,std::placeholders::_1)); BroadcastServer_ = std::make_shared(GroundTruthAddr, GroundTruthPort); + + + // BroadcastServer_ = std::make_shared("239.0.0.1", 10000); - TrackList_ = std::make_unique(); + // TrackList_ = std::make_unique(); } @@ -137,9 +145,9 @@ namespace Entities void Entity::stop() { - LOG_S(INFO)<<"Child pods:" << PodController_->getListOfChildPods(); + LOG_S(INFO)<<"Child pods:" << PodController_->getInfoForAllPods().size(); PodController_->stopAllPods(); - LOG_S(INFO)<<"Child pods after stopping:" << PodController_->getListOfChildPods(); + LOG_S(INFO)<<"Child pods after stopping:" << PodController_->getInfoForAllPods().size(); std::this_thread::sleep_for(std::chrono::milliseconds(5000)); @@ -318,9 +326,9 @@ namespace Entities } case SimCore::GET_TRACKLIST: { - nlohmann::json j; - this->TrackList_->getJsonTRackList(j); - this->CommandCommsServer_->sendMessage(j.dump()); + + + break; } diff --git a/src/Entities/Sensor.cpp b/src/Entities/Sensor.cpp index babb800..d870b84 100644 --- a/src/Entities/Sensor.cpp +++ b/src/Entities/Sensor.cpp @@ -41,7 +41,7 @@ namespace Entities { GroundTruthUDPListener_->connect(); GroundTruthUDPListener_->subscribe(WHISPER::MsgTopics::TRACK); - client_ = std::make_unique(ParentPort_,ParentIPAddress_); + client_ = std::make_unique(ParentPort_,ParentIPAddress_,this->OwnID_.getUUID()); client_->registerMessageCallback(std::bind(&Sensor::handlServerMessages,this,std::placeholders::_1)); client_->sendMessage("Hello Server"); diff --git a/src/Entities/SensorControl.cpp b/src/Entities/SensorControl.cpp new file mode 100644 index 0000000..a6d78b2 --- /dev/null +++ b/src/Entities/SensorControl.cpp @@ -0,0 +1,49 @@ +#include "Entities/Tracklist/Tracklist.hpp" +#include "nlohmann/json_fwd.hpp" +#include +#include +#include + + + + + +namespace Entities +{ + SensorControl::SensorControl(std::string ID, std::string Name, std::string IP, SimCore::SensorKinds sensorKind): + ID_(ID),IP_(IP),Name_(Name),SensorKind_(sensorKind) + { + TrackStore = std::make_unique(); + } + + std::string SensorControl::getName() + { + return Name_; + } + + std::string SensorControl::getID() + { + return ID_; + } + + + SimCore::SensorKinds SensorControl::getSensorKind() + { + return SensorKind_; + } + + void SensorControl::updateStatus(SimCore::Status status) + { + SensorSatus_ = status; + } + + SimCore::Status SensorControl::getSensorStatus() + { + return SensorSatus_; + } + + + + + +} \ No newline at end of file diff --git a/src/Entities/SensorManager.cpp b/src/Entities/SensorManager.cpp new file mode 100644 index 0000000..5c61bba --- /dev/null +++ b/src/Entities/SensorManager.cpp @@ -0,0 +1,158 @@ +#include "Entities/SensorControl.hpp" +#include "SimCore/Messages/SimTrack.hpp" +#include "SimCore/SimCore.hpp" +#include "WHISPER/Messages/Message.hpp" +#include "nlohmann/json_fwd.hpp" +#include +#include +#include +#include + + +namespace Entities +{ + SensorManager::SensorManager(SimCore::Identifier OwnID,std::shared_ptr PodController,ushort sensorPort): + OwnId_(OwnID),PodController_(PodController) + { + SensorServer_ = std::make_shared(SensorPort_,OwnID.getUUID()); + SensorServer_->registerMessageCallback(std::bind(&SensorManager::handlSensorMessages,this,std::placeholders::_1)); + } + + void SensorManager::startSensor(std::shared_ptr pod,SimCore::SensorKinds SensorKind) + { + PodController_->startPod(pod); + SensorStore[pod->getUUID()] = std::make_unique(pod->getUUID(),pod->getName(),pod->getIp(),SensorKind); + } + + + void SensorManager::stopSenser(std::string uuid) + { + //TODO send stop message to sensor + } + + + void SensorManager::deleteSensor(std::string uuid) + { + PodController_->stopPod(uuid); + SensorStore.erase(uuid); + } + + + + + void SensorManager::handlSensorMessages(std::string Message) + { + WHISPER::Message msg(Message); + + switch (msg.msgType_) + { + case WHISPER::MsgType::SIM_TRACK: + { + auto track = std::make_shared(SimCore::SimTrack::unpack(msg)); + updateTracklistForSensor(msg.senderUUID_, track); + break; + } + case WHISPER::MsgType::SYSTEMSTATE_UPDATE: + { + + break; + } + + } + + } + + + + void SensorManager::updateTracklistForSensor(std::string uuidSensor, std::shared_ptr track) + { + auto it = SensorStore.find(uuidSensor); + it->second->TrackStore->addTrack(track); + + } + + + std::string SensorManager::getTracklistStringBySensor() + { + nlohmann::json result; + nlohmann::json radar; + radar["SensorType"] = SimCore::toString(SimCore::SensorKinds::RADAR); + nlohmann::json esm; + esm["SensorType"] = SimCore::toString(SimCore::SensorKinds::ESM); + nlohmann::json sonar; + sonar["SensorType"] = SimCore::toString(SimCore::SensorKinds::SONAR); + nlohmann::json visual; + visual["SensorType"] = SimCore::toString(SimCore::SensorKinds::VISUAL); + + for(const auto& [key, value] : SensorStore ) + { + + nlohmann::json sensor; + sensor["SensorName"] = value->getName(); + sensor["SensorID"] = value->getID(); + sensor["SensorStatus"] = SimCore::toString(value->getSensorStatus()); + sensor["SensorEnabled"] = "false"; + if (value->getSensorStatus() == SimCore::Status::ACTIVE) + { + sensor["SensorEnabled"] = "true"; + } + sensor["SensorDamaged"] = "false"; + if (value->getSensorStatus() == SimCore::Status::DEFEKT || value->getSensorStatus() == SimCore::Status::DEGRADED) + { + sensor["SensorDamaged"] = "true"; + } + nlohmann::json contacts; + value->TrackStore->getJsonTRackList(contacts); + sensor["SensorContacts"].push_back(contacts); + + + switch (value->getSensorKind()) { + case SimCore::SensorKinds::RADAR: + { + + radar["Sensors"].push_back(sensor); + break; + } + case SimCore::SensorKinds::ESM : + { + esm["Sensors"].push_back(sensor); + break; + } + case SimCore::SensorKinds::SONAR : + { + sonar["Sensors"].push_back(sensor); + + break; + } + case SimCore::SensorKinds::VISUAL : + { + visual["Sensors"].push_back(sensor); + + break; + } + } + + + result.push_back(radar); + result.push_back(esm); + result.push_back(sonar); + result.push_back(visual); + + + + + } + + return result.dump(); + } + + + std::string SensorManager::getTracklistStringFusioned() + { + + } + + + + +} \ No newline at end of file diff --git a/tests/test_EntityClass.cpp b/tests/test_EntityClass.cpp index 822ff85..f0d4722 100644 --- a/tests/test_EntityClass.cpp +++ b/tests/test_EntityClass.cpp @@ -15,6 +15,7 @@ // SimCore::Identifier OwnID, SimCore::Identifier ParentID, SimCore::SensorKinds SensorKind,std::uint32_t GroundTruthPort, std::uint32_t ParentPort,std::string ParentIPAddress class Ship : public Entities::Entity { + public: Ship(SimCore::Identifier OwnID, std::string EntityName, @@ -23,7 +24,7 @@ class Ship : public Entities::Entity std::uint32_t GroundTruthPort, ushort CommandPort ): - Entity( OwnID,EntityName,ownType, 10000, EntityKind,SimCore::Side::EntitySide::FRIEND, "127.0.0.1",GroundTruthPort, CommandPort,false) + Entity( OwnID,EntityName,ownType, 10000, EntityKind,SimCore::Side::EntitySide::FRIEND, "127.0.0.1",GroundTruthPort, CommandPort, 5557,false) { SimCore::Position pos1; pos1.setGeodesicPos(55, 6, 0);