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