Skip to content

Commit

Permalink
#verification #docs #sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
serges147 committed May 8, 2024
1 parent 27b44b0 commit 04e5eff
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
4 changes: 3 additions & 1 deletion include/libcyphal/transport/can/delegate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ class TransportDelegate

/// @brief Releases memory allocated for canard (by previous `allocateMemoryForCanard` call).
///
void freeCanardMemory(void* const pointer)
/// NOSONAR b/s it is unavoidable: this is integration with low-level C code of Canard memory management.
///
void freeCanardMemory(void* const pointer) // NOSONAR
{
if (pointer == nullptr)
{
Expand Down
11 changes: 5 additions & 6 deletions include/libcyphal/transport/can/msg_rx_session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class MessageRxSession final : public IMessageRxSession, private IRxSessionDeleg
{
const std::int8_t result = ::canardRxSubscribe(&delegate.canard_instance(),
CanardTransferKindMessage,
static_cast<CanardPortID>(params_.subject_id),
static_cast<std::size_t>(params_.extent_bytes),
params_.subject_id,
params_.extent_bytes,
CANARD_DEFAULT_TRANSFER_ID_TIMEOUT_USEC,
&subscription_);
(void) result;
Expand All @@ -97,9 +97,8 @@ class MessageRxSession final : public IMessageRxSession, private IRxSessionDeleg

~MessageRxSession() override
{
const int8_t result = ::canardRxUnsubscribe(&delegate_.canard_instance(),
CanardTransferKindMessage,
static_cast<CanardPortID>(params_.subject_id));
const int8_t result =
::canardRxUnsubscribe(&delegate_.canard_instance(), CanardTransferKindMessage, params_.subject_id);
(void) result;
CETL_DEBUG_ASSERT(result >= 0, "There is no way currently to get an error here.");
CETL_DEBUG_ASSERT(result > 0, "Subscription supposed to be made at constructor.");
Expand Down Expand Up @@ -156,7 +155,7 @@ class MessageRxSession final : public IMessageRxSession, private IRxSessionDeleg
const MessageTransferMetadata meta{transfer_id, timestamp, priority, publisher_node_id};
TransportDelegate::CanardMemory canard_memory{delegate_, transfer.payload, transfer.payload_size};

last_rx_transfer_.emplace(MessageRxTransfer{meta, ScatteredBuffer{std::move(canard_memory)}});
(void) last_rx_transfer_.emplace(MessageRxTransfer{meta, ScatteredBuffer{std::move(canard_memory)}});
}

// MARK: Data members:
Expand Down
2 changes: 1 addition & 1 deletion include/libcyphal/transport/can/msg_tx_session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class MessageTxSession final : public IMessageTxSession
{
const auto canard_metadata = CanardTransferMetadata{static_cast<CanardPriority>(metadata.priority),
CanardTransferKindMessage,
static_cast<CanardPortID>(params_.subject_id),
params_.subject_id,
CANARD_NODE_ID_UNSET,
static_cast<CanardTransferID>(metadata.transfer_id)};

Expand Down
10 changes: 4 additions & 6 deletions include/libcyphal/transport/can/svc_rx_sessions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class SvcRxSession final : public Interface_, private IRxSessionDelegate
{
const int8_t result = ::canardRxSubscribe(&delegate.canard_instance(),
TransferKind,
static_cast<CanardPortID>(params_.service_id),
static_cast<std::size_t>(params_.extent_bytes),
params_.service_id,
params_.extent_bytes,
CANARD_DEFAULT_TRANSFER_ID_TIMEOUT_USEC,
&subscription_);
(void) result;
Expand All @@ -105,9 +105,7 @@ class SvcRxSession final : public Interface_, private IRxSessionDelegate

~SvcRxSession() override
{
const int8_t result = ::canardRxUnsubscribe(&delegate_.canard_instance(),
TransferKind,
static_cast<CanardPortID>(params_.service_id));
const int8_t result = ::canardRxUnsubscribe(&delegate_.canard_instance(), TransferKind, params_.service_id);
(void) result;
CETL_DEBUG_ASSERT(result >= 0, "There is no way currently to get an error here.");
CETL_DEBUG_ASSERT(result > 0, "Subscription supposed to be made at constructor.");
Expand Down Expand Up @@ -160,7 +158,7 @@ class SvcRxSession final : public Interface_, private IRxSessionDelegate
const ServiceTransferMetadata meta{transfer_id, timestamp, priority, remote_node_id};
TransportDelegate::CanardMemory canard_memory{delegate_, transfer.payload, transfer.payload_size};

last_rx_transfer_.emplace(ServiceRxTransfer{meta, ScatteredBuffer{std::move(canard_memory)}});
(void) last_rx_transfer_.emplace(ServiceRxTransfer{meta, ScatteredBuffer{std::move(canard_memory)}});
}

// MARK: Data members:
Expand Down
4 changes: 2 additions & 2 deletions include/libcyphal/transport/can/svc_tx_sessions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class SvcRequestTxSession final : public IRequestTxSession

const auto canard_metadata = CanardTransferMetadata{static_cast<CanardPriority>(metadata.priority),
CanardTransferKindRequest,
static_cast<CanardPortID>(params_.service_id),
params_.service_id,
static_cast<CanardNodeID>(params_.server_node_id),
static_cast<CanardTransferID>(metadata.transfer_id)};

Expand Down Expand Up @@ -196,7 +196,7 @@ class SvcResponseTxSession final : public IResponseTxSession

const auto canard_metadata = CanardTransferMetadata{static_cast<CanardPriority>(metadata.priority),
CanardTransferKindResponse,
static_cast<CanardPortID>(params_.service_id),
params_.service_id,
static_cast<CanardNodeID>(metadata.remote_node_id),
static_cast<CanardTransferID>(metadata.transfer_id)};

Expand Down
11 changes: 7 additions & 4 deletions include/libcyphal/transport/can/transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ class TransportImpl final : public ICanTransport, private TransportDelegate
// - At least one media interface must be provided, but no more than the maximum allowed (255).
// - If a local node ID is provided, it must be within the valid range.
//
const auto media_count = static_cast<std::size_t>(
std::count_if(media.begin(), media.end(), [](IMedia* const media) { return media != nullptr; }));
const auto media_count =
static_cast<std::size_t>(std::count_if(media.begin(), media.end(), [](const IMedia* const media_ptr) {
return media_ptr != nullptr;
}));
if ((media_count == 0) || (media_count > std::numeric_limits<std::uint8_t>::max()))
{
return ArgumentError{};
Expand Down Expand Up @@ -416,7 +418,8 @@ class TransportImpl final : public ICanTransport, private TransportDelegate
if (media_interface != nullptr)
{
IMedia& media = *media_interface;
media_array.emplace_back(index++, media, tx_capacity);
media_array.emplace_back(index, media, tx_capacity);
index++;
}
}
CETL_DEBUG_ASSERT(index == media_count, "");
Expand Down Expand Up @@ -493,7 +496,7 @@ class TransportImpl final : public ICanTransport, private TransportDelegate
const cetl::span<const cetl::byte> payload{static_cast<const cetl::byte*>(tx_item->frame.payload),
tx_item->frame.payload_size};
const Expected<bool, MediaError> maybe_pushed =
media.interface().push(deadline, static_cast<CanId>(tx_item->frame.extended_can_id), payload);
media.interface().push(deadline, tx_item->frame.extended_can_id, payload);
if (const auto* const is_pushed = cetl::get_if<bool>(&maybe_pushed))
{
if (!*is_pushed)
Expand Down
3 changes: 1 addition & 2 deletions include/libcyphal/transport/udp/transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ class TransportImpl final : public IUdpTransport
}

// TODO: Implement!

return ArgumentError{};
return {};
}

CETL_NODISCARD ProtocolParams getProtocolParams() const noexcept override
Expand Down

0 comments on commit 04e5eff

Please sign in to comment.