Skip to content

Commit

Permalink
refactor(can-gen): ♻️ Improve CAN generation and build support. (#109)
Browse files Browse the repository at this point in the history
* refactor(can-gen): ♻️ Improve CAN generation and build support.

Convert ETL from an include path to a proper target in CMake. Refactor cangen Python code to use a functional paradigm and be more "Pythonic"

* undoes unnecessary indent change

* adds requiremens.txt for cangen
  • Loading branch information
BlakeFreer authored Apr 15, 2024
1 parent 419897f commit 8404833
Show file tree
Hide file tree
Showing 8 changed files with 315 additions and 353 deletions.
6 changes: 0 additions & 6 deletions firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@ add_subdirectory(${DIR_MCAL}) # provides "mcal-<name>" (library)
add_subdirectory(${DIR_PROJECT}) # modifies "main" (executable)
add_subdirectory(${DIR_PLATFORM}) # modifies "bindings" (library)

set(DIR_ETL "${CMAKE_CURRENT_SOURCE_DIR}/third-party/etl/include")
target_include_directories(main
PUBLIC
${DIR_ETL}
)

target_link_libraries(main PRIVATE shared)
target_link_libraries(main PRIVATE bindings)

Expand Down
3 changes: 2 additions & 1 deletion firmware/mcal/raspi/periph/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class CanBase : public shared::periph::CanBase {

void Setup() {
// Create a socket
sock_ = socket(PF_CAN, SOCK_RAW, CAN_RAW) if (sock_ < 0) {
sock_ = socket(PF_CAN, SOCK_RAW, CAN_RAW);
if (sock_ < 0) {
perror("Error creating socket");
return;
}
Expand Down
4 changes: 2 additions & 2 deletions firmware/mcal/windows/periph/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "shared/comms/can/raw_can_msg.h"
#include "shared/periph/can.h"

namespace mcal::periph {
namespace mcal::windows::periph {

class CanBase : public shared::periph::CanBase {
public:
Expand Down Expand Up @@ -48,4 +48,4 @@ class CanBase : public shared::periph::CanBase {
std::string iface_;
};

} // namespace mcal::periph
} // namespace mcal::windows::periph
5 changes: 5 additions & 0 deletions firmware/projects/DemoCan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ target_sources(main
)
add_dependencies(main generated_can)


target_include_directories(main
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/inc
)

# Link ETL which is needed for generated/can/msg_registry.h
add_subdirectory(${CMAKE_SOURCE_DIR}/third-party/etl ${CMAKE_BINARY_DIR}/third-party)
target_link_libraries(main PRIVATE etl)

# Notice that we don't include any mcal/ subdirectory in this CMake file.
# The master CMakeLists handles platform selection and library linking.
2 changes: 1 addition & 1 deletion firmware/projects/DemoCan/platforms/windows/bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "shared/periph/can.h"

namespace mcal {
using namespace periph::windows;
using namespace windows::periph;

CanBase veh_can_base{"vcan0"};
} // namespace mcal
Expand Down
Loading

0 comments on commit 8404833

Please sign in to comment.