microRTPS_bridge: structural change to make possible to generate pub/sub code for multi-topics/aliased msgs

This commit is contained in:
TSC21
2019-07-26 15:05:54 +02:00
committed by Beat Küng
parent a747116eab
commit 3d9f83a4f2
23 changed files with 290 additions and 153 deletions
@@ -18,9 +18,11 @@ import gencpp
from px_generate_uorb_topic_helper import * # this is in Tools/
from px_generate_uorb_topic_files import MsgScope # this is in Tools/
topic_names = [single_spec.short_name for single_spec in spec]
send_topics = [s.short_name for idx, s in enumerate(spec) if scope[idx] == MsgScope.SEND]
recv_topics = [s.short_name for idx, s in enumerate(spec) if scope[idx] == MsgScope.RECEIVE]
topic_names = [s.short_name for idx, s in enumerate(spec)]
send_topics = [(alias[idx] if alias[idx] else s.short_name) for idx, s in enumerate(spec) if scope[idx] == MsgScope.SEND]
send_base_types = [s.short_name for idx, s in enumerate(spec) if scope[idx] == MsgScope.SEND]
recv_topics = [(alias[idx] if alias[idx] else s.short_name) for idx, s in enumerate(spec) if scope[idx] == MsgScope.RECEIVE]
receive_base_types = [s.short_name for idx, s in enumerate(spec) if scope[idx] == MsgScope.RECEIVE]
}@
/****************************************************************************
*
@@ -108,11 +110,11 @@ void* send(void* /*unused*/)
if (updated)
{
// obtained data for the file descriptor
struct @(topic)_s data;
struct @(send_base_types[idx])_s data;
// copy raw data into local buffer
if (orb_copy(ORB_ID(@(topic)), fds[@(idx)], &data) == 0) {
/* payload is shifted by header length to make room for header*/
serialize_@(topic)(&writer, &data, &data_buffer[header_length], &length);
serialize_@(send_base_types[idx])(&writer, &data, &data_buffer[header_length], &length);
if (0 < (read = transport_node->write((char)@(rtps_message_id(ids, topic)), data_buffer, length)))
{
@@ -161,8 +163,8 @@ void micrortps_start_topics(struct timespec &begin, int &total_read, uint32_t &r
uint8_t topic_ID = 255;
// Declare received topics
@[for topic in recv_topics]@
struct @(topic)_s @(topic)_data;
@[for idx, topic in enumerate(recv_topics)]@
struct @(receive_base_types[idx])_s @(topic)_data;
orb_advert_t @(topic)_pub = nullptr;
@[end for]@
@@ -188,11 +190,10 @@ void micrortps_start_topics(struct timespec &begin, int &total_read, uint32_t &r
total_read += read;
switch (topic_ID)
{
@[for topic in recv_topics]@
@[for idx, topic in enumerate(recv_topics)]@
case @(rtps_message_id(ids, topic)):
{
deserialize_@(topic)(&reader, &@(topic)_data, data_buffer);
deserialize_@(receive_base_types[idx])(&reader, &@(topic)_data, data_buffer);
if (!@(topic)_pub) {
@(topic)_pub = orb_advertise(ORB_ID(@(topic)), &@(topic)_data);
} else {
+2 -1
View File
@@ -15,11 +15,12 @@ import genmsg.msgs
import gencpp
from px_generate_uorb_topic_helper import * # this is in Tools/
topic = spec.short_name
topic = alias if alias else spec.short_name
}@
/****************************************************************************
*
* Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima).
* Copyright (C) 2018-2019 PX4 Pro Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
+2 -1
View File
@@ -15,11 +15,12 @@ import genmsg.msgs
import gencpp
from px_generate_uorb_topic_helper import * # this is in Tools/
topic = spec.short_name
topic = alias if alias else spec.short_name
}@
/****************************************************************************
*
* Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima).
* Copyright (C) 2018-2019 PX4 Pro Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
+4 -3
View File
@@ -17,12 +17,13 @@ import gencpp
from px_generate_uorb_topic_helper import * # this is in Tools/
from px_generate_uorb_topic_files import MsgScope # this is in Tools/
send_topics = [s.short_name for idx, s in enumerate(spec) if scope[idx] == MsgScope.SEND]
recv_topics = [s.short_name for idx, s in enumerate(spec) if scope[idx] == MsgScope.RECEIVE]
send_topics = [(alias[idx] if alias[idx] else s.short_name) for idx, s in enumerate(spec) if scope[idx] == MsgScope.SEND]
recv_topics = [(alias[idx] if alias[idx] else s.short_name) for idx, s in enumerate(spec) if scope[idx] == MsgScope.RECEIVE]
}@
/****************************************************************************
*
* Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima).
* Copyright (C) 2018-2019 PX4 Pro Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -88,7 +89,7 @@ void RtpsTopics::publish(uint8_t topic_ID, char data_buffer[], size_t len)
{
switch (topic_ID)
{
@[for topic in send_topics]@
@[for idx, topic in enumerate(send_topics)]@
case @(rtps_message_id(ids, topic)): // @(topic)
{
@(topic)_ st;
+3 -3
View File
@@ -17,13 +17,13 @@ import gencpp
from px_generate_uorb_topic_helper import * # this is in Tools/
from px_generate_uorb_topic_files import MsgScope # this is in Tools/
topic_names = [single_spec.short_name for single_spec in spec]
send_topics = [s.short_name for idx, s in enumerate(spec) if scope[idx] == MsgScope.SEND]
recv_topics = [s.short_name for idx, s in enumerate(spec) if scope[idx] == MsgScope.RECEIVE]
send_topics = [(alias[idx] if alias[idx] else s.short_name) for idx, s in enumerate(spec) if scope[idx] == MsgScope.SEND]
recv_topics = [(alias[idx] if alias[idx] else s.short_name) for idx, s in enumerate(spec) if scope[idx] == MsgScope.RECEIVE]
}@
/****************************************************************************
*
* Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima).
* Copyright (C) 2018-2019 PX4 Pro Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
+2 -1
View File
@@ -15,11 +15,12 @@ import genmsg.msgs
import gencpp
from px_generate_uorb_topic_helper import * # this is in Tools/
topic = spec.short_name
topic = alias if alias else spec.short_name
}@
/****************************************************************************
*
* Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima).
* Copyright (C) 2018-2019 PX4 Pro Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
+2 -1
View File
@@ -15,11 +15,12 @@ import genmsg.msgs
import gencpp
from px_generate_uorb_topic_helper import * # this is in Tools/
topic = spec.short_name
topic = alias if alias else spec.short_name
}@
/****************************************************************************
*
* Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima).
* Copyright (C) 2018-2019 PX4 Pro Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
+2 -3
View File
@@ -16,9 +16,8 @@ import gencpp
from px_generate_uorb_topic_helper import * # this is in Tools/
from px_generate_uorb_topic_files import MsgScope # this is in Tools/
topic_names = [single_spec.short_name for single_spec in spec]
send_topics = [s.short_name for idx, s in enumerate(spec) if scope[idx] == MsgScope.SEND]
recv_topics = [s.short_name for idx, s in enumerate(spec) if scope[idx] == MsgScope.RECEIVE]
send_topics = [(alias[idx] if alias[idx] else s.short_name) for idx, s in enumerate(spec) if scope[idx] == MsgScope.SEND]
recv_topics = [(alias[idx] if alias[idx] else s.short_name) for idx, s in enumerate(spec) if scope[idx] == MsgScope.RECEIVE]
}@
/****************************************************************************
*
@@ -1,6 +1,7 @@
################################################################################
#
# Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima).
# Copyright (C) 2018-2019 PX4 Pro Development Team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@@ -1,6 +1,7 @@
/****************************************************************************
*
* Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima).
* Copyright (C) 2018-2019 PX4 Pro Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
+12 -9
View File
@@ -7,6 +7,7 @@
@################################################################################
@#
@# Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima).
@# Copyright (C) 2018-2019 PX4 Development Team. All rights reserved.
@#
@# Redistribution and use in source and binary forms, with or without
@# modification, are permitted provided that the following conditions are met:
@@ -42,6 +43,8 @@ from px_generate_uorb_topic_helper import * # this is in Tools/
builtin_types = set()
array_types = set()
topic = alias if alias else spec.short_name
}@
@#################################################
@# Searching for serialize function per each field
@@ -71,7 +74,7 @@ def get_idl_type_name(field_type):
def add_msg_field(field):
if (not field.is_header):
if field.is_array:
print(' {0}__{1}_array_{2} {3}_;'.format(spec.short_name, str(get_idl_type_name(field.base_type)).replace(" ", "_"), str(field.array_len), field.name))
print(' {0}__{1}_array_{2} {3}_;'.format(topic, str(get_idl_type_name(field.base_type)).replace(" ", "_"), str(field.array_len), field.name))
else:
base_type = get_idl_type_name(field.base_type) + "_" if get_idl_type_name(field.base_type) in builtin_types else get_idl_type_name(field.base_type)
print(' {0} {1}_;'.format(base_type, field.name))
@@ -86,7 +89,7 @@ def add_array_typedefs():
for field in spec.parsed_fields():
if not field.is_header and field.is_array:
base_type = get_idl_type_name(field.base_type) + "_" if get_idl_type_name(field.base_type) in builtin_types else get_idl_type_name(field.base_type)
array_type = 'typedef {0} {1}__{2}_array_{3}[{4}];'.format(base_type, spec.short_name, get_idl_type_name(field.base_type).replace(" ", "_"), field.array_len, field.array_len)
array_type = 'typedef {0} {1}__{2}_array_{3}[{4}];'.format(base_type, topic, get_idl_type_name(field.base_type).replace(" ", "_"), field.array_len, field.array_len)
if array_type not in array_types:
array_types.add(array_type)
for atype in array_types:
@@ -97,11 +100,11 @@ def add_msg_constants():
sorted_constants = sorted(spec.constants,
key=sizeof_field_type, reverse=True)
for constant in sorted_constants:
print('const {0} {1}__{2} = {3};'.format(get_idl_type_name(constant.type), spec.short_name, constant.name, constant.val))
print('const {0} {1}__{2} = {3};'.format(get_idl_type_name(constant.type), topic, constant.name, constant.val))
}
#ifndef __@(spec.short_name)__idl__
#define __@(spec.short_name)__idl__
#ifndef __@(topic)__idl__
#define __@(topic)__idl__
@#############################
@# Include dependency messages
@@ -113,11 +116,11 @@ def add_msg_constants():
@add_msg_constants()
@# Array types
@add_array_typedefs()
struct @(spec.short_name)_
struct @(topic)_
{
@add_msg_fields()
}; // struct @(spec.short_name)_
}; // struct @(topic)_
#pragma keylist @(spec.short_name)_
#pragma keylist @(topic)_
#endif // __@(spec.short_name)__idl__
#endif // __@(topic)__idl__