Explicit event initialization, local unit test execution

This commit is contained in:
Cabooman 2024-02-09 23:23:16 +01:00
parent efc5a7111f
commit fb33bee991
5 changed files with 62 additions and 15 deletions

View file

@ -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)

View file

@ -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;

View file

@ -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;

15
cmake_clean.bat Normal file
View file

@ -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..

View file

@ -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;
@ -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);
}
}