mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-29 03:36:07 +08:00
Update micro-CDR to latest and fix API usage (#9651)
* uorb_microcdr: msg.cpp.template: update API for how the buffer length is obtained * micrortps_bridge: CMakeLists: temporarily deactivate check endianness option
This commit is contained in:
committed by
Daniel Agar
parent
72de9a901d
commit
83fd5a5fd1
@@ -454,7 +454,7 @@ function(px4_add_common_flags)
|
|||||||
|
|
||||||
set(visibility_flags
|
set(visibility_flags
|
||||||
-fvisibility=hidden
|
-fvisibility=hidden
|
||||||
-include visibility.h
|
-include ${PX4_SOURCE_DIR}/src/include/visibility.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(added_c_flags
|
set(added_c_flags
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ recv_topics = [s.short_name for idx, s in enumerate(spec) if scope[idx] == MsgSc
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#include <microcdr/microCdr.h>
|
#include <microcdr/microcdr.h>
|
||||||
#include <px4_time.h>
|
#include <px4_time.h>
|
||||||
#include <uORB/uORB.h>
|
#include <uORB/uORB.h>
|
||||||
|
|
||||||
@@ -90,13 +90,10 @@ void* send(void* /*unused*/)
|
|||||||
orb_set_interval(fds[@(idx)], _options.update_time_ms);
|
orb_set_interval(fds[@(idx)], _options.update_time_ms);
|
||||||
@[end for]@
|
@[end for]@
|
||||||
|
|
||||||
// microBuffer to serialized using the user defined buffer
|
// MicroBuffer to serialized using the user defined buffer
|
||||||
struct microBuffer microBufferWriter;
|
MicroBuffer MicroBufferWriter;
|
||||||
header_length=transport_node->get_header_length();
|
header_length=transport_node->get_header_length();
|
||||||
initStaticAlignedBuffer(&data_buffer[header_length], BUFFER_SIZE-header_length, µBufferWriter);
|
init_micro_buffer(&MicroBufferWriter, (uint8_t*)&data_buffer[header_length], BUFFER_SIZE - header_length);
|
||||||
// microCDR structs for managing the microBuffer
|
|
||||||
struct microCDR microCDRWriter;
|
|
||||||
initMicroCDR(µCDRWriter, µBufferWriter);
|
|
||||||
|
|
||||||
struct timespec begin;
|
struct timespec begin;
|
||||||
px4_clock_gettime(CLOCK_REALTIME, &begin);
|
px4_clock_gettime(CLOCK_REALTIME, &begin);
|
||||||
@@ -113,7 +110,7 @@ void* send(void* /*unused*/)
|
|||||||
// copy raw data into local buffer
|
// copy raw data into local buffer
|
||||||
if (orb_copy(ORB_ID(@(topic)), fds[@(idx)], &data) == 0) {
|
if (orb_copy(ORB_ID(@(topic)), fds[@(idx)], &data) == 0) {
|
||||||
/* payload is shifted by header length to make room for header*/
|
/* payload is shifted by header length to make room for header*/
|
||||||
serialize_@(topic)(&data, &data_buffer[header_length], &length, µCDRWriter);
|
serialize_@(topic)(&MicroBufferWriter, &data, &data_buffer[header_length], &length);
|
||||||
|
|
||||||
if (0 < (read = transport_node->write((char)@(message_id(topic)), data_buffer, length)))
|
if (0 < (read = transport_node->write((char)@(message_id(topic)), data_buffer, length)))
|
||||||
{
|
{
|
||||||
@@ -167,12 +164,9 @@ void micrortps_start_topics(struct timespec &begin, int &total_read, uint32_t &r
|
|||||||
orb_advert_t @(topic)_pub = nullptr;
|
orb_advert_t @(topic)_pub = nullptr;
|
||||||
@[end for]@
|
@[end for]@
|
||||||
|
|
||||||
// microBuffer to deserialized using the user defined buffer
|
// MicroBuffer to deserialized using the user defined buffer
|
||||||
struct microBuffer microBufferReader;
|
MicroBuffer MicroBufferReader;
|
||||||
initDeserializedAlignedBuffer(data_buffer, BUFFER_SIZE, µBufferReader);
|
init_micro_buffer(&MicroBufferReader, (uint8_t*)data_buffer, BUFFER_SIZE);
|
||||||
// microCDR structs for managing the microBuffer
|
|
||||||
struct microCDR microCDRReader;
|
|
||||||
initMicroCDR(µCDRReader, µBufferReader);
|
|
||||||
@[end if]@
|
@[end if]@
|
||||||
|
|
||||||
px4_clock_gettime(CLOCK_REALTIME, &begin);
|
px4_clock_gettime(CLOCK_REALTIME, &begin);
|
||||||
@@ -195,7 +189,7 @@ void micrortps_start_topics(struct timespec &begin, int &total_read, uint32_t &r
|
|||||||
@[for topic in recv_topics]@
|
@[for topic in recv_topics]@
|
||||||
case @(message_id(topic)):
|
case @(message_id(topic)):
|
||||||
{
|
{
|
||||||
deserialize_@(topic)(&@(topic)_data, data_buffer, µCDRReader);
|
deserialize_@(topic)(&MicroBufferReader, &@(topic)_data, data_buffer);
|
||||||
if (!@(topic)_pub) {
|
if (!@(topic)_pub) {
|
||||||
@(topic)_pub = orb_advertise(ORB_ID(@(topic)), &@(topic)_data);
|
@(topic)_pub = orb_advertise(ORB_ID(@(topic)), &@(topic)_data);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ topic_name = spec.short_name
|
|||||||
}@
|
}@
|
||||||
|
|
||||||
#include <px4_config.h>
|
#include <px4_config.h>
|
||||||
#include <microcdr/microCdr.h>
|
#include <microcdr/microcdr.h>
|
||||||
#include <uORB/topics/@(topic_name).h>
|
#include <uORB/topics/@(topic_name).h>
|
||||||
#include <uORB_microcdr/topics/@(topic_name).h>
|
#include <uORB_microcdr/topics/@(topic_name).h>
|
||||||
|
|
||||||
@@ -98,9 +98,9 @@ def add_serialize_functions(fields, scope_name):
|
|||||||
if (not field.is_header):
|
if (not field.is_header):
|
||||||
if (field.is_builtin):
|
if (field.is_builtin):
|
||||||
if (not field.is_array):
|
if (not field.is_array):
|
||||||
print(" serialize"+str(get_serialization_type_name(field.type))+"(input->"+scope_name+str(field.name)+", microCDRWriter);")
|
print(" serialize_" + str(get_serialization_type_name(field.type)) + "(microCDRWriter, input->" + scope_name+str(field.name) + ");")
|
||||||
else:
|
else:
|
||||||
print(" serialize"+str(get_serialization_type_name(field.base_type))+"Array(input->"+scope_name+str(field.name)+", "+str(field.array_len)+", microCDRWriter);")
|
print(" serialize_array_" + str(get_serialization_type_name(field.base_type)) + "(microCDRWriter, input->" + scope_name+str(field.name) + ", " + str(field.array_len) + ");")
|
||||||
else:
|
else:
|
||||||
name = field.name
|
name = field.name
|
||||||
children_fields = get_children_fields(field.base_type, search_path)
|
children_fields = get_children_fields(field.base_type, search_path)
|
||||||
@@ -116,10 +116,9 @@ def add_deserialize_functions(fields, scope_name):
|
|||||||
if (not field.is_header):
|
if (not field.is_header):
|
||||||
if (field.is_builtin):
|
if (field.is_builtin):
|
||||||
if (not field.is_array):
|
if (not field.is_array):
|
||||||
print(" deserialize"+str(get_serialization_type_name(field.type))+"(&output->"+scope_name+str(field.name)+", microCDRReader);")
|
print(" deserialize_" + str(get_serialization_type_name(field.type)) + "(microCDRReader, &output->" + scope_name+str(field.name) + ");")
|
||||||
else:
|
else:
|
||||||
for i in range(field.array_len):
|
print(" deserialize_array_" + str(get_serialization_type_name(field.base_type)) + "(microCDRReader, output->" + scope_name+str(field.name) + ", " + str(field.array_len) + ");")
|
||||||
print(" deserialize"+str(get_serialization_type_name(field.base_type))+"(&output->"+scope_name+str(field.name)+ str('[%d]' %i) +", microCDRReader);")
|
|
||||||
else:
|
else:
|
||||||
name = field.name
|
name = field.name
|
||||||
children_fields = get_children_fields(field.base_type, search_path)
|
children_fields = get_children_fields(field.base_type, search_path)
|
||||||
@@ -141,24 +140,25 @@ def add_code_to_deserialize():
|
|||||||
add_deserialize_functions(sorted_fields, "")
|
add_deserialize_functions(sorted_fields, "")
|
||||||
}@
|
}@
|
||||||
|
|
||||||
void serialize_@(topic_name)(const struct @(uorb_struct) *input, char *output, uint32_t *length, struct microCDR *microCDRWriter)
|
void serialize_@(topic_name)(MicroBuffer *microCDRWriter, const struct @(uorb_struct) *input, char *output, uint32_t *length)
|
||||||
{
|
{
|
||||||
if (nullptr == input || nullptr == output || nullptr == length || nullptr == microCDRWriter) return;
|
if (nullptr == microCDRWriter || nullptr == input || nullptr == output || nullptr == length)
|
||||||
|
return;
|
||||||
|
|
||||||
resetStaticMicroCDRForSerialize(microCDRWriter);
|
reset_micro_buffer(microCDRWriter);
|
||||||
|
|
||||||
serializeUnsignedLong(input->timestamp, microCDRWriter);
|
serialize_uint64_t(microCDRWriter, input->timestamp);
|
||||||
@add_code_to_serialize()
|
@add_code_to_serialize()
|
||||||
|
(*length) = micro_buffer_length(microCDRWriter);
|
||||||
(*length) = microCDRWriter->m_microBuffer->m_serializedBuffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void deserialize_@(topic_name)(struct @(uorb_struct) *output, char *input, struct microCDR *microCDRReader)
|
void deserialize_@(topic_name)(MicroBuffer *microCDRReader, struct @(uorb_struct) *output, const char *input)
|
||||||
{
|
{
|
||||||
if (nullptr == output || nullptr == input || nullptr == microCDRReader) return;
|
if (nullptr == microCDRReader || nullptr == output || nullptr == input)
|
||||||
|
return;
|
||||||
|
|
||||||
resetStaticMicroCDRForDeserialize(microCDRReader);
|
reset_micro_buffer(microCDRReader);
|
||||||
|
|
||||||
deserializeUnsignedLong(&output->timestamp, microCDRReader);
|
deserialize_uint64_t(microCDRReader, &output->timestamp);
|
||||||
@add_code_to_deserialize()
|
@add_code_to_deserialize()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,8 +68,7 @@ topic_name = spec.short_name
|
|||||||
#include <uORB/topics/@(topic_name).h>
|
#include <uORB/topics/@(topic_name).h>
|
||||||
#include <uORB_microcdr/topics/@(topic_name).h>
|
#include <uORB_microcdr/topics/@(topic_name).h>
|
||||||
|
|
||||||
struct microCDR;
|
struct MicroBuffer;
|
||||||
|
|
||||||
|
void serialize_@(topic_name)(MicroBuffer *microCDRWriter, const struct @(uorb_struct) *input, char *output, uint32_t *length);
|
||||||
void serialize_@(topic_name)(const struct @(uorb_struct) *input, char *output, uint32_t *length, struct microCDR *microCDRWriter);
|
void deserialize_@(topic_name)(MicroBuffer *microCDRReader, struct @(uorb_struct) *output, const char *input);
|
||||||
void deserialize_@(topic_name)(struct @(uorb_struct) *output, char *input, struct microCDR *microCDRReader);
|
|
||||||
|
|||||||
@@ -43,4 +43,4 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <uORB/uORB.h>
|
#include <uORB/uORB.h>
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ bool @(topic)_Publisher::init()
|
|||||||
PublisherAttributes Wparam;
|
PublisherAttributes Wparam;
|
||||||
Wparam.topic.topicKind = NO_KEY;
|
Wparam.topic.topicKind = NO_KEY;
|
||||||
Wparam.topic.topicDataType = myType.getName(); //This type MUST be registered
|
Wparam.topic.topicDataType = myType.getName(); //This type MUST be registered
|
||||||
Wparam.topic.topicName = "@(topic)";
|
Wparam.topic.topicName = "@(topic)_PubSubTopic";
|
||||||
mp_publisher = Domain::createPublisher(mp_participant, Wparam, (PublisherListener*) &m_listener);
|
mp_publisher = Domain::createPublisher(mp_participant, Wparam, (PublisherListener*) &m_listener);
|
||||||
if(mp_publisher == nullptr)
|
if(mp_publisher == nullptr)
|
||||||
return false;
|
return false;
|
||||||
@@ -100,7 +100,7 @@ bool @(topic)_Publisher::init()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void @(topic)_Publisher::PubListener::onPublicationMatched(Publisher* pub,MatchingInfo& info)
|
void @(topic)_Publisher::PubListener::onPublicationMatched(Publisher* pub, MatchingInfo& info)
|
||||||
{
|
{
|
||||||
if (info.status == MATCHED_MATCHING)
|
if (info.status == MATCHED_MATCHING)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -90,14 +90,14 @@ bool @(topic)_Subscriber::init()
|
|||||||
SubscriberAttributes Rparam;
|
SubscriberAttributes Rparam;
|
||||||
Rparam.topic.topicKind = NO_KEY;
|
Rparam.topic.topicKind = NO_KEY;
|
||||||
Rparam.topic.topicDataType = myType.getName(); //Must be registered before the creation of the subscriber
|
Rparam.topic.topicDataType = myType.getName(); //Must be registered before the creation of the subscriber
|
||||||
Rparam.topic.topicName = "@(topic)";
|
Rparam.topic.topicName = "@(topic)_PubSubTopic";
|
||||||
mp_subscriber = Domain::createSubscriber(mp_participant, Rparam, (SubscriberListener*) &m_listener);
|
mp_subscriber = Domain::createSubscriber(mp_participant, Rparam, (SubscriberListener*) &m_listener);
|
||||||
if(mp_subscriber == nullptr)
|
if(mp_subscriber == nullptr)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void @(topic)_Subscriber::SubListener::onSubscriptionMatched(Subscriber* sub,MatchingInfo& info)
|
void @(topic)_Subscriber::SubListener::onSubscriptionMatched(Subscriber* sub, MatchingInfo& info)
|
||||||
{
|
{
|
||||||
if (info.status == MATCHED_MATCHING)
|
if (info.status == MATCHED_MATCHING)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,18 +24,18 @@ type_map = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type_serialize_map = {
|
type_serialize_map = {
|
||||||
'int8': 'SignedChar',
|
'int8': 'char',
|
||||||
'int16': 'Short',
|
'int16': 'int16_t',
|
||||||
'int32': 'Int',
|
'int32': 'int32_t',
|
||||||
'int64': 'Long',
|
'int64': 'int64_t',
|
||||||
'uint8': 'UnsignedChar',
|
'uint8': 'uint8_t',
|
||||||
'uint16': 'UnsignedShort',
|
'uint16': 'uint16_t',
|
||||||
'uint32': 'UnsignedInt',
|
'uint32': 'uint32_t',
|
||||||
'uint64': 'UnsignedLong',
|
'uint64': 'uint64_t',
|
||||||
'float32': 'Float',
|
'float32': 'float',
|
||||||
'float64': 'Double',
|
'float64': 'double',
|
||||||
'bool': 'Bool',
|
'bool': 'bool',
|
||||||
'char': 'Char',
|
'char': 'char',
|
||||||
}
|
}
|
||||||
|
|
||||||
type_idl_map = {
|
type_idl_map = {
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ endif()
|
|||||||
|
|
||||||
if (GENERATE_RTPS_BRIDGE)
|
if (GENERATE_RTPS_BRIDGE)
|
||||||
|
|
||||||
|
# temporarily set to OFF
|
||||||
|
option(CHECK_ENDIANNESS OFF)
|
||||||
|
|
||||||
add_subdirectory(micrortps_client)
|
add_subdirectory(micrortps_client)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@@ -132,15 +135,16 @@ if (GENERATE_RTPS_BRIDGE)
|
|||||||
add_dependencies(uorb_msgs_microcdr
|
add_dependencies(uorb_msgs_microcdr
|
||||||
uorb_headers_microcdr_gen
|
uorb_headers_microcdr_gen
|
||||||
git_micro_cdr
|
git_micro_cdr
|
||||||
lib__micro-CDR
|
microcdr
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(uorb_msgs_microcdr PRIVATE lib__micro-CDR)
|
|
||||||
|
|
||||||
# microCDR
|
# microCDR
|
||||||
target_include_directories(uorb_msgs_microcdr
|
target_include_directories(uorb_msgs_microcdr
|
||||||
PUBLIC
|
PUBLIC
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/micro-CDR/include
|
${CMAKE_CURRENT_SOURCE_DIR}/micro-CDR/include
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/micro-CDR/include
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/micro-CDR/include/microcdr
|
${CMAKE_CURRENT_BINARY_DIR}/micro-CDR/include/microcdr
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_link_libraries(uorb_msgs_microcdr PRIVATE microcdr)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
Submodule src/modules/micrortps_bridge/micro-CDR updated: 50776f4ab7...890b118196
@@ -100,4 +100,4 @@ if (NOT "${config_rtps_send_topics}" STREQUAL "" OR NOT "${config_rtps_receive_t
|
|||||||
topic_bridge_files
|
topic_bridge_files
|
||||||
)
|
)
|
||||||
target_link_libraries(modules__micrortps_bridge__micrortps_client PRIVATE uorb_msgs_microcdr)
|
target_link_libraries(modules__micrortps_bridge__micrortps_client PRIVATE uorb_msgs_microcdr)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
|
||||||
#include <microcdr/microCdr.h>
|
#include <microcdr/microcdr.h>
|
||||||
#include <px4_config.h>
|
#include <px4_config.h>
|
||||||
#include <px4_getopt.h>
|
#include <px4_getopt.h>
|
||||||
#include <px4_posix.h>
|
#include <px4_posix.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user