Skip to content

Commit

Permalink
Explicit event initialization, local unit test execution
Browse files Browse the repository at this point in the history
  • Loading branch information
Cabooman committed Feb 9, 2024
1 parent efc5a71 commit fb33bee
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
cmake_minimum_required(VERSION 3.10)

# Set the C++ standard to C++20
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

project(BatteryEmulator)

# add_subdirectory(Software/src/devboard/utils)
Expand Down
2 changes: 1 addition & 1 deletion Software/Software.ino
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ void handle_LED_state() {
} else if (!rampUp && brightness == 0) {
rampUp = true;
}
switch (get_event_ledcolor()) {
switch (LEDcolor) {
case GREEN:
pixels.setPixelColor(0, pixels.Color(0, brightness, 0)); // Green pulsing LED
break;
Expand Down
50 changes: 38 additions & 12 deletions Software/src/devboard/utils/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,45 @@ void run_event_handling(void) {

/* Initialization function */
void init_events(void) {
for (uint8_t i = 0; i < EVENT_NOF_EVENTS; i++) {
events.entries[i].timestamp = 0;
events.entries[i].data = 0;
events.entries[i].occurences = 0;
events.entries[i].led_color = RED; // Most events are RED
events.entries[i].state = EVENT_STATE_INACTIVE;
}

// YELLOW events below
events.entries[EVENT_12V_LOW].led_color = YELLOW;
events.entries[EVENT_CAN_WARNING].led_color = YELLOW;
events.entries[EVENT_CELL_DEVIATION_HIGH].led_color = YELLOW;
events.entries[EVENT_KWH_PLAUSIBILITY_ERROR].led_color = YELLOW;
events.entries[EVENT_CAN_FAILURE] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = RED, .state = EVENT_STATE_INACTIVE};
events.entries[EVENT_CAN_WARNING] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = YELLOW, .state = EVENT_STATE_INACTIVE};
events.entries[EVENT_WATER_INGRESS] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = RED, .state = EVENT_STATE_INACTIVE};
events.entries[EVENT_12V_LOW] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = YELLOW, .state = EVENT_STATE_INACTIVE};
events.entries[EVENT_SOC_PLAUSIBILITY_ERROR] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = RED, .state = EVENT_STATE_INACTIVE};
events.entries[EVENT_KWH_PLAUSIBILITY_ERROR] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = YELLOW, .state = EVENT_STATE_INACTIVE};
events.entries[EVENT_BATTERY_CHG_STOP_REQ] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = RED, .state = EVENT_STATE_INACTIVE};
events.entries[EVENT_BATTERY_DISCHG_STOP_REQ] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = RED, .state = EVENT_STATE_INACTIVE};
events.entries[EVENT_BATTERY_CHG_DISCHG_STOP_REQ] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = RED, .state = EVENT_STATE_INACTIVE};
events.entries[EVENT_LOW_SOH] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = RED, .state = EVENT_STATE_INACTIVE};
events.entries[EVENT_HVIL_FAILURE] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = RED, .state = EVENT_STATE_INACTIVE};
events.entries[EVENT_INTERNAL_OPEN_FAULT] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = RED, .state = EVENT_STATE_INACTIVE};
events.entries[EVENT_CELL_UNDER_VOLTAGE] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = RED, .state = EVENT_STATE_INACTIVE};
events.entries[EVENT_CELL_OVER_VOLTAGE] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = RED, .state = EVENT_STATE_INACTIVE};
events.entries[EVENT_CELL_DEVIATION_HIGH] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = YELLOW, .state = EVENT_STATE_INACTIVE};
events.entries[EVENT_UNKNOWN_EVENT_SET] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = RED, .state = EVENT_STATE_INACTIVE};
events.entries[EVENT_OTA_UPDATE] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = BLUE, .state = EVENT_STATE_INACTIVE};
events.entries[EVENT_DUMMY] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = RED, .state = EVENT_STATE_INACTIVE};
events.entries[EVENT_NOF_EVENTS] = {
.timestamp = 0, .data = 0, .occurences = 0, .led_color = RED, .state = EVENT_STATE_INACTIVE};

// BLUE...
events.entries[EVENT_OTA_UPDATE].led_color = BLUE;
Expand Down
15 changes: 15 additions & 0 deletions cmake_clean.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@echo off
echo Cleaning up
rmdir /Q/S build
echo Creating new CMake build folder
mkdir build
cd build
echo Building CMake project
call cmake ..
call cmake --build .
echo Executing tests
for %%i in ("test\Debug\*.exe") do (
echo Running %%i
%%i
)
cd..
6 changes: 4 additions & 2 deletions test/utils/events_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include "../test_lib.h"

#include "../../Software/src/devboard/config.h"
#include "events.cpp"
#include "timer.cpp"
#include "../../Software/src/devboard/utils/events.cpp"
#include "../../Software/src/devboard/utils/timer.cpp"

/* Local rest variables */
bool elapsed = false;
Expand All @@ -20,6 +20,8 @@ TEST(init_events_test) {

for (uint8_t i = 0; i < EVENT_NOF_EVENTS; i++) {
ASSERT_EQ(events.entries[i].occurences, 0);
ASSERT_EQ(events.entries[i].data, 0);
ASSERT_EQ(events.entries[i].timestamp, 0);
}
}

Expand Down

0 comments on commit fb33bee

Please sign in to comment.