From 941f4aef03d2684a8803fcf4db5602fcea68a3af Mon Sep 17 00:00:00 2001 From: Sam Parent Date: Wed, 10 Apr 2024 15:42:29 -0400 Subject: [PATCH] WIP: make can message private --- firmware/projects/DemoCan/generated/can_messages.h | 4 ++-- firmware/shared/comms/can/can_msg.h | 6 +++--- firmware/shared/comms/can/msg_registry.h | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/firmware/projects/DemoCan/generated/can_messages.h b/firmware/projects/DemoCan/generated/can_messages.h index f8d7980e5..717d19bd7 100644 --- a/firmware/projects/DemoCan/generated/can_messages.h +++ b/firmware/projects/DemoCan/generated/can_messages.h @@ -47,7 +47,7 @@ class DebugLedOverride : public shared::comms::can::CanRxMsg { static constexpr bool kIsExtFrame = true; public: - void Clone(shared::comms::can::CanRxMsg& rx_msg) { + void Clone(shared::comms::can::CanRxMsg& rx_msg) const { DebugLedOverride* p_rx_msg = static_cast(&rx_msg); p_rx_msg->set_green_led = set_green_led; @@ -61,7 +61,7 @@ class DebugLedOverride : public shared::comms::can::CanRxMsg { } } - shared::comms::can::CanId Id() { + shared::comms::can::CanId Id() const { return kCanId; } diff --git a/firmware/shared/comms/can/can_msg.h b/firmware/shared/comms/can/can_msg.h index de1b20184..a2818de42 100644 --- a/firmware/shared/comms/can/can_msg.h +++ b/firmware/shared/comms/can/can_msg.h @@ -12,10 +12,10 @@ class DemoCanVehMsgRegistry; class CanMsg {}; class CanRxMsg : public CanMsg { -public: - virtual void Clone(CanRxMsg&) = 0; +private: + virtual const void Clone(CanRxMsg&) const = 0; virtual void Unpack(const RawCanMsg&) = 0; - virtual CanId Id() = 0; + virtual CanId Id() const = 0; }; class CanTxMsg : public CanMsg { diff --git a/firmware/shared/comms/can/msg_registry.h b/firmware/shared/comms/can/msg_registry.h index 1498bd366..53c09290d 100644 --- a/firmware/shared/comms/can/msg_registry.h +++ b/firmware/shared/comms/can/msg_registry.h @@ -11,6 +11,20 @@ class MsgRegistry { public: virtual bool SetMessage(const RawCanMsg&) = 0; virtual bool GetMessage(CanRxMsg&) = 0; +protected: + static inline void Unpack(CanRxMsg* rx_msg, const RawCanMsg& raw_msg) { + rx_msg.Unpack(raw_msg); + } + + static inline void Clone(const CanRxMsg* const dst_rx_msg, CanRxMsg& dst_rx_msg) { + rx_msg.Clone(raw_msg); + } + + static inline CanId MsgId(const CanRxMsg* const rx_msg){ + return rx_msg.Clone(raw_msg); + } + + }; } // namespace shared::comms::can \ No newline at end of file