Skip to content
Snippets Groups Projects
Commit a7580b14 authored by TSC21's avatar TSC21 Committed by Beat Küng
Browse files

update IDL template so it can process builtin types

parent b11ab09d
No related branches found
No related tags found
No related merge requests found
......@@ -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__
......@@ -76,18 +76,20 @@ type_serialize_map = {
}
type_idl_map = {
'bool': 'boolean',
'byte': 'octet',
'char': 'char',
'int8': 'octet',
'int16': 'short',
'int32': 'long',
'int64': 'long long',
'uint8': 'octet',
'int16': 'short',
'uint16': 'unsigned short',
'int32': 'long',
'uint32': 'unsigned long',
'int64': 'long long',
'uint64': 'unsigned long long',
'float32': 'float',
'float64': 'double',
'bool': 'boolean',
'char': 'char',
'string': 'string',
}
msgtype_size_map = {
......
......@@ -8,8 +8,8 @@ rtps:
id: 15
- msg: esc_report
id: 21
#- msg: esc_status
# id: 22
- msg: esc_status
id: 22
- msg: estimator_status
id: 23
- msg: iridiumsbd_status
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment