diff --git a/msg/templates/uorb/msg.cpp.template b/msg/templates/uorb/msg.cpp.template index ff5afb297e..54313dc5ec 100644 --- a/msg/templates/uorb/msg.cpp.template +++ b/msg/templates/uorb/msg.cpp.template @@ -57,8 +57,7 @@ uorb_struct = '%s_s'%spec.short_name uorb_pack_func = 'pack_%s'%spec.short_name topic_name = spec.short_name -type_map = { - 'int8': 'int8_t', +type_map = {'int8': 'int8_t', 'int16': 'int16_t', 'int32': 'int32_t', 'int64': 'int64_t', @@ -72,11 +71,9 @@ type_map = { 'char': 'char', 'fence_vertex': 'fence_vertex', 'position_setpoint': 'position_setpoint', - 'esc_report': 'esc_report' -} + 'esc_report': 'esc_report'} -msgtype_size_map = { - 'int8': 8, +msgtype_size_map = {'int8': 8, 'int16': 16, 'int32': 32, 'int64': 64, @@ -90,8 +87,7 @@ msgtype_size_map = { 'char': 1, 'fence_vertex': 8, 'position_setpoint': 104, - 'esc_report': 36 -} + 'esc_report': 36} def convert_type(spec_type): bare_type = spec_type diff --git a/msg/templates/uorb/msg.h.template b/msg/templates/uorb/msg.h.template index 564657c2e9..8ad98c61d5 100644 --- a/msg/templates/uorb/msg.h.template +++ b/msg/templates/uorb/msg.h.template @@ -63,6 +63,11 @@ topic_name = spec.short_name @# Generic Includes @############################## #include +#ifdef __cplusplus +#include +#else +#include +#endif #include @############################## @@ -88,8 +93,7 @@ for field in spec.parsed_fields(): @# Main struct of message @############################## @{ -type_map = { - 'int8': 'int8_t', +type_map = {'int8': 'int8_t', 'int16': 'int16_t', 'int32': 'int32_t', 'int64': 'int64_t', @@ -124,6 +128,33 @@ msgtype_size_map = { 'esc_report': 36 } +def bare_name(msg_type): + bare = msg_type + if '/' in msg_type: + # removing prefix + bare = (msg_type.split('/'))[1] + # removing suffix + return bare.split('[')[0] + +def sizeof_field_type(field): + return msgtype_size_map[bare_name(field.type)] + +msgtype_size_map = {'int8': 8, + 'int16': 16, + 'int32': 32, + 'int64': 64, + 'uint8': 8, + 'uint16': 16, + 'uint32': 32, + 'uint64': 64, + 'float32': 32, + 'float64': 64, + 'bool': 1, + 'char': 1, + 'fence_vertex': 8, + 'position_setpoint': 104, + 'esc_report': 36} + def bare_name(msg_type): bare = msg_type if '/' in msg_type: @@ -173,8 +204,7 @@ def print_parsed_fields(): }@ -// #pragma pack(push, 1) -ORBPACKED( +#pragma pack(push, 1) #ifdef __cplusplus @#class @(uorb_struct) { struct __EXPORT @(uorb_struct) { @@ -199,8 +229,12 @@ for constant in spec.constants: print('\tstatic const %s %s = %s;'%(type_px4, constant.name, int(constant.val))) } #endif -}); -//#pragma pack(pop) +}; +#pragma pack(pop) + +/** + * @@} + */ /* register this as object request broker structure */ @[for multi_topic in topics]@ diff --git a/src/modules/uORB/uORB.h b/src/modules/uORB/uORB.h index f58e093090..d9e57c9436 100644 --- a/src/modules/uORB/uORB.h +++ b/src/modules/uORB/uORB.h @@ -118,7 +118,7 @@ enum ORB_PRIO { * * @param _name The name of the topic. * @param _struct The structure the topic provides. - * @param _fields All fields in a semicolon separated list e.g: "float[3] position;bool armed" + * @param _func The pointer to a function that packs topic */ #define ORB_DEFINE(_name, _struct, _fields) \ const struct orb_metadata __orb_##_name = { \