mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-17 05:13:35 +08:00
Optional pre-initialization for GenericPublisher<>, TransferSender accessor
This commit is contained in:
@@ -106,6 +106,11 @@ public:
|
||||
|
||||
~GenericPublisher() { }
|
||||
|
||||
int init()
|
||||
{
|
||||
return checkInit() ? 0 : -1;
|
||||
}
|
||||
|
||||
int publish(const DataStruct& message, TransferType transfer_type, NodeID dst_node_id,
|
||||
MonotonicTime blocking_deadline = MonotonicTime())
|
||||
{
|
||||
@@ -118,6 +123,12 @@ public:
|
||||
return genericPublish(message, transfer_type, dst_node_id, &tid, blocking_deadline);
|
||||
}
|
||||
|
||||
TransferSender* getTransferSender()
|
||||
{
|
||||
checkInit();
|
||||
return sender_.isConstructed() ? static_cast<TransferSender*>(sender_) : NULL;
|
||||
}
|
||||
|
||||
static MonotonicDuration getMinTxTimeout() { return MonotonicDuration::fromUSec(200); }
|
||||
static MonotonicDuration getMaxTxTimeout() { return MonotonicDuration::fromMSec(60000); }
|
||||
|
||||
|
||||
@@ -44,6 +44,8 @@ public:
|
||||
|
||||
static MonotonicDuration getDefaultTxTimeout() { return MonotonicDuration::fromMSec(5); } // 5 ms --> 200 Hz max
|
||||
|
||||
using BaseType::init;
|
||||
using BaseType::getTransferSender;
|
||||
using BaseType::getMinTxTimeout;
|
||||
using BaseType::getMaxTxTimeout;
|
||||
using BaseType::getTxTimeout;
|
||||
|
||||
@@ -143,6 +143,11 @@ public:
|
||||
|
||||
virtual ~ServiceClient() { cancel(); }
|
||||
|
||||
int init()
|
||||
{
|
||||
return publisher_.init();
|
||||
}
|
||||
|
||||
int call(NodeID server_node_id, const RequestType& request) // TODO: Refactor, move into a non-template subclass!
|
||||
{
|
||||
/*
|
||||
|
||||
@@ -79,6 +79,12 @@ public:
|
||||
}
|
||||
callback_ = callback;
|
||||
|
||||
const int publisher_res = publisher_.init();
|
||||
if (publisher_res < 0)
|
||||
{
|
||||
UAVCAN_TRACE("ServiceServer", "Publisher initialization failure: %i", publisher_res);
|
||||
return publisher_res;
|
||||
}
|
||||
return SubscriberType::startAsServiceRequestListener();
|
||||
}
|
||||
|
||||
|
||||
@@ -105,4 +105,18 @@ TEST(Publisher, Basic)
|
||||
* Misc
|
||||
*/
|
||||
ASSERT_TRUE(uavcan::GlobalDataTypeRegistry::instance().isFrozen());
|
||||
ASSERT_TRUE(publisher.getTransferSender());
|
||||
}
|
||||
|
||||
|
||||
TEST(Publisher, ImplicitInitialization)
|
||||
{
|
||||
SystemClockMock clock_mock(100);
|
||||
CanDriverMock can_driver(2, clock_mock);
|
||||
TestNode node(can_driver, clock_mock, 1);
|
||||
|
||||
uavcan::Publisher<uavcan::mavlink::Message> publisher(node);
|
||||
|
||||
// Will be initialized ad-hoc
|
||||
ASSERT_TRUE(publisher.getTransferSender());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user