ADD: added functionality to show the position in a simtrack of a connected ship
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
|
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)
|
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
|
||||||
include(defaultOptions)
|
include(defaultOptions)
|
||||||
|
|
||||||
@@ -58,6 +58,11 @@ target_link_libraries(SimControlApplication
|
|||||||
SimControl
|
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
|
# target_include_directories(EntitiyManagerApplication
|
||||||
# PRIVATE
|
# PRIVATE
|
||||||
# src)
|
# src)
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
#define __SIMCONTROL__
|
#define __SIMCONTROL__
|
||||||
|
|
||||||
#include "DirectCommunicationClient.hpp"
|
#include "DirectCommunicationClient.hpp"
|
||||||
|
#include "SimCore/Identifier.hpp"
|
||||||
|
#include "crossguid/guid.hpp"
|
||||||
|
#include "kubecontrol/PodController.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
@@ -9,6 +12,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
@@ -22,15 +26,23 @@ namespace SimControl {
|
|||||||
class SimControl{
|
class SimControl{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SimControl( std::string addr, ushort port);
|
SimControl(ushort CommandPort);
|
||||||
~SimControl();
|
~SimControl();
|
||||||
|
void stop();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const SimCore::Identifier ID_;
|
||||||
|
ushort CommandPort_;
|
||||||
void MainFunction_();
|
void MainFunction_();
|
||||||
|
|
||||||
void HandleMessage(std::string msg);
|
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_;
|
std::unique_ptr<DirectCommunication::DirectCommunicationClient> TCPClient_;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
#include <SimControl/SimControl.hpp>
|
||||||
|
|
||||||
|
|
||||||
@@ -5,35 +12,96 @@
|
|||||||
#include <loguru.hpp>
|
#include <loguru.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
|
||||||
namespace SimControl {
|
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_->registerMessageCallback(std::bind(&SimControl::HandleMessage,this,std::placeholders::_1));
|
||||||
TCPClient_->sendMessage("Hello Server");
|
TCPClient_->sendMessage("Hello Server");
|
||||||
|
|
||||||
|
this->stopMainThread_ = false;
|
||||||
|
MainThread_ = std::thread(&SimControl::MainFunction_,this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SimControl::~SimControl()
|
SimControl::~SimControl()
|
||||||
{
|
{
|
||||||
|
this->stopMainThread_ = true;
|
||||||
|
|
||||||
TCPClient_ = nullptr;
|
TCPClient_ = nullptr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SimControl::stop()
|
||||||
|
{
|
||||||
|
this->stopMainThread_ = true;
|
||||||
|
TCPClient_.reset();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void SimControl::HandleMessage(std::string msg)
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
34
src/main.cpp
34
src/main.cpp
@@ -1,3 +1,4 @@
|
|||||||
|
#include "Orders/MoveOrder.hpp"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
@@ -32,26 +33,37 @@ int main()
|
|||||||
sigIntHandler.sa_flags = 0;
|
sigIntHandler.sa_flags = 0;
|
||||||
sigaction(SIGINT, &sigIntHandler, NULL);
|
sigaction(SIGINT, &sigIntHandler, NULL);
|
||||||
|
|
||||||
ushort port = 3500;
|
const char* CommandPortChar = "31371";
|
||||||
// SimControl::SimControl sc("127.0.0.1",5557);
|
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) {
|
while (running) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
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(2000));
|
||||||
|
sc.stop();
|
||||||
|
|
||||||
LOG_S(INFO)<<"end app";
|
LOG_S(INFO)<<"end app";
|
||||||
std::exit(0);
|
|
||||||
return 0;
|
return 0;
|
||||||
|
std::exit(0);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user