diff --git a/include/charger.h b/include/charger.h index d44803a..e921599 100644 --- a/include/charger.h +++ b/include/charger.h @@ -12,4 +12,5 @@ void EvseRead(); bool CheckStartCondition(); bool CheckVoltage(); void ResetValuesInOffMode(); +void CalcEnable(); #endif diff --git a/libopeninv/libopeninv.a b/libopeninv/libopeninv.a index bda1a57..e7fc1de 100644 Binary files a/libopeninv/libopeninv.a and b/libopeninv/libopeninv.a differ diff --git a/src/charger.cpp b/src/charger.cpp index 261ff52..ade0736 100644 --- a/src/charger.cpp +++ b/src/charger.cpp @@ -1,4 +1,5 @@ #include "my_math.h" +#include "errormessage.h" #include "charger.h" #ifdef TEST_COMMON_H #include "../test/test_common.h" @@ -177,3 +178,33 @@ void ResetValuesInOffMode() } } +void CalcEnable() +{ + static int recheckCan = 10; + bool enablePol = Param::GetBool(Param::enablepol); + bool enable = DigIo::enable_in.Get() ^ enablePol; + + enable &= !Param::GetBool(Param::cancontrol) || Param::GetBool(Param::canenable); + + if (Param::GetBool(Param::cancontrol)) + { + if (recheckCan == 0) + { + if (Param::GetInt(Param::canenable) == 3) + { + Param::SetInt(Param::canenable, 0); + ErrorMessage::Post(ERR_EXTCAN); + } + else + { + Param::SetInt(Param::canenable, 3); //Must be overwritten by CAN message within the next second + } + recheckCan = 10; + } + + recheckCan--; + } + + Param::SetInt(Param::enable, enable); +} + diff --git a/src/main.cpp b/src/main.cpp index cf2af08..2e45c9a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -211,36 +211,6 @@ static void ChargerStateMachine() Param::SetInt(Param::state, state); } -static void CalcEnable() -{ - static int recheckCan = 10; - bool enablePol = Param::GetBool(Param::enablepol); - bool enable = DigIo::enable_in.Get() ^ enablePol; - - enable &= !Param::GetBool(Param::cancontrol) || Param::GetBool(Param::canenable); - - if (Param::GetBool(Param::cancontrol)) - { - if (recheckCan == 0) - { - if (Param::GetInt(Param::canenable) == 3) - { - Param::SetInt(Param::canenable, 0); - ErrorMessage::Post(ERR_EXTCAN); - } - else - { - Param::SetInt(Param::canenable, 3); //Must be overwritten by CAN message within the next second - } - recheckCan = 10; - } - - recheckCan--; - } - - Param::SetInt(Param::enable, enable); -} - //sample 100ms task static void Ms100Task(void) { diff --git a/test/test.c b/test/test.c index 0bb01e0..8fbc45f 100644 --- a/test/test.c +++ b/test/test.c @@ -26,6 +26,7 @@ int main() { (TestCase){"test_check_start_condition", test_check_start_condition}, (TestCase){"test_check_voltage", test_check_voltage}, (TestCase){"test_reset_values_in_off_mode", test_reset_values_in_off_mode}, + (TestCase){"test_calc_enable", test_calc_enable}, // Example: //(TestCase){"Your tests name", function_name_without_brackets} //... diff --git a/test/test.out b/test/test.out index 6ee71ef..baf4831 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 697eb85..3ad5e5b 100644 --- a/test/test_logic.h +++ b/test/test_logic.h @@ -181,3 +181,60 @@ void test_reset_values_in_off_mode(){ assert(0 == Param::GetInt(Param::c3stt)); assert(0 == Param::GetInt(Param::c3uac)); } + +void test_calc_enable(){ + + int enable; + + //default off + Param::SetInt(Param::enable, 0); + Param::SetInt(Param::enablepol, 0); // polarity switch for DigIo + Param::SetInt(Param::cancontrol, 0); + Param::SetInt(Param::canenable, 0); + DigIo::enable_in.Clear(); + CalcEnable(); + enable = Param::GetInt(Param::enable); + assert(!enable); + + //only DigIo high -> on + Param::SetInt(Param::enable, 0); + Param::SetInt(Param::enablepol, 0); + Param::SetInt(Param::cancontrol, 0); + Param::SetInt(Param::canenable, 0); + DigIo::enable_in.Set(); + CalcEnable(); + enable = Param::GetInt(Param::enable); + assert(enable); + + //DigIo and enablepol high -> off + Param::SetInt(Param::enable, 0); + Param::SetInt(Param::enablepol, 1); + Param::SetInt(Param::cancontrol, 0); + Param::SetInt(Param::canenable, 0); + DigIo::enable_in.Set(); + CalcEnable(); + enable = Param::GetInt(Param::enable); + assert(!enable); + + + // DigIo & canenable -> on + Param::SetInt(Param::enable, 0); + Param::SetInt(Param::enablepol, 0); + Param::SetInt(Param::cancontrol, 0); + Param::SetInt(Param::canenable, 2); + DigIo::enable_in.Set(); + CalcEnable(); + enable = Param::GetInt(Param::enable); + assert(enable); + + //recheck can after 10+ calls + // TODO unfinished test + //int canenable = Param::GetInt(Param::canenable); + //Param::SetInt(Param::cancontrol, 1); + //for(int i =0; i < 15;i++){ + // CalcEnable(); + // enable = Param::GetInt(Param::enable); + // assert(enable); + //} + //assert(3 == canenable); +}