ADD: added prototype of sensormanager

This commit is contained in:
Henry Winkel
2024-02-12 18:43:53 +01:00
parent fc7fe2193b
commit cfe2aff5ce
11 changed files with 396 additions and 14 deletions

View File

@@ -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<kubecontrol::PodController>("docs/config");
PodController_ = std::make_shared<kubecontrol::PodController>("docs/config");
SensorManager_ = std::make_unique<Entities::SensorManager>(OwnID, PodController_,SensorPort_);
OwnShipTrack = std::make_shared<SimCore::SimTrack>(OwnID, EnttityName, EntityKind,EntitySide);
OwnShipTrack->setPosition(SimCore::Position());
OwnShipTrack->RCS.setValue(RCS_);
MovemtServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(__MOVEMENT_SERVER_PORT__);
MovemtServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(__MOVEMENT_SERVER_PORT__,OwnID.getUUID());
CommandCommsServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(CommandPort);
CommandCommsServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(CommandPort,OwnID.getUUID());
CommandCommsServer_->registerMessageCallback(std::bind(&Entity::handleExternalComms,this,std::placeholders::_1));
BroadcastServer_ = std::make_shared<WHISPER::InternalUDPSender>(GroundTruthAddr, GroundTruthPort);
// BroadcastServer_ = std::make_shared<WHISPER::InternalUDPSender>("239.0.0.1", 10000);
TrackList_ = std::make_unique<TrackList::TrackList>();
// TrackList_ = std::make_unique<TrackList::TrackList>();
}
@@ -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;
}

View File

@@ -41,7 +41,7 @@ namespace Entities {
GroundTruthUDPListener_->connect();
GroundTruthUDPListener_->subscribe(WHISPER::MsgTopics::TRACK);
client_ = std::make_unique<DirectCommunication::DirectCommunicationClient>(ParentPort_,ParentIPAddress_);
client_ = std::make_unique<DirectCommunication::DirectCommunicationClient>(ParentPort_,ParentIPAddress_,this->OwnID_.getUUID());
client_->registerMessageCallback(std::bind(&Sensor::handlServerMessages,this,std::placeholders::_1));
client_->sendMessage("Hello Server");

View File

@@ -0,0 +1,49 @@
#include "Entities/Tracklist/Tracklist.hpp"
#include "nlohmann/json_fwd.hpp"
#include <Entities/SensorControl.hpp>
#include <memory>
#include <string>
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<TrackList::TrackList>();
}
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_;
}
}

View File

@@ -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 <Entities/SensorManager.hpp>
#include <memory>
#include <string>
#include <utility>
namespace Entities
{
SensorManager::SensorManager(SimCore::Identifier OwnID,std::shared_ptr<kubecontrol::PodController> PodController,ushort sensorPort):
OwnId_(OwnID),PodController_(PodController)
{
SensorServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(SensorPort_,OwnID.getUUID());
SensorServer_->registerMessageCallback(std::bind(&SensorManager::handlSensorMessages,this,std::placeholders::_1));
}
void SensorManager::startSensor(std::shared_ptr<kubecontrol::KubePod> pod,SimCore::SensorKinds SensorKind)
{
PodController_->startPod(pod);
SensorStore[pod->getUUID()] = std::make_unique<Entities::SensorControl>(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>(SimCore::SimTrack::unpack(msg));
updateTracklistForSensor(msg.senderUUID_, track);
break;
}
case WHISPER::MsgType::SYSTEMSTATE_UPDATE:
{
break;
}
}
}
void SensorManager::updateTracklistForSensor(std::string uuidSensor, std::shared_ptr<SimCore::SimTrack> 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()
{
}
}