From ecbd8bf8a9491b47a69b031ef276c123e10b0ca2 Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Sat, 25 Apr 2026 15:11:40 +0200 Subject: [PATCH] protobuf messages --- CMakeLists.txt | 2 + protobuf/CMakeLists.txt | 43 +++++++++++++ protobuf/m_ui_items.proto | 131 ++++++++++++++++++++++++++++++++++++++ protobuf/messages.proto | 50 +++++++++++++++ 4 files changed, 226 insertions(+) create mode 100644 protobuf/CMakeLists.txt create mode 100644 protobuf/m_ui_items.proto create mode 100644 protobuf/messages.proto diff --git a/CMakeLists.txt b/CMakeLists.txt index 21407f2..0cc9422 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,8 @@ add_subdirectory(client) # contains an "external" library we will link to add_subdirectory(external) +add_subdirectory(protobuf) + # defines the executable if(NOT EMSCRIPTEN) add_subdirectory(server) diff --git a/protobuf/CMakeLists.txt b/protobuf/CMakeLists.txt new file mode 100644 index 0000000..4216b4d --- /dev/null +++ b/protobuf/CMakeLists.txt @@ -0,0 +1,43 @@ +find_package(Qt6 REQUIRED COMPONENTS Protobuf Grpc) + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +add_library(proto-ui STATIC) +set_target_properties( + proto-ui + PROPERTIES + AUTOMOC ON + POSITION_INDEPENDENT_CODE ON +) +qt_add_protobuf(proto-ui + PROTO_FILES + ${CMAKE_CURRENT_LIST_DIR}/m_ui_items.proto + ${CMAKE_CURRENT_LIST_DIR}/messages.proto +) +target_link_libraries(proto-ui PUBLIC Qt6::Protobuf) + +add_library(proto-ui-client STATIC) +set_target_properties( + proto-ui-client + PROPERTIES + AUTOMOC ON + POSITION_INDEPENDENT_CODE ON +) +qt_add_grpc(proto-ui-client CLIENT + PROTO_FILES + ${CMAKE_CURRENT_LIST_DIR}/messages.proto +) +target_link_libraries(proto-ui-client PUBLIC Qt6::Protobuf Qt6::Grpc proto-ui) + +# add_library(proto-ui-server STATIC) +# set_target_properties( +# proto-ui-server +# PROPERTIES +# AUTOMOC ON +# POSITION_INDEPENDENT_CODE ON +# ) +# qt_add_grpc(proto-ui-server SERVER +# PROTO_FILES +# ${CMAKE_CURRENT_LIST_DIR}/messages.proto +# ) +# target_link_libraries(proto-ui-server PUBLIC Qt6::Protobuf Qt6::Grpc proto-ui) \ No newline at end of file diff --git a/protobuf/m_ui_items.proto b/protobuf/m_ui_items.proto new file mode 100644 index 0000000..be59b78 --- /dev/null +++ b/protobuf/m_ui_items.proto @@ -0,0 +1,131 @@ +syntax = "proto3"; + +enum UI_type { + undef = 0; + ui_button = 1; + ui_can = 2; + ui_checkbox = 3; + ui_combobox = 4; + ui_dial = 5; + ui_double_spinbox = 6; + ui_hex_spinbox = 7; + ui_label = 8; + ui_led = 9; + ui_plot = 10; + ui_slider = 11; + ui_spinbox = 12; + ui_stacked_widget = 13; + ui_status_bar = 14; + ui_tab_widget = 15; + ui_table = 16; + ui_textbox = 17; + ui_thermo = 18; +} + +message CAN_Frame_m { + uint32 sid = 1; + int64 dlc = 2; + bytes payload = 3; +} + +message UI_color { + uint32 fg_color = 1; + uint32 bg_color = 2; +} + +message UI_label_m { + UI_color color = 1; + string text = 2; +} + +message UI_can_m { + UI_color color = 1; + repeated CAN_Frame_m send_frames = 2; + repeated CAN_Frame_m recv_frames = 3; +} + +message UI_checkbox_m { + UI_color color = 1; + string text = 2; + bool checked = 3; +} + +message UI_combobox_m { + int64 selected = 1; + repeated string options = 2; +} + +message UI_range_m { + double min = 1; + double max = 2; + double value = 3; + string unit = 4; + string text = 5; +} + +message UI_spinbox_m { + double min = 1; + double max = 2; + double value = 3; +} + +message UI_plot_m { + UI_color color = 1; + string text = 2; + string x_label = 3; + string y_label = 4; + repeated double x_vals = 5; + repeated double y_vals = 6; +} + +message UI_stacked_widget_m { + int64 tab_count = 1; + int64 current_tab = 2; +} + +message UI_tab_widget_m { + int64 selecte_tab = 1; + repeated string tab_names = 2; + repeated bool tab_visible = 3; +} + +message UI_status_bar_m { + uint64 timeout = 1; + string message = 2; +} + +message UI_table_m { + int64 row_count = 1; + int64 column_count = 2; + repeated string row_labels = 3; + repeated string column_labels = 4; + repeated string table = 5; +} + +message UI_textbox_m { + UI_color color = 1; + string text = 2; + string hint = 3; +} + +message UI_item_m { + uint64 id = 1; + UI_type type = 2; + bool enabled = 3; + bool visible = 4; + + oneof kind { + UI_label_m label = 5; + UI_can_m can = 6; + UI_checkbox_m checkbox = 7; + UI_combobox_m combobox = 8; + UI_range_m range = 9; + UI_spinbox_m spinbox = 10; + UI_plot_m plot = 11; + UI_stacked_widget_m stacked_widget = 12; + UI_tab_widget_m tab_widget = 13; + UI_status_bar_m status_bar = 14; + UI_table_m table = 15; + UI_textbox_m textbox = 16; + } +} \ No newline at end of file diff --git a/protobuf/messages.proto b/protobuf/messages.proto new file mode 100644 index 0000000..223d07c --- /dev/null +++ b/protobuf/messages.proto @@ -0,0 +1,50 @@ +syntax = "proto3"; +import "m_ui_items.proto"; + +message Empty {} + +message UI_id_m { uint32 id = 1; } +message UI_items_m { repeated UI_item_m item = 1; } + +message Simulator_m { string simuator = 1;} + +message Simulators_m { repeated string simulator = 1; } + +message Clicked_m {} + +message Value_changed_m { double value = 1; } + +message Text_changed_m { string text = 1; } + +message Selected_m { uint32 selected = 1; } + +message CAN_send_m { CAN_Frame_m frame = 1; } + +message Clear_m {} + +message Event_m { + uint32 id = 1; + oneof kind { + Clicked_m clicked = 2; + Value_changed_m value_changed = 3; + Text_changed_m text_changed = 4; + Selected_m selected = 5; + CAN_send_m can_send = 6; + Clear_m clear = 7; + } +} + +service RemoteUiService { + // Commands + rpc Command_get_ui_element (UI_id_m) returns (UI_items_m); + rpc Command_get_ui_elements (Empty) returns (UI_items_m); + rpc Command_switch_simulator (Simulator_m) returns (Empty); + rpc Command_get_active_simulator (Empty) returns (Simulator_m); + rpc Command_get_simulators (Empty) returns (Simulators_m); + + // Events + rpc SendEvent (Event_m) returns (Empty); + + // Broadcasting + rpc SubscribeUIChanges (Empty) returns (stream UI_items_m); +} \ No newline at end of file