Skip to content

Commit

Permalink
microRTPS_bridge: structural change to make possible to generate pub/…
Browse files Browse the repository at this point in the history
…sub code for multi-topics/aliased msgs
  • Loading branch information
TSC21 authored and bkueng committed Jul 26, 2019
1 parent a747116 commit 3d9f83a
Show file tree
Hide file tree
Showing 23 changed files with 287 additions and 150 deletions.
2 changes: 1 addition & 1 deletion Tools/sitl_gazebo
21 changes: 11 additions & 10 deletions msg/templates/uorb_microcdr/microRTPS_client.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}@
/****************************************************************************
*
Expand Down Expand Up @@ -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)))
{
Expand Down Expand Up @@ -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]@

Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion msg/templates/urtps/Publisher.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion msg/templates/urtps/Publisher.h.em
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions msg/templates/urtps/RtpsTopics.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions msg/templates/urtps/RtpsTopics.h.em
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion msg/templates/urtps/Subscriber.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion msg/templates/urtps/Subscriber.h.em
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions msg/templates/urtps/microRTPS_agent.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}@
/****************************************************************************
*
Expand Down
1 change: 1 addition & 0 deletions msg/templates/urtps/microRTPS_agent_CMakeLists.txt.em
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
1 change: 1 addition & 0 deletions msg/templates/urtps/microRTPS_transport.h
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
21 changes: 12 additions & 9 deletions msg/templates/urtps/msg.idl.em
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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__
Loading

0 comments on commit 3d9f83a

Please sign in to comment.