add protobuf generation
This commit is contained in:
parent
ae49cd9fde
commit
90f64c2b37
@ -11,7 +11,9 @@ gperf \
|
||||
python \
|
||||
python-serial \
|
||||
cmake \
|
||||
ninja-build
|
||||
ninja-build \
|
||||
protobuf-compiler \
|
||||
python-protobuf
|
||||
|
||||
RUN mkdir /esp
|
||||
WORKDIR /esp
|
||||
|
6
components/nanopb/CMakeLists.txt
Normal file
6
components/nanopb/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
set(COMPONENT_SRCS "nanopb/pb_common.c"
|
||||
"nanopb/pb_decode.c"
|
||||
"nanopb/pb_encode.c")
|
||||
set(COMPONENT_ADD_INCLUDEDIRS "nanopb")
|
||||
|
||||
register_component()
|
20
components/nanopb/functions.cmake
Normal file
20
components/nanopb/functions.cmake
Normal file
@ -0,0 +1,20 @@
|
||||
function(nanopb_generate PROTO_FILE PB_OUT HDR_VAR SRC_VAR)
|
||||
get_filename_component(PROTO_FILE_NAME ${PROTO_FILE} NAME_WE)
|
||||
get_filename_component(PROTO_FILE_PATH ${PROTO_FILE} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
get_filename_component(PROTO_FILE_DIR ${PROTO_FILE_PATH} DIRECTORY)
|
||||
set(PROTO_HDR "${PB_OUT}/${PROTO_FILE_NAME}.pb.h")
|
||||
set(PROTO_SRC "${PB_OUT}/${PROTO_FILE_NAME}.pb.c")
|
||||
list(APPEND "${HDR_VAR}" ${PROTO_HDR})
|
||||
list(APPEND "${SRC_VAR}" ${PROTO_SRC})
|
||||
if(NOT CMAKE_SCRIPT_MODE_FILE)
|
||||
add_custom_command(OUTPUT ${PROTO_HDR} ${PROTO_SRC}
|
||||
COMMAND protoc
|
||||
--plugin=protoc-gen-nanopb=${CMAKE_CURRENT_LIST_DIR}/nanopb/generator/protoc-gen-nanopb
|
||||
--nanopb_out=${PB_OUT}
|
||||
--proto_path ${PROTO_FILE_DIR}
|
||||
${PROTO_FILE_PATH}
|
||||
DEPENDS ${PROTO_FILE_PATH})
|
||||
endif()
|
||||
list(APPEND ADDITIONAL_MAKE_CLEAN_FILES ${PROTO_HDR} ${PROTO_SRC})
|
||||
endfunction()
|
||||
|
1
main/.gitignore
vendored
Normal file
1
main/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/pb_out
|
@ -1,8 +1,17 @@
|
||||
set(COMPONENT_SRCS "ugv_main.c"
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../components/nanopb/functions.cmake)
|
||||
|
||||
set(PB_OUT ${CMAKE_CURRENT_SOURCE_DIR}/pb_out)
|
||||
|
||||
nanopb_generate(messages.proto ${PB_OUT} PROTO_HDRS PROTO_SRCS)
|
||||
|
||||
list(APPEND COMPONENT_SRCS "ugv_main.c"
|
||||
"ugv_comms.c"
|
||||
"u8g2_esp32_hal.c")
|
||||
set(COMPONENT_ADD_INCLUDEDIRS ".")
|
||||
set(COMPONENT_REQUIRES "u8g2" "sx127x_driver")
|
||||
"u8g2_esp32_hal.c"
|
||||
${PROTO_SRCS})
|
||||
set(COMPONENT_PRIV_INCLUDEDIRS "." ${PB_OUT})
|
||||
set(COMPONENT_REQUIRES "u8g2" "sx127x_driver" "nanopb")
|
||||
|
||||
make_directory(${PB_OUT})
|
||||
|
||||
register_component()
|
||||
|
||||
|
43
main/messages.proto
Normal file
43
main/messages.proto
Normal file
@ -0,0 +1,43 @@
|
||||
syntax = "proto3";
|
||||
|
||||
enum UGV_State {
|
||||
IDLE = 0;
|
||||
AQUIRING = 1;
|
||||
DRIVING = 2;
|
||||
FINISHED = 3;
|
||||
}
|
||||
|
||||
message Location {
|
||||
uint32 fix_quality = 1;
|
||||
float latitude = 2;
|
||||
float longitude = 3;
|
||||
float altitude = 4;
|
||||
}
|
||||
|
||||
message UGV_Status {
|
||||
UGV_State state = 1;
|
||||
Location location = 2;
|
||||
}
|
||||
|
||||
message UGV_Message {
|
||||
oneof ugv_message {
|
||||
UGV_Status status = 1;
|
||||
uint32 command_ack = 2;
|
||||
}
|
||||
}
|
||||
|
||||
enum GroundCommandType {
|
||||
DISABLE = 0;
|
||||
ENABLE = 1;
|
||||
}
|
||||
|
||||
message GroundCommand {
|
||||
uint32 id = 1;
|
||||
GroundCommandType type = 2;
|
||||
}
|
||||
|
||||
message GroundMessage {
|
||||
oneof ground_message {
|
||||
GroundCommand command = 1;
|
||||
}
|
||||
}
|
@ -9,6 +9,9 @@
|
||||
#include "u8g2_esp32_hal.h"
|
||||
#include "ugv_comms.h"
|
||||
#include "ugv_config.h"
|
||||
#include "messages.pb.h"
|
||||
|
||||
#include <pb_decode.h>
|
||||
|
||||
static const char *TAG = "ugv_main";
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user