diff --git a/include/charger.h b/include/charger.h index f4e138e..872dc06 100644 --- a/include/charger.h +++ b/include/charger.h @@ -9,4 +9,5 @@ void CalcTotals(); void DisableAll(); void EvseRead(); bool CheckStartCondition(); +bool CheckVoltage(); #endif diff --git a/libopeninv/libopeninv.a b/libopeninv/libopeninv.a index c947dd3..ba7384a 100644 Binary files a/libopeninv/libopeninv.a and b/libopeninv/libopeninv.a differ diff --git a/src/charger.cpp b/src/charger.cpp index 0261ee3..4cf9359 100644 --- a/src/charger.cpp +++ b/src/charger.cpp @@ -54,6 +54,23 @@ bool CheckStartCondition() (!IsEvseInput() && Param::GetBool(Param::enable)); } +bool CheckVoltage() +{ + static int timeout = 0; + + if (Param::Get(Param::udc) > Param::Get(Param::udclim)) + { + timeout++; + } + else + { + timeout = 0; + } + + return timeout > 10; +} + + bool CheckTimeout() { uint32_t now = rtc_get_counter_val(); diff --git a/src/main.cpp b/src/main.cpp index 8d37c57..755c775 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,23 +48,6 @@ static Can* can; static PiController dcCurController; uint32_t startTime; - -static bool CheckVoltage() -{ - static int timeout = 0; - - if (Param::Get(Param::udc) > Param::Get(Param::udclim)) - { - timeout++; - } - else - { - timeout = 0; - } - - return timeout > 10; -} - static bool CheckChargerFaults() { const int acPresentThresh = 70; diff --git a/test/test.c b/test/test.c index 4737b31..5bdf44c 100644 --- a/test/test.c +++ b/test/test.c @@ -23,6 +23,7 @@ int main() { (TestCase){"test_check_timeout", test_check_timeout}, (TestCase){"test_evse_read", test_evse_read}, (TestCase){"test_check_start_condition", test_check_start_condition}, + (TestCase){"test_check_voltage", test_check_voltage}, // Example: //(TestCase){"Your tests name", function_name_without_brackets} //... diff --git a/test/test.out b/test/test.out index 109cd2a..ff6cca7 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 7193552..9a9f28b 100644 --- a/test/test_logic.h +++ b/test/test_logic.h @@ -129,3 +129,19 @@ void test_check_start_condition() res = CheckStartCondition(); assert(!res); } + +void test_check_voltage(){ + bool res; + Param::SetInt(Param::udc, 400); + Param::SetInt(Param::udclim, 390); + + // tolerate up to ten one off spikes + res = CheckVoltage(); + assert(!res); + + // drop out if received more than ten + for(int i =0; i < 15;i++){ + res = CheckVoltage(); + } + assert(res); +}