Compare commits
10 Commits
5e829298fd
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c89b60a4ab | ||
|
|
913cef4342 | ||
|
|
fb6b8f6178 | ||
|
|
d6b18f560d | ||
|
|
ae9dc2fa97 | ||
|
|
14e4fddab4 | ||
|
|
e947d29669 | ||
|
|
3f7b7ebcae | ||
|
|
96b99afff9 | ||
|
|
b932c4a917 |
43
.drone.yml
Normal file
43
.drone.yml
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
kind: pipeline
|
||||||
|
type: kubernetes
|
||||||
|
name: default-build
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: build
|
||||||
|
image: kmaster.ti.unibw-hamburg.de:30808/debianbullseye
|
||||||
|
commands:
|
||||||
|
- git submodule update --init --recursive --jobs=4
|
||||||
|
- mkdir -p build && cd build
|
||||||
|
- CC=clang-11 CXX=clang++-11 cmake -DCMAKE_BUILD_TYPE=DEBUG ..
|
||||||
|
- make -j
|
||||||
|
- make test
|
||||||
|
|
||||||
|
- name: SimControl
|
||||||
|
image: kmaster.ti.unibw-hamburg.de:30808/drone-ftewa-codechecker
|
||||||
|
pull: always
|
||||||
|
settings:
|
||||||
|
CODECHECKER_URL: "http://codechecker:8001"
|
||||||
|
CODECHECKER_PRODUCT: "Kubecontrol"
|
||||||
|
CODECHECKER_USER:
|
||||||
|
from_secret: CODECHECKER_USER_SECRET
|
||||||
|
CODECHECKER_PASS:
|
||||||
|
from_secret: CODECHECKER_PASS_SECRET
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
include:
|
||||||
|
- push
|
||||||
|
- pull_request
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: secret
|
||||||
|
name: CODECHECKER_USER_SECRET
|
||||||
|
get:
|
||||||
|
path: codechecker-client
|
||||||
|
name: username
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: secret
|
||||||
|
name: CODECHECKER_PASS_SECRET
|
||||||
|
get:
|
||||||
|
path: codechecker-client
|
||||||
|
name: password
|
||||||
12
.gitmodules
vendored
12
.gitmodules
vendored
@@ -4,9 +4,15 @@
|
|||||||
[submodule "build/libs/SimCore/libs/whisper-comm"]
|
[submodule "build/libs/SimCore/libs/whisper-comm"]
|
||||||
path = build/libs/SimCore/libs/whisper-comm
|
path = build/libs/SimCore/libs/whisper-comm
|
||||||
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/OrderLibrary"]
|
|
||||||
path = libs/OrderLibrary
|
|
||||||
url = ssh://git@dev-gitea.ftewa.ti.unibw-hamburg.de:12000/hwinkel/OrderLibrary.git
|
|
||||||
[submodule "libs/ixwebsocket"]
|
[submodule "libs/ixwebsocket"]
|
||||||
path = libs/ixwebsocket
|
path = libs/ixwebsocket
|
||||||
url = https://github.com/machinezone/IXWebSocket.git
|
url = https://github.com/machinezone/IXWebSocket.git
|
||||||
|
[submodule "libs/WebsocketClient"]
|
||||||
|
path = libs/WebsocketClient
|
||||||
|
url = https://github.com/zaphoyd/websocketpp.git
|
||||||
|
[submodule "libs/easywsclient"]
|
||||||
|
path = libs/easywsclient
|
||||||
|
url = https://github.com/dhbaird/easywsclient.git
|
||||||
|
[submodule "libs/OrderLibrary"]
|
||||||
|
path = libs/OrderLibrary
|
||||||
|
url = ssh://git@dev-gitea.ftewa.ti.unibw-hamburg.de:12000/hwinkel/OrderLibrary.git
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ IF(NOT TARGET ixwebsocket)
|
|||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
|
||||||
|
IF(NOT TARGET easywsclient)
|
||||||
|
add_library(easywsclient STATIC libs/easywsclient/easywsclient.hpp libs/easywsclient/easywsclient.cpp)
|
||||||
|
target_include_directories( easywsclient PUBLIC libs/easywsclient/ )
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
|
||||||
add_library(SimControl STATIC
|
add_library(SimControl STATIC
|
||||||
|
|
||||||
include/SimControl/SimControl.hpp
|
include/SimControl/SimControl.hpp
|
||||||
@@ -47,7 +53,10 @@ add_library(SimControl STATIC
|
|||||||
|
|
||||||
include/SimControl/Tracklist.hpp
|
include/SimControl/Tracklist.hpp
|
||||||
src/SimControl/Tracklist.cpp
|
src/SimControl/Tracklist.cpp
|
||||||
)
|
|
||||||
|
include/SimControl/TrackItem.hpp
|
||||||
|
src/SimControl/TrackItem.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(SimControl
|
target_link_libraries(SimControl
|
||||||
@@ -98,9 +107,13 @@ IF (${TEST_SIMCONTROLLER_LIBRARY})
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
add_executable(test_podlist tests/test_podlist.cpp)
|
add_executable(test_tracklist tests/test_tracklist.cpp)
|
||||||
target_link_libraries(test_podlist Catch2::Catch2 SimControl loguru)
|
target_link_libraries(test_tracklist Catch2::Catch2 SimControl loguru)
|
||||||
catch_discover_tests(test_podlist)
|
catch_discover_tests(test_tracklist)
|
||||||
|
|
||||||
|
add_executable(test_Simcontrol tests/test_Simcontrol.cpp)
|
||||||
|
target_link_libraries(test_Simcontrol Catch2::Catch2 SimControl easywsclient loguru)
|
||||||
|
catch_discover_tests(test_Simcontrol)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
39
Dockerfile
39
Dockerfile
@@ -24,32 +24,33 @@ RUN apt-get -y install tcpdump nano netcat-openbsd htop
|
|||||||
RUN apt-get -y install libsodium23 libuuid1 libstdc++5 libcurl4 libcurl4-gnutls-dev
|
RUN apt-get -y install libsodium23 libuuid1 libstdc++5 libcurl4 libcurl4-gnutls-dev
|
||||||
|
|
||||||
# copy all custom buld libs
|
# copy all custom buld libs
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/libzmq/lib/libzmq.so.5 /usr/lib/
|
|
||||||
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/libzmq/lib/libzmq.so.5 /usr/lib/
|
||||||
# COPY build/libs/EntityLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/libprotobuf.so.32 /usr/lib/
|
# COPY build/libs/EntityLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/libprotobuf.so.32 /usr/lib/
|
||||||
# COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/libprotobuf.so.32 /usr/lib/
|
# COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/libprotobuf.so.32 /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/libprotobufd.so.25.0.0 /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/libprotobuf*.so.25.0.0 /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/crc/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/crc/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/base/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/base/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/log/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/log/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/debugging/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/debugging/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/flags/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/flags/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/container/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/container/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/hash/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/hash/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/numeric/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/numeric/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/profiling/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/profiling/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/status/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/status/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/strings/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/strings/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/synchronization/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/synchronization/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/time/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/time/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/types/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/types/*.so.* /usr/lib/
|
||||||
|
|
||||||
|
|
||||||
COPY build/libs/SimCore/libs/geographiclib/src/libGeographicLib.so.23 /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/geographiclib/src/libGeographicLib.so.23 /usr/lib/
|
||||||
COPY build/libs/KubeControl/libs/yaml-cpp/libyaml-cpp.so.0.8 /usr/lib/
|
# COPY build/libs/KubeControl/libs/yaml-cpp/libyaml-cpp.so.0.8 /usr/lib/
|
||||||
COPY build/libs/KubeControl/libs/curlpp/libcurlpp.so.1 /usr/lib/
|
COPY build/libs/KubeControl/libs/curlpp/libcurlpp.so.1 /usr/lib/
|
||||||
# COPY build/libs/EntityLibrary/libs/SimCore/libs/crossguid/libcrossguid.so.0 /usr/lib/
|
# COPY build/libs/EntityLibrary/libs/SimCore/libs/crossguid/libcrossguid.so.0 /usr/lib/
|
||||||
# COPY build/libs/SimCore/libs/crossguid/libcrossguid.so.0 /usr/lib/
|
# COPY build/libs/SimCore/libs/crossguid/libcrossguid.so.0 /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/crossguid/libcrossguid-dgb.so.0 /usr/lib/
|
# COPY build/libs/SimCore/libs/crossguid/libcrossguid-dgb.so.0 /usr/lib/
|
||||||
|
|
||||||
COPY build/libs/ixwebsocket/libixwebsocket.so.0.1.0 /usr/lib/
|
COPY build/libs/ixwebsocket/libixwebsocket.so.0.1.0 /usr/lib/
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ function(protobuf_generate_cpp)
|
|||||||
${ARGN})
|
${ARGN})
|
||||||
|
|
||||||
FILE(GLOB PROTO_FILES ${protobuf_PROTO_PATH}/*.proto)
|
FILE(GLOB PROTO_FILES ${protobuf_PROTO_PATH}/*.proto)
|
||||||
set(PROTOC ${CMAKE_BINARY_DIR}/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/protoc)
|
set(PROTOC ${CMAKE_BINARY_DIR}/libs/OrderLibrary/libs/SimCore/libs/SimCom/libs/protobuf/protoc)
|
||||||
message(STATUS "protoc path: " ${PROTOC})
|
message(STATUS "protoc path: " ${PROTOC})
|
||||||
|
|
||||||
FOREACH(proto ${PROTO_FILES})
|
FOREACH(proto ${PROTO_FILES})
|
||||||
@@ -28,7 +28,7 @@ function(protobuf_generate_cpp)
|
|||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT "${protoDIR}/${protoFILENAME}.pb.cc"
|
OUTPUT "${protoDIR}/${protoFILENAME}.pb.cc"
|
||||||
DEPENDS "${protoDIR}/${protoFILENAME}.proto"
|
DEPENDS "${protoDIR}/${protoFILENAME}.proto"
|
||||||
COMMAND ${PROTOC} --cpp_out=${protoDIR} --proto_path=${protoDIR} --proto_path="${CMAKE_SOURCE_DIR}/libs/OrderLibrary/libs/SimCore/include/SimCore/Messages/Protos" --proto_path="${CMAKE_SOURCE_DIR}/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/src" "${protoDIR}/${protoFILENAME}.proto"
|
COMMAND ${PROTOC} --cpp_out=${protoDIR} --proto_path=${protoDIR} --proto_path="${CMAKE_SOURCE_DIR}/libs/OrderLibrary/libs/SimCore/include/SimCore/Messages/Protos" --proto_path="${CMAKE_SOURCE_DIR}/libs/OrderLibrary/libs/SimCore/libs/SimCom/libs/protobuf/src" "${protoDIR}/${protoFILENAME}.proto"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ class SimControl{
|
|||||||
~SimControl();
|
~SimControl();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
|
||||||
|
std::string sendRecvMessageToClient( std::string ip, std::string port,WHISPER::Message msg, bool waitForResponse );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool online_;
|
bool online_;
|
||||||
|
|
||||||
@@ -56,7 +59,7 @@ class SimControl{
|
|||||||
|
|
||||||
|
|
||||||
void startShip(std::string name);
|
void startShip(std::string name);
|
||||||
void startNewShip(std::string Name, std::string lat, std::string lon, std::string height , std::string course, std::string speed);
|
void startNewShip(std::string Name, std::string lat, std::string lon, std::string height , std::string course, std::string speed, bool WaitTillRunning = true);
|
||||||
void updateShip(nlohmann::json request);
|
void updateShip(nlohmann::json request);
|
||||||
void deleteShip(nlohmann::json request);
|
void deleteShip(nlohmann::json request);
|
||||||
|
|
||||||
|
|||||||
65
include/SimControl/TrackItem.hpp
Normal file
65
include/SimControl/TrackItem.hpp
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "SimCore/Messages/SimTrack.hpp"
|
||||||
|
#include "nlohmann/json_fwd.hpp"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace SimControl
|
||||||
|
{
|
||||||
|
|
||||||
|
class TrackItem : public SimCore::SimTrack
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Track Item object
|
||||||
|
*
|
||||||
|
* @param track
|
||||||
|
*/
|
||||||
|
TrackItem(SimCore::SimTrack track);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief mark track as deleteed
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void markAsDelete();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @return true if is marked as deleted
|
||||||
|
* @return false if not
|
||||||
|
*/
|
||||||
|
bool isMarkedAsDelete();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the Last Update Timestamp object
|
||||||
|
*
|
||||||
|
* @return std::chrono::time_point<std::chrono::system_clock>
|
||||||
|
*/
|
||||||
|
std::time_t getLastUpdateTimestamp();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @return nlohmann::json
|
||||||
|
*/
|
||||||
|
nlohmann::json toJSON();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @return std::string
|
||||||
|
*/
|
||||||
|
std::string toString();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool markedAsDeleted;
|
||||||
|
std::time_t lastReceiveTimestamp_;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,20 +5,28 @@
|
|||||||
|
|
||||||
#include "nlohmann/json_fwd.hpp"
|
#include "nlohmann/json_fwd.hpp"
|
||||||
#include <SimCore/Identifier.hpp>
|
#include <SimCore/Identifier.hpp>
|
||||||
#include <SimCore/Messages/SimTrack.hpp>
|
#include <SimControl/TrackItem.hpp>
|
||||||
|
#include <cstddef>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace SimControl
|
namespace SimControl
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TrackList
|
class TrackList
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TrackList();
|
TrackList();
|
||||||
void addTrack(std::shared_ptr<SimCore::SimTrack> Track);
|
void addTrack(std::shared_ptr<SimControl::TrackItem> Track);
|
||||||
std::shared_ptr<SimCore::SimTrack> getTrack(SimCore::Identifier);
|
std::shared_ptr<SimControl::TrackItem> getTrack(SimCore::Identifier);
|
||||||
|
|
||||||
void deleteTrack(std::string ID);
|
void deleteTrack(std::string ID);
|
||||||
void deleteTrack(SimCore::Identifier);
|
void deleteTrack(SimCore::Identifier);
|
||||||
@@ -26,11 +34,18 @@ namespace SimControl
|
|||||||
|
|
||||||
|
|
||||||
void getJsonTRackList(nlohmann::json &message);
|
void getJsonTRackList(nlohmann::json &message);
|
||||||
|
size_t getTracklistSize();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable std::mutex mx_;
|
mutable std::mutex mx_;
|
||||||
std::map<std::string, std::shared_ptr<SimCore::SimTrack>> TrackStore_;
|
std::map<std::string, std::shared_ptr<SimControl::TrackItem>> TrackStore_;
|
||||||
|
|
||||||
|
// std::map<std::string, std::time_t> markedAsDeletedTracks_;
|
||||||
|
|
||||||
|
void checkTracksTimeout();
|
||||||
|
|
||||||
|
const int TrackTimeoutTime = 6;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Submodule libs/KubeControl updated: f11742ce64...b645005aeb
Submodule libs/OrderLibrary updated: 9d892fdcb6...650028c84a
1
libs/easywsclient
Submodule
1
libs/easywsclient
Submodule
Submodule libs/easywsclient added at afc1d8cfc5
@@ -2,13 +2,16 @@
|
|||||||
#include <SimCore/Identifier.hpp>
|
#include <SimCore/Identifier.hpp>
|
||||||
#include "DirectCommunicationServer.hpp"
|
#include "DirectCommunicationServer.hpp"
|
||||||
#include "GeographicLib/Geodesic.hpp"
|
#include "GeographicLib/Geodesic.hpp"
|
||||||
|
#include "Orders/TracklistRequest.hpp"
|
||||||
#include "SimControl/Tracklist.hpp"
|
#include "SimControl/Tracklist.hpp"
|
||||||
#include "SimCore/Messages/Control.hpp"
|
#include "SimCore/Messages/Control.hpp"
|
||||||
#include "SimCore/Messages/SimTrack.hpp"
|
#include "SimCore/Messages/SimTrack.hpp"
|
||||||
|
#include "SimCore/Messages/TracklistUpdate.hpp"
|
||||||
#include "SimCore/SimCore.hpp"
|
#include "SimCore/SimCore.hpp"
|
||||||
#include "SimCore/UtilFunctions.hpp"
|
#include "SimCore/UtilFunctions.hpp"
|
||||||
#include "WHISPER/InternalUDPListener.hpp"
|
#include "WHISPER/InternalUDPListener.hpp"
|
||||||
#include "WHISPER/Messages/Message.hpp"
|
#include "WHISPER/Messages/Message.hpp"
|
||||||
|
#include "WHISPER/Messages/stringData.hpp"
|
||||||
#include "crossguid/guid.hpp"
|
#include "crossguid/guid.hpp"
|
||||||
#include "ixwebsocket/IXConnectionState.h"
|
#include "ixwebsocket/IXConnectionState.h"
|
||||||
#include "ixwebsocket/IXWebSocket.h"
|
#include "ixwebsocket/IXWebSocket.h"
|
||||||
@@ -17,12 +20,16 @@
|
|||||||
#include "nlohmann/json_fwd.hpp"
|
#include "nlohmann/json_fwd.hpp"
|
||||||
#include <SimControl/SimControl.hpp>
|
#include <SimControl/SimControl.hpp>
|
||||||
|
|
||||||
|
#include <SimControl/TrackItem.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <future>
|
#include <future>
|
||||||
|
#include <iterator>
|
||||||
#include <loguru.hpp>
|
#include <loguru.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -35,7 +42,12 @@ namespace SimControl {
|
|||||||
|
|
||||||
|
|
||||||
SimControl::SimControl(bool online,std::string CommandPort,std::string GroundTruthAddr, ushort GroundTruthPort,std::string Namespace):
|
SimControl::SimControl(bool online,std::string CommandPort,std::string GroundTruthAddr, ushort GroundTruthPort,std::string Namespace):
|
||||||
online_(online),CommandPort_(CommandPort),GroundTruthAddr_(GroundTruthAddr),GroundTruthPort_(GroundTruthPort),Namespace_(Namespace),ID_(SimCore::Identifier(xg::newGuid()))
|
online_(online),
|
||||||
|
CommandPort_(CommandPort),
|
||||||
|
GroundTruthAddr_(GroundTruthAddr),
|
||||||
|
GroundTruthPort_(GroundTruthPort),
|
||||||
|
Namespace_(Namespace),
|
||||||
|
ID_(SimCore::Identifier(xg::newGuid()))
|
||||||
{
|
{
|
||||||
// BroadcastListener_ = std::make_shared<WHISPER::InternalUDPListener>("239.0.0.1",10000);
|
// BroadcastListener_ = std::make_shared<WHISPER::InternalUDPListener>("239.0.0.1",10000);
|
||||||
BroadcastListener_ = std::make_shared<WHISPER::InternalUDPListener>(GroundTruthAddr_,GroundTruthPort_);
|
BroadcastListener_ = std::make_shared<WHISPER::InternalUDPListener>(GroundTruthAddr_,GroundTruthPort_);
|
||||||
@@ -44,17 +56,12 @@ namespace SimControl {
|
|||||||
BroadcastListener_->connect();
|
BroadcastListener_->connect();
|
||||||
BroadcastListener_->subscribe(WHISPER::MsgTopics::TRACK);
|
BroadcastListener_->subscribe(WHISPER::MsgTopics::TRACK);
|
||||||
|
|
||||||
PodController_ = std::make_unique<kubecontrol::PodController>("docs/config");
|
if(online)
|
||||||
ExternalTCPServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(5000);
|
{
|
||||||
ExternalTCPServer_->registerMessageCallback(std::bind(&SimControl::HandleTCPMessage,this,std::placeholders::_1));
|
PodController_ = std::make_unique<kubecontrol::PodController>("docs/config");
|
||||||
// TCPClient_ = std::make_unique<DirectCommunication::DirectCommunicationClient>(30200,"192.168.252.6");
|
}
|
||||||
// TCPClient_ = std::make_unique<DirectCommunication::DirectCommunicationClient>(5555,"127.0.0.1");
|
|
||||||
|
|
||||||
// TCPClient_->registerMessageCallback(std::bind(&SimControl::HandleMessage,this,std::placeholders::_1));
|
|
||||||
// TCPClient_->sendMessage("Hello Server");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
WebsocketServer_ = std::make_shared<ix::WebSocketServer>(port,host);
|
WebsocketServer_ = std::make_shared<ix::WebSocketServer>(port,host);
|
||||||
WebsocketServer_->setOnClientMessageCallback( [this](std::shared_ptr<ix::ConnectionState> connectionState, ix::WebSocket &websocket, const ix::WebSocketMessagePtr &msg)
|
WebsocketServer_->setOnClientMessageCallback( [this](std::shared_ptr<ix::ConnectionState> connectionState, ix::WebSocket &websocket, const ix::WebSocketMessagePtr &msg)
|
||||||
{
|
{
|
||||||
@@ -103,8 +110,10 @@ namespace SimControl {
|
|||||||
|
|
||||||
void SimControl::stop()
|
void SimControl::stop()
|
||||||
{
|
{
|
||||||
|
if(PodController_ != nullptr)
|
||||||
PodController_->stopAllPods();
|
{
|
||||||
|
PodController_->stopAllPods();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimControl::HandleMessage(std::string msg)
|
void SimControl::HandleMessage(std::string msg)
|
||||||
@@ -138,8 +147,11 @@ namespace SimControl {
|
|||||||
auto track = SimCore::SimTrack::unpack(msg);
|
auto track = SimCore::SimTrack::unpack(msg);
|
||||||
if (track != nullptr)
|
if (track != nullptr)
|
||||||
{
|
{
|
||||||
|
auto item = std::make_shared<TrackItem>(*track);
|
||||||
|
|
||||||
// LOG_S(INFO)<<"Track received";
|
// LOG_S(INFO)<<"Track received";
|
||||||
Tracklist_->addTrack(std::move(track));
|
Tracklist_->addTrack(item);
|
||||||
|
LOG_S(INFO)<<Tracklist_->getTracklistSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -170,7 +182,7 @@ namespace SimControl {
|
|||||||
|
|
||||||
if (msg->type == ix::WebSocketMessageType::Open)
|
if (msg->type == ix::WebSocketMessageType::Open)
|
||||||
{
|
{
|
||||||
// LOG_S(INFO)<< "New connection" ;
|
LOG_S(INFO)<< "New connection" ;
|
||||||
|
|
||||||
// A connection state object is available, and has a default id
|
// A connection state object is available, and has a default id
|
||||||
// You can subclass ConnectionState and pass an alternate factory
|
// You can subclass ConnectionState and pass an alternate factory
|
||||||
@@ -198,9 +210,7 @@ namespace SimControl {
|
|||||||
nlohmann::json response;
|
nlohmann::json response;
|
||||||
response["Data"] = "COP";
|
response["Data"] = "COP";
|
||||||
Tracklist_->getJsonTRackList(response);
|
Tracklist_->getJsonTRackList(response);
|
||||||
LOG_S(INFO)<<"Tracklist size: " << Tracklist_->getTracklistSize();
|
|
||||||
|
|
||||||
// LOG_S(INFO)<<response;
|
|
||||||
websocket.send(response.dump());
|
websocket.send(response.dump());
|
||||||
}else if(j["Type"] == "EntityTrackList")
|
}else if(j["Type"] == "EntityTrackList")
|
||||||
{
|
{
|
||||||
@@ -209,7 +219,6 @@ namespace SimControl {
|
|||||||
{
|
{
|
||||||
nlohmann::json response;
|
nlohmann::json response;
|
||||||
this->getTrackListForEntity(j["ID"].get<std::string>(),response);
|
this->getTrackListForEntity(j["ID"].get<std::string>(),response);
|
||||||
|
|
||||||
websocket.send(response.dump());
|
websocket.send(response.dump());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,6 +236,7 @@ namespace SimControl {
|
|||||||
|
|
||||||
}else if(j["Type"] == "Delete")
|
}else if(j["Type"] == "Delete")
|
||||||
{
|
{
|
||||||
|
LOG_S(INFO)<< j;
|
||||||
deleteShip(j);
|
deleteShip(j);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,6 +263,8 @@ namespace SimControl {
|
|||||||
{
|
{
|
||||||
nlohmann::json response;
|
nlohmann::json response;
|
||||||
response["Message"] = "Hello world";
|
response["Message"] = "Hello world";
|
||||||
|
LOG_S(INFO)<<response;
|
||||||
|
|
||||||
websocket.send(response.dump());
|
websocket.send(response.dump());
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -308,13 +320,15 @@ namespace SimControl {
|
|||||||
// ShipPod1.setEnvironmentVar("GROUNDTRUTH_ADDR", "\""+this->GroundTruthAddr_+"\"");
|
// ShipPod1.setEnvironmentVar("GROUNDTRUTH_ADDR", "\""+this->GroundTruthAddr_+"\"");
|
||||||
// ShipPod1.setEnvironmentVar("COMMAND_PORT", "\""+CommandPort_+"\"");
|
// ShipPod1.setEnvironmentVar("COMMAND_PORT", "\""+CommandPort_+"\"");
|
||||||
|
|
||||||
ShipPod1.createYAML();
|
if(PodController_ != nullptr)
|
||||||
PodController_->startPod(ShipPod1);
|
{
|
||||||
|
PodController_->startPod(ShipPod1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SimControl::startNewShip(std::string Name, std::string lat, std::string lon, std::string height , std::string course, std::string speed)
|
void SimControl::startNewShip(std::string Name, std::string lat, std::string lon, std::string height , std::string course, std::string speed,bool WaitTillRunning )
|
||||||
{
|
{
|
||||||
LOG_S(INFO)<< "start New Ship";
|
LOG_S(INFO)<< "start New Ship";
|
||||||
|
|
||||||
@@ -347,20 +361,40 @@ namespace SimControl {
|
|||||||
ShipPod1.setEnvironmentVar("COMMAND_PORT", "\""+CommandPort_+"\"");
|
ShipPod1.setEnvironmentVar("COMMAND_PORT", "\""+CommandPort_+"\"");
|
||||||
ShipPod1.setEnvironmentVar("CONFIG", vars.dump());
|
ShipPod1.setEnvironmentVar("CONFIG", vars.dump());
|
||||||
|
|
||||||
ShipPod1.createYAML();
|
if(PodController_ != nullptr)
|
||||||
PodController_->startPod(ShipPod1);
|
{
|
||||||
|
PodController_->startPod(ShipPod1,WaitTillRunning);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string SimControl::sendRecvMessageToClient(std::string ip, std::string port,WHISPER::Message msg, bool waitForResponse)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
DirectCommunication::DirectCommunicationClient client(std::stoi(port),ip,this->ID_.getUUID());
|
||||||
|
LOG_S(INFO)<<"send message";
|
||||||
|
client.sendMessage("hello");
|
||||||
|
client.sendMessage(msg);
|
||||||
|
|
||||||
|
if(waitForResponse == true)
|
||||||
|
{
|
||||||
|
std::string message = client.getLatestMessage();
|
||||||
|
LOG_S(INFO)<<"message received " << message;
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
client.disconnect();
|
||||||
|
return "";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SimControl::updateShip(nlohmann::json request)
|
void SimControl::updateShip(nlohmann::json request)
|
||||||
{
|
{
|
||||||
LOG_S(INFO)<< "Update Ship: "<< request["ID"];
|
LOG_S(INFO)<< "Update Ship: "<< request["ID"];
|
||||||
|
|
||||||
// if (j["Type"] == ) {
|
|
||||||
// statements
|
|
||||||
// }
|
|
||||||
LOG_S(INFO)<< "Entity values:" << request;
|
LOG_S(INFO)<< "Entity values:" << request;
|
||||||
auto track = Tracklist_->getTrackBySringID(request["ID"].get<std::string>());
|
auto track = Tracklist_->getTrackBySringID(request["ID"].get<std::string>());
|
||||||
Orders::MoveOrder moveOrder(track->getIdentifier());
|
Orders::MoveOrder moveOrder(track->getIdentifier());
|
||||||
@@ -370,6 +404,7 @@ namespace SimControl {
|
|||||||
LOG_S(INFO)<<request["Course"].get<std::string>();
|
LOG_S(INFO)<<request["Course"].get<std::string>();
|
||||||
|
|
||||||
moveOrder.Speed.setValue(std::stod(request["Speed"].get<std::string>()));
|
moveOrder.Speed.setValue(std::stod(request["Speed"].get<std::string>()));
|
||||||
|
LOG_S(INFO)<<"Course as double"<< std::stod(request["Course"].get<std::string>());
|
||||||
moveOrder.Course.setValue(std::stod(request["Course"].get<std::string>()));
|
moveOrder.Course.setValue(std::stod(request["Course"].get<std::string>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,32 +420,40 @@ namespace SimControl {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto info = PodController_->getPodsInfo(request["ID"].get<std::string>());
|
if(PodController_ == nullptr)
|
||||||
if(info != nullptr)
|
|
||||||
{
|
{
|
||||||
LOG_S(INFO)<<"PODS Info: " <<info->ToJson();
|
return;
|
||||||
DirectCommunication::DirectCommunicationClient client(std::stoi(CommandPort_),info->Ip);
|
|
||||||
client.sendMessage(moveOrder.buildMessage().serialize());
|
|
||||||
// client.disconnect();
|
|
||||||
}
|
}
|
||||||
|
auto info = PodController_->getInfoForPod(request["ID"].get<std::string>());
|
||||||
|
|
||||||
|
|
||||||
|
LOG_S(INFO)<<"PODS Info: " <<info.Component;
|
||||||
|
DirectCommunication::DirectCommunicationClient client(std::stoi(CommandPort_),info.IP,ID_.getUUID());
|
||||||
|
client.sendMessage(moveOrder.buildMessage());
|
||||||
|
// client.disconnect();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimControl::deleteShip(nlohmann::json request)
|
void SimControl::deleteShip(nlohmann::json request)
|
||||||
{
|
{
|
||||||
LOG_S(INFO)<<"REQUEST: "<<request;
|
LOG_S(INFO)<<"REQUEST: "<<request;
|
||||||
PodController_->checkPodsHierarchy();
|
|
||||||
|
|
||||||
auto info = PodController_->getPodsInfo(request["ID"].get<std::string>());
|
|
||||||
if(info != nullptr)
|
|
||||||
{
|
|
||||||
LOG_S(INFO)<<"PODS Info: " <<info->ToJson();
|
|
||||||
DirectCommunication::DirectCommunicationClient client(std::stoi(CommandPort_),info->Ip);
|
|
||||||
SimCore::Control control(this->ID_,SimCore::ControlType::SHUT_DOWN,"Bye");
|
|
||||||
client.sendMessage(control.buildMessage().serialize());
|
|
||||||
client.disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if(PodController_ == nullptr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto info = PodController_->getInfoForPod(request["ID"].get<std::string>());
|
||||||
|
|
||||||
|
LOG_S(INFO)<<"PODS Info: " <<info.Component;
|
||||||
|
if(!std::empty(info.IP))
|
||||||
|
{
|
||||||
|
DirectCommunication::DirectCommunicationClient client(std::stoi(CommandPort_),info.IP,ID_.getUUID());
|
||||||
|
SimCore::Control control(this->ID_,SimCore::ControlType::SHUT_DOWN,"Bye");
|
||||||
|
client.sendMessage(control.buildMessage());
|
||||||
|
client.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
// std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
// std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
|
|
||||||
PodController_->stopPod(request["ID"]);
|
PodController_->stopPod(request["ID"]);
|
||||||
@@ -423,29 +466,67 @@ namespace SimControl {
|
|||||||
|
|
||||||
void SimControl::getTrackListForEntity(std::string id,nlohmann::json &j)
|
void SimControl::getTrackListForEntity(std::string id,nlohmann::json &j)
|
||||||
{
|
{
|
||||||
|
if(PodController_ == nullptr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// LOG_S(INFO)<<"REQUEST: "<<request;
|
// LOG_S(INFO)<<"REQUEST: "<<request;
|
||||||
PodController_->checkPodsHierarchy();
|
|
||||||
std::string response;
|
std::string response;
|
||||||
auto info = PodController_->getPodsInfo(id);
|
auto info = PodController_->getInfoForPod(id);
|
||||||
if(info != nullptr)
|
std::unique_ptr<kubecontrol::PodChild> cmsPod = nullptr;
|
||||||
{
|
bool hasCMS = false;
|
||||||
LOG_S(INFO)<<"PODS Info: " <<info->ToJson();
|
std::string IP = info.IP;
|
||||||
DirectCommunication::DirectCommunicationClient client(std::stoi(CommandPort_),info->Ip);
|
|
||||||
SimCore::Control control(this->ID_,SimCore::ControlType::GET_TRACKLIST,"Tracklist");
|
|
||||||
client.sendMessage(control.buildMessage().serialize());
|
|
||||||
response = client.getLatestMessage();
|
|
||||||
|
|
||||||
client.disconnect();
|
for (auto child: info.Childs) {
|
||||||
|
if (child.Component == "cms")
|
||||||
|
{
|
||||||
|
cmsPod = std::make_unique<kubecontrol::PodChild>(child);
|
||||||
|
hasCMS = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cmsPod == nullptr && hasCMS == true)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
IP = cmsPod->IP;
|
||||||
|
|
||||||
|
|
||||||
|
LOG_S(INFO)<<"PODS Info: " <<cmsPod->IP;
|
||||||
|
|
||||||
|
DirectCommunication::DirectCommunicationClient client(std::stoi(CommandPort_),IP,ID_.getUUID());
|
||||||
|
Orders::TracklistRequest TrackListRequest(ID_,SimCore::Identifier(id),true);
|
||||||
|
// SimCore::Control control(this->ID_,SimCore::ControlType::GET_TRACKLIST,"Tracklist");
|
||||||
|
client.sendMessage(TrackListRequest.buildMessage());
|
||||||
|
response = client.getLatestMessage();
|
||||||
|
client.disconnect();
|
||||||
if (response != "NULL")
|
if (response != "NULL")
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
nlohmann::json tracks = nlohmann::json::parse(response);
|
LOG_S(INFO)<<"raw data"<< response;
|
||||||
j["Tracks"] = tracks;
|
auto message = WHISPER::StringData(response);
|
||||||
|
LOG_S(INFO)<<"message from cms: "<< message.data_;
|
||||||
|
j["Tracks"] = nlohmann::json::parse(message.data_);
|
||||||
|
|
||||||
}catch (const std::exception e) {
|
// auto update = SimCore::TracklistUpdate::unpack(WHISPER::Message(response));
|
||||||
|
// if(update == nullptr)
|
||||||
|
// {
|
||||||
|
// LOG_S(INFO)<<"no update received";
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// nlohmann::json Jsontracks;
|
||||||
|
// auto tracks = update->getTracks();
|
||||||
|
// LOG_S(INFO)<<"Tracklist Update Size: " <<tracks.size();
|
||||||
|
// for(auto item : tracks)
|
||||||
|
// {
|
||||||
|
// Jsontracks.push_back(item.getsTrackListItemAsJSON());
|
||||||
|
// }
|
||||||
|
// j["Tracks"] = Jsontracks;
|
||||||
|
|
||||||
|
}catch (const std::exception &e) {
|
||||||
LOG_S(ERROR)<< e.what();
|
LOG_S(ERROR)<< e.what();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,12 +536,13 @@ namespace SimControl {
|
|||||||
|
|
||||||
void SimControl::startWebApp()
|
void SimControl::startWebApp()
|
||||||
{
|
{
|
||||||
|
if(PodController_ == nullptr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
kubecontrol::KubePod Webapp("controller","webapp","webapp","webapp:latest",Namespace_);
|
kubecontrol::KubePod Webapp("controller","webapp","webapp","webapp:latest",Namespace_);
|
||||||
Webapp.setEnvironmentVar("REACT_APP_WEBAPP_WS_URL", SimCore::UtilFunctions::getOwnIP());
|
Webapp.setEnvironmentVar("REACT_APP_WEBAPP_WS_URL", SimCore::UtilFunctions::getOwnIP());
|
||||||
|
|
||||||
Webapp.createYAML();
|
|
||||||
|
|
||||||
PodController_->startPod(Webapp);
|
PodController_->startPod(Webapp);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -501,7 +583,7 @@ namespace SimControl {
|
|||||||
double lat2, lon2;
|
double lat2, lon2;
|
||||||
geod.Direct(lat, lonTmp, 90, distance, lat2, lon2);
|
geod.Direct(lat, lonTmp, 90, distance, lat2, lon2);
|
||||||
|
|
||||||
SimControl::startNewShip(name, std::to_string(lat2), std::to_string(lon2), "0", "0", "0");
|
SimControl::startNewShip(name, std::to_string(lat2), std::to_string(lon2), "0", "0", "0",false);
|
||||||
lonTmp = lon2;
|
lonTmp = lon2;
|
||||||
counter ++;
|
counter ++;
|
||||||
}
|
}
|
||||||
@@ -523,27 +605,13 @@ namespace SimControl {
|
|||||||
{
|
{
|
||||||
// std::string uuid = xg::newGuid().str();
|
// std::string uuid = xg::newGuid().str();
|
||||||
if (online_ != false) {
|
if (online_ != false) {
|
||||||
startShip("hamburg");
|
|
||||||
startWebApp();
|
startWebApp();
|
||||||
|
startShip("hamburg");
|
||||||
|
startNewShip("Test", "55.16131", "7.86004", "0", "0", "0");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// LOG_S(INFO)<<PodController_->getInfoForPod("hamburg");
|
|
||||||
|
|
||||||
// auto IP = PodController_->getPodsInfo("hamburg")->Ip;
|
|
||||||
// TCPClient_ = std::make_shared<DirectCommunication::DirectCommunicationClient>(5555,IP);
|
|
||||||
// // Orders::MoveOrder order(this->ID_);
|
|
||||||
// order.Speed.setValue(0);
|
|
||||||
// TCPClient_->sendMessage(order.buildMessage().serialize());
|
|
||||||
|
|
||||||
|
|
||||||
// std::this_thread::sleep_for(std::chrono::milliseconds(10000));
|
|
||||||
// SimCore::Control shutdown(this->ID_,SimCore::SHUT_DOWN,"");
|
|
||||||
// TCPClient_->sendMessage(shutdown.buildMessage().serialize());
|
|
||||||
// // TCPClient_->disconnect();
|
|
||||||
// // TCPClient_.reset();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while (!stopMainThread_)
|
while (!stopMainThread_)
|
||||||
@@ -560,5 +628,4 @@ namespace SimControl {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
54
src/SimControl/TrackItem.cpp
Normal file
54
src/SimControl/TrackItem.cpp
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#include "SimCore/Messages/SimTrack.hpp"
|
||||||
|
#include "nlohmann/json.hpp"
|
||||||
|
#include <SimControl/TrackItem.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace SimControl
|
||||||
|
{
|
||||||
|
|
||||||
|
TrackItem::TrackItem(SimCore::SimTrack track)
|
||||||
|
:SimCore::SimTrack(track), markedAsDeleted(false),lastReceiveTimestamp_(time(0))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void TrackItem::markAsDelete()
|
||||||
|
{
|
||||||
|
markedAsDeleted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TrackItem::isMarkedAsDelete()
|
||||||
|
{
|
||||||
|
return markedAsDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::time_t TrackItem::getLastUpdateTimestamp()
|
||||||
|
{
|
||||||
|
return lastReceiveTimestamp_;
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json TrackItem::toJSON()
|
||||||
|
{
|
||||||
|
|
||||||
|
nlohmann::json j;
|
||||||
|
j["id"] = this->getIdentifier().getUUID();
|
||||||
|
j["Name"] = this->Name.getValue();
|
||||||
|
j["Course"] = this->Course.getValue();
|
||||||
|
j["Speed"] = this->Speed.getValue();
|
||||||
|
j["External"] = this->getIdentifier().isExternal();
|
||||||
|
j["Position"] = {this->getPosition().getGeodesicPos()[SimCore::LATITUDE], this->getPosition().getGeodesicPos()[SimCore::LONGITUDE]};
|
||||||
|
j["Height"] = this->getPosition().getGeodesicPos()[SimCore::HEIGHT];
|
||||||
|
j["Type"] = SimCore::Kind::EntityKindMap[this->EntityKind.getValue()];
|
||||||
|
j["Side"] = SimCore::Side::EntitySideMap[this->EntitySide.getValue()];
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
std::string TrackItem::toString()
|
||||||
|
{
|
||||||
|
return toJSON().dump();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
|
#include "SimControl/TrackItem.hpp"
|
||||||
#include "SimCore/SimCore.hpp"
|
#include "SimCore/SimCore.hpp"
|
||||||
#include "nlohmann/json_fwd.hpp"
|
#include "nlohmann/json_fwd.hpp"
|
||||||
#include <SimControl/Tracklist.hpp>
|
#include <SimControl/Tracklist.hpp>
|
||||||
|
#include <ctime>
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -8,75 +12,131 @@
|
|||||||
namespace SimControl
|
namespace SimControl
|
||||||
{
|
{
|
||||||
|
|
||||||
TrackList::TrackList()
|
TrackList::TrackList()
|
||||||
|
{
|
||||||
|
|
||||||
|
TrackStore_ = std::map<std::string, std::shared_ptr<SimControl::TrackItem>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrackList::addTrack(std::shared_ptr<SimControl::TrackItem> Track)
|
||||||
|
{
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(mx_);
|
||||||
|
checkTracksTimeout();
|
||||||
|
|
||||||
|
auto [iterator, inserted] = TrackStore_.try_emplace(Track->getIdentifier().getUUID(),Track);
|
||||||
|
if (!inserted)
|
||||||
|
{
|
||||||
|
if (iterator->second->isMarkedAsDelete() == false)
|
||||||
{
|
{
|
||||||
|
iterator->second = Track;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
mx_.unlock();
|
||||||
|
LOG_S(INFO)<< "Track added new Size:" << this->getTracklistSize();
|
||||||
|
}
|
||||||
|
|
||||||
TrackStore_ = std::map<std::string, std::shared_ptr<SimCore::SimTrack>>();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void TrackList::addTrack(std::shared_ptr<SimCore::SimTrack> Track)
|
|
||||||
|
|
||||||
|
void TrackList::checkTracksTimeout()
|
||||||
|
{
|
||||||
|
|
||||||
|
for (std::map<std::string, std::shared_ptr<SimControl::TrackItem>>::iterator it=TrackStore_.begin(); it != TrackStore_.end();)
|
||||||
|
{
|
||||||
|
|
||||||
|
if ((time(0) - it->second->getLastUpdateTimestamp())>= TrackTimeoutTime )
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mx_);
|
it = TrackStore_.erase(it);
|
||||||
|
}else {
|
||||||
auto [iterator, inserted] = TrackStore_.try_emplace(Track->getIdentifier().getUUID(),Track);
|
it++;
|
||||||
if (!inserted) { iterator->second = Track; }
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
std::shared_ptr<SimCore::SimTrack> TrackList::getTrack(const SimCore::Identifier ID)
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::shared_ptr<SimControl::TrackItem> TrackList::getTrack(const SimCore::Identifier ID)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(mx_);
|
||||||
|
|
||||||
|
auto it = TrackStore_.find(ID.getUUID());
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<SimCore::SimTrack> TrackList::getTrackBySringID(std::string ID)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(mx_);
|
||||||
|
|
||||||
|
auto it = TrackStore_.find(ID);
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrackList::deleteTrack(std::string ID)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(mx_);
|
||||||
|
auto it = TrackStore_.find(ID);
|
||||||
|
if(it != TrackStore_.end())
|
||||||
|
{
|
||||||
|
it->second->markAsDelete();
|
||||||
|
// markedAsDeletedTracks_.emplace(std::make_pair(ID, std::time(0)));
|
||||||
|
// TrackStore_.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrackList::deleteTrack(SimCore::Identifier ID)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(mx_);
|
||||||
|
// markedAsDeletedTracks_.emplace(std::make_pair(ID.getUUID(), std::time(0)));
|
||||||
|
auto it = TrackStore_.find(ID.getUUID());
|
||||||
|
it->second->markAsDelete();
|
||||||
|
// TrackStore_.erase(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TrackList::getJsonTRackList(nlohmann::json &message)
|
||||||
|
{
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(mx_);
|
||||||
|
checkTracksTimeout();
|
||||||
|
try {
|
||||||
|
for (std::map<std::string, std::shared_ptr<SimControl::TrackItem>>::iterator it=TrackStore_.begin(); it!=TrackStore_.end(); ++it)
|
||||||
|
{
|
||||||
|
if(!it->second->isMarkedAsDelete())
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mx_);
|
message["Entities"].push_back(it->second->toJSON());
|
||||||
|
|
||||||
auto it = TrackStore_.find(ID.getUUID());
|
|
||||||
return it->second;
|
|
||||||
}
|
}
|
||||||
|
// nlohmann::json j;
|
||||||
|
// j["id"] = it->first;
|
||||||
|
// j["Name"] = it->second->Name.getValue();
|
||||||
|
// j["Course"] = it->second->Course.getValue();
|
||||||
|
// j["Speed"] = it->second->Speed.getValue();
|
||||||
|
// j["External"] = false;
|
||||||
|
// j["Position"] = {it->second->getPosition().getGeodesicPos()[SimCore::LATITUDE], it->second->getPosition().getGeodesicPos()[SimCore::LONGITUDE]};
|
||||||
|
// j["Height"] = it->second->getPosition().getGeodesicPos()[SimCore::HEIGHT];
|
||||||
|
// j["Type"] = SimCore::Kind::EntityKindMap[it->second->EntityKind.getValue()];
|
||||||
|
// j["Side"] = SimCore::Side::EntitySideMap[it->second->EntitySide.getValue()];
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<SimCore::SimTrack> TrackList::getTrackBySringID(std::string ID)
|
}
|
||||||
{
|
}catch (const std::exception e) {
|
||||||
std::lock_guard<std::mutex> lock(mx_);
|
LOG_S(ERROR)<< e.what();
|
||||||
|
}
|
||||||
auto it = TrackStore_.find(ID);
|
}
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackList::deleteTrack(std::string ID)
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(mx_);
|
|
||||||
auto it = TrackStore_.find(ID);
|
|
||||||
TrackStore_.erase(it);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrackList::deleteTrack(SimCore::Identifier ID)
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(mx_);
|
|
||||||
auto it = TrackStore_.find(ID.getUUID());
|
|
||||||
TrackStore_.erase(it);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TrackList::getJsonTRackList(nlohmann::json &message)
|
size_t TrackList::getTracklistSize()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mx_);
|
std::lock_guard<std::mutex> lock(mx_);
|
||||||
try {
|
size_t size = this->TrackStore_.size();
|
||||||
for (std::map<std::string, std::shared_ptr<SimCore::SimTrack>>::iterator it=TrackStore_.begin(); it!=TrackStore_.end(); ++it)
|
return size;
|
||||||
{
|
|
||||||
nlohmann::json j;
|
}
|
||||||
j["id"] = it->first;
|
|
||||||
j["Name"] = it->second->Name.getValue();
|
|
||||||
j["Course"] = it->second->Course.getValue();
|
|
||||||
j["Speed"] = it->second->Speed.getValue();
|
|
||||||
j["External"] = false;
|
|
||||||
j["Position"] = {it->second->getPosition().getGeodesicPos()[SimCore::LATITUDE], it->second->getPosition().getGeodesicPos()[SimCore::LONGITUDE]};
|
|
||||||
j["Height"] = it->second->getPosition().getGeodesicPos()[SimCore::HEIGHT];
|
|
||||||
j["Type"] = SimCore::Kind::EntityKindMap[it->second->EntityKind.getValue()];
|
|
||||||
j["Side"] = SimCore::Side::EntitySideMap[it->second->EntitySide.getValue()];
|
|
||||||
|
|
||||||
message["Entities"].push_back(j);
|
|
||||||
}
|
|
||||||
}catch (const std::exception e) {
|
|
||||||
LOG_S(ERROR)<< e.what();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,11 +42,11 @@ int main()
|
|||||||
}
|
}
|
||||||
const char* GroundTruthAddr = "239.0.0.1";
|
const char* GroundTruthAddr = "239.0.0.1";
|
||||||
if (std::getenv("GROUNDTRUTH_ADDR") != nullptr) {
|
if (std::getenv("GROUNDTRUTH_ADDR") != nullptr) {
|
||||||
CommandPortChar = std::getenv("GROUNDTRUTH_ADDR");
|
GroundTruthAddr = std::getenv("GROUNDTRUTH_ADDR");
|
||||||
}
|
}
|
||||||
const char* GroundTruthPort = "10000";
|
const char* GroundTruthPort = "10000";
|
||||||
if (std::getenv("GROUNDTRUTH_PORT") != nullptr) {
|
if (std::getenv("GROUNDTRUTH_PORT") != nullptr) {
|
||||||
CommandPortChar = std::getenv("GROUNDTRUTH_PORT");
|
GroundTruthPort = std::getenv("GROUNDTRUTH_PORT");
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* Namespace = "simulator";
|
const char* Namespace = "simulator";
|
||||||
@@ -67,6 +67,8 @@ int main()
|
|||||||
|
|
||||||
LOG_S(INFO)<<"online:" << online;
|
LOG_S(INFO)<<"online:" << online;
|
||||||
|
|
||||||
|
LOG_S(INFO)<< "command port"<< CommandPortChar;
|
||||||
|
|
||||||
SimControl::SimControl sc(online,CommandPortChar,GroundTruthAddr,SimCore::UtilFunctions::StringToUShort(GroundTruthPort),Namespace);
|
SimControl::SimControl sc(online,CommandPortChar,GroundTruthAddr,SimCore::UtilFunctions::StringToUShort(GroundTruthPort),Namespace);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
232
tests/test_Simcontrol.cpp
Normal file
232
tests/test_Simcontrol.cpp
Normal file
@@ -0,0 +1,232 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include "SimControl/SimControl.hpp"
|
||||||
|
|
||||||
|
#include "SimCore/Messages/SensorTrack.hpp"
|
||||||
|
#include "nlohmann/json_fwd.hpp"
|
||||||
|
#include <fstream>
|
||||||
|
#include <future>
|
||||||
|
#include <memory>
|
||||||
|
#include <queue>
|
||||||
|
#include <string>
|
||||||
|
#define CATCH_CONFIG_MAIN
|
||||||
|
#include "SimControl/PodList.hpp"
|
||||||
|
#include <catch2/catch.hpp>
|
||||||
|
#include <loguru.hpp>
|
||||||
|
|
||||||
|
#include <Orders/TracklistRequest.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "easywsclient.hpp"
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <SimCore/Messages/TracklistUpdate.hpp>
|
||||||
|
#include <SimCore/Messages/TracklistItem.hpp>
|
||||||
|
|
||||||
|
// std::shared_ptr<SimControl::SimControl> sc;
|
||||||
|
struct HelpMessage{
|
||||||
|
std::string IP;
|
||||||
|
std::string Port;
|
||||||
|
WHISPER::Message msg;
|
||||||
|
} ;
|
||||||
|
WHISPER::threadSafeQueue<HelpMessage> Wmsgqueue_in_;
|
||||||
|
|
||||||
|
int runSimConntrol(bool *running)
|
||||||
|
{
|
||||||
|
SimControl::SimControl sc(false,"CommandPortChar","5555",SimCore::UtilFunctions::StringToUShort("10000"),"simulator");
|
||||||
|
// sc = std::make_shared<SimControl::SimControl>(false,"CommandPortChar","5555",SimCore::UtilFunctions::StringToUShort("10000"),"simulator");
|
||||||
|
|
||||||
|
while (*running) {
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
// LOG_S(INFO)<<*running;
|
||||||
|
if (Wmsgqueue_in_.size()> 0)
|
||||||
|
{
|
||||||
|
auto msg = Wmsgqueue_in_.get();
|
||||||
|
sc.sendRecvMessageToClient(msg.IP,msg.Port,msg.msg, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
LOG_S(INFO)<<"stopping ";
|
||||||
|
sc.stop();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
WHISPER::threadSafeQueue<std::string> msgqueue_in_;
|
||||||
|
WHISPER::threadSafeQueue<std::string> msgqueue_out_;
|
||||||
|
|
||||||
|
// std::queue<std::string> msgqueue_in_;
|
||||||
|
// std::queue<std::string> msgqueue_out_;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void handle_message(std::string m)
|
||||||
|
{
|
||||||
|
LOG_S(INFO)<<m;
|
||||||
|
msgqueue_in_.addElement(m);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wsFunction(bool *running)
|
||||||
|
{
|
||||||
|
std::unique_ptr<easywsclient::WebSocket> ws(easywsclient::WebSocket::from_url("ws://localhost:9999/"));
|
||||||
|
|
||||||
|
|
||||||
|
while (*running)
|
||||||
|
{
|
||||||
|
ws->poll();
|
||||||
|
ws->dispatch(handle_message);
|
||||||
|
while(msgqueue_out_.size() > 0)
|
||||||
|
{
|
||||||
|
ws->send(msgqueue_out_.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
ws->close();
|
||||||
|
|
||||||
|
}
|
||||||
|
double fRand(double fMin, double fMax)
|
||||||
|
{
|
||||||
|
double f = (double)rand() / RAND_MAX;
|
||||||
|
return fMin + f * (fMax - fMin);
|
||||||
|
}
|
||||||
|
void addTracksToTracklistUpdate(SimCore::TracklistUpdate *update, int amount)
|
||||||
|
{
|
||||||
|
|
||||||
|
for(int i = 0; i < amount; i++)
|
||||||
|
{
|
||||||
|
std::string name = "test1-" + std::to_string(i);
|
||||||
|
auto track = std::make_shared<SimCore::SensorTrack>(name,SimCore::Kind::EntityKind::SURFACE,SimCore::Side::NEUTRAL);
|
||||||
|
SimCore::Position pos;
|
||||||
|
double lat = fRand(-90, 90);
|
||||||
|
double lon = fRand(-180, 180);
|
||||||
|
|
||||||
|
pos.setGeodesicPos( lat, lon, 0);
|
||||||
|
track->setPosition(pos);
|
||||||
|
SimCore::TracklistItem item(track);
|
||||||
|
update->addTrack(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::atomic_bool TracklistRequestReceived;
|
||||||
|
|
||||||
|
void serverCallback(std::string msg)
|
||||||
|
{
|
||||||
|
|
||||||
|
// LOG_S(INFO)<<msg;
|
||||||
|
WHISPER::Message Wmsg_(msg);
|
||||||
|
|
||||||
|
switch (Wmsg_.msgType_)
|
||||||
|
{
|
||||||
|
case WHISPER::MsgType::ORDER:
|
||||||
|
{
|
||||||
|
Orders::OrderType OrderType = Orders::Order::getType(Wmsg_);
|
||||||
|
switch (OrderType)
|
||||||
|
{
|
||||||
|
case Orders::TRACKLIST_REQUEST:
|
||||||
|
{
|
||||||
|
auto TrackListRequest = Orders::TracklistRequest::unpack(Wmsg_);
|
||||||
|
if (TrackListRequest == nullptr)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
LOG_S(INFO)<<"tracklist request received";
|
||||||
|
TracklistRequestReceived = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SCENARIO("Testing the the podlist")
|
||||||
|
{
|
||||||
|
bool *running = new bool(true);
|
||||||
|
std::thread t1(runSimConntrol,running) ;
|
||||||
|
// auto res = std::async(std::launch::deferred,runSimConntrol,running);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
||||||
|
std::thread t2(wsFunction,running) ;
|
||||||
|
|
||||||
|
nlohmann::json j;
|
||||||
|
j["Data"] = "TEST";
|
||||||
|
|
||||||
|
bool gotMessage = false;
|
||||||
|
|
||||||
|
msgqueue_out_.addElement(j.dump());
|
||||||
|
|
||||||
|
|
||||||
|
GIVEN("different Attributes for a Track in different forms")
|
||||||
|
{
|
||||||
|
SimCore::Identifier ID_;
|
||||||
|
SimCore::Identifier ID1_;
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
|
|
||||||
|
DirectCommunication::DirectCommunicationServer server(5555,ID1_.getUUID());
|
||||||
|
server.registerMessageCallback(serverCallback);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
|
// auto client = std::make_unique<DirectCommunication::DirectCommunicationClient>(5001,"127.0.0.1",ID_.getUUID());
|
||||||
|
// client->sendMessage("test");
|
||||||
|
Orders::TracklistRequest TrackListRequest(ID_,ID1_);
|
||||||
|
|
||||||
|
HelpMessage msg1;
|
||||||
|
msg1.IP = "127.0.0.1";
|
||||||
|
msg1.Port = "5555";
|
||||||
|
msg1.msg = TrackListRequest.buildMessage();
|
||||||
|
Wmsgqueue_in_.addElement(msg1);
|
||||||
|
WHEN("constructing Track Object with data")
|
||||||
|
{
|
||||||
|
// std::string response = sc->sendRecvMessageToClient("127.0.0.1","5555",TrackListRequest.buildMessage(),false);
|
||||||
|
LOG_S(INFO)<<"sended";
|
||||||
|
// LOG_S(INFO)<<Helper.getLatesMessage().msgType_;
|
||||||
|
THEN("check if Track attributes are correct")
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
|
|
||||||
|
|
||||||
|
REQUIRE(TracklistRequestReceived == true );
|
||||||
|
|
||||||
|
if (TracklistRequestReceived == true)
|
||||||
|
{
|
||||||
|
SimCore::TracklistUpdate *update = new SimCore::TracklistUpdate(ID_);
|
||||||
|
|
||||||
|
int amount = 5;
|
||||||
|
addTracksToTracklistUpdate(update, amount);
|
||||||
|
LOG_S(INFO)<<update->getTracks().size();
|
||||||
|
REQUIRE(update->getTracks().size() == amount );
|
||||||
|
|
||||||
|
|
||||||
|
server.sendMessage(update->buildMessage());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_S(INFO)<<"stop";
|
||||||
|
*running = false;
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||||
|
|
||||||
|
|
||||||
|
auto j = nlohmann::json::parse(msgqueue_in_.get());
|
||||||
|
|
||||||
|
REQUIRE(j["Message"] == "Hello world" );
|
||||||
|
|
||||||
|
t1.join();
|
||||||
|
t2.join();
|
||||||
|
|
||||||
|
|
||||||
|
} //THEN
|
||||||
|
// client->disconnect();
|
||||||
|
} // WHEN
|
||||||
|
} // GIVEN
|
||||||
|
} //SCENARIO
|
||||||
113
tests/test_tracklist.cpp
Normal file
113
tests/test_tracklist.cpp
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include "SimControl/TrackItem.hpp"
|
||||||
|
#include "SimControl/Tracklist.hpp"
|
||||||
|
#include "SimCore/Identifier.hpp"
|
||||||
|
#include "SimCore/Messages/SimTrack.hpp"
|
||||||
|
#include "SimCore/Position.hpp"
|
||||||
|
#include "SimCore/SimCore.hpp"
|
||||||
|
#include <fstream>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
#define CATCH_CONFIG_MAIN
|
||||||
|
#include "SimControl/PodList.hpp"
|
||||||
|
#include <catch2/catch.hpp>
|
||||||
|
#include <loguru.hpp>
|
||||||
|
|
||||||
|
#include "string.cpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void createScenario(SimControl::TrackList *list,std::vector<std::string> *ids)
|
||||||
|
{
|
||||||
|
GeographicLib::Geodesic geod(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f());
|
||||||
|
double lat = 54, lon = 1;
|
||||||
|
int counter = 0;
|
||||||
|
double distance = 10000;
|
||||||
|
|
||||||
|
int rasterSize = 5;
|
||||||
|
|
||||||
|
for (int i = 0; i < rasterSize; i++ )
|
||||||
|
{
|
||||||
|
double lonTmp = lon;
|
||||||
|
for (int a = 0; a < rasterSize; a++)
|
||||||
|
{
|
||||||
|
|
||||||
|
std::string name = "test";
|
||||||
|
name += std::to_string(counter);
|
||||||
|
double lat2, lon2;
|
||||||
|
geod.Direct(lat, lonTmp, 90, distance, lat2, lon2);
|
||||||
|
|
||||||
|
SimCore::Identifier id;
|
||||||
|
ids->push_back(id.getUUID());
|
||||||
|
|
||||||
|
SimCore::Position pos;
|
||||||
|
pos.setGeodesicPos(lat2, lon2, 0);
|
||||||
|
auto track = std::make_shared<SimCore::SimTrack>(id,name,SimCore::Kind::EntityKind::SURFACE,SimCore::Side::NEUTRAL);
|
||||||
|
track->setPosition(pos);
|
||||||
|
list->addTrack(std::make_shared<SimControl::TrackItem>(*track));
|
||||||
|
// SimControl::startNewShip(name, std::to_string(lat2), std::to_string(lon2), "0", "0", "0");
|
||||||
|
lonTmp = lon2;
|
||||||
|
counter ++;
|
||||||
|
}
|
||||||
|
double lat2, lon2;
|
||||||
|
|
||||||
|
geod.Direct(lat, lon, 0, distance, lat2, lon2);
|
||||||
|
|
||||||
|
lat = lat2;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SCENARIO("Testing the the podlist")
|
||||||
|
{
|
||||||
|
|
||||||
|
std::vector<std::string> ids;
|
||||||
|
SimControl::TrackList list;
|
||||||
|
|
||||||
|
createScenario(&list,&ids);
|
||||||
|
|
||||||
|
auto track = list.getTrackBySringID(ids[3]);
|
||||||
|
|
||||||
|
// list.deleteTrack(track->getIdentifier());
|
||||||
|
|
||||||
|
// list.addTrack(track);
|
||||||
|
// std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
||||||
|
|
||||||
|
|
||||||
|
GIVEN("different Attributes for a Track in different forms")
|
||||||
|
{
|
||||||
|
|
||||||
|
WHEN("constructing Track Object with data")
|
||||||
|
{
|
||||||
|
|
||||||
|
THEN("check if Track attributes are correct")
|
||||||
|
{
|
||||||
|
REQUIRE(ids.size() == 25);
|
||||||
|
REQUIRE(list.getTracklistSize() == 25);
|
||||||
|
|
||||||
|
list.deleteTrack(track->getIdentifier());
|
||||||
|
|
||||||
|
list.addTrack(std::make_shared<SimControl::TrackItem>(*track));
|
||||||
|
// REQUIRE(list.getTracklistSize() == 24);
|
||||||
|
LOG_S(INFO)<<"wait for 7500ms";
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(7500));
|
||||||
|
LOG_S(INFO)<<"continue";
|
||||||
|
LOG_S(INFO)<<"add saved track";
|
||||||
|
list.addTrack(std::make_shared<SimControl::TrackItem>(*track));
|
||||||
|
LOG_S(INFO)<<"added saved track";
|
||||||
|
|
||||||
|
REQUIRE(list.getTracklistSize() == 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} //THEN
|
||||||
|
} // WHEN
|
||||||
|
} // GIVEN
|
||||||
|
} //SCENARIO
|
||||||
Reference in New Issue
Block a user