diff --git a/Makefile b/Makefile index d3e0e74..44ce955 100644 --- a/Makefile +++ b/Makefile @@ -126,8 +126,9 @@ Test: g++ -c -Ilibopeninv/include/ -Iinclude -o errormessage.o libopeninv/src/errormessage.cpp g++ -c -Ilibopeninv/include/ -Iinclude -o printf.o libopeninv/src/printf.cpp g++ -c -Ilibopeninv/include/ -Iinclude -o digio_mock.o test/digio_mock.cpp + g++ -c -Ilibopeninv/include/ -Iinclude -o timer_mock.o test/timer_mock.cpp ar rcs libopeninv/libopeninv.a *.o - rm -f my_fp.o my_string.o params.o errormessage.o printf.o digio_mock.o chademo.o terminal.o + rm -f my_fp.o my_string.o params.o errormessage.o printf.o digio_mock.o timer_mock.o chademo.o terminal.o g++ -gdwarf-2 -g test/test.c -Llibopeninv -Iinclude -lopeninv -o test/test.out && gdb -ex='set confirm on' -ex=run -ex=quit --args ./test/test.out cleanTest: cd test && $(MAKE) clean diff --git a/include/charger.h b/include/charger.h index d08f8c1..b7e66b0 100644 --- a/include/charger.h +++ b/include/charger.h @@ -1,6 +1,10 @@ #include "../libopeninv/include/params.h" #ifdef TEST_COMMON_H #include "../test/digio_mock.h" +#include "../test/timer_mock.h" +#else +#include +#include #endif static bool IsEvseInput(); @@ -43,3 +47,14 @@ static void CalcTotals() Param::SetFixed(Param::udc, udcmax); } +static uint32_t startTime; +static bool CheckTimeout() +{ + uint32_t now = rtc_get_counter_val(); + uint32_t timeout = Param::GetInt(Param::timelim); + + timeout *= 60; + + return timeout > 0 && (now - startTime) > timeout; +} + diff --git a/include/param_prj.h b/include/param_prj.h index abd3edd..134d06e 100644 --- a/include/param_prj.h +++ b/include/param_prj.h @@ -107,6 +107,7 @@ VALUE_ENTRY(c3iac, "A", 2034 ) \ VALUE_ENTRY(c3udc, "V", 2035 ) \ VALUE_ENTRY(c3idc, "A", 2036 ) \ + VALUE_ENTRY(test_time, "s", 2037 ) \ /***** Enum String definitions *****/ diff --git a/libopeninv/libopeninv.a b/libopeninv/libopeninv.a index f081895..1f3f92c 100644 Binary files a/libopeninv/libopeninv.a and b/libopeninv/libopeninv.a differ diff --git a/src/main.cpp b/src/main.cpp index 843e2bb..a5b9dca 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,8 +18,12 @@ */ #include #include +#ifdef TEST_COMMON_H +#include "../test/timer_mock.h" +#else #include #include +#endif #include #include #include @@ -42,7 +46,6 @@ static Stm32Scheduler* scheduler; static Can* can; static PiController dcCurController; -static uint32_t startTime; static void EvseRead() { @@ -189,16 +192,6 @@ static bool CheckChargerFaults() (active3 && ((Param::GetInt(Param::c3flag) & FLAG_FAULT) || timeouts[2])); } -static bool CheckTimeout() -{ - uint32_t now = rtc_get_counter_val(); - uint32_t timeout = Param::GetInt(Param::timelim); - - timeout *= 60; - - return timeout > 0 && (now - startTime) > timeout; -} - static bool CheckDelay() { uint32_t now = rtc_get_counter_val(); diff --git a/test/test.c b/test/test.c index eeaff39..38354da 100644 --- a/test/test.c +++ b/test/test.c @@ -20,6 +20,7 @@ int main() { (TestCase){"test_check_unplugged", test_check_unplugged}, (TestCase){"test_disable_all", test_disable_all}, (TestCase){"test_calc_totals", test_calc_totals}, + (TestCase){"test_check_timeout", test_check_timeout}, // Example: //(TestCase){"Your tests name", function_name_without_brackets} //... diff --git a/test/test.out b/test/test.out index d28182d..e170f40 100755 Binary files a/test/test.out and b/test/test.out differ diff --git a/test/test_common.h b/test/test_common.h index 3d388a8..41f96cf 100644 --- a/test/test_common.h +++ b/test/test_common.h @@ -1,7 +1,6 @@ - #ifndef TEST_COMMON_H #define TEST_COMMON_H -#include "charger.h" +#include "timer_mock.h" #include "digio_mock.h" - +#include "charger.h" #endif diff --git a/test/test_logic.h b/test/test_logic.h index f4e2b8e..20d2c43 100644 --- a/test/test_logic.h +++ b/test/test_logic.h @@ -27,3 +27,23 @@ void test_calc_totals() s32fp udcmax = Param::Get(Param::udc); assert(366 == FP_TOINT(udcmax)); } + +// TIMER NEEDED +void test_check_timeout() +{ + bool res; + startTime = 11; + Param::SetInt(Param::test_time, 14 * 60); + Param::SetInt(Param::timelim, 13); + + res = CheckTimeout(); + assert(res); + + Param::SetInt(Param::test_time, 12 * 60); + res = CheckTimeout(); + assert(!res); + + startTime = 1100; + res = CheckTimeout(); + assert(res); +} diff --git a/test/timer_mock.cpp b/test/timer_mock.cpp new file mode 100644 index 0000000..0656fec --- /dev/null +++ b/test/timer_mock.cpp @@ -0,0 +1,5 @@ +#include "timer_mock.h" + +uint32_t rtc_get_counter_val(){ + return Param::Get(Param::test_time) >> 5; +} diff --git a/test/timer_mock.h b/test/timer_mock.h new file mode 100644 index 0000000..34a842a --- /dev/null +++ b/test/timer_mock.h @@ -0,0 +1,3 @@ +#include +#include "../libopeninv/include/params.h" +uint32_t rtc_get_counter_val();