mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-23 05:43:34 +08:00
use a yaml file description instead of json; minor improvements and cleanup
This commit is contained in:
@@ -10,16 +10,24 @@
|
||||
@# - multi_topics (List) list of all multi-topic names
|
||||
@###############################################
|
||||
@{
|
||||
import os
|
||||
|
||||
import genmsg.msgs
|
||||
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/
|
||||
from uorb_rtps_message_ids import * # 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]
|
||||
|
||||
yaml_file = os.path.abspath('uorb_rtps_message_ids.yaml')
|
||||
try:
|
||||
msg_ids = parse_yaml_msg_id_file(yaml_file)
|
||||
except OSError as e:
|
||||
if e.errno == errno.ENOENT:
|
||||
raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), yaml_file)
|
||||
else:
|
||||
raise
|
||||
}@
|
||||
/****************************************************************************
|
||||
*
|
||||
@@ -112,7 +120,7 @@ void* send(void* /*unused*/)
|
||||
/* payload is shifted by header length to make room for header*/
|
||||
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)@(rtps_message_id(msg_ids, topic)), data_buffer, length)))
|
||||
{
|
||||
total_sent += read;
|
||||
++sent;
|
||||
@@ -187,7 +195,8 @@ void micrortps_start_topics(struct timespec &begin, int &total_read, uint32_t &r
|
||||
switch (topic_ID)
|
||||
{
|
||||
@[for topic in recv_topics]@
|
||||
case @(message_id(topic)):
|
||||
|
||||
case @(rtps_message_id(msg_ids, topic)):
|
||||
{
|
||||
deserialize_@(topic)(&MicroBufferReader, &@(topic)_data, data_buffer);
|
||||
if (!@(topic)_pub) {
|
||||
|
||||
@@ -19,6 +19,14 @@ 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]
|
||||
yaml_file = os.path.abspath('uorb_rtps_message_ids.yaml')
|
||||
try:
|
||||
msg_ids = parse_yaml_msg_id_file(yaml_file)
|
||||
except OSError as e:
|
||||
if e.errno == errno.ENOENT:
|
||||
raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), yaml_file)
|
||||
else:
|
||||
raise
|
||||
}@
|
||||
/****************************************************************************
|
||||
*
|
||||
@@ -89,7 +97,7 @@ void RtpsTopics::publish(uint8_t topic_ID, char data_buffer[], size_t len)
|
||||
switch (topic_ID)
|
||||
{
|
||||
@[for topic in send_topics]@
|
||||
case @(rtps_message_id(os.path.abspath('uorb_rtps_message_ids.json'), topic)): // @(topic)
|
||||
case @(rtps_message_id(msg_ids, topic)): // @(topic)
|
||||
{
|
||||
@(topic)_ st;
|
||||
eprosima::fastcdr::FastBuffer cdrbuffer(data_buffer, len);
|
||||
@@ -117,7 +125,7 @@ bool RtpsTopics::hasMsg(uint8_t *topic_ID)
|
||||
switch (_sub_topics[_next_sub_idx])
|
||||
{
|
||||
@[for topic in recv_topics]@
|
||||
case @(rtps_message_id(os.path.abspath('uorb_rtps_message_ids.json'), topic)): if (_@(topic)_sub.hasMsg()) *topic_ID = @(rtps_message_id(os.path.abspath('uorb_rtps_message_ids.json'), topic)); break;
|
||||
case @(rtps_message_id(msg_ids, topic)): if (_@(topic)_sub.hasMsg()) *topic_ID = @(rtps_message_id(msg_ids, topic)); break;
|
||||
@[end for]@
|
||||
default:
|
||||
printf("Unexpected topic ID to check hasMsg\n");
|
||||
@@ -141,7 +149,7 @@ bool RtpsTopics::getMsg(const uint8_t topic_ID, eprosima::fastcdr::Cdr &scdr)
|
||||
switch (topic_ID)
|
||||
{
|
||||
@[for topic in recv_topics]@
|
||||
case @(rtps_message_id(os.path.abspath('uorb_rtps_message_ids.json'), topic)): // @(topic)
|
||||
case @(rtps_message_id(msg_ids, topic)): // @(topic)
|
||||
if (_@(topic)_sub.hasMsg())
|
||||
{
|
||||
@(topic)_ msg = _@(topic)_sub.getMsg();
|
||||
|
||||
@@ -19,6 +19,14 @@ 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]
|
||||
yaml_file = os.path.abspath('uorb_rtps_message_ids.yaml')
|
||||
try:
|
||||
msg_ids = parse_yaml_msg_id_file(yaml_file)
|
||||
except OSError as e:
|
||||
if e.errno == errno.ENOENT:
|
||||
raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), yaml_file)
|
||||
else:
|
||||
raise
|
||||
}@
|
||||
/****************************************************************************
|
||||
*
|
||||
@@ -89,7 +97,7 @@ private:
|
||||
unsigned _next_sub_idx = 0;
|
||||
char _sub_topics[@(len(recv_topics))] = {
|
||||
@[for topic in recv_topics]@
|
||||
@(rtps_message_id(os.path.abspath('uorb_rtps_message_ids.json'), topic)), // @(topic)
|
||||
@(rtps_message_id(msg_ids, topic)), // @(topic)
|
||||
@[end for]@
|
||||
};
|
||||
@[end if]@
|
||||
|
||||
Reference in New Issue
Block a user