Skip to content

Commit

Permalink
Merge pull request #7 from BuzzVerse/feature/nanopb-integration
Browse files Browse the repository at this point in the history
refactor: Improve Nanopb protobuf build configuration and include paths
  • Loading branch information
wybran authored Jan 30, 2025
2 parents d990240 + 0502f78 commit 8918eca
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ source ~/zephyrproject/.venv/bin/activate

west init -m https://github.com/BuzzVerse/buzznode --mr main buzznode
cd buzznode
west update

west config manifest.project-filter -- +nanopb
west blobs fetch hal_espressif
west blobs fetch hal_stm32
west update
```

### Registering a device
Expand Down
25 changes: 21 additions & 4 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,32 @@ endif()
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(buzznode)

# Nanopb setup
list(APPEND CMAKE_MODULE_PATH ${ZEPHYR_BASE}/modules/nanopb)
include(nanopb)

# Find all proto files
file(GLOB_RECURSE proto_files protobufs/*.proto)
# Set proto path for imports
set(PROTO_PATH ${CMAKE_CURRENT_SOURCE_DIR}/protobufs)

# Generate protobuf files
file(GLOB_RECURSE proto_files protobufs/buzzverse/*.proto)
foreach(proto_file ${proto_files})
zephyr_nanopb_sources(app ${proto_file})
get_filename_component(proto_name ${proto_file} NAME_WE)
nanopb_generate_cpp(PROTO_SRCS PROTO_HDRS ${proto_file}
RELPATH ${PROTO_PATH}
)
list(APPEND proto_sources ${PROTO_SRCS})
endforeach()

# Create a separate library for proto files
zephyr_library_named(proto)
target_sources(proto PRIVATE ${proto_sources})
target_include_directories(proto PUBLIC
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/protobufs
)

# Add application sources
file(GLOB_RECURSE app_sources src/*.cpp)
target_sources(app PRIVATE ${app_sources})

Expand All @@ -36,4 +53,4 @@ set_target_properties(app PROPERTIES
CXX_EXTENSIONS OFF
)

target_link_libraries(app PRIVATE etl::etl)
target_link_libraries(app PRIVATE proto etl::etl)
2 changes: 1 addition & 1 deletion app/protobufs
4 changes: 2 additions & 2 deletions app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#include "bme280.hpp"
#include "lorawan_handler.hpp"
#include "protobufs/buzzverse/bme280.pb.h"
#include "protobufs/buzzverse/packet.pb.h"
#include "buzzverse/bme280.pb.h"
#include "buzzverse/packet.pb.h"
#include "utils/packet_handler.hpp"

LOG_MODULE_REGISTER(main, LOG_LEVEL_DBG);
Expand Down
2 changes: 1 addition & 1 deletion app/src/utils/packet_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <pb_decode.h>
#include <pb_encode.h>

#include "protobufs/buzzverse/packet.pb.h"
#include "buzzverse/packet.pb.h"

class PacketHandler {
public:
Expand Down

0 comments on commit 8918eca

Please sign in to comment.