From 6e1d01b549d15aefde8ed0144a045e56eaa78f93 Mon Sep 17 00:00:00 2001 From: luaibash Date: Tue, 5 Nov 2024 22:22:42 -0500 Subject: [PATCH 01/15] Moved all CANError demo code to branch --- .../projects/Demo/CANErrors/CMakeLists.txt | 1 + firmware/projects/Demo/CANErrors/README.md | 8 ++ firmware/projects/Demo/CANErrors/bindings.h | 5 + firmware/projects/Demo/CANErrors/config.yaml | 5 + firmware/projects/Demo/CANErrors/errors.dbc | 101 ++++++++++++++++++ firmware/projects/Demo/CANErrors/main.cc | 14 +++ .../CANErrors/platforms/cli/CMakeLists.txt | 3 + .../Demo/CANErrors/platforms/cli/bindings.cc | 7 ++ .../CANErrors/platforms/cli/mcal_conf.cmake | 1 + 9 files changed, 145 insertions(+) create mode 100644 firmware/projects/Demo/CANErrors/CMakeLists.txt create mode 100644 firmware/projects/Demo/CANErrors/README.md create mode 100644 firmware/projects/Demo/CANErrors/bindings.h create mode 100644 firmware/projects/Demo/CANErrors/config.yaml create mode 100644 firmware/projects/Demo/CANErrors/errors.dbc create mode 100644 firmware/projects/Demo/CANErrors/main.cc create mode 100644 firmware/projects/Demo/CANErrors/platforms/cli/CMakeLists.txt create mode 100644 firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc create mode 100644 firmware/projects/Demo/CANErrors/platforms/cli/mcal_conf.cmake diff --git a/firmware/projects/Demo/CANErrors/CMakeLists.txt b/firmware/projects/Demo/CANErrors/CMakeLists.txt new file mode 100644 index 000000000..d528587c7 --- /dev/null +++ b/firmware/projects/Demo/CANErrors/CMakeLists.txt @@ -0,0 +1 @@ +target_sources(main PUBLIC main.cc) \ No newline at end of file diff --git a/firmware/projects/Demo/CANErrors/README.md b/firmware/projects/Demo/CANErrors/README.md new file mode 100644 index 000000000..af9f55bc9 --- /dev/null +++ b/firmware/projects/Demo/CANErrors/README.md @@ -0,0 +1,8 @@ +# CANErrors + +This is the CAN Errors demo project. This defines the mechanism for reporting errors from the vehicle microcontrollers. This project will send errors over the CAN line and process them on a host machine. + +## Generating The Code +- Code must be generated using CanGen. Install CanGen in the racecar directory with "pip install -e scripts/cangen" + - A venv isn't needed for this! +- Generate the code in the firmware directory with "cangen projects/Demo/CANErrors" \ No newline at end of file diff --git a/firmware/projects/Demo/CANErrors/bindings.h b/firmware/projects/Demo/CANErrors/bindings.h new file mode 100644 index 000000000..f392cf54f --- /dev/null +++ b/firmware/projects/Demo/CANErrors/bindings.h @@ -0,0 +1,5 @@ +#pragma once + +namespace bindings { + +} // namespace bindings \ No newline at end of file diff --git a/firmware/projects/Demo/CANErrors/config.yaml b/firmware/projects/Demo/CANErrors/config.yaml new file mode 100644 index 000000000..8e0788a79 --- /dev/null +++ b/firmware/projects/Demo/CANErrors/config.yaml @@ -0,0 +1,5 @@ +canGen: + busses: + - name: error + node: tms + dbcFile: errors.dbc \ No newline at end of file diff --git a/firmware/projects/Demo/CANErrors/errors.dbc b/firmware/projects/Demo/CANErrors/errors.dbc new file mode 100644 index 000000000..f226c85e3 --- /dev/null +++ b/firmware/projects/Demo/CANErrors/errors.dbc @@ -0,0 +1,101 @@ +VERSION "" + +NS_ : + NS_DESC_ + CM_ + BA_DEF_ + BA_ + VAL_ + CAT_DEF_ + CAT_ + FILTER + BA_DEF_DEF_ + EV_DATA_ + ENVVAR_DATA_ + SGTYPE_ + SGTYPE_VAL_ + BA_DEF_SGTYPE_ + BA_SGTYPE_ + SIG_TYPE_REF_ + VAL_TABLE_ + SIG_GROUP_ + SIG_VALTYPE_ + SIGTYPE_VALTYPE_ + BO_TX_BU_ + BA_DEF_REL_ + BA_REL_ + BA_DEF_DEF_REL_ + BU_SG_REL_ + BU_EV_REL_ + BU_BO_REL_ + SG_MUL_VAL_ + +BS_: + +BU_: TMS + +BO_ 390 TMS_ERROR: 8 TMS + SG_ Error0 : 0|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error1 : 1|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error2 : 2|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error3 : 3|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error4 : 4|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error5 : 5|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error6 : 6|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error7 : 7|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error8 : 8|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error9 : 9|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error10 : 10|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error11 : 11|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error12 : 12|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error13 : 13|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error14 : 14|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error15 : 15|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error16 : 16|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error17 : 17|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error18 : 18|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error19 : 19|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error20 : 20|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error21 : 21|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error22 : 22|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error23 : 23|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error24 : 24|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error25 : 25|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error26 : 26|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error27 : 27|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error28 : 28|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error29 : 29|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error30 : 30|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error31 : 31|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error32 : 32|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error33 : 33|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error34 : 34|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error35 : 35|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error36 : 36|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error37 : 37|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error38 : 38|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error39 : 39|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error40 : 40|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error41 : 41|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error42 : 42|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error43 : 43|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error44 : 44|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error45 : 45|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error46 : 46|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error47 : 47|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error48 : 48|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error49 : 49|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error50 : 50|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error51 : 51|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error52 : 52|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error53 : 53|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error54 : 54|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error55 : 55|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error56 : 56|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error57 : 57|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error58 : 58|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error59 : 59|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error60 : 60|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error61 : 61|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error62 : 62|1@1- (1,0) [0|0] "bool" Vector__XXX + SG_ Error63 : 63|1@1- (1,0) [0|0] "bool" Vector__XXX \ No newline at end of file diff --git a/firmware/projects/Demo/CANErrors/main.cc b/firmware/projects/Demo/CANErrors/main.cc new file mode 100644 index 000000000..d3efd8254 --- /dev/null +++ b/firmware/projects/Demo/CANErrors/main.cc @@ -0,0 +1,14 @@ +#include "bindings.h" + +int main() { + bindings::Initialize(); + + while (true) { + bindings::indicator.SetHigh(); + bindings::DelayMS(1000); + bindings::indicator.SetLow(); + bindings::DelayMS(1000); + } + + return 0; +} \ No newline at end of file diff --git a/firmware/projects/Demo/CANErrors/platforms/cli/CMakeLists.txt b/firmware/projects/Demo/CANErrors/platforms/cli/CMakeLists.txt new file mode 100644 index 000000000..6748669b7 --- /dev/null +++ b/firmware/projects/Demo/CANErrors/platforms/cli/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(bindings PRIVATE bindings.cc) + +target_link_libraries(bindings PUBLIC mcal-cli) \ No newline at end of file diff --git a/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc b/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc new file mode 100644 index 000000000..105f93916 --- /dev/null +++ b/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc @@ -0,0 +1,7 @@ +#include + +#include + +namespace mcal { + +} // namespace bindings \ No newline at end of file diff --git a/firmware/projects/Demo/CANErrors/platforms/cli/mcal_conf.cmake b/firmware/projects/Demo/CANErrors/platforms/cli/mcal_conf.cmake new file mode 100644 index 000000000..a30e90e12 --- /dev/null +++ b/firmware/projects/Demo/CANErrors/platforms/cli/mcal_conf.cmake @@ -0,0 +1 @@ +set(MCAL cli) \ No newline at end of file From 22dcb56b93933e6982fed76a3ea3011a93e223cb Mon Sep 17 00:00:00 2001 From: luaibash Date: Wed, 6 Nov 2024 00:44:42 -0500 Subject: [PATCH 02/15] Fixing the config files for the CAN project --- firmware/projects/Demo/CAN/Bar/config.yaml | 3 +-- firmware/projects/Demo/CAN/Foo/config.yaml | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/firmware/projects/Demo/CAN/Bar/config.yaml b/firmware/projects/Demo/CAN/Bar/config.yaml index 2599bb986..0aab1cb92 100644 --- a/firmware/projects/Demo/CAN/Bar/config.yaml +++ b/firmware/projects/Demo/CAN/Bar/config.yaml @@ -2,5 +2,4 @@ canGen: busses: - name: veh node: bar - dbcFiles: - - "../demo.dbc" + dbcFile: "../demo.dbc" diff --git a/firmware/projects/Demo/CAN/Foo/config.yaml b/firmware/projects/Demo/CAN/Foo/config.yaml index 4ef5a0ddc..91fb7387a 100644 --- a/firmware/projects/Demo/CAN/Foo/config.yaml +++ b/firmware/projects/Demo/CAN/Foo/config.yaml @@ -2,5 +2,4 @@ canGen: busses: - name: veh node: foo - dbcFiles: - - "../demo.dbc" \ No newline at end of file + dbcFile: "../demo.dbc" \ No newline at end of file From bb3ee3913cbdc5f4ab39a0eb082d18b31d08219f Mon Sep 17 00:00:00 2001 From: luaibash Date: Wed, 6 Nov 2024 00:45:23 -0500 Subject: [PATCH 03/15] Added sending/logging functionality of errors in CANErrors project --- .../projects/Demo/CANErrors/CMakeLists.txt | 21 ++++++- firmware/projects/Demo/CANErrors/README.md | 9 ++- firmware/projects/Demo/CANErrors/main.cc | 55 +++++++++++++++++-- .../Demo/CANErrors/platforms/cli/bindings.cc | 26 ++++++++- 4 files changed, 100 insertions(+), 11 deletions(-) diff --git a/firmware/projects/Demo/CANErrors/CMakeLists.txt b/firmware/projects/Demo/CANErrors/CMakeLists.txt index d528587c7..f089022d5 100644 --- a/firmware/projects/Demo/CANErrors/CMakeLists.txt +++ b/firmware/projects/Demo/CANErrors/CMakeLists.txt @@ -1 +1,20 @@ -target_sources(main PUBLIC main.cc) \ No newline at end of file +# Luai Bashar +# November 5, 2024 + +# The target executable 'main' is created in the master CMakeLists. Do not change its name. +# We only need to add the source code files and include directories. + +include("${CMAKE_SOURCE_DIR}/cmake/cangen.cmake") + +target_sources(main + PRIVATE + main.cc +) + +target_include_directories(main + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/inc +) + +# Notice that we don't include any mcal/ subdirectory in this CMake file. +# The master CMakeLists handles platform selection and library linking. \ No newline at end of file diff --git a/firmware/projects/Demo/CANErrors/README.md b/firmware/projects/Demo/CANErrors/README.md index af9f55bc9..6eb6a613b 100644 --- a/firmware/projects/Demo/CANErrors/README.md +++ b/firmware/projects/Demo/CANErrors/README.md @@ -2,7 +2,12 @@ This is the CAN Errors demo project. This defines the mechanism for reporting errors from the vehicle microcontrollers. This project will send errors over the CAN line and process them on a host machine. -## Generating The Code +## Generating The DBC Code - Code must be generated using CanGen. Install CanGen in the racecar directory with "pip install -e scripts/cangen" - A venv isn't needed for this! -- Generate the code in the firmware directory with "cangen projects/Demo/CANErrors" \ No newline at end of file +- Generate the code in the firmware directory with "cangen projects/Demo/CANErrors" + +## Building the Project +- To build the project, run the following in the firmware directory "make PROJECT=Demo/CANErrors PLATFORM=cli" + - This should create a build file with no errors! +- To execute the new build, run "./build/Demo/CANErrors/cli/main.exe" \ No newline at end of file diff --git a/firmware/projects/Demo/CANErrors/main.cc b/firmware/projects/Demo/CANErrors/main.cc index d3efd8254..464df137f 100644 --- a/firmware/projects/Demo/CANErrors/main.cc +++ b/firmware/projects/Demo/CANErrors/main.cc @@ -1,13 +1,56 @@ -#include "bindings.h" +/// @author Luai Bashar +/// @date 2024-11-05 -int main() { +#include + +#include "generated/can/error_can_messages.h" +#include "generated/can/error_msg_registry.h" +#include "shared/comms/can/can_bus.h" + +namespace bindings { + extern shared::periph::CanBase& error_can_base; + extern void Initialize(); + extern void TickBlocking(uint32_t); +} // namespace bindings + +generated::can::ErrorMsgRegistry error_can_registry{}; + +shared::can::CanBus error_can_bus{ + bindings::error_can_base, + error_can_registry, +}; + +int main(void) { bindings::Initialize(); + uint32_t tick_duration = 100; + + // Initialize the error object that holds all 64 errors + generated::can::TMS_ERROR error_msg{}; while (true) { - bindings::indicator.SetHigh(); - bindings::DelayMS(1000); - bindings::indicator.SetLow(); - bindings::DelayMS(1000); + error_can_bus.Update(); + + // Set the 1st error to the opposite value and send + error_msg.error0 = !error_msg.error0; + error_can_bus.Send(error_msg); + + // Set the 15th error to the opposite value and send + error_msg.error15 = !error_msg.error15; + error_can_bus.Send(error_msg); + + // Set the 33rd error to the opposite value and send + error_msg.error33 = !error_msg.error33; + error_can_bus.Send(error_msg); + + // Set the 7th error to the opposite value and send + error_msg.error7 = !error_msg.error7; + error_can_bus.Send(error_msg); + + // Set the 63rd error to the opposite value and send + error_msg.error63 = !error_msg.error63; + error_can_bus.Send(error_msg); + + bindings::TickBlocking(tick_duration); } return 0; diff --git a/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc b/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc index 105f93916..e7e53c07f 100644 --- a/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc +++ b/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc @@ -1,7 +1,29 @@ -#include +/// @author Luai Bashar +/// @date 2024-11-05 -#include +#include +#include + +#include "mcal/cli/periph/can.h" +#include "shared/periph/can.h" namespace mcal { +using namespace cli::periph; + +CanBase error_can_base{"vcan0"}; +} // namespace mcal + +namespace bindings { +shared::periph::CanBase& error_can_base = mcal::error_can_base; + +void TickBlocking(uint32_t ticks) { + std::chrono::milliseconds duration(ticks); + + std::this_thread::sleep_for(duration); +} +void Initialize() { + mcal::error_can_base.Setup(); + std::cout << "Initializing CLI..." << std::endl; +} } // namespace bindings \ No newline at end of file From 9dada04afeaeacc84ad11c358b49c6452ee57eff Mon Sep 17 00:00:00 2001 From: luaibash Date: Fri, 8 Nov 2024 22:44:05 -0500 Subject: [PATCH 04/15] Reformatted code and added comments for clarity --- firmware/projects/Demo/CANErrors/main.cc | 5 +++- .../Demo/CANErrors/platforms/cli/bindings.cc | 28 ++++++++++--------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/firmware/projects/Demo/CANErrors/main.cc b/firmware/projects/Demo/CANErrors/main.cc index 464df137f..aaaef397d 100644 --- a/firmware/projects/Demo/CANErrors/main.cc +++ b/firmware/projects/Demo/CANErrors/main.cc @@ -11,7 +11,7 @@ namespace bindings { extern shared::periph::CanBase& error_can_base; extern void Initialize(); extern void TickBlocking(uint32_t); -} // namespace bindings +} generated::can::ErrorMsgRegistry error_can_registry{}; @@ -21,6 +21,7 @@ shared::can::CanBus error_can_bus{ }; int main(void) { + // Initialize the CLI and milliseconds to repeat by bindings::Initialize(); uint32_t tick_duration = 100; @@ -28,6 +29,7 @@ int main(void) { generated::can::TMS_ERROR error_msg{}; while (true) { + // "Send" the output, printing to stdout error_can_bus.Update(); // Set the 1st error to the opposite value and send @@ -50,6 +52,7 @@ int main(void) { error_msg.error63 = !error_msg.error63; error_can_bus.Send(error_msg); + // Wait for 100ms before repeating the process bindings::TickBlocking(tick_duration); } diff --git a/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc b/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc index e7e53c07f..6f4cbc74a 100644 --- a/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc +++ b/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc @@ -8,22 +8,24 @@ #include "shared/periph/can.h" namespace mcal { -using namespace cli::periph; + using namespace cli::periph; -CanBase error_can_base{"vcan0"}; -} // namespace mcal + CanBase error_can_base{"vcan0"}; +} namespace bindings { -shared::periph::CanBase& error_can_base = mcal::error_can_base; + shared::periph::CanBase& error_can_base = mcal::error_can_base; -void TickBlocking(uint32_t ticks) { - std::chrono::milliseconds duration(ticks); + // Simulates a sleep, waiting for inputted ticks ms + void TickBlocking(uint32_t ticks) { + std::chrono::milliseconds duration(ticks); - std::this_thread::sleep_for(duration); -} + std::this_thread::sleep_for(duration); + } -void Initialize() { - mcal::error_can_base.Setup(); - std::cout << "Initializing CLI..." << std::endl; -} -} // namespace bindings \ No newline at end of file + // Initializes the can/CLI outputs + void Initialize() { + mcal::error_can_base.Setup(); + std::cout << "Initializing CLI..." << std::endl; + } +} \ No newline at end of file From 27e54af70a3378b6a821ef004da3a18578c6d953 Mon Sep 17 00:00:00 2001 From: luaibash Date: Sat, 9 Nov 2024 00:17:24 -0500 Subject: [PATCH 05/15] Combined all errors into one 64 bit signal in dbc file for easier use --- firmware/projects/Demo/CANErrors/errors.dbc | 66 +-------------------- 1 file changed, 2 insertions(+), 64 deletions(-) diff --git a/firmware/projects/Demo/CANErrors/errors.dbc b/firmware/projects/Demo/CANErrors/errors.dbc index f226c85e3..3d62ecb93 100644 --- a/firmware/projects/Demo/CANErrors/errors.dbc +++ b/firmware/projects/Demo/CANErrors/errors.dbc @@ -34,68 +34,6 @@ BS_: BU_: TMS +// Defines one 64 bit signal where each bit represents a different error BO_ 390 TMS_ERROR: 8 TMS - SG_ Error0 : 0|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error1 : 1|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error2 : 2|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error3 : 3|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error4 : 4|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error5 : 5|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error6 : 6|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error7 : 7|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error8 : 8|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error9 : 9|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error10 : 10|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error11 : 11|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error12 : 12|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error13 : 13|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error14 : 14|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error15 : 15|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error16 : 16|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error17 : 17|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error18 : 18|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error19 : 19|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error20 : 20|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error21 : 21|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error22 : 22|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error23 : 23|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error24 : 24|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error25 : 25|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error26 : 26|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error27 : 27|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error28 : 28|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error29 : 29|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error30 : 30|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error31 : 31|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error32 : 32|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error33 : 33|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error34 : 34|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error35 : 35|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error36 : 36|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error37 : 37|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error38 : 38|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error39 : 39|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error40 : 40|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error41 : 41|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error42 : 42|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error43 : 43|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error44 : 44|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error45 : 45|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error46 : 46|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error47 : 47|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error48 : 48|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error49 : 49|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error50 : 50|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error51 : 51|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error52 : 52|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error53 : 53|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error54 : 54|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error55 : 55|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error56 : 56|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error57 : 57|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error58 : 58|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error59 : 59|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error60 : 60|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error61 : 61|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error62 : 62|1@1- (1,0) [0|0] "bool" Vector__XXX - SG_ Error63 : 63|1@1- (1,0) [0|0] "bool" Vector__XXX \ No newline at end of file + SG_ Errors : 0|64@1- (1,0) [0|0] "bitfield" Vector__XXX \ No newline at end of file From b60b6ecca8198e56f67a9bf5147dfe823efbf9c4 Mon Sep 17 00:00:00 2001 From: luaibash Date: Sat, 9 Nov 2024 00:17:47 -0500 Subject: [PATCH 06/15] Created errors class to set/send errors --- .../Demo/CANErrors/platforms/cli/bindings.cc | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc b/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc index 6f4cbc74a..e401fe541 100644 --- a/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc +++ b/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc @@ -7,6 +7,9 @@ #include "mcal/cli/periph/can.h" #include "shared/periph/can.h" +#include "../../generated/can/error_can_messages.h" +#include "shared/comms/can/can_bus.h" + namespace mcal { using namespace cli::periph; @@ -28,4 +31,34 @@ namespace bindings { mcal::error_can_base.Setup(); std::cout << "Initializing CLI..." << std::endl; } + + // Interface to set/send all possible errors for the system + class Errors { + private: + // Object that holds a 64 bit int, each bit representing an error + generated::can::TMS_ERROR error_msg{}; + public: + // Sets the error based on the error index given + void setError(uint32_t error) { + if (error < 0 || error > 63) { + std::cerr << "Error index must be between 0 and 63!" << std::endl; + return; + } + + error_msg.errors |= (1ULL << error); + } + + // Sends the error message through the provided CAN bus + void sendError(shared::can::CanBus error_can_bus) { + error_can_bus.Send(error_msg); + + // Reset after a send to not send duplicate errors + resetError(); + } + + // Resets all errors back to untriggered + void resetError() { + error_msg.errors = 0; + } + }; } \ No newline at end of file From 46ccd1e065e37f0f7df8bcedd2ae32816f6fa8c0 Mon Sep 17 00:00:00 2001 From: luaibash Date: Sat, 9 Nov 2024 00:18:14 -0500 Subject: [PATCH 07/15] Moved bindings to its own file and started using errors class --- firmware/projects/Demo/CANErrors/bindings.h | 16 +++++++- firmware/projects/Demo/CANErrors/main.cc | 42 +++++---------------- 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/firmware/projects/Demo/CANErrors/bindings.h b/firmware/projects/Demo/CANErrors/bindings.h index f392cf54f..9d3868805 100644 --- a/firmware/projects/Demo/CANErrors/bindings.h +++ b/firmware/projects/Demo/CANErrors/bindings.h @@ -1,5 +1,19 @@ #pragma once +#include "shared/comms/can/can_bus.h" +#include "generated/can/error_can_messages.h" + namespace bindings { + extern shared::periph::CanBase& error_can_base; + extern void Initialize(); + extern void TickBlocking(uint32_t); -} // namespace bindings \ No newline at end of file + class Errors { + private: + generated::can::TMS_ERROR error_msg{}; + public: + void setError(uint32_t error); + void sendError(shared::can::CanBus error_can_bus); + void resetError(); + }; +} \ No newline at end of file diff --git a/firmware/projects/Demo/CANErrors/main.cc b/firmware/projects/Demo/CANErrors/main.cc index aaaef397d..69933b8c5 100644 --- a/firmware/projects/Demo/CANErrors/main.cc +++ b/firmware/projects/Demo/CANErrors/main.cc @@ -2,19 +2,12 @@ /// @date 2024-11-05 #include - -#include "generated/can/error_can_messages.h" -#include "generated/can/error_msg_registry.h" +#include "bindings.h" #include "shared/comms/can/can_bus.h" +#include "generated/can/error_msg_registry.h" -namespace bindings { - extern shared::periph::CanBase& error_can_base; - extern void Initialize(); - extern void TickBlocking(uint32_t); -} - +// Initializing can bus that sends the error message generated::can::ErrorMsgRegistry error_can_registry{}; - shared::can::CanBus error_can_bus{ bindings::error_can_base, error_can_registry, @@ -25,32 +18,17 @@ int main(void) { bindings::Initialize(); uint32_t tick_duration = 100; - // Initialize the error object that holds all 64 errors - generated::can::TMS_ERROR error_msg{}; + // Initialize the error object that sets/sends each error + bindings::Errors error_msg{}; while (true) { - // "Send" the output, printing to stdout error_can_bus.Update(); - // Set the 1st error to the opposite value and send - error_msg.error0 = !error_msg.error0; - error_can_bus.Send(error_msg); - - // Set the 15th error to the opposite value and send - error_msg.error15 = !error_msg.error15; - error_can_bus.Send(error_msg); - - // Set the 33rd error to the opposite value and send - error_msg.error33 = !error_msg.error33; - error_can_bus.Send(error_msg); - - // Set the 7th error to the opposite value and send - error_msg.error7 = !error_msg.error7; - error_can_bus.Send(error_msg); - - // Set the 63rd error to the opposite value and send - error_msg.error63 = !error_msg.error63; - error_can_bus.Send(error_msg); + // Iterate through each error, setting it and sending it + for (int i = 0; i < 63; i++) { + // error_msg.setError(i); + // error_msg.sendError(error_can_bus); + } // Wait for 100ms before repeating the process bindings::TickBlocking(tick_duration); From bf4c91d1c8974fecd00a9875bbb138c783b85978 Mon Sep 17 00:00:00 2001 From: luaibash Date: Sun, 10 Nov 2024 18:28:07 -0500 Subject: [PATCH 08/15] Moved class to header file, added enums for errors --- firmware/projects/Demo/CANErrors/bindings.h | 99 ++++++++++++++++++- firmware/projects/Demo/CANErrors/main.cc | 14 ++- .../Demo/CANErrors/platforms/cli/bindings.cc | 30 ------ 3 files changed, 105 insertions(+), 38 deletions(-) diff --git a/firmware/projects/Demo/CANErrors/bindings.h b/firmware/projects/Demo/CANErrors/bindings.h index 9d3868805..a774200b2 100644 --- a/firmware/projects/Demo/CANErrors/bindings.h +++ b/firmware/projects/Demo/CANErrors/bindings.h @@ -8,12 +8,101 @@ namespace bindings { extern void Initialize(); extern void TickBlocking(uint32_t); - class Errors { + // Interface to set/send all possible errors for the system + class ErrorHandler { private: + // Object that holds a 64 bit int, each bit representing an error generated::can::TMS_ERROR error_msg{}; public: - void setError(uint32_t error); - void sendError(shared::can::CanBus error_can_bus); - void resetError(); + // Sets the error based on the error index given + void setError(uint32_t error) { + if (error < 0 || error > 63) { + std::cerr << "Error index must be between 0 and 63!" << std::endl; + return; + } + + error_msg.errors |= (1ULL << error); + } + + // Sends the error message through the provided CAN bus + void sendError(shared::can::CanBus error_can_bus) { + error_can_bus.Send(error_msg); + + // Reset after a send to not send duplicate errors + resetError(); + } + + // Resets all errors back to untriggered + void resetError() { + error_msg.errors = 0; + } + }; + + // Defines all possible errors to set + enum Error { + Error0 = 0, + Error1 = 1, + Error2 = 2, + Error3 = 3, + Error4 = 4, + Error5 = 5, + Error6 = 6, + Error7 = 7, + Error8 = 8, + Error9 = 9, + Error10 = 10, + Error11 = 11, + Error12 = 12, + Error13 = 13, + Error14 = 14, + Error15 = 15, + Error16 = 16, + Error17 = 17, + Error18 = 18, + Error19 = 19, + Error20 = 20, + Error21 = 21, + Error22 = 22, + Error23 = 23, + Error24 = 24, + Error25 = 25, + Error26 = 26, + Error27 = 27, + Error28 = 28, + Error29 = 29, + Error30 = 30, + Error31 = 31, + Error32 = 32, + Error33 = 33, + Error34 = 34, + Error35 = 35, + Error36 = 36, + Error37 = 37, + Error38 = 38, + Error39 = 39, + Error40 = 40, + Error41 = 41, + Error42 = 42, + Error43 = 43, + Error44 = 44, + Error45 = 45, + Error46 = 46, + Error47 = 47, + Error48 = 48, + Error49 = 49, + Error50 = 50, + Error51 = 51, + Error52 = 52, + Error53 = 53, + Error54 = 54, + Error55 = 55, + Error56 = 56, + Error57 = 57, + Error58 = 58, + Error59 = 59, + Error60 = 60, + Error61 = 61, + Error62 = 62, + Error63 = 63 }; -} \ No newline at end of file +} // namespace bindings \ No newline at end of file diff --git a/firmware/projects/Demo/CANErrors/main.cc b/firmware/projects/Demo/CANErrors/main.cc index 69933b8c5..b62ad0616 100644 --- a/firmware/projects/Demo/CANErrors/main.cc +++ b/firmware/projects/Demo/CANErrors/main.cc @@ -19,17 +19,25 @@ int main(void) { uint32_t tick_duration = 100; // Initialize the error object that sets/sends each error - bindings::Errors error_msg{}; + bindings::ErrorHandler error_msg{}; while (true) { error_can_bus.Update(); // Iterate through each error, setting it and sending it for (int i = 0; i < 63; i++) { - // error_msg.setError(i); - // error_msg.sendError(error_can_bus); + error_msg.setError(i); + error_msg.sendError(error_can_bus); } + // Set random errors using the enum + error_msg.setError(bindings::Error0); + error_msg.setError(bindings::Error5); + error_msg.setError(bindings::Error10); + error_msg.setError(bindings::Error15); + error_msg.setError(bindings::Error20); + error_msg.sendError(error_can_bus); + // Wait for 100ms before repeating the process bindings::TickBlocking(tick_duration); } diff --git a/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc b/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc index e401fe541..53df07dd2 100644 --- a/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc +++ b/firmware/projects/Demo/CANErrors/platforms/cli/bindings.cc @@ -31,34 +31,4 @@ namespace bindings { mcal::error_can_base.Setup(); std::cout << "Initializing CLI..." << std::endl; } - - // Interface to set/send all possible errors for the system - class Errors { - private: - // Object that holds a 64 bit int, each bit representing an error - generated::can::TMS_ERROR error_msg{}; - public: - // Sets the error based on the error index given - void setError(uint32_t error) { - if (error < 0 || error > 63) { - std::cerr << "Error index must be between 0 and 63!" << std::endl; - return; - } - - error_msg.errors |= (1ULL << error); - } - - // Sends the error message through the provided CAN bus - void sendError(shared::can::CanBus error_can_bus) { - error_can_bus.Send(error_msg); - - // Reset after a send to not send duplicate errors - resetError(); - } - - // Resets all errors back to untriggered - void resetError() { - error_msg.errors = 0; - } - }; } \ No newline at end of file From 89ca802c06c4aefb74413926ce4b2981a4d4f092 Mon Sep 17 00:00:00 2001 From: luaibash Date: Sun, 10 Nov 2024 19:12:35 -0500 Subject: [PATCH 09/15] Removed changes for foo/bar config files --- firmware/projects/Demo/CAN/Bar/config.yaml | 3 ++- firmware/projects/Demo/CAN/Foo/config.yaml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/firmware/projects/Demo/CAN/Bar/config.yaml b/firmware/projects/Demo/CAN/Bar/config.yaml index 0aab1cb92..2599bb986 100644 --- a/firmware/projects/Demo/CAN/Bar/config.yaml +++ b/firmware/projects/Demo/CAN/Bar/config.yaml @@ -2,4 +2,5 @@ canGen: busses: - name: veh node: bar - dbcFile: "../demo.dbc" + dbcFiles: + - "../demo.dbc" diff --git a/firmware/projects/Demo/CAN/Foo/config.yaml b/firmware/projects/Demo/CAN/Foo/config.yaml index 91fb7387a..d58dd5f28 100644 --- a/firmware/projects/Demo/CAN/Foo/config.yaml +++ b/firmware/projects/Demo/CAN/Foo/config.yaml @@ -2,4 +2,5 @@ canGen: busses: - name: veh node: foo - dbcFile: "../demo.dbc" \ No newline at end of file + dbcFile: + - "../demo.dbc" \ No newline at end of file From deb1eb7e5f314b21995583552eeac7621a74e3bc Mon Sep 17 00:00:00 2001 From: luaibash Date: Sun, 10 Nov 2024 19:13:22 -0500 Subject: [PATCH 10/15] fixed foo config file --- firmware/projects/Demo/CAN/Foo/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/projects/Demo/CAN/Foo/config.yaml b/firmware/projects/Demo/CAN/Foo/config.yaml index d58dd5f28..4ef5a0ddc 100644 --- a/firmware/projects/Demo/CAN/Foo/config.yaml +++ b/firmware/projects/Demo/CAN/Foo/config.yaml @@ -2,5 +2,5 @@ canGen: busses: - name: veh node: foo - dbcFile: + dbcFiles: - "../demo.dbc" \ No newline at end of file From e741081cc1e911039cd7c9a7654c9974578ef7bc Mon Sep 17 00:00:00 2001 From: luaibash Date: Sun, 10 Nov 2024 19:32:47 -0500 Subject: [PATCH 11/15] Moved error class/enum to app.h file --- firmware/projects/Demo/CANErrors/bindings.h | 99 ------------------ firmware/projects/Demo/CANErrors/inc/app.h | 110 ++++++++++++++++++++ firmware/projects/Demo/CANErrors/main.cc | 18 ++-- 3 files changed, 120 insertions(+), 107 deletions(-) create mode 100644 firmware/projects/Demo/CANErrors/inc/app.h diff --git a/firmware/projects/Demo/CANErrors/bindings.h b/firmware/projects/Demo/CANErrors/bindings.h index a774200b2..f3ad02d53 100644 --- a/firmware/projects/Demo/CANErrors/bindings.h +++ b/firmware/projects/Demo/CANErrors/bindings.h @@ -1,108 +1,9 @@ #pragma once #include "shared/comms/can/can_bus.h" -#include "generated/can/error_can_messages.h" namespace bindings { extern shared::periph::CanBase& error_can_base; extern void Initialize(); extern void TickBlocking(uint32_t); - - // Interface to set/send all possible errors for the system - class ErrorHandler { - private: - // Object that holds a 64 bit int, each bit representing an error - generated::can::TMS_ERROR error_msg{}; - public: - // Sets the error based on the error index given - void setError(uint32_t error) { - if (error < 0 || error > 63) { - std::cerr << "Error index must be between 0 and 63!" << std::endl; - return; - } - - error_msg.errors |= (1ULL << error); - } - - // Sends the error message through the provided CAN bus - void sendError(shared::can::CanBus error_can_bus) { - error_can_bus.Send(error_msg); - - // Reset after a send to not send duplicate errors - resetError(); - } - - // Resets all errors back to untriggered - void resetError() { - error_msg.errors = 0; - } - }; - - // Defines all possible errors to set - enum Error { - Error0 = 0, - Error1 = 1, - Error2 = 2, - Error3 = 3, - Error4 = 4, - Error5 = 5, - Error6 = 6, - Error7 = 7, - Error8 = 8, - Error9 = 9, - Error10 = 10, - Error11 = 11, - Error12 = 12, - Error13 = 13, - Error14 = 14, - Error15 = 15, - Error16 = 16, - Error17 = 17, - Error18 = 18, - Error19 = 19, - Error20 = 20, - Error21 = 21, - Error22 = 22, - Error23 = 23, - Error24 = 24, - Error25 = 25, - Error26 = 26, - Error27 = 27, - Error28 = 28, - Error29 = 29, - Error30 = 30, - Error31 = 31, - Error32 = 32, - Error33 = 33, - Error34 = 34, - Error35 = 35, - Error36 = 36, - Error37 = 37, - Error38 = 38, - Error39 = 39, - Error40 = 40, - Error41 = 41, - Error42 = 42, - Error43 = 43, - Error44 = 44, - Error45 = 45, - Error46 = 46, - Error47 = 47, - Error48 = 48, - Error49 = 49, - Error50 = 50, - Error51 = 51, - Error52 = 52, - Error53 = 53, - Error54 = 54, - Error55 = 55, - Error56 = 56, - Error57 = 57, - Error58 = 58, - Error59 = 59, - Error60 = 60, - Error61 = 61, - Error62 = 62, - Error63 = 63 - }; } // namespace bindings \ No newline at end of file diff --git a/firmware/projects/Demo/CANErrors/inc/app.h b/firmware/projects/Demo/CANErrors/inc/app.h new file mode 100644 index 000000000..e39668a7f --- /dev/null +++ b/firmware/projects/Demo/CANErrors/inc/app.h @@ -0,0 +1,110 @@ +/// @author Luai Bashar +/// @date 2024-11-10 +/// @brief Functions and types that will be used in CANErrors main + +#pragma once + +#include "../generated/can/error_can_messages.h" +#include "shared/comms/can/can_bus.h" + +/*************************************************************** + App-level objects +***************************************************************/ + +// Interface to set/send all possible errors for the system +class ErrorHandler { + private: + // Object that holds a 64 bit int, each bit representing an error + generated::can::TMS_ERROR error_msg{}; + public: + // Sets the error based on the error index given + void setError(uint32_t error) { + if (error < 0 || error > 63) { + std::cerr << "Error index must be between 0 and 63!" << std::endl; + return; + } + + error_msg.errors |= (1ULL << error); + } + + // Sends the error message through the provided CAN bus + void sendError(shared::can::CanBus error_can_bus) { + error_can_bus.Send(error_msg); + + // Reset after a send to not send duplicate errors + resetError(); + } + + // Resets all errors back to untriggered + void resetError() { + error_msg.errors = 0; + } +}; + +// Defines all possible errors to set +enum Error { + Error0 = 0, + Error1 = 1, + Error2 = 2, + Error3 = 3, + Error4 = 4, + Error5 = 5, + Error6 = 6, + Error7 = 7, + Error8 = 8, + Error9 = 9, + Error10 = 10, + Error11 = 11, + Error12 = 12, + Error13 = 13, + Error14 = 14, + Error15 = 15, + Error16 = 16, + Error17 = 17, + Error18 = 18, + Error19 = 19, + Error20 = 20, + Error21 = 21, + Error22 = 22, + Error23 = 23, + Error24 = 24, + Error25 = 25, + Error26 = 26, + Error27 = 27, + Error28 = 28, + Error29 = 29, + Error30 = 30, + Error31 = 31, + Error32 = 32, + Error33 = 33, + Error34 = 34, + Error35 = 35, + Error36 = 36, + Error37 = 37, + Error38 = 38, + Error39 = 39, + Error40 = 40, + Error41 = 41, + Error42 = 42, + Error43 = 43, + Error44 = 44, + Error45 = 45, + Error46 = 46, + Error47 = 47, + Error48 = 48, + Error49 = 49, + Error50 = 50, + Error51 = 51, + Error52 = 52, + Error53 = 53, + Error54 = 54, + Error55 = 55, + Error56 = 56, + Error57 = 57, + Error58 = 58, + Error59 = 59, + Error60 = 60, + Error61 = 61, + Error62 = 62, + Error63 = 63 +}; \ No newline at end of file diff --git a/firmware/projects/Demo/CANErrors/main.cc b/firmware/projects/Demo/CANErrors/main.cc index b62ad0616..71cd1a4b6 100644 --- a/firmware/projects/Demo/CANErrors/main.cc +++ b/firmware/projects/Demo/CANErrors/main.cc @@ -2,6 +2,8 @@ /// @date 2024-11-05 #include + +#include "app.h" #include "bindings.h" #include "shared/comms/can/can_bus.h" #include "generated/can/error_msg_registry.h" @@ -19,23 +21,23 @@ int main(void) { uint32_t tick_duration = 100; // Initialize the error object that sets/sends each error - bindings::ErrorHandler error_msg{}; + ErrorHandler error_msg{}; while (true) { error_can_bus.Update(); - // Iterate through each error, setting it and sending it + // Test #1: Iterate through each error, setting it and sending it for (int i = 0; i < 63; i++) { error_msg.setError(i); error_msg.sendError(error_can_bus); } - // Set random errors using the enum - error_msg.setError(bindings::Error0); - error_msg.setError(bindings::Error5); - error_msg.setError(bindings::Error10); - error_msg.setError(bindings::Error15); - error_msg.setError(bindings::Error20); + // Test #2: Set random errors using the enum + error_msg.setError(Error0); + error_msg.setError(Error5); + error_msg.setError(Error10); + error_msg.setError(Error15); + error_msg.setError(Error20); error_msg.sendError(error_can_bus); // Wait for 100ms before repeating the process From 016baebde0675e7a2a6fa65e600bc34eab1c0d8a Mon Sep 17 00:00:00 2001 From: luaibash Date: Mon, 11 Nov 2024 16:55:55 -0500 Subject: [PATCH 12/15] Removed NS section of dbc file, and added more content to readme --- firmware/projects/Demo/CANErrors/README.md | 33 +++++++++++++++++---- firmware/projects/Demo/CANErrors/errors.dbc | 30 ------------------- 2 files changed, 28 insertions(+), 35 deletions(-) diff --git a/firmware/projects/Demo/CANErrors/README.md b/firmware/projects/Demo/CANErrors/README.md index 6eb6a613b..be2c6f1c0 100644 --- a/firmware/projects/Demo/CANErrors/README.md +++ b/firmware/projects/Demo/CANErrors/README.md @@ -1,13 +1,36 @@ # CANErrors +This is the CAN Errors demo project. It defines a global system for the vehicle to send/receive errors through different subsystems. It defines: +- A 64 bit CAN error signal. Each bit represents a different error, and will be sent periodically for other systems to know if an error has occurred +- The `ErrorHandler` class, an interface to set/send different errors on the CAN signal +- Enum `Error` that defines all 64 possible errors to send through the CAN signal -This is the CAN Errors demo project. This defines the mechanism for reporting errors from the vehicle microcontrollers. This project will send errors over the CAN line and process them on a host machine. +
-## Generating The DBC Code -- Code must be generated using CanGen. Install CanGen in the racecar directory with "pip install -e scripts/cangen" - - A venv isn't needed for this! -- Generate the code in the firmware directory with "cangen projects/Demo/CANErrors" +## How to use `ErrorHandler` + +### Defining an instance of ErrorHandler: +``` +ErrorHandler error_handler{}; +``` + +### Setting errors with ErrorHandler: +- `setError` takes an error from the `Error` enum and sets it +``` +error_handler.setError(Error0); +error_handler.setError(Error15); +error_handler.setError(Error48); +``` + +### Sending errors with ErrorHandler: +- `sendError` takes a CAN bus and sends the errors through that bus. It resets the errors to send the next set of errors +``` +error_handler.sendError(error_can_bus); +``` + +
## Building the Project - To build the project, run the following in the firmware directory "make PROJECT=Demo/CANErrors PLATFORM=cli" - This should create a build file with no errors! + - This will also generate the dbc files automatically, but if you want to generate them seperately, run "cangen projects/Demo/CANErrors" - To execute the new build, run "./build/Demo/CANErrors/cli/main.exe" \ No newline at end of file diff --git a/firmware/projects/Demo/CANErrors/errors.dbc b/firmware/projects/Demo/CANErrors/errors.dbc index 3d62ecb93..ba63efdf1 100644 --- a/firmware/projects/Demo/CANErrors/errors.dbc +++ b/firmware/projects/Demo/CANErrors/errors.dbc @@ -1,35 +1,5 @@ VERSION "" -NS_ : - NS_DESC_ - CM_ - BA_DEF_ - BA_ - VAL_ - CAT_DEF_ - CAT_ - FILTER - BA_DEF_DEF_ - EV_DATA_ - ENVVAR_DATA_ - SGTYPE_ - SGTYPE_VAL_ - BA_DEF_SGTYPE_ - BA_SGTYPE_ - SIG_TYPE_REF_ - VAL_TABLE_ - SIG_GROUP_ - SIG_VALTYPE_ - SIGTYPE_VALTYPE_ - BO_TX_BU_ - BA_DEF_REL_ - BA_REL_ - BA_DEF_DEF_REL_ - BU_SG_REL_ - BU_EV_REL_ - BU_BO_REL_ - SG_MUL_VAL_ - BS_: BU_: TMS From db1ece3cd34462bb4b1d10abffb2942b8bf2e95d Mon Sep 17 00:00:00 2001 From: luaibash Date: Mon, 11 Nov 2024 17:27:03 -0500 Subject: [PATCH 13/15] Cleaned up ErrorHandler and main file --- firmware/projects/Demo/CANErrors/inc/app.h | 60 +++++++++++----------- firmware/projects/Demo/CANErrors/main.cc | 21 ++++---- 2 files changed, 41 insertions(+), 40 deletions(-) diff --git a/firmware/projects/Demo/CANErrors/inc/app.h b/firmware/projects/Demo/CANErrors/inc/app.h index e39668a7f..25a50b983 100644 --- a/firmware/projects/Demo/CANErrors/inc/app.h +++ b/firmware/projects/Demo/CANErrors/inc/app.h @@ -11,36 +11,6 @@ App-level objects ***************************************************************/ -// Interface to set/send all possible errors for the system -class ErrorHandler { - private: - // Object that holds a 64 bit int, each bit representing an error - generated::can::TMS_ERROR error_msg{}; - public: - // Sets the error based on the error index given - void setError(uint32_t error) { - if (error < 0 || error > 63) { - std::cerr << "Error index must be between 0 and 63!" << std::endl; - return; - } - - error_msg.errors |= (1ULL << error); - } - - // Sends the error message through the provided CAN bus - void sendError(shared::can::CanBus error_can_bus) { - error_can_bus.Send(error_msg); - - // Reset after a send to not send duplicate errors - resetError(); - } - - // Resets all errors back to untriggered - void resetError() { - error_msg.errors = 0; - } -}; - // Defines all possible errors to set enum Error { Error0 = 0, @@ -107,4 +77,34 @@ enum Error { Error61 = 61, Error62 = 62, Error63 = 63 +}; + +// Interface to set/send all possible errors for the system +class ErrorHandler { + private: + // Object that holds a 64 bit int, each bit representing an error + generated::can::TMS_ERROR error_message{}; + + // Resets all errors back to untriggered + void resetError() { + error_message.errors = 0; + } + public: + // Sets the error based on the error index given + void setError(Error error) { + if (error < 0 || error > 63) { + std::cerr << "Error index must be between 0 and 63!" << std::endl; + return; + } + + error_message.errors |= (1ULL << error); + } + + // Sends the error message through the provided CAN bus + void sendError(shared::can::CanBus error_can_bus) { + error_can_bus.Send(error_message); + + // Reset after a send to not send duplicate errors + resetError(); + } }; \ No newline at end of file diff --git a/firmware/projects/Demo/CANErrors/main.cc b/firmware/projects/Demo/CANErrors/main.cc index 71cd1a4b6..0a7d0b6b0 100644 --- a/firmware/projects/Demo/CANErrors/main.cc +++ b/firmware/projects/Demo/CANErrors/main.cc @@ -21,24 +21,25 @@ int main(void) { uint32_t tick_duration = 100; // Initialize the error object that sets/sends each error - ErrorHandler error_msg{}; + ErrorHandler error_message{}; while (true) { error_can_bus.Update(); // Test #1: Iterate through each error, setting it and sending it - for (int i = 0; i < 63; i++) { - error_msg.setError(i); - error_msg.sendError(error_can_bus); + for (int i = 0; i < 64; i++) { + Error error = static_cast(i); + error_message.setError(error); + error_message.sendError(error_can_bus); } // Test #2: Set random errors using the enum - error_msg.setError(Error0); - error_msg.setError(Error5); - error_msg.setError(Error10); - error_msg.setError(Error15); - error_msg.setError(Error20); - error_msg.sendError(error_can_bus); + error_message.setError(Error0); + error_message.setError(Error5); + error_message.setError(Error10); + error_message.setError(Error15); + error_message.setError(Error20); + error_message.sendError(error_can_bus); // Wait for 100ms before repeating the process bindings::TickBlocking(tick_duration); From 81c69b4f7c52d61bff25f1518b4f6253e17a593b Mon Sep 17 00:00:00 2001 From: luaibash Date: Mon, 11 Nov 2024 22:33:10 -0500 Subject: [PATCH 14/15] Modified dbc file to create unsigned int --- firmware/projects/Demo/CANErrors/errors.dbc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/projects/Demo/CANErrors/errors.dbc b/firmware/projects/Demo/CANErrors/errors.dbc index ba63efdf1..194bed25b 100644 --- a/firmware/projects/Demo/CANErrors/errors.dbc +++ b/firmware/projects/Demo/CANErrors/errors.dbc @@ -6,4 +6,4 @@ BU_: TMS // Defines one 64 bit signal where each bit represents a different error BO_ 390 TMS_ERROR: 8 TMS - SG_ Errors : 0|64@1- (1,0) [0|0] "bitfield" Vector__XXX \ No newline at end of file + SG_ Errors : 0|64@1+ (1,0) [0|0] "bitfield" Vector__XXX \ No newline at end of file From b8efff7e635f48b3b8d99c4fd64aa03031f780df Mon Sep 17 00:00:00 2001 From: luaibash Date: Mon, 11 Nov 2024 22:33:39 -0500 Subject: [PATCH 15/15] Refactored app.h to follow naming conventions/best practices, and switch the enum to an enum class --- firmware/projects/Demo/CANErrors/README.md | 22 ++- firmware/projects/Demo/CANErrors/inc/app.h | 163 ++++++++++----------- firmware/projects/Demo/CANErrors/main.cc | 16 +- 3 files changed, 97 insertions(+), 104 deletions(-) diff --git a/firmware/projects/Demo/CANErrors/README.md b/firmware/projects/Demo/CANErrors/README.md index be2c6f1c0..a66db442c 100644 --- a/firmware/projects/Demo/CANErrors/README.md +++ b/firmware/projects/Demo/CANErrors/README.md @@ -4,8 +4,6 @@ This is the CAN Errors demo project. It defines a global system for the vehicle - The `ErrorHandler` class, an interface to set/send different errors on the CAN signal - Enum `Error` that defines all 64 possible errors to send through the CAN signal -
- ## How to use `ErrorHandler` ### Defining an instance of ErrorHandler: @@ -14,23 +12,21 @@ ErrorHandler error_handler{}; ``` ### Setting errors with ErrorHandler: -- `setError` takes an error from the `Error` enum and sets it +- `SetError` takes an error from the `Error` enum and sets it ``` -error_handler.setError(Error0); -error_handler.setError(Error15); -error_handler.setError(Error48); +error_handler.SetError(Error0); +error_handler.SetError(Error15); +error_handler.SetError(Error48); ``` ### Sending errors with ErrorHandler: -- `sendError` takes a CAN bus and sends the errors through that bus. It resets the errors to send the next set of errors +- `SendError` takes a CAN bus and sends the errors through that bus. It resets the errors to send the next set of errors ``` -error_handler.sendError(error_can_bus); +error_handler.SendError(error_can_bus); ``` -
- ## Building the Project -- To build the project, run the following in the firmware directory "make PROJECT=Demo/CANErrors PLATFORM=cli" +- To build the project, run the following in the firmware directory `make PROJECT=Demo/CANErrors PLATFORM=cli` - This should create a build file with no errors! - - This will also generate the dbc files automatically, but if you want to generate them seperately, run "cangen projects/Demo/CANErrors" -- To execute the new build, run "./build/Demo/CANErrors/cli/main.exe" \ No newline at end of file + - This will also generate the dbc files automatically, but if you want to generate them seperately, run `cangen projects/Demo/CANErrors` +- To execute the new build, run `./build/Demo/CANErrors/cli/main.exe` \ No newline at end of file diff --git a/firmware/projects/Demo/CANErrors/inc/app.h b/firmware/projects/Demo/CANErrors/inc/app.h index 25a50b983..673342fd6 100644 --- a/firmware/projects/Demo/CANErrors/inc/app.h +++ b/firmware/projects/Demo/CANErrors/inc/app.h @@ -12,99 +12,96 @@ ***************************************************************/ // Defines all possible errors to set -enum Error { - Error0 = 0, - Error1 = 1, - Error2 = 2, - Error3 = 3, - Error4 = 4, - Error5 = 5, - Error6 = 6, - Error7 = 7, - Error8 = 8, - Error9 = 9, - Error10 = 10, - Error11 = 11, - Error12 = 12, - Error13 = 13, - Error14 = 14, - Error15 = 15, - Error16 = 16, - Error17 = 17, - Error18 = 18, - Error19 = 19, - Error20 = 20, - Error21 = 21, - Error22 = 22, - Error23 = 23, - Error24 = 24, - Error25 = 25, - Error26 = 26, - Error27 = 27, - Error28 = 28, - Error29 = 29, - Error30 = 30, - Error31 = 31, - Error32 = 32, - Error33 = 33, - Error34 = 34, - Error35 = 35, - Error36 = 36, - Error37 = 37, - Error38 = 38, - Error39 = 39, - Error40 = 40, - Error41 = 41, - Error42 = 42, - Error43 = 43, - Error44 = 44, - Error45 = 45, - Error46 = 46, - Error47 = 47, - Error48 = 48, - Error49 = 49, - Error50 = 50, - Error51 = 51, - Error52 = 52, - Error53 = 53, - Error54 = 54, - Error55 = 55, - Error56 = 56, - Error57 = 57, - Error58 = 58, - Error59 = 59, - Error60 = 60, - Error61 = 61, - Error62 = 62, - Error63 = 63 +enum class Error { + kError0 = 0, + kError1 = 1, + kError2 = 2, + kError3 = 3, + kError4 = 4, + kError5 = 5, + kError6 = 6, + kError7 = 7, + kError8 = 8, + kError9 = 9, + kError10 = 10, + kError11 = 11, + kError12 = 12, + kError13 = 13, + kError14 = 14, + kError15 = 15, + kError16 = 16, + kError17 = 17, + kError18 = 18, + kError19 = 19, + kError20 = 20, + kError21 = 21, + kError22 = 22, + kError23 = 23, + kError24 = 24, + kError25 = 25, + kError26 = 26, + kError27 = 27, + kError28 = 28, + kError29 = 29, + kError30 = 30, + kError31 = 31, + kError32 = 32, + kError33 = 33, + kError34 = 34, + kError35 = 35, + kError36 = 36, + kError37 = 37, + kError38 = 38, + kError39 = 39, + kError40 = 40, + kError41 = 41, + kError42 = 42, + kError43 = 43, + kError44 = 44, + kError45 = 45, + kError46 = 46, + kError47 = 47, + kError48 = 48, + kError49 = 49, + kError50 = 50, + kError51 = 51, + kError52 = 52, + kError53 = 53, + kError54 = 54, + kError55 = 55, + kError56 = 56, + kError57 = 57, + kError58 = 58, + kError59 = 59, + kError60 = 60, + kError61 = 61, + kError62 = 62, + kError63 = 63 }; // Interface to set/send all possible errors for the system class ErrorHandler { - private: - // Object that holds a 64 bit int, each bit representing an error - generated::can::TMS_ERROR error_message{}; - - // Resets all errors back to untriggered - void resetError() { - error_message.errors = 0; - } public: // Sets the error based on the error index given - void setError(Error error) { - if (error < 0 || error > 63) { - std::cerr << "Error index must be between 0 and 63!" << std::endl; - return; - } - - error_message.errors |= (1ULL << error); + void SetError(Error error) { + uint64_t error_index = static_cast(error); + error_message_.errors |= (1ULL << error_index); } // Sends the error message through the provided CAN bus - void sendError(shared::can::CanBus error_can_bus) { - error_can_bus.Send(error_message); + // TODO: Error message is only for a specific bus, change this when autogen code is created + void SendError(shared::can::CanBus error_can_bus) { + error_can_bus.Send(error_message_); // Reset after a send to not send duplicate errors - resetError(); + ResetError(); + } + private: + // Object that holds a 64 bit int, each bit representing an error + generated::can::TMS_ERROR error_message_{}; + + // Resets all errors back to untriggered + void ResetError() { + error_message_.errors = 0; } }; \ No newline at end of file diff --git a/firmware/projects/Demo/CANErrors/main.cc b/firmware/projects/Demo/CANErrors/main.cc index 0a7d0b6b0..3fd35ffc3 100644 --- a/firmware/projects/Demo/CANErrors/main.cc +++ b/firmware/projects/Demo/CANErrors/main.cc @@ -29,17 +29,17 @@ int main(void) { // Test #1: Iterate through each error, setting it and sending it for (int i = 0; i < 64; i++) { Error error = static_cast(i); - error_message.setError(error); - error_message.sendError(error_can_bus); + error_message.SetError(error); + error_message.SendError(error_can_bus); } // Test #2: Set random errors using the enum - error_message.setError(Error0); - error_message.setError(Error5); - error_message.setError(Error10); - error_message.setError(Error15); - error_message.setError(Error20); - error_message.sendError(error_can_bus); + error_message.SetError(Error::kError0); + error_message.SetError(Error::kError5); + error_message.SetError(Error::kError10); + error_message.SetError(Error::kError15); + error_message.SetError(Error::kError20); + error_message.SendError(error_can_bus); // Wait for 100ms before repeating the process bindings::TickBlocking(tick_duration);