mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 16:53:33 +08:00
Support for priority in TransferSender
This commit is contained in:
@@ -21,6 +21,7 @@ class UAVCAN_EXPORT TransferSender
|
|||||||
{
|
{
|
||||||
const MonotonicDuration max_transfer_interval_;
|
const MonotonicDuration max_transfer_interval_;
|
||||||
const DataTypeDescriptor& data_type_;
|
const DataTypeDescriptor& data_type_;
|
||||||
|
TransferPriority priority_;
|
||||||
const CanTxQueue::Qos qos_;
|
const CanTxQueue::Qos qos_;
|
||||||
const TransferCRC crc_base_;
|
const TransferCRC crc_base_;
|
||||||
CanIOFlags flags_;
|
CanIOFlags flags_;
|
||||||
@@ -29,7 +30,7 @@ class UAVCAN_EXPORT TransferSender
|
|||||||
|
|
||||||
Dispatcher& dispatcher_;
|
Dispatcher& dispatcher_;
|
||||||
|
|
||||||
void registerError();
|
void registerError() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum { AllIfacesMask = 0xFF };
|
enum { AllIfacesMask = 0xFF };
|
||||||
@@ -43,6 +44,7 @@ public:
|
|||||||
MonotonicDuration max_transfer_interval = getDefaultMaxTransferInterval())
|
MonotonicDuration max_transfer_interval = getDefaultMaxTransferInterval())
|
||||||
: max_transfer_interval_(max_transfer_interval)
|
: max_transfer_interval_(max_transfer_interval)
|
||||||
, data_type_(data_type)
|
, data_type_(data_type)
|
||||||
|
, priority_(TransferPriorityNormal)
|
||||||
, qos_(qos)
|
, qos_(qos)
|
||||||
, crc_base_(data_type.getSignature().toTransferCRC())
|
, crc_base_(data_type.getSignature().toTransferCRC())
|
||||||
, flags_(CanIOFlags(0))
|
, flags_(CanIOFlags(0))
|
||||||
@@ -61,6 +63,23 @@ public:
|
|||||||
iface_mask_ = iface_mask;
|
iface_mask_ = iface_mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transfer priority can be assigned only for message transfers.
|
||||||
|
* Attempt to change priority of a service transfer will not have any effect.
|
||||||
|
*/
|
||||||
|
TransferPriority getPriority() const { return priority_; }
|
||||||
|
void setPriority(TransferPriority prio)
|
||||||
|
{
|
||||||
|
if (prio < NumTransferPriorities && prio != TransferPriorityService)
|
||||||
|
{
|
||||||
|
priority_ = prio;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UAVCAN_ASSERT(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Anonymous transfers (i.e. transfers that don't carry a valid Source Node ID) can be sent if
|
* Anonymous 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).
|
* the local node is configured in passive mode (i.e. the node doesn't have a valid Node ID).
|
||||||
@@ -76,14 +95,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
int send(const uint8_t* payload, unsigned payload_len, MonotonicTime tx_deadline,
|
int send(const uint8_t* payload, unsigned payload_len, MonotonicTime tx_deadline,
|
||||||
MonotonicTime blocking_deadline, TransferType transfer_type, NodeID dst_node_id,
|
MonotonicTime blocking_deadline, TransferType transfer_type, NodeID dst_node_id,
|
||||||
TransferID tid);
|
TransferID tid) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send with automatic Transfer ID.
|
* Send with automatic Transfer ID.
|
||||||
* TID is managed by OutgoingTransferRegistry.
|
* TID is managed by OutgoingTransferRegistry.
|
||||||
*/
|
*/
|
||||||
int send(const uint8_t* payload, unsigned payload_len, MonotonicTime tx_deadline,
|
int send(const uint8_t* payload, unsigned payload_len, MonotonicTime tx_deadline,
|
||||||
MonotonicTime blocking_deadline, TransferType transfer_type, NodeID dst_node_id);
|
MonotonicTime blocking_deadline, TransferType transfer_type, NodeID dst_node_id) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ uint_fast8_t Frame::getMaxIndexForTransferType(const TransferType type)
|
|||||||
|
|
||||||
void Frame::setPriority(const TransferPriority priority)
|
void Frame::setPriority(const TransferPriority priority)
|
||||||
{
|
{
|
||||||
|
UAVCAN_ASSERT(priority < NumTransferPriorities);
|
||||||
if (transfer_type_ == TransferTypeMessageBroadcast ||
|
if (transfer_type_ == TransferTypeMessageBroadcast ||
|
||||||
transfer_type_ == TransferTypeMessageUnicast)
|
transfer_type_ == TransferTypeMessageUnicast)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,14 +10,14 @@
|
|||||||
namespace uavcan
|
namespace uavcan
|
||||||
{
|
{
|
||||||
|
|
||||||
void TransferSender::registerError()
|
void TransferSender::registerError() const
|
||||||
{
|
{
|
||||||
dispatcher_.getTransferPerfCounter().addError();
|
dispatcher_.getTransferPerfCounter().addError();
|
||||||
}
|
}
|
||||||
|
|
||||||
int TransferSender::send(const uint8_t* payload, unsigned payload_len, MonotonicTime tx_deadline,
|
int TransferSender::send(const uint8_t* payload, unsigned payload_len, MonotonicTime tx_deadline,
|
||||||
MonotonicTime blocking_deadline, TransferType transfer_type, NodeID dst_node_id,
|
MonotonicTime blocking_deadline, TransferType transfer_type, NodeID dst_node_id,
|
||||||
TransferID tid)
|
TransferID tid) const
|
||||||
{
|
{
|
||||||
if (payload_len > getMaxPayloadLenForTransferType(transfer_type))
|
if (payload_len > getMaxPayloadLenForTransferType(transfer_type))
|
||||||
{
|
{
|
||||||
@@ -25,6 +25,12 @@ int TransferSender::send(const uint8_t* payload, unsigned payload_len, Monotonic
|
|||||||
}
|
}
|
||||||
|
|
||||||
Frame frame(data_type_.getID(), transfer_type, dispatcher_.getNodeID(), dst_node_id, 0, tid);
|
Frame frame(data_type_.getID(), transfer_type, dispatcher_.getNodeID(), dst_node_id, 0, tid);
|
||||||
|
if (transfer_type == TransferTypeMessageBroadcast ||
|
||||||
|
transfer_type == TransferTypeMessageUnicast)
|
||||||
|
{
|
||||||
|
UAVCAN_ASSERT(priority_ != TransferPriorityService);
|
||||||
|
frame.setPriority(priority_);
|
||||||
|
}
|
||||||
UAVCAN_TRACE("TransferSender", "%s", frame.toString().c_str());
|
UAVCAN_TRACE("TransferSender", "%s", frame.toString().c_str());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -126,7 +132,7 @@ int TransferSender::send(const uint8_t* payload, unsigned payload_len, Monotonic
|
|||||||
}
|
}
|
||||||
|
|
||||||
int TransferSender::send(const uint8_t* payload, unsigned payload_len, MonotonicTime tx_deadline,
|
int TransferSender::send(const uint8_t* payload, unsigned payload_len, MonotonicTime tx_deadline,
|
||||||
MonotonicTime blocking_deadline, TransferType transfer_type, NodeID dst_node_id)
|
MonotonicTime blocking_deadline, TransferType transfer_type, NodeID dst_node_id) const
|
||||||
{
|
{
|
||||||
// This check must be performed before TID is incremented to avoid skipping TID values on failures
|
// This check must be performed before TID is incremented to avoid skipping TID values on failures
|
||||||
if (payload_len > getMaxPayloadLenForTransferType(transfer_type))
|
if (payload_len > getMaxPayloadLenForTransferType(transfer_type))
|
||||||
@@ -134,6 +140,9 @@ int TransferSender::send(const uint8_t* payload, unsigned payload_len, Monotonic
|
|||||||
return -ErrTransferTooLong;
|
return -ErrTransferTooLong;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO: TID is not needed for anonymous transfers, this part of the code can be skipped?
|
||||||
|
*/
|
||||||
const OutgoingTransferRegistryKey otr_key(data_type_.getID(), transfer_type, dst_node_id);
|
const OutgoingTransferRegistryKey otr_key(data_type_.getID(), transfer_type, dst_node_id);
|
||||||
|
|
||||||
UAVCAN_ASSERT(!tx_deadline.isZero());
|
UAVCAN_ASSERT(!tx_deadline.isZero());
|
||||||
|
|||||||
Reference in New Issue
Block a user