ADD: added functionality to show the position in a simtrack of a connected ship
This commit is contained in:
@@ -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,32 +12,93 @@
|
||||
#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_->registerMessageCallback(std::bind(&SimControl::HandleMessage,this,std::placeholders::_1));
|
||||
TCPClient_->sendMessage("Hello Server");
|
||||
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()
|
||||
{
|
||||
TCPClient_ = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
SimControl::~SimControl()
|
||||
{
|
||||
this->stopMainThread_ = true;
|
||||
|
||||
void SimControl::HandleMessage(std::string msg)
|
||||
{
|
||||
TCPClient_ = nullptr;
|
||||
|
||||
LOG_S(INFO)<<msg;
|
||||
}
|
||||
|
||||
}
|
||||
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));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
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 <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);
|
||||
}
|
||||
Reference in New Issue
Block a user