Skip to content

Commit

Permalink
WIP: make can message private
Browse files Browse the repository at this point in the history
  • Loading branch information
samparent97 committed Apr 10, 2024
1 parent b12a3ed commit 941f4ae
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions firmware/projects/DemoCan/generated/can_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<DebugLedOverride*>(&rx_msg);

p_rx_msg->set_green_led = set_green_led;
Expand All @@ -61,7 +61,7 @@ class DebugLedOverride : public shared::comms::can::CanRxMsg {
}
}

shared::comms::can::CanId Id() {
shared::comms::can::CanId Id() const {
return kCanId;
}

Expand Down
6 changes: 3 additions & 3 deletions firmware/shared/comms/can/can_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions firmware/shared/comms/can/msg_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 941f4ae

Please sign in to comment.