mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-07 06:00:34 +08:00
Naming: TransferSender::allowRogueTransfers()
This commit is contained in:
@@ -25,7 +25,7 @@ class UAVCAN_EXPORT TransferSender
|
||||
const TransferCRC crc_base_;
|
||||
CanIOFlags flags_;
|
||||
uint8_t iface_mask_;
|
||||
bool allow_broadcasting_in_passive_mode_;
|
||||
bool allow_rogue_transfers_;
|
||||
|
||||
Dispatcher& dispatcher_;
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
, crc_base_(data_type.getSignature().toTransferCRC())
|
||||
, flags_(CanIOFlags(0))
|
||||
, iface_mask_(AllIfacesMask)
|
||||
, allow_broadcasting_in_passive_mode_(false)
|
||||
, allow_rogue_transfers_(false)
|
||||
, dispatcher_(dispatcher)
|
||||
{ }
|
||||
|
||||
@@ -62,11 +62,13 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, this class will return an error on any attempt to publish a message while the
|
||||
* dispatcher is configured in passive mode. This method allows to permanently enable sending
|
||||
* broadcast transfers in passive mode for this class instance.
|
||||
* Rogue transfers (i.e. transfers that don't carry a valid Source Node ID) can be sent if
|
||||
* the local node is configured in passive mode (i.e. the node doesn't have a valid Node ID).
|
||||
* By default, this class will return an error if it is asked to send a transfer while the
|
||||
* node is configured in passive mode. However, if this option is enabled, it will be possible
|
||||
* to send rogue transfers from passive mode.
|
||||
*/
|
||||
void allowBroadcastingInPassiveMode() { allow_broadcasting_in_passive_mode_ = true; }
|
||||
void allowRogueTransfers() { allow_rogue_transfers_ = true; }
|
||||
|
||||
/**
|
||||
* Send with explicit Transfer ID.
|
||||
|
||||
@@ -29,14 +29,12 @@ int TransferSender::send(const uint8_t* payload, unsigned payload_len, Monotonic
|
||||
UAVCAN_TRACE("TransferSender", "%s", frame.toString().c_str());
|
||||
|
||||
/*
|
||||
* Checking if we're allowed to send. In passive mode we can send only if:
|
||||
* - Passive broadcasting is enabled
|
||||
* - Transfer type is broadcast
|
||||
* - Transfer payload fits one CAN frame
|
||||
* Checking if we're allowed to send.
|
||||
* In passive mode we can send only rogue transfers, if they are enabled.
|
||||
*/
|
||||
if (dispatcher_.isPassiveMode())
|
||||
{
|
||||
const bool allow = allow_broadcasting_in_passive_mode_ &&
|
||||
const bool allow = allow_rogue_transfers_ &&
|
||||
(transfer_type == TransferTypeMessageBroadcast) &&
|
||||
(int(payload_len) <= frame.getMaxPayloadLen());
|
||||
if (!allow)
|
||||
|
||||
@@ -241,7 +241,7 @@ TEST(TransferSender, PassiveMode)
|
||||
uavcan::TransferTypeMessageBroadcast, uavcan::NodeID::Broadcast));
|
||||
|
||||
// Overriding the default
|
||||
sender.allowBroadcastingInPassiveMode();
|
||||
sender.allowRogueTransfers();
|
||||
|
||||
// OK, now we can broadcast in any mode
|
||||
ASSERT_LE(0, sender.send(Payload, sizeof(Payload), tsMono(1000), uavcan::MonotonicTime(),
|
||||
|
||||
Reference in New Issue
Block a user