diff --git a/CMakeLists.txt b/CMakeLists.txt index 01086b6..01f13ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,9 @@ -cmake_minimum_required(VERSION 2.6.0) +cmake_minimum_required(VERSION 3.5.0) +set (CMAKE_CXX_STANDARD 11) -include_directories(include) +# project(proj VERSION 0.0.1 DESCRIPTION "GraphSDK wrapper to Julia system.") +# include_directories(include) +include_directories(src/test) add_subdirectory(src) diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 4d317af..099529e 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -14,8 +14,28 @@ find_library(ZeroMQ_LIBRARY PATHS ${PC_ZeroMQ_LIBRARY_DIRS} ) +message("CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR}") + +add_library(graffsdk SHARED GraffSDK.cpp) +# set_target_properties(graffsdk PROPERTIES VERSION ${PROJECT_VERSION}) +set_target_properties(graffsdk PROPERTIES PUBLIC_HEADER GraffSDK.h) +target_include_directories(graffsdk PRIVATE .) +include(GNUInstallDirs) +install(TARGETS graffsdk + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + add_executable(feitor-test main.cpp) ## add the include directory to our compile directives target_include_directories(feitor-test PUBLIC ${ZeroMQ_INCLUDE_DIR}) ## at the 0mq library to our link directive target_link_libraries(feitor-test PUBLIC ${ZeroMQ_LIBRARY}) +# target_link_libraries(feitor-test PUBLIC graffsdk) + +# the api testing program +add_executable(api-test apitest.cpp) +## add the include directory to our compile directives +target_include_directories(api-test PUBLIC ${ZeroMQ_INCLUDE_DIR}) +## at the 0mq library to our link directive +target_link_libraries(api-test PUBLIC ${ZeroMQ_LIBRARY}) +target_link_libraries(api-test PUBLIC graffsdk) diff --git a/src/test/GraffSDK.cpp b/src/test/GraffSDK.cpp new file mode 100644 index 0000000..528dc36 --- /dev/null +++ b/src/test/GraffSDK.cpp @@ -0,0 +1,17 @@ +// GraffSDK +#include "GraffSDK.h" +#include +#include "json.hpp" + +using nlohmann::json; + + +std::string getStatus(const GraffConfig &cfg) { + json request; + request["userId"] = cfg.userId; + request["robotId"] = cfg.robotId; + request["sessionId"] = cfg.sessionId; + request["type"] = "getStatus"; + std::string request_str = request.dump(2); // serialize + return request_str; +} diff --git a/src/test/GraffSDK.h b/src/test/GraffSDK.h new file mode 100644 index 0000000..ec55cdb --- /dev/null +++ b/src/test/GraffSDK.h @@ -0,0 +1,13 @@ +// GraffSDK + +#include +#include "json.hpp" + + +struct GraffConfig { + std::string userId; + std::string robotId; + std::string sessionId; +}; + +std::string getStatus(const GraffConfig &cfg); diff --git a/src/test/apitest.cpp b/src/test/apitest.cpp new file mode 100644 index 0000000..fd9b1fe --- /dev/null +++ b/src/test/apitest.cpp @@ -0,0 +1,77 @@ +#include +#include +#include +#include + +#include + +#include "json.hpp" +#include "GraffSDK.h" + +using nlohmann::json; + +const double PI = 3.141592653589793238463; + + + +int main(int argCount, char **argValues) { + // Prepare our context and socket + zmq::context_t context(1); + zmq::socket_t socket(context, ZMQ_REQ); + + std::cout << "Connecting to navi server…" << std::endl; + socket.connect("tcp://localhost:5555"); + + std::string robot_id = "FeitorBot"; + std::string session_id = "FeitorBotTestSession001"; + + GraffConfig gff; + gff.userId = "Pedro"; + gff.robotId = "PedroBot"; + gff.sessionId = "ThisIsACTest001"; + + std::cout << "made it this far" << std::endl; + + std::string stsr = getStatus(gff); + + zmq::message_t msg(stsr.length()); + memcpy(msg.data(), stsr.c_str(), stsr.length()); + socket.send(msg); + + + std::cout << "Asked for status" << std::endl; + + // for (int i = 0; i < 6; ++i) { + // create request + // json request; + // request["robot_id"] = robot_id; + // request["session_id"] = session_id; + // request["type"] = "AddOdometry2D"; + // request["measurement"] = {10.0, 0.0, PI / 3.0}; + // request["covariance"] = {{0.1, 0.0, 0.1}, {0.1, 0.0, 0.1}, {0.1, 0.0, 0.1}}; + // std::string request_str = request.dump(2); // serialize + // + // // send it + // zmq::message_t msg(request_str.length()); + // memcpy(msg.data(), request_str.c_str(), request_str.length()); + // socket.send(msg); + // + // std::cout << "Sent request " << i << "…"; + // + // // wait for reply + // zmq::message_t reply; + // if (socket.recv(&reply) < 0) { + // std::cerr << "something went wrong :("; + // break; + // } + // std::string result = + // std::string(static_cast(reply.data()), reply.size()); + // std::cout << result << "\n"; + // + // if (result.compare("OK")) { + // std::cerr << "server is unhappy with request." << "\n"; + // break; + // } + // } + return(0); +} diff --git a/src/test/main.cpp b/src/test/main.cpp index f7bdf1a..a15eb32 100644 --- a/src/test/main.cpp +++ b/src/test/main.cpp @@ -11,6 +11,8 @@ using nlohmann::json; const double PI = 3.141592653589793238463; + + int main(int argCount, char **argValues) { // Prepare our context and socket zmq::context_t context(1);