|
|
|
@ -2,52 +2,86 @@
@@ -2,52 +2,86 @@
|
|
|
|
|
import xml.etree.ElementTree as ET |
|
|
|
|
import os |
|
|
|
|
|
|
|
|
|
if len(os.sys.argv) != 3: |
|
|
|
|
if len(os.sys.argv) != 2: |
|
|
|
|
print "Error in %s" % os.sys.argv[0] |
|
|
|
|
print "Usage: %s <parameters.xml> <parameters.c>" |
|
|
|
|
print "Usage: %s <parameters.xml>" |
|
|
|
|
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]) |
|
|
|
|
root = tree.getroot() |
|
|
|
|
body = """ |
|
|
|
|
|
|
|
|
|
# Generate the header file content |
|
|
|
|
header = """ |
|
|
|
|
#include <stdint.h> |
|
|
|
|
#include <systemlib/param/param.h> |
|
|
|
|
|
|
|
|
|
// DO NOT EDIT |
|
|
|
|
// This file is autogenerated from paramaters.xml |
|
|
|
|
|
|
|
|
|
struct px4_parameters_t { |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
start_name = "" |
|
|
|
|
end_name = "" |
|
|
|
|
|
|
|
|
|
for group in root: |
|
|
|
|
if group.tag == "group": |
|
|
|
|
body += "// %s\n" % group.attrib["name"] |
|
|
|
|
header += """ |
|
|
|
|
/***************************************************************** |
|
|
|
|
* %s |
|
|
|
|
****************************************************************/""" % group.attrib["name"] |
|
|
|
|
for param in group: |
|
|
|
|
if not start_name: |
|
|
|
|
start_name = param.attrib["name"] |
|
|
|
|
end_name = param.attrib["name"] |
|
|
|
|
body += """ |
|
|
|
|
header += """ |
|
|
|
|
const struct param_info_s __param__%s;""" % param.attrib["name"] |
|
|
|
|
header += """ |
|
|
|
|
const unsigned int param_count; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
extern const struct px4_parameters_t px4_parameters; |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
# 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 param_info_s __param__%s = { |
|
|
|
|
"%s", |
|
|
|
|
PARAM_TYPE_%s, |
|
|
|
|
.val.f = %s |
|
|
|
|
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 |
|
|
|
|
}; |
|
|
|
|
""" % (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 |
|
|
|
|
__attribute__((alias("__param__%s"))) |
|
|
|
|
struct param_info_s __param_end; |
|
|
|
|
""" % (start_name, end_name) |
|
|
|
|
|
|
|
|
|
fp.write(body) |
|
|
|
|
|
|
|
|
|
extern const struct px4_parameters_t px4_parameters __attribute__((alias("px4_parameters_impl"))); |
|
|
|
|
""" % i |
|
|
|
|
|
|
|
|
|
fp_header.write(header) |
|
|
|
|
fp_src.write(src) |
|
|
|
|
|
|
|
|
|