update IDL template so it can process builtin types

This commit is contained in:
TSC21
2018-10-08 10:58:45 +02:00
committed by Beat Küng
parent b11ab09d29
commit a7580b14ba
3 changed files with 51 additions and 15 deletions
+42 -8
View File
@@ -38,13 +38,27 @@
@{
import genmsg.msgs
import gencpp
from px_generate_uorb_topic_helper import * # this is in Tools/
from px_generate_uorb_topic_helper import * # this is in Tools/
builtin_types = set()
}@
@#################################################
@# Searching for serialize function per each field
@#################################################
@{
def get_include_directives(spec):
include_directives = set()
for field in (spec.parsed_fields()):
if genmsg.msgs.is_valid_constant_type(genmsg.msgs.bare_msg_type(field.type)):
continue
builtin_type = str(field.base_type).replace('px4/', '')
include_directive = '#include "%s_.idl"' % builtin_type
builtin_types.add(builtin_type)
include_directives.add(include_directive)
return sorted(include_directives)
def get_idl_type_name(field_type):
if field_type in type_idl_map:
return type_idl_map[field_type]
@@ -52,23 +66,43 @@ def get_idl_type_name(field_type):
(package, name) = genmsg.names.package_resource_name(field_type)
return name
def add_msg_field(field):
if (not field.is_header):
if (not field.is_array):
print(" " + str(get_idl_type_name(field.type)) + ' ' + field.name + ';')
if field.is_array:
print(" " + str(get_idl_type_name(field.base_type)) +
' ' + field.name + '[' + str(field.array_len) + '];')
else:
print(" " + str(get_idl_type_name(field.base_type)) + ' ' + field.name + '[' +str(field.array_len)+ '];')
print(" " + str(get_idl_type_name(field.type)) +
' ' + field.name + ';')
def add_msg_fields():
# sort fields (using a stable sort) as in the declaration of the type
sorted_fields = sorted(spec.parsed_fields(), key=sizeof_field_type, reverse=True)
sorted_fields = sorted(spec.parsed_fields(),
key=sizeof_field_type, reverse=True)
for field in sorted_fields:
add_msg_field(field)
}@
@
#ifndef __@(spec.short_name)__idl__
#define __@(spec.short_name)__idl__
@#############################
@# Include dependency messages
@#############################
@[for line in get_include_directives(spec)]@
@(line)
@[end for]@
@[for type in builtin_types]@
typedef @(type + '_') @(type);
@[end for]@
struct @(spec.short_name)_
{
@add_msg_fields()
}; // struct @(spec.short_name)_
#pragma keylist @(spec.short_name)_
#endif // __@(spec.short_name)__idl__