From 79b43e6b2c788f08fd825645c772f82bb6c9cfae Mon Sep 17 00:00:00 2001 From: mbsaloka Date: Fri, 26 Apr 2024 20:33:46 +0700 Subject: [PATCH] feat: make proto grpc --- CMakeLists.txt | 64 ++++++++++++++++++++++++++++++++++++++++++-- msg/ColorSetting.msg | 7 +++++ proto/ninshiki.proto | 27 +++++++++++++++++++ 3 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 msg/ColorSetting.msg create mode 100644 proto/ninshiki.proto diff --git a/CMakeLists.txt b/CMakeLists.txt index 90b7737..7d02a61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 3.5) - project(ninshiki_interfaces) if(NOT CMAKE_C_STANDARD) @@ -17,12 +16,73 @@ endif() find_package(ament_cmake REQUIRED) find_package(rosidl_default_generators REQUIRED) +set(protobuf_MODULE_COMPATIBLE TRUE) +find_package(Protobuf CONFIG REQUIRED) +message(STATUS "Using protobuf ${Protobuf_VERSION}") + +find_package(gRPC CONFIG REQUIRED) +message(STATUS "Using gRPC ${gRPC_VERSION}") + +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/proto) +add_custom_command( + OUTPUT + "${CMAKE_CURRENT_BINARY_DIR}/proto/ninshiki.pb.cc" + "${CMAKE_CURRENT_BINARY_DIR}/proto/ninshiki.pb.h" + "${CMAKE_CURRENT_BINARY_DIR}/proto/ninshiki.grpc.pb.cc" + "${CMAKE_CURRENT_BINARY_DIR}/proto/ninshiki.grpc.pb.h" + COMMAND $ + ARGS + --grpc_out "${CMAKE_CURRENT_BINARY_DIR}/proto" + --cpp_out "${CMAKE_CURRENT_BINARY_DIR}/proto" + -I ${CMAKE_CURRENT_SOURCE_DIR}/proto + --plugin=protoc-gen-grpc=$ + ${CMAKE_CURRENT_SOURCE_DIR}/proto/ninshiki.proto + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/proto/ninshiki.proto +) + +add_library(ninshiki_proto SHARED + "${CMAKE_CURRENT_BINARY_DIR}/proto/ninshiki.pb.cc" + "${CMAKE_CURRENT_BINARY_DIR}/proto/ninshiki.pb.h" + "${CMAKE_CURRENT_BINARY_DIR}/proto/ninshiki.grpc.pb.cc" + "${CMAKE_CURRENT_BINARY_DIR}/proto/ninshiki.grpc.pb.h" +) + +target_compile_options(ninshiki_proto PRIVATE -fPIC) +target_compile_features(ninshiki_proto PUBLIC cxx_std_17) + +target_link_libraries(ninshiki_proto PUBLIC + protobuf::libprotobuf +) + rosidl_generate_interfaces(${PROJECT_NAME} "msg/DetectedObject.msg" "msg/DetectedObjects.msg" "msg/Point.msg" "msg/Contour.msg" - "msg/Contours.msg") + "msg/Contours.msg" + "msg/ColorSetting.msg") + +install ( + DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/proto/ + DESTINATION include/${PROJECT_NAME} +) + +install ( + TARGETS ninshiki_proto + EXPORT ninshiki_proto + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin + INCLUDES DESTINATION include +) + +if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + ament_lint_auto_find_test_dependencies() +endif() ament_export_dependencies(rosidl_default_runtime) + +ament_export_dependencies(rosidl_default_runtime protobuf gRPC) +ament_export_targets(ninshiki_proto HAS_LIBRARY_TARGET) ament_package() diff --git a/msg/ColorSetting.msg b/msg/ColorSetting.msg new file mode 100644 index 0000000..e20acca --- /dev/null +++ b/msg/ColorSetting.msg @@ -0,0 +1,7 @@ +string name +int32 min_hue +int32 max_hue +int32 min_saturation +int32 max_saturation +int32 min_value +int32 max_value diff --git a/proto/ninshiki.proto b/proto/ninshiki.proto new file mode 100644 index 0000000..7c4df5e --- /dev/null +++ b/proto/ninshiki.proto @@ -0,0 +1,27 @@ +syntax = "proto3"; + +package ninshiki_interfaces.proto; + +service Config { + rpc GetColorSetting (Empty) returns (ConfigColor) {} + + rpc SaveColorSetting (ConfigColor) returns (Empty) {} + + rpc SetColorSetting (ColorSetting) returns (Empty) {} +} + +message Empty {} + +message ConfigColor { + string json_color = 1; +} + +message ColorSetting { + string name = 1; + int32 min_hue = 2; + int32 max_hue = 3; + int32 min_saturation = 4; + int32 max_saturation = 5; + int32 min_value = 6; + int32 max_value = 7; +}