ADD: added json lib and made some changes in the entity class

This commit is contained in:
hwinkel
2023-07-05 22:11:44 +02:00
parent 5485c8550e
commit 3333fadf20
6 changed files with 53 additions and 25 deletions

3
.gitmodules vendored
View File

@@ -7,3 +7,6 @@
[submodule "libs/whisper-com"]
path = libs/SimCore/libs/whisper-com
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

View File

@@ -13,6 +13,11 @@ set(TEST_SIMCORE_LIBRARY OFF CACHE INTERNAL "")
add_subdirectory(libs/SimCore EXCLUDE_FROM_ALL)
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)
@@ -73,6 +78,7 @@ target_link_libraries(EntityLibrary
SimCore
eigen
loguru
nlohmann_json
)
# add_dependencies(SimCore protoc)

View File

@@ -19,6 +19,8 @@
#include <WHISPER/threadSafeQueue.hpp>
#include <SimCore/Identifier.hpp>
#include <SimCore/Position.hpp>
#include <nlohmann/json.hpp>
#include <atomic>
#include <chrono>
#include <memory>
@@ -98,7 +100,7 @@ namespace Entities {
void startMovementWorker();
std::atomic<bool> MovementWorkerStarted = false;
std::shared_ptr<DirectCommunication::DirectCommunicationServer> MovemtServer_ = nullptr;
void handleMovement();

1
libs/nlohmannJSON Submodule

Submodule libs/nlohmannJSON added at 5d2754306d

View File

@@ -34,6 +34,7 @@ namespace Entities
{
OwnShipTrack = std::make_shared<SimCore::SimTrack>(OwnID, OwnType, EntityKind);
OwnShipTrack->setPosition(SimCore::Position());
MovemtServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(__MOVEMENT_SERVER_PORT__);
@@ -52,19 +53,31 @@ namespace Entities
void Entity::setPosition(SimCore::Position pos)
{
OwnShipTrack->setPosition(pos);
SimCore::SimTrack newSimTrack(OwnShipTrack->getIdentifier(),WHISPER::SourceType::ENTITY,EntityKind_);
newSimTrack.setPosition(pos);
}
void Entity::setSpeed(double 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)
{
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)
{
OwnShipTrack->Pitch.setValue(val);
SimCore::SimTrack newSimTrack(OwnShipTrack->getIdentifier(),WHISPER::SourceType::ENTITY,EntityKind_);
newSimTrack.Pitch.setValue(val);
}
void Entity::start()
@@ -107,15 +120,33 @@ namespace Entities
if (MovemtServer_->countClients() > 0 )
{
std::string msg = MovemtServer_->getLatestMessage();
if (msg == "Hello Server")
{
if(OwnShipTrack->getPosition().isValid())
{
LOG_S(INFO)<< "POS: LAT: "<< OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LATITUDE) << " LON: " << OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LONGITUDE);
MovementWorkerStarted = true;
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";
while (!stopMainLoop)
{
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);
}
}
handleMovement();
std::this_thread::sleep_for(std::chrono::milliseconds(500));