#include "SimControl/SimControl.hpp" #include "nlohmann/json_fwd.hpp" #include #include #include #include #include #define CATCH_CONFIG_MAIN #include "SimControl/PodList.hpp" #include #include #include #include "easywsclient.hpp" #include #include #include // std::shared_ptr sc; struct HelpMessage{ std::string IP; std::string Port; WHISPER::Message msg; } ; WHISPER::threadSafeQueue Wmsgqueue_in_; int runSimConntrol(bool *running) { SimControl::SimControl sc(false,"CommandPortChar","5555",SimCore::UtilFunctions::StringToUShort("10000"),"simulator"); // sc = std::make_shared(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 msgqueue_in_; WHISPER::threadSafeQueue msgqueue_out_; // std::queue msgqueue_in_; // std::queue msgqueue_out_; void handle_message(std::string m) { LOG_S(INFO)< 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(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)<(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)<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