Skip to content

Commit

Permalink
Remove all build warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
samparent97 committed Apr 30, 2024
1 parent dc8e164 commit 5fdcb87
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
7 changes: 5 additions & 2 deletions firmware/projects/TMS/main.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/// @author Blake Freer
/// @date 2023-11-18

#include <sys/_stdint.h>

#include <cstdint>
#include <string>

Expand Down Expand Up @@ -154,8 +156,9 @@ void Update() {
float temp_avg =
shared::util::GetAverage<float, kSensorCount>(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<int8_t>(temp_max), low_thermistor_idx,
static_cast<int8_t>(temp_min), static_cast<int8_t>(temp_avg));

fan_controller.Update(temp_avg);
}
Expand Down
13 changes: 7 additions & 6 deletions firmware/shared/util/algorithms/arrays.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#pragma once

#include <algorithm>
#include <concepts>
#include <limits>

Expand All @@ -22,13 +23,13 @@ concept Numeric = requires { std::is_arithmetic_v<T>; };
/// @return Minimum value of the array.
/// @note Returns a large value if `array_length = 0`.
template <Numeric T, int array_length, Numeric I>
requires(array_length >= 0)
requires(array_length >= 0, array_length < std::numeric_limits<I>::max())
T GetMinimum(T* array, I* idx_min) {
// start minimum at greatest value
T cur_min = std::numeric_limits<T>().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;
Expand All @@ -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 <Numeric T, int array_length, Numeric I>
requires(array_length >= 0)
requires(array_length >= 0, array_length < std::numeric_limits<I>::max())
T GetMaximum(T* array, I* idx_max) {
// start maximum at lowest value
T cur_max = std::numeric_limits<T>().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;
Expand Down
10 changes: 5 additions & 5 deletions scripts/cangen/templates/can_messages.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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 {
Expand All @@ -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<double>({{ sig_var }} - {{ sig_var_offset }}) / static_cast<double>({{ sig_var_scale }}));
{{ temp_sig_var_type }} {{ temp_sig_var }} = static_cast<{{ temp_sig_var_type }}>(static_cast<double>({{ sig_var }} - {{ sig_var_offset }}) / {{ sig_var_scale }});
{% endfor %}

{% for sig in msg.signals %}
Expand Down
15 changes: 15 additions & 0 deletions scripts/cangen/templates/msg_registry.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -66,5 +80,6 @@ private:
{% endfor %}
};
};
{% endif %}

} // namespace generated::can

0 comments on commit 5fdcb87

Please sign in to comment.