ADD: added json lib and made some changes in the entity class
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -7,3 +7,6 @@
|
|||||||
[submodule "libs/whisper-com"]
|
[submodule "libs/whisper-com"]
|
||||||
path = libs/SimCore/libs/whisper-com
|
path = libs/SimCore/libs/whisper-com
|
||||||
url = ssh://git@dev-gitea.ftewa.ti.unibw-hamburg.de:12000/hwinkel/whisper-com.git
|
url = ssh://git@dev-gitea.ftewa.ti.unibw-hamburg.de:12000/hwinkel/whisper-com.git
|
||||||
|
[submodule "libs/nlohmannJSON"]
|
||||||
|
path = libs/nlohmannJSON
|
||||||
|
url = https://github.com/nlohmann/json.git
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ set(TEST_SIMCORE_LIBRARY OFF CACHE INTERNAL "")
|
|||||||
add_subdirectory(libs/SimCore EXCLUDE_FROM_ALL)
|
add_subdirectory(libs/SimCore EXCLUDE_FROM_ALL)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
IF(NOT TARGET nlohmann_json)
|
||||||
|
set(JSON_BuildTests_INIT OFF CACHE INTERNAL "")
|
||||||
|
add_subdirectory(libs/nlohmannJSON EXCLUDE_FROM_ALL)
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protobuf_generate_cpp(PROTO_PATH include/Orders/protos CPP_PATH include/Orders/protos HPP_PATH include/Orders/protos)
|
protobuf_generate_cpp(PROTO_PATH include/Orders/protos CPP_PATH include/Orders/protos HPP_PATH include/Orders/protos)
|
||||||
@@ -73,6 +78,7 @@ target_link_libraries(EntityLibrary
|
|||||||
SimCore
|
SimCore
|
||||||
eigen
|
eigen
|
||||||
loguru
|
loguru
|
||||||
|
nlohmann_json
|
||||||
)
|
)
|
||||||
# add_dependencies(SimCore protoc)
|
# add_dependencies(SimCore protoc)
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
#include <WHISPER/threadSafeQueue.hpp>
|
#include <WHISPER/threadSafeQueue.hpp>
|
||||||
#include <SimCore/Identifier.hpp>
|
#include <SimCore/Identifier.hpp>
|
||||||
#include <SimCore/Position.hpp>
|
#include <SimCore/Position.hpp>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -98,7 +100,7 @@ namespace Entities {
|
|||||||
void startMovementWorker();
|
void startMovementWorker();
|
||||||
std::atomic<bool> MovementWorkerStarted = false;
|
std::atomic<bool> MovementWorkerStarted = false;
|
||||||
std::shared_ptr<DirectCommunication::DirectCommunicationServer> MovemtServer_ = nullptr;
|
std::shared_ptr<DirectCommunication::DirectCommunicationServer> MovemtServer_ = nullptr;
|
||||||
|
void handleMovement();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Submodule libs/SimCore updated: 1a878af6a5...0123a22aac
1
libs/nlohmannJSON
Submodule
1
libs/nlohmannJSON
Submodule
Submodule libs/nlohmannJSON added at 5d2754306d
@@ -34,6 +34,7 @@ namespace Entities
|
|||||||
|
|
||||||
{
|
{
|
||||||
OwnShipTrack = std::make_shared<SimCore::SimTrack>(OwnID, OwnType, EntityKind);
|
OwnShipTrack = std::make_shared<SimCore::SimTrack>(OwnID, OwnType, EntityKind);
|
||||||
|
OwnShipTrack->setPosition(SimCore::Position());
|
||||||
|
|
||||||
MovemtServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(__MOVEMENT_SERVER_PORT__);
|
MovemtServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(__MOVEMENT_SERVER_PORT__);
|
||||||
|
|
||||||
@@ -52,19 +53,31 @@ namespace Entities
|
|||||||
void Entity::setPosition(SimCore::Position pos)
|
void Entity::setPosition(SimCore::Position pos)
|
||||||
{
|
{
|
||||||
OwnShipTrack->setPosition(pos);
|
OwnShipTrack->setPosition(pos);
|
||||||
|
SimCore::SimTrack newSimTrack(OwnShipTrack->getIdentifier(),WHISPER::SourceType::ENTITY,EntityKind_);
|
||||||
|
newSimTrack.setPosition(pos);
|
||||||
}
|
}
|
||||||
void Entity::setSpeed(double val)
|
void Entity::setSpeed(double val)
|
||||||
{
|
{
|
||||||
OwnShipTrack->Speed.setValue(val);
|
OwnShipTrack->Speed.setValue(val);
|
||||||
|
SimCore::SimTrack newSimTrack(OwnShipTrack->getIdentifier(),WHISPER::SourceType::ENTITY,EntityKind_);
|
||||||
|
newSimTrack.Speed.setValue(val);
|
||||||
|
MovemtServer_->sendMessage(newSimTrack.buildMessage().serialize());
|
||||||
|
|
||||||
}
|
}
|
||||||
void Entity::setCourse(double val)
|
void Entity::setCourse(double val)
|
||||||
{
|
{
|
||||||
OwnShipTrack->Course.setValue(val);
|
OwnShipTrack->Course.setValue(val);
|
||||||
|
SimCore::SimTrack newSimTrack(OwnShipTrack->getIdentifier(),WHISPER::SourceType::ENTITY,EntityKind_);
|
||||||
|
newSimTrack.Course.setValue(val);
|
||||||
|
LOG_S(INFO)<< "NEW Course: "<< val;
|
||||||
|
MovemtServer_->sendMessage(newSimTrack.buildMessage().serialize());
|
||||||
}
|
}
|
||||||
void Entity::setPitch( double val)
|
void Entity::setPitch( double val)
|
||||||
{
|
{
|
||||||
OwnShipTrack->Pitch.setValue(val);
|
OwnShipTrack->Pitch.setValue(val);
|
||||||
|
SimCore::SimTrack newSimTrack(OwnShipTrack->getIdentifier(),WHISPER::SourceType::ENTITY,EntityKind_);
|
||||||
|
newSimTrack.Pitch.setValue(val);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entity::start()
|
void Entity::start()
|
||||||
@@ -107,15 +120,33 @@ namespace Entities
|
|||||||
|
|
||||||
if (MovemtServer_->countClients() > 0 )
|
if (MovemtServer_->countClients() > 0 )
|
||||||
{
|
{
|
||||||
std::string msg = MovemtServer_->getLatestMessage();
|
if(OwnShipTrack->getPosition().isValid())
|
||||||
if (msg == "Hello Server")
|
{
|
||||||
{
|
LOG_S(INFO)<< "POS: LAT: "<< OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LATITUDE) << " LON: " << OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LONGITUDE);
|
||||||
|
|
||||||
MovementWorkerStarted = true;
|
MovementWorkerStarted = true;
|
||||||
MovemtServer_->sendMessage(OwnShipTrack->buildMessage().serialize());
|
MovemtServer_->sendMessage(OwnShipTrack->buildMessage().serialize());
|
||||||
}
|
LOG_S(INFO)<< "Initial Message send to MovementWorker";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Entity::handleMovement()
|
||||||
|
{
|
||||||
|
if (!MovementWorkerStarted)
|
||||||
|
{
|
||||||
|
startMovementWorker();
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
std::string msg = MovemtServer_->getLatestMessage();
|
||||||
|
auto newTrack = SimCore::SimTrack::unpack(msg);
|
||||||
|
if (newTrack != nullptr)
|
||||||
|
{
|
||||||
|
OwnShipTrack->setPosition(newTrack->getPosition());
|
||||||
|
LOG_S(INFO)<< "new POS: LAT: "<< OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LATITUDE) << " LON: " << OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LONGITUDE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,22 +158,7 @@ namespace Entities
|
|||||||
LOG_S(INFO)<< "main loop started";
|
LOG_S(INFO)<< "main loop started";
|
||||||
while (!stopMainLoop)
|
while (!stopMainLoop)
|
||||||
{
|
{
|
||||||
if (!MovementWorkerStarted)
|
handleMovement();
|
||||||
{
|
|
||||||
startMovementWorker();
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
std::string msg = MovemtServer_->getLatestMessage();
|
|
||||||
auto newTrack = SimCore::SimTrack::unpack(msg);
|
|
||||||
if (newTrack != nullptr)
|
|
||||||
{
|
|
||||||
OwnShipTrack->setPosition(newTrack->getPosition());
|
|
||||||
LOG_S(INFO)<< "new POS: LAT: "<< OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LATITUDE) << " LON: " << OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LONGITUDE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
|
|||||||
Reference in New Issue
Block a user