From 0e4034d01ebe3abc0fd070f88419d4580347f81e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Wed, 31 Jan 2018 10:23:50 +0100 Subject: [PATCH] param: add a px4_parameters_public.h.jinja template Generates an enum with all params & additional type information for static type checking The generated public param header is required to build the modules using the new BlockParam classes. --- CMakeLists.txt | 2 +- src/modules/systemlib/param/CMakeLists.txt | 8 +++- .../systemlib/param/px_generate_params.py | 1 + .../templates/px4_parameters_public.h.jinja | 37 +++++++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 src/modules/systemlib/param/templates/px4_parameters_public.h.jinja diff --git a/CMakeLists.txt b/CMakeLists.txt index c5f1bf449b..fc5dec731e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -335,7 +335,7 @@ px4_join(OUT CMAKE_EXE_LINKER_FLAGS LIST "${CMAKE_EXE_LINKER_FLAGS};${exe_linker px4_join(OUT CMAKE_C_FLAGS LIST "${CMAKE_C_FLAGS};${c_flags};${optimization_flags}" GLUE " ") px4_join(OUT CMAKE_CXX_FLAGS LIST "${CMAKE_CXX_FLAGS};${cxx_flags};${optimization_flags}" GLUE " ") -include_directories(${include_dirs}) +include_directories(${include_dirs} ${CMAKE_CURRENT_BINARY_DIR}/src/modules/systemlib/param) link_directories(${link_dirs}) add_definitions(${definitions}) diff --git a/src/modules/systemlib/param/CMakeLists.txt b/src/modules/systemlib/param/CMakeLists.txt index c29c458c97..b74b3fc03b 100644 --- a/src/modules/systemlib/param/CMakeLists.txt +++ b/src/modules/systemlib/param/CMakeLists.txt @@ -98,8 +98,8 @@ add_custom_command(OUTPUT ${parameters_xml} ) add_custom_target(parameters_xml DEPENDS ${parameters_xml}) -# generate px4_parameters.c and px4_parameters.h -add_custom_command(OUTPUT px4_parameters.c px4_parameters.h +# generate px4_parameters.c and px4_parameters{,_public}.h +add_custom_command(OUTPUT px4_parameters.c px4_parameters.h px4_parameters_public.h COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/px_generate_params.py --xml ${parameters_xml} --dest ${CMAKE_CURRENT_BINARY_DIR} DEPENDS @@ -107,8 +107,12 @@ add_custom_command(OUTPUT px4_parameters.c px4_parameters.h px_generate_params.py templates/px4_parameters.c.jinja templates/px4_parameters.h.jinja + templates/px4_parameters_public.h.jinja ) +add_custom_target(parameter_headers DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/px4_parameters_public.h) +add_dependencies(prebuild_targets parameter_headers) + px4_add_module( MODULE modules__systemlib__param COMPILE_FLAGS diff --git a/src/modules/systemlib/param/px_generate_params.py b/src/modules/systemlib/param/px_generate_params.py index 103e0c3bce..af746fb7ed 100755 --- a/src/modules/systemlib/param/px_generate_params.py +++ b/src/modules/systemlib/param/px_generate_params.py @@ -40,6 +40,7 @@ def generate(xml_file, dest='.'): template_files = [ 'px4_parameters.h.jinja', + 'px4_parameters_public.h.jinja', 'px4_parameters.c.jinja', ] for template_file in template_files: diff --git a/src/modules/systemlib/param/templates/px4_parameters_public.h.jinja b/src/modules/systemlib/param/templates/px4_parameters_public.h.jinja new file mode 100644 index 0000000000..5685f615aa --- /dev/null +++ b/src/modules/systemlib/param/templates/px4_parameters_public.h.jinja @@ -0,0 +1,37 @@ +{# jinja syntax: http://jinja.pocoo.org/docs/2.9/templates/ #} +#include +#include + +// DO NOT EDIT +// This file is autogenerated from parameters.xml + + +#ifdef __cplusplus + +namespace px4 { {# wrap the enum in a namespace, otherwise we get shadowing errors for MAV_TYPE #} + +/// Enum with all parameters +enum class params { + {# enums are guaranteed to start with 0 (if the value for the first is not + specified), and then incremented by 1 #} +{%- for param in params %} + {{ param.attrib["name"] }}, +{%- endfor %} + + _COUNT +}; + +// All parameter types +{# (px4_parameters is marked as extern, so we cannot use it as constexpr) #} +static const constexpr int param_types_array[] = { +{%- for param in params %} + PARAM_TYPE_{{ param.attrib["type"] }}, // {{ param.attrib["name"] }} +{%- endfor %} +}; + + +} // namespace px4 + + +#endif /* __cplusplus */ +