-
Notifications
You must be signed in to change notification settings - Fork 503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation of CAN Msg Rx Session #347
Implementation of CAN Msg Rx Session #347
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really need some high-level comments on the classes to comprehend your intentions.
namespace detail | ||
{ | ||
|
||
struct TransportDelegate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's not fall behind on the comments in this code base. Please ensure all classes, interfaces, and public methods have some level of documentation. Especially as things first go in it helps to know what you are thinking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all classes, interfaces, and public methods
See my comment here about omitting documentation in obvious cases (I am not saying that this case in particular is obvious): #343 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, documentation will come, just a bit later - when api will be more stable. For now I'm not documenting yet to faster get something to play with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in the other review, my main concern is interface/class/struct documentation. It doesn't have to be complete at the start but I need some help understanding your design intention in these early reviews.
{ | ||
auto& self = getSelfFrom(ins); | ||
|
||
const auto memory_size = sizeof(CanardMemoryHeader) + amount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's follow AUTOSAR A7-1-5 and only use auto
to:
- declare that a variable has the same type as return type of a function call
- declare that a variable has the same type as initializer of non-fundamental type
- declare parameters of a generic lambda expression
- declare a function template using trailing return type syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will read this A7-1-5 carefully I try fix obvious cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe/hope it's fine to use more auto
-s in unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Just remember humans need to read code too so sometimes auto helps by simplifying a statement and sometimes it obfuscates by making the type inscrutable. You can always use github co-pilot to reduce the amount of typing ;-)
@@ -65,6 +65,18 @@ using PmrAllocator = cetl::pmr::polymorphic_allocator<T>; | |||
template <typename T> | |||
using VarArray = cetl::VariableLengthArray<T, PmrAllocator<T>>; | |||
|
|||
template <typename Tag, typename... Args> | |||
CETL_NODISCARD UniquePtr<typename Tag::Interface> makeUniquePtr(cetl::pmr::memory_resource& memory, Args&&... args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to promote this pattern up into cetl::pmr::Factory at some point. As such, let's adopt a more appropriate name that distinguishes this from unique_ptr
. Pavel and I had discussed calling this technique: dark_ptr
since it hides the concrete type from the user of the smart-pointer-to-interface type. So dark_ptr
and make_dark
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it's voldemort_ptr
and make_voldemort
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about interface_ptr
and makeInterfacePtr
? Both "dark" and "voldemort" are funny, but IMHO doesn't look serious...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interface_ptr seems reasonable. I'm fairly certain voldemort
is a trademark anyway.
I think my biggest sticking point here is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed on call: we have the right issues captured now to ensure my overarching concerns with this PR will be addressed moving forward
canard_instance().user_reference = this; | ||
} | ||
|
||
CETL_NODISCARD inline CanardInstance& canard_instance() noexcept |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CETL_NODISCARD inline CanardInstance& canard_instance() noexcept | |
CETL_NODISCARD CanardInstance& canard_instance() noexcept |
inline
is redundant and should be removed; see the other methods as well
type_id_type<0x11, 0x41, 0xF5, 0xC0, 0x2E, 0x61, 0x44, 0xBF, 0x9F, 0x0E, 0xFA, 0x1C, 0x51, 0x8C, 0xD5, 0x17>; | ||
|
||
public: | ||
class CanardMemory final : public cetl::rtti_helper<CanardMemoryTypeIdType, ScatteredBuffer::Interface> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe CanardScatteredBuffer
makes a better name? The current name is a bit too generic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe... in the next pr I will already have ScatteredBuffer
(renamed DynamicBuffer
)
} | ||
|
||
const auto bytes_to_copy = std::min(length_bytes, payload_size_ - offset_bytes); | ||
memcpy(destination, static_cast<cetl::byte*>(buffer_) + offset_bytes, bytes_to_copy); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memcpy(destination, static_cast<cetl::byte*>(buffer_) + offset_bytes, bytes_to_copy); | |
std::memmove(destination, static_cast<cetl::byte*>(buffer_) + offset_bytes, bytes_to_copy); |
{ | ||
std::uint32_t code; | ||
}; | ||
|
||
struct SessionAlreadyExistsError final |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct SessionAlreadyExistsError final | |
struct AlreadyExistsError final |
This way, the error type will be reusable and whether it's related to a session or anything else will be evident from context.
@@ -0,0 +1,53 @@ | |||
/// @file | |||
/// libcyphal common header. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy/paste error
CanardRxSubscription* out_subscription{}; | ||
|
||
// TODO: Handle errors. | ||
const auto result = canardRxAccept(&canard_instance(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need an assertion check here that we never get an argument error back from libcanard
const auto result = canardRxAccept(&canard_instance(), | ||
static_cast<CanardMicrosecond>(timestamp_us.count()), | ||
&canard_frame, | ||
static_cast<uint8_t>(media_index), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static_cast<uint8_t>(media_index), | |
static_cast<std::uint8_t>(media_index), |
AFAIK C++ does not define symbols in the global namespace, this thing comes from C.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thinking was that in such conversions I covert to terms/types Canard is using... in this particular case the 4th parameter of ::canardRxAccept
.
|
||
CETL_NODISCARD static inline TransportImpl& getSelfFrom(const CanardInstance* const ins) | ||
CETL_NODISCARD inline TransportDelegate& asDelegate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another redundant inline here
MessageRxSession
can::TransportDelegate
entity:Also: