From 43573042e1ac88d3e76c45ae9c1e01f11930645c Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Fri, 11 Oct 2024 13:09:49 +0200 Subject: [PATCH] nanopb creation scripts added generated nanopb files renamed and moved to another target folder nanopb version 0.4.9 used (0.4.8 before) --- build_win/nanopb/compile-nanopb.bat | 1 + build_win/nanopb/compile-nanopb.py | 112 ++++++++++++++++++ ecal/core/CMakeLists.txt | 48 ++++---- .../serialization/ecal_serialize_common.cpp | 2 +- .../serialization/ecal_serialize_logging.cpp | 2 +- .../ecal_serialize_monitoring.cpp | 2 +- .../ecal_serialize_sample_payload.cpp | 2 +- .../ecal_serialize_sample_registration.cpp | 2 +- .../serialization/ecal_serialize_service.cpp | 2 +- .../{ecal.pb.c => ecal/core/pb/ecal.npb.c} | 5 +- .../{ecal.pb.h => ecal/core/pb/ecal.npb.h} | 14 +-- .../{host.pb.c => ecal/core/pb/host.npb.c} | 4 +- .../{host.pb.h => ecal/core/pb/host.npb.h} | 6 +- .../{layer.pb.c => ecal/core/pb/layer.npb.c} | 5 +- .../{layer.pb.h => ecal/core/pb/layer.npb.h} | 8 +- .../core/pb/logging.npb.c} | 4 +- .../core/pb/logging.npb.h} | 6 +- .../core/pb/monitoring.npb.c} | 4 +- .../core/pb/monitoring.npb.h} | 14 +-- .../core/pb/process.npb.c} | 7 +- .../core/pb/process.npb.h} | 6 +- .../core/pb/service.npb.c} | 5 +- .../core/pb/service.npb.h} | 6 +- .../{topic.pb.c => ecal/core/pb/topic.npb.c} | 4 +- .../{topic.pb.h => ecal/core/pb/topic.npb.h} | 8 +- .../serialization/nanopb/{nanopb => }/pb.h | 23 ++-- .../nanopb/{nanopb => }/pb_common.c | 0 .../nanopb/{nanopb => }/pb_common.h | 0 .../nanopb/{nanopb => }/pb_decode.c | 11 +- .../nanopb/{nanopb => }/pb_decode.h | 13 +- .../nanopb/{nanopb => }/pb_encode.c | 11 +- .../nanopb/{nanopb => }/pb_encode.h | 16 ++- .../cpp/serialization_test/CMakeLists.txt | 46 +++---- 33 files changed, 273 insertions(+), 126 deletions(-) create mode 100644 build_win/nanopb/compile-nanopb.bat create mode 100644 build_win/nanopb/compile-nanopb.py rename ecal/core/src/serialization/nanopb/{ecal.pb.c => ecal/core/pb/ecal.npb.c} (85%) rename ecal/core/src/serialization/nanopb/{ecal.pb.h => ecal/core/pb/ecal.npb.h} (96%) rename ecal/core/src/serialization/nanopb/{host.pb.c => ecal/core/pb/host.npb.c} (83%) rename ecal/core/src/serialization/nanopb/{host.pb.h => ecal/core/pb/host.npb.h} (95%) rename ecal/core/src/serialization/nanopb/{layer.pb.c => ecal/core/pb/layer.npb.c} (89%) rename ecal/core/src/serialization/nanopb/{layer.pb.h => ecal/core/pb/layer.npb.h} (97%) rename ecal/core/src/serialization/nanopb/{logging.pb.c => ecal/core/pb/logging.npb.c} (83%) rename ecal/core/src/serialization/nanopb/{logging.pb.h => ecal/core/pb/logging.npb.h} (96%) rename ecal/core/src/serialization/nanopb/{monitoring.pb.c => ecal/core/pb/monitoring.npb.c} (79%) rename ecal/core/src/serialization/nanopb/{monitoring.pb.h => ecal/core/pb/monitoring.npb.h} (89%) rename ecal/core/src/serialization/nanopb/{process.pb.c => ecal/core/pb/process.npb.c} (82%) rename ecal/core/src/serialization/nanopb/{process.pb.h => ecal/core/pb/process.npb.h} (98%) rename ecal/core/src/serialization/nanopb/{service.pb.c => ecal/core/pb/service.npb.c} (89%) rename ecal/core/src/serialization/nanopb/{service.pb.h => ecal/core/pb/service.npb.h} (98%) rename ecal/core/src/serialization/nanopb/{topic.pb.c => ecal/core/pb/topic.npb.c} (86%) rename ecal/core/src/serialization/nanopb/{topic.pb.h => ecal/core/pb/topic.npb.h} (97%) rename ecal/core/src/serialization/nanopb/{nanopb => }/pb.h (99%) rename ecal/core/src/serialization/nanopb/{nanopb => }/pb_common.c (100%) rename ecal/core/src/serialization/nanopb/{nanopb => }/pb_common.h (100%) rename ecal/core/src/serialization/nanopb/{nanopb => }/pb_decode.c (99%) rename ecal/core/src/serialization/nanopb/{nanopb => }/pb_decode.h (92%) rename ecal/core/src/serialization/nanopb/{nanopb => }/pb_encode.c (99%) rename ecal/core/src/serialization/nanopb/{nanopb => }/pb_encode.h (93%) diff --git a/build_win/nanopb/compile-nanopb.bat b/build_win/nanopb/compile-nanopb.bat new file mode 100644 index 0000000000..fdbf4f4589 --- /dev/null +++ b/build_win/nanopb/compile-nanopb.bat @@ -0,0 +1 @@ +python compile-nanopb.py --nano_pb_path c:\nanopb\nanopb-0.4.9 --ecal_repository "..\.." \ No newline at end of file diff --git a/build_win/nanopb/compile-nanopb.py b/build_win/nanopb/compile-nanopb.py new file mode 100644 index 0000000000..5632fc90e0 --- /dev/null +++ b/build_win/nanopb/compile-nanopb.py @@ -0,0 +1,112 @@ +import sys +import re +import subprocess +import logging +from pathlib import Path +import shutil +import argparse + +def setup_logging(): + """Sets up the logging configuration.""" + logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') + + +def list_files(directory: Path, extension: str) -> list[Path]: + """Returns a list of files with specific extension in the given directory.""" + if not directory.exists(): + logging.error(f"Directory {directory} does not exist.") + return [] + return list(directory.glob(f"*{extension}")) + + +def copy_files(source_dir: Path, target_dir: Path, file_types: list[str]): + """Copies files of specific types from source to target directory.""" + target_dir.mkdir(parents=True, exist_ok=True) + for file_type in file_types: + for file in source_dir.glob(file_type): + try: + shutil.copy2(file, target_dir) + logging.info(f"Copied {file.name} to {target_dir}") + except Exception as e: + logging.error(f"Error copying {file.name} to {target_dir}: {e}") + + +def check_nanopb_compiler_exists(compiler_path: Path): + """Checks if the nanopb_generator exists.""" + if not compiler_path.exists(): + logging.error(f"nanopb generator not found at {compiler_path}") + sys.exit(1) + + +def run_nanopb_generator(proto_files: list[Path], compiler: Path, ecal_pb_base_path: Path, ecal_pb_sub_path: Path, target_dir: Path): + """Runs the nanopb generator for each proto file.""" + for proto_file_path in proto_files: + proto_file_name = proto_file_path.name + + command = [ + str(compiler), + "-I" + str(ecal_pb_base_path), + "-I" + str(ecal_pb_base_path / ecal_pb_sub_path), + "-D" + str(target_dir / ecal_pb_sub_path), + "-e" + ".npb", + proto_file_name + ] + + logging.info(f"Running: {' '.join(command)}") + + try: + result = subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, cwd=proto_file_path.parent) + logging.info(f"Success: {proto_file_name} processed.") + logging.debug(result.stdout) + except subprocess.CalledProcessError as e: + logging.error(f"Error running nanopb_generator for {proto_file_name}: {e.stderr}") + + +def main(nano_pb_path: Path, ecal_repository: Path): + setup_logging() + + # Define paths based on the provided arguments + ecal_pb_base_path = Path(ecal_repository / "ecal/core_pb/src") + ecal_pb_sub_path = Path("ecal/core/pb") + ecal_target_path = Path("../../core/src/serialization/nanopb") + + # Combine paths and list .proto files + proto_files_dir = ecal_pb_base_path / ecal_pb_sub_path + ecal_pb_files = list_files(proto_files_dir, ".proto") + + # Check if nanopb generator exists + nano_pb_compiler = nano_pb_path / "generator-bin/nanopb_generator.exe" + check_nanopb_compiler_exists(nano_pb_compiler) + + # Check if any .proto files are found + if not ecal_pb_files: + logging.error(f"No .proto files found in {proto_files_dir}") + sys.exit(1) + + # Prepare target directory + absolute_target_path = (ecal_pb_base_path / ecal_target_path).resolve() + absolute_target_path.mkdir(parents=True, exist_ok=True) + + # Copy nanopb common decoder and encoder to target nanopb directory + target_nanopb_dir = absolute_target_path + copy_files(nano_pb_path, target_nanopb_dir, ["*.c", "*.h"]) + + # Run nanopb_generator for each .proto file + run_nanopb_generator(ecal_pb_files, nano_pb_compiler, ecal_pb_base_path, ecal_pb_sub_path, absolute_target_path) + + +if __name__ == "__main__": + # Set up argument parsing + parser = argparse.ArgumentParser(description="Process nanopb and eCAL protobuf files.") + parser.add_argument("--nano_pb_path", type=Path, required=True, help="Path to the nanopb directory") + parser.add_argument("--ecal_repository", type=Path, required=True, help="Path to the eCAL repository") + + # Parse the arguments + args = parser.parse_args() + + # Resolve paths to absolute paths to support relative paths + nano_pb_path = Path(args.nano_pb_path).resolve() + ecal_repository = Path(args.ecal_repository).resolve() + + # Call the main function with resolved absolute paths + main(nano_pb_path, ecal_repository) \ No newline at end of file diff --git a/ecal/core/CMakeLists.txt b/ecal/core/CMakeLists.txt index 287577fe72..2400f00848 100644 --- a/ecal/core/CMakeLists.txt +++ b/ecal/core/CMakeLists.txt @@ -329,29 +329,29 @@ endif() # serialization ###################################### set(ecal_serialization_src - src/serialization/nanopb/nanopb/pb.h - src/serialization/nanopb/nanopb/pb_common.c - src/serialization/nanopb/nanopb/pb_common.h - src/serialization/nanopb/nanopb/pb_decode.c - src/serialization/nanopb/nanopb/pb_decode.h - src/serialization/nanopb/nanopb/pb_encode.c - src/serialization/nanopb/nanopb/pb_encode.h - src/serialization/nanopb/ecal.pb.c - src/serialization/nanopb/ecal.pb.h - src/serialization/nanopb/host.pb.c - src/serialization/nanopb/host.pb.h - src/serialization/nanopb/layer.pb.c - src/serialization/nanopb/layer.pb.h - src/serialization/nanopb/logging.pb.c - src/serialization/nanopb/logging.pb.h - src/serialization/nanopb/monitoring.pb.c - src/serialization/nanopb/monitoring.pb.h - src/serialization/nanopb/process.pb.c - src/serialization/nanopb/process.pb.h - src/serialization/nanopb/service.pb.c - src/serialization/nanopb/service.pb.h - src/serialization/nanopb/topic.pb.c - src/serialization/nanopb/topic.pb.h + src/serialization/nanopb/pb.h + src/serialization/nanopb/pb_common.c + src/serialization/nanopb/pb_common.h + src/serialization/nanopb/pb_decode.c + src/serialization/nanopb/pb_decode.h + src/serialization/nanopb/pb_encode.c + src/serialization/nanopb/pb_encode.h + src/serialization/nanopb/ecal/core/pb/ecal.npb.c + src/serialization/nanopb/ecal/core/pb/ecal.npb.h + src/serialization/nanopb/ecal/core/pb/host.npb.c + src/serialization/nanopb/ecal/core/pb/host.npb.h + src/serialization/nanopb/ecal/core/pb/layer.npb.c + src/serialization/nanopb/ecal/core/pb/layer.npb.h + src/serialization/nanopb/ecal/core/pb/logging.npb.c + src/serialization/nanopb/ecal/core/pb/logging.npb.h + src/serialization/nanopb/ecal/core/pb/monitoring.npb.c + src/serialization/nanopb/ecal/core/pb/monitoring.npb.h + src/serialization/nanopb/ecal/core/pb/process.npb.c + src/serialization/nanopb/ecal/core/pb/process.npb.h + src/serialization/nanopb/ecal/core/pb/service.npb.c + src/serialization/nanopb/ecal/core/pb/service.npb.h + src/serialization/nanopb/ecal/core/pb/topic.npb.c + src/serialization/nanopb/ecal/core/pb/topic.npb.h src/serialization/ecal_serialize_common.cpp src/serialization/ecal_serialize_common.h src/serialization/ecal_serialize_logging.cpp @@ -700,8 +700,8 @@ target_link_libraries(${PROJECT_NAME} target_include_directories(${PROJECT_NAME} PRIVATE $ + $ $ - $ PUBLIC $ $ diff --git a/ecal/core/src/serialization/ecal_serialize_common.cpp b/ecal/core/src/serialization/ecal_serialize_common.cpp index 53fcb8d1f3..13d0649240 100644 --- a/ecal/core/src/serialization/ecal_serialize_common.cpp +++ b/ecal/core/src/serialization/ecal_serialize_common.cpp @@ -22,7 +22,7 @@ * @brief eCAL common (de)serialization **/ -#include "nanopb/ecal.pb.h" +#include "nanopb/ecal/core/pb/ecal.npb.h" #include "nanopb/pb_decode.h" #include "nanopb/pb_encode.h" #include diff --git a/ecal/core/src/serialization/ecal_serialize_logging.cpp b/ecal/core/src/serialization/ecal_serialize_logging.cpp index ef67992538..89c75664cb 100644 --- a/ecal/core/src/serialization/ecal_serialize_logging.cpp +++ b/ecal/core/src/serialization/ecal_serialize_logging.cpp @@ -24,7 +24,7 @@ #include "nanopb/pb_encode.h" #include "nanopb/pb_decode.h" -#include "nanopb/logging.pb.h" +#include "nanopb/ecal/core/pb/logging.npb.h" #include "ecal_serialize_common.h" #include "ecal_serialize_logging.h" diff --git a/ecal/core/src/serialization/ecal_serialize_monitoring.cpp b/ecal/core/src/serialization/ecal_serialize_monitoring.cpp index 5e0bd04a52..59fafbff19 100644 --- a/ecal/core/src/serialization/ecal_serialize_monitoring.cpp +++ b/ecal/core/src/serialization/ecal_serialize_monitoring.cpp @@ -24,7 +24,7 @@ #include "nanopb/pb_encode.h" #include "nanopb/pb_decode.h" -#include "nanopb/monitoring.pb.h" +#include "nanopb/ecal/core/pb/monitoring.npb.h" #include "ecal_serialize_common.h" #include "ecal_serialize_monitoring.h" diff --git a/ecal/core/src/serialization/ecal_serialize_sample_payload.cpp b/ecal/core/src/serialization/ecal_serialize_sample_payload.cpp index da891ed1f8..f80ceb2776 100644 --- a/ecal/core/src/serialization/ecal_serialize_sample_payload.cpp +++ b/ecal/core/src/serialization/ecal_serialize_sample_payload.cpp @@ -24,7 +24,7 @@ #include "nanopb/pb_encode.h" #include "nanopb/pb_decode.h" -#include "nanopb/ecal.pb.h" +#include "nanopb/ecal/core/pb/ecal.npb.h" #include "ecal_serialize_common.h" #include "ecal_struct_sample_payload.h" diff --git a/ecal/core/src/serialization/ecal_serialize_sample_registration.cpp b/ecal/core/src/serialization/ecal_serialize_sample_registration.cpp index 1e0fb62a7f..744f6ebd33 100644 --- a/ecal/core/src/serialization/ecal_serialize_sample_registration.cpp +++ b/ecal/core/src/serialization/ecal_serialize_sample_registration.cpp @@ -24,7 +24,7 @@ #include "nanopb/pb_encode.h" #include "nanopb/pb_decode.h" -#include "nanopb/ecal.pb.h" +#include "nanopb/ecal/core/pb/ecal.npb.h" #include "ecal_serialize_common.h" #include "ecal_serialize_sample_registration.h" diff --git a/ecal/core/src/serialization/ecal_serialize_service.cpp b/ecal/core/src/serialization/ecal_serialize_service.cpp index 9bf6260d51..08902c537b 100644 --- a/ecal/core/src/serialization/ecal_serialize_service.cpp +++ b/ecal/core/src/serialization/ecal_serialize_service.cpp @@ -24,7 +24,7 @@ #include "nanopb/pb_encode.h" #include "nanopb/pb_decode.h" -#include "nanopb/ecal.pb.h" +#include "nanopb/ecal/core/pb/ecal.npb.h" #include "ecal_serialize_common.h" #include "ecal_serialize_service.h" diff --git a/ecal/core/src/serialization/nanopb/ecal.pb.c b/ecal/core/src/serialization/nanopb/ecal/core/pb/ecal.npb.c similarity index 85% rename from ecal/core/src/serialization/nanopb/ecal.pb.c rename to ecal/core/src/serialization/nanopb/ecal/core/pb/ecal.npb.c index aaf947bc7f..cd260f71d8 100644 --- a/ecal/core/src/serialization/nanopb/ecal.pb.c +++ b/ecal/core/src/serialization/nanopb/ecal/core/pb/ecal.npb.c @@ -1,7 +1,7 @@ /* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.4.8 */ +/* Generated by nanopb-0.4.9 */ -#include "ecal.pb.h" +#include "ecal.npb.h" #if PB_PROTO_HEADER_VERSION != 40 #error Regenerate this file with the current version of nanopb generator. #endif @@ -17,3 +17,4 @@ PB_BIND(eCAL_pb_SampleList, eCAL_pb_SampleList, AUTO) + diff --git a/ecal/core/src/serialization/nanopb/ecal.pb.h b/ecal/core/src/serialization/nanopb/ecal/core/pb/ecal.npb.h similarity index 96% rename from ecal/core/src/serialization/nanopb/ecal.pb.h rename to ecal/core/src/serialization/nanopb/ecal/core/pb/ecal.npb.h index 8711ae4c83..d77987cb4d 100644 --- a/ecal/core/src/serialization/nanopb/ecal.pb.h +++ b/ecal/core/src/serialization/nanopb/ecal/core/pb/ecal.npb.h @@ -1,13 +1,13 @@ /* Automatically generated nanopb header */ -/* Generated by nanopb-0.4.8 */ +/* Generated by nanopb-0.4.9 */ -#ifndef PB_ECAL_PB_ECAL_PB_H_INCLUDED -#define PB_ECAL_PB_ECAL_PB_H_INCLUDED +#ifndef PB_ECAL_PB_ECAL_NPB_H_INCLUDED +#define PB_ECAL_PB_ECAL_NPB_H_INCLUDED #include -#include "host.pb.h" -#include "process.pb.h" -#include "service.pb.h" -#include "topic.pb.h" +#include "ecal/core/pb/host.npb.h" +#include "ecal/core/pb/process.npb.h" +#include "ecal/core/pb/service.npb.h" +#include "ecal/core/pb/topic.npb.h" #if PB_PROTO_HEADER_VERSION != 40 #error Regenerate this file with the current version of nanopb generator. diff --git a/ecal/core/src/serialization/nanopb/host.pb.c b/ecal/core/src/serialization/nanopb/ecal/core/pb/host.npb.c similarity index 83% rename from ecal/core/src/serialization/nanopb/host.pb.c rename to ecal/core/src/serialization/nanopb/ecal/core/pb/host.npb.c index e7720239c7..54b6cb5e8f 100644 --- a/ecal/core/src/serialization/nanopb/host.pb.c +++ b/ecal/core/src/serialization/nanopb/ecal/core/pb/host.npb.c @@ -1,7 +1,7 @@ /* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.4.8 */ +/* Generated by nanopb-0.4.9 */ -#include "host.pb.h" +#include "host.npb.h" #if PB_PROTO_HEADER_VERSION != 40 #error Regenerate this file with the current version of nanopb generator. #endif diff --git a/ecal/core/src/serialization/nanopb/host.pb.h b/ecal/core/src/serialization/nanopb/ecal/core/pb/host.npb.h similarity index 95% rename from ecal/core/src/serialization/nanopb/host.pb.h rename to ecal/core/src/serialization/nanopb/ecal/core/pb/host.npb.h index 63d43d6fd2..adc7f50269 100644 --- a/ecal/core/src/serialization/nanopb/host.pb.h +++ b/ecal/core/src/serialization/nanopb/ecal/core/pb/host.npb.h @@ -1,8 +1,8 @@ /* Automatically generated nanopb header */ -/* Generated by nanopb-0.4.8 */ +/* Generated by nanopb-0.4.9 */ -#ifndef PB_ECAL_PB_HOST_PB_H_INCLUDED -#define PB_ECAL_PB_HOST_PB_H_INCLUDED +#ifndef PB_ECAL_PB_HOST_NPB_H_INCLUDED +#define PB_ECAL_PB_HOST_NPB_H_INCLUDED #include #if PB_PROTO_HEADER_VERSION != 40 diff --git a/ecal/core/src/serialization/nanopb/layer.pb.c b/ecal/core/src/serialization/nanopb/ecal/core/pb/layer.npb.c similarity index 89% rename from ecal/core/src/serialization/nanopb/layer.pb.c rename to ecal/core/src/serialization/nanopb/ecal/core/pb/layer.npb.c index 876144d582..aa8ba1cfb6 100644 --- a/ecal/core/src/serialization/nanopb/layer.pb.c +++ b/ecal/core/src/serialization/nanopb/ecal/core/pb/layer.npb.c @@ -1,7 +1,7 @@ /* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.4.8 */ +/* Generated by nanopb-0.4.9 */ -#include "layer.pb.h" +#include "layer.npb.h" #if PB_PROTO_HEADER_VERSION != 40 #error Regenerate this file with the current version of nanopb generator. #endif @@ -23,3 +23,4 @@ PB_BIND(eCAL_pb_TLayer, eCAL_pb_TLayer, AUTO) + diff --git a/ecal/core/src/serialization/nanopb/layer.pb.h b/ecal/core/src/serialization/nanopb/ecal/core/pb/layer.npb.h similarity index 97% rename from ecal/core/src/serialization/nanopb/layer.pb.h rename to ecal/core/src/serialization/nanopb/ecal/core/pb/layer.npb.h index 64f39f35ff..56e6ddac1a 100644 --- a/ecal/core/src/serialization/nanopb/layer.pb.h +++ b/ecal/core/src/serialization/nanopb/ecal/core/pb/layer.npb.h @@ -1,8 +1,8 @@ /* Automatically generated nanopb header */ -/* Generated by nanopb-0.4.8 */ +/* Generated by nanopb-0.4.9 */ -#ifndef PB_ECAL_PB_LAYER_PB_H_INCLUDED -#define PB_ECAL_PB_LAYER_PB_H_INCLUDED +#ifndef PB_ECAL_PB_LAYER_NPB_H_INCLUDED +#define PB_ECAL_PB_LAYER_NPB_H_INCLUDED #include #if PB_PROTO_HEADER_VERSION != 40 @@ -150,7 +150,7 @@ extern const pb_msgdesc_t eCAL_pb_TLayer_msg; /* eCAL_pb_LayerParShm_size depends on runtime parameters */ /* eCAL_pb_ConnnectionPar_size depends on runtime parameters */ /* eCAL_pb_TLayer_size depends on runtime parameters */ -#define ECAL_PB_LAYER_PB_H_MAX_SIZE eCAL_pb_LayerParTcp_size +#define ECAL_PB_LAYER_NPB_H_MAX_SIZE eCAL_pb_LayerParTcp_size #define eCAL_pb_LayerParTcp_size 11 #define eCAL_pb_LayerParUdpMC_size 0 diff --git a/ecal/core/src/serialization/nanopb/logging.pb.c b/ecal/core/src/serialization/nanopb/ecal/core/pb/logging.npb.c similarity index 83% rename from ecal/core/src/serialization/nanopb/logging.pb.c rename to ecal/core/src/serialization/nanopb/ecal/core/pb/logging.npb.c index aba64cb7e0..a00a3e9e3f 100644 --- a/ecal/core/src/serialization/nanopb/logging.pb.c +++ b/ecal/core/src/serialization/nanopb/ecal/core/pb/logging.npb.c @@ -1,7 +1,7 @@ /* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.4.8 */ +/* Generated by nanopb-0.4.9 */ -#include "logging.pb.h" +#include "logging.npb.h" #if PB_PROTO_HEADER_VERSION != 40 #error Regenerate this file with the current version of nanopb generator. #endif diff --git a/ecal/core/src/serialization/nanopb/logging.pb.h b/ecal/core/src/serialization/nanopb/ecal/core/pb/logging.npb.h similarity index 96% rename from ecal/core/src/serialization/nanopb/logging.pb.h rename to ecal/core/src/serialization/nanopb/ecal/core/pb/logging.npb.h index 696fa02971..1a71f1f174 100644 --- a/ecal/core/src/serialization/nanopb/logging.pb.h +++ b/ecal/core/src/serialization/nanopb/ecal/core/pb/logging.npb.h @@ -1,8 +1,8 @@ /* Automatically generated nanopb header */ -/* Generated by nanopb-0.4.8 */ +/* Generated by nanopb-0.4.9 */ -#ifndef PB_ECAL_PB_LOGGING_PB_H_INCLUDED -#define PB_ECAL_PB_LOGGING_PB_H_INCLUDED +#ifndef PB_ECAL_PB_LOGGING_NPB_H_INCLUDED +#define PB_ECAL_PB_LOGGING_NPB_H_INCLUDED #include #if PB_PROTO_HEADER_VERSION != 40 diff --git a/ecal/core/src/serialization/nanopb/monitoring.pb.c b/ecal/core/src/serialization/nanopb/ecal/core/pb/monitoring.npb.c similarity index 79% rename from ecal/core/src/serialization/nanopb/monitoring.pb.c rename to ecal/core/src/serialization/nanopb/ecal/core/pb/monitoring.npb.c index e512c68e58..f1332cbab4 100644 --- a/ecal/core/src/serialization/nanopb/monitoring.pb.c +++ b/ecal/core/src/serialization/nanopb/ecal/core/pb/monitoring.npb.c @@ -1,7 +1,7 @@ /* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.4.8 */ +/* Generated by nanopb-0.4.9 */ -#include "monitoring.pb.h" +#include "monitoring.npb.h" #if PB_PROTO_HEADER_VERSION != 40 #error Regenerate this file with the current version of nanopb generator. #endif diff --git a/ecal/core/src/serialization/nanopb/monitoring.pb.h b/ecal/core/src/serialization/nanopb/ecal/core/pb/monitoring.npb.h similarity index 89% rename from ecal/core/src/serialization/nanopb/monitoring.pb.h rename to ecal/core/src/serialization/nanopb/ecal/core/pb/monitoring.npb.h index e6cc1dbc4d..24f535965e 100644 --- a/ecal/core/src/serialization/nanopb/monitoring.pb.h +++ b/ecal/core/src/serialization/nanopb/ecal/core/pb/monitoring.npb.h @@ -1,13 +1,13 @@ /* Automatically generated nanopb header */ -/* Generated by nanopb-0.4.8 */ +/* Generated by nanopb-0.4.9 */ -#ifndef PB_ECAL_PB_MONITORING_PB_H_INCLUDED -#define PB_ECAL_PB_MONITORING_PB_H_INCLUDED +#ifndef PB_ECAL_PB_MONITORING_NPB_H_INCLUDED +#define PB_ECAL_PB_MONITORING_NPB_H_INCLUDED #include -#include "host.pb.h" -#include "process.pb.h" -#include "service.pb.h" -#include "topic.pb.h" +#include "ecal/core/pb/host.npb.h" +#include "ecal/core/pb/process.npb.h" +#include "ecal/core/pb/service.npb.h" +#include "ecal/core/pb/topic.npb.h" #if PB_PROTO_HEADER_VERSION != 40 #error Regenerate this file with the current version of nanopb generator. diff --git a/ecal/core/src/serialization/nanopb/process.pb.c b/ecal/core/src/serialization/nanopb/ecal/core/pb/process.npb.c similarity index 82% rename from ecal/core/src/serialization/nanopb/process.pb.c rename to ecal/core/src/serialization/nanopb/ecal/core/pb/process.npb.c index 60dfc2db46..adecbca87b 100644 --- a/ecal/core/src/serialization/nanopb/process.pb.c +++ b/ecal/core/src/serialization/nanopb/ecal/core/pb/process.npb.c @@ -1,7 +1,7 @@ /* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.4.8 */ +/* Generated by nanopb-0.4.9 */ -#include "process.pb.h" +#include "process.npb.h" #if PB_PROTO_HEADER_VERSION != 40 #error Regenerate this file with the current version of nanopb generator. #endif @@ -16,3 +16,6 @@ PB_BIND(eCAL_pb_Process, eCAL_pb_Process, AUTO) + + + diff --git a/ecal/core/src/serialization/nanopb/process.pb.h b/ecal/core/src/serialization/nanopb/ecal/core/pb/process.npb.h similarity index 98% rename from ecal/core/src/serialization/nanopb/process.pb.h rename to ecal/core/src/serialization/nanopb/ecal/core/pb/process.npb.h index 592f0b5f17..7139ac4960 100644 --- a/ecal/core/src/serialization/nanopb/process.pb.h +++ b/ecal/core/src/serialization/nanopb/ecal/core/pb/process.npb.h @@ -1,8 +1,8 @@ /* Automatically generated nanopb header */ -/* Generated by nanopb-0.4.8 */ +/* Generated by nanopb-0.4.9 */ -#ifndef PB_ECAL_PB_PROCESS_PB_H_INCLUDED -#define PB_ECAL_PB_PROCESS_PB_H_INCLUDED +#ifndef PB_ECAL_PB_PROCESS_NPB_H_INCLUDED +#define PB_ECAL_PB_PROCESS_NPB_H_INCLUDED #include #if PB_PROTO_HEADER_VERSION != 40 diff --git a/ecal/core/src/serialization/nanopb/service.pb.c b/ecal/core/src/serialization/nanopb/ecal/core/pb/service.npb.c similarity index 89% rename from ecal/core/src/serialization/nanopb/service.pb.c rename to ecal/core/src/serialization/nanopb/ecal/core/pb/service.npb.c index 9a2b53399c..77181a02b1 100644 --- a/ecal/core/src/serialization/nanopb/service.pb.c +++ b/ecal/core/src/serialization/nanopb/ecal/core/pb/service.npb.c @@ -1,7 +1,7 @@ /* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.4.8 */ +/* Generated by nanopb-0.4.9 */ -#include "service.pb.h" +#include "service.npb.h" #if PB_PROTO_HEADER_VERSION != 40 #error Regenerate this file with the current version of nanopb generator. #endif @@ -26,3 +26,4 @@ PB_BIND(eCAL_pb_Client, eCAL_pb_Client, AUTO) + diff --git a/ecal/core/src/serialization/nanopb/service.pb.h b/ecal/core/src/serialization/nanopb/ecal/core/pb/service.npb.h similarity index 98% rename from ecal/core/src/serialization/nanopb/service.pb.h rename to ecal/core/src/serialization/nanopb/ecal/core/pb/service.npb.h index 611f224e07..f60c1b2ce6 100644 --- a/ecal/core/src/serialization/nanopb/service.pb.h +++ b/ecal/core/src/serialization/nanopb/ecal/core/pb/service.npb.h @@ -1,8 +1,8 @@ /* Automatically generated nanopb header */ -/* Generated by nanopb-0.4.8 */ +/* Generated by nanopb-0.4.9 */ -#ifndef PB_ECAL_PB_SERVICE_PB_H_INCLUDED -#define PB_ECAL_PB_SERVICE_PB_H_INCLUDED +#ifndef PB_ECAL_PB_SERVICE_NPB_H_INCLUDED +#define PB_ECAL_PB_SERVICE_NPB_H_INCLUDED #include #if PB_PROTO_HEADER_VERSION != 40 diff --git a/ecal/core/src/serialization/nanopb/topic.pb.c b/ecal/core/src/serialization/nanopb/ecal/core/pb/topic.npb.c similarity index 86% rename from ecal/core/src/serialization/nanopb/topic.pb.c rename to ecal/core/src/serialization/nanopb/ecal/core/pb/topic.npb.c index 7b8316dd23..85f7d1970a 100644 --- a/ecal/core/src/serialization/nanopb/topic.pb.c +++ b/ecal/core/src/serialization/nanopb/ecal/core/pb/topic.npb.c @@ -1,7 +1,7 @@ /* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.4.8 */ +/* Generated by nanopb-0.4.9 */ -#include "topic.pb.h" +#include "topic.npb.h" #if PB_PROTO_HEADER_VERSION != 40 #error Regenerate this file with the current version of nanopb generator. #endif diff --git a/ecal/core/src/serialization/nanopb/topic.pb.h b/ecal/core/src/serialization/nanopb/ecal/core/pb/topic.npb.h similarity index 97% rename from ecal/core/src/serialization/nanopb/topic.pb.h rename to ecal/core/src/serialization/nanopb/ecal/core/pb/topic.npb.h index c7eb1ffc22..97993e98a4 100644 --- a/ecal/core/src/serialization/nanopb/topic.pb.h +++ b/ecal/core/src/serialization/nanopb/ecal/core/pb/topic.npb.h @@ -1,10 +1,10 @@ /* Automatically generated nanopb header */ -/* Generated by nanopb-0.4.8 */ +/* Generated by nanopb-0.4.9 */ -#ifndef PB_ECAL_PB_TOPIC_PB_H_INCLUDED -#define PB_ECAL_PB_TOPIC_PB_H_INCLUDED +#ifndef PB_ECAL_PB_TOPIC_NPB_H_INCLUDED +#define PB_ECAL_PB_TOPIC_NPB_H_INCLUDED #include -#include "layer.pb.h" +#include "ecal/core/pb/layer.npb.h" #if PB_PROTO_HEADER_VERSION != 40 #error Regenerate this file with the current version of nanopb generator. diff --git a/ecal/core/src/serialization/nanopb/nanopb/pb.h b/ecal/core/src/serialization/nanopb/pb.h similarity index 99% rename from ecal/core/src/serialization/nanopb/nanopb/pb.h rename to ecal/core/src/serialization/nanopb/pb.h index c7a055f08f..1bff70e4e6 100644 --- a/ecal/core/src/serialization/nanopb/nanopb/pb.h +++ b/ecal/core/src/serialization/nanopb/pb.h @@ -65,7 +65,7 @@ /* Version of the nanopb library. Just in case you want to check it in * your own program. */ -#define NANOPB_VERSION "nanopb-0.4.8" +#define NANOPB_VERSION "nanopb-0.4.9" /* Include all the system headers needed by nanopb. You will need the * definitions of the following: @@ -215,12 +215,23 @@ PB_STATIC_ASSERT(1, STATIC_ASSERT_IS_NOT_WORKING) #endif #endif +/* Data type for storing encoded data and other byte streams. + * This typedef exists to support platforms where uint8_t does not exist. + * You can regard it as equivalent on uint8_t on other platforms. + */ +#if defined(PB_BYTE_T_OVERRIDE) +typedef PB_BYTE_T_OVERRIDE pb_byte_t; +#elif defined(UINT8_MAX) +typedef uint8_t pb_byte_t; +#else +typedef uint_least8_t pb_byte_t; +#endif + /* List of possible field types. These are used in the autogenerated code. * Least-significant 4 bits tell the scalar type * Most-significant 4 bits specify repeated/required/packed etc. */ - -typedef uint_least8_t pb_type_t; +typedef pb_byte_t pb_type_t; /**** Field data types ****/ @@ -301,12 +312,6 @@ typedef uint_least8_t pb_type_t; #endif #define PB_SIZE_MAX ((pb_size_t)-1) -/* Data type for storing encoded data and other byte streams. - * This typedef exists to support platforms where uint8_t does not exist. - * You can regard it as equivalent on uint8_t on other platforms. - */ -typedef uint_least8_t pb_byte_t; - /* Forward declaration of struct types */ typedef struct pb_istream_s pb_istream_t; typedef struct pb_ostream_s pb_ostream_t; diff --git a/ecal/core/src/serialization/nanopb/nanopb/pb_common.c b/ecal/core/src/serialization/nanopb/pb_common.c similarity index 100% rename from ecal/core/src/serialization/nanopb/nanopb/pb_common.c rename to ecal/core/src/serialization/nanopb/pb_common.c diff --git a/ecal/core/src/serialization/nanopb/nanopb/pb_common.h b/ecal/core/src/serialization/nanopb/pb_common.h similarity index 100% rename from ecal/core/src/serialization/nanopb/nanopb/pb_common.h rename to ecal/core/src/serialization/nanopb/pb_common.h diff --git a/ecal/core/src/serialization/nanopb/nanopb/pb_decode.c b/ecal/core/src/serialization/nanopb/pb_decode.c similarity index 99% rename from ecal/core/src/serialization/nanopb/nanopb/pb_decode.c rename to ecal/core/src/serialization/nanopb/pb_decode.c index 788998eb96..068306a053 100644 --- a/ecal/core/src/serialization/nanopb/nanopb/pb_decode.c +++ b/ecal/core/src/serialization/nanopb/pb_decode.c @@ -4,13 +4,14 @@ */ /* Use the GCC warn_unused_result attribute to check that all return values - * are propagated correctly. On other compilers and gcc before 3.4.0 just - * ignore the annotation. + * are propagated correctly. On other compilers, gcc before 3.4.0 and iar + * before 9.40.1 just ignore the annotation. */ -#if !defined(__GNUC__) || ( __GNUC__ < 3) || (__GNUC__ == 3 && __GNUC_MINOR__ < 4) - #define checkreturn -#else +#if (defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))) || \ + (defined(__IAR_SYSTEMS_ICC__) && (__VER__ >= 9040001)) #define checkreturn __attribute__((warn_unused_result)) +#else + #define checkreturn #endif #include "pb.h" diff --git a/ecal/core/src/serialization/nanopb/nanopb/pb_decode.h b/ecal/core/src/serialization/nanopb/pb_decode.h similarity index 92% rename from ecal/core/src/serialization/nanopb/nanopb/pb_decode.h rename to ecal/core/src/serialization/nanopb/pb_decode.h index ae1d3ccf2e..3f392b2938 100644 --- a/ecal/core/src/serialization/nanopb/nanopb/pb_decode.h +++ b/ecal/core/src/serialization/nanopb/pb_decode.h @@ -37,10 +37,21 @@ struct pb_istream_s bool (*callback)(pb_istream_t *stream, pb_byte_t *buf, size_t count); #endif - void *state; /* Free field for use by callback implementation */ + /* state is a free field for use of the callback function defined above. + * Note that when pb_istream_from_buffer() is used, it reserves this field + * for its own use. + */ + void *state; + + /* Maximum number of bytes left in this stream. Callback can report + * EOF before this limit is reached. Setting a limit is recommended + * when decoding directly from file or network streams to avoid + * denial-of-service by excessively long messages. + */ size_t bytes_left; #ifndef PB_NO_ERRMSG + /* Pointer to constant (ROM) string when decoding function returns error */ const char *errmsg; #endif }; diff --git a/ecal/core/src/serialization/nanopb/nanopb/pb_encode.c b/ecal/core/src/serialization/nanopb/pb_encode.c similarity index 99% rename from ecal/core/src/serialization/nanopb/nanopb/pb_encode.c rename to ecal/core/src/serialization/nanopb/pb_encode.c index 7f56201255..f9034a5428 100644 --- a/ecal/core/src/serialization/nanopb/nanopb/pb_encode.c +++ b/ecal/core/src/serialization/nanopb/pb_encode.c @@ -8,13 +8,14 @@ #include "pb_common.h" /* Use the GCC warn_unused_result attribute to check that all return values - * are propagated correctly. On other compilers and gcc before 3.4.0 just - * ignore the annotation. + * are propagated correctly. On other compilers, gcc before 3.4.0 and iar + * before 9.40.1 just ignore the annotation. */ -#if !defined(__GNUC__) || ( __GNUC__ < 3) || (__GNUC__ == 3 && __GNUC_MINOR__ < 4) - #define checkreturn -#else +#if (defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))) || \ + (defined(__IAR_SYSTEMS_ICC__) && (__VER__ >= 9040001)) #define checkreturn __attribute__((warn_unused_result)) +#else + #define checkreturn #endif /************************************** diff --git a/ecal/core/src/serialization/nanopb/nanopb/pb_encode.h b/ecal/core/src/serialization/nanopb/pb_encode.h similarity index 93% rename from ecal/core/src/serialization/nanopb/nanopb/pb_encode.h rename to ecal/core/src/serialization/nanopb/pb_encode.h index 891368322f..6dc089da30 100644 --- a/ecal/core/src/serialization/nanopb/nanopb/pb_encode.h +++ b/ecal/core/src/serialization/nanopb/pb_encode.h @@ -37,11 +37,21 @@ struct pb_ostream_s #else bool (*callback)(pb_ostream_t *stream, const pb_byte_t *buf, size_t count); #endif - void *state; /* Free field for use by callback implementation. */ - size_t max_size; /* Limit number of output bytes written (or use SIZE_MAX). */ - size_t bytes_written; /* Number of bytes written so far. */ + + /* state is a free field for use of the callback function defined above. + * Note that when pb_ostream_from_buffer() is used, it reserves this field + * for its own use. + */ + void *state; + + /* Limit number of output bytes written. Can be set to SIZE_MAX. */ + size_t max_size; + + /* Number of bytes written so far. */ + size_t bytes_written; #ifndef PB_NO_ERRMSG + /* Pointer to constant (ROM) string when decoding function returns error */ const char *errmsg; #endif }; diff --git a/ecal/tests/cpp/serialization_test/CMakeLists.txt b/ecal/tests/cpp/serialization_test/CMakeLists.txt index 4554421303..2ae63f551c 100644 --- a/ecal/tests/cpp/serialization_test/CMakeLists.txt +++ b/ecal/tests/cpp/serialization_test/CMakeLists.txt @@ -22,32 +22,32 @@ find_package(Threads REQUIRED) find_package(GTest REQUIRED) set(nanopb_lib_src - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/nanopb/pb.h - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/nanopb/pb_common.c - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/nanopb/pb_common.h - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/nanopb/pb_decode.c - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/nanopb/pb_decode.h - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/nanopb/pb_encode.c - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/nanopb/pb_encode.h + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/pb.h + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/pb_common.c + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/pb_common.h + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/pb_decode.c + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/pb_decode.h + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/pb_encode.c + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/pb_encode.h ) set(nanopb_generated_src - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/ecal.pb.c - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/ecal.pb.h - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/host.pb.c - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/host.pb.h - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/layer.pb.c - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/layer.pb.h - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/logging.pb.c - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/logging.pb.h - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/monitoring.pb.c - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/monitoring.pb.h - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/process.pb.c - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/process.pb.h - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/service.pb.c - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/service.pb.h - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/topic.pb.c - ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/topic.pb.h + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/ecal/core/pb/ecal.npb.c + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/ecal/core/pb/ecal.npb.h + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/ecal/core/pb/host.npb.c + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/ecal/core/pb/host.npb.h + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/ecal/core/pb/layer.npb.c + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/ecal/core/pb/layer.npb.h + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/ecal/core/pb/logging.npb.c + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/ecal/core/pb/logging.npb.h + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/ecal/core/pb/monitoring.npb.c + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/ecal/core/pb/monitoring.npb.h + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/ecal/core/pb/process.npb.c + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/ecal/core/pb/process.npb.h + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/ecal/core/pb/service.npb.c + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/ecal/core/pb/service.npb.h + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/ecal/core/pb/topic.npb.c + ${ECAL_CORE_PROJECT_ROOT}/core/src/serialization/nanopb/ecal/core/pb/topic.npb.h ) set(ecal_serialize_src