1212#include < nunavut/support/serialization.hpp>
1313
1414#include < cetl/pf17/cetlpf.hpp>
15+ #include < libcyphal/common/crc.hpp>
1516
1617#include < cstddef>
1718#include < functional>
@@ -33,11 +34,19 @@ class AnyChannel
3334 struct Disconnected
3435 {};
3536
36- template <typename Input >
37- using EventVar = cetl::variant<Input , Connected, Disconnected>;
37+ template <typename Message >
38+ using EventVar = cetl::variant<Message , Connected, Disconnected>;
3839
39- template <typename Input>
40- using EventHandler = std::function<void (const EventVar<Input>&)>;
40+ template <typename Message>
41+ using EventHandler = std::function<void (const EventVar<Message>&)>;
42+
43+ template <typename Message>
44+ static detail::MsgTypeId getTypeId () noexcept
45+ {
46+ const cetl::string_view type_name{Message::_traits_::FullNameAndVersion ()};
47+ const libcyphal::common::CRC64WE crc64{type_name.cbegin (), type_name.cend ()};
48+ return crc64.get ();
49+ }
4150
4251protected:
4352 AnyChannel () = default ;
@@ -57,6 +66,7 @@ class Channel final : public AnyChannel
5766 : memory_{other.memory_ }
5867 , gateway_{std::move (other.gateway_ )}
5968 , event_handler_{std::move (other.event_handler_ )}
69+ , output_type_id_{other.output_type_id_ }
6070 {
6171 setupEventHandler ();
6272 }
@@ -83,7 +93,7 @@ class Channel final : public AnyChannel
8393 output,
8494 [this ](const auto payload) {
8595 //
86- gateway_->send (payload);
96+ gateway_->send (output_type_id_, payload);
8797 return cetl::nullopt ;
8898 });
8999 }
@@ -95,6 +105,7 @@ class Channel final : public AnyChannel
95105 : memory_{memory}
96106 , gateway_{std::move (gateway)}
97107 , event_handler_{std::move (event_handler)}
108+ , output_type_id_{getTypeId<Output>()}
98109 {
99110 CETL_DEBUG_ASSERT (gateway_, " " );
100111 CETL_DEBUG_ASSERT (event_handler_, " " );
@@ -139,6 +150,7 @@ class Channel final : public AnyChannel
139150 cetl::pmr::memory_resource& memory_;
140151 detail::Gateway::Ptr gateway_;
141152 EventHandler event_handler_;
153+ detail::MsgTypeId output_type_id_;
142154
143155}; // Channel
144156
0 commit comments