-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2b7591
commit 0035f5e
Showing
4 changed files
with
116 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/// @author Samuel Parent | ||
/// @date {{ date }} | ||
|
||
#pragma once | ||
|
||
#include "can_messages.h" | ||
#include "shared/comms/can/can_msg.h" | ||
#include "shared/comms/can/msg_registry.h" | ||
#include "shared/comms/can/raw_can_msg.h" | ||
#include "third-party/etl/include/etl/unordered_map.h" | ||
|
||
namespace generated::can { | ||
|
||
{% set reg_class_name = bus_name + "MsgRegistry" %} | ||
class {{ reg_class_name }} : public shared::can::MsgRegistry { | ||
public: | ||
bool SetMessage(const shared::can::RawCanMsg& raw_msg) { | ||
bool msg_found = false; | ||
|
||
if (rx_msg_map_.count(raw_msg.header.id) > 0) { | ||
msg_found = true; | ||
|
||
Unpack(rx_msg_map_[raw_msg.header.id], raw_msg); | ||
} | ||
|
||
return msg_found; | ||
} | ||
|
||
bool GetMessage(shared::can::CanRxMsg& rx_msg) { | ||
bool msg_found = false; | ||
|
||
shared::can::CanId mid = MsgId(&rx_msg); | ||
|
||
if (rx_msg_map_.count(mid) > 0) { | ||
msg_found = true; | ||
|
||
Clone(rx_msg_map_[mid], rx_msg); | ||
} | ||
|
||
return msg_found; | ||
} | ||
|
||
private: | ||
static constexpr size_t kNumRxMsgs = {{ rx_msgs | length }}; | ||
|
||
// Message IDs | ||
{% for msg in rx_msgs %} | ||
{% set class_name = msg.name %} | ||
{% set class_const = "k" + class_name + "CanId" %} | ||
{% set hex_id = msg.frame_id | decimal_to_hex %} | ||
static constexpr shared::can::CanId {{ class_const }} = {{ hex_id }}; | ||
{% endfor %} | ||
|
||
// Can Rx Messages | ||
{% for msg in rx_msgs %} | ||
{% set class_name = msg.name %} | ||
{% set class_var = (class_name | camel_to_snake) + "_" %} | ||
{{ class_name }} {{ class_var }}; | ||
{% endfor %} | ||
|
||
etl::unordered_map<shared::can::CanId, shared::can::CanRxMsg*, kNumRxMsgs> | ||
{% for msg in rx_msgs %} | ||
{% set class_name = msg.name %} | ||
{% set class_var = (class_name | camel_to_snake) + "_" %} | ||
{% set msg_id = "k" + class_name + "CanId" %} | ||
rx_msg_map_ = { | ||
{ {{ msg_id }}, &{{class_var}} }, | ||
}; | ||
{% endfor %} | ||
}; | ||
|
||
} // namespace generated::can |