From 5fdcb8742e803feae0a685a2dba6697affd4833a Mon Sep 17 00:00:00 2001 From: samparent97 Date: Tue, 30 Apr 2024 14:28:51 -0300 Subject: [PATCH] Remove all build warnings --- firmware/projects/TMS/main.cc | 7 +++++-- firmware/shared/util/algorithms/arrays.h | 13 +++++++------ scripts/cangen/templates/can_messages.h.jinja2 | 10 +++++----- scripts/cangen/templates/msg_registry.h.jinja2 | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/firmware/projects/TMS/main.cc b/firmware/projects/TMS/main.cc index 054744b5d..358a08f9b 100644 --- a/firmware/projects/TMS/main.cc +++ b/firmware/projects/TMS/main.cc @@ -1,6 +1,8 @@ /// @author Blake Freer /// @date 2023-11-18 +#include + #include #include @@ -154,8 +156,9 @@ void Update() { float temp_avg = shared::util::GetAverage(temperature_buffer); - bms_broadcaster.SendBmsBroadcast(high_thermistor_idx, temp_max, - low_thermistor_idx, temp_min, temp_avg); + bms_broadcaster.SendBmsBroadcast( + high_thermistor_idx, static_cast(temp_max), low_thermistor_idx, + static_cast(temp_min), static_cast(temp_avg)); fan_controller.Update(temp_avg); } diff --git a/firmware/shared/util/algorithms/arrays.h b/firmware/shared/util/algorithms/arrays.h index 03cda7a62..e63a398a7 100644 --- a/firmware/shared/util/algorithms/arrays.h +++ b/firmware/shared/util/algorithms/arrays.h @@ -3,6 +3,7 @@ #pragma once +#include #include #include @@ -22,13 +23,13 @@ concept Numeric = requires { std::is_arithmetic_v; }; /// @return Minimum value of the array. /// @note Returns a large value if `array_length = 0`. template - requires(array_length >= 0) + requires(array_length >= 0, array_length < std::numeric_limits::max()) T GetMinimum(T* array, I* idx_min) { // start minimum at greatest value T cur_min = std::numeric_limits().max(); - int temp_idx_min = -1; + I temp_idx_min = -1; - for (int i = 0; i < array_length; i++) { + for (I i = 0; i < array_length; i++) { if (array[i] < cur_min) { cur_min = array[i]; temp_idx_min = i; @@ -53,13 +54,13 @@ T GetMinimum(T* array, I* idx_min) { /// @return Maximum value of the array. /// @note Returns a low value if `array_length = 0`. template - requires(array_length >= 0) + requires(array_length >= 0, array_length < std::numeric_limits::max()) T GetMaximum(T* array, I* idx_max) { // start maximum at lowest value T cur_max = std::numeric_limits().min(); - int temp_idx_max = -1; + I temp_idx_max = -1; - for (int i = 0; i < array_length; i++) { + for (I i = 0; i < array_length; i++) { if (array[i] > cur_max) { cur_max = array[i]; temp_idx_max = i; diff --git a/scripts/cangen/templates/can_messages.h.jinja2 b/scripts/cangen/templates/can_messages.h.jinja2 index e5cff06e9..fd46d5038 100644 --- a/scripts/cangen/templates/can_messages.h.jinja2 +++ b/scripts/cangen/templates/can_messages.h.jinja2 @@ -40,8 +40,8 @@ private: {% for sig in msg.signals %} {% set sig_var = sig.name | camel_to_snake %} {% set sig_var_type = signal_types[msg.name][sig.name] %} - static constexpr {{ sig_var_type }} k{{ sig.name }}Scale = {{ sig.scale }}; - static constexpr {{ sig_var_type }} k{{ sig.name }}Offset = {{ sig.offset }}; + static constexpr double k{{ sig.name }}Scale = {{ sig.scale }}; + static constexpr double k{{ sig.name }}Offset = {{ sig.offset }}; {% endfor %} shared::can::CanId Id() const override { return kCanId; } @@ -114,8 +114,8 @@ private: {% for sig in msg.signals %} {% set sig_var = sig.name | camel_to_snake %} {% set sig_var_type = signal_types[msg.name][sig.name] %} - static constexpr {{ sig_var_type }} k{{ sig.name }}Scale = {{ sig.scale }}; - static constexpr {{ sig_var_type }} k{{ sig.name }}Offset = {{ sig.offset }}; + static constexpr double k{{ sig.name }}Scale = {{ sig.scale }}; + static constexpr double k{{ sig.name }}Offset = {{ sig.offset }}; {% endfor %} void Pack(shared::can::RawCanMsg& raw_msg) const override { @@ -134,7 +134,7 @@ private: {% set sig_var_offset = "k" + sig.name + "Offset" %} {% set temp_sig_var = "temp_" + (sig.name | camel_to_snake) %} {% set temp_sig_var_type = temp_signal_types[msg.name][sig.name] %} - {{ temp_sig_var_type }} {{ temp_sig_var }} = static_cast<{{ temp_sig_var_type }}>(static_cast({{ sig_var }} - {{ sig_var_offset }}) / static_cast({{ sig_var_scale }})); + {{ temp_sig_var_type }} {{ temp_sig_var }} = static_cast<{{ temp_sig_var_type }}>(static_cast({{ sig_var }} - {{ sig_var_offset }}) / {{ sig_var_scale }}); {% endfor %} {% for sig in msg.signals %} diff --git a/scripts/cangen/templates/msg_registry.h.jinja2 b/scripts/cangen/templates/msg_registry.h.jinja2 index 89de6403d..6985b824b 100644 --- a/scripts/cangen/templates/msg_registry.h.jinja2 +++ b/scripts/cangen/templates/msg_registry.h.jinja2 @@ -14,6 +14,20 @@ namespace generated::can { {% set reg_class_name = bus_name + "MsgRegistry" %} + +{% if rx_msgs | length == 0 %} +// Dummy class - there are no rx messages for this ecu. +class {{ reg_class_name }} : public shared::can::MsgRegistry { +public: + bool SetMessage(const shared::can::RawCanMsg& raw_msg) override { + return false; + } + + bool GetMessage(shared::can::CanRxMsg& rx_msg) override { + return false; + } +}; +{% else %} class {{ reg_class_name }} : public shared::can::MsgRegistry { public: bool SetMessage(const shared::can::RawCanMsg& raw_msg) override { @@ -66,5 +80,6 @@ private: {% endfor %} }; }; +{% endif %} } // namespace generated::can \ No newline at end of file