255 lines
8.9 KiB
C++
255 lines
8.9 KiB
C++
|
|
#include "DirectCommunicationClient.hpp"
|
|
#include "Entities/SensorControl.hpp"
|
|
#include "Entities/SensorManager.hpp"
|
|
#include "SimCore/Messages/SensorData.hpp"
|
|
#include "SimCore/Messages/SensorTrack.hpp"
|
|
#include "SimCore/Messages/SimTrack.hpp"
|
|
#include "SimCore/Position.hpp"
|
|
#include "nlohmann/json_fwd.hpp"
|
|
#include <kubecontrol/PodController.hpp>
|
|
#include <SimCore/Identifier.hpp>
|
|
#include <SimCore/SimCore.hpp>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <utility>
|
|
#define CATCH_CONFIG_MAIN
|
|
#include <catch2/catch.hpp>
|
|
#include <Entities/Sensor.hpp>
|
|
|
|
// SimCore::Identifier OwnID, SimCore::Identifier ParentID, SimCore::SensorKinds SensorKind,std::uint32_t GroundTruthPort, std::uint32_t ParentPort,std::string ParentIPAddress
|
|
double fRand(double fMin, double fMax)
|
|
{
|
|
double f = (double)rand() / RAND_MAX;
|
|
return fMin + f * (fMax - fMin);
|
|
}
|
|
void sendRandomTrack(std::shared_ptr<DirectCommunication::DirectCommunicationClient> client,std::shared_ptr<Sensor::SensorControl> sensor, int number)
|
|
{
|
|
for (int i = 0; i < number; i++) {
|
|
std::string name = "test1-" + std::to_string(i);
|
|
auto simtrack = std::make_shared<SimCore::SimTrack>(name,SimCore::Kind::EntityKind::SURFACE,SimCore::Side::NEUTRAL);
|
|
auto track = std::make_shared<SimCore::SensorTrack>(simtrack,sensor);
|
|
// LOG_S(INFO)<<track->getSensorData()->getName();
|
|
SimCore::Position pos;
|
|
double lat = fRand(-90, 90);
|
|
double lon = fRand(-180, 180);
|
|
|
|
pos.setGeodesicPos( lat, lon, 0);
|
|
track->setPosition(pos);
|
|
client->sendMessage(track->buildMessage());
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void sendRandomTracktoManager(std::shared_ptr<Entities::SensorManager> SensorManager_)
|
|
{
|
|
// for (int i = 0; i < 5; i++) {
|
|
// std::string name = "test1-" + std::to_string(i);
|
|
// SimCore::SensorTrack track(name,SimCore::Kind::EntityKind::SURFACE,SimCore::Side::NEUTRAL);
|
|
// SimCore::Position pos;
|
|
// double lat = fRand(-90, 90);
|
|
// double lon = fRand(-180, 180);
|
|
|
|
// pos.setGeodesicPos( lat, lon, 0);
|
|
// track.setPosition(pos);
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
auto id0 = SimCore::Identifier();
|
|
LOG_S(INFO)<<id0.getUUID();
|
|
auto control = std::make_shared<Sensor::SensorControl>(id0.getUUID(),"Sensor", "127.0.0.1", SimCore::SensorKinds::RADAR);
|
|
auto test = std::static_pointer_cast<SimCore::SensorData>(control);
|
|
LOG_S(INFO)<< test->getSensorDataAsJson();
|
|
|
|
auto client = std::make_shared<DirectCommunication::DirectCommunicationClient>(5557,"127.0.0.1",id0.getUUID());
|
|
SensorManager_->addSensorLocal(control);
|
|
// sendRandomTrack(client,5);
|
|
|
|
auto id1 = SimCore::Identifier();
|
|
auto control1 = std::make_shared<Sensor::SensorControl>(id1.getUUID(),"Sensor1", "127.0.0.1", SimCore::SensorKinds::RADAR);
|
|
auto client1 = std::make_shared<DirectCommunication::DirectCommunicationClient>(5557,"127.0.0.1",id1.getUUID());
|
|
SensorManager_->addSensorLocal(control1);
|
|
// sendRandomTrack(client1,5);
|
|
|
|
auto id2 = SimCore::Identifier();
|
|
auto control2 = std::make_shared<Sensor::SensorControl>(id2.getUUID(),"Sensor2", "127.0.0.1", SimCore::SensorKinds::VISUAL);
|
|
auto client2 = std::make_shared<DirectCommunication::DirectCommunicationClient>(5557,"127.0.0.1",id2.getUUID());
|
|
SensorManager_->addSensorLocal(control2);
|
|
// sendRandomTrack(client2,5);
|
|
|
|
auto id3 = SimCore::Identifier();
|
|
auto control3 = std::make_shared<Sensor::SensorControl>(id3.getUUID(),"Sensor3", "127.0.0.1", SimCore::SensorKinds::ESM);
|
|
auto client3 = std::make_shared<DirectCommunication::DirectCommunicationClient>(5557,"127.0.0.1",id3.getUUID());
|
|
SensorManager_->addSensorLocal(control3);
|
|
sendRandomTrack(client2,control3,5);
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
std::string name = "identical-" + std::to_string(i);
|
|
auto Simtrack = std::make_shared<SimCore::SimTrack>(name,SimCore::Kind::EntityKind::SURFACE,SimCore::Side::NEUTRAL);
|
|
SimCore::SensorTrack track(Simtrack);
|
|
|
|
// LOG_S(INFO)<<track.getSensorData()->getID().getUUID();
|
|
|
|
SimCore::Position pos;
|
|
double lat = fRand(-90, 90);
|
|
double lon = fRand(-180, 180);
|
|
|
|
pos.setGeodesicPos( lat, lon, 0);
|
|
track.setPosition(pos);
|
|
|
|
client->sendMessage(track.buildMessage());
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
client1->sendMessage(track.buildMessage());
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
client2->sendMessage(track.buildMessage());
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
client3->sendMessage(track.buildMessage());
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
void startSensors(SimCore::Identifier ownid, std::string GroundTruthAddr_,ushort GroundTruthPort_, ushort SensorPort_ , auto SensorManager_)
|
|
{
|
|
LOG_S(INFO)<<"__ONLINE__";
|
|
std::string SensorUUID_ = xg::newGuid().str();
|
|
LOG_S(INFO)<<ownid.getUUID();
|
|
|
|
|
|
|
|
auto RadarPod = std::make_shared<kubecontrol::KubePod>(ownid.getUUID(),SensorUUID_,"radar:latest");
|
|
|
|
RadarPod->setEnvironmentVar("SERVER_IP", SimCore::UtilFunctions::getOwnIP());
|
|
|
|
nlohmann::json vars;
|
|
vars["OWN_SHIP_ID"] = ownid.getUUID();
|
|
vars["SENSOR_ID"] = SensorUUID_;
|
|
vars["SENSOR_NAME"] = "APAR";
|
|
vars["GROUNDTRUTH_PORT"] = std::to_string(GroundTruthPort_);
|
|
vars["GROUNDTRUTH_ADDR"] = GroundTruthAddr_;
|
|
vars["TRANSMIT_POWER"] = "66";
|
|
vars["GAIN_TRANSMIT"] = "40";
|
|
vars["GAIN_RECEIVE"] = "40";
|
|
vars["TRANSMIT_FREQUENCY"] = "2657";
|
|
vars["INSTRUMENTED_RANGE"] = "150000";
|
|
vars["MOUNTED_HEIGHT"] = "23";
|
|
vars["OWN_SHIP_IP"] = SimCore::UtilFunctions::getOwnIP();
|
|
vars["OWN_SHIP_PORT"] = std::to_string(SensorPort_);
|
|
|
|
RadarPod->setEnvironmentVar("CONFIG", vars.dump());
|
|
|
|
RadarPod->setComponent("Radar");
|
|
|
|
SensorManager_->startSensor(RadarPod, SimCore::SensorKinds::RADAR);
|
|
|
|
|
|
}
|
|
|
|
SCENARIO("Testing the SimCore SensorManager")
|
|
{
|
|
GIVEN("different Attributes for a Track in different forms")
|
|
{
|
|
SimCore::Identifier id;
|
|
|
|
auto PodController_ = std::make_shared<kubecontrol::PodController>("docs/config");
|
|
|
|
auto ownShip = std::make_shared<SimCore::SimTrack>(id,"Test Ship", SimCore::Kind::EntityKind::SURFACE,SimCore::Side::EntitySide::FRIEND);
|
|
auto SensorManager_ = std::make_shared<Entities::SensorManager>(ownShip, PodController_,5557);
|
|
|
|
|
|
startSensors(id, "239.0.0.1", 7000, 5557, SensorManager_);
|
|
|
|
|
|
|
|
WHEN("constructing Track Object with data")
|
|
{
|
|
|
|
THEN("check if Track attributes are correct")
|
|
{
|
|
REQUIRE(PodController_->getInfoForAllPods().size() == 1);
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
SensorManager_->deleteAllSensor();
|
|
|
|
REQUIRE(PodController_->getInfoForAllPods().size() == 0);
|
|
|
|
SensorManager_->stop();
|
|
} //THEN
|
|
} // WHEN
|
|
} // GIVEN
|
|
} //SCENARIO
|
|
|
|
|
|
SCENARIO("Testing the SimCore SensorManager with local sensors")
|
|
{
|
|
GIVEN("different Attributes for a Track in different forms")
|
|
{
|
|
SimCore::Identifier id;
|
|
|
|
auto PodController_ = std::make_shared<kubecontrol::PodController>("docs/config");
|
|
|
|
auto ownShip = std::make_shared<SimCore::SimTrack>(id,"Test Ship", SimCore::Kind::EntityKind::SURFACE,SimCore::Side::EntitySide::FRIEND);
|
|
|
|
auto SensorManager_ = std::make_shared<Entities::SensorManager>(ownShip, PodController_,5557);
|
|
|
|
|
|
sendRandomTracktoManager(SensorManager_);
|
|
// std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
|
|
|
|
|
WHEN("constructing Track Object with data")
|
|
{
|
|
std::string tracklist1 = SensorManager_->getTracklistStringBySensor();
|
|
std::string tracklist2 = SensorManager_->getTracklistStringFusioned();
|
|
|
|
LOG_S(INFO)<<tracklist1;
|
|
|
|
|
|
|
|
|
|
THEN("check if Track attributes are correct")
|
|
{
|
|
|
|
|
|
nlohmann::json j = nlohmann::json::parse(tracklist1);
|
|
nlohmann::json j2 = nlohmann::json::parse(tracklist2);
|
|
|
|
REQUIRE( j[0]["Sensors"].size() == 2);
|
|
REQUIRE( j[0]["Sensors"][0]["SensorContacts"].size() == 3);
|
|
|
|
REQUIRE( j[0]["Sensors"][0]["SensorContacts"].size() == j[0]["Sensors"][1]["SensorContacts"].size());
|
|
REQUIRE( j[0]["Sensors"][0]["SensorContacts"][0]["id"] == j[0]["Sensors"][1]["SensorContacts"][0]["id"]);
|
|
REQUIRE( j[0]["Sensors"][0]["SensorContacts"][0]["id"] == j[1]["Sensors"][0]["SensorContacts"][0]["id"]);
|
|
|
|
REQUIRE( j2.size() == 8);
|
|
|
|
REQUIRE(SensorManager_->getSensorCount() == 4);
|
|
|
|
|
|
REQUIRE(SensorManager_->getTrackListUpdateRaw()->getSensors().size() == 4);
|
|
REQUIRE(SensorManager_->getTrackListUpdateRaw()->getSensors().at(0).getTracksCount() == 3);
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
|
|
|
|
REQUIRE(SensorManager_->getTrackListUpdateRaw()->getSensors().at(0).getTracksCount() == 0);
|
|
|
|
|
|
SensorManager_->stop();
|
|
|
|
} //THEN
|
|
} // WHEN
|
|
} // GIVEN
|
|
} //SCENARIO
|