ADD: added functionality to show the position in a simtrack of a connected ship

This commit is contained in:
Henry Winkel
2023-08-10 17:18:10 +02:00
parent 5739585b90
commit bbf4be8108
4 changed files with 125 additions and 28 deletions

View File

@@ -1,5 +1,5 @@
cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
project (EntitiyManager VERSION 0.1.0 LANGUAGES CXX C)
project (SimControlApplication VERSION 0.1.0 LANGUAGES CXX C)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
include(defaultOptions)
@@ -58,6 +58,11 @@ target_link_libraries(SimControlApplication
SimControl
)
add_custom_command(TARGET SimControlApplication POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/libs/EntityLibrary/libs/KubeControl/docs $<TARGET_FILE_DIR:${PROJECT_NAME}>/docs)
# target_include_directories(EntitiyManagerApplication
# PRIVATE
# src)

View File

@@ -2,6 +2,9 @@
#define __SIMCONTROL__
#include "DirectCommunicationClient.hpp"
#include "SimCore/Identifier.hpp"
#include "crossguid/guid.hpp"
#include "kubecontrol/PodController.hpp"
#include <iostream>
@@ -9,6 +12,7 @@
#include <cstdint>
#include <memory>
#include <string>
#include <sys/types.h>
#include <thread>
#include <mutex>
#include <queue>
@@ -22,15 +26,23 @@ namespace SimControl {
class SimControl{
public:
SimControl( std::string addr, ushort port);
SimControl(ushort CommandPort);
~SimControl();
void stop();
private:
const SimCore::Identifier ID_;
ushort CommandPort_;
void MainFunction_();
void HandleMessage(std::string msg);
std::unique_ptr<kubecontrol::PodController> PodController_;
std::thread MainThread_;
std::atomic<bool> stopMainThread_ = false;
std::unique_ptr<DirectCommunication::DirectCommunicationClient> TCPClient_;

View File

@@ -1,3 +1,10 @@
#include "Orders/MoveOrder.hpp"
#include "SimCore/Identifier.hpp"
#include "SimCore/Messages/SimTrack.hpp"
#include "WHISPER/Messages/Message.hpp"
#include "crossguid/guid.hpp"
#include "kubecontrol/KubePod.hpp"
#include "kubecontrol/PodController.hpp"
#include <SimControl/SimControl.hpp>
@@ -5,35 +12,96 @@
#include <loguru.hpp>
#include <memory>
#include <string>
#include <thread>
namespace SimControl {
SimControl::SimControl( std::string addr, ushort port)
SimControl::SimControl( ushort CommandPort):CommandPort_(CommandPort),ID_(SimCore::Identifier(xg::newGuid()))
{
PodController_ = std::make_unique<kubecontrol::PodController>("docs/config");
TCPClient_ = std::make_unique<DirectCommunication::DirectCommunicationClient>(port,addr);
TCPClient_ = std::make_unique<DirectCommunication::DirectCommunicationClient>(30200,"192.168.252.6");
TCPClient_->registerMessageCallback(std::bind(&SimControl::HandleMessage,this,std::placeholders::_1));
TCPClient_->sendMessage("Hello Server");
this->stopMainThread_ = false;
MainThread_ = std::thread(&SimControl::MainFunction_,this);
}
SimControl::~SimControl()
{
this->stopMainThread_ = true;
TCPClient_ = nullptr;
}
void SimControl::stop()
{
this->stopMainThread_ = true;
TCPClient_.reset();
}
void SimControl::HandleMessage(std::string msg)
{
TCPClient_->sendMessage("Hello Server") ;
// LOG_S(INFO)<<msg;
auto simtrack = SimCore::SimTrack::unpack(msg);
if (simtrack != nullptr)
{
LOG_S(INFO)<< "own ship data received";
auto OwnShipPos = std::make_shared<SimCore::Position>(simtrack->getPosition());
LOG_S(INFO)<< " pos: Lat= "<< OwnShipPos->getGeodesicPos().x() << "Lon= "<< OwnShipPos->getGeodesicPos().y();
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));
LOG_S(INFO)<<msg;
}
void SimControl::MainFunction_()
{
kubecontrol::KubePod ShipPod1("hamburg","ship1","ship:latest");
ShipPod1.setEnvironmentVar("ENTITY_ID", "ship1");
ShipPod1.setEnvironmentVar("ENTITY_NAME", "hamburg");
ShipPod1.setEnvironmentVar("POS_LAT", "\"55\"");
ShipPod1.setEnvironmentVar("POS_LONG", "\"8\"");
ShipPod1.setEnvironmentVar("POS_HEIGHT", "\"0\"");
ShipPod1.setEnvironmentVar("GROUNDTRUTH_PORT", "\"8000\"");
ShipPod1.setEnvironmentVar("COMMAND_PORT", "\"5555\"");
ShipPod1.createYAML();
Orders::MoveOrder order(this->ID_,WHISPER::SourceType::SIMCOMTROLER);
order.Speed.setValue(5.14444);
TCPClient_->sendMessage(order.buildMessage().serialize());
// std::this_thread::sleep_for(std::chrono::milliseconds(3000));
// TCPClient_->disconnect();
// TCPClient_.reset();
while (!stopMainThread_)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
// std::this_thread::sleep_for(std::chrono::milliseconds(3000));
TCPClient_->disconnect();
LOG_S(INFO)<<"main func stopped";
}
}

View File

@@ -1,3 +1,4 @@
#include "Orders/MoveOrder.hpp"
#include <cstdlib>
#include <iostream>
#include <csignal>
@@ -32,26 +33,37 @@ int main()
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, NULL);
ushort port = 3500;
// SimControl::SimControl sc("127.0.0.1",5557);
const char* CommandPortChar = "31371";
if (std::getenv("COMMAND_PORT") != nullptr) {
CommandPortChar = std::getenv("COMMAND_PORT");
}
ushort commandPort_ = (unsigned short)strtol(CommandPortChar,NULL,0);
DirectCommunication::DirectCommunicationClient client(port,"127.0.0.1");
const char *ServerAddress = nullptr;
ServerAddress = std::getenv("SERVER_IP");
if (ServerAddress == nullptr) {
ServerAddress = "127.0.0.1";
}
LOG_S(INFO)<<ServerAddress;
ushort port = 8000;
SimControl::SimControl sc(commandPort_);
client.sendMessage("Hello Server");
while (running) {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
client.sendMessage("Hello Server");
std::string MessageString = client.getLatestMessage();
LOG_S(INFO)<<MessageString;
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
sc.stop();
LOG_S(INFO)<<"end app";
std::exit(0);
return 0;
std::exit(0);
}