mavlink & system: add events interface

- sending protocol
- uorb event message & template methods for argument packing
- libevents submodule to send common events and handle json files
- cmake maintains a list of all (PX4) source files for the current build
  (PX4 modules + libs), which is used to extract event metadata and
  generate a json file
This commit is contained in:
Beat Küng
2021-07-07 21:38:09 -04:00
committed by Daniel Agar
parent 7c5838116a
commit 38f3b8d356
28 changed files with 1007 additions and 3 deletions
@@ -36,9 +36,11 @@
# 1: COMP_METADATA_TYPE_PARAMETER
# 2: COMP_METADATA_TYPE_COMMANDS
# 3: COMP_METADATA_TYPE_PERIPHERALS
# 4: COMP_METADATA_TYPE_EVENTS
set(comp_metadata_types)
set(comp_metadata_board "${PX4_BOARD_VENDOR}_${PX4_BOARD_MODEL}_${PX4_BOARD_LABEL}")
set(s3_url "https://px4-travis.s3.amazonaws.com")
set(comp_metadata_param_uri_board "${s3_url}/Firmware/{version}/${comp_metadata_board}/parameters.json.xz")
list(FIND config_romfs_extra_dependencies "parameters_xml" index)
if (${index} EQUAL -1)
@@ -52,6 +54,19 @@ endif()
# arguments: type, metadata file, uri, fallback uri, optional translation uri
list(APPEND comp_metadata_types "--type" "1,${PX4_BINARY_DIR}/parameters.json.xz,${comp_metadata_param_uri},${comp_metadata_param_uri_fallback},")
set(comp_metadata_events_uri_board "${s3_url}/Firmware/{version}/${comp_metadata_board}/all_events.json.xz")
list(FIND config_romfs_extra_dependencies "events_json" index)
if (${index} EQUAL -1)
set(comp_metadata_events_uri ${comp_metadata_events_uri_board})
# use generic URL as fallback
set(comp_metadata_events_uri_fallback "${s3_url}/Firmware/{version}/_general/all_events.json.xz")
else()
set(comp_metadata_events_uri "mftp://etc/extras/all_events.json.xz")
set(comp_metadata_events_uri_fallback ${comp_metadata_events_uri_board})
endif()
list(APPEND comp_metadata_types "--type" "4,${PX4_BINARY_DIR}/events/all_events.json.xz,${comp_metadata_events_uri},${comp_metadata_events_uri_fallback},")
set(component_general_json ${PX4_BINARY_DIR}/component_general.json)
add_custom_command(OUTPUT ${component_general_json} ${component_general_json}.xz
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/generate_component_general.py
@@ -63,6 +78,8 @@ add_custom_command(OUTPUT ${component_general_json} ${component_general_json}.xz
generate_component_general.py
${PX4_BINARY_DIR}/parameters.json.xz
parameters_xml
${PX4_BINARY_DIR}/events/all_events.json.xz
events_json
ver_gen
COMMENT "Generating component_general.json"
)
+95
View File
@@ -0,0 +1,95 @@
############################################################################
#
# Copyright (c) 2020 PX4 Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name PX4 nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
px4_add_git_submodule(TARGET git_libevents PATH "libevents")
get_property(all_px4_src_files GLOBAL PROPERTY PX4_SRC_FILES)
set(generated_events_dir ${PX4_BINARY_DIR}/events)
set(generated_events_px4_file ${generated_events_dir}/px4.json)
add_custom_command(OUTPUT ${generated_events_px4_file}
COMMAND ${CMAKE_COMMAND} -E make_directory ${generated_events_dir}
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/px_process_events.py
--src-path ${all_px4_src_files}
--json ${generated_events_px4_file} #--verbose
DEPENDS
${all_px4_src_files}
${PX4_SOURCE_DIR}/Tools/px_process_events.py
${PX4_SOURCE_DIR}/Tools/px4events/jsonout.py
${PX4_SOURCE_DIR}/Tools/px4events/srcparser.py
${PX4_SOURCE_DIR}/Tools/px4events/srcscanner.py
COMMENT "Generating px4 event json file from source"
)
add_custom_target(events_px4_json DEPENDS ${generated_events_px4_file})
set(generated_events_file ${generated_events_dir}/all_events.json)
add_custom_command(OUTPUT ${generated_events_file} ${generated_events_file}.xz
COMMAND ${PYTHON_EXECUTABLE} libevents/scripts/combine.py
${generated_events_px4_file}
libevents/events/common.json
--output ${generated_events_file}
COMMAND ${PYTHON_EXECUTABLE} libevents/scripts/validate.py
${generated_events_file}
COMMAND ${PYTHON_EXECUTABLE} ${PX4_SOURCE_DIR}/Tools/compress.py
${generated_events_file}
DEPENDS
${generated_events_px4_file}
libevents/events/common.json
libevents/scripts/combine.py
libevents/scripts/validate.py
${PX4_SOURCE_DIR}/Tools/compress.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating combined event json file"
)
add_custom_target(events_json DEPENDS ${generated_events_file})
# generate header from common.json
# (we don't add the definitions from the source as they are not needed and to
# avoid additional dependencies)
set(generated_events_header ${generated_events_dir}/events_generated.h)
add_custom_command(OUTPUT ${generated_events_header}
COMMAND ${CMAKE_COMMAND} -E make_directory ${generated_events_dir}
COMMAND ${PYTHON_EXECUTABLE} libevents/scripts/generate.py
--template libevents/libs/cpp/templates/events_generated.h.jinja
--output ${generated_events_dir}
libevents/events/common.json
DEPENDS
libevents/events/common.json
libevents/libs/cpp/templates/events_generated.h.jinja
libevents/scripts/generate.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating px4 event header file"
)
add_custom_target(events_header DEPENDS ${generated_events_header})
add_dependencies(prebuild_targets events_header)