mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-30 21:12:20 +08:00
fix(uavcan): reply to file services on the request interface (#28455)
* fix(uavcan): reply to file services on the request interface Firmware-update File.Read responses were queued on every CAN interface. Dual-CAN boards use independent buses, so the other interface's TX queue filled with a copy of the image. Assisted-by: Grok:grok-4.6 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com> * perf(uavcan): set the response iface mask only for opted-in servers The unconditional write restored AllIfacesMask on every response of every ServiceServer instantiation, costing ~168 B of flash for a mask that was already in place. Assisted-by: Claude:claude-fable-5 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com> * fix(uavcan): restore all-iface mask when request-iface replies are off The per-response write was dropped to save flash, so disabling the option left the publisher on the last request's interface. Assisted-by: Grok:grok-4.6 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com> --------- Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
This commit is contained in:
1 parent
5b333f04a1
commit
34f467b610
4 files changed
+104
-2
No files matched your search
@@ -73,6 +73,8 @@ public:
|
||||
TransferPriority getPriority() const { return sender_.getPriority(); }
|
||||
void setPriority(const TransferPriority prio) { sender_.setPriority(prio); }
|
||||
|
||||
void setIfaceMask(uint8_t iface_mask) { sender_.setIfaceMask(iface_mask); }
|
||||
|
||||
INode& getNode() const { return node_; }
|
||||
};
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ private:
|
||||
PublisherType publisher_;
|
||||
Callback callback_;
|
||||
uint32_t response_failure_count_;
|
||||
bool respond_on_request_iface_;
|
||||
|
||||
virtual void handleReceivedDataStruct(ReceivedDataStructure<RequestType>& request) override
|
||||
{
|
||||
@@ -124,6 +125,10 @@ private:
|
||||
{
|
||||
publisher_.setPriority(request.getPriority()); // Responding at the same priority.
|
||||
|
||||
publisher_.setIfaceMask(respond_on_request_iface_ ?
|
||||
uint8_t(1U << request.getIfaceIndex()) :
|
||||
uint8_t(TransferSender::AllIfacesMask));
|
||||
|
||||
const int res = publisher_.publish(response, TransferTypeServiceResponse, request.getSrcNodeID(),
|
||||
request.getTransferID());
|
||||
if (res < 0)
|
||||
@@ -145,6 +150,7 @@ public:
|
||||
, publisher_(node, getDefaultTxTimeout())
|
||||
, callback_()
|
||||
, response_failure_count_(0)
|
||||
, respond_on_request_iface_(false)
|
||||
{
|
||||
UAVCAN_ASSERT(getTxTimeout() == getDefaultTxTimeout()); // Making sure it is valid
|
||||
|
||||
@@ -187,6 +193,12 @@ public:
|
||||
MonotonicDuration getTxTimeout() const { return publisher_.getTxTimeout(); }
|
||||
void setTxTimeout(MonotonicDuration tx_timeout) { publisher_.setTxTimeout(tx_timeout); }
|
||||
|
||||
/**
|
||||
* Default false: responses go out on every CAN interface (UAVCAN v0 redundant-bus).
|
||||
* Set true to reply only on the interface that carried the request.
|
||||
*/
|
||||
void setRespondOnRequestIface(bool enable) { respond_on_request_iface_ = enable; }
|
||||
|
||||
/**
|
||||
* Returns the number of failed attempts to decode data structs. Generally, a failed attempt means either:
|
||||
* - Transient failure in the transport layer.
|
||||
|
||||
@@ -227,7 +227,13 @@ public:
|
||||
: get_info_srv_(node)
|
||||
, read_srv_(node)
|
||||
, backend_(backend)
|
||||
{ }
|
||||
{
|
||||
// Dual-CAN boards are usually independent buses, not redundant copies of one.
|
||||
// File.Read is the firmware-update payload; echoing it onto the other iface
|
||||
// fills that iface's TX queue with traffic nobody asked for.
|
||||
get_info_srv_.setRespondOnRequestIface(true);
|
||||
read_srv_.setRespondOnRequestIface(true);
|
||||
}
|
||||
|
||||
int start(const char* server_root = UAVCAN_NULLPTR, const char* server_alt_root = UAVCAN_NULLPTR)
|
||||
{
|
||||
@@ -302,7 +308,11 @@ public:
|
||||
, write_srv_(node)
|
||||
, delete_srv_(node)
|
||||
, get_directory_entry_info_srv_(node)
|
||||
{ }
|
||||
{
|
||||
write_srv_.setRespondOnRequestIface(true);
|
||||
delete_srv_.setRespondOnRequestIface(true);
|
||||
get_directory_entry_info_srv_.setRespondOnRequestIface(true);
|
||||
}
|
||||
|
||||
int start()
|
||||
{
|
||||
|
||||
@@ -133,6 +133,84 @@ TEST(ServiceServer, Basic)
|
||||
}
|
||||
|
||||
|
||||
static void pushStringServiceRequest(CanDriverMock& can_driver, SystemClockDriver& clock_driver,
|
||||
uint8_t iface_index, uint8_t src_node_id, uint8_t transfer_id)
|
||||
{
|
||||
uavcan::Frame frame(root_ns_a::StringService::DefaultDataTypeID, uavcan::TransferTypeServiceRequest,
|
||||
uavcan::NodeID(src_node_id), 1, transfer_id);
|
||||
|
||||
const uint8_t req[] = {'r', 'e', 'q', '0'};
|
||||
frame.setPayload(req, sizeof(req));
|
||||
frame.setStartOfTransfer(true);
|
||||
frame.setEndOfTransfer(true);
|
||||
frame.setPriority(0);
|
||||
|
||||
uavcan::RxFrame rx_frame(frame, clock_driver.getMonotonic(), clock_driver.getUtc(), iface_index);
|
||||
can_driver.ifaces.at(iface_index).pushRx(rx_frame);
|
||||
}
|
||||
|
||||
TEST(ServiceServer, ResponseIfaceFromRequest)
|
||||
{
|
||||
uavcan::GlobalDataTypeRegistry::instance().reset();
|
||||
uavcan::DefaultDataTypeRegistrator<root_ns_a::StringService> _registrator;
|
||||
|
||||
SystemClockDriver clock_driver;
|
||||
CanDriverMock can_driver(2, clock_driver);
|
||||
TestNode node(can_driver, clock_driver, 1);
|
||||
|
||||
StringServerImpl impl("456");
|
||||
uavcan::ServiceServer<root_ns_a::StringService, StringServerImpl::Binder> server(node);
|
||||
ASSERT_EQ(0, server.start(impl.bind()));
|
||||
|
||||
// Default: request on iface 1 is answered on both ifaces.
|
||||
pushStringServiceRequest(can_driver, clock_driver, 1, 0x10, 0);
|
||||
node.spin(clock_driver.getMonotonic() + uavcan::MonotonicDuration::fromUSec(10000));
|
||||
ASSERT_EQ(2, can_driver.ifaces[0].tx.size());
|
||||
ASSERT_EQ(2, can_driver.ifaces[1].tx.size());
|
||||
|
||||
while (!can_driver.ifaces[0].tx.empty())
|
||||
{
|
||||
(void)can_driver.ifaces[0].popTxFrame();
|
||||
}
|
||||
while (!can_driver.ifaces[1].tx.empty())
|
||||
{
|
||||
(void)can_driver.ifaces[1].popTxFrame();
|
||||
}
|
||||
|
||||
server.setRespondOnRequestIface(true);
|
||||
|
||||
// Request on iface 1 stays on iface 1.
|
||||
pushStringServiceRequest(can_driver, clock_driver, 1, 0x10, 1);
|
||||
node.spin(clock_driver.getMonotonic() + uavcan::MonotonicDuration::fromUSec(10000));
|
||||
ASSERT_EQ(0, can_driver.ifaces[0].tx.size());
|
||||
ASSERT_EQ(2, can_driver.ifaces[1].tx.size());
|
||||
|
||||
while (!can_driver.ifaces[1].tx.empty())
|
||||
{
|
||||
(void)can_driver.ifaces[1].popTxFrame();
|
||||
}
|
||||
|
||||
// Next request on iface 0 must not stick to the previous mask.
|
||||
pushStringServiceRequest(can_driver, clock_driver, 0, 0x11, 2);
|
||||
node.spin(clock_driver.getMonotonic() + uavcan::MonotonicDuration::fromUSec(10000));
|
||||
ASSERT_EQ(2, can_driver.ifaces[0].tx.size());
|
||||
ASSERT_EQ(0, can_driver.ifaces[1].tx.size());
|
||||
|
||||
while (!can_driver.ifaces[0].tx.empty())
|
||||
{
|
||||
(void)can_driver.ifaces[0].popTxFrame();
|
||||
}
|
||||
|
||||
server.setRespondOnRequestIface(false);
|
||||
|
||||
// Disabling must restore the all-interface mask, not keep the last request iface.
|
||||
pushStringServiceRequest(can_driver, clock_driver, 1, 0x10, 3);
|
||||
node.spin(clock_driver.getMonotonic() + uavcan::MonotonicDuration::fromUSec(10000));
|
||||
ASSERT_EQ(2, can_driver.ifaces[0].tx.size());
|
||||
ASSERT_EQ(2, can_driver.ifaces[1].tx.size());
|
||||
}
|
||||
|
||||
|
||||
TEST(ServiceServer, Empty)
|
||||
{
|
||||
// Manual type registration - we can't rely on the GDTR state
|
||||
|
||||
Reference in new issue
Block a user