uorb autogeneration

This commit is contained in:
Daniel Agar
2016-04-25 17:36:13 -04:00
committed by Lorenz Meier
parent 728de5f87b
commit 9a0e962cbf
3 changed files with 45 additions and 15 deletions
+4 -8
View File
@@ -57,8 +57,7 @@ uorb_struct = '%s_s'%spec.short_name
uorb_pack_func = 'pack_%s'%spec.short_name uorb_pack_func = 'pack_%s'%spec.short_name
topic_name = spec.short_name topic_name = spec.short_name
type_map = { type_map = {'int8': 'int8_t',
'int8': 'int8_t',
'int16': 'int16_t', 'int16': 'int16_t',
'int32': 'int32_t', 'int32': 'int32_t',
'int64': 'int64_t', 'int64': 'int64_t',
@@ -72,11 +71,9 @@ type_map = {
'char': 'char', 'char': 'char',
'fence_vertex': 'fence_vertex', 'fence_vertex': 'fence_vertex',
'position_setpoint': 'position_setpoint', 'position_setpoint': 'position_setpoint',
'esc_report': 'esc_report' 'esc_report': 'esc_report'}
}
msgtype_size_map = { msgtype_size_map = {'int8': 8,
'int8': 8,
'int16': 16, 'int16': 16,
'int32': 32, 'int32': 32,
'int64': 64, 'int64': 64,
@@ -90,8 +87,7 @@ msgtype_size_map = {
'char': 1, 'char': 1,
'fence_vertex': 8, 'fence_vertex': 8,
'position_setpoint': 104, 'position_setpoint': 104,
'esc_report': 36 'esc_report': 36}
}
def convert_type(spec_type): def convert_type(spec_type):
bare_type = spec_type bare_type = spec_type
+40 -6
View File
@@ -63,6 +63,11 @@ topic_name = spec.short_name
@# Generic Includes @# Generic Includes
@############################## @##############################
#include <stdint.h> #include <stdint.h>
#ifdef __cplusplus
#include <cstring>
#else
#include <string.h>
#endif
#include <uORB/uORB.h> #include <uORB/uORB.h>
@############################## @##############################
@@ -88,8 +93,7 @@ for field in spec.parsed_fields():
@# Main struct of message @# Main struct of message
@############################## @##############################
@{ @{
type_map = { type_map = {'int8': 'int8_t',
'int8': 'int8_t',
'int16': 'int16_t', 'int16': 'int16_t',
'int32': 'int32_t', 'int32': 'int32_t',
'int64': 'int64_t', 'int64': 'int64_t',
@@ -124,6 +128,33 @@ msgtype_size_map = {
'esc_report': 36 '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): def bare_name(msg_type):
bare = msg_type bare = msg_type
if '/' in msg_type: if '/' in msg_type:
@@ -173,8 +204,7 @@ def print_parsed_fields():
}@ }@
// #pragma pack(push, 1) #pragma pack(push, 1)
ORBPACKED(
#ifdef __cplusplus #ifdef __cplusplus
@#class @(uorb_struct) { @#class @(uorb_struct) {
struct __EXPORT @(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))) print('\tstatic const %s %s = %s;'%(type_px4, constant.name, int(constant.val)))
} }
#endif #endif
}); };
//#pragma pack(pop) #pragma pack(pop)
/**
* @@}
*/
/* register this as object request broker structure */ /* register this as object request broker structure */
@[for multi_topic in topics]@ @[for multi_topic in topics]@
+1 -1
View File
@@ -118,7 +118,7 @@ enum ORB_PRIO {
* *
* @param _name The name of the topic. * @param _name The name of the topic.
* @param _struct The structure the topic provides. * @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) \ #define ORB_DEFINE(_name, _struct, _fields) \
const struct orb_metadata __orb_##_name = { \ const struct orb_metadata __orb_##_name = { \