diff --git a/include/charger.h b/include/charger.h index 872dc06..14e3c24 100644 --- a/include/charger.h +++ b/include/charger.h @@ -5,6 +5,7 @@ extern uint32_t startTime; bool IsEvseInput(); bool CheckUnplugged(); bool CheckTimeout(); +bool CheckDelay(); void CalcTotals(); void DisableAll(); void EvseRead(); diff --git a/libopeninv/libopeninv.a b/libopeninv/libopeninv.a index ba7384a..62596d2 100644 Binary files a/libopeninv/libopeninv.a and b/libopeninv/libopeninv.a differ diff --git a/src/charger.cpp b/src/charger.cpp index 4cf9359..e4cba2c 100644 --- a/src/charger.cpp +++ b/src/charger.cpp @@ -81,6 +81,15 @@ bool CheckTimeout() return timeout > 0 && (now - startTime) > timeout; } +bool CheckDelay() +{ + uint32_t now = rtc_get_counter_val(); + uint32_t start = Param::GetInt(Param::timedly) * 60; + + return start <= 0 || (now - startTime) > start; +} + + void EvseRead() { const int threshProxType1 = 2200; diff --git a/src/main.cpp b/src/main.cpp index 755c775..57ede44 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -93,14 +93,6 @@ static bool CheckChargerFaults() (active3 && ((Param::GetInt(Param::c3flag) & FLAG_FAULT) || timeouts[2])); } -static bool CheckDelay() -{ - uint32_t now = rtc_get_counter_val(); - uint32_t start = Param::GetInt(Param::timedly) * 60; - - return start <= 0 || (now - startTime) > start; -} - static void CalcAcCurrentLimit() { int configuredChargers = Param::GetInt(Param::chargerena); diff --git a/test/test.c b/test/test.c index 5bdf44c..7b98ac0 100644 --- a/test/test.c +++ b/test/test.c @@ -21,6 +21,7 @@ int main() { (TestCase){"test_disable_all", test_disable_all}, (TestCase){"test_calc_totals", test_calc_totals}, (TestCase){"test_check_timeout", test_check_timeout}, + (TestCase){"test_check_delay", test_check_delay}, (TestCase){"test_evse_read", test_evse_read}, (TestCase){"test_check_start_condition", test_check_start_condition}, (TestCase){"test_check_voltage", test_check_voltage}, diff --git a/test/test.out b/test/test.out index ff6cca7..4c71687 100755 Binary files a/test/test.out and b/test/test.out differ diff --git a/test/test_logic.h b/test/test_logic.h index 9a9f28b..749b852 100644 --- a/test/test_logic.h +++ b/test/test_logic.h @@ -52,6 +52,29 @@ void test_check_timeout() assert(res); } +void test_check_delay() +{ + bool res; + startTime = 11; + + //after delay + Param::SetInt(Param::test_time, 14 * 60); + Param::SetInt(Param::timedly, 13); + res = CheckDelay(); + assert(res); + + //before delay + Param::SetInt(Param::test_time, 12 * 60); + res = CheckDelay(); + assert(!res); + + //start time changes result + startTime = 1100; + res = CheckDelay(); + assert(res); +} + + void test_evse_read() { // INP_MANUAL