Skip to content

Commit

Permalink
try poll #verification #sonar #docs
Browse files Browse the repository at this point in the history
  • Loading branch information
serges147 committed Dec 9, 2024
1 parent 1b7345b commit 9a4424d
Showing 1 changed file with 0 additions and 73 deletions.
73 changes: 0 additions & 73 deletions include/libcyphal/transport/can/can_transport_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,79 +574,6 @@ class TransportImpl final : private TransportDelegate, public ICanTransport
}
}

/// @brief Tries to push next frame from TX queue to media.
///
void pushNextFrameToMedia_old(Media& media)
{
TimePoint tx_deadline;
while (CanardTxQueueItem* const tx_item = peekFirstValidTxItem(media.canard_tx_queue(), tx_deadline))
{
// Move the payload from the frame to the media payload - `media.push` might take ownership of it.
// No Sonar `cpp:S5356` and `cpp:S5357` b/c we integrate here with C libcanard API.
//
auto& frame_payload = tx_item->frame.payload;
MediaPayload payload{frame_payload.size,
static_cast<cetl::byte*>(frame_payload.data), // NOSONAR cpp:S5356 cpp:S5357
frame_payload.allocated_size,
&media.interface().getTxMemoryResource()};
frame_payload = {0, nullptr, 0};

auto push_result = media.interface().push(tx_deadline, tx_item->frame.extended_can_id, payload);

// In case of media push error, we are going to drop this problematic frame
// (b/c it looks like media can't handle this frame),
// but we will continue to process with another transfer frame.
// Note that media not being ready/able to push a frame just yet (aka temporary)
// is not reported as an error (see `is_pushed` below).
//
auto* const push_failure = cetl::get_if<IMedia::PushResult::Failure>(&push_result);
if (nullptr == push_failure)
{
const auto push = cetl::get<IMedia::PushResult::Success>(push_result);
if (push.is_accepted)
{
popAndFreeCanardTxQueueItem(media.canard_tx_queue(),
canardInstance(),
tx_item,
false /* single frame */);
}
else
{
// Media has not accepted the frame, so we need return original payload back to the item,
// so that in the future potential retry could try to push it again.
const auto org_payload = payload.release();
frame_payload.size = std::get<0>(org_payload);
frame_payload.data = std::get<1>(org_payload);
frame_payload.allocated_size = std::get<2>(org_payload);
}

// If needed schedule (recursively!) next frame to push.
// Already existing callback will be called by executor when media TX is ready to push more.
//
if (!media.tx_callback())
{
media.tx_callback() = media.interface().registerPushCallback([this, &media](const auto&) {
//
pushNextFrameToMedia_old(media);
});
}
return;
}

// Release whole problematic transfer from the TX queue,
// so that other transfers in TX queue have their chance.
// Otherwise, we would be stuck in an execution loop trying to send the same frame.
popAndFreeCanardTxQueueItem(media.canard_tx_queue(), canardInstance(), tx_item, true /* whole transfer */);

using Report = TransientErrorReport::MediaPush;
tryHandleTransientMediaFailure<Report>(media, std::move(*push_failure));

} // for a valid tx item

// There is nothing to send anymore, so we are done with this media TX - no more callbacks for now.
media.tx_callback().reset();
}

/// @brief Tries to push next frame from TX queue to media.
///
void pushNextFrameToMedia(Media& media)
Expand Down

0 comments on commit 9a4424d

Please sign in to comment.