diff --git a/include/charger.h b/include/charger.h index 3e3e47b..f4e138e 100644 --- a/include/charger.h +++ b/include/charger.h @@ -8,4 +8,5 @@ bool CheckTimeout(); void CalcTotals(); void DisableAll(); void EvseRead(); +bool CheckStartCondition(); #endif diff --git a/libopeninv/libopeninv.a b/libopeninv/libopeninv.a index b70a1ca..c947dd3 100644 Binary files a/libopeninv/libopeninv.a and b/libopeninv/libopeninv.a differ diff --git a/src/charger.cpp b/src/charger.cpp index 018ad5e..0261ee3 100644 --- a/src/charger.cpp +++ b/src/charger.cpp @@ -48,6 +48,12 @@ void CalcTotals() Param::SetFixed(Param::udc, udcmax); } +bool CheckStartCondition() +{ + return (IsEvseInput() && Param::GetBool(Param::proximity) && Param::Get(Param::cablelim) > FP_FROMFLT(1.4) && Param::GetBool(Param::enable)) || + (!IsEvseInput() && Param::GetBool(Param::enable)); +} + bool CheckTimeout() { uint32_t now = rtc_get_counter_val(); diff --git a/src/main.cpp b/src/main.cpp index e9765f6..8d37c57 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,11 +48,6 @@ static Can* can; static PiController dcCurController; uint32_t startTime; -static bool CheckStartCondition() -{ - return (IsEvseInput() && Param::GetBool(Param::proximity) && Param::Get(Param::cablelim) > FP_FROMFLT(1.4) && Param::GetBool(Param::enable)) || - (!IsEvseInput() && Param::GetBool(Param::enable)); -} static bool CheckVoltage() { diff --git a/test/test.c b/test/test.c index 2a04fbf..4737b31 100644 --- a/test/test.c +++ b/test/test.c @@ -22,6 +22,7 @@ int main() { (TestCase){"test_calc_totals", test_calc_totals}, (TestCase){"test_check_timeout", test_check_timeout}, (TestCase){"test_evse_read", test_evse_read}, + (TestCase){"test_check_start_condition", test_check_start_condition}, // Example: //(TestCase){"Your tests name", function_name_without_brackets} //... diff --git a/test/test.out b/test/test.out index 9f24529..109cd2a 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 68872b2..7193552 100644 --- a/test/test_logic.h +++ b/test/test_logic.h @@ -73,4 +73,59 @@ void test_evse_read() EvseRead(); assert(0 == Param::GetInt(Param::proximity)); assert(0 == Param::GetInt(Param::cablelim)); + + // INP_TYPE2 and variations + //above threshold + Param::SetInt(Param::inputype, INP_TYPE2); + AnaIn::cablelim.Set(4222); + EvseRead(); + assert(0 == Param::GetInt(Param::proximity)); + assert(0 == Param::GetInt(Param::cablelim)); + + // under threshold (example) + Param::SetInt(Param::inputype, INP_TYPE2); + AnaIn::cablelim.Set(2822); + EvseRead(); + assert(1 == Param::GetInt(Param::proximity)); + assert(20 == Param::GetInt(Param::cablelim)); +} + +void test_check_start_condition() +{ + bool res; + //not met by default + Param::SetInt(Param::inputype, INP_TYPE1); + Param::SetInt(Param::cablelim, 0); + Param::SetInt(Param::proximity, 0); + assert(IsEvseInput()); + res = CheckStartCondition(); + assert(!res); + + //enable override not in EVSE type + Param::SetInt(Param::enable, 1); + assert(IsEvseInput()); + res = CheckStartCondition(); + assert(!res); + + //enable override in manual type + Param::SetInt(Param::inputype, INP_MANUAL); + assert(!IsEvseInput()); + res = CheckStartCondition(); + assert(res); + + //EVSE start condition met + Param::SetInt(Param::inputype, INP_TYPE2_3P); + Param::SetInt(Param::enable, 1); + Param::SetInt(Param::proximity, 1); + Param::SetInt(Param::cablelim, 32); + res = CheckStartCondition(); + assert(res); + + //EVSE start condition not met cablelim + Param::SetInt(Param::inputype, INP_TYPE2_3P); + Param::SetInt(Param::enable, 1); + Param::SetInt(Param::proximity, 1); + Param::SetInt(Param::cablelim, 0); + res = CheckStartCondition(); + assert(!res); }