mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-22 00:53:33 +08:00
TransferSender is now capable of broadcasting in passive mode; Frame::isValid() was modified to accept SFT broadcasts with zero SNID
This commit is contained in:
@@ -170,9 +170,12 @@ bool Frame::isValid() const
|
||||
const bool invalid =
|
||||
(frame_index_ > MaxIndex) ||
|
||||
((frame_index_ == MaxIndex) && !last_frame_) ||
|
||||
(!src_node_id_.isUnicast()) ||
|
||||
(!src_node_id_.isValid()) ||
|
||||
(!dst_node_id_.isValid()) ||
|
||||
(src_node_id_ == dst_node_id_) ||
|
||||
(src_node_id_.isUnicast() ? (src_node_id_ == dst_node_id_) : false) ||
|
||||
(src_node_id_.isBroadcast()
|
||||
? (!last_frame_ || (frame_index_ > 0) || (transfer_type_ != TransferTypeMessageBroadcast))
|
||||
: false) ||
|
||||
((transfer_type_ == TransferTypeMessageBroadcast) != dst_node_id_.isBroadcast()) ||
|
||||
(transfer_type_ >= NumTransferTypes) ||
|
||||
(static_cast<int>(payload_len_) > getMaxPayloadLen()) ||
|
||||
|
||||
@@ -19,15 +19,37 @@ int TransferSender::send(const uint8_t* payload, unsigned payload_len, Monotonic
|
||||
MonotonicTime blocking_deadline, TransferType transfer_type, NodeID dst_node_id,
|
||||
TransferID tid)
|
||||
{
|
||||
if (payload_len > MaxTransferPayloadLen)
|
||||
{
|
||||
UAVCAN_ASSERT(0);
|
||||
return -ErrInvalidParam;
|
||||
}
|
||||
|
||||
Frame frame(data_type_.getID(), transfer_type, dispatcher_.getNodeID(), dst_node_id, 0, tid);
|
||||
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
|
||||
*/
|
||||
if (dispatcher_.isPassiveMode())
|
||||
{
|
||||
return -ErrPassiveMode;
|
||||
const bool allow = allow_broadcasting_in_passive_mode_ &&
|
||||
(transfer_type == TransferTypeMessageBroadcast) &&
|
||||
(int(payload_len) <= frame.getMaxPayloadLen());
|
||||
if (!allow)
|
||||
{
|
||||
return -ErrPassiveMode;
|
||||
}
|
||||
}
|
||||
|
||||
dispatcher_.getTransferPerfCounter().addTxTransfer();
|
||||
|
||||
Frame frame(data_type_.getID(), transfer_type, dispatcher_.getNodeID(), dst_node_id, 0, tid);
|
||||
|
||||
/*
|
||||
* Sending frames
|
||||
*/
|
||||
if (frame.getMaxPayloadLen() >= int(payload_len)) // Single Frame Transfer
|
||||
{
|
||||
const int res = frame.setPayload(payload, payload_len);
|
||||
|
||||
Reference in New Issue
Block a user