mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-27 18:27:05 +08:00
cmake: param refactoring
Use a struct to contain all the parameters so the ordering in memory is not machine dependent. Add number of parameters to the param struct. The struct actually allows direct accessing by the member name if desired. Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
+57
-23
@@ -2,52 +2,86 @@
|
|||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
import os
|
import os
|
||||||
|
|
||||||
if len(os.sys.argv) != 3:
|
if len(os.sys.argv) != 2:
|
||||||
print "Error in %s" % os.sys.argv[0]
|
print "Error in %s" % os.sys.argv[0]
|
||||||
print "Usage: %s <parameters.xml> <parameters.c>"
|
print "Usage: %s <parameters.xml>"
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
fp = open(os.sys.argv[2], "w")
|
fp_header = open("px4_parameters.h", "w")
|
||||||
|
fp_src = open("px4_parameters.c", "w")
|
||||||
|
|
||||||
tree = ET.parse(os.sys.argv[1])
|
tree = ET.parse(os.sys.argv[1])
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
body = """
|
|
||||||
|
# Generate the header file content
|
||||||
|
header = """
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <systemlib/param/param.h>
|
#include <systemlib/param/param.h>
|
||||||
|
|
||||||
// DO NOT EDIT
|
// DO NOT EDIT
|
||||||
// This file is autogenerated from paramaters.xml
|
// This file is autogenerated from paramaters.xml
|
||||||
|
|
||||||
|
struct px4_parameters_t {
|
||||||
"""
|
"""
|
||||||
|
|
||||||
start_name = ""
|
start_name = ""
|
||||||
end_name = ""
|
end_name = ""
|
||||||
|
|
||||||
for group in root:
|
for group in root:
|
||||||
if group.tag == "group":
|
if group.tag == "group":
|
||||||
body += "// %s\n" % group.attrib["name"]
|
header += """
|
||||||
|
/*****************************************************************
|
||||||
|
* %s
|
||||||
|
****************************************************************/""" % group.attrib["name"]
|
||||||
for param in group:
|
for param in group:
|
||||||
if not start_name:
|
if not start_name:
|
||||||
start_name = param.attrib["name"]
|
start_name = param.attrib["name"]
|
||||||
end_name = param.attrib["name"]
|
end_name = param.attrib["name"]
|
||||||
body += """
|
header += """
|
||||||
static const
|
const struct param_info_s __param__%s;""" % param.attrib["name"]
|
||||||
__attribute__((used, section("__param")))
|
header += """
|
||||||
struct param_info_s __param__%s = {
|
const unsigned int param_count;
|
||||||
"%s",
|
|
||||||
PARAM_TYPE_%s,
|
|
||||||
.val.f = %s
|
|
||||||
};
|
};
|
||||||
""" % (param.attrib["name"], param.attrib["name"], param.attrib["type"], param.attrib["default"])
|
|
||||||
body += """
|
|
||||||
extern const
|
|
||||||
__attribute__((alias("__param__%s")))
|
|
||||||
struct param_info_s __param_start;
|
|
||||||
|
|
||||||
extern const
|
extern const struct px4_parameters_t px4_parameters;
|
||||||
__attribute__((alias("__param__%s")))
|
"""
|
||||||
struct param_info_s __param_end;
|
|
||||||
""" % (start_name, end_name)
|
|
||||||
|
|
||||||
fp.write(body)
|
# Generate the C file content
|
||||||
|
src = """
|
||||||
|
#include <px4_parameters.h>
|
||||||
|
|
||||||
|
// DO NOT EDIT
|
||||||
|
// This file is autogenerated from paramaters.xml
|
||||||
|
|
||||||
|
static const
|
||||||
|
__attribute__((used, section("__param")))
|
||||||
|
struct px4_parameters_t px4_parameters_impl = {
|
||||||
|
"""
|
||||||
|
i=0
|
||||||
|
for group in root:
|
||||||
|
if group.tag == "group":
|
||||||
|
src += """
|
||||||
|
/*****************************************************************
|
||||||
|
* %s
|
||||||
|
****************************************************************/""" % group.attrib["name"]
|
||||||
|
for param in group:
|
||||||
|
if not start_name:
|
||||||
|
start_name = param.attrib["name"]
|
||||||
|
end_name = param.attrib["name"]
|
||||||
|
i+=1
|
||||||
|
src += """
|
||||||
|
{
|
||||||
|
"%s",
|
||||||
|
PARAM_TYPE_%s,
|
||||||
|
.val.f = %s
|
||||||
|
},
|
||||||
|
""" % (param.attrib["name"], param.attrib["type"], param.attrib["default"])
|
||||||
|
src += """
|
||||||
|
%d
|
||||||
|
};
|
||||||
|
|
||||||
|
extern const struct px4_parameters_t px4_parameters __attribute__((alias("px4_parameters_impl")));
|
||||||
|
""" % i
|
||||||
|
|
||||||
|
fp_header.write(header)
|
||||||
|
fp_src.write(src)
|
||||||
|
|
||||||
|
|||||||
@@ -681,7 +681,7 @@ function(px4_generate_parameters)
|
|||||||
)
|
)
|
||||||
|
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Tools/px_generate_params.py ${CMAKE_BINARY_DIR}/parameters.xml ${CMAKE_BINARY_DIR}/parameters.c
|
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Tools/px_generate_params.py ${CMAKE_BINARY_DIR}/parameters.xml
|
||||||
)
|
)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ px4_generate_parameters()
|
|||||||
|
|
||||||
add_executable(mainapp
|
add_executable(mainapp
|
||||||
${CMAKE_SOURCE_DIR}/src/platforms/posix/main.cpp
|
${CMAKE_SOURCE_DIR}/src/platforms/posix/main.cpp
|
||||||
${CMAKE_BINARY_DIR}/parameters.c
|
${CMAKE_BINARY_DIR}/px4_parameters.c
|
||||||
apps.h
|
apps.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,7 @@
|
|||||||
|
|
||||||
#include "uORB/uORB.h"
|
#include "uORB/uORB.h"
|
||||||
#include "uORB/topics/parameter_update.h"
|
#include "uORB/topics/parameter_update.h"
|
||||||
|
#include "px4_parameters.h"
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
# define debug(fmt, args...) do { warnx(fmt, ##args); } while(0)
|
# define debug(fmt, args...) do { warnx(fmt, ##args); } while(0)
|
||||||
@@ -86,14 +87,11 @@ extern struct param_info_s param_array[];
|
|||||||
extern struct param_info_s *param_info_base;
|
extern struct param_info_s *param_info_base;
|
||||||
extern struct param_info_s *param_info_limit;
|
extern struct param_info_s *param_info_limit;
|
||||||
#else
|
#else
|
||||||
extern const struct param_info_s __param_start, __param_end;
|
|
||||||
|
|
||||||
// FIXME - start and end are reversed
|
// FIXME - start and end are reversed
|
||||||
static const struct param_info_s *param_info_base = &__param_end;
|
static const struct param_info_s *param_info_base = (const struct param_info_s *)&px4_parameters;
|
||||||
static const struct param_info_s *param_info_limit = &__param_start;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define param_info_count ((unsigned)(param_info_limit - param_info_base))
|
#define param_info_count px4_parameters.param_count
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Storage for modified parameters.
|
* Storage for modified parameters.
|
||||||
|
|||||||
Reference in New Issue
Block a user